annotation_editor_params.js 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /* Copyright 2022 Mozilla Foundation
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. import { AnnotationEditorParamsType } from "pdfjs-lib";
  16. class AnnotationEditorParams {
  17. /**
  18. * @param {AnnotationEditorParamsOptions} options
  19. * @param {EventBus} eventBus
  20. */
  21. constructor(options, eventBus) {
  22. this.eventBus = eventBus;
  23. this.#bindListeners(options);
  24. }
  25. #bindListeners({
  26. editorFreeTextFontSize,
  27. editorFreeTextColor,
  28. editorInkColor,
  29. editorInkThickness,
  30. editorInkOpacity,
  31. }) {
  32. editorFreeTextFontSize.addEventListener("input", evt => {
  33. this.eventBus.dispatch("switchannotationeditorparams", {
  34. source: this,
  35. type: AnnotationEditorParamsType.FREETEXT_SIZE,
  36. value: editorFreeTextFontSize.valueAsNumber,
  37. });
  38. });
  39. editorFreeTextColor.addEventListener("input", evt => {
  40. this.eventBus.dispatch("switchannotationeditorparams", {
  41. source: this,
  42. type: AnnotationEditorParamsType.FREETEXT_COLOR,
  43. value: editorFreeTextColor.value,
  44. });
  45. });
  46. editorInkColor.addEventListener("input", evt => {
  47. this.eventBus.dispatch("switchannotationeditorparams", {
  48. source: this,
  49. type: AnnotationEditorParamsType.INK_COLOR,
  50. value: editorInkColor.value,
  51. });
  52. });
  53. editorInkThickness.addEventListener("input", evt => {
  54. this.eventBus.dispatch("switchannotationeditorparams", {
  55. source: this,
  56. type: AnnotationEditorParamsType.INK_THICKNESS,
  57. value: editorInkThickness.valueAsNumber,
  58. });
  59. });
  60. editorInkOpacity.addEventListener("input", evt => {
  61. this.eventBus.dispatch("switchannotationeditorparams", {
  62. source: this,
  63. type: AnnotationEditorParamsType.INK_OPACITY,
  64. value: editorInkOpacity.valueAsNumber,
  65. });
  66. });
  67. this.eventBus._on("annotationeditorparamschanged", evt => {
  68. for (const [type, value] of evt.details) {
  69. switch (type) {
  70. case AnnotationEditorParamsType.FREETEXT_SIZE:
  71. editorFreeTextFontSize.value = value;
  72. break;
  73. case AnnotationEditorParamsType.FREETEXT_COLOR:
  74. editorFreeTextColor.value = value;
  75. break;
  76. case AnnotationEditorParamsType.INK_COLOR:
  77. editorInkColor.value = value;
  78. break;
  79. case AnnotationEditorParamsType.INK_THICKNESS:
  80. editorInkThickness.value = value;
  81. break;
  82. case AnnotationEditorParamsType.INK_OPACITY:
  83. editorInkOpacity.value = value;
  84. break;
  85. }
  86. }
  87. });
  88. }
  89. }
  90. export { AnnotationEditorParams };