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 CHANGED
@@ -3,11 +3,11 @@
3
3
  javascript library for haptic feedback inside of safari on ios
4
4
 
5
5
  ![GitHub last commit](https://img.shields.io/github/last-commit/tijnjh/ios-haptics)
6
- [![npm version](https://img.shields.io/npm/v/tsuite.svg)](https://npmjs.com/package/ios-haptics)
6
+ [![npm version](https://img.shields.io/npm/v/ios-haptics.svg)](https://npmjs.com/package/ios-haptics)
7
7
  ![NPM Downloads](https://img.shields.io/npm/dm/ios-haptics)
8
8
  ![npm package minimized gzipped size](https://img.shields.io/bundlejs/size/ios-haptics)
9
9
 
10
- demo: [ios-haptics demo](https://wg.tijn.dev?h=s0kqLSnJz1PITLFVykgsKMlMVrKD0Db6ECk7Lkw1zvl5aZlFuTClCskQPj4trkVF%7EUVwDakgHlw5AA&c=UwAA&j=hYwxDsIwDEX3nMLKBAPJTsQC6sAxUJqSiDqObDMgxN1RlY6Vun3pv_cKNmKFL%7ERH0xLhBxMTgs2qTc7eJ0En2ReSUyfEBmNGim9MVd0z6TCnZV4_9_FgO2OPjmqcS3zBZQ2HPedGdSqMG6qL_dpNDMzEW4G0HMH8AQ)
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 (good for confirmation)
26
+ // two rapid haptics
27
27
  haptic.confirm()
28
28
 
29
- // three rapid haptics (useful for errors)
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 (which has haptic feedback), then remove 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
- * ios-haptics v0.0.9
3
- * tijn.dev
4
- * @license MIT
5
- */
6
- declare function haptic(): void;
7
- declare namespace haptic {
8
- var confirm: () => void;
9
- var error: () => void;
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
- export { haptic };
28
+ declare const h: Haptic;
29
+ //#endregion
30
+ export { h as haptic };
package/dist/index.js CHANGED
@@ -1,33 +1,55 @@
1
1
  /**
2
- * ios-haptics v0.0.9
3
- * tijn.dev
4
- * @license MIT
5
- */
2
+ * ios-haptics v0.1.1
3
+ * tijn.dev
4
+ * @license MIT
5
+ **/
6
+ //#region src/index.ts
6
7
  function haptic() {
7
- try {
8
- const labelEl = document.createElement('label');
9
- labelEl.ariaHidden = 'true';
10
- labelEl.style.display = 'none';
11
- const inputEl = document.createElement('input');
12
- inputEl.type = 'checkbox';
13
- inputEl.setAttribute('switch', '');
14
- labelEl.appendChild(inputEl);
15
- document.head.appendChild(labelEl);
16
- labelEl.click();
17
- document.head.removeChild(labelEl);
18
- }
19
- catch {
20
- // do nothing
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
- haptic();
26
- setTimeout(() => haptic(), 120);
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
- haptic();
30
- setTimeout(() => haptic(), 120);
31
- setTimeout(() => haptic(), 240);
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
- export { haptic };
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.0.9",
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.cts",
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.cjs",
24
+ "main": "./dist/index.js",
26
25
  "module": "./dist/index.js",
27
- "types": "./dist/index.d.cts",
26
+ "types": "./dist/index.d.ts",
28
27
  "files": [
29
28
  "dist"
30
29
  ],
31
- "devDependencies": {
32
- "@antfu/eslint-config": "^4.16.2",
33
- "eslint": "^9.31.0",
34
- "typescript": "^5.8.3",
35
- "zshy": "^0.2.3"
30
+ "scripts": {
31
+ "build": "tsdown",
32
+ "dev": "tsdown --watch"
36
33
  },
37
- "zshy": "./src/index.ts"
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
- };
package/dist/index.d.cts DELETED
@@ -1,11 +0,0 @@
1
- /**
2
- * ios-haptics v0.0.9
3
- * tijn.dev
4
- * @license MIT
5
- */
6
- declare function haptic(): void;
7
- declare namespace haptic {
8
- var confirm: () => void;
9
- var error: () => void;
10
- }
11
- export { haptic };