DOMWindowPlugin

View source

ExtendsPlugin

Adds browser canvas integration for ECS window entities in an App.

For each Window component, the browser integration uses the matching canvas when its selector resolves. A window without a selector gets a new canvas appended to document.body. A selector that does not resolve to a canvas is retried on a later update. A malformed selector is passed to querySelector and can throw its DOM exception.

When a canvas is attached, it is recorded in the Windows resource, made focusable with tabIndex = -1, focused, and connected to keyboard, pointer, and file input events. Removing the component or despawning its entity removes the canvas and its resource entry synchronously. The plugin does not create window entities itself; the default WindowPlugin configuration creates the primary entity with Window and MainWindow for it to attach.

Attached canvases stay synchronized with their displayed size while the app is running. When the rounded dimensions from a bounding rectangle differ, the plugin updates the canvas backing size and the Window dimensions, then writes a WindowResize event. Unchanged dimensions do not produce an event.

This plugin requires CorePlugin and WindowPlugin. Register both dependencies on the app before starting it; dependencies are checked but are not installed automatically.

Examples

import { App } from '@wimaengine/app'
import { CommandsPlugin } from '@wimaengine/command'
import { CorePlugin } from '@wimaengine/core'
import { ReflectPlugin } from '@wimaengine/reflect'
import { DOMWindowPlugin } from '@wimaengine/window-dom'
import { WindowPlugin } from '@wimaengine/window'

new App()
  .registerPlugin(new ReflectPlugin())
  .registerPlugin(new CorePlugin())
  .registerPlugin(new CommandsPlugin())
  .registerPlugin(new WindowPlugin({
    primaryWindowOptions: { width: 1280, height: 720 }
  }))
  .registerPlugin(new DOMWindowPlugin())
  .run() // CorePlugin supplies the default requestAnimationFrame runner.

Constructor


constructor()

Methods


register(app: App): void

View source

Registers browser canvas behavior for Window components in an App.

Attached canvases receive keyboard, pointer, and file input events and are tracked in Windows. Removing a window component removes its canvas. Displayed canvas dimensions are synchronized with the Window component and changes produce WindowResize events.

Parameters

NameDescriptionDefault
app

App to configure.

—