diff --git a/src/widgets/Board/lib/cycleGestures/cycleGestures.test.ts b/src/widgets/Board/lib/cycleGestures/cycleGestures.test.ts new file mode 100644 index 0000000..1e4cf0f --- /dev/null +++ b/src/widgets/Board/lib/cycleGestures/cycleGestures.test.ts @@ -0,0 +1,23 @@ +import { + describe, + expect, + it, +} from 'vitest'; +import { swipeDirection } from './cycleGestures'; + +describe('swipeDirection', () => { + it('maps a leftward swipe past threshold to next', () => { + expect(swipeDirection(-80, 50)).toBe(1); + }); + it('maps a rightward swipe past threshold to previous', () => { + expect(swipeDirection(80, 50)).toBe(-1); + }); + it('ignores sub-threshold movement', () => { + expect(swipeDirection(20, 50)).toBe(0); + expect(swipeDirection(-20, 50)).toBe(0); + }); + it('treats the exact threshold as a swipe (inclusive)', () => { + expect(swipeDirection(-50, 50)).toBe(1); + expect(swipeDirection(50, 50)).toBe(-1); + }); +}); diff --git a/src/widgets/Board/lib/cycleGestures/cycleGestures.ts b/src/widgets/Board/lib/cycleGestures/cycleGestures.ts new file mode 100644 index 0000000..b493378 --- /dev/null +++ b/src/widgets/Board/lib/cycleGestures/cycleGestures.ts @@ -0,0 +1,18 @@ +/** + * Maps a horizontal swipe delta to a cycle direction. A leftward swipe (negative + * dx) advances to the next pairing (+1); a rightward swipe (positive dx) goes to + * the previous (-1). Movement below the threshold is ignored (0). + * + * @param dx - Horizontal travel in px (end minus start). + * @param threshold - Minimum absolute travel in px to count as a swipe. + * @returns +1 (next), -1 (previous), or 0 (no cycle). + */ +export function swipeDirection(dx: number, threshold: number): -1 | 0 | 1 { + if (dx <= -threshold) { + return 1; + } + if (dx >= threshold) { + return -1; + } + return 0; +} diff --git a/src/widgets/Board/ui/Board/Board.svelte b/src/widgets/Board/ui/Board/Board.svelte new file mode 100644 index 0000000..3069091 --- /dev/null +++ b/src/widgets/Board/ui/Board/Board.svelte @@ -0,0 +1,60 @@ + + + +