From b9e559d46520487ef94ad7311fab50d44f29e86a Mon Sep 17 00:00:00 2001 From: Donald Hanson Date: Sat, 28 Jul 2018 19:24:20 -0700 Subject: [PATCH] 1.0.1 --- example/codeKeyframes.js | 110 +++++++++++++++++++++++++++++------ example/codeKeyframes.min.js | 2 +- src/js/app/main.js | 110 +++++++++++++++++++++++++++++------ 3 files changed, 183 insertions(+), 39 deletions(-) diff --git a/example/codeKeyframes.js b/example/codeKeyframes.js index aca6b8b..0593848 100644 --- a/example/codeKeyframes.js +++ b/example/codeKeyframes.js @@ -32,6 +32,7 @@ function CodeKeyframes(args){ this.activeRegion = null this.skipLength = 1 this.zoom = 30 + this.nudging = false this.sequence = [] this.sequenceCursor = 0 @@ -90,6 +91,7 @@ function CodeKeyframes(args){ this.activeRegion.data.code = this._code.value this.saveRegions() this.updateSequence() + this.runRegionCode(this.activeRegion) } this._code.onkeydown = (e) => { @@ -116,15 +118,32 @@ function CodeKeyframes(args){ this._code.value = JSON.stringify(keyframes) } - document.onkeydown = (e) =>{ + this._editor.onkeydown = (e) =>{ + + console.log(e.which) var keycodes = { // left - 37:()=>{ this.wavesurfer.skip(this.skipLength*-1) }, + 37:()=>{ + + if( this.nudging ){ + this.nudgeActiveRegion('left') + }else{ + this.wavesurfer.skip(this.skipLength*-1) + } + + + }, // right - 39:()=>{ this.wavesurfer.skip(this.skipLength) }, + 39:()=>{ + if( this.nudging ){ + this.nudgeActiveRegion('right') + }else{ + this.wavesurfer.skip(this.skipLength) + } + }, // up 38:()=>{ @@ -144,6 +163,13 @@ function CodeKeyframes(args){ e.preventDefault() }, + // alt + 18:()=>{ + this.nudging = true + // alert(this.nudging) + e.preventDefault() + }, + // enter 13:()=>{ @@ -164,6 +190,9 @@ function CodeKeyframes(args){ // space 32:()=>{ + + console.log("PLAYPAUSE") + this.wavesurfer.playPause() this._code.classList.remove('error') }, @@ -178,6 +207,16 @@ function CodeKeyframes(args){ this.editCode( this.getPrevRegion() ) }, + // left bracket + 219:()=>{ + this.editCode( this.getPrevRegion() ) + }, + + // right bracket + 221:()=>{ + this.editCode( this.getNextRegion() ) + }, + // delete 46:()=>{ this.activeRegion.remove() @@ -185,6 +224,13 @@ function CodeKeyframes(args){ this.updateSequence() }, + // delete (backspace) + 8:()=>{ + this.activeRegion.remove() + this.saveRegions() + this.updateSequence() + }, + } @@ -200,7 +246,12 @@ function CodeKeyframes(args){ // shift 16:()=>{ this.skipLength = 1 - } + }, + + // alt + 18:()=>{ + this.nudging = false + }, } if( keycodes[e.which] ){ @@ -308,11 +359,34 @@ function CodeKeyframes(args){ } } + this.nudgeActiveRegion = (direction) => { + + region = this.activeRegion + nudgeAmount = (direction == 'left') ? -.1 : .1 + + this.activeRegion = this.wavesurfer.addRegion({ + start: region.start + nudgeAmount, + end: region.end +nudgeAmount, + data: region.data, + drag: false, + resize: false + }) + + this.activeRegion.element.classList.add('active') + region.remove() + this.saveRegions() + + } + this.editCode = function(region, seek = true) { - if( !this.editorOpen ) return if(!region) return + // execute the keyframe code + this.runRegionCode(region) + + if( !this.editorOpen ) return + // remove active class from all regions _regions = this._editor.querySelectorAll('region') for (var i = _regions.length - 1; i >= 0; i--) { @@ -325,7 +399,6 @@ function CodeKeyframes(args){ if( seek ){ this.wavesurfer.seekAndCenter( (region.start / this.wavesurfer.getDuration())) } - // show the code for this region this._code.value = region.data.code @@ -335,6 +408,17 @@ function CodeKeyframes(args){ } + this.runRegionCode = function(region){ + this._code.classList.remove('error') + + try{ + eval(region.data.code) + } catch(error){ + this._code.classList.add('error') + console.log(error) + } + }, + this.getNextRegion = function(){ if( !this.editorOpen ) return @@ -448,17 +532,7 @@ function CodeKeyframes(args){ var command = this.sequence[this.sequenceCursor] if( !command ) return if( time > command.time ){ - this.sequenceCursor++ - - this._code.classList.remove('error') - - try{ - eval(command.code) - } catch(error){ - this._code.classList.add('error') - console.log(error) - } - + this.sequenceCursor++ // find the region to show var regions = this.wavesurfer.regions.list @@ -471,6 +545,4 @@ function CodeKeyframes(args){ } }) - - } \ No newline at end of file diff --git a/example/codeKeyframes.min.js b/example/codeKeyframes.min.js index 496ddf8..4d3a9ba 100644 --- a/example/codeKeyframes.min.js +++ b/example/codeKeyframes.min.js @@ -1 +1 @@ -function CodeKeyframes(args){if(args.audioPath){this.audioPath=args.audioPath,this.editorOpen=args.editorOpen||!1,this.keyframes=args.keyframes||[],this.label=args.label,this.autoplay=args.autoplay||!1,this.activeRegion=null,this.skipLength=1,this.zoom=30,this.sequence=[],this.sequenceCursor=0,this.sequenceNextTime=null,document.querySelector("body").insertAdjacentHTML("beforeend",'\n
\n
\n
\n \n \n
\n
'),this._editor=document.querySelector("#ckf-editor"),this._waveform=document.querySelector("#ckf-editor #waveform"),this._codeForm=document.querySelector("#ckf-editor .code-form"),this._code=document.querySelector("#ckf-editor #code"),this._renderButton=document.querySelector("#ckf-editor .render"),this.label&&(_label=document.createElement("div"),_label.innerHTML=this.label,_label.classList.add("ckf-label"),this._editor.appendChild(_label)),this.editorOpen||(this._editor.classList.add("closed"),this._codeForm.remove()),this._code.onkeyup=(e=>{this.activeRegion.data.code=this._code.value,this.saveRegions(),this.updateSequence()}),this._code.onkeydown=(e=>{33!=e.which&&34!=e.which&&e.stopPropagation()}),this._renderButton.onclick=(e=>{var t=[];this.wavesurfer.regions.list;for(var r in this.wavesurfer.regions.list){var i=this.wavesurfer.regions.list[r];t.push({start:i.start,end:i.end,data:i.data})}this.activeRegion=null,this._code.value=JSON.stringify(t)}),document.onkeydown=(e=>{var t={37:()=>{this.wavesurfer.skip(-1*this.skipLength)},39:()=>{this.wavesurfer.skip(this.skipLength)},38:()=>{this.zoom+=.5,this.wavesurfer.zoom(this.zoom)},40:()=>{this.zoom-=.5,this.wavesurfer.zoom(this.zoom)},16:()=>{this.skipLength=.1,e.preventDefault()},13:()=>{var e=this.wavesurfer.addRegion({start:this.wavesurfer.getCurrentTime(),end:this.wavesurfer.getCurrentTime()+.1,drag:!1,resize:!1,data:{code:this._code.value}});this.editCode(e),this.saveRegions(),this.updateSequence()},32:()=>{this.wavesurfer.playPause(),this._code.classList.remove("error")},33:()=>{this.editCode(this.getNextRegion())},34:()=>{this.editCode(this.getPrevRegion())},46:()=>{this.activeRegion.remove(),this.saveRegions(),this.updateSequence()}};t[e.which]&&t[e.which]()}),this._editor.onkeyup=(e=>{var t={16:()=>{this.skipLength=1}};t[e.which]&&t[e.which]()}),this.saveRegions=(()=>{this.editorOpen&&(localStorage.regions=JSON.stringify(Object.keys(this.wavesurfer.regions.list).map(e=>{var t=this.wavesurfer.regions.list[e];return{start:t.start,end:t.end,data:t.data}})))}),this.loadRegions=function(e){var t=this.keyframes,r=[];localStorage.regions&&(r=JSON.parse(localStorage.regions));for(var i=[],n=t.concat(r),a=n.length;a--;){var s=n[a];unique=!0;for(var o=i.length-1;o>=0;o--)i[o].start==s.start&&(unique=!1);unique&&i.unshift(s)}i.forEach(e=>{this.wavesurfer.addRegion({start:e.start,end:e.end,data:e.data,drag:!1,resize:!1})})},this.updateSequence=(()=>{this.sequence=[];var e=this.wavesurfer.regions.list;for(var t in e){var r={time:e[t].start,code:e[t].data.code};this.sequence.push(r)}this.sequence.sort(function(e,t){return e.time>t.time?1:e.time=0;r--)_regions[r].classList.remove("active");e.element.classList.add("active"),t&&this.wavesurfer.seekAndCenter(e.start/this.wavesurfer.getDuration()),this._code.value=e.data.code,this.activeRegion=e}},this.getNextRegion=function(){if(this.editorOpen){var e=-1;this.activeRegion&&(e=this.activeRegion.start);var t=[];for(var r in this.wavesurfer.regions.list){var i=this.wavesurfer.regions.list[r];i.start>e&&t.push(i)}return t.sort(function(e,t){return e.start>t.start?1:e.startt.start?-1:e.start==t.start?0:void 0}),t[0]}};var waveHeight=100;this.editorOpen||(waveHeight=50);var waveColor=args.waveColor||"#3AEAD2",progressColor=args.progressColor||"#0c9fa7";this.wavesurfer=WaveSurfer.create({container:"#ckf-waveform",height:waveHeight,scrollParent:!0,normalize:!0,waveColor:waveColor,progressColor:progressColor,barWidth:1,cursorColor:"#fff",plugins:[WaveSurfer.cursor.create(),WaveSurfer.regions.create()]}),this.wavesurfer.load(this.audioPath),this.wavesurfer.on("ready",e=>{this.wavesurfer.zoom(this.zoom),this.loadRegions(),this.updateSequence(),this.autoplay&&this.wavesurfer.play()}),this.wavesurfer.on("region-click",e=>{this.editCode(e),this.updateSequence()}),this.wavesurfer.on("seek",()=>{this.updateSequence()}),this.wavesurfer.on("audioprocess",()=>{var time=this.wavesurfer.getCurrentTime(),command=this.sequence[this.sequenceCursor];if(command&&time>command.time){this.sequenceCursor++,this._code.classList.remove("error");try{eval(command.code)}catch(e){this._code.classList.add("error"),console.log(e)}var regions=this.wavesurfer.regions.list;for(var key in regions)if(regions[key].start==command.time){this.editCode(regions[key],!1);break}}})}}!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("WaveSurfer",[],t):"object"==typeof exports?exports.WaveSurfer=t():e.WaveSurfer=t()}(window,function(){return function(e){var t={};function r(i){if(t[i])return t[i].exports;var n=t[i]={i:i,l:!1,exports:{}};return e[i].call(n.exports,n,n.exports,r),n.l=!0,n.exports}return r.m=e,r.c=t,r.d=function(e,t,i){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:i})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var i=Object.create(null);if(r.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var n in e)r.d(i,n,function(t){return e[t]}.bind(null,n));return i},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=17)}([function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var i=r(16);Object.defineProperty(t,"ajax",{enumerable:!0,get:function(){return p(i).default}});var n=r(15);Object.defineProperty(t,"getId",{enumerable:!0,get:function(){return p(n).default}});var a=r(14);Object.defineProperty(t,"max",{enumerable:!0,get:function(){return p(a).default}});var s=r(13);Object.defineProperty(t,"min",{enumerable:!0,get:function(){return p(s).default}});var o=r(3);Object.defineProperty(t,"Observer",{enumerable:!0,get:function(){return p(o).default}});var u=r(12);Object.defineProperty(t,"extend",{enumerable:!0,get:function(){return p(u).default}});var l=r(11);Object.defineProperty(t,"style",{enumerable:!0,get:function(){return p(l).default}});var c=r(2);Object.defineProperty(t,"requestAnimationFrame",{enumerable:!0,get:function(){return p(c).default}});var h=r(10);Object.defineProperty(t,"frame",{enumerable:!0,get:function(){return p(h).default}});var d=r(9);Object.defineProperty(t,"debounce",{enumerable:!0,get:function(){return p(d).default}});var f=r(8);function p(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(t,"preventClick",{enumerable:!0,get:function(){return p(f).default}})},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var i=function(){function e(e,t){for(var r=0;r=e.getDuration()?(e.setState(u),e.fireEvent("pause")):t>=e.scheduledPause?e.pause():e.state===e.states[s]&&e.fireEvent("audioprocess",t)}}},{key:"removeOnAudioProcess",value:function(){this.scriptNode.onaudioprocess=null}},{key:"createAnalyserNode",value:function(){this.analyser=this.ac.createAnalyser(),this.analyser.connect(this.gainNode)}},{key:"createVolumeNode",value:function(){this.ac.createGain?this.gainNode=this.ac.createGain():this.gainNode=this.ac.createGainNode(),this.gainNode.connect(this.ac.destination)}},{key:"setSinkId",value:function(e){if(e){var t=new window.Audio;if(!t.setSinkId)return Promise.reject(new Error("setSinkId is not supported in your browser"));t.autoplay=!0;var r=this.ac.createMediaStreamDestination();return this.gainNode.disconnect(),this.gainNode.connect(r),t.src=URL.createObjectURL(r.stream),t.setSinkId(e)}return Promise.reject(new Error("Invalid deviceId: "+e))}},{key:"setVolume",value:function(e){this.gainNode.gain.setValueAtTime(e,this.ac.currentTime)}},{key:"getVolume",value:function(){return this.gainNode.gain.value}},{key:"decodeArrayBuffer",value:function(e,t,r){this.offlineAc||(this.offlineAc=this.getOfflineAudioContext(this.ac?this.ac.sampleRate:44100)),this.offlineAc.decodeAudioData(e,function(e){return t(e)},r)}},{key:"setPeaks",value:function(e,t){this.explicitDuration=t,this.peaks=e}},{key:"setLength",value:function(e){if(!this.mergedPeaks||e!=2*this.mergedPeaks.length-1+2){this.splitPeaks=[],this.mergedPeaks=[];var t=this.buffer?this.buffer.numberOfChannels:1,r=void 0;for(r=0;rp&&(p=m),mthis.mergedPeaks[2*c])&&(this.mergedPeaks[2*c]=p),(0==o||f=this.getDuration()&&(e=0),null==t&&(t=this.getDuration()),this.startPosition=e,this.lastPlay=this.ac.currentTime,this.state===this.states[u]&&this.setState(o),{start:e,end:t}}},{key:"getPlayedTime",value:function(){return(this.ac.currentTime-this.lastPlay)*this.playbackRate}},{key:"play",value:function(e,t){if(this.buffer){this.createSource();var r=this.seekTo(e,t);e=r.start,t=r.end,this.scheduledPause=t,this.source.start(0,e,t-e),"suspended"==this.ac.state&&this.ac.resume&&this.ac.resume(),this.setState(s),this.fireEvent("play")}}},{key:"pause",value:function(){this.scheduledPause=null,this.startPosition+=this.getPlayedTime(),this.source&&this.source.stop(0),this.setState(o),this.fireEvent("pause")}},{key:"getCurrentTime",value:function(){return this.state.getCurrentTime.call(this)}},{key:"getPlaybackRate",value:function(){return this.playbackRate}},{key:"setPlaybackRate",value:function(e){e=e||1,this.isPaused()?this.playbackRate=e:(this.pause(),this.playbackRate=e,this.play())}}]),t}();l.scriptBufferSize=256,t.default=l,e.exports=t.default},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=(window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||function(e,t){return setTimeout(e,1e3/60)}).bind(window),e.exports=t.default},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var i=function(){function e(e,t){for(var r=0;r=0;i--)r[i]==t&&r.splice(i,1);else r.length=0}}},{key:"unAll",value:function(){this.handlers=null}},{key:"once",value:function(e,t){var r=this;return this.on(e,function i(){for(var n=arguments.length,a=Array(n),s=0;s1?t-1:0),i=1;i=1/0&&(e=this.media.seekable.end(0)),e}},{key:"getCurrentTime",value:function(){return this.media&&this.media.currentTime}},{key:"getPlayedPercents",value:function(){return this.getCurrentTime()/this.getDuration()||0}},{key:"getPlaybackRate",value:function(){return this.playbackRate||this.media.playbackRate}},{key:"setPlaybackRate",value:function(e){this.playbackRate=e||1,this.media.playbackRate=this.playbackRate}},{key:"seekTo",value:function(e){null!=e&&(this.media.currentTime=e),this.clearPlayEnd()}},{key:"play",value:function(e,t){this.seekTo(e);var r=this.media.play();return t&&this.setPlayEnd(t),r}},{key:"pause",value:function(){var e=void 0;return this.media&&(e=this.media.pause()),this.clearPlayEnd(),e}},{key:"setPlayEnd",value:function(e){var t=this;this._onPlayEnd=function(r){r>=e&&(t.pause(),t.seekTo(e))},this.on("audioprocess",this._onPlayEnd)}},{key:"clearPlayEnd",value:function(){this._onPlayEnd&&(this.un("audioprocess",this._onPlayEnd),this._onPlayEnd=null)}},{key:"getPeaks",value:function(e,r,i){return this.buffer?function e(t,r,i){null===t&&(t=Function.prototype);var n=Object.getOwnPropertyDescriptor(t,r);if(void 0===n){var a=Object.getPrototypeOf(t);return null===a?void 0:e(a,r,i)}if("value"in n)return n.value;var s=n.get;return void 0!==s?s.call(i):void 0}(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),"getPeaks",this).call(this,e,r,i):this.peaks||[]}},{key:"setSinkId",value:function(e){return e?this.media.setSinkId?this.media.setSinkId(e):Promise.reject(new Error("setSinkId is not supported in your browser")):Promise.reject(new Error("Invalid deviceId: "+e))}},{key:"getVolume",value:function(){return this.volume||this.media.volume}},{key:"setVolume",value:function(e){this.volume=e,this.media.volume=this.volume}},{key:"destroy",value:function(){this.pause(),this.unAll(),this.params.removeMediaElementOnDestroy&&this.media&&this.media.parentNode&&this.media.parentNode.removeChild(this.media),this.media=null}}]),t}();t.default=s,e.exports=t.default},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var i=function(){function e(e,t){for(var r=0;r1&&(s=1):s=(r-i.left+this.wrapper.scrollLeft)/this.wrapper.scrollWidth||0,s}},{key:"setupWrapperEvents",value:function(){var e=this;this.wrapper.addEventListener("click",function(t){var r=e.wrapper.offsetHeight-e.wrapper.clientHeight;if(0!=r){var i=e.wrapper.getBoundingClientRect();if(t.clientY>=i.bottom-r)return}e.params.interact&&e.fireEvent("click",t,e.handleEvent(t))}),this.wrapper.addEventListener("scroll",function(t){return e.fireEvent("scroll",t)})}},{key:"drawPeaks",value:function(e,t,r,i){this.setWidth(t)||this.clearWave(),this.params.barWidth?this.drawBars(e,0,r,i):this.drawWave(e,0,r,i)}},{key:"resetScroll",value:function(){null!==this.wrapper&&(this.wrapper.scrollLeft=0)}},{key:"recenter",value:function(e){var t=this.wrapper.scrollWidth*e;this.recenterOnPosition(t,!0)}},{key:"recenterOnPosition",value:function(e,t){var r=this.wrapper.scrollLeft,i=~~(this.wrapper.clientWidth/2),n=this.wrapper.scrollWidth-this.wrapper.clientWidth,a=e-i,s=a-r;0!=n&&(!t&&-i<=s&&s=t){if(this.lastPos=r,this.params.scrollParent&&this.params.autoCenter){var i=~~(this.wrapper.scrollWidth*e);this.recenterOnPosition(i)}this.updateProgress(r)}}},{key:"destroy",value:function(){this.unAll(),this.wrapper&&(this.wrapper.parentNode==this.container&&this.container.removeChild(this.wrapper),this.wrapper=null)}},{key:"updateCursor",value:function(){}},{key:"updateSize",value:function(){}},{key:"drawBars",value:function(e,t,r,i){}},{key:"drawWave",value:function(e,t,r,i){}},{key:"clearWave",value:function(){}},{key:"updateProgress",value:function(e){}}]),t}();t.default=a,e.exports=t.default},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var i,n=function(){function e(e,t){for(var r=0;rr;)this.removeCanvas();this.canvases.forEach(function(t,r){var i=e.maxCanvasWidth+2*Math.ceil(e.params.pixelRatio/2);r==e.canvases.length-1&&(i=e.width-e.maxCanvasWidth*(e.canvases.length-1)),e.updateDimensions(t,i,e.height),e.clearWaveForEntry(t)})}},{key:"addCanvas",value:function(){var e={},t=this.maxCanvasElementWidth*this.canvases.length;e.wave=this.wrapper.appendChild(this.style(document.createElement("canvas"),{position:"absolute",zIndex:2,left:t+"px",top:0,bottom:0,height:"100%",pointerEvents:"none"})),e.waveCtx=e.wave.getContext("2d"),this.hasProgressCanvas&&(e.progress=this.progressWave.appendChild(this.style(document.createElement("canvas"),{position:"absolute",left:t+"px",top:0,bottom:0,height:"100%"})),e.progressCtx=e.progress.getContext("2d")),this.canvases.push(e)}},{key:"removeCanvas",value:function(){var e=this.canvases.pop();e.wave.parentElement.removeChild(e.wave),this.hasProgressCanvas&&e.progress.parentElement.removeChild(e.progress)}},{key:"updateDimensions",value:function(e,t,r){var i=Math.round(t/this.params.pixelRatio),n=Math.round(this.width/this.params.pixelRatio);e.start=e.waveCtx.canvas.offsetLeft/n||0,e.end=e.start+i/n,e.waveCtx.canvas.width=t,e.waveCtx.canvas.height=r,this.style(e.waveCtx.canvas,{width:i+"px"}),this.style(this.progressWave,{display:"block"}),this.hasProgressCanvas&&(e.progressCtx.canvas.width=t,e.progressCtx.canvas.height=r,this.style(e.progressCtx.canvas,{width:i+"px"}))}},{key:"clearWave",value:function(){var e=this;this.canvases.forEach(function(t){return e.clearWaveForEntry(t)})}},{key:"clearWaveForEntry",value:function(e){e.waveCtx.clearRect(0,0,e.waveCtx.canvas.width,e.waveCtx.canvas.height),this.hasProgressCanvas&&e.progressCtx.clearRect(0,0,e.progressCtx.canvas.width,e.progressCtx.canvas.height)}},{key:"drawBars",value:function(e,t,r,i){var n=this;return this.prepareDraw(e,t,r,i,function(e){var t=e.absmax,a=e.hasMinVals,s=(e.height,e.offsetY),o=e.halfH,u=e.peaks;if(void 0!==r){var l=a?2:1,c=u.length/l,h=n.params.barWidth*n.params.pixelRatio,d=h+(null===n.params.barGap?Math.max(n.params.pixelRatio,~~(h/2)):Math.max(n.params.pixelRatio,n.params.barGap*n.params.pixelRatio)),f=c/n.width,p=i,v=void 0;for(v=r;vo||h=d;v--){var g=r[2*v+1]||0,w=Math.round(g/i*n);t.lineTo((v-c)*l+this.halfPixel,n-w+a)}t.closePath(),t.fill()}}}},{key:"fillRect",value:function(e,t,r,i){var n=Math.floor(e/this.maxCanvasWidth),a=Math.min(Math.ceil((e+r)/this.maxCanvasWidth)+1,this.canvases.length),s=void 0;for(s=n;sl?-c:l}var h=[].some.call(e,function(e){return e<0}),d=a.params.height*a.params.pixelRatio;return n({absmax:u,hasMinVals:h,height:d,offsetY:d*t||0,halfH:d/2,peaks:e})})()}},{key:"fillRectToContext",value:function(e,t,r,i,n){e&&e.fillRect(t,r,i,n)}},{key:"setFillStyles",value:function(e){e.waveCtx.fillStyle=this.params.waveColor,this.hasProgressCanvas&&(e.progressCtx.fillStyle=this.params.progressColor)}},{key:"getImage",value:function(e,t){var r=this.canvases.map(function(r){return r.wave.toDataURL(e,t)});return r.length>1?r:r[0]}},{key:"updateProgress",value:function(e){this.style(this.progressWave,{width:e+"px"})}}]),t}();t.default=o,e.exports=t.default},function(e,t,r){"use strict";function i(e){e.stopPropagation(),document.body.removeEventListener("click",i,!0)}Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e){document.body.addEventListener("click",i,!0)},e.exports=t.default},function(e,t){e.exports=function(e,t,r){var i,n,a,s,o;function u(){var l=Date.now()-s;l=0?i=setTimeout(u,t-l):(i=null,r||(o=e.apply(a,n),a=n=null))}null==t&&(t=100);var l=function(){a=this,n=arguments,s=Date.now();var l=r&&!i;return i||(i=setTimeout(u,t)),l&&(o=e.apply(a,n),a=n=null),o};return l.clear=function(){i&&(clearTimeout(i),i=null)},l.flush=function(){i&&(o=e.apply(a,n),a=n=null,clearTimeout(i),i=null)},l}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e){return function(){for(var t=arguments.length,r=Array(t),i=0;i1?t-1:0),i=1;it&&(t=e[r])}),t},e.exports=t.default},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(){return"wavesurfer_"+Math.random().toString(32).substring(2)},e.exports=t.default},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e){var t=new n.default,r=new XMLHttpRequest,i=!1;return r.open(e.method||"GET",e.url,!0),r.responseType=e.responseType||"json",e.xhr&&(e.xhr.requestHeaders&&e.xhr.requestHeaders.forEach(function(e){r.setRequestHeader(e.key,e.value)}),e.xhr.withCredentials&&(r.withCredentials=!0)),r.addEventListener("progress",function(e){t.fireEvent("progress",e),e.lengthComputable&&e.loaded==e.total&&(i=!0)}),r.addEventListener("load",function(e){i||t.fireEvent("progress",e),t.fireEvent("load",e),200==r.status||206==r.status?t.fireEvent("success",r.response,e):t.fireEvent("error",e)}),r.addEventListener("error",function(e){return t.fireEvent("error",e)}),r.send(),t.xhr=r,t};var i,n=(i=r(3))&&i.__esModule?i:{default:i};e.exports=t.default},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var i=function(){function e(e,t){for(var r=0;r=this.getDuration()?this.seekTo(1):this.seekTo(e/this.getDuration())}},{key:"play",value:function(e,t){var r=this;return this.fireEvent("interaction",function(){return r.play(e,t)}),this.backend.play(e,t)}},{key:"pause",value:function(){if(!this.backend.isPaused())return this.backend.pause()}},{key:"playPause",value:function(){return this.backend.isPaused()?this.play():this.pause()}},{key:"isPlaying",value:function(){return!this.backend.isPaused()}},{key:"skipBackward",value:function(e){this.skip(-e||-this.params.skipLength)}},{key:"skipForward",value:function(e){this.skip(e||this.params.skipLength)}},{key:"skip",value:function(e){var t=this.getDuration()||1,r=this.getCurrentTime()||0;r=Math.max(0,Math.min(t,r+(e||0))),this.seekAndCenter(r/t)}},{key:"seekAndCenter",value:function(e){this.seekTo(e),this.drawer.recenter(e)}},{key:"seekTo",value:function(e){var t=this;if("number"!=typeof e||!isFinite(e)||e<0||e>1)return console.error("Error calling wavesurfer.seekTo, parameter must be a number between 0 and 1!");this.fireEvent("interaction",function(){return t.seekTo(e)});var r=this.backend.isPaused();r||this.backend.pause();var i=this.params.scrollParent;this.params.scrollParent=!1,this.backend.seekTo(e*this.getDuration()),this.drawer.progress(e),r||this.backend.play(),this.params.scrollParent=i,this.fireEvent("seek",e)}},{key:"stop",value:function(){this.pause(),this.seekTo(0),this.drawer.progress(0)}},{key:"setSinkId",value:function(e){return this.backend.setSinkId(e)}},{key:"setVolume",value:function(e){this.backend.setVolume(e),this.fireEvent("volume",e)}},{key:"getVolume",value:function(){return this.backend.getVolume()}},{key:"setPlaybackRate",value:function(e){this.backend.setPlaybackRate(e)}},{key:"getPlaybackRate",value:function(){return this.backend.getPlaybackRate()}},{key:"toggleMute",value:function(){this.setMute(!this.isMuted)}},{key:"setMute",value:function(e){e!==this.isMuted?(e?(this.savedVolume=this.backend.getVolume(),this.backend.setVolume(0),this.isMuted=!0,this.fireEvent("volume",0)):(this.backend.setVolume(this.savedVolume),this.isMuted=!1,this.fireEvent("volume",this.savedVolume)),this.fireEvent("mute",this.isMuted)):this.fireEvent("mute",this.isMuted)}},{key:"getMute",value:function(){return this.isMuted}},{key:"isReady",value:function(){return this.isReady}},{key:"getFilters",value:function(){return this.backend.filters||[]}},{key:"toggleScroll",value:function(){this.params.scrollParent=!this.params.scrollParent,this.drawBuffer()}},{key:"toggleInteraction",value:function(){this.params.interact=!this.params.interact}},{key:"getWaveColor",value:function(){return this.params.waveColor}},{key:"setWaveColor",value:function(e){this.params.waveColor=e,this.drawBuffer()}},{key:"getProgressColor",value:function(){return this.params.progressColor}},{key:"setProgressColor",value:function(e){this.params.progressColor=e,this.drawBuffer()}},{key:"getCursorColor",value:function(){return this.params.cursorColor}},{key:"setCursorColor",value:function(e){this.params.cursorColor=e,this.drawer.updateCursor()}},{key:"getHeight",value:function(){return this.params.height}},{key:"setHeight",value:function(e){this.params.height=e,this.drawer.setHeight(e*this.params.pixelRatio),this.drawBuffer()}},{key:"drawBuffer",value:function(){var e=Math.round(this.getDuration()*this.params.minPxPerSec*this.params.pixelRatio),t=this.drawer.getWidth(),r=e,i=this.drawer.getScrollX(),n=Math.max(i+t,r);this.params.fillParent&&(!this.params.scrollParent||ee&&(this.end=e,this.start=e-(this.end-this.start)),null!=this.minLength&&(this.end=Math.max(this.start+this.minLength,this.end)),null!=this.maxLength&&(this.end=Math.min(this.start+this.maxLength,this.end)),null!=this.element){var r=Math.round(this.start/e*t),i=Math.round(this.end/e*t)-r;for(var n in this.style(this.element,{left:r+"px",width:i+"px",backgroundColor:this.color,cursor:this.drag?"move":"default"}),this.attributes)this.element.setAttribute("data-region-"+n,this.attributes[n]);this.element.title=this.formatTime(this.start,this.end)}}},{key:"bindInOut",value:function(){var e=this;this.firedIn=!1,this.firedOut=!1;var t=function(t){!e.firedOut&&e.firedIn&&(e.start>=Math.round(100*t)/100||e.end<=Math.round(100*t)/100)&&(e.firedOut=!0,e.firedIn=!1,e.fireEvent("out"),e.wavesurfer.fireEvent("region-out",e)),!e.firedIn&&e.start<=t&&e.end>t&&(e.firedIn=!0,e.firedOut=!1,e.fireEvent("in"),e.wavesurfer.fireEvent("region-in",e))};this.wavesurfer.backend.on("audioprocess",t),this.on("remove",function(){e.wavesurfer.backend.un("audioprocess",t)}),this.on("out",function(){e.loop&&e.wavesurfer.play(e.start)})}},{key:"bindEvents",value:function(){var e,t,r,i,n,a,s,o,u,l,c,h,d,f,p,v=this;this.element.addEventListener("mouseenter",function(e){v.fireEvent("mouseenter",e),v.wavesurfer.fireEvent("region-mouseenter",v,e)}),this.element.addEventListener("mouseleave",function(e){v.fireEvent("mouseleave",e),v.wavesurfer.fireEvent("region-mouseleave",v,e)}),this.element.addEventListener("click",function(e){e.preventDefault(),v.fireEvent("click",e),v.wavesurfer.fireEvent("region-click",v,e)}),this.element.addEventListener("dblclick",function(e){e.stopPropagation(),e.preventDefault(),v.fireEvent("dblclick",e),v.wavesurfer.fireEvent("region-dblclick",v,e)}),(this.drag||this.resize)&&(e=v.wavesurfer.drawer.container,t=v.wavesurfer.getDuration(),r=v.scrollSpeed,i=v.scrollThreshold,n=void 0,a=void 0,s=void 0,o=void 0,u=void 0,l=!1,c=void 0,h=void 0,d=function(e){e.touches&&e.touches.length>1||(a=e.targetTouches?e.targetTouches[0].identifier:null,e.stopPropagation(),n=v.wavesurfer.drawer.handleEvent(e,!0)*t,o=v.wrapper.scrollWidth-v.wrapper.clientWidth,h=v.wrapper.getBoundingClientRect(),"handle"==e.target.tagName.toLowerCase()?u=e.target.classList.contains("wavesurfer-handle-start")?"start":"end":(s=!0,u=!1))},f=function(e){e.touches&&e.touches.length>1||((s||u)&&(s=!1,c=null,u=!1),l&&(l=!1,v.util.preventClick(),v.fireEvent("update-end",e),v.wavesurfer.fireEvent("region-update-end",v,e)))},p=function(d){if(!(d.touches&&d.touches.length>1)&&(!d.targetTouches||d.targetTouches[0].identifier==a)&&(s||u)){var f=n,p=v.wavesurfer.drawer.handleEvent(d)*t,m=p-n;if(n=p,v.drag&&s&&(l=l||!!m,v.onDrag(m)),v.resize&&u&&(l=l||!!m,v.onResize(m,u)),v.scroll&&e.clientWidth=0?c=-1:p>f&&g+y.width<=h.right&&(c=1),(-1===c&&g>i||1===c&&g+y.width=h.right-i?1:null}c&&function e(i){if(c&&(s||u)){var a=v.wrapper.scrollLeft+r*c;v.wrapper.scrollLeft=a=Math.min(o,Math.max(0,a));var l=v.wavesurfer.drawer.handleEvent(i)*t,h=l-n;n=l,s?v.onDrag(h):v.onResize(h,u),window.requestAnimationFrame(function(){e(i)})}}(d)}}},v.element.addEventListener("mousedown",d),v.element.addEventListener("touchstart",d),v.wrapper.addEventListener("mousemove",p),v.wrapper.addEventListener("touchmove",p),document.body.addEventListener("mouseup",f),document.body.addEventListener("touchend",f),v.on("remove",function(){document.body.removeEventListener("mouseup",f),document.body.removeEventListener("touchend",f),v.wrapper.removeEventListener("mousemove",p),v.wrapper.removeEventListener("touchmove",p)}),v.wavesurfer.on("destroy",function(){document.body.removeEventListener("mouseup",f),document.body.removeEventListener("touchend",f)}))}},{key:"onDrag",value:function(e){var t=this.wavesurfer.getDuration();this.end+e>t||this.start+e<0||this.update({start:this.start+e,end:this.end+e})}},{key:"onResize",value:function(e,t){"start"==t?this.update({start:Math.min(this.start+e,this.end),end:Math.max(this.start+e,this.end)}):this.update({start:Math.min(this.end+e,this.start),end:Math.max(this.end+e,this.start)})}}]),e}(),s=function(){function e(t,r){var i=this;n(this,e),this.params=t,this.wavesurfer=r,this.util=r.util,Object.getOwnPropertyNames(this.util.Observer.prototype).forEach(function(e){a.prototype[e]=i.util.Observer.prototype[e]}),this.wavesurfer.Region=a,this.list={},this._onReady=function(){i.wrapper=i.wavesurfer.drawer.wrapper,i.params.regions&&i.params.regions.forEach(function(e){i.add(e)}),i.params.dragSelection&&i.enableDragSelection(i.params)}}return i(e,null,[{key:"create",value:function(t){return{name:"regions",deferInit:!(!t||!t.deferInit)&&t.deferInit,params:t,staticProps:{initRegions:function(){console.warn('Deprecated initRegions! Use wavesurfer.initPlugins("regions") instead!'),this.initPlugin("regions")},addRegion:function(e){return this.initialisedPluginList.regions||this.initPlugin("regions"),this.regions.add(e)},clearRegions:function(){this.regions&&this.regions.clear()},enableDragSelection:function(e){this.initialisedPluginList.regions||this.initPlugin("regions"),this.regions.enableDragSelection(e)},disableDragSelection:function(){this.regions.disableDragSelection()}},instance:e}}}]),i(e,[{key:"init",value:function(){this.wavesurfer.isReady&&this._onReady(),this.wavesurfer.on("ready",this._onReady)}},{key:"destroy",value:function(){this.wavesurfer.un("ready",this._onReady),this.disableDragSelection(),this.clear()}},{key:"add",value:function(e){var t=this,r=new this.wavesurfer.Region(e,this.wavesurfer);return this.list[r.id]=r,r.on("remove",function(){delete t.list[r.id]}),r}},{key:"clear",value:function(){var e=this;Object.keys(this.list).forEach(function(t){e.list[t].remove()})}},{key:"enableDragSelection",value:function(e){var t=this,r=e.slop||2,i=this.wavesurfer.drawer.container,n=!1!==e.scroll&&this.wavesurfer.params.scrollParent,a=e.scrollSpeed||1,s=e.scrollThreshold||10,o=void 0,u=this.wavesurfer.getDuration(),l=void 0,c=void 0,h=void 0,d=void 0,f=0,p=void 0,v=void 0,m=function(e){e.touches&&e.touches.length>1||(u=t.wavesurfer.getDuration(),d=e.targetTouches?e.targetTouches[0].identifier:null,l=t.wrapper.scrollWidth-t.wrapper.clientWidth,v=t.wrapper.getBoundingClientRect(),o=!0,c=t.wavesurfer.drawer.handleEvent(e,!0),h=null,p=null)};this.wrapper.addEventListener("mousedown",m),this.wrapper.addEventListener("touchstart",m),this.on("disable-drag-selection",function(){t.wrapper.removeEventListener("touchstart",m),t.wrapper.removeEventListener("mousedown",m)});var y=function(e){e.touches&&e.touches.length>1||(o=!1,f=0,p=null,h&&(t.util.preventClick(),h.fireEvent("update-end",e),t.wavesurfer.fireEvent("region-update-end",h,e)),h=null)};this.wrapper.addEventListener("mouseup",y),this.wrapper.addEventListener("touchend",y),document.body.addEventListener("mouseup",y),document.body.addEventListener("touchend",y),this.on("disable-drag-selection",function(){document.body.removeEventListener("mouseup",y),document.body.removeEventListener("touchend",y),t.wrapper.removeEventListener("touchend",y),t.wrapper.removeEventListener("mouseup",y)});var g=function(m){if(o&&!(++f<=r||m.touches&&m.touches.length>1||m.targetTouches&&m.targetTouches[0].identifier!=d)){h||(h=t.add(e||{}));var y=t.wavesurfer.drawer.handleEvent(m);if(h.update({start:Math.min(y*u,c*u),end:Math.max(y*u,c*u)}),n&&i.clientWidth=v.right-s?1:null)&&function e(r){if(h&&p){var i=t.wrapper.scrollLeft+a*p;t.wrapper.scrollLeft=i=Math.min(l,Math.max(0,i));var n=t.wavesurfer.drawer.handleEvent(r);h.update({start:Math.min(n*u,c*u),end:Math.max(n*u,c*u)}),i0&&window.requestAnimationFrame(function(){e(r)})}}(m)}}};this.wrapper.addEventListener("mousemove",g),this.wrapper.addEventListener("touchmove",g),this.on("disable-drag-selection",function(){t.wrapper.removeEventListener("touchmove",g),t.wrapper.removeEventListener("mousemove",g)})}},{key:"disableDragSelection",value:function(){this.fireEvent("disable-drag-selection")}},{key:"getCurrentRegion",value:function(){var e=this,t=this.wavesurfer.getCurrentTime(),r=null;return Object.keys(this.list).forEach(function(i){var n=e.list[i];n.start<=t&&n.end>=t&&(!r||n.end-n.start\n
\n
\n \n \n
\n '),this._editor=document.querySelector("#ckf-editor"),this._waveform=document.querySelector("#ckf-editor #waveform"),this._codeForm=document.querySelector("#ckf-editor .code-form"),this._code=document.querySelector("#ckf-editor #code"),this._renderButton=document.querySelector("#ckf-editor .render"),this.label&&(_label=document.createElement("div"),_label.innerHTML=this.label,_label.classList.add("ckf-label"),this._editor.appendChild(_label)),this.editorOpen||(this._editor.classList.add("closed"),this._codeForm.remove()),this._code.onkeyup=(e=>{this.activeRegion.data.code=this._code.value,this.saveRegions(),this.updateSequence(),this.runRegionCode(this.activeRegion)}),this._code.onkeydown=(e=>{33!=e.which&&34!=e.which&&e.stopPropagation()}),this._renderButton.onclick=(e=>{var t=[];this.wavesurfer.regions.list;for(var r in this.wavesurfer.regions.list){var i=this.wavesurfer.regions.list[r];t.push({start:i.start,end:i.end,data:i.data})}this.activeRegion=null,this._code.value=JSON.stringify(t)}),this._editor.onkeydown=(e=>{console.log(e.which);var t={37:()=>{this.nudging?this.nudgeActiveRegion("left"):this.wavesurfer.skip(-1*this.skipLength)},39:()=>{this.nudging?this.nudgeActiveRegion("right"):this.wavesurfer.skip(this.skipLength)},38:()=>{this.zoom+=.5,this.wavesurfer.zoom(this.zoom)},40:()=>{this.zoom-=.5,this.wavesurfer.zoom(this.zoom)},16:()=>{this.skipLength=.1,e.preventDefault()},18:()=>{this.nudging=!0,e.preventDefault()},13:()=>{var e=this.wavesurfer.addRegion({start:this.wavesurfer.getCurrentTime(),end:this.wavesurfer.getCurrentTime()+.1,drag:!1,resize:!1,data:{code:this._code.value}});this.editCode(e),this.saveRegions(),this.updateSequence()},32:()=>{console.log("PLAYPAUSE"),this.wavesurfer.playPause(),this._code.classList.remove("error")},33:()=>{this.editCode(this.getNextRegion())},34:()=>{this.editCode(this.getPrevRegion())},219:()=>{this.editCode(this.getPrevRegion())},221:()=>{this.editCode(this.getNextRegion())},46:()=>{this.activeRegion.remove(),this.saveRegions(),this.updateSequence()},8:()=>{this.activeRegion.remove(),this.saveRegions(),this.updateSequence()}};t[e.which]&&t[e.which]()}),this._editor.onkeyup=(e=>{var t={16:()=>{this.skipLength=1},18:()=>{this.nudging=!1}};t[e.which]&&t[e.which]()}),this.saveRegions=(()=>{this.editorOpen&&(localStorage.regions=JSON.stringify(Object.keys(this.wavesurfer.regions.list).map(e=>{var t=this.wavesurfer.regions.list[e];return{start:t.start,end:t.end,data:t.data}})))}),this.loadRegions=function(e){var t=this.keyframes,r=[];localStorage.regions&&(r=JSON.parse(localStorage.regions));for(var i=[],n=t.concat(r),a=n.length;a--;){var s=n[a];unique=!0;for(var o=i.length-1;o>=0;o--)i[o].start==s.start&&(unique=!1);unique&&i.unshift(s)}i.forEach(e=>{this.wavesurfer.addRegion({start:e.start,end:e.end,data:e.data,drag:!1,resize:!1})})},this.updateSequence=(()=>{this.sequence=[];var e=this.wavesurfer.regions.list;for(var t in e){var r={time:e[t].start,code:e[t].data.code};this.sequence.push(r)}this.sequence.sort(function(e,t){return e.time>t.time?1:e.time{region=this.activeRegion,nudgeAmount="left"==e?-.1:.1,this.activeRegion=this.wavesurfer.addRegion({start:region.start+nudgeAmount,end:region.end+nudgeAmount,data:region.data,drag:!1,resize:!1}),this.activeRegion.element.classList.add("active"),region.remove(),this.saveRegions()}),this.editCode=function(e,t=!0){if(e&&(this.runRegionCode(e),this.editorOpen)){_regions=this._editor.querySelectorAll("region");for(var r=_regions.length-1;r>=0;r--)_regions[r].classList.remove("active");e.element.classList.add("active"),t&&this.wavesurfer.seekAndCenter(e.start/this.wavesurfer.getDuration()),this._code.value=e.data.code,this.activeRegion=e}},this.runRegionCode=function(region){this._code.classList.remove("error");try{eval(region.data.code)}catch(e){this._code.classList.add("error"),console.log(e)}},this.getNextRegion=function(){if(this.editorOpen){var e=-1;this.activeRegion&&(e=this.activeRegion.start);var t=[];for(var r in this.wavesurfer.regions.list){var i=this.wavesurfer.regions.list[r];i.start>e&&t.push(i)}return t.sort(function(e,t){return e.start>t.start?1:e.startt.start?-1:e.start==t.start?0:void 0}),t[0]}};var waveHeight=100;this.editorOpen||(waveHeight=50);var waveColor=args.waveColor||"#3AEAD2",progressColor=args.progressColor||"#0c9fa7";this.wavesurfer=WaveSurfer.create({container:"#ckf-waveform",height:waveHeight,scrollParent:!0,normalize:!0,waveColor:waveColor,progressColor:progressColor,barWidth:1,cursorColor:"#fff",plugins:[WaveSurfer.cursor.create(),WaveSurfer.regions.create()]}),this.wavesurfer.load(this.audioPath),this.wavesurfer.on("ready",e=>{this.wavesurfer.zoom(this.zoom),this.loadRegions(),this.updateSequence(),this.autoplay&&this.wavesurfer.play()}),this.wavesurfer.on("region-click",e=>{this.editCode(e),this.updateSequence()}),this.wavesurfer.on("seek",()=>{this.updateSequence()}),this.wavesurfer.on("audioprocess",()=>{var e=this.wavesurfer.getCurrentTime(),t=this.sequence[this.sequenceCursor];if(t&&e>t.time){this.sequenceCursor++;var r=this.wavesurfer.regions.list;for(var i in r)if(r[i].start==t.time){this.editCode(r[i],!1);break}}})}}!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("WaveSurfer",[],t):"object"==typeof exports?exports.WaveSurfer=t():e.WaveSurfer=t()}(window,function(){return function(e){var t={};function r(i){if(t[i])return t[i].exports;var n=t[i]={i:i,l:!1,exports:{}};return e[i].call(n.exports,n,n.exports,r),n.l=!0,n.exports}return r.m=e,r.c=t,r.d=function(e,t,i){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:i})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var i=Object.create(null);if(r.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var n in e)r.d(i,n,function(t){return e[t]}.bind(null,n));return i},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=17)}([function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var i=r(16);Object.defineProperty(t,"ajax",{enumerable:!0,get:function(){return p(i).default}});var n=r(15);Object.defineProperty(t,"getId",{enumerable:!0,get:function(){return p(n).default}});var a=r(14);Object.defineProperty(t,"max",{enumerable:!0,get:function(){return p(a).default}});var s=r(13);Object.defineProperty(t,"min",{enumerable:!0,get:function(){return p(s).default}});var o=r(3);Object.defineProperty(t,"Observer",{enumerable:!0,get:function(){return p(o).default}});var u=r(12);Object.defineProperty(t,"extend",{enumerable:!0,get:function(){return p(u).default}});var l=r(11);Object.defineProperty(t,"style",{enumerable:!0,get:function(){return p(l).default}});var h=r(2);Object.defineProperty(t,"requestAnimationFrame",{enumerable:!0,get:function(){return p(h).default}});var c=r(10);Object.defineProperty(t,"frame",{enumerable:!0,get:function(){return p(c).default}});var d=r(9);Object.defineProperty(t,"debounce",{enumerable:!0,get:function(){return p(d).default}});var f=r(8);function p(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(t,"preventClick",{enumerable:!0,get:function(){return p(f).default}})},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var i=function(){function e(e,t){for(var r=0;r=e.getDuration()?(e.setState(u),e.fireEvent("pause")):t>=e.scheduledPause?e.pause():e.state===e.states[s]&&e.fireEvent("audioprocess",t)}}},{key:"removeOnAudioProcess",value:function(){this.scriptNode.onaudioprocess=null}},{key:"createAnalyserNode",value:function(){this.analyser=this.ac.createAnalyser(),this.analyser.connect(this.gainNode)}},{key:"createVolumeNode",value:function(){this.ac.createGain?this.gainNode=this.ac.createGain():this.gainNode=this.ac.createGainNode(),this.gainNode.connect(this.ac.destination)}},{key:"setSinkId",value:function(e){if(e){var t=new window.Audio;if(!t.setSinkId)return Promise.reject(new Error("setSinkId is not supported in your browser"));t.autoplay=!0;var r=this.ac.createMediaStreamDestination();return this.gainNode.disconnect(),this.gainNode.connect(r),t.src=URL.createObjectURL(r.stream),t.setSinkId(e)}return Promise.reject(new Error("Invalid deviceId: "+e))}},{key:"setVolume",value:function(e){this.gainNode.gain.setValueAtTime(e,this.ac.currentTime)}},{key:"getVolume",value:function(){return this.gainNode.gain.value}},{key:"decodeArrayBuffer",value:function(e,t,r){this.offlineAc||(this.offlineAc=this.getOfflineAudioContext(this.ac?this.ac.sampleRate:44100)),this.offlineAc.decodeAudioData(e,function(e){return t(e)},r)}},{key:"setPeaks",value:function(e,t){this.explicitDuration=t,this.peaks=e}},{key:"setLength",value:function(e){if(!this.mergedPeaks||e!=2*this.mergedPeaks.length-1+2){this.splitPeaks=[],this.mergedPeaks=[];var t=this.buffer?this.buffer.numberOfChannels:1,r=void 0;for(r=0;rp&&(p=m),mthis.mergedPeaks[2*h])&&(this.mergedPeaks[2*h]=p),(0==o||f=this.getDuration()&&(e=0),null==t&&(t=this.getDuration()),this.startPosition=e,this.lastPlay=this.ac.currentTime,this.state===this.states[u]&&this.setState(o),{start:e,end:t}}},{key:"getPlayedTime",value:function(){return(this.ac.currentTime-this.lastPlay)*this.playbackRate}},{key:"play",value:function(e,t){if(this.buffer){this.createSource();var r=this.seekTo(e,t);e=r.start,t=r.end,this.scheduledPause=t,this.source.start(0,e,t-e),"suspended"==this.ac.state&&this.ac.resume&&this.ac.resume(),this.setState(s),this.fireEvent("play")}}},{key:"pause",value:function(){this.scheduledPause=null,this.startPosition+=this.getPlayedTime(),this.source&&this.source.stop(0),this.setState(o),this.fireEvent("pause")}},{key:"getCurrentTime",value:function(){return this.state.getCurrentTime.call(this)}},{key:"getPlaybackRate",value:function(){return this.playbackRate}},{key:"setPlaybackRate",value:function(e){e=e||1,this.isPaused()?this.playbackRate=e:(this.pause(),this.playbackRate=e,this.play())}}]),t}();l.scriptBufferSize=256,t.default=l,e.exports=t.default},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=(window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||function(e,t){return setTimeout(e,1e3/60)}).bind(window),e.exports=t.default},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var i=function(){function e(e,t){for(var r=0;r=0;i--)r[i]==t&&r.splice(i,1);else r.length=0}}},{key:"unAll",value:function(){this.handlers=null}},{key:"once",value:function(e,t){var r=this;return this.on(e,function i(){for(var n=arguments.length,a=Array(n),s=0;s1?t-1:0),i=1;i=1/0&&(e=this.media.seekable.end(0)),e}},{key:"getCurrentTime",value:function(){return this.media&&this.media.currentTime}},{key:"getPlayedPercents",value:function(){return this.getCurrentTime()/this.getDuration()||0}},{key:"getPlaybackRate",value:function(){return this.playbackRate||this.media.playbackRate}},{key:"setPlaybackRate",value:function(e){this.playbackRate=e||1,this.media.playbackRate=this.playbackRate}},{key:"seekTo",value:function(e){null!=e&&(this.media.currentTime=e),this.clearPlayEnd()}},{key:"play",value:function(e,t){this.seekTo(e);var r=this.media.play();return t&&this.setPlayEnd(t),r}},{key:"pause",value:function(){var e=void 0;return this.media&&(e=this.media.pause()),this.clearPlayEnd(),e}},{key:"setPlayEnd",value:function(e){var t=this;this._onPlayEnd=function(r){r>=e&&(t.pause(),t.seekTo(e))},this.on("audioprocess",this._onPlayEnd)}},{key:"clearPlayEnd",value:function(){this._onPlayEnd&&(this.un("audioprocess",this._onPlayEnd),this._onPlayEnd=null)}},{key:"getPeaks",value:function(e,r,i){return this.buffer?function e(t,r,i){null===t&&(t=Function.prototype);var n=Object.getOwnPropertyDescriptor(t,r);if(void 0===n){var a=Object.getPrototypeOf(t);return null===a?void 0:e(a,r,i)}if("value"in n)return n.value;var s=n.get;return void 0!==s?s.call(i):void 0}(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),"getPeaks",this).call(this,e,r,i):this.peaks||[]}},{key:"setSinkId",value:function(e){return e?this.media.setSinkId?this.media.setSinkId(e):Promise.reject(new Error("setSinkId is not supported in your browser")):Promise.reject(new Error("Invalid deviceId: "+e))}},{key:"getVolume",value:function(){return this.volume||this.media.volume}},{key:"setVolume",value:function(e){this.volume=e,this.media.volume=this.volume}},{key:"destroy",value:function(){this.pause(),this.unAll(),this.params.removeMediaElementOnDestroy&&this.media&&this.media.parentNode&&this.media.parentNode.removeChild(this.media),this.media=null}}]),t}();t.default=s,e.exports=t.default},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var i=function(){function e(e,t){for(var r=0;r1&&(s=1):s=(r-i.left+this.wrapper.scrollLeft)/this.wrapper.scrollWidth||0,s}},{key:"setupWrapperEvents",value:function(){var e=this;this.wrapper.addEventListener("click",function(t){var r=e.wrapper.offsetHeight-e.wrapper.clientHeight;if(0!=r){var i=e.wrapper.getBoundingClientRect();if(t.clientY>=i.bottom-r)return}e.params.interact&&e.fireEvent("click",t,e.handleEvent(t))}),this.wrapper.addEventListener("scroll",function(t){return e.fireEvent("scroll",t)})}},{key:"drawPeaks",value:function(e,t,r,i){this.setWidth(t)||this.clearWave(),this.params.barWidth?this.drawBars(e,0,r,i):this.drawWave(e,0,r,i)}},{key:"resetScroll",value:function(){null!==this.wrapper&&(this.wrapper.scrollLeft=0)}},{key:"recenter",value:function(e){var t=this.wrapper.scrollWidth*e;this.recenterOnPosition(t,!0)}},{key:"recenterOnPosition",value:function(e,t){var r=this.wrapper.scrollLeft,i=~~(this.wrapper.clientWidth/2),n=this.wrapper.scrollWidth-this.wrapper.clientWidth,a=e-i,s=a-r;0!=n&&(!t&&-i<=s&&s=t){if(this.lastPos=r,this.params.scrollParent&&this.params.autoCenter){var i=~~(this.wrapper.scrollWidth*e);this.recenterOnPosition(i)}this.updateProgress(r)}}},{key:"destroy",value:function(){this.unAll(),this.wrapper&&(this.wrapper.parentNode==this.container&&this.container.removeChild(this.wrapper),this.wrapper=null)}},{key:"updateCursor",value:function(){}},{key:"updateSize",value:function(){}},{key:"drawBars",value:function(e,t,r,i){}},{key:"drawWave",value:function(e,t,r,i){}},{key:"clearWave",value:function(){}},{key:"updateProgress",value:function(e){}}]),t}();t.default=a,e.exports=t.default},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var i,n=function(){function e(e,t){for(var r=0;rr;)this.removeCanvas();this.canvases.forEach(function(t,r){var i=e.maxCanvasWidth+2*Math.ceil(e.params.pixelRatio/2);r==e.canvases.length-1&&(i=e.width-e.maxCanvasWidth*(e.canvases.length-1)),e.updateDimensions(t,i,e.height),e.clearWaveForEntry(t)})}},{key:"addCanvas",value:function(){var e={},t=this.maxCanvasElementWidth*this.canvases.length;e.wave=this.wrapper.appendChild(this.style(document.createElement("canvas"),{position:"absolute",zIndex:2,left:t+"px",top:0,bottom:0,height:"100%",pointerEvents:"none"})),e.waveCtx=e.wave.getContext("2d"),this.hasProgressCanvas&&(e.progress=this.progressWave.appendChild(this.style(document.createElement("canvas"),{position:"absolute",left:t+"px",top:0,bottom:0,height:"100%"})),e.progressCtx=e.progress.getContext("2d")),this.canvases.push(e)}},{key:"removeCanvas",value:function(){var e=this.canvases.pop();e.wave.parentElement.removeChild(e.wave),this.hasProgressCanvas&&e.progress.parentElement.removeChild(e.progress)}},{key:"updateDimensions",value:function(e,t,r){var i=Math.round(t/this.params.pixelRatio),n=Math.round(this.width/this.params.pixelRatio);e.start=e.waveCtx.canvas.offsetLeft/n||0,e.end=e.start+i/n,e.waveCtx.canvas.width=t,e.waveCtx.canvas.height=r,this.style(e.waveCtx.canvas,{width:i+"px"}),this.style(this.progressWave,{display:"block"}),this.hasProgressCanvas&&(e.progressCtx.canvas.width=t,e.progressCtx.canvas.height=r,this.style(e.progressCtx.canvas,{width:i+"px"}))}},{key:"clearWave",value:function(){var e=this;this.canvases.forEach(function(t){return e.clearWaveForEntry(t)})}},{key:"clearWaveForEntry",value:function(e){e.waveCtx.clearRect(0,0,e.waveCtx.canvas.width,e.waveCtx.canvas.height),this.hasProgressCanvas&&e.progressCtx.clearRect(0,0,e.progressCtx.canvas.width,e.progressCtx.canvas.height)}},{key:"drawBars",value:function(e,t,r,i){var n=this;return this.prepareDraw(e,t,r,i,function(e){var t=e.absmax,a=e.hasMinVals,s=(e.height,e.offsetY),o=e.halfH,u=e.peaks;if(void 0!==r){var l=a?2:1,h=u.length/l,c=n.params.barWidth*n.params.pixelRatio,d=c+(null===n.params.barGap?Math.max(n.params.pixelRatio,~~(c/2)):Math.max(n.params.pixelRatio,n.params.barGap*n.params.pixelRatio)),f=h/n.width,p=i,v=void 0;for(v=r;vo||c=d;v--){var g=r[2*v+1]||0,w=Math.round(g/i*n);t.lineTo((v-h)*l+this.halfPixel,n-w+a)}t.closePath(),t.fill()}}}},{key:"fillRect",value:function(e,t,r,i){var n=Math.floor(e/this.maxCanvasWidth),a=Math.min(Math.ceil((e+r)/this.maxCanvasWidth)+1,this.canvases.length),s=void 0;for(s=n;sl?-h:l}var c=[].some.call(e,function(e){return e<0}),d=a.params.height*a.params.pixelRatio;return n({absmax:u,hasMinVals:c,height:d,offsetY:d*t||0,halfH:d/2,peaks:e})})()}},{key:"fillRectToContext",value:function(e,t,r,i,n){e&&e.fillRect(t,r,i,n)}},{key:"setFillStyles",value:function(e){e.waveCtx.fillStyle=this.params.waveColor,this.hasProgressCanvas&&(e.progressCtx.fillStyle=this.params.progressColor)}},{key:"getImage",value:function(e,t){var r=this.canvases.map(function(r){return r.wave.toDataURL(e,t)});return r.length>1?r:r[0]}},{key:"updateProgress",value:function(e){this.style(this.progressWave,{width:e+"px"})}}]),t}();t.default=o,e.exports=t.default},function(e,t,r){"use strict";function i(e){e.stopPropagation(),document.body.removeEventListener("click",i,!0)}Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e){document.body.addEventListener("click",i,!0)},e.exports=t.default},function(e,t){e.exports=function(e,t,r){var i,n,a,s,o;function u(){var l=Date.now()-s;l=0?i=setTimeout(u,t-l):(i=null,r||(o=e.apply(a,n),a=n=null))}null==t&&(t=100);var l=function(){a=this,n=arguments,s=Date.now();var l=r&&!i;return i||(i=setTimeout(u,t)),l&&(o=e.apply(a,n),a=n=null),o};return l.clear=function(){i&&(clearTimeout(i),i=null)},l.flush=function(){i&&(o=e.apply(a,n),a=n=null,clearTimeout(i),i=null)},l}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e){return function(){for(var t=arguments.length,r=Array(t),i=0;i1?t-1:0),i=1;it&&(t=e[r])}),t},e.exports=t.default},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(){return"wavesurfer_"+Math.random().toString(32).substring(2)},e.exports=t.default},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e){var t=new n.default,r=new XMLHttpRequest,i=!1;return r.open(e.method||"GET",e.url,!0),r.responseType=e.responseType||"json",e.xhr&&(e.xhr.requestHeaders&&e.xhr.requestHeaders.forEach(function(e){r.setRequestHeader(e.key,e.value)}),e.xhr.withCredentials&&(r.withCredentials=!0)),r.addEventListener("progress",function(e){t.fireEvent("progress",e),e.lengthComputable&&e.loaded==e.total&&(i=!0)}),r.addEventListener("load",function(e){i||t.fireEvent("progress",e),t.fireEvent("load",e),200==r.status||206==r.status?t.fireEvent("success",r.response,e):t.fireEvent("error",e)}),r.addEventListener("error",function(e){return t.fireEvent("error",e)}),r.send(),t.xhr=r,t};var i,n=(i=r(3))&&i.__esModule?i:{default:i};e.exports=t.default},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var i=function(){function e(e,t){for(var r=0;r=this.getDuration()?this.seekTo(1):this.seekTo(e/this.getDuration())}},{key:"play",value:function(e,t){var r=this;return this.fireEvent("interaction",function(){return r.play(e,t)}),this.backend.play(e,t)}},{key:"pause",value:function(){if(!this.backend.isPaused())return this.backend.pause()}},{key:"playPause",value:function(){return this.backend.isPaused()?this.play():this.pause()}},{key:"isPlaying",value:function(){return!this.backend.isPaused()}},{key:"skipBackward",value:function(e){this.skip(-e||-this.params.skipLength)}},{key:"skipForward",value:function(e){this.skip(e||this.params.skipLength)}},{key:"skip",value:function(e){var t=this.getDuration()||1,r=this.getCurrentTime()||0;r=Math.max(0,Math.min(t,r+(e||0))),this.seekAndCenter(r/t)}},{key:"seekAndCenter",value:function(e){this.seekTo(e),this.drawer.recenter(e)}},{key:"seekTo",value:function(e){var t=this;if("number"!=typeof e||!isFinite(e)||e<0||e>1)return console.error("Error calling wavesurfer.seekTo, parameter must be a number between 0 and 1!");this.fireEvent("interaction",function(){return t.seekTo(e)});var r=this.backend.isPaused();r||this.backend.pause();var i=this.params.scrollParent;this.params.scrollParent=!1,this.backend.seekTo(e*this.getDuration()),this.drawer.progress(e),r||this.backend.play(),this.params.scrollParent=i,this.fireEvent("seek",e)}},{key:"stop",value:function(){this.pause(),this.seekTo(0),this.drawer.progress(0)}},{key:"setSinkId",value:function(e){return this.backend.setSinkId(e)}},{key:"setVolume",value:function(e){this.backend.setVolume(e),this.fireEvent("volume",e)}},{key:"getVolume",value:function(){return this.backend.getVolume()}},{key:"setPlaybackRate",value:function(e){this.backend.setPlaybackRate(e)}},{key:"getPlaybackRate",value:function(){return this.backend.getPlaybackRate()}},{key:"toggleMute",value:function(){this.setMute(!this.isMuted)}},{key:"setMute",value:function(e){e!==this.isMuted?(e?(this.savedVolume=this.backend.getVolume(),this.backend.setVolume(0),this.isMuted=!0,this.fireEvent("volume",0)):(this.backend.setVolume(this.savedVolume),this.isMuted=!1,this.fireEvent("volume",this.savedVolume)),this.fireEvent("mute",this.isMuted)):this.fireEvent("mute",this.isMuted)}},{key:"getMute",value:function(){return this.isMuted}},{key:"isReady",value:function(){return this.isReady}},{key:"getFilters",value:function(){return this.backend.filters||[]}},{key:"toggleScroll",value:function(){this.params.scrollParent=!this.params.scrollParent,this.drawBuffer()}},{key:"toggleInteraction",value:function(){this.params.interact=!this.params.interact}},{key:"getWaveColor",value:function(){return this.params.waveColor}},{key:"setWaveColor",value:function(e){this.params.waveColor=e,this.drawBuffer()}},{key:"getProgressColor",value:function(){return this.params.progressColor}},{key:"setProgressColor",value:function(e){this.params.progressColor=e,this.drawBuffer()}},{key:"getCursorColor",value:function(){return this.params.cursorColor}},{key:"setCursorColor",value:function(e){this.params.cursorColor=e,this.drawer.updateCursor()}},{key:"getHeight",value:function(){return this.params.height}},{key:"setHeight",value:function(e){this.params.height=e,this.drawer.setHeight(e*this.params.pixelRatio),this.drawBuffer()}},{key:"drawBuffer",value:function(){var e=Math.round(this.getDuration()*this.params.minPxPerSec*this.params.pixelRatio),t=this.drawer.getWidth(),r=e,i=this.drawer.getScrollX(),n=Math.max(i+t,r);this.params.fillParent&&(!this.params.scrollParent||ee&&(this.end=e,this.start=e-(this.end-this.start)),null!=this.minLength&&(this.end=Math.max(this.start+this.minLength,this.end)),null!=this.maxLength&&(this.end=Math.min(this.start+this.maxLength,this.end)),null!=this.element){var r=Math.round(this.start/e*t),i=Math.round(this.end/e*t)-r;for(var n in this.style(this.element,{left:r+"px",width:i+"px",backgroundColor:this.color,cursor:this.drag?"move":"default"}),this.attributes)this.element.setAttribute("data-region-"+n,this.attributes[n]);this.element.title=this.formatTime(this.start,this.end)}}},{key:"bindInOut",value:function(){var e=this;this.firedIn=!1,this.firedOut=!1;var t=function(t){!e.firedOut&&e.firedIn&&(e.start>=Math.round(100*t)/100||e.end<=Math.round(100*t)/100)&&(e.firedOut=!0,e.firedIn=!1,e.fireEvent("out"),e.wavesurfer.fireEvent("region-out",e)),!e.firedIn&&e.start<=t&&e.end>t&&(e.firedIn=!0,e.firedOut=!1,e.fireEvent("in"),e.wavesurfer.fireEvent("region-in",e))};this.wavesurfer.backend.on("audioprocess",t),this.on("remove",function(){e.wavesurfer.backend.un("audioprocess",t)}),this.on("out",function(){e.loop&&e.wavesurfer.play(e.start)})}},{key:"bindEvents",value:function(){var e,t,r,i,n,a,s,o,u,l,h,c,d,f,p,v=this;this.element.addEventListener("mouseenter",function(e){v.fireEvent("mouseenter",e),v.wavesurfer.fireEvent("region-mouseenter",v,e)}),this.element.addEventListener("mouseleave",function(e){v.fireEvent("mouseleave",e),v.wavesurfer.fireEvent("region-mouseleave",v,e)}),this.element.addEventListener("click",function(e){e.preventDefault(),v.fireEvent("click",e),v.wavesurfer.fireEvent("region-click",v,e)}),this.element.addEventListener("dblclick",function(e){e.stopPropagation(),e.preventDefault(),v.fireEvent("dblclick",e),v.wavesurfer.fireEvent("region-dblclick",v,e)}),(this.drag||this.resize)&&(e=v.wavesurfer.drawer.container,t=v.wavesurfer.getDuration(),r=v.scrollSpeed,i=v.scrollThreshold,n=void 0,a=void 0,s=void 0,o=void 0,u=void 0,l=!1,h=void 0,c=void 0,d=function(e){e.touches&&e.touches.length>1||(a=e.targetTouches?e.targetTouches[0].identifier:null,e.stopPropagation(),n=v.wavesurfer.drawer.handleEvent(e,!0)*t,o=v.wrapper.scrollWidth-v.wrapper.clientWidth,c=v.wrapper.getBoundingClientRect(),"handle"==e.target.tagName.toLowerCase()?u=e.target.classList.contains("wavesurfer-handle-start")?"start":"end":(s=!0,u=!1))},f=function(e){e.touches&&e.touches.length>1||((s||u)&&(s=!1,h=null,u=!1),l&&(l=!1,v.util.preventClick(),v.fireEvent("update-end",e),v.wavesurfer.fireEvent("region-update-end",v,e)))},p=function(d){if(!(d.touches&&d.touches.length>1)&&(!d.targetTouches||d.targetTouches[0].identifier==a)&&(s||u)){var f=n,p=v.wavesurfer.drawer.handleEvent(d)*t,m=p-n;if(n=p,v.drag&&s&&(l=l||!!m,v.onDrag(m)),v.resize&&u&&(l=l||!!m,v.onResize(m,u)),v.scroll&&e.clientWidth=0?h=-1:p>f&&g+y.width<=c.right&&(h=1),(-1===h&&g>i||1===h&&g+y.width=c.right-i?1:null}h&&function e(i){if(h&&(s||u)){var a=v.wrapper.scrollLeft+r*h;v.wrapper.scrollLeft=a=Math.min(o,Math.max(0,a));var l=v.wavesurfer.drawer.handleEvent(i)*t,c=l-n;n=l,s?v.onDrag(c):v.onResize(c,u),window.requestAnimationFrame(function(){e(i)})}}(d)}}},v.element.addEventListener("mousedown",d),v.element.addEventListener("touchstart",d),v.wrapper.addEventListener("mousemove",p),v.wrapper.addEventListener("touchmove",p),document.body.addEventListener("mouseup",f),document.body.addEventListener("touchend",f),v.on("remove",function(){document.body.removeEventListener("mouseup",f),document.body.removeEventListener("touchend",f),v.wrapper.removeEventListener("mousemove",p),v.wrapper.removeEventListener("touchmove",p)}),v.wavesurfer.on("destroy",function(){document.body.removeEventListener("mouseup",f),document.body.removeEventListener("touchend",f)}))}},{key:"onDrag",value:function(e){var t=this.wavesurfer.getDuration();this.end+e>t||this.start+e<0||this.update({start:this.start+e,end:this.end+e})}},{key:"onResize",value:function(e,t){"start"==t?this.update({start:Math.min(this.start+e,this.end),end:Math.max(this.start+e,this.end)}):this.update({start:Math.min(this.end+e,this.start),end:Math.max(this.end+e,this.start)})}}]),e}(),s=function(){function e(t,r){var i=this;n(this,e),this.params=t,this.wavesurfer=r,this.util=r.util,Object.getOwnPropertyNames(this.util.Observer.prototype).forEach(function(e){a.prototype[e]=i.util.Observer.prototype[e]}),this.wavesurfer.Region=a,this.list={},this._onReady=function(){i.wrapper=i.wavesurfer.drawer.wrapper,i.params.regions&&i.params.regions.forEach(function(e){i.add(e)}),i.params.dragSelection&&i.enableDragSelection(i.params)}}return i(e,null,[{key:"create",value:function(t){return{name:"regions",deferInit:!(!t||!t.deferInit)&&t.deferInit,params:t,staticProps:{initRegions:function(){console.warn('Deprecated initRegions! Use wavesurfer.initPlugins("regions") instead!'),this.initPlugin("regions")},addRegion:function(e){return this.initialisedPluginList.regions||this.initPlugin("regions"),this.regions.add(e)},clearRegions:function(){this.regions&&this.regions.clear()},enableDragSelection:function(e){this.initialisedPluginList.regions||this.initPlugin("regions"),this.regions.enableDragSelection(e)},disableDragSelection:function(){this.regions.disableDragSelection()}},instance:e}}}]),i(e,[{key:"init",value:function(){this.wavesurfer.isReady&&this._onReady(),this.wavesurfer.on("ready",this._onReady)}},{key:"destroy",value:function(){this.wavesurfer.un("ready",this._onReady),this.disableDragSelection(),this.clear()}},{key:"add",value:function(e){var t=this,r=new this.wavesurfer.Region(e,this.wavesurfer);return this.list[r.id]=r,r.on("remove",function(){delete t.list[r.id]}),r}},{key:"clear",value:function(){var e=this;Object.keys(this.list).forEach(function(t){e.list[t].remove()})}},{key:"enableDragSelection",value:function(e){var t=this,r=e.slop||2,i=this.wavesurfer.drawer.container,n=!1!==e.scroll&&this.wavesurfer.params.scrollParent,a=e.scrollSpeed||1,s=e.scrollThreshold||10,o=void 0,u=this.wavesurfer.getDuration(),l=void 0,h=void 0,c=void 0,d=void 0,f=0,p=void 0,v=void 0,m=function(e){e.touches&&e.touches.length>1||(u=t.wavesurfer.getDuration(),d=e.targetTouches?e.targetTouches[0].identifier:null,l=t.wrapper.scrollWidth-t.wrapper.clientWidth,v=t.wrapper.getBoundingClientRect(),o=!0,h=t.wavesurfer.drawer.handleEvent(e,!0),c=null,p=null)};this.wrapper.addEventListener("mousedown",m),this.wrapper.addEventListener("touchstart",m),this.on("disable-drag-selection",function(){t.wrapper.removeEventListener("touchstart",m),t.wrapper.removeEventListener("mousedown",m)});var y=function(e){e.touches&&e.touches.length>1||(o=!1,f=0,p=null,c&&(t.util.preventClick(),c.fireEvent("update-end",e),t.wavesurfer.fireEvent("region-update-end",c,e)),c=null)};this.wrapper.addEventListener("mouseup",y),this.wrapper.addEventListener("touchend",y),document.body.addEventListener("mouseup",y),document.body.addEventListener("touchend",y),this.on("disable-drag-selection",function(){document.body.removeEventListener("mouseup",y),document.body.removeEventListener("touchend",y),t.wrapper.removeEventListener("touchend",y),t.wrapper.removeEventListener("mouseup",y)});var g=function(m){if(o&&!(++f<=r||m.touches&&m.touches.length>1||m.targetTouches&&m.targetTouches[0].identifier!=d)){c||(c=t.add(e||{}));var y=t.wavesurfer.drawer.handleEvent(m);if(c.update({start:Math.min(y*u,h*u),end:Math.max(y*u,h*u)}),n&&i.clientWidth=v.right-s?1:null)&&function e(r){if(c&&p){var i=t.wrapper.scrollLeft+a*p;t.wrapper.scrollLeft=i=Math.min(l,Math.max(0,i));var n=t.wavesurfer.drawer.handleEvent(r);c.update({start:Math.min(n*u,h*u),end:Math.max(n*u,h*u)}),i0&&window.requestAnimationFrame(function(){e(r)})}}(m)}}};this.wrapper.addEventListener("mousemove",g),this.wrapper.addEventListener("touchmove",g),this.on("disable-drag-selection",function(){t.wrapper.removeEventListener("touchmove",g),t.wrapper.removeEventListener("mousemove",g)})}},{key:"disableDragSelection",value:function(){this.fireEvent("disable-drag-selection")}},{key:"getCurrentRegion",value:function(){var e=this,t=this.wavesurfer.getCurrentTime(),r=null;return Object.keys(this.list).forEach(function(i){var n=e.list[i];n.start<=t&&n.end>=t&&(!r||n.end-n.start { @@ -95,15 +97,32 @@ function CodeKeyframes(args){ this._code.value = JSON.stringify(keyframes) } - document.onkeydown = (e) =>{ + this._editor.onkeydown = (e) =>{ + + console.log(e.which) var keycodes = { // left - 37:()=>{ this.wavesurfer.skip(this.skipLength*-1) }, + 37:()=>{ + + if( this.nudging ){ + this.nudgeActiveRegion('left') + }else{ + this.wavesurfer.skip(this.skipLength*-1) + } + + + }, // right - 39:()=>{ this.wavesurfer.skip(this.skipLength) }, + 39:()=>{ + if( this.nudging ){ + this.nudgeActiveRegion('right') + }else{ + this.wavesurfer.skip(this.skipLength) + } + }, // up 38:()=>{ @@ -123,6 +142,13 @@ function CodeKeyframes(args){ e.preventDefault() }, + // alt + 18:()=>{ + this.nudging = true + // alert(this.nudging) + e.preventDefault() + }, + // enter 13:()=>{ @@ -143,6 +169,9 @@ function CodeKeyframes(args){ // space 32:()=>{ + + console.log("PLAYPAUSE") + this.wavesurfer.playPause() this._code.classList.remove('error') }, @@ -157,6 +186,16 @@ function CodeKeyframes(args){ this.editCode( this.getPrevRegion() ) }, + // left bracket + 219:()=>{ + this.editCode( this.getPrevRegion() ) + }, + + // right bracket + 221:()=>{ + this.editCode( this.getNextRegion() ) + }, + // delete 46:()=>{ this.activeRegion.remove() @@ -164,6 +203,13 @@ function CodeKeyframes(args){ this.updateSequence() }, + // delete (backspace) + 8:()=>{ + this.activeRegion.remove() + this.saveRegions() + this.updateSequence() + }, + } @@ -179,7 +225,12 @@ function CodeKeyframes(args){ // shift 16:()=>{ this.skipLength = 1 - } + }, + + // alt + 18:()=>{ + this.nudging = false + }, } if( keycodes[e.which] ){ @@ -287,11 +338,34 @@ function CodeKeyframes(args){ } } + this.nudgeActiveRegion = (direction) => { + + region = this.activeRegion + nudgeAmount = (direction == 'left') ? -.1 : .1 + + this.activeRegion = this.wavesurfer.addRegion({ + start: region.start + nudgeAmount, + end: region.end +nudgeAmount, + data: region.data, + drag: false, + resize: false + }) + + this.activeRegion.element.classList.add('active') + region.remove() + this.saveRegions() + + } + this.editCode = function(region, seek = true) { - if( !this.editorOpen ) return if(!region) return + // execute the keyframe code + this.runRegionCode(region) + + if( !this.editorOpen ) return + // remove active class from all regions _regions = this._editor.querySelectorAll('region') for (var i = _regions.length - 1; i >= 0; i--) { @@ -304,7 +378,6 @@ function CodeKeyframes(args){ if( seek ){ this.wavesurfer.seekAndCenter( (region.start / this.wavesurfer.getDuration())) } - // show the code for this region this._code.value = region.data.code @@ -314,6 +387,17 @@ function CodeKeyframes(args){ } + this.runRegionCode = function(region){ + this._code.classList.remove('error') + + try{ + eval(region.data.code) + } catch(error){ + this._code.classList.add('error') + console.log(error) + } + }, + this.getNextRegion = function(){ if( !this.editorOpen ) return @@ -427,17 +511,7 @@ function CodeKeyframes(args){ var command = this.sequence[this.sequenceCursor] if( !command ) return if( time > command.time ){ - this.sequenceCursor++ - - this._code.classList.remove('error') - - try{ - eval(command.code) - } catch(error){ - this._code.classList.add('error') - console.log(error) - } - + this.sequenceCursor++ // find the region to show var regions = this.wavesurfer.regions.list @@ -450,6 +524,4 @@ function CodeKeyframes(args){ } }) - - } \ No newline at end of file