@weasel-js/gestures 1.9.4 → 1.10.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 +386 -206
- package/dist/index.js +401 -19
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* Reflection, matcher, and inspector UI all read this table. Adding a new
|
|
8
8
|
* gesture name in one place updates every consumer.
|
|
9
9
|
*/
|
|
10
|
-
type GestureName = 'click' | 'pointerDown' | 'dblTap' | 'drag' | 'wheel' | 'pinch' | 'keyDown' | 'keyUp' | 'keyHeld' | 'contextMenu' | 'longPress' | 'multiTouch' | 'multiTouchTap' | 'drop' | 'paste';
|
|
10
|
+
type GestureName = 'click' | 'pointerDown' | 'hover' | 'dblTap' | 'drag' | 'wheel' | 'pinch' | 'keyDown' | 'keyUp' | 'keyHeld' | 'contextMenu' | 'longPress' | 'multiTouch' | 'multiTouchTap' | 'drop' | 'paste';
|
|
11
11
|
/**
|
|
12
12
|
* Gesture kinds an affordance claim can bar, in the spec vocabulary bindings
|
|
13
13
|
* are written in. `'pointer'` is one token because `pointerDown` / `click` /
|
|
@@ -62,9 +62,9 @@ type ModifierCombo = 'default' | 'mod' | 'shift' | 'alt' | 'mod+shift' | 'mod+al
|
|
|
62
62
|
*/
|
|
63
63
|
declare function mods(...keys: ReadonlyArray<'mod' | 'shift' | 'alt'>): ModifierCombo;
|
|
64
64
|
|
|
65
|
-
/**
|
|
66
|
-
*
|
|
67
|
-
*
|
|
65
|
+
/** Where a tool stands when a binding is matched: `engaged` while an action it
|
|
66
|
+
* began is still in flight, `initial` otherwise. The route grammar's `[phase]`
|
|
67
|
+
* slot draws from this set. */
|
|
68
68
|
type RoutePhase = 'initial' | 'engaged';
|
|
69
69
|
|
|
70
70
|
/**
|
|
@@ -83,9 +83,7 @@ type RoutePhase = 'initial' | 'engaged';
|
|
|
83
83
|
* sigil = '+' | '?' -- ! @ # $ % ^ & * reserved as id-prefix
|
|
84
84
|
* modName = 'mod' | 'shift' | 'alt' | 'ctrl' | 'meta'
|
|
85
85
|
*
|
|
86
|
-
*
|
|
87
|
-
* own phase"). `[engaged]` ≡ `[&:engaged]`; `[*]` ≡ `[&:*]`. The truly-loose
|
|
88
|
-
* form (any channel, any phase) is `[*:*]`.
|
|
86
|
+
* The truly-loose form (any channel, any phase) is `[*:*]`.
|
|
89
87
|
*
|
|
90
88
|
* Examples:
|
|
91
89
|
* [initial] click => empty +shift -- self idle
|
|
@@ -118,9 +116,7 @@ declare const RESERVED_ID_NAMES: ReadonlySet<string>;
|
|
|
118
116
|
/** v3 modifier requirement on a single modifier key. Absent from a
|
|
119
117
|
* `ParsedModifiers` map means "must not be held" (the strict default). */
|
|
120
118
|
type ModRequirement = 'required' | 'optional';
|
|
121
|
-
/** Canonical modifier names accepted in the modSlot, in canonical order.
|
|
122
|
-
* Single source of truth: the {@link ModifierKey} type and the runtime
|
|
123
|
-
* validator (`MOD_NAME_SET`) are both derived from this tuple. */
|
|
119
|
+
/** Canonical modifier names accepted in the modSlot, in canonical order. */
|
|
124
120
|
declare const VALID_MOD_NAMES: readonly ["mod", "shift", "alt", "ctrl", "meta"];
|
|
125
121
|
/** A single modifier name accepted in the modSlot. */
|
|
126
122
|
type ModifierKey = (typeof VALID_MOD_NAMES)[number];
|
|
@@ -167,18 +163,12 @@ declare function parseRoute(input: string): ParsedRoute;
|
|
|
167
163
|
declare function formatPhaseAtom(a: PhaseAtom): string;
|
|
168
164
|
/** Visual-collapse pass: given a list of route strings, fold pairs that
|
|
169
165
|
* differ ONLY in `shift` presence (one has `+shift`, the other doesn't,
|
|
170
|
-
* everything else identical) into a single route with `?shift`.
|
|
171
|
-
* for inspector / palette displays that want to show "Cmd+[" and
|
|
172
|
-
* "Cmd+Shift+[" as one Cmd+?Shift+[ chip rather than two rows.
|
|
166
|
+
* everything else identical) into a single route with `?shift`.
|
|
173
167
|
*
|
|
174
168
|
* Preserves input order — the first member of each fold-pair holds the
|
|
175
|
-
* position; the second is dropped.
|
|
176
|
-
* vs absent twin pass through unchanged. Does NOT fold other modifier
|
|
169
|
+
* position; the second is dropped. Does NOT fold other modifier
|
|
177
170
|
* pairs (alt/ctrl/meta/mod) — those tend to carry meaning across the
|
|
178
|
-
* same key
|
|
179
|
-
* actions, but Cmd+] vs Cmd+Shift+] is more often parametric variation
|
|
180
|
-
* of one action). Open the helper if a use case for the other
|
|
181
|
-
* modifiers shows up.
|
|
171
|
+
* same key.
|
|
182
172
|
*/
|
|
183
173
|
declare function collapseShiftPairs(routes: readonly string[]): string[];
|
|
184
174
|
/** Render a parsed route back to a canonical route string: shorthand where
|
|
@@ -186,32 +176,20 @@ declare function collapseShiftPairs(routes: readonly string[]): string[];
|
|
|
186
176
|
* `parseRoute(formatRoute(r))` yields `r` again. */
|
|
187
177
|
declare function formatRoute(r: ParsedRoute): string;
|
|
188
178
|
|
|
189
|
-
/**
|
|
190
|
-
* GestureSpec — describes the form of a user input event that can fire an action.
|
|
191
|
-
*
|
|
192
|
-
* Used by `Action.defaultBinding` (the action's preferred gesture) and by
|
|
193
|
-
* `GestureBinding.spec` (a tool's binding table entry). The dispatcher matches
|
|
194
|
-
* incoming input events against registered specs to determine which action to
|
|
195
|
-
* invoke.
|
|
196
|
-
*
|
|
197
|
-
* See `docs/superpowers/specs/2026-05-16-registry-unification-design.md` § "Types".
|
|
198
|
-
*/
|
|
179
|
+
/** GestureSpec — describes the form of a user input event that can fire an action. */
|
|
199
180
|
/** Optional modifier-key requirement for a gesture spec.
|
|
200
181
|
*
|
|
201
|
-
* Matching
|
|
202
|
-
*
|
|
203
|
-
*
|
|
204
|
-
*
|
|
205
|
-
* This mirrors today's `KeyBinding` matcher and keeps conflict detection
|
|
206
|
-
* coherent.
|
|
182
|
+
* Matching is strict: an omitted modifier field means the modifier MUST NOT
|
|
183
|
+
* be held — a bare `{ kind: 'key', key: 'Escape' }` matches only unmodified
|
|
184
|
+
* Escape, NOT Cmd+Escape. A `true` means the modifier MUST be held; `false`
|
|
185
|
+
* is the same as omitted.
|
|
207
186
|
*
|
|
208
187
|
* `mod` is a platform-aware shorthand: matches `metaKey` on mac, `ctrlKey`
|
|
209
|
-
* elsewhere
|
|
188
|
+
* elsewhere.
|
|
210
189
|
*
|
|
211
190
|
* Every modifier additionally accepts `'optional'`, meaning "held or not,
|
|
212
|
-
* both acceptable" —
|
|
213
|
-
*
|
|
214
|
-
* does not.
|
|
191
|
+
* both acceptable" — used by actions like nudge whose step size depends on
|
|
192
|
+
* shift but whose firing does not.
|
|
215
193
|
*/
|
|
216
194
|
type ModSpec = Partial<{
|
|
217
195
|
alt: boolean | 'optional';
|
|
@@ -242,10 +220,8 @@ declare function hitPredicate(fn: (hit: unknown, bodyTarget?: string) => boolean
|
|
|
242
220
|
declare function bodyPredicate(fn: (bodyTarget: string | undefined) => boolean): TargetPredicate & {
|
|
243
221
|
readsAffordance: false;
|
|
244
222
|
};
|
|
245
|
-
/** Target selector for click and drag gesture specs.
|
|
246
|
-
*
|
|
247
|
-
* that ships, consumers can pass `{ kindOf: predicate }` to classify hits
|
|
248
|
-
* themselves.
|
|
223
|
+
/** Target selector for click and drag gesture specs. Consumers can pass
|
|
224
|
+
* `{ kindOf: predicate }` to classify hits themselves.
|
|
249
225
|
*
|
|
250
226
|
* Adding a form here is a compile error in `parseTargetSpec` until
|
|
251
227
|
* `TargetSpecForm` grows a matching variant — which is in turn a compile
|
|
@@ -254,19 +230,16 @@ type TargetSpec = 'empty' | 'selected-body' | 'unselected-body' | `kind:${string
|
|
|
254
230
|
kindOf: TargetPredicate;
|
|
255
231
|
};
|
|
256
232
|
/** Phase qualifier on a gesture spec. Restricts when the spec matches based
|
|
257
|
-
* on per-tool gesture-lifecycle state.
|
|
233
|
+
* on per-tool gesture-lifecycle state. When omitted, matches in any phase.
|
|
258
234
|
*
|
|
259
|
-
* Shorthand forms
|
|
235
|
+
* Shorthand forms gate on the binding's own tool:
|
|
260
236
|
* `'engaged'` → `[{ channel: '&', phase: 'engaged' }]` // self mid-gesture
|
|
261
237
|
* `'initial'` → `[{ channel: '&', phase: 'initial' }]` // self idle
|
|
262
238
|
* `'*'` → `[{ channel: '&', phase: '*' }]` // either self phase
|
|
263
239
|
*
|
|
264
240
|
* Array form for explicit channel:phase atoms — e.g. `[{ channel: 'rect',
|
|
265
241
|
* phase: 'engaged' }]` for "when the rect tool is mid-gesture, regardless of
|
|
266
|
-
* which scope I'm in."
|
|
267
|
-
* `@weasel-js/gestures/grammar` for the full lattice.
|
|
268
|
-
*
|
|
269
|
-
* When omitted, matches in any phase (preserves pre-phase behavior). */
|
|
242
|
+
* which scope I'm in." */
|
|
270
243
|
type PhaseSpec = 'initial' | 'engaged' | '*' | readonly PhaseAtom[];
|
|
271
244
|
/** Single-keystroke gesture (keydown). */
|
|
272
245
|
interface KeySpec {
|
|
@@ -292,10 +265,8 @@ interface KeyHeldSpec {
|
|
|
292
265
|
mods?: ModSpec;
|
|
293
266
|
phase?: PhaseSpec;
|
|
294
267
|
}
|
|
295
|
-
/** Wheel-event gesture. `direction` filters by deltaY sign
|
|
296
|
-
*
|
|
297
|
-
* - `'down'` → matches only deltaY > 0
|
|
298
|
-
* - `'*'` → matches either sign (default; universal-wildcard convention) */
|
|
268
|
+
/** Wheel-event gesture. `direction` filters by deltaY sign: `'up'` matches
|
|
269
|
+
* only deltaY < 0, `'down'` only deltaY > 0, and the default `'*'` either. */
|
|
299
270
|
interface WheelSpec {
|
|
300
271
|
kind: 'wheel';
|
|
301
272
|
direction?: 'up' | 'down' | '*';
|
|
@@ -304,10 +275,9 @@ interface WheelSpec {
|
|
|
304
275
|
phase?: PhaseSpec;
|
|
305
276
|
}
|
|
306
277
|
/** Pinch reported as a scale factor about a focal point (WebKit
|
|
307
|
-
* `gesturechange`). `direction` filters by the sample's scale
|
|
308
|
-
*
|
|
309
|
-
*
|
|
310
|
-
* A touchscreen pinch is {@link MultiTouchSpec}, not this. */
|
|
278
|
+
* `gesturechange`). `direction` filters by the sample's scale: `'out'` is
|
|
279
|
+
* scale > 1, `'in'` is scale < 1; default `'*'`. A touchscreen pinch is
|
|
280
|
+
* {@link MultiTouchSpec}, not this. */
|
|
311
281
|
interface PinchSpec {
|
|
312
282
|
kind: 'pinch';
|
|
313
283
|
direction?: 'in' | 'out' | '*';
|
|
@@ -324,9 +294,7 @@ interface ClickSpec {
|
|
|
324
294
|
phase?: PhaseSpec;
|
|
325
295
|
}
|
|
326
296
|
/** Double-click: two `click` events within 600ms and 8px of each other.
|
|
327
|
-
* Synthesized by `useGestureDispatcher`; emitted AFTER the second
|
|
328
|
-
* `click`. Bindings that want to handle a double-click should declare
|
|
329
|
-
* this kind rather than chasing two `click` events. */
|
|
297
|
+
* Synthesized by `useGestureDispatcher`; emitted AFTER the second `click`. */
|
|
330
298
|
interface DoubleClickSpec {
|
|
331
299
|
kind: 'doubleClick';
|
|
332
300
|
target?: TargetSpec;
|
|
@@ -351,13 +319,10 @@ interface DragSpec {
|
|
|
351
319
|
}
|
|
352
320
|
/**
|
|
353
321
|
* Bare pointer press, matched at down time — before the dispatcher knows
|
|
354
|
-
* whether the gesture will become a click or a drag.
|
|
355
|
-
*
|
|
356
|
-
*
|
|
357
|
-
*
|
|
358
|
-
* highlights it immediately, and the drag that may follow then starts from an
|
|
359
|
-
* already-correct selection. Anything that can wait for the release belongs on
|
|
360
|
-
* a `click` spec, which does not fire on a press that turns into a drag.
|
|
322
|
+
* whether the gesture will become a click or a drag. Reach for this only when
|
|
323
|
+
* the effect must be visible while the button is still held; anything that
|
|
324
|
+
* can wait for the release belongs on a `click` spec, which does not fire on
|
|
325
|
+
* a press that turns into a drag.
|
|
361
326
|
*
|
|
362
327
|
* A matching binding does NOT own the gesture: the same press goes on to open
|
|
363
328
|
* a drag or synthesize a click as usual. Bind an immediate action here, not an
|
|
@@ -369,17 +334,30 @@ interface PointerDownSpec {
|
|
|
369
334
|
mods?: ModSpec;
|
|
370
335
|
phase?: PhaseSpec;
|
|
371
336
|
}
|
|
337
|
+
/**
|
|
338
|
+
* The pointer moving over the surface with no button pressed. Fires on every
|
|
339
|
+
* such move; a held pointer's moves belong to its drag and fire nothing here.
|
|
340
|
+
*
|
|
341
|
+
* A hover binding claims nothing. Every live binding that matches the move
|
|
342
|
+
* runs, not only the best one, and the move still reaches the hover-cursor
|
|
343
|
+
* pump. There is no press to own, so bind an immediate action, not an ongoing
|
|
344
|
+
* one. Its params carry `worldX` / `worldY`, `clientX` / `clientY`,
|
|
345
|
+
* `affordance`, `bodyTarget`, and `mods`.
|
|
346
|
+
*/
|
|
347
|
+
interface HoverSpec {
|
|
348
|
+
kind: 'hover';
|
|
349
|
+
target?: TargetSpec;
|
|
350
|
+
mods?: ModSpec;
|
|
351
|
+
phase?: PhaseSpec;
|
|
352
|
+
}
|
|
372
353
|
/**
|
|
373
354
|
* Press held past the long-press threshold without crossing the drag
|
|
374
355
|
* threshold. Synthesized by `useGestureDispatcher` from the pointer stream.
|
|
375
|
-
*
|
|
376
|
-
*
|
|
377
|
-
* second is an ordinary slow click, and firing on it would produce a context
|
|
378
|
-
* menu nobody asked for.
|
|
356
|
+
* Fires for `touch` and `pen` pointers only: a mouse held still is an
|
|
357
|
+
* ordinary slow click.
|
|
379
358
|
*
|
|
380
359
|
* When a long-press matches no binding, the dispatcher re-dispatches it as a
|
|
381
|
-
* `contextmenu` event
|
|
382
|
-
* consumer changes, while `longPress` stays independently bindable.
|
|
360
|
+
* `contextmenu` event, so `contextMenu` bindings work under a finger.
|
|
383
361
|
*/
|
|
384
362
|
interface LongPressSpec {
|
|
385
363
|
kind: 'longPress';
|
|
@@ -421,10 +399,8 @@ interface PasteSpec {
|
|
|
421
399
|
mods?: ModSpec;
|
|
422
400
|
phase?: PhaseSpec;
|
|
423
401
|
}
|
|
424
|
-
/** The full union of supported gesture spec kinds.
|
|
425
|
-
|
|
426
|
-
* the `Action` type. */
|
|
427
|
-
type GestureSpec = KeySpec | KeyHeldSpec | WheelSpec | PinchSpec | ClickSpec | DoubleClickSpec | ContextMenuSpec | DragSpec | PointerDownSpec | LongPressSpec | MultiTouchSpec | MultiTouchTapSpec | DropSpec | PasteSpec;
|
|
402
|
+
/** The full union of supported gesture spec kinds. */
|
|
403
|
+
type GestureSpec = KeySpec | KeyHeldSpec | WheelSpec | PinchSpec | ClickSpec | DoubleClickSpec | ContextMenuSpec | DragSpec | PointerDownSpec | HoverSpec | LongPressSpec | MultiTouchSpec | MultiTouchTapSpec | DropSpec | PasteSpec;
|
|
428
404
|
|
|
429
405
|
/**
|
|
430
406
|
* Mini-grammar for the `arg` slot of `keyDown` / `keyUp` routes.
|
|
@@ -537,11 +513,7 @@ declare function modifierComboToParsed(key: ModifierCombo): ParsedModifiers;
|
|
|
537
513
|
* `name=req` pairs joined by `&`. */
|
|
538
514
|
declare function canonicalModifiers(mods: ParsedModifiers): string;
|
|
539
515
|
|
|
540
|
-
/**
|
|
541
|
-
* Keyboard/pointer modifier flags carried by every {@link InputEvent} arm.
|
|
542
|
-
* Factored out so the four booleans are documented once instead of repeated
|
|
543
|
-
* on all twelve event shapes.
|
|
544
|
-
*/
|
|
516
|
+
/** Keyboard/pointer modifier flags carried by every {@link InputEvent} arm. */
|
|
545
517
|
interface EventModifiers {
|
|
546
518
|
altKey: boolean;
|
|
547
519
|
ctrlKey: boolean;
|
|
@@ -558,24 +530,15 @@ type BodyTarget = 'empty' | 'selected-body' | 'unselected-body';
|
|
|
558
530
|
/**
|
|
559
531
|
* Semantic kind of the node body under the point — `'text'`, `'rect'`, or an
|
|
560
532
|
* app's own `'app:note'`. Companion to {@link BodyTarget}, which says only how
|
|
561
|
-
* the body relates to the selection
|
|
562
|
-
* `
|
|
563
|
-
*
|
|
564
|
-
*
|
|
565
|
-
* Supplied by the same `classifyTarget` thunk that supplies `bodyTarget`, and
|
|
566
|
-
* absent for the same reasons plus one more: the thunk hit a body whose kind
|
|
567
|
-
* the scene can't name. An absent `bodyKind` makes every `kind:` form
|
|
568
|
-
* no-match, never a wildcard.
|
|
533
|
+
* the body relates to the selection. Supplied by the same `classifyTarget`
|
|
534
|
+
* thunk; an absent `bodyKind` makes every `kind:` form no-match, never a
|
|
535
|
+
* wildcard.
|
|
569
536
|
*/
|
|
570
537
|
type BodyKind = string;
|
|
571
538
|
/**
|
|
572
539
|
* What a scene hit-test found under a point — the shape a `classifyTarget`
|
|
573
540
|
* thunk returns, and the source of both {@link BodyTarget} and
|
|
574
541
|
* {@link BodyKind} on the events the matcher sees.
|
|
575
|
-
*
|
|
576
|
-
* One thunk returns both halves rather than two thunks returning one each:
|
|
577
|
-
* the two answers come from the same hit-test, and splitting them would cost
|
|
578
|
-
* a second pick on every pointer event.
|
|
579
542
|
*/
|
|
580
543
|
interface BodyClassification {
|
|
581
544
|
/** How the hit body relates to the current selection. */
|
|
@@ -650,14 +613,10 @@ interface PointerSampleStylus {
|
|
|
650
613
|
tiltY?: number;
|
|
651
614
|
}
|
|
652
615
|
/**
|
|
653
|
-
* Which physical pointer a sample came from
|
|
654
|
-
*
|
|
655
|
-
*
|
|
656
|
-
*
|
|
657
|
-
* mouse, each touch, and the stylus into one slot. Optional because
|
|
658
|
-
* synthesized events (tests, programmatic drags, the hover pump's
|
|
659
|
-
* `resolveOnly` probe) have no originating `PointerEvent`; those all key to
|
|
660
|
-
* the same default slot, which is the pre-`pointerId` behavior.
|
|
616
|
+
* Which physical pointer a sample came from, so the dispatcher can key
|
|
617
|
+
* in-flight gesture handles per pointer. Optional because synthesized events
|
|
618
|
+
* (tests, programmatic drags, the hover pump's `resolveOnly` probe) have no
|
|
619
|
+
* originating `PointerEvent`; those all key to the same default slot.
|
|
661
620
|
*/
|
|
662
621
|
interface PointerIdentity {
|
|
663
622
|
/** `PointerEvent.pointerId` from the originating DOM event. */
|
|
@@ -667,21 +626,17 @@ interface PointerIdentity {
|
|
|
667
626
|
interface PointerDownEvent extends EventModifiers, PointerSampleStylus, PointerIdentity {
|
|
668
627
|
kind: 'pointerdown';
|
|
669
628
|
/**
|
|
670
|
-
* Which of the two dispatches this press produces.
|
|
671
|
-
*
|
|
672
|
-
* A physical pointerdown is dispatched twice, for two different audiences:
|
|
629
|
+
* Which of the two dispatches this press produces. A physical pointerdown
|
|
630
|
+
* is dispatched twice:
|
|
673
631
|
*
|
|
674
632
|
* - `'press'` — emitted immediately, at down time. Matches `pointerDown`
|
|
675
|
-
* specs only.
|
|
676
|
-
* gesture is classified (select applies the selection here, so
|
|
677
|
-
* press-and-hold highlights without waiting for a release).
|
|
633
|
+
* specs only.
|
|
678
634
|
* - omitted — the copy the dispatcher buffers and flushes once movement
|
|
679
635
|
* crosses the drag threshold. Matches `drag` specs only, and is what
|
|
680
636
|
* opens a drag handle.
|
|
681
637
|
*
|
|
682
638
|
* The split is what keeps one press from firing both a `pointerDown` and a
|
|
683
|
-
* `drag` binding.
|
|
684
|
-
* omitted, so drag prediction is unaffected.
|
|
639
|
+
* `drag` binding.
|
|
685
640
|
*/
|
|
686
641
|
stage?: 'press';
|
|
687
642
|
target?: unknown;
|
|
@@ -728,8 +683,6 @@ interface ClickEvent extends EventModifiers {
|
|
|
728
683
|
/**
|
|
729
684
|
* World-space coordinates of the click, derived via the `clientToWorld`
|
|
730
685
|
* thunk supplied to the dispatcher. Absent when the thunk isn't wired.
|
|
731
|
-
* Forwarded into action params so click invokers can act on the click's
|
|
732
|
-
* position without their own pointer-listener plumbing.
|
|
733
686
|
*/
|
|
734
687
|
x?: number;
|
|
735
688
|
y?: number;
|
|
@@ -743,23 +696,18 @@ interface ClickEvent extends EventModifiers {
|
|
|
743
696
|
/**
|
|
744
697
|
* World-space coordinates of the *press* that opened this click, as opposed
|
|
745
698
|
* to `x`/`y`, which are the release. The two differ by up to the
|
|
746
|
-
* drag threshold (`DRAG_THRESHOLD_PX`, in screen pixels).
|
|
747
|
-
*
|
|
748
|
-
*
|
|
749
|
-
*
|
|
750
|
-
* press point keeps a snapped coordinate stable against the small drift
|
|
751
|
-
* between press and release. Absent when the `clientToWorld` thunk isn't
|
|
752
|
-
* wired, same as `x`/`y`.
|
|
699
|
+
* drag threshold (`DRAG_THRESHOLD_PX`, in screen pixels). Actions that place
|
|
700
|
+
* geometry at the click want this one: pinning to the press point keeps a
|
|
701
|
+
* snapped coordinate stable against the drift between press and release.
|
|
702
|
+
* Absent when the `clientToWorld` thunk isn't wired, same as `x`/`y`.
|
|
753
703
|
*/
|
|
754
704
|
pressX?: number;
|
|
755
705
|
pressY?: number;
|
|
756
706
|
/**
|
|
757
707
|
* Affordance the *press* landed on, carried forward from the pointerdown
|
|
758
|
-
*
|
|
759
|
-
*
|
|
760
|
-
*
|
|
761
|
-
* would receive the raw DOM element while the same predicate on a drag spec
|
|
762
|
-
* receives the affordance.
|
|
708
|
+
* like {@link ClickEvent.bodyTarget} is. Without this a `kindOf` target on
|
|
709
|
+
* a click spec would receive the raw DOM element while the same predicate
|
|
710
|
+
* on a drag spec receives the affordance.
|
|
763
711
|
*/
|
|
764
712
|
affordance?: unknown;
|
|
765
713
|
bodyTarget?: BodyTarget;
|
|
@@ -793,6 +741,18 @@ interface ContextMenuEvent extends EventModifiers {
|
|
|
793
741
|
bodyTarget?: BodyTarget;
|
|
794
742
|
bodyKind?: BodyKind;
|
|
795
743
|
}
|
|
744
|
+
/** A move of a pointer with no button pressed. Matched by `hover` specs. */
|
|
745
|
+
interface HoverEvent extends EventModifiers {
|
|
746
|
+
kind: 'hover';
|
|
747
|
+
/** World-space position of the pointer. */
|
|
748
|
+
x: number;
|
|
749
|
+
y: number;
|
|
750
|
+
clientX?: number;
|
|
751
|
+
clientY?: number;
|
|
752
|
+
affordance?: unknown;
|
|
753
|
+
bodyTarget?: BodyTarget;
|
|
754
|
+
bodyKind?: BodyKind;
|
|
755
|
+
}
|
|
796
756
|
/** A press held past the long-press threshold without moving. */
|
|
797
757
|
interface LongPressEvent extends EventModifiers {
|
|
798
758
|
kind: 'longpress';
|
|
@@ -818,9 +778,8 @@ interface MultiTouchEvent extends EventModifiers {
|
|
|
818
778
|
* which is the space `zoomAt` anchors in. Not client coords, and not world:
|
|
819
779
|
* calling `clientToWorld` on it subtracts the canvas origin a second time.
|
|
820
780
|
*
|
|
821
|
-
*
|
|
822
|
-
*
|
|
823
|
-
* pointerdown-triggered multitouch event.
|
|
781
|
+
* Present on the event a finger landing produces and on each move of a
|
|
782
|
+
* running gesture; absent on the one that ends it.
|
|
824
783
|
*/
|
|
825
784
|
centroid?: {
|
|
826
785
|
x: number;
|
|
@@ -829,10 +788,15 @@ interface MultiTouchEvent extends EventModifiers {
|
|
|
829
788
|
/**
|
|
830
789
|
* Distance between the two primary pointers, in CSS pixels. A distance is
|
|
831
790
|
* origin-free, so it reads the same in client and canvas-local space.
|
|
832
|
-
*
|
|
833
|
-
* event.
|
|
791
|
+
* Present and absent alongside `centroid`.
|
|
834
792
|
*/
|
|
835
793
|
spread?: number;
|
|
794
|
+
/**
|
|
795
|
+
* Direction from the first of the two primary pointers to the second, in
|
|
796
|
+
* degrees in (-180, 180], growing clockwise on screen. Present and absent
|
|
797
|
+
* alongside `centroid`.
|
|
798
|
+
*/
|
|
799
|
+
angle?: number;
|
|
836
800
|
/**
|
|
837
801
|
* Set on the event that ends the running multitouch gesture, whatever its
|
|
838
802
|
* finger count: `'commit'` when a finger lifts, `'cancel'` when one of its
|
|
@@ -876,47 +840,23 @@ interface PasteEvent extends EventModifiers {
|
|
|
876
840
|
items: readonly IngestItem[];
|
|
877
841
|
}
|
|
878
842
|
/**
|
|
879
|
-
* Normalized input-event shape consumed by the pure matcher.
|
|
880
|
-
* React seam (`useGestureDispatcher`) from DOM events. Pump-only events
|
|
843
|
+
* Normalized input-event shape consumed by the pure matcher. Pump-only events
|
|
881
844
|
* ({@link PointerMoveEvent}, {@link PointerUpEvent}, {@link PointerCancelEvent})
|
|
882
845
|
* ride in the same union so the dispatcher's `handleInput` signature stays
|
|
883
846
|
* uniform; the matcher itself never matches them.
|
|
884
847
|
*
|
|
885
848
|
* The `affordance?` field on {@link PointerDownEvent} is widened to `unknown`
|
|
886
849
|
* in this package — the kit narrows it back to `AffordanceHit` at consumption.
|
|
887
|
-
* This keeps `@weasel-js/gestures` free of any kit-affordance type.
|
|
888
850
|
*/
|
|
889
|
-
type InputEvent = KeyEvent | KeyHeldEvent | WheelEvent | PinchEvent | PointerDownEvent | PointerMoveEvent | PointerUpEvent | PointerCancelEvent | ClickEvent | DoubleClickEvent | ContextMenuEvent | LongPressEvent | MultiTouchEvent | MultiTouchTapEvent | DropEvent | PasteEvent;
|
|
851
|
+
type InputEvent = KeyEvent | KeyHeldEvent | WheelEvent | PinchEvent | PointerDownEvent | PointerMoveEvent | HoverEvent | PointerUpEvent | PointerCancelEvent | ClickEvent | DoubleClickEvent | ContextMenuEvent | LongPressEvent | MultiTouchEvent | MultiTouchTapEvent | DropEvent | PasteEvent;
|
|
890
852
|
|
|
891
853
|
/**
|
|
892
|
-
*
|
|
893
|
-
*
|
|
894
|
-
* The kit's dispatcher orchestrator wraps these primitives with its
|
|
895
|
-
* actions-layer concerns (BindingScope, ScopedBinding, MatchResult, matchBest).
|
|
896
|
-
*
|
|
897
|
-
* ## key-held phase decision
|
|
898
|
-
* `matchSpec` returns `true` only for `phase: 'down'`, not `phase: 'up'`.
|
|
899
|
-
* The dispatcher tracks the held key independently and handles the `up` phase
|
|
900
|
-
* itself; the matcher never sees an "un-match" it needs to distinguish.
|
|
901
|
-
* This keeps the matcher's output a simple boolean and avoids a three-valued
|
|
902
|
-
* return type.
|
|
903
|
-
*
|
|
904
|
-
* ## TargetSpec string forms
|
|
905
|
-
* Every form `TargetSpec` declares is resolved here, each from a different
|
|
906
|
-
* field the dispatcher packs onto the event:
|
|
907
|
-
*
|
|
908
|
-
* | Form | Read from | Supplied by |
|
|
909
|
-
* | --- | --- | --- |
|
|
910
|
-
* | `'empty'` / `'selected-body'` / `'unselected-body'` | `bodyTarget` | the `classifyTarget` thunk |
|
|
911
|
-
* | `kind:<k>` / `kind:<k>:selected` | `bodyKind` + `bodyTarget` | the `classifyTarget` thunk's node-kind resolver |
|
|
912
|
-
* | `affordance:<k>` | the raw target's `.kind` | the `affordanceAt` thunk |
|
|
913
|
-
* | `{ kindOf }` | the raw target + `bodyTarget` | both |
|
|
914
|
-
*
|
|
915
|
-
* A form whose source field is absent does not match — an unwired
|
|
916
|
-
* `classifyTarget` makes every `bodyTarget`/`bodyKind` form `false` rather
|
|
917
|
-
* than a silent wildcard. That is deliberate: a binding that can't be
|
|
918
|
-
* evaluated should stay out of the way of one that can.
|
|
854
|
+
* The stylus fields `src` carries, as a spread-able partial: a sample that
|
|
855
|
+
* carries none of them adds no `undefined`-valued keys to what it is spread into.
|
|
919
856
|
*/
|
|
857
|
+
declare function stylusOf(src: PointerSampleStylus): PointerSampleStylus;
|
|
858
|
+
|
|
859
|
+
/** Pure gesture matcher — no React, no state, no DOM. */
|
|
920
860
|
|
|
921
861
|
/** The modifier-state fields `matchModifiers` reads. Structural, so a DOM
|
|
922
862
|
* `KeyboardEvent` or `PointerEvent` satisfies it directly. */
|
|
@@ -929,27 +869,21 @@ type ModifiersEvent = {
|
|
|
929
869
|
/**
|
|
930
870
|
* Strict modifier match.
|
|
931
871
|
*
|
|
932
|
-
* - Omitted
|
|
933
|
-
* - `true
|
|
934
|
-
* - `
|
|
935
|
-
* - `
|
|
936
|
-
*
|
|
937
|
-
*
|
|
938
|
-
* When `mod` is set, the corresponding `meta`/`ctrl` field is implied AND
|
|
939
|
-
* the *other* platform key is forbidden. Callers should not combine `mod`
|
|
940
|
-
* with `meta`/`ctrl`.
|
|
872
|
+
* - Omitted or `false`: MUST NOT be held.
|
|
873
|
+
* - `true`: MUST be held.
|
|
874
|
+
* - `'optional'`: accepts either held or unheld.
|
|
875
|
+
* - `mod` is platform-aware: matches `metaKey` on mac, `ctrlKey` elsewhere,
|
|
876
|
+
* and the *other* platform key is forbidden. Callers should not combine
|
|
877
|
+
* `mod` with `meta`/`ctrl`.
|
|
941
878
|
*/
|
|
942
879
|
declare function matchModifiers(e: ModifiersEvent, mods: ModSpec | undefined, isMac: boolean): boolean;
|
|
943
880
|
/** Case-insensitive key match; supports string or string[] (any-of). */
|
|
944
881
|
declare function matchKey(eventKey: string, specKey: string | string[]): boolean;
|
|
945
882
|
/**
|
|
946
883
|
* A {@link TargetSpec} resolved to its form, with the parts each form encodes
|
|
947
|
-
* in its string pulled out.
|
|
948
|
-
*
|
|
949
|
-
*
|
|
950
|
-
* each does something different — `matchTarget` below, and `targetRank` /
|
|
951
|
-
* `targetConsultsAffordance` in `@weasel-js/core`'s dispatcher matcher — so
|
|
952
|
-
* they switch on `form` exhaustively rather than re-deriving the prefixes.
|
|
884
|
+
* in its string pulled out. This is the one enumeration of the target forms:
|
|
885
|
+
* sites that act on it switch on `form` exhaustively rather than re-deriving
|
|
886
|
+
* the prefixes.
|
|
953
887
|
*/
|
|
954
888
|
type TargetSpecForm = {
|
|
955
889
|
form: 'body';
|
|
@@ -976,16 +910,13 @@ declare function parseTargetSpec(spec: TargetSpec): TargetSpecForm | null;
|
|
|
976
910
|
/**
|
|
977
911
|
* Match a target value + event against a TargetSpec.
|
|
978
912
|
*
|
|
979
|
-
* - `{ kindOf: predicate }` — calls the predicate with the
|
|
980
|
-
*
|
|
981
|
-
* `bodyTarget` string. Predicates that only need the target can ignore
|
|
982
|
-
* the second arg.
|
|
913
|
+
* - `{ kindOf: predicate }` — calls the predicate with the affordance hit and
|
|
914
|
+
* the `bodyTarget` string.
|
|
983
915
|
* - `'empty'`, `'selected-body'`, `'unselected-body'` — compared against
|
|
984
|
-
* `bodyTarget` on the event
|
|
985
|
-
* `classifyTarget` thunk is supplied).
|
|
916
|
+
* `bodyTarget` on the event.
|
|
986
917
|
* - `kind:<k>` — compared against `bodyKind`, the *semantic* kind of the node
|
|
987
|
-
* body under the point (`'text'`, `'rect'`, an app's own `'app:note'`)
|
|
988
|
-
*
|
|
918
|
+
* body under the point (`'text'`, `'rect'`, an app's own `'app:note'`).
|
|
919
|
+
* Selection-agnostic.
|
|
989
920
|
* - `kind:<k>:selected` — the same, and additionally requires the body to be
|
|
990
921
|
* in the current selection. Only the final `:selected` is a suffix, so a
|
|
991
922
|
* kind may itself contain colons.
|
|
@@ -1001,16 +932,11 @@ declare function parseTargetSpec(spec: TargetSpec): TargetSpecForm | null;
|
|
|
1001
932
|
* silent wildcard.
|
|
1002
933
|
*/
|
|
1003
934
|
declare function matchTarget(target: unknown, specTarget: TargetSpec | undefined, bodyTarget?: string, bodyKind?: string): boolean;
|
|
1004
|
-
/** Per-tool gesture-lifecycle state at match time.
|
|
1005
|
-
*
|
|
1006
|
-
*
|
|
1007
|
-
*
|
|
1008
|
-
*
|
|
1009
|
-
* that case any `phase: '&'` atom can't match.
|
|
1010
|
-
* - `engagedChannels` is the set of tool ids that currently have an
|
|
1011
|
-
* in-flight handle. Derived by the dispatcher from its `inFlight()`
|
|
1012
|
-
* map keyed by tool id at match time.
|
|
1013
|
-
*/
|
|
935
|
+
/** Per-tool gesture-lifecycle state at match time. `selfChannel` is the tool
|
|
936
|
+
* id `'&'` resolves to — the tool that owns the binding being evaluated — or
|
|
937
|
+
* `null` for a binding without an owning tool, in which case no `'&'` atom
|
|
938
|
+
* can match. `engagedChannels` is the set of tool ids that currently have an
|
|
939
|
+
* in-flight handle. */
|
|
1014
940
|
interface PhaseContext {
|
|
1015
941
|
selfChannel: string | null;
|
|
1016
942
|
engagedChannels: ReadonlySet<string>;
|
|
@@ -1020,14 +946,6 @@ interface PhaseContext {
|
|
|
1020
946
|
* constraint). Union semantics: a phase atom list matches when ANY
|
|
1021
947
|
* atom matches. */
|
|
1022
948
|
declare function matchPhase(spec: PhaseSpec | undefined, ctx: PhaseContext): boolean;
|
|
1023
|
-
/** MIME-glob match: `'image/*'` prefix-matches the major type; anything
|
|
1024
|
-
* else is an exact (case-insensitive) match; bare `'*'` or `'*\/*'` matches all. */
|
|
1025
|
-
declare function mimeMatchesGlob(mime: string, glob: string): boolean;
|
|
1026
|
-
/** True if ANY item's MIME matches ANY of the `types` globs.
|
|
1027
|
-
* `types: []` (empty) ≡ omitted = match any. */
|
|
1028
|
-
declare function matchIngestTypes(items: readonly {
|
|
1029
|
-
mime: string;
|
|
1030
|
-
}[], types: string[] | undefined): boolean;
|
|
1031
949
|
/**
|
|
1032
950
|
* Match a single GestureSpec against an InputEvent.
|
|
1033
951
|
*
|
|
@@ -1036,6 +954,20 @@ declare function matchIngestTypes(items: readonly {
|
|
|
1036
954
|
*/
|
|
1037
955
|
declare function matchSpec(e: InputEvent, spec: GestureSpec, isMac: boolean, phaseCtx?: PhaseContext): boolean;
|
|
1038
956
|
|
|
957
|
+
/** Which external content a `drop` or `paste` spec's MIME globs let through. */
|
|
958
|
+
/** MIME-glob match: `'image/*'` prefix-matches the major type; anything
|
|
959
|
+
* else is an exact (case-insensitive) match; bare `'*'` or `'*\/*'` matches all. */
|
|
960
|
+
declare function mimeMatchesGlob(mime: string, glob: string): boolean;
|
|
961
|
+
/** The MIME of an item whose type is not known yet: a file hovering in an OS
|
|
962
|
+
* drag, which some browsers do not name until it is dropped. */
|
|
963
|
+
declare const UNKNOWN_MIME = "*/*";
|
|
964
|
+
/** True if ANY item's MIME matches ANY of the `types` globs.
|
|
965
|
+
* `types: []` (empty) ≡ omitted = match any. An item of
|
|
966
|
+
* {@link UNKNOWN_MIME} passes every glob. */
|
|
967
|
+
declare function matchIngestTypes(items: readonly {
|
|
968
|
+
mime: string;
|
|
969
|
+
}[], types: string[] | undefined): boolean;
|
|
970
|
+
|
|
1039
971
|
/**
|
|
1040
972
|
* Whether this is an Apple platform, where `mod` means the Command key and
|
|
1041
973
|
* not Ctrl. iPhone and iPad count: with a keyboard attached their shortcuts
|
|
@@ -1047,6 +979,28 @@ declare function matchSpec(e: InputEvent, spec: GestureSpec, isMac: boolean, pha
|
|
|
1047
979
|
*/
|
|
1048
980
|
declare function isApplePlatform(): boolean;
|
|
1049
981
|
|
|
982
|
+
/**
|
|
983
|
+
* The nearest element `from` sits inside that can host a portalled overlay,
|
|
984
|
+
* or `null` when there is none and the body is the only answer.
|
|
985
|
+
*/
|
|
986
|
+
declare function nearestPortalHost(from: Element | null | undefined): HTMLElement | null;
|
|
987
|
+
/**
|
|
988
|
+
* Where a `position: fixed` element following the pointer mounts: `host`, and
|
|
989
|
+
* the client-space point its `left: 0; top: 0` lands on.
|
|
990
|
+
*/
|
|
991
|
+
interface FixedSeat {
|
|
992
|
+
host: HTMLElement;
|
|
993
|
+
left: number;
|
|
994
|
+
top: number;
|
|
995
|
+
}
|
|
996
|
+
/**
|
|
997
|
+
* The seat for something drawn at a client-space point on behalf of `from`, a
|
|
998
|
+
* drag ghost above all: the nearest portal host, so it resolves the theme
|
|
999
|
+
* `from` is drawn in, or the body. Subtract `left` and `top` from the client
|
|
1000
|
+
* point to place it.
|
|
1001
|
+
*/
|
|
1002
|
+
declare function fixedSeat(from: Element | null | undefined): FixedSeat;
|
|
1003
|
+
|
|
1050
1004
|
/** CSS-style specificity tuple for a GestureSpec. Higher tuple wins under
|
|
1051
1005
|
* lexicographic compare. Dimensions, in order of precedence:
|
|
1052
1006
|
*
|
|
@@ -1058,14 +1012,14 @@ declare function isApplePlatform(): boolean;
|
|
|
1058
1012
|
* non-empty `types` MIME filter, else 1.
|
|
1059
1013
|
*
|
|
1060
1014
|
* Identical tuples fall back to registration order in the matcher's
|
|
1061
|
-
* stable sort
|
|
1015
|
+
* stable sort. */
|
|
1062
1016
|
declare function specificity(spec: GestureSpec): readonly [number, number, number, number];
|
|
1063
1017
|
|
|
1064
1018
|
/**
|
|
1065
1019
|
* How far, in CSS pixels, a press must travel before it is a drag rather than
|
|
1066
|
-
* a click. `drag` specs match only past it:
|
|
1067
|
-
*
|
|
1068
|
-
*
|
|
1020
|
+
* a click. `drag` specs match only past it: the pointer recognizer holds a
|
|
1021
|
+
* pointerdown back until the pointer crosses it, so a press-and-release that
|
|
1022
|
+
* stays under it never opens a drag.
|
|
1069
1023
|
*/
|
|
1070
1024
|
declare const DRAG_THRESHOLD_PX = 4;
|
|
1071
1025
|
/** Whether a pointer that went down at `from` has travelled far enough, by
|
|
@@ -1078,6 +1032,214 @@ declare function pastDragThreshold(from: {
|
|
|
1078
1032
|
clientY: number;
|
|
1079
1033
|
}, threshold?: number): boolean;
|
|
1080
1034
|
|
|
1035
|
+
/**
|
|
1036
|
+
* The times and distances that tell one pointer gesture from another. The
|
|
1037
|
+
* drag threshold sits with its helper in `ui/dragThreshold.ts`.
|
|
1038
|
+
*/
|
|
1039
|
+
/** How long a touch or pen press is held before it fires `longPress`, in ms. */
|
|
1040
|
+
declare const LONG_PRESS_MS = 500;
|
|
1041
|
+
/** The longest gap between two clicks that still makes a double click, in ms:
|
|
1042
|
+
* the upper end of OS double-click settings. */
|
|
1043
|
+
declare const DOUBLE_CLICK_MAX_MS = 600;
|
|
1044
|
+
/** How far apart, in CSS pixels, two clicks may land and still make a double
|
|
1045
|
+
* click: the drift of a real mouse or trackpad between them. */
|
|
1046
|
+
declare const DOUBLE_CLICK_MAX_PX = 8;
|
|
1047
|
+
/** How far, in CSS pixels, a finger or the centroid of a multitouch gesture
|
|
1048
|
+
* may travel before the gesture stops being a tap. */
|
|
1049
|
+
declare const TAP_THRESHOLD_PX = 8;
|
|
1050
|
+
|
|
1051
|
+
/** A position in whatever space the recognizer's `positionOf` reports. */
|
|
1052
|
+
interface Point {
|
|
1053
|
+
x: number;
|
|
1054
|
+
y: number;
|
|
1055
|
+
}
|
|
1056
|
+
/** Where two or more pointers sit: what `multiTouchGeometry` reads from their positions. */
|
|
1057
|
+
interface MultiTouchGeometry {
|
|
1058
|
+
centroid: Point;
|
|
1059
|
+
/** Distance between the first two pointers. */
|
|
1060
|
+
spread: number;
|
|
1061
|
+
/** Direction from the first pointer to the second, in degrees in (-180, 180],
|
|
1062
|
+
* growing clockwise on screen. */
|
|
1063
|
+
angle: number;
|
|
1064
|
+
}
|
|
1065
|
+
/** Every pointer's centroid, and the first two's spread and angle. All zero with fewer than 2 pointers. */
|
|
1066
|
+
declare function multiTouchGeometry(positions: Iterable<Point>): MultiTouchGeometry;
|
|
1067
|
+
|
|
1068
|
+
/**
|
|
1069
|
+
* What the recognizer remembers of a press, and the events a release or a
|
|
1070
|
+
* hold on it synthesizes.
|
|
1071
|
+
*/
|
|
1072
|
+
|
|
1073
|
+
/** Press-time state replayed onto a synthesized click, long-press or
|
|
1074
|
+
* contextmenu, whose matchers resolve targets against it. */
|
|
1075
|
+
interface PressFacts extends EventModifiers {
|
|
1076
|
+
target: unknown;
|
|
1077
|
+
clientX: number;
|
|
1078
|
+
clientY: number;
|
|
1079
|
+
/** World-space press point, forwarded onto the synthesized click as
|
|
1080
|
+
* `pressX`/`pressY` — see `ClickEvent`. */
|
|
1081
|
+
worldX: number;
|
|
1082
|
+
worldY: number;
|
|
1083
|
+
affordance?: unknown;
|
|
1084
|
+
bodyTarget?: BodyTarget;
|
|
1085
|
+
bodyKind?: BodyKind;
|
|
1086
|
+
}
|
|
1087
|
+
/** Where and how a press was released, for the click it turned out to be. */
|
|
1088
|
+
interface ReleaseFacts extends EventModifiers {
|
|
1089
|
+
target: unknown;
|
|
1090
|
+
clientX: number;
|
|
1091
|
+
clientY: number;
|
|
1092
|
+
worldX: number;
|
|
1093
|
+
worldY: number;
|
|
1094
|
+
}
|
|
1095
|
+
/** A press released where it went down, as a click, and as the double click
|
|
1096
|
+
* it is when it follows another closely. Both happen at the release, with the
|
|
1097
|
+
* release's modifiers, on what the press landed on. */
|
|
1098
|
+
declare function clickEvents(down: PressFacts, up: ReleaseFacts): {
|
|
1099
|
+
click: InputEvent;
|
|
1100
|
+
doubleclick: InputEvent;
|
|
1101
|
+
};
|
|
1102
|
+
/** A held press as a long-press, and as the contextmenu it falls back to when
|
|
1103
|
+
* the long-press matches nothing. The fallback is what makes existing
|
|
1104
|
+
* `contextMenu` bindings reachable by touch with no consumer change. */
|
|
1105
|
+
declare function longPressEvents(down: PressFacts): {
|
|
1106
|
+
longpress: InputEvent;
|
|
1107
|
+
contextmenu: InputEvent;
|
|
1108
|
+
};
|
|
1109
|
+
|
|
1110
|
+
/** A press released in place: its click, and the double click a second one makes. */
|
|
1111
|
+
|
|
1112
|
+
/**
|
|
1113
|
+
* The click a double click would follow. Held by the host rather than the
|
|
1114
|
+
* recognizer when it has to outlive one: a host that rebuilds its recognizer
|
|
1115
|
+
* between two clicks would otherwise drop the double click.
|
|
1116
|
+
*/
|
|
1117
|
+
interface ClickMemory {
|
|
1118
|
+
last: {
|
|
1119
|
+
t: number;
|
|
1120
|
+
clientX: number;
|
|
1121
|
+
clientY: number;
|
|
1122
|
+
} | null;
|
|
1123
|
+
}
|
|
1124
|
+
/** Told of clicks without competing for them, as a binding would. */
|
|
1125
|
+
interface ClickObserver {
|
|
1126
|
+
/** After the click was dispatched, so whatever its binding changed is readable. */
|
|
1127
|
+
click?(world: Point): void;
|
|
1128
|
+
/** Before the double click is dispatched, whichever binding then handles it. */
|
|
1129
|
+
doubleClick?(world: Point): void;
|
|
1130
|
+
}
|
|
1131
|
+
/** What a release composed. `doubleClick` is absent unless one was dispatched. */
|
|
1132
|
+
interface ReleaseOutcome {
|
|
1133
|
+
doubleClick?: 'handled' | 'unhandled';
|
|
1134
|
+
}
|
|
1135
|
+
|
|
1136
|
+
/** The one press being timed toward a long-press. */
|
|
1137
|
+
|
|
1138
|
+
/** A clock and a timer, so a host or a test supplies its own. */
|
|
1139
|
+
interface RecognizerClock {
|
|
1140
|
+
now(): number;
|
|
1141
|
+
setTimer(fn: () => void, ms: number): unknown;
|
|
1142
|
+
clearTimer(timer: unknown): void;
|
|
1143
|
+
}
|
|
1144
|
+
/** A press held toward a long-press. */
|
|
1145
|
+
interface HeldPress {
|
|
1146
|
+
pointerId: number;
|
|
1147
|
+
/** A mouse never arms one. */
|
|
1148
|
+
pointerType: 'touch' | 'pen';
|
|
1149
|
+
press: PressFacts;
|
|
1150
|
+
/** `RecognizerClock.now()` when the hold started. */
|
|
1151
|
+
startedAt: number;
|
|
1152
|
+
/** How long the hold must last before the long-press fires, in ms. */
|
|
1153
|
+
duration: number;
|
|
1154
|
+
}
|
|
1155
|
+
|
|
1156
|
+
/**
|
|
1157
|
+
* What a host feeds the pointer recognizer, one per pointer event, and the
|
|
1158
|
+
* pump events each becomes.
|
|
1159
|
+
*/
|
|
1160
|
+
|
|
1161
|
+
/** One pointer event, in client space. */
|
|
1162
|
+
interface PointerSample extends EventModifiers, PointerSampleStylus {
|
|
1163
|
+
pointerId: number;
|
|
1164
|
+
clientX: number;
|
|
1165
|
+
clientY: number;
|
|
1166
|
+
/** What the originating event was aimed at. */
|
|
1167
|
+
target?: unknown;
|
|
1168
|
+
}
|
|
1169
|
+
/** A pointer going down, with what the host found under it. */
|
|
1170
|
+
interface PressSample extends PointerSample {
|
|
1171
|
+
/** The world point the host hit-tested at. */
|
|
1172
|
+
x: number;
|
|
1173
|
+
y: number;
|
|
1174
|
+
/** `PointerEvent.pointerType`. Only `'touch'` and `'pen'` arm a long-press. */
|
|
1175
|
+
pointerType: string;
|
|
1176
|
+
affordance?: unknown;
|
|
1177
|
+
bodyTarget?: BodyTarget;
|
|
1178
|
+
bodyKind?: BodyKind;
|
|
1179
|
+
}
|
|
1180
|
+
|
|
1181
|
+
/**
|
|
1182
|
+
* Turns pointer samples into the gestures they add up to: a press, the drag
|
|
1183
|
+
* it becomes past the threshold, the click it is when released in place, the
|
|
1184
|
+
* double click two of those make, a long-press, and multitouch.
|
|
1185
|
+
*
|
|
1186
|
+
* It decides with its sink's answers, so it is not a pure function of its
|
|
1187
|
+
* input: a long-press only spends its press when something handled it.
|
|
1188
|
+
*/
|
|
1189
|
+
|
|
1190
|
+
/** Where recognized events go. */
|
|
1191
|
+
interface RecognizerSink {
|
|
1192
|
+
dispatch(ev: InputEvent): 'handled' | 'unhandled';
|
|
1193
|
+
/** Whether a multitouch gesture of `fingers` fingers is running, to be pumped. */
|
|
1194
|
+
multiTouchInFlight(fingers: number): boolean;
|
|
1195
|
+
}
|
|
1196
|
+
/** What a host hears about beyond the events themselves, to drive press feedback. */
|
|
1197
|
+
interface RecognizerObserver extends ClickObserver {
|
|
1198
|
+
/** The press being held toward a long-press, or `null` once it fires or is abandoned. */
|
|
1199
|
+
holdChanged?(pending: HeldPress | null): void;
|
|
1200
|
+
/** A long-press something handled, as itself or as its contextmenu fallback. */
|
|
1201
|
+
longPress?(pointerType: 'touch' | 'pen'): void;
|
|
1202
|
+
}
|
|
1203
|
+
/** What {@link createPointerRecognizer} needs from its host. */
|
|
1204
|
+
interface PointerRecognizerOptions {
|
|
1205
|
+
sink: RecognizerSink;
|
|
1206
|
+
clock: RecognizerClock;
|
|
1207
|
+
/**
|
|
1208
|
+
* Client point to world point; the identity by default. Asked as each event
|
|
1209
|
+
* is built rather than once per sample: an event dispatched earlier in the
|
|
1210
|
+
* same sample, a pinch step say, may have moved the view.
|
|
1211
|
+
*/
|
|
1212
|
+
toWorld?: (clientX: number, clientY: number) => Point;
|
|
1213
|
+
/** Client point to the space a multitouch centroid is reported in. The identity by default. */
|
|
1214
|
+
toSurface?: (client: Point) => Point;
|
|
1215
|
+
/** Long-press hold time in ms, read at each press. Default `LONG_PRESS_MS`. */
|
|
1216
|
+
longPressMs?: () => number | undefined;
|
|
1217
|
+
clicks?: ClickMemory;
|
|
1218
|
+
observer?: RecognizerObserver;
|
|
1219
|
+
}
|
|
1220
|
+
/** A recognizer for one surface. Its host feeds it every pointer sample the surface receives. */
|
|
1221
|
+
interface PointerRecognizer {
|
|
1222
|
+
press(sample: PressSample): void;
|
|
1223
|
+
/** A move of any pointer, held or not. */
|
|
1224
|
+
move(sample: PointerSample): void;
|
|
1225
|
+
release(sample: PointerSample): ReleaseOutcome;
|
|
1226
|
+
/** A held pointer ended without a release. */
|
|
1227
|
+
cancel(pointerId: number): void;
|
|
1228
|
+
/**
|
|
1229
|
+
* Whether a touch or pen that armed a long-press is still held. One still
|
|
1230
|
+
* pending fires here, ahead of its timer: a platform that reports the hold
|
|
1231
|
+
* itself is reporting the same one.
|
|
1232
|
+
*/
|
|
1233
|
+
takeHold(): boolean;
|
|
1234
|
+
heldCount(): number;
|
|
1235
|
+
/** A held pointer's latest client position. */
|
|
1236
|
+
positionOf(pointerId: number): Point | undefined;
|
|
1237
|
+
/** Forget every held pointer and stop timing, dispatching nothing. */
|
|
1238
|
+
reset(): void;
|
|
1239
|
+
}
|
|
1240
|
+
/** Build a recognizer holding no pointers. It touches no DOM: time and timers come from `opts.clock`. */
|
|
1241
|
+
declare function createPointerRecognizer(opts: PointerRecognizerOptions): PointerRecognizer;
|
|
1242
|
+
|
|
1081
1243
|
/** Elements that handle their own press and keys. */
|
|
1082
1244
|
declare const CONTROL_SELECTOR: string;
|
|
1083
1245
|
/**
|
|
@@ -1088,4 +1250,22 @@ declare const CONTROL_SELECTOR: string;
|
|
|
1088
1250
|
*/
|
|
1089
1251
|
declare function isInControlWithin(target: EventTarget | null, host: Element): boolean;
|
|
1090
1252
|
|
|
1091
|
-
|
|
1253
|
+
/** Returns true when the target takes typed text: an input, a textarea, or a contenteditable element. */
|
|
1254
|
+
declare function isEditableTarget(target: EventTarget | null): boolean;
|
|
1255
|
+
/**
|
|
1256
|
+
* True when `e` is Space or Enter on a focused control those keys activate — a
|
|
1257
|
+
* button, a link, a checkbox. The key is that control's, so a page-level
|
|
1258
|
+
* listener that claims it cancels the control's own activation.
|
|
1259
|
+
*/
|
|
1260
|
+
declare function activatesFocusedControl(e: KeyboardEvent): boolean;
|
|
1261
|
+
/**
|
|
1262
|
+
* True when the key `e` reports belongs to the control it was typed on: Space
|
|
1263
|
+
* or Enter on anything those activate, and a `<select>`'s type-ahead
|
|
1264
|
+
* characters and navigation keys. A select claims nothing else, so Delete,
|
|
1265
|
+
* Escape, and every modifier chord typed on one are still a page-level
|
|
1266
|
+
* listener's to take. A text field is {@link isEditableTarget}'s question,
|
|
1267
|
+
* since it owns every key.
|
|
1268
|
+
*/
|
|
1269
|
+
declare function focusedControlOwnsKey(e: KeyboardEvent): boolean;
|
|
1270
|
+
|
|
1271
|
+
export { ACTIVE_SIGILS, type BodyClassification, type BodyKind, type BodyTarget, CONTROL_SELECTOR, 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 DoubleClickEvent, type DoubleClickSpec, type DragSpec, type DropEvent, type DropSpec, type EventModifiers, type FixedSeat, GESTURE_DESCRIPTORS, type GestureArgSpec, type GestureDescriptor, type GestureName, type GestureSpec, type HeldPress, type HoverEvent, type HoverSpec, type IngestItem, type InputEvent, type KeyEvent, type KeyHeldEvent, type KeyHeldSpec, type KeySpec, LONG_PRESS_MS, type LongPressEvent, type LongPressSpec, 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 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, 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, fixedSeat, focusedControlOwnsKey, formatKeyRoute, formatPhaseAtom, formatRoute, getGestureDescriptor, hitPredicate, isApplePlatform, isEditableTarget, isInControlWithin, isKnownGestureName, keyRouteToSpec, longPressEvents, matchIngestTypes, matchKey, matchModifiers, matchPhase, matchSpec, matchTarget, mimeMatchesGlob, modifierComboToParsed, mods, multiTouchGeometry, nearestPortalHost, parseKeyRoute, parseRoute, parseTargetSpec, pastDragThreshold, routeGestureForSpecKind, routeToSpec, specKindForRouteGesture, specificity, stylusOf };
|