clicktone 1.8.0-dev.0 → 1.8.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.
- package/README.md +26 -15
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
|
|
10
10
|
</div>
|
|
11
11
|
|
|
12
|
-
<p align="center">ClickTone is
|
|
13
|
-
<p align="center"><sup>
|
|
12
|
+
<p align="center">ClickTone is a lightweight helper for UI sound feedback. It wraps the Web Audio API, giving you instant click‑sounds with volume control, throttling, callbacks, and an iOS resume workaround.</p>
|
|
13
|
+
<p align="center"><sup>1.2kB gzipped</sup></p>
|
|
14
14
|
<p align="center"><a href="https://codepen.io/ux-ui/pen/yLwbmMr">Demo</a></p>
|
|
15
15
|
<br>
|
|
16
16
|
|
|
@@ -31,32 +31,43 @@ import ClickTone from 'clicktone';
|
|
|
31
31
|
|
|
32
32
|
➤ **Usage**
|
|
33
33
|
|
|
34
|
-
|
|
34
|
+
```html
|
|
35
|
+
<audio preload="auto">
|
|
36
|
+
<source id="click-source" src="./click.mp3" type="audio/mpeg" />
|
|
37
|
+
<source src="./click.ogg" type="audio/ogg" />
|
|
38
|
+
</audio>
|
|
39
|
+
```
|
|
40
|
+
|
|
35
41
|
```javascript
|
|
36
42
|
const sound = new ClickTone({
|
|
37
|
-
|
|
43
|
+
// Any of the forms work:
|
|
44
|
+
// file: './sound.mp3',
|
|
38
45
|
// file: new URL('./sound.mp3', import.meta.url).href,
|
|
46
|
+
// file: document.querySelector('#click-source') as HTMLSourceElement,
|
|
47
|
+
file: { id: 'click-source' },
|
|
48
|
+
|
|
39
49
|
volume: 0.7,
|
|
40
50
|
throttle: 100,
|
|
41
|
-
callback: () =>
|
|
51
|
+
callback: () => console.log('done'),
|
|
42
52
|
debug: true,
|
|
43
53
|
});
|
|
44
54
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
button.addEventListener('pointerdown', play);
|
|
55
|
+
button.addEventListener('click', () => click.play());
|
|
48
56
|
```
|
|
57
|
+
<sup>ClickTone uses the Web Audio API, which supports many audio file formats: MP3, WAV, OGG, AAC and others. Note that not all browsers support these formats.</sup>
|
|
49
58
|
<br>
|
|
59
|
+
<sup>Tip: you can also override the source at call‑time: click.play('./alt.wav').</sup>
|
|
60
|
+
<br><br>
|
|
50
61
|
|
|
51
62
|
➤ **Options**
|
|
52
63
|
|
|
53
|
-
| Option |
|
|
54
|
-
|
|
55
|
-
| `file` |
|
|
56
|
-
| `volume` |
|
|
57
|
-
| `callback` |
|
|
58
|
-
| `throttle` |
|
|
59
|
-
| `debug` |
|
|
64
|
+
| Option | Type | Default | Description |
|
|
65
|
+
|:----------:|:-----------------------------------------------:|:-------:|:--------------------------------------------------------------------------------------------------------------------------------|
|
|
66
|
+
| `file` | `string \| HTMLSourceElement \| { id: string }` | – | Audio source. Either a direct URL, an actual `<source>` element, or an object whose id maps to a `<source>` already in the DOM. |
|
|
67
|
+
| `volume` | `number` | `1` | Playback volume `0`–`1`. |
|
|
68
|
+
| `callback` | `((error?: Error) => void) \| null` | `null` | Called after playback ends or if an error occurs. |
|
|
69
|
+
| `throttle` | `number` | `0` | Debounce interval in ms. Playback requests arriving sooner are ignored. |
|
|
70
|
+
| `debug` | `boolean` | `false` | Log internal errors/warnings to the console. |
|
|
60
71
|
<br>
|
|
61
72
|
|
|
62
73
|
➤ **License**
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clicktone",
|
|
3
|
-
"version": "1.8.0
|
|
4
|
-
"description": "ClickTone is
|
|
3
|
+
"version": "1.8.0",
|
|
4
|
+
"description": "ClickTone is a lightweight helper for UI sound feedback. It wraps the Web Audio API, giving you instant click‑sounds with volume control, throttling, callbacks, and an iOS resume workaround.",
|
|
5
5
|
"author": "ux-ui.pro",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|