2018-11-05 05:06:39 -05:00
|
|
|
/* eslint-disable
|
|
|
|
max-len,
|
|
|
|
no-return-assign,
|
|
|
|
no-unused-vars,
|
|
|
|
*/
|
|
|
|
// TODO: This file was created by bulk-decaffeinate.
|
|
|
|
// Fix any style issues and re-enable lint.
|
|
|
|
/*
|
|
|
|
* decaffeinate suggestions:
|
|
|
|
* DS101: Remove unnecessary use of Array.from
|
|
|
|
* DS102: Remove unnecessary code created because of implicit returns
|
|
|
|
* DS207: Consider shorter variations of null checks
|
|
|
|
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
|
|
|
*/
|
2020-04-06 07:45:56 -04:00
|
|
|
define(['../../../base', './pdfJsLoader'], (App, PDFJS) =>
|
2018-11-05 05:06:39 -05:00
|
|
|
// app = angular.module 'pdfHighlights', []
|
|
|
|
|
2019-07-16 05:13:18 -04:00
|
|
|
App.factory('pdfHighlights', function() {
|
|
|
|
let pdfHighlights
|
|
|
|
return (pdfHighlights = class pdfHighlights {
|
|
|
|
constructor(options) {
|
|
|
|
this.highlightsLayerDiv = options.highlights[0]
|
|
|
|
this.highlightElements = []
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2019-07-16 05:13:18 -04:00
|
|
|
addHighlight(viewport, left, top, width, height) {
|
|
|
|
let rect = viewport.convertToViewportRectangle([
|
|
|
|
left,
|
|
|
|
top,
|
|
|
|
left + width,
|
|
|
|
top + height
|
|
|
|
])
|
|
|
|
rect = PDFJS.Util.normalizeRect(rect)
|
|
|
|
const element = document.createElement('div')
|
|
|
|
element.style.left = Math.floor(rect[0]) + 'px'
|
|
|
|
element.style.top = Math.floor(rect[1]) + 'px'
|
|
|
|
element.style.width = Math.ceil(rect[2] - rect[0]) + 'px'
|
|
|
|
element.style.height = Math.ceil(rect[3] - rect[1]) + 'px'
|
|
|
|
this.highlightElements.push(element)
|
|
|
|
this.highlightsLayerDiv.appendChild(element)
|
|
|
|
return element
|
|
|
|
}
|
2018-11-05 05:06:39 -05:00
|
|
|
|
2019-07-16 05:13:18 -04:00
|
|
|
clearHighlights() {
|
|
|
|
for (let h of Array.from(this.highlightElements)) {
|
|
|
|
if (h != null) {
|
|
|
|
h.parentNode.removeChild(h)
|
2018-11-05 05:06:39 -05:00
|
|
|
}
|
|
|
|
}
|
2019-07-16 05:13:18 -04:00
|
|
|
return (this.highlightElements = [])
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}))
|