File tree Expand file tree Collapse file tree
apps/typegpu-docs/src/components Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -254,12 +254,28 @@ function useResizableCanvas(exampleHtmlRef: RefObject<HTMLDivElement | null>) {
254254
255255 canvas . parentElement ?. replaceChild ( container , canvas ) ;
256256
257- const onResize : ResizeObserverCallback = ( entries ) => {
258- const size = entries [ 0 ] ?. devicePixelContentBoxSize [ 0 ] ;
259- if ( size ) {
260- newCanvas . width = size . inlineSize ;
261- newCanvas . height = size . blockSize ;
257+ const onResize : ResizeObserverCallback = ( [ entry ] ) => {
258+ if ( ! entry ) {
259+ return ;
262260 }
261+
262+ // Despite what the types say this property does not exist in Safari (hence the optional chaining).
263+ const dpcb = entry . devicePixelContentBoxSize ?. [ 0 ] as
264+ | ResizeObserverSize
265+ | undefined ;
266+
267+ const dpr = dpcb ? 1 : window . devicePixelRatio || 1 ;
268+ const box = dpcb ??
269+ ( Array . isArray ( entry . contentBoxSize )
270+ ? entry . contentBoxSize [ 0 ]
271+ : entry . contentBoxSize ) ;
272+
273+ if ( ! box ) {
274+ return ;
275+ }
276+
277+ newCanvas . width = Math . round ( box . inlineSize * dpr ) ;
278+ newCanvas . height = Math . round ( box . blockSize * dpr ) ;
263279 } ;
264280
265281 const observer = new ResizeObserver ( onResize ) ;
You can’t perform that action at this time.
0 commit comments