ios-haptics 2.0.0 → 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/LICENSE +21 -0
- package/README.md +44 -0
- package/dist/index.d.mts +15 -1
- package/dist/index.d.ts +15 -1
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/dist/svelte/HapticTrigger.svelte +3 -5
- package/package.json +5 -6
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# 📳 ios-haptics
|
|
2
|
+
|
|
3
|
+
javascript library for haptic feedback inside of safari on ios
|
|
4
|
+
|
|
5
|
+

|
|
6
|
+
[](https://npmjs.com/package/ios-haptics)
|
|
7
|
+

|
|
8
|
+

|
|
9
|
+
|
|
10
|
+
demo: [ios-haptics demo](https://codepen.io/tijnjh/pen/KwpgPqB)
|
|
11
|
+
|
|
12
|
+
## 📦 installation
|
|
13
|
+
|
|
14
|
+
```sh
|
|
15
|
+
npm i ios-haptics
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## 🚀 usage
|
|
19
|
+
|
|
20
|
+
```javascript
|
|
21
|
+
import { haptic } from 'ios-haptics'
|
|
22
|
+
|
|
23
|
+
// a single haptic
|
|
24
|
+
haptic()
|
|
25
|
+
|
|
26
|
+
// two rapid haptics
|
|
27
|
+
haptic.confirm()
|
|
28
|
+
|
|
29
|
+
// three rapid haptics
|
|
30
|
+
haptic.error()
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## ⚙️ how it works
|
|
34
|
+
|
|
35
|
+
this uses the `<input type="checkbox" switch />` (introduced in safari 17.4), which has haptic feedback when toggled
|
|
36
|
+
|
|
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
|
|
40
|
+
|
|
41
|
+
---
|
|
42
|
+
|
|
43
|
+
feel free to send a pr or open an issue if you have suggestions or find
|
|
44
|
+
improvements
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
declare const supportsHaptics: boolean;
|
|
2
|
+
/** INTERNAL */
|
|
3
|
+
declare function _triggerAndroidHaptic(): void;
|
|
2
4
|
interface haptic {
|
|
3
5
|
/** @deprecated */
|
|
4
6
|
apply: never;
|
|
@@ -27,6 +29,18 @@ interface haptic {
|
|
|
27
29
|
/** three rapid haptics */
|
|
28
30
|
error: () => void;
|
|
29
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
|
+
*/
|
|
30
44
|
declare const __haptic: haptic;
|
|
31
45
|
|
|
32
|
-
export { __haptic as haptic, supportsHaptics };
|
|
46
|
+
export { _triggerAndroidHaptic, __haptic as haptic, supportsHaptics };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
declare const supportsHaptics: boolean;
|
|
2
|
+
/** INTERNAL */
|
|
3
|
+
declare function _triggerAndroidHaptic(): void;
|
|
2
4
|
interface haptic {
|
|
3
5
|
/** @deprecated */
|
|
4
6
|
apply: never;
|
|
@@ -27,6 +29,18 @@ interface haptic {
|
|
|
27
29
|
/** three rapid haptics */
|
|
28
30
|
error: () => void;
|
|
29
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
|
+
*/
|
|
30
44
|
declare const __haptic: haptic;
|
|
31
45
|
|
|
32
|
-
export { __haptic as haptic, supportsHaptics };
|
|
46
|
+
export { _triggerAndroidHaptic, __haptic as haptic, supportsHaptics };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';var
|
|
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
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
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};
|
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
<script
|
|
2
|
-
|
|
3
|
-
import { HapticTriggerProps } from './types'
|
|
4
|
-
|
|
1
|
+
<script>
|
|
2
|
+
/** @type {import("./types.ts").HapticTriggerProps<any>} */
|
|
5
3
|
const {
|
|
6
4
|
as,
|
|
7
5
|
ontap,
|
|
8
6
|
children,
|
|
9
7
|
...props
|
|
10
|
-
}
|
|
8
|
+
} = $props()
|
|
11
9
|
</script>
|
|
12
10
|
|
|
13
11
|
<svelte:element
|
package/package.json
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ios-haptics",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "haptic feedback for ios safari",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
|
-
"url": "git+https://github.com/tijnjh/ios-haptics.git"
|
|
9
|
-
"directory": "packages/ios-haptics"
|
|
8
|
+
"url": "git+https://github.com/tijnjh/ios-haptics.git"
|
|
10
9
|
},
|
|
11
10
|
"keywords": [
|
|
12
11
|
"haptic",
|
|
@@ -21,9 +20,9 @@
|
|
|
21
20
|
"sideEffects": false,
|
|
22
21
|
"exports": {
|
|
23
22
|
".": {
|
|
24
|
-
|
|
25
|
-
"import": "./dist/
|
|
26
|
-
"require": "./dist/
|
|
23
|
+
"types": {
|
|
24
|
+
"import": "./dist/index.d.mts",
|
|
25
|
+
"require": "./dist/index.d.ts"
|
|
27
26
|
},
|
|
28
27
|
"import": "./dist/index.mjs",
|
|
29
28
|
"require": "./dist/index.js"
|