@map-gesture-controls/core 0.1.3 → 0.1.5

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/README.md ADDED
@@ -0,0 +1,89 @@
1
+ # @map-gesture-controls/core
2
+
3
+ [![npm version](https://img.shields.io/npm/v/@map-gesture-controls/core?style=flat-square)](https://www.npmjs.com/package/@map-gesture-controls/core)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg?style=flat-square)](https://opensource.org/licenses/MIT)
5
+ [![Bundle size](https://img.shields.io/bundlephobia/minzip/@map-gesture-controls/core?style=flat-square&label=minzipped)](https://bundlephobia.com/package/@map-gesture-controls/core)
6
+ [![TypeScript](https://img.shields.io/badge/TypeScript-typed-blue?style=flat-square&logo=typescript)](https://www.typescriptlang.org/)
7
+
8
+ **Turn any web map into a hands-free experience.** This is the map-agnostic gesture detection engine behind [map-gesture-controls](https://github.com/sanderdesnaijer/map-gesture-controls). It uses [MediaPipe](https://developers.google.com/mediapipe) hand-tracking WASM to detect hand gestures from a webcam feed, classify them in real time, and expose a clean event-driven API. All processing runs locally in the browser. No video data ever leaves the device.
9
+
10
+ > Building with OpenLayers? Use [`@map-gesture-controls/ol`](https://www.npmjs.com/package/@map-gesture-controls/ol) instead. It wraps this package and adds map integration out of the box.
11
+
12
+ ## What it does
13
+
14
+ - Detects hands and classifies gestures at 30+ fps using MediaPipe Hand Landmarker
15
+ - Recognizes **fist** (pan), **open palm** (zoom), and **idle** states
16
+ - Manages gesture transitions with dwell timers and grace periods to avoid flickering
17
+ - Provides a configurable webcam overlay with corner/full/hidden display modes
18
+ - Ships fully typed TypeScript declarations
19
+
20
+ ## Install
21
+
22
+ ```bash
23
+ npm install @map-gesture-controls/core
24
+ ```
25
+
26
+ ## Quick start
27
+
28
+ ```ts
29
+ import { GestureController } from '@map-gesture-controls/core';
30
+ import '@map-gesture-controls/core/style.css';
31
+
32
+ const controller = new GestureController({
33
+ onGestureFrame(frame) {
34
+ // frame.hands contains detected hands with landmarks and gesture type
35
+ console.log(frame);
36
+ },
37
+ });
38
+
39
+ // Must be called from a user interaction (button click) for webcam permission
40
+ await controller.start();
41
+ ```
42
+
43
+ ## Exports
44
+
45
+ | Export | Type | Description |
46
+ | --- | --- | --- |
47
+ | `GestureController` | Class | Opens the webcam, runs MediaPipe detection, and emits gesture frames |
48
+ | `GestureStateMachine` | Class | Manages gesture state transitions with dwell and grace timers |
49
+ | `WebcamOverlay` | Class | Renders a configurable camera preview overlay |
50
+ | `classifyGesture` | Function | Classifies a set of hand landmarks into `fist`, `openPalm`, or `none` |
51
+ | `getHandSize` | Function | Computes the bounding size of a hand from its landmarks |
52
+ | `getTwoHandDistance` | Function | Measures the distance between two detected hands |
53
+ | `DEFAULT_WEBCAM_CONFIG` | Constant | Default webcam overlay settings |
54
+ | `DEFAULT_TUNING_CONFIG` | Constant | Default tuning parameters |
55
+
56
+ Full TypeScript types are exported for `GestureMode`, `GestureFrame`, `DetectedHand`, `WebcamConfig`, `TuningConfig`, and more.
57
+
58
+ ## Gesture recognition
59
+
60
+ | Gesture | Detection rule | Use case |
61
+ | --- | --- | --- |
62
+ | **Fist** | One hand, 3+ fingers curled | Pan / drag |
63
+ | **Open palm** | Two hands, all fingers extended and spread | Zoom in/out |
64
+ | **Idle** | Anything else | No action |
65
+
66
+ Gestures are confirmed after a configurable dwell period (default 80 ms) and held through a grace period (default 150 ms) to prevent flickering when tracking briefly drops.
67
+
68
+ ## Use cases
69
+
70
+ - **Kiosk and exhibit displays** where touch screens get dirty or break down
71
+ - **Accessibility** for users who cannot use a mouse or touchscreen
72
+ - **Touchless interfaces** in medical, industrial, or public environments
73
+ - **Custom map integrations** beyond OpenLayers (build your own adapter using this core engine)
74
+
75
+ ## Browser support
76
+
77
+ Requires **WebGL**, **`getUserMedia`** (webcam), and **WASM** support. Works in Chrome 111+, Edge 111+, Firefox 115+, and Safari 17+.
78
+
79
+ ## Documentation
80
+
81
+ Full docs, live demos, and configuration reference at **[sanderdesnaijer.github.io/map-gesture-controls](https://sanderdesnaijer.github.io/map-gesture-controls/)**
82
+
83
+ ## Privacy
84
+
85
+ MediaPipe WASM and the hand landmarker model are loaded from public CDNs. No video frames are sent to any server. All gesture processing happens locally in the browser.
86
+
87
+ ## License
88
+
89
+ MIT
@@ -5,7 +5,7 @@ export interface StateMachineOutput {
5
5
  zoomDelta: number | null;
6
6
  }
7
7
  /**
8
- * GestureStateMachine 3-state FSM
8
+ * GestureStateMachine: 3-state FSM
9
9
  *
10
10
  * Priority rules (evaluated every frame):
11
11
  * both hands visible AND both open palm → desired = 'zooming'
@@ -65,7 +65,7 @@ class EMAScalar {
65
65
  }
66
66
  }
67
67
  /**
68
- * GestureStateMachine 3-state FSM
68
+ * GestureStateMachine: 3-state FSM
69
69
  *
70
70
  * Priority rules (evaluated every frame):
71
71
  * both hands visible AND both open palm → desired = 'zooming'
@@ -7,7 +7,7 @@ const FAST_TUNING = {
7
7
  releaseGraceMs: 0, // grace=0: idle on the SECOND frame after release
8
8
  panDeadzonePx: 0,
9
9
  zoomDeadzoneRatio: 0,
10
- smoothingAlpha: 1, // no smoothing raw values pass through
10
+ smoothingAlpha: 1, // no smoothing, raw values pass through
11
11
  minDetectionConfidence: 0.65,
12
12
  minTrackingConfidence: 0.65,
13
13
  minPresenceConfidence: 0.60,
@@ -97,9 +97,9 @@ describe('GestureStateMachine', () => {
97
97
  fsm.update(makeFrame(0, makeHand('fist', lm1), null));
98
98
  // Frame 2: transition fires → panning, but buildOutput returns from idle branch (panDelta=null)
99
99
  fsm.update(makeFrame(0, makeHand('fist', lm1), null));
100
- // Frame 3: first real panning frame sets prevPanPos = wristPos1, no delta yet
100
+ // Frame 3: first real panning frame, sets prevPanPos = wristPos1, no delta yet
101
101
  fsm.update(makeFrame(1, makeHand('fist', lm1), null));
102
- // Frame 4: second panning frame emits delta
102
+ // Frame 4: second panning frame, emits delta
103
103
  const out = fsm.update(makeFrame(2, makeHand('fist', lm2), null));
104
104
  expect(out.mode).toBe('panning');
105
105
  expect(out.panDelta).not.toBeNull();
@@ -122,7 +122,7 @@ describe('GestureStateMachine', () => {
122
122
  // Frame 1+2: dwell + transition (zooming entered on frame 2, but output comes from idle branch)
123
123
  fsm.update(makeFrame(0, makeHand('openPalm', lmL1), makeHand('openPalm', lmR1)));
124
124
  fsm.update(makeFrame(0, makeHand('openPalm', lmL1), makeHand('openPalm', lmR1)));
125
- // Frame 3: first real zooming frame sets prevZoomDist, no delta yet
125
+ // Frame 3: first real zooming frame, sets prevZoomDist, no delta yet
126
126
  fsm.update(makeFrame(1, makeHand('openPalm', lmL1), makeHand('openPalm', lmR1)));
127
127
  // Frame 4: wider spread → positive delta
128
128
  const out = fsm.update(makeFrame(2, makeHand('openPalm', lmL2), makeHand('openPalm', lmR2)));
@@ -1,13 +1,13 @@
1
1
  import type { HandLandmark, GestureType } from './types.js';
2
2
  /**
3
3
  * Returns the apparent 2D size of the hand: wrist-to-middle-MCP distance
4
- * in normalised screen space (01). Used as a depth proxy hand grows
5
- * larger as it moves toward the camera.
4
+ * in normalised screen space (0-1). Used as a depth proxy (hand grows
5
+ * larger as it moves toward the camera).
6
6
  */
7
7
  export declare function getHandSize(landmarks: HandLandmark[]): number;
8
8
  /**
9
9
  * Returns the Euclidean distance between the index fingertips of two hands
10
- * in normalised screen space (01). Used as the two-hand zoom metric
10
+ * in normalised screen space (0-1). Used as the two-hand zoom metric:
11
11
  * hands moving apart = positive delta = zoom in.
12
12
  */
13
13
  export declare function getTwoHandDistance(landmarksA: HandLandmark[], landmarksB: HandLandmark[]): number;
@@ -11,7 +11,7 @@ function dist(a, b) {
11
11
  * Returns true if all four fingers (index–pinky) are extended AND spread apart.
12
12
  *
13
13
  * "Extended": tip is farther from the wrist than its MCP joint (allows slightly
14
- * bent fingers the 0.9 factor gives ~10% slack).
14
+ * bent fingers; the 0.9 factor gives ~10% slack).
15
15
  *
16
16
  * "Spread": the minimum distance between any two adjacent fingertips (index–middle,
17
17
  * middle–ring, ring–pinky) must be at least spreadThreshold × handSize. Using the
@@ -31,7 +31,7 @@ function areAllFingersExtended(landmarks) {
31
31
  }
32
32
  // Spread check: minimum pairwise distance between adjacent fingertips vs hand size.
33
33
  // Using the minimum (not mean) catches duck/pinch shapes where adjacent fingertips
34
- // touch the mean can stay high because the outer pair (index↔pinky) is still far
34
+ // touch: the mean can stay high because the outer pair (index↔pinky) is still far
35
35
  // apart, but the minimum collapses to near zero when any two tips cluster together.
36
36
  // A natural open hand has even adjacent tips ~20–35% of handSize apart.
37
37
  // A duck has adjacent tips at ~2–8% of handSize. Threshold of 0.18 separates them.
@@ -67,8 +67,8 @@ function areAllFingersCurled(landmarks) {
67
67
  }
68
68
  /**
69
69
  * Returns the apparent 2D size of the hand: wrist-to-middle-MCP distance
70
- * in normalised screen space (01). Used as a depth proxy hand grows
71
- * larger as it moves toward the camera.
70
+ * in normalised screen space (0-1). Used as a depth proxy (hand grows
71
+ * larger as it moves toward the camera).
72
72
  */
73
73
  export function getHandSize(landmarks) {
74
74
  const wrist = landmarks[LANDMARKS.WRIST];
@@ -79,7 +79,7 @@ export function getHandSize(landmarks) {
79
79
  }
80
80
  /**
81
81
  * Returns the Euclidean distance between the index fingertips of two hands
82
- * in normalised screen space (01). Used as the two-hand zoom metric
82
+ * in normalised screen space (0-1). Used as the two-hand zoom metric:
83
83
  * hands moving apart = positive delta = zoom in.
84
84
  */
85
85
  export function getTwoHandDistance(landmarksA, landmarksB) {
@@ -31,7 +31,7 @@ function makeOpenPalmLandmarks() {
31
31
  lm[LANDMARKS.MIDDLE_MCP] = { x: 0.4, y: 0.5, z: 0 };
32
32
  lm[LANDMARKS.RING_MCP] = { x: 0.5, y: 0.5, z: 0 };
33
33
  lm[LANDMARKS.PINKY_MCP] = { x: 0.6, y: 0.5, z: 0 };
34
- // Fingertips extended (farther from wrist than MCPs) and spread
34
+ // Fingertips: extended (farther from wrist than MCPs) and spread
35
35
  lm[LANDMARKS.INDEX_TIP] = { x: 0.2, y: 0.1, z: 0 };
36
36
  lm[LANDMARKS.MIDDLE_TIP] = { x: 0.35, y: 0.1, z: 0 };
37
37
  lm[LANDMARKS.RING_TIP] = { x: 0.5, y: 0.1, z: 0 };
@@ -42,7 +42,7 @@ function makeOpenPalmLandmarks() {
42
42
  * Build a fist hand.
43
43
  *
44
44
  * Strategy: wrist at (0.5, 0.8), MCP joints at (0.5, 0.5),
45
- * fingertips curled back to (0.5, 0.7) closer to wrist than MCPs.
45
+ * fingertips curled back to (0.5, 0.7), closer to wrist than MCPs.
46
46
  *
47
47
  * dist(tip, wrist) ≈ 0.1 < dist(mcp, wrist) * 1.1 ≈ 0.33 ✓
48
48
  */
@@ -72,7 +72,7 @@ describe('classifyGesture', () => {
72
72
  expect(classifyGesture(makeFistLandmarks())).toBe('fist');
73
73
  });
74
74
  it('returns "none" for an ambiguous / neutral hand', () => {
75
- // All landmarks at the same point fingers neither extended nor curled
75
+ // All landmarks at the same point, fingers neither extended nor curled
76
76
  expect(classifyGesture(makeLandmarks())).toBe('none');
77
77
  });
78
78
  it('prefers "fist" over "openPalm" when both criteria match', () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@map-gesture-controls/core",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "description": "Map-agnostic hand gesture detection and state machine (MediaPipe)",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -30,8 +30,29 @@
30
30
  "keywords": [
31
31
  "mediapipe",
32
32
  "hand-gestures",
33
- "gesture-detection"
33
+ "gesture-detection",
34
+ "gesture-recognition",
35
+ "hand-tracking",
36
+ "webcam",
37
+ "touchless",
38
+ "hands-free",
39
+ "accessibility",
40
+ "computer-vision",
41
+ "wasm",
42
+ "kiosk",
43
+ "map",
44
+ "interaction"
34
45
  ],
46
+ "homepage": "https://sanderdesnaijer.github.io/map-gesture-controls/",
47
+ "repository": {
48
+ "type": "git",
49
+ "url": "https://github.com/sanderdesnaijer/map-gesture-controls.git",
50
+ "directory": "packages/map-gesture-core"
51
+ },
52
+ "bugs": {
53
+ "url": "https://github.com/sanderdesnaijer/map-gesture-controls/issues"
54
+ },
55
+ "author": "Sander de Snaijer",
35
56
  "overrides": {
36
57
  "esbuild": "^0.25.0"
37
58
  },