Skip to content

sumitsahoo/web-haptic-engine

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

37 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

๐Ÿ“ณ Web Haptic Engine

A cross-platform haptic feedback engine for the web.
Supports Android vibration, iOS Taptic feedback, audio impulse synthesis, drag haptics, and 23 built-in presets.

npm version MIT License Platform TypeScript Documentation


โœจ Features

Category Details
๐Ÿ“ฑ Android Vibration Full navigator.vibrate() pattern support with intensity-scaled durations
๐ŸŽ iOS Taptic Exploits the <input type="checkbox" switch> toggle to trigger native Taptic Engine feedback
๐Ÿ”Š Audio Impulse Layer 8 synthesized AudioBuffer impulses (tick, tap, thud, click, snap, buzz, confirm, harsh)
๐Ÿ‘† Drag Haptics Touchmove-driven haptic feedback with distance threshold โ€” works reliably on iOS
๐ŸŽ›๏ธ 23 Presets Ready-to-use patterns: success, warning, error, heartbeat, spring, buzz, and more
๐Ÿ”— Sequences Chain presets with delays, repeats, and custom gaps
ใ€ฐ๏ธ Easing Functions linear, easeIn, easeOut, easeInOut, bounce, spring
๐Ÿ“ฆ Zero Dependencies No external runtime dependencies โ€” pure TypeScript

๐Ÿ“š Documentation

Full documentation with framework integration guides is available at sumitsahoo.github.io/web-haptic-engine/docs.


๐Ÿ“ฅ Installation

npm install web-haptic-engine
pnpm add web-haptic-engine
yarn add web-haptic-engine

๐Ÿš€ Quick Start

import { haptic } from "web-haptic-engine";

await haptic("success");
await haptic("heavy", { intensity: 0.8 });

See the full documentation for engine setup, drag haptics, sequences, custom presets, and framework-specific guides.


๐Ÿง‘โ€๐Ÿ’ป Development

# Install dependencies
vp install

# Build the library
vp pack

# Run tests
vp test

# Watch mode (rebuild on changes)
vp pack --watch

# Start docs dev server
vp run docs:dev

# Build docs for production
vp run docs:build

๐ŸŽฎ Demo

Try the live demo at sumitsahoo.github.io/web-haptic-engine.

An interactive demo is also included in the demo/ directory. It showcases all 23 presets, drag haptics, impulse buffers, sequences, and real-time controls for intensity and audio gain.

# Install dependencies (if not already done)
vp install

# Start the demo dev server
vp run demo

This launches a Vite dev server. Open the URL shown in the terminal (typically http://localhost:5173) in your browser. For the full haptic experience, open it on a mobile device โ€” Android for vibration, iOS Safari for Taptic feedback. On desktop, audio impulses still play as a fallback.


๐Ÿ“ Project Structure

web-haptic-engine/
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ core/               # Types, constants, easings & presets
โ”‚   โ”œโ”€โ”€ audio/              # Web Audio impulse synthesis & playback
โ”‚   โ”œโ”€โ”€ platform/           # Platform detection & adapters (Android, iOS)
โ”‚   โ”œโ”€โ”€ interactions/       # User interaction patterns (drag haptics)
โ”‚   โ”œโ”€โ”€ haptic-engine.ts    # Main HapticEngine class & convenience helpers
โ”‚   โ””โ”€โ”€ index.ts            # Public API exports
โ”œโ”€โ”€ docs/                   # VitePress documentation site
โ”‚   โ”œโ”€โ”€ .vitepress/         # VitePress config & theme
โ”‚   โ”œโ”€โ”€ guide/              # Getting started, presets, platform support
โ”‚   โ”œโ”€โ”€ frameworks/         # React, Next.js, Vue integration guides
โ”‚   โ””โ”€โ”€ api/                # API reference (HapticEngine, DragHaptics, Types)
โ”œโ”€โ”€ demo/
โ”‚   โ”œโ”€โ”€ index.html          # Demo page
โ”‚   โ”œโ”€โ”€ main.ts             # Demo app (imports from library)
โ”‚   โ””โ”€โ”€ vite.config.ts      # Vite config for demo dev server
โ”œโ”€โ”€ tests/
โ”‚   โ””โ”€โ”€ index.test.ts       # Unit tests
โ”œโ”€โ”€ tsdown.config.ts        # Library build config
โ”œโ”€โ”€ vite.config.ts          # Vite+ unified config
โ”œโ”€โ”€ tsconfig.json           # TypeScript config
โ””โ”€โ”€ package.json

๐Ÿ’ก Acknowledgements

This project was initially inspired by web-haptics by @lochie.


๐Ÿค Contributing

Contributions are welcome! Please see the CONTRIBUTING.md guide for details.


๐Ÿ“„ License

This project is licensed under the MIT License โ€” feel free to use it for both personal and commercial purposes. See the LICENSE file for details.


Built with โค๏ธ by Sumit Sahoo

About

Cross-platform (iOS, Android and Web) haptic feedback engine for the web

Topics

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Sponsor this project

Packages

 
 
 

Contributors