pdfHighlights.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /* eslint-disable
  2. max-len,
  3. no-return-assign,
  4. no-unused-vars,
  5. */
  6. // TODO: This file was created by bulk-decaffeinate.
  7. // Fix any style issues and re-enable lint.
  8. /*
  9. * decaffeinate suggestions:
  10. * DS101: Remove unnecessary use of Array.from
  11. * DS102: Remove unnecessary code created because of implicit returns
  12. * DS207: Consider shorter variations of null checks
  13. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  14. */
  15. import App from '../../../base'
  16. import PDFJS from './pdfJsLoader'
  17. export default App.factory('pdfHighlights', function() {
  18. let pdfHighlights
  19. return (pdfHighlights = class pdfHighlights {
  20. constructor(options) {
  21. this.highlightsLayerDiv = options.highlights[0]
  22. this.highlightElements = []
  23. }
  24. addHighlight(viewport, left, top, width, height) {
  25. let rect = viewport.convertToViewportRectangle([
  26. left,
  27. top,
  28. left + width,
  29. top + height
  30. ])
  31. rect = PDFJS.Util.normalizeRect(rect)
  32. const element = document.createElement('div')
  33. element.style.left = Math.floor(rect[0]) + 'px'
  34. element.style.top = Math.floor(rect[1]) + 'px'
  35. element.style.width = Math.ceil(rect[2] - rect[0]) + 'px'
  36. element.style.height = Math.ceil(rect[3] - rect[1]) + 'px'
  37. this.highlightElements.push(element)
  38. this.highlightsLayerDiv.appendChild(element)
  39. return element
  40. }
  41. clearHighlights() {
  42. for (let h of Array.from(this.highlightElements)) {
  43. if (h != null) {
  44. h.parentNode.removeChild(h)
  45. }
  46. }
  47. return (this.highlightElements = [])
  48. }
  49. })
  50. })