2012-09-01 07:48:21 +09:00
|
|
|
/* Copyright 2012 Mozilla Foundation
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
2012-02-14 10:35:58 +09:00
|
|
|
|
2023-07-21 23:30:28 +09:00
|
|
|
const { OPS } = globalThis.pdfjsLib || (await import("pdfjs-lib"));
|
|
|
|
|
|
|
|
const opMap = Object.create(null);
|
|
|
|
for (const key in OPS) {
|
|
|
|
opMap[OPS[key]] = key;
|
|
|
|
}
|
2012-02-14 10:35:58 +09:00
|
|
|
|
Convert `web/debugger.js` to a *basic* module
The various functionality in `web/debugger.js` is currently *indirectly* added to the global scope, since that's how `var` works when it's used outside of any functions/closures.
Given how this functionality is being accessed/used, not just in the viewer but also in the API and textLayer, simply converting the entire file to a module isn't trivial[1]. However, we can at least export the `PDFBug`-part properly and then `import` that dynamically in the viewer.
Also, to improve the code a little bit, we're now *explicitly* exporting the necessary functionality globally.
According to MDN, see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#browser_compatibility, all the browsers that we now support have dynamic `imports` implementations.
---
[1] We could probably pass around references to the necessary functionality, but given how this is being used I'm just not sure it's worth the effort. Also, adding *official* support for these viewer-specific debugging tools in the API feels both unnecessary and unfortunate.
2022-04-03 18:51:49 +09:00
|
|
|
const FontInspector = (function FontInspectorClosure() {
|
[web/debugger.js] Enable the ESLint `no-var` rule
These changes were made *mostly* automatically, using `gulp lint --fix`, with the following manual changes:
```diff
diff --git a/web/debugger.js b/web/debugger.js
index 1cda4066e..6f8b4a9f0 100644
--- a/web/debugger.js
+++ b/web/debugger.js
@@ -264,10 +264,9 @@ const Stepper = (function StepperClosure() {
}
if ("length" in args) {
// array
- let simpleArgs = [],
- i,
- ii;
- const MAX_ITEMS = 10;
+ const MAX_ITEMS = 10,
+ simpleArgs = [];
+ let i, ii;
for (i = 0, ii = Math.min(MAX_ITEMS, args.length); i < ii; i++) {
simpleArgs.push(simplifyArgs(args[i]));
}
@@ -511,11 +510,8 @@ window.PDFBug = (function PDFBugClosure() {
return {
tools: [FontInspector, StepperManager, Stats],
enable(ids) {
- let all = false,
- tools = this.tools;
- if (ids.length === 1 && ids[0] === "all") {
- all = true;
- }
+ const all = ids.length === 1 && ids[0] === "all";
+ const tools = this.tools;
for (let i = 0; i < tools.length; ++i) {
const tool = tools[i];
if (all || ids.includes(tool.id)) {
```
2021-05-04 21:37:16 +09:00
|
|
|
let fonts;
|
|
|
|
let active = false;
|
|
|
|
const fontAttribute = "data-font-name";
|
2012-02-14 10:35:58 +09:00
|
|
|
function removeSelection() {
|
2019-12-27 08:22:32 +09:00
|
|
|
const divs = document.querySelectorAll(`span[${fontAttribute}]`);
|
|
|
|
for (const div of divs) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
div.className = "";
|
2012-02-14 10:35:58 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
function resetSelection() {
|
2019-12-27 08:22:32 +09:00
|
|
|
const divs = document.querySelectorAll(`span[${fontAttribute}]`);
|
|
|
|
for (const div of divs) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
div.className = "debuggerHideText";
|
2012-02-14 10:35:58 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
function selectFont(fontName, show) {
|
2019-12-27 08:22:32 +09:00
|
|
|
const divs = document.querySelectorAll(
|
|
|
|
`span[${fontAttribute}=${fontName}]`
|
|
|
|
);
|
|
|
|
for (const div of divs) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
div.className = show ? "debuggerShowText" : "debuggerHideText";
|
2012-02-14 10:35:58 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
function textLayerClick(e) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (
|
|
|
|
!e.target.dataset.fontName ||
|
|
|
|
e.target.tagName.toUpperCase() !== "SPAN"
|
|
|
|
) {
|
2012-02-14 10:35:58 +09:00
|
|
|
return;
|
2014-03-09 07:42:23 +09:00
|
|
|
}
|
[web/debugger.js] Enable the ESLint `no-var` rule
These changes were made *mostly* automatically, using `gulp lint --fix`, with the following manual changes:
```diff
diff --git a/web/debugger.js b/web/debugger.js
index 1cda4066e..6f8b4a9f0 100644
--- a/web/debugger.js
+++ b/web/debugger.js
@@ -264,10 +264,9 @@ const Stepper = (function StepperClosure() {
}
if ("length" in args) {
// array
- let simpleArgs = [],
- i,
- ii;
- const MAX_ITEMS = 10;
+ const MAX_ITEMS = 10,
+ simpleArgs = [];
+ let i, ii;
for (i = 0, ii = Math.min(MAX_ITEMS, args.length); i < ii; i++) {
simpleArgs.push(simplifyArgs(args[i]));
}
@@ -511,11 +510,8 @@ window.PDFBug = (function PDFBugClosure() {
return {
tools: [FontInspector, StepperManager, Stats],
enable(ids) {
- let all = false,
- tools = this.tools;
- if (ids.length === 1 && ids[0] === "all") {
- all = true;
- }
+ const all = ids.length === 1 && ids[0] === "all";
+ const tools = this.tools;
for (let i = 0; i < tools.length; ++i) {
const tool = tools[i];
if (all || ids.includes(tool.id)) {
```
2021-05-04 21:37:16 +09:00
|
|
|
const fontName = e.target.dataset.fontName;
|
|
|
|
const selects = document.getElementsByTagName("input");
|
2022-04-02 18:53:59 +09:00
|
|
|
for (const select of selects) {
|
2014-08-01 05:01:54 +09:00
|
|
|
if (select.dataset.fontName !== fontName) {
|
2014-03-09 07:42:23 +09:00
|
|
|
continue;
|
|
|
|
}
|
2012-02-14 10:35:58 +09:00
|
|
|
select.checked = !select.checked;
|
|
|
|
selectFont(fontName, select.checked);
|
|
|
|
select.scrollIntoView();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return {
|
2012-08-09 03:26:24 +09:00
|
|
|
// Properties/functions needed by PDFBug.
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
id: "FontInspector",
|
|
|
|
name: "Font Inspector",
|
2012-02-14 10:35:58 +09:00
|
|
|
panel: null,
|
|
|
|
manager: null,
|
2023-07-21 23:30:28 +09:00
|
|
|
init() {
|
[web/debugger.js] Enable the ESLint `no-var` rule
These changes were made *mostly* automatically, using `gulp lint --fix`, with the following manual changes:
```diff
diff --git a/web/debugger.js b/web/debugger.js
index 1cda4066e..6f8b4a9f0 100644
--- a/web/debugger.js
+++ b/web/debugger.js
@@ -264,10 +264,9 @@ const Stepper = (function StepperClosure() {
}
if ("length" in args) {
// array
- let simpleArgs = [],
- i,
- ii;
- const MAX_ITEMS = 10;
+ const MAX_ITEMS = 10,
+ simpleArgs = [];
+ let i, ii;
for (i = 0, ii = Math.min(MAX_ITEMS, args.length); i < ii; i++) {
simpleArgs.push(simplifyArgs(args[i]));
}
@@ -511,11 +510,8 @@ window.PDFBug = (function PDFBugClosure() {
return {
tools: [FontInspector, StepperManager, Stats],
enable(ids) {
- let all = false,
- tools = this.tools;
- if (ids.length === 1 && ids[0] === "all") {
- all = true;
- }
+ const all = ids.length === 1 && ids[0] === "all";
+ const tools = this.tools;
for (let i = 0; i < tools.length; ++i) {
const tool = tools[i];
if (all || ids.includes(tool.id)) {
```
2021-05-04 21:37:16 +09:00
|
|
|
const panel = this.panel;
|
|
|
|
const tmp = document.createElement("button");
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
tmp.addEventListener("click", resetSelection);
|
|
|
|
tmp.textContent = "Refresh";
|
2022-06-12 19:20:25 +09:00
|
|
|
panel.append(tmp);
|
2012-02-14 10:35:58 +09:00
|
|
|
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
fonts = document.createElement("div");
|
2022-06-12 19:20:25 +09:00
|
|
|
panel.append(fonts);
|
2012-02-14 10:35:58 +09:00
|
|
|
},
|
2022-04-02 18:53:59 +09:00
|
|
|
cleanup() {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
fonts.textContent = "";
|
2014-03-27 05:18:53 +09:00
|
|
|
},
|
2012-02-14 10:35:58 +09:00
|
|
|
enabled: false,
|
|
|
|
get active() {
|
|
|
|
return active;
|
|
|
|
},
|
|
|
|
set active(value) {
|
|
|
|
active = value;
|
|
|
|
if (active) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
document.body.addEventListener("click", textLayerClick, true);
|
2012-02-14 10:35:58 +09:00
|
|
|
resetSelection();
|
|
|
|
} else {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
document.body.removeEventListener("click", textLayerClick, true);
|
2012-02-14 10:35:58 +09:00
|
|
|
removeSelection();
|
|
|
|
}
|
|
|
|
},
|
2012-02-15 02:24:29 +09:00
|
|
|
// FontInspector specific functions.
|
2022-04-02 18:53:59 +09:00
|
|
|
fontAdded(fontObj, url) {
|
2012-02-14 10:35:58 +09:00
|
|
|
function properties(obj, list) {
|
[web/debugger.js] Enable the ESLint `no-var` rule
These changes were made *mostly* automatically, using `gulp lint --fix`, with the following manual changes:
```diff
diff --git a/web/debugger.js b/web/debugger.js
index 1cda4066e..6f8b4a9f0 100644
--- a/web/debugger.js
+++ b/web/debugger.js
@@ -264,10 +264,9 @@ const Stepper = (function StepperClosure() {
}
if ("length" in args) {
// array
- let simpleArgs = [],
- i,
- ii;
- const MAX_ITEMS = 10;
+ const MAX_ITEMS = 10,
+ simpleArgs = [];
+ let i, ii;
for (i = 0, ii = Math.min(MAX_ITEMS, args.length); i < ii; i++) {
simpleArgs.push(simplifyArgs(args[i]));
}
@@ -511,11 +510,8 @@ window.PDFBug = (function PDFBugClosure() {
return {
tools: [FontInspector, StepperManager, Stats],
enable(ids) {
- let all = false,
- tools = this.tools;
- if (ids.length === 1 && ids[0] === "all") {
- all = true;
- }
+ const all = ids.length === 1 && ids[0] === "all";
+ const tools = this.tools;
for (let i = 0; i < tools.length; ++i) {
const tool = tools[i];
if (all || ids.includes(tool.id)) {
```
2021-05-04 21:37:16 +09:00
|
|
|
const moreInfo = document.createElement("table");
|
2022-04-02 18:53:59 +09:00
|
|
|
for (const entry of list) {
|
[web/debugger.js] Enable the ESLint `no-var` rule
These changes were made *mostly* automatically, using `gulp lint --fix`, with the following manual changes:
```diff
diff --git a/web/debugger.js b/web/debugger.js
index 1cda4066e..6f8b4a9f0 100644
--- a/web/debugger.js
+++ b/web/debugger.js
@@ -264,10 +264,9 @@ const Stepper = (function StepperClosure() {
}
if ("length" in args) {
// array
- let simpleArgs = [],
- i,
- ii;
- const MAX_ITEMS = 10;
+ const MAX_ITEMS = 10,
+ simpleArgs = [];
+ let i, ii;
for (i = 0, ii = Math.min(MAX_ITEMS, args.length); i < ii; i++) {
simpleArgs.push(simplifyArgs(args[i]));
}
@@ -511,11 +510,8 @@ window.PDFBug = (function PDFBugClosure() {
return {
tools: [FontInspector, StepperManager, Stats],
enable(ids) {
- let all = false,
- tools = this.tools;
- if (ids.length === 1 && ids[0] === "all") {
- all = true;
- }
+ const all = ids.length === 1 && ids[0] === "all";
+ const tools = this.tools;
for (let i = 0; i < tools.length; ++i) {
const tool = tools[i];
if (all || ids.includes(tool.id)) {
```
2021-05-04 21:37:16 +09:00
|
|
|
const tr = document.createElement("tr");
|
|
|
|
const td1 = document.createElement("td");
|
2022-04-02 18:53:59 +09:00
|
|
|
td1.textContent = entry;
|
2022-06-12 19:20:25 +09:00
|
|
|
tr.append(td1);
|
[web/debugger.js] Enable the ESLint `no-var` rule
These changes were made *mostly* automatically, using `gulp lint --fix`, with the following manual changes:
```diff
diff --git a/web/debugger.js b/web/debugger.js
index 1cda4066e..6f8b4a9f0 100644
--- a/web/debugger.js
+++ b/web/debugger.js
@@ -264,10 +264,9 @@ const Stepper = (function StepperClosure() {
}
if ("length" in args) {
// array
- let simpleArgs = [],
- i,
- ii;
- const MAX_ITEMS = 10;
+ const MAX_ITEMS = 10,
+ simpleArgs = [];
+ let i, ii;
for (i = 0, ii = Math.min(MAX_ITEMS, args.length); i < ii; i++) {
simpleArgs.push(simplifyArgs(args[i]));
}
@@ -511,11 +510,8 @@ window.PDFBug = (function PDFBugClosure() {
return {
tools: [FontInspector, StepperManager, Stats],
enable(ids) {
- let all = false,
- tools = this.tools;
- if (ids.length === 1 && ids[0] === "all") {
- all = true;
- }
+ const all = ids.length === 1 && ids[0] === "all";
+ const tools = this.tools;
for (let i = 0; i < tools.length; ++i) {
const tool = tools[i];
if (all || ids.includes(tool.id)) {
```
2021-05-04 21:37:16 +09:00
|
|
|
const td2 = document.createElement("td");
|
2022-04-02 18:53:59 +09:00
|
|
|
td2.textContent = obj[entry].toString();
|
2022-06-12 19:20:25 +09:00
|
|
|
tr.append(td2);
|
|
|
|
moreInfo.append(tr);
|
2012-02-14 10:35:58 +09:00
|
|
|
}
|
|
|
|
return moreInfo;
|
|
|
|
}
|
2023-10-05 17:19:07 +09:00
|
|
|
|
|
|
|
const moreInfo = fontObj.css
|
|
|
|
? properties(fontObj, ["baseFontName"])
|
|
|
|
: properties(fontObj, ["name", "type"]);
|
|
|
|
|
2020-03-13 20:55:00 +09:00
|
|
|
const fontName = fontObj.loadedName;
|
[web/debugger.js] Enable the ESLint `no-var` rule
These changes were made *mostly* automatically, using `gulp lint --fix`, with the following manual changes:
```diff
diff --git a/web/debugger.js b/web/debugger.js
index 1cda4066e..6f8b4a9f0 100644
--- a/web/debugger.js
+++ b/web/debugger.js
@@ -264,10 +264,9 @@ const Stepper = (function StepperClosure() {
}
if ("length" in args) {
// array
- let simpleArgs = [],
- i,
- ii;
- const MAX_ITEMS = 10;
+ const MAX_ITEMS = 10,
+ simpleArgs = [];
+ let i, ii;
for (i = 0, ii = Math.min(MAX_ITEMS, args.length); i < ii; i++) {
simpleArgs.push(simplifyArgs(args[i]));
}
@@ -511,11 +510,8 @@ window.PDFBug = (function PDFBugClosure() {
return {
tools: [FontInspector, StepperManager, Stats],
enable(ids) {
- let all = false,
- tools = this.tools;
- if (ids.length === 1 && ids[0] === "all") {
- all = true;
- }
+ const all = ids.length === 1 && ids[0] === "all";
+ const tools = this.tools;
for (let i = 0; i < tools.length; ++i) {
const tool = tools[i];
if (all || ids.includes(tool.id)) {
```
2021-05-04 21:37:16 +09:00
|
|
|
const font = document.createElement("div");
|
|
|
|
const name = document.createElement("span");
|
2012-02-14 10:35:58 +09:00
|
|
|
name.textContent = fontName;
|
2023-10-05 17:19:07 +09:00
|
|
|
let download;
|
|
|
|
if (!fontObj.css) {
|
|
|
|
download = document.createElement("a");
|
|
|
|
if (url) {
|
|
|
|
url = /url\(['"]?([^)"']+)/.exec(url);
|
|
|
|
download.href = url[1];
|
|
|
|
} else if (fontObj.data) {
|
|
|
|
download.href = URL.createObjectURL(
|
|
|
|
new Blob([fontObj.data], { type: fontObj.mimetype })
|
|
|
|
);
|
|
|
|
}
|
|
|
|
download.textContent = "Download";
|
2014-10-01 04:24:31 +09:00
|
|
|
}
|
2023-10-05 17:19:07 +09:00
|
|
|
|
[web/debugger.js] Enable the ESLint `no-var` rule
These changes were made *mostly* automatically, using `gulp lint --fix`, with the following manual changes:
```diff
diff --git a/web/debugger.js b/web/debugger.js
index 1cda4066e..6f8b4a9f0 100644
--- a/web/debugger.js
+++ b/web/debugger.js
@@ -264,10 +264,9 @@ const Stepper = (function StepperClosure() {
}
if ("length" in args) {
// array
- let simpleArgs = [],
- i,
- ii;
- const MAX_ITEMS = 10;
+ const MAX_ITEMS = 10,
+ simpleArgs = [];
+ let i, ii;
for (i = 0, ii = Math.min(MAX_ITEMS, args.length); i < ii; i++) {
simpleArgs.push(simplifyArgs(args[i]));
}
@@ -511,11 +510,8 @@ window.PDFBug = (function PDFBugClosure() {
return {
tools: [FontInspector, StepperManager, Stats],
enable(ids) {
- let all = false,
- tools = this.tools;
- if (ids.length === 1 && ids[0] === "all") {
- all = true;
- }
+ const all = ids.length === 1 && ids[0] === "all";
+ const tools = this.tools;
for (let i = 0; i < tools.length; ++i) {
const tool = tools[i];
if (all || ids.includes(tool.id)) {
```
2021-05-04 21:37:16 +09:00
|
|
|
const logIt = document.createElement("a");
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
logIt.href = "";
|
|
|
|
logIt.textContent = "Log";
|
2020-04-14 19:28:14 +09:00
|
|
|
logIt.addEventListener("click", function (event) {
|
2012-02-14 10:35:58 +09:00
|
|
|
event.preventDefault();
|
|
|
|
console.log(fontObj);
|
|
|
|
});
|
2020-03-13 20:55:00 +09:00
|
|
|
const select = document.createElement("input");
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
select.setAttribute("type", "checkbox");
|
2012-02-14 10:35:58 +09:00
|
|
|
select.dataset.fontName = fontName;
|
2020-04-14 19:28:14 +09:00
|
|
|
select.addEventListener("click", function () {
|
2020-03-13 20:55:00 +09:00
|
|
|
selectFont(fontName, select.checked);
|
|
|
|
});
|
2023-10-05 17:19:07 +09:00
|
|
|
if (download) {
|
|
|
|
font.append(select, name, " ", download, " ", logIt, moreInfo);
|
|
|
|
} else {
|
|
|
|
font.append(select, name, " ", logIt, moreInfo);
|
|
|
|
}
|
2022-06-12 19:20:25 +09:00
|
|
|
fonts.append(font);
|
2012-02-15 02:24:29 +09:00
|
|
|
// Somewhat of a hack, should probably add a hook for when the text layer
|
2012-02-14 10:35:58 +09:00
|
|
|
// is done rendering.
|
2017-05-05 00:09:50 +09:00
|
|
|
setTimeout(() => {
|
2014-03-09 07:42:23 +09:00
|
|
|
if (this.active) {
|
2012-02-14 10:35:58 +09:00
|
|
|
resetSelection();
|
2014-03-09 07:42:23 +09:00
|
|
|
}
|
2017-05-05 00:09:50 +09:00
|
|
|
}, 2000);
|
Fix inconsistent spacing and trailing commas in objects in `web/` files, so we can enable the `comma-dangle` and `object-curly-spacing` ESLint rules later on
http://eslint.org/docs/rules/comma-dangle
http://eslint.org/docs/rules/object-curly-spacing
Given that we currently have quite inconsistent object formatting, fixing this in in *one* big patch probably wouldn't be feasible (since I cannot imagine anyone wanting to review that); hence I've opted to try and do this piecewise instead.
*Please note:* This patch was created automatically, using the ESLint `--fix` command line option. In a couple of places this caused lines to become too long, and I've fixed those manually; please refer to the interdiff below for the only hand-edits in this patch.
```diff
diff --git a/web/pdf_thumbnail_view.js b/web/pdf_thumbnail_view.js
index 002dbf29..1de4e530 100644
--- a/web/pdf_thumbnail_view.js
+++ b/web/pdf_thumbnail_view.js
@@ -420,8 +420,8 @@ var PDFThumbnailView = (function PDFThumbnailViewClosure() {
setPageLabel: function PDFThumbnailView_setPageLabel(label) {
this.pageLabel = (typeof label === 'string' ? label : null);
- this.l10n.get('thumb_page_title', { page: this.pageId, }, 'Page {{page}}').
- then((msg) => {
+ this.l10n.get('thumb_page_title', { page: this.pageId, },
+ 'Page {{page}}').then((msg) => {
this.anchor.title = msg;
});
diff --git a/web/secondary_toolbar.js b/web/secondary_toolbar.js
index 160e0410..6495fc5e 100644
--- a/web/secondary_toolbar.js
+++ b/web/secondary_toolbar.js
@@ -65,7 +65,8 @@ class SecondaryToolbar {
{ element: options.printButton, eventName: 'print', close: true, },
{ element: options.downloadButton, eventName: 'download', close: true, },
{ element: options.viewBookmarkButton, eventName: null, close: true, },
- { element: options.firstPageButton, eventName: 'firstpage', close: true, },
+ { element: options.firstPageButton, eventName: 'firstpage',
+ close: true, },
{ element: options.lastPageButton, eventName: 'lastpage', close: true, },
{ element: options.pageRotateCwButton, eventName: 'rotatecw',
close: false, },
@@ -76,7 +77,7 @@ class SecondaryToolbar {
{ element: options.cursorHandToolButton, eventName: 'switchcursortool',
eventDetails: { tool: CursorTool.HAND, }, close: true, },
{ element: options.documentPropertiesButton,
- eventName: 'documentproperties', close: true, }
+ eventName: 'documentproperties', close: true, },
];
this.items = {
firstPage: options.firstPageButton,
```
2017-06-01 19:46:12 +09:00
|
|
|
},
|
2012-02-14 10:35:58 +09:00
|
|
|
};
|
|
|
|
})();
|
|
|
|
|
|
|
|
// Manages all the page steppers.
|
Convert `web/debugger.js` to a *basic* module
The various functionality in `web/debugger.js` is currently *indirectly* added to the global scope, since that's how `var` works when it's used outside of any functions/closures.
Given how this functionality is being accessed/used, not just in the viewer but also in the API and textLayer, simply converting the entire file to a module isn't trivial[1]. However, we can at least export the `PDFBug`-part properly and then `import` that dynamically in the viewer.
Also, to improve the code a little bit, we're now *explicitly* exporting the necessary functionality globally.
According to MDN, see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#browser_compatibility, all the browsers that we now support have dynamic `imports` implementations.
---
[1] We could probably pass around references to the necessary functionality, but given how this is being used I'm just not sure it's worth the effort. Also, adding *official* support for these viewer-specific debugging tools in the API feels both unnecessary and unfortunate.
2022-04-03 18:51:49 +09:00
|
|
|
const StepperManager = (function StepperManagerClosure() {
|
[web/debugger.js] Enable the ESLint `no-var` rule
These changes were made *mostly* automatically, using `gulp lint --fix`, with the following manual changes:
```diff
diff --git a/web/debugger.js b/web/debugger.js
index 1cda4066e..6f8b4a9f0 100644
--- a/web/debugger.js
+++ b/web/debugger.js
@@ -264,10 +264,9 @@ const Stepper = (function StepperClosure() {
}
if ("length" in args) {
// array
- let simpleArgs = [],
- i,
- ii;
- const MAX_ITEMS = 10;
+ const MAX_ITEMS = 10,
+ simpleArgs = [];
+ let i, ii;
for (i = 0, ii = Math.min(MAX_ITEMS, args.length); i < ii; i++) {
simpleArgs.push(simplifyArgs(args[i]));
}
@@ -511,11 +510,8 @@ window.PDFBug = (function PDFBugClosure() {
return {
tools: [FontInspector, StepperManager, Stats],
enable(ids) {
- let all = false,
- tools = this.tools;
- if (ids.length === 1 && ids[0] === "all") {
- all = true;
- }
+ const all = ids.length === 1 && ids[0] === "all";
+ const tools = this.tools;
for (let i = 0; i < tools.length; ++i) {
const tool = tools[i];
if (all || ids.includes(tool.id)) {
```
2021-05-04 21:37:16 +09:00
|
|
|
let steppers = [];
|
|
|
|
let stepperDiv = null;
|
|
|
|
let stepperControls = null;
|
|
|
|
let stepperChooser = null;
|
|
|
|
let breakPoints = Object.create(null);
|
2012-02-14 10:35:58 +09:00
|
|
|
return {
|
2012-08-09 03:26:24 +09:00
|
|
|
// Properties/functions needed by PDFBug.
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
id: "Stepper",
|
|
|
|
name: "Stepper",
|
2012-02-14 10:35:58 +09:00
|
|
|
panel: null,
|
|
|
|
manager: null,
|
2023-07-21 23:30:28 +09:00
|
|
|
init() {
|
[web/debugger.js] Enable the ESLint `no-var` rule
These changes were made *mostly* automatically, using `gulp lint --fix`, with the following manual changes:
```diff
diff --git a/web/debugger.js b/web/debugger.js
index 1cda4066e..6f8b4a9f0 100644
--- a/web/debugger.js
+++ b/web/debugger.js
@@ -264,10 +264,9 @@ const Stepper = (function StepperClosure() {
}
if ("length" in args) {
// array
- let simpleArgs = [],
- i,
- ii;
- const MAX_ITEMS = 10;
+ const MAX_ITEMS = 10,
+ simpleArgs = [];
+ let i, ii;
for (i = 0, ii = Math.min(MAX_ITEMS, args.length); i < ii; i++) {
simpleArgs.push(simplifyArgs(args[i]));
}
@@ -511,11 +510,8 @@ window.PDFBug = (function PDFBugClosure() {
return {
tools: [FontInspector, StepperManager, Stats],
enable(ids) {
- let all = false,
- tools = this.tools;
- if (ids.length === 1 && ids[0] === "all") {
- all = true;
- }
+ const all = ids.length === 1 && ids[0] === "all";
+ const tools = this.tools;
for (let i = 0; i < tools.length; ++i) {
const tool = tools[i];
if (all || ids.includes(tool.id)) {
```
2021-05-04 21:37:16 +09:00
|
|
|
const self = this;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
stepperControls = document.createElement("div");
|
|
|
|
stepperChooser = document.createElement("select");
|
2020-04-14 19:28:14 +09:00
|
|
|
stepperChooser.addEventListener("change", function (event) {
|
2012-02-14 10:35:58 +09:00
|
|
|
self.selectStepper(this.value);
|
|
|
|
});
|
2022-06-12 19:20:25 +09:00
|
|
|
stepperControls.append(stepperChooser);
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
stepperDiv = document.createElement("div");
|
2022-06-12 19:20:25 +09:00
|
|
|
this.panel.append(stepperControls, stepperDiv);
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (sessionStorage.getItem("pdfjsBreakPoints")) {
|
|
|
|
breakPoints = JSON.parse(sessionStorage.getItem("pdfjsBreakPoints"));
|
2014-03-09 07:42:23 +09:00
|
|
|
}
|
2012-02-14 10:35:58 +09:00
|
|
|
},
|
2022-04-02 18:53:59 +09:00
|
|
|
cleanup() {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
stepperChooser.textContent = "";
|
|
|
|
stepperDiv.textContent = "";
|
2014-03-27 05:18:53 +09:00
|
|
|
steppers = [];
|
|
|
|
},
|
2012-02-14 10:35:58 +09:00
|
|
|
enabled: false,
|
|
|
|
active: false,
|
2012-02-16 07:12:58 +09:00
|
|
|
// Stepper specific functions.
|
2022-04-02 18:53:59 +09:00
|
|
|
create(pageIndex) {
|
[web/debugger.js] Enable the ESLint `no-var` rule
These changes were made *mostly* automatically, using `gulp lint --fix`, with the following manual changes:
```diff
diff --git a/web/debugger.js b/web/debugger.js
index 1cda4066e..6f8b4a9f0 100644
--- a/web/debugger.js
+++ b/web/debugger.js
@@ -264,10 +264,9 @@ const Stepper = (function StepperClosure() {
}
if ("length" in args) {
// array
- let simpleArgs = [],
- i,
- ii;
- const MAX_ITEMS = 10;
+ const MAX_ITEMS = 10,
+ simpleArgs = [];
+ let i, ii;
for (i = 0, ii = Math.min(MAX_ITEMS, args.length); i < ii; i++) {
simpleArgs.push(simplifyArgs(args[i]));
}
@@ -511,11 +510,8 @@ window.PDFBug = (function PDFBugClosure() {
return {
tools: [FontInspector, StepperManager, Stats],
enable(ids) {
- let all = false,
- tools = this.tools;
- if (ids.length === 1 && ids[0] === "all") {
- all = true;
- }
+ const all = ids.length === 1 && ids[0] === "all";
+ const tools = this.tools;
for (let i = 0; i < tools.length; ++i) {
const tool = tools[i];
if (all || ids.includes(tool.id)) {
```
2021-05-04 21:37:16 +09:00
|
|
|
const debug = document.createElement("div");
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
debug.id = "stepper" + pageIndex;
|
2021-02-08 08:21:49 +09:00
|
|
|
debug.hidden = true;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
debug.className = "stepper";
|
2022-06-12 19:20:25 +09:00
|
|
|
stepperDiv.append(debug);
|
[web/debugger.js] Enable the ESLint `no-var` rule
These changes were made *mostly* automatically, using `gulp lint --fix`, with the following manual changes:
```diff
diff --git a/web/debugger.js b/web/debugger.js
index 1cda4066e..6f8b4a9f0 100644
--- a/web/debugger.js
+++ b/web/debugger.js
@@ -264,10 +264,9 @@ const Stepper = (function StepperClosure() {
}
if ("length" in args) {
// array
- let simpleArgs = [],
- i,
- ii;
- const MAX_ITEMS = 10;
+ const MAX_ITEMS = 10,
+ simpleArgs = [];
+ let i, ii;
for (i = 0, ii = Math.min(MAX_ITEMS, args.length); i < ii; i++) {
simpleArgs.push(simplifyArgs(args[i]));
}
@@ -511,11 +510,8 @@ window.PDFBug = (function PDFBugClosure() {
return {
tools: [FontInspector, StepperManager, Stats],
enable(ids) {
- let all = false,
- tools = this.tools;
- if (ids.length === 1 && ids[0] === "all") {
- all = true;
- }
+ const all = ids.length === 1 && ids[0] === "all";
+ const tools = this.tools;
for (let i = 0; i < tools.length; ++i) {
const tool = tools[i];
if (all || ids.includes(tool.id)) {
```
2021-05-04 21:37:16 +09:00
|
|
|
const b = document.createElement("option");
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
b.textContent = "Page " + (pageIndex + 1);
|
2012-04-13 06:02:47 +09:00
|
|
|
b.value = pageIndex;
|
2022-06-12 19:20:25 +09:00
|
|
|
stepperChooser.append(b);
|
[web/debugger.js] Enable the ESLint `no-var` rule
These changes were made *mostly* automatically, using `gulp lint --fix`, with the following manual changes:
```diff
diff --git a/web/debugger.js b/web/debugger.js
index 1cda4066e..6f8b4a9f0 100644
--- a/web/debugger.js
+++ b/web/debugger.js
@@ -264,10 +264,9 @@ const Stepper = (function StepperClosure() {
}
if ("length" in args) {
// array
- let simpleArgs = [],
- i,
- ii;
- const MAX_ITEMS = 10;
+ const MAX_ITEMS = 10,
+ simpleArgs = [];
+ let i, ii;
for (i = 0, ii = Math.min(MAX_ITEMS, args.length); i < ii; i++) {
simpleArgs.push(simplifyArgs(args[i]));
}
@@ -511,11 +510,8 @@ window.PDFBug = (function PDFBugClosure() {
return {
tools: [FontInspector, StepperManager, Stats],
enable(ids) {
- let all = false,
- tools = this.tools;
- if (ids.length === 1 && ids[0] === "all") {
- all = true;
- }
+ const all = ids.length === 1 && ids[0] === "all";
+ const tools = this.tools;
for (let i = 0; i < tools.length; ++i) {
const tool = tools[i];
if (all || ids.includes(tool.id)) {
```
2021-05-04 21:37:16 +09:00
|
|
|
const initBreakPoints = breakPoints[pageIndex] || [];
|
|
|
|
const stepper = new Stepper(debug, pageIndex, initBreakPoints);
|
2012-02-16 07:12:58 +09:00
|
|
|
steppers.push(stepper);
|
2014-03-09 07:42:23 +09:00
|
|
|
if (steppers.length === 1) {
|
2012-04-13 06:02:47 +09:00
|
|
|
this.selectStepper(pageIndex, false);
|
2014-03-09 07:42:23 +09:00
|
|
|
}
|
2012-02-16 07:12:58 +09:00
|
|
|
return stepper;
|
2012-02-14 10:35:58 +09:00
|
|
|
},
|
2022-04-02 18:53:59 +09:00
|
|
|
selectStepper(pageIndex, selectPanel) {
|
2021-07-04 18:51:11 +09:00
|
|
|
pageIndex |= 0;
|
2014-03-09 07:42:23 +09:00
|
|
|
if (selectPanel) {
|
2014-03-27 05:18:53 +09:00
|
|
|
this.manager.selectPanel(this);
|
2014-03-09 07:42:23 +09:00
|
|
|
}
|
2022-04-02 18:53:59 +09:00
|
|
|
for (const stepper of steppers) {
|
2021-02-08 08:21:49 +09:00
|
|
|
stepper.panel.hidden = stepper.pageIndex !== pageIndex;
|
2012-02-14 10:35:58 +09:00
|
|
|
}
|
2022-04-02 18:53:59 +09:00
|
|
|
for (const option of stepperChooser.options) {
|
2014-08-01 05:01:54 +09:00
|
|
|
option.selected = (option.value | 0) === pageIndex;
|
2012-02-22 06:37:22 +09:00
|
|
|
}
|
2012-02-14 10:35:58 +09:00
|
|
|
},
|
2022-04-02 18:53:59 +09:00
|
|
|
saveBreakPoints(pageIndex, bps) {
|
2012-04-13 06:02:47 +09:00
|
|
|
breakPoints[pageIndex] = bps;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
sessionStorage.setItem("pdfjsBreakPoints", JSON.stringify(breakPoints));
|
Fix inconsistent spacing and trailing commas in objects in `web/` files, so we can enable the `comma-dangle` and `object-curly-spacing` ESLint rules later on
http://eslint.org/docs/rules/comma-dangle
http://eslint.org/docs/rules/object-curly-spacing
Given that we currently have quite inconsistent object formatting, fixing this in in *one* big patch probably wouldn't be feasible (since I cannot imagine anyone wanting to review that); hence I've opted to try and do this piecewise instead.
*Please note:* This patch was created automatically, using the ESLint `--fix` command line option. In a couple of places this caused lines to become too long, and I've fixed those manually; please refer to the interdiff below for the only hand-edits in this patch.
```diff
diff --git a/web/pdf_thumbnail_view.js b/web/pdf_thumbnail_view.js
index 002dbf29..1de4e530 100644
--- a/web/pdf_thumbnail_view.js
+++ b/web/pdf_thumbnail_view.js
@@ -420,8 +420,8 @@ var PDFThumbnailView = (function PDFThumbnailViewClosure() {
setPageLabel: function PDFThumbnailView_setPageLabel(label) {
this.pageLabel = (typeof label === 'string' ? label : null);
- this.l10n.get('thumb_page_title', { page: this.pageId, }, 'Page {{page}}').
- then((msg) => {
+ this.l10n.get('thumb_page_title', { page: this.pageId, },
+ 'Page {{page}}').then((msg) => {
this.anchor.title = msg;
});
diff --git a/web/secondary_toolbar.js b/web/secondary_toolbar.js
index 160e0410..6495fc5e 100644
--- a/web/secondary_toolbar.js
+++ b/web/secondary_toolbar.js
@@ -65,7 +65,8 @@ class SecondaryToolbar {
{ element: options.printButton, eventName: 'print', close: true, },
{ element: options.downloadButton, eventName: 'download', close: true, },
{ element: options.viewBookmarkButton, eventName: null, close: true, },
- { element: options.firstPageButton, eventName: 'firstpage', close: true, },
+ { element: options.firstPageButton, eventName: 'firstpage',
+ close: true, },
{ element: options.lastPageButton, eventName: 'lastpage', close: true, },
{ element: options.pageRotateCwButton, eventName: 'rotatecw',
close: false, },
@@ -76,7 +77,7 @@ class SecondaryToolbar {
{ element: options.cursorHandToolButton, eventName: 'switchcursortool',
eventDetails: { tool: CursorTool.HAND, }, close: true, },
{ element: options.documentPropertiesButton,
- eventName: 'documentproperties', close: true, }
+ eventName: 'documentproperties', close: true, },
];
this.items = {
firstPage: options.firstPageButton,
```
2017-06-01 19:46:12 +09:00
|
|
|
},
|
2012-02-14 10:35:58 +09:00
|
|
|
};
|
|
|
|
})();
|
|
|
|
|
2021-05-04 21:29:05 +09:00
|
|
|
// The stepper for each page's operatorList.
|
2023-09-17 15:06:26 +09:00
|
|
|
class Stepper {
|
2013-08-01 03:17:36 +09:00
|
|
|
// Shorter way to create element and optionally set textContent.
|
2023-09-17 15:06:26 +09:00
|
|
|
#c(tag, textContent) {
|
[web/debugger.js] Enable the ESLint `no-var` rule
These changes were made *mostly* automatically, using `gulp lint --fix`, with the following manual changes:
```diff
diff --git a/web/debugger.js b/web/debugger.js
index 1cda4066e..6f8b4a9f0 100644
--- a/web/debugger.js
+++ b/web/debugger.js
@@ -264,10 +264,9 @@ const Stepper = (function StepperClosure() {
}
if ("length" in args) {
// array
- let simpleArgs = [],
- i,
- ii;
- const MAX_ITEMS = 10;
+ const MAX_ITEMS = 10,
+ simpleArgs = [];
+ let i, ii;
for (i = 0, ii = Math.min(MAX_ITEMS, args.length); i < ii; i++) {
simpleArgs.push(simplifyArgs(args[i]));
}
@@ -511,11 +510,8 @@ window.PDFBug = (function PDFBugClosure() {
return {
tools: [FontInspector, StepperManager, Stats],
enable(ids) {
- let all = false,
- tools = this.tools;
- if (ids.length === 1 && ids[0] === "all") {
- all = true;
- }
+ const all = ids.length === 1 && ids[0] === "all";
+ const tools = this.tools;
for (let i = 0; i < tools.length; ++i) {
const tool = tools[i];
if (all || ids.includes(tool.id)) {
```
2021-05-04 21:37:16 +09:00
|
|
|
const d = document.createElement(tag);
|
2014-03-09 07:42:23 +09:00
|
|
|
if (textContent) {
|
2013-08-01 03:17:36 +09:00
|
|
|
d.textContent = textContent;
|
2014-03-09 07:42:23 +09:00
|
|
|
}
|
2013-08-01 03:17:36 +09:00
|
|
|
return d;
|
|
|
|
}
|
|
|
|
|
2023-09-17 15:06:26 +09:00
|
|
|
#simplifyArgs(args) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (typeof args === "string") {
|
[web/debugger.js] Enable the ESLint `no-var` rule
These changes were made *mostly* automatically, using `gulp lint --fix`, with the following manual changes:
```diff
diff --git a/web/debugger.js b/web/debugger.js
index 1cda4066e..6f8b4a9f0 100644
--- a/web/debugger.js
+++ b/web/debugger.js
@@ -264,10 +264,9 @@ const Stepper = (function StepperClosure() {
}
if ("length" in args) {
// array
- let simpleArgs = [],
- i,
- ii;
- const MAX_ITEMS = 10;
+ const MAX_ITEMS = 10,
+ simpleArgs = [];
+ let i, ii;
for (i = 0, ii = Math.min(MAX_ITEMS, args.length); i < ii; i++) {
simpleArgs.push(simplifyArgs(args[i]));
}
@@ -511,11 +510,8 @@ window.PDFBug = (function PDFBugClosure() {
return {
tools: [FontInspector, StepperManager, Stats],
enable(ids) {
- let all = false,
- tools = this.tools;
- if (ids.length === 1 && ids[0] === "all") {
- all = true;
- }
+ const all = ids.length === 1 && ids[0] === "all";
+ const tools = this.tools;
for (let i = 0; i < tools.length; ++i) {
const tool = tools[i];
if (all || ids.includes(tool.id)) {
```
2021-05-04 21:37:16 +09:00
|
|
|
const MAX_STRING_LENGTH = 75;
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
return args.length <= MAX_STRING_LENGTH
|
|
|
|
? args
|
|
|
|
: args.substring(0, MAX_STRING_LENGTH) + "...";
|
2014-03-27 05:18:53 +09:00
|
|
|
}
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if (typeof args !== "object" || args === null) {
|
2014-03-27 05:18:53 +09:00
|
|
|
return args;
|
|
|
|
}
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
if ("length" in args) {
|
|
|
|
// array
|
[web/debugger.js] Enable the ESLint `no-var` rule
These changes were made *mostly* automatically, using `gulp lint --fix`, with the following manual changes:
```diff
diff --git a/web/debugger.js b/web/debugger.js
index 1cda4066e..6f8b4a9f0 100644
--- a/web/debugger.js
+++ b/web/debugger.js
@@ -264,10 +264,9 @@ const Stepper = (function StepperClosure() {
}
if ("length" in args) {
// array
- let simpleArgs = [],
- i,
- ii;
- const MAX_ITEMS = 10;
+ const MAX_ITEMS = 10,
+ simpleArgs = [];
+ let i, ii;
for (i = 0, ii = Math.min(MAX_ITEMS, args.length); i < ii; i++) {
simpleArgs.push(simplifyArgs(args[i]));
}
@@ -511,11 +510,8 @@ window.PDFBug = (function PDFBugClosure() {
return {
tools: [FontInspector, StepperManager, Stats],
enable(ids) {
- let all = false,
- tools = this.tools;
- if (ids.length === 1 && ids[0] === "all") {
- all = true;
- }
+ const all = ids.length === 1 && ids[0] === "all";
+ const tools = this.tools;
for (let i = 0; i < tools.length; ++i) {
const tool = tools[i];
if (all || ids.includes(tool.id)) {
```
2021-05-04 21:37:16 +09:00
|
|
|
const MAX_ITEMS = 10,
|
|
|
|
simpleArgs = [];
|
|
|
|
let i, ii;
|
2014-03-27 05:18:53 +09:00
|
|
|
for (i = 0, ii = Math.min(MAX_ITEMS, args.length); i < ii; i++) {
|
2023-09-17 15:06:26 +09:00
|
|
|
simpleArgs.push(this.#simplifyArgs(args[i]));
|
2014-03-27 05:18:53 +09:00
|
|
|
}
|
|
|
|
if (i < args.length) {
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
simpleArgs.push("...");
|
2014-03-27 05:18:53 +09:00
|
|
|
}
|
|
|
|
return simpleArgs;
|
|
|
|
}
|
[web/debugger.js] Enable the ESLint `no-var` rule
These changes were made *mostly* automatically, using `gulp lint --fix`, with the following manual changes:
```diff
diff --git a/web/debugger.js b/web/debugger.js
index 1cda4066e..6f8b4a9f0 100644
--- a/web/debugger.js
+++ b/web/debugger.js
@@ -264,10 +264,9 @@ const Stepper = (function StepperClosure() {
}
if ("length" in args) {
// array
- let simpleArgs = [],
- i,
- ii;
- const MAX_ITEMS = 10;
+ const MAX_ITEMS = 10,
+ simpleArgs = [];
+ let i, ii;
for (i = 0, ii = Math.min(MAX_ITEMS, args.length); i < ii; i++) {
simpleArgs.push(simplifyArgs(args[i]));
}
@@ -511,11 +510,8 @@ window.PDFBug = (function PDFBugClosure() {
return {
tools: [FontInspector, StepperManager, Stats],
enable(ids) {
- let all = false,
- tools = this.tools;
- if (ids.length === 1 && ids[0] === "all") {
- all = true;
- }
+ const all = ids.length === 1 && ids[0] === "all";
+ const tools = this.tools;
for (let i = 0; i < tools.length; ++i) {
const tool = tools[i];
if (all || ids.includes(tool.id)) {
```
2021-05-04 21:37:16 +09:00
|
|
|
const simpleObj = {};
|
|
|
|
for (const key in args) {
|
2023-09-17 15:06:26 +09:00
|
|
|
simpleObj[key] = this.#simplifyArgs(args[key]);
|
2014-03-27 05:18:53 +09:00
|
|
|
}
|
|
|
|
return simpleObj;
|
|
|
|
}
|
|
|
|
|
2023-09-17 15:06:26 +09:00
|
|
|
constructor(panel, pageIndex, initialBreakPoints) {
|
|
|
|
this.panel = panel;
|
|
|
|
this.breakPoint = 0;
|
|
|
|
this.nextBreakPoint = null;
|
|
|
|
this.pageIndex = pageIndex;
|
|
|
|
this.breakPoints = initialBreakPoints;
|
|
|
|
this.currentIdx = -1;
|
|
|
|
this.operatorListIdx = 0;
|
|
|
|
this.indentLevel = 0;
|
|
|
|
}
|
2021-05-04 21:29:05 +09:00
|
|
|
|
2023-09-17 15:06:26 +09:00
|
|
|
init(operatorList) {
|
|
|
|
const panel = this.panel;
|
|
|
|
const content = this.#c("div", "c=continue, s=step");
|
|
|
|
const table = this.#c("table");
|
|
|
|
content.append(table);
|
|
|
|
table.cellSpacing = 0;
|
|
|
|
const headerRow = this.#c("tr");
|
|
|
|
table.append(headerRow);
|
|
|
|
headerRow.append(
|
|
|
|
this.#c("th", "Break"),
|
|
|
|
this.#c("th", "Idx"),
|
|
|
|
this.#c("th", "fn"),
|
|
|
|
this.#c("th", "args")
|
|
|
|
);
|
|
|
|
panel.append(content);
|
|
|
|
this.table = table;
|
|
|
|
this.updateOperatorList(operatorList);
|
|
|
|
}
|
2021-05-04 21:29:05 +09:00
|
|
|
|
2023-09-17 15:06:26 +09:00
|
|
|
updateOperatorList(operatorList) {
|
|
|
|
const self = this;
|
2014-04-20 08:05:38 +09:00
|
|
|
|
2023-09-17 15:06:26 +09:00
|
|
|
function cboxOnClick() {
|
|
|
|
const x = +this.dataset.idx;
|
|
|
|
if (this.checked) {
|
|
|
|
self.breakPoints.push(x);
|
|
|
|
} else {
|
|
|
|
self.breakPoints.splice(self.breakPoints.indexOf(x), 1);
|
2014-03-27 05:18:53 +09:00
|
|
|
}
|
2023-09-17 15:06:26 +09:00
|
|
|
StepperManager.saveBreakPoints(self.pageIndex, self.breakPoints);
|
|
|
|
}
|
2014-03-27 05:18:53 +09:00
|
|
|
|
2023-09-17 15:06:26 +09:00
|
|
|
const MAX_OPERATORS_COUNT = 15000;
|
|
|
|
if (this.operatorListIdx > MAX_OPERATORS_COUNT) {
|
|
|
|
return;
|
|
|
|
}
|
2014-03-27 05:18:53 +09:00
|
|
|
|
2023-09-17 15:06:26 +09:00
|
|
|
const chunk = document.createDocumentFragment();
|
|
|
|
const operatorsToDisplay = Math.min(
|
|
|
|
MAX_OPERATORS_COUNT,
|
|
|
|
operatorList.fnArray.length
|
|
|
|
);
|
|
|
|
for (let i = this.operatorListIdx; i < operatorsToDisplay; i++) {
|
|
|
|
const line = this.#c("tr");
|
|
|
|
line.className = "line";
|
|
|
|
line.dataset.idx = i;
|
|
|
|
chunk.append(line);
|
|
|
|
const checked = this.breakPoints.includes(i);
|
|
|
|
const args = operatorList.argsArray[i] || [];
|
2012-02-14 10:35:58 +09:00
|
|
|
|
2023-09-17 15:06:26 +09:00
|
|
|
const breakCell = this.#c("td");
|
|
|
|
const cbox = this.#c("input");
|
|
|
|
cbox.type = "checkbox";
|
|
|
|
cbox.className = "points";
|
|
|
|
cbox.checked = checked;
|
|
|
|
cbox.dataset.idx = i;
|
|
|
|
cbox.onclick = cboxOnClick;
|
2012-02-14 10:35:58 +09:00
|
|
|
|
2023-09-17 15:06:26 +09:00
|
|
|
breakCell.append(cbox);
|
|
|
|
line.append(breakCell, this.#c("td", i.toString()));
|
|
|
|
const fn = opMap[operatorList.fnArray[i]];
|
|
|
|
let decArgs = args;
|
|
|
|
if (fn === "showText") {
|
|
|
|
const glyphs = args[0];
|
|
|
|
const charCodeRow = this.#c("tr");
|
|
|
|
const fontCharRow = this.#c("tr");
|
|
|
|
const unicodeRow = this.#c("tr");
|
|
|
|
for (const glyph of glyphs) {
|
|
|
|
if (typeof glyph === "object" && glyph !== null) {
|
|
|
|
charCodeRow.append(this.#c("td", glyph.originalCharCode));
|
|
|
|
fontCharRow.append(this.#c("td", glyph.fontChar));
|
|
|
|
unicodeRow.append(this.#c("td", glyph.unicode));
|
|
|
|
} else {
|
|
|
|
// null or number
|
|
|
|
const advanceEl = this.#c("td", glyph);
|
|
|
|
advanceEl.classList.add("advance");
|
|
|
|
charCodeRow.append(advanceEl);
|
|
|
|
fontCharRow.append(this.#c("td"));
|
|
|
|
unicodeRow.append(this.#c("td"));
|
2013-08-15 07:34:55 +09:00
|
|
|
}
|
2021-06-05 01:48:30 +09:00
|
|
|
}
|
2023-09-17 15:06:26 +09:00
|
|
|
decArgs = this.#c("td");
|
|
|
|
const table = this.#c("table");
|
|
|
|
table.classList.add("showText");
|
|
|
|
decArgs.append(table);
|
|
|
|
table.append(charCodeRow, fontCharRow, unicodeRow);
|
|
|
|
} else if (fn === "restore" && this.indentLevel > 0) {
|
|
|
|
this.indentLevel--;
|
2014-03-27 05:18:53 +09:00
|
|
|
}
|
2023-09-17 15:06:26 +09:00
|
|
|
line.append(this.#c("td", " ".repeat(this.indentLevel * 2) + fn));
|
|
|
|
if (fn === "save") {
|
|
|
|
this.indentLevel++;
|
2012-02-14 10:35:58 +09:00
|
|
|
}
|
2023-09-17 15:06:26 +09:00
|
|
|
|
|
|
|
if (decArgs instanceof HTMLElement) {
|
|
|
|
line.append(decArgs);
|
|
|
|
} else {
|
|
|
|
line.append(this.#c("td", JSON.stringify(this.#simplifyArgs(decArgs))));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (operatorsToDisplay < operatorList.fnArray.length) {
|
|
|
|
const lastCell = this.#c("td", "...");
|
|
|
|
lastCell.colspan = 4;
|
|
|
|
chunk.append(lastCell);
|
2021-05-04 21:29:05 +09:00
|
|
|
}
|
2023-09-17 15:06:26 +09:00
|
|
|
this.operatorListIdx = operatorList.fnArray.length;
|
|
|
|
this.table.append(chunk);
|
|
|
|
}
|
2021-05-04 21:29:05 +09:00
|
|
|
|
2023-09-17 15:06:26 +09:00
|
|
|
getNextBreakPoint() {
|
|
|
|
this.breakPoints.sort(function (a, b) {
|
|
|
|
return a - b;
|
|
|
|
});
|
|
|
|
for (const breakPoint of this.breakPoints) {
|
|
|
|
if (breakPoint > this.currentIdx) {
|
|
|
|
return breakPoint;
|
2012-02-14 10:35:58 +09:00
|
|
|
}
|
2021-05-04 21:29:05 +09:00
|
|
|
}
|
2023-09-17 15:06:26 +09:00
|
|
|
return null;
|
|
|
|
}
|
2021-05-04 21:29:05 +09:00
|
|
|
|
2023-09-17 15:06:26 +09:00
|
|
|
breakIt(idx, callback) {
|
|
|
|
StepperManager.selectStepper(this.pageIndex, true);
|
|
|
|
this.currentIdx = idx;
|
2021-05-04 21:29:05 +09:00
|
|
|
|
2023-09-17 15:06:26 +09:00
|
|
|
const listener = evt => {
|
|
|
|
switch (evt.keyCode) {
|
|
|
|
case 83: // step
|
|
|
|
document.removeEventListener("keydown", listener);
|
|
|
|
this.nextBreakPoint = this.currentIdx + 1;
|
|
|
|
this.goTo(-1);
|
|
|
|
callback();
|
|
|
|
break;
|
|
|
|
case 67: // continue
|
|
|
|
document.removeEventListener("keydown", listener);
|
|
|
|
this.nextBreakPoint = this.getNextBreakPoint();
|
|
|
|
this.goTo(-1);
|
|
|
|
callback();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
document.addEventListener("keydown", listener);
|
|
|
|
this.goTo(idx);
|
|
|
|
}
|
2021-05-04 21:29:05 +09:00
|
|
|
|
2023-09-17 15:06:26 +09:00
|
|
|
goTo(idx) {
|
|
|
|
const allRows = this.panel.getElementsByClassName("line");
|
|
|
|
for (const row of allRows) {
|
|
|
|
if ((row.dataset.idx | 0) === idx) {
|
|
|
|
row.style.backgroundColor = "rgb(251,250,207)";
|
|
|
|
row.scrollIntoView();
|
|
|
|
} else {
|
|
|
|
row.style.backgroundColor = null;
|
2012-02-14 10:35:58 +09:00
|
|
|
}
|
2021-05-04 21:29:05 +09:00
|
|
|
}
|
|
|
|
}
|
2023-09-17 15:06:26 +09:00
|
|
|
}
|
2012-02-14 10:35:58 +09:00
|
|
|
|
Convert `web/debugger.js` to a *basic* module
The various functionality in `web/debugger.js` is currently *indirectly* added to the global scope, since that's how `var` works when it's used outside of any functions/closures.
Given how this functionality is being accessed/used, not just in the viewer but also in the API and textLayer, simply converting the entire file to a module isn't trivial[1]. However, we can at least export the `PDFBug`-part properly and then `import` that dynamically in the viewer.
Also, to improve the code a little bit, we're now *explicitly* exporting the necessary functionality globally.
According to MDN, see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#browser_compatibility, all the browsers that we now support have dynamic `imports` implementations.
---
[1] We could probably pass around references to the necessary functionality, but given how this is being used I'm just not sure it's worth the effort. Also, adding *official* support for these viewer-specific debugging tools in the API feels both unnecessary and unfortunate.
2022-04-03 18:51:49 +09:00
|
|
|
const Stats = (function Stats() {
|
[web/debugger.js] Enable the ESLint `no-var` rule
These changes were made *mostly* automatically, using `gulp lint --fix`, with the following manual changes:
```diff
diff --git a/web/debugger.js b/web/debugger.js
index 1cda4066e..6f8b4a9f0 100644
--- a/web/debugger.js
+++ b/web/debugger.js
@@ -264,10 +264,9 @@ const Stepper = (function StepperClosure() {
}
if ("length" in args) {
// array
- let simpleArgs = [],
- i,
- ii;
- const MAX_ITEMS = 10;
+ const MAX_ITEMS = 10,
+ simpleArgs = [];
+ let i, ii;
for (i = 0, ii = Math.min(MAX_ITEMS, args.length); i < ii; i++) {
simpleArgs.push(simplifyArgs(args[i]));
}
@@ -511,11 +510,8 @@ window.PDFBug = (function PDFBugClosure() {
return {
tools: [FontInspector, StepperManager, Stats],
enable(ids) {
- let all = false,
- tools = this.tools;
- if (ids.length === 1 && ids[0] === "all") {
- all = true;
- }
+ const all = ids.length === 1 && ids[0] === "all";
+ const tools = this.tools;
for (let i = 0; i < tools.length; ++i) {
const tool = tools[i];
if (all || ids.includes(tool.id)) {
```
2021-05-04 21:37:16 +09:00
|
|
|
let stats = [];
|
2012-02-22 02:52:09 +09:00
|
|
|
function clear(node) {
|
2021-11-16 20:36:22 +09:00
|
|
|
node.textContent = ""; // Remove any `node` contents from the DOM.
|
2012-02-22 02:52:09 +09:00
|
|
|
}
|
|
|
|
function getStatIndex(pageNumber) {
|
2022-04-02 18:53:59 +09:00
|
|
|
for (const [i, stat] of stats.entries()) {
|
|
|
|
if (stat.pageNumber === pageNumber) {
|
2012-02-22 02:52:09 +09:00
|
|
|
return i;
|
2014-03-09 07:42:23 +09:00
|
|
|
}
|
|
|
|
}
|
2012-02-22 02:52:09 +09:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return {
|
2012-08-09 03:26:24 +09:00
|
|
|
// Properties/functions needed by PDFBug.
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
id: "Stats",
|
|
|
|
name: "Stats",
|
2012-02-22 02:52:09 +09:00
|
|
|
panel: null,
|
|
|
|
manager: null,
|
2023-07-21 23:30:28 +09:00
|
|
|
init() {},
|
2012-02-22 02:52:09 +09:00
|
|
|
enabled: false,
|
|
|
|
active: false,
|
|
|
|
// Stats specific functions.
|
2017-04-28 19:02:42 +09:00
|
|
|
add(pageNumber, stat) {
|
2014-03-09 07:42:23 +09:00
|
|
|
if (!stat) {
|
2012-02-22 02:52:09 +09:00
|
|
|
return;
|
2014-03-09 07:42:23 +09:00
|
|
|
}
|
[web/debugger.js] Enable the ESLint `no-var` rule
These changes were made *mostly* automatically, using `gulp lint --fix`, with the following manual changes:
```diff
diff --git a/web/debugger.js b/web/debugger.js
index 1cda4066e..6f8b4a9f0 100644
--- a/web/debugger.js
+++ b/web/debugger.js
@@ -264,10 +264,9 @@ const Stepper = (function StepperClosure() {
}
if ("length" in args) {
// array
- let simpleArgs = [],
- i,
- ii;
- const MAX_ITEMS = 10;
+ const MAX_ITEMS = 10,
+ simpleArgs = [];
+ let i, ii;
for (i = 0, ii = Math.min(MAX_ITEMS, args.length); i < ii; i++) {
simpleArgs.push(simplifyArgs(args[i]));
}
@@ -511,11 +510,8 @@ window.PDFBug = (function PDFBugClosure() {
return {
tools: [FontInspector, StepperManager, Stats],
enable(ids) {
- let all = false,
- tools = this.tools;
- if (ids.length === 1 && ids[0] === "all") {
- all = true;
- }
+ const all = ids.length === 1 && ids[0] === "all";
+ const tools = this.tools;
for (let i = 0; i < tools.length; ++i) {
const tool = tools[i];
if (all || ids.includes(tool.id)) {
```
2021-05-04 21:37:16 +09:00
|
|
|
const statsIndex = getStatIndex(pageNumber);
|
2012-02-22 02:52:09 +09:00
|
|
|
if (statsIndex !== false) {
|
2021-11-16 20:36:22 +09:00
|
|
|
stats[statsIndex].div.remove();
|
2012-02-22 02:52:09 +09:00
|
|
|
stats.splice(statsIndex, 1);
|
|
|
|
}
|
[web/debugger.js] Enable the ESLint `no-var` rule
These changes were made *mostly* automatically, using `gulp lint --fix`, with the following manual changes:
```diff
diff --git a/web/debugger.js b/web/debugger.js
index 1cda4066e..6f8b4a9f0 100644
--- a/web/debugger.js
+++ b/web/debugger.js
@@ -264,10 +264,9 @@ const Stepper = (function StepperClosure() {
}
if ("length" in args) {
// array
- let simpleArgs = [],
- i,
- ii;
- const MAX_ITEMS = 10;
+ const MAX_ITEMS = 10,
+ simpleArgs = [];
+ let i, ii;
for (i = 0, ii = Math.min(MAX_ITEMS, args.length); i < ii; i++) {
simpleArgs.push(simplifyArgs(args[i]));
}
@@ -511,11 +510,8 @@ window.PDFBug = (function PDFBugClosure() {
return {
tools: [FontInspector, StepperManager, Stats],
enable(ids) {
- let all = false,
- tools = this.tools;
- if (ids.length === 1 && ids[0] === "all") {
- all = true;
- }
+ const all = ids.length === 1 && ids[0] === "all";
+ const tools = this.tools;
for (let i = 0; i < tools.length; ++i) {
const tool = tools[i];
if (all || ids.includes(tool.id)) {
```
2021-05-04 21:37:16 +09:00
|
|
|
const wrapper = document.createElement("div");
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
wrapper.className = "stats";
|
[web/debugger.js] Enable the ESLint `no-var` rule
These changes were made *mostly* automatically, using `gulp lint --fix`, with the following manual changes:
```diff
diff --git a/web/debugger.js b/web/debugger.js
index 1cda4066e..6f8b4a9f0 100644
--- a/web/debugger.js
+++ b/web/debugger.js
@@ -264,10 +264,9 @@ const Stepper = (function StepperClosure() {
}
if ("length" in args) {
// array
- let simpleArgs = [],
- i,
- ii;
- const MAX_ITEMS = 10;
+ const MAX_ITEMS = 10,
+ simpleArgs = [];
+ let i, ii;
for (i = 0, ii = Math.min(MAX_ITEMS, args.length); i < ii; i++) {
simpleArgs.push(simplifyArgs(args[i]));
}
@@ -511,11 +510,8 @@ window.PDFBug = (function PDFBugClosure() {
return {
tools: [FontInspector, StepperManager, Stats],
enable(ids) {
- let all = false,
- tools = this.tools;
- if (ids.length === 1 && ids[0] === "all") {
- all = true;
- }
+ const all = ids.length === 1 && ids[0] === "all";
+ const tools = this.tools;
for (let i = 0; i < tools.length; ++i) {
const tool = tools[i];
if (all || ids.includes(tool.id)) {
```
2021-05-04 21:37:16 +09:00
|
|
|
const title = document.createElement("div");
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
title.className = "title";
|
|
|
|
title.textContent = "Page: " + pageNumber;
|
[web/debugger.js] Enable the ESLint `no-var` rule
These changes were made *mostly* automatically, using `gulp lint --fix`, with the following manual changes:
```diff
diff --git a/web/debugger.js b/web/debugger.js
index 1cda4066e..6f8b4a9f0 100644
--- a/web/debugger.js
+++ b/web/debugger.js
@@ -264,10 +264,9 @@ const Stepper = (function StepperClosure() {
}
if ("length" in args) {
// array
- let simpleArgs = [],
- i,
- ii;
- const MAX_ITEMS = 10;
+ const MAX_ITEMS = 10,
+ simpleArgs = [];
+ let i, ii;
for (i = 0, ii = Math.min(MAX_ITEMS, args.length); i < ii; i++) {
simpleArgs.push(simplifyArgs(args[i]));
}
@@ -511,11 +510,8 @@ window.PDFBug = (function PDFBugClosure() {
return {
tools: [FontInspector, StepperManager, Stats],
enable(ids) {
- let all = false,
- tools = this.tools;
- if (ids.length === 1 && ids[0] === "all") {
- all = true;
- }
+ const all = ids.length === 1 && ids[0] === "all";
+ const tools = this.tools;
for (let i = 0; i < tools.length; ++i) {
const tool = tools[i];
if (all || ids.includes(tool.id)) {
```
2021-05-04 21:37:16 +09:00
|
|
|
const statsDiv = document.createElement("div");
|
2012-02-22 02:52:09 +09:00
|
|
|
statsDiv.textContent = stat.toString();
|
2022-06-12 19:20:25 +09:00
|
|
|
wrapper.append(title, statsDiv);
|
Enable auto-formatting of the entire code-base using Prettier (issue 11444)
Note that Prettier, purposely, has only limited [configuration options](https://prettier.io/docs/en/options.html). The configuration file is based on [the one in `mozilla central`](https://searchfox.org/mozilla-central/source/.prettierrc) with just a few additions (to avoid future breakage if the defaults ever changes).
Prettier is being used for a couple of reasons:
- To be consistent with `mozilla-central`, where Prettier is already in use across the tree.
- To ensure a *consistent* coding style everywhere, which is automatically enforced during linting (since Prettier is used as an ESLint plugin). This thus ends "all" formatting disussions once and for all, removing the need for review comments on most stylistic matters.
Many ESLint options are now redundant, and I've tried my best to remove all the now unnecessary options (but I may have missed some).
Note also that since Prettier considers the `printWidth` option as a guide, rather than a hard rule, this patch resorts to a small hack in the ESLint config to ensure that *comments* won't become too long.
*Please note:* This patch is generated automatically, by appending the `--fix` argument to the ESLint call used in the `gulp lint` task. It will thus require some additional clean-up, which will be done in a *separate* commit.
(On a more personal note, I'll readily admit that some of the changes Prettier makes are *extremely* ugly. However, in the name of consistency we'll probably have to live with that.)
2019-12-25 23:59:37 +09:00
|
|
|
stats.push({ pageNumber, div: wrapper });
|
2020-04-14 19:28:14 +09:00
|
|
|
stats.sort(function (a, b) {
|
2017-02-03 20:58:08 +09:00
|
|
|
return a.pageNumber - b.pageNumber;
|
|
|
|
});
|
2012-02-22 02:52:09 +09:00
|
|
|
clear(this.panel);
|
2022-04-02 18:53:59 +09:00
|
|
|
for (const entry of stats) {
|
2022-06-12 19:20:25 +09:00
|
|
|
this.panel.append(entry.div);
|
2014-03-09 07:42:23 +09:00
|
|
|
}
|
2014-03-27 05:18:53 +09:00
|
|
|
},
|
2017-04-28 19:02:42 +09:00
|
|
|
cleanup() {
|
2014-03-27 05:18:53 +09:00
|
|
|
stats = [];
|
|
|
|
clear(this.panel);
|
Fix inconsistent spacing and trailing commas in objects in `web/` files, so we can enable the `comma-dangle` and `object-curly-spacing` ESLint rules later on
http://eslint.org/docs/rules/comma-dangle
http://eslint.org/docs/rules/object-curly-spacing
Given that we currently have quite inconsistent object formatting, fixing this in in *one* big patch probably wouldn't be feasible (since I cannot imagine anyone wanting to review that); hence I've opted to try and do this piecewise instead.
*Please note:* This patch was created automatically, using the ESLint `--fix` command line option. In a couple of places this caused lines to become too long, and I've fixed those manually; please refer to the interdiff below for the only hand-edits in this patch.
```diff
diff --git a/web/pdf_thumbnail_view.js b/web/pdf_thumbnail_view.js
index 002dbf29..1de4e530 100644
--- a/web/pdf_thumbnail_view.js
+++ b/web/pdf_thumbnail_view.js
@@ -420,8 +420,8 @@ var PDFThumbnailView = (function PDFThumbnailViewClosure() {
setPageLabel: function PDFThumbnailView_setPageLabel(label) {
this.pageLabel = (typeof label === 'string' ? label : null);
- this.l10n.get('thumb_page_title', { page: this.pageId, }, 'Page {{page}}').
- then((msg) => {
+ this.l10n.get('thumb_page_title', { page: this.pageId, },
+ 'Page {{page}}').then((msg) => {
this.anchor.title = msg;
});
diff --git a/web/secondary_toolbar.js b/web/secondary_toolbar.js
index 160e0410..6495fc5e 100644
--- a/web/secondary_toolbar.js
+++ b/web/secondary_toolbar.js
@@ -65,7 +65,8 @@ class SecondaryToolbar {
{ element: options.printButton, eventName: 'print', close: true, },
{ element: options.downloadButton, eventName: 'download', close: true, },
{ element: options.viewBookmarkButton, eventName: null, close: true, },
- { element: options.firstPageButton, eventName: 'firstpage', close: true, },
+ { element: options.firstPageButton, eventName: 'firstpage',
+ close: true, },
{ element: options.lastPageButton, eventName: 'lastpage', close: true, },
{ element: options.pageRotateCwButton, eventName: 'rotatecw',
close: false, },
@@ -76,7 +77,7 @@ class SecondaryToolbar {
{ element: options.cursorHandToolButton, eventName: 'switchcursortool',
eventDetails: { tool: CursorTool.HAND, }, close: true, },
{ element: options.documentPropertiesButton,
- eventName: 'documentproperties', close: true, }
+ eventName: 'documentproperties', close: true, },
];
this.items = {
firstPage: options.firstPageButton,
```
2017-06-01 19:46:12 +09:00
|
|
|
},
|
2012-02-22 02:52:09 +09:00
|
|
|
};
|
|
|
|
})();
|
|
|
|
|
2012-02-14 10:35:58 +09:00
|
|
|
// Manages all the debugging tools.
|
2023-09-17 15:06:43 +09:00
|
|
|
class PDFBug {
|
|
|
|
static #buttons = [];
|
2012-02-14 10:35:58 +09:00
|
|
|
|
2023-09-17 15:06:43 +09:00
|
|
|
static #activePanel = null;
|
Move the `PDFBug`-related CSS from `viewer.css` and into its own file
Given that none of these CSS rules are used at all, unless debugging is enabled, it seems completely unnecessary to load them *unconditionally* for all users.[1]
Note that if *both* the `textLayer` and `pdfBug` debugging hash-parameters are specified simultaneously, we'll now load the `PDFBug`-file *twice* (since the code is simpler that way). However, given first of all that none of this is enabled by default and secondly that using those parameters together isn't helpful[2], potentially loading that file twice is hopefully not an issue.
For the `gulp mozcentral` target, the size of the *built* `viewer.css` file is reduced `> 3%` with this patch.
---
[1] For the Firefox built-in PDF Viewer, in order to even be able to access the `PDFBug` functionality, you need to first of all set `pdfjs.pdfBugEnabled = true` manually in `about:config`. Secondly, you then also need to append the `pdfBug=...` hash-parameter to the URL when *initially* loading the document.
[2] Note how the `textLayer`-settings are already, since essentially forever, overriding the highlighting-features of the "FontInspector"-tab.
2022-04-06 01:14:17 +09:00
|
|
|
|
2023-09-17 15:06:43 +09:00
|
|
|
static tools = [FontInspector, StepperManager, Stats];
|
Move the `PDFBug`-related CSS from `viewer.css` and into its own file
Given that none of these CSS rules are used at all, unless debugging is enabled, it seems completely unnecessary to load them *unconditionally* for all users.[1]
Note that if *both* the `textLayer` and `pdfBug` debugging hash-parameters are specified simultaneously, we'll now load the `PDFBug`-file *twice* (since the code is simpler that way). However, given first of all that none of this is enabled by default and secondly that using those parameters together isn't helpful[2], potentially loading that file twice is hopefully not an issue.
For the `gulp mozcentral` target, the size of the *built* `viewer.css` file is reduced `> 3%` with this patch.
---
[1] For the Firefox built-in PDF Viewer, in order to even be able to access the `PDFBug` functionality, you need to first of all set `pdfjs.pdfBugEnabled = true` manually in `about:config`. Secondly, you then also need to append the `pdfBug=...` hash-parameter to the URL when *initially* loading the document.
[2] Note how the `textLayer`-settings are already, since essentially forever, overriding the highlighting-features of the "FontInspector"-tab.
2022-04-06 01:14:17 +09:00
|
|
|
|
2023-09-17 15:06:43 +09:00
|
|
|
static enable(ids) {
|
|
|
|
const all = ids.length === 1 && ids[0] === "all";
|
|
|
|
const tools = this.tools;
|
|
|
|
for (const tool of tools) {
|
|
|
|
if (all || ids.includes(tool.id)) {
|
|
|
|
tool.enabled = true;
|
2014-03-27 05:18:53 +09:00
|
|
|
}
|
2023-09-17 15:06:43 +09:00
|
|
|
}
|
|
|
|
if (!all) {
|
|
|
|
// Sort the tools by the order they are enabled.
|
|
|
|
tools.sort(function (a, b) {
|
|
|
|
let indexA = ids.indexOf(a.id);
|
|
|
|
indexA = indexA < 0 ? tools.length : indexA;
|
|
|
|
let indexB = ids.indexOf(b.id);
|
|
|
|
indexB = indexB < 0 ? tools.length : indexB;
|
|
|
|
return indexA - indexB;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static init(container, ids) {
|
|
|
|
this.loadCSS();
|
|
|
|
this.enable(ids);
|
|
|
|
/*
|
|
|
|
* Basic Layout:
|
|
|
|
* PDFBug
|
|
|
|
* Controls
|
|
|
|
* Panels
|
|
|
|
* Panel
|
|
|
|
* Panel
|
|
|
|
* ...
|
|
|
|
*/
|
|
|
|
const ui = document.createElement("div");
|
|
|
|
ui.id = "PDFBug";
|
|
|
|
|
|
|
|
const controls = document.createElement("div");
|
|
|
|
controls.setAttribute("class", "controls");
|
|
|
|
ui.append(controls);
|
|
|
|
|
|
|
|
const panels = document.createElement("div");
|
|
|
|
panels.setAttribute("class", "panels");
|
|
|
|
ui.append(panels);
|
|
|
|
|
|
|
|
container.append(ui);
|
|
|
|
container.style.right = "var(--panel-width)";
|
|
|
|
|
|
|
|
// Initialize all the debugging tools.
|
|
|
|
for (const tool of this.tools) {
|
|
|
|
const panel = document.createElement("div");
|
|
|
|
const panelButton = document.createElement("button");
|
|
|
|
panelButton.textContent = tool.name;
|
|
|
|
panelButton.addEventListener("click", event => {
|
|
|
|
event.preventDefault();
|
|
|
|
this.selectPanel(tool);
|
|
|
|
});
|
|
|
|
controls.append(panelButton);
|
|
|
|
panels.append(panel);
|
|
|
|
tool.panel = panel;
|
|
|
|
tool.manager = this;
|
|
|
|
if (tool.enabled) {
|
|
|
|
tool.init();
|
|
|
|
} else {
|
|
|
|
panel.textContent =
|
|
|
|
`${tool.name} is disabled. To enable add "${tool.id}" to ` +
|
|
|
|
"the pdfBug parameter and refresh (separate multiple by commas).";
|
2014-03-09 07:42:23 +09:00
|
|
|
}
|
2023-09-17 15:06:43 +09:00
|
|
|
this.#buttons.push(panelButton);
|
|
|
|
}
|
|
|
|
this.selectPanel(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static loadCSS() {
|
|
|
|
const { url } = import.meta;
|
|
|
|
|
|
|
|
const link = document.createElement("link");
|
|
|
|
link.rel = "stylesheet";
|
2023-10-08 20:14:09 +09:00
|
|
|
link.href = url.replace(/\.mjs$/, ".css");
|
2023-09-17 15:06:43 +09:00
|
|
|
|
|
|
|
document.head.append(link);
|
|
|
|
}
|
|
|
|
|
|
|
|
static cleanup() {
|
|
|
|
for (const tool of this.tools) {
|
|
|
|
if (tool.enabled) {
|
|
|
|
tool.cleanup();
|
2012-02-14 10:35:58 +09:00
|
|
|
}
|
2023-09-17 15:06:43 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static selectPanel(index) {
|
|
|
|
if (typeof index !== "number") {
|
|
|
|
index = this.tools.indexOf(index);
|
|
|
|
}
|
|
|
|
if (index === this.#activePanel) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.#activePanel = index;
|
|
|
|
for (const [j, tool] of this.tools.entries()) {
|
|
|
|
const isActive = j === index;
|
|
|
|
this.#buttons[j].classList.toggle("active", isActive);
|
|
|
|
tool.active = isActive;
|
|
|
|
tool.panel.hidden = !isActive;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
Convert `web/debugger.js` to a *basic* module
The various functionality in `web/debugger.js` is currently *indirectly* added to the global scope, since that's how `var` works when it's used outside of any functions/closures.
Given how this functionality is being accessed/used, not just in the viewer but also in the API and textLayer, simply converting the entire file to a module isn't trivial[1]. However, we can at least export the `PDFBug`-part properly and then `import` that dynamically in the viewer.
Also, to improve the code a little bit, we're now *explicitly* exporting the necessary functionality globally.
According to MDN, see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#browser_compatibility, all the browsers that we now support have dynamic `imports` implementations.
---
[1] We could probably pass around references to the necessary functionality, but given how this is being used I'm just not sure it's worth the effort. Also, adding *official* support for these viewer-specific debugging tools in the API feels both unnecessary and unfortunate.
2022-04-03 18:51:49 +09:00
|
|
|
|
|
|
|
globalThis.FontInspector = FontInspector;
|
|
|
|
globalThis.StepperManager = StepperManager;
|
|
|
|
globalThis.Stats = Stats;
|
|
|
|
|
|
|
|
export { PDFBug };
|