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 CHANGED
@@ -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
 
@@ -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
- * ios-haptics v0.1.0
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,45 +1,55 @@
1
1
  /**
2
- * ios-haptics v0.1.0
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
- if (navigator.vibrate) {
9
- navigator.vibrate(50);
10
- return;
11
- }
12
- const labelEl = document.createElement('label');
13
- labelEl.ariaHidden = 'true';
14
- labelEl.style.display = 'none';
15
- const inputEl = document.createElement('input');
16
- inputEl.type = 'checkbox';
17
- inputEl.setAttribute('switch', '');
18
- labelEl.appendChild(inputEl);
19
- document.head.appendChild(labelEl);
20
- labelEl.click();
21
- document.head.removeChild(labelEl);
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
- if (navigator.vibrate) {
30
- navigator.vibrate([50, 70, 50]);
31
- return;
32
- }
33
- haptic();
34
- 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);
35
36
  };
36
37
  haptic.error = () => {
37
- if (navigator.vibrate) {
38
- navigator.vibrate([50, 70, 50, 70, 50]);
39
- return;
40
- }
41
- haptic();
42
- setTimeout(() => haptic(), 120);
43
- 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);
44
51
  };
45
- 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.1.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.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": "^5.1.0",
33
- "eslint": "^9.32.0",
34
- "typescript": "^5.9.2",
35
- "zshy": "^0.3.4"
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,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
- };
package/dist/index.d.cts DELETED
@@ -1,11 +0,0 @@
1
- /**
2
- * ios-haptics v0.1.0
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 };