@pdftools/four-heights-pdf-web-viewer 4.3.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (367) hide show
  1. package/LICENSE.md +446 -0
  2. package/README.md +145 -0
  3. package/css/pdf-web-viewer.css +2407 -0
  4. package/doc/PdfWebViewer.pdf +0 -0
  5. package/es6/common/Checkbox.d.ts +9 -0
  6. package/es6/common/Checkbox.js +8 -0
  7. package/es6/common/Color.d.ts +23 -0
  8. package/es6/common/Color.js +118 -0
  9. package/es6/common/ColorPicker.d.ts +15 -0
  10. package/es6/common/ColorPicker.js +46 -0
  11. package/es6/common/Contextbar.d.ts +6 -0
  12. package/es6/common/Contextbar.js +19 -0
  13. package/es6/common/DragMoveHandler.d.ts +51 -0
  14. package/es6/common/DragMoveHandler.js +175 -0
  15. package/es6/common/Dropdown.d.ts +36 -0
  16. package/es6/common/Dropdown.js +76 -0
  17. package/es6/common/DropdownMenu.d.ts +9 -0
  18. package/es6/common/DropdownMenu.js +10 -0
  19. package/es6/common/DropdownSeparator.d.ts +3 -0
  20. package/es6/common/DropdownSeparator.js +6 -0
  21. package/es6/common/Icon.d.ts +13 -0
  22. package/es6/common/Icon.js +8 -0
  23. package/es6/common/Loader.d.ts +3 -0
  24. package/es6/common/Loader.js +6 -0
  25. package/es6/common/RangeSlider.d.ts +17 -0
  26. package/es6/common/RangeSlider.js +42 -0
  27. package/es6/common/StrokeStylePicker.d.ts +11 -0
  28. package/es6/common/StrokeStylePicker.js +20 -0
  29. package/es6/common/StrokeWidthPicker.d.ts +11 -0
  30. package/es6/common/StrokeWidthPicker.js +20 -0
  31. package/es6/common/Toolbar.d.ts +10 -0
  32. package/es6/common/Toolbar.js +6 -0
  33. package/es6/common/ToolbarButton.d.ts +14 -0
  34. package/es6/common/ToolbarButton.js +21 -0
  35. package/es6/common/ToolbarFileButton.d.ts +15 -0
  36. package/es6/common/ToolbarFileButton.js +27 -0
  37. package/es6/common/ToolbarItemGroup.d.ts +8 -0
  38. package/es6/common/ToolbarItemGroup.js +12 -0
  39. package/es6/common/ToolbarSeparator.d.ts +3 -0
  40. package/es6/common/ToolbarSeparator.js +6 -0
  41. package/es6/common/Tools.d.ts +10 -0
  42. package/es6/common/Tools.js +89 -0
  43. package/es6/common/TooltipManager.d.ts +12 -0
  44. package/es6/common/TooltipManager.js +54 -0
  45. package/es6/common/TranslationManager.d.ts +11 -0
  46. package/es6/common/TranslationManager.js +61 -0
  47. package/es6/common/classNames.d.ts +2 -0
  48. package/es6/common/classNames.js +18 -0
  49. package/es6/common/formatDate.d.ts +1 -0
  50. package/es6/common/formatDate.js +1 -0
  51. package/es6/common/icons.d.ts +13 -0
  52. package/es6/common/icons.js +412 -0
  53. package/es6/common/utils.d.ts +2 -0
  54. package/es6/common/utils.js +19 -0
  55. package/es6/custom/history.d.ts +2 -0
  56. package/es6/custom/history.js +59 -0
  57. package/es6/index.d.ts +5 -0
  58. package/es6/index.js +5 -0
  59. package/es6/lib/hyperapp/index.d.ts +108 -0
  60. package/es6/lib/hyperapp/index.js +327 -0
  61. package/es6/modules/CanvasLayer.d.ts +32 -0
  62. package/es6/modules/CanvasLayer.js +83 -0
  63. package/es6/modules/CanvasModule.d.ts +59 -0
  64. package/es6/modules/CanvasModule.js +98 -0
  65. package/es6/modules/eraser/EraserLayer.d.ts +13 -0
  66. package/es6/modules/eraser/EraserLayer.js +141 -0
  67. package/es6/modules/eraser/EraserModule.d.ts +19 -0
  68. package/es6/modules/eraser/EraserModule.js +34 -0
  69. package/es6/modules/eraser/EraserToolbar.d.ts +10 -0
  70. package/es6/modules/eraser/EraserToolbar.js +30 -0
  71. package/es6/modules/form-fields/CheckBoxWidget.d.ts +9 -0
  72. package/es6/modules/form-fields/CheckBoxWidget.js +45 -0
  73. package/es6/modules/form-fields/ComboBoxWidget.d.ts +22 -0
  74. package/es6/modules/form-fields/ComboBoxWidget.js +152 -0
  75. package/es6/modules/form-fields/EditFormFieldLayer.d.ts +17 -0
  76. package/es6/modules/form-fields/EditFormFieldLayer.js +238 -0
  77. package/es6/modules/form-fields/FormFieldModule.d.ts +15 -0
  78. package/es6/modules/form-fields/FormFieldModule.js +27 -0
  79. package/es6/modules/form-fields/ListBoxWidget.d.ts +9 -0
  80. package/es6/modules/form-fields/ListBoxWidget.js +73 -0
  81. package/es6/modules/form-fields/RadioButtonWidget.d.ts +9 -0
  82. package/es6/modules/form-fields/RadioButtonWidget.js +45 -0
  83. package/es6/modules/form-fields/SelectListWidget.d.ts +9 -0
  84. package/es6/modules/form-fields/SelectListWidget.js +45 -0
  85. package/es6/modules/form-fields/TextBoxWidget.d.ts +9 -0
  86. package/es6/modules/form-fields/TextBoxWidget.js +53 -0
  87. package/es6/modules/form-fields/WidgetBase.d.ts +23 -0
  88. package/es6/modules/form-fields/WidgetBase.js +29 -0
  89. package/es6/modules/freetext-annotation/AddFreetextAnnotationLayer.d.ts +19 -0
  90. package/es6/modules/freetext-annotation/AddFreetextAnnotationLayer.js +181 -0
  91. package/es6/modules/freetext-annotation/AddFreetextAnnotationToolbar.d.ts +21 -0
  92. package/es6/modules/freetext-annotation/AddFreetextAnnotationToolbar.js +37 -0
  93. package/es6/modules/freetext-annotation/EditFreetextAnnotationLayer.d.ts +20 -0
  94. package/es6/modules/freetext-annotation/EditFreetextAnnotationLayer.js +211 -0
  95. package/es6/modules/freetext-annotation/EditFreetextAnnotationToolbar.d.ts +50 -0
  96. package/es6/modules/freetext-annotation/EditFreetextAnnotationToolbar.js +118 -0
  97. package/es6/modules/freetext-annotation/FreetextAnnotationModule.d.ts +28 -0
  98. package/es6/modules/freetext-annotation/FreetextAnnotationModule.js +58 -0
  99. package/es6/modules/freetext-annotation/RichTextEditor.d.ts +31 -0
  100. package/es6/modules/freetext-annotation/RichTextEditor.js +223 -0
  101. package/es6/modules/highlight-annotation/AddHighlightAnnotationLayer.d.ts +31 -0
  102. package/es6/modules/highlight-annotation/AddHighlightAnnotationLayer.js +289 -0
  103. package/es6/modules/highlight-annotation/AddHighlightAnnotationToolbar.d.ts +20 -0
  104. package/es6/modules/highlight-annotation/AddHighlightAnnotationToolbar.js +52 -0
  105. package/es6/modules/highlight-annotation/EditHighlightAnnotationLayer.d.ts +15 -0
  106. package/es6/modules/highlight-annotation/EditHighlightAnnotationLayer.js +104 -0
  107. package/es6/modules/highlight-annotation/EditHighlightAnnotationToolbar.d.ts +15 -0
  108. package/es6/modules/highlight-annotation/EditHighlightAnnotationToolbar.js +28 -0
  109. package/es6/modules/highlight-annotation/HighlightAnnotationModule.d.ts +27 -0
  110. package/es6/modules/highlight-annotation/HighlightAnnotationModule.js +54 -0
  111. package/es6/modules/image-annotations/ImageAnnotationModule.d.ts +23 -0
  112. package/es6/modules/image-annotations/ImageAnnotationModule.js +169 -0
  113. package/es6/modules/index.d.ts +13 -0
  114. package/es6/modules/index.js +13 -0
  115. package/es6/modules/ink-annotation/AddInkAnnotationLayer.d.ts +40 -0
  116. package/es6/modules/ink-annotation/AddInkAnnotationLayer.js +503 -0
  117. package/es6/modules/ink-annotation/AddInkAnnotationToolbar.d.ts +30 -0
  118. package/es6/modules/ink-annotation/AddInkAnnotationToolbar.js +53 -0
  119. package/es6/modules/ink-annotation/EditInkAnnotationLayer.d.ts +20 -0
  120. package/es6/modules/ink-annotation/EditInkAnnotationLayer.js +137 -0
  121. package/es6/modules/ink-annotation/EditInkAnnotationToolbar.d.ts +25 -0
  122. package/es6/modules/ink-annotation/EditInkAnnotationToolbar.js +47 -0
  123. package/es6/modules/ink-annotation/InkAnnotationModule.d.ts +27 -0
  124. package/es6/modules/ink-annotation/InkAnnotationModule.js +50 -0
  125. package/es6/modules/popup/Popup.d.ts +64 -0
  126. package/es6/modules/popup/Popup.js +360 -0
  127. package/es6/modules/popup/PopupLayer.d.ts +31 -0
  128. package/es6/modules/popup/PopupLayer.js +509 -0
  129. package/es6/modules/popup/PopupModule.d.ts +16 -0
  130. package/es6/modules/popup/PopupModule.js +25 -0
  131. package/es6/modules/print-service/PrintServiceDialog.d.ts +30 -0
  132. package/es6/modules/print-service/PrintServiceDialog.js +134 -0
  133. package/es6/modules/print-service/PrintServiceLayer.d.ts +24 -0
  134. package/es6/modules/print-service/PrintServiceLayer.js +310 -0
  135. package/es6/modules/print-service/PrintServiceModule.d.ts +18 -0
  136. package/es6/modules/print-service/PrintServiceModule.js +30 -0
  137. package/es6/modules/shape-annotations/AddShapeAnnotationLayer.d.ts +24 -0
  138. package/es6/modules/shape-annotations/AddShapeAnnotationLayer.js +210 -0
  139. package/es6/modules/shape-annotations/AddShapeAnnotationToolbar.d.ts +26 -0
  140. package/es6/modules/shape-annotations/AddShapeAnnotationToolbar.js +69 -0
  141. package/es6/modules/shape-annotations/EditShapeAnnotationLayer.d.ts +19 -0
  142. package/es6/modules/shape-annotations/EditShapeAnnotationLayer.js +148 -0
  143. package/es6/modules/shape-annotations/EditShapeAnnotationToolbar.d.ts +24 -0
  144. package/es6/modules/shape-annotations/EditShapeAnnotationToolbar.js +57 -0
  145. package/es6/modules/shape-annotations/ShapeAnnotationModule.d.ts +28 -0
  146. package/es6/modules/shape-annotations/ShapeAnnotationModule.js +50 -0
  147. package/es6/modules/stamp-annotation/AddStampAnnotationLayer.d.ts +19 -0
  148. package/es6/modules/stamp-annotation/AddStampAnnotationLayer.js +257 -0
  149. package/es6/modules/stamp-annotation/AddStampAnnotationToolbar.d.ts +17 -0
  150. package/es6/modules/stamp-annotation/AddStampAnnotationToolbar.js +68 -0
  151. package/es6/modules/stamp-annotation/StampAnnotationModule.d.ts +20 -0
  152. package/es6/modules/stamp-annotation/StampAnnotationModule.js +35 -0
  153. package/es6/modules/text-annotation/AddTextAnnotationLayer.d.ts +14 -0
  154. package/es6/modules/text-annotation/AddTextAnnotationLayer.js +132 -0
  155. package/es6/modules/text-annotation/AddTextAnnotationToolbar.d.ts +15 -0
  156. package/es6/modules/text-annotation/AddTextAnnotationToolbar.js +27 -0
  157. package/es6/modules/text-annotation/TextAnnotationModule.d.ts +19 -0
  158. package/es6/modules/text-annotation/TextAnnotationModule.js +34 -0
  159. package/es6/pdf-viewer-api/ImageContainer.d.ts +10 -0
  160. package/es6/pdf-viewer-api/ImageContainer.js +43 -0
  161. package/es6/pdf-viewer-api/PdfViewerApi.d.ts +463 -0
  162. package/es6/pdf-viewer-api/PdfViewerApi.js +732 -0
  163. package/es6/pdf-viewer-api/PdfViewingWrapper.d.ts +178 -0
  164. package/es6/pdf-viewer-api/PdfViewingWrapper.js +2037 -0
  165. package/es6/pdf-viewer-api/annotationDefaultBehaviors.d.ts +3 -0
  166. package/es6/pdf-viewer-api/annotationDefaultBehaviors.js +30 -0
  167. package/es6/pdf-viewer-api/enums.d.ts +100 -0
  168. package/es6/pdf-viewer-api/enums.js +113 -0
  169. package/es6/pdf-viewer-api/index.d.ts +3 -0
  170. package/es6/pdf-viewer-api/index.js +3 -0
  171. package/es6/pdf-viewer-api/types.d.ts +284 -0
  172. package/es6/pdf-viewer-api/types.js +6 -0
  173. package/es6/pdf-viewer-canvas/CanvasEvents.d.ts +76 -0
  174. package/es6/pdf-viewer-canvas/CanvasEvents.js +345 -0
  175. package/es6/pdf-viewer-canvas/PdfViewerCanvas.d.ts +175 -0
  176. package/es6/pdf-viewer-canvas/PdfViewerCanvas.js +1226 -0
  177. package/es6/pdf-viewer-canvas/state/annotations.d.ts +36 -0
  178. package/es6/pdf-viewer-canvas/state/annotations.js +157 -0
  179. package/es6/pdf-viewer-canvas/state/appState.d.ts +10 -0
  180. package/es6/pdf-viewer-canvas/state/appState.js +60 -0
  181. package/es6/pdf-viewer-canvas/state/canvas.d.ts +31 -0
  182. package/es6/pdf-viewer-canvas/state/canvas.js +41 -0
  183. package/es6/pdf-viewer-canvas/state/document.d.ts +50 -0
  184. package/es6/pdf-viewer-canvas/state/document.js +99 -0
  185. package/es6/pdf-viewer-canvas/state/pointer.d.ts +31 -0
  186. package/es6/pdf-viewer-canvas/state/pointer.js +31 -0
  187. package/es6/pdf-viewer-canvas/state/scroll.d.ts +22 -0
  188. package/es6/pdf-viewer-canvas/state/scroll.js +25 -0
  189. package/es6/pdf-viewer-canvas/state/search.d.ts +36 -0
  190. package/es6/pdf-viewer-canvas/state/search.js +27 -0
  191. package/es6/pdf-viewer-canvas/state/store.d.ts +39 -0
  192. package/es6/pdf-viewer-canvas/state/store.js +52 -0
  193. package/es6/pdf-viewer-canvas/state/viewer.d.ts +91 -0
  194. package/es6/pdf-viewer-canvas/state/viewer.js +175 -0
  195. package/es6/pdf-viewer-canvas/view-layers/AnnotationSelectionLayer.d.ts +28 -0
  196. package/es6/pdf-viewer-canvas/view-layers/AnnotationSelectionLayer.js +452 -0
  197. package/es6/pdf-viewer-canvas/view-layers/BusyStateLayer.d.ts +9 -0
  198. package/es6/pdf-viewer-canvas/view-layers/BusyStateLayer.js +25 -0
  199. package/es6/pdf-viewer-canvas/view-layers/PdfDocumentLayer.d.ts +10 -0
  200. package/es6/pdf-viewer-canvas/view-layers/PdfDocumentLayer.js +149 -0
  201. package/es6/pdf-viewer-canvas/view-layers/ScrollLayer.d.ts +48 -0
  202. package/es6/pdf-viewer-canvas/view-layers/ScrollLayer.js +308 -0
  203. package/es6/pdf-viewer-canvas/view-layers/TextSelectionLayer.d.ts +19 -0
  204. package/es6/pdf-viewer-canvas/view-layers/TextSelectionLayer.js +289 -0
  205. package/es6/pdf-viewer-canvas/view-layers/ViewLayerBase.d.ts +31 -0
  206. package/es6/pdf-viewer-canvas/view-layers/ViewLayerBase.js +106 -0
  207. package/es6/pdf-viewer-canvas/view-layers/canvasShapes.d.ts +11 -0
  208. package/es6/pdf-viewer-canvas/view-layers/canvasShapes.js +149 -0
  209. package/es6/pdf-viewer-canvas/view-layers/canvasUtlis.d.ts +3 -0
  210. package/es6/pdf-viewer-canvas/view-layers/canvasUtlis.js +10 -0
  211. package/es6/pdf-viewer-canvas/view-layers/views/AnnotationBorder.d.ts +52 -0
  212. package/es6/pdf-viewer-canvas/view-layers/views/AnnotationBorder.js +377 -0
  213. package/es6/pdf-viewer-canvas/view-layers/views/AnnotationContextBar.d.ts +47 -0
  214. package/es6/pdf-viewer-canvas/view-layers/views/AnnotationContextBar.js +102 -0
  215. package/es6/pdf-viewer-canvas/view-layers/views/TextSelectionContextBar.d.ts +14 -0
  216. package/es6/pdf-viewer-canvas/view-layers/views/TextSelectionContextBar.js +36 -0
  217. package/es6/pdf-viewing/PdfViewing.d.ts +4865 -0
  218. package/es6/pdf-viewing/PdfViewing.js +9611 -0
  219. package/es6/pdf-web-viewer/PdfWebViewer.d.ts +372 -0
  220. package/es6/pdf-web-viewer/PdfWebViewer.js +1386 -0
  221. package/es6/pdf-web-viewer/UserSettings.d.ts +8 -0
  222. package/es6/pdf-web-viewer/UserSettings.js +40 -0
  223. package/es6/pdf-web-viewer/WebViewerOptions.d.ts +387 -0
  224. package/es6/pdf-web-viewer/WebViewerOptions.js +582 -0
  225. package/es6/pdf-web-viewer/state/index.d.ts +80 -0
  226. package/es6/pdf-web-viewer/state/index.js +98 -0
  227. package/es6/pdf-web-viewer/state/layout.d.ts +24 -0
  228. package/es6/pdf-web-viewer/state/layout.js +21 -0
  229. package/es6/pdf-web-viewer/state/mobile.d.ts +16 -0
  230. package/es6/pdf-web-viewer/state/mobile.js +11 -0
  231. package/es6/pdf-web-viewer/state/navigationPanel.d.ts +61 -0
  232. package/es6/pdf-web-viewer/state/navigationPanel.js +84 -0
  233. package/es6/pdf-web-viewer/state/passwordForm.d.ts +18 -0
  234. package/es6/pdf-web-viewer/state/passwordForm.js +21 -0
  235. package/es6/pdf-web-viewer/state/pdfDocument.d.ts +31 -0
  236. package/es6/pdf-web-viewer/state/pdfDocument.js +41 -0
  237. package/es6/pdf-web-viewer/state/search.d.ts +29 -0
  238. package/es6/pdf-web-viewer/state/search.js +23 -0
  239. package/es6/pdf-web-viewer/views/App.d.ts +4 -0
  240. package/es6/pdf-web-viewer/views/App.js +19 -0
  241. package/es6/pdf-web-viewer/views/CustomButtons.d.ts +9 -0
  242. package/es6/pdf-web-viewer/views/CustomButtons.js +18 -0
  243. package/es6/pdf-web-viewer/views/DropZone.d.ts +9 -0
  244. package/es6/pdf-web-viewer/views/DropZone.js +53 -0
  245. package/es6/pdf-web-viewer/views/Layout.d.ts +4 -0
  246. package/es6/pdf-web-viewer/views/Layout.js +22 -0
  247. package/es6/pdf-web-viewer/views/annotationbar/Annotationbar.d.ts +4 -0
  248. package/es6/pdf-web-viewer/views/annotationbar/Annotationbar.js +21 -0
  249. package/es6/pdf-web-viewer/views/appbar/AddonsToolbar.d.ts +4 -0
  250. package/es6/pdf-web-viewer/views/appbar/AddonsToolbar.js +35 -0
  251. package/es6/pdf-web-viewer/views/appbar/AnnotationsMenu.d.ts +4 -0
  252. package/es6/pdf-web-viewer/views/appbar/AnnotationsMenu.js +22 -0
  253. package/es6/pdf-web-viewer/views/appbar/AppBar.d.ts +4 -0
  254. package/es6/pdf-web-viewer/views/appbar/AppBar.js +26 -0
  255. package/es6/pdf-web-viewer/views/appbar/DocumentBar.d.ts +4 -0
  256. package/es6/pdf-web-viewer/views/appbar/DocumentBar.js +36 -0
  257. package/es6/pdf-web-viewer/views/appbar/Menu.d.ts +4 -0
  258. package/es6/pdf-web-viewer/views/appbar/Menu.js +80 -0
  259. package/es6/pdf-web-viewer/views/appbar/NavigationBar.d.ts +4 -0
  260. package/es6/pdf-web-viewer/views/appbar/NavigationBar.js +74 -0
  261. package/es6/pdf-web-viewer/views/appbar/SearchBar.d.ts +4 -0
  262. package/es6/pdf-web-viewer/views/appbar/SearchBar.js +83 -0
  263. package/es6/pdf-web-viewer/views/appbar/SearchOptions.d.ts +10 -0
  264. package/es6/pdf-web-viewer/views/appbar/SearchOptions.js +55 -0
  265. package/es6/pdf-web-viewer/views/appbar/ViewBar.d.ts +4 -0
  266. package/es6/pdf-web-viewer/views/appbar/ViewBar.js +52 -0
  267. package/es6/pdf-web-viewer/views/appbar/ZoomBar.d.ts +4 -0
  268. package/es6/pdf-web-viewer/views/appbar/ZoomBar.js +18 -0
  269. package/es6/pdf-web-viewer/views/modal/ApplicationError.d.ts +4 -0
  270. package/es6/pdf-web-viewer/views/modal/ApplicationError.js +25 -0
  271. package/es6/pdf-web-viewer/views/modal/LoadApplication.d.ts +3 -0
  272. package/es6/pdf-web-viewer/views/modal/LoadApplication.js +6 -0
  273. package/es6/pdf-web-viewer/views/modal/LoadFile.d.ts +3 -0
  274. package/es6/pdf-web-viewer/views/modal/LoadFile.js +10 -0
  275. package/es6/pdf-web-viewer/views/modal/Modal.d.ts +4 -0
  276. package/es6/pdf-web-viewer/views/modal/Modal.js +39 -0
  277. package/es6/pdf-web-viewer/views/modal/OpenFile.d.ts +4 -0
  278. package/es6/pdf-web-viewer/views/modal/OpenFile.js +30 -0
  279. package/es6/pdf-web-viewer/views/modal/OpenFileError.d.ts +4 -0
  280. package/es6/pdf-web-viewer/views/modal/OpenFileError.js +13 -0
  281. package/es6/pdf-web-viewer/views/modal/PasswordForm.d.ts +4 -0
  282. package/es6/pdf-web-viewer/views/modal/PasswordForm.js +54 -0
  283. package/es6/pdf-web-viewer/views/modal/SaveFile.d.ts +4 -0
  284. package/es6/pdf-web-viewer/views/modal/SaveFile.js +10 -0
  285. package/es6/pdf-web-viewer/views/modal/UnsavedChanges.d.ts +4 -0
  286. package/es6/pdf-web-viewer/views/modal/UnsavedChanges.js +32 -0
  287. package/es6/pdf-web-viewer/views/navigation/AnnotationList.d.ts +8 -0
  288. package/es6/pdf-web-viewer/views/navigation/AnnotationList.js +26 -0
  289. package/es6/pdf-web-viewer/views/navigation/AnnotationListItem.d.ts +8 -0
  290. package/es6/pdf-web-viewer/views/navigation/AnnotationListItem.js +158 -0
  291. package/es6/pdf-web-viewer/views/navigation/AnnotationNavigation.d.ts +4 -0
  292. package/es6/pdf-web-viewer/views/navigation/AnnotationNavigation.js +11 -0
  293. package/es6/pdf-web-viewer/views/navigation/NavigationPanel.d.ts +4 -0
  294. package/es6/pdf-web-viewer/views/navigation/NavigationPanel.js +50 -0
  295. package/es6/pdf-web-viewer/views/navigation/OutlineList.d.ts +12 -0
  296. package/es6/pdf-web-viewer/views/navigation/OutlineList.js +19 -0
  297. package/es6/pdf-web-viewer/views/navigation/OutlineNavigation.d.ts +4 -0
  298. package/es6/pdf-web-viewer/views/navigation/OutlineNavigation.js +10 -0
  299. package/es6/pdf-web-viewer/views/navigation/ThumbnailNavigation.d.ts +16 -0
  300. package/es6/pdf-web-viewer/views/navigation/ThumbnailNavigation.js +32 -0
  301. package/package.json +24 -0
  302. package/pdfwebviewer/PdfViewing.data +0 -0
  303. package/pdfwebviewer/PdfViewing_Main.js +1 -0
  304. package/pdfwebviewer/PdfViewing_Main.wasm +0 -0
  305. package/pdfwebviewer/PdfViewing_Worker.js +1 -0
  306. package/pdfwebviewer/PdfViewing_Worker.wasm +0 -0
  307. package/pdfwebviewer/pdf-web-viewer.css +2407 -0
  308. package/pdfwebviewer/pdf-web-viewer.development.js +25955 -0
  309. package/pdfwebviewer/pdf-web-viewer.min.js +1 -0
  310. package/pdfwebviewer/translations.de.json +151 -0
  311. package/pdfwebviewer/translations.en.json +151 -0
  312. package/pdfwebviewer/translations.fr.json +151 -0
  313. package/pdfwebviewer/translations.it.json +151 -0
  314. package/scss/common/_breakpoints.scss +44 -0
  315. package/scss/common/_buttons.scss +42 -0
  316. package/scss/common/_colorpicker.scss +89 -0
  317. package/scss/common/_common.scss +21 -0
  318. package/scss/common/_contextbar.scss +44 -0
  319. package/scss/common/_dropdown.scss +176 -0
  320. package/scss/common/_icon.scss +9 -0
  321. package/scss/common/_index.scss +19 -0
  322. package/scss/common/_loader.scss +30 -0
  323. package/scss/common/_rangeslider.scss +24 -0
  324. package/scss/common/_scrollbars.scss +64 -0
  325. package/scss/common/_stroke-style-picker.scss +64 -0
  326. package/scss/common/_stroke-width-picker.scss +23 -0
  327. package/scss/common/_toolbar.scss +117 -0
  328. package/scss/common/_tooltip.scss +39 -0
  329. package/scss/modules/_eraser.scss +28 -0
  330. package/scss/modules/_forms.scss +56 -0
  331. package/scss/modules/_highlightannotation.scss +12 -0
  332. package/scss/modules/_index.scss +5 -0
  333. package/scss/modules/_inkannotation.scss +41 -0
  334. package/scss/modules/_stampannotation.scss +19 -0
  335. package/scss/pdf-viewer-canvas/_annotationborder.scss +107 -0
  336. package/scss/pdf-viewer-canvas/_busy-loader.scss +53 -0
  337. package/scss/pdf-viewer-canvas/_freetexteditor.scss +28 -0
  338. package/scss/pdf-viewer-canvas/_index.scss +7 -0
  339. package/scss/pdf-viewer-canvas/_layout.scss +52 -0
  340. package/scss/pdf-viewer-canvas/_popup.scss +217 -0
  341. package/scss/pdf-viewer-canvas/_printservice.scss +171 -0
  342. package/scss/pdf-viewer-canvas/_textselection.scss +17 -0
  343. package/scss/pdf-web-viewer/_annotationbar.scss +47 -0
  344. package/scss/pdf-web-viewer/_index.scss +8 -0
  345. package/scss/pdf-web-viewer/_layout.scss +63 -0
  346. package/scss/pdf-web-viewer/_modal.scss +186 -0
  347. package/scss/pdf-web-viewer/_navigationpanel.scss +398 -0
  348. package/scss/pdf-web-viewer/_searchbar.scss +47 -0
  349. package/scss/pdf-web-viewer/_toolbar.scss +134 -0
  350. package/scss/pdf-web-viewer/_viewer.scss +54 -0
  351. package/scss/pdf-web-viewer.scss +1 -0
  352. package/scss/themes/default/_light.scss +32 -0
  353. package/scss/themes/default/_mixins.scss +129 -0
  354. package/scss/themes/default/_theme.scss +161 -0
  355. package/scss/themes/pdf-web-viewer.scss +1 -0
  356. package/umd/pdf-web-viewer.development.js +25955 -0
  357. package/umd/pdf-web-viewer.development.js.map +1 -0
  358. package/umd/pdf-web-viewer.min.js +1 -0
  359. package/wasm/PdfViewing.data +0 -0
  360. package/wasm/PdfViewing_Main.js +1 -0
  361. package/wasm/PdfViewing_Main.wasm +0 -0
  362. package/wasm/PdfViewing_Worker.js +1 -0
  363. package/wasm/PdfViewing_Worker.wasm +0 -0
  364. package/wasm/translations.de.json +151 -0
  365. package/wasm/translations.en.json +151 -0
  366. package/wasm/translations.fr.json +151 -0
  367. package/wasm/translations.it.json +151 -0
@@ -0,0 +1,2037 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ var __asyncValues = (this && this.__asyncValues) || function (o) {
11
+ if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
12
+ var m = o[Symbol.asyncIterator], i;
13
+ return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
14
+ function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
15
+ function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
16
+ };
17
+ import { PdfActionType, PdfFitMode, PdfItemCategory, PdfItemType, WidgetType, PdfPageLayoutMode, AnnotationBorderStyle, DocumentChange, RotationDirection, } from './enums';
18
+ import { FileType, } from './types';
19
+ import { annotationDefaultBehaviors } from './annotationDefaultBehaviors';
20
+ import { PdfViewing } from '../pdf-viewing/PdfViewing';
21
+ import { ImageContainer } from './ImageContainer';
22
+ export class PdfViewingWrapper {
23
+ constructor(key, pdfViewerApiOptions) {
24
+ this.pdfDocument = null;
25
+ this.objectUrls = [];
26
+ this.view = null;
27
+ this.textFragmentCache = new Map();
28
+ this.nativeAnnotationCache = new Map();
29
+ this.handleAnnotationCache = new Map();
30
+ this.pageAnnotationCache = new Map();
31
+ this.imageBitmapCache = new Map();
32
+ this.ignoreDocumentPreferences = false;
33
+ this.nativeOutlines = new Map();
34
+ this.devicePixelRatio = window.devicePixelRatio;
35
+ this.xDPI = 0;
36
+ this.yDPI = 0;
37
+ PdfViewing.Sdk.initialize(key, PdfViewing.Sdk.version);
38
+ this.validateViewingSdkVersion();
39
+ this.pdfViewerApiOptions = pdfViewerApiOptions;
40
+ this.licenseFeatures = PdfViewing.Sdk.supportedFeatures;
41
+ this.pdfController = new PdfViewing.ViewerController();
42
+ this.eventListeners = new Map();
43
+ this.viewportSize = new PdfViewing.Pdf.Geometry.Real.Size(0, 0);
44
+ this.pdfStampDocuments = new Map();
45
+ this.registeredPdfStamps = new Map();
46
+ this.attachEventListeners = this.attachEventListeners.bind(this);
47
+ this.onDocumentOpened = this.onDocumentOpened.bind(this);
48
+ this.onViewUpdated = this.onViewUpdated.bind(this);
49
+ this.onImageCreated = this.onImageCreated.bind(this);
50
+ this.onImageRemovedFromCache = this.onImageRemovedFromCache.bind(this);
51
+ this.getAnnotationsFromPage = this.getAnnotationsFromPage.bind(this);
52
+ }
53
+ getIgnoringPreferences() {
54
+ return this.ignoreDocumentPreferences;
55
+ }
56
+ setIgnoringPreferences(ignorePreferences) {
57
+ this.ignoreDocumentPreferences = ignorePreferences;
58
+ }
59
+ open(pdfFile, fdfFiles, password, viewOptions, renderOptions, viewportSize) {
60
+ return new Promise((resolve, reject) => {
61
+ const mapInputDocument = (file, fileType) => {
62
+ try {
63
+ let mimeType = 'application/pdf';
64
+ switch (fileType) {
65
+ case FileType.Fdf:
66
+ mimeType = 'application/vnd.fdf';
67
+ break;
68
+ // case FileType.Xfdf:
69
+ // mimeType = 'application/vnd.adobe.xfdf'
70
+ // break
71
+ }
72
+ const { data } = file;
73
+ let uri = '';
74
+ let httpOptions = new PdfViewing.IO.HttpOptions();
75
+ if (data) {
76
+ uri = URL.createObjectURL(new File([data], pdfFile.sourceTag || '', {
77
+ type: mimeType,
78
+ }));
79
+ }
80
+ else {
81
+ const inputUri = file;
82
+ uri = inputUri.uri;
83
+ if (inputUri.httpOptions) {
84
+ const { headers, mode, cache, credentials, redirect, referrerPolicy } = inputUri.httpOptions;
85
+ if (mode !== undefined ||
86
+ cache !== undefined ||
87
+ credentials !== undefined ||
88
+ redirect !== undefined ||
89
+ referrerPolicy !== undefined) {
90
+ console.warn(`
91
+ You are using a property that has been deprecated for stability reasons on iOS.
92
+ Affected properties are: mode, cache, credentials, redirect, referrerPolicy.
93
+ If you want to continue using one of these properties, please switch to the separate build that is now available at: https://pdftools-public-downloads-production.s3.eu-west-1.amazonaws.com/productkits/VIEWWEB/4.3.6/extended/pdf-tools-four-heights-pdf-web-viewer-4.3.6.tar.gz
94
+ You can read more about this in our docs: https://www.pdf-tools.com/public/downloads/manuals/PdfWebViewer.pdf
95
+ `);
96
+ }
97
+ if (headers) {
98
+ // httpOptions.headers = new PdfViewing.StringMap()
99
+ Object.keys(headers).forEach((key) => {
100
+ var _a;
101
+ (_a = httpOptions.headers) === null || _a === void 0 ? void 0 : _a.set(key, headers[key]);
102
+ });
103
+ }
104
+ httpOptions.credentials = null;
105
+ httpOptions.cache = null;
106
+ httpOptions.mode = null;
107
+ httpOptions.redirect = null;
108
+ httpOptions.referrerPolicy = null;
109
+ }
110
+ }
111
+ return new PdfViewing.IO.InputUri(uri, httpOptions, pdfFile.sourceTag);
112
+ }
113
+ catch (err) {
114
+ throw new Error('failed to create InputDocument');
115
+ }
116
+ };
117
+ const pdfInputFile = mapInputDocument(pdfFile, FileType.Pdf);
118
+ const fdfInputFiles = new PdfViewing.IO.InputDocumentList();
119
+ if (fdfFiles && fdfFiles.length) {
120
+ fdfFiles.forEach((file) => {
121
+ const fdfFile = mapInputDocument(file, FileType.Fdf);
122
+ if (fdfFile) {
123
+ fdfInputFiles.add(fdfFile);
124
+ }
125
+ });
126
+ }
127
+ const mapViewOptions = (viewOptions) => {
128
+ try {
129
+ if (!viewOptions) {
130
+ return null;
131
+ }
132
+ const options = new PdfViewing.Pdf.ViewOptions();
133
+ options.initialDestination = null;
134
+ if (typeof viewOptions.initialFitMode === 'number') {
135
+ options.initialFitMode = this.WwFitModeToViewingFitMode(viewOptions.initialFitMode);
136
+ }
137
+ if (typeof viewOptions.initialPageLayoutMode === 'number') {
138
+ options.initialPageLayoutMode = this.WwPageLayoutToViewingPageLayout(viewOptions.initialPageLayoutMode);
139
+ }
140
+ if (typeof viewOptions.initialPageNumber === 'number' ||
141
+ typeof viewOptions.initialZoom === 'number') {
142
+ const pageNumber = typeof viewOptions.initialPageNumber === 'number' ? viewOptions.initialPageNumber : 1;
143
+ const zoom = typeof viewOptions.initialZoom === 'number' ? viewOptions.initialZoom : null;
144
+ options.initialDestination = new PdfViewing.Pdf.Navigation.LocationZoomDestination(pageNumber, null, null, zoom);
145
+ }
146
+ if (typeof viewportSize === 'object') {
147
+ this.viewportSize = new PdfViewing.Pdf.Geometry.Integer.Size(viewportSize.width, viewportSize.height);
148
+ options.viewportSize = this.viewportSize;
149
+ }
150
+ return options;
151
+ }
152
+ catch (err) {
153
+ console.error(err);
154
+ throw new Error('failed to create View Options');
155
+ }
156
+ };
157
+ const sdkViewOptions = mapViewOptions(viewOptions);
158
+ const mapRenderOptions = (renderOptions) => {
159
+ try {
160
+ if (!renderOptions) {
161
+ return null;
162
+ }
163
+ const options = new PdfViewing.Pdf.RenderOptions();
164
+ if (renderOptions.formFieldHighlightColor) {
165
+ options.formFieldHighlightColor = this.createNativeColor(renderOptions.formFieldHighlightColor);
166
+ }
167
+ if (renderOptions.formFieldRequiredHighlightColor) {
168
+ options.formFieldRequiredHighlightColor = this.createNativeColor(renderOptions.formFieldRequiredHighlightColor);
169
+ }
170
+ // if (renderOptions.annotationFilter) {
171
+ // options.annotationFilter = this.createAnnotationFilter(renderOptions.annotationFilter)
172
+ // }
173
+ return options;
174
+ }
175
+ catch (err) {
176
+ throw new Error('failed to create Render Options');
177
+ }
178
+ };
179
+ const sdkRenderOptions = mapRenderOptions(renderOptions);
180
+ this.pdfController
181
+ .open(pdfInputFile, fdfInputFiles, password)
182
+ .then((document) => {
183
+ this.pdfDocument = document;
184
+ this.onDocumentOpened(document, sdkRenderOptions, sdkViewOptions);
185
+ resolve();
186
+ })
187
+ .catch((error) => {
188
+ console.warn(error);
189
+ reject(error);
190
+ });
191
+ });
192
+ }
193
+ save(saveOptions) {
194
+ const { fileType, annotationFilter, password } = saveOptions || {};
195
+ const _saveOptions = new PdfViewing.Pdf.SaveOptions();
196
+ switch (fileType) {
197
+ case FileType.Fdf:
198
+ _saveOptions.fileType = PdfViewing.IO.FileType.Fdf;
199
+ break;
200
+ // case FileType.Xfdf:
201
+ // type = PdfViewing.IO.FileType.Xfdf
202
+ // break
203
+ default:
204
+ _saveOptions.fileType = PdfViewing.IO.FileType.Pdf;
205
+ }
206
+ _saveOptions.annotationFilter = annotationFilter
207
+ ? this.createAnnotationFilter(annotationFilter)
208
+ : null;
209
+ if (password) {
210
+ _saveOptions.password = password;
211
+ }
212
+ return new Promise((resolve, reject) => {
213
+ if (this.pdfDocument) {
214
+ this.pdfDocument
215
+ .save(_saveOptions)
216
+ .then((file) => {
217
+ const buffer = file.bufferData;
218
+ if (buffer) {
219
+ const blob = new Blob([file.bufferData]);
220
+ file.close();
221
+ resolve(blob);
222
+ }
223
+ else {
224
+ reject('Returned save buffer is null');
225
+ }
226
+ })
227
+ .catch((error) => {
228
+ console.warn(error);
229
+ reject(error);
230
+ });
231
+ }
232
+ else {
233
+ reject('No document opened');
234
+ }
235
+ });
236
+ }
237
+ close() {
238
+ var _a, _b;
239
+ this.nativeAnnotationCache.forEach((annot) => {
240
+ var _a;
241
+ if (annot instanceof PdfViewing.Pdf.Annotations.MarkupAnnotation) {
242
+ (_a = annot.info) === null || _a === void 0 ? void 0 : _a.close();
243
+ }
244
+ annot.close();
245
+ });
246
+ this.nativeAnnotationCache.clear();
247
+ this.handleAnnotationCache.clear();
248
+ this.pageAnnotationCache.clear();
249
+ this.textFragmentCache.clear();
250
+ this.objectUrls.forEach((url) => {
251
+ URL.revokeObjectURL(url);
252
+ });
253
+ this.objectUrls = [];
254
+ this.nativeOutlines.forEach((outline) => {
255
+ outline.close();
256
+ });
257
+ this.nativeOutlines.clear();
258
+ (_a = this.view) === null || _a === void 0 ? void 0 : _a.close();
259
+ (_b = this.pdfDocument) === null || _b === void 0 ? void 0 : _b.close();
260
+ this.pdfDocument = null;
261
+ }
262
+ destroy() {
263
+ if (this.view) {
264
+ this.view.removeEventListener('viewUpdated', this.onViewUpdated);
265
+ this.view.removeEventListener('imageCreated', this.onImageCreated);
266
+ this.view.removeEventListener('imageRemovedFromCache', this.onImageRemovedFromCache);
267
+ }
268
+ this.close();
269
+ this.pdfStampDocuments.forEach((stampDocument) => {
270
+ stampDocument.close();
271
+ });
272
+ this.pdfController.close();
273
+ this.imageBitmapCache.forEach((imageContainer) => {
274
+ imageContainer.destroy();
275
+ });
276
+ this.nativeOutlines.clear();
277
+ this.imageBitmapCache.clear();
278
+ this.textFragmentCache.clear();
279
+ this.nativeAnnotationCache.clear();
280
+ this.handleAnnotationCache.clear();
281
+ this.pageAnnotationCache.clear();
282
+ this.pdfStampDocuments.clear();
283
+ this.registeredPdfStamps.clear();
284
+ }
285
+ registerPdfStampFile(pdfStampFileName, data, onStampCreated) {
286
+ const url = URL.createObjectURL(new File([data], pdfStampFileName, { type: 'application/pdf' }));
287
+ this.objectUrls.push(url);
288
+ this.pdfController
289
+ .openUri(url, null, null, null, null)
290
+ .then((pdfDocument) => {
291
+ const createStamps = () => __awaiter(this, void 0, void 0, function* () {
292
+ var _a, e_1, _b, _c, _d, e_2, _e, _f;
293
+ const pageNumbers = Array.from({ length: pdfDocument.pageCount }, (_, i) => i + 1);
294
+ let maxHeight = 0;
295
+ let maxWidth = 0;
296
+ const stampSizes = {};
297
+ try {
298
+ for (var _g = true, pageNumbers_1 = __asyncValues(pageNumbers), pageNumbers_1_1; pageNumbers_1_1 = yield pageNumbers_1.next(), _a = pageNumbers_1_1.done, !_a;) {
299
+ _c = pageNumbers_1_1.value;
300
+ _g = false;
301
+ try {
302
+ let pageNumber = _c;
303
+ const size = yield pdfDocument.getPagePdfSize(pageNumber);
304
+ stampSizes[pageNumber] = size;
305
+ maxHeight = Math.max(size.height, maxHeight);
306
+ maxWidth = Math.max(size.width, maxWidth);
307
+ }
308
+ finally {
309
+ _g = true;
310
+ }
311
+ }
312
+ }
313
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
314
+ finally {
315
+ try {
316
+ if (!_g && !_a && (_b = pageNumbers_1.return)) yield _b.call(pageNumbers_1);
317
+ }
318
+ finally { if (e_1) throw e_1.error; }
319
+ }
320
+ const MAX_PX_WIDTH = 200;
321
+ const MAX_PX_HEIGHT = 100;
322
+ const scale = Math.max(maxHeight / MAX_PX_HEIGHT, maxWidth / MAX_PX_WIDTH);
323
+ try {
324
+ for (var _h = true, pageNumbers_2 = __asyncValues(pageNumbers), pageNumbers_2_1; pageNumbers_2_1 = yield pageNumbers_2.next(), _d = pageNumbers_2_1.done, !_d;) {
325
+ _f = pageNumbers_2_1.value;
326
+ _h = false;
327
+ try {
328
+ let pageNumber = _f;
329
+ const size = stampSizes[pageNumber];
330
+ const aspectRatio = size.width / size.height;
331
+ const img = yield pdfDocument.renderPage(pageNumber, size.width / scale, size.height / scale, 0);
332
+ const tempCanvas = document.createElement('canvas');
333
+ tempCanvas.width = img.width;
334
+ tempCanvas.height = img.height;
335
+ const tempContext = tempCanvas.getContext('2d');
336
+ const imgData = new ImageData(new Uint8ClampedArray(img.bufferView), img.width, img.height);
337
+ tempContext.putImageData(imgData, 0, 0);
338
+ const thumbnail = tempCanvas.toDataURL('png');
339
+ onStampCreated({
340
+ pdfStampFileName,
341
+ name: `${pdfStampFileName} - ${pageNumber}`,
342
+ pageNumber,
343
+ thumbnail,
344
+ aspectRatio,
345
+ });
346
+ }
347
+ finally {
348
+ _h = true;
349
+ }
350
+ }
351
+ }
352
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
353
+ finally {
354
+ try {
355
+ if (!_h && !_d && (_e = pageNumbers_2.return)) yield _e.call(pageNumbers_2);
356
+ }
357
+ finally { if (e_2) throw e_2.error; }
358
+ }
359
+ });
360
+ this.pdfStampDocuments.set(pdfStampFileName, pdfDocument);
361
+ createStamps();
362
+ })
363
+ .catch((error) => {
364
+ console.warn(error);
365
+ });
366
+ }
367
+ getPageCount() {
368
+ if (this.pdfDocument) {
369
+ return this.pdfDocument.pageCount;
370
+ }
371
+ else {
372
+ return null;
373
+ }
374
+ }
375
+ registerImage(imageBuffer) {
376
+ return new Promise((resolve, reject) => {
377
+ if (this.pdfDocument) {
378
+ const imgBlob = URL.createObjectURL(new Blob([imageBuffer]));
379
+ this.pdfDocument.registerImageUri(imgBlob, null).then((id) => {
380
+ resolve(id);
381
+ });
382
+ }
383
+ });
384
+ }
385
+ registerPdfPage(fileName, pageNumber) {
386
+ return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
387
+ if (this.pdfDocument) {
388
+ const pdfDoc = this.pdfStampDocuments.get(fileName);
389
+ if (!pdfDoc) {
390
+ resolve(0);
391
+ }
392
+ else {
393
+ const registeredPdfStampsKey = `${fileName}__${pageNumber}`;
394
+ const stampRefId = this.registeredPdfStamps.get(registeredPdfStampsKey);
395
+ if (stampRefId) {
396
+ resolve(stampRefId);
397
+ }
398
+ else {
399
+ const id = yield this.pdfDocument.registerPdfPage(pdfDoc, pageNumber);
400
+ this.registeredPdfStamps.set(registeredPdfStampsKey, id);
401
+ resolve(id);
402
+ }
403
+ }
404
+ }
405
+ }));
406
+ }
407
+ getPageNumber() {
408
+ if (this.view) {
409
+ return this.view.pageNumber;
410
+ }
411
+ return 0;
412
+ }
413
+ getFitMode() {
414
+ var _a;
415
+ var fitMode = (_a = this.view) === null || _a === void 0 ? void 0 : _a.fitMode;
416
+ if (fitMode === undefined) {
417
+ throw new Error('Invalid fit mode');
418
+ }
419
+ else {
420
+ return fitMode;
421
+ }
422
+ }
423
+ setFitMode(mode) {
424
+ if (this.view) {
425
+ this.view.fitMode = mode;
426
+ }
427
+ }
428
+ setPageNumber(page) {
429
+ if (this.view) {
430
+ this.view.pageNumber = page;
431
+ }
432
+ }
433
+ getZoom() {
434
+ if (this.view) {
435
+ return this.view.zoom;
436
+ }
437
+ return 0;
438
+ }
439
+ setZoom(zoom, location) {
440
+ if (this.view) {
441
+ if (location) {
442
+ const p = new PdfViewing.Pdf.Geometry.Integer.Point(location.x, location.y);
443
+ this.view.zoomOnLocation(zoom, p);
444
+ }
445
+ else {
446
+ this.view.zoom = zoom;
447
+ }
448
+ }
449
+ }
450
+ getRotation() {
451
+ if (this.view) {
452
+ return this.view.viewRotation;
453
+ }
454
+ return 0;
455
+ }
456
+ setRotation(rotation) {
457
+ if (this.view) {
458
+ this.view.viewRotation = rotation;
459
+ }
460
+ }
461
+ setBorderSize(size) {
462
+ if (this.view) {
463
+ this.view.borderSize = size;
464
+ }
465
+ }
466
+ getBorderSize() {
467
+ if (this.view) {
468
+ return this.view.borderSize;
469
+ }
470
+ return 0;
471
+ }
472
+ suspendDrawing() {
473
+ var _a;
474
+ (_a = this.view) === null || _a === void 0 ? void 0 : _a.suspendDrawing();
475
+ }
476
+ resumeDrawing() {
477
+ var _a;
478
+ (_a = this.view) === null || _a === void 0 ? void 0 : _a.resumeDrawing();
479
+ }
480
+ renderCanvas(ctx, options) {
481
+ var _a;
482
+ if (this.view) {
483
+ // viewport size changed?
484
+ if (this.viewportSize.width != ctx.canvas.width ||
485
+ this.viewportSize.height != ctx.canvas.height) {
486
+ this.viewportSize.width = ctx.canvas.width;
487
+ this.viewportSize.height = ctx.canvas.height;
488
+ this.view.viewportSize = new PdfViewing.Pdf.Geometry.Integer.Size(ctx.canvas.width, ctx.canvas.height);
489
+ }
490
+ const data = (_a = this.view) === null || _a === void 0 ? void 0 : _a.getRenderedResults();
491
+ if (data) {
492
+ this.drawImages(ctx, data, options);
493
+ data.close();
494
+ }
495
+ }
496
+ }
497
+ renderPage(page, width, height, annotationFilter) {
498
+ // TODO: expose rotation
499
+ let renderOptions = null;
500
+ if (annotationFilter) {
501
+ renderOptions = new PdfViewing.Pdf.RenderOptions();
502
+ renderOptions.annotationFilter = this.createAnnotationFilter(annotationFilter);
503
+ }
504
+ return new Promise((resolve, reject) => {
505
+ var _a;
506
+ (_a = this.pdfDocument) === null || _a === void 0 ? void 0 : _a.renderPage(page, width, height, /* rotation = */ 0, renderOptions).then((image) => {
507
+ const imgBuffer = image.bufferView;
508
+ if (!imgBuffer) {
509
+ reject();
510
+ }
511
+ let pageImage = {};
512
+ pageImage.page = page;
513
+ pageImage.imageData = new ImageData(new Uint8ClampedArray(imgBuffer), image.width, image.height);
514
+ image.close();
515
+ resolve(pageImage);
516
+ }).catch((err) => {
517
+ if (err.message !== 'Document was closed before operation could finish') {
518
+ reject(`failed to render page ${page}`);
519
+ }
520
+ });
521
+ });
522
+ }
523
+ rotatePage(pageNumber, direction) {
524
+ var _a;
525
+ const page = (_a = this.pdfDocument) === null || _a === void 0 ? void 0 : _a.pages.get(pageNumber - 1);
526
+ if (page) {
527
+ page.rotatePage(direction === RotationDirection.CLOCKWISE ? 90 : -90);
528
+ this.dispatchEvent('pageChanged', pageNumber);
529
+ }
530
+ }
531
+ getPagePdfSize(page) {
532
+ return new Promise((resolve, reject) => {
533
+ var _a;
534
+ (_a = this.pdfDocument) === null || _a === void 0 ? void 0 : _a.getPagePdfSize(page).then((pageSize) => {
535
+ resolve(pageSize);
536
+ });
537
+ });
538
+ }
539
+ setLicenseKey(key) {
540
+ try {
541
+ PdfViewing.Sdk.initialize(key, PdfViewing.Sdk.version);
542
+ return true;
543
+ }
544
+ catch (error) {
545
+ return false;
546
+ }
547
+ }
548
+ getSupportedFeatures() {
549
+ return PdfViewing.Sdk.supportedFeatures;
550
+ }
551
+ hasChanges() {
552
+ if (this.pdfDocument) {
553
+ const changes = this.pdfDocument.hasChanges;
554
+ let ret = DocumentChange.NONE;
555
+ if (changes & PdfViewing.Pdf.DocumentChange.Annotation) {
556
+ ret = ret | DocumentChange.ANNOTATION;
557
+ }
558
+ if (changes & PdfViewing.Pdf.DocumentChange.Content) {
559
+ ret = ret | DocumentChange.CONTENT;
560
+ }
561
+ return ret;
562
+ }
563
+ return null;
564
+ }
565
+ getSearchIterator(keyword, page, caseSensitive, wrap, regex) {
566
+ var _a;
567
+ try {
568
+ return (_a = this.pdfDocument) === null || _a === void 0 ? void 0 : _a.searchText(keyword, page, caseSensitive, wrap, regex);
569
+ }
570
+ catch (err) {
571
+ if (err.message !== 'Invalid search text') {
572
+ throw err;
573
+ }
574
+ console.warn(err.message);
575
+ }
576
+ }
577
+ getTextFragmentOnPoint(point) {
578
+ var _a;
579
+ const pointOnVp = new PdfViewing.Pdf.Geometry.Integer.Point(point.x, point.y);
580
+ if (this.pdfDocument === null)
581
+ return null;
582
+ try {
583
+ const fragmentList = (_a = this.view) === null || _a === void 0 ? void 0 : _a.getTextFragmentsOnPoint(pointOnVp);
584
+ let frag = null;
585
+ if (fragmentList && fragmentList.size > 0) {
586
+ const nativeFrag = fragmentList.get(0);
587
+ frag = this.createWebViewerFragment(nativeFrag);
588
+ nativeFrag.close();
589
+ fragmentList === null || fragmentList === void 0 ? void 0 : fragmentList.close();
590
+ }
591
+ return frag;
592
+ }
593
+ catch (error) {
594
+ return null;
595
+ }
596
+ }
597
+ getWordOnPoint(point) {
598
+ var _a;
599
+ const pointOnPage = new PdfViewing.Pdf.Geometry.Real.PointOnPage(point.page, point.pdfX, point.pdfY);
600
+ try {
601
+ const selection = (_a = this.view) === null || _a === void 0 ? void 0 : _a.getWordOnPoint(pointOnPage);
602
+ if (selection) {
603
+ const { textArea } = selection;
604
+ if (textArea) {
605
+ const quadrilaterals = [];
606
+ for (let index = 0; index < textArea.size; index++) {
607
+ quadrilaterals.push(textArea.get(index));
608
+ }
609
+ textArea.close();
610
+ selection.close();
611
+ const q = quadrilaterals[0];
612
+ if (q) {
613
+ const { bottomLeft, bottomRight, topRight, topLeft, pageNumber } = q;
614
+ return {
615
+ quadrilaterals,
616
+ startPoint: {
617
+ pdfX: Math.min(bottomLeft.x, bottomRight.x, topRight.x, topLeft.x),
618
+ pdfY: Math.max(bottomLeft.y, bottomRight.y, topRight.y, topLeft.y),
619
+ page: pageNumber,
620
+ },
621
+ endPoint: {
622
+ pdfX: Math.max(bottomLeft.x, bottomRight.x, topRight.x, topLeft.x),
623
+ pdfY: Math.min(bottomLeft.y, bottomRight.y, topRight.y, topLeft.y),
624
+ page: pageNumber,
625
+ },
626
+ };
627
+ }
628
+ }
629
+ }
630
+ }
631
+ catch (e) { }
632
+ return null;
633
+ }
634
+ getTextSelection(startPoint, endPoint) {
635
+ var _a;
636
+ const startPointOnPage = new PdfViewing.Pdf.Geometry.Real.PointOnPage(startPoint.page, startPoint.pdfX, startPoint.pdfY);
637
+ const endPointOnPage = new PdfViewing.Pdf.Geometry.Real.PointOnPage(endPoint.page, endPoint.pdfX, endPoint.pdfY);
638
+ try {
639
+ const selection = (_a = this.view) === null || _a === void 0 ? void 0 : _a.getTextSelection(startPointOnPage, endPointOnPage);
640
+ if (selection) {
641
+ const { textArea } = selection;
642
+ if (textArea) {
643
+ const quadrilaterals = [];
644
+ for (let index = 0; index < textArea.size; index++) {
645
+ quadrilaterals.push(textArea.get(index));
646
+ }
647
+ textArea.close();
648
+ selection.close();
649
+ return {
650
+ quadrilaterals,
651
+ startPoint,
652
+ endPoint,
653
+ };
654
+ }
655
+ }
656
+ }
657
+ catch (e) { }
658
+ return null;
659
+ }
660
+ getRectangularTextSelection(startPoint, endPoint) {
661
+ var _a;
662
+ const startPointOnPage = new PdfViewing.Pdf.Geometry.Real.PointOnPage(startPoint.page, startPoint.pdfX, startPoint.pdfY);
663
+ const endPointOnPage = new PdfViewing.Pdf.Geometry.Real.PointOnPage(endPoint.page, endPoint.pdfX, endPoint.pdfY);
664
+ try {
665
+ const selection = (_a = this.view) === null || _a === void 0 ? void 0 : _a.getRectangularTextSelection(startPointOnPage, endPointOnPage);
666
+ if (selection) {
667
+ const { textArea } = selection;
668
+ if (textArea) {
669
+ const quadrilaterals = [];
670
+ for (let index = 0; index < textArea.size; index++) {
671
+ quadrilaterals.push(textArea.get(index));
672
+ }
673
+ textArea.close();
674
+ selection.close();
675
+ return {
676
+ quadrilaterals,
677
+ startPoint,
678
+ endPoint,
679
+ };
680
+ }
681
+ }
682
+ }
683
+ catch (err) { }
684
+ return null;
685
+ }
686
+ getText(startPoint, endPoint) {
687
+ var _a;
688
+ const startPointOnPage = new PdfViewing.Pdf.Geometry.Real.PointOnPage(startPoint.page, startPoint.pdfX, startPoint.pdfY);
689
+ const endPointOnPage = new PdfViewing.Pdf.Geometry.Real.PointOnPage(endPoint.page, endPoint.pdfX, endPoint.pdfY);
690
+ try {
691
+ const selection = (_a = this.view) === null || _a === void 0 ? void 0 : _a.getTextSelection(startPointOnPage, endPointOnPage);
692
+ if (selection) {
693
+ const { text } = selection;
694
+ selection.close();
695
+ return text;
696
+ }
697
+ }
698
+ catch (e) { }
699
+ return null;
700
+ }
701
+ getTextForRectangularSelection(startPoint, endPoint) {
702
+ var _a;
703
+ const startPointOnPage = new PdfViewing.Pdf.Geometry.Real.PointOnPage(startPoint.page, startPoint.pdfX, startPoint.pdfY);
704
+ const endPointOnPage = new PdfViewing.Pdf.Geometry.Real.PointOnPage(endPoint.page, endPoint.pdfX, endPoint.pdfY);
705
+ try {
706
+ const selection = (_a = this.view) === null || _a === void 0 ? void 0 : _a.getRectangularTextSelection(startPointOnPage, endPointOnPage);
707
+ if (selection) {
708
+ const { text } = selection;
709
+ selection.close();
710
+ return text;
711
+ }
712
+ }
713
+ catch (e) { }
714
+ return null;
715
+ }
716
+ createWebViewerFragment(nativeFragment) {
717
+ const fragment = {};
718
+ fragment.glyphOffsets = nativeFragment.glyphOffsets ? nativeFragment.glyphOffsets : [];
719
+ fragment.text = nativeFragment.text || '';
720
+ // Convert Tetragon to Rect
721
+ const fragRect = nativeFragment.rectangleOnPage;
722
+ if (fragRect) {
723
+ fragment.pdfRect = this.ViewingPdfRect2WwPdfRect(fragRect);
724
+ }
725
+ return fragment;
726
+ }
727
+ getIsOpen() {
728
+ return this.pdfDocument !== null;
729
+ }
730
+ getOutlines(parent) {
731
+ return new Promise((resolve, reject) => {
732
+ if (this.pdfDocument) {
733
+ if (parent !== null) {
734
+ parent = this.nativeOutlines.get(parent.id);
735
+ }
736
+ this.pdfDocument
737
+ .getOutlines(parent)
738
+ .then((outlineList) => {
739
+ const outlines = [];
740
+ for (let i = 0; i < outlineList.size; i++) {
741
+ const nativeOutline = outlineList.get(i);
742
+ const outline = {};
743
+ outline.id = nativeOutline.getHashCode();
744
+ outline.title = nativeOutline.title || '';
745
+ outline.hasDescendants = nativeOutline.hasChildren;
746
+ outline.destination = nativeOutline.destination;
747
+ this.nativeOutlines.set(nativeOutline.getHashCode(), nativeOutline);
748
+ outlines.push(outline);
749
+ }
750
+ outlineList.close();
751
+ resolve(outlines);
752
+ })
753
+ .catch((err) => {
754
+ if (err.message !== 'Document was closed before operation could finish') {
755
+ reject('failed to get outlines');
756
+ }
757
+ });
758
+ }
759
+ else {
760
+ reject();
761
+ }
762
+ });
763
+ }
764
+ goTo(destination) {
765
+ if (destination != null)
766
+ this.goToPage(destination.pageNumber, destination.left, destination.top, destination.zoom);
767
+ }
768
+ goToPage(pageNumber, left = null, top = null, zoom = null) {
769
+ if (this.view) {
770
+ const nativeDest = new PdfViewing.Pdf.Navigation.LocationZoomDestination(pageNumber, left, top, zoom);
771
+ this.view.goToDestination(nativeDest);
772
+ }
773
+ }
774
+ goToRectangle(rectangle) {
775
+ if (this.view) {
776
+ const rectangleOnPage = new PdfViewing.Pdf.Geometry.Real.RectangleOnPage(rectangle.page, rectangle.pdfX, rectangle.pdfY, rectangle.pdfW, rectangle.pdfH);
777
+ this.view.goToRectangle(rectangleOnPage);
778
+ }
779
+ }
780
+ getAnnotationsFromPage(page) {
781
+ return new Promise((resolve, reject) => {
782
+ var _a;
783
+ (_a = this.pdfDocument) === null || _a === void 0 ? void 0 : _a.getAnnotations(page).then((annotList) => {
784
+ var _a;
785
+ const annotRet = {};
786
+ annotRet.page = page;
787
+ annotRet.itemCategory = 1;
788
+ annotRet.items = [];
789
+ for (let i = 0; i < annotList.size; i++) {
790
+ const nativeAnnot = annotList.get(i);
791
+ const ww_annot = this.createWebViewerAnnotation(nativeAnnot, page);
792
+ if (ww_annot) {
793
+ annotRet.items.push(ww_annot);
794
+ this.nativeAnnotationCache.set(ww_annot.id, nativeAnnot);
795
+ this.handleAnnotationCache.set(ww_annot.id, ww_annot);
796
+ if (!this.pageAnnotationCache.has(page)) {
797
+ this.pageAnnotationCache.set(page, []);
798
+ }
799
+ (_a = this.pageAnnotationCache.get(page)) === null || _a === void 0 ? void 0 : _a.push(ww_annot);
800
+ }
801
+ }
802
+ resolve(annotRet);
803
+ }).catch((err) => {
804
+ if (err.message !== 'Document was closed before operation could finish') {
805
+ reject(`Failed to get annotations for page ${page}, ${err}`);
806
+ }
807
+ });
808
+ });
809
+ }
810
+ deleteItem(item) {
811
+ return this.deleteAnnotation(item);
812
+ }
813
+ validateViewingSdkVersion() {
814
+ const parseVersionString = (versionString) => {
815
+ const match = versionString.match(/(\d+)\.(\d+)\.(\d+)[\-]{0,1}(\w*)[\.]{0,1}(\d*)/);
816
+ if (match) {
817
+ return {
818
+ major: parseInt(match[1]),
819
+ minor: parseInt(match[2]),
820
+ patch: parseInt(match[3]),
821
+ type: match[4],
822
+ buildId: parseInt(match[5]),
823
+ };
824
+ }
825
+ };
826
+ // 4.3.6-rc.17600 will be replaced with the current PdfViewing SDK Version by webpack
827
+ const requiredSdk = parseVersionString('4.3.6-rc.17600');
828
+ const currentSdk = parseVersionString(PdfViewing.Sdk.version);
829
+ if (requiredSdk && currentSdk) {
830
+ const valid = requiredSdk.major === currentSdk.major &&
831
+ requiredSdk.minor === currentSdk.minor &&
832
+ requiredSdk.patch === currentSdk.patch &&
833
+ (requiredSdk.type ? requiredSdk.buildId === currentSdk.buildId : true);
834
+ if (!valid) {
835
+ console.warn(`**************************************
836
+ Version mismatch between PDF Viewing SDK and PDF Web Viewer
837
+
838
+ Most likely, the static assets of the PDF Viewing SDK have not been copied to the configured location. For more information please consult the documentation ("static assets").
839
+
840
+ Current version: ${currentSdk.major}.${currentSdk.minor}.${currentSdk.patch}
841
+ Required version: ${requiredSdk.major}.${requiredSdk.minor}.${requiredSdk.patch}${requiredSdk.type ? ` (${requiredSdk.type.toUpperCase()} version)` : ''}
842
+
843
+ **************************************`);
844
+ }
845
+ }
846
+ else {
847
+ console.warn('The PDF Viewing SDK version number has an incorrect format');
848
+ }
849
+ }
850
+ deleteAnnotation(item) {
851
+ return new Promise((resolve, reject) => {
852
+ var _a;
853
+ const id = item.id;
854
+ const nativeAnnot = this.nativeAnnotationCache.get(id);
855
+ const page = item.page;
856
+ if (nativeAnnot) {
857
+ (_a = this.pdfDocument) === null || _a === void 0 ? void 0 : _a.deleteAnnotation(nativeAnnot).then(() => {
858
+ nativeAnnot.close();
859
+ this.nativeAnnotationCache.delete(id);
860
+ this.handleAnnotationCache.delete(id);
861
+ this.dispatchEvent('itemDeleted', { page, id, categoryType: 1 });
862
+ this.dispatchEvent('pageChanged', page);
863
+ resolve();
864
+ });
865
+ }
866
+ });
867
+ }
868
+ getItem(id) {
869
+ if (this.handleAnnotationCache.has(id)) {
870
+ return this.handleAnnotationCache.get(id);
871
+ }
872
+ return null;
873
+ }
874
+ createItem(item) {
875
+ return this.createAnnotation(item);
876
+ }
877
+ createAnnotationFilter(annotationFilter) {
878
+ return (annot) => {
879
+ const { pageNumber } = annot.boundingBox;
880
+ const ww_annot = this.createWebViewerAnnotation(annot, pageNumber);
881
+ annot.close();
882
+ const res = annotationFilter(ww_annot);
883
+ return res;
884
+ };
885
+ }
886
+ createMarkupAnnotation(item) {
887
+ const color = this.createNativeColor(item.color);
888
+ const fillColor = this.createNativeColor(item.fillColor);
889
+ let borderStyle = PdfViewing.Pdf.Annotations.BorderStyleType.Lined;
890
+ const stroke = new PdfViewing.Pdf.Annotations.AnnotationStroke();
891
+ if (item.border) {
892
+ stroke.lineWidth = item.border.width;
893
+ borderStyle = this.convertToNativeBorderStyle(item.border.style);
894
+ if (item.border.style === 1) {
895
+ stroke.dashArray = [item.border.width];
896
+ }
897
+ }
898
+ const bbox = new PdfViewing.Pdf.Geometry.Real.RectangleOnPage(item.pdfRect.page, item.pdfRect.pdfX, item.pdfRect.pdfY, item.pdfRect.pdfW, item.pdfRect.pdfH);
899
+ switch (item.itemType) {
900
+ case 1: // Sticky Note
901
+ const stickyOrigin = new PdfViewing.Pdf.Geometry.Real.PointOnPage(item.pdfRect.page, item.pdfRect.pdfX, item.pdfRect.pdfY);
902
+ return PdfViewing.Pdf.Annotations.StickyNote.create(stickyOrigin, '', color);
903
+ case 3: // Freetext
904
+ return PdfViewing.Pdf.Annotations.FreeText.create(bbox, item.richtext, color, stroke, this.view ? this.view.viewRotation : PdfViewing.Pdf.Geometry.Rotation.NoRotation);
905
+ case 5: // Rectangle
906
+ return PdfViewing.Pdf.Annotations.RectangleAnnotation.create(bbox, stroke.lineWidth ? color : null, stroke, borderStyle, fillColor);
907
+ case 6: // Ellipse
908
+ return PdfViewing.Pdf.Annotations.EllipseAnnotation.create(bbox, stroke.lineWidth ? color : null, stroke, borderStyle, fillColor);
909
+ case 9: // Highlight
910
+ return PdfViewing.Pdf.Annotations.Highlight.create(this.createQuadrilateralList(item.quadrilaterals), color);
911
+ case 10: // Underline
912
+ return PdfViewing.Pdf.Annotations.Underline.create(this.createQuadrilateralList(item.quadrilaterals), color);
913
+ case 11: // Squiggly
914
+ return PdfViewing.Pdf.Annotations.Squiggly.create(this.createQuadrilateralList(item.quadrilaterals), color);
915
+ case 12: // StrikeThrough
916
+ return PdfViewing.Pdf.Annotations.StrikeThrough.create(this.createQuadrilateralList(item.quadrilaterals), color);
917
+ case 13: // Text Stamp
918
+ if (item.stampText) {
919
+ return PdfViewing.Pdf.Annotations.CustomTextStamp.create(bbox, item.stampText, item.stampColor, this.view ? this.view.viewRotation : PdfViewing.Pdf.Geometry.Rotation.NoRotation);
920
+ }
921
+ else if (item.imageId) {
922
+ return PdfViewing.Pdf.Annotations.CustomImageStamp.create(bbox, item.imageId, this.view ? this.view.viewRotation : PdfViewing.Pdf.Geometry.Rotation.NoRotation);
923
+ }
924
+ else {
925
+ throw new Error(`createAnnotation: Unknown custom stamp annotation`);
926
+ }
927
+ case 15: // Ink
928
+ const inkList = item.inkList;
929
+ const path = new PdfViewing.Pdf.Geometry.Real.Path();
930
+ if (inkList) {
931
+ const pathGen = new PdfViewing.Pdf.Geometry.Real.PathGenerator(path);
932
+ for (let i = 0; i < inkList.length; i++) {
933
+ pathGen.moveTo(new PdfViewing.Pdf.Geometry.Real.Point(inkList[i][0], inkList[i][1]));
934
+ for (let j = 2; j < inkList[i].length; j += 2) {
935
+ pathGen.lineTo(new PdfViewing.Pdf.Geometry.Real.Point(inkList[i][j], inkList[i][j + 1]));
936
+ }
937
+ }
938
+ pathGen.close();
939
+ }
940
+ return PdfViewing.Pdf.Annotations.InkAnnotation.create(item.page, path, color, stroke);
941
+ default:
942
+ throw new Error(`createAnnotation: Type not implemented: ${item.itemType}`);
943
+ }
944
+ }
945
+ createAnnotation(item) {
946
+ let annot = this.createMarkupAnnotation(item);
947
+ const page = item.page;
948
+ // Set general properties
949
+ annot.info.author = item.author || '';
950
+ return new Promise((resolve, reject) => {
951
+ var _a;
952
+ (_a = this.pdfDocument) === null || _a === void 0 ? void 0 : _a.createAnnotation(annot).then(() => {
953
+ const ww_annot = this.createWebViewerAnnotation(annot, item.page);
954
+ if (ww_annot) {
955
+ this.nativeAnnotationCache.set(ww_annot.id, annot);
956
+ this.handleAnnotationCache.set(ww_annot.id, ww_annot);
957
+ this.dispatchEvent('itemCreated', ww_annot);
958
+ this.dispatchEvent('pageChanged', page);
959
+ resolve(ww_annot);
960
+ }
961
+ reject('Failed to create Web Viewer annotation');
962
+ }).catch((error) => {
963
+ reject(error);
964
+ });
965
+ });
966
+ }
967
+ createQuadrilateralList(quadrilaterals) {
968
+ const quadrilateralList = new PdfViewing.Pdf.Geometry.Real.QuadrilateralList();
969
+ for (let i = 0; i < quadrilaterals.length; i++) {
970
+ const q = quadrilaterals[i];
971
+ quadrilateralList.add(new PdfViewing.Pdf.Geometry.Real.QuadrilateralOnPage(q.pageNumber, new PdfViewing.Pdf.Geometry.Real.Point(q.bottomLeft.x, q.bottomLeft.y), new PdfViewing.Pdf.Geometry.Real.Point(q.bottomRight.x, q.bottomRight.y), new PdfViewing.Pdf.Geometry.Real.Point(q.topRight.x, q.topRight.y), new PdfViewing.Pdf.Geometry.Real.Point(q.topLeft.x, q.topLeft.y)));
972
+ }
973
+ return quadrilateralList;
974
+ }
975
+ convertToNativeBorderStyle(style) {
976
+ switch (style) {
977
+ case 0:
978
+ return PdfViewing.Pdf.Annotations.BorderStyleType.Lined;
979
+ case 2:
980
+ return PdfViewing.Pdf.Annotations.BorderStyleType.Beveled;
981
+ case 3:
982
+ return PdfViewing.Pdf.Annotations.BorderStyleType.Inset;
983
+ case 4:
984
+ return PdfViewing.Pdf.Annotations.BorderStyleType.Underline;
985
+ default:
986
+ return PdfViewing.Pdf.Annotations.BorderStyleType.Lined;
987
+ }
988
+ }
989
+ convertToWebViewerBorderStyle(style) {
990
+ switch (style) {
991
+ case PdfViewing.Pdf.Annotations.BorderStyleType.Lined:
992
+ return 0;
993
+ case PdfViewing.Pdf.Annotations.BorderStyleType.Beveled:
994
+ return 2;
995
+ case PdfViewing.Pdf.Annotations.BorderStyleType.Inset:
996
+ return 3;
997
+ case PdfViewing.Pdf.Annotations.BorderStyleType.Underline:
998
+ return 4;
999
+ default:
1000
+ return 0;
1001
+ }
1002
+ }
1003
+ updateItem(item) {
1004
+ return new Promise((resolve, reject) => {
1005
+ var _a, _b;
1006
+ if (item.itemType === PdfItemType.WIDGET) {
1007
+ (_a = this.pdfDocument) === null || _a === void 0 ? void 0 : _a.editAnnotation(item.widget).then(() => {
1008
+ // this.dispatchEvent('itemUpdated', item)
1009
+ this.dispatchEvent('pageChanged', item.widget.boundingBox.pageNumber);
1010
+ resolve(item);
1011
+ }).catch((error) => {
1012
+ reject(error);
1013
+ });
1014
+ }
1015
+ else {
1016
+ const nativeAnnot = this.nativeAnnotationCache.get(item.id);
1017
+ if (nativeAnnot) {
1018
+ const rotationChanged = item.hasOwnProperty('rotation') &&
1019
+ item.rotation % 360 !== nativeAnnot.rotation % 360;
1020
+ if (!rotationChanged) {
1021
+ const bbox = new PdfViewing.Pdf.Geometry.Real.RectangleOnPage(item.pdfRect.page, item.pdfRect.pdfX, item.pdfRect.pdfY, item.pdfRect.pdfW, item.pdfRect.pdfH);
1022
+ nativeAnnot.boundingBox = bbox;
1023
+ }
1024
+ let nativeColor = null;
1025
+ nativeColor = this.createNativeColor(item.color);
1026
+ const markupAnnot = nativeAnnot;
1027
+ if (markupAnnot && item.privateData) {
1028
+ markupAnnot.privateData = item.privateData;
1029
+ }
1030
+ if (nativeAnnot.popup) {
1031
+ const rect = item.popup.pdfRect;
1032
+ nativeAnnot.popup.boundingBox =
1033
+ new PdfViewing.Pdf.Geometry.Real.RectangleOnPage(rect.page, rect.pdfX, rect.pdfY, rect.pdfW, rect.pdfH);
1034
+ nativeAnnot.popup.isOpen = item.popup.isOpen;
1035
+ }
1036
+ if (markupAnnot && markupAnnot.info) {
1037
+ markupAnnot.info.content = item.content || '';
1038
+ markupAnnot.info.subject = item.subject || '';
1039
+ }
1040
+ if (item.itemType === PdfItemType.TEXT) {
1041
+ const stickyAnnot = nativeAnnot;
1042
+ stickyAnnot.color = nativeColor;
1043
+ }
1044
+ if (item.itemType === PdfItemType.FREE_TEXT) {
1045
+ const freetextAnnot = nativeAnnot;
1046
+ freetextAnnot.richText = item.richText;
1047
+ freetextAnnot.backgroundColor = this.createNativeColor(item.color);
1048
+ const stroke = freetextAnnot.annotationStroke;
1049
+ if (stroke) {
1050
+ stroke.lineWidth = item.border.width;
1051
+ freetextAnnot.annotationStroke = stroke;
1052
+ stroke.close();
1053
+ }
1054
+ if (rotationChanged) {
1055
+ freetextAnnot.rotation = item.rotation;
1056
+ item.pdfRect = {
1057
+ page: freetextAnnot.boundingBox.pageNumber,
1058
+ pdfX: freetextAnnot.boundingBox.x,
1059
+ pdfY: freetextAnnot.boundingBox.y,
1060
+ pdfW: freetextAnnot.boundingBox.width,
1061
+ pdfH: freetextAnnot.boundingBox.height,
1062
+ };
1063
+ }
1064
+ }
1065
+ if (item.itemType === PdfItemType.INK) {
1066
+ const inkAnnotation = nativeAnnot;
1067
+ const inkAnnot = item;
1068
+ inkAnnotation.strokeColor = nativeColor;
1069
+ const { annotationStroke } = inkAnnotation;
1070
+ if (annotationStroke) {
1071
+ annotationStroke.lineWidth = item.border.width;
1072
+ inkAnnotation.annotationStroke = annotationStroke;
1073
+ }
1074
+ const { path } = inkAnnotation;
1075
+ const { vertices } = path;
1076
+ vertices.clear();
1077
+ for (let line of inkAnnot.inkList) {
1078
+ let isFirstPoint = true;
1079
+ for (let point of line) {
1080
+ if (isFirstPoint) {
1081
+ vertices.add(new PdfViewing.Pdf.Geometry.Real.Vertex(inkAnnot.page, point.x, point.y, PdfViewing.Pdf.Geometry.Real.PathOperation.MoveTo));
1082
+ isFirstPoint = false;
1083
+ }
1084
+ else {
1085
+ vertices.add(new PdfViewing.Pdf.Geometry.Real.Vertex(inkAnnot.page, point.x, point.y, PdfViewing.Pdf.Geometry.Real.PathOperation.LineTo));
1086
+ }
1087
+ }
1088
+ }
1089
+ path.vertices = vertices;
1090
+ inkAnnotation.setPath(path);
1091
+ }
1092
+ if (item.itemType === PdfItemType.SQUARE || item.itemType === PdfItemType.CIRCLE) {
1093
+ // ! using square annotation type because there is no common base class
1094
+ const shapeAnnotation = nativeAnnot;
1095
+ // update stroke
1096
+ const { annotationStroke } = shapeAnnotation;
1097
+ if (annotationStroke) {
1098
+ annotationStroke.lineWidth = item.border.width;
1099
+ if (item.border.style === 1) {
1100
+ annotationStroke.dashArray = [item.border.width];
1101
+ }
1102
+ else {
1103
+ annotationStroke.dashArray = [0];
1104
+ }
1105
+ shapeAnnotation.annotationStroke = annotationStroke;
1106
+ }
1107
+ shapeAnnotation.borderStyleType = this.convertToNativeBorderStyle(item.border.style);
1108
+ shapeAnnotation.strokeColor = nativeColor;
1109
+ shapeAnnotation.fillColor = this.createNativeColor(item.fillColor);
1110
+ }
1111
+ if (item.itemType === PdfItemType.HIGHLIGHT ||
1112
+ item.itemType === PdfItemType.SQUIGGLY ||
1113
+ item.itemType === PdfItemType.STRIKE_OUT ||
1114
+ item.itemType === PdfItemType.UNDERLINE) {
1115
+ const textMarkupAnnot = nativeAnnot;
1116
+ textMarkupAnnot.color = nativeColor;
1117
+ }
1118
+ if (item.itemType === PdfItemType.STAMP) {
1119
+ const stampAnnot = nativeAnnot;
1120
+ if (rotationChanged) {
1121
+ stampAnnot.rotation = item.rotation;
1122
+ item.pdfRect = {
1123
+ page: stampAnnot.boundingBox.pageNumber,
1124
+ pdfX: stampAnnot.boundingBox.x,
1125
+ pdfY: stampAnnot.boundingBox.y,
1126
+ pdfW: stampAnnot.boundingBox.width,
1127
+ pdfH: stampAnnot.boundingBox.height,
1128
+ };
1129
+ }
1130
+ }
1131
+ (_b = this.pdfDocument) === null || _b === void 0 ? void 0 : _b.editAnnotation(nativeAnnot).then(() => {
1132
+ const { pageNumber } = nativeAnnot.boundingBox;
1133
+ const updatedItem = this.createWebViewerAnnotation(nativeAnnot, pageNumber);
1134
+ if (updatedItem) {
1135
+ this.handleAnnotationCache.set(item.id, updatedItem);
1136
+ this.dispatchEvent('itemUpdated', updatedItem);
1137
+ this.dispatchEvent('pageChanged', pageNumber);
1138
+ resolve(updatedItem);
1139
+ }
1140
+ else {
1141
+ throw new Error('failed to update item');
1142
+ }
1143
+ }).catch((error) => {
1144
+ reject(error);
1145
+ });
1146
+ }
1147
+ }
1148
+ });
1149
+ }
1150
+ getTextStampAspectRatio(stampText) {
1151
+ return new Promise((resolve, reject) => {
1152
+ var _a;
1153
+ if (this.pdfDocument && this.view) {
1154
+ (_a = this.pdfDocument) === null || _a === void 0 ? void 0 : _a.getTextStampAspectRatio(stampText).then((ratio) => {
1155
+ resolve(ratio);
1156
+ });
1157
+ }
1158
+ else {
1159
+ reject('No document opened');
1160
+ }
1161
+ });
1162
+ }
1163
+ createNativeColor(color) {
1164
+ let red = 0;
1165
+ let green = 0;
1166
+ let blue = 0;
1167
+ let alpha = 0;
1168
+ if (!color) {
1169
+ return new PdfViewing.Pdf.Annotations.Color(red, green, blue, alpha);
1170
+ }
1171
+ color = color.replace(/\s+/gi, '');
1172
+ if (color.indexOf('#') === 0) {
1173
+ if (color.length === 4) {
1174
+ red = parseInt(color.substring(1, 2), 16);
1175
+ green = parseInt(color.substring(2, 3), 16);
1176
+ blue = parseInt(color.substring(3, 4), 16);
1177
+ alpha = 255;
1178
+ }
1179
+ else if (color.length === 5) {
1180
+ red = parseInt(color.substring(1, 2), 16);
1181
+ green = parseInt(color.substring(2, 3), 16);
1182
+ blue = parseInt(color.substring(3, 4), 16);
1183
+ alpha = parseInt(color.substring(4, 5), 16);
1184
+ }
1185
+ else if (color.length === 7) {
1186
+ red = parseInt(color.substring(1, 3), 16);
1187
+ green = parseInt(color.substring(3, 5), 16);
1188
+ blue = parseInt(color.substring(5, 7), 16);
1189
+ alpha = 255;
1190
+ }
1191
+ else if (color.length === 9) {
1192
+ red = parseInt(color.substring(1, 3), 16);
1193
+ green = parseInt(color.substring(3, 5), 16);
1194
+ blue = parseInt(color.substring(5, 7), 16);
1195
+ alpha = parseInt(color.substring(7, 9), 16);
1196
+ }
1197
+ else {
1198
+ throw new Error('invalid color string: ' + color);
1199
+ }
1200
+ }
1201
+ else if (color.indexOf('rgb') === 0) {
1202
+ const values = color.substring(color.indexOf('(') + 1, color.indexOf(')')).split(',');
1203
+ if (values.length < 3 || values.length > 4) {
1204
+ throw new Error('invalid color string: ' + color);
1205
+ }
1206
+ red = parseInt(values[0], 10);
1207
+ green = parseInt(values[1], 10);
1208
+ blue = parseInt(values[2], 10);
1209
+ if (values.length === 4) {
1210
+ alpha = Math.floor(parseFloat(values[3]) * 255);
1211
+ }
1212
+ else {
1213
+ alpha = 255;
1214
+ }
1215
+ }
1216
+ else {
1217
+ throw new Error('invalid color string: ' + color);
1218
+ }
1219
+ return new PdfViewing.Pdf.Annotations.Color(red, green, blue, alpha);
1220
+ }
1221
+ createWebViewerAnnotation(annot, page) {
1222
+ var _a, _b;
1223
+ let ww_annot = {};
1224
+ ww_annot.itemCategory = PdfItemCategory.ANNOTATION;
1225
+ ww_annot.sourceTag = annot.sourceTag;
1226
+ if (annot instanceof PdfViewing.Pdf.Annotations.MarkupAnnotation) {
1227
+ const bbox = annot.boundingBox;
1228
+ if (bbox) {
1229
+ ww_annot.pdfRect = this.ViewingPdfRect2WwPdfRect(bbox);
1230
+ }
1231
+ ww_annot.page = page;
1232
+ ww_annot.privateData = annot.privateData ? annot.privateData : null;
1233
+ const info = annot.info;
1234
+ if (info) {
1235
+ ww_annot.content = info === null || info === void 0 ? void 0 : info.content;
1236
+ ww_annot.author = (info === null || info === void 0 ? void 0 : info.author) || '';
1237
+ ww_annot.id = info === null || info === void 0 ? void 0 : info.getHashCode();
1238
+ ww_annot.modificationDate = (info === null || info === void 0 ? void 0 : info.modificationDate) || null;
1239
+ ww_annot.creationDate = (info === null || info === void 0 ? void 0 : info.creationDate) || null;
1240
+ ww_annot.subject = info === null || info === void 0 ? void 0 : info.subject;
1241
+ }
1242
+ ww_annot.isLocked = () => {
1243
+ const cachedAnnotation = this.nativeAnnotationCache.get(ww_annot.id);
1244
+ if (cachedAnnotation instanceof PdfViewing.Pdf.Annotations.MarkupAnnotation) {
1245
+ const markupAnnot = cachedAnnotation;
1246
+ if (markupAnnot.info) {
1247
+ return markupAnnot.info.locked;
1248
+ }
1249
+ }
1250
+ console.warn('annotation not found');
1251
+ return false;
1252
+ };
1253
+ ww_annot.setLock = (isLocked) => {
1254
+ const cachedAnnotation = this.nativeAnnotationCache.get(ww_annot.id);
1255
+ if (cachedAnnotation instanceof PdfViewing.Pdf.Annotations.MarkupAnnotation) {
1256
+ const markupAnnot = cachedAnnotation;
1257
+ if (markupAnnot.info) {
1258
+ markupAnnot.info.locked = isLocked;
1259
+ }
1260
+ }
1261
+ };
1262
+ if (annot instanceof PdfViewing.Pdf.Annotations.TextMarkup) {
1263
+ ww_annot.color = this.convertColorToRgbaString(annot.color);
1264
+ }
1265
+ ww_annot.isHidden = () => {
1266
+ const cachedAnnotation = this.nativeAnnotationCache.get(ww_annot.id);
1267
+ if (!cachedAnnotation) {
1268
+ console.warn('annotation not found');
1269
+ return false;
1270
+ }
1271
+ return cachedAnnotation.hidden;
1272
+ };
1273
+ ww_annot.setHidden = (isHidden) => {
1274
+ const cachedAnnotation = this.nativeAnnotationCache.get(ww_annot.id);
1275
+ if (!cachedAnnotation) {
1276
+ console.warn('annotation not found');
1277
+ return false;
1278
+ }
1279
+ return (cachedAnnotation.hidden = isHidden);
1280
+ };
1281
+ ww_annot.border = {};
1282
+ this.addPopup(ww_annot, annot);
1283
+ if (annot instanceof PdfViewing.Pdf.Annotations.StickyNote) {
1284
+ ww_annot.color = this.convertColorToRgbaString(annot.color);
1285
+ ww_annot.itemType = PdfItemType.TEXT;
1286
+ }
1287
+ else if (annot instanceof PdfViewing.Pdf.Annotations.FreeText) {
1288
+ ww_annot.itemType = PdfItemType.FREE_TEXT;
1289
+ const freetextAnnot = annot;
1290
+ const ww_freetextAnnot = ww_annot;
1291
+ ww_freetextAnnot.richText =
1292
+ freetextAnnot.richText ||
1293
+ `<?xml version="1.0"?><body xmlns="http://www.w3.org/1999/xhtml" xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/" xfa:APIVersion="Acrobat:21.11.0" xfa:spec="2.0.2" style="color:#000000;font-family:Helvetica;font-size:12pt;"><p>${annot.info.content}</p></body>`;
1294
+ ww_freetextAnnot.rotation = freetextAnnot.rotation;
1295
+ ww_freetextAnnot.color = this.convertColorToRgbaString(freetextAnnot.backgroundColor);
1296
+ const stroke = freetextAnnot.annotationStroke;
1297
+ if (stroke) {
1298
+ ww_freetextAnnot.border.width = stroke === null || stroke === void 0 ? void 0 : stroke.lineWidth;
1299
+ ww_freetextAnnot.border.style = 0;
1300
+ stroke.close();
1301
+ }
1302
+ }
1303
+ else if (annot instanceof PdfViewing.Pdf.Annotations.RectangleAnnotation) {
1304
+ const ww_shapeAnnot = ww_annot;
1305
+ ww_shapeAnnot.itemType = PdfItemType.SQUARE;
1306
+ ww_shapeAnnot.color = this.convertColorToRgbaString(annot.strokeColor);
1307
+ const stroke = annot.annotationStroke;
1308
+ if (stroke) {
1309
+ ww_shapeAnnot.border.width = stroke === null || stroke === void 0 ? void 0 : stroke.lineWidth;
1310
+ const hasDashArray = stroke.dashArray.length && stroke.dashArray[0] > 0;
1311
+ ww_shapeAnnot.border.style = hasDashArray
1312
+ ? 1
1313
+ : this.convertToWebViewerBorderStyle(annot.borderStyleType);
1314
+ stroke.close();
1315
+ }
1316
+ if (annot.fillColor) {
1317
+ ww_shapeAnnot.fillColor = this.convertColorToRgbaString(annot.fillColor);
1318
+ }
1319
+ }
1320
+ else if (annot instanceof PdfViewing.Pdf.Annotations.EllipseAnnotation) {
1321
+ const ww_shapeAnnot = ww_annot;
1322
+ ww_shapeAnnot.itemType = PdfItemType.CIRCLE;
1323
+ ww_shapeAnnot.color = this.convertColorToRgbaString(annot.strokeColor);
1324
+ const stroke = annot.annotationStroke;
1325
+ if (stroke) {
1326
+ ww_shapeAnnot.border.width = stroke === null || stroke === void 0 ? void 0 : stroke.lineWidth;
1327
+ const hasDashArray = stroke.dashArray.length && stroke.dashArray[0] > 0;
1328
+ ww_shapeAnnot.border.style = hasDashArray
1329
+ ? 1
1330
+ : this.convertToWebViewerBorderStyle(annot.borderStyleType);
1331
+ stroke.close();
1332
+ }
1333
+ if (annot.fillColor) {
1334
+ ww_shapeAnnot.fillColor = this.convertColorToRgbaString(annot.fillColor);
1335
+ }
1336
+ }
1337
+ else if (annot instanceof PdfViewing.Pdf.Annotations.PolygonAnnotation) {
1338
+ ww_annot.itemType = PdfItemType.POLYGON;
1339
+ const stroke = annot.annotationStroke;
1340
+ if (stroke) {
1341
+ ww_annot.border.width = stroke === null || stroke === void 0 ? void 0 : stroke.lineWidth;
1342
+ const hasDashArray = stroke.dashArray.length && stroke.dashArray[0] > 0;
1343
+ ww_annot.border.style = hasDashArray
1344
+ ? 1
1345
+ : this.convertToWebViewerBorderStyle(annot.borderStyleType);
1346
+ }
1347
+ }
1348
+ else if (annot instanceof PdfViewing.Pdf.Annotations.PolyLineAnnotation) {
1349
+ ww_annot.itemType = PdfItemType.POLY_LINE;
1350
+ const stroke = annot.annotationStroke;
1351
+ if (stroke) {
1352
+ ww_annot.border.width = stroke === null || stroke === void 0 ? void 0 : stroke.lineWidth;
1353
+ ww_annot.border.style = 0;
1354
+ stroke.close();
1355
+ }
1356
+ }
1357
+ else if (annot instanceof PdfViewing.Pdf.Annotations.TextMarkup) {
1358
+ const highlightAnnot = ww_annot;
1359
+ highlightAnnot.markedText = annot.markedText;
1360
+ if (annot.markupArea !== null) {
1361
+ highlightAnnot.quadrilaterals = [];
1362
+ for (let index = 0; index < annot.markupArea.size; index++) {
1363
+ highlightAnnot.quadrilaterals.push(annot.markupArea.get(index));
1364
+ }
1365
+ }
1366
+ if (annot instanceof PdfViewing.Pdf.Annotations.Highlight) {
1367
+ highlightAnnot.itemType = PdfItemType.HIGHLIGHT;
1368
+ }
1369
+ else if (annot instanceof PdfViewing.Pdf.Annotations.Underline) {
1370
+ highlightAnnot.itemType = PdfItemType.UNDERLINE;
1371
+ }
1372
+ else if (annot instanceof PdfViewing.Pdf.Annotations.Squiggly) {
1373
+ highlightAnnot.itemType = PdfItemType.SQUIGGLY;
1374
+ }
1375
+ else if (annot instanceof PdfViewing.Pdf.Annotations.StrikeThrough) {
1376
+ highlightAnnot.itemType = PdfItemType.STRIKE_OUT;
1377
+ }
1378
+ }
1379
+ else if (annot instanceof PdfViewing.Pdf.Annotations.Stamp) {
1380
+ const stampAnnot = ww_annot;
1381
+ stampAnnot.itemType = PdfItemType.STAMP;
1382
+ stampAnnot.rotation = annot.rotation;
1383
+ }
1384
+ else if (annot instanceof PdfViewing.Pdf.Annotations.TextInsert) {
1385
+ return null;
1386
+ }
1387
+ else if (annot instanceof PdfViewing.Pdf.Annotations.InkAnnotation) {
1388
+ const sdkInkAnnot = annot;
1389
+ const inkAnnot = ww_annot;
1390
+ inkAnnot.itemType = PdfItemType.INK;
1391
+ inkAnnot.color = this.convertColorToRgbaString(sdkInkAnnot.strokeColor);
1392
+ inkAnnot.border = {
1393
+ width: ((_a = sdkInkAnnot.annotationStroke) === null || _a === void 0 ? void 0 : _a.lineWidth) || 1,
1394
+ style: AnnotationBorderStyle.SOLID,
1395
+ };
1396
+ // extract inklist
1397
+ inkAnnot.inkList = [];
1398
+ const { vertices } = sdkInkAnnot.path;
1399
+ let path = null;
1400
+ for (let i = 0; i < vertices.size; i++) {
1401
+ const vertex = vertices.get(i);
1402
+ if (vertex.operator === PdfViewing.Pdf.Geometry.Real.PathOperation.MoveTo) {
1403
+ if (path) {
1404
+ inkAnnot.inkList.push(path);
1405
+ }
1406
+ path = [{ x: vertex.x, y: vertex.y }];
1407
+ }
1408
+ else if (vertex.operator === PdfViewing.Pdf.Geometry.Real.PathOperation.LineTo) {
1409
+ path === null || path === void 0 ? void 0 : path.push({ x: vertex.x, y: vertex.y });
1410
+ }
1411
+ }
1412
+ if (path) {
1413
+ inkAnnot.inkList.push(path);
1414
+ }
1415
+ }
1416
+ else if (annot instanceof PdfViewing.Pdf.Annotations.Popup) {
1417
+ return null;
1418
+ }
1419
+ else {
1420
+ return null;
1421
+ }
1422
+ }
1423
+ else if (annot instanceof PdfViewing.Pdf.Annotations.Link) {
1424
+ ww_annot.itemType = PdfItemType.LINK;
1425
+ const linkAnnot = ww_annot;
1426
+ ww_annot.id = annot.getHashCode();
1427
+ ww_annot.pdfRect = this.ViewingPdfRect2WwPdfRect(annot.boundingBox);
1428
+ if (annot instanceof PdfViewing.Pdf.Annotations.WebLink) {
1429
+ linkAnnot.uri = annot.uri;
1430
+ linkAnnot.actionType = PdfActionType.URI;
1431
+ }
1432
+ else if (annot instanceof PdfViewing.Pdf.Annotations.InternalLink) {
1433
+ const target = (_b = annot.destination) === null || _b === void 0 ? void 0 : _b.target;
1434
+ linkAnnot.actionType = PdfActionType.GO_TO;
1435
+ if (target) {
1436
+ linkAnnot.destination = {
1437
+ destinationType: 8,
1438
+ pageNumber: target.pageNumber,
1439
+ left: null,
1440
+ top: null,
1441
+ zoom: null,
1442
+ };
1443
+ }
1444
+ }
1445
+ }
1446
+ else if (annot instanceof PdfViewing.Pdf.Forms.Widget) {
1447
+ const widgetAnnot = ww_annot;
1448
+ widgetAnnot.id = annot.getHashCode();
1449
+ widgetAnnot.itemType = PdfItemType.WIDGET;
1450
+ widgetAnnot.page = page;
1451
+ const bbox = annot.boundingBox;
1452
+ widgetAnnot.pdfRect = this.ViewingPdfRect2WwPdfRect(bbox);
1453
+ widgetAnnot.widget = annot;
1454
+ widgetAnnot.isLocked = () => {
1455
+ return false;
1456
+ };
1457
+ widgetAnnot.isHidden = () => {
1458
+ return annot.hidden;
1459
+ };
1460
+ widgetAnnot.setHidden = (isHidden) => {
1461
+ annot.hidden = isHidden;
1462
+ };
1463
+ widgetAnnot.pdfDocument = this.pdfDocument;
1464
+ if (annot instanceof PdfViewing.Pdf.Forms.CheckBox) {
1465
+ widgetAnnot.widgetType = WidgetType.CHECK_BOX;
1466
+ }
1467
+ else if (annot instanceof PdfViewing.Pdf.Forms.RadioButton) {
1468
+ widgetAnnot.widgetType = WidgetType.RADIO_BUTTON;
1469
+ }
1470
+ else if (annot instanceof PdfViewing.Pdf.Forms.TextBox) {
1471
+ widgetAnnot.widgetType = WidgetType.TEXT_BOX;
1472
+ }
1473
+ else if (annot instanceof PdfViewing.Pdf.Forms.ListBox) {
1474
+ widgetAnnot.widgetType = WidgetType.LIST_BOX;
1475
+ }
1476
+ else if (annot instanceof PdfViewing.Pdf.Forms.ComboBox) {
1477
+ widgetAnnot.widgetType = WidgetType.COMBO_BOX;
1478
+ // } else if (annot instanceof PdfViewing.Pdf.Forms.ListBox) {
1479
+ // widgetAnnot.widgetType = WidgetType.STRING_LIST
1480
+ }
1481
+ }
1482
+ else {
1483
+ return null;
1484
+ }
1485
+ const isReadOnly = () => {
1486
+ const { annotationPermissionCallback, onlyAuthorCanEdit, user } = this.pdfViewerApiOptions;
1487
+ let eventThrottlingTimer = null;
1488
+ let lastResult = false;
1489
+ const viewOnly = this.pdfViewerApiOptions.viewOnly ||
1490
+ !(PdfViewing.Sdk.supportedFeatures & PdfViewing.LicenseFeature.Annotate);
1491
+ return () => {
1492
+ if (eventThrottlingTimer) {
1493
+ return lastResult;
1494
+ }
1495
+ lastResult = false;
1496
+ if (viewOnly || !(PdfViewing.Sdk.supportedFeatures & PdfViewing.LicenseFeature.Annotate)) {
1497
+ lastResult = true;
1498
+ }
1499
+ else if (annotationPermissionCallback) {
1500
+ lastResult = !annotationPermissionCallback(ww_annot, user);
1501
+ }
1502
+ else if (onlyAuthorCanEdit) {
1503
+ lastResult = !ww_annot.author || user !== ww_annot.author;
1504
+ }
1505
+ eventThrottlingTimer = window.setTimeout(() => {
1506
+ eventThrottlingTimer = null;
1507
+ }, 50);
1508
+ return lastResult;
1509
+ };
1510
+ };
1511
+ ww_annot.isReadOnly = isReadOnly();
1512
+ ww_annot.behaviors = this.getAnnotationBehaviors(ww_annot);
1513
+ return ww_annot;
1514
+ }
1515
+ getAnnotationBehaviors(ww_annot) {
1516
+ const defaultBehaviors = annotationDefaultBehaviors[ww_annot.itemType];
1517
+ if (!defaultBehaviors) {
1518
+ return {
1519
+ isReadOnly: true,
1520
+ selectable: false,
1521
+ editable: false,
1522
+ deletable: false,
1523
+ movable: false,
1524
+ rotatable: false,
1525
+ resizable: false,
1526
+ aspectRatioChangeable: false,
1527
+ canHavePopup: false,
1528
+ link: false,
1529
+ text: false,
1530
+ };
1531
+ }
1532
+ let isReadOnly = false;
1533
+ if (this.pdfViewerApiOptions.viewOnly ||
1534
+ !(this.licenseFeatures & PdfViewing.LicenseFeature.Annotate)) {
1535
+ isReadOnly = true;
1536
+ }
1537
+ const behaviors = {
1538
+ isReadOnly,
1539
+ selectable: defaultBehaviors[0],
1540
+ editable: defaultBehaviors[1],
1541
+ deletable: defaultBehaviors[2],
1542
+ movable: defaultBehaviors[3],
1543
+ rotatable: defaultBehaviors[4],
1544
+ resizable: defaultBehaviors[5],
1545
+ aspectRatioChangeable: defaultBehaviors[6],
1546
+ canHavePopup: this.pdfViewerApiOptions.allowPopups && defaultBehaviors[7],
1547
+ link: defaultBehaviors[8],
1548
+ text: defaultBehaviors[9],
1549
+ };
1550
+ return behaviors;
1551
+ }
1552
+ addPopup(ww_annot, annot) {
1553
+ const popup = annot.popup;
1554
+ if (popup) {
1555
+ ww_annot.popup = {};
1556
+ ww_annot.popup.pdfRect = this.ViewingPdfRect2WwPdfRect(popup.boundingBox);
1557
+ ww_annot.popup.isOpen = popup.isOpen;
1558
+ ww_annot.popup.pdfRect.page = ww_annot.page;
1559
+ popup.close();
1560
+ }
1561
+ }
1562
+ getOpenPopups(firstPage, lastPage) {
1563
+ var _a;
1564
+ const annotationsWithOpenPopups = [];
1565
+ for (let i = firstPage; i <= lastPage; i++) {
1566
+ (_a = this.pageAnnotationCache.get(i)) === null || _a === void 0 ? void 0 : _a.forEach((annot) => {
1567
+ if (annot.popup && annot.popup.isOpen) {
1568
+ annotationsWithOpenPopups.push(annot);
1569
+ }
1570
+ });
1571
+ }
1572
+ return annotationsWithOpenPopups;
1573
+ }
1574
+ convertColorToRgbaString(color) {
1575
+ let rgba_string = '#';
1576
+ if (!color) {
1577
+ rgba_string += '00000000';
1578
+ return rgba_string;
1579
+ }
1580
+ // add red
1581
+ rgba_string += color.red.toString(16).padStart(2, '0');
1582
+ // add green
1583
+ rgba_string += color.green.toString(16).padStart(2, '0');
1584
+ // add blue
1585
+ rgba_string += color.blue.toString(16).padStart(2, '0');
1586
+ // add alpha
1587
+ rgba_string += color.alpha.toString(16).padStart(2, '0');
1588
+ return rgba_string;
1589
+ }
1590
+ getPageLayoutMode() {
1591
+ if (this.view) {
1592
+ return this.view.pageLayoutMode;
1593
+ }
1594
+ return PdfViewing.Pdf.Navigation.PageLayoutMode.SinglePage;
1595
+ }
1596
+ setPageLayoutMode(layout) {
1597
+ if (this.view) {
1598
+ this.view.pageLayoutMode = layout;
1599
+ }
1600
+ }
1601
+ getScrollMaxPosition() {
1602
+ var _a;
1603
+ const sp = (_a = this.view) === null || _a === void 0 ? void 0 : _a.scrollMaxPosition;
1604
+ if (sp) {
1605
+ sp.x = Math.max(sp.x - this.viewportSize.width, 0);
1606
+ sp.y = Math.max(sp.y - this.viewportSize.height, 0);
1607
+ }
1608
+ return sp;
1609
+ }
1610
+ getScrollPosition() {
1611
+ var _a;
1612
+ return (_a = this.view) === null || _a === void 0 ? void 0 : _a.scrollPosition;
1613
+ }
1614
+ setScrollPosition(pos) {
1615
+ const sp = new PdfViewing.Pdf.Geometry.Integer.ScrollPosition(pos.x, pos.y);
1616
+ if (this.view) {
1617
+ this.view.scrollPosition = pos; //sp // TODO: Is this good? Or should I create a PdfViewing.ScrollPosition first?
1618
+ }
1619
+ }
1620
+ getPageScreenRect(page) {
1621
+ var _a;
1622
+ const viewingRect = (_a = this.view) === null || _a === void 0 ? void 0 : _a.getPageRectangleOnViewport(page);
1623
+ if (viewingRect) {
1624
+ return this.ViewingVPRect2WwVpRect(viewingRect);
1625
+ }
1626
+ return null;
1627
+ }
1628
+ getClosestPointOnPdfByScreenPoint(point, padding = 0, page) {
1629
+ if (this.view && this.pdfDocument) {
1630
+ const p = new PdfViewing.Pdf.Geometry.Integer.Point(point.x, point.y);
1631
+ const pointOnPage = page
1632
+ ? this.view.transformPointFromViewportToSpecificPage(p, page, true)
1633
+ : this.view.transformPointFromViewportToPage(p, true);
1634
+ const pageSize = this.pdfDocument.getPageSize(pointOnPage.pageNumber, true);
1635
+ const pdfPoint = {
1636
+ pdfX: pointOnPage.x,
1637
+ pdfY: pointOnPage.y,
1638
+ page: pointOnPage.pageNumber,
1639
+ };
1640
+ if (pdfPoint.pdfX < padding) {
1641
+ pdfPoint.pdfX = padding;
1642
+ }
1643
+ else if (pdfPoint.pdfX > pageSize.width - padding) {
1644
+ pdfPoint.pdfX = pageSize.width - padding;
1645
+ }
1646
+ if (pdfPoint.pdfY < padding) {
1647
+ pdfPoint.pdfY = padding;
1648
+ }
1649
+ else if (pdfPoint.pdfY > pageSize.height - padding) {
1650
+ pdfPoint.pdfY = pageSize.height - padding;
1651
+ }
1652
+ return pdfPoint;
1653
+ }
1654
+ throw new Error('PDF Document must not be null');
1655
+ }
1656
+ transformPdfLengthToScreenLength(pdfLength) {
1657
+ var _a;
1658
+ if (this.view) {
1659
+ return (_a = this.view) === null || _a === void 0 ? void 0 : _a.transformPdfLengthToViewportLength(pdfLength);
1660
+ }
1661
+ throw new Error('View must not be null');
1662
+ }
1663
+ transformScreenLengthToPdfLength(pdfLength) {
1664
+ var _a;
1665
+ if (this.view) {
1666
+ return (_a = this.view) === null || _a === void 0 ? void 0 : _a.transformViewportLengthToPdfLength(pdfLength);
1667
+ }
1668
+ throw new Error('View must not be null');
1669
+ }
1670
+ transformScreenPointToPdfPoint(point, page) {
1671
+ if (this.view && this.pdfDocument) {
1672
+ const p = new PdfViewing.Pdf.Geometry.Integer.Point(point.x, point.y);
1673
+ try {
1674
+ const pointOnPage = page
1675
+ ? this.view.transformPointFromViewportToSpecificPage(p, page, false)
1676
+ : this.view.transformPointFromViewportToPage(p, false);
1677
+ const pageSize = this.pdfDocument.getPageSize(pointOnPage.pageNumber, true);
1678
+ return {
1679
+ pdfPoint: { pdfX: pointOnPage.x, pdfY: pointOnPage.y, page: pointOnPage.pageNumber },
1680
+ isOnPage: pointOnPage.x >= 0 &&
1681
+ pointOnPage.x <= pageSize.width &&
1682
+ pointOnPage.y >= 0 &&
1683
+ pointOnPage.y <= pageSize.height,
1684
+ };
1685
+ }
1686
+ catch (error) {
1687
+ if (error instanceof PdfViewing.ArgumentError) {
1688
+ return { pdfPoint: null, isOnPage: false };
1689
+ }
1690
+ }
1691
+ }
1692
+ return null;
1693
+ }
1694
+ transformPdfPointToScreenPoint(pdfPoint) {
1695
+ var _a;
1696
+ const screenPoint = (_a = this.view) === null || _a === void 0 ? void 0 : _a.transformPointFromPageToViewport(new PdfViewing.Pdf.Geometry.Real.PointOnPage(pdfPoint.page, pdfPoint.pdfX, pdfPoint.pdfY));
1697
+ return {
1698
+ x: screenPoint === null || screenPoint === void 0 ? void 0 : screenPoint.x,
1699
+ y: screenPoint === null || screenPoint === void 0 ? void 0 : screenPoint.y,
1700
+ };
1701
+ }
1702
+ transformPdfPageRectToScreenRect(pdfRect) {
1703
+ var _a;
1704
+ const screenRect = (_a = this.view) === null || _a === void 0 ? void 0 : _a.transformRectangleFromPageToViewport(new PdfViewing.Pdf.Geometry.Real.RectangleOnPage(pdfRect.page, pdfRect.pdfX, pdfRect.pdfY, pdfRect.pdfW, pdfRect.pdfH));
1705
+ return {
1706
+ x: screenRect === null || screenRect === void 0 ? void 0 : screenRect.x,
1707
+ y: screenRect === null || screenRect === void 0 ? void 0 : screenRect.y,
1708
+ w: screenRect === null || screenRect === void 0 ? void 0 : screenRect.width,
1709
+ h: screenRect === null || screenRect === void 0 ? void 0 : screenRect.height,
1710
+ };
1711
+ }
1712
+ transformScreenRectToPdfRect(screenRect, page) {
1713
+ var _a;
1714
+ const vpRect = new PdfViewing.Pdf.Geometry.Integer.Rectangle(screenRect.x, screenRect.y, screenRect.w, screenRect.h);
1715
+ try {
1716
+ const pdfRect = (_a = this.view) === null || _a === void 0 ? void 0 : _a.transformRectangleFromViewportToSpecificPage(vpRect, page);
1717
+ return {
1718
+ pdfX: pdfRect === null || pdfRect === void 0 ? void 0 : pdfRect.x,
1719
+ pdfY: pdfRect === null || pdfRect === void 0 ? void 0 : pdfRect.y,
1720
+ pdfW: pdfRect === null || pdfRect === void 0 ? void 0 : pdfRect.width,
1721
+ pdfH: pdfRect === null || pdfRect === void 0 ? void 0 : pdfRect.height,
1722
+ page,
1723
+ };
1724
+ }
1725
+ catch (error) {
1726
+ return null;
1727
+ }
1728
+ }
1729
+ transformQuadrilateralToViewport(quadrilateral) {
1730
+ const points = [];
1731
+ if (this.view) {
1732
+ points.push(this.view.transformPointFromPageToViewport(new PdfViewing.Pdf.Geometry.Real.PointOnPage(quadrilateral.pageNumber, quadrilateral.topLeft.x, quadrilateral.topLeft.y)));
1733
+ points.push(this.view.transformPointFromPageToViewport(new PdfViewing.Pdf.Geometry.Real.PointOnPage(quadrilateral.pageNumber, quadrilateral.topRight.x, quadrilateral.topRight.y)));
1734
+ points.push(this.view.transformPointFromPageToViewport(new PdfViewing.Pdf.Geometry.Real.PointOnPage(quadrilateral.pageNumber, quadrilateral.bottomRight.x, quadrilateral.bottomRight.y)));
1735
+ points.push(this.view.transformPointFromPageToViewport(new PdfViewing.Pdf.Geometry.Real.PointOnPage(quadrilateral.pageNumber, quadrilateral.bottomLeft.x, quadrilateral.bottomLeft.y)));
1736
+ }
1737
+ return points;
1738
+ }
1739
+ getAnnotationsOnPoint(point, onlySelectable) {
1740
+ var _a;
1741
+ const annotList = (_a = this.view) === null || _a === void 0 ? void 0 : _a.getAnnotationsOnPoint(point, onlySelectable);
1742
+ if (annotList && annotList.size > 0) {
1743
+ const annotationList = [];
1744
+ for (let i = 0; i < annotList.size; i++) {
1745
+ const annot = annotList.get(i);
1746
+ const annotId = annot.getHashCode();
1747
+ if (this.handleAnnotationCache.has(annotId)) {
1748
+ annotationList.push(this.handleAnnotationCache.get(annotId));
1749
+ }
1750
+ else {
1751
+ console.warn('annotation handle is not cached');
1752
+ }
1753
+ annot.close();
1754
+ }
1755
+ annotList.close();
1756
+ return annotationList;
1757
+ }
1758
+ return null;
1759
+ }
1760
+ getItemsFromPage(page, type) {
1761
+ if (type === 1) {
1762
+ return this.getAnnotationsFromPage(page);
1763
+ }
1764
+ }
1765
+ onDocumentOpened(document, renderOptions, viewOptions) {
1766
+ const _viewOptions = viewOptions ? viewOptions : new PdfViewing.Pdf.ViewOptions();
1767
+ _viewOptions.viewDPI = this.getXDPI();
1768
+ const { initialDestination, initialPageLayoutMode } = document;
1769
+ if (initialPageLayoutMode !== null && _viewOptions.initialPageLayoutMode === null) {
1770
+ _viewOptions.initialPageLayoutMode = initialPageLayoutMode;
1771
+ }
1772
+ if (initialDestination !== null && _viewOptions.initialDestination === null) {
1773
+ _viewOptions.initialDestination = initialDestination;
1774
+ }
1775
+ this.view = PdfViewing.Pdf.View.create(document, renderOptions, viewOptions);
1776
+ this.attachEventListeners();
1777
+ if (this.view) {
1778
+ this.dispatchEvent('firstVisiblePage', this.view.firstVisiblePage);
1779
+ this.dispatchEvent('lastVisiblePage', this.view.lastVisiblePage);
1780
+ this.dispatchEvent('pageNumber', this.view.pageNumber);
1781
+ this.dispatchEvent('fitMode', this.view.fitMode);
1782
+ this.dispatchEvent('pageLayoutMode', this.ViewingPageLayoutToWwPageLayout(this.view.pageLayoutMode));
1783
+ }
1784
+ }
1785
+ ViewingPageLayoutToWwPageLayout(layout) {
1786
+ switch (layout) {
1787
+ case PdfViewing.Pdf.Navigation.PageLayoutMode.OneColumn:
1788
+ return PdfPageLayoutMode.ONE_COLUMN;
1789
+ case PdfViewing.Pdf.Navigation.PageLayoutMode.SinglePage:
1790
+ return PdfPageLayoutMode.SINGLE_PAGE;
1791
+ case PdfViewing.Pdf.Navigation.PageLayoutMode.TwoColumnLeft:
1792
+ return PdfPageLayoutMode.TWO_COLUMN_LEFT;
1793
+ case PdfViewing.Pdf.Navigation.PageLayoutMode.TwoColumnRight:
1794
+ return PdfPageLayoutMode.TWO_COLUMN_RIGHT;
1795
+ case PdfViewing.Pdf.Navigation.PageLayoutMode.TwoPageLeft:
1796
+ return PdfPageLayoutMode.TWO_PAGE_LEFT;
1797
+ case PdfViewing.Pdf.Navigation.PageLayoutMode.TwoPageRight:
1798
+ return PdfPageLayoutMode.TWO_PAGE_RIGHT;
1799
+ default:
1800
+ return PdfPageLayoutMode.ONE_COLUMN;
1801
+ }
1802
+ }
1803
+ WwPageLayoutToViewingPageLayout(layout) {
1804
+ switch (layout) {
1805
+ case PdfPageLayoutMode.ONE_COLUMN:
1806
+ return PdfViewing.Pdf.Navigation.PageLayoutMode.OneColumn;
1807
+ case PdfPageLayoutMode.SINGLE_PAGE:
1808
+ return PdfViewing.Pdf.Navigation.PageLayoutMode.SinglePage;
1809
+ case PdfPageLayoutMode.TWO_COLUMN_LEFT:
1810
+ return PdfViewing.Pdf.Navigation.PageLayoutMode.TwoColumnLeft;
1811
+ case PdfPageLayoutMode.TWO_COLUMN_RIGHT:
1812
+ return PdfViewing.Pdf.Navigation.PageLayoutMode.TwoColumnRight;
1813
+ case PdfPageLayoutMode.TWO_PAGE_LEFT:
1814
+ return PdfViewing.Pdf.Navigation.PageLayoutMode.TwoPageLeft;
1815
+ case PdfPageLayoutMode.TWO_PAGE_RIGHT:
1816
+ return PdfViewing.Pdf.Navigation.PageLayoutMode.TwoPageRight;
1817
+ case PdfPageLayoutMode.ONE_COLUMN:
1818
+ default:
1819
+ return PdfViewing.Pdf.Navigation.PageLayoutMode.OneColumn;
1820
+ }
1821
+ }
1822
+ WwFitModeToViewingFitMode(fitMode) {
1823
+ switch (fitMode) {
1824
+ case PdfFitMode.NONE:
1825
+ return PdfViewing.Pdf.Navigation.FitMode.None;
1826
+ case PdfFitMode.FIT_PAGE:
1827
+ return PdfViewing.Pdf.Navigation.FitMode.FitPage;
1828
+ case PdfFitMode.FIT_WIDTH:
1829
+ return PdfViewing.Pdf.Navigation.FitMode.FitWidth;
1830
+ default:
1831
+ return PdfViewing.Pdf.Navigation.FitMode.None;
1832
+ }
1833
+ }
1834
+ getLastVisiblePage() {
1835
+ if (this.view) {
1836
+ return this.view.lastVisiblePage;
1837
+ }
1838
+ return 0;
1839
+ }
1840
+ getFirstVisiblePage() {
1841
+ if (this.view) {
1842
+ return this.view.firstVisiblePage;
1843
+ }
1844
+ return 0;
1845
+ }
1846
+ drawImages(ctx, data, options) {
1847
+ if (data.visiblePages) {
1848
+ ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height);
1849
+ const currentPage = this.getPageNumber();
1850
+ for (let i = 0; i < data.visiblePages.size; i++) {
1851
+ const { image, pageRect, pageNumber } = data.visiblePages.get(i);
1852
+ ctx.save();
1853
+ if (currentPage === pageNumber && options.currentPageShadow) {
1854
+ ctx.shadowColor = options.currentPageShadow.shadowColor;
1855
+ ctx.shadowBlur = options.currentPageShadow.shadowBlur;
1856
+ ctx.shadowOffsetX = options.currentPageShadow.shadowOffsetX;
1857
+ ctx.shadowOffsetY = options.currentPageShadow.shadowOffsetY;
1858
+ }
1859
+ else if (options.pageShadow) {
1860
+ ctx.shadowColor = options.pageShadow.shadowColor;
1861
+ ctx.shadowBlur = options.pageShadow.shadowBlur;
1862
+ ctx.shadowOffsetX = options.pageShadow.shadowOffsetX;
1863
+ ctx.shadowOffsetY = options.pageShadow.shadowOffsetY;
1864
+ }
1865
+ ctx.fillStyle = '#ffffffff';
1866
+ ctx.fillRect(pageRect.x, pageRect.y, pageRect.width, pageRect.height);
1867
+ ctx.restore();
1868
+ if (image) {
1869
+ const imageContainer = this.imageBitmapCache.get(image.id);
1870
+ if (imageContainer) {
1871
+ const { scaledImage, imageData } = imageContainer;
1872
+ const { imageRectangle } = image;
1873
+ if (imageData && scaledImage) {
1874
+ if (imageRectangle.width !== image.width || imageRectangle.height !== image.height) {
1875
+ ctx.drawImage(scaledImage, pageRect.x + imageRectangle.x, pageRect.y + imageRectangle.y, imageRectangle.width, imageRectangle.height);
1876
+ }
1877
+ else {
1878
+ ctx.putImageData(imageData, pageRect.x + imageRectangle.x, pageRect.y + imageRectangle.y);
1879
+ }
1880
+ }
1881
+ }
1882
+ image.close();
1883
+ }
1884
+ }
1885
+ }
1886
+ }
1887
+ addEventListener(type, listener) {
1888
+ if (type === 'busyState') {
1889
+ this.pdfController.addEventListener('busyChanged', listener);
1890
+ return;
1891
+ }
1892
+ if (this.eventListeners.has(type)) {
1893
+ ;
1894
+ this.eventListeners.get(type).push(listener);
1895
+ }
1896
+ else {
1897
+ this.eventListeners.set(type, [listener]);
1898
+ }
1899
+ }
1900
+ removeEventListener(type, listener) {
1901
+ if (this.eventListeners.has(type)) {
1902
+ let listeners = this.eventListeners.get(type);
1903
+ listeners = listeners.filter((listenerInArray) => listenerInArray !== listener);
1904
+ if (listeners.length !== 0) {
1905
+ this.eventListeners.set(type, listeners);
1906
+ }
1907
+ else {
1908
+ this.eventListeners.delete(type);
1909
+ }
1910
+ }
1911
+ }
1912
+ dispatchEvent(type, args) {
1913
+ if (this.eventListeners.has(type)) {
1914
+ const listeners = this.eventListeners.get(type);
1915
+ listeners.forEach((listener) => listener(args));
1916
+ }
1917
+ }
1918
+ attachEventListeners() {
1919
+ if (this.view) {
1920
+ this.view.addEventListener('viewUpdated', this.onViewUpdated);
1921
+ this.view.addEventListener('imageCreated', this.onImageCreated);
1922
+ this.view.addEventListener('imageRemovedFromCache', this.onImageRemovedFromCache);
1923
+ }
1924
+ }
1925
+ onViewUpdated(args) {
1926
+ var _a, _b, _c, _d, _e, _f, _g, _h;
1927
+ if (args.bitmapsUpdated) {
1928
+ }
1929
+ if (args.fitmodeChanged) {
1930
+ (_a = this.eventListeners.get('fitMode')) === null || _a === void 0 ? void 0 : _a.forEach((listener) => {
1931
+ listener(this.view ? this.view.fitMode : PdfViewing.Pdf.Navigation.FitMode.None);
1932
+ });
1933
+ }
1934
+ if (args.pageLayoutModeChanged) {
1935
+ (_b = this.eventListeners.get('pageLayoutMode')) === null || _b === void 0 ? void 0 : _b.forEach((listener) => {
1936
+ listener(this.view ? this.view.pageLayoutMode : 0);
1937
+ });
1938
+ }
1939
+ if (args.pageSizeUpdated) {
1940
+ }
1941
+ if (args.scrollMaxPositionChanged) {
1942
+ }
1943
+ if (args.viewRotationChanged) {
1944
+ (_c = this.eventListeners.get('rotation')) === null || _c === void 0 ? void 0 : _c.forEach((listener) => {
1945
+ listener(this.view ? this.view.viewRotation : 0);
1946
+ });
1947
+ }
1948
+ if (args.visisblePageRangeChanged) {
1949
+ (_d = this.eventListeners.get('firstVisiblePage')) === null || _d === void 0 ? void 0 : _d.forEach((listener) => {
1950
+ listener(this.view ? this.view.firstVisiblePage : 0);
1951
+ });
1952
+ (_e = this.eventListeners.get('lastVisiblePage')) === null || _e === void 0 ? void 0 : _e.forEach((listener) => {
1953
+ listener(this.view ? this.view.lastVisiblePage : 0);
1954
+ });
1955
+ }
1956
+ if (args.pageNumberChanged) {
1957
+ (_f = this.eventListeners.get('pageNumber')) === null || _f === void 0 ? void 0 : _f.forEach((listener) => {
1958
+ listener(this.view ? this.view.pageNumber : 0);
1959
+ });
1960
+ }
1961
+ if (args.zoomChanged) {
1962
+ (_g = this.eventListeners.get('zoom')) === null || _g === void 0 ? void 0 : _g.forEach((listener) => {
1963
+ listener(this.view ? this.view.zoom : 0);
1964
+ });
1965
+ }
1966
+ // A ViewUpdatedEvent should always dispatch a
1967
+ // CanvasInvalidated Event
1968
+ (_h = this.eventListeners.get('canvasInvalidated')) === null || _h === void 0 ? void 0 : _h.forEach((listener) => {
1969
+ listener(true);
1970
+ });
1971
+ }
1972
+ onImageRemovedFromCache(id) {
1973
+ const imgContainer = this.imageBitmapCache.get(id);
1974
+ imgContainer === null || imgContainer === void 0 ? void 0 : imgContainer.destroy();
1975
+ this.imageBitmapCache.delete(id);
1976
+ }
1977
+ onImageCreated(image) {
1978
+ this.imageBitmapCache.set(image.id, new ImageContainer(image));
1979
+ image.removeImageData();
1980
+ image.close();
1981
+ }
1982
+ getProductVersion() {
1983
+ return PdfViewing.Sdk.version;
1984
+ }
1985
+ getXDPI() {
1986
+ var _a;
1987
+ if (this.devicePixelRatio !== window.devicePixelRatio || this.xDPI === 0) {
1988
+ const dpi = document.createElement('div');
1989
+ dpi.style.height = '1in';
1990
+ dpi.style.width = '1in';
1991
+ dpi.style.visibility = 'hidden';
1992
+ document.body.appendChild(dpi);
1993
+ this.xDPI = window.devicePixelRatio * dpi.offsetWidth;
1994
+ (_a = dpi.parentNode) === null || _a === void 0 ? void 0 : _a.removeChild(dpi);
1995
+ }
1996
+ return this.xDPI;
1997
+ }
1998
+ getYDPI() {
1999
+ var _a;
2000
+ if (this.devicePixelRatio !== window.devicePixelRatio || this.yDPI === 0) {
2001
+ const dpi = document.createElement('div');
2002
+ dpi.style.height = '1in';
2003
+ dpi.style.width = '1in';
2004
+ dpi.style.visibility = 'hidden';
2005
+ document.body.appendChild(dpi);
2006
+ this.yDPI = window.devicePixelRatio * dpi.offsetHeight;
2007
+ (_a = dpi.parentNode) === null || _a === void 0 ? void 0 : _a.removeChild(dpi);
2008
+ }
2009
+ return this.yDPI;
2010
+ }
2011
+ ViewingPdfRect2WwPdfRect(rect) {
2012
+ return {
2013
+ pdfX: rect.x,
2014
+ pdfY: rect.y,
2015
+ pdfW: rect.width,
2016
+ pdfH: rect.height,
2017
+ page: rect.pageNumber,
2018
+ };
2019
+ }
2020
+ ViewingQuadrilateral2WwPdfRect(quadrilateral) {
2021
+ if (quadrilateral.bottomLeft && quadrilateral.bottomRight && quadrilateral.topLeft) {
2022
+ const width = quadrilateral.bottomRight.x - quadrilateral.bottomLeft.x;
2023
+ const height = quadrilateral.topLeft.y - quadrilateral.bottomLeft.y;
2024
+ return {
2025
+ pdfX: quadrilateral.bottomLeft.x,
2026
+ pdfY: quadrilateral.bottomLeft.y,
2027
+ pdfW: width,
2028
+ pdfH: height,
2029
+ page: quadrilateral.pageNumber,
2030
+ };
2031
+ }
2032
+ return { page: -1, pdfX: -1, pdfY: -1, pdfW: -1, pdfH: -1 };
2033
+ }
2034
+ ViewingVPRect2WwVpRect(rect) {
2035
+ return { x: rect.x, y: rect.y, w: rect.width, h: rect.height };
2036
+ }
2037
+ }