annotation_layer_builder.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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$renderInteractiv = _ref.renderInteractiveForms,
  39. renderInteractiveForms = _ref$renderInteractiv === undefined ? false : _ref$renderInteractiv,
  40. _ref$l10n = _ref.l10n,
  41. l10n = _ref$l10n === undefined ? _ui_utils.NullL10n : _ref$l10n;
  42. _classCallCheck(this, AnnotationLayerBuilder);
  43. this.pageDiv = pageDiv;
  44. this.pdfPage = pdfPage;
  45. this.linkService = linkService;
  46. this.downloadManager = downloadManager;
  47. this.renderInteractiveForms = renderInteractiveForms;
  48. this.l10n = l10n;
  49. this.div = null;
  50. this._cancelled = false;
  51. }
  52. _createClass(AnnotationLayerBuilder, [{
  53. key: 'render',
  54. value: function render(viewport) {
  55. var _this = this;
  56. var intent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'display';
  57. this.pdfPage.getAnnotations({ intent: intent }).then(function (annotations) {
  58. if (_this._cancelled) {
  59. return;
  60. }
  61. var parameters = {
  62. viewport: viewport.clone({ dontFlip: true }),
  63. div: _this.div,
  64. annotations: annotations,
  65. page: _this.pdfPage,
  66. renderInteractiveForms: _this.renderInteractiveForms,
  67. linkService: _this.linkService,
  68. downloadManager: _this.downloadManager
  69. };
  70. if (_this.div) {
  71. _pdf.AnnotationLayer.update(parameters);
  72. } else {
  73. if (annotations.length === 0) {
  74. return;
  75. }
  76. _this.div = document.createElement('div');
  77. _this.div.className = 'annotationLayer';
  78. _this.pageDiv.appendChild(_this.div);
  79. parameters.div = _this.div;
  80. _pdf.AnnotationLayer.render(parameters);
  81. _this.l10n.translate(_this.div);
  82. }
  83. });
  84. }
  85. }, {
  86. key: 'cancel',
  87. value: function cancel() {
  88. this._cancelled = true;
  89. }
  90. }, {
  91. key: 'hide',
  92. value: function hide() {
  93. if (!this.div) {
  94. return;
  95. }
  96. this.div.setAttribute('hidden', 'true');
  97. }
  98. }]);
  99. return AnnotationLayerBuilder;
  100. }();
  101. var DefaultAnnotationLayerFactory = function () {
  102. function DefaultAnnotationLayerFactory() {
  103. _classCallCheck(this, DefaultAnnotationLayerFactory);
  104. }
  105. _createClass(DefaultAnnotationLayerFactory, [{
  106. key: 'createAnnotationLayerBuilder',
  107. value: function createAnnotationLayerBuilder(pageDiv, pdfPage) {
  108. var renderInteractiveForms = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  109. var l10n = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : _ui_utils.NullL10n;
  110. return new AnnotationLayerBuilder({
  111. pageDiv: pageDiv,
  112. pdfPage: pdfPage,
  113. renderInteractiveForms: renderInteractiveForms,
  114. linkService: new _pdf_link_service.SimpleLinkService(),
  115. l10n: l10n
  116. });
  117. }
  118. }]);
  119. return DefaultAnnotationLayerFactory;
  120. }();
  121. exports.AnnotationLayerBuilder = AnnotationLayerBuilder;
  122. exports.DefaultAnnotationLayerFactory = DefaultAnnotationLayerFactory;