annotation_layer_builder.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /* Copyright 2017 Mozilla Foundation
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. 'use strict';
  16. Object.defineProperty(exports, "__esModule", {
  17. value: true
  18. });
  19. exports.DefaultAnnotationLayerFactory = exports.AnnotationLayerBuilder = undefined;
  20. 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; }; }();
  21. var _pdf = require('../pdf');
  22. var _ui_utils = require('./ui_utils');
  23. var _pdf_link_service = require('./pdf_link_service');
  24. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  25. var AnnotationLayerBuilder = function () {
  26. function AnnotationLayerBuilder(_ref) {
  27. var pageDiv = _ref.pageDiv,
  28. pdfPage = _ref.pdfPage,
  29. linkService = _ref.linkService,
  30. downloadManager = _ref.downloadManager,
  31. _ref$renderInteractiv = _ref.renderInteractiveForms,
  32. renderInteractiveForms = _ref$renderInteractiv === undefined ? false : _ref$renderInteractiv,
  33. _ref$l10n = _ref.l10n,
  34. l10n = _ref$l10n === undefined ? _ui_utils.NullL10n : _ref$l10n;
  35. _classCallCheck(this, AnnotationLayerBuilder);
  36. this.pageDiv = pageDiv;
  37. this.pdfPage = pdfPage;
  38. this.linkService = linkService;
  39. this.downloadManager = downloadManager;
  40. this.renderInteractiveForms = renderInteractiveForms;
  41. this.l10n = l10n;
  42. this.div = null;
  43. }
  44. _createClass(AnnotationLayerBuilder, [{
  45. key: 'render',
  46. value: function render(viewport) {
  47. var _this = this;
  48. var intent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'display';
  49. this.pdfPage.getAnnotations({ intent: intent }).then(function (annotations) {
  50. var parameters = {
  51. viewport: viewport.clone({ dontFlip: true }),
  52. div: _this.div,
  53. annotations: annotations,
  54. page: _this.pdfPage,
  55. renderInteractiveForms: _this.renderInteractiveForms,
  56. linkService: _this.linkService,
  57. downloadManager: _this.downloadManager
  58. };
  59. if (_this.div) {
  60. _pdf.AnnotationLayer.update(parameters);
  61. } else {
  62. if (annotations.length === 0) {
  63. return;
  64. }
  65. _this.div = document.createElement('div');
  66. _this.div.className = 'annotationLayer';
  67. _this.pageDiv.appendChild(_this.div);
  68. parameters.div = _this.div;
  69. _pdf.AnnotationLayer.render(parameters);
  70. _this.l10n.translate(_this.div);
  71. }
  72. });
  73. }
  74. }, {
  75. key: 'hide',
  76. value: function hide() {
  77. if (!this.div) {
  78. return;
  79. }
  80. this.div.setAttribute('hidden', 'true');
  81. }
  82. }]);
  83. return AnnotationLayerBuilder;
  84. }();
  85. var DefaultAnnotationLayerFactory = function () {
  86. function DefaultAnnotationLayerFactory() {
  87. _classCallCheck(this, DefaultAnnotationLayerFactory);
  88. }
  89. _createClass(DefaultAnnotationLayerFactory, [{
  90. key: 'createAnnotationLayerBuilder',
  91. value: function createAnnotationLayerBuilder(pageDiv, pdfPage) {
  92. var renderInteractiveForms = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  93. var l10n = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : _ui_utils.NullL10n;
  94. return new AnnotationLayerBuilder({
  95. pageDiv: pageDiv,
  96. pdfPage: pdfPage,
  97. renderInteractiveForms: renderInteractiveForms,
  98. linkService: new _pdf_link_service.SimpleLinkService(),
  99. l10n: l10n
  100. });
  101. }
  102. }]);
  103. return DefaultAnnotationLayerFactory;
  104. }();
  105. exports.AnnotationLayerBuilder = AnnotationLayerBuilder;
  106. exports.DefaultAnnotationLayerFactory = DefaultAnnotationLayerFactory;