mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-22 16:18:08 +02:00
[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:
parent
3f8b5449e8
commit
571ce13dd6
13 changed files with 34 additions and 559 deletions
|
@ -110,9 +110,8 @@ function isValidAnnotationEditorMode(mode) {
|
|||
* @property {boolean} [removePageBorders] - Removes the border shadow around
|
||||
* the pages. The default value is `false`.
|
||||
* @property {number} [textLayerMode] - Controls if the text layer used for
|
||||
* selection and searching is created, and if the improved text selection
|
||||
* behaviour is enabled. The constants from {TextLayerMode} should be used.
|
||||
* The default value is `TextLayerMode.ENABLE`.
|
||||
* selection and searching is created. The constants from {TextLayerMode}
|
||||
* should be used. The default value is `TextLayerMode.ENABLE`.
|
||||
* @property {number} [annotationMode] - Controls if the annotation layer is
|
||||
* created, and if interactive form elements or `AnnotationStorage`-data are
|
||||
* being rendered. The constants from {@link AnnotationMode} should be used;
|
||||
|
@ -1636,7 +1635,6 @@ class BaseViewer {
|
|||
* @property {HTMLDivElement} textLayerDiv
|
||||
* @property {number} pageIndex
|
||||
* @property {PageViewport} viewport
|
||||
* @property {boolean} [enhanceTextSelection]
|
||||
* @property {EventBus} eventBus
|
||||
* @property {TextHighlighter} highlighter
|
||||
* @property {TextAccessibilityManager} [accessibilityManager]
|
||||
|
@ -1650,7 +1648,6 @@ class BaseViewer {
|
|||
textLayerDiv,
|
||||
pageIndex,
|
||||
viewport,
|
||||
enhanceTextSelection = false,
|
||||
eventBus,
|
||||
highlighter,
|
||||
accessibilityManager = null,
|
||||
|
@ -1660,9 +1657,6 @@ class BaseViewer {
|
|||
eventBus,
|
||||
pageIndex,
|
||||
viewport,
|
||||
enhanceTextSelection: this.isInPresentationMode
|
||||
? false
|
||||
: enhanceTextSelection,
|
||||
highlighter,
|
||||
accessibilityManager,
|
||||
});
|
||||
|
|
|
@ -374,12 +374,8 @@ class ChromePreferences extends BasePreferences {
|
|||
delete items.enableHandToolOnLoad;
|
||||
|
||||
// Migration code for https://github.com/mozilla/pdf.js/pull/9479.
|
||||
if (items.textLayerMode !== 1) {
|
||||
if (items.disableTextLayer) {
|
||||
items.textLayerMode = 0;
|
||||
} else if (items.enhanceTextSelection) {
|
||||
items.textLayerMode = 2;
|
||||
}
|
||||
if (items.textLayerMode !== 1 && items.disableTextLayer) {
|
||||
items.textLayerMode = 0;
|
||||
}
|
||||
delete items.disableTextLayer;
|
||||
delete items.enhanceTextSelection;
|
||||
|
|
|
@ -168,7 +168,6 @@ class DefaultTextLayerFactory {
|
|||
* @property {HTMLDivElement} textLayerDiv
|
||||
* @property {number} pageIndex
|
||||
* @property {PageViewport} viewport
|
||||
* @property {boolean} [enhanceTextSelection]
|
||||
* @property {EventBus} eventBus
|
||||
* @property {TextHighlighter} highlighter
|
||||
* @property {TextAccessibilityManager} [accessibilityManager]
|
||||
|
@ -182,7 +181,6 @@ class DefaultTextLayerFactory {
|
|||
textLayerDiv,
|
||||
pageIndex,
|
||||
viewport,
|
||||
enhanceTextSelection = false,
|
||||
eventBus,
|
||||
highlighter,
|
||||
accessibilityManager = null,
|
||||
|
@ -191,7 +189,6 @@ class DefaultTextLayerFactory {
|
|||
textLayerDiv,
|
||||
pageIndex,
|
||||
viewport,
|
||||
enhanceTextSelection,
|
||||
eventBus,
|
||||
highlighter,
|
||||
accessibilityManager,
|
||||
|
|
|
@ -161,7 +161,6 @@ class IPDFTextLayerFactory {
|
|||
* @property {HTMLDivElement} textLayerDiv
|
||||
* @property {number} pageIndex
|
||||
* @property {PageViewport} viewport
|
||||
* @property {boolean} [enhanceTextSelection]
|
||||
* @property {EventBus} eventBus
|
||||
* @property {TextHighlighter} highlighter
|
||||
* @property {TextAccessibilityManager} [accessibilityManager]
|
||||
|
@ -175,7 +174,6 @@ class IPDFTextLayerFactory {
|
|||
textLayerDiv,
|
||||
pageIndex,
|
||||
viewport,
|
||||
enhanceTextSelection = false,
|
||||
eventBus,
|
||||
highlighter,
|
||||
accessibilityManager,
|
||||
|
|
|
@ -66,9 +66,8 @@ import { TextAccessibilityManager } from "./text_accessibility.js";
|
|||
* @property {PDFRenderingQueue} [renderingQueue] - The rendering queue object.
|
||||
* @property {IPDFTextLayerFactory} [textLayerFactory]
|
||||
* @property {number} [textLayerMode] - Controls if the text layer used for
|
||||
* selection and searching is created, and if the improved text selection
|
||||
* behaviour is enabled. The constants from {TextLayerMode} should be used.
|
||||
* The default value is `TextLayerMode.ENABLE`.
|
||||
* selection and searching is created. The constants from {TextLayerMode}
|
||||
* should be used. The default value is `TextLayerMode.ENABLE`.
|
||||
* @property {number} [annotationMode] - Controls if the annotation layer is
|
||||
* created, and if interactive form elements or `AnnotationStorage`-data are
|
||||
* being rendered. The constants from {@link AnnotationMode} should be used;
|
||||
|
@ -717,8 +716,6 @@ class PDFPageView {
|
|||
textLayerDiv,
|
||||
pageIndex: this.id - 1,
|
||||
viewport: this.viewport,
|
||||
enhanceTextSelection:
|
||||
this.textLayerMode === TextLayerMode.ENABLE_ENHANCE,
|
||||
eventBus: this.eventBus,
|
||||
highlighter: this.textHighlighter,
|
||||
accessibilityManager: this._accessibilityManager,
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -57,7 +57,6 @@ const RendererType =
|
|||
const TextLayerMode = {
|
||||
DISABLE: 0,
|
||||
ENABLE: 1,
|
||||
ENABLE_ENHANCE: 2,
|
||||
};
|
||||
|
||||
const ScrollMode = {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue