Skip to content

Commit

Permalink
hmmm
Browse files Browse the repository at this point in the history
  • Loading branch information
molarmanful committed Apr 8, 2024
1 parent 28417aa commit 2120ca9
Showing 1 changed file with 32 additions and 8 deletions.
40 changes: 32 additions & 8 deletions site/src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import { browser } from '$app/environment'
const adjust = n => (0 | (n * devicePixelRatio)) / devicePixelRatio
let pxdiff = 1
let rm = () => {}
const updpi = () => {
rm()
Expand All @@ -11,27 +14,40 @@
rm = () => {
media.removeEventListener('change', updpi)
}
pxdiff = (0 | devicePixelRatio) / devicePixelRatio
document.documentElement.style.setProperty(
'--sz',
(16 * factor * (0 | devicePixelRatio)) / devicePixelRatio + 'px'
16 * factor * pxdiff + 'px'
)
}
let els
const rpx = () => {
for (let el of els) {
const style = getComputedStyle(el)
if (el.matches('section, [rsz-x]')) {
el.style.marginLeft = el.style.marginRight = 'auto'
const m = 0 | style.getPropertyValue('margin-left').replace('px', '')
el.style.marginLeft = m + 'px'
}
if (el.matches('[rsz-y]')) {
el.style.marginTop = el.style.marginBottom = 'auto'
const m = 0 | style.getPropertyValue('margin-top').replace('px', '')
console.log(style.getPropertyValue('margin-top'), m)
el.style.marginTop = m + 'px'
}
requestAnimationFrame(() => {
if (el.matches('section, [rsz-x]')) {
const m = adjust(
getComputedStyle(el)
.getPropertyValue('margin-left')
.replace('px', '')
)
el.style.marginLeft = m + 'px'
}
if (el.matches('[rsz-y]')) {
const m = adjust(
getComputedStyle(el)
.getPropertyValue('margin-top')
.replace('px', '')
)
el.style.marginTop = m + 'px'
}
})
}
}
Expand Down Expand Up @@ -100,7 +116,15 @@
}
:global(section, [rsz-x], [rsz-y]) {
@apply mx-auto max-w-[80ch] p-8;
@apply max-w-[80ch] p-8;
}
:global([rsz-x]) {
@apply mx-auto;
}
:global([rsz-y]) {
@apply my-auto;
}
:global(h1, h2, h3) {
Expand Down

0 comments on commit 2120ca9

Please sign in to comment.