annotation_layer_builder.js 5.4 KB

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