@weasel-js/gestures 1.11.0 → 1.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +84 -12
- package/dist/index.js +205 -63
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -81,10 +81,13 @@ type RoutePhase = 'initial' | 'engaged';
|
|
|
81
81
|
* argSlot = '(' argValue ')' -- whitespace inside parens is significant
|
|
82
82
|
* targetSlot = '=>' WS targetValue -- omitted slot defaults to '*' for hasTarget
|
|
83
83
|
* modSlot = modAtom (WS modAtom)*
|
|
84
|
-
* modAtom = sigil modName
|
|
84
|
+
* modAtom = sigil (modName | 'held')
|
|
85
85
|
* sigil = '+' | '?' -- ! @ # $ % ^ & * reserved as id-prefix
|
|
86
86
|
* modName = 'mod' | 'shift' | 'alt' | 'ctrl' | 'meta'
|
|
87
87
|
*
|
|
88
|
+
* `held` is a pressed button, read as a modifier is: `?held` a button may be
|
|
89
|
+
* held, `+held` one must be, absent none may. Only `hover` takes it.
|
|
90
|
+
*
|
|
88
91
|
* The truly-loose form (any channel, any phase) is `[*:*]`.
|
|
89
92
|
*
|
|
90
93
|
* Examples:
|
|
@@ -152,6 +155,9 @@ interface ParsedRoute {
|
|
|
152
155
|
target: string | undefined;
|
|
153
156
|
/** Structured modifier requirements; empty map = "no modifiers held". */
|
|
154
157
|
modifiers: ParsedModifiers;
|
|
158
|
+
/** Whether a pressed button may or must be held. Absent, none may. Only on
|
|
159
|
+
* `hover`. */
|
|
160
|
+
held?: ModRequirement;
|
|
155
161
|
}
|
|
156
162
|
/** Parse a route string into its slots, filling in the shorthand defaults the
|
|
157
163
|
* grammar defines (bare phases mean channel `&`; an omitted arg or target
|
|
@@ -338,7 +344,8 @@ interface PointerDownSpec {
|
|
|
338
344
|
}
|
|
339
345
|
/**
|
|
340
346
|
* The pointer moving over the surface with no button pressed. Fires on every
|
|
341
|
-
* such move; a held pointer's moves belong to its drag and fire nothing here
|
|
347
|
+
* such move; a held pointer's moves belong to its drag and fire nothing here,
|
|
348
|
+
* unless `held` says otherwise.
|
|
342
349
|
*
|
|
343
350
|
* With `motion: 'leave'` it fires instead when the pointer passes out of what
|
|
344
351
|
* the binding targets: onto something its `target` does not match, or off the
|
|
@@ -349,11 +356,16 @@ interface PointerDownSpec {
|
|
|
349
356
|
* runs, not only the best one, and the move still reaches the hover-cursor
|
|
350
357
|
* pump. There is no press to own, so bind an immediate action, not an ongoing
|
|
351
358
|
* one. Its params carry `worldX` / `worldY`, `clientX` / `clientY`,
|
|
352
|
-
* `affordance`, `bodyTarget`, and `
|
|
359
|
+
* `affordance`, `bodyTarget`, `mods`, and `held`.
|
|
353
360
|
*/
|
|
354
361
|
interface HoverSpec {
|
|
355
362
|
kind: 'hover';
|
|
356
363
|
motion?: 'move' | 'leave';
|
|
364
|
+
/** Whether a pressed button may (`'optional'`) or must (`true`) be held, as
|
|
365
|
+
* `mods` says of a modifier; omitted, a held pointer's moves are not hovers.
|
|
366
|
+
* Such a binding still claims nothing, so the drag keeps its moves. Leaving
|
|
367
|
+
* the surface is a leave whether or not a button is held. */
|
|
368
|
+
held?: true | 'optional';
|
|
357
369
|
target?: TargetSpec;
|
|
358
370
|
mods?: ModSpec;
|
|
359
371
|
phase?: PhaseSpec;
|
|
@@ -410,10 +422,15 @@ interface DropSpec {
|
|
|
410
422
|
* its moves update it, the release commits it, and leaving the surface or
|
|
411
423
|
* canceling the press cancels it. An immediate action fires once, on the
|
|
412
424
|
* release.
|
|
425
|
+
*
|
|
426
|
+
* `target` is matched against what is under the carry. With one, an ongoing
|
|
427
|
+
* action starts on the first step that is over its target, as the carry comes
|
|
428
|
+
* over or as it moves on, and an immediate action fires only on a release over it.
|
|
413
429
|
*/
|
|
414
430
|
interface CarrySpec {
|
|
415
431
|
kind: 'carry';
|
|
416
432
|
types?: string[];
|
|
433
|
+
target?: TargetSpec;
|
|
417
434
|
mods?: ModSpec;
|
|
418
435
|
phase?: PhaseSpec;
|
|
419
436
|
}
|
|
@@ -795,6 +812,8 @@ interface HoverEvent extends EventModifiers {
|
|
|
795
812
|
from?: HoverWhere;
|
|
796
813
|
/** The pointer has left the surface. Where it is and what it is over are its last move's. */
|
|
797
814
|
off?: boolean;
|
|
815
|
+
/** A button was held through this move. Never set on `off`. */
|
|
816
|
+
held?: boolean;
|
|
798
817
|
/** World-space position of the pointer. */
|
|
799
818
|
x: number;
|
|
800
819
|
y: number;
|
|
@@ -899,6 +918,10 @@ interface CarryEvent extends EventModifiers {
|
|
|
899
918
|
y: number;
|
|
900
919
|
clientX: number;
|
|
901
920
|
clientY: number;
|
|
921
|
+
/** What is under the carry, classified as a press there would be. */
|
|
922
|
+
affordance?: unknown;
|
|
923
|
+
bodyTarget?: BodyTarget;
|
|
924
|
+
bodyKind?: BodyKind;
|
|
902
925
|
}
|
|
903
926
|
/** External content pasted from the system clipboard. Carries no point. */
|
|
904
927
|
interface PasteEvent extends EventModifiers {
|
|
@@ -1141,15 +1164,31 @@ type ShortcutInput = MenuShortcut;
|
|
|
1141
1164
|
interface FormatShortcutOptions {
|
|
1142
1165
|
/** Defaults to the detected platform. */
|
|
1143
1166
|
platform?: Platform;
|
|
1167
|
+
/** {@link formatShortcutParts} only; {@link formatShortcut} picks its own. Defaults to `'auto'`. */
|
|
1168
|
+
legend?: LegendStyle;
|
|
1144
1169
|
}
|
|
1145
|
-
/**
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1170
|
+
/** One keymap on the way to a key: its label, and the chips of the leader that opens it. */
|
|
1171
|
+
interface ShortcutLeaderStep {
|
|
1172
|
+
label: string;
|
|
1173
|
+
keys: readonly KeyLegend[];
|
|
1174
|
+
}
|
|
1175
|
+
/** A shortcut as display chips: {@link formatShortcutParts}'s result. */
|
|
1176
|
+
interface ShortcutParts {
|
|
1177
|
+
/** The keymaps leading to the key, outermost first; empty for a key outside any keymap. */
|
|
1178
|
+
leader: readonly ShortcutLeaderStep[];
|
|
1179
|
+
/** The key's own chips: the modifiers, then the key. */
|
|
1180
|
+
keys: readonly KeyLegend[];
|
|
1181
|
+
}
|
|
1182
|
+
/** What {@link formatShortcut} writes after each leader step's label: `Loupe ▸ 2`. */
|
|
1183
|
+
declare const SHORTCUT_LEADER_SEPARATOR = " \u25B8 ";
|
|
1184
|
+
/** Format a shortcut as display chips, one per key: the modifiers, then the
|
|
1185
|
+
* key, each as the platform's keyboard prints it, so `mod` is `⌘` on macOS
|
|
1186
|
+
* and `Ctrl` elsewhere, after the keymaps that lead to it (`Loupe ▸ 2`).
|
|
1187
|
+
* UIs that want a boxed per-key look render each chip in its own element.
|
|
1188
|
+
* `shift: 'optional'` gives an optional chip. */
|
|
1189
|
+
declare function formatShortcutParts(b: ShortcutInput | undefined, opts?: FormatShortcutOptions): ShortcutParts | undefined;
|
|
1151
1190
|
/** Format a shortcut as a single display string. Order: mod, shift, alt,
|
|
1152
|
-
* key. On macOS the glyphs run together (`⌘⇧Z`); elsewhere the keys are
|
|
1191
|
+
* key, after each keymap that leads to it (`Loupe ▸ ⌘2`). On macOS the glyphs run together (`⌘⇧Z`); elsewhere the keys are
|
|
1153
1192
|
* spelled out and joined with `+` (`Ctrl+Shift+Z`). Returns `undefined` for
|
|
1154
1193
|
* `undefined` input so callers can `??` a fallback. When `key` is an array,
|
|
1155
1194
|
* the first element is used. `shift: 'optional'` is treated as falsy. */
|
|
@@ -1158,7 +1197,7 @@ declare function formatShortcut(b: ShortcutInput | undefined, opts?: FormatShort
|
|
|
1158
1197
|
/**
|
|
1159
1198
|
* A shortcut as key legends, one per key, as `@weasel-js/ui`'s `KeySequence` draws them: mod, shift, alt, then the
|
|
1160
1199
|
* key, each in the platform's own legend (`⌘` on macOS, `Ctrl` elsewhere).
|
|
1161
|
-
* `formatShortcutParts`
|
|
1200
|
+
* Only the key itself: `formatShortcutParts` adds the keymaps that lead to it. `shift: 'optional'`
|
|
1162
1201
|
* becomes an optional key; a key list
|
|
1163
1202
|
* renders its first key. Returns `undefined` for no shortcut.
|
|
1164
1203
|
*
|
|
@@ -1168,6 +1207,32 @@ declare function formatShortcut(b: ShortcutInput | undefined, opts?: FormatShort
|
|
|
1168
1207
|
*/
|
|
1169
1208
|
declare function keySpecsFromShortcut(shortcut: ShortcutInput | undefined, opts?: KeySpecsFromModsOptions): readonly KeyLegend[] | undefined;
|
|
1170
1209
|
|
|
1210
|
+
/**
|
|
1211
|
+
* The legend of the physical key a `KeyboardEvent.code` names (`KeyA`, `ShiftLeft`, `ArrowUp`), as
|
|
1212
|
+
* {@link keySpecFromKey} prints that key on the platform: `MetaLeft` is `⌘` on macOS and `⊞` on
|
|
1213
|
+
* Windows. Letters and punctuation print as a US keyboard prints them. `opts.labels` answers by code
|
|
1214
|
+
* first, then as it does for {@link keySpecFromKey} and {@link keySpecsFromMods}.
|
|
1215
|
+
*/
|
|
1216
|
+
declare function keySpecFromCode(code: string, opts?: KeySpecsFromModsOptions): KeyLegend;
|
|
1217
|
+
|
|
1218
|
+
/** A keystroke in the `Mod+Shift+K` form. Modifiers are case-insensitive:
|
|
1219
|
+
* `Meta`/`Cmd`/`Command`, `Ctrl`/`Control`, `Alt`/`Option`, `Shift`, and
|
|
1220
|
+
* `Mod` for Cmd on Apple platforms and Ctrl elsewhere. */
|
|
1221
|
+
declare function key(shortcut: string): KeySpec;
|
|
1222
|
+
/** The same keystroke held down, as a `key-held` spec. */
|
|
1223
|
+
declare function held(shortcut: string): KeyHeldSpec;
|
|
1224
|
+
/** A binding override that removes the binding. */
|
|
1225
|
+
declare function unbound(): null;
|
|
1226
|
+
/** What a binding override is written as: a route string, a spec, or `null` to unbind. */
|
|
1227
|
+
type BindingOverrideInput = string | GestureSpec | null;
|
|
1228
|
+
/** Read a binding override into the spec it names, or `null`. */
|
|
1229
|
+
declare function bindingSpec(input: BindingOverrideInput): GestureSpec | null;
|
|
1230
|
+
/** A key spec as its route string — what `bindingSpec` reads back to an
|
|
1231
|
+
* equal spec — or `null` for a key the route grammar cannot spell (`?`,
|
|
1232
|
+
* `)`, `*`). A spec is plain JSON, so store that one as it is. A key list is
|
|
1233
|
+
* written as its first key. */
|
|
1234
|
+
declare function keySpecRoute(spec: KeySpec | KeyHeldSpec): string | null;
|
|
1235
|
+
|
|
1171
1236
|
/**
|
|
1172
1237
|
* The nearest element `from` sits inside that can host a portalled overlay,
|
|
1173
1238
|
* or `null` when there is none and the body is the only answer.
|
|
@@ -1356,6 +1421,13 @@ interface PointerSample extends EventModifiers, PointerSampleStylus {
|
|
|
1356
1421
|
clientY: number;
|
|
1357
1422
|
/** What the originating event was aimed at. */
|
|
1358
1423
|
target?: unknown;
|
|
1424
|
+
/**
|
|
1425
|
+
* When the input happened, on the recognizer clock's timeline: a DOM event's
|
|
1426
|
+
* `timeStamp` beside `performance.now()`. The windows between two inputs are
|
|
1427
|
+
* measured on it, so a long task that delays an event's handling does not
|
|
1428
|
+
* widen them. Read as the clock's `now()` when absent, 0, or ahead of it.
|
|
1429
|
+
*/
|
|
1430
|
+
timeStamp?: number;
|
|
1359
1431
|
}
|
|
1360
1432
|
/** A pointer going down, with what the host found under it. */
|
|
1361
1433
|
interface PressSample extends PointerSample {
|
|
@@ -1485,4 +1557,4 @@ declare function activatesFocusedControl(e: KeyboardEvent): boolean;
|
|
|
1485
1557
|
*/
|
|
1486
1558
|
declare function focusedControlOwnsKey(e: KeyboardEvent): boolean;
|
|
1487
1559
|
|
|
1488
|
-
export { ACTIVE_SIGILS, type BodyClassification, type BodyKind, type BodyTarget, CONTROL_SELECTOR, type CarryEvent, type CarrySpec, type ChannelRef, type ClaimableGesture, type ClickEvent, type ClickMemory, type ClickObserver, type ClickSpec, type ContextMenuEvent, type ContextMenuSpec, DOUBLE_CLICK_MAX_MS, DOUBLE_CLICK_MAX_PX, DRAG_THRESHOLD_PX, type DescribeRouteOptions, type DoubleClickBody, type DoubleClickEvent, type DoubleClickSpec, type DragSpec, type DropEvent, type DropSpec, type EventModifiers, type FixedSeat, type FormatShortcutOptions, GESTURE_DESCRIPTORS, type GestureArgSpec, type GestureDescriptor, type GestureName, type GestureSpec, type HeldPointers, type HeldPress, type HoverEvent, type HoverSpec, type HoverWhere, type IngestItem, type InputEvent, type KeyEvent, type KeyHeldEvent, type KeyHeldSpec, type KeyLabels, type KeyLegend, type KeySpec, type KeySpecsFromModsOptions, LONG_PRESS_MS, type LegendStyle, type LogicalMod, type LogicalModSpec, type LongPressEvent, type LongPressSpec, MODIFIER_LABELS, MOD_NAME_SET, type ModRequirement, type ModSpec, type ModifierCombo, type ModifierKey, type ModifiersEvent, type MultiTouchEvent, type MultiTouchGeometry, type MultiTouchSpec, type MultiTouchTapEvent, type MultiTouchTapSpec, type OptionalMod, type ParsedKeyRoute, type ParsedModifiers, type ParsedRoute, type PasteEvent, type PasteSpec, type PhaseAtom, type PhaseContext, type PhaseSpec, type PinchEvent, type PinchSpec, type Platform, type Point, type PointerCancelEvent, type PointerDownEvent, type PointerDownSpec, type PointerIdentity, type PointerMoveEvent, type PointerRecognizer, type PointerRecognizerOptions, type PointerSample, type PointerSampleStylus, type PointerUpEvent, type PressFacts, type PressSample, RESERVED_ID_NAMES, RESERVED_ID_PREFIXES, RESERVED_SIGILS, ROUTE_FIELD_DEFINITIONS, ROUTE_TERMS, type RecognizerClock, type RecognizerObserver, type RecognizerSink, type ReleaseFacts, type ReleaseOutcome, type RouteDescriptionPart, type RouteFieldName, type RoutePhase, type RouteTermLabel, type ShortcutInput, TAP_THRESHOLD_PX, type TargetPredicate, type TargetSpec, type TargetSpecForm, UNKNOWN_MIME, VALID_MOD_NAMES, type WheelEvent, type WheelSpec, activatesFocusedControl, bodyPredicate, canonicalModifiers, clickEvents, collapseShiftPairs, createPointerRecognizer, describeRoute, describeRouteParts, detectPlatform, fixedSeat, focusedControlOwnsKey, formatKeyRoute, formatPhaseAtom, formatRoute, formatShortcut, formatShortcutParts, getGestureDescriptor, heldPointers, hitPredicate, isApplePlatform, isEditableTarget, isInControlWithin, isKnownGestureName, keyRouteToSpec, keySpecFromKey, keySpecsFromMods, keySpecsFromShortcut, longPressEvents, matchIngestTypes, matchKey, matchModifiers, matchPhase, matchSpec, matchTarget, mimeMatchesGlob, modifierComboToParsed, mods, multiTouchGeometry, nearestPortalHost, parseKeyRoute, parseRoute, parseTargetSpec, pastDragThreshold, routeGestureForSpecKind, routeToSpec, specKindForRouteGesture, specificity, stylusOf };
|
|
1560
|
+
export { ACTIVE_SIGILS, type BindingOverrideInput, type BodyClassification, type BodyKind, type BodyTarget, CONTROL_SELECTOR, type CarryEvent, type CarrySpec, type ChannelRef, type ClaimableGesture, type ClickEvent, type ClickMemory, type ClickObserver, type ClickSpec, type ContextMenuEvent, type ContextMenuSpec, DOUBLE_CLICK_MAX_MS, DOUBLE_CLICK_MAX_PX, DRAG_THRESHOLD_PX, type DescribeRouteOptions, type DoubleClickBody, type DoubleClickEvent, type DoubleClickSpec, type DragSpec, type DropEvent, type DropSpec, type EventModifiers, type FixedSeat, type FormatShortcutOptions, GESTURE_DESCRIPTORS, type GestureArgSpec, type GestureDescriptor, type GestureName, type GestureSpec, type HeldPointers, type HeldPress, type HoverEvent, type HoverSpec, type HoverWhere, type IngestItem, type InputEvent, type KeyEvent, type KeyHeldEvent, type KeyHeldSpec, type KeyLabels, type KeyLegend, type KeySpec, type KeySpecsFromModsOptions, LONG_PRESS_MS, type LegendStyle, type LogicalMod, type LogicalModSpec, type LongPressEvent, type LongPressSpec, MODIFIER_LABELS, MOD_NAME_SET, type ModRequirement, type ModSpec, type ModifierCombo, type ModifierKey, type ModifiersEvent, type MultiTouchEvent, type MultiTouchGeometry, type MultiTouchSpec, type MultiTouchTapEvent, type MultiTouchTapSpec, type OptionalMod, type ParsedKeyRoute, type ParsedModifiers, type ParsedRoute, type PasteEvent, type PasteSpec, type PhaseAtom, type PhaseContext, type PhaseSpec, type PinchEvent, type PinchSpec, type Platform, type Point, type PointerCancelEvent, type PointerDownEvent, type PointerDownSpec, type PointerIdentity, type PointerMoveEvent, type PointerRecognizer, type PointerRecognizerOptions, type PointerSample, type PointerSampleStylus, type PointerUpEvent, type PressFacts, type PressSample, RESERVED_ID_NAMES, RESERVED_ID_PREFIXES, RESERVED_SIGILS, ROUTE_FIELD_DEFINITIONS, ROUTE_TERMS, type RecognizerClock, type RecognizerObserver, type RecognizerSink, type ReleaseFacts, type ReleaseOutcome, type RouteDescriptionPart, type RouteFieldName, type RoutePhase, type RouteTermLabel, SHORTCUT_LEADER_SEPARATOR, type ShortcutInput, type ShortcutLeaderStep, type ShortcutParts, TAP_THRESHOLD_PX, type TargetPredicate, type TargetSpec, type TargetSpecForm, UNKNOWN_MIME, VALID_MOD_NAMES, type WheelEvent, type WheelSpec, activatesFocusedControl, bindingSpec, bodyPredicate, canonicalModifiers, clickEvents, collapseShiftPairs, createPointerRecognizer, describeRoute, describeRouteParts, detectPlatform, fixedSeat, focusedControlOwnsKey, formatKeyRoute, formatPhaseAtom, formatRoute, formatShortcut, formatShortcutParts, getGestureDescriptor, held, heldPointers, hitPredicate, isApplePlatform, isEditableTarget, isInControlWithin, isKnownGestureName, key, keyRouteToSpec, keySpecFromCode, keySpecFromKey, keySpecRoute, keySpecsFromMods, keySpecsFromShortcut, longPressEvents, matchIngestTypes, matchKey, matchModifiers, matchPhase, matchSpec, matchTarget, mimeMatchesGlob, modifierComboToParsed, mods, multiTouchGeometry, nearestPortalHost, parseKeyRoute, parseRoute, parseTargetSpec, pastDragThreshold, routeGestureForSpecKind, routeToSpec, specKindForRouteGesture, specificity, stylusOf, unbound };
|