chore: code formatting

This commit is contained in:
github-actions[bot]
2022-01-21 04:35:56 +00:00
parent 4571a89b57
commit 000af9197e
3 changed files with 41 additions and 36 deletions

View File

@@ -435,41 +435,45 @@ export const svg = {
console.debug("metrics/svg/resize > resizing svg")
let height, resized, width
try {
({resized, width, height} = await page.evaluate(async (padding, js) => {
//Execute user JavaScript if provided
if (js) {
try {
console.debug(`metrics/svg/resize > executing ${js}`)
await new Function("document", `return (async () => {${js}})()`)(document) //eslint-disable-line no-new-func
console.debug("metrics/svg/resize > successfully executed user javascript")
({resized, width, height} = await page.evaluate(
async (padding, js) => {
//Execute user JavaScript if provided
if (js) {
try {
console.debug(`metrics/svg/resize > executing ${js}`)
await new Function("document", `return (async () => {${js}})()`)(document) //eslint-disable-line no-new-func
console.debug("metrics/svg/resize > successfully executed user javascript")
}
catch (error) {
console.debug(`an error occured while evaluating user js: ${error}`)
}
}
catch (error) {
console.debug(`an error occured while evaluating user js: ${error}`)
}
}
//Disable animations
const animated = !document.querySelector("svg").classList.contains("no-animations")
if (animated)
document.querySelector("svg").classList.add("no-animations")
console.debug(`animations are ${animated ? "enabled" : "disabled"}`)
await new Promise(solve => setTimeout(solve, 2400))
//Get bounds and resize
let {y:height, width} = document.querySelector("svg #metrics-end").getBoundingClientRect()
console.debug(`bounds width=${width}, height=${height}`)
height = Math.ceil(height * padding.height + padding.absolute.height)
width = Math.ceil(width * padding.width + padding.absolute.width)
console.debug(`bounds after applying padding width=${width} (*${padding.width}+${padding.absolute.width}), height=${height} (*${padding.height}+${padding.absolute.height})`)
//Resize svg
if (document.querySelector("svg").getAttribute("height") === "auto")
console.debug('skipped height resizing because it was set to "auto"')
else
document.querySelector("svg").setAttribute("height", height)
//Enable animations
if (animated)
document.querySelector("svg").classList.remove("no-animations")
//Result
return {resized:new XMLSerializer().serializeToString(document.querySelector("svg")), height, width}
}, padding, js))
//Disable animations
const animated = !document.querySelector("svg").classList.contains("no-animations")
if (animated)
document.querySelector("svg").classList.add("no-animations")
console.debug(`animations are ${animated ? "enabled" : "disabled"}`)
await new Promise(solve => setTimeout(solve, 2400))
//Get bounds and resize
let {y:height, width} = document.querySelector("svg #metrics-end").getBoundingClientRect()
console.debug(`bounds width=${width}, height=${height}`)
height = Math.ceil(height * padding.height + padding.absolute.height)
width = Math.ceil(width * padding.width + padding.absolute.width)
console.debug(`bounds after applying padding width=${width} (*${padding.width}+${padding.absolute.width}), height=${height} (*${padding.height}+${padding.absolute.height})`)
//Resize svg
if (document.querySelector("svg").getAttribute("height") === "auto")
console.debug('skipped height resizing because it was set to "auto"')
else
document.querySelector("svg").setAttribute("height", height)
//Enable animations
if (animated)
document.querySelector("svg").classList.remove("no-animations")
//Result
return {resized:new XMLSerializer().serializeToString(document.querySelector("svg")), height, width}
},
padding,
js,
))
}
catch (error) {
console.error(error)