1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 | "use strict";
|
23 |
|
24 | Object.defineProperty(exports, "__esModule", {
|
25 | value: true
|
26 | });
|
27 | exports.PDFCursorTools = exports.CursorTool = void 0;
|
28 |
|
29 | var _grab_to_pan = require("./grab_to_pan.js");
|
30 |
|
31 | var _ui_utils = require("./ui_utils.js");
|
32 |
|
33 | const CursorTool = {
|
34 | SELECT: 0,
|
35 | HAND: 1,
|
36 | ZOOM: 2
|
37 | };
|
38 | exports.CursorTool = CursorTool;
|
39 |
|
40 | class PDFCursorTools {
|
41 | constructor({
|
42 | container,
|
43 | eventBus,
|
44 | cursorToolOnLoad = CursorTool.SELECT
|
45 | }) {
|
46 | this.container = container;
|
47 | this.eventBus = eventBus;
|
48 | this.active = CursorTool.SELECT;
|
49 | this.activeBeforePresentationMode = null;
|
50 | this.handTool = new _grab_to_pan.GrabToPan({
|
51 | element: this.container
|
52 | });
|
53 | this.#addEventListeners();
|
54 | Promise.resolve().then(() => {
|
55 | this.switchTool(cursorToolOnLoad);
|
56 | });
|
57 | }
|
58 |
|
59 | get activeTool() {
|
60 | return this.active;
|
61 | }
|
62 |
|
63 | switchTool(tool) {
|
64 | if (this.activeBeforePresentationMode !== null) {
|
65 | return;
|
66 | }
|
67 |
|
68 | if (tool === this.active) {
|
69 | return;
|
70 | }
|
71 |
|
72 | const disableActiveTool = () => {
|
73 | switch (this.active) {
|
74 | case CursorTool.SELECT:
|
75 | break;
|
76 |
|
77 | case CursorTool.HAND:
|
78 | this.handTool.deactivate();
|
79 | break;
|
80 |
|
81 | case CursorTool.ZOOM:
|
82 | }
|
83 | };
|
84 |
|
85 | switch (tool) {
|
86 | case CursorTool.SELECT:
|
87 | disableActiveTool();
|
88 | break;
|
89 |
|
90 | case CursorTool.HAND:
|
91 | disableActiveTool();
|
92 | this.handTool.activate();
|
93 | break;
|
94 |
|
95 | case CursorTool.ZOOM:
|
96 | default:
|
97 | console.error(`switchTool: "${tool}" is an unsupported value.`);
|
98 | return;
|
99 | }
|
100 |
|
101 | this.active = tool;
|
102 | this.#dispatchEvent();
|
103 | }
|
104 |
|
105 | #dispatchEvent() {
|
106 | this.eventBus.dispatch("cursortoolchanged", {
|
107 | source: this,
|
108 | tool: this.active
|
109 | });
|
110 | }
|
111 |
|
112 | #addEventListeners() {
|
113 | this.eventBus._on("switchcursortool", evt => {
|
114 | this.switchTool(evt.tool);
|
115 | });
|
116 |
|
117 | this.eventBus._on("presentationmodechanged", evt => {
|
118 | switch (evt.state) {
|
119 | case _ui_utils.PresentationModeState.FULLSCREEN:
|
120 | {
|
121 | const previouslyActive = this.active;
|
122 | this.switchTool(CursorTool.SELECT);
|
123 | this.activeBeforePresentationMode = previouslyActive;
|
124 | break;
|
125 | }
|
126 |
|
127 | case _ui_utils.PresentationModeState.NORMAL:
|
128 | {
|
129 | const previouslyActive = this.activeBeforePresentationMode;
|
130 | this.activeBeforePresentationMode = null;
|
131 | this.switchTool(previouslyActive);
|
132 | break;
|
133 | }
|
134 | }
|
135 | });
|
136 | }
|
137 |
|
138 | }
|
139 |
|
140 | exports.PDFCursorTools = PDFCursorTools; |
\ | No newline at end of file |