mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-20 15:18:08 +02:00
Merge pull request #17701 from calixteman/alt_text_ai
[Editor] Add the possibility to query some ML stuff to guess an alt text for an image
This commit is contained in:
commit
72b8b29147
11 changed files with 102 additions and 6 deletions
11
web/app.js
11
web/app.js
|
@ -53,7 +53,7 @@ import {
|
|||
} from "pdfjs-lib";
|
||||
import { AppOptions, OptionKind } from "./app_options.js";
|
||||
import { AutomationEventBus, EventBus } from "./event_utils.js";
|
||||
import { ExternalServices, initCom } from "web-external_services";
|
||||
import { ExternalServices, initCom, MLManager } from "web-external_services";
|
||||
import { LinkTarget, PDFLinkService } from "./pdf_link_service.js";
|
||||
import { AltTextManager } from "web-alt_text_manager";
|
||||
import { AnnotationEditorParams } from "web-annotation_editor_params";
|
||||
|
@ -420,6 +420,7 @@ const PDFViewerApplication = {
|
|||
maxCanvasPixels: AppOptions.get("maxCanvasPixels"),
|
||||
enablePermissions: AppOptions.get("enablePermissions"),
|
||||
pageColors,
|
||||
mlManager: this.mlManager,
|
||||
});
|
||||
this.pdfViewer = pdfViewer;
|
||||
|
||||
|
@ -682,6 +683,14 @@ const PDFViewerApplication = {
|
|||
return shadow(this, "externalServices", new ExternalServices());
|
||||
},
|
||||
|
||||
get mlManager() {
|
||||
return shadow(
|
||||
this,
|
||||
"mlManager",
|
||||
AppOptions.get("enableML") === true ? new MLManager() : null
|
||||
);
|
||||
},
|
||||
|
||||
get initialized() {
|
||||
return this._initializedCapability.settled;
|
||||
},
|
||||
|
|
|
@ -143,6 +143,11 @@ const defaultOptions = {
|
|||
value: typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING"),
|
||||
kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
|
||||
},
|
||||
enableML: {
|
||||
/** @type {boolean} */
|
||||
value: false,
|
||||
kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
|
||||
},
|
||||
enablePermissions: {
|
||||
/** @type {boolean} */
|
||||
value: false,
|
||||
|
|
|
@ -435,4 +435,10 @@ class ExternalServices extends BaseExternalServices {
|
|||
}
|
||||
}
|
||||
|
||||
export { ExternalServices, initCom, Preferences };
|
||||
class MLManager {
|
||||
async guess() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export { ExternalServices, initCom, MLManager, Preferences };
|
||||
|
|
|
@ -314,6 +314,12 @@ class FirefoxScripting {
|
|||
}
|
||||
}
|
||||
|
||||
class MLManager {
|
||||
guess(data) {
|
||||
return FirefoxCom.requestAsync("mlGuess", data);
|
||||
}
|
||||
}
|
||||
|
||||
class ExternalServices extends BaseExternalServices {
|
||||
updateFindControlState(data) {
|
||||
FirefoxCom.request("updateFindControlState", data);
|
||||
|
@ -415,4 +421,4 @@ class ExternalServices extends BaseExternalServices {
|
|||
}
|
||||
}
|
||||
|
||||
export { DownloadManager, ExternalServices, initCom, Preferences };
|
||||
export { DownloadManager, ExternalServices, initCom, MLManager, Preferences };
|
||||
|
|
|
@ -47,4 +47,10 @@ class ExternalServices extends BaseExternalServices {
|
|||
}
|
||||
}
|
||||
|
||||
export { ExternalServices, initCom, Preferences };
|
||||
class MLManager {
|
||||
async guess() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export { ExternalServices, initCom, MLManager, Preferences };
|
||||
|
|
|
@ -216,6 +216,8 @@ class PDFViewer {
|
|||
|
||||
#enablePermissions = false;
|
||||
|
||||
#mlManager = null;
|
||||
|
||||
#getAllTextInProgress = false;
|
||||
|
||||
#hiddenCopyElement = null;
|
||||
|
@ -292,6 +294,7 @@ class PDFViewer {
|
|||
}
|
||||
this.#enablePermissions = options.enablePermissions || false;
|
||||
this.pageColors = options.pageColors || null;
|
||||
this.#mlManager = options.mlManager || null;
|
||||
|
||||
this.defaultRenderingQueue = !options.renderingQueue;
|
||||
if (
|
||||
|
@ -857,7 +860,8 @@ class PDFViewer {
|
|||
this.eventBus,
|
||||
pdfDocument,
|
||||
this.pageColors,
|
||||
this.#annotationEditorHighlightColors
|
||||
this.#annotationEditorHighlightColors,
|
||||
this.#mlManager
|
||||
);
|
||||
this.eventBus.dispatch("annotationeditoruimanager", {
|
||||
source: this,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue