annotation_editor_layer_builder.js 2.7 KB

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