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.
Files changed (2) hide show
  1. package/README.md +26 -15
  2. 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 designed to control audio playback with various settings, including volume control, callback and debug mode. It also includes iOS support.</p>
13
- <p align="center"><sup>1kB gzipped</sup></p>
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
  &#10148; **Usage**
33
33
 
34
- <sub>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.</sub>
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
- file: './sound.mp3',
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: () => { console.log('Playback ended') },
51
+ callback: () => console.log('done'),
42
52
  debug: true,
43
53
  });
44
54
 
45
- const play = () => sound.play();
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
  &#10148; **Options**
52
63
 
53
- | Option | Type | Default | Description |
54
- |:----------:|:-----------------------------------:|:--------:|:---------------------------------------------------------------------------------------------|
55
- | `file` | `string` | `none` | The URL of the audio file to be played. |
56
- | `volume` | `number` | `1.0` | Volume level for the audio playback, ranging from 0.0 (mute) to 1.0 (full volume). |
57
- | `callback` | `((error?: Error) => void) \| null` | `null` | A callback function to be executed after the audio finishes playing, or if an error occurs. |
58
- | `throttle` | `number` | `0` | Minimum time (in milliseconds) between successive audio plays to prevent rapid repeat plays. |
59
- | `debug` | `boolean` | `false` | If `true`, debug information and errors will be logged to the console. |
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
  &#10148; **License**
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "clicktone",
3
- "version": "1.8.0-dev.0",
4
- "description": "ClickTone is designed to control audio playback with various settings, including volume control, callback and debug mode. It also includes iOS support.",
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": {