mirror of
https://github.com/zen-browser/pdf.js.git
synced 2025-07-08 09:20:06 +02: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.
This commit is contained in:
parent
7c8a92da77
commit
8fa73dbfab
3 changed files with 41 additions and 27 deletions
|
@ -13,10 +13,9 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
let opMap;
|
||||
|
||||
// eslint-disable-next-line no-var
|
||||
var FontInspector = (function FontInspectorClosure() {
|
||||
const FontInspector = (function FontInspectorClosure() {
|
||||
let fonts;
|
||||
let active = false;
|
||||
const fontAttribute = "data-font-name";
|
||||
|
@ -154,12 +153,8 @@ var FontInspector = (function FontInspectorClosure() {
|
|||
};
|
||||
})();
|
||||
|
||||
let opMap;
|
||||
|
||||
// Manages all the page steppers.
|
||||
//
|
||||
// eslint-disable-next-line no-var
|
||||
var StepperManager = (function StepperManagerClosure() {
|
||||
const StepperManager = (function StepperManagerClosure() {
|
||||
let steppers = [];
|
||||
let stepperDiv = null;
|
||||
let stepperControls = null;
|
||||
|
@ -451,8 +446,7 @@ const Stepper = (function StepperClosure() {
|
|||
return Stepper;
|
||||
})();
|
||||
|
||||
// eslint-disable-next-line no-var
|
||||
var Stats = (function Stats() {
|
||||
const Stats = (function Stats() {
|
||||
let stats = [];
|
||||
function clear(node) {
|
||||
node.textContent = ""; // Remove any `node` contents from the DOM.
|
||||
|
@ -510,7 +504,7 @@ var Stats = (function Stats() {
|
|||
})();
|
||||
|
||||
// Manages all the debugging tools.
|
||||
window.PDFBug = (function PDFBugClosure() {
|
||||
const PDFBug = (function PDFBugClosure() {
|
||||
const panelWidth = 300;
|
||||
const buttons = [];
|
||||
let activePanel = null;
|
||||
|
@ -562,13 +556,13 @@ window.PDFBug = (function PDFBugClosure() {
|
|||
container.style.right = panelWidth + "px";
|
||||
|
||||
// Initialize all the debugging tools.
|
||||
for (const [i, tool] of this.tools.entries()) {
|
||||
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(i);
|
||||
this.selectPanel(tool);
|
||||
});
|
||||
controls.appendChild(panelButton);
|
||||
panels.appendChild(panel);
|
||||
|
@ -609,3 +603,9 @@ window.PDFBug = (function PDFBugClosure() {
|
|||
},
|
||||
};
|
||||
})();
|
||||
|
||||
globalThis.FontInspector = FontInspector;
|
||||
globalThis.StepperManager = StepperManager;
|
||||
globalThis.Stats = Stats;
|
||||
|
||||
export { PDFBug };
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue