@n-uf/motion 26.11.62 → 26.11.63
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/CHANGELOG.md +16 -0
- package/dist/browser.d.ts +105 -2
- package/dist/browser.js +215 -0
- package/dist/browser.js.map +1 -1
- package/dist/{chunk-3B3MPKM6.js → chunk-K6TAWCGL.js} +47 -19
- package/dist/{chunk-3B3MPKM6.js.map → chunk-K6TAWCGL.js.map} +1 -1
- package/dist/double-click-jtUSNuHL.d.ts +16 -0
- package/dist/drag.d.ts +3 -2
- package/dist/gestures.d.ts +7 -214
- package/dist/gestures.js +3 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.js +3 -1
- package/dist/{double-click-DBfbiP2U.d.ts → keys-BpcrOp4S.d.ts} +1 -16
- package/dist/paged-swipe-CIzjr2DQ.d.ts +244 -0
- package/package.json +2 -2
package/dist/gestures.d.ts
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
1
|
+
import { a as Modifiers, M as ModifierKey } from './keys-BpcrOp4S.js';
|
|
2
|
+
export { i as isHeld } from './keys-BpcrOp4S.js';
|
|
3
3
|
import { P as Point } from './shapes-EbQlwbCu.js';
|
|
4
|
+
import { a as DoubleClick } from './double-click-jtUSNuHL.js';
|
|
5
|
+
export { D as DOUBLE_CLICK } from './double-click-jtUSNuHL.js';
|
|
4
6
|
import { C as ClockPort, T as TimerSource } from './port-CmlUctqx.js';
|
|
7
|
+
import { M as Machine, D as Deadline } from './paged-swipe-CIzjr2DQ.js';
|
|
8
|
+
export { a as MachineOptions, P as PAGED_SWIPE_DEFAULTS, b as PAGED_SWIPE_EMPTY_CONTEXT, c as PAGED_SWIPE_IDLE, d as PagedSwipeConfig, e as PagedSwipeContext, f as PagedSwipeInput, g as PagedSwipeOptions, h as PagedSwipeState, S as SwipeSide, i as createMachine, j as createPagedSwipe, p as pagedSwipeDeadline, k as pagedSwipeReducer, r as rubberBand, s as swipeProgress } from './paged-swipe-CIzjr2DQ.js';
|
|
5
9
|
|
|
6
10
|
/**
|
|
7
11
|
* Input types: plain event objects in, one gesture stream out. Nothing here
|
|
@@ -304,46 +308,6 @@ interface Recognizer {
|
|
|
304
308
|
}
|
|
305
309
|
declare function createRecognizer(options: RecognizerOptions, emit: (gesture: InputGesture) => void): Recognizer;
|
|
306
310
|
|
|
307
|
-
/**
|
|
308
|
-
* A timer event a state asks for: send `event(t)` when the clock reaches
|
|
309
|
-
* `at`. Machines stay pure; this is how a long-press or a dwell turns into
|
|
310
|
-
* an event without the reducer touching a timer.
|
|
311
|
-
*/
|
|
312
|
-
interface Deadline<E> {
|
|
313
|
-
/** Clock time in ms. */
|
|
314
|
-
readonly at: number;
|
|
315
|
-
/** The event to send, given the clock time it fired at. */
|
|
316
|
-
readonly event: (t: number) => E;
|
|
317
|
-
}
|
|
318
|
-
/** Options of {@link createMachine}. */
|
|
319
|
-
interface MachineOptions<S, E> {
|
|
320
|
-
/** The pure transition function. Returning the same state means "no change". */
|
|
321
|
-
readonly reducer: (state: S, event: E) => S;
|
|
322
|
-
readonly initial: S;
|
|
323
|
-
/** Timers come from here (and `now()` for their events). */
|
|
324
|
-
readonly clock: TimerSource;
|
|
325
|
-
/** The timer event the state needs, or `null`. Checked after every transition. */
|
|
326
|
-
readonly deadline?: (state: S) => Deadline<E> | null;
|
|
327
|
-
}
|
|
328
|
-
/** A running machine: the state, a way to send events, and change listeners. */
|
|
329
|
-
interface Machine<S, E> {
|
|
330
|
-
/** The current state; reactive (read it in a computed or an effect). */
|
|
331
|
-
readonly state: S;
|
|
332
|
-
/** The current state, untracked. */
|
|
333
|
-
peek(): S;
|
|
334
|
-
/**
|
|
335
|
-
* Run `event` through the reducer and return the new state. An event sent
|
|
336
|
-
* from a listener waits until the current one has been handled.
|
|
337
|
-
*/
|
|
338
|
-
send(event: E): S;
|
|
339
|
-
/** Called after each change of state (not for events that changed nothing). */
|
|
340
|
-
subscribe(listener: (next: S, previous: S, event: E) => void): () => void;
|
|
341
|
-
/** Clear the timer and drop listeners. Events sent after this are ignored. */
|
|
342
|
-
dispose(): void;
|
|
343
|
-
}
|
|
344
|
-
/** Run a pure machine on a clock: it arms and clears the deadline timer for you. */
|
|
345
|
-
declare function createMachine<S, E>(options: MachineOptions<S, E>): Machine<S, E>;
|
|
346
|
-
|
|
347
311
|
/**
|
|
348
312
|
* The dwell machine (spring-load): hold over the same target long enough and
|
|
349
313
|
* it fires, once.
|
|
@@ -482,175 +446,4 @@ interface TouchPressOptions {
|
|
|
482
446
|
/** A touch press on a clock: the hold timer is armed for you. */
|
|
483
447
|
declare function createTouchPress(options: TouchPressOptions): Machine<TouchPressState, TouchPressInput>;
|
|
484
448
|
|
|
485
|
-
|
|
486
|
-
* A paged swipe: a trackpad's two-finger scroll or a finger swipes from one page to the previous or the next, the
|
|
487
|
-
* pages following it, and commits or snaps back when it ends.
|
|
488
|
-
*
|
|
489
|
-
* ```text
|
|
490
|
-
* idle ──wheel / touch-move (arming rules pass)──► armed ──travel ≥ threshold──► tracking
|
|
491
|
-
* ▲ │ │
|
|
492
|
-
* │ rule breach / idle / end gesture end
|
|
493
|
-
* │ ▼ ▼
|
|
494
|
-
* └──────── lockout elapsed ◄── lockout ◄── settled (commit) ◄───────────── settling
|
|
495
|
-
* └──────────────────────────────────────── settled (cancel) ◄───────────────────┤
|
|
496
|
-
* └──────────────────────────────────────── cancel (transition stopped) ◄────────┘
|
|
497
|
-
* ```
|
|
498
|
-
*
|
|
499
|
-
* - **Arming:** nothing else owns the pointer (`blocked`), the movement runs mostly along the swipe (more than twice
|
|
500
|
-
* the cross movement), no Ctrl (a pinch), the configured modifier is held, nothing under the pointer can still
|
|
501
|
-
* scroll that way (`canScrollFurther`), and there is a page on that side (or `wrap`). A wheel run that breaks a
|
|
502
|
-
* rule belongs to scrolling until the wheel has been idle `idle`.
|
|
503
|
-
* - **Tracking:** `progress` is the travel over the page size, −1 to 1, held at 0 towards a side with no page.
|
|
504
|
-
* - **Ending:** a touch ends when the finger lifts, a wheel run after `idle` without samples. It commits when
|
|
505
|
-
* `|progress| ≥ commitFraction`, or the peak speed towards the target reached `commitVelocity` (the peak starts
|
|
506
|
-
* over when the travel crosses zero, so a fast fling out and a pull back does not commit the way back).
|
|
507
|
-
* - **Settling** lasts as long as the host's page transition; the host sends `settled` when it is done (or `cancel`,
|
|
508
|
-
* which goes straight back to idle, when it stops the transition). After a commit, `lockout` swallows the
|
|
509
|
-
* trackpad's momentum for `lockout`, and the run stays claimed after it.
|
|
510
|
-
*
|
|
511
|
-
* Pure and timer-free: {@link pagedSwipeDeadline} says when the next `tick` is due ({@link createPagedSwipe} arms it).
|
|
512
|
-
* Signs: a wheel delta > 0 along the swipe heads to `next`; a finger moving towards smaller x (or y) heads to `next`.
|
|
513
|
-
*/
|
|
514
|
-
/** Which side of the current page a swipe heads to. */
|
|
515
|
-
type SwipeSide = "prev" | "next";
|
|
516
|
-
/** Tunables of the paged swipe. */
|
|
517
|
-
interface PagedSwipeConfig {
|
|
518
|
-
/** px of travel before an armed swipe tracks. Default 24. */
|
|
519
|
-
readonly threshold: number;
|
|
520
|
-
/** The share of the page size that commits at the end. Default 0.35. */
|
|
521
|
-
readonly commitFraction: number;
|
|
522
|
-
/** px/ms: a peak speed towards the target that commits at the end. Default 0.6. */
|
|
523
|
-
readonly commitVelocity: number;
|
|
524
|
-
/** ms without a wheel sample that ends a wheel run. Default 120. */
|
|
525
|
-
readonly idle: number;
|
|
526
|
-
/** ms after a commit during which wheel samples are swallowed (momentum). Default 350. */
|
|
527
|
-
readonly lockout: number;
|
|
528
|
-
/** Past the last page comes the first, and back. Default false. */
|
|
529
|
-
readonly wrap: boolean;
|
|
530
|
-
/** The page size in px when no sample or context gives one. Default 800. */
|
|
531
|
-
readonly size: number;
|
|
532
|
-
/** A modifier the wheel needs held to swipe (`null`: none). Touch never needs one. Default null. */
|
|
533
|
-
readonly modifier: ModifierKey | null;
|
|
534
|
-
/** The swipe's direction: `"x"` (the default) or `"y"`. */
|
|
535
|
-
readonly along: "x" | "y";
|
|
536
|
-
}
|
|
537
|
-
/** Defaults of {@link PagedSwipeConfig}. */
|
|
538
|
-
declare const PAGED_SWIPE_DEFAULTS: PagedSwipeConfig;
|
|
539
|
-
/** What the host knows about the pages now. */
|
|
540
|
-
interface PagedSwipeContext {
|
|
541
|
-
readonly hasPrev: boolean;
|
|
542
|
-
readonly hasNext: boolean;
|
|
543
|
-
/** The page size in px, or null (the config's). */
|
|
544
|
-
readonly size: number | null;
|
|
545
|
-
/** Something else owns the pointer (a drag): nothing arms, and a swipe in progress gives way. */
|
|
546
|
-
readonly blocked: boolean;
|
|
547
|
-
}
|
|
548
|
-
/** The context before the host has said anything. */
|
|
549
|
-
declare const PAGED_SWIPE_EMPTY_CONTEXT: PagedSwipeContext;
|
|
550
|
-
type Input = "wheel" | "touch";
|
|
551
|
-
interface Base {
|
|
552
|
-
readonly context: PagedSwipeContext;
|
|
553
|
-
/** −1 to 1; negative towards `prev`. */
|
|
554
|
-
readonly progress: number;
|
|
555
|
-
readonly target: SwipeSide | null;
|
|
556
|
-
}
|
|
557
|
-
/** The paged swipe's state. Every phase has a way back to `idle`. */
|
|
558
|
-
type PagedSwipeState = (Base & {
|
|
559
|
-
readonly phase: "idle";
|
|
560
|
-
/** The last wheel sample of the current run (null: none, or the run went idle). */
|
|
561
|
-
readonly lastWheel: number | null;
|
|
562
|
-
/** This wheel run broke the arming rules (or committed): it cannot arm until the wheel is idle `idle`. */
|
|
563
|
-
readonly claimed: boolean;
|
|
564
|
-
}) | (Base & {
|
|
565
|
-
readonly phase: "armed";
|
|
566
|
-
readonly input: Input;
|
|
567
|
-
/** Where the finger went down (touch). */
|
|
568
|
-
readonly origin: {
|
|
569
|
-
readonly x: number;
|
|
570
|
-
readonly y: number;
|
|
571
|
-
};
|
|
572
|
-
/** Wheel travel along the swipe and across it so far. */
|
|
573
|
-
readonly travel: number;
|
|
574
|
-
readonly cross: number;
|
|
575
|
-
readonly last: number;
|
|
576
|
-
}) | (Base & {
|
|
577
|
-
readonly phase: "tracking";
|
|
578
|
-
readonly input: Input;
|
|
579
|
-
readonly origin: {
|
|
580
|
-
readonly x: number;
|
|
581
|
-
readonly y: number;
|
|
582
|
-
};
|
|
583
|
-
readonly travel: number;
|
|
584
|
-
readonly last: number;
|
|
585
|
-
/** The highest speed (px/ms) towards the current target. */
|
|
586
|
-
readonly peak: number;
|
|
587
|
-
}) | (Base & {
|
|
588
|
-
readonly phase: "settling";
|
|
589
|
-
readonly input: Input;
|
|
590
|
-
readonly outcome: "commit" | "cancel";
|
|
591
|
-
readonly ended: number;
|
|
592
|
-
readonly lastWheel: number;
|
|
593
|
-
}) | (Base & {
|
|
594
|
-
readonly phase: "lockout";
|
|
595
|
-
readonly until: number;
|
|
596
|
-
readonly lastWheel: number;
|
|
597
|
-
});
|
|
598
|
-
/** Events of the paged swipe. `t` is the clock time in ms. */
|
|
599
|
-
type PagedSwipeInput = {
|
|
600
|
-
readonly type: "wheel";
|
|
601
|
-
readonly dx: number;
|
|
602
|
-
readonly dy: number;
|
|
603
|
-
readonly t: number;
|
|
604
|
-
readonly modifiers: Modifiers;
|
|
605
|
-
/** Something under the pointer can still scroll that way: no arming. */
|
|
606
|
-
readonly canScrollFurther?: boolean;
|
|
607
|
-
readonly size?: number;
|
|
608
|
-
} | {
|
|
609
|
-
readonly type: "touch-start";
|
|
610
|
-
readonly x: number;
|
|
611
|
-
readonly y: number;
|
|
612
|
-
readonly t: number;
|
|
613
|
-
readonly size?: number;
|
|
614
|
-
} | {
|
|
615
|
-
readonly type: "touch-move";
|
|
616
|
-
readonly x: number;
|
|
617
|
-
readonly y: number;
|
|
618
|
-
readonly t: number;
|
|
619
|
-
readonly canScrollFurther?: boolean;
|
|
620
|
-
readonly size?: number;
|
|
621
|
-
} | {
|
|
622
|
-
readonly type: "touch-end";
|
|
623
|
-
readonly t: number;
|
|
624
|
-
} | {
|
|
625
|
-
readonly type: "tick";
|
|
626
|
-
readonly t: number;
|
|
627
|
-
} | {
|
|
628
|
-
readonly type: "settled";
|
|
629
|
-
} | {
|
|
630
|
-
readonly type: "cancel";
|
|
631
|
-
} | {
|
|
632
|
-
readonly type: "block";
|
|
633
|
-
readonly on: boolean;
|
|
634
|
-
} | {
|
|
635
|
-
readonly type: "context";
|
|
636
|
-
readonly hasPrev: boolean;
|
|
637
|
-
readonly hasNext: boolean;
|
|
638
|
-
readonly size?: number;
|
|
639
|
-
};
|
|
640
|
-
/** The idle state with no context. */
|
|
641
|
-
declare const PAGED_SWIPE_IDLE: PagedSwipeState;
|
|
642
|
-
/** Travel to progress: over the page size, −1 to 1, 0 towards a side with no page (unless `wrap`). */
|
|
643
|
-
declare function swipeProgress(travel: number, size: number, c: PagedSwipeContext, wrap: boolean): number;
|
|
644
|
-
/** The paged swipe's pure transition function. Unmatched pairs return the state unchanged. */
|
|
645
|
-
declare function pagedSwipeReducer(state: PagedSwipeState, event: PagedSwipeInput, config?: PagedSwipeConfig): PagedSwipeState;
|
|
646
|
-
/** When the next `tick` is due: a wheel run's idle end, or the end of the lockout; `null` when none is. */
|
|
647
|
-
declare function pagedSwipeDeadline(state: PagedSwipeState, config?: PagedSwipeConfig): Deadline<PagedSwipeInput> | null;
|
|
648
|
-
/** Options of {@link createPagedSwipe}. */
|
|
649
|
-
interface PagedSwipeOptions {
|
|
650
|
-
readonly clock: TimerSource;
|
|
651
|
-
readonly config?: Partial<PagedSwipeConfig>;
|
|
652
|
-
}
|
|
653
|
-
/** A paged swipe on a clock: the idle and lockout timers are armed for you. */
|
|
654
|
-
declare function createPagedSwipe(options: PagedSwipeOptions): Machine<PagedSwipeState, PagedSwipeInput>;
|
|
655
|
-
|
|
656
|
-
export { type CancelReason, DWELL_DEFAULTS, DWELL_IDLE, type Deadline, DoubleClick, type DwellConfig, type DwellInput, type DwellMachineOptions, type DwellState, type GesturePointer, type InputGesture, type InputGestureType, type Machine, type MachineOptions, ModifierKey, Modifiers, NO_MODIFIERS, PAGED_SWIPE_DEFAULTS, PAGED_SWIPE_EMPTY_CONTEXT, PAGED_SWIPE_IDLE, type PagedSwipeConfig, type PagedSwipeContext, type PagedSwipeInput, type PagedSwipeOptions, type PagedSwipeState, type Platform, Point, type PointerKind, RECOGNIZER_DEFAULTS, type RawInputEvent, type RawPointerEvent, type RawPointerType, type RawSafariGestureEvent, type RawWheelEvent, type Recognizer, type RecognizerOptions, type RecognizerTimers, type SwipeSide, TOUCH_PRESS_DEFAULTS, TOUCH_PRESS_IDLE, type TouchPressConfig, type TouchPressInput, type TouchPressOptions, type TouchPressState, WHEEL_DEFAULTS, WHEEL_PAN_DEFAULTS, type WheelIntent, type WheelOptions, type WheelPanOptions, classifyWheel, createDwellMachine, createMachine, createPagedSwipe, createRecognizer, createTouchPress, dampWheelPan, defaultDragModifier, dwellDeadline, dwellReducer, modHeld, pagedSwipeDeadline, pagedSwipeReducer, platformButton, resolveDragModifier, swipeProgress, toModifiers, touchPressDeadline, touchPressReducer, wheelDelta };
|
|
449
|
+
export { type CancelReason, DWELL_DEFAULTS, DWELL_IDLE, Deadline, DoubleClick, type DwellConfig, type DwellInput, type DwellMachineOptions, type DwellState, type GesturePointer, type InputGesture, type InputGestureType, Machine, ModifierKey, Modifiers, NO_MODIFIERS, type Platform, Point, type PointerKind, RECOGNIZER_DEFAULTS, type RawInputEvent, type RawPointerEvent, type RawPointerType, type RawSafariGestureEvent, type RawWheelEvent, type Recognizer, type RecognizerOptions, type RecognizerTimers, TOUCH_PRESS_DEFAULTS, TOUCH_PRESS_IDLE, type TouchPressConfig, type TouchPressInput, type TouchPressOptions, type TouchPressState, WHEEL_DEFAULTS, WHEEL_PAN_DEFAULTS, type WheelIntent, type WheelOptions, type WheelPanOptions, classifyWheel, createDwellMachine, createRecognizer, createTouchPress, dampWheelPan, defaultDragModifier, dwellDeadline, dwellReducer, modHeld, platformButton, resolveDragModifier, toModifiers, touchPressDeadline, touchPressReducer, wheelDelta };
|
package/dist/gestures.js
CHANGED
|
@@ -25,12 +25,13 @@ import {
|
|
|
25
25
|
pagedSwipeReducer,
|
|
26
26
|
platformButton,
|
|
27
27
|
resolveDragModifier,
|
|
28
|
+
rubberBand,
|
|
28
29
|
swipeProgress,
|
|
29
30
|
toModifiers,
|
|
30
31
|
touchPressDeadline,
|
|
31
32
|
touchPressReducer,
|
|
32
33
|
wheelDelta
|
|
33
|
-
} from "./chunk-
|
|
34
|
+
} from "./chunk-K6TAWCGL.js";
|
|
34
35
|
import "./chunk-OOKRBVMB.js";
|
|
35
36
|
import {
|
|
36
37
|
DOUBLE_CLICK,
|
|
@@ -65,6 +66,7 @@ export {
|
|
|
65
66
|
pagedSwipeReducer,
|
|
66
67
|
platformButton,
|
|
67
68
|
resolveDragModifier,
|
|
69
|
+
rubberBand,
|
|
68
70
|
swipeProgress,
|
|
69
71
|
toModifiers,
|
|
70
72
|
touchPressDeadline,
|
package/dist/index.d.ts
CHANGED
|
@@ -6,8 +6,10 @@ export { A as Animator, S as SETTLE_DEFAULTS, a as SETTLE_TEMPO, b as Settle, c
|
|
|
6
6
|
export { A as Animatable, P as Point, R as Rect, V as Vector, W as Widen, s as shapeEquals } from './shapes-EbQlwbCu.js';
|
|
7
7
|
export { AnimatorValue, Easing, MotionOptions, MotionValue, SPRING_DEFAULTS, SetOptions, Spring, SpringConfig, SpringParams, SpringState, Tween, TweenConfig, createSpring, createTween, cubicBezier, ease, easeIn, easeInOut, easeInOutCubic, easeOut, easeOutCubic, linear, motionValue, resolveSpring, settleValue, springStep, springValue, tweenValue } from './values.js';
|
|
8
8
|
export { P as PopIn, R as RevealFrame, p as popIn, r as reveal } from './reveal-Dg5fqoWS.js';
|
|
9
|
-
export { CancelReason, DWELL_DEFAULTS, DWELL_IDLE,
|
|
10
|
-
export { D as DOUBLE_CLICK, a as DoubleClick
|
|
9
|
+
export { CancelReason, DWELL_DEFAULTS, DWELL_IDLE, DwellConfig, DwellInput, DwellMachineOptions, DwellState, GesturePointer, InputGesture, InputGestureType, NO_MODIFIERS, Platform, PointerKind, RECOGNIZER_DEFAULTS, RawInputEvent, RawPointerEvent, RawPointerType, RawSafariGestureEvent, RawWheelEvent, Recognizer, RecognizerOptions, RecognizerTimers, TOUCH_PRESS_DEFAULTS, TOUCH_PRESS_IDLE, TouchPressConfig, TouchPressInput, TouchPressOptions, TouchPressState, WHEEL_DEFAULTS, WHEEL_PAN_DEFAULTS, WheelIntent, WheelOptions, WheelPanOptions, classifyWheel, createDwellMachine, createRecognizer, createTouchPress, dampWheelPan, defaultDragModifier, dwellDeadline, dwellReducer, modHeld, platformButton, resolveDragModifier, toModifiers, touchPressDeadline, touchPressReducer, wheelDelta } from './gestures.js';
|
|
10
|
+
export { D as DOUBLE_CLICK, a as DoubleClick } from './double-click-jtUSNuHL.js';
|
|
11
|
+
export { D as Deadline, M as Machine, a as MachineOptions, P as PAGED_SWIPE_DEFAULTS, b as PAGED_SWIPE_EMPTY_CONTEXT, c as PAGED_SWIPE_IDLE, d as PagedSwipeConfig, e as PagedSwipeContext, f as PagedSwipeInput, g as PagedSwipeOptions, h as PagedSwipeState, S as SwipeSide, i as createMachine, j as createPagedSwipe, p as pagedSwipeDeadline, k as pagedSwipeReducer, r as rubberBand, s as swipeProgress } from './paged-swipe-CIzjr2DQ.js';
|
|
11
12
|
export { ClearRect, DRAG_DEFAULTS, DRAG_PREVIEW_DEFAULT, DragFrame, DragIntent, DragIntentOptions, DragIntentState, DragKeys, DragModifiers, DragPreview, DragTarget, DragTuning, GripPress, GripRelease, GuideRectsOptions, LANDING_APPROACH, LANDING_GATES, LANDING_MARGINS, LANDING_MODIFIERS, LANDING_TOUCH_MARGINS, LandingApproach, LandingFrame, LandingGates, LandingGeometry, LandingGuideRef, LandingHeld, LandingLane, LandingMargins, LandingModel, LandingModifiers, LandingOptions, LandingRegion, LandingRegions, LandingRelease, LandingSpot, LiftDecision, MIN_BOX_LENGTH, PLACE_GUIDES_DEFAULT, PlaceGuides, PlacedGuide, PreviewFrame, PreviewMode, PreviewPlan, REFUSAL_RANK, createDragIntent, createGripPress, createLandingModel, guideRects, guidesOf, inRect, liftDecision, pickRank, previewPlan, targetAt } from './drag.js';
|
|
13
|
+
export { M as ModifierKey, a as Modifiers, i as isHeld } from './keys-BpcrOp4S.js';
|
|
12
14
|
export { D as DrawEntry, a as DrawFrame, b as Drawable, L as LayoutItem, c as LayoutMotion, d as LayoutMotionOptions, e as LayoutTask, f as createLayoutMotion } from './motion-sElR1A_c.js';
|
|
13
15
|
export { AnchoredMorph, BoxSize, HeldDrag, MORPH_TEMPO, anchoredMorph, holdItem } from './layout.js';
|
package/dist/index.js
CHANGED
|
@@ -51,12 +51,13 @@ import {
|
|
|
51
51
|
pagedSwipeReducer,
|
|
52
52
|
platformButton,
|
|
53
53
|
resolveDragModifier,
|
|
54
|
+
rubberBand,
|
|
54
55
|
swipeProgress,
|
|
55
56
|
toModifiers,
|
|
56
57
|
touchPressDeadline,
|
|
57
58
|
touchPressReducer,
|
|
58
59
|
wheelDelta
|
|
59
|
-
} from "./chunk-
|
|
60
|
+
} from "./chunk-K6TAWCGL.js";
|
|
60
61
|
import {
|
|
61
62
|
batch,
|
|
62
63
|
computed,
|
|
@@ -183,6 +184,7 @@ export {
|
|
|
183
184
|
resolveDragModifier,
|
|
184
185
|
resolveSpring,
|
|
185
186
|
reveal,
|
|
187
|
+
rubberBand,
|
|
186
188
|
settleValue,
|
|
187
189
|
shapeEquals,
|
|
188
190
|
signal,
|
|
@@ -21,19 +21,4 @@ type ModifierKey = keyof Modifiers | "mod";
|
|
|
21
21
|
*/
|
|
22
22
|
declare function isHeld(modifiers: Partial<Modifiers> | undefined, key: ModifierKey | null): boolean;
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
* A double click: two presses within `ms` of each other (press to press) and `px` of the first. One value for the whole
|
|
26
|
-
* package: the gesture recognizer's `clickCount` (`RECOGNIZER_DEFAULTS.multiClick`) and a grip's double-activate
|
|
27
|
-
* (`createGripPress`) both default to it.
|
|
28
|
-
*/
|
|
29
|
-
interface DoubleClick {
|
|
30
|
-
readonly ms: number;
|
|
31
|
-
readonly px: number;
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* 500 ms and 5 px: the desktop systems' own default interval (browsers don't expose the user's setting). A host that has
|
|
35
|
-
* the platform's count (a `mousedown`'s `detail`) can pass it to `createGripPress`'s `down` instead.
|
|
36
|
-
*/
|
|
37
|
-
declare const DOUBLE_CLICK: DoubleClick;
|
|
38
|
-
|
|
39
|
-
export { DOUBLE_CLICK as D, type ModifierKey as M, type DoubleClick as a, type Modifiers as b, isHeld as i };
|
|
24
|
+
export { type ModifierKey as M, type Modifiers as a, isHeld as i };
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
import { T as TimerSource } from './port-CmlUctqx.js';
|
|
2
|
+
import { a as Modifiers, M as ModifierKey } from './keys-BpcrOp4S.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A timer event a state asks for: send `event(t)` when the clock reaches
|
|
6
|
+
* `at`. Machines stay pure; this is how a long-press or a dwell turns into
|
|
7
|
+
* an event without the reducer touching a timer.
|
|
8
|
+
*/
|
|
9
|
+
interface Deadline<E> {
|
|
10
|
+
/** Clock time in ms. */
|
|
11
|
+
readonly at: number;
|
|
12
|
+
/** The event to send, given the clock time it fired at. */
|
|
13
|
+
readonly event: (t: number) => E;
|
|
14
|
+
}
|
|
15
|
+
/** Options of {@link createMachine}. */
|
|
16
|
+
interface MachineOptions<S, E> {
|
|
17
|
+
/** The pure transition function. Returning the same state means "no change". */
|
|
18
|
+
readonly reducer: (state: S, event: E) => S;
|
|
19
|
+
readonly initial: S;
|
|
20
|
+
/** Timers come from here (and `now()` for their events). */
|
|
21
|
+
readonly clock: TimerSource;
|
|
22
|
+
/** The timer event the state needs, or `null`. Checked after every transition. */
|
|
23
|
+
readonly deadline?: (state: S) => Deadline<E> | null;
|
|
24
|
+
}
|
|
25
|
+
/** A running machine: the state, a way to send events, and change listeners. */
|
|
26
|
+
interface Machine<S, E> {
|
|
27
|
+
/** The current state; reactive (read it in a computed or an effect). */
|
|
28
|
+
readonly state: S;
|
|
29
|
+
/** The current state, untracked. */
|
|
30
|
+
peek(): S;
|
|
31
|
+
/**
|
|
32
|
+
* Run `event` through the reducer and return the new state. An event sent
|
|
33
|
+
* from a listener waits until the current one has been handled.
|
|
34
|
+
*/
|
|
35
|
+
send(event: E): S;
|
|
36
|
+
/** Called after each change of state (not for events that changed nothing). */
|
|
37
|
+
subscribe(listener: (next: S, previous: S, event: E) => void): () => void;
|
|
38
|
+
/** Clear the timer and drop listeners. Events sent after this are ignored. */
|
|
39
|
+
dispose(): void;
|
|
40
|
+
}
|
|
41
|
+
/** Run a pure machine on a clock: it arms and clears the deadline timer for you. */
|
|
42
|
+
declare function createMachine<S, E>(options: MachineOptions<S, E>): Machine<S, E>;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* A paged swipe: a trackpad's two-finger scroll or a finger swipes from one page to the previous or the next, the
|
|
46
|
+
* pages following it, and commits or snaps back when it ends.
|
|
47
|
+
*
|
|
48
|
+
* ```text
|
|
49
|
+
* idle ──wheel / touch-move (arming rules pass)──► armed ──travel ≥ threshold──► tracking
|
|
50
|
+
* ▲ │ │
|
|
51
|
+
* │ rule breach / idle / end gesture end
|
|
52
|
+
* │ ▼ ▼
|
|
53
|
+
* └──────── lockout elapsed ◄── lockout ◄── settled (commit) ◄───────────── settling
|
|
54
|
+
* └──────────────────────────────────────── settled (cancel) ◄───────────────────┤
|
|
55
|
+
* └──────────────────────────────────────── cancel (transition stopped) ◄────────┘
|
|
56
|
+
* ```
|
|
57
|
+
*
|
|
58
|
+
* - **Arming:** nothing else owns the pointer (`blocked`), the movement runs mostly along the swipe (more than twice
|
|
59
|
+
* the cross movement), no Ctrl (a pinch), the configured modifier is held, nothing under the pointer can still
|
|
60
|
+
* scroll that way (`canScrollFurther`), and there is a page on that side (or `wrap`). A wheel run that breaks a
|
|
61
|
+
* rule belongs to scrolling until the wheel has been idle `idle`.
|
|
62
|
+
* - **Tracking:** `progress` is the travel over the page size, −1 to 1, held at 0 towards a side with no page.
|
|
63
|
+
* - **Ending:** a touch ends when the finger lifts, a wheel run after `idle` without samples. It commits when
|
|
64
|
+
* `|progress| ≥ commitFraction`, or the peak speed towards the target reached `commitVelocity` (the peak starts
|
|
65
|
+
* over when the travel crosses zero, so a fast fling out and a pull back does not commit the way back).
|
|
66
|
+
* - **Settling** lasts as long as the host's page transition; the host sends `settled` when it is done (or `cancel`
|
|
67
|
+
* when it stops the transition). After a commit, `lockout` swallows the trackpad's momentum for `lockout`, and the
|
|
68
|
+
* run stays claimed after it. A cancel never skips a lockout: a committing settle that is cancelled goes to it too,
|
|
69
|
+
* so momentum can't commit twice.
|
|
70
|
+
* - **A finger:** a start that is `claimed` (it belongs to someone else: the system's screen edge, content that keeps
|
|
71
|
+
* its gestures) never arms until the finger lifts. Something that `scrolled` while a finger swipes takes the swipe
|
|
72
|
+
* (it commits nothing), and a finger that goes down before nothing has scrolled for `idle` never arms: a flick that
|
|
73
|
+
* ran a scroll to its end doesn't page on the next flick. A finger that rested `flickRest` before lifting isn't flicking. With `band`, a
|
|
74
|
+
* finger also tracks towards a side with no page (progress 0, never a commit), so the host can draw a rubber band
|
|
75
|
+
* from `travel` ({@link rubberBand}).
|
|
76
|
+
*
|
|
77
|
+
* Pure and timer-free: {@link pagedSwipeDeadline} says when the next `tick` is due ({@link createPagedSwipe} arms it).
|
|
78
|
+
* Signs: a wheel delta > 0 along the swipe heads to `next`; a finger moving towards smaller x (or y) heads to `next`.
|
|
79
|
+
*/
|
|
80
|
+
/** Which side of the current page a swipe heads to. */
|
|
81
|
+
type SwipeSide = "prev" | "next";
|
|
82
|
+
/** Tunables of the paged swipe. */
|
|
83
|
+
interface PagedSwipeConfig {
|
|
84
|
+
/** px of travel before an armed swipe tracks. Default 24. */
|
|
85
|
+
readonly threshold: number;
|
|
86
|
+
/** The share of the page size that commits at the end. Default 0.35. */
|
|
87
|
+
readonly commitFraction: number;
|
|
88
|
+
/** px/ms: a peak speed towards the target that commits at the end. Default 0.6. */
|
|
89
|
+
readonly commitVelocity: number;
|
|
90
|
+
/** ms without a wheel sample that ends a wheel run. Default 120. */
|
|
91
|
+
readonly idle: number;
|
|
92
|
+
/** ms after a commit during which wheel samples are swallowed (momentum). Default 350. */
|
|
93
|
+
readonly lockout: number;
|
|
94
|
+
/** Past the last page comes the first, and back. Default false. */
|
|
95
|
+
readonly wrap: boolean;
|
|
96
|
+
/** The page size in px when no sample or context gives one. Default 800. */
|
|
97
|
+
readonly size: number;
|
|
98
|
+
/** A modifier the wheel needs held to swipe (`null`: none). Touch never needs one. Default null. */
|
|
99
|
+
readonly modifier: ModifierKey | null;
|
|
100
|
+
/** The swipe's direction: `"x"` (the default) or `"y"`. */
|
|
101
|
+
readonly along: "x" | "y";
|
|
102
|
+
/** ms: a finger resting this long before it lifts ends without a flick (its peak speed doesn't count). Default 100. */
|
|
103
|
+
readonly flickRest?: number;
|
|
104
|
+
/** A finger may track towards a side with no page, never committing there (for a rubber band). Default false. */
|
|
105
|
+
readonly band?: boolean;
|
|
106
|
+
}
|
|
107
|
+
/** Defaults of {@link PagedSwipeConfig}. */
|
|
108
|
+
declare const PAGED_SWIPE_DEFAULTS: PagedSwipeConfig;
|
|
109
|
+
/** What the host knows about the pages now. */
|
|
110
|
+
interface PagedSwipeContext {
|
|
111
|
+
readonly hasPrev: boolean;
|
|
112
|
+
readonly hasNext: boolean;
|
|
113
|
+
/** The page size in px, or null (the config's). */
|
|
114
|
+
readonly size: number | null;
|
|
115
|
+
/** Something else owns the pointer (a drag): nothing arms, and a swipe in progress gives way. */
|
|
116
|
+
readonly blocked: boolean;
|
|
117
|
+
/** When something last `scrolled` (ms), or null (the default): a finger that goes down within `idle` of it never arms. */
|
|
118
|
+
readonly scrolledAt?: number | null;
|
|
119
|
+
}
|
|
120
|
+
/** The context before the host has said anything. */
|
|
121
|
+
declare const PAGED_SWIPE_EMPTY_CONTEXT: PagedSwipeContext;
|
|
122
|
+
type Input = "wheel" | "touch";
|
|
123
|
+
interface Base {
|
|
124
|
+
readonly context: PagedSwipeContext;
|
|
125
|
+
/** −1 to 1; negative towards `prev`. */
|
|
126
|
+
readonly progress: number;
|
|
127
|
+
readonly target: SwipeSide | null;
|
|
128
|
+
}
|
|
129
|
+
/** The paged swipe's state. Every phase has a way back to `idle`. */
|
|
130
|
+
type PagedSwipeState = (Base & {
|
|
131
|
+
readonly phase: "idle";
|
|
132
|
+
/** The last wheel sample of the current run (null: none, or the run went idle). */
|
|
133
|
+
readonly lastWheel: number | null;
|
|
134
|
+
/** This wheel run broke the arming rules (or committed): it cannot arm until the wheel is idle `idle`. */
|
|
135
|
+
readonly claimed: boolean;
|
|
136
|
+
}) | (Base & {
|
|
137
|
+
readonly phase: "armed";
|
|
138
|
+
readonly input: Input;
|
|
139
|
+
/** Where the finger went down (touch). */
|
|
140
|
+
readonly origin: {
|
|
141
|
+
readonly x: number;
|
|
142
|
+
readonly y: number;
|
|
143
|
+
};
|
|
144
|
+
/** Wheel travel along the swipe and across it so far. */
|
|
145
|
+
readonly travel: number;
|
|
146
|
+
readonly cross: number;
|
|
147
|
+
readonly last: number;
|
|
148
|
+
}) | (Base & {
|
|
149
|
+
readonly phase: "tracking";
|
|
150
|
+
readonly input: Input;
|
|
151
|
+
readonly origin: {
|
|
152
|
+
readonly x: number;
|
|
153
|
+
readonly y: number;
|
|
154
|
+
};
|
|
155
|
+
readonly travel: number;
|
|
156
|
+
readonly last: number;
|
|
157
|
+
/** The highest speed (px/ms) towards the current target. */
|
|
158
|
+
readonly peak: number;
|
|
159
|
+
/** The context the swipe armed with: its pages and size hold until it ends (a `context` meanwhile waits). */
|
|
160
|
+
readonly held: PagedSwipeContext;
|
|
161
|
+
}) | (Base & {
|
|
162
|
+
readonly phase: "settling";
|
|
163
|
+
readonly input: Input;
|
|
164
|
+
readonly outcome: "commit" | "cancel";
|
|
165
|
+
readonly ended: number;
|
|
166
|
+
readonly lastWheel: number;
|
|
167
|
+
}) | (Base & {
|
|
168
|
+
readonly phase: "lockout";
|
|
169
|
+
readonly until: number;
|
|
170
|
+
readonly lastWheel: number;
|
|
171
|
+
});
|
|
172
|
+
/** Events of the paged swipe. `t` is the clock time in ms. */
|
|
173
|
+
type PagedSwipeInput = {
|
|
174
|
+
readonly type: "wheel";
|
|
175
|
+
readonly dx: number;
|
|
176
|
+
readonly dy: number;
|
|
177
|
+
readonly t: number;
|
|
178
|
+
readonly modifiers: Modifiers;
|
|
179
|
+
/** Something under the pointer can still scroll that way: no arming. */
|
|
180
|
+
readonly canScrollFurther?: boolean;
|
|
181
|
+
readonly size?: number;
|
|
182
|
+
}
|
|
183
|
+
/** A finger went down; `claimed`: the start belongs to someone else, and this touch never arms. */
|
|
184
|
+
| {
|
|
185
|
+
readonly type: "touch-start";
|
|
186
|
+
readonly x: number;
|
|
187
|
+
readonly y: number;
|
|
188
|
+
readonly t: number;
|
|
189
|
+
readonly size?: number;
|
|
190
|
+
readonly claimed?: boolean;
|
|
191
|
+
} | {
|
|
192
|
+
readonly type: "touch-move";
|
|
193
|
+
readonly x: number;
|
|
194
|
+
readonly y: number;
|
|
195
|
+
readonly t: number;
|
|
196
|
+
readonly canScrollFurther?: boolean;
|
|
197
|
+
readonly size?: number;
|
|
198
|
+
} | {
|
|
199
|
+
readonly type: "touch-end";
|
|
200
|
+
readonly t: number;
|
|
201
|
+
} | {
|
|
202
|
+
readonly type: "tick";
|
|
203
|
+
readonly t: number;
|
|
204
|
+
} | {
|
|
205
|
+
readonly type: "settled";
|
|
206
|
+
} | {
|
|
207
|
+
readonly type: "cancel";
|
|
208
|
+
} | {
|
|
209
|
+
readonly type: "block";
|
|
210
|
+
readonly on: boolean;
|
|
211
|
+
}
|
|
212
|
+
/** Something under the swipe scrolled (any axis): a finger's swipe in progress gives way, and none arms for `idle`. */
|
|
213
|
+
| {
|
|
214
|
+
readonly type: "scrolled";
|
|
215
|
+
readonly t: number;
|
|
216
|
+
} | {
|
|
217
|
+
readonly type: "context";
|
|
218
|
+
readonly hasPrev: boolean;
|
|
219
|
+
readonly hasNext: boolean;
|
|
220
|
+
readonly size?: number;
|
|
221
|
+
};
|
|
222
|
+
/** The idle state with no context. */
|
|
223
|
+
declare const PAGED_SWIPE_IDLE: PagedSwipeState;
|
|
224
|
+
/**
|
|
225
|
+
* A rubber band: how far (px) to draw a travel of `over` px past the last page, for a page `size` px long. It starts at
|
|
226
|
+
* `strength` px per px of travel, grows ever more slowly, stays under `size`, keeps the sign of `over`, and never turns
|
|
227
|
+
* back. Use it on `travel` while a `band` swipe heads to a side with no page.
|
|
228
|
+
*/
|
|
229
|
+
declare function rubberBand(over: number, size: number, strength?: number): number;
|
|
230
|
+
/** Travel to progress: over the page size, −1 to 1, 0 towards a side with no page (unless `wrap`). */
|
|
231
|
+
declare function swipeProgress(travel: number, size: number, c: PagedSwipeContext, wrap: boolean): number;
|
|
232
|
+
/** The paged swipe's pure transition function. Unmatched pairs return the state unchanged. */
|
|
233
|
+
declare function pagedSwipeReducer(state: PagedSwipeState, event: PagedSwipeInput, config?: PagedSwipeConfig): PagedSwipeState;
|
|
234
|
+
/** When the next `tick` is due: a wheel run's idle end, or the end of the lockout; `null` when none is. */
|
|
235
|
+
declare function pagedSwipeDeadline(state: PagedSwipeState, config?: PagedSwipeConfig): Deadline<PagedSwipeInput> | null;
|
|
236
|
+
/** Options of {@link createPagedSwipe}. */
|
|
237
|
+
interface PagedSwipeOptions {
|
|
238
|
+
readonly clock: TimerSource;
|
|
239
|
+
readonly config?: Partial<PagedSwipeConfig>;
|
|
240
|
+
}
|
|
241
|
+
/** A paged swipe on a clock: the idle and lockout timers are armed for you. */
|
|
242
|
+
declare function createPagedSwipe(options: PagedSwipeOptions): Machine<PagedSwipeState, PagedSwipeInput>;
|
|
243
|
+
|
|
244
|
+
export { type Deadline as D, type Machine as M, PAGED_SWIPE_DEFAULTS as P, type SwipeSide as S, type MachineOptions as a, PAGED_SWIPE_EMPTY_CONTEXT as b, PAGED_SWIPE_IDLE as c, type PagedSwipeConfig as d, type PagedSwipeContext as e, type PagedSwipeInput as f, type PagedSwipeOptions as g, type PagedSwipeState as h, createMachine as i, createPagedSwipe as j, pagedSwipeReducer as k, pagedSwipeDeadline as p, rubberBand as r, swipeProgress as s };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@n-uf/motion",
|
|
3
|
-
"version": "26.11.
|
|
3
|
+
"version": "26.11.63",
|
|
4
4
|
"description": "How things move: one frame loop with an injected clock, springs, tweens and the settle curve, a DOM-free gesture recognizer, the drag intent and the landing model, and layout motion. No DOM, no framework.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"animation",
|
|
@@ -97,7 +97,7 @@
|
|
|
97
97
|
},
|
|
98
98
|
"scripts": {
|
|
99
99
|
"build": "tsup && node ./scripts/check-dist.mjs",
|
|
100
|
-
"typecheck": "tsc -p tsconfig.json && tsc -p tsconfig.test.json",
|
|
100
|
+
"typecheck": "tsc -p tsconfig.json && tsc -p tsconfig.test.json && tsc -p tsconfig.dom.json",
|
|
101
101
|
"test": "vitest run",
|
|
102
102
|
"bench": "node ./bench/run.mjs && node ./bench/compare.mjs",
|
|
103
103
|
"check": "pnpm typecheck && pnpm test && pnpm build",
|