pdf_cursor_tools.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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. Object.defineProperty(exports, "__esModule", {
  24. value: true
  25. });
  26. exports.PDFCursorTools = exports.CursorTool = void 0;
  27. var _grab_to_pan = require("./grab_to_pan");
  28. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  29. 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); } }
  30. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  31. var CursorTool = {
  32. SELECT: 0,
  33. HAND: 1,
  34. ZOOM: 2
  35. };
  36. exports.CursorTool = CursorTool;
  37. var PDFCursorTools =
  38. /*#__PURE__*/
  39. function () {
  40. function PDFCursorTools(_ref) {
  41. var _this = this;
  42. var container = _ref.container,
  43. eventBus = _ref.eventBus,
  44. _ref$cursorToolOnLoad = _ref.cursorToolOnLoad,
  45. cursorToolOnLoad = _ref$cursorToolOnLoad === void 0 ? CursorTool.SELECT : _ref$cursorToolOnLoad;
  46. _classCallCheck(this, PDFCursorTools);
  47. this.container = container;
  48. this.eventBus = eventBus;
  49. this.active = CursorTool.SELECT;
  50. this.activeBeforePresentationMode = null;
  51. this.handTool = new _grab_to_pan.GrabToPan({
  52. element: this.container
  53. });
  54. this._addEventListeners();
  55. Promise.resolve().then(function () {
  56. _this.switchTool(cursorToolOnLoad);
  57. });
  58. }
  59. _createClass(PDFCursorTools, [{
  60. key: "switchTool",
  61. value: function switchTool(tool) {
  62. var _this2 = this;
  63. if (this.activeBeforePresentationMode !== null) {
  64. return;
  65. }
  66. if (tool === this.active) {
  67. return;
  68. }
  69. var disableActiveTool = function disableActiveTool() {
  70. switch (_this2.active) {
  71. case CursorTool.SELECT:
  72. break;
  73. case CursorTool.HAND:
  74. _this2.handTool.deactivate();
  75. break;
  76. case CursorTool.ZOOM:
  77. }
  78. };
  79. switch (tool) {
  80. case CursorTool.SELECT:
  81. disableActiveTool();
  82. break;
  83. case CursorTool.HAND:
  84. disableActiveTool();
  85. this.handTool.activate();
  86. break;
  87. case CursorTool.ZOOM:
  88. default:
  89. console.error("switchTool: \"".concat(tool, "\" is an unsupported value."));
  90. return;
  91. }
  92. this.active = tool;
  93. this._dispatchEvent();
  94. }
  95. }, {
  96. key: "_dispatchEvent",
  97. value: function _dispatchEvent() {
  98. this.eventBus.dispatch('cursortoolchanged', {
  99. source: this,
  100. tool: this.active
  101. });
  102. }
  103. }, {
  104. key: "_addEventListeners",
  105. value: function _addEventListeners() {
  106. var _this3 = this;
  107. this.eventBus.on('switchcursortool', function (evt) {
  108. _this3.switchTool(evt.tool);
  109. });
  110. this.eventBus.on('presentationmodechanged', function (evt) {
  111. if (evt.switchInProgress) {
  112. return;
  113. }
  114. var previouslyActive;
  115. if (evt.active) {
  116. previouslyActive = _this3.active;
  117. _this3.switchTool(CursorTool.SELECT);
  118. _this3.activeBeforePresentationMode = previouslyActive;
  119. } else {
  120. previouslyActive = _this3.activeBeforePresentationMode;
  121. _this3.activeBeforePresentationMode = null;
  122. _this3.switchTool(previouslyActive);
  123. }
  124. });
  125. }
  126. }, {
  127. key: "activeTool",
  128. get: function get() {
  129. return this.active;
  130. }
  131. }]);
  132. return PDFCursorTools;
  133. }();
  134. exports.PDFCursorTools = PDFCursorTools;