ios-haptics 0.1.5 → 2.0.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
@@ -2,8 +2,6 @@
2
2
 
3
3
  javascript library for haptic feedback inside of safari on ios
4
4
 
5
- please note this only works on ios 17.4 to 26.4, as apple patched it in ios 26.5
6
-
7
5
  ![GitHub last commit](https://img.shields.io/github/last-commit/tijnjh/ios-haptics)
8
6
  [![npm version](https://img.shields.io/npm/v/ios-haptics.svg)](https://npmjs.com/package/ios-haptics)
9
7
  ![NPM Downloads](https://img.shields.io/npm/dm/ios-haptics)
@@ -36,9 +34,6 @@ haptic.error()
36
34
 
37
35
  this uses the `<input type="checkbox" switch />` (introduced in safari 17.4), which has haptic feedback when toggled
38
36
 
39
- > [!IMPORTANT]
40
- > apple patched the bug this library used for haptic feedback in ios 26.5. you can no longer trigger haptic feedback programmatically by calling `.click()` on a `<label>` that is `for` an `<input type="checkbox" switch />`. haptic feedback still works when the user directly clicks the checkbox switch themselves, but it can no longer be done programmatically.
41
-
42
37
  every `haptic` call, it will create one of those in the background, toggle it, then remove it
43
38
 
44
39
  on devices that support it, `navigator.vibrate()` is called instead, so it works on android too
@@ -0,0 +1,46 @@
1
+ declare const supportsHaptics: boolean;
2
+ /** INTERNAL */
3
+ declare function _triggerAndroidHaptic(): void;
4
+ interface haptic {
5
+ /** @deprecated */
6
+ apply: never;
7
+ /** @deprecated */
8
+ arguments: never;
9
+ /** @deprecated */
10
+ bind: never;
11
+ /** @deprecated */
12
+ call: never;
13
+ /** @deprecated */
14
+ caller: never;
15
+ /** @deprecated */
16
+ length: never;
17
+ /** @deprecated */
18
+ name: never;
19
+ /** @deprecated */
20
+ prototype: never;
21
+ /** @deprecated */
22
+ toString: never;
23
+ /** @deprecated */
24
+ Symbol: never;
25
+ /** a single haptic */
26
+ (): void;
27
+ /** two rapid haptics */
28
+ confirm: () => void;
29
+ /** three rapid haptics */
30
+ error: () => void;
31
+ }
32
+ /**
33
+ * @deprecated no longer works in newer ios versions, use the component instead
34
+ *
35
+ * @example
36
+ * ```tsx
37
+ * import { HapticTrigger } from 'ios-haptics/(react|svelte|vue)'
38
+ *
39
+ * <HapticTrigger>
40
+ * click me
41
+ * </HapticTrigger>
42
+ *
43
+ */
44
+ declare const __haptic: haptic;
45
+
46
+ export { _triggerAndroidHaptic, __haptic as haptic, supportsHaptics };
package/dist/index.d.ts CHANGED
@@ -1,33 +1,46 @@
1
- //#region src/index.d.ts
2
1
  declare const supportsHaptics: boolean;
2
+ /** INTERNAL */
3
+ declare function _triggerAndroidHaptic(): void;
3
4
  interface haptic {
4
- /** @deprecated */
5
- apply: never;
6
- /** @deprecated */
7
- arguments: never;
8
- /** @deprecated */
9
- bind: never;
10
- /** @deprecated */
11
- call: never;
12
- /** @deprecated */
13
- caller: never;
14
- /** @deprecated */
15
- length: never;
16
- /** @deprecated */
17
- name: never;
18
- /** @deprecated */
19
- prototype: never;
20
- /** @deprecated */
21
- toString: never;
22
- /** @deprecated */
23
- Symbol: never;
24
- /** a single haptic */
25
- (): void;
26
- /** two rapid haptics */
27
- confirm: () => void;
28
- /** three rapid haptics */
29
- error: () => void;
5
+ /** @deprecated */
6
+ apply: never;
7
+ /** @deprecated */
8
+ arguments: never;
9
+ /** @deprecated */
10
+ bind: never;
11
+ /** @deprecated */
12
+ call: never;
13
+ /** @deprecated */
14
+ caller: never;
15
+ /** @deprecated */
16
+ length: never;
17
+ /** @deprecated */
18
+ name: never;
19
+ /** @deprecated */
20
+ prototype: never;
21
+ /** @deprecated */
22
+ toString: never;
23
+ /** @deprecated */
24
+ Symbol: never;
25
+ /** a single haptic */
26
+ (): void;
27
+ /** two rapid haptics */
28
+ confirm: () => void;
29
+ /** three rapid haptics */
30
+ error: () => void;
30
31
  }
32
+ /**
33
+ * @deprecated no longer works in newer ios versions, use the component instead
34
+ *
35
+ * @example
36
+ * ```tsx
37
+ * import { HapticTrigger } from 'ios-haptics/(react|svelte|vue)'
38
+ *
39
+ * <HapticTrigger>
40
+ * click me
41
+ * </HapticTrigger>
42
+ *
43
+ */
31
44
  declare const __haptic: haptic;
32
- //#endregion
33
- export { __haptic as haptic, supportsHaptics };
45
+
46
+ export { _triggerAndroidHaptic, __haptic as haptic, supportsHaptics };
package/dist/index.js CHANGED
@@ -1,57 +1 @@
1
- /**
2
- * ios-haptics v0.1.4
3
- * tijn.dev
4
- * @license MIT
5
- **/
6
- //#region src/index.ts
7
- const supportsHaptics = typeof window === "undefined" || typeof window.matchMedia !== "function" ? false : window.matchMedia("(pointer: coarse)").matches;
8
- function _haptic() {
9
- try {
10
- if (navigator.vibrate) {
11
- navigator.vibrate(50);
12
- return;
13
- }
14
- if (!supportsHaptics) return;
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
- } catch {}
26
- }
27
- _haptic.confirm = () => {
28
- if (navigator.vibrate) {
29
- navigator.vibrate([
30
- 50,
31
- 70,
32
- 50
33
- ]);
34
- return;
35
- }
36
- _haptic();
37
- setTimeout(() => _haptic(), 120);
38
- };
39
- _haptic.error = () => {
40
- if (navigator.vibrate) {
41
- navigator.vibrate([
42
- 50,
43
- 70,
44
- 50,
45
- 70,
46
- 50
47
- ]);
48
- return;
49
- }
50
- _haptic();
51
- setTimeout(() => _haptic(), 120);
52
- setTimeout(() => _haptic(), 240);
53
- };
54
- const __haptic = _haptic;
55
-
56
- //#endregion
57
- export { __haptic as haptic, supportsHaptics };
1
+ 'use strict';var i=typeof window>"u"||typeof window.matchMedia!="function"?false:window.matchMedia("(pointer: coarse)").matches;function n(){try{if(!i)return;navigator.vibrate&&navigator.vibrate(50);}catch{}}function e(){try{if(navigator.vibrate){navigator.vibrate(50);return}if(!i)return;let t=document.createElement("label");t.ariaHidden="true",t.style.display="none";let r=document.createElement("input");r.type="checkbox",r.setAttribute("switch",""),t.appendChild(r),document.head.appendChild(t),t.click(),document.head.removeChild(t);}catch{}}e.confirm=()=>{if(navigator.vibrate){navigator.vibrate([50,70,50]);return}e(),setTimeout(e,120);};e.error=()=>{if(navigator.vibrate){navigator.vibrate([50,70,50,70,50]);return}e(),setTimeout(e,120),setTimeout(e,240);};var a=e;exports._triggerAndroidHaptic=n;exports.haptic=a;exports.supportsHaptics=i;
package/dist/index.mjs ADDED
@@ -0,0 +1 @@
1
+ var i=typeof window>"u"||typeof window.matchMedia!="function"?false:window.matchMedia("(pointer: coarse)").matches;function n(){try{if(!i)return;navigator.vibrate&&navigator.vibrate(50);}catch{}}function e(){try{if(navigator.vibrate){navigator.vibrate(50);return}if(!i)return;let t=document.createElement("label");t.ariaHidden="true",t.style.display="none";let r=document.createElement("input");r.type="checkbox",r.setAttribute("switch",""),t.appendChild(r),document.head.appendChild(t),t.click(),document.head.removeChild(t);}catch{}}e.confirm=()=>{if(navigator.vibrate){navigator.vibrate([50,70,50]);return}e(),setTimeout(e,120);};e.error=()=>{if(navigator.vibrate){navigator.vibrate([50,70,50,70,50]);return}e(),setTimeout(e,120),setTimeout(e,240);};var a=e;export{n as _triggerAndroidHaptic,a as haptic,i as supportsHaptics};
@@ -0,0 +1,11 @@
1
+ import * as react from 'react';
2
+ import { ElementType, ComponentPropsWithoutRef } from 'react';
3
+
4
+ type HapticTriggerProps<T extends ElementType> = {
5
+ as?: T;
6
+ onTap?: () => void;
7
+ } & ComponentPropsWithoutRef<T>;
8
+
9
+ declare function HapticTrigger<T extends ElementType>({ as, onTap, children, ...props }: HapticTriggerProps<T>): react.JSX.Element;
10
+
11
+ export { HapticTrigger };
@@ -0,0 +1,11 @@
1
+ import * as react from 'react';
2
+ import { ElementType, ComponentPropsWithoutRef } from 'react';
3
+
4
+ type HapticTriggerProps<T extends ElementType> = {
5
+ as?: T;
6
+ onTap?: () => void;
7
+ } & ComponentPropsWithoutRef<T>;
8
+
9
+ declare function HapticTrigger<T extends ElementType>({ as, onTap, children, ...props }: HapticTriggerProps<T>): react.JSX.Element;
10
+
11
+ export { HapticTrigger };
@@ -0,0 +1 @@
1
+ 'use strict';function t({as:e,onTap:i,children:r,...o}){return React.createElement(e??"button",{...o,style:{position:"relative",display:"inline-flex"}},r,React.createElement("input",{style:{position:"absolute",top:0,left:0,width:"100%",height:"100%",margin:0,opacity:0,cursor:"pointer",clipPath:"inset(0 round 999px)",WebkitTapHighlightColor:"transparent",touchAction:"manipulation"},type:"checkbox",onChange:i,switch:""}))}exports.HapticTrigger=t;
@@ -0,0 +1 @@
1
+ function t({as:e,onTap:i,children:r,...o}){return React.createElement(e??"button",{...o,style:{position:"relative",display:"inline-flex"}},r,React.createElement("input",{style:{position:"absolute",top:0,left:0,width:"100%",height:"100%",margin:0,opacity:0,cursor:"pointer",clipPath:"inset(0 round 999px)",WebkitTapHighlightColor:"transparent",touchAction:"manipulation"},type:"checkbox",onChange:i,switch:""}))}export{t as HapticTrigger};
@@ -0,0 +1,40 @@
1
+ <script>
2
+ /** @type {import("./types.ts").HapticTriggerProps<any>} */
3
+ const {
4
+ as,
5
+ ontap,
6
+ children,
7
+ ...props
8
+ } = $props()
9
+ </script>
10
+
11
+ <svelte:element
12
+ this={as ?? 'button'}
13
+ {...props}
14
+ style='
15
+ position: relative;
16
+ display: inline-flex;
17
+ '
18
+ >
19
+ {@render children?.()}
20
+
21
+ <input
22
+ style='
23
+ position: absolute;
24
+ top: 0;
25
+ left: 0;
26
+ width: 100%;
27
+ height: 100%;
28
+ margin: 0;
29
+ opacity: 0;
30
+ cursor: pointer;
31
+ clip-path: inset(0 round 999px);
32
+ -webkit-tap-highlight-color: transparent;
33
+ touch-action: manipulation;
34
+ '
35
+ type='checkbox'
36
+ onchange={ontap}
37
+ // @ts-expect-error - unrecognized attribute
38
+ switch
39
+ />
40
+ </svelte:element>
@@ -0,0 +1,10 @@
1
+ import { Component } from 'svelte';
2
+ import { SvelteHTMLElements } from 'svelte/elements';
3
+
4
+ type HapticTriggerProps<T extends keyof SvelteHTMLElements> = {
5
+ as?: T;
6
+ ontap?: () => void;
7
+ } & SvelteHTMLElements[T];
8
+ declare const HapticTrigger: Component<HapticTriggerProps<any>>;
9
+
10
+ export { HapticTrigger, type HapticTriggerProps };
@@ -0,0 +1,10 @@
1
+ import { Component } from 'svelte';
2
+ import { SvelteHTMLElements } from 'svelte/elements';
3
+
4
+ type HapticTriggerProps<T extends keyof SvelteHTMLElements> = {
5
+ as?: T;
6
+ ontap?: () => void;
7
+ } & SvelteHTMLElements[T];
8
+ declare const HapticTrigger: Component<HapticTriggerProps<any>>;
9
+
10
+ export { HapticTrigger, type HapticTriggerProps };
@@ -0,0 +1 @@
1
+ export { default as HapticTrigger } from "./HapticTrigger.svelte";
@@ -0,0 +1 @@
1
+ export { default as HapticTrigger } from "./HapticTrigger.svelte";
@@ -0,0 +1,13 @@
1
+ import * as vue from 'vue';
2
+
3
+ declare const _default: vue.DefineComponent<vue.ExtractPropTypes<{
4
+ as: StringConstructor;
5
+ }>, () => vue.VNode<vue.RendererNode, vue.RendererElement, {
6
+ [key: string]: any;
7
+ }>, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, "tap"[], "tap", vue.PublicProps, Readonly<vue.ExtractPropTypes<{
8
+ as: StringConstructor;
9
+ }>> & Readonly<{
10
+ onTap?: ((...args: any[]) => any) | undefined;
11
+ }>, {}, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
12
+
13
+ export { _default as HapticTrigger };
@@ -0,0 +1,13 @@
1
+ import * as vue from 'vue';
2
+
3
+ declare const _default: vue.DefineComponent<vue.ExtractPropTypes<{
4
+ as: StringConstructor;
5
+ }>, () => vue.VNode<vue.RendererNode, vue.RendererElement, {
6
+ [key: string]: any;
7
+ }>, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, "tap"[], "tap", vue.PublicProps, Readonly<vue.ExtractPropTypes<{
8
+ as: StringConstructor;
9
+ }>> & Readonly<{
10
+ onTap?: ((...args: any[]) => any) | undefined;
11
+ }>, {}, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
12
+
13
+ export { _default as HapticTrigger };
@@ -0,0 +1 @@
1
+ 'use strict';var vue=require('vue');var n=vue.defineComponent({name:"HapticTrigger",props:{as:String},emits:["tap"],setup(i,{emit:e,slots:r,attrs:o}){return ()=>{let p=i.as??"button";return vue.h(p,{...o,style:{position:"relative",display:"inline-flex"}},[r.default?.(),vue.h("input",{type:"checkbox",switch:"",style:{position:"absolute",top:0,left:0,width:"100%",height:"100%",margin:0,opacity:0,cursor:"pointer",clipPath:"inset(0 round 999px)",WebkitTapHighlightColor:"transparent",touchAction:"manipulation"},onChange:e("tap")})])}}});exports.HapticTrigger=n;
@@ -0,0 +1 @@
1
+ import {defineComponent,h}from'vue';var n=defineComponent({name:"HapticTrigger",props:{as:String},emits:["tap"],setup(i,{emit:e,slots:r,attrs:o}){return ()=>{let p=i.as??"button";return h(p,{...o,style:{position:"relative",display:"inline-flex"}},[r.default?.(),h("input",{type:"checkbox",switch:"",style:{position:"absolute",top:0,left:0,width:"100%",height:"100%",margin:0,opacity:0,cursor:"pointer",clipPath:"inset(0 round 999px)",WebkitTapHighlightColor:"transparent",touchAction:"manipulation"},onChange:e("tap")})])}}});export{n as HapticTrigger};
package/package.json CHANGED
@@ -1,13 +1,15 @@
1
1
  {
2
2
  "name": "ios-haptics",
3
- "type": "module",
4
- "version": "0.1.5",
3
+ "version": "2.0.1",
5
4
  "description": "haptic feedback for ios safari",
6
- "author": "tijnjh",
7
5
  "license": "MIT",
8
- "repository": "tijnjh/ios-haptics",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/tijnjh/ios-haptics.git"
9
+ },
9
10
  "keywords": [
10
11
  "haptic",
12
+ "haptics",
11
13
  "ios",
12
14
  "feedback",
13
15
  "haptic-feedback",
@@ -15,23 +17,86 @@
15
17
  "safari",
16
18
  "vibrate"
17
19
  ],
20
+ "sideEffects": false,
18
21
  "exports": {
19
22
  ".": {
20
- "types": "./dist/index.d.ts",
21
- "import": "./dist/index.js"
23
+ "types": {
24
+ "import": "./dist/index.d.mts",
25
+ "require": "./dist/index.d.ts"
26
+ },
27
+ "import": "./dist/index.mjs",
28
+ "require": "./dist/index.js"
29
+ },
30
+ "./react": {
31
+ "types": {
32
+ "import": "./dist/react/index.d.mts",
33
+ "require": "./dist/react/index.d.ts"
34
+ },
35
+ "import": "./dist/react/index.mjs",
36
+ "require": "./dist/react/index.js"
37
+ },
38
+ "./vue": {
39
+ "types": {
40
+ "import": "./dist/vue/index.d.mts",
41
+ "require": "./dist/vue/index.d.ts"
42
+ },
43
+ "import": "./dist/vue/index.mjs",
44
+ "require": "./dist/vue/index.js"
45
+ },
46
+ "./svelte": {
47
+ "types": {
48
+ "import": "./dist/svelte/index.d.mts",
49
+ "require": "./dist/svelte/index.d.ts"
50
+ },
51
+ "svelte": "./dist/svelte/index.mjs",
52
+ "import": "./dist/svelte/index.mjs",
53
+ "require": "./dist/svelte/index.js"
22
54
  }
23
55
  },
24
- "main": "./dist/index.js",
25
- "module": "./dist/index.js",
26
- "types": "./dist/index.d.ts",
56
+ "main": "dist/index.js",
57
+ "module": "dist/index.mjs",
58
+ "types": "dist/index.d.ts",
27
59
  "files": [
28
- "dist"
60
+ "dist/*"
29
61
  ],
30
62
  "scripts": {
31
- "build": "tsdown",
32
- "dev": "tsdown --watch"
63
+ "build": "tsup && node scripts/build-svelte.mjs",
64
+ "dev": "tsup --watch"
65
+ },
66
+ "peerDependencies": {
67
+ "react": ">=18",
68
+ "react-dom": ">=18",
69
+ "svelte": ">=5",
70
+ "vue": ">=3"
71
+ },
72
+ "peerDependenciesMeta": {
73
+ "react": {
74
+ "optional": true
75
+ },
76
+ "react-dom": {
77
+ "optional": true
78
+ },
79
+ "svelte": {
80
+ "optional": true
81
+ },
82
+ "vue": {
83
+ "optional": true
84
+ }
33
85
  },
34
86
  "devDependencies": {
35
- "tsdown": "latest"
87
+ "@antfu/eslint-config": "^9.0.0",
88
+ "@eslint-react/eslint-plugin": "^5.6.0",
89
+ "@types/react": "^19.2.17",
90
+ "eslint": "^10.3.0",
91
+ "eslint-plugin-format": "^2.0.1",
92
+ "eslint-plugin-react-refresh": "^0.5.2",
93
+ "eslint-plugin-svelte": "^3.17.1",
94
+ "react": "^19.2.7",
95
+ "react-dom": "^19.2.7",
96
+ "svelte": "^5.56.3",
97
+ "svelte-eslint-parser": "^1.6.1",
98
+ "tsup": "^8.5.1",
99
+ "typescript": "5",
100
+ "vue": "^3.5.38"
36
101
  }
37
102
  }