Add mouse coordinate view with click to copy

Signed-off-by: Justin Georgi <justin.georgi@gmail.com>
This commit is contained in:
2026-05-24 15:31:38 -07:00
parent f0d06bb931
commit d3d51a04d6
4 changed files with 56 additions and 18 deletions

21
modules/annot-prev.js Normal file
View File

@@ -0,0 +1,21 @@
console.log('Previewing Annotation page...')
elSvgCont = document.querySelector('div#svg-wrapper')
elSvg = elSvgCont.childNodes[0]
elCoordBox = document.createElement('div')
elCoordBox.style.display='none'
elCoordBox.style.position='absolute'
elCoordBox.style.padding='3px'
elCoordBox.style.background='#ffffff99'
elCoordBox.style.border='1px solid black'
elSvgCont.appendChild(elCoordBox)
elScale = elSvg.getAttribute('mwscale')
elSvgCont.addEventListener('click', () => {navigator.clipboard.writeText(`[${elCoordBox.textContent}]`)})
elSvgCont.addEventListener('mouseenter', () => {elCoordBox.style.display='block'})
elSvgCont.addEventListener('mouseleave', () => {elCoordBox.style.display='none'})
elSvgCont.addEventListener('mousemove',(e) => {
xPoint = ((e.offsetX / elSvgCont.clientWidth) * elSvg.width.baseVal.value / elScale).toFixed(1)
yPoint = ((e.offsetY / elSvgCont.clientHeight) * elSvg.height.baseVal.value / elScale).toFixed(1)
elCoordBox.textContent = `${xPoint}, ${yPoint}`
elCoordBox.style.left = e.offsetX + 6
elCoordBox.style.top = e.offsetY + 12
})