mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-19 06:38:07 +02:00
Don't bundle the FakeMLManager
class in regular builds
Given that this functionality is only used in the development viewer and in TESTING builds, there's no reason to include this in the regular builds.
This commit is contained in:
parent
50c573d16d
commit
b5ac96da19
1 changed files with 69 additions and 64 deletions
|
@ -53,6 +53,12 @@ class ExternalServices extends BaseExternalServices {
|
||||||
}
|
}
|
||||||
|
|
||||||
class MLManager {
|
class MLManager {
|
||||||
|
static {
|
||||||
|
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) {
|
||||||
|
this.getFakeMLManager = options => new FakeMLManager(options);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async isEnabledFor(_name) {
|
async isEnabledFor(_name) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -68,83 +74,82 @@ class MLManager {
|
||||||
guess(_data) {}
|
guess(_data) {}
|
||||||
|
|
||||||
toggleService(_name, _enabled) {}
|
toggleService(_name, _enabled) {}
|
||||||
|
|
||||||
static getFakeMLManager(options) {
|
|
||||||
return new FakeMLManager(options);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class FakeMLManager {
|
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) {
|
||||||
eventBus = null;
|
// eslint-disable-next-line no-var
|
||||||
|
var FakeMLManager = class {
|
||||||
|
eventBus = null;
|
||||||
|
|
||||||
hasProgress = false;
|
hasProgress = false;
|
||||||
|
|
||||||
constructor({ enableGuessAltText, enableAltTextModelDownload }) {
|
constructor({ enableGuessAltText, enableAltTextModelDownload }) {
|
||||||
this.enableGuessAltText = enableGuessAltText;
|
this.enableGuessAltText = enableGuessAltText;
|
||||||
this.enableAltTextModelDownload = enableAltTextModelDownload;
|
this.enableAltTextModelDownload = enableAltTextModelDownload;
|
||||||
}
|
}
|
||||||
|
|
||||||
setEventBus(eventBus, abortSignal) {
|
setEventBus(eventBus, abortSignal) {
|
||||||
this.eventBus = eventBus;
|
this.eventBus = eventBus;
|
||||||
}
|
}
|
||||||
|
|
||||||
async isEnabledFor(_name) {
|
async isEnabledFor(_name) {
|
||||||
return this.enableGuessAltText;
|
return this.enableGuessAltText;
|
||||||
}
|
}
|
||||||
|
|
||||||
async deleteModel(_name) {
|
async deleteModel(_name) {
|
||||||
this.enableAltTextModelDownload = false;
|
this.enableAltTextModelDownload = false;
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
async loadModel(_name) {}
|
async loadModel(_name) {}
|
||||||
|
|
||||||
async downloadModel(_name) {
|
async downloadModel(_name) {
|
||||||
// Simulate downloading the model but with progress.
|
// Simulate downloading the model but with progress.
|
||||||
// The progress can be seen in the new alt-text dialog.
|
// The progress can be seen in the new alt-text dialog.
|
||||||
this.hasProgress = true;
|
this.hasProgress = true;
|
||||||
|
|
||||||
const { promise, resolve } = Promise.withResolvers();
|
const { promise, resolve } = Promise.withResolvers();
|
||||||
const total = 1e8;
|
const total = 1e8;
|
||||||
const end = 1.5 * total;
|
const end = 1.5 * total;
|
||||||
const increment = 5e6;
|
const increment = 5e6;
|
||||||
let loaded = 0;
|
let loaded = 0;
|
||||||
const id = setInterval(() => {
|
const id = setInterval(() => {
|
||||||
loaded += increment;
|
loaded += increment;
|
||||||
if (loaded <= end) {
|
if (loaded <= end) {
|
||||||
this.eventBus.dispatch("loadaiengineprogress", {
|
this.eventBus.dispatch("loadaiengineprogress", {
|
||||||
source: this,
|
source: this,
|
||||||
detail: {
|
detail: {
|
||||||
total,
|
total,
|
||||||
totalLoaded: loaded,
|
totalLoaded: loaded,
|
||||||
finished: loaded + increment >= end,
|
finished: loaded + increment >= end,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
clearInterval(id);
|
clearInterval(id);
|
||||||
this.hasProgress = false;
|
this.hasProgress = false;
|
||||||
this.enableAltTextModelDownload = true;
|
this.enableAltTextModelDownload = true;
|
||||||
resolve(true);
|
resolve(true);
|
||||||
}, 900);
|
}, 900);
|
||||||
return promise;
|
return promise;
|
||||||
}
|
}
|
||||||
|
|
||||||
isReady(_name) {
|
isReady(_name) {
|
||||||
return this.enableAltTextModelDownload;
|
return this.enableAltTextModelDownload;
|
||||||
}
|
}
|
||||||
|
|
||||||
guess({ request: { data } }) {
|
guess({ request: { data } }) {
|
||||||
return new Promise(resolve => {
|
return new Promise(resolve => {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
resolve(data ? { output: "Fake alt text." } : { error: true });
|
resolve(data ? { output: "Fake alt text." } : { error: true });
|
||||||
}, 3000);
|
}, 3000);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
toggleService(_name, enabled) {
|
toggleService(_name, enabled) {
|
||||||
this.enableGuessAltText = enabled;
|
this.enableGuessAltText = enabled;
|
||||||
}
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export { ExternalServices, initCom, MLManager, Preferences };
|
export { ExternalServices, initCom, MLManager, Preferences };
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue