From 4f82dd39326968da7f313eeee592d3e4bb632cfe Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Wed, 28 Jun 2023 12:23:02 +0200 Subject: [PATCH] Create a `GrabToPan`-instance lazily in the `PDFCursorTools` class Unless the user enables the "HandTool" we don't actually need to create a `GrabToPan`-instance. --- web/pdf_cursor_tools.js | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/web/pdf_cursor_tools.js b/web/pdf_cursor_tools.js index 2bba8520a..416122b13 100644 --- a/web/pdf_cursor_tools.js +++ b/web/pdf_cursor_tools.js @@ -13,8 +13,8 @@ * limitations under the License. */ +import { AnnotationEditorType, shadow } from "pdfjs-lib"; import { CursorTool, PresentationModeState } from "./ui_utils.js"; -import { AnnotationEditorType } from "pdfjs-lib"; import { GrabToPan } from "./grab_to_pan.js"; /** @@ -38,10 +38,6 @@ class PDFCursorTools { this.container = container; this.eventBus = eventBus; - this.handTool = new GrabToPan({ - element: this.container, - }); - this.#addEventListeners(); // Defer the initial `switchTool` call, to give other viewer components @@ -76,7 +72,7 @@ class PDFCursorTools { case CursorTool.SELECT: break; case CursorTool.HAND: - this.handTool.deactivate(); + this._handTool.deactivate(); break; case CursorTool.ZOOM: /* falls through */ @@ -90,7 +86,7 @@ class PDFCursorTools { break; case CursorTool.HAND: disableActiveTool(); - this.handTool.activate(); + this._handTool.activate(); break; case CursorTool.ZOOM: /* falls through */ @@ -164,6 +160,19 @@ class PDFCursorTools { } }); } + + /** + * @private + */ + get _handTool() { + return shadow( + this, + "_handTool", + new GrabToPan({ + element: this.container, + }) + ); + } } export { PDFCursorTools };