annotation_layer_builder.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /**
  2. * @licstart The following is the entire license notice for the
  3. * Javascript code in this page
  4. *
  5. * Copyright 2020 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 = void 0;
  27. var _pdf = require("../pdf");
  28. var _ui_utils = require("./ui_utils.js");
  29. var _pdf_link_service = require("./pdf_link_service.js");
  30. class AnnotationLayerBuilder {
  31. constructor({
  32. pageDiv,
  33. pdfPage,
  34. linkService,
  35. downloadManager,
  36. annotationStorage = null,
  37. imageResourcesPath = "",
  38. renderInteractiveForms = true,
  39. l10n = _ui_utils.NullL10n
  40. }) {
  41. this.pageDiv = pageDiv;
  42. this.pdfPage = pdfPage;
  43. this.linkService = linkService;
  44. this.downloadManager = downloadManager;
  45. this.imageResourcesPath = imageResourcesPath;
  46. this.renderInteractiveForms = renderInteractiveForms;
  47. this.l10n = l10n;
  48. this.annotationStorage = annotationStorage;
  49. this.div = null;
  50. this._cancelled = false;
  51. }
  52. render(viewport, intent = "display") {
  53. return this.pdfPage.getAnnotations({
  54. intent
  55. }).then(annotations => {
  56. if (this._cancelled) {
  57. return;
  58. }
  59. if (annotations.length === 0) {
  60. return;
  61. }
  62. const parameters = {
  63. viewport: viewport.clone({
  64. dontFlip: true
  65. }),
  66. div: this.div,
  67. annotations,
  68. page: this.pdfPage,
  69. imageResourcesPath: this.imageResourcesPath,
  70. renderInteractiveForms: this.renderInteractiveForms,
  71. linkService: this.linkService,
  72. downloadManager: this.downloadManager,
  73. annotationStorage: this.annotationStorage
  74. };
  75. if (this.div) {
  76. _pdf.AnnotationLayer.update(parameters);
  77. } else {
  78. this.div = document.createElement("div");
  79. this.div.className = "annotationLayer";
  80. this.pageDiv.appendChild(this.div);
  81. parameters.div = this.div;
  82. _pdf.AnnotationLayer.render(parameters);
  83. this.l10n.translate(this.div);
  84. }
  85. });
  86. }
  87. cancel() {
  88. this._cancelled = true;
  89. }
  90. hide() {
  91. if (!this.div) {
  92. return;
  93. }
  94. this.div.setAttribute("hidden", "true");
  95. }
  96. }
  97. exports.AnnotationLayerBuilder = AnnotationLayerBuilder;
  98. class DefaultAnnotationLayerFactory {
  99. createAnnotationLayerBuilder(pageDiv, pdfPage, annotationStorage = null, imageResourcesPath = "", renderInteractiveForms = true, l10n = _ui_utils.NullL10n) {
  100. return new AnnotationLayerBuilder({
  101. pageDiv,
  102. pdfPage,
  103. imageResourcesPath,
  104. renderInteractiveForms,
  105. linkService: new _pdf_link_service.SimpleLinkService(),
  106. l10n,
  107. annotationStorage
  108. });
  109. }
  110. }
  111. exports.DefaultAnnotationLayerFactory = DefaultAnnotationLayerFactory;