@mintplayer/web-components 2.1.0 → 2.2.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.
@@ -0,0 +1,184 @@
1
+ class r {
2
+ constructor(t, s = {}) {
3
+ this.callbacks = s, this.origin = null, this.locked = !1, this.dragging = !1, this.lastDeltaPx = 0, this.startTimer = null, this.destroyed = !1, this.orientation = t.orientation, this.thresholdPx = t.swipeThresholdPx ?? r.DEFAULT_THRESHOLD_PX, this.startDelayMs = t.startDelayMs ?? r.DEFAULT_START_DELAY_MS;
4
+ }
5
+ static {
6
+ this.DEFAULT_THRESHOLD_PX = 3;
7
+ }
8
+ static {
9
+ this.DEFAULT_START_DELAY_MS = 20;
10
+ }
11
+ setOrientation(t) {
12
+ this.orientation = t;
13
+ }
14
+ /** `touch-action` the consumer should set on the gesture surface. */
15
+ get touchAction() {
16
+ return this.orientation === "horizontal" ? "pan-y" : "pan-x";
17
+ }
18
+ pointerDown(t, s) {
19
+ this.destroyed || (this.reset(), this.origin = { x: t, y: s }, this.startTimer = setTimeout(() => {
20
+ this.startTimer = null, !(this.destroyed || !this.origin) && (this.dragging = !0, this.callbacks.onDragStart?.(), this.callbacks.onDragMove?.(this.lastDeltaPx));
21
+ }, this.startDelayMs));
22
+ }
23
+ /** Returns true when the caller should preventDefault() on this move event. */
24
+ pointerMove(t, s) {
25
+ if (!this.origin) return !1;
26
+ const i = Math.abs(t - this.origin.x), e = Math.abs(s - this.origin.y), n = this.orientation === "horizontal" ? i : e, a = this.orientation === "horizontal" ? e : i;
27
+ return !this.locked && n > this.thresholdPx && n >= a && (this.locked = !0), this.lastDeltaPx = this.orientation === "horizontal" ? t - this.origin.x : s - this.origin.y, this.dragging && this.callbacks.onDragMove?.(this.lastDeltaPx), this.locked;
28
+ }
29
+ /** Returns true when the caller should preventDefault() on the end event. */
30
+ pointerUp() {
31
+ const t = this.locked;
32
+ if (this.startTimer !== null)
33
+ return this.reset(), this.callbacks.onTap?.(), !1;
34
+ if (this.dragging) {
35
+ const s = this.lastDeltaPx;
36
+ this.reset(), this.callbacks.onDragEnd?.(s);
37
+ } else
38
+ this.reset();
39
+ return t;
40
+ }
41
+ /** Abandon the gesture without emitting anything (e.g. pointercancel). */
42
+ abort() {
43
+ this.reset();
44
+ }
45
+ destroy() {
46
+ this.destroyed = !0, this.reset();
47
+ }
48
+ reset() {
49
+ this.startTimer !== null && (clearTimeout(this.startTimer), this.startTimer = null), this.origin = null, this.locked = !1, this.dragging = !1, this.lastDeltaPx = 0;
50
+ }
51
+ }
52
+ class l {
53
+ constructor(t, s = {}, i) {
54
+ this.host = t, this.callbacks = s, this.index = 0, this.pending = null, this.animating = !1, this.dragRatio = 0, this.dragging = !1, this.count = i.count, this.wrap = i.wrap ?? !0, this.durationMs = i.durationMs ?? 500, this.minimumOffsetPx = i.minimumOffsetPx ?? 50, this.prefersReducedMotion = i.prefersReducedMotion;
55
+ }
56
+ // ---- config / state -------------------------------------------------------
57
+ setConfig(t) {
58
+ t.count !== void 0 && (this.count = t.count, this.index >= this.count && (this.commit(Math.max(0, this.count - 1)), this.host.applyOffsetRatio(this.index))), t.wrap !== void 0 && (this.wrap = t.wrap), t.durationMs !== void 0 && (this.durationMs = t.durationMs), t.minimumOffsetPx !== void 0 && (this.minimumOffsetPx = t.minimumOffsetPx), t.prefersReducedMotion !== void 0 && (this.prefersReducedMotion = t.prefersReducedMotion);
59
+ }
60
+ getIndex() {
61
+ return this.index;
62
+ }
63
+ get isAnimating() {
64
+ return this.animating;
65
+ }
66
+ // ---- navigation -----------------------------------------------------------
67
+ next() {
68
+ this.relative(1);
69
+ }
70
+ previous() {
71
+ this.relative(-1);
72
+ }
73
+ /**
74
+ * Navigate to an absolute index. Out-of-range targets are a no-op (never
75
+ * wrapped — wrapping is a property of *relative* movement). `animate: false`
76
+ * jumps instantly with no events beyond `onIndexChange`.
77
+ */
78
+ goto(t, s = {}) {
79
+ if (!(t < 0 || t >= this.count)) {
80
+ if (this.interrupt(), s.animate === !1) {
81
+ this.endDragState(), this.commit(t), this.host.applyOffsetRatio(this.index);
82
+ return;
83
+ }
84
+ t === this.index && !this.dragging || this.transitionTo(t, t);
85
+ }
86
+ }
87
+ intent(t) {
88
+ switch (t) {
89
+ case "previous":
90
+ return this.previous();
91
+ case "next":
92
+ return this.next();
93
+ case "first":
94
+ return this.goto(0);
95
+ case "last":
96
+ return this.goto(Math.max(0, this.count - 1));
97
+ }
98
+ }
99
+ relative(t) {
100
+ this.interrupt();
101
+ const s = this.index + t, i = this.resolve(s);
102
+ i !== null && (!this.wrap && i === this.index && !this.dragging || this.transitionTo(s, i));
103
+ }
104
+ // ---- drag -----------------------------------------------------------------
105
+ /** A drag began: interrupt any in-flight transition so the finger owns the track. */
106
+ beginDrag() {
107
+ this.interrupt(), this.dragging = !0, this.dragRatio = 0;
108
+ }
109
+ /** Live drag update. Content follows the pointer: positive delta drags backwards. */
110
+ dragBy(t, s) {
111
+ if (!this.dragging || s <= 0) return;
112
+ let i = t / s;
113
+ if (!this.wrap) {
114
+ const e = this.index - i;
115
+ e < 0 && (i = this.index), e > this.count - 1 && (i = this.index - (this.count - 1));
116
+ }
117
+ this.dragRatio = i, this.host.applyOffsetRatio(this.index - i);
118
+ }
119
+ /** Drag release: commit when past the threshold, snap back otherwise. */
120
+ endDrag(t, s) {
121
+ if (!this.dragging) return;
122
+ const e = Math.abs(t) >= this.minimumOffsetPx ? this.index + (t < 0 ? 1 : -1) : this.index, n = this.resolve(e);
123
+ if (n === null || !this.wrap && n === this.index && e !== this.index) {
124
+ this.transitionTo(this.index, this.index);
125
+ return;
126
+ }
127
+ this.transitionTo(e, n);
128
+ }
129
+ // ---- internals ------------------------------------------------------------
130
+ /** Wrap (or clamp) a raw target into the committed range; null when empty. */
131
+ resolve(t) {
132
+ return this.count <= 0 ? null : t >= 0 && t < this.count ? t : this.wrap ? (t % this.count + this.count) % this.count : Math.min(Math.max(t, 0), this.count - 1);
133
+ }
134
+ /** Finish (commit) an in-flight transition so a new owner can take the track. */
135
+ interrupt() {
136
+ this.pending?.finish();
137
+ }
138
+ endDragState() {
139
+ this.dragging = !1, this.dragRatio = 0;
140
+ }
141
+ transitionTo(t, s) {
142
+ this.interrupt();
143
+ const i = this.index - this.dragRatio;
144
+ this.endDragState();
145
+ const e = this.prefersReducedMotion?.() ? 0 : this.durationMs;
146
+ this.callbacks.onAnimationStart?.();
147
+ const n = () => {
148
+ this.animating = !1, this.pending = null, this.commit(s), this.host.applyOffsetRatio(this.index), this.callbacks.onAnimationEnd?.();
149
+ };
150
+ if (e <= 0 || i === t) {
151
+ n();
152
+ return;
153
+ }
154
+ this.animating = !0, this.pending = this.host.runTransition(i, t, e, n);
155
+ }
156
+ commit(t) {
157
+ t !== this.index && (this.index = t, this.callbacks.onIndexChange?.(t));
158
+ }
159
+ destroy() {
160
+ this.pending?.cancel(), this.pending = null, this.animating = !1;
161
+ }
162
+ }
163
+ const o = {
164
+ horizontal: {
165
+ ArrowLeft: "previous",
166
+ ArrowRight: "next",
167
+ Home: "first",
168
+ End: "last"
169
+ },
170
+ vertical: {
171
+ ArrowUp: "previous",
172
+ ArrowDown: "next",
173
+ Home: "first",
174
+ End: "last"
175
+ }
176
+ };
177
+ function d(h, t) {
178
+ return o[t][h] ?? null;
179
+ }
180
+ export {
181
+ l as IndexMachine,
182
+ r as PointerArbiter,
183
+ d as keyToIntent
184
+ };
@@ -0,0 +1,59 @@
1
+ import { IndexMachineCallbacks, IndexMachineConfig, IndexMachineHost, SwipeIntent } from './models';
2
+ /**
3
+ * Slide-index state machine over a plain `count`, with transitions.
4
+ *
5
+ * Positions leave the machine only as a unit-free `offsetRatio` in slide units
6
+ * (see {@link IndexMachineHost}), so the host is free to realise motion as a
7
+ * transform, a scroll offset, or a timed crossfade. Wrap-around/clamping lives
8
+ * HERE, so buttons, keyboard, and drag release all obey one rule. During a
9
+ * wrapping relative move the visual target transiently leaves [0, count-1]
10
+ * (-1 or `count` — the host's wrap cells); the committed index is always
11
+ * wrapped back into range.
12
+ *
13
+ * Interruption: starting any navigation (or a new drag) finishes an in-flight
14
+ * transition first — `finish()` jumps it to its end state and commits.
15
+ */
16
+ export declare class IndexMachine {
17
+ private readonly host;
18
+ private readonly callbacks;
19
+ private index;
20
+ private count;
21
+ private wrap;
22
+ private durationMs;
23
+ private minimumOffsetPx;
24
+ private prefersReducedMotion?;
25
+ private pending;
26
+ private animating;
27
+ private dragRatio;
28
+ private dragging;
29
+ constructor(host: IndexMachineHost, callbacks: IndexMachineCallbacks | undefined, config: IndexMachineConfig);
30
+ setConfig(config: Partial<IndexMachineConfig>): void;
31
+ getIndex(): number;
32
+ get isAnimating(): boolean;
33
+ next(): void;
34
+ previous(): void;
35
+ /**
36
+ * Navigate to an absolute index. Out-of-range targets are a no-op (never
37
+ * wrapped — wrapping is a property of *relative* movement). `animate: false`
38
+ * jumps instantly with no events beyond `onIndexChange`.
39
+ */
40
+ goto(target: number, opts?: {
41
+ animate?: boolean;
42
+ }): void;
43
+ intent(intent: SwipeIntent): void;
44
+ private relative;
45
+ /** A drag began: interrupt any in-flight transition so the finger owns the track. */
46
+ beginDrag(): void;
47
+ /** Live drag update. Content follows the pointer: positive delta drags backwards. */
48
+ dragBy(deltaPx: number, extentPx: number): void;
49
+ /** Drag release: commit when past the threshold, snap back otherwise. */
50
+ endDrag(deltaPx: number, extentPx: number): void;
51
+ /** Wrap (or clamp) a raw target into the committed range; null when empty. */
52
+ private resolve;
53
+ /** Finish (commit) an in-flight transition so a new owner can take the track. */
54
+ interrupt(): void;
55
+ private endDragState;
56
+ private transitionTo;
57
+ private commit;
58
+ destroy(): void;
59
+ }
@@ -0,0 +1,4 @@
1
+ export * from './models';
2
+ export { PointerArbiter } from './pointer-arbiter';
3
+ export { IndexMachine } from './index-machine';
4
+ export { keyToIntent } from './keymap';
@@ -0,0 +1,2 @@
1
+ import { SwipeIntent, SwipeOrientation } from './models';
2
+ export declare function keyToIntent(key: string, orientation: SwipeOrientation): SwipeIntent | null;
@@ -0,0 +1 @@
1
+ export * from './types';
@@ -0,0 +1,99 @@
1
+ export type SwipeOrientation = 'horizontal' | 'vertical';
2
+ /**
3
+ * Semantic navigation intents. Input arbiters (pointer, wheel, keyboard) reduce
4
+ * raw input to these; the consumer routes them into an {@link IndexMachine}
5
+ * (or its own index logic — a scroll-snap consumer needs no machine at all).
6
+ */
7
+ export type SwipeIntent = 'previous' | 'next' | 'first' | 'last';
8
+ export interface PointerArbiterConfig {
9
+ orientation: SwipeOrientation;
10
+ /**
11
+ * Primary-axis movement (px) before the gesture locks onto its axis and the
12
+ * caller should start calling preventDefault(). 3px — deliberately small so
13
+ * the lock can engage on the first or second move event, before Firefox
14
+ * Android's APZ claims a downward gesture as pull-to-refresh.
15
+ */
16
+ swipeThresholdPx?: number;
17
+ /**
18
+ * How long (ms) a press must survive before it is treated as a drag rather
19
+ * than a tap. A release inside this window is reported as a tap and produces
20
+ * no drag events.
21
+ */
22
+ startDelayMs?: number;
23
+ }
24
+ export interface PointerArbiterCallbacks {
25
+ /** The press outlived the start delay: a drag is now in progress. */
26
+ onDragStart?(): void;
27
+ /** Live primary-axis delta from the drag origin, in px. */
28
+ onDragMove?(deltaPx: number): void;
29
+ /** The pointer lifted after a settled drag. */
30
+ onDragEnd?(deltaPx: number): void;
31
+ /** The pointer lifted inside the start-delay window. */
32
+ onTap?(): void;
33
+ }
34
+ export interface WheelArbiterConfig {
35
+ orientation: SwipeOrientation;
36
+ /** Accumulated primary-axis delta (px) that resolves to one intent. */
37
+ intentThresholdPx?: number;
38
+ /** Quiet period (ms) after an intent during which further deltas are ignored. */
39
+ cooldownMs?: number;
40
+ }
41
+ export interface WheelArbiterCallbacks {
42
+ onIntent?(intent: Extract<SwipeIntent, 'previous' | 'next'>): void;
43
+ }
44
+ /**
45
+ * A wheel/trackpad input arbiter: feed it wheel deltas, it emits at most one
46
+ * intent per physical gesture. `wheel(deltaPx)` returns `true` when the caller
47
+ * should preventDefault() (the arbiter owns the axis for this gesture).
48
+ */
49
+ export interface WheelArbiter {
50
+ wheel(deltaPx: number): boolean;
51
+ destroy(): void;
52
+ }
53
+ /**
54
+ * Handle to an in-flight transition, with the interruption contract every
55
+ * swipe UI needs: `finish()` jumps to the end state and MUST invoke the
56
+ * transition's `onDone`; `cancel()` abandons it and MUST NOT.
57
+ */
58
+ export interface TransitionHandle {
59
+ finish(): void;
60
+ cancel(): void;
61
+ }
62
+ /**
63
+ * What the machine needs from its environment. Positions are expressed as a
64
+ * unit-free ratio in slide units: ratio 0 = slide 0 at rest, 1.5 = halfway
65
+ * between slides 1 and 2. During a wrap transition the ratio transiently
66
+ * leaves [0, count-1] (e.g. `count` = the after-last wrap cell); the host maps
67
+ * logical ratios to physical positions (a transform, a scroll offset, …).
68
+ */
69
+ export interface IndexMachineHost {
70
+ /** Park the track at a position instantly (resting state or live drag). */
71
+ applyOffsetRatio(ratio: number): void;
72
+ /**
73
+ * Animate between two positions over `durationMs` (> 0 — the machine handles
74
+ * zero-duration moves itself). How the motion looks — a transform, a
75
+ * crossfade timed to match, … — is entirely the host's business.
76
+ */
77
+ runTransition(fromRatio: number, toRatio: number, durationMs: number, onDone: () => void): TransitionHandle;
78
+ }
79
+ export interface IndexMachineCallbacks {
80
+ /** The committed index changed (never fires for snap-backs or no-ops). */
81
+ onIndexChange?(index: number): void;
82
+ onAnimationStart?(): void;
83
+ onAnimationEnd?(): void;
84
+ }
85
+ export interface IndexMachineConfig {
86
+ /** Number of navigable slides (excluding any wrap cells the host renders). */
87
+ count: number;
88
+ /**
89
+ * Wrap-around at the edges. Enforced HERE, so every input path — buttons,
90
+ * keyboard, drag release — obeys the same rule.
91
+ */
92
+ wrap?: boolean;
93
+ /** Transition duration. The machine drops it to 0 under reduced motion. */
94
+ durationMs?: number;
95
+ /** Minimum drag distance (px) for a release to commit a slide change. */
96
+ minimumOffsetPx?: number;
97
+ /** Supplier consulted per transition; true → the move is instant. */
98
+ prefersReducedMotion?: () => boolean;
99
+ }
@@ -0,0 +1,45 @@
1
+ import { PointerArbiterCallbacks, PointerArbiterConfig } from './models';
2
+ /**
3
+ * Pointer-gesture arbiter: coordinates in, drag/tap semantics out.
4
+ *
5
+ * Never touches a DOM event — callers feed it (x, y) pairs from whatever input
6
+ * they listen to (touch, pointer, synthetic) and honour its boolean verdicts:
7
+ * `pointerMove`/`pointerUp` return `true` when the caller should
8
+ * `preventDefault()` (the gesture has locked onto this widget's axis and
9
+ * native scroll / pull-to-refresh must not run).
10
+ *
11
+ * The two constants encode hard-won behavior — see
12
+ * docs/prd/vertical-swipe-firefox-android.md:
13
+ * - 3px lock threshold with primary-dominates-perpendicular arbitration, so
14
+ * preventDefault() can fire before Firefox Android's APZ claims the gesture,
15
+ * while a 4px off-axis jitter still leaves native page scroll alone.
16
+ * - 20ms start delay so a tap settles without being recognised as a drag; a
17
+ * release inside the window is a tap and produces no drag events at all.
18
+ */
19
+ export declare class PointerArbiter {
20
+ private readonly callbacks;
21
+ private static readonly DEFAULT_THRESHOLD_PX;
22
+ private static readonly DEFAULT_START_DELAY_MS;
23
+ private readonly thresholdPx;
24
+ private readonly startDelayMs;
25
+ private orientation;
26
+ private origin;
27
+ private locked;
28
+ private dragging;
29
+ private lastDeltaPx;
30
+ private startTimer;
31
+ private destroyed;
32
+ constructor(config: PointerArbiterConfig, callbacks?: PointerArbiterCallbacks);
33
+ setOrientation(orientation: PointerArbiterConfig['orientation']): void;
34
+ /** `touch-action` the consumer should set on the gesture surface. */
35
+ get touchAction(): 'pan-x' | 'pan-y';
36
+ pointerDown(x: number, y: number): void;
37
+ /** Returns true when the caller should preventDefault() on this move event. */
38
+ pointerMove(x: number, y: number): boolean;
39
+ /** Returns true when the caller should preventDefault() on the end event. */
40
+ pointerUp(): boolean;
41
+ /** Abandon the gesture without emitting anything (e.g. pointercancel). */
42
+ abort(): void;
43
+ destroy(): void;
44
+ private reset;
45
+ }
@@ -1,2 +0,0 @@
1
- export declare const dropdownStyles: import('lit').CSSResult;
2
- export default dropdownStyles;