annotation_layer_builder.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /**
  2. * @licstart The following is the entire license notice for the
  3. * Javascript code in this page
  4. *
  5. * Copyright 2018 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.DefaultAnnotationLayerFactory = exports.AnnotationLayerBuilder = void 0;
  27. var _pdf = require("../pdf");
  28. var _ui_utils = require("./ui_utils");
  29. var _pdf_link_service = require("./pdf_link_service");
  30. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  31. 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); } }
  32. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  33. var AnnotationLayerBuilder =
  34. /*#__PURE__*/
  35. function () {
  36. function AnnotationLayerBuilder(_ref) {
  37. var pageDiv = _ref.pageDiv,
  38. pdfPage = _ref.pdfPage,
  39. linkService = _ref.linkService,
  40. downloadManager = _ref.downloadManager,
  41. _ref$imageResourcesPa = _ref.imageResourcesPath,
  42. imageResourcesPath = _ref$imageResourcesPa === void 0 ? '' : _ref$imageResourcesPa,
  43. _ref$renderInteractiv = _ref.renderInteractiveForms,
  44. renderInteractiveForms = _ref$renderInteractiv === void 0 ? false : _ref$renderInteractiv,
  45. _ref$l10n = _ref.l10n,
  46. l10n = _ref$l10n === void 0 ? _ui_utils.NullL10n : _ref$l10n;
  47. _classCallCheck(this, AnnotationLayerBuilder);
  48. this.pageDiv = pageDiv;
  49. this.pdfPage = pdfPage;
  50. this.linkService = linkService;
  51. this.downloadManager = downloadManager;
  52. this.imageResourcesPath = imageResourcesPath;
  53. this.renderInteractiveForms = renderInteractiveForms;
  54. this.l10n = l10n;
  55. this.div = null;
  56. this._cancelled = false;
  57. }
  58. _createClass(AnnotationLayerBuilder, [{
  59. key: "render",
  60. value: function render(viewport) {
  61. var _this = this;
  62. var intent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'display';
  63. this.pdfPage.getAnnotations({
  64. intent: intent
  65. }).then(function (annotations) {
  66. if (_this._cancelled) {
  67. return;
  68. }
  69. var parameters = {
  70. viewport: viewport.clone({
  71. dontFlip: true
  72. }),
  73. div: _this.div,
  74. annotations: annotations,
  75. page: _this.pdfPage,
  76. imageResourcesPath: _this.imageResourcesPath,
  77. renderInteractiveForms: _this.renderInteractiveForms,
  78. linkService: _this.linkService,
  79. downloadManager: _this.downloadManager
  80. };
  81. if (_this.div) {
  82. _pdf.AnnotationLayer.update(parameters);
  83. } else {
  84. if (annotations.length === 0) {
  85. return;
  86. }
  87. _this.div = document.createElement('div');
  88. _this.div.className = 'annotationLayer';
  89. _this.pageDiv.appendChild(_this.div);
  90. parameters.div = _this.div;
  91. _pdf.AnnotationLayer.render(parameters);
  92. _this.l10n.translate(_this.div);
  93. }
  94. });
  95. }
  96. }, {
  97. key: "cancel",
  98. value: function cancel() {
  99. this._cancelled = true;
  100. }
  101. }, {
  102. key: "hide",
  103. value: function hide() {
  104. if (!this.div) {
  105. return;
  106. }
  107. this.div.setAttribute('hidden', 'true');
  108. }
  109. }]);
  110. return AnnotationLayerBuilder;
  111. }();
  112. exports.AnnotationLayerBuilder = AnnotationLayerBuilder;
  113. var DefaultAnnotationLayerFactory =
  114. /*#__PURE__*/
  115. function () {
  116. function DefaultAnnotationLayerFactory() {
  117. _classCallCheck(this, DefaultAnnotationLayerFactory);
  118. }
  119. _createClass(DefaultAnnotationLayerFactory, [{
  120. key: "createAnnotationLayerBuilder",
  121. value: function createAnnotationLayerBuilder(pageDiv, pdfPage) {
  122. var imageResourcesPath = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
  123. var renderInteractiveForms = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
  124. var l10n = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : _ui_utils.NullL10n;
  125. return new AnnotationLayerBuilder({
  126. pageDiv: pageDiv,
  127. pdfPage: pdfPage,
  128. imageResourcesPath: imageResourcesPath,
  129. renderInteractiveForms: renderInteractiveForms,
  130. linkService: new _pdf_link_service.SimpleLinkService(),
  131. l10n: l10n
  132. });
  133. }
  134. }]);
  135. return DefaultAnnotationLayerFactory;
  136. }();
  137. exports.DefaultAnnotationLayerFactory = DefaultAnnotationLayerFactory;