ios-haptics 0.1.0 → 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 +4 -2
- package/dist/index.d.ts +29 -10
- package/dist/index.js +48 -38
- package/package.json +14 -13
- package/dist/index.cjs +0 -47
- package/dist/index.d.cts +0 -11
package/README.md
CHANGED
|
@@ -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
|
|
|
@@ -36,6 +36,8 @@ this uses the `<input type="checkbox" switch />` (introduced in safari 17.4), wh
|
|
|
36
36
|
|
|
37
37
|
every `haptic` call, it will create one of those in the background, toggle it, then remove it
|
|
38
38
|
|
|
39
|
+
on devices that support it, `navigator.vibrate()` is called instead, so it works on android too
|
|
40
|
+
|
|
39
41
|
---
|
|
40
42
|
|
|
41
43
|
Feel free to send a PR or open an issue if you have suggestions or find
|
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,45 +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
|
-
|
|
22
|
-
|
|
23
|
-
catch {
|
|
24
|
-
// do nothing
|
|
25
|
-
}
|
|
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 {}
|
|
26
24
|
}
|
|
27
|
-
;
|
|
28
25
|
haptic.confirm = () => {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
26
|
+
if (navigator.vibrate) {
|
|
27
|
+
navigator.vibrate([
|
|
28
|
+
50,
|
|
29
|
+
70,
|
|
30
|
+
50
|
|
31
|
+
]);
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
haptic();
|
|
35
|
+
setTimeout(() => haptic(), 120);
|
|
35
36
|
};
|
|
36
37
|
haptic.error = () => {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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);
|
|
44
51
|
};
|
|
45
|
-
|
|
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.1.
|
|
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.9.2",
|
|
35
|
-
"zshy": "^0.3.4"
|
|
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,47 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* ios-haptics v0.1.0
|
|
4
|
-
* tijn.dev
|
|
5
|
-
* @license MIT
|
|
6
|
-
*/
|
|
7
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
-
exports.haptic = haptic;
|
|
9
|
-
function haptic() {
|
|
10
|
-
try {
|
|
11
|
-
if (navigator.vibrate) {
|
|
12
|
-
navigator.vibrate(50);
|
|
13
|
-
return;
|
|
14
|
-
}
|
|
15
|
-
const labelEl = document.createElement('label');
|
|
16
|
-
labelEl.ariaHidden = 'true';
|
|
17
|
-
labelEl.style.display = 'none';
|
|
18
|
-
const inputEl = document.createElement('input');
|
|
19
|
-
inputEl.type = 'checkbox';
|
|
20
|
-
inputEl.setAttribute('switch', '');
|
|
21
|
-
labelEl.appendChild(inputEl);
|
|
22
|
-
document.head.appendChild(labelEl);
|
|
23
|
-
labelEl.click();
|
|
24
|
-
document.head.removeChild(labelEl);
|
|
25
|
-
}
|
|
26
|
-
catch {
|
|
27
|
-
// do nothing
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
;
|
|
31
|
-
haptic.confirm = () => {
|
|
32
|
-
if (navigator.vibrate) {
|
|
33
|
-
navigator.vibrate([50, 70, 50]);
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
haptic();
|
|
37
|
-
setTimeout(() => haptic(), 120);
|
|
38
|
-
};
|
|
39
|
-
haptic.error = () => {
|
|
40
|
-
if (navigator.vibrate) {
|
|
41
|
-
navigator.vibrate([50, 70, 50, 70, 50]);
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
haptic();
|
|
45
|
-
setTimeout(() => haptic(), 120);
|
|
46
|
-
setTimeout(() => haptic(), 240);
|
|
47
|
-
};
|