Skip to content

Commit

Permalink
adjust media viewport and add dom rect viewport #97
Browse files Browse the repository at this point in the history
  • Loading branch information
abrahamjuliot committed Jan 13, 2021
1 parent 0c1fa8c commit ed0c145
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions docs/tests/screen.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ const getScreenMatchMedia = () => {
return { width: widthMatched, height: heightMatched }
}

//947.3333129882812
const getCSS = () => {
const gcd = (a, b) => b == 0 ? a : gcd(b, a%b)
const { innerWidth, innerHeight } = window
Expand All @@ -127,7 +128,14 @@ const getCSS = () => {
patch(el, html`
<div id="fingerprint-data">
<style>
@media (height: ${innerHeight}px) and (width: ${innerWidth}px) {
body {
width: 100vw;
height: 100vh;
}
@media (width: ${innerWidth}px) and (height: ${innerHeight}px) {
body {--viewport: ${innerWidth} x ${innerHeight};}
}
@media (min-width: ${innerWidth}px) and (min-height: ${innerHeight}px) {
body {--viewport: ${innerWidth} x ${innerHeight};}
}
@media (aspect-ratio: ${aspectRatio}) {
Expand All @@ -148,8 +156,10 @@ const getCSS = () => {
</style>
</div>
`)
const { width: domRectWidth, height: domRectHeight } = document.body.getBoundingClientRect()
const style = getComputedStyle(document.body)
return {
domRectViewport: `${domRectWidth} x ${domRectHeight}`,
viewport: style.getPropertyValue('--viewport').trim() || undefined,
viewportAspectRatio: style.getPropertyValue('--viewport-aspect-ratio').trim() || undefined,
deviceAspectRatio: style.getPropertyValue('--device-aspect-ratio').trim() || undefined,
Expand Down Expand Up @@ -182,6 +192,7 @@ const { width: viewportWidth, height: viewportHeight } = vViewport
const { width: mediaWidth, height: mediaHeight } = getScreenMedia()
const { width: matchMediaWidth, height: matchMediaHeight } = getScreenMatchMedia()
const {
domRectViewport,
viewport,
viewportAspectRatio,
deviceAspectRatio,
Expand Down Expand Up @@ -241,7 +252,8 @@ patch(el, html`
<div>inner: ${''+innerWidth} x ${''+innerHeight}</div>
<div>client: ${''+clientWidth} x ${''+clientHeight}</div>
<div>@media viewport: ${''+viewport}</div>
<div>visualViewport: ${viewportWidth && viewportHeight ? `${''+Math.round(viewportWidth)} x ${''+Math.round(viewportHeight)}` : note.unsupported}</div>
<div>dom rect viewport: ${''+domRectViewport}</div>
<div>visualViewport: ${viewportWidth && viewportHeight ? `${''+Math.round(viewportWidth)} x ${''+viewportHeight}` : note.unsupported}</div>
<div>colorDepth: ${''+colorDepth}</div>
<div>pixelDepth: ${''+pixelDepth}</div>
Expand Down

0 comments on commit ed0c145

Please sign in to comment.