ios-haptics 0.0.9 → 0.1.1
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 +7 -5
- package/dist/index.d.ts +29 -10
- package/dist/index.js +48 -26
- package/package.json +14 -13
- package/dist/index.cjs +0 -35
- package/dist/index.d.cts +0 -11
package/README.md
CHANGED
|
@@ -3,11 +3,11 @@
|
|
|
3
3
|
javascript library for haptic feedback inside of safari on ios
|
|
4
4
|
|
|
5
5
|

|
|
6
|
-
[](https://npmjs.com/package/ios-haptics)
|
|
7
7
|

|
|
8
8
|

|
|
9
9
|
|
|
10
|
-
demo: [ios-haptics demo](https://
|
|
10
|
+
demo: [ios-haptics demo](https://codepen.io/tijnjh/pen/KwpgPqB)
|
|
11
11
|
|
|
12
12
|
## installation
|
|
13
13
|
|
|
@@ -23,10 +23,10 @@ import { haptic } from 'ios-haptics'
|
|
|
23
23
|
// a single haptic
|
|
24
24
|
haptic()
|
|
25
25
|
|
|
26
|
-
// two rapid haptics
|
|
26
|
+
// two rapid haptics
|
|
27
27
|
haptic.confirm()
|
|
28
28
|
|
|
29
|
-
// three rapid haptics
|
|
29
|
+
// three rapid haptics
|
|
30
30
|
haptic.error()
|
|
31
31
|
```
|
|
32
32
|
|
|
@@ -34,7 +34,9 @@ haptic.error()
|
|
|
34
34
|
|
|
35
35
|
this uses the `<input type="checkbox" switch />` (introduced in safari 17.4), which has haptic feedback when toggled
|
|
36
36
|
|
|
37
|
-
every `haptic` call, it will create one of those in the background, toggle it
|
|
37
|
+
every `haptic` call, it will create one of those in the background, toggle it, then remove it
|
|
38
|
+
|
|
39
|
+
on devices that support it, `navigator.vibrate()` is called instead, so it works on android too
|
|
38
40
|
|
|
39
41
|
---
|
|
40
42
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
//#region src/index.d.ts
|
|
2
|
+
declare interface Haptic {
|
|
3
|
+
/** @deprecated */
|
|
4
|
+
apply: never;
|
|
5
|
+
/** @deprecated */
|
|
6
|
+
arguments: never;
|
|
7
|
+
/** @deprecated */
|
|
8
|
+
bind: never;
|
|
9
|
+
/** @deprecated */
|
|
10
|
+
call: never;
|
|
11
|
+
/** @deprecated */
|
|
12
|
+
caller: never;
|
|
13
|
+
/** @deprecated */
|
|
14
|
+
length: never;
|
|
15
|
+
/** @deprecated */
|
|
16
|
+
name: never;
|
|
17
|
+
/** @deprecated */
|
|
18
|
+
prototype: never;
|
|
19
|
+
/** @deprecated */
|
|
20
|
+
toString: never;
|
|
21
|
+
/** a single haptic */
|
|
22
|
+
(): void;
|
|
23
|
+
/** two rapid haptics */
|
|
24
|
+
confirm: () => void;
|
|
25
|
+
/** three rapid haptics */
|
|
26
|
+
error: () => void;
|
|
10
27
|
}
|
|
11
|
-
|
|
28
|
+
declare const h: Haptic;
|
|
29
|
+
//#endregion
|
|
30
|
+
export { h as haptic };
|
package/dist/index.js
CHANGED
|
@@ -1,33 +1,55 @@
|
|
|
1
1
|
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
* ios-haptics v0.1.1
|
|
3
|
+
* tijn.dev
|
|
4
|
+
* @license MIT
|
|
5
|
+
**/
|
|
6
|
+
//#region src/index.ts
|
|
6
7
|
function haptic() {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
8
|
+
try {
|
|
9
|
+
if (navigator.vibrate) {
|
|
10
|
+
navigator.vibrate(50);
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
const labelEl = document.createElement("label");
|
|
14
|
+
labelEl.ariaHidden = "true";
|
|
15
|
+
labelEl.style.display = "none";
|
|
16
|
+
const inputEl = document.createElement("input");
|
|
17
|
+
inputEl.type = "checkbox";
|
|
18
|
+
inputEl.setAttribute("switch", "");
|
|
19
|
+
labelEl.appendChild(inputEl);
|
|
20
|
+
document.head.appendChild(labelEl);
|
|
21
|
+
labelEl.click();
|
|
22
|
+
document.head.removeChild(labelEl);
|
|
23
|
+
} catch {}
|
|
22
24
|
}
|
|
23
|
-
;
|
|
24
25
|
haptic.confirm = () => {
|
|
25
|
-
|
|
26
|
-
|
|
26
|
+
if (navigator.vibrate) {
|
|
27
|
+
navigator.vibrate([
|
|
28
|
+
50,
|
|
29
|
+
70,
|
|
30
|
+
50
|
|
31
|
+
]);
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
haptic();
|
|
35
|
+
setTimeout(() => haptic(), 120);
|
|
27
36
|
};
|
|
28
37
|
haptic.error = () => {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
38
|
+
if (navigator.vibrate) {
|
|
39
|
+
navigator.vibrate([
|
|
40
|
+
50,
|
|
41
|
+
70,
|
|
42
|
+
50,
|
|
43
|
+
70,
|
|
44
|
+
50
|
|
45
|
+
]);
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
haptic();
|
|
49
|
+
setTimeout(() => haptic(), 120);
|
|
50
|
+
setTimeout(() => haptic(), 240);
|
|
32
51
|
};
|
|
33
|
-
|
|
52
|
+
const h = haptic;
|
|
53
|
+
|
|
54
|
+
//#endregion
|
|
55
|
+
export { h as haptic };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ios-haptics",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.1.1",
|
|
5
5
|
"description": "haptic feedback for ios safari",
|
|
6
6
|
"author": "tijnjh",
|
|
7
7
|
"license": "MIT",
|
|
@@ -17,22 +17,23 @@
|
|
|
17
17
|
],
|
|
18
18
|
"exports": {
|
|
19
19
|
".": {
|
|
20
|
-
"types": "./dist/index.d.
|
|
21
|
-
"import": "./dist/index.js"
|
|
22
|
-
"require": "./dist/index.cjs"
|
|
20
|
+
"types": "./dist/index.d.ts",
|
|
21
|
+
"import": "./dist/index.js"
|
|
23
22
|
}
|
|
24
23
|
},
|
|
25
|
-
"main": "./dist/index.
|
|
24
|
+
"main": "./dist/index.js",
|
|
26
25
|
"module": "./dist/index.js",
|
|
27
|
-
"types": "./dist/index.d.
|
|
26
|
+
"types": "./dist/index.d.ts",
|
|
28
27
|
"files": [
|
|
29
28
|
"dist"
|
|
30
29
|
],
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
"typescript": "^5.8.3",
|
|
35
|
-
"zshy": "^0.2.3"
|
|
30
|
+
"scripts": {
|
|
31
|
+
"build": "tsdown",
|
|
32
|
+
"dev": "tsdown --watch"
|
|
36
33
|
},
|
|
37
|
-
"
|
|
38
|
-
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"tsdown": "latest",
|
|
36
|
+
"@antfu/eslint-config": "^5.3.0",
|
|
37
|
+
"eslint": "^9.35.0"
|
|
38
|
+
}
|
|
39
|
+
}
|
package/dist/index.cjs
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* ios-haptics v0.0.9
|
|
4
|
-
* tijn.dev
|
|
5
|
-
* @license MIT
|
|
6
|
-
*/
|
|
7
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
-
exports.haptic = haptic;
|
|
9
|
-
function haptic() {
|
|
10
|
-
try {
|
|
11
|
-
const labelEl = document.createElement('label');
|
|
12
|
-
labelEl.ariaHidden = 'true';
|
|
13
|
-
labelEl.style.display = 'none';
|
|
14
|
-
const inputEl = document.createElement('input');
|
|
15
|
-
inputEl.type = 'checkbox';
|
|
16
|
-
inputEl.setAttribute('switch', '');
|
|
17
|
-
labelEl.appendChild(inputEl);
|
|
18
|
-
document.head.appendChild(labelEl);
|
|
19
|
-
labelEl.click();
|
|
20
|
-
document.head.removeChild(labelEl);
|
|
21
|
-
}
|
|
22
|
-
catch {
|
|
23
|
-
// do nothing
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
;
|
|
27
|
-
haptic.confirm = () => {
|
|
28
|
-
haptic();
|
|
29
|
-
setTimeout(() => haptic(), 120);
|
|
30
|
-
};
|
|
31
|
-
haptic.error = () => {
|
|
32
|
-
haptic();
|
|
33
|
-
setTimeout(() => haptic(), 120);
|
|
34
|
-
setTimeout(() => haptic(), 240);
|
|
35
|
-
};
|