bzzz 0.1.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.
- package/LICENSE +21 -0
- package/README.md +30 -0
- package/dist/chunk-RLTRZ2WN.mjs +398 -0
- package/dist/index.d.mts +124 -0
- package/dist/index.d.ts +124 -0
- package/dist/index.js +430 -0
- package/dist/index.mjs +18 -0
- package/dist/react.d.mts +34 -0
- package/dist/react.d.ts +34 -0
- package/dist/react.js +447 -0
- package/dist/react.mjs +45 -0
- package/dist/types-BRn0rP4m.d.mts +47 -0
- package/dist/types-BRn0rP4m.d.ts +47 -0
- package/package.json +72 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Pavle Lucic
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# bzzz
|
|
2
|
+
|
|
3
|
+
Haptic feedback for the web. Native vibration + audio fallback.
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/bzzz)
|
|
6
|
+
[](https://bundlephobia.com/package/bzzz)
|
|
7
|
+
|
|
8
|
+
## Install
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npm install bzzz
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Usage
|
|
15
|
+
|
|
16
|
+
```typescript
|
|
17
|
+
import { haptics } from "bzzz";
|
|
18
|
+
|
|
19
|
+
button.addEventListener("click", () => {
|
|
20
|
+
haptics.success();
|
|
21
|
+
});
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Documentation
|
|
25
|
+
|
|
26
|
+
[pavlito.github.io/bzzz](https://pavlito.github.io/bzzz)
|
|
27
|
+
|
|
28
|
+
## License
|
|
29
|
+
|
|
30
|
+
MIT
|
|
@@ -0,0 +1,398 @@
|
|
|
1
|
+
// src/capabilities.ts
|
|
2
|
+
function getAudioContextConstructor() {
|
|
3
|
+
const runtime = globalThis;
|
|
4
|
+
return runtime.AudioContext ?? runtime.webkitAudioContext;
|
|
5
|
+
}
|
|
6
|
+
function isIOS() {
|
|
7
|
+
if (typeof navigator === "undefined") return false;
|
|
8
|
+
const ua = navigator.userAgent;
|
|
9
|
+
if (/iPad|iPhone|iPod/.test(ua)) return true;
|
|
10
|
+
if (navigator.maxTouchPoints > 1) {
|
|
11
|
+
if (navigator.platform === "MacIntel") return true;
|
|
12
|
+
const uad = navigator.userAgentData;
|
|
13
|
+
if (uad?.platform === "macOS") return true;
|
|
14
|
+
}
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
function hasVibrationHardware() {
|
|
18
|
+
if (typeof navigator === "undefined") return false;
|
|
19
|
+
if (typeof navigator.vibrate !== "function") return false;
|
|
20
|
+
if (typeof matchMedia !== "undefined" && matchMedia("(pointer: coarse)").matches) {
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
function prefersReducedMotion() {
|
|
26
|
+
if (typeof matchMedia === "undefined") return false;
|
|
27
|
+
return matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
28
|
+
}
|
|
29
|
+
function getCapabilityState() {
|
|
30
|
+
return {
|
|
31
|
+
haptics: hasVibrationHardware(),
|
|
32
|
+
audio: Boolean(getAudioContextConstructor()),
|
|
33
|
+
ios: isIOS(),
|
|
34
|
+
reducedMotion: prefersReducedMotion()
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// src/patterns.ts
|
|
39
|
+
var defaultPatterns = {
|
|
40
|
+
selection: [
|
|
41
|
+
{ type: "pulse", duration: 8, intensity: 0.4 },
|
|
42
|
+
{ type: "gap", duration: 12 },
|
|
43
|
+
{ type: "pulse", duration: 10, intensity: 0.6 }
|
|
44
|
+
],
|
|
45
|
+
success: [
|
|
46
|
+
{ type: "pulse", duration: 15, intensity: 0.4 },
|
|
47
|
+
{ type: "gap", duration: 40 },
|
|
48
|
+
{ type: "pulse", duration: 25, intensity: 0.7 },
|
|
49
|
+
{ type: "gap", duration: 60 },
|
|
50
|
+
{ type: "pulse", duration: 35, intensity: 1 }
|
|
51
|
+
],
|
|
52
|
+
error: [
|
|
53
|
+
{ type: "pulse", duration: 30, intensity: 0.7 },
|
|
54
|
+
{ type: "gap", duration: 30 },
|
|
55
|
+
{ type: "pulse", duration: 30, intensity: 0.7 },
|
|
56
|
+
{ type: "gap", duration: 30 },
|
|
57
|
+
{ type: "pulse", duration: 35, intensity: 0.9 },
|
|
58
|
+
{ type: "gap", duration: 30 },
|
|
59
|
+
{ type: "pulse", duration: 40, intensity: 1 }
|
|
60
|
+
],
|
|
61
|
+
toggle: [
|
|
62
|
+
{ type: "pulse", duration: 12, intensity: 0.5 },
|
|
63
|
+
{ type: "gap", duration: 24 },
|
|
64
|
+
{ type: "pulse", duration: 18, intensity: 0.8 },
|
|
65
|
+
{ type: "gap", duration: 24 },
|
|
66
|
+
{ type: "pulse", duration: 12, intensity: 0.5 }
|
|
67
|
+
],
|
|
68
|
+
snap: [
|
|
69
|
+
{ type: "pulse", duration: 8, intensity: 0.3 },
|
|
70
|
+
{ type: "gap", duration: 8 },
|
|
71
|
+
{ type: "pulse", duration: 10, intensity: 0.5 },
|
|
72
|
+
{ type: "gap", duration: 8 },
|
|
73
|
+
{ type: "pulse", duration: 12, intensity: 0.7 },
|
|
74
|
+
{ type: "gap", duration: 8 },
|
|
75
|
+
{ type: "pulse", duration: 14, intensity: 0.9 },
|
|
76
|
+
{ type: "gap", duration: 8 },
|
|
77
|
+
{ type: "pulse", duration: 16, intensity: 1 }
|
|
78
|
+
]
|
|
79
|
+
};
|
|
80
|
+
for (const pattern of Object.values(defaultPatterns)) {
|
|
81
|
+
Object.freeze(pattern);
|
|
82
|
+
for (const block of pattern) {
|
|
83
|
+
Object.freeze(block);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
Object.freeze(defaultPatterns);
|
|
87
|
+
function clonePattern(pattern) {
|
|
88
|
+
return pattern.map((block) => ({ ...block }));
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// src/audio.ts
|
|
92
|
+
var CLICK_DURATION = 5e-3;
|
|
93
|
+
var CLICK_GAIN = 0.3;
|
|
94
|
+
var FILTER_FREQ = 2200;
|
|
95
|
+
var FILTER_Q = 3;
|
|
96
|
+
var engine = null;
|
|
97
|
+
function getAudioEngine() {
|
|
98
|
+
if (engine) return engine;
|
|
99
|
+
try {
|
|
100
|
+
let createClickBuffer2 = function() {
|
|
101
|
+
const buffer = ctx.createBuffer(1, bufferLength, ctx.sampleRate);
|
|
102
|
+
const data = buffer.getChannelData(0);
|
|
103
|
+
for (let i = 0; i < data.length; i++) {
|
|
104
|
+
const t = i / data.length;
|
|
105
|
+
const envelope = (1 - t) * (1 - t);
|
|
106
|
+
data[i] = (Math.random() * 2 - 1) * envelope;
|
|
107
|
+
}
|
|
108
|
+
return buffer;
|
|
109
|
+
}, playTap2 = function(startTime, intensity = 1) {
|
|
110
|
+
if (ctx.state === "suspended") {
|
|
111
|
+
ctx.resume().catch(() => void 0);
|
|
112
|
+
}
|
|
113
|
+
const level = Math.max(0, Math.min(1, intensity));
|
|
114
|
+
if (level === 0) return;
|
|
115
|
+
const buffer = createClickBuffer2();
|
|
116
|
+
const source = ctx.createBufferSource();
|
|
117
|
+
source.buffer = buffer;
|
|
118
|
+
const filter = ctx.createBiquadFilter();
|
|
119
|
+
filter.type = "lowpass";
|
|
120
|
+
filter.frequency.setValueAtTime(
|
|
121
|
+
FILTER_FREQ + (Math.random() - 0.5) * 400,
|
|
122
|
+
startTime
|
|
123
|
+
);
|
|
124
|
+
filter.Q.setValueAtTime(FILTER_Q, startTime);
|
|
125
|
+
const gain = ctx.createGain();
|
|
126
|
+
gain.gain.setValueAtTime(CLICK_GAIN * level, startTime);
|
|
127
|
+
source.connect(filter);
|
|
128
|
+
filter.connect(gain);
|
|
129
|
+
gain.connect(ctx.destination);
|
|
130
|
+
source.start(startTime);
|
|
131
|
+
source.stop(startTime + CLICK_DURATION);
|
|
132
|
+
};
|
|
133
|
+
var createClickBuffer = createClickBuffer2, playTap = playTap2;
|
|
134
|
+
const AC = globalThis.AudioContext ?? globalThis.webkitAudioContext;
|
|
135
|
+
if (!AC) return null;
|
|
136
|
+
const ctx = new AC();
|
|
137
|
+
const bufferLength = Math.ceil(CLICK_DURATION * ctx.sampleRate);
|
|
138
|
+
engine = { playTap: playTap2, context: ctx };
|
|
139
|
+
return engine;
|
|
140
|
+
} catch {
|
|
141
|
+
return null;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
function resetAudioEngine() {
|
|
145
|
+
if (engine) {
|
|
146
|
+
try {
|
|
147
|
+
engine.context.close().catch(() => {
|
|
148
|
+
});
|
|
149
|
+
} catch {
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
engine = null;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// src/safari-haptics.ts
|
|
156
|
+
var TAP_INTERVAL = 26;
|
|
157
|
+
var label = null;
|
|
158
|
+
function ensureDOM() {
|
|
159
|
+
if (label) return;
|
|
160
|
+
if (typeof document === "undefined") return;
|
|
161
|
+
label = document.createElement("label");
|
|
162
|
+
label.ariaHidden = "true";
|
|
163
|
+
Object.assign(label.style, {
|
|
164
|
+
position: "fixed",
|
|
165
|
+
left: "-9999px",
|
|
166
|
+
top: "-9999px",
|
|
167
|
+
opacity: "0.01",
|
|
168
|
+
pointerEvents: "none"
|
|
169
|
+
});
|
|
170
|
+
const input = document.createElement("input");
|
|
171
|
+
input.type = "checkbox";
|
|
172
|
+
input.setAttribute("switch", "");
|
|
173
|
+
input.ariaHidden = "true";
|
|
174
|
+
input.tabIndex = -1;
|
|
175
|
+
label.appendChild(input);
|
|
176
|
+
document.body.appendChild(label);
|
|
177
|
+
}
|
|
178
|
+
function triggerSafariHaptic() {
|
|
179
|
+
if (typeof document === "undefined") return;
|
|
180
|
+
ensureDOM();
|
|
181
|
+
label?.click();
|
|
182
|
+
}
|
|
183
|
+
var pendingTimers = [];
|
|
184
|
+
function playSafariPattern(pattern) {
|
|
185
|
+
for (const id of pendingTimers) clearTimeout(id);
|
|
186
|
+
pendingTimers = [];
|
|
187
|
+
let cursorMs = 0;
|
|
188
|
+
const pulseTimes = [];
|
|
189
|
+
for (const block of pattern) {
|
|
190
|
+
if (block.type === "pulse" && block.duration >= 5) {
|
|
191
|
+
pulseTimes.push(cursorMs);
|
|
192
|
+
}
|
|
193
|
+
cursorMs += block.duration;
|
|
194
|
+
}
|
|
195
|
+
if (pulseTimes.length === 0) return;
|
|
196
|
+
triggerSafariHaptic();
|
|
197
|
+
for (let i = 1; i < pulseTimes.length; i++) {
|
|
198
|
+
const delay = Math.max(pulseTimes[i] - pulseTimes[0], i * TAP_INTERVAL);
|
|
199
|
+
pendingTimers.push(setTimeout(() => triggerSafariHaptic(), delay));
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
function destroySafariHaptic() {
|
|
203
|
+
for (const id of pendingTimers) clearTimeout(id);
|
|
204
|
+
pendingTimers = [];
|
|
205
|
+
if (label?.parentNode) label.parentNode.removeChild(label);
|
|
206
|
+
label = null;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// src/playback.ts
|
|
210
|
+
var PWM_CYCLE = 20;
|
|
211
|
+
function modulateVibration(duration, intensity) {
|
|
212
|
+
if (intensity >= 1) return [duration];
|
|
213
|
+
if (intensity <= 0) return [];
|
|
214
|
+
if (duration <= PWM_CYCLE) return [duration];
|
|
215
|
+
const onTime = Math.max(1, Math.round(PWM_CYCLE * intensity));
|
|
216
|
+
const offTime = PWM_CYCLE - onTime;
|
|
217
|
+
const result = [];
|
|
218
|
+
let remaining = duration;
|
|
219
|
+
while (remaining >= PWM_CYCLE) {
|
|
220
|
+
result.push(onTime, offTime);
|
|
221
|
+
remaining -= PWM_CYCLE;
|
|
222
|
+
}
|
|
223
|
+
if (remaining > 0) {
|
|
224
|
+
const remainOn = Math.min(remaining, onTime);
|
|
225
|
+
result.push(remainOn);
|
|
226
|
+
const remainOff = remaining - remainOn;
|
|
227
|
+
if (remainOff > 0) {
|
|
228
|
+
result.push(remainOff);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
return result;
|
|
232
|
+
}
|
|
233
|
+
function toVibrationPattern(pattern) {
|
|
234
|
+
const result = [];
|
|
235
|
+
for (const block of pattern) {
|
|
236
|
+
if (block.type === "pulse") {
|
|
237
|
+
const intensity = block.intensity ?? 1;
|
|
238
|
+
const modulated = modulateVibration(block.duration, intensity);
|
|
239
|
+
if (modulated.length > 0) {
|
|
240
|
+
if (result.length > 0 && result.length % 2 === 1) {
|
|
241
|
+
result.push(0, ...modulated);
|
|
242
|
+
} else {
|
|
243
|
+
result.push(...modulated);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
} else if (block.type === "gap") {
|
|
247
|
+
if (result.length === 0) continue;
|
|
248
|
+
if (result.length % 2 === 0) {
|
|
249
|
+
result[result.length - 1] += block.duration;
|
|
250
|
+
} else {
|
|
251
|
+
result.push(block.duration);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
return result;
|
|
256
|
+
}
|
|
257
|
+
function playAudioClicks(pattern) {
|
|
258
|
+
const engine2 = getAudioEngine();
|
|
259
|
+
if (!engine2) return false;
|
|
260
|
+
const startTime = engine2.context.currentTime + 0.01;
|
|
261
|
+
let cursorMs = 0;
|
|
262
|
+
let scheduled = false;
|
|
263
|
+
for (const block of pattern) {
|
|
264
|
+
if (block.type === "pulse" && block.duration >= 5) {
|
|
265
|
+
engine2.playTap(startTime + cursorMs / 1e3, block.intensity ?? 1);
|
|
266
|
+
scheduled = true;
|
|
267
|
+
}
|
|
268
|
+
cursorMs += block.duration;
|
|
269
|
+
}
|
|
270
|
+
return scheduled;
|
|
271
|
+
}
|
|
272
|
+
function validatePattern(pattern) {
|
|
273
|
+
return pattern.map((b) => {
|
|
274
|
+
const duration = Math.max(0, Number.isFinite(b.duration) ? b.duration : 0);
|
|
275
|
+
if (b.type === "pulse") {
|
|
276
|
+
return {
|
|
277
|
+
type: "pulse",
|
|
278
|
+
duration,
|
|
279
|
+
intensity: b.intensity != null ? Math.max(0, Math.min(1, b.intensity)) : void 0
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
return { type: "gap", duration };
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
function playPattern(pattern, options) {
|
|
286
|
+
const capabilities = getCapabilityState();
|
|
287
|
+
if (capabilities.reducedMotion || options?.enabled === false) return { mode: "none" };
|
|
288
|
+
const validated = validatePattern(pattern);
|
|
289
|
+
const vibrationPattern = toVibrationPattern(validated);
|
|
290
|
+
if (capabilities.ios && validated.some((b) => b.type === "pulse" && b.duration >= 5)) {
|
|
291
|
+
playSafariPattern(validated);
|
|
292
|
+
try {
|
|
293
|
+
playAudioClicks(validated);
|
|
294
|
+
} catch {
|
|
295
|
+
}
|
|
296
|
+
return { mode: "haptics" };
|
|
297
|
+
}
|
|
298
|
+
if (vibrationPattern.length > 0 && capabilities.haptics && navigator.vibrate(vibrationPattern)) {
|
|
299
|
+
try {
|
|
300
|
+
playAudioClicks(validated);
|
|
301
|
+
} catch {
|
|
302
|
+
}
|
|
303
|
+
return { mode: "haptics" };
|
|
304
|
+
}
|
|
305
|
+
if (capabilities.audio) {
|
|
306
|
+
try {
|
|
307
|
+
const played = playAudioClicks(validated);
|
|
308
|
+
return { mode: played ? "audio" : "none" };
|
|
309
|
+
} catch {
|
|
310
|
+
return { mode: "none" };
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
return { mode: "none" };
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
// src/runtime.ts
|
|
317
|
+
function createRegistry(overrides) {
|
|
318
|
+
const registry = /* @__PURE__ */ new Map();
|
|
319
|
+
for (const [name, pattern] of Object.entries(defaultPatterns)) {
|
|
320
|
+
registry.set(name, clonePattern(pattern));
|
|
321
|
+
}
|
|
322
|
+
if (overrides) {
|
|
323
|
+
for (const [name, pattern] of Object.entries(overrides)) {
|
|
324
|
+
registry.set(name, clonePattern(pattern));
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
return registry;
|
|
328
|
+
}
|
|
329
|
+
function resolvePattern(registry, nameOrPattern) {
|
|
330
|
+
if (typeof nameOrPattern !== "string") {
|
|
331
|
+
return clonePattern(nameOrPattern);
|
|
332
|
+
}
|
|
333
|
+
const pattern = registry.get(nameOrPattern);
|
|
334
|
+
if (!pattern) {
|
|
335
|
+
throw new Error(`Unknown haptics pattern: ${nameOrPattern}`);
|
|
336
|
+
}
|
|
337
|
+
return clonePattern(pattern);
|
|
338
|
+
}
|
|
339
|
+
var singletonEnabled = true;
|
|
340
|
+
function playNamedPattern(name) {
|
|
341
|
+
return playPattern(clonePattern(defaultPatterns[name]), { enabled: singletonEnabled });
|
|
342
|
+
}
|
|
343
|
+
var haptics = {
|
|
344
|
+
selection: () => playNamedPattern("selection"),
|
|
345
|
+
success: () => playNamedPattern("success"),
|
|
346
|
+
error: () => playNamedPattern("error"),
|
|
347
|
+
toggle: () => playNamedPattern("toggle"),
|
|
348
|
+
snap: () => playNamedPattern("snap"),
|
|
349
|
+
play: (pattern) => playPattern(clonePattern(pattern), { enabled: singletonEnabled }),
|
|
350
|
+
getCapabilities: () => getCapabilityState(),
|
|
351
|
+
setEnabled: (enabled) => {
|
|
352
|
+
singletonEnabled = enabled;
|
|
353
|
+
},
|
|
354
|
+
isEnabled: () => singletonEnabled,
|
|
355
|
+
dispose: () => {
|
|
356
|
+
resetAudioEngine();
|
|
357
|
+
destroySafariHaptic();
|
|
358
|
+
}
|
|
359
|
+
};
|
|
360
|
+
function createHaptics(options = {}) {
|
|
361
|
+
const registry = createRegistry(options.patterns);
|
|
362
|
+
let enabled = true;
|
|
363
|
+
return {
|
|
364
|
+
play: (nameOrPattern) => playPattern(resolvePattern(registry, nameOrPattern), { enabled }),
|
|
365
|
+
register: (name, pattern) => {
|
|
366
|
+
registry.set(name, clonePattern(pattern));
|
|
367
|
+
},
|
|
368
|
+
getCapabilities: () => getCapabilityState(),
|
|
369
|
+
setEnabled: (value) => {
|
|
370
|
+
enabled = value;
|
|
371
|
+
},
|
|
372
|
+
isEnabled: () => enabled,
|
|
373
|
+
dispose: () => {
|
|
374
|
+
resetAudioEngine();
|
|
375
|
+
destroySafariHaptic();
|
|
376
|
+
}
|
|
377
|
+
};
|
|
378
|
+
}
|
|
379
|
+
function dispose() {
|
|
380
|
+
resetAudioEngine();
|
|
381
|
+
destroySafariHaptic();
|
|
382
|
+
}
|
|
383
|
+
function setEnabled(enabled) {
|
|
384
|
+
haptics.setEnabled(enabled);
|
|
385
|
+
}
|
|
386
|
+
function isEnabled() {
|
|
387
|
+
return haptics.isEnabled();
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
export {
|
|
391
|
+
getCapabilityState,
|
|
392
|
+
defaultPatterns,
|
|
393
|
+
haptics,
|
|
394
|
+
createHaptics,
|
|
395
|
+
dispose,
|
|
396
|
+
setEnabled,
|
|
397
|
+
isEnabled
|
|
398
|
+
};
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { C as CapabilityState, a as CreateHapticsOptions, H as HapticsInstance, b as HapticsApi } from './types-BRn0rP4m.mjs';
|
|
2
|
+
export { G as GapBlock, N as NamedPattern, P as PatternBlock, c as PatternRegistry, d as PlaybackMode, e as PlaybackResult, f as PulseBlock } from './types-BRn0rP4m.mjs';
|
|
3
|
+
|
|
4
|
+
declare function getCapabilityState(): CapabilityState;
|
|
5
|
+
|
|
6
|
+
declare const defaultPatterns: {
|
|
7
|
+
readonly selection: readonly [{
|
|
8
|
+
readonly type: "pulse";
|
|
9
|
+
readonly duration: 8;
|
|
10
|
+
readonly intensity: 0.4;
|
|
11
|
+
}, {
|
|
12
|
+
readonly type: "gap";
|
|
13
|
+
readonly duration: 12;
|
|
14
|
+
}, {
|
|
15
|
+
readonly type: "pulse";
|
|
16
|
+
readonly duration: 10;
|
|
17
|
+
readonly intensity: 0.6;
|
|
18
|
+
}];
|
|
19
|
+
readonly success: readonly [{
|
|
20
|
+
readonly type: "pulse";
|
|
21
|
+
readonly duration: 15;
|
|
22
|
+
readonly intensity: 0.4;
|
|
23
|
+
}, {
|
|
24
|
+
readonly type: "gap";
|
|
25
|
+
readonly duration: 40;
|
|
26
|
+
}, {
|
|
27
|
+
readonly type: "pulse";
|
|
28
|
+
readonly duration: 25;
|
|
29
|
+
readonly intensity: 0.7;
|
|
30
|
+
}, {
|
|
31
|
+
readonly type: "gap";
|
|
32
|
+
readonly duration: 60;
|
|
33
|
+
}, {
|
|
34
|
+
readonly type: "pulse";
|
|
35
|
+
readonly duration: 35;
|
|
36
|
+
readonly intensity: 1;
|
|
37
|
+
}];
|
|
38
|
+
readonly error: readonly [{
|
|
39
|
+
readonly type: "pulse";
|
|
40
|
+
readonly duration: 30;
|
|
41
|
+
readonly intensity: 0.7;
|
|
42
|
+
}, {
|
|
43
|
+
readonly type: "gap";
|
|
44
|
+
readonly duration: 30;
|
|
45
|
+
}, {
|
|
46
|
+
readonly type: "pulse";
|
|
47
|
+
readonly duration: 30;
|
|
48
|
+
readonly intensity: 0.7;
|
|
49
|
+
}, {
|
|
50
|
+
readonly type: "gap";
|
|
51
|
+
readonly duration: 30;
|
|
52
|
+
}, {
|
|
53
|
+
readonly type: "pulse";
|
|
54
|
+
readonly duration: 35;
|
|
55
|
+
readonly intensity: 0.9;
|
|
56
|
+
}, {
|
|
57
|
+
readonly type: "gap";
|
|
58
|
+
readonly duration: 30;
|
|
59
|
+
}, {
|
|
60
|
+
readonly type: "pulse";
|
|
61
|
+
readonly duration: 40;
|
|
62
|
+
readonly intensity: 1;
|
|
63
|
+
}];
|
|
64
|
+
readonly toggle: readonly [{
|
|
65
|
+
readonly type: "pulse";
|
|
66
|
+
readonly duration: 12;
|
|
67
|
+
readonly intensity: 0.5;
|
|
68
|
+
}, {
|
|
69
|
+
readonly type: "gap";
|
|
70
|
+
readonly duration: 24;
|
|
71
|
+
}, {
|
|
72
|
+
readonly type: "pulse";
|
|
73
|
+
readonly duration: 18;
|
|
74
|
+
readonly intensity: 0.8;
|
|
75
|
+
}, {
|
|
76
|
+
readonly type: "gap";
|
|
77
|
+
readonly duration: 24;
|
|
78
|
+
}, {
|
|
79
|
+
readonly type: "pulse";
|
|
80
|
+
readonly duration: 12;
|
|
81
|
+
readonly intensity: 0.5;
|
|
82
|
+
}];
|
|
83
|
+
readonly snap: readonly [{
|
|
84
|
+
readonly type: "pulse";
|
|
85
|
+
readonly duration: 8;
|
|
86
|
+
readonly intensity: 0.3;
|
|
87
|
+
}, {
|
|
88
|
+
readonly type: "gap";
|
|
89
|
+
readonly duration: 8;
|
|
90
|
+
}, {
|
|
91
|
+
readonly type: "pulse";
|
|
92
|
+
readonly duration: 10;
|
|
93
|
+
readonly intensity: 0.5;
|
|
94
|
+
}, {
|
|
95
|
+
readonly type: "gap";
|
|
96
|
+
readonly duration: 8;
|
|
97
|
+
}, {
|
|
98
|
+
readonly type: "pulse";
|
|
99
|
+
readonly duration: 12;
|
|
100
|
+
readonly intensity: 0.7;
|
|
101
|
+
}, {
|
|
102
|
+
readonly type: "gap";
|
|
103
|
+
readonly duration: 8;
|
|
104
|
+
}, {
|
|
105
|
+
readonly type: "pulse";
|
|
106
|
+
readonly duration: 14;
|
|
107
|
+
readonly intensity: 0.9;
|
|
108
|
+
}, {
|
|
109
|
+
readonly type: "gap";
|
|
110
|
+
readonly duration: 8;
|
|
111
|
+
}, {
|
|
112
|
+
readonly type: "pulse";
|
|
113
|
+
readonly duration: 16;
|
|
114
|
+
readonly intensity: 1;
|
|
115
|
+
}];
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
declare const haptics: HapticsApi;
|
|
119
|
+
declare function createHaptics(options?: CreateHapticsOptions): HapticsInstance;
|
|
120
|
+
declare function dispose(): void;
|
|
121
|
+
declare function setEnabled(enabled: boolean): void;
|
|
122
|
+
declare function isEnabled(): boolean;
|
|
123
|
+
|
|
124
|
+
export { CapabilityState, CreateHapticsOptions, HapticsApi, HapticsInstance, createHaptics, defaultPatterns, dispose, getCapabilityState as getCapabilities, haptics, isEnabled, setEnabled };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { C as CapabilityState, a as CreateHapticsOptions, H as HapticsInstance, b as HapticsApi } from './types-BRn0rP4m.js';
|
|
2
|
+
export { G as GapBlock, N as NamedPattern, P as PatternBlock, c as PatternRegistry, d as PlaybackMode, e as PlaybackResult, f as PulseBlock } from './types-BRn0rP4m.js';
|
|
3
|
+
|
|
4
|
+
declare function getCapabilityState(): CapabilityState;
|
|
5
|
+
|
|
6
|
+
declare const defaultPatterns: {
|
|
7
|
+
readonly selection: readonly [{
|
|
8
|
+
readonly type: "pulse";
|
|
9
|
+
readonly duration: 8;
|
|
10
|
+
readonly intensity: 0.4;
|
|
11
|
+
}, {
|
|
12
|
+
readonly type: "gap";
|
|
13
|
+
readonly duration: 12;
|
|
14
|
+
}, {
|
|
15
|
+
readonly type: "pulse";
|
|
16
|
+
readonly duration: 10;
|
|
17
|
+
readonly intensity: 0.6;
|
|
18
|
+
}];
|
|
19
|
+
readonly success: readonly [{
|
|
20
|
+
readonly type: "pulse";
|
|
21
|
+
readonly duration: 15;
|
|
22
|
+
readonly intensity: 0.4;
|
|
23
|
+
}, {
|
|
24
|
+
readonly type: "gap";
|
|
25
|
+
readonly duration: 40;
|
|
26
|
+
}, {
|
|
27
|
+
readonly type: "pulse";
|
|
28
|
+
readonly duration: 25;
|
|
29
|
+
readonly intensity: 0.7;
|
|
30
|
+
}, {
|
|
31
|
+
readonly type: "gap";
|
|
32
|
+
readonly duration: 60;
|
|
33
|
+
}, {
|
|
34
|
+
readonly type: "pulse";
|
|
35
|
+
readonly duration: 35;
|
|
36
|
+
readonly intensity: 1;
|
|
37
|
+
}];
|
|
38
|
+
readonly error: readonly [{
|
|
39
|
+
readonly type: "pulse";
|
|
40
|
+
readonly duration: 30;
|
|
41
|
+
readonly intensity: 0.7;
|
|
42
|
+
}, {
|
|
43
|
+
readonly type: "gap";
|
|
44
|
+
readonly duration: 30;
|
|
45
|
+
}, {
|
|
46
|
+
readonly type: "pulse";
|
|
47
|
+
readonly duration: 30;
|
|
48
|
+
readonly intensity: 0.7;
|
|
49
|
+
}, {
|
|
50
|
+
readonly type: "gap";
|
|
51
|
+
readonly duration: 30;
|
|
52
|
+
}, {
|
|
53
|
+
readonly type: "pulse";
|
|
54
|
+
readonly duration: 35;
|
|
55
|
+
readonly intensity: 0.9;
|
|
56
|
+
}, {
|
|
57
|
+
readonly type: "gap";
|
|
58
|
+
readonly duration: 30;
|
|
59
|
+
}, {
|
|
60
|
+
readonly type: "pulse";
|
|
61
|
+
readonly duration: 40;
|
|
62
|
+
readonly intensity: 1;
|
|
63
|
+
}];
|
|
64
|
+
readonly toggle: readonly [{
|
|
65
|
+
readonly type: "pulse";
|
|
66
|
+
readonly duration: 12;
|
|
67
|
+
readonly intensity: 0.5;
|
|
68
|
+
}, {
|
|
69
|
+
readonly type: "gap";
|
|
70
|
+
readonly duration: 24;
|
|
71
|
+
}, {
|
|
72
|
+
readonly type: "pulse";
|
|
73
|
+
readonly duration: 18;
|
|
74
|
+
readonly intensity: 0.8;
|
|
75
|
+
}, {
|
|
76
|
+
readonly type: "gap";
|
|
77
|
+
readonly duration: 24;
|
|
78
|
+
}, {
|
|
79
|
+
readonly type: "pulse";
|
|
80
|
+
readonly duration: 12;
|
|
81
|
+
readonly intensity: 0.5;
|
|
82
|
+
}];
|
|
83
|
+
readonly snap: readonly [{
|
|
84
|
+
readonly type: "pulse";
|
|
85
|
+
readonly duration: 8;
|
|
86
|
+
readonly intensity: 0.3;
|
|
87
|
+
}, {
|
|
88
|
+
readonly type: "gap";
|
|
89
|
+
readonly duration: 8;
|
|
90
|
+
}, {
|
|
91
|
+
readonly type: "pulse";
|
|
92
|
+
readonly duration: 10;
|
|
93
|
+
readonly intensity: 0.5;
|
|
94
|
+
}, {
|
|
95
|
+
readonly type: "gap";
|
|
96
|
+
readonly duration: 8;
|
|
97
|
+
}, {
|
|
98
|
+
readonly type: "pulse";
|
|
99
|
+
readonly duration: 12;
|
|
100
|
+
readonly intensity: 0.7;
|
|
101
|
+
}, {
|
|
102
|
+
readonly type: "gap";
|
|
103
|
+
readonly duration: 8;
|
|
104
|
+
}, {
|
|
105
|
+
readonly type: "pulse";
|
|
106
|
+
readonly duration: 14;
|
|
107
|
+
readonly intensity: 0.9;
|
|
108
|
+
}, {
|
|
109
|
+
readonly type: "gap";
|
|
110
|
+
readonly duration: 8;
|
|
111
|
+
}, {
|
|
112
|
+
readonly type: "pulse";
|
|
113
|
+
readonly duration: 16;
|
|
114
|
+
readonly intensity: 1;
|
|
115
|
+
}];
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
declare const haptics: HapticsApi;
|
|
119
|
+
declare function createHaptics(options?: CreateHapticsOptions): HapticsInstance;
|
|
120
|
+
declare function dispose(): void;
|
|
121
|
+
declare function setEnabled(enabled: boolean): void;
|
|
122
|
+
declare function isEnabled(): boolean;
|
|
123
|
+
|
|
124
|
+
export { CapabilityState, CreateHapticsOptions, HapticsApi, HapticsInstance, createHaptics, defaultPatterns, dispose, getCapabilityState as getCapabilities, haptics, isEnabled, setEnabled };
|