2022-03-18 06:27:29 -04:00
|
|
|
export function buildHighlightElement(highlight, wrapper) {
|
|
|
|
const pageView = wrapper.viewer.getPageView(highlight.page - 1)
|
2021-09-30 07:29:25 -04:00
|
|
|
|
|
|
|
const viewport = pageView.viewport
|
|
|
|
|
|
|
|
const height = viewport.viewBox[3]
|
|
|
|
|
|
|
|
const rect = viewport.convertToViewportRectangle([
|
|
|
|
highlight.h, // xMin
|
|
|
|
height - (highlight.v + highlight.height) + 10, // yMin
|
|
|
|
highlight.h + highlight.width, // xMax
|
|
|
|
height - highlight.v + 10, // yMax
|
|
|
|
])
|
|
|
|
|
2022-03-18 06:27:29 -04:00
|
|
|
const [left, top, right, bottom] = wrapper.PDFJS.Util.normalizeRect(rect)
|
2021-09-30 07:29:25 -04:00
|
|
|
|
|
|
|
const element = document.createElement('div')
|
2022-04-27 06:32:11 -04:00
|
|
|
element.style.left = Math.floor(pageView.div.offsetLeft + left) + 'px'
|
|
|
|
element.style.top = Math.floor(pageView.div.offsetTop + top + 10) + 'px'
|
2021-09-30 07:29:25 -04:00
|
|
|
element.style.width = Math.ceil(right - left) + 'px'
|
|
|
|
element.style.height = Math.ceil(bottom - top) + 'px'
|
|
|
|
element.style.backgroundColor = 'rgba(255,255,0)'
|
|
|
|
element.style.position = 'absolute'
|
|
|
|
element.style.display = 'inline-block'
|
|
|
|
element.style.scrollMargin = '72px'
|
|
|
|
element.style.pointerEvents = 'none'
|
|
|
|
element.style.opacity = '0'
|
2022-04-27 06:32:11 -04:00
|
|
|
element.style.transition = 'opacity 1s'
|
2021-09-30 07:29:25 -04:00
|
|
|
|
2022-04-27 06:32:11 -04:00
|
|
|
wrapper.viewer.viewer.append(element)
|
2021-09-30 07:29:25 -04:00
|
|
|
|
|
|
|
return element
|
|
|
|
}
|