2
0

annotation_layer_builder.js 3.4 KB

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