ios-haptics 0.1.5 → 2.0.0

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.
@@ -0,0 +1,32 @@
1
+ declare const supportsHaptics: boolean;
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;
29
+ }
30
+ declare const __haptic: haptic;
31
+
32
+ export { __haptic as haptic, supportsHaptics };
package/dist/index.d.ts CHANGED
@@ -1,33 +1,32 @@
1
- //#region src/index.d.ts
2
1
  declare const supportsHaptics: boolean;
3
2
  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;
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;
30
29
  }
31
30
  declare const __haptic: haptic;
32
- //#endregion
33
- export { __haptic as haptic, supportsHaptics };
31
+
32
+ export { __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 r=typeof window>"u"||typeof window.matchMedia!="function"?false:window.matchMedia("(pointer: coarse)").matches;function e(){try{if(navigator.vibrate){navigator.vibrate(50);return}if(!r)return;let t=document.createElement("label");t.ariaHidden="true",t.style.display="none";let n=document.createElement("input");n.type="checkbox",n.setAttribute("switch",""),t.appendChild(n),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 i=e;exports.haptic=i;exports.supportsHaptics=r;
package/dist/index.mjs ADDED
@@ -0,0 +1 @@
1
+ var r=typeof window>"u"||typeof window.matchMedia!="function"?false:window.matchMedia("(pointer: coarse)").matches;function e(){try{if(navigator.vibrate){navigator.vibrate(50);return}if(!r)return;let t=document.createElement("label");t.ariaHidden="true",t.style.display="none";let n=document.createElement("input");n.type="checkbox",n.setAttribute("switch",""),t.appendChild(n),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 i=e;export{i as haptic,r 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,42 @@
1
+ <script lang='ts' generics="T extends keyof SvelteHTMLElements">
2
+ import type { SvelteHTMLElements } from 'svelte/elements'
3
+ import { HapticTriggerProps } from './types'
4
+
5
+ const {
6
+ as,
7
+ ontap,
8
+ children,
9
+ ...props
10
+ }: HapticTriggerProps<T> = $props()
11
+ </script>
12
+
13
+ <svelte:element
14
+ this={as ?? 'button'}
15
+ {...props}
16
+ style='
17
+ position: relative;
18
+ display: inline-flex;
19
+ '
20
+ >
21
+ {@render children?.()}
22
+
23
+ <input
24
+ style='
25
+ position: absolute;
26
+ top: 0;
27
+ left: 0;
28
+ width: 100%;
29
+ height: 100%;
30
+ margin: 0;
31
+ opacity: 0;
32
+ cursor: pointer;
33
+ clip-path: inset(0 round 999px);
34
+ -webkit-tap-highlight-color: transparent;
35
+ touch-action: manipulation;
36
+ '
37
+ type='checkbox'
38
+ onchange={ontap}
39
+ // @ts-expect-error - unrecognized attribute
40
+ switch
41
+ />
42
+ </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,16 @@
1
1
  {
2
2
  "name": "ios-haptics",
3
- "type": "module",
4
- "version": "0.1.5",
3
+ "version": "2.0.0",
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
+ "directory": "packages/ios-haptics"
10
+ },
9
11
  "keywords": [
10
12
  "haptic",
13
+ "haptics",
11
14
  "ios",
12
15
  "feedback",
13
16
  "haptic-feedback",
@@ -15,23 +18,86 @@
15
18
  "safari",
16
19
  "vibrate"
17
20
  ],
21
+ "sideEffects": false,
18
22
  "exports": {
19
23
  ".": {
20
- "types": "./dist/index.d.ts",
21
- "import": "./dist/index.js"
24
+ "types": {
25
+ "import": "./dist/react/index.d.mts",
26
+ "require": "./dist/react/index.d.ts"
27
+ },
28
+ "import": "./dist/index.mjs",
29
+ "require": "./dist/index.js"
30
+ },
31
+ "./react": {
32
+ "types": {
33
+ "import": "./dist/react/index.d.mts",
34
+ "require": "./dist/react/index.d.ts"
35
+ },
36
+ "import": "./dist/react/index.mjs",
37
+ "require": "./dist/react/index.js"
38
+ },
39
+ "./vue": {
40
+ "types": {
41
+ "import": "./dist/vue/index.d.mts",
42
+ "require": "./dist/vue/index.d.ts"
43
+ },
44
+ "import": "./dist/vue/index.mjs",
45
+ "require": "./dist/vue/index.js"
46
+ },
47
+ "./svelte": {
48
+ "types": {
49
+ "import": "./dist/svelte/index.d.mts",
50
+ "require": "./dist/svelte/index.d.ts"
51
+ },
52
+ "svelte": "./dist/svelte/index.mjs",
53
+ "import": "./dist/svelte/index.mjs",
54
+ "require": "./dist/svelte/index.js"
22
55
  }
23
56
  },
24
- "main": "./dist/index.js",
25
- "module": "./dist/index.js",
26
- "types": "./dist/index.d.ts",
57
+ "main": "dist/index.js",
58
+ "module": "dist/index.mjs",
59
+ "types": "dist/index.d.ts",
27
60
  "files": [
28
- "dist"
61
+ "dist/*"
29
62
  ],
30
63
  "scripts": {
31
- "build": "tsdown",
32
- "dev": "tsdown --watch"
64
+ "build": "tsup && node scripts/build-svelte.mjs",
65
+ "dev": "tsup --watch"
66
+ },
67
+ "peerDependencies": {
68
+ "react": ">=18",
69
+ "react-dom": ">=18",
70
+ "svelte": ">=5",
71
+ "vue": ">=3"
72
+ },
73
+ "peerDependenciesMeta": {
74
+ "react": {
75
+ "optional": true
76
+ },
77
+ "react-dom": {
78
+ "optional": true
79
+ },
80
+ "svelte": {
81
+ "optional": true
82
+ },
83
+ "vue": {
84
+ "optional": true
85
+ }
33
86
  },
34
87
  "devDependencies": {
35
- "tsdown": "latest"
88
+ "@antfu/eslint-config": "^9.0.0",
89
+ "@eslint-react/eslint-plugin": "^5.6.0",
90
+ "@types/react": "^19.2.17",
91
+ "eslint": "^10.3.0",
92
+ "eslint-plugin-format": "^2.0.1",
93
+ "eslint-plugin-react-refresh": "^0.5.2",
94
+ "eslint-plugin-svelte": "^3.17.1",
95
+ "react": "^19.2.7",
96
+ "react-dom": "^19.2.7",
97
+ "svelte": "^5.56.3",
98
+ "svelte-eslint-parser": "^1.6.1",
99
+ "tsup": "^8.5.1",
100
+ "typescript": "5",
101
+ "vue": "^3.5.38"
36
102
  }
37
103
  }
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License Copyright (c) 2025 tijn
2
-
3
- Permission is hereby granted, free of
4
- charge, to any person obtaining a copy of this software and associated
5
- documentation files (the "Software"), to deal in the Software without
6
- restriction, including without limitation the rights to use, copy, modify, merge,
7
- publish, distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to the
9
- following conditions:
10
-
11
- The above copyright notice and this permission notice
12
- (including the next paragraph) shall be included in all copies or substantial
13
- portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
16
- ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
18
- EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
19
- OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20
- FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- THE SOFTWARE.
package/README.md DELETED
@@ -1,49 +0,0 @@
1
- # 📳 ios-haptics
2
-
3
- javascript library for haptic feedback inside of safari on ios
4
-
5
- please note this only works on ios 17.4 to 26.4, as apple patched it in ios 26.5
6
-
7
- ![GitHub last commit](https://img.shields.io/github/last-commit/tijnjh/ios-haptics)
8
- [![npm version](https://img.shields.io/npm/v/ios-haptics.svg)](https://npmjs.com/package/ios-haptics)
9
- ![NPM Downloads](https://img.shields.io/npm/dm/ios-haptics)
10
- ![npm package minimized gzipped size](https://img.shields.io/bundlejs/size/ios-haptics)
11
-
12
- demo: [ios-haptics demo](https://codepen.io/tijnjh/pen/KwpgPqB)
13
-
14
- ## 📦 installation
15
-
16
- ```sh
17
- npm i ios-haptics
18
- ```
19
-
20
- ## 🚀 usage
21
-
22
- ```javascript
23
- import { haptic } from 'ios-haptics'
24
-
25
- // a single haptic
26
- haptic()
27
-
28
- // two rapid haptics
29
- haptic.confirm()
30
-
31
- // three rapid haptics
32
- haptic.error()
33
- ```
34
-
35
- ## ⚙️ how it works
36
-
37
- this uses the `<input type="checkbox" switch />` (introduced in safari 17.4), which has haptic feedback when toggled
38
-
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
- every `haptic` call, it will create one of those in the background, toggle it, then remove it
43
-
44
- on devices that support it, `navigator.vibrate()` is called instead, so it works on android too
45
-
46
- ---
47
-
48
- feel free to send a pr or open an issue if you have suggestions or find
49
- improvements