clicktone 0.0.1 → 0.0.2

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
@@ -10,7 +10,7 @@
10
10
  </div>
11
11
 
12
12
  <p align="center">A simple class to create elements that play audio when clicked.</p>
13
- <p align="center"><a href="https://4j8rvr.csb.app/">Demo</a></p>
13
+ <p align="center"><a href="https://5mq6lq.csb.app/">Demo</a></p>
14
14
  <br>
15
15
 
16
16
  &#10148; **Install**
package/dist/index.js CHANGED
@@ -11,7 +11,9 @@ $parcel$defineInteropFlag(module.exports);
11
11
 
12
12
  $parcel$export(module.exports, "default", () => $4fa36e821943b400$export$2e2bcd8739ae039);
13
13
  class $4fa36e821943b400$var$ClickTone {
14
- constructor(){
14
+ constructor({ el: el = "", sound: sound = "" } = {}){
15
+ this.el = el;
16
+ this.sound = sound;
15
17
  this.audioContext = new (window.AudioContext || window.webkitAudioContext)();
16
18
  this.setupIOSAudioContextFix();
17
19
  }
@@ -35,10 +37,10 @@ class $4fa36e821943b400$var$ClickTone {
35
37
  source.start(0);
36
38
  }).catch();
37
39
  }
38
- init(buttonId, audioFileUrl) {
39
- const button = document.getElementById(buttonId);
40
- button.addEventListener("click", ()=>{
41
- this.playAudio(audioFileUrl);
40
+ init() {
41
+ const targetElement = typeof this.el === "string" ? document.querySelector(this.el) : this.el;
42
+ targetElement.addEventListener("click", ()=>{
43
+ this.playAudio(this.sound);
42
44
  });
43
45
  }
44
46
  }
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;;;;AAAA,MAAM;IACJ,aAAc;QACZ,IAAI,CAAC,YAAY,GAAG,IAAK,CAAA,OAAO,YAAY,IAAI,OAAO,kBAAkB,AAAD;QACxE,IAAI,CAAC,uBAAuB;IAC9B;IAEA,0BAA0B;QACxB,IAAI,IAAI,CAAC,YAAY,CAAC,KAAK,KAAK,eAAe,kBAAkB,QAAQ;YACvE,MAAM,SAAS;gBACb,IAAI,CAAC,YAAY,CAAC,MAAM,GAAG,IAAI,CAAC;oBAC9B,SAAS,IAAI,CAAC,mBAAmB,CAAC,cAAc;oBAChD,SAAS,IAAI,CAAC,mBAAmB,CAAC,YAAY;gBAChD;YACF;YAEA,SAAS,IAAI,CAAC,gBAAgB,CAAC,cAAc,QAAQ;YACrD,SAAS,IAAI,CAAC,gBAAgB,CAAC,YAAY,QAAQ;QACrD;IACF;IAEA,UAAU,GAAG,EAAE;QACb,MAAM,KACH,IAAI,CAAC,CAAC,WAAa,SAAS,WAAW,IACvC,IAAI,CAAC,CAAC,SAAW,IAAI,CAAC,YAAY,CAAC,eAAe,CAAC,SACnD,IAAI,CAAC,CAAC;YACL,MAAM,SAAS,IAAI,CAAC,YAAY,CAAC,kBAAkB;YACnD,OAAO,MAAM,GAAG;YAChB,OAAO,OAAO,CAAC,IAAI,CAAC,YAAY,CAAC,WAAW;YAC5C,OAAO,KAAK,CAAC;QACf,GACC,KAAK;IACV;IAEA,KAAK,QAAQ,EAAE,YAAY,EAAE;QAC3B,MAAM,SAAS,SAAS,cAAc,CAAC;QAEvC,OAAO,gBAAgB,CAAC,SAAS;YAC/B,IAAI,CAAC,SAAS,CAAC;QACjB;IACF;AACF;IAEA,2CAAe","sources":["src/index.js"],"sourcesContent":["class ClickTone {\n constructor() {\n this.audioContext = new (window.AudioContext || window.webkitAudioContext)();\n this.setupIOSAudioContextFix();\n }\n\n setupIOSAudioContextFix() {\n if (this.audioContext.state === 'suspended' && 'ontouchstart' in window) {\n const unlock = () => {\n this.audioContext.resume().then(() => {\n document.body.removeEventListener('touchstart', unlock);\n document.body.removeEventListener('touchend', unlock);\n });\n };\n\n document.body.addEventListener('touchstart', unlock, false);\n document.body.addEventListener('touchend', unlock, false);\n }\n }\n\n playAudio(url) {\n fetch(url)\n .then((response) => response.arrayBuffer())\n .then((buffer) => this.audioContext.decodeAudioData(buffer))\n .then((audioData) => {\n const source = this.audioContext.createBufferSource();\n source.buffer = audioData;\n source.connect(this.audioContext.destination);\n source.start(0);\n })\n .catch();\n }\n\n init(buttonId, audioFileUrl) {\n const button = document.getElementById(buttonId);\n\n button.addEventListener('click', () => {\n this.playAudio(audioFileUrl);\n });\n }\n}\n\nexport default ClickTone;\n"],"names":[],"version":3,"file":"index.js.map"}
1
+ {"mappings":";;;;;;;;;;;;AAAA,MAAM;IACJ,YAAY,MAAE,KAAK,WAAI,QAAQ,IAAI,GAAG,CAAC,CAAC,CAAE;QACxC,IAAI,CAAC,EAAE,GAAG;QACV,IAAI,CAAC,KAAK,GAAG;QAEb,IAAI,CAAC,YAAY,GAAG,IAAK,CAAA,OAAO,YAAY,IAC1C,OAAO,kBAAkB,AAAD;QAC1B,IAAI,CAAC,uBAAuB;IAC9B;IAEA,0BAA0B;QACxB,IAAI,IAAI,CAAC,YAAY,CAAC,KAAK,KAAK,eAAe,kBAAkB,QAAQ;YACvE,MAAM,SAAS;gBACb,IAAI,CAAC,YAAY,CAAC,MAAM,GAAG,IAAI,CAAC;oBAC9B,SAAS,IAAI,CAAC,mBAAmB,CAAC,cAAc;oBAChD,SAAS,IAAI,CAAC,mBAAmB,CAAC,YAAY;gBAChD;YACF;YAEA,SAAS,IAAI,CAAC,gBAAgB,CAAC,cAAc,QAAQ;YACrD,SAAS,IAAI,CAAC,gBAAgB,CAAC,YAAY,QAAQ;QACrD;IACF;IAEA,UAAU,GAAG,EAAE;QACb,MAAM,KACH,IAAI,CAAC,CAAC,WAAa,SAAS,WAAW,IACvC,IAAI,CAAC,CAAC,SAAW,IAAI,CAAC,YAAY,CAAC,eAAe,CAAC,SACnD,IAAI,CAAC,CAAC;YACL,MAAM,SAAS,IAAI,CAAC,YAAY,CAAC,kBAAkB;YACnD,OAAO,MAAM,GAAG;YAChB,OAAO,OAAO,CAAC,IAAI,CAAC,YAAY,CAAC,WAAW;YAC5C,OAAO,KAAK,CAAC;QACf,GACC,KAAK;IACV;IAEA,OAAO;QACL,MAAM,gBACJ,OAAO,IAAI,CAAC,EAAE,KAAK,WAAW,SAAS,aAAa,CAAC,IAAI,CAAC,EAAE,IAAI,IAAI,CAAC,EAAE;QAEzE,cAAc,gBAAgB,CAAC,SAAS;YACtC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK;QAC3B;IACF;AACF;IAEA,2CAAe","sources":["src/index.js"],"sourcesContent":["class ClickTone {\n constructor({ el = '', sound = '' } = {}) {\n this.el = el;\n this.sound = sound;\n\n this.audioContext = new (window.AudioContext ||\n window.webkitAudioContext)();\n this.setupIOSAudioContextFix();\n }\n\n setupIOSAudioContextFix() {\n if (this.audioContext.state === 'suspended' && 'ontouchstart' in window) {\n const unlock = () => {\n this.audioContext.resume().then(() => {\n document.body.removeEventListener('touchstart', unlock);\n document.body.removeEventListener('touchend', unlock);\n });\n };\n\n document.body.addEventListener('touchstart', unlock, false);\n document.body.addEventListener('touchend', unlock, false);\n }\n }\n\n playAudio(url) {\n fetch(url)\n .then((response) => response.arrayBuffer())\n .then((buffer) => this.audioContext.decodeAudioData(buffer))\n .then((audioData) => {\n const source = this.audioContext.createBufferSource();\n source.buffer = audioData;\n source.connect(this.audioContext.destination);\n source.start(0);\n })\n .catch();\n }\n\n init() {\n const targetElement =\n typeof this.el === 'string' ? document.querySelector(this.el) : this.el;\n\n targetElement.addEventListener('click', () => {\n this.playAudio(this.sound);\n });\n }\n}\n\nexport default ClickTone;\n"],"names":[],"version":3,"file":"index.js.map"}
@@ -1,5 +1,7 @@
1
1
  class $cf838c15c8b009ba$var$ClickTone {
2
- constructor(){
2
+ constructor({ el: el = "", sound: sound = "" } = {}){
3
+ this.el = el;
4
+ this.sound = sound;
3
5
  this.audioContext = new (window.AudioContext || window.webkitAudioContext)();
4
6
  this.setupIOSAudioContextFix();
5
7
  }
@@ -23,10 +25,10 @@ class $cf838c15c8b009ba$var$ClickTone {
23
25
  source.start(0);
24
26
  }).catch();
25
27
  }
26
- init(buttonId, audioFileUrl) {
27
- const button = document.getElementById(buttonId);
28
- button.addEventListener("click", ()=>{
29
- this.playAudio(audioFileUrl);
28
+ init() {
29
+ const targetElement = typeof this.el === "string" ? document.querySelector(this.el) : this.el;
30
+ targetElement.addEventListener("click", ()=>{
31
+ this.playAudio(this.sound);
30
32
  });
31
33
  }
32
34
  }
@@ -1 +1 @@
1
- {"mappings":"AAAA,MAAM;IACJ,aAAc;QACZ,IAAI,CAAC,YAAY,GAAG,IAAK,CAAA,OAAO,YAAY,IAAI,OAAO,kBAAkB,AAAD;QACxE,IAAI,CAAC,uBAAuB;IAC9B;IAEA,0BAA0B;QACxB,IAAI,IAAI,CAAC,YAAY,CAAC,KAAK,KAAK,eAAe,kBAAkB,QAAQ;YACvE,MAAM,SAAS;gBACb,IAAI,CAAC,YAAY,CAAC,MAAM,GAAG,IAAI,CAAC;oBAC9B,SAAS,IAAI,CAAC,mBAAmB,CAAC,cAAc;oBAChD,SAAS,IAAI,CAAC,mBAAmB,CAAC,YAAY;gBAChD;YACF;YAEA,SAAS,IAAI,CAAC,gBAAgB,CAAC,cAAc,QAAQ;YACrD,SAAS,IAAI,CAAC,gBAAgB,CAAC,YAAY,QAAQ;QACrD;IACF;IAEA,UAAU,GAAG,EAAE;QACb,MAAM,KACH,IAAI,CAAC,CAAC,WAAa,SAAS,WAAW,IACvC,IAAI,CAAC,CAAC,SAAW,IAAI,CAAC,YAAY,CAAC,eAAe,CAAC,SACnD,IAAI,CAAC,CAAC;YACL,MAAM,SAAS,IAAI,CAAC,YAAY,CAAC,kBAAkB;YACnD,OAAO,MAAM,GAAG;YAChB,OAAO,OAAO,CAAC,IAAI,CAAC,YAAY,CAAC,WAAW;YAC5C,OAAO,KAAK,CAAC;QACf,GACC,KAAK;IACV;IAEA,KAAK,QAAQ,EAAE,YAAY,EAAE;QAC3B,MAAM,SAAS,SAAS,cAAc,CAAC;QAEvC,OAAO,gBAAgB,CAAC,SAAS;YAC/B,IAAI,CAAC,SAAS,CAAC;QACjB;IACF;AACF;IAEA,2CAAe","sources":["src/index.js"],"sourcesContent":["class ClickTone {\n constructor() {\n this.audioContext = new (window.AudioContext || window.webkitAudioContext)();\n this.setupIOSAudioContextFix();\n }\n\n setupIOSAudioContextFix() {\n if (this.audioContext.state === 'suspended' && 'ontouchstart' in window) {\n const unlock = () => {\n this.audioContext.resume().then(() => {\n document.body.removeEventListener('touchstart', unlock);\n document.body.removeEventListener('touchend', unlock);\n });\n };\n\n document.body.addEventListener('touchstart', unlock, false);\n document.body.addEventListener('touchend', unlock, false);\n }\n }\n\n playAudio(url) {\n fetch(url)\n .then((response) => response.arrayBuffer())\n .then((buffer) => this.audioContext.decodeAudioData(buffer))\n .then((audioData) => {\n const source = this.audioContext.createBufferSource();\n source.buffer = audioData;\n source.connect(this.audioContext.destination);\n source.start(0);\n })\n .catch();\n }\n\n init(buttonId, audioFileUrl) {\n const button = document.getElementById(buttonId);\n\n button.addEventListener('click', () => {\n this.playAudio(audioFileUrl);\n });\n }\n}\n\nexport default ClickTone;\n"],"names":[],"version":3,"file":"index.module.js.map"}
1
+ {"mappings":"AAAA,MAAM;IACJ,YAAY,MAAE,KAAK,WAAI,QAAQ,IAAI,GAAG,CAAC,CAAC,CAAE;QACxC,IAAI,CAAC,EAAE,GAAG;QACV,IAAI,CAAC,KAAK,GAAG;QAEb,IAAI,CAAC,YAAY,GAAG,IAAK,CAAA,OAAO,YAAY,IAC1C,OAAO,kBAAkB,AAAD;QAC1B,IAAI,CAAC,uBAAuB;IAC9B;IAEA,0BAA0B;QACxB,IAAI,IAAI,CAAC,YAAY,CAAC,KAAK,KAAK,eAAe,kBAAkB,QAAQ;YACvE,MAAM,SAAS;gBACb,IAAI,CAAC,YAAY,CAAC,MAAM,GAAG,IAAI,CAAC;oBAC9B,SAAS,IAAI,CAAC,mBAAmB,CAAC,cAAc;oBAChD,SAAS,IAAI,CAAC,mBAAmB,CAAC,YAAY;gBAChD;YACF;YAEA,SAAS,IAAI,CAAC,gBAAgB,CAAC,cAAc,QAAQ;YACrD,SAAS,IAAI,CAAC,gBAAgB,CAAC,YAAY,QAAQ;QACrD;IACF;IAEA,UAAU,GAAG,EAAE;QACb,MAAM,KACH,IAAI,CAAC,CAAC,WAAa,SAAS,WAAW,IACvC,IAAI,CAAC,CAAC,SAAW,IAAI,CAAC,YAAY,CAAC,eAAe,CAAC,SACnD,IAAI,CAAC,CAAC;YACL,MAAM,SAAS,IAAI,CAAC,YAAY,CAAC,kBAAkB;YACnD,OAAO,MAAM,GAAG;YAChB,OAAO,OAAO,CAAC,IAAI,CAAC,YAAY,CAAC,WAAW;YAC5C,OAAO,KAAK,CAAC;QACf,GACC,KAAK;IACV;IAEA,OAAO;QACL,MAAM,gBACJ,OAAO,IAAI,CAAC,EAAE,KAAK,WAAW,SAAS,aAAa,CAAC,IAAI,CAAC,EAAE,IAAI,IAAI,CAAC,EAAE;QAEzE,cAAc,gBAAgB,CAAC,SAAS;YACtC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK;QAC3B;IACF;AACF;IAEA,2CAAe","sources":["src/index.js"],"sourcesContent":["class ClickTone {\n constructor({ el = '', sound = '' } = {}) {\n this.el = el;\n this.sound = sound;\n\n this.audioContext = new (window.AudioContext ||\n window.webkitAudioContext)();\n this.setupIOSAudioContextFix();\n }\n\n setupIOSAudioContextFix() {\n if (this.audioContext.state === 'suspended' && 'ontouchstart' in window) {\n const unlock = () => {\n this.audioContext.resume().then(() => {\n document.body.removeEventListener('touchstart', unlock);\n document.body.removeEventListener('touchend', unlock);\n });\n };\n\n document.body.addEventListener('touchstart', unlock, false);\n document.body.addEventListener('touchend', unlock, false);\n }\n }\n\n playAudio(url) {\n fetch(url)\n .then((response) => response.arrayBuffer())\n .then((buffer) => this.audioContext.decodeAudioData(buffer))\n .then((audioData) => {\n const source = this.audioContext.createBufferSource();\n source.buffer = audioData;\n source.connect(this.audioContext.destination);\n source.start(0);\n })\n .catch();\n }\n\n init() {\n const targetElement =\n typeof this.el === 'string' ? document.querySelector(this.el) : this.el;\n\n targetElement.addEventListener('click', () => {\n this.playAudio(this.sound);\n });\n }\n}\n\nexport default ClickTone;\n"],"names":[],"version":3,"file":"index.module.js.map"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clicktone",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "A simple class to create elements that play audio when clicked.",
5
5
  "author": "ux-ui.pro",
6
6
  "license": "MIT",
package/src/index.js CHANGED
@@ -1,6 +1,10 @@
1
1
  class ClickTone {
2
- constructor() {
3
- this.audioContext = new (window.AudioContext || window.webkitAudioContext)();
2
+ constructor({ el = '', sound = '' } = {}) {
3
+ this.el = el;
4
+ this.sound = sound;
5
+
6
+ this.audioContext = new (window.AudioContext ||
7
+ window.webkitAudioContext)();
4
8
  this.setupIOSAudioContextFix();
5
9
  }
6
10
 
@@ -31,11 +35,12 @@ class ClickTone {
31
35
  .catch();
32
36
  }
33
37
 
34
- init(buttonId, audioFileUrl) {
35
- const button = document.getElementById(buttonId);
38
+ init() {
39
+ const targetElement =
40
+ typeof this.el === 'string' ? document.querySelector(this.el) : this.el;
36
41
 
37
- button.addEventListener('click', () => {
38
- this.playAudio(audioFileUrl);
42
+ targetElement.addEventListener('click', () => {
43
+ this.playAudio(this.sound);
39
44
  });
40
45
  }
41
46
  }