UNPKG

4.63 kBJavaScriptView Raw
1/**
2 * @licstart The following is the entire license notice for the
3 * Javascript code in this page
4 *
5 * Copyright 2019 Mozilla Foundation
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 *
19 * @licend The above is the entire license notice for the
20 * Javascript code in this page
21 */
22"use strict";
23
24Object.defineProperty(exports, "__esModule", {
25 value: true
26});
27exports.PDFCursorTools = exports.CursorTool = void 0;
28
29var _grab_to_pan = require("./grab_to_pan");
30
31function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
32
33function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
34
35function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
36
37var CursorTool = {
38 SELECT: 0,
39 HAND: 1,
40 ZOOM: 2
41};
42exports.CursorTool = CursorTool;
43
44var PDFCursorTools =
45/*#__PURE__*/
46function () {
47 function PDFCursorTools(_ref) {
48 var _this = this;
49
50 var container = _ref.container,
51 eventBus = _ref.eventBus,
52 _ref$cursorToolOnLoad = _ref.cursorToolOnLoad,
53 cursorToolOnLoad = _ref$cursorToolOnLoad === void 0 ? CursorTool.SELECT : _ref$cursorToolOnLoad;
54
55 _classCallCheck(this, PDFCursorTools);
56
57 this.container = container;
58 this.eventBus = eventBus;
59 this.active = CursorTool.SELECT;
60 this.activeBeforePresentationMode = null;
61 this.handTool = new _grab_to_pan.GrabToPan({
62 element: this.container
63 });
64
65 this._addEventListeners();
66
67 Promise.resolve().then(function () {
68 _this.switchTool(cursorToolOnLoad);
69 });
70 }
71
72 _createClass(PDFCursorTools, [{
73 key: "switchTool",
74 value: function switchTool(tool) {
75 var _this2 = this;
76
77 if (this.activeBeforePresentationMode !== null) {
78 return;
79 }
80
81 if (tool === this.active) {
82 return;
83 }
84
85 var disableActiveTool = function disableActiveTool() {
86 switch (_this2.active) {
87 case CursorTool.SELECT:
88 break;
89
90 case CursorTool.HAND:
91 _this2.handTool.deactivate();
92
93 break;
94
95 case CursorTool.ZOOM:
96 }
97 };
98
99 switch (tool) {
100 case CursorTool.SELECT:
101 disableActiveTool();
102 break;
103
104 case CursorTool.HAND:
105 disableActiveTool();
106 this.handTool.activate();
107 break;
108
109 case CursorTool.ZOOM:
110 default:
111 console.error("switchTool: \"".concat(tool, "\" is an unsupported value."));
112 return;
113 }
114
115 this.active = tool;
116
117 this._dispatchEvent();
118 }
119 }, {
120 key: "_dispatchEvent",
121 value: function _dispatchEvent() {
122 this.eventBus.dispatch('cursortoolchanged', {
123 source: this,
124 tool: this.active
125 });
126 }
127 }, {
128 key: "_addEventListeners",
129 value: function _addEventListeners() {
130 var _this3 = this;
131
132 this.eventBus.on('switchcursortool', function (evt) {
133 _this3.switchTool(evt.tool);
134 });
135 this.eventBus.on('presentationmodechanged', function (evt) {
136 if (evt.switchInProgress) {
137 return;
138 }
139
140 var previouslyActive;
141
142 if (evt.active) {
143 previouslyActive = _this3.active;
144
145 _this3.switchTool(CursorTool.SELECT);
146
147 _this3.activeBeforePresentationMode = previouslyActive;
148 } else {
149 previouslyActive = _this3.activeBeforePresentationMode;
150 _this3.activeBeforePresentationMode = null;
151
152 _this3.switchTool(previouslyActive);
153 }
154 });
155 }
156 }, {
157 key: "activeTool",
158 get: function get() {
159 return this.active;
160 }
161 }]);
162
163 return PDFCursorTools;
164}();
165
166exports.PDFCursorTools = PDFCursorTools;
\No newline at end of file