ios-haptics 0.1.0 → 0.1.2

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
@@ -1,4 +1,4 @@
1
- # ios-haptics
1
+ # 📳 ios-haptics
2
2
 
3
3
  javascript library for haptic feedback inside of safari on ios
4
4
 
@@ -9,13 +9,13 @@ javascript library for haptic feedback inside of safari on ios
9
9
 
10
10
  demo: [ios-haptics demo](https://codepen.io/tijnjh/pen/KwpgPqB)
11
11
 
12
- ## installation
12
+ ## 📦 installation
13
13
 
14
14
  ```sh
15
15
  npm i ios-haptics
16
16
  ```
17
17
 
18
- ## usage
18
+ ## 🚀 usage
19
19
 
20
20
  ```javascript
21
21
  import { haptic } from 'ios-haptics'
@@ -23,20 +23,22 @@ 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
 
33
- ## how it works
33
+ ## ⚙️ how it works
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
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
- Feel free to send a PR or open an issue if you have suggestions or find
42
- improvements.
43
+ feel free to send a pr or open an issue if you have suggestions or find
44
+ improvements
package/dist/index.d.ts CHANGED
@@ -1,11 +1,32 @@
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
+ 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
+ /** @deprecated */
22
+ Symbol: never;
23
+ /** a single haptic */
24
+ (): void;
25
+ /** two rapid haptics */
26
+ confirm: () => void;
27
+ /** three rapid haptics */
28
+ error: () => void;
10
29
  }
11
- export { haptic };
30
+ declare const __haptic: haptic;
31
+ //#endregion
32
+ export { __haptic 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
- */
6
- 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
- }
2
+ * ios-haptics v0.1.2
3
+ * tijn.dev
4
+ * @license MIT
5
+ **/
6
+ //#region src/index.ts
7
+ function _haptic() {
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
- haptic.confirm = () => {
29
- if (navigator.vibrate) {
30
- navigator.vibrate([50, 70, 50]);
31
- return;
32
- }
33
- haptic();
34
- setTimeout(() => haptic(), 120);
25
+ _haptic.confirm = () => {
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
- 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);
37
+ _haptic.error = () => {
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 __haptic = _haptic;
53
+
54
+ //#endregion
55
+ export { __haptic 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.2",
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 };