feat: best scale auto-choose

This commit is contained in:
DarkCat09 2024-07-11 20:08:26 +04:00
parent a0259cc51d
commit 326844fe1c
Signed by: DarkCat09
GPG key ID: 0A26CD5B3345D6E3

View file

@ -127,9 +127,27 @@ addEventListener('DOMContentLoaded', () => {
}) })
{ // Choose best scale for screen height { // Choose best scale for screen height
const height = document.documentElement.clientHeight; let padding = getComputedStyle(document.body).paddingBottom
const padding = getComputedStyle(document.body).paddingTop; // remove `px` at the end and convert to number
// TODO padding = Number(padding.slice(0, padding.length - 2))
// compute available height
const height =
document.documentElement.clientHeight
- canvas.offsetTop // substract height of everything above canvas
- padding // substract body padding
const width =
document.documentElement.clientWidth
- padding * 2
options.scale.value = Math.max(
intDiv(
width < height ? width : height,
25, // divide least dimension by QR version 2 size
),
10, // minimum scale for this auto-detect algorithm
)
} }
{ // QR version related stuff { // QR version related stuff