annotation_layer_builder.js 4.3 KB

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