DomInput

The DOM's InputSource: pointer, keyboard and focus events as core's own, mapped from the DOM's names by toPointer, keyOf, kindOf and buttonOf. It isn't in DomLive: a binding builds layer with the first gesture an app uses, so an app with none ships no input code.

import * as DomInput from "@wardic/dom/DomInput"

DomInput.keyOf("ArrowLeft") // "left"
DomInput.buttonOf(2) // "secondary"

Type Aliases

Where

type Where = "target" | "elsewhere";

Where a pointer event landed, as its feed says: on the feed's target, or elsewhere.

Variables

buttonOf

const buttonOf: (button) => InputSource.PointerButton;

A PointerEvent.button in core's names: 0 the main button, 1 the middle, 2 the secondary, -1 none, as on a move, and the rest, back, forward, a pen's eraser, other.

Parameters

button

number

Returns

InputSource.PointerButton


keyOf

const keyOf: (key) => InputSource.Key;

A KeyboardEvent.key in core's names: the keys core acts on, else "other".

Parameters

key

string

Returns

InputSource.Key


kindOf

const kindOf: (pointerType) => InputSource.PointerKind;

A PointerEvent.pointerType as core's pointer kind: the DOM's three, else "other".

Parameters

pointerType

string

Returns

InputSource.PointerKind


layer

const layer: Layer.Layer<InputSource.InputSource>;

Core's InputSource on the DOM's events: each target's pointer, keys and focus, shared by everyone who listens to it, for as long as the Layer lives. Building it on a server fails, with an error that says it's client-only.

Functions

makeFocusable()

function makeFocusable(target): void;

Makes a pressable element focusable, as Motion's press does: an HTML element that doesn't take focus of itself, with no tabindex, gets tabindex="0", so a key can press it. An SVG element, or one already focusable, is left as it is. Called at mount, on the client.

Parameters

target

unknown

Returns

void


toPointer()

function toPointer(
   type, 
   ev, 
   where?
): PointerLikeEvent;

A DOM PointerEvent as core's pointer event: at its point in the viewport, with no scroll counted (InputSource.heldPointer counts it), and where it landed as its feed says: on the feed's target, or elsewhere.

Parameters

type

PointerLikeEvent

ev

PointerEvent

where?

Where = "target"

Returns

PointerLikeEvent