annotation_editor_layer_builder.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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.AnnotationEditorLayerBuilder = void 0;
  27. var _pdf = require("../pdf");
  28. var _l10n_utils = require("./l10n_utils.js");
  29. class AnnotationEditorLayerBuilder {
  30. #uiManager;
  31. constructor(options) {
  32. this.pageDiv = options.pageDiv;
  33. this.pdfPage = options.pdfPage;
  34. this.annotationStorage = options.annotationStorage || null;
  35. this.accessibilityManager = options.accessibilityManager;
  36. this.l10n = options.l10n || _l10n_utils.NullL10n;
  37. this.annotationEditorLayer = null;
  38. this.div = null;
  39. this._cancelled = false;
  40. this.#uiManager = options.uiManager;
  41. }
  42. async render(viewport, intent = "display") {
  43. if (intent !== "display") {
  44. return;
  45. }
  46. if (this._cancelled) {
  47. return;
  48. }
  49. const clonedViewport = viewport.clone({
  50. dontFlip: true
  51. });
  52. if (this.div) {
  53. this.annotationEditorLayer.update({
  54. viewport: clonedViewport
  55. });
  56. this.show();
  57. return;
  58. }
  59. this.div = document.createElement("div");
  60. this.div.className = "annotationEditorLayer";
  61. this.div.tabIndex = 0;
  62. this.pageDiv.append(this.div);
  63. this.annotationEditorLayer = new _pdf.AnnotationEditorLayer({
  64. uiManager: this.#uiManager,
  65. div: this.div,
  66. annotationStorage: this.annotationStorage,
  67. accessibilityManager: this.accessibilityManager,
  68. pageIndex: this.pdfPage._pageIndex,
  69. l10n: this.l10n,
  70. viewport: clonedViewport
  71. });
  72. const parameters = {
  73. viewport: clonedViewport,
  74. div: this.div,
  75. annotations: null,
  76. intent
  77. };
  78. this.annotationEditorLayer.render(parameters);
  79. }
  80. cancel() {
  81. this._cancelled = true;
  82. this.destroy();
  83. }
  84. hide() {
  85. if (!this.div) {
  86. return;
  87. }
  88. this.div.hidden = true;
  89. }
  90. show() {
  91. if (!this.div) {
  92. return;
  93. }
  94. this.div.hidden = false;
  95. }
  96. destroy() {
  97. if (!this.div) {
  98. return;
  99. }
  100. this.pageDiv = null;
  101. this.annotationEditorLayer.destroy();
  102. this.div.remove();
  103. }
  104. }
  105. exports.AnnotationEditorLayerBuilder = AnnotationEditorLayerBuilder;