Function: createContainerResizeSync()
createContainerResizeSync(
container,resizables):ContainerResizeSync
Defined in: utilities/create-container-resize-sync.ts:33
Watches container for size changes and calls resize() on every entry
in resizables whenever the container's size actually changes, so a
canvas (and anything derived from its width/height, such as a camera's
projection matrix) follows a resizable page - or a container that
changes size for any other reason, like a fullscreen toggle - instead of
staying pinned to whatever size it had when this was created.
Watching starts immediately and runs independently of any game loop;
call the returned stop() to disconnect it early (e.g. when switching
to a headless mode with no canvas left to keep sized). It's safe to never
call stop() at all if container is simply removed from the DOM -
browsers silently drop a ResizeObserver's registration for a target
once nothing else references it, so it won't keep the container alive.
Does nothing (and returns a no-op stop()) if resizables is empty.
Parameters
container
HTMLElement
The element to watch for size changes.
resizables
readonly Resizable[]
The resizable objects (e.g. RenderContext instances) to resize whenever container's size changes.
Returns
An object whose stop() disconnects the observer.