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");
|
30 |
|
31 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
32 |
|
33 | function _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 |
|
35 | function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
36 |
|
37 | var CursorTool = {
|
38 | SELECT: 0,
|
39 | HAND: 1,
|
40 | ZOOM: 2
|
41 | };
|
42 | exports.CursorTool = CursorTool;
|
43 |
|
44 | var PDFCursorTools =
|
45 |
|
46 | function () {
|
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 |
|
166 | exports.PDFCursorTools = PDFCursorTools; |
\ | No newline at end of file |