[api-major] Remove the enhanceTextSelection functionality (PR 15145 follow-up)

For the `gulp mozcentral` command, this reduces the size of the *built* `pdf.js` file by `> 10` kB.
This commit is contained in:
Jonas Jenwald 2022-01-18 18:09:12 +01:00
parent 3f8b5449e8
commit 571ce13dd6
13 changed files with 34 additions and 559 deletions

View file

@ -22,8 +22,6 @@
import { renderTextLayer } from "pdfjs-lib";
const EXPAND_DIVS_TIMEOUT = 300; // ms
/**
* @typedef {Object} TextLayerBuilderOptions
* @property {HTMLDivElement} textLayerDiv - The text layer container.
@ -32,8 +30,6 @@ const EXPAND_DIVS_TIMEOUT = 300; // ms
* @property {PageViewport} viewport - The viewport of the text layer.
* @property {TextHighlighter} highlighter - Optional object that will handle
* highlighting text from the find controller.
* @property {boolean} enhanceTextSelection - Option to turn on improved
* text selection.
* @property {TextAccessibilityManager} [accessibilityManager]
*/
@ -49,7 +45,6 @@ class TextLayerBuilder {
pageIndex,
viewport,
highlighter = null,
enhanceTextSelection = false,
accessibilityManager = null,
}) {
this.textLayerDiv = textLayerDiv;
@ -63,23 +58,17 @@ class TextLayerBuilder {
this.textDivs = [];
this.textLayerRenderTask = null;
this.highlighter = highlighter;
this.enhanceTextSelection = enhanceTextSelection;
this.accessibilityManager = accessibilityManager;
this._bindMouse();
this.#bindMouse();
}
/**
* @private
*/
_finishRendering() {
#finishRendering() {
this.renderingDone = true;
if (!this.enhanceTextSelection) {
const endOfContent = document.createElement("div");
endOfContent.className = "endOfContent";
this.textLayerDiv.append(endOfContent);
}
const endOfContent = document.createElement("div");
endOfContent.className = "endOfContent";
this.textLayerDiv.append(endOfContent);
this.eventBus.dispatch("textlayerrendered", {
source: this,
@ -113,12 +102,11 @@ class TextLayerBuilder {
textDivs: this.textDivs,
textContentItemsStr: this.textContentItemsStr,
timeout,
enhanceTextSelection: this.enhanceTextSelection,
});
this.textLayerRenderTask.promise.then(
() => {
this.textLayerDiv.append(textLayerFrag);
this._finishRendering();
this.#finishRendering();
this.highlighter?.enable();
this.accessibilityManager?.enable();
},
@ -154,26 +142,11 @@ class TextLayerBuilder {
* Improves text selection by adding an additional div where the mouse was
* clicked. This reduces flickering of the content if the mouse is slowly
* dragged up or down.
*
* @private
*/
_bindMouse() {
#bindMouse() {
const div = this.textLayerDiv;
let expandDivsTimer = null;
div.addEventListener("mousedown", evt => {
if (this.enhanceTextSelection && this.textLayerRenderTask) {
this.textLayerRenderTask.expandTextDivs(true);
if (
(typeof PDFJSDev === "undefined" || !PDFJSDev.test("MOZCENTRAL")) &&
expandDivsTimer
) {
clearTimeout(expandDivsTimer);
expandDivsTimer = null;
}
return;
}
const end = div.querySelector(".endOfContent");
if (!end) {
return;
@ -185,11 +158,9 @@ class TextLayerBuilder {
// However it does not work when selection is started on empty space.
let adjustTop = evt.target !== div;
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
adjustTop =
adjustTop &&
window
.getComputedStyle(end)
.getPropertyValue("-moz-user-select") !== "none";
adjustTop &&=
getComputedStyle(end).getPropertyValue("-moz-user-select") !==
"none";
}
if (adjustTop) {
const divBounds = div.getBoundingClientRect();
@ -201,20 +172,6 @@ class TextLayerBuilder {
});
div.addEventListener("mouseup", () => {
if (this.enhanceTextSelection && this.textLayerRenderTask) {
if (typeof PDFJSDev === "undefined" || !PDFJSDev.test("MOZCENTRAL")) {
expandDivsTimer = setTimeout(() => {
if (this.textLayerRenderTask) {
this.textLayerRenderTask.expandTextDivs(false);
}
expandDivsTimer = null;
}, EXPAND_DIVS_TIMEOUT);
} else {
this.textLayerRenderTask.expandTextDivs(false);
}
return;
}
const end = div.querySelector(".endOfContent");
if (!end) {
return;