Skip to content

Commit

Permalink
Format element sizes
Browse files Browse the repository at this point in the history
  • Loading branch information
tamuratak committed Nov 11, 2024
1 parent 7e9088f commit 691d520
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions viewer/utils/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export function debugPrintElements(elems: HTMLElement[]) {
if (!DEBUG) {
return
}
const mesg = []
let mesg = ''
for (const elem of elems) {
let elemName = elem.nodeName.toLowerCase()
const elemId = elem.id
Expand All @@ -32,11 +32,27 @@ export function debugPrintElements(elems: HTMLElement[]) {
if (classList.length > 0) {
elemName += ' class=' + JSON.stringify(classList)
}
mesg.push(elemName)
mesg += elemName + '\n'
const rect = elem.getBoundingClientRect()
const { top, left, width, height } = rect
const clientWidth = elem.clientWidth
mesg.push({ top, left, width, height, clientWidth })
const args = {
top: formatFloat(top),
left: formatFloat(left),
width: formatFloat(width),
height: formatFloat(height),
clientWidth: formatFloat(clientWidth)
}
let elemSizes = '{ '
for (const [key, val] of Object.entries(args)) {
elemSizes += `${key}: ${val}, `
}
elemSizes += '}'
mesg += elemSizes + '\n'
}
debugPrint(...mesg)
console.log(mesg)
}

function formatFloat(num: number): string {
return num.toFixed(3).padStart(10)
}

0 comments on commit 691d520

Please sign in to comment.