/*! * wavesurfer.js regions plugin 4.6.0 (2024-02-05) * https://wavesurfer-js.org * @license BSD-3-Clause */ !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=e.WaveSurfer||{},e.WaveSurfer.regions=t())}(this,(()=>(()=>{"use strict";var e={608:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var n=r(488);function i(e){return i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},i(e)}function s(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function a(e){for(var t=1;t=this.maxRegions}},{key:"add",value:function(e){var t=this;if(this.wouldExceedMaxRegions())return null;!e.minLength&&this.regionsMinLength&&(e=a(a({},e),{},{minLength:this.regionsMinLength}));var r=new this.wavesurfer.Region(e,this.util,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;this.disableDragSelection();var r,n,i,s,a,o,u,l=e.slop||2,h=this.wavesurfer.drawer.container,d=!1!==e.scroll&&this.wavesurfer.params.scrollParent,c=e.scrollSpeed||1,f=e.scrollThreshold||10,v=this.wavesurfer.getDuration(),p=0,g=function e(r){if(s&&o){var a=t.wrapper.scrollLeft+c*o;t.wrapper.scrollLeft=a=Math.min(n,Math.max(0,a));var u=t.wavesurfer.drawer.handleEvent(r);s.update({start:Math.min(u*v,i*v),end:Math.max(u*v,i*v)}),a0&&window.requestAnimationFrame((function(){e(r)}))}},m=function(e){e.touches&&e.touches.length>1||(v=t.wavesurfer.getDuration(),a=e.targetTouches?e.targetTouches[0].identifier:null,n=t.wrapper.scrollWidth-t.wrapper.clientWidth,u=t.wrapper.getBoundingClientRect(),r=!0,i=t.wavesurfer.drawer.handleEvent(e,!0),s=null,o=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 w=function(e){e.touches&&e.touches.length>1||(r=!1,p=0,o=null,s&&(t.util.preventClick(),s.fireEvent("update-end",e),t.wavesurfer.fireEvent("region-update-end",s,e)),s=null)};this.wrapper.addEventListener("mouseleave",w),this.wrapper.addEventListener("mouseup",w),this.wrapper.addEventListener("touchend",w),document.body.addEventListener("mouseup",w),document.body.addEventListener("touchend",w),this.on("disable-drag-selection",(function(){document.body.removeEventListener("mouseup",w),document.body.removeEventListener("touchend",w),t.wrapper.removeEventListener("touchend",w),t.wrapper.removeEventListener("mouseup",w),t.wrapper.removeEventListener("mouseleave",w)}));var b=function(n){if(r&&!(++p<=l)&&!(n.touches&&n.touches.length>1)&&(!n.targetTouches||n.targetTouches[0].identifier==a)&&(s||(s=t.add(e||{})))){var c=t.wavesurfer.drawer.handleEvent(n),m=t.wavesurfer.regions.util.getRegionSnapToGridValue(i*v),w=t.wavesurfer.regions.util.getRegionSnapToGridValue(c*v);if(s.update({start:Math.min(w,m),end:Math.max(w,m)}),d&&h.clientWidth=u.right-f?1:null)&&g(n)}}};this.wrapper.addEventListener("mousemove",b),this.wrapper.addEventListener("touchmove",b),this.on("disable-drag-selection",(function(){t.wrapper.removeEventListener("touchmove",b),t.wrapper.removeEventListener("mousemove",b)})),this.wavesurfer.on("region-created",(function(e){t.regionsMinLength&&(e.minLength=t.regionsMinLength)}))}},{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(n){var i=e.list[n];i.start<=t&&i.end>=t&&(!r||i.end-i.start{function r(e){return r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},r(e)}function n(e,t){for(var r=0;r=0&&se&&(r=e-((n=e)-r)),null!=this.minLength&&(n=Math.max(r+this.minLength,n)),null!=this.maxLength&&(n=Math.min(r+this.maxLength,n)),null!=this.element){var i=Math.round(r/e*t),s=Math.round(n/e*t)-i;for(var a in this.style(this.element,{left:i+"px",width:s+"px",backgroundColor:this.color,cursor:this.drag?"move":"default"}),this.attributes)this.element.setAttribute("data-region-"+a,this.attributes[a]);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){var r=Math.round(10*e.start)/10,n=Math.round(10*e.end)/10;t=Math.round(10*t)/10,!e.firedOut&&e.firedIn&&(r>t||n<=t)&&(e.firedOut=!0,e.firedIn=!1,e.fireEvent("out"),e.wavesurfer.fireEvent("region-out",e)),!e.firedIn&&r<=t&&n>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(){if(e.loop){var t=e.wavesurfer.getCurrentTime();t>=e.start&&t<=e.end&&e.wavesurfer.play(e.start)}}))}},{key:"bindEvents",value:function(){var e=this,t=this.preventContextMenu;this.element.addEventListener("mouseenter",(function(t){e.fireEvent("mouseenter",t),e.wavesurfer.fireEvent("region-mouseenter",e,t)})),this.element.addEventListener("mouseleave",(function(t){e.fireEvent("mouseleave",t),e.wavesurfer.fireEvent("region-mouseleave",e,t)})),this.element.addEventListener("click",(function(t){t.preventDefault(),e.fireEvent("click",t),e.wavesurfer.fireEvent("region-click",e,t)})),this.element.addEventListener("dblclick",(function(t){t.stopPropagation(),t.preventDefault(),e.fireEvent("dblclick",t),e.wavesurfer.fireEvent("region-dblclick",e,t)})),this.element.addEventListener("contextmenu",(function(r){t&&r.preventDefault(),e.fireEvent("contextmenu",r),e.wavesurfer.fireEvent("region-contextmenu",e,r)})),(this.drag||this.resize)&&this.bindDragEvents()}},{key:"bindDragEvents",value:function(){var e,t,r,n,i,s,a,o,u,l=this,h=this.wavesurfer.drawer.container,d=this.scrollSpeed,c=(this.scrollThreshold,!1),f=function t(h){var c=l.wavesurfer.getDuration();if(s&&(r||i)){var f=h.clientX,v=0,p=0,g=0,m=l.regionsUtil.getRegionSnapToGridValue(l.wavesurfer.drawer.handleEvent(h)*c);if(r)-1===s?(p=o*l.wavesurfer.params.minPxPerSec,v=f-a.left):(p=u*l.wavesurfer.params.minPxPerSec,v=a.right-f);else{var w=l.minLength;w||(w=0),"start"===i?(m>l.end-w&&(m=l.end-w,g=d*s),m<0&&(m=0)):"end"===i&&(mc&&(m=c))}if(-1===s){if(0===Math.round(l.wrapper.scrollLeft))return;if(Math.round(l.wrapper.scrollLeft-p+v)<=0)return}else{if(Math.round(l.wrapper.scrollLeft)===n)return;if(Math.round(l.wrapper.scrollLeft+p-v)>=n)return}var b=l.wrapper.scrollLeft-g+d*s;if(-1===s){var y=Math.max(0+p-v,b);l.wrapper.scrollLeft=b=y}else{var E=Math.min(n-p+v,b);l.wrapper.scrollLeft=b=E}var L=m-e;e=m,r?l.onDrag(L):l.onResize(L,i),window.requestAnimationFrame((function(){t(h)}))}},v=function(s){var h=l.wavesurfer.getDuration();s.touches&&s.touches.length>1||(t=s.targetTouches?s.targetTouches[0].identifier:null,(l.drag||l.resize)&&s.stopPropagation(),e=l.regionsUtil.getRegionSnapToGridValue(l.wavesurfer.drawer.handleEvent(s,!0)*h),o=e-l.start,u=l.end-e,n=l.wrapper.scrollWidth-l.wrapper.clientWidth,a=l.wrapper.getBoundingClientRect(),l.isResizing=!1,l.isDragging=!1,"handle"===s.target.tagName.toLowerCase()?(l.isResizing=!0,i=s.target.classList.contains("wavesurfer-handle-start")?"start":"end"):(l.isDragging=!0,r=!0,i=!1))},p=function(e){e.touches&&e.touches.length>1||((r||i)&&(l.isDragging=!1,l.isResizing=!1,r=!1,s=null,i=!1),c&&(c=!1,l.util.preventClick(),l.fireEvent("update-end",e),l.wavesurfer.fireEvent("region-update-end",l,e)))},g=function(n){var d=l.wavesurfer.getDuration();if(!(n.touches&&n.touches.length>1)&&(!n.targetTouches||n.targetTouches[0].identifier==t)&&(r||i)){var v=l.regionsUtil.getRegionSnapToGridValue(l.wavesurfer.drawer.handleEvent(n)*d);if(r){var p=l.wavesurfer.getDuration();v>p-u&&(v=p-u),v-o<0&&(v=o)}if(i){var g=l.minLength;g||(g=0),"start"===i?(v>l.end-g&&(v=l.end-g),v<0&&(v=0)):"end"===i&&(vd&&(v=d))}var m=v-e;if(e=v,l.drag&&r&&(c=c||!!m,l.onDrag(m)),l.resize&&i&&(c=c||!!m,l.onResize(m,i)),l.scroll&&h.clientWidtha.right-l.edgeScrollWidth?1:null}else{var b=n.clientX;s=ba.right-l.edgeScrollWidth?1:null}s&&f(n)}}};this.element.addEventListener("mousedown",v),this.element.addEventListener("touchstart",v),document.body.addEventListener("mousemove",g),document.body.addEventListener("touchmove",g),document.body.addEventListener("mouseup",p),document.body.addEventListener("touchend",p),this.on("remove",(function(){document.body.removeEventListener("mouseup",p),document.body.removeEventListener("touchend",p),document.body.removeEventListener("mousemove",g),document.body.removeEventListener("touchmove",g)})),this.wavesurfer.on("destroy",(function(){document.body.removeEventListener("mouseup",p),document.body.removeEventListener("touchend",p)}))}},{key:"onDrag",value:function(e){var t=this.wavesurfer.getDuration();this.end+e>t&&(e=t-this.end),this.start+e<0&&(e=-1*this.start),this.update({start:this.start+e,end:this.end+e})}},{key:"onResize",value:function(e,t){var r=this.wavesurfer.getDuration();"start"===t?(e>0&&this.end-(this.start+e)0&&this.end+e>r&&(e=r-this.end),this.update({start:Math.min(this.end+e,this.start),end:Math.max(this.end+e,this.start)}))}},{key:"updateHandlesResize",value:function(e){var t=e?"col-resize":"auto";this.handleLeftEl&&this.style(this.handleLeftEl,{cursor:t}),this.handleRightEl&&this.style(this.handleRightEl,{cursor:t})}}])&&n(t.prototype,r),i&&n(t,i),Object.defineProperty(t,"prototype",{writable:!1}),e}()}},t={};var r=function r(n){var i=t[n];if(void 0!==i)return i.exports;var s=t[n]={exports:{}};return e[n](s,s.exports,r),s.exports}(608);return r})())); //# sourceMappingURL=wavesurfer.regions.min.js.map