annotation_layer_builder.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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 _pdfjs = require('./pdfjs');
  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(options) {
  27. _classCallCheck(this, AnnotationLayerBuilder);
  28. this.pageDiv = options.pageDiv;
  29. this.pdfPage = options.pdfPage;
  30. this.renderInteractiveForms = options.renderInteractiveForms;
  31. this.linkService = options.linkService;
  32. this.downloadManager = options.downloadManager;
  33. this.div = null;
  34. }
  35. _createClass(AnnotationLayerBuilder, [{
  36. key: 'render',
  37. value: function render(viewport) {
  38. var _this = this;
  39. var intent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'display';
  40. this.pdfPage.getAnnotations({ intent: intent }).then(function (annotations) {
  41. var parameters = {
  42. viewport: viewport.clone({ dontFlip: true }),
  43. div: _this.div,
  44. annotations: annotations,
  45. page: _this.pdfPage,
  46. renderInteractiveForms: _this.renderInteractiveForms,
  47. linkService: _this.linkService,
  48. downloadManager: _this.downloadManager
  49. };
  50. if (_this.div) {
  51. _pdfjs.AnnotationLayer.update(parameters);
  52. } else {
  53. if (annotations.length === 0) {
  54. return;
  55. }
  56. _this.div = document.createElement('div');
  57. _this.div.className = 'annotationLayer';
  58. _this.pageDiv.appendChild(_this.div);
  59. parameters.div = _this.div;
  60. _pdfjs.AnnotationLayer.render(parameters);
  61. if (typeof _ui_utils.mozL10n !== 'undefined') {
  62. _ui_utils.mozL10n.translate(_this.div);
  63. }
  64. }
  65. });
  66. }
  67. }, {
  68. key: 'hide',
  69. value: function hide() {
  70. if (!this.div) {
  71. return;
  72. }
  73. this.div.setAttribute('hidden', 'true');
  74. }
  75. }]);
  76. return AnnotationLayerBuilder;
  77. }();
  78. var DefaultAnnotationLayerFactory = function () {
  79. function DefaultAnnotationLayerFactory() {
  80. _classCallCheck(this, DefaultAnnotationLayerFactory);
  81. }
  82. _createClass(DefaultAnnotationLayerFactory, [{
  83. key: 'createAnnotationLayerBuilder',
  84. value: function createAnnotationLayerBuilder(pageDiv, pdfPage) {
  85. var renderInteractiveForms = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  86. return new AnnotationLayerBuilder({
  87. pageDiv: pageDiv,
  88. pdfPage: pdfPage,
  89. renderInteractiveForms: renderInteractiveForms,
  90. linkService: new _pdf_link_service.SimpleLinkService()
  91. });
  92. }
  93. }]);
  94. return DefaultAnnotationLayerFactory;
  95. }();
  96. exports.AnnotationLayerBuilder = AnnotationLayerBuilder;
  97. exports.DefaultAnnotationLayerFactory = DefaultAnnotationLayerFactory;