API reference

Every public class, method, and event in @codexo/exojs. Generated from source.

C

classOffscreenPlatform

@codexo/exojs / core / stable

The PlatformAdapter for a render surface with no document around it: an `OffscreenCanvas`, whether it stayed on the main thread or was transferred into a worker. What it provides on its own is everything that needs no DOM - the host's monotonic clock, frame scheduling, and the surface's backing-store size. Everything else is fed in by whoever owns the document: pointer and key events through OffscreenPlatform.emitSurfaceEvent and OffscreenPlatform.emitWindowEvent, the surface's on-screen rect through OffscreenPlatform.setSurfaceRect, and visibility, focus and gamepads through their setters. Nothing is invented: with no host feeding it, the adapter reports a visible, unfocused surface receiving no input. The affordances that act on a document - focus, cursor, touch-action, pointer capture - do nothing here, and deliberately do not throw. They are mechanisms whose absence degrades the experience rather than breaking the application, exactly as they already do on a browser host that refuses pointer capture, and an application should not have to know which kind of surface it draws into before it can ask for a cursor. Frame scheduling uses the realm's own `requestAnimationFrame` where there is one. A dedicated worker generally has none, so the adapter falls back to a timer at approximately 60 Hz. That fallback is not display-synchronised; a worker-hosted renderer that must not tear should be driven by frames the document's host forwards instead.

14
props
21
methods
0
events
Import
import { OffscreenPlatform } from '@codexo/exojs'

The PlatformAdapter for a render surface with no document around it: an `OffscreenCanvas`, whether it stayed on the main thread or was transferred into a worker.

What it provides on its own is everything that needs no DOM - the host's monotonic clock, frame scheduling, and the surface's backing-store size. Everything else is fed in by whoever owns the document: pointer and key events through OffscreenPlatform.emitSurfaceEvent and OffscreenPlatform.emitWindowEvent, the surface's on-screen rect through OffscreenPlatform.setSurfaceRect, and visibility, focus and gamepads through their setters. Nothing is invented: with no host feeding it, the adapter reports a visible, unfocused surface receiving no input.

The affordances that act on a document - focus, cursor, touch-action, pointer capture - do nothing here, and deliberately do not throw. They are mechanisms whose absence degrades the experience rather than breaking the application, exactly as they already do on a browser host that refuses pointer capture, and an application should not have to know which kind of surface it draws into before it can ask for a cursor.

Frame scheduling uses the realm's own `requestAnimationFrame` where there is one. A dedicated worker generally has none, so the adapter falls back to a timer at approximately 60 Hz. That fallback is not display-synchronised; a worker-hosted renderer that must not tear should be driven by frames the document's host forwards instead.

Constructors1
Methods21
cancelFrame(handle: number): void
Cancel a frame scheduled by FrameScheduler.requestFrame.
There is nothing to attach a keyboard or IME to inside a worker realm: a text widget on this adapter renders and takes focus, but rejects edits.
destroy(): void
Release everything the adapter itself holds. Called by Application.destroy only for an adapter the application created; an injected adapter stays the caller's to dispose.
Deliver a surface event to whatever the input pipeline subscribed. Takes the event's data alone, which is what survives a postMessage; the suppression calls are supplied here. Returns whether the engine asked for the host's default handling of this event to be suppressed. Across a worker boundary that answer necessarily arrives after the host's own event has finished dispatching, so it informs the host's policy for later events rather than cancelling this one.
Current position, display size and backing-store resolution of the drawing surface. Read per pointer event, so implementations should keep it cheap.
now(): number
Milliseconds elapsed since this source's own origin.
Subscribe to PlatformAdapter.devicePixelRatio changes. Optional: a host that cannot observe the ratio omits it, and everything derived from the ratio then keeps the value it was first resolved at.
Never fires - OffscreenPlatform.pointerLocked cannot change.
Subscribe to a surface event. Which events are listened for - and whether one is suppressed - stays an input-policy decision made above this seam, so the adapter only wires up the delivery.
Subscribe to PlatformAdapter.documentVisible changes.
requestFrame(callback: (timestamp: number) => void): number
Schedule callback for the next display frame and return a handle for FrameScheduler.cancelFrame. One-shot - a frame loop reschedules itself every frame. timestamp is the host's frame time. It is the time the frame was *scheduled for*, not the time the callback happened to run, so deltas derived from it are free of the jitter that reading a clock at the top of the callback introduces.
Record the host's most recent gamepad sample. The array is read as-is on every poll and never copied, so hand over a snapshot rather than a buffer that keeps changing.
Record what the host reports about network reachability. Drives PlatformAdapter.networkHint and its subscribers. A realm without online/offline events has no way to learn this on its own, so a host that wants connectivity to work here has to forward it.
setPixelRatio(ratio: number): void
Record the display's device-pixel ratio. Drives PlatformAdapter.devicePixelRatio and its subscribers, so a host that wants the backing store to follow a monitor or zoom change has to forward it - a worker realm sees no display of its own.
setSurfaceFocused(focused: boolean): void
Record whether the host considers the surface focused. Keyboard input is gated on this, so a host forwarding key events must forward focus too.
Record where the surface is displayed, in the same coordinate space as the clientX/clientY of the pointer events being forwarded. Pointer positions are mapped through this rect, so a host forwarding pointer events has to keep it current across layout and scroll changes.
setVisible(visible: boolean): void
Record whether the host's document is visible. Drives PlatformAdapter.documentVisible, its subscribers, and so pauseOnHidden.
Properties14
capturePointer: () => void
No document to route pointer events in - a forwarded event already carries its identity.
focusSurface: () => void
No document to move focus in.
lockPointer: () => void
No document to lock a pointer to; a host that locks one forwards the relative motion itself.
pointerLocked: false
Always false: nothing here can hold a pointer lock.
releasePointer: () => void
Counterpart to OffscreenPlatform.capturePointer, equally inert.
setCursor: () => void
No document to style.
setTouchAction: () => void
No document to set a touch-action policy on.
textInputFocused: false
Always false: this adapter has no text transport that could hold host focus.
unlockPointer: () => void
Counterpart to OffscreenPlatform.lockPointer, equally inert.
devicePixelRatio: number
Device pixels the host currently packs into one CSS pixel. 1 where the host reports nothing. A property of the display the surface is shown on, not of the surface: it changes when the window moves to a different monitor or the page is zoomed, which is what PlatformAdapter.onPixelRatioChange reports.
documentVisible: boolean
Whether the document showing the surface is currently visible to the user.
What the host reports about network reachability. A hint, and nothing more: a host saying 'online' has a network interface, not a route to any particular origin. 'unknown' is what a host that reports nothing means, and is deliberately not folded into 'online'.
surfaceFocused: boolean
Whether the drawing surface currently holds host focus.
Source