@wimaengine/touch models touch contact state for Wima, translating touch pointer events into ECS-accessible slots with stable IDs, current position, and previous-position history.
Installation
npm i @wimaengine/touch
Capability Highlights
- Keeps active touches in a compact
Touchesresource backed by indexed slots and a browser pointer ID map. - Tracks both current and previous touch positions through
TouchPointerfor frame-to-frame motion and gesture logic. - Installs touch state into the app through
TouchPlugin, which registers the runtime update and startup systems. - Filters
@wimaengine/windowpointer events down to touch-only input by checkingpointerType === 'touch'. - Registers
Toucheswith the reflection/type registry so ECS consumers can work with the resource by type. - Exports both the package root and a
./srcsubpath, with the same public surface on each path.
Core Concepts
TouchPlugin
TouchPlugin is the integration point for the package. Its register method installs the touch resource, schedules the runtime updater during AppSchedule.Update, and registers the touch type metadata during startup. That keeps touch state available whenever the app frame loop runs.
Touches
Touches is the runtime resource that stores live touch contacts. It uses a fixed 10-slot list and a Map<number, TouchId> to translate browser pointer IDs into compact engine IDs. The resource exposes helpers for looking up a touch by pointer ID, reading the first or last active contact, collecting all active touches, inserting or updating a touch, deleting a touch, and reading a contact by touch slot.
TouchPointer
TouchPointer is the per-contact data object. Each pointer carries a stable id plus position and lastposition vectors from @wimaengine/math. That shape makes it useful for touch deltas, swipe logic, and any system that needs the current and previous frame positions.
TouchId
TouchId is the numeric typedef used for the engine-side slot assigned to an active touch contact. It separates the compact internal touch index from the browser pointer ID that arrives on the window event.
Exported Surface
TouchPluginfromsrc/plugin.js.Touchesfromsrc/resources/touches.js.TouchPointerfromsrc/core/pointer.js.TouchIdfromsrc/typedef/id.js.- The package root
@wimaengine/touchand@wimaengine/touch/srcboth resolve to the same re-exported surface.
Notes
- The package consumes
PointerDown,PointerMove,PointerUp, andPointerCancelevents from@wimaengine/windowand ignores non-touch pointers. updateTouchcreates aTouchPointeron pointer down, copies positions on pointer move, and deletes the slot on pointer up or cancel.registerTouchTypesregistersToucheswithTypeRegistryusingOpaqueInfo, so the resource is visible to reflection-aware code without exposing internal structure.- The source tree is intentionally small:
core,resources,plugin, andtypedefare public, whilesystemsis an internal helper module used by the plugin.
