streamlit-nightly 1.41.2.dev20250119__py2.py3-none-any.whl → 1.41.2.dev20250122__py2.py3-none-any.whl
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.
- streamlit/config.py +14 -0
- streamlit/elements/vega_charts.py +19 -5
- streamlit/runtime/runtime.py +8 -3
- streamlit/static/index.html +2 -2
- streamlit/static/static/js/{FileDownload.esm.BUw5ikQY.js → FileDownload.esm.B5oak9Ia.js} +1 -1
- streamlit/static/static/js/{FormClearHelper.Bvmaiutv.js → FormClearHelper.DPFVZXH5.js} +1 -1
- streamlit/static/static/js/{Hooks.DcERo8tB.js → Hooks.FlVdDTii.js} +1 -1
- streamlit/static/static/js/{InputInstructions.BupGmSrJ.js → InputInstructions.BdYrHlrF.js} +1 -1
- streamlit/static/static/js/ProgressBar.DGXb6QOO.js +2 -0
- streamlit/static/static/js/{RenderInPortalIfExists.BhbPC-G8.js → RenderInPortalIfExists.DON4V-QO.js} +1 -1
- streamlit/static/static/js/Toolbar.CLiZhV_n.js +1 -0
- streamlit/static/static/js/{base-input.BBtHVXa2.js → base-input.DXAKraS2.js} +1 -1
- streamlit/static/static/js/{createSuper.BBR-BbJr.js → createSuper.D3jRSoi-.js} +1 -1
- streamlit/static/static/js/{data-grid-overlay-editor.DuZabixr.js → data-grid-overlay-editor.XiPt9jLK.js} +1 -1
- streamlit/static/static/js/{downloader.4xvEoIbd.js → downloader.CGTT4RY7.js} +1 -1
- streamlit/static/static/js/{es6.DmlLpYMO.js → es6.CDFMHaCm.js} +2 -2
- streamlit/static/static/js/{getPrototypeOf.M3x98UQ7.js → getPrototypeOf.IRomgPPd.js} +1 -1
- streamlit/static/static/js/{iframeResizer.contentWindow.CgYHddZ1.js → iframeResizer.contentWindow.CX6Wwtuu.js} +1 -1
- streamlit/static/static/js/{index.rOJcC1R3.js → index.B0Ui6vRC.js} +2 -2
- streamlit/static/static/js/{index.DcY4XgAF.js → index.B9-Y-BaD.js} +1 -1
- streamlit/static/static/js/{index.CkCtIbw0.js → index.B9_xTTEV.js} +1 -1
- streamlit/static/static/js/index.BBP4aKVi.js +1 -0
- streamlit/static/static/js/{index.CrcobIb0.js → index.BER0Q_9x.js} +56 -56
- streamlit/static/static/js/{index.CAZxiea2.js → index.BHgKtzWr.js} +2 -2
- streamlit/static/static/js/index.BIUi0PJE.js +3 -0
- streamlit/static/static/js/{index.DZdyNQo1.js → index.BMvd0REJ.js} +1 -1
- streamlit/static/static/js/index.BPivlwOm.js +1 -0
- streamlit/static/static/js/index.B_Ox2Ter.js +2 -0
- streamlit/static/static/js/{index.BaskQ92_.js → index.Ba40Nozz.js} +1 -1
- streamlit/static/static/js/{index.DysCLUsb.js → index.BasbevcS.js} +1 -1
- streamlit/static/static/js/{index.BYyuymTq.js → index.BeOUz4rC.js} +1 -1
- streamlit/static/static/js/{index.STXqYP7Q.js → index.BxUEHjBi.js} +1 -1
- streamlit/static/static/js/index.C42wlzzb.js +1 -0
- streamlit/static/static/js/index.C5QDcDeL.js +1 -0
- streamlit/static/static/js/index.C8iea7ju.js +1 -0
- streamlit/static/static/js/{index.DH9CvsgQ.js → index.C8wS6l2r.js} +1 -1
- streamlit/static/static/js/{index.C4Hwzvpq.js → index.CBc6ijSu.js} +1 -1
- streamlit/static/static/js/index.CHOk0J7Q.js +1 -0
- streamlit/static/static/js/{index.CC_t9mT8.js → index.CI0zYnTG.js} +1 -1
- streamlit/static/static/js/index.CUZhGVfE.js +197 -0
- streamlit/static/static/js/index.C_4dOSWN.js +1 -0
- streamlit/static/static/js/{index.CsdGlifB.js → index.ChXuNNZF.js} +13 -13
- streamlit/static/static/js/index.CyDO0RFh.js +1 -0
- streamlit/static/static/js/{index.DKi-ElEv.js → index.CzxmEs9w.js} +1 -1
- streamlit/static/static/js/{index.CjxOLcYo.js → index.DDM9v87n.js} +1 -1
- streamlit/static/static/js/{index.Bu8uxdTh.js → index.Dn7UmyWt.js} +2 -2
- streamlit/static/static/js/{index.C8nPrwl-.js → index.Dvhers7X.js} +1 -1
- streamlit/static/static/js/{index.CeKudMLQ.js → index.EtvrDk73.js} +1 -1
- streamlit/static/static/js/index.Ld6ZhSbF.js +1 -0
- streamlit/static/static/js/{index.61noqmIB.js → index.V-8vv3GC.js} +1 -1
- streamlit/static/static/js/index.WLh-TFDC.js +1 -0
- streamlit/static/static/js/{index.Bq6R9vFh.js → index.eDkLcswt.js} +1 -1
- streamlit/static/static/js/{index.DeeIZCGU.js → index.iX8U-Vgv.js} +3 -3
- streamlit/static/static/js/{index.g24MGpB6.js → index.lKc9LHL6.js} +2 -2
- streamlit/static/static/js/index.rmAI4WPp.js +1 -0
- streamlit/static/static/js/{input.BIth4Mda.js → input.l_XjOrMQ.js} +1 -1
- streamlit/static/static/js/{memory.C0ticMnk.js → memory.Ctihf9kR.js} +1 -1
- streamlit/static/static/js/{mergeWith.CnJI40Ol.js → mergeWith.C1vYu6FF.js} +1 -1
- streamlit/static/static/js/{number-overlay-editor.B4oKK-_Y.js → number-overlay-editor.B6AKIEFz.js} +1 -1
- streamlit/static/static/js/{sandbox.D1ghBIHY.js → sandbox.DhpripZd.js} +1 -1
- streamlit/static/static/js/{slicedToArray.C1s2cVDA.js → slicedToArray.C54-k4r_.js} +1 -1
- streamlit/static/static/js/{textarea.C1RJDJe0.js → textarea.C2VzK-E-.js} +1 -1
- streamlit/static/static/js/{timepicker.CmttWl-Y.js → timepicker.C6vlo4mG.js} +1 -1
- streamlit/static/static/js/{uniqueId.BT1SAZF-.js → uniqueId.C5O-wLYh.js} +1 -1
- streamlit/static/static/js/{useBasicWidgetState.BB9oQkjJ.js → useBasicWidgetState.nirky3Hn.js} +1 -1
- streamlit/static/static/js/{useOnInputChange.DldtvoCQ.js → useOnInputChange.DawRSruf.js} +1 -1
- streamlit/static/static/js/withFullScreenWrapper.DMpPC-b8.js +1 -0
- {streamlit_nightly-1.41.2.dev20250119.dist-info → streamlit_nightly-1.41.2.dev20250122.dist-info}/METADATA +1 -1
- {streamlit_nightly-1.41.2.dev20250119.dist-info → streamlit_nightly-1.41.2.dev20250122.dist-info}/RECORD +76 -76
- streamlit/static/static/js/ProgressBar.CTBNJVpb.js +0 -2
- streamlit/static/static/js/Toolbar.Dw79Vekz.js +0 -1
- streamlit/static/static/js/index.27TXU2hu.js +0 -1
- streamlit/static/static/js/index.AoUAN-9W.js +0 -1
- streamlit/static/static/js/index.B1KjaM9R.js +0 -1
- streamlit/static/static/js/index.BXejhz8S.js +0 -197
- streamlit/static/static/js/index.BtxHQDnZ.js +0 -1
- streamlit/static/static/js/index.C-0rgxAG.js +0 -1
- streamlit/static/static/js/index.C21AcM0r.js +0 -1
- streamlit/static/static/js/index.CuzQoPgT.js +0 -1
- streamlit/static/static/js/index.DqjAk5qg.js +0 -3
- streamlit/static/static/js/index.Dva5NuFG.js +0 -1
- streamlit/static/static/js/index.DvfPGXer.js +0 -1
- streamlit/static/static/js/index.PWzpo-hC.js +0 -2
- streamlit/static/static/js/index.WSrEkxsE.js +0 -1
- streamlit/static/static/js/index.tjVAqGRi.js +0 -1
- streamlit/static/static/js/withFullScreenWrapper.CWPfcXAP.js +0 -1
- /streamlit/static/static/css/{index.B26BQfSF.css → index.Bmkmz40k.css} +0 -0
- /streamlit/static/static/css/{index.BWGEWL3m.css → index.DBTu7gXp.css} +0 -0
- /streamlit/static/static/css/{index.CG16XVnL.css → index.DzuxGC_t.css} +0 -0
- {streamlit_nightly-1.41.2.dev20250119.data → streamlit_nightly-1.41.2.dev20250122.data}/scripts/streamlit.cmd +0 -0
- {streamlit_nightly-1.41.2.dev20250119.dist-info → streamlit_nightly-1.41.2.dev20250122.dist-info}/WHEEL +0 -0
- {streamlit_nightly-1.41.2.dev20250119.dist-info → streamlit_nightly-1.41.2.dev20250122.dist-info}/entry_points.txt +0 -0
- {streamlit_nightly-1.41.2.dev20250119.dist-info → streamlit_nightly-1.41.2.dev20250122.dist-info}/top_level.txt +0 -0
@@ -1,4 +1,4 @@
|
|
1
|
-
import{r as u,E as H,_ as V,aZ as ut,bi as Vt,bj as $t,bk as jt,A as G,D as X,R as yt,aA as Gt,n as x,bl as Xt,aB as N,j as v,bm as qt,b6 as Yt,bn as Zt,bo as Kt,ag as Jt,ae as Qt,bp as Q,ap as te,at as ee,bq as ie,br as ne,ba as se,bs as re}from"./index.CrcobIb0.js";import{u as oe,F as ae}from"./FormClearHelper.Bvmaiutv.js";import{T as le,a as pt}from"./Toolbar.Dw79Vekz.js";import{u as ce}from"./Hooks.DcERo8tB.js";import{c as de}from"./createDownloadLinkElement.DZMwyjvU.js";import{F as he,D as ue}from"./FileDownload.esm.BUw5ikQY.js";var wt=u.forwardRef(function(n,t){var e={fill:"currentColor",xmlns:"http://www.w3.org/2000/svg"};return u.createElement(H,V({iconAttrs:e,iconVerticalAlign:"middle",iconViewBox:"0 0 24 24"},n,{ref:t}),u.createElement("g",{fill:"none"},u.createElement("rect",{width:24,height:24}),u.createElement("rect",{width:24,height:24}),u.createElement("rect",{width:24,height:24})),u.createElement("path",{d:"M12 14c1.66 0 3-1.34 3-3V5c0-1.66-1.34-3-3-3S9 3.34 9 5v6c0 1.66 1.34 3 3 3z"}),u.createElement("path",{d:"M17 11c0 2.76-2.24 5-5 5s-5-2.24-5-5H5c0 3.53 2.61 6.43 6 6.92V21h2v-3.08c3.39-.49 6-3.39 6-6.92h-2z"}))});wt.displayName="Mic";var Ct=u.forwardRef(function(n,t){var e={fill:"currentColor",xmlns:"http://www.w3.org/2000/svg"};return u.createElement(H,V({iconAttrs:e,iconVerticalAlign:"middle",iconViewBox:"0 0 24 24"},n,{ref:t}),u.createElement("rect",{width:24,height:24,fill:"none"}),u.createElement("path",{d:"M8 19c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2s-2 .9-2 2v10c0 1.1.9 2 2 2zm6-12v10c0 1.1.9 2 2 2s2-.9 2-2V7c0-1.1-.9-2-2-2s-2 .9-2 2z"}))});Ct.displayName="Pause";var St=u.forwardRef(function(n,t){var e={fill:"currentColor",xmlns:"http://www.w3.org/2000/svg"};return u.createElement(H,V({iconAttrs:e,iconVerticalAlign:"middle",iconViewBox:"0 0 24 24"},n,{ref:t}),u.createElement("rect",{width:24,height:24,fill:"none"}),u.createElement("path",{d:"M8 6.82v10.36c0 .79.87 1.27 1.54.84l8.14-5.18a1 1 0 000-1.69L9.54 5.98A.998.998 0 008 6.82z"}))});St.displayName="PlayArrow";var Rt=u.forwardRef(function(n,t){var e={fill:"currentColor",xmlns:"http://www.w3.org/2000/svg"};return u.createElement(H,V({iconAttrs:e,iconVerticalAlign:"middle",iconViewBox:"0 0 24 24"},n,{ref:t}),u.createElement("path",{fill:"none",d:"M0 0h24v24H0V0z"}),u.createElement("path",{d:"M17.65 6.35a7.95 7.95 0 00-6.48-2.31c-3.67.37-6.69 3.35-7.1 7.02C3.52 15.91 7.27 20 12 20a7.98 7.98 0 007.21-4.56c.32-.67-.16-1.44-.9-1.44-.37 0-.72.2-.88.53a5.994 5.994 0 01-6.8 3.31c-2.22-.49-4.01-2.3-4.48-4.52A6.002 6.002 0 0112 6c1.66 0 3.14.69 4.22 1.78l-1.51 1.51c-.63.63-.19 1.71.7 1.71H19c.55 0 1-.45 1-1V6.41c0-.89-1.08-1.34-1.71-.71l-.64.65z"}))});Rt.displayName="Refresh";var Et=u.forwardRef(function(n,t){var e={fill:"currentColor",xmlns:"http://www.w3.org/2000/svg"};return u.createElement(H,V({iconAttrs:e,iconVerticalAlign:"middle",iconViewBox:"0 0 24 24"},n,{ref:t}),u.createElement("g",{fill:"none"},u.createElement("rect",{width:24,height:24}),u.createElement("rect",{width:24,height:24})),u.createElement("path",{fillRule:"evenodd",d:"M9 16h6c.55 0 1-.45 1-1V9c0-.55-.45-1-1-1H9c-.55 0-1 .45-1 1v6c0 .55.45 1 1 1zm3-14C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2z"}))});Et.displayName="StopCircle";function E(n,t,e,i){return new(e||(e=Promise))(function(r,s){function a(c){try{d(i.next(c))}catch(l){s(l)}}function o(c){try{d(i.throw(c))}catch(l){s(l)}}function d(c){var l;c.done?r(c.value):(l=c.value,l instanceof e?l:new e(function(p){p(l)})).then(a,o)}d((i=i.apply(n,t||[])).next())})}let $=class{constructor(){this.listeners={}}on(t,e,i){if(this.listeners[t]||(this.listeners[t]=new Set),this.listeners[t].add(e),i==null?void 0:i.once){const r=()=>{this.un(t,r),this.un(t,e)};return this.on(t,r),r}return()=>this.un(t,e)}un(t,e){var i;(i=this.listeners[t])===null||i===void 0||i.delete(e)}once(t,e){return this.on(t,e,{once:!0})}unAll(){this.listeners={}}emit(t,...e){this.listeners[t]&&this.listeners[t].forEach(i=>i(...e))}};const mt={decode:function(n,t){return E(this,void 0,void 0,function*(){const e=new AudioContext({sampleRate:t});return e.decodeAudioData(n).finally(()=>e.close())})},createBuffer:function(n,t){return typeof n[0]=="number"&&(n=[n]),function(e){const i=e[0];if(i.some(r=>r>1||r<-1)){const r=i.length;let s=0;for(let a=0;a<r;a++){const o=Math.abs(i[a]);o>s&&(s=o)}for(const a of e)for(let o=0;o<r;o++)a[o]/=s}}(n),{duration:t,length:n[0].length,sampleRate:n[0].length/t,numberOfChannels:n.length,getChannelData:e=>n==null?void 0:n[e],copyFromChannel:AudioBuffer.prototype.copyFromChannel,copyToChannel:AudioBuffer.prototype.copyToChannel}}};function xt(n,t){const e=t.xmlns?document.createElementNS(t.xmlns,n):document.createElement(n);for(const[i,r]of Object.entries(t))if(i==="children")for(const[s,a]of Object.entries(t))typeof a=="string"?e.appendChild(document.createTextNode(a)):e.appendChild(xt(s,a));else i==="style"?Object.assign(e.style,r):i==="textContent"?e.textContent=r:e.setAttribute(i,r.toString());return e}function ft(n,t,e){const i=xt(n,t||{});return e==null||e.appendChild(i),i}var pe=Object.freeze({__proto__:null,createElement:ft,default:ft});const me={fetchBlob:function(n,t,e){return E(this,void 0,void 0,function*(){const i=yield fetch(n,e);if(i.status>=400)throw new Error(`Failed to fetch ${n}: ${i.status} (${i.statusText})`);return function(r,s){E(this,void 0,void 0,function*(){if(!r.body||!r.headers)return;const a=r.body.getReader(),o=Number(r.headers.get("Content-Length"))||0;let d=0;const c=p=>E(this,void 0,void 0,function*(){d+=(p==null?void 0:p.length)||0;const h=Math.round(d/o*100);s(h)}),l=()=>E(this,void 0,void 0,function*(){let p;try{p=yield a.read()}catch{return}p.done||(c(p.value),yield l())});l()})}(i.clone(),t),i.blob()})}};class fe extends ${constructor(t){super(),this.isExternalMedia=!1,t.media?(this.media=t.media,this.isExternalMedia=!0):this.media=document.createElement("audio"),t.mediaControls&&(this.media.controls=!0),t.autoplay&&(this.media.autoplay=!0),t.playbackRate!=null&&this.onMediaEvent("canplay",()=>{t.playbackRate!=null&&(this.media.playbackRate=t.playbackRate)},{once:!0})}onMediaEvent(t,e,i){return this.media.addEventListener(t,e,i),()=>this.media.removeEventListener(t,e,i)}getSrc(){return this.media.currentSrc||this.media.src||""}revokeSrc(){const t=this.getSrc();t.startsWith("blob:")&&URL.revokeObjectURL(t)}canPlayType(t){return this.media.canPlayType(t)!==""}setSrc(t,e){const i=this.getSrc();if(t&&i===t)return;this.revokeSrc();const r=e instanceof Blob&&(this.canPlayType(e.type)||!t)?URL.createObjectURL(e):t;try{this.media.src=r}catch{this.media.src=t}}destroy(){this.media.pause(),this.isExternalMedia||(this.media.remove(),this.revokeSrc(),this.media.src="",this.media.load())}setMediaElement(t){this.media=t}play(){return E(this,void 0,void 0,function*(){return this.media.play()})}pause(){this.media.pause()}isPlaying(){return!this.media.paused&&!this.media.ended}setTime(t){this.media.currentTime=t}getDuration(){return this.media.duration}getCurrentTime(){return this.media.currentTime}getVolume(){return this.media.volume}setVolume(t){this.media.volume=t}getMuted(){return this.media.muted}setMuted(t){this.media.muted=t}getPlaybackRate(){return this.media.playbackRate}isSeeking(){return this.media.seeking}setPlaybackRate(t,e){e!=null&&(this.media.preservesPitch=e),this.media.playbackRate=t}getMediaElement(){return this.media}setSinkId(t){return this.media.setSinkId(t)}}class U extends ${constructor(t,e){super(),this.timeouts=[],this.isScrollable=!1,this.audioData=null,this.resizeObserver=null,this.lastContainerWidth=0,this.isDragging=!1,this.subscriptions=[],this.subscriptions=[],this.options=t;const i=this.parentFromOptionsContainer(t.container);this.parent=i;const[r,s]=this.initHtml();i.appendChild(r),this.container=r,this.scrollContainer=s.querySelector(".scroll"),this.wrapper=s.querySelector(".wrapper"),this.canvasWrapper=s.querySelector(".canvases"),this.progressWrapper=s.querySelector(".progress"),this.cursor=s.querySelector(".cursor"),e&&s.appendChild(e),this.initEvents()}parentFromOptionsContainer(t){let e;if(typeof t=="string"?e=document.querySelector(t):t instanceof HTMLElement&&(e=t),!e)throw new Error("Container not found");return e}initEvents(){const t=e=>{const i=this.wrapper.getBoundingClientRect(),r=e.clientX-i.left,s=e.clientY-i.top;return[r/i.width,s/i.height]};if(this.wrapper.addEventListener("click",e=>{const[i,r]=t(e);this.emit("click",i,r)}),this.wrapper.addEventListener("dblclick",e=>{const[i,r]=t(e);this.emit("dblclick",i,r)}),this.options.dragToSeek!==!0&&typeof this.options.dragToSeek!="object"||this.initDrag(),this.scrollContainer.addEventListener("scroll",()=>{const{scrollLeft:e,scrollWidth:i,clientWidth:r}=this.scrollContainer,s=e/i,a=(e+r)/i;this.emit("scroll",s,a,e,e+r)}),typeof ResizeObserver=="function"){const e=this.createDelay(100);this.resizeObserver=new ResizeObserver(()=>{e().then(()=>this.onContainerResize()).catch(()=>{})}),this.resizeObserver.observe(this.scrollContainer)}}onContainerResize(){const t=this.parent.clientWidth;t===this.lastContainerWidth&&this.options.height!=="auto"||(this.lastContainerWidth=t,this.reRender())}initDrag(){this.subscriptions.push(function(t,e,i,r,s=3,a=0,o=100){if(!t)return()=>{};const d=matchMedia("(pointer: coarse)").matches;let c=()=>{};const l=p=>{if(p.button!==a)return;p.preventDefault(),p.stopPropagation();let h=p.clientX,m=p.clientY,f=!1;const b=Date.now(),g=C=>{if(C.preventDefault(),C.stopPropagation(),d&&Date.now()-b<o)return;const D=C.clientX,W=C.clientY,M=D-h,A=W-m;if(f||Math.abs(M)>s||Math.abs(A)>s){const I=t.getBoundingClientRect(),{left:F,top:L}=I;f||(i==null||i(h-F,m-L),f=!0),e(M,A,D-F,W-L),h=D,m=W}},w=C=>{if(f){const D=C.clientX,W=C.clientY,M=t.getBoundingClientRect(),{left:A,top:I}=M;r==null||r(D-A,W-I)}c()},y=C=>{C.relatedTarget&&C.relatedTarget!==document.documentElement||w(C)},P=C=>{f&&(C.stopPropagation(),C.preventDefault())},T=C=>{f&&C.preventDefault()};document.addEventListener("pointermove",g),document.addEventListener("pointerup",w),document.addEventListener("pointerout",y),document.addEventListener("pointercancel",y),document.addEventListener("touchmove",T,{passive:!1}),document.addEventListener("click",P,{capture:!0}),c=()=>{document.removeEventListener("pointermove",g),document.removeEventListener("pointerup",w),document.removeEventListener("pointerout",y),document.removeEventListener("pointercancel",y),document.removeEventListener("touchmove",T),setTimeout(()=>{document.removeEventListener("click",P,{capture:!0})},10)}};return t.addEventListener("pointerdown",l),()=>{c(),t.removeEventListener("pointerdown",l)}}(this.wrapper,(t,e,i)=>{this.emit("drag",Math.max(0,Math.min(1,i/this.wrapper.getBoundingClientRect().width)))},t=>{this.isDragging=!0,this.emit("dragstart",Math.max(0,Math.min(1,t/this.wrapper.getBoundingClientRect().width)))},t=>{this.isDragging=!1,this.emit("dragend",Math.max(0,Math.min(1,t/this.wrapper.getBoundingClientRect().width)))}))}getHeight(t,e){var i;const r=((i=this.audioData)===null||i===void 0?void 0:i.numberOfChannels)||1;if(t==null)return 128;if(!isNaN(Number(t)))return Number(t);if(t==="auto"){const s=this.parent.clientHeight||128;return e!=null&&e.every(a=>!a.overlay)?s/r:s}return 128}initHtml(){const t=document.createElement("div"),e=t.attachShadow({mode:"open"}),i=this.options.cspNonce&&typeof this.options.cspNonce=="string"?this.options.cspNonce.replace(/"/g,""):"";return e.innerHTML=`
|
1
|
+
import{r as u,E as H,_ as V,aZ as ut,bi as Vt,bj as $t,bk as jt,J as G,M as X,R as yt,aC as Gt,n as x,bl as Xt,z as N,j as v,bm as qt,b6 as Yt,bn as Zt,bo as Jt,am as Kt,y as Qt,bp as Q,av as te,az as ee,bq as ie,br as ne,ba as se,bs as re}from"./index.BER0Q_9x.js";import{u as oe,F as ae}from"./FormClearHelper.DPFVZXH5.js";import{T as le,a as pt}from"./Toolbar.CLiZhV_n.js";import{u as ce}from"./Hooks.FlVdDTii.js";import{c as de}from"./createDownloadLinkElement.DZMwyjvU.js";import{F as he,D as ue}from"./FileDownload.esm.B5oak9Ia.js";var wt=u.forwardRef(function(n,t){var e={fill:"currentColor",xmlns:"http://www.w3.org/2000/svg"};return u.createElement(H,V({iconAttrs:e,iconVerticalAlign:"middle",iconViewBox:"0 0 24 24"},n,{ref:t}),u.createElement("g",{fill:"none"},u.createElement("rect",{width:24,height:24}),u.createElement("rect",{width:24,height:24}),u.createElement("rect",{width:24,height:24})),u.createElement("path",{d:"M12 14c1.66 0 3-1.34 3-3V5c0-1.66-1.34-3-3-3S9 3.34 9 5v6c0 1.66 1.34 3 3 3z"}),u.createElement("path",{d:"M17 11c0 2.76-2.24 5-5 5s-5-2.24-5-5H5c0 3.53 2.61 6.43 6 6.92V21h2v-3.08c3.39-.49 6-3.39 6-6.92h-2z"}))});wt.displayName="Mic";var Ct=u.forwardRef(function(n,t){var e={fill:"currentColor",xmlns:"http://www.w3.org/2000/svg"};return u.createElement(H,V({iconAttrs:e,iconVerticalAlign:"middle",iconViewBox:"0 0 24 24"},n,{ref:t}),u.createElement("rect",{width:24,height:24,fill:"none"}),u.createElement("path",{d:"M8 19c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2s-2 .9-2 2v10c0 1.1.9 2 2 2zm6-12v10c0 1.1.9 2 2 2s2-.9 2-2V7c0-1.1-.9-2-2-2s-2 .9-2 2z"}))});Ct.displayName="Pause";var St=u.forwardRef(function(n,t){var e={fill:"currentColor",xmlns:"http://www.w3.org/2000/svg"};return u.createElement(H,V({iconAttrs:e,iconVerticalAlign:"middle",iconViewBox:"0 0 24 24"},n,{ref:t}),u.createElement("rect",{width:24,height:24,fill:"none"}),u.createElement("path",{d:"M8 6.82v10.36c0 .79.87 1.27 1.54.84l8.14-5.18a1 1 0 000-1.69L9.54 5.98A.998.998 0 008 6.82z"}))});St.displayName="PlayArrow";var Rt=u.forwardRef(function(n,t){var e={fill:"currentColor",xmlns:"http://www.w3.org/2000/svg"};return u.createElement(H,V({iconAttrs:e,iconVerticalAlign:"middle",iconViewBox:"0 0 24 24"},n,{ref:t}),u.createElement("path",{fill:"none",d:"M0 0h24v24H0V0z"}),u.createElement("path",{d:"M17.65 6.35a7.95 7.95 0 00-6.48-2.31c-3.67.37-6.69 3.35-7.1 7.02C3.52 15.91 7.27 20 12 20a7.98 7.98 0 007.21-4.56c.32-.67-.16-1.44-.9-1.44-.37 0-.72.2-.88.53a5.994 5.994 0 01-6.8 3.31c-2.22-.49-4.01-2.3-4.48-4.52A6.002 6.002 0 0112 6c1.66 0 3.14.69 4.22 1.78l-1.51 1.51c-.63.63-.19 1.71.7 1.71H19c.55 0 1-.45 1-1V6.41c0-.89-1.08-1.34-1.71-.71l-.64.65z"}))});Rt.displayName="Refresh";var Et=u.forwardRef(function(n,t){var e={fill:"currentColor",xmlns:"http://www.w3.org/2000/svg"};return u.createElement(H,V({iconAttrs:e,iconVerticalAlign:"middle",iconViewBox:"0 0 24 24"},n,{ref:t}),u.createElement("g",{fill:"none"},u.createElement("rect",{width:24,height:24}),u.createElement("rect",{width:24,height:24})),u.createElement("path",{fillRule:"evenodd",d:"M9 16h6c.55 0 1-.45 1-1V9c0-.55-.45-1-1-1H9c-.55 0-1 .45-1 1v6c0 .55.45 1 1 1zm3-14C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2z"}))});Et.displayName="StopCircle";function E(n,t,e,i){return new(e||(e=Promise))(function(r,s){function a(c){try{d(i.next(c))}catch(l){s(l)}}function o(c){try{d(i.throw(c))}catch(l){s(l)}}function d(c){var l;c.done?r(c.value):(l=c.value,l instanceof e?l:new e(function(p){p(l)})).then(a,o)}d((i=i.apply(n,t||[])).next())})}let $=class{constructor(){this.listeners={}}on(t,e,i){if(this.listeners[t]||(this.listeners[t]=new Set),this.listeners[t].add(e),i==null?void 0:i.once){const r=()=>{this.un(t,r),this.un(t,e)};return this.on(t,r),r}return()=>this.un(t,e)}un(t,e){var i;(i=this.listeners[t])===null||i===void 0||i.delete(e)}once(t,e){return this.on(t,e,{once:!0})}unAll(){this.listeners={}}emit(t,...e){this.listeners[t]&&this.listeners[t].forEach(i=>i(...e))}};const mt={decode:function(n,t){return E(this,void 0,void 0,function*(){const e=new AudioContext({sampleRate:t});return e.decodeAudioData(n).finally(()=>e.close())})},createBuffer:function(n,t){return typeof n[0]=="number"&&(n=[n]),function(e){const i=e[0];if(i.some(r=>r>1||r<-1)){const r=i.length;let s=0;for(let a=0;a<r;a++){const o=Math.abs(i[a]);o>s&&(s=o)}for(const a of e)for(let o=0;o<r;o++)a[o]/=s}}(n),{duration:t,length:n[0].length,sampleRate:n[0].length/t,numberOfChannels:n.length,getChannelData:e=>n==null?void 0:n[e],copyFromChannel:AudioBuffer.prototype.copyFromChannel,copyToChannel:AudioBuffer.prototype.copyToChannel}}};function xt(n,t){const e=t.xmlns?document.createElementNS(t.xmlns,n):document.createElement(n);for(const[i,r]of Object.entries(t))if(i==="children")for(const[s,a]of Object.entries(t))typeof a=="string"?e.appendChild(document.createTextNode(a)):e.appendChild(xt(s,a));else i==="style"?Object.assign(e.style,r):i==="textContent"?e.textContent=r:e.setAttribute(i,r.toString());return e}function ft(n,t,e){const i=xt(n,t||{});return e==null||e.appendChild(i),i}var pe=Object.freeze({__proto__:null,createElement:ft,default:ft});const me={fetchBlob:function(n,t,e){return E(this,void 0,void 0,function*(){const i=yield fetch(n,e);if(i.status>=400)throw new Error(`Failed to fetch ${n}: ${i.status} (${i.statusText})`);return function(r,s){E(this,void 0,void 0,function*(){if(!r.body||!r.headers)return;const a=r.body.getReader(),o=Number(r.headers.get("Content-Length"))||0;let d=0;const c=p=>E(this,void 0,void 0,function*(){d+=(p==null?void 0:p.length)||0;const h=Math.round(d/o*100);s(h)}),l=()=>E(this,void 0,void 0,function*(){let p;try{p=yield a.read()}catch{return}p.done||(c(p.value),yield l())});l()})}(i.clone(),t),i.blob()})}};class fe extends ${constructor(t){super(),this.isExternalMedia=!1,t.media?(this.media=t.media,this.isExternalMedia=!0):this.media=document.createElement("audio"),t.mediaControls&&(this.media.controls=!0),t.autoplay&&(this.media.autoplay=!0),t.playbackRate!=null&&this.onMediaEvent("canplay",()=>{t.playbackRate!=null&&(this.media.playbackRate=t.playbackRate)},{once:!0})}onMediaEvent(t,e,i){return this.media.addEventListener(t,e,i),()=>this.media.removeEventListener(t,e,i)}getSrc(){return this.media.currentSrc||this.media.src||""}revokeSrc(){const t=this.getSrc();t.startsWith("blob:")&&URL.revokeObjectURL(t)}canPlayType(t){return this.media.canPlayType(t)!==""}setSrc(t,e){const i=this.getSrc();if(t&&i===t)return;this.revokeSrc();const r=e instanceof Blob&&(this.canPlayType(e.type)||!t)?URL.createObjectURL(e):t;try{this.media.src=r}catch{this.media.src=t}}destroy(){this.media.pause(),this.isExternalMedia||(this.media.remove(),this.revokeSrc(),this.media.src="",this.media.load())}setMediaElement(t){this.media=t}play(){return E(this,void 0,void 0,function*(){return this.media.play()})}pause(){this.media.pause()}isPlaying(){return!this.media.paused&&!this.media.ended}setTime(t){this.media.currentTime=t}getDuration(){return this.media.duration}getCurrentTime(){return this.media.currentTime}getVolume(){return this.media.volume}setVolume(t){this.media.volume=t}getMuted(){return this.media.muted}setMuted(t){this.media.muted=t}getPlaybackRate(){return this.media.playbackRate}isSeeking(){return this.media.seeking}setPlaybackRate(t,e){e!=null&&(this.media.preservesPitch=e),this.media.playbackRate=t}getMediaElement(){return this.media}setSinkId(t){return this.media.setSinkId(t)}}class U extends ${constructor(t,e){super(),this.timeouts=[],this.isScrollable=!1,this.audioData=null,this.resizeObserver=null,this.lastContainerWidth=0,this.isDragging=!1,this.subscriptions=[],this.subscriptions=[],this.options=t;const i=this.parentFromOptionsContainer(t.container);this.parent=i;const[r,s]=this.initHtml();i.appendChild(r),this.container=r,this.scrollContainer=s.querySelector(".scroll"),this.wrapper=s.querySelector(".wrapper"),this.canvasWrapper=s.querySelector(".canvases"),this.progressWrapper=s.querySelector(".progress"),this.cursor=s.querySelector(".cursor"),e&&s.appendChild(e),this.initEvents()}parentFromOptionsContainer(t){let e;if(typeof t=="string"?e=document.querySelector(t):t instanceof HTMLElement&&(e=t),!e)throw new Error("Container not found");return e}initEvents(){const t=e=>{const i=this.wrapper.getBoundingClientRect(),r=e.clientX-i.left,s=e.clientY-i.top;return[r/i.width,s/i.height]};if(this.wrapper.addEventListener("click",e=>{const[i,r]=t(e);this.emit("click",i,r)}),this.wrapper.addEventListener("dblclick",e=>{const[i,r]=t(e);this.emit("dblclick",i,r)}),this.options.dragToSeek!==!0&&typeof this.options.dragToSeek!="object"||this.initDrag(),this.scrollContainer.addEventListener("scroll",()=>{const{scrollLeft:e,scrollWidth:i,clientWidth:r}=this.scrollContainer,s=e/i,a=(e+r)/i;this.emit("scroll",s,a,e,e+r)}),typeof ResizeObserver=="function"){const e=this.createDelay(100);this.resizeObserver=new ResizeObserver(()=>{e().then(()=>this.onContainerResize()).catch(()=>{})}),this.resizeObserver.observe(this.scrollContainer)}}onContainerResize(){const t=this.parent.clientWidth;t===this.lastContainerWidth&&this.options.height!=="auto"||(this.lastContainerWidth=t,this.reRender())}initDrag(){this.subscriptions.push(function(t,e,i,r,s=3,a=0,o=100){if(!t)return()=>{};const d=matchMedia("(pointer: coarse)").matches;let c=()=>{};const l=p=>{if(p.button!==a)return;p.preventDefault(),p.stopPropagation();let h=p.clientX,m=p.clientY,f=!1;const b=Date.now(),g=C=>{if(C.preventDefault(),C.stopPropagation(),d&&Date.now()-b<o)return;const D=C.clientX,W=C.clientY,M=D-h,A=W-m;if(f||Math.abs(M)>s||Math.abs(A)>s){const I=t.getBoundingClientRect(),{left:F,top:L}=I;f||(i==null||i(h-F,m-L),f=!0),e(M,A,D-F,W-L),h=D,m=W}},w=C=>{if(f){const D=C.clientX,W=C.clientY,M=t.getBoundingClientRect(),{left:A,top:I}=M;r==null||r(D-A,W-I)}c()},y=C=>{C.relatedTarget&&C.relatedTarget!==document.documentElement||w(C)},P=C=>{f&&(C.stopPropagation(),C.preventDefault())},T=C=>{f&&C.preventDefault()};document.addEventListener("pointermove",g),document.addEventListener("pointerup",w),document.addEventListener("pointerout",y),document.addEventListener("pointercancel",y),document.addEventListener("touchmove",T,{passive:!1}),document.addEventListener("click",P,{capture:!0}),c=()=>{document.removeEventListener("pointermove",g),document.removeEventListener("pointerup",w),document.removeEventListener("pointerout",y),document.removeEventListener("pointercancel",y),document.removeEventListener("touchmove",T),setTimeout(()=>{document.removeEventListener("click",P,{capture:!0})},10)}};return t.addEventListener("pointerdown",l),()=>{c(),t.removeEventListener("pointerdown",l)}}(this.wrapper,(t,e,i)=>{this.emit("drag",Math.max(0,Math.min(1,i/this.wrapper.getBoundingClientRect().width)))},t=>{this.isDragging=!0,this.emit("dragstart",Math.max(0,Math.min(1,t/this.wrapper.getBoundingClientRect().width)))},t=>{this.isDragging=!1,this.emit("dragend",Math.max(0,Math.min(1,t/this.wrapper.getBoundingClientRect().width)))}))}getHeight(t,e){var i;const r=((i=this.audioData)===null||i===void 0?void 0:i.numberOfChannels)||1;if(t==null)return 128;if(!isNaN(Number(t)))return Number(t);if(t==="auto"){const s=this.parent.clientHeight||128;return e!=null&&e.every(a=>!a.overlay)?s/r:s}return 128}initHtml(){const t=document.createElement("div"),e=t.attachShadow({mode:"open"}),i=this.options.cspNonce&&typeof this.options.cspNonce=="string"?this.options.cspNonce.replace(/"/g,""):"";return e.innerHTML=`
|
2
2
|
<style${i?` nonce="${i}"`:""}>
|
3
3
|
:host {
|
4
4
|
user-select: none;
|
@@ -70,4 +70,4 @@ import{r as u,E as H,_ as V,aZ as ut,bi as Vt,bj as $t,bk as jt,A as G,D as X,R
|
|
70
70
|
<div class="cursor" part="cursor"></div>
|
71
71
|
</div>
|
72
72
|
</div>
|
73
|
-
`,[t,e]}setOptions(t){if(this.options.container!==t.container){const e=this.parentFromOptionsContainer(t.container);e.appendChild(this.container),this.parent=e}t.dragToSeek!==!0&&typeof this.options.dragToSeek!="object"||this.initDrag(),this.options=t,this.reRender()}getWrapper(){return this.wrapper}getWidth(){return this.scrollContainer.clientWidth}getScroll(){return this.scrollContainer.scrollLeft}setScroll(t){this.scrollContainer.scrollLeft=t}setScrollPercentage(t){const{scrollWidth:e}=this.scrollContainer,i=e*t;this.setScroll(i)}destroy(){var t,e;this.subscriptions.forEach(i=>i()),this.container.remove(),(t=this.resizeObserver)===null||t===void 0||t.disconnect(),(e=this.unsubscribeOnScroll)===null||e===void 0||e.call(this)}createDelay(t=10){let e,i;const r=()=>{e&&clearTimeout(e),i&&i()};return this.timeouts.push(r),()=>new Promise((s,a)=>{r(),i=a,e=setTimeout(()=>{e=void 0,i=void 0,s()},t)})}convertColorValues(t){if(!Array.isArray(t))return t||"";if(t.length<2)return t[0]||"";const e=document.createElement("canvas"),i=e.getContext("2d"),r=e.height*(window.devicePixelRatio||1),s=i.createLinearGradient(0,0,0,r),a=1/(t.length-1);return t.forEach((o,d)=>{const c=d*a;s.addColorStop(c,o)}),s}getPixelRatio(){return Math.max(1,window.devicePixelRatio||1)}renderBarWaveform(t,e,i,r){const s=t[0],a=t[1]||t[0],o=s.length,{width:d,height:c}=i.canvas,l=c/2,p=this.getPixelRatio(),h=e.barWidth?e.barWidth*p:1,m=e.barGap?e.barGap*p:e.barWidth?h/2:0,f=e.barRadius||0,b=d/(h+m)/o,g=f&&"roundRect"in i?"roundRect":"rect";i.beginPath();let w=0,y=0,P=0;for(let T=0;T<=o;T++){const C=Math.round(T*b);if(C>w){const M=Math.round(y*l*r),A=M+Math.round(P*l*r)||1;let I=l-M;e.barAlign==="top"?I=0:e.barAlign==="bottom"&&(I=c-A),i[g](w*(h+m),I,h,A,f),w=C,y=0,P=0}const D=Math.abs(s[T]||0),W=Math.abs(a[T]||0);D>y&&(y=D),W>P&&(P=W)}i.fill(),i.closePath()}renderLineWaveform(t,e,i,r){const s=a=>{const o=t[a]||t[0],d=o.length,{height:c}=i.canvas,l=c/2,p=i.canvas.width/d;i.moveTo(0,l);let h=0,m=0;for(let f=0;f<=d;f++){const b=Math.round(f*p);if(b>h){const w=l+(Math.round(m*l*r)||1)*(a===0?-1:1);i.lineTo(h,w),h=b,m=0}const g=Math.abs(o[f]||0);g>m&&(m=g)}i.lineTo(h,l)};i.beginPath(),s(0),s(1),i.fill(),i.closePath()}renderWaveform(t,e,i){if(i.fillStyle=this.convertColorValues(e.waveColor),e.renderFunction)return void e.renderFunction(t,i);let r=e.barHeight||1;if(e.normalize){const s=Array.from(t[0]).reduce((a,o)=>Math.max(a,Math.abs(o)),0);r=s?1/s:1}e.barWidth||e.barGap||e.barAlign?this.renderBarWaveform(t,e,i,r):this.renderLineWaveform(t,e,i,r)}renderSingleCanvas(t,e,i,r,s,a,o){const d=this.getPixelRatio(),c=document.createElement("canvas");c.width=Math.round(i*d),c.height=Math.round(r*d),c.style.width=`${i}px`,c.style.height=`${r}px`,c.style.left=`${Math.round(s)}px`,a.appendChild(c);const l=c.getContext("2d");if(this.renderWaveform(t,e,l),c.width>0&&c.height>0){const p=c.cloneNode(),h=p.getContext("2d");h.drawImage(c,0,0),h.globalCompositeOperation="source-in",h.fillStyle=this.convertColorValues(e.progressColor),h.fillRect(0,0,c.width,c.height),o.appendChild(p)}}renderMultiCanvas(t,e,i,r,s,a){const o=this.getPixelRatio(),{clientWidth:d}=this.scrollContainer,c=i/o;let l=Math.min(U.MAX_CANVAS_WIDTH,d,c),p={};if(e.barWidth||e.barGap){const g=e.barWidth||.5,w=g+(e.barGap||g/2);l%w!=0&&(l=Math.floor(l/w)*w)}const h=g=>{if(g<0||g>=m||p[g])return;p[g]=!0;const w=g*l,y=Math.min(c-w,l);if(y<=0)return;const P=t.map(T=>{const C=Math.floor(w/c*T.length),D=Math.floor((w+y)/c*T.length);return T.slice(C,D)});this.renderSingleCanvas(P,e,y,r,w,s,a)},m=Math.ceil(c/l);if(!this.isScrollable){for(let g=0;g<m;g++)h(g);return}const f=this.scrollContainer.scrollLeft/c,b=Math.floor(f*m);h(b-1),h(b),h(b+1),m>1&&(this.unsubscribeOnScroll=this.on("scroll",()=>{const{scrollLeft:g}=this.scrollContainer,w=Math.floor(g/c*m);Object.keys(p).length>U.MAX_NODES&&(s.innerHTML="",a.innerHTML="",p={}),h(w-1),h(w),h(w+1)}))}renderChannel(t,e,i,r){var{overlay:s}=e,a=function(l,p){var h={};for(var m in l)Object.prototype.hasOwnProperty.call(l,m)&&p.indexOf(m)<0&&(h[m]=l[m]);if(l!=null&&typeof Object.getOwnPropertySymbols=="function"){var f=0;for(m=Object.getOwnPropertySymbols(l);f<m.length;f++)p.indexOf(m[f])<0&&Object.prototype.propertyIsEnumerable.call(l,m[f])&&(h[m[f]]=l[m[f]])}return h}(e,["overlay"]);const o=document.createElement("div"),d=this.getHeight(a.height,a.splitChannels);o.style.height=`${d}px`,s&&r>0&&(o.style.marginTop=`-${d}px`),this.canvasWrapper.style.minHeight=`${d}px`,this.canvasWrapper.appendChild(o);const c=o.cloneNode();this.progressWrapper.appendChild(c),this.renderMultiCanvas(t,a,i,d,o,c)}render(t){return E(this,void 0,void 0,function*(){var e;this.timeouts.forEach(d=>d()),this.timeouts=[],this.canvasWrapper.innerHTML="",this.progressWrapper.innerHTML="",this.options.width!=null&&(this.scrollContainer.style.width=typeof this.options.width=="number"?`${this.options.width}px`:this.options.width);const i=this.getPixelRatio(),r=this.scrollContainer.clientWidth,s=Math.ceil(t.duration*(this.options.minPxPerSec||0));this.isScrollable=s>r;const a=this.options.fillParent&&!this.isScrollable,o=(a?r:s)*i;if(this.wrapper.style.width=a?"100%":`${s}px`,this.scrollContainer.style.overflowX=this.isScrollable?"auto":"hidden",this.scrollContainer.classList.toggle("noScrollbar",!!this.options.hideScrollbar),this.cursor.style.backgroundColor=`${this.options.cursorColor||this.options.progressColor}`,this.cursor.style.width=`${this.options.cursorWidth}px`,this.audioData=t,this.emit("render"),this.options.splitChannels)for(let d=0;d<t.numberOfChannels;d++){const c=Object.assign(Object.assign({},this.options),(e=this.options.splitChannels)===null||e===void 0?void 0:e[d]);this.renderChannel([t.getChannelData(d)],c,o,d)}else{const d=[t.getChannelData(0)];t.numberOfChannels>1&&d.push(t.getChannelData(1)),this.renderChannel(d,this.options,o,0)}Promise.resolve().then(()=>this.emit("rendered"))})}reRender(){var t;if((t=this.unsubscribeOnScroll)===null||t===void 0||t.call(this),delete this.unsubscribeOnScroll,!this.audioData)return;const{scrollWidth:e}=this.scrollContainer,{right:i}=this.progressWrapper.getBoundingClientRect();if(this.render(this.audioData),this.isScrollable&&e!==this.scrollContainer.scrollWidth){const{right:r}=this.progressWrapper.getBoundingClientRect();let s=r-i;s*=2,s=s<0?Math.floor(s):Math.ceil(s),s/=2,this.scrollContainer.scrollLeft+=s}}zoom(t){this.options.minPxPerSec=t,this.reRender()}scrollIntoView(t,e=!1){const{scrollLeft:i,scrollWidth:r,clientWidth:s}=this.scrollContainer,a=t*r,o=i,d=i+s,c=s/2;if(this.isDragging)a+30>d?this.scrollContainer.scrollLeft+=30:a-30<o&&(this.scrollContainer.scrollLeft-=30);else{(a<o||a>d)&&(this.scrollContainer.scrollLeft=a-(this.options.autoCenter?c:0));const l=a-i-c;e&&this.options.autoCenter&&l>0&&(this.scrollContainer.scrollLeft+=Math.min(l,10))}{const l=this.scrollContainer.scrollLeft,p=l/r,h=(l+s)/r;this.emit("scroll",p,h,l,l+s)}}renderProgress(t,e){if(isNaN(t))return;const i=100*t;this.canvasWrapper.style.clipPath=`polygon(${i}% 0, 100% 0, 100% 100%, ${i}% 100%)`,this.progressWrapper.style.width=`${i}%`,this.cursor.style.left=`${i}%`,this.cursor.style.transform=`translateX(-${Math.round(i)===100?this.options.cursorWidth:0}px)`,this.isScrollable&&this.options.autoScroll&&this.scrollIntoView(t,e)}exportImage(t,e,i){return E(this,void 0,void 0,function*(){const r=this.canvasWrapper.querySelectorAll("canvas");if(!r.length)throw new Error("No waveform data");if(i==="dataURL"){const s=Array.from(r).map(a=>a.toDataURL(t,e));return Promise.resolve(s)}return Promise.all(Array.from(r).map(s=>new Promise((a,o)=>{s.toBlob(d=>{d?a(d):o(new Error("Could not export image"))},t,e)})))})}}U.MAX_CANVAS_WIDTH=8e3,U.MAX_NODES=10;class ge extends ${constructor(){super(...arguments),this.unsubscribe=()=>{}}start(){this.unsubscribe=this.on("tick",()=>{requestAnimationFrame(()=>{this.emit("tick")})}),this.emit("tick")}stop(){this.unsubscribe()}destroy(){this.unsubscribe()}}class gt extends ${constructor(t=new AudioContext){super(),this.bufferNode=null,this.playStartTime=0,this.playedDuration=0,this._muted=!1,this._playbackRate=1,this._duration=void 0,this.buffer=null,this.currentSrc="",this.paused=!0,this.crossOrigin=null,this.seeking=!1,this.autoplay=!1,this.addEventListener=this.on,this.removeEventListener=this.un,this.audioContext=t,this.gainNode=this.audioContext.createGain(),this.gainNode.connect(this.audioContext.destination)}load(){return E(this,void 0,void 0,function*(){})}get src(){return this.currentSrc}set src(t){if(this.currentSrc=t,this._duration=void 0,!t)return this.buffer=null,void this.emit("emptied");fetch(t).then(e=>{if(e.status>=400)throw new Error(`Failed to fetch ${t}: ${e.status} (${e.statusText})`);return e.arrayBuffer()}).then(e=>this.currentSrc!==t?null:this.audioContext.decodeAudioData(e)).then(e=>{this.currentSrc===t&&(this.buffer=e,this.emit("loadedmetadata"),this.emit("canplay"),this.autoplay&&this.play())})}_play(){var t;if(!this.paused)return;this.paused=!1,(t=this.bufferNode)===null||t===void 0||t.disconnect(),this.bufferNode=this.audioContext.createBufferSource(),this.buffer&&(this.bufferNode.buffer=this.buffer),this.bufferNode.playbackRate.value=this._playbackRate,this.bufferNode.connect(this.gainNode);let e=this.playedDuration*this._playbackRate;e>=this.duration&&(e=0,this.playedDuration=0),this.bufferNode.start(this.audioContext.currentTime,e),this.playStartTime=this.audioContext.currentTime,this.bufferNode.onended=()=>{this.currentTime>=this.duration&&(this.pause(),this.emit("ended"))}}_pause(){var t;this.paused=!0,(t=this.bufferNode)===null||t===void 0||t.stop(),this.playedDuration+=this.audioContext.currentTime-this.playStartTime}play(){return E(this,void 0,void 0,function*(){this.paused&&(this._play(),this.emit("play"))})}pause(){this.paused||(this._pause(),this.emit("pause"))}stopAt(t){var e,i;const r=t-this.currentTime;(e=this.bufferNode)===null||e===void 0||e.stop(this.audioContext.currentTime+r),(i=this.bufferNode)===null||i===void 0||i.addEventListener("ended",()=>{this.bufferNode=null,this.pause()},{once:!0})}setSinkId(t){return E(this,void 0,void 0,function*(){return this.audioContext.setSinkId(t)})}get playbackRate(){return this._playbackRate}set playbackRate(t){this._playbackRate=t,this.bufferNode&&(this.bufferNode.playbackRate.value=t)}get currentTime(){return(this.paused?this.playedDuration:this.playedDuration+(this.audioContext.currentTime-this.playStartTime))*this._playbackRate}set currentTime(t){const e=!this.paused;e&&this._pause(),this.playedDuration=t/this._playbackRate,e&&this._play(),this.emit("seeking"),this.emit("timeupdate")}get duration(){var t,e;return(t=this._duration)!==null&&t!==void 0?t:((e=this.buffer)===null||e===void 0?void 0:e.duration)||0}set duration(t){this._duration=t}get volume(){return this.gainNode.gain.value}set volume(t){this.gainNode.gain.value=t,this.emit("volumechange")}get muted(){return this._muted}set muted(t){this._muted!==t&&(this._muted=t,this._muted?this.gainNode.disconnect():this.gainNode.connect(this.audioContext.destination))}canPlayType(t){return/^(audio|video)\//.test(t)}getGainNode(){return this.gainNode}getChannelData(){const t=[];if(!this.buffer)return t;const e=this.buffer.numberOfChannels;for(let i=0;i<e;i++)t.push(this.buffer.getChannelData(i));return t}}const ve={waveColor:"#999",progressColor:"#555",cursorWidth:1,minPxPerSec:0,fillParent:!0,interact:!0,dragToSeek:!1,autoScroll:!0,autoCenter:!0,sampleRate:8e3};class z extends fe{static create(t){return new z(t)}constructor(t){const e=t.media||(t.backend==="WebAudio"?new gt:void 0);super({media:e,mediaControls:t.mediaControls,autoplay:t.autoplay,playbackRate:t.audioRate}),this.plugins=[],this.decodedData=null,this.subscriptions=[],this.mediaSubscriptions=[],this.abortController=null,this.options=Object.assign({},ve,t),this.timer=new ge;const i=e?void 0:this.getMediaElement();this.renderer=new U(this.options,i),this.initPlayerEvents(),this.initRendererEvents(),this.initTimerEvents(),this.initPlugins();const r=this.options.url||this.getSrc()||"";Promise.resolve().then(()=>{this.emit("init");const{peaks:s,duration:a}=this.options;(r||s&&a)&&this.load(r,s,a).catch(()=>null)})}updateProgress(t=this.getCurrentTime()){return this.renderer.renderProgress(t/this.getDuration(),this.isPlaying()),t}initTimerEvents(){this.subscriptions.push(this.timer.on("tick",()=>{if(!this.isSeeking()){const t=this.updateProgress();this.emit("timeupdate",t),this.emit("audioprocess",t)}}))}initPlayerEvents(){this.isPlaying()&&(this.emit("play"),this.timer.start()),this.mediaSubscriptions.push(this.onMediaEvent("timeupdate",()=>{const t=this.updateProgress();this.emit("timeupdate",t)}),this.onMediaEvent("play",()=>{this.emit("play"),this.timer.start()}),this.onMediaEvent("pause",()=>{this.emit("pause"),this.timer.stop()}),this.onMediaEvent("emptied",()=>{this.timer.stop()}),this.onMediaEvent("ended",()=>{this.emit("finish")}),this.onMediaEvent("seeking",()=>{this.emit("seeking",this.getCurrentTime())}),this.onMediaEvent("error",t=>{this.emit("error",t.error)}))}initRendererEvents(){this.subscriptions.push(this.renderer.on("click",(t,e)=>{this.options.interact&&(this.seekTo(t),this.emit("interaction",t*this.getDuration()),this.emit("click",t,e))}),this.renderer.on("dblclick",(t,e)=>{this.emit("dblclick",t,e)}),this.renderer.on("scroll",(t,e,i,r)=>{const s=this.getDuration();this.emit("scroll",t*s,e*s,i,r)}),this.renderer.on("render",()=>{this.emit("redraw")}),this.renderer.on("rendered",()=>{this.emit("redrawcomplete")}),this.renderer.on("dragstart",t=>{this.emit("dragstart",t)}),this.renderer.on("dragend",t=>{this.emit("dragend",t)}));{let t;this.subscriptions.push(this.renderer.on("drag",e=>{if(!this.options.interact)return;let i;this.renderer.renderProgress(e),clearTimeout(t),this.isPlaying()?i=0:this.options.dragToSeek===!0?i=200:typeof this.options.dragToSeek=="object"&&this.options.dragToSeek!==void 0&&(i=this.options.dragToSeek.debounceTime),t=setTimeout(()=>{this.seekTo(e)},i),this.emit("interaction",e*this.getDuration()),this.emit("drag",e)}))}}initPlugins(){var t;!((t=this.options.plugins)===null||t===void 0)&&t.length&&this.options.plugins.forEach(e=>{this.registerPlugin(e)})}unsubscribePlayerEvents(){this.mediaSubscriptions.forEach(t=>t()),this.mediaSubscriptions=[]}setOptions(t){this.options=Object.assign({},this.options,t),this.renderer.setOptions(this.options),t.audioRate&&this.setPlaybackRate(t.audioRate),t.mediaControls!=null&&(this.getMediaElement().controls=t.mediaControls)}registerPlugin(t){return t._init(this),this.plugins.push(t),this.subscriptions.push(t.once("destroy",()=>{this.plugins=this.plugins.filter(e=>e!==t)})),t}getWrapper(){return this.renderer.getWrapper()}getWidth(){return this.renderer.getWidth()}getScroll(){return this.renderer.getScroll()}setScroll(t){return this.renderer.setScroll(t)}setScrollTime(t){const e=t/this.getDuration();this.renderer.setScrollPercentage(e)}getActivePlugins(){return this.plugins}loadAudio(t,e,i,r){return E(this,void 0,void 0,function*(){var s;if(this.emit("load",t),!this.options.media&&this.isPlaying()&&this.pause(),this.decodedData=null,!e&&!i){const o=this.options.fetchParams||{};window.AbortController&&!o.signal&&(this.abortController=new AbortController,o.signal=(s=this.abortController)===null||s===void 0?void 0:s.signal);const d=c=>this.emit("loading",c);e=yield me.fetchBlob(t,d,o)}this.setSrc(t,e);const a=yield new Promise(o=>{const d=r||this.getDuration();d?o(d):this.mediaSubscriptions.push(this.onMediaEvent("loadedmetadata",()=>o(this.getDuration()),{once:!0}))});if(!t&&!e){const o=this.getMediaElement();o instanceof gt&&(o.duration=a)}if(i)this.decodedData=mt.createBuffer(i,a||0);else if(e){const o=yield e.arrayBuffer();this.decodedData=yield mt.decode(o,this.options.sampleRate)}this.decodedData&&(this.emit("decode",this.getDuration()),this.renderer.render(this.decodedData)),this.emit("ready",this.getDuration())})}load(t,e,i){return E(this,void 0,void 0,function*(){try{return yield this.loadAudio(t,void 0,e,i)}catch(r){throw this.emit("error",r),r}})}loadBlob(t,e,i){return E(this,void 0,void 0,function*(){try{return yield this.loadAudio("",t,e,i)}catch(r){throw this.emit("error",r),r}})}zoom(t){if(!this.decodedData)throw new Error("No audio loaded");this.renderer.zoom(t),this.emit("zoom",t)}getDecodedData(){return this.decodedData}exportPeaks({channels:t=2,maxLength:e=8e3,precision:i=1e4}={}){if(!this.decodedData)throw new Error("The audio has not been decoded yet");const r=Math.min(t,this.decodedData.numberOfChannels),s=[];for(let a=0;a<r;a++){const o=this.decodedData.getChannelData(a),d=[],c=o.length/e;for(let l=0;l<e;l++){const p=o.slice(Math.floor(l*c),Math.ceil((l+1)*c));let h=0;for(let m=0;m<p.length;m++){const f=p[m];Math.abs(f)>Math.abs(h)&&(h=f)}d.push(Math.round(h*i)/i)}s.push(d)}return s}getDuration(){let t=super.getDuration()||0;return t!==0&&t!==1/0||!this.decodedData||(t=this.decodedData.duration),t}toggleInteraction(t){this.options.interact=t}setTime(t){super.setTime(t),this.updateProgress(t),this.emit("timeupdate",t)}seekTo(t){const e=this.getDuration()*t;this.setTime(e)}playPause(){return E(this,void 0,void 0,function*(){return this.isPlaying()?this.pause():this.play()})}stop(){this.pause(),this.setTime(0)}skip(t){this.setTime(this.getCurrentTime()+t)}empty(){this.load("",[[0]],.001)}setMediaElement(t){this.unsubscribePlayerEvents(),super.setMediaElement(t),this.initPlayerEvents()}exportImage(){return E(this,arguments,void 0,function*(t="image/png",e=1,i="dataURL"){return this.renderer.exportImage(t,e,i)})}destroy(){var t;this.emit("destroy"),(t=this.abortController)===null||t===void 0||t.abort(),this.plugins.forEach(e=>e.destroy()),this.subscriptions.forEach(e=>e()),this.unsubscribePlayerEvents(),this.timer.destroy(),this.renderer.destroy(),super.destroy()}}z.BasePlugin=class extends ${constructor(n){super(),this.subscriptions=[],this.options=n}onInit(){}_init(n){this.wavesurfer=n,this.onInit()}destroy(){this.emit("destroy"),this.subscriptions.forEach(n=>n())}},z.dom=pe;function tt(n,t,e,i){return new(e||(e=Promise))(function(r,s){function a(c){try{d(i.next(c))}catch(l){s(l)}}function o(c){try{d(i.throw(c))}catch(l){s(l)}}function d(c){var l;c.done?r(c.value):(l=c.value,l instanceof e?l:new e(function(p){p(l)})).then(a,o)}d((i=i.apply(n,[])).next())})}class Pt{constructor(){this.listeners={}}on(t,e,i){if(this.listeners[t]||(this.listeners[t]=new Set),this.listeners[t].add(e),i==null?void 0:i.once){const r=()=>{this.un(t,r),this.un(t,e)};return this.on(t,r),r}return()=>this.un(t,e)}un(t,e){var i;(i=this.listeners[t])===null||i===void 0||i.delete(e)}once(t,e){return this.on(t,e,{once:!0})}unAll(){this.listeners={}}emit(t,...e){this.listeners[t]&&this.listeners[t].forEach(i=>i(...e))}}class be extends Pt{constructor(t){super(),this.subscriptions=[],this.options=t}onInit(){}_init(t){this.wavesurfer=t,this.onInit()}destroy(){this.emit("destroy"),this.subscriptions.forEach(t=>t())}}class ye extends Pt{constructor(){super(...arguments),this.unsubscribe=()=>{}}start(){this.unsubscribe=this.on("tick",()=>{requestAnimationFrame(()=>{this.emit("tick")})}),this.emit("tick")}stop(){this.unsubscribe()}destroy(){this.unsubscribe()}}const we=["audio/webm","audio/wav","audio/mpeg","audio/mp4","audio/mp3"];class q extends be{constructor(t){var e,i,r,s,a,o;super(Object.assign(Object.assign({},t),{audioBitsPerSecond:(e=t.audioBitsPerSecond)!==null&&e!==void 0?e:128e3,scrollingWaveform:(i=t.scrollingWaveform)!==null&&i!==void 0&&i,scrollingWaveformWindow:(r=t.scrollingWaveformWindow)!==null&&r!==void 0?r:5,continuousWaveform:(s=t.continuousWaveform)!==null&&s!==void 0&&s,renderRecordedAudio:(a=t.renderRecordedAudio)===null||a===void 0||a,mediaRecorderTimeslice:(o=t.mediaRecorderTimeslice)!==null&&o!==void 0?o:void 0})),this.stream=null,this.mediaRecorder=null,this.dataWindow=null,this.isWaveformPaused=!1,this.lastStartTime=0,this.lastDuration=0,this.duration=0,this.timer=new ye,this.subscriptions.push(this.timer.on("tick",()=>{const d=performance.now()-this.lastStartTime;this.duration=this.isPaused()?this.duration:this.lastDuration+d,this.emit("record-progress",this.duration)}))}static create(t){return new q(t||{})}renderMicStream(t){var e;const i=new AudioContext,r=i.createMediaStreamSource(t),s=i.createAnalyser();r.connect(s),this.options.continuousWaveform&&(s.fftSize=32);const a=s.frequencyBinCount,o=new Float32Array(a);let d=0;this.wavesurfer&&((e=this.originalOptions)!==null&&e!==void 0||(this.originalOptions=Object.assign({},this.wavesurfer.options)),this.wavesurfer.options.interact=!1,this.options.scrollingWaveform&&(this.wavesurfer.options.cursorWidth=0));const c=setInterval(()=>{var l,p,h,m;if(!this.isWaveformPaused){if(s.getFloatTimeDomainData(o),this.options.scrollingWaveform){const f=Math.floor((this.options.scrollingWaveformWindow||0)*i.sampleRate),b=Math.min(f,this.dataWindow?this.dataWindow.length+a:a),g=new Float32Array(f);if(this.dataWindow){const w=Math.max(0,f-this.dataWindow.length);g.set(this.dataWindow.slice(-b+a),w)}g.set(o,f-a),this.dataWindow=g}else if(this.options.continuousWaveform){if(!this.dataWindow){const b=this.options.continuousWaveformDuration?Math.round(100*this.options.continuousWaveformDuration):((p=(l=this.wavesurfer)===null||l===void 0?void 0:l.getWidth())!==null&&p!==void 0?p:0)*window.devicePixelRatio;this.dataWindow=new Float32Array(b)}let f=0;for(let b=0;b<a;b++){const g=Math.abs(o[b]);g>f&&(f=g)}if(d+1>this.dataWindow.length){const b=new Float32Array(2*this.dataWindow.length);b.set(this.dataWindow,0),this.dataWindow=b}this.dataWindow[d]=f,d++}else this.dataWindow=o;if(this.wavesurfer){const f=((m=(h=this.dataWindow)===null||h===void 0?void 0:h.length)!==null&&m!==void 0?m:0)/100;this.wavesurfer.load("",[this.dataWindow],this.options.scrollingWaveform?this.options.scrollingWaveformWindow:f).then(()=>{this.wavesurfer&&this.options.continuousWaveform&&(this.wavesurfer.setTime(this.getDuration()/1e3),this.wavesurfer.options.minPxPerSec||this.wavesurfer.setOptions({minPxPerSec:this.wavesurfer.getWidth()/this.wavesurfer.getDuration()}))}).catch(b=>{console.error("Error rendering real-time recording data:",b)})}}},10);return{onDestroy:()=>{clearInterval(c),r==null||r.disconnect(),i==null||i.close()},onEnd:()=>{this.isWaveformPaused=!0,clearInterval(c),this.stopMic()}}}startMic(t){return tt(this,void 0,void 0,function*(){let e;try{e=yield navigator.mediaDevices.getUserMedia({audio:!(t!=null&&t.deviceId)||{deviceId:t.deviceId}})}catch(s){throw new Error("Error accessing the microphone: "+s.message)}const{onDestroy:i,onEnd:r}=this.renderMicStream(e);return this.subscriptions.push(this.once("destroy",i)),this.subscriptions.push(this.once("record-end",r)),this.stream=e,e})}stopMic(){this.stream&&(this.stream.getTracks().forEach(t=>t.stop()),this.stream=null,this.mediaRecorder=null)}startRecording(t){return tt(this,void 0,void 0,function*(){const e=this.stream||(yield this.startMic(t));this.dataWindow=null;const i=this.mediaRecorder||new MediaRecorder(e,{mimeType:this.options.mimeType||we.find(a=>MediaRecorder.isTypeSupported(a)),audioBitsPerSecond:this.options.audioBitsPerSecond});this.mediaRecorder=i,this.stopRecording();const r=[];i.ondataavailable=a=>{a.data.size>0&&r.push(a.data),this.emit("record-data-available",a.data)};const s=a=>{var o;const d=new Blob(r,{type:i.mimeType});this.emit(a,d),this.options.renderRecordedAudio&&(this.applyOriginalOptionsIfNeeded(),(o=this.wavesurfer)===null||o===void 0||o.load(URL.createObjectURL(d)))};i.onpause=()=>s("record-pause"),i.onstop=()=>s("record-end"),i.start(this.options.mediaRecorderTimeslice),this.lastStartTime=performance.now(),this.lastDuration=0,this.duration=0,this.isWaveformPaused=!1,this.timer.start(),this.emit("record-start")})}getDuration(){return this.duration}isRecording(){var t;return((t=this.mediaRecorder)===null||t===void 0?void 0:t.state)==="recording"}isPaused(){var t;return((t=this.mediaRecorder)===null||t===void 0?void 0:t.state)==="paused"}isActive(){var t;return((t=this.mediaRecorder)===null||t===void 0?void 0:t.state)!=="inactive"}stopRecording(){var t;this.isActive()&&((t=this.mediaRecorder)===null||t===void 0||t.stop(),this.timer.stop())}pauseRecording(){var t,e;this.isRecording()&&(this.isWaveformPaused=!0,(t=this.mediaRecorder)===null||t===void 0||t.requestData(),(e=this.mediaRecorder)===null||e===void 0||e.pause(),this.timer.stop(),this.lastDuration=this.duration)}resumeRecording(){var t;this.isPaused()&&(this.isWaveformPaused=!1,(t=this.mediaRecorder)===null||t===void 0||t.resume(),this.timer.start(),this.lastStartTime=performance.now(),this.emit("record-resume"))}static getAvailableAudioDevices(){return tt(this,void 0,void 0,function*(){return navigator.mediaDevices.enumerateDevices().then(t=>t.filter(e=>e.kind==="audioinput"))})}destroy(){this.applyOriginalOptionsIfNeeded(),super.destroy(),this.stopRecording(),this.stopMic()}applyOriginalOptionsIfNeeded(){this.wavesurfer&&this.originalOptions&&(this.wavesurfer.setOptions(this.originalOptions),delete this.originalOptions)}}const Ce=async({files:n,uploadClient:t,widgetMgr:e,widgetInfo:i,fragmentId:r})=>{let s=[];try{s=await t.fetchFileURLs(n)}catch(c){return{successfulUploads:[],failedUploads:n.map(l=>({file:l,error:ut(c)}))}}const a=Vt(n,s),o=[],d=[];return await Promise.all(a.map(async([c,l])=>{if(!c||!l||!l.uploadUrl||!l.fileId)return{file:c,fileUrl:l,error:new Error("No upload URL found")};try{await t.uploadFile({id:l.fileId,formId:i.formId||""},l.uploadUrl,c),o.push({fileUrl:l,file:c})}catch(p){const h=ut(p);d.push({file:c,error:h})}})),e.setFileUploaderStateValue(i,new $t({uploadedFileInfo:o.map(({file:c,fileUrl:l})=>new jt({fileId:l.fileId,fileUrls:l,name:c.name,size:c.size}))}),{fromUi:!0},r),{successfulUploads:o,failedUploads:d}},et=({widgetMgr:n,id:t,formId:e,key:i,defaultValue:r})=>{u.useEffect(()=>{const l=n.getElementState(t,i);G(l)&&X(r)&&n.setElementState(t,i,r)},[n,t,i,r]);const[s,a]=u.useState(n.getElementState(t,i)??r),o=u.useCallback(l=>{n.setElementState(t,i,l),a(l)},[n,t,i]),d=u.useMemo(()=>({formId:e||""}),[e]),c=u.useCallback(()=>o(r),[r,o]);return oe({element:d,widgetMgr:n,onFormCleared:c}),[s,o]},Se=(n,t)=>{const{libConfig:{enforceDownloadInNewTab:e=!1}}=yt.useContext(Gt);return u.useCallback(()=>{if(!n)return;const r=de({enforceDownloadInNewTab:e,url:n,filename:t});r.style.display="none",document.body.appendChild(r),r.click(),document.body.removeChild(r)},[n,e,t])},Re=x("div",{target:"e1lme4w10"})(),vt=x("div",{target:"e1lme4w11"})(({theme:n})=>({height:n.sizes.largestElementHeight,width:"100%",background:n.colors.secondaryBg,borderRadius:n.radii.default,marginBottom:n.spacing.twoXS,display:"flex",alignItems:"center",position:"relative",paddingLeft:n.spacing.xs,paddingRight:n.spacing.sm})),Ee=x("div",{target:"e1lme4w12"})({flex:1}),xe=x("div",{target:"e1lme4w13"})(({show:n})=>({display:n?"block":"none"})),Pe=x("span",{target:"e1lme4w14"})(({theme:n,isPlayingOrRecording:t})=>({margin:n.spacing.sm,fontFamily:n.fonts.monospace,color:t?n.colors.bodyText:n.colors.fadedText60,backgroundColor:n.colors.secondaryBg,fontSize:n.fontSizes.sm})),Tt=x("div",{target:"e1lme4w15"})({width:"100%",textAlign:"center",overflow:"hidden"}),Dt=x("span",{target:"e1lme4w16"})(({theme:n})=>({color:n.colors.bodyText})),Te=x("a",{target:"e1lme4w17"})(({theme:n})=>({color:n.colors.linkText,textDecoration:"underline"})),De=x("div",{target:"e1lme4w18"})(({theme:n})=>({height:n.sizes.largestElementHeight,display:"flex",justifyContent:"center",alignItems:"center"})),We=x("div",{target:"e1lme4w19"})(({theme:n})=>{const t="0.625em";return{opacity:.2,width:"100%",height:t,backgroundSize:t,backgroundImage:`radial-gradient(${n.colors.fadedText10} 40%, transparent 40%)`,backgroundRepeat:"repeat"}}),Ae=x("span",{target:"e1lme4w110"})(({theme:n})=>({"& > button":{color:n.colors.primary,padding:n.spacing.threeXS},"& > button:hover, & > button:focus":{color:n.colors.red}})),ke=x("span",{target:"e1lme4w111"})(({theme:n})=>({"& > button":{padding:n.spacing.threeXS,color:n.colors.fadedText40},"& > button:hover, & > button:focus":{color:n.colors.primary}})),Wt=x("span",{target:"e1lme4w112"})(({theme:n})=>({"& > button":{padding:n.spacing.threeXS,color:n.colors.fadedText60},"& > button:hover, & > button:focus":{color:n.colors.bodyText}})),it=x("div",{target:"e1lme4w113"})(({theme:n})=>({display:"flex",justifyContent:"center",alignItems:"center",flexGrow:0,flexShrink:1,padding:n.spacing.xs,gap:n.spacing.twoXS,marginRight:n.spacing.twoXS})),Me=x("div",{target:"e1lme4w114"})(({theme:n})=>({marginLeft:n.spacing.sm})),Ie=x(Xt,{target:"e1lme4w115"})(({theme:n})=>({fontSize:n.fontSizes.sm,width:n.sizes.spinnerSize,height:n.sizes.spinnerSize,borderWidth:n.sizes.spinnerThickness,radius:n.radii.md,justifyContents:"center",padding:n.spacing.none,margin:n.spacing.none,borderColor:n.colors.borderColor,borderTopColor:n.colors.primary,flexGrow:0,flexShrink:0})),Oe=()=>N(Tt,{children:[v(Dt,{children:"This app would like to use your microphone."})," ",v(Te,{href:qt,children:"Learn how to allow access."})]}),Le=()=>v(De,{children:v(We,{})}),Be=4,Ne=4,Ue=4,Fe=8,ze=0,j="00:00",bt=n=>new Date(n).toLocaleTimeString(void 0,{minute:"2-digit",second:"2-digit",timeZone:"UTC"}),_=({onClick:n,disabled:t,ariaLabel:e,iconContent:i})=>v(Kt,{kind:Yt.BORDERLESS_ICON,onClick:n,disabled:t,"aria-label":e,fluidWidth:!0,"data-testid":"stAudioInputActionButton",children:v(Zt,{content:i,size:"lg",color:"inherit"})}),_e=({disabled:n,stopRecording:t})=>v(Ae,{children:v(_,{onClick:t,disabled:n,ariaLabel:"Stop recording",iconContent:Et})}),He=({disabled:n,isPlaying:t,onClickPlayPause:e})=>v(Wt,{children:t?v(_,{onClick:e,disabled:n,ariaLabel:"Pause",iconContent:Ct}):v(_,{onClick:e,disabled:n,ariaLabel:"Play",iconContent:St})}),Ve=({disabled:n,startRecording:t})=>v(ke,{children:v(_,{onClick:t,disabled:n,ariaLabel:"Record",iconContent:wt})}),$e=({onClick:n})=>v(Wt,{children:v(_,{disabled:!1,onClick:n,ariaLabel:"Reset",iconContent:Rt})}),je=({disabled:n,isRecording:t,isPlaying:e,isUploading:i,isError:r,recordingUrlExists:s,startRecording:a,stopRecording:o,onClickPlayPause:d,onClear:c})=>r?v(it,{children:v($e,{onClick:c})}):i?v(it,{children:v(Ie,{"aria-label":"Uploading"})}):N(it,{children:[t?v(_e,{disabled:n,stopRecording:o}):v(Ve,{disabled:n,startRecording:a}),s&&v(He,{disabled:n,isPlaying:e,onClickPlayPause:d})]}),Ge=u.memo(je);async function Xe(n){const t=new window.AudioContext,e=await n.arrayBuffer();let i;try{i=await t.decodeAudioData(e)}catch(m){Jt(m);return}const r=44,s=i.numberOfChannels,a=i.sampleRate,o=i.length*s*2+r,d=new ArrayBuffer(o),c=new DataView(d),l={0:{type:"string",value:"RIFF"},4:{type:"uint32",value:o-8},8:{type:"string",value:"WAVE"},12:{type:"string",value:"fmt "},16:{type:"uint32",value:16},20:{type:"uint16",value:1},22:{type:"uint16",value:s},24:{type:"uint32",value:a},28:{type:"uint32",value:a*s*2},32:{type:"uint16",value:s*2},34:{type:"uint16",value:16},36:{type:"string",value:"data"},40:{type:"uint32",value:i.length*s*2}};Object.entries(l).forEach(([m,{type:f,value:b}])=>{const g=parseInt(m,10);f==="string"?qe(c,g,b):f==="uint32"?c.setUint32(g,b,!0):f==="uint16"&&c.setUint16(g,b,!0)});let p=r;for(let m=0;m<i.length;m++)for(let f=0;f<s;f++){const b=Math.max(-1,Math.min(1,i.getChannelData(f)[m]));c.setInt16(p,b*32767,!0),p+=2}const h=new Uint8Array(d);return new Blob([h],{type:"audio/wav"})}function qe(n,t,e){for(let i=0;i<e.length;i++)n.setUint8(t+i,e.charCodeAt(i))}const Ye=()=>v(Tt,{children:v(Dt,{children:"An error has occurred, please try again."})}),Ze=({element:n,uploadClient:t,widgetMgr:e,fragmentId:i,disabled:r})=>{var ht;const s=Qt(),a=ce(s),[o,d]=u.useState(null),c=yt.useRef(null),[l,p]=et({widgetMgr:e,id:n.id,key:"deleteFileUrl",defaultValue:null}),[h,m]=u.useState(null),[f,b]=u.useState([]),[g,w]=u.useState(null),[y,P]=et({widgetMgr:e,id:n.id,key:"recordingUrl",defaultValue:null}),[,T]=u.useState(0),C=()=>{T(S=>S+1)},[D,W]=u.useState(j),[M,A]=et({widgetMgr:e,id:n.id,formId:n.formId,key:"recordingTime",defaultValue:j}),[I,F]=u.useState(!1),[L,At]=u.useState(!1),[nt,kt]=u.useState(!1),[Mt,st]=u.useState(!1),[Y,Z]=u.useState(!1),rt=n.id,O=n.formId,ot=u.useCallback(async S=>{st(!0),X(O)&&e.setFormsWithUploadsInProgress(new Set([O]));let R;if(S.type==="audio/wav"?R=S:R=await Xe(S),!R){Z(!0);return}const k=URL.createObjectURL(R),Ft=new Date().toISOString().slice(0,16).replace(":","-"),zt=new File([R],`${Ft}_audio.wav`,{type:R.type});P(k),Ce({files:[zt],uploadClient:t,widgetMgr:e,widgetInfo:{id:rt,formId:O},fragmentId:i}).then(({successfulUploads:_t,failedUploads:Ht})=>{if(Ht.length>0){Z(!0);return}const J=_t[0];J&&J.fileUrl.deleteUrl&&p(J.fileUrl.deleteUrl)}).finally(()=>{X(O)&&e.setFormsWithUploadsInProgress(new Set),st(!1)})},[P,t,e,rt,O,i,p]),B=u.useCallback(({updateWidgetManager:S,deleteFile:R})=>{G(o)||G(l)||(P(null),o.empty(),R&&t.deleteFile(l),p(null),W(j),A(j),S&&e.setFileUploaderStateValue(n,{},{fromUi:!0},i),F(!1),X(y)&&URL.revokeObjectURL(y))},[l,y,t,o,n,e,i,A,P,p]);u.useEffect(()=>{if(G(O))return;const S=new ae;return S.manageFormClearListener(e,O,()=>B({updateWidgetManager:!0,deleteFile:!1})),()=>S.disconnect()},[O,B,e]);const at=u.useCallback(()=>{if(c.current===null)return;const S=z.create({container:c.current,waveColor:y?Q(s.colors.fadedText40,s.colors.secondaryBg):s.colors.primary,progressColor:s.colors.bodyText,height:te(s.sizes.largestElementHeight)-2*Be,barWidth:Ne,barGap:Ue,barRadius:Fe,cursorWidth:ze,url:y??void 0});S.on("timeupdate",k=>{W(bt(k*1e3))}),S.on("pause",()=>{C()});const R=S.registerPlugin(q.create({scrollingWaveform:!1,renderRecordedAudio:!0}));return R.on("record-end",async k=>{ot(k)}),R.on("record-progress",k=>{A(bt(k))}),d(S),m(R),()=>{S&&S.destroy(),R&&R.destroy()}},[ot]);u.useEffect(()=>at(),[at]),u.useEffect(()=>{ee(a,s)||o==null||o.setOptions({waveColor:y?Q(s.colors.fadedText40,s.colors.secondaryBg):s.colors.primary,progressColor:s.colors.bodyText})},[s,a,y,o]);const It=u.useCallback(()=>{o&&(o.playPause(),F(!0),C())},[o]),Ot=u.useCallback(async()=>{let S=g;nt||(await navigator.mediaDevices.getUserMedia({audio:!0}).then(()=>q.getAvailableAudioDevices().then(R=>{if(b(R),R.length>0){const{deviceId:k}=R[0];w(k),S=k}})).catch(R=>{At(!0)}),kt(!0)),!(!h||!S||!o)&&(o.setOptions({waveColor:s.colors.primary}),y&&B({updateWidgetManager:!1,deleteFile:!0}),h.startRecording({deviceId:S}).then(()=>{C()}))},[g,h,s,o,y,B,nt]),Lt=u.useCallback(()=>{h&&(h.stopRecording(),o==null||o.setOptions({waveColor:Q(s.colors.fadedText40,s.colors.secondaryBg)}))},[h,o,s]),Bt=Se(y,"recording.wav"),K=!!(h!=null&&h.isRecording()),lt=!!(o!=null&&o.isPlaying()),Nt=K||lt,ct=!K&&!y&&!L,Ut=L||ct||Y,dt=r||L;return N(Re,{className:"stAudioInput","data-testid":"stAudioInput",children:[v(re,{label:n.label,disabled:dt,labelVisibility:ie((ht=n.labelVisibility)==null?void 0:ht.value),children:n.help&&v(Me,{children:v(ne,{content:n.help,placement:se.TOP})})}),N(vt,{children:[N(le,{isFullScreen:!1,disableFullscreenMode:!0,target:vt,children:[y&&v(pt,{label:"Download as WAV",icon:he,onClick:()=>Bt()}),l&&v(pt,{label:"Clear recording",icon:ue,onClick:()=>B({updateWidgetManager:!0,deleteFile:!0})})]}),v(Ge,{isRecording:K,isPlaying:lt,isUploading:Mt,isError:Y,recordingUrlExists:!!y,startRecording:Ot,stopRecording:Lt,onClickPlayPause:It,onClear:()=>{B({updateWidgetManager:!1,deleteFile:!0}),Z(!1)},disabled:dt}),N(Ee,{children:[Y&&v(Ye,{}),ct&&v(Le,{}),L&&v(Oe,{}),v(xe,{"data-testid":"stAudioInputWaveSurfer",ref:c,show:!Ut})]}),v(Pe,{isPlayingOrRecording:Nt,"data-testid":"stAudioInputWaveformTimeCode",children:I?D:M})]})]})},si=u.memo(Ze);export{si as default};
|
73
|
+
`,[t,e]}setOptions(t){if(this.options.container!==t.container){const e=this.parentFromOptionsContainer(t.container);e.appendChild(this.container),this.parent=e}t.dragToSeek!==!0&&typeof this.options.dragToSeek!="object"||this.initDrag(),this.options=t,this.reRender()}getWrapper(){return this.wrapper}getWidth(){return this.scrollContainer.clientWidth}getScroll(){return this.scrollContainer.scrollLeft}setScroll(t){this.scrollContainer.scrollLeft=t}setScrollPercentage(t){const{scrollWidth:e}=this.scrollContainer,i=e*t;this.setScroll(i)}destroy(){var t,e;this.subscriptions.forEach(i=>i()),this.container.remove(),(t=this.resizeObserver)===null||t===void 0||t.disconnect(),(e=this.unsubscribeOnScroll)===null||e===void 0||e.call(this)}createDelay(t=10){let e,i;const r=()=>{e&&clearTimeout(e),i&&i()};return this.timeouts.push(r),()=>new Promise((s,a)=>{r(),i=a,e=setTimeout(()=>{e=void 0,i=void 0,s()},t)})}convertColorValues(t){if(!Array.isArray(t))return t||"";if(t.length<2)return t[0]||"";const e=document.createElement("canvas"),i=e.getContext("2d"),r=e.height*(window.devicePixelRatio||1),s=i.createLinearGradient(0,0,0,r),a=1/(t.length-1);return t.forEach((o,d)=>{const c=d*a;s.addColorStop(c,o)}),s}getPixelRatio(){return Math.max(1,window.devicePixelRatio||1)}renderBarWaveform(t,e,i,r){const s=t[0],a=t[1]||t[0],o=s.length,{width:d,height:c}=i.canvas,l=c/2,p=this.getPixelRatio(),h=e.barWidth?e.barWidth*p:1,m=e.barGap?e.barGap*p:e.barWidth?h/2:0,f=e.barRadius||0,b=d/(h+m)/o,g=f&&"roundRect"in i?"roundRect":"rect";i.beginPath();let w=0,y=0,P=0;for(let T=0;T<=o;T++){const C=Math.round(T*b);if(C>w){const M=Math.round(y*l*r),A=M+Math.round(P*l*r)||1;let I=l-M;e.barAlign==="top"?I=0:e.barAlign==="bottom"&&(I=c-A),i[g](w*(h+m),I,h,A,f),w=C,y=0,P=0}const D=Math.abs(s[T]||0),W=Math.abs(a[T]||0);D>y&&(y=D),W>P&&(P=W)}i.fill(),i.closePath()}renderLineWaveform(t,e,i,r){const s=a=>{const o=t[a]||t[0],d=o.length,{height:c}=i.canvas,l=c/2,p=i.canvas.width/d;i.moveTo(0,l);let h=0,m=0;for(let f=0;f<=d;f++){const b=Math.round(f*p);if(b>h){const w=l+(Math.round(m*l*r)||1)*(a===0?-1:1);i.lineTo(h,w),h=b,m=0}const g=Math.abs(o[f]||0);g>m&&(m=g)}i.lineTo(h,l)};i.beginPath(),s(0),s(1),i.fill(),i.closePath()}renderWaveform(t,e,i){if(i.fillStyle=this.convertColorValues(e.waveColor),e.renderFunction)return void e.renderFunction(t,i);let r=e.barHeight||1;if(e.normalize){const s=Array.from(t[0]).reduce((a,o)=>Math.max(a,Math.abs(o)),0);r=s?1/s:1}e.barWidth||e.barGap||e.barAlign?this.renderBarWaveform(t,e,i,r):this.renderLineWaveform(t,e,i,r)}renderSingleCanvas(t,e,i,r,s,a,o){const d=this.getPixelRatio(),c=document.createElement("canvas");c.width=Math.round(i*d),c.height=Math.round(r*d),c.style.width=`${i}px`,c.style.height=`${r}px`,c.style.left=`${Math.round(s)}px`,a.appendChild(c);const l=c.getContext("2d");if(this.renderWaveform(t,e,l),c.width>0&&c.height>0){const p=c.cloneNode(),h=p.getContext("2d");h.drawImage(c,0,0),h.globalCompositeOperation="source-in",h.fillStyle=this.convertColorValues(e.progressColor),h.fillRect(0,0,c.width,c.height),o.appendChild(p)}}renderMultiCanvas(t,e,i,r,s,a){const o=this.getPixelRatio(),{clientWidth:d}=this.scrollContainer,c=i/o;let l=Math.min(U.MAX_CANVAS_WIDTH,d,c),p={};if(e.barWidth||e.barGap){const g=e.barWidth||.5,w=g+(e.barGap||g/2);l%w!=0&&(l=Math.floor(l/w)*w)}const h=g=>{if(g<0||g>=m||p[g])return;p[g]=!0;const w=g*l,y=Math.min(c-w,l);if(y<=0)return;const P=t.map(T=>{const C=Math.floor(w/c*T.length),D=Math.floor((w+y)/c*T.length);return T.slice(C,D)});this.renderSingleCanvas(P,e,y,r,w,s,a)},m=Math.ceil(c/l);if(!this.isScrollable){for(let g=0;g<m;g++)h(g);return}const f=this.scrollContainer.scrollLeft/c,b=Math.floor(f*m);h(b-1),h(b),h(b+1),m>1&&(this.unsubscribeOnScroll=this.on("scroll",()=>{const{scrollLeft:g}=this.scrollContainer,w=Math.floor(g/c*m);Object.keys(p).length>U.MAX_NODES&&(s.innerHTML="",a.innerHTML="",p={}),h(w-1),h(w),h(w+1)}))}renderChannel(t,e,i,r){var{overlay:s}=e,a=function(l,p){var h={};for(var m in l)Object.prototype.hasOwnProperty.call(l,m)&&p.indexOf(m)<0&&(h[m]=l[m]);if(l!=null&&typeof Object.getOwnPropertySymbols=="function"){var f=0;for(m=Object.getOwnPropertySymbols(l);f<m.length;f++)p.indexOf(m[f])<0&&Object.prototype.propertyIsEnumerable.call(l,m[f])&&(h[m[f]]=l[m[f]])}return h}(e,["overlay"]);const o=document.createElement("div"),d=this.getHeight(a.height,a.splitChannels);o.style.height=`${d}px`,s&&r>0&&(o.style.marginTop=`-${d}px`),this.canvasWrapper.style.minHeight=`${d}px`,this.canvasWrapper.appendChild(o);const c=o.cloneNode();this.progressWrapper.appendChild(c),this.renderMultiCanvas(t,a,i,d,o,c)}render(t){return E(this,void 0,void 0,function*(){var e;this.timeouts.forEach(d=>d()),this.timeouts=[],this.canvasWrapper.innerHTML="",this.progressWrapper.innerHTML="",this.options.width!=null&&(this.scrollContainer.style.width=typeof this.options.width=="number"?`${this.options.width}px`:this.options.width);const i=this.getPixelRatio(),r=this.scrollContainer.clientWidth,s=Math.ceil(t.duration*(this.options.minPxPerSec||0));this.isScrollable=s>r;const a=this.options.fillParent&&!this.isScrollable,o=(a?r:s)*i;if(this.wrapper.style.width=a?"100%":`${s}px`,this.scrollContainer.style.overflowX=this.isScrollable?"auto":"hidden",this.scrollContainer.classList.toggle("noScrollbar",!!this.options.hideScrollbar),this.cursor.style.backgroundColor=`${this.options.cursorColor||this.options.progressColor}`,this.cursor.style.width=`${this.options.cursorWidth}px`,this.audioData=t,this.emit("render"),this.options.splitChannels)for(let d=0;d<t.numberOfChannels;d++){const c=Object.assign(Object.assign({},this.options),(e=this.options.splitChannels)===null||e===void 0?void 0:e[d]);this.renderChannel([t.getChannelData(d)],c,o,d)}else{const d=[t.getChannelData(0)];t.numberOfChannels>1&&d.push(t.getChannelData(1)),this.renderChannel(d,this.options,o,0)}Promise.resolve().then(()=>this.emit("rendered"))})}reRender(){var t;if((t=this.unsubscribeOnScroll)===null||t===void 0||t.call(this),delete this.unsubscribeOnScroll,!this.audioData)return;const{scrollWidth:e}=this.scrollContainer,{right:i}=this.progressWrapper.getBoundingClientRect();if(this.render(this.audioData),this.isScrollable&&e!==this.scrollContainer.scrollWidth){const{right:r}=this.progressWrapper.getBoundingClientRect();let s=r-i;s*=2,s=s<0?Math.floor(s):Math.ceil(s),s/=2,this.scrollContainer.scrollLeft+=s}}zoom(t){this.options.minPxPerSec=t,this.reRender()}scrollIntoView(t,e=!1){const{scrollLeft:i,scrollWidth:r,clientWidth:s}=this.scrollContainer,a=t*r,o=i,d=i+s,c=s/2;if(this.isDragging)a+30>d?this.scrollContainer.scrollLeft+=30:a-30<o&&(this.scrollContainer.scrollLeft-=30);else{(a<o||a>d)&&(this.scrollContainer.scrollLeft=a-(this.options.autoCenter?c:0));const l=a-i-c;e&&this.options.autoCenter&&l>0&&(this.scrollContainer.scrollLeft+=Math.min(l,10))}{const l=this.scrollContainer.scrollLeft,p=l/r,h=(l+s)/r;this.emit("scroll",p,h,l,l+s)}}renderProgress(t,e){if(isNaN(t))return;const i=100*t;this.canvasWrapper.style.clipPath=`polygon(${i}% 0, 100% 0, 100% 100%, ${i}% 100%)`,this.progressWrapper.style.width=`${i}%`,this.cursor.style.left=`${i}%`,this.cursor.style.transform=`translateX(-${Math.round(i)===100?this.options.cursorWidth:0}px)`,this.isScrollable&&this.options.autoScroll&&this.scrollIntoView(t,e)}exportImage(t,e,i){return E(this,void 0,void 0,function*(){const r=this.canvasWrapper.querySelectorAll("canvas");if(!r.length)throw new Error("No waveform data");if(i==="dataURL"){const s=Array.from(r).map(a=>a.toDataURL(t,e));return Promise.resolve(s)}return Promise.all(Array.from(r).map(s=>new Promise((a,o)=>{s.toBlob(d=>{d?a(d):o(new Error("Could not export image"))},t,e)})))})}}U.MAX_CANVAS_WIDTH=8e3,U.MAX_NODES=10;class ge extends ${constructor(){super(...arguments),this.unsubscribe=()=>{}}start(){this.unsubscribe=this.on("tick",()=>{requestAnimationFrame(()=>{this.emit("tick")})}),this.emit("tick")}stop(){this.unsubscribe()}destroy(){this.unsubscribe()}}class gt extends ${constructor(t=new AudioContext){super(),this.bufferNode=null,this.playStartTime=0,this.playedDuration=0,this._muted=!1,this._playbackRate=1,this._duration=void 0,this.buffer=null,this.currentSrc="",this.paused=!0,this.crossOrigin=null,this.seeking=!1,this.autoplay=!1,this.addEventListener=this.on,this.removeEventListener=this.un,this.audioContext=t,this.gainNode=this.audioContext.createGain(),this.gainNode.connect(this.audioContext.destination)}load(){return E(this,void 0,void 0,function*(){})}get src(){return this.currentSrc}set src(t){if(this.currentSrc=t,this._duration=void 0,!t)return this.buffer=null,void this.emit("emptied");fetch(t).then(e=>{if(e.status>=400)throw new Error(`Failed to fetch ${t}: ${e.status} (${e.statusText})`);return e.arrayBuffer()}).then(e=>this.currentSrc!==t?null:this.audioContext.decodeAudioData(e)).then(e=>{this.currentSrc===t&&(this.buffer=e,this.emit("loadedmetadata"),this.emit("canplay"),this.autoplay&&this.play())})}_play(){var t;if(!this.paused)return;this.paused=!1,(t=this.bufferNode)===null||t===void 0||t.disconnect(),this.bufferNode=this.audioContext.createBufferSource(),this.buffer&&(this.bufferNode.buffer=this.buffer),this.bufferNode.playbackRate.value=this._playbackRate,this.bufferNode.connect(this.gainNode);let e=this.playedDuration*this._playbackRate;e>=this.duration&&(e=0,this.playedDuration=0),this.bufferNode.start(this.audioContext.currentTime,e),this.playStartTime=this.audioContext.currentTime,this.bufferNode.onended=()=>{this.currentTime>=this.duration&&(this.pause(),this.emit("ended"))}}_pause(){var t;this.paused=!0,(t=this.bufferNode)===null||t===void 0||t.stop(),this.playedDuration+=this.audioContext.currentTime-this.playStartTime}play(){return E(this,void 0,void 0,function*(){this.paused&&(this._play(),this.emit("play"))})}pause(){this.paused||(this._pause(),this.emit("pause"))}stopAt(t){var e,i;const r=t-this.currentTime;(e=this.bufferNode)===null||e===void 0||e.stop(this.audioContext.currentTime+r),(i=this.bufferNode)===null||i===void 0||i.addEventListener("ended",()=>{this.bufferNode=null,this.pause()},{once:!0})}setSinkId(t){return E(this,void 0,void 0,function*(){return this.audioContext.setSinkId(t)})}get playbackRate(){return this._playbackRate}set playbackRate(t){this._playbackRate=t,this.bufferNode&&(this.bufferNode.playbackRate.value=t)}get currentTime(){return(this.paused?this.playedDuration:this.playedDuration+(this.audioContext.currentTime-this.playStartTime))*this._playbackRate}set currentTime(t){const e=!this.paused;e&&this._pause(),this.playedDuration=t/this._playbackRate,e&&this._play(),this.emit("seeking"),this.emit("timeupdate")}get duration(){var t,e;return(t=this._duration)!==null&&t!==void 0?t:((e=this.buffer)===null||e===void 0?void 0:e.duration)||0}set duration(t){this._duration=t}get volume(){return this.gainNode.gain.value}set volume(t){this.gainNode.gain.value=t,this.emit("volumechange")}get muted(){return this._muted}set muted(t){this._muted!==t&&(this._muted=t,this._muted?this.gainNode.disconnect():this.gainNode.connect(this.audioContext.destination))}canPlayType(t){return/^(audio|video)\//.test(t)}getGainNode(){return this.gainNode}getChannelData(){const t=[];if(!this.buffer)return t;const e=this.buffer.numberOfChannels;for(let i=0;i<e;i++)t.push(this.buffer.getChannelData(i));return t}}const ve={waveColor:"#999",progressColor:"#555",cursorWidth:1,minPxPerSec:0,fillParent:!0,interact:!0,dragToSeek:!1,autoScroll:!0,autoCenter:!0,sampleRate:8e3};class z extends fe{static create(t){return new z(t)}constructor(t){const e=t.media||(t.backend==="WebAudio"?new gt:void 0);super({media:e,mediaControls:t.mediaControls,autoplay:t.autoplay,playbackRate:t.audioRate}),this.plugins=[],this.decodedData=null,this.subscriptions=[],this.mediaSubscriptions=[],this.abortController=null,this.options=Object.assign({},ve,t),this.timer=new ge;const i=e?void 0:this.getMediaElement();this.renderer=new U(this.options,i),this.initPlayerEvents(),this.initRendererEvents(),this.initTimerEvents(),this.initPlugins();const r=this.options.url||this.getSrc()||"";Promise.resolve().then(()=>{this.emit("init");const{peaks:s,duration:a}=this.options;(r||s&&a)&&this.load(r,s,a).catch(()=>null)})}updateProgress(t=this.getCurrentTime()){return this.renderer.renderProgress(t/this.getDuration(),this.isPlaying()),t}initTimerEvents(){this.subscriptions.push(this.timer.on("tick",()=>{if(!this.isSeeking()){const t=this.updateProgress();this.emit("timeupdate",t),this.emit("audioprocess",t)}}))}initPlayerEvents(){this.isPlaying()&&(this.emit("play"),this.timer.start()),this.mediaSubscriptions.push(this.onMediaEvent("timeupdate",()=>{const t=this.updateProgress();this.emit("timeupdate",t)}),this.onMediaEvent("play",()=>{this.emit("play"),this.timer.start()}),this.onMediaEvent("pause",()=>{this.emit("pause"),this.timer.stop()}),this.onMediaEvent("emptied",()=>{this.timer.stop()}),this.onMediaEvent("ended",()=>{this.emit("finish")}),this.onMediaEvent("seeking",()=>{this.emit("seeking",this.getCurrentTime())}),this.onMediaEvent("error",t=>{this.emit("error",t.error)}))}initRendererEvents(){this.subscriptions.push(this.renderer.on("click",(t,e)=>{this.options.interact&&(this.seekTo(t),this.emit("interaction",t*this.getDuration()),this.emit("click",t,e))}),this.renderer.on("dblclick",(t,e)=>{this.emit("dblclick",t,e)}),this.renderer.on("scroll",(t,e,i,r)=>{const s=this.getDuration();this.emit("scroll",t*s,e*s,i,r)}),this.renderer.on("render",()=>{this.emit("redraw")}),this.renderer.on("rendered",()=>{this.emit("redrawcomplete")}),this.renderer.on("dragstart",t=>{this.emit("dragstart",t)}),this.renderer.on("dragend",t=>{this.emit("dragend",t)}));{let t;this.subscriptions.push(this.renderer.on("drag",e=>{if(!this.options.interact)return;let i;this.renderer.renderProgress(e),clearTimeout(t),this.isPlaying()?i=0:this.options.dragToSeek===!0?i=200:typeof this.options.dragToSeek=="object"&&this.options.dragToSeek!==void 0&&(i=this.options.dragToSeek.debounceTime),t=setTimeout(()=>{this.seekTo(e)},i),this.emit("interaction",e*this.getDuration()),this.emit("drag",e)}))}}initPlugins(){var t;!((t=this.options.plugins)===null||t===void 0)&&t.length&&this.options.plugins.forEach(e=>{this.registerPlugin(e)})}unsubscribePlayerEvents(){this.mediaSubscriptions.forEach(t=>t()),this.mediaSubscriptions=[]}setOptions(t){this.options=Object.assign({},this.options,t),this.renderer.setOptions(this.options),t.audioRate&&this.setPlaybackRate(t.audioRate),t.mediaControls!=null&&(this.getMediaElement().controls=t.mediaControls)}registerPlugin(t){return t._init(this),this.plugins.push(t),this.subscriptions.push(t.once("destroy",()=>{this.plugins=this.plugins.filter(e=>e!==t)})),t}getWrapper(){return this.renderer.getWrapper()}getWidth(){return this.renderer.getWidth()}getScroll(){return this.renderer.getScroll()}setScroll(t){return this.renderer.setScroll(t)}setScrollTime(t){const e=t/this.getDuration();this.renderer.setScrollPercentage(e)}getActivePlugins(){return this.plugins}loadAudio(t,e,i,r){return E(this,void 0,void 0,function*(){var s;if(this.emit("load",t),!this.options.media&&this.isPlaying()&&this.pause(),this.decodedData=null,!e&&!i){const o=this.options.fetchParams||{};window.AbortController&&!o.signal&&(this.abortController=new AbortController,o.signal=(s=this.abortController)===null||s===void 0?void 0:s.signal);const d=c=>this.emit("loading",c);e=yield me.fetchBlob(t,d,o)}this.setSrc(t,e);const a=yield new Promise(o=>{const d=r||this.getDuration();d?o(d):this.mediaSubscriptions.push(this.onMediaEvent("loadedmetadata",()=>o(this.getDuration()),{once:!0}))});if(!t&&!e){const o=this.getMediaElement();o instanceof gt&&(o.duration=a)}if(i)this.decodedData=mt.createBuffer(i,a||0);else if(e){const o=yield e.arrayBuffer();this.decodedData=yield mt.decode(o,this.options.sampleRate)}this.decodedData&&(this.emit("decode",this.getDuration()),this.renderer.render(this.decodedData)),this.emit("ready",this.getDuration())})}load(t,e,i){return E(this,void 0,void 0,function*(){try{return yield this.loadAudio(t,void 0,e,i)}catch(r){throw this.emit("error",r),r}})}loadBlob(t,e,i){return E(this,void 0,void 0,function*(){try{return yield this.loadAudio("",t,e,i)}catch(r){throw this.emit("error",r),r}})}zoom(t){if(!this.decodedData)throw new Error("No audio loaded");this.renderer.zoom(t),this.emit("zoom",t)}getDecodedData(){return this.decodedData}exportPeaks({channels:t=2,maxLength:e=8e3,precision:i=1e4}={}){if(!this.decodedData)throw new Error("The audio has not been decoded yet");const r=Math.min(t,this.decodedData.numberOfChannels),s=[];for(let a=0;a<r;a++){const o=this.decodedData.getChannelData(a),d=[],c=o.length/e;for(let l=0;l<e;l++){const p=o.slice(Math.floor(l*c),Math.ceil((l+1)*c));let h=0;for(let m=0;m<p.length;m++){const f=p[m];Math.abs(f)>Math.abs(h)&&(h=f)}d.push(Math.round(h*i)/i)}s.push(d)}return s}getDuration(){let t=super.getDuration()||0;return t!==0&&t!==1/0||!this.decodedData||(t=this.decodedData.duration),t}toggleInteraction(t){this.options.interact=t}setTime(t){super.setTime(t),this.updateProgress(t),this.emit("timeupdate",t)}seekTo(t){const e=this.getDuration()*t;this.setTime(e)}playPause(){return E(this,void 0,void 0,function*(){return this.isPlaying()?this.pause():this.play()})}stop(){this.pause(),this.setTime(0)}skip(t){this.setTime(this.getCurrentTime()+t)}empty(){this.load("",[[0]],.001)}setMediaElement(t){this.unsubscribePlayerEvents(),super.setMediaElement(t),this.initPlayerEvents()}exportImage(){return E(this,arguments,void 0,function*(t="image/png",e=1,i="dataURL"){return this.renderer.exportImage(t,e,i)})}destroy(){var t;this.emit("destroy"),(t=this.abortController)===null||t===void 0||t.abort(),this.plugins.forEach(e=>e.destroy()),this.subscriptions.forEach(e=>e()),this.unsubscribePlayerEvents(),this.timer.destroy(),this.renderer.destroy(),super.destroy()}}z.BasePlugin=class extends ${constructor(n){super(),this.subscriptions=[],this.options=n}onInit(){}_init(n){this.wavesurfer=n,this.onInit()}destroy(){this.emit("destroy"),this.subscriptions.forEach(n=>n())}},z.dom=pe;function tt(n,t,e,i){return new(e||(e=Promise))(function(r,s){function a(c){try{d(i.next(c))}catch(l){s(l)}}function o(c){try{d(i.throw(c))}catch(l){s(l)}}function d(c){var l;c.done?r(c.value):(l=c.value,l instanceof e?l:new e(function(p){p(l)})).then(a,o)}d((i=i.apply(n,[])).next())})}class Pt{constructor(){this.listeners={}}on(t,e,i){if(this.listeners[t]||(this.listeners[t]=new Set),this.listeners[t].add(e),i==null?void 0:i.once){const r=()=>{this.un(t,r),this.un(t,e)};return this.on(t,r),r}return()=>this.un(t,e)}un(t,e){var i;(i=this.listeners[t])===null||i===void 0||i.delete(e)}once(t,e){return this.on(t,e,{once:!0})}unAll(){this.listeners={}}emit(t,...e){this.listeners[t]&&this.listeners[t].forEach(i=>i(...e))}}class be extends Pt{constructor(t){super(),this.subscriptions=[],this.options=t}onInit(){}_init(t){this.wavesurfer=t,this.onInit()}destroy(){this.emit("destroy"),this.subscriptions.forEach(t=>t())}}class ye extends Pt{constructor(){super(...arguments),this.unsubscribe=()=>{}}start(){this.unsubscribe=this.on("tick",()=>{requestAnimationFrame(()=>{this.emit("tick")})}),this.emit("tick")}stop(){this.unsubscribe()}destroy(){this.unsubscribe()}}const we=["audio/webm","audio/wav","audio/mpeg","audio/mp4","audio/mp3"];class q extends be{constructor(t){var e,i,r,s,a,o;super(Object.assign(Object.assign({},t),{audioBitsPerSecond:(e=t.audioBitsPerSecond)!==null&&e!==void 0?e:128e3,scrollingWaveform:(i=t.scrollingWaveform)!==null&&i!==void 0&&i,scrollingWaveformWindow:(r=t.scrollingWaveformWindow)!==null&&r!==void 0?r:5,continuousWaveform:(s=t.continuousWaveform)!==null&&s!==void 0&&s,renderRecordedAudio:(a=t.renderRecordedAudio)===null||a===void 0||a,mediaRecorderTimeslice:(o=t.mediaRecorderTimeslice)!==null&&o!==void 0?o:void 0})),this.stream=null,this.mediaRecorder=null,this.dataWindow=null,this.isWaveformPaused=!1,this.lastStartTime=0,this.lastDuration=0,this.duration=0,this.timer=new ye,this.subscriptions.push(this.timer.on("tick",()=>{const d=performance.now()-this.lastStartTime;this.duration=this.isPaused()?this.duration:this.lastDuration+d,this.emit("record-progress",this.duration)}))}static create(t){return new q(t||{})}renderMicStream(t){var e;const i=new AudioContext,r=i.createMediaStreamSource(t),s=i.createAnalyser();r.connect(s),this.options.continuousWaveform&&(s.fftSize=32);const a=s.frequencyBinCount,o=new Float32Array(a);let d=0;this.wavesurfer&&((e=this.originalOptions)!==null&&e!==void 0||(this.originalOptions=Object.assign({},this.wavesurfer.options)),this.wavesurfer.options.interact=!1,this.options.scrollingWaveform&&(this.wavesurfer.options.cursorWidth=0));const c=setInterval(()=>{var l,p,h,m;if(!this.isWaveformPaused){if(s.getFloatTimeDomainData(o),this.options.scrollingWaveform){const f=Math.floor((this.options.scrollingWaveformWindow||0)*i.sampleRate),b=Math.min(f,this.dataWindow?this.dataWindow.length+a:a),g=new Float32Array(f);if(this.dataWindow){const w=Math.max(0,f-this.dataWindow.length);g.set(this.dataWindow.slice(-b+a),w)}g.set(o,f-a),this.dataWindow=g}else if(this.options.continuousWaveform){if(!this.dataWindow){const b=this.options.continuousWaveformDuration?Math.round(100*this.options.continuousWaveformDuration):((p=(l=this.wavesurfer)===null||l===void 0?void 0:l.getWidth())!==null&&p!==void 0?p:0)*window.devicePixelRatio;this.dataWindow=new Float32Array(b)}let f=0;for(let b=0;b<a;b++){const g=Math.abs(o[b]);g>f&&(f=g)}if(d+1>this.dataWindow.length){const b=new Float32Array(2*this.dataWindow.length);b.set(this.dataWindow,0),this.dataWindow=b}this.dataWindow[d]=f,d++}else this.dataWindow=o;if(this.wavesurfer){const f=((m=(h=this.dataWindow)===null||h===void 0?void 0:h.length)!==null&&m!==void 0?m:0)/100;this.wavesurfer.load("",[this.dataWindow],this.options.scrollingWaveform?this.options.scrollingWaveformWindow:f).then(()=>{this.wavesurfer&&this.options.continuousWaveform&&(this.wavesurfer.setTime(this.getDuration()/1e3),this.wavesurfer.options.minPxPerSec||this.wavesurfer.setOptions({minPxPerSec:this.wavesurfer.getWidth()/this.wavesurfer.getDuration()}))}).catch(b=>{console.error("Error rendering real-time recording data:",b)})}}},10);return{onDestroy:()=>{clearInterval(c),r==null||r.disconnect(),i==null||i.close()},onEnd:()=>{this.isWaveformPaused=!0,clearInterval(c),this.stopMic()}}}startMic(t){return tt(this,void 0,void 0,function*(){let e;try{e=yield navigator.mediaDevices.getUserMedia({audio:!(t!=null&&t.deviceId)||{deviceId:t.deviceId}})}catch(s){throw new Error("Error accessing the microphone: "+s.message)}const{onDestroy:i,onEnd:r}=this.renderMicStream(e);return this.subscriptions.push(this.once("destroy",i)),this.subscriptions.push(this.once("record-end",r)),this.stream=e,e})}stopMic(){this.stream&&(this.stream.getTracks().forEach(t=>t.stop()),this.stream=null,this.mediaRecorder=null)}startRecording(t){return tt(this,void 0,void 0,function*(){const e=this.stream||(yield this.startMic(t));this.dataWindow=null;const i=this.mediaRecorder||new MediaRecorder(e,{mimeType:this.options.mimeType||we.find(a=>MediaRecorder.isTypeSupported(a)),audioBitsPerSecond:this.options.audioBitsPerSecond});this.mediaRecorder=i,this.stopRecording();const r=[];i.ondataavailable=a=>{a.data.size>0&&r.push(a.data),this.emit("record-data-available",a.data)};const s=a=>{var o;const d=new Blob(r,{type:i.mimeType});this.emit(a,d),this.options.renderRecordedAudio&&(this.applyOriginalOptionsIfNeeded(),(o=this.wavesurfer)===null||o===void 0||o.load(URL.createObjectURL(d)))};i.onpause=()=>s("record-pause"),i.onstop=()=>s("record-end"),i.start(this.options.mediaRecorderTimeslice),this.lastStartTime=performance.now(),this.lastDuration=0,this.duration=0,this.isWaveformPaused=!1,this.timer.start(),this.emit("record-start")})}getDuration(){return this.duration}isRecording(){var t;return((t=this.mediaRecorder)===null||t===void 0?void 0:t.state)==="recording"}isPaused(){var t;return((t=this.mediaRecorder)===null||t===void 0?void 0:t.state)==="paused"}isActive(){var t;return((t=this.mediaRecorder)===null||t===void 0?void 0:t.state)!=="inactive"}stopRecording(){var t;this.isActive()&&((t=this.mediaRecorder)===null||t===void 0||t.stop(),this.timer.stop())}pauseRecording(){var t,e;this.isRecording()&&(this.isWaveformPaused=!0,(t=this.mediaRecorder)===null||t===void 0||t.requestData(),(e=this.mediaRecorder)===null||e===void 0||e.pause(),this.timer.stop(),this.lastDuration=this.duration)}resumeRecording(){var t;this.isPaused()&&(this.isWaveformPaused=!1,(t=this.mediaRecorder)===null||t===void 0||t.resume(),this.timer.start(),this.lastStartTime=performance.now(),this.emit("record-resume"))}static getAvailableAudioDevices(){return tt(this,void 0,void 0,function*(){return navigator.mediaDevices.enumerateDevices().then(t=>t.filter(e=>e.kind==="audioinput"))})}destroy(){this.applyOriginalOptionsIfNeeded(),super.destroy(),this.stopRecording(),this.stopMic()}applyOriginalOptionsIfNeeded(){this.wavesurfer&&this.originalOptions&&(this.wavesurfer.setOptions(this.originalOptions),delete this.originalOptions)}}const Ce=async({files:n,uploadClient:t,widgetMgr:e,widgetInfo:i,fragmentId:r})=>{let s=[];try{s=await t.fetchFileURLs(n)}catch(c){return{successfulUploads:[],failedUploads:n.map(l=>({file:l,error:ut(c)}))}}const a=Vt(n,s),o=[],d=[];return await Promise.all(a.map(async([c,l])=>{if(!c||!l||!l.uploadUrl||!l.fileId)return{file:c,fileUrl:l,error:new Error("No upload URL found")};try{await t.uploadFile({id:l.fileId,formId:i.formId||""},l.uploadUrl,c),o.push({fileUrl:l,file:c})}catch(p){const h=ut(p);d.push({file:c,error:h})}})),e.setFileUploaderStateValue(i,new $t({uploadedFileInfo:o.map(({file:c,fileUrl:l})=>new jt({fileId:l.fileId,fileUrls:l,name:c.name,size:c.size}))}),{fromUi:!0},r),{successfulUploads:o,failedUploads:d}},et=({widgetMgr:n,id:t,formId:e,key:i,defaultValue:r})=>{u.useEffect(()=>{const l=n.getElementState(t,i);G(l)&&X(r)&&n.setElementState(t,i,r)},[n,t,i,r]);const[s,a]=u.useState(n.getElementState(t,i)??r),o=u.useCallback(l=>{n.setElementState(t,i,l),a(l)},[n,t,i]),d=u.useMemo(()=>({formId:e||""}),[e]),c=u.useCallback(()=>o(r),[r,o]);return oe({element:d,widgetMgr:n,onFormCleared:c}),[s,o]},Se=(n,t)=>{const{libConfig:{enforceDownloadInNewTab:e=!1}}=yt.useContext(Gt);return u.useCallback(()=>{if(!n)return;const r=de({enforceDownloadInNewTab:e,url:n,filename:t});r.style.display="none",document.body.appendChild(r),r.click(),document.body.removeChild(r)},[n,e,t])},Re=x("div",{target:"e1lme4w10"})(),vt=x("div",{target:"e1lme4w11"})(({theme:n})=>({height:n.sizes.largestElementHeight,width:"100%",background:n.colors.secondaryBg,borderRadius:n.radii.default,marginBottom:n.spacing.twoXS,display:"flex",alignItems:"center",position:"relative",paddingLeft:n.spacing.xs,paddingRight:n.spacing.sm})),Ee=x("div",{target:"e1lme4w12"})({flex:1}),xe=x("div",{target:"e1lme4w13"})(({show:n})=>({display:n?"block":"none"})),Pe=x("span",{target:"e1lme4w14"})(({theme:n,isPlayingOrRecording:t})=>({margin:n.spacing.sm,fontFamily:n.fonts.monospace,color:t?n.colors.bodyText:n.colors.fadedText60,backgroundColor:n.colors.secondaryBg,fontSize:n.fontSizes.sm})),Tt=x("div",{target:"e1lme4w15"})({width:"100%",textAlign:"center",overflow:"hidden"}),Dt=x("span",{target:"e1lme4w16"})(({theme:n})=>({color:n.colors.bodyText})),Te=x("a",{target:"e1lme4w17"})(({theme:n})=>({color:n.colors.linkText,textDecoration:"underline"})),De=x("div",{target:"e1lme4w18"})(({theme:n})=>({height:n.sizes.largestElementHeight,display:"flex",justifyContent:"center",alignItems:"center"})),We=x("div",{target:"e1lme4w19"})(({theme:n})=>{const t="0.625em";return{opacity:.2,width:"100%",height:t,backgroundSize:t,backgroundImage:`radial-gradient(${n.colors.fadedText10} 40%, transparent 40%)`,backgroundRepeat:"repeat"}}),Ae=x("span",{target:"e1lme4w110"})(({theme:n})=>({"& > button":{color:n.colors.primary,padding:n.spacing.threeXS},"& > button:hover, & > button:focus":{color:n.colors.red}})),ke=x("span",{target:"e1lme4w111"})(({theme:n})=>({"& > button":{padding:n.spacing.threeXS,color:n.colors.fadedText40},"& > button:hover, & > button:focus":{color:n.colors.primary}})),Wt=x("span",{target:"e1lme4w112"})(({theme:n})=>({"& > button":{padding:n.spacing.threeXS,color:n.colors.fadedText60},"& > button:hover, & > button:focus":{color:n.colors.bodyText}})),it=x("div",{target:"e1lme4w113"})(({theme:n})=>({display:"flex",justifyContent:"center",alignItems:"center",flexGrow:0,flexShrink:1,padding:n.spacing.xs,gap:n.spacing.twoXS,marginRight:n.spacing.twoXS})),Me=x("div",{target:"e1lme4w114"})(({theme:n})=>({marginLeft:n.spacing.sm})),Ie=x(Xt,{target:"e1lme4w115"})(({theme:n})=>({fontSize:n.fontSizes.sm,width:n.sizes.spinnerSize,height:n.sizes.spinnerSize,borderWidth:n.sizes.spinnerThickness,radius:n.radii.md,justifyContents:"center",padding:n.spacing.none,margin:n.spacing.none,borderColor:n.colors.borderColor,borderTopColor:n.colors.primary,flexGrow:0,flexShrink:0})),Oe=()=>N(Tt,{children:[v(Dt,{children:"This app would like to use your microphone."})," ",v(Te,{href:qt,children:"Learn how to allow access."})]}),Le=()=>v(De,{children:v(We,{})}),Be=4,Ne=4,Ue=4,Fe=8,ze=0,j="00:00",bt=n=>new Date(n).toLocaleTimeString(void 0,{minute:"2-digit",second:"2-digit",timeZone:"UTC"}),_=({onClick:n,disabled:t,ariaLabel:e,iconContent:i})=>v(Jt,{kind:Yt.BORDERLESS_ICON,onClick:n,disabled:t,"aria-label":e,fluidWidth:!0,"data-testid":"stAudioInputActionButton",children:v(Zt,{content:i,size:"lg",color:"inherit"})}),_e=({disabled:n,stopRecording:t})=>v(Ae,{children:v(_,{onClick:t,disabled:n,ariaLabel:"Stop recording",iconContent:Et})}),He=({disabled:n,isPlaying:t,onClickPlayPause:e})=>v(Wt,{children:t?v(_,{onClick:e,disabled:n,ariaLabel:"Pause",iconContent:Ct}):v(_,{onClick:e,disabled:n,ariaLabel:"Play",iconContent:St})}),Ve=({disabled:n,startRecording:t})=>v(ke,{children:v(_,{onClick:t,disabled:n,ariaLabel:"Record",iconContent:wt})}),$e=({onClick:n})=>v(Wt,{children:v(_,{disabled:!1,onClick:n,ariaLabel:"Reset",iconContent:Rt})}),je=({disabled:n,isRecording:t,isPlaying:e,isUploading:i,isError:r,recordingUrlExists:s,startRecording:a,stopRecording:o,onClickPlayPause:d,onClear:c})=>r?v(it,{children:v($e,{onClick:c})}):i?v(it,{children:v(Ie,{"aria-label":"Uploading"})}):N(it,{children:[t?v(_e,{disabled:n,stopRecording:o}):v(Ve,{disabled:n,startRecording:a}),s&&v(He,{disabled:n,isPlaying:e,onClickPlayPause:d})]}),Ge=u.memo(je);async function Xe(n){const t=new window.AudioContext,e=await n.arrayBuffer();let i;try{i=await t.decodeAudioData(e)}catch(m){Kt(m);return}const r=44,s=i.numberOfChannels,a=i.sampleRate,o=i.length*s*2+r,d=new ArrayBuffer(o),c=new DataView(d),l={0:{type:"string",value:"RIFF"},4:{type:"uint32",value:o-8},8:{type:"string",value:"WAVE"},12:{type:"string",value:"fmt "},16:{type:"uint32",value:16},20:{type:"uint16",value:1},22:{type:"uint16",value:s},24:{type:"uint32",value:a},28:{type:"uint32",value:a*s*2},32:{type:"uint16",value:s*2},34:{type:"uint16",value:16},36:{type:"string",value:"data"},40:{type:"uint32",value:i.length*s*2}};Object.entries(l).forEach(([m,{type:f,value:b}])=>{const g=parseInt(m,10);f==="string"?qe(c,g,b):f==="uint32"?c.setUint32(g,b,!0):f==="uint16"&&c.setUint16(g,b,!0)});let p=r;for(let m=0;m<i.length;m++)for(let f=0;f<s;f++){const b=Math.max(-1,Math.min(1,i.getChannelData(f)[m]));c.setInt16(p,b*32767,!0),p+=2}const h=new Uint8Array(d);return new Blob([h],{type:"audio/wav"})}function qe(n,t,e){for(let i=0;i<e.length;i++)n.setUint8(t+i,e.charCodeAt(i))}const Ye=()=>v(Tt,{children:v(Dt,{children:"An error has occurred, please try again."})}),Ze=({element:n,uploadClient:t,widgetMgr:e,fragmentId:i,disabled:r})=>{var ht;const s=Qt(),a=ce(s),[o,d]=u.useState(null),c=yt.useRef(null),[l,p]=et({widgetMgr:e,id:n.id,key:"deleteFileUrl",defaultValue:null}),[h,m]=u.useState(null),[f,b]=u.useState([]),[g,w]=u.useState(null),[y,P]=et({widgetMgr:e,id:n.id,key:"recordingUrl",defaultValue:null}),[,T]=u.useState(0),C=()=>{T(S=>S+1)},[D,W]=u.useState(j),[M,A]=et({widgetMgr:e,id:n.id,formId:n.formId,key:"recordingTime",defaultValue:j}),[I,F]=u.useState(!1),[L,At]=u.useState(!1),[nt,kt]=u.useState(!1),[Mt,st]=u.useState(!1),[Y,Z]=u.useState(!1),rt=n.id,O=n.formId,ot=u.useCallback(async S=>{st(!0),X(O)&&e.setFormsWithUploadsInProgress(new Set([O]));let R;if(S.type==="audio/wav"?R=S:R=await Xe(S),!R){Z(!0);return}const k=URL.createObjectURL(R),Ft=new Date().toISOString().slice(0,16).replace(":","-"),zt=new File([R],`${Ft}_audio.wav`,{type:R.type});P(k),Ce({files:[zt],uploadClient:t,widgetMgr:e,widgetInfo:{id:rt,formId:O},fragmentId:i}).then(({successfulUploads:_t,failedUploads:Ht})=>{if(Ht.length>0){Z(!0);return}const K=_t[0];K&&K.fileUrl.deleteUrl&&p(K.fileUrl.deleteUrl)}).finally(()=>{X(O)&&e.setFormsWithUploadsInProgress(new Set),st(!1)})},[P,t,e,rt,O,i,p]),B=u.useCallback(({updateWidgetManager:S,deleteFile:R})=>{G(o)||G(l)||(P(null),o.empty(),R&&t.deleteFile(l),p(null),W(j),A(j),S&&e.setFileUploaderStateValue(n,{},{fromUi:!0},i),F(!1),X(y)&&URL.revokeObjectURL(y))},[l,y,t,o,n,e,i,A,P,p]);u.useEffect(()=>{if(G(O))return;const S=new ae;return S.manageFormClearListener(e,O,()=>B({updateWidgetManager:!0,deleteFile:!1})),()=>S.disconnect()},[O,B,e]);const at=u.useCallback(()=>{if(c.current===null)return;const S=z.create({container:c.current,waveColor:y?Q(s.colors.fadedText40,s.colors.secondaryBg):s.colors.primary,progressColor:s.colors.bodyText,height:te(s.sizes.largestElementHeight)-2*Be,barWidth:Ne,barGap:Ue,barRadius:Fe,cursorWidth:ze,url:y??void 0});S.on("timeupdate",k=>{W(bt(k*1e3))}),S.on("pause",()=>{C()});const R=S.registerPlugin(q.create({scrollingWaveform:!1,renderRecordedAudio:!0}));return R.on("record-end",async k=>{ot(k)}),R.on("record-progress",k=>{A(bt(k))}),d(S),m(R),()=>{S&&S.destroy(),R&&R.destroy()}},[ot]);u.useEffect(()=>at(),[at]),u.useEffect(()=>{ee(a,s)||o==null||o.setOptions({waveColor:y?Q(s.colors.fadedText40,s.colors.secondaryBg):s.colors.primary,progressColor:s.colors.bodyText})},[s,a,y,o]);const It=u.useCallback(()=>{o&&(o.playPause(),F(!0),C())},[o]),Ot=u.useCallback(async()=>{let S=g;nt||(await navigator.mediaDevices.getUserMedia({audio:!0}).then(()=>q.getAvailableAudioDevices().then(R=>{if(b(R),R.length>0){const{deviceId:k}=R[0];w(k),S=k}})).catch(R=>{At(!0)}),kt(!0)),!(!h||!S||!o)&&(o.setOptions({waveColor:s.colors.primary}),y&&B({updateWidgetManager:!1,deleteFile:!0}),h.startRecording({deviceId:S}).then(()=>{C()}))},[g,h,s,o,y,B,nt]),Lt=u.useCallback(()=>{h&&(h.stopRecording(),o==null||o.setOptions({waveColor:Q(s.colors.fadedText40,s.colors.secondaryBg)}))},[h,o,s]),Bt=Se(y,"recording.wav"),J=!!(h!=null&&h.isRecording()),lt=!!(o!=null&&o.isPlaying()),Nt=J||lt,ct=!J&&!y&&!L,Ut=L||ct||Y,dt=r||L;return N(Re,{className:"stAudioInput","data-testid":"stAudioInput",children:[v(re,{label:n.label,disabled:dt,labelVisibility:ie((ht=n.labelVisibility)==null?void 0:ht.value),children:n.help&&v(Me,{children:v(ne,{content:n.help,placement:se.TOP})})}),N(vt,{children:[N(le,{isFullScreen:!1,disableFullscreenMode:!0,target:vt,children:[y&&v(pt,{label:"Download as WAV",icon:he,onClick:()=>Bt()}),l&&v(pt,{label:"Clear recording",icon:ue,onClick:()=>B({updateWidgetManager:!0,deleteFile:!0})})]}),v(Ge,{isRecording:J,isPlaying:lt,isUploading:Mt,isError:Y,recordingUrlExists:!!y,startRecording:Ot,stopRecording:Lt,onClickPlayPause:It,onClear:()=>{B({updateWidgetManager:!1,deleteFile:!0}),Z(!1)},disabled:dt}),N(Ee,{children:[Y&&v(Ye,{}),ct&&v(Le,{}),L&&v(Oe,{}),v(xe,{"data-testid":"stAudioInputWaveSurfer",ref:c,show:!Ut})]}),v(Pe,{isPlayingOrRecording:Nt,"data-testid":"stAudioInputWaveformTimeCode",children:I?D:M})]})]})},si=u.memo(Ze);export{si as default};
|