Convert PDFBug
, in web/debugger.js
, to a class with static methods
This gets rid of one more closure from the code-base.
This commit is contained in:
parent
c9cd934f8a
commit
2d79be941e
@ -491,13 +491,14 @@ const Stats = (function Stats() {
|
||||
})();
|
||||
|
||||
// Manages all the debugging tools.
|
||||
const PDFBug = (function PDFBugClosure() {
|
||||
const buttons = [];
|
||||
let activePanel = null;
|
||||
class PDFBug {
|
||||
static #buttons = [];
|
||||
|
||||
return {
|
||||
tools: [FontInspector, StepperManager, Stats],
|
||||
enable(ids) {
|
||||
static #activePanel = null;
|
||||
|
||||
static tools = [FontInspector, StepperManager, Stats];
|
||||
|
||||
static enable(ids) {
|
||||
const all = ids.length === 1 && ids[0] === "all";
|
||||
const tools = this.tools;
|
||||
for (const tool of tools) {
|
||||
@ -515,8 +516,9 @@ const PDFBug = (function PDFBugClosure() {
|
||||
return indexA - indexB;
|
||||
});
|
||||
}
|
||||
},
|
||||
init(container, ids) {
|
||||
}
|
||||
|
||||
static init(container, ids) {
|
||||
this.loadCSS();
|
||||
this.enable(ids);
|
||||
/*
|
||||
@ -562,11 +564,12 @@ const PDFBug = (function PDFBugClosure() {
|
||||
`${tool.name} is disabled. To enable add "${tool.id}" to ` +
|
||||
"the pdfBug parameter and refresh (separate multiple by commas).";
|
||||
}
|
||||
buttons.push(panelButton);
|
||||
this.#buttons.push(panelButton);
|
||||
}
|
||||
this.selectPanel(0);
|
||||
},
|
||||
loadCSS() {
|
||||
}
|
||||
|
||||
static loadCSS() {
|
||||
const { url } = import.meta;
|
||||
|
||||
const link = document.createElement("link");
|
||||
@ -574,31 +577,32 @@ const PDFBug = (function PDFBugClosure() {
|
||||
link.href = url.replace(/.js$/, ".css");
|
||||
|
||||
document.head.append(link);
|
||||
},
|
||||
cleanup() {
|
||||
}
|
||||
|
||||
static cleanup() {
|
||||
for (const tool of this.tools) {
|
||||
if (tool.enabled) {
|
||||
tool.cleanup();
|
||||
}
|
||||
}
|
||||
},
|
||||
selectPanel(index) {
|
||||
}
|
||||
|
||||
static selectPanel(index) {
|
||||
if (typeof index !== "number") {
|
||||
index = this.tools.indexOf(index);
|
||||
}
|
||||
if (index === activePanel) {
|
||||
if (index === this.#activePanel) {
|
||||
return;
|
||||
}
|
||||
activePanel = index;
|
||||
this.#activePanel = index;
|
||||
for (const [j, tool] of this.tools.entries()) {
|
||||
const isActive = j === index;
|
||||
buttons[j].classList.toggle("active", isActive);
|
||||
this.#buttons[j].classList.toggle("active", isActive);
|
||||
tool.active = isActive;
|
||||
tool.panel.hidden = !isActive;
|
||||
}
|
||||
},
|
||||
};
|
||||
})();
|
||||
}
|
||||
}
|
||||
|
||||
globalThis.FontInspector = FontInspector;
|
||||
globalThis.StepperManager = StepperManager;
|
||||
|
Loading…
x
Reference in New Issue
Block a user