Skip to content

Commit

Permalink
fix init view centering
Browse files Browse the repository at this point in the history
  • Loading branch information
leomcelroy committed Nov 21, 2023
1 parent d47e9e7 commit ef6acaa
Showing 1 changed file with 13 additions and 21 deletions.
34 changes: 13 additions & 21 deletions astro/src/components/Preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,31 +38,23 @@ function init() {

const bodyListener = createListener(document.body)
const canvasListener = createListener(canvas)
const { docDimensions } = getStore()
if (!canvas) return

const br = canvas.getBoundingClientRect()
panZoomParams.scale = Math.min(
(br.width - 20) / docDimensions.width,
(br.height - 20) / docDimensions.height
)

panZoomParams.panX =
br.width / 2 - (docDimensions.width * panZoomParams.scale) / 2
panZoomParams.panY =
br.height / 2 + (docDimensions.height * panZoomParams.scale) / 2
// center view
const { docDimensions } = getStore()

requestRedraw(canvas)
})
const br = canvas.getBoundingClientRect()
panZoomParams.scale = Math.min(
(br.width - 20) / docDimensions.width,
(br.height - 20) / docDimensions.height
)

const resizeObserver = new ResizeObserver(entries => {
const { width, height } = entries[0].contentRect
dpr = window.devicePixelRatio || 1
canvas.width = width * dpr
canvas.height = height * dpr
setCtxProperties() // setting width/height clears ctx state
panZoomParams.panX =
br.width / 2 - (docDimensions.width * panZoomParams.scale) / 2
panZoomParams.panY =
br.height / 2 + (docDimensions.height * panZoomParams.scale) / 2

requestRedraw(canvas)
requestRedraw(canvas)


canvasListener(
'wheel',
Expand Down

1 comment on commit ef6acaa

@vercel
Copy link

@vercel vercel bot commented on ef6acaa Nov 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

blot – ./astro

blot.hackclub.dev
blot-git-main.hackclub.dev

Please sign in to comment.