streamlit-nightly 1.42.3.dev20250222__py2.py3-none-any.whl → 1.42.3.dev20250224__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/dataframe_util.py +6 -1
- streamlit/elements/bokeh_chart.py +6 -0
- streamlit/elements/markdown.py +2 -0
- streamlit/static/index.html +1 -1
- streamlit/static/static/js/{FileDownload.esm.B1kyp21I.js → FileDownload.esm.Db6P60XC.js} +1 -1
- streamlit/static/static/js/FileHelper.LHDgAkEu.js +5 -0
- streamlit/static/static/js/{FormClearHelper.CEl0YyS3.js → FormClearHelper.BkPbs0OF.js} +1 -1
- streamlit/static/static/js/{Hooks.B_-0sclb.js → Hooks.CW1Ujj-E.js} +1 -1
- streamlit/static/static/js/{InputInstructions.M8GsfWtP.js → InputInstructions.CHpHVupe.js} +1 -1
- streamlit/static/static/js/{ProgressBar.DDliFXvs.js → ProgressBar.CSZV-k_M.js} +2 -2
- streamlit/static/static/js/{RenderInPortalIfExists.DON5no2j.js → RenderInPortalIfExists.CrI9B0Qh.js} +1 -1
- streamlit/static/static/js/{Toolbar.DGwjBtCI.js → Toolbar.CfNF-56q.js} +1 -1
- streamlit/static/static/js/{base-input.Dz6cKnV_.js → base-input.BBFJwxWO.js} +4 -4
- streamlit/static/static/js/{createSuper.bXxYJzro.js → createSuper.rz8EjYR0.js} +1 -1
- streamlit/static/static/js/{data-grid-overlay-editor.BrHDbHOn.js → data-grid-overlay-editor.DUagmDpG.js} +1 -1
- streamlit/static/static/js/{downloader.BUh1naKp.js → downloader.DEY2_Oao.js} +1 -1
- streamlit/static/static/js/{es6.C8XVTTHj.js → es6.Cbt8Qb0v.js} +2 -2
- streamlit/static/static/js/{iframeResizer.contentWindow.DGWt48-l.js → iframeResizer.contentWindow.DlY1zPt7.js} +1 -1
- streamlit/static/static/js/{index.6zGrdP7S.js → index.7HEH_7fJ.js} +15 -15
- streamlit/static/static/js/{index.DvUg88R_.js → index.8pg9ijwI.js} +1 -1
- streamlit/static/static/js/{index.jSEMrPEJ.js → index.B5Q1lb1E.js} +1 -1
- streamlit/static/static/js/{index.DgCaLwAb.js → index.BFFhpOhV.js} +1 -1
- streamlit/static/static/js/{index.DU4gaNU_.js → index.BcIDRdbw.js} +1 -1
- streamlit/static/static/js/index.Bhf5i-o4.js +1 -0
- streamlit/static/static/js/{index.DcA_kXA1.js → index.BtBNIxWC.js} +2 -2
- streamlit/static/static/js/{index.BhKdTR4z.js → index.Bv1JbhEf.js} +1 -1
- streamlit/static/static/js/index.C29vTftb.js +3865 -0
- streamlit/static/static/js/{index.94WymsOx.js → index.C3FZ8TOb.js} +3 -3
- streamlit/static/static/js/index.C41AtD-D.js +1 -0
- streamlit/static/static/js/{index.C5zcxetk.js → index.C9kvqGu0.js} +1 -1
- streamlit/static/static/js/{index.DO1Rv491.js → index.CIDueoC2.js} +1 -1
- streamlit/static/static/js/{index.C2skmlN3.js → index.CUFUpykP.js} +2 -2
- streamlit/static/static/js/index.CUWXxL_C.js +1 -0
- streamlit/static/static/js/{index.BBotNZr-.js → index.CUepHEom.js} +1 -1
- streamlit/static/static/js/index.C_SUbLL7.js +1 -0
- streamlit/static/static/js/index.CdiPATR3.js +197 -0
- streamlit/static/static/js/index.CgZ_3VRU.js +1 -0
- streamlit/static/static/js/{index.BiCX2JZK.js → index.CjN5S59O.js} +1 -1
- streamlit/static/static/js/{index.B66JaJi3.js → index.Con6tiNg.js} +1 -1
- streamlit/static/static/js/{index.D-4pSvTG.js → index.D1sfL1bE.js} +1 -1
- streamlit/static/static/js/{index.CNDCHhth.js → index.D2PC_wwi.js} +1 -1
- streamlit/static/static/js/index.D8mp5ppE.js +201 -0
- streamlit/static/static/js/{index.C2VChsA1.js → index.DEz7mrAp.js} +1 -1
- streamlit/static/static/js/{index.BrXMfzqp.js → index.DPZJrrNj.js} +1 -1
- streamlit/static/static/js/{index.DB9G9YYY.js → index.Df3vkO_v.js} +1 -1
- streamlit/static/static/js/{index.BXFE-6NA.js → index.DuUcgXrv.js} +1 -1
- streamlit/static/static/js/{index.lCzpOFcS.js → index.DxvQWdtj.js} +1 -1
- streamlit/static/static/js/{index.D_tVZ0u0.js → index.DymllY6d.js} +2 -2
- streamlit/static/static/js/{index.Da7VTJGp.js → index.G1PSqufB.js} +2 -2
- streamlit/static/static/js/{index.B1Y_k9Fh.js → index.I2Ij_yHL.js} +1 -1
- streamlit/static/static/js/{index.NifETEVc.js → index.InwDjRN5.js} +1 -1
- streamlit/static/static/js/{index.iYzAfcLx.js → index.LmMDdxLh.js} +1 -1
- streamlit/static/static/js/{index.C9nK-VoQ.js → index.LypQPPkP.js} +3 -3
- streamlit/static/static/js/index.RDHMaPCV.js +1 -0
- streamlit/static/static/js/index.jj20zRA4.js +1 -0
- streamlit/static/static/js/{input.DqK048_c.js → input.QeLiGsyn.js} +2 -2
- streamlit/static/static/js/{memory.BYwXutbg.js → memory.0fYVo8Wx.js} +1 -1
- streamlit/static/static/js/{mergeWith.CwfhUp-s.js → mergeWith.AOqADio_.js} +1 -1
- streamlit/static/static/js/{number-overlay-editor.B-1TJraW.js → number-overlay-editor.DAvAckzz.js} +1 -1
- streamlit/static/static/js/{possibleConstructorReturn.CCjgmGB4.js → possibleConstructorReturn.C4RsC1R8.js} +1 -1
- streamlit/static/static/js/{sandbox.CzVH3fBX.js → sandbox.DT2p3KTe.js} +1 -1
- streamlit/static/static/js/{textarea.D47OO5VD.js → textarea.DQh9RYKV.js} +2 -2
- streamlit/static/static/js/{timepicker.Dq2FqiYO.js → timepicker.Br_cR0hi.js} +4 -4
- streamlit/static/static/js/{toConsumableArray.7OyX1dIj.js → toConsumableArray.CzYSWELu.js} +1 -1
- streamlit/static/static/js/{uniqueId.naIyoATl.js → uniqueId.BdUnRe3-.js} +1 -1
- streamlit/static/static/js/{useBasicWidgetState.DH0ClB0l.js → useBasicWidgetState.6R32QW2v.js} +1 -1
- streamlit/static/static/js/{useOnInputChange.3GZT2mEx.js → useOnInputChange.C4OiWI1_.js} +1 -1
- streamlit/static/static/js/withFullScreenWrapper.BLeP_b5i.js +1 -0
- streamlit/user_info.py +8 -2
- {streamlit_nightly-1.42.3.dev20250222.dist-info → streamlit_nightly-1.42.3.dev20250224.dist-info}/METADATA +1 -1
- {streamlit_nightly-1.42.3.dev20250222.dist-info → streamlit_nightly-1.42.3.dev20250224.dist-info}/RECORD +75 -75
- streamlit/static/static/js/FileDropzone.uWzTac7M.js +0 -5
- streamlit/static/static/js/index.BUnE-2Mi.js +0 -201
- streamlit/static/static/js/index.BxBwZJQr.js +0 -1
- streamlit/static/static/js/index.CNYNhiEk.js +0 -1
- streamlit/static/static/js/index.CUKOkOB2.js +0 -197
- streamlit/static/static/js/index.Ceuq3IzZ.js +0 -1
- streamlit/static/static/js/index.ChSsIvr7.js +0 -3865
- streamlit/static/static/js/index.DKFH0WYB.js +0 -1
- streamlit/static/static/js/index.DQT0NMTW.js +0 -1
- streamlit/static/static/js/index.DiXeiIyQ.js +0 -1
- streamlit/static/static/js/index.Dl_RyApM.js +0 -1
- streamlit/static/static/js/withFullScreenWrapper.HzikaPlG.js +0 -1
- {streamlit_nightly-1.42.3.dev20250222.data → streamlit_nightly-1.42.3.dev20250224.data}/scripts/streamlit.cmd +0 -0
- {streamlit_nightly-1.42.3.dev20250222.dist-info → streamlit_nightly-1.42.3.dev20250224.dist-info}/WHEEL +0 -0
- {streamlit_nightly-1.42.3.dev20250222.dist-info → streamlit_nightly-1.42.3.dev20250224.dist-info}/entry_points.txt +0 -0
- {streamlit_nightly-1.42.3.dev20250222.dist-info → streamlit_nightly-1.42.3.dev20250224.dist-info}/top_level.txt +0 -0
@@ -1,4 +1,4 @@
|
|
1
|
-
import{r as u,E as $,_ as H,aV as ut,bj as Ht,bk as Vt,bl as jt,K as q,M as G,R as yt,aC as qt,n as x,bm as Gt,C as z,j as v,bn as Xt,b4 as Yt,bo as Kt,bp as Jt,aq as Qt,y as Zt,bq as Z,z as te,az as ee,br as ie,bs as se,b9 as ne,bt as re}from"./index.6zGrdP7S.js";import{u as oe,F as ae}from"./FormClearHelper.CEl0YyS3.js";import{T as le,a as pt}from"./Toolbar.DGwjBtCI.js";import{u as ce}from"./Hooks.B_-0sclb.js";import{c as de}from"./createDownloadLinkElement.DZMwyjvU.js";import{F as he,D as ue}from"./FileDownload.esm.B1kyp21I.js";var wt=u.forwardRef(function(s,t){var e={fill:"currentColor",xmlns:"http://www.w3.org/2000/svg"};return u.createElement($,H({iconAttrs:e,iconVerticalAlign:"middle",iconViewBox:"0 0 24 24"},s,{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 St=u.forwardRef(function(s,t){var e={fill:"currentColor",xmlns:"http://www.w3.org/2000/svg"};return u.createElement($,H({iconAttrs:e,iconVerticalAlign:"middle",iconViewBox:"0 0 24 24"},s,{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"}))});St.displayName="Pause";var Ct=u.forwardRef(function(s,t){var e={fill:"currentColor",xmlns:"http://www.w3.org/2000/svg"};return u.createElement($,H({iconAttrs:e,iconVerticalAlign:"middle",iconViewBox:"0 0 24 24"},s,{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"}))});Ct.displayName="PlayArrow";var Rt=u.forwardRef(function(s,t){var e={fill:"currentColor",xmlns:"http://www.w3.org/2000/svg"};return u.createElement($,H({iconAttrs:e,iconVerticalAlign:"middle",iconViewBox:"0 0 24 24"},s,{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(s,t){var e={fill:"currentColor",xmlns:"http://www.w3.org/2000/svg"};return u.createElement($,H({iconAttrs:e,iconVerticalAlign:"middle",iconViewBox:"0 0 24 24"},s,{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(s,t,e,i){return new(e||(e=Promise))(function(r,n){function a(c){try{d(i.next(c))}catch(l){n(l)}}function o(c){try{d(i.throw(c))}catch(l){n(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(s,t||[])).next())})}let V=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(s,t){return E(this,void 0,void 0,function*(){const e=new AudioContext({sampleRate:t});return e.decodeAudioData(s).finally(()=>e.close())})},createBuffer:function(s,t){return typeof s[0]=="number"&&(s=[s]),function(e){const i=e[0];if(i.some(r=>r>1||r<-1)){const r=i.length;let n=0;for(let a=0;a<r;a++){const o=Math.abs(i[a]);o>n&&(n=o)}for(const a of e)for(let o=0;o<r;o++)a[o]/=n}}(s),{duration:t,length:s[0].length,sampleRate:s[0].length/t,numberOfChannels:s.length,getChannelData:e=>s==null?void 0:s[e],copyFromChannel:AudioBuffer.prototype.copyFromChannel,copyToChannel:AudioBuffer.prototype.copyToChannel}}};function xt(s,t){const e=t.xmlns?document.createElementNS(t.xmlns,s):document.createElement(s);for(const[i,r]of Object.entries(t))if(i==="children")for(const[n,a]of Object.entries(t))typeof a=="string"?e.appendChild(document.createTextNode(a)):e.appendChild(xt(n,a));else i==="style"?Object.assign(e.style,r):i==="textContent"?e.textContent=r:e.setAttribute(i,r.toString());return e}function ft(s,t,e){const i=xt(s,t||{});return e==null||e.appendChild(i),i}var pe=Object.freeze({__proto__:null,createElement:ft,default:ft});const me={fetchBlob:function(s,t,e){return E(this,void 0,void 0,function*(){const i=yield fetch(s,e);if(i.status>=400)throw new Error(`Failed to fetch ${s}: ${i.status} (${i.statusText})`);return function(r,n){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);n(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 V{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 N extends V{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,n]=this.initHtml();i.appendChild(r),this.container=r,this.scrollContainer=n.querySelector(".scroll"),this.wrapper=n.querySelector(".wrapper"),this.canvasWrapper=n.querySelector(".canvases"),this.progressWrapper=n.querySelector(".progress"),this.cursor=n.querySelector(".cursor"),e&&n.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,n=e.clientY-i.top;return[r/i.width,n/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,n=e/i,a=(e+r)/i;this.emit("scroll",n,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,n=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=S=>{if(S.preventDefault(),S.stopPropagation(),d&&Date.now()-b<o)return;const W=S.clientX,D=S.clientY,k=W-h,A=D-m;if(f||Math.abs(k)>n||Math.abs(A)>n){const I=t.getBoundingClientRect(),{left:U,top:O}=I;f||(i==null||i(h-U,m-O),f=!0),e(k,A,W-U,D-O),h=W,m=D}},w=S=>{if(f){const W=S.clientX,D=S.clientY,k=t.getBoundingClientRect(),{left:A,top:I}=k;r==null||r(W-A,D-I)}c()},y=S=>{S.relatedTarget&&S.relatedTarget!==document.documentElement||w(S)},P=S=>{f&&(S.stopPropagation(),S.preventDefault())},T=S=>{f&&S.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 n=this.parent.clientHeight||128;return e!=null&&e.every(a=>!a.overlay)?n/r:n}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 $,_ as H,aW as ut,bk as Ht,bl as Vt,bm as jt,K as G,M as X,R as yt,aD as Gt,n as x,bn as Xt,B as z,j as v,bo as qt,b5 as Yt,bp as Kt,bq as Jt,ar as Qt,y as Zt,br as Z,G as te,aA as ee,bs as ie,bt as se,ba as ne,bu as re}from"./index.7HEH_7fJ.js";import{u as oe,F as ae}from"./FormClearHelper.BkPbs0OF.js";import{T as le,a as pt}from"./Toolbar.CfNF-56q.js";import{u as ce}from"./Hooks.CW1Ujj-E.js";import{c as de}from"./createDownloadLinkElement.DZMwyjvU.js";import{F as he,D as ue}from"./FileDownload.esm.Db6P60XC.js";var wt=u.forwardRef(function(s,t){var e={fill:"currentColor",xmlns:"http://www.w3.org/2000/svg"};return u.createElement($,H({iconAttrs:e,iconVerticalAlign:"middle",iconViewBox:"0 0 24 24"},s,{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 St=u.forwardRef(function(s,t){var e={fill:"currentColor",xmlns:"http://www.w3.org/2000/svg"};return u.createElement($,H({iconAttrs:e,iconVerticalAlign:"middle",iconViewBox:"0 0 24 24"},s,{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"}))});St.displayName="Pause";var Ct=u.forwardRef(function(s,t){var e={fill:"currentColor",xmlns:"http://www.w3.org/2000/svg"};return u.createElement($,H({iconAttrs:e,iconVerticalAlign:"middle",iconViewBox:"0 0 24 24"},s,{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"}))});Ct.displayName="PlayArrow";var Rt=u.forwardRef(function(s,t){var e={fill:"currentColor",xmlns:"http://www.w3.org/2000/svg"};return u.createElement($,H({iconAttrs:e,iconVerticalAlign:"middle",iconViewBox:"0 0 24 24"},s,{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(s,t){var e={fill:"currentColor",xmlns:"http://www.w3.org/2000/svg"};return u.createElement($,H({iconAttrs:e,iconVerticalAlign:"middle",iconViewBox:"0 0 24 24"},s,{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(s,t,e,i){return new(e||(e=Promise))(function(r,n){function a(c){try{d(i.next(c))}catch(l){n(l)}}function o(c){try{d(i.throw(c))}catch(l){n(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(s,t||[])).next())})}let V=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(s,t){return E(this,void 0,void 0,function*(){const e=new AudioContext({sampleRate:t});return e.decodeAudioData(s).finally(()=>e.close())})},createBuffer:function(s,t){return typeof s[0]=="number"&&(s=[s]),function(e){const i=e[0];if(i.some(r=>r>1||r<-1)){const r=i.length;let n=0;for(let a=0;a<r;a++){const o=Math.abs(i[a]);o>n&&(n=o)}for(const a of e)for(let o=0;o<r;o++)a[o]/=n}}(s),{duration:t,length:s[0].length,sampleRate:s[0].length/t,numberOfChannels:s.length,getChannelData:e=>s==null?void 0:s[e],copyFromChannel:AudioBuffer.prototype.copyFromChannel,copyToChannel:AudioBuffer.prototype.copyToChannel}}};function xt(s,t){const e=t.xmlns?document.createElementNS(t.xmlns,s):document.createElement(s);for(const[i,r]of Object.entries(t))if(i==="children")for(const[n,a]of Object.entries(t))typeof a=="string"?e.appendChild(document.createTextNode(a)):e.appendChild(xt(n,a));else i==="style"?Object.assign(e.style,r):i==="textContent"?e.textContent=r:e.setAttribute(i,r.toString());return e}function ft(s,t,e){const i=xt(s,t||{});return e==null||e.appendChild(i),i}var pe=Object.freeze({__proto__:null,createElement:ft,default:ft});const me={fetchBlob:function(s,t,e){return E(this,void 0,void 0,function*(){const i=yield fetch(s,e);if(i.status>=400)throw new Error(`Failed to fetch ${s}: ${i.status} (${i.statusText})`);return function(r,n){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);n(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 V{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 N extends V{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,n]=this.initHtml();i.appendChild(r),this.container=r,this.scrollContainer=n.querySelector(".scroll"),this.wrapper=n.querySelector(".wrapper"),this.canvasWrapper=n.querySelector(".canvases"),this.progressWrapper=n.querySelector(".progress"),this.cursor=n.querySelector(".cursor"),e&&n.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,n=e.clientY-i.top;return[r/i.width,n/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,n=e/i,a=(e+r)/i;this.emit("scroll",n,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,n=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=S=>{if(S.preventDefault(),S.stopPropagation(),d&&Date.now()-b<o)return;const D=S.clientX,T=S.clientY,k=D-h,A=T-m;if(f||Math.abs(k)>n||Math.abs(A)>n){const I=t.getBoundingClientRect(),{left:U,top:O}=I;f||(i==null||i(h-U,m-O),f=!0),e(k,A,D-U,T-O),h=D,m=T}},w=S=>{if(f){const D=S.clientX,T=S.clientY,k=t.getBoundingClientRect(),{left:A,top:I}=k;r==null||r(D-A,T-I)}c()},y=S=>{S.relatedTarget&&S.relatedTarget!==document.documentElement||w(S)},P=S=>{f&&(S.stopPropagation(),S.preventDefault())},W=S=>{f&&S.preventDefault()};document.addEventListener("pointermove",g),document.addEventListener("pointerup",w),document.addEventListener("pointerout",y),document.addEventListener("pointercancel",y),document.addEventListener("touchmove",W,{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",W),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 n=this.parent.clientHeight||128;return e!=null&&e.every(a=>!a.overlay)?n/r:n}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 $,_ as H,aV as ut,bj as Ht,bk as Vt,bl as jt,K as q,M as G,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((n,a)=>{r(),i=a,e=setTimeout(()=>{e=void 0,i=void 0,n()},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),n=i.createLinearGradient(0,0,0,r),a=1/(t.length-1);return t.forEach((o,d)=>{const c=d*a;n.addColorStop(c,o)}),n}getPixelRatio(){return Math.max(1,window.devicePixelRatio||1)}renderBarWaveform(t,e,i,r){const n=t[0],a=t[1]||t[0],o=n.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 S=Math.round(T*b);if(S>w){const k=Math.round(y*l*r),A=k+Math.round(P*l*r)||1;let I=l-k;e.barAlign==="top"?I=0:e.barAlign==="bottom"&&(I=c-A),i[g](w*(h+m),I,h,A,f),w=S,y=0,P=0}const W=Math.abs(n[T]||0),D=Math.abs(a[T]||0);W>y&&(y=W),D>P&&(P=D)}i.fill(),i.closePath()}renderLineWaveform(t,e,i,r){const n=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(),n(0),n(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 n=Array.from(t[0]).reduce((a,o)=>Math.max(a,Math.abs(o)),0);r=n?1/n:1}e.barWidth||e.barGap||e.barAlign?this.renderBarWaveform(t,e,i,r):this.renderLineWaveform(t,e,i,r)}renderSingleCanvas(t,e,i,r,n,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(n)}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,n,a){const o=this.getPixelRatio(),{clientWidth:d}=this.scrollContainer,c=i/o;let l=Math.min(N.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 S=Math.floor(w/c*T.length),W=Math.floor((w+y)/c*T.length);return T.slice(S,W)});this.renderSingleCanvas(P,e,y,r,w,n,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>N.MAX_NODES&&(n.innerHTML="",a.innerHTML="",p={}),h(w-1),h(w),h(w+1)}))}renderChannel(t,e,i,r){var{overlay:n}=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`,n&&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,n=Math.ceil(t.duration*(this.options.minPxPerSec||0));this.isScrollable=n>r;const a=this.options.fillParent&&!this.isScrollable,o=(a?r:n)*i;if(this.wrapper.style.width=a?"100%":`${n}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 n=r-i;n*=2,n=n<0?Math.floor(n):Math.ceil(n),n/=2,this.scrollContainer.scrollLeft+=n}}zoom(t){this.options.minPxPerSec=t,this.reRender()}scrollIntoView(t,e=!1){const{scrollLeft:i,scrollWidth:r,clientWidth:n}=this.scrollContainer,a=t*r,o=i,d=i+n,c=n/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+n)/r;this.emit("scroll",p,h,l,l+n)}}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 n=Array.from(r).map(a=>a.toDataURL(t,e));return Promise.resolve(n)}return Promise.all(Array.from(r).map(n=>new Promise((a,o)=>{n.toBlob(d=>{d?a(d):o(new Error("Could not export image"))},t,e)})))})}}N.MAX_CANVAS_WIDTH=8e3,N.MAX_NODES=10;class ge extends V{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 V{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 F extends fe{static create(t){return new F(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 N(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:n,duration:a}=this.options;(r||n&&a)&&this.load(r,n,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 n=this.getDuration();this.emit("scroll",t*n,e*n,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 n;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=(n=this.abortController)===null||n===void 0?void 0:n.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),n=[];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)}n.push(d)}return n}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()}}F.BasePlugin=class extends V{constructor(s){super(),this.subscriptions=[],this.options=s}onInit(){}_init(s){this.wavesurfer=s,this.onInit()}destroy(){this.emit("destroy"),this.subscriptions.forEach(s=>s())}},F.dom=pe;function tt(s,t,e,i){return new(e||(e=Promise))(function(r,n){function a(c){try{d(i.next(c))}catch(l){n(l)}}function o(c){try{d(i.throw(c))}catch(l){n(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(s,[])).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 X extends be{constructor(t){var e,i,r,n,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:(n=t.continuousWaveform)!==null&&n!==void 0&&n,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 X(t||{})}renderMicStream(t){var e;const i=new AudioContext,r=i.createMediaStreamSource(t),n=i.createAnalyser();r.connect(n),this.options.continuousWaveform&&(n.fftSize=32);const a=n.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(n.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(n){throw new Error("Error accessing the microphone: "+n.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 n=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=()=>n("record-pause"),i.onstop=()=>n("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 Se=async({files:s,uploadClient:t,widgetMgr:e,widgetInfo:i,fragmentId:r})=>{let n=[];try{n=await t.fetchFileURLs(s)}catch(c){return{successfulUploads:[],failedUploads:s.map(l=>({file:l,error:ut(c)}))}}const a=Ht(s,n),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 Vt({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:s,id:t,formId:e,key:i,defaultValue:r})=>{u.useEffect(()=>{const l=s.getElementState(t,i);q(l)&&G(r)&&s.setElementState(t,i,r)},[s,t,i,r]);const[n,a]=u.useState(s.getElementState(t,i)??r),o=u.useCallback(l=>{s.setElementState(t,i,l),a(l)},[s,t,i]),d=u.useMemo(()=>({formId:e||""}),[e]),c=u.useCallback(()=>o(r),[r,o]);return oe({element:d,widgetMgr:s,onFormCleared:c}),[n,o]},Ce=(s,t)=>{const{libConfig:{enforceDownloadInNewTab:e=!1}}=yt.useContext(qt);return u.useCallback(()=>{if(!s)return;const r=de({enforceDownloadInNewTab:e,url:s,filename:t});r.style.display="none",document.body.appendChild(r),r.click(),document.body.removeChild(r)},[s,e,t])},Re=x("div",{target:"etzg8g80"})(),vt=x("div",{target:"etzg8g81"})(({theme:s})=>({height:s.sizes.largestElementHeight,width:"100%",background:s.colors.secondaryBg,borderRadius:s.radii.default,marginBottom:s.spacing.twoXS,display:"flex",alignItems:"center",position:"relative",paddingLeft:s.spacing.xs,paddingRight:s.spacing.sm,border:s.colors.widgetBorderColor?`${s.sizes.borderWidth} solid ${s.colors.widgetBorderColor}`:void 0})),Ee=x("div",{target:"etzg8g82"})({flex:1}),xe=x("div",{target:"etzg8g83"})(({show:s})=>({display:s?"block":"none"})),Pe=x("span",{target:"etzg8g84"})(({theme:s,isPlayingOrRecording:t})=>({margin:s.spacing.sm,fontFamily:s.fonts.monospace,color:t?s.colors.bodyText:s.colors.fadedText60,backgroundColor:s.colors.secondaryBg,fontSize:s.fontSizes.sm})),Tt=x("div",{target:"etzg8g85"})({width:"100%",textAlign:"center",overflow:"hidden"}),Wt=x("span",{target:"etzg8g86"})(({theme:s})=>({color:s.colors.bodyText})),Te=x("a",{target:"etzg8g87"})(({theme:s})=>({color:s.colors.link,textDecoration:"underline"})),We=x("div",{target:"etzg8g88"})(({theme:s})=>({height:s.sizes.largestElementHeight,display:"flex",justifyContent:"center",alignItems:"center"})),De=x("div",{target:"etzg8g89"})(({theme:s})=>{const t="0.625em";return{opacity:.2,width:"100%",height:t,backgroundSize:t,backgroundImage:`radial-gradient(${s.colors.fadedText10} 40%, transparent 40%)`,backgroundRepeat:"repeat"}}),Ae=x("span",{target:"etzg8g810"})(({theme:s})=>({"& > button":{color:s.colors.primary,padding:s.spacing.threeXS},"& > button:hover, & > button:focus":{color:s.colors.red}})),Me=x("span",{target:"etzg8g811"})(({theme:s})=>({"& > button":{padding:s.spacing.threeXS,color:s.colors.fadedText40},"& > button:hover, & > button:focus":{color:s.colors.primary}})),Dt=x("span",{target:"etzg8g812"})(({theme:s})=>({"& > button":{padding:s.spacing.threeXS,color:s.colors.fadedText60},"& > button:hover, & > button:focus":{color:s.colors.bodyText}})),it=x("div",{target:"etzg8g813"})(({theme:s})=>({display:"flex",justifyContent:"center",alignItems:"center",flexGrow:0,flexShrink:1,padding:s.spacing.xs,gap:s.spacing.twoXS,marginRight:s.spacing.twoXS})),ke=x("div",{target:"etzg8g814"})(({theme:s})=>({marginLeft:s.spacing.sm})),Ie=x(Gt,{target:"etzg8g815"})(({theme:s})=>({fontSize:s.fontSizes.sm,width:s.sizes.spinnerSize,height:s.sizes.spinnerSize,borderWidth:s.sizes.spinnerThickness,justifyContents:"center",padding:s.spacing.none,margin:s.spacing.none,borderColor:s.colors.borderColor,borderTopColor:s.colors.secondary,flexGrow:0,flexShrink:0})),Le=()=>z(Tt,{children:[v(Wt,{children:"This app would like to use your microphone."})," ",v(Te,{href:Xt,children:"Learn how to allow access."})]}),Oe=()=>v(We,{children:v(De,{})}),Be=4,ze=4,Ne=4,Ue=8,Fe=0,j="00:00",bt=s=>{const t=Math.floor(s/1e3),e=Math.floor(t/60),i=Math.floor(e/60),r=t%60,n=e%60,a=r.toString().padStart(2,"0"),o=n.toString().padStart(2,"0"),d=i.toString().padStart(2,"0");return e<60?`${o}:${a}`:`${d}:${o}:${a}`},_=({onClick:s,disabled:t,ariaLabel:e,iconContent:i})=>v(Jt,{kind:Yt.BORDERLESS_ICON,onClick:s,disabled:t,"aria-label":e,fluidWidth:!0,"data-testid":"stAudioInputActionButton",children:v(Kt,{content:i,size:"lg",color:"inherit"})}),_e=({disabled:s,stopRecording:t})=>v(Ae,{children:v(_,{onClick:t,disabled:s,ariaLabel:"Stop recording",iconContent:Et})}),$e=({disabled:s,isPlaying:t,onClickPlayPause:e})=>v(Dt,{children:t?v(_,{onClick:e,disabled:s,ariaLabel:"Pause",iconContent:St}):v(_,{onClick:e,disabled:s,ariaLabel:"Play",iconContent:Ct})}),He=({disabled:s,startRecording:t})=>v(Me,{children:v(_,{onClick:t,disabled:s,ariaLabel:"Record",iconContent:wt})}),Ve=({onClick:s})=>v(Dt,{children:v(_,{disabled:!1,onClick:s,ariaLabel:"Reset",iconContent:Rt})}),je=({disabled:s,isRecording:t,isPlaying:e,isUploading:i,isError:r,recordingUrlExists:n,startRecording:a,stopRecording:o,onClickPlayPause:d,onClear:c})=>r?v(it,{children:v(Ve,{onClick:c})}):i?v(it,{children:v(Ie,{"aria-label":"Uploading"})}):z(it,{children:[t?v(_e,{disabled:s,stopRecording:o}):v(He,{disabled:s,startRecording:a}),n&&v($e,{disabled:s,isPlaying:e,onClickPlayPause:d})]}),qe=u.memo(je),Ge=Qt.getLogger("convertAudioToWav");async function Xe(s){const t=new window.AudioContext,e=await s.arrayBuffer();let i;try{i=await t.decodeAudioData(e)}catch(m){Ge.error(m);return}const r=44,n=i.numberOfChannels,a=i.sampleRate,o=i.length*n*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:n},24:{type:"uint32",value:a},28:{type:"uint32",value:a*n*2},32:{type:"uint16",value:n*2},34:{type:"uint16",value:16},36:{type:"string",value:"data"},40:{type:"uint32",value:i.length*n*2}};Object.entries(l).forEach(([m,{type:f,value:b}])=>{const g=parseInt(m,10);f==="string"?Ye(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<n;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 Ye(s,t,e){for(let i=0;i<e.length;i++)s.setUint8(t+i,e.charCodeAt(i))}const Ke=()=>v(Tt,{children:v(Wt,{children:"An error has occurred, please try again."})}),Je=({element:s,uploadClient:t,widgetMgr:e,fragmentId:i,disabled:r})=>{var ht;const n=Zt(),a=ce(n),[o,d]=u.useState(null),c=yt.useRef(null),[l,p]=et({widgetMgr:e,id:s.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:s.id,key:"recordingUrl",defaultValue:null}),[,T]=u.useState(0),S=()=>{T(C=>C+1)},[W,D]=u.useState(j),[k,A]=et({widgetMgr:e,id:s.id,formId:s.formId,key:"recordingTime",defaultValue:j}),[I,U]=u.useState(!1),[O,At]=u.useState(!1),[st,Mt]=u.useState(!1),[kt,nt]=u.useState(!1),[Y,K]=u.useState(!1),rt=s.id,L=s.formId,ot=u.useCallback(async C=>{nt(!0),G(L)&&e.setFormsWithUploadsInProgress(new Set([L]));let R;if(C.type==="audio/wav"?R=C:R=await Xe(C),!R){K(!0);return}const M=URL.createObjectURL(R),Ut=new Date().toISOString().slice(0,16).replace(":","-"),Ft=new File([R],`${Ut}_audio.wav`,{type:R.type});P(M),Se({files:[Ft],uploadClient:t,widgetMgr:e,widgetInfo:{id:rt,formId:L},fragmentId:i}).then(({successfulUploads:_t,failedUploads:$t})=>{if($t.length>0){K(!0);return}const Q=_t[0];Q&&Q.fileUrl.deleteUrl&&p(Q.fileUrl.deleteUrl)}).finally(()=>{G(L)&&e.setFormsWithUploadsInProgress(new Set),nt(!1)})},[P,t,e,rt,L,i,p]),B=u.useCallback(({updateWidgetManager:C,deleteFile:R})=>{q(o)||q(l)||(P(null),o.empty(),R&&t.deleteFile(l),p(null),D(j),A(j),C&&e.setFileUploaderStateValue(s,{},{fromUi:!0},i),U(!1),G(y)&&URL.revokeObjectURL(y))},[l,y,t,o,s,e,i,A,P,p]);u.useEffect(()=>{if(q(L))return;const C=new ae;return C.manageFormClearListener(e,L,()=>B({updateWidgetManager:!0,deleteFile:!1})),()=>C.disconnect()},[L,B,e]);const at=u.useCallback(()=>{if(c.current===null)return;const C=F.create({container:c.current,waveColor:y?Z(n.colors.fadedText40,n.colors.secondaryBg):n.colors.primary,progressColor:n.colors.bodyText,height:te(n.sizes.largestElementHeight)-2*Be,barWidth:ze,barGap:Ne,barRadius:Ue,cursorWidth:Fe,url:y??void 0});C.on("timeupdate",M=>{D(bt(M*1e3))}),C.on("pause",()=>{S()});const R=C.registerPlugin(X.create({scrollingWaveform:!1,renderRecordedAudio:!0}));return R.on("record-end",async M=>{ot(M)}),R.on("record-progress",M=>{A(bt(M))}),d(C),m(R),()=>{C&&C.destroy(),R&&R.destroy()}},[ot]);u.useEffect(()=>at(),[at]),u.useEffect(()=>{ee(a,n)||o==null||o.setOptions({waveColor:y?Z(n.colors.fadedText40,n.colors.secondaryBg):n.colors.primary,progressColor:n.colors.bodyText})},[n,a,y,o]);const It=u.useCallback(()=>{o&&(o.playPause(),U(!0),S())},[o]),Lt=u.useCallback(async()=>{let C=g;st||(await navigator.mediaDevices.getUserMedia({audio:!0}).then(()=>X.getAvailableAudioDevices().then(R=>{if(b(R),R.length>0){const{deviceId:M}=R[0];w(M),C=M}})).catch(R=>{At(!0)}),Mt(!0)),!(!h||!C||!o)&&(o.setOptions({waveColor:n.colors.primary}),y&&B({updateWidgetManager:!1,deleteFile:!0}),h.startRecording({deviceId:C}).then(()=>{S()}))},[g,h,n,o,y,B,st]),Ot=u.useCallback(()=>{h&&(h.stopRecording(),o==null||o.setOptions({waveColor:Z(n.colors.fadedText40,n.colors.secondaryBg)}))},[h,o,n]),Bt=Ce(y,"recording.wav"),J=!!(h!=null&&h.isRecording()),lt=!!(o!=null&&o.isPlaying()),zt=J||lt,ct=!J&&!y&&!O,Nt=O||ct||Y,dt=r||O;return z(Re,{className:"stAudioInput","data-testid":"stAudioInput",children:[v(re,{label:s.label,disabled:dt,labelVisibility:ie((ht=s.labelVisibility)==null?void 0:ht.value),children:s.help&&v(ke,{children:v(se,{content:s.help,placement:ne.TOP})})}),z(vt,{children:[z(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(qe,{isRecording:J,isPlaying:lt,isUploading:kt,isError:Y,recordingUrlExists:!!y,startRecording:Lt,stopRecording:Ot,onClickPlayPause:It,onClear:()=>{B({updateWidgetManager:!1,deleteFile:!0}),K(!1)},disabled:dt}),z(Ee,{children:[Y&&v(Ke,{}),ct&&v(Oe,{}),O&&v(Le,{}),v(xe,{"data-testid":"stAudioInputWaveSurfer",ref:c,show:!Nt})]}),v(Pe,{isPlayingOrRecording:zt,"data-testid":"stAudioInputWaveformTimeCode",children:I?W:k})]})]})},ri=u.memo(Je);export{ri 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((n,a)=>{r(),i=a,e=setTimeout(()=>{e=void 0,i=void 0,n()},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),n=i.createLinearGradient(0,0,0,r),a=1/(t.length-1);return t.forEach((o,d)=>{const c=d*a;n.addColorStop(c,o)}),n}getPixelRatio(){return Math.max(1,window.devicePixelRatio||1)}renderBarWaveform(t,e,i,r){const n=t[0],a=t[1]||t[0],o=n.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 W=0;W<=o;W++){const S=Math.round(W*b);if(S>w){const k=Math.round(y*l*r),A=k+Math.round(P*l*r)||1;let I=l-k;e.barAlign==="top"?I=0:e.barAlign==="bottom"&&(I=c-A),i[g](w*(h+m),I,h,A,f),w=S,y=0,P=0}const D=Math.abs(n[W]||0),T=Math.abs(a[W]||0);D>y&&(y=D),T>P&&(P=T)}i.fill(),i.closePath()}renderLineWaveform(t,e,i,r){const n=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(),n(0),n(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 n=Array.from(t[0]).reduce((a,o)=>Math.max(a,Math.abs(o)),0);r=n?1/n:1}e.barWidth||e.barGap||e.barAlign?this.renderBarWaveform(t,e,i,r):this.renderLineWaveform(t,e,i,r)}renderSingleCanvas(t,e,i,r,n,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(n)}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,n,a){const o=this.getPixelRatio(),{clientWidth:d}=this.scrollContainer,c=i/o;let l=Math.min(N.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(W=>{const S=Math.floor(w/c*W.length),D=Math.floor((w+y)/c*W.length);return W.slice(S,D)});this.renderSingleCanvas(P,e,y,r,w,n,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>N.MAX_NODES&&(n.innerHTML="",a.innerHTML="",p={}),h(w-1),h(w),h(w+1)}))}renderChannel(t,e,i,r){var{overlay:n}=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`,n&&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,n=Math.ceil(t.duration*(this.options.minPxPerSec||0));this.isScrollable=n>r;const a=this.options.fillParent&&!this.isScrollable,o=(a?r:n)*i;if(this.wrapper.style.width=a?"100%":`${n}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 n=r-i;n*=2,n=n<0?Math.floor(n):Math.ceil(n),n/=2,this.scrollContainer.scrollLeft+=n}}zoom(t){this.options.minPxPerSec=t,this.reRender()}scrollIntoView(t,e=!1){const{scrollLeft:i,scrollWidth:r,clientWidth:n}=this.scrollContainer,a=t*r,o=i,d=i+n,c=n/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+n)/r;this.emit("scroll",p,h,l,l+n)}}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 n=Array.from(r).map(a=>a.toDataURL(t,e));return Promise.resolve(n)}return Promise.all(Array.from(r).map(n=>new Promise((a,o)=>{n.toBlob(d=>{d?a(d):o(new Error("Could not export image"))},t,e)})))})}}N.MAX_CANVAS_WIDTH=8e3,N.MAX_NODES=10;class ge extends V{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 V{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 F extends fe{static create(t){return new F(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 N(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:n,duration:a}=this.options;(r||n&&a)&&this.load(r,n,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 n=this.getDuration();this.emit("scroll",t*n,e*n,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 n;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=(n=this.abortController)===null||n===void 0?void 0:n.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),n=[];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)}n.push(d)}return n}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()}}F.BasePlugin=class extends V{constructor(s){super(),this.subscriptions=[],this.options=s}onInit(){}_init(s){this.wavesurfer=s,this.onInit()}destroy(){this.emit("destroy"),this.subscriptions.forEach(s=>s())}},F.dom=pe;function tt(s,t,e,i){return new(e||(e=Promise))(function(r,n){function a(c){try{d(i.next(c))}catch(l){n(l)}}function o(c){try{d(i.throw(c))}catch(l){n(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(s,[])).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,n,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:(n=t.continuousWaveform)!==null&&n!==void 0&&n,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),n=i.createAnalyser();r.connect(n),this.options.continuousWaveform&&(n.fftSize=32);const a=n.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(n.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(n){throw new Error("Error accessing the microphone: "+n.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 n=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=()=>n("record-pause"),i.onstop=()=>n("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 Se=async({files:s,uploadClient:t,widgetMgr:e,widgetInfo:i,fragmentId:r})=>{let n=[];try{n=await t.fetchFileURLs(s)}catch(c){return{successfulUploads:[],failedUploads:s.map(l=>({file:l,error:ut(c)}))}}const a=Ht(s,n),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 Vt({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:s,id:t,formId:e,key:i,defaultValue:r})=>{u.useEffect(()=>{const l=s.getElementState(t,i);G(l)&&X(r)&&s.setElementState(t,i,r)},[s,t,i,r]);const[n,a]=u.useState(s.getElementState(t,i)??r),o=u.useCallback(l=>{s.setElementState(t,i,l),a(l)},[s,t,i]),d=u.useMemo(()=>({formId:e||""}),[e]),c=u.useCallback(()=>o(r),[r,o]);return oe({element:d,widgetMgr:s,onFormCleared:c}),[n,o]},Ce=(s,t)=>{const{libConfig:{enforceDownloadInNewTab:e=!1}}=yt.useContext(Gt);return u.useCallback(()=>{if(!s)return;const r=de({enforceDownloadInNewTab:e,url:s,filename:t});r.style.display="none",document.body.appendChild(r),r.click(),document.body.removeChild(r)},[s,e,t])},Re=x("div",{target:"etzg8g80"})(),vt=x("div",{target:"etzg8g81"})(({theme:s})=>({height:s.sizes.largestElementHeight,width:"100%",background:s.colors.secondaryBg,borderRadius:s.radii.default,marginBottom:s.spacing.twoXS,display:"flex",alignItems:"center",position:"relative",paddingLeft:s.spacing.xs,paddingRight:s.spacing.sm,border:s.colors.widgetBorderColor?`${s.sizes.borderWidth} solid ${s.colors.widgetBorderColor}`:void 0})),Ee=x("div",{target:"etzg8g82"})({flex:1}),xe=x("div",{target:"etzg8g83"})(({show:s})=>({display:s?"block":"none"})),Pe=x("span",{target:"etzg8g84"})(({theme:s,isPlayingOrRecording:t})=>({margin:s.spacing.sm,fontFamily:s.fonts.monospace,color:t?s.colors.bodyText:s.colors.fadedText60,backgroundColor:s.colors.secondaryBg,fontSize:s.fontSizes.sm})),Wt=x("div",{target:"etzg8g85"})({width:"100%",textAlign:"center",overflow:"hidden"}),Dt=x("span",{target:"etzg8g86"})(({theme:s})=>({color:s.colors.bodyText})),We=x("a",{target:"etzg8g87"})(({theme:s})=>({color:s.colors.link,textDecoration:"underline"})),De=x("div",{target:"etzg8g88"})(({theme:s})=>({height:s.sizes.largestElementHeight,display:"flex",justifyContent:"center",alignItems:"center"})),Te=x("div",{target:"etzg8g89"})(({theme:s})=>{const t="0.625em";return{opacity:.2,width:"100%",height:t,backgroundSize:t,backgroundImage:`radial-gradient(${s.colors.fadedText10} 40%, transparent 40%)`,backgroundRepeat:"repeat"}}),Ae=x("span",{target:"etzg8g810"})(({theme:s})=>({"& > button":{color:s.colors.primary,padding:s.spacing.threeXS},"& > button:hover, & > button:focus":{color:s.colors.red}})),Me=x("span",{target:"etzg8g811"})(({theme:s})=>({"& > button":{padding:s.spacing.threeXS,color:s.colors.fadedText40},"& > button:hover, & > button:focus":{color:s.colors.primary}})),Tt=x("span",{target:"etzg8g812"})(({theme:s})=>({"& > button":{padding:s.spacing.threeXS,color:s.colors.fadedText60},"& > button:hover, & > button:focus":{color:s.colors.bodyText}})),it=x("div",{target:"etzg8g813"})(({theme:s})=>({display:"flex",justifyContent:"center",alignItems:"center",flexGrow:0,flexShrink:1,padding:s.spacing.xs,gap:s.spacing.twoXS,marginRight:s.spacing.twoXS})),ke=x("div",{target:"etzg8g814"})(({theme:s})=>({marginLeft:s.spacing.sm})),Ie=x(Xt,{target:"etzg8g815"})(({theme:s})=>({fontSize:s.fontSizes.sm,width:s.sizes.spinnerSize,height:s.sizes.spinnerSize,borderWidth:s.sizes.spinnerThickness,justifyContents:"center",padding:s.spacing.none,margin:s.spacing.none,borderColor:s.colors.borderColor,borderTopColor:s.colors.secondary,flexGrow:0,flexShrink:0})),Le=()=>z(Wt,{children:[v(Dt,{children:"This app would like to use your microphone."})," ",v(We,{href:qt,children:"Learn how to allow access."})]}),Oe=()=>v(De,{children:v(Te,{})}),Be=4,ze=4,Ne=4,Ue=8,Fe=0,j="00:00",bt=s=>{const t=Math.floor(s/1e3),e=Math.floor(t/60),i=Math.floor(e/60),r=t%60,n=e%60,a=r.toString().padStart(2,"0"),o=n.toString().padStart(2,"0"),d=i.toString().padStart(2,"0");return e<60?`${o}:${a}`:`${d}:${o}:${a}`},_=({onClick:s,disabled:t,ariaLabel:e,iconContent:i})=>v(Jt,{kind:Yt.BORDERLESS_ICON,onClick:s,disabled:t,"aria-label":e,fluidWidth:!0,"data-testid":"stAudioInputActionButton",children:v(Kt,{content:i,size:"lg",color:"inherit"})}),_e=({disabled:s,stopRecording:t})=>v(Ae,{children:v(_,{onClick:t,disabled:s,ariaLabel:"Stop recording",iconContent:Et})}),$e=({disabled:s,isPlaying:t,onClickPlayPause:e})=>v(Tt,{children:t?v(_,{onClick:e,disabled:s,ariaLabel:"Pause",iconContent:St}):v(_,{onClick:e,disabled:s,ariaLabel:"Play",iconContent:Ct})}),He=({disabled:s,startRecording:t})=>v(Me,{children:v(_,{onClick:t,disabled:s,ariaLabel:"Record",iconContent:wt})}),Ve=({onClick:s})=>v(Tt,{children:v(_,{disabled:!1,onClick:s,ariaLabel:"Reset",iconContent:Rt})}),je=({disabled:s,isRecording:t,isPlaying:e,isUploading:i,isError:r,recordingUrlExists:n,startRecording:a,stopRecording:o,onClickPlayPause:d,onClear:c})=>r?v(it,{children:v(Ve,{onClick:c})}):i?v(it,{children:v(Ie,{"aria-label":"Uploading"})}):z(it,{children:[t?v(_e,{disabled:s,stopRecording:o}):v(He,{disabled:s,startRecording:a}),n&&v($e,{disabled:s,isPlaying:e,onClickPlayPause:d})]}),Ge=u.memo(je),Xe=Qt.getLogger("convertAudioToWav");async function qe(s){const t=new window.AudioContext,e=await s.arrayBuffer();let i;try{i=await t.decodeAudioData(e)}catch(m){Xe.error(m);return}const r=44,n=i.numberOfChannels,a=i.sampleRate,o=i.length*n*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:n},24:{type:"uint32",value:a},28:{type:"uint32",value:a*n*2},32:{type:"uint16",value:n*2},34:{type:"uint16",value:16},36:{type:"string",value:"data"},40:{type:"uint32",value:i.length*n*2}};Object.entries(l).forEach(([m,{type:f,value:b}])=>{const g=parseInt(m,10);f==="string"?Ye(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<n;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 Ye(s,t,e){for(let i=0;i<e.length;i++)s.setUint8(t+i,e.charCodeAt(i))}const Ke=()=>v(Wt,{children:v(Dt,{children:"An error has occurred, please try again."})}),Je=({element:s,uploadClient:t,widgetMgr:e,fragmentId:i,disabled:r})=>{var ht;const n=Zt(),a=ce(n),[o,d]=u.useState(null),c=yt.useRef(null),[l,p]=et({widgetMgr:e,id:s.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:s.id,key:"recordingUrl",defaultValue:null}),[,W]=u.useState(0),S=()=>{W(C=>C+1)},[D,T]=u.useState(j),[k,A]=et({widgetMgr:e,id:s.id,formId:s.formId,key:"recordingTime",defaultValue:j}),[I,U]=u.useState(!1),[O,At]=u.useState(!1),[st,Mt]=u.useState(!1),[kt,nt]=u.useState(!1),[Y,K]=u.useState(!1),rt=s.id,L=s.formId,ot=u.useCallback(async C=>{nt(!0),X(L)&&e.setFormsWithUploadsInProgress(new Set([L]));let R;if(C.type==="audio/wav"?R=C:R=await qe(C),!R){K(!0);return}const M=URL.createObjectURL(R),Ut=new Date().toISOString().slice(0,16).replace(":","-"),Ft=new File([R],`${Ut}_audio.wav`,{type:R.type});P(M),Se({files:[Ft],uploadClient:t,widgetMgr:e,widgetInfo:{id:rt,formId:L},fragmentId:i}).then(({successfulUploads:_t,failedUploads:$t})=>{if($t.length>0){K(!0);return}const Q=_t[0];Q&&Q.fileUrl.deleteUrl&&p(Q.fileUrl.deleteUrl)}).finally(()=>{X(L)&&e.setFormsWithUploadsInProgress(new Set),nt(!1)})},[P,t,e,rt,L,i,p]),B=u.useCallback(({updateWidgetManager:C,deleteFile:R})=>{G(o)||G(l)||(P(null),o.empty(),R&&t.deleteFile(l),p(null),T(j),A(j),C&&e.setFileUploaderStateValue(s,{},{fromUi:!0},i),U(!1),X(y)&&URL.revokeObjectURL(y))},[l,y,t,o,s,e,i,A,P,p]);u.useEffect(()=>{if(G(L))return;const C=new ae;return C.manageFormClearListener(e,L,()=>B({updateWidgetManager:!0,deleteFile:!1})),()=>C.disconnect()},[L,B,e]);const at=u.useCallback(()=>{if(c.current===null)return;const C=F.create({container:c.current,waveColor:y?Z(n.colors.fadedText40,n.colors.secondaryBg):n.colors.primary,progressColor:n.colors.bodyText,height:te(n.sizes.largestElementHeight)-2*Be,barWidth:ze,barGap:Ne,barRadius:Ue,cursorWidth:Fe,url:y??void 0});C.on("timeupdate",M=>{T(bt(M*1e3))}),C.on("pause",()=>{S()});const R=C.registerPlugin(q.create({scrollingWaveform:!1,renderRecordedAudio:!0}));return R.on("record-end",async M=>{ot(M)}),R.on("record-progress",M=>{A(bt(M))}),d(C),m(R),()=>{C&&C.destroy(),R&&R.destroy()}},[ot]);u.useEffect(()=>at(),[at]),u.useEffect(()=>{ee(a,n)||o==null||o.setOptions({waveColor:y?Z(n.colors.fadedText40,n.colors.secondaryBg):n.colors.primary,progressColor:n.colors.bodyText})},[n,a,y,o]);const It=u.useCallback(()=>{o&&(o.playPause(),U(!0),S())},[o]),Lt=u.useCallback(async()=>{let C=g;st||(await navigator.mediaDevices.getUserMedia({audio:!0}).then(()=>q.getAvailableAudioDevices().then(R=>{if(b(R),R.length>0){const{deviceId:M}=R[0];w(M),C=M}})).catch(R=>{At(!0)}),Mt(!0)),!(!h||!C||!o)&&(o.setOptions({waveColor:n.colors.primary}),y&&B({updateWidgetManager:!1,deleteFile:!0}),h.startRecording({deviceId:C}).then(()=>{S()}))},[g,h,n,o,y,B,st]),Ot=u.useCallback(()=>{h&&(h.stopRecording(),o==null||o.setOptions({waveColor:Z(n.colors.fadedText40,n.colors.secondaryBg)}))},[h,o,n]),Bt=Ce(y,"recording.wav"),J=!!(h!=null&&h.isRecording()),lt=!!(o!=null&&o.isPlaying()),zt=J||lt,ct=!J&&!y&&!O,Nt=O||ct||Y,dt=r||O;return z(Re,{className:"stAudioInput","data-testid":"stAudioInput",children:[v(re,{label:s.label,disabled:dt,labelVisibility:ie((ht=s.labelVisibility)==null?void 0:ht.value),children:s.help&&v(ke,{children:v(se,{content:s.help,placement:ne.TOP})})}),z(vt,{children:[z(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:kt,isError:Y,recordingUrlExists:!!y,startRecording:Lt,stopRecording:Ot,onClickPlayPause:It,onClear:()=>{B({updateWidgetManager:!1,deleteFile:!0}),K(!1)},disabled:dt}),z(Ee,{children:[Y&&v(Ke,{}),ct&&v(Oe,{}),O&&v(Le,{}),v(xe,{"data-testid":"stAudioInputWaveSurfer",ref:c,show:!Nt})]}),v(Pe,{isPlayingOrRecording:zt,"data-testid":"stAudioInputWaveformTimeCode",children:I?D:k})]})]})},ri=u.memo(Je);export{ri as default};
|
@@ -0,0 +1 @@
|
|
1
|
+
import{r,E as X,_ as q,n as x,y as ut,bh as ct,cr as dt,M as J,cB as I,K as b,B as N,j as u,bs as pt,bF as ft,bt,ba as mt,bu as gt,bp as M,ar as ht}from"./index.7HEH_7fJ.js";import{s as yt}from"./sprintf.D7DtBTRn.js";import{u as It}from"./uniqueId.BdUnRe3-.js";import{u as Tt}from"./FormClearHelper.BkPbs0OF.js";import{I as wt}from"./InputInstructions.CHpHVupe.js";import{I as Ct}from"./input.QeLiGsyn.js";import"./base-input.BBFJwxWO.js";var Q=r.forwardRef(function(t,e){var o={fill:"currentColor",xmlns:"http://www.w3.org/2000/svg"};return r.createElement(X,q({iconAttrs:o,iconVerticalAlign:"middle",iconViewBox:"0 0 8 8"},t,{ref:e}),r.createElement("path",{d:"M0 3v2h8V3H0z"}))});Q.displayName="Minus";var Y=r.forwardRef(function(t,e){var o={fill:"currentColor",xmlns:"http://www.w3.org/2000/svg"};return r.createElement(X,q({iconAttrs:o,iconVerticalAlign:"middle",iconViewBox:"0 0 8 8"},t,{ref:e}),r.createElement("path",{d:"M3 0v3H0v2h3v3h2V5h3V3H5V0H3z"}))});Y.displayName="Plus";const vt=x("div",{target:"e5tuigk0"})(({theme:t})=>({display:"flex",flexDirection:"row",flexWrap:"nowrap",alignItems:"center",height:t.sizes.minElementHeight,borderWidth:t.sizes.borderWidth,borderStyle:"solid",borderColor:t.colors.widgetBorderColor??t.colors.secondaryBg,transitionDuration:"200ms",transitionProperty:"border",transitionTimingFunction:"cubic-bezier(0.2, 0.8, 0.4, 1)",borderRadius:t.radii.default,overflow:"hidden","&.focused":{borderColor:t.colors.primary},input:{MozAppearance:"textfield","&::-webkit-inner-spin-button, &::-webkit-outer-spin-button":{WebkitAppearance:"none",margin:t.spacing.none}}})),St=x("div",{target:"e5tuigk1"})({display:"flex",flexDirection:"row",alignSelf:"stretch"}),G=x("button",{target:"e5tuigk2"})(({theme:t})=>({margin:t.spacing.none,border:"none",height:t.sizes.full,display:"flex",alignItems:"center",width:t.sizes.numberInputControlsWidth,justifyContent:"center",color:t.colors.bodyText,transition:"color 300ms, backgroundColor 300ms",backgroundColor:t.colors.secondaryBg,"&:hover:enabled, &:focus:enabled":{color:t.colors.white,backgroundColor:t.colors.primary,transition:"none",outline:"none"},"&:active":{outline:"none",border:"none"},"&:last-of-type":{borderTopRightRadius:t.radii.default,borderBottomRightRadius:t.radii.default},"&:disabled":{cursor:"not-allowed",color:t.colors.fadedText40}})),Vt=x("div",{target:"e5tuigk3"})(({theme:t,clearable:e})=>({position:"absolute",marginRight:t.spacing.twoXS,left:0,right:`calc(${t.sizes.numberInputControlsWidth} * 2 + ${e?"1em":"0em"})`})),kt=ht.getLogger("NumberInput");function xt(t){return b(t)||t===""?void 0:t}const Rt=t=>(t.element.dataType===I.DataType.INT?t.widgetMgr.getIntValue(t.element):t.widgetMgr.getDoubleValue(t.element))??t.element.default??null,K=({step:t,dataType:e})=>t||(e===I.DataType.INT?1:.01),z=({value:t,format:e,step:o,dataType:f})=>{if(b(t))return null;let n=xt(e);if(b(n)&&J(o)){const d=o.toString();f===I.DataType.FLOAT&&o!==0&&d.includes(".")&&(n=`%0.${d.split(".")[1].length}f`)}if(b(n))return t.toString();try{return yt.sprintf(n,t)}catch(d){return kt.warn(`Error in sprintf(${n}, ${t}): ${d}`),String(t)}},Dt=(t,e,o)=>b(t)?!1:t-e>=o,Et=(t,e,o)=>b(t)?!1:t+e<=o,Ft=({disabled:t,element:e,widgetMgr:o,fragmentId:f})=>{var j;const n=ut(),{dataType:d,id:C,formId:p,default:B,format:W}=e,m=e.hasMin?e.min:-1/0,g=e.hasMax?e.max:1/0,{values:[A],elementRef:Z}=ct(r.useMemo(()=>["width"],[])),[s,tt]=r.useState(K(e)),H=Rt({element:e,widgetMgr:o}),[h,T]=r.useState(!1),[i,w]=r.useState(H),[L,v]=r.useState(z({value:H,...e,step:s})),[P,U]=r.useState(!1),R=r.useRef(null),$=r.useRef(It("number_input_")),S=Dt(i,s,m),V=Et(i,s,g),O=dt({formId:p}),et=O?o.allowFormEnterToSubmit(p):h,rt=P&&A>n.breakpoints.hideWidgetDetails;r.useEffect(()=>{tt(K({step:e.step,dataType:e.dataType}))},[e.dataType,e.step]);const l=r.useCallback(({value:a,source:c})=>{var y;if(J(a)&&(m>a||a>g))(y=R.current)==null||y.reportValidity();else{const k=a??B??null;switch(d){case I.DataType.INT:o.setIntValue({id:C,formId:p},k,c,f);break;case I.DataType.FLOAT:o.setDoubleValue({id:C,formId:p},k,c,f);break;default:throw new Error("Invalid data type")}T(!1),w(k),v(z({value:k,dataType:d,format:W,step:s}))}},[m,g,R,o,f,s,d,C,p,B,W]),ot=r.useCallback(()=>{h&&l({value:i,source:{fromUi:!0}}),U(!1)},[h,i,l]),nt=r.useCallback(()=>{U(!0)},[]),_=r.useCallback(()=>{const{value:a}=e;e.setValue=!1,w(a??null),v(z({value:a??null,...e,step:s})),l({value:a??null,source:{fromUi:!1}})},[e,s,l]);r.useEffect(()=>{e.setValue?_():l({value:i,source:{fromUi:!1}})},[]),e.setValue&&_();const D=b(e.default)&&!t,at=r.useCallback(()=>{const a=e.default??null;w(a),l({value:a,source:{fromUi:!0}})},[e]);Tt({element:e,widgetMgr:o,onFormCleared:at});const st=a=>{const{value:c}=a.target;if(c==="")T(!0),w(null),v(null);else{let y;e.dataType===I.DataType.INT?y=parseInt(c,10):y=parseFloat(c),T(!0),w(y),v(c)}},E=r.useCallback(()=>{V&&(T(!0),l({value:(i??m)+s,source:{fromUi:!0}}))},[i,m,s,V]),F=r.useCallback(()=>{S&&(T(!0),l({value:(i??g)-s,source:{fromUi:!0}}))},[i,g,s,S]),it=r.useCallback(a=>{const{key:c}=a;switch(c){case"ArrowUp":a.preventDefault(),E();break;case"ArrowDown":a.preventDefault(),F();break}},[E,F]),lt=r.useCallback(a=>{a.key==="Enter"&&(h&&l({value:i,source:{fromUi:!0}}),o.allowFormEnterToSubmit(p)&&o.submitForm(p,f))},[h,i,l,o,p,f]);return N("div",{className:"stNumberInput","data-testid":"stNumberInput",ref:Z,children:[u(gt,{label:e.label,disabled:t,labelVisibility:pt((j=e.labelVisibility)==null?void 0:j.value),htmlFor:$.current,children:e.help&&u(ft,{children:u(bt,{content:e.help,placement:mt.TOP_RIGHT})})}),N(vt,{className:P?"focused":"","data-testid":"stNumberInputContainer",children:[u(Ct,{type:"number",inputRef:R,value:L??"",placeholder:e.placeholder,onBlur:ot,onFocus:nt,onChange:st,onKeyPress:lt,onKeyDown:it,clearable:D,clearOnEscape:D,disabled:t,"aria-label":e.label,id:$.current,overrides:{ClearIconContainer:{style:{padding:0}},ClearIcon:{props:{overrides:{Svg:{style:{color:n.colors.darkGray,padding:n.spacing.threeXS,height:n.sizes.clearIconSize,width:n.sizes.clearIconSize,":hover":{fill:n.colors.bodyText}}}}}},Input:{props:{"data-testid":"stNumberInputField",step:s,min:m,max:g,type:"number",inputMode:""},style:{lineHeight:n.lineHeights.inputWidget,paddingRight:n.spacing.sm,paddingLeft:n.spacing.sm,paddingBottom:n.spacing.sm,paddingTop:n.spacing.sm}},InputContainer:{style:()=>({borderTopRightRadius:0,borderBottomRightRadius:0})},Root:{style:{borderTopRightRadius:0,borderBottomRightRadius:0,borderTopLeftRadius:0,borderBottomLeftRadius:0,borderLeftWidth:0,borderRightWidth:0,borderTopWidth:0,borderBottomWidth:0,paddingRight:0}}}}),A>n.breakpoints.hideNumberInputControls&&N(St,{children:[u(G,{"data-testid":"stNumberInputStepDown",onClick:F,disabled:!S||t,tabIndex:-1,children:u(M,{content:Q,size:"xs",color:S?"inherit":n.colors.disabled})}),u(G,{"data-testid":"stNumberInputStepUp",onClick:E,disabled:!V||t,tabIndex:-1,children:u(M,{content:Y,size:"xs",color:V?"inherit":n.colors.disabled})})]})]}),rt&&u(Vt,{clearable:D,children:u(wt,{dirty:h,value:L??"",inForm:O,allowEnterToSubmit:et})})]})},Pt=r.memo(Ft);export{Pt as default};
|
@@ -1 +1 @@
|
|
1
|
-
import{r as l,
|
1
|
+
import{r as l,b5 as i,j as e,b6 as u,bq as d,b4 as B,b7 as c,b8 as b}from"./index.7HEH_7fJ.js";function m(n){const{disabled:s,element:t,widgetMgr:o,fragmentId:r}=n;let a=i.SECONDARY;return t.type==="primary"?a=i.PRIMARY:t.type==="tertiary"&&(a=i.TERTIARY),e(b,{className:"stButton","data-testid":"stButton",children:e(u,{help:t.help,children:e(d,{kind:a,size:B.SMALL,disabled:s,fluidWidth:t.useContainerWidth||!!t.help,onClick:()=>o.setTriggerValue(t,{fromUi:!0},r),children:e(c,{icon:t.icon,label:t.label})})})})}const f=l.memo(m);export{f as default};
|
@@ -0,0 +1 @@
|
|
1
|
+
import{r as M,E as T,_ as O,n as I,ax as K,B as P,j as h,bv as Y,ba as $,bq as Z,b5 as ee,bp as j,bC as z,d as te,g as re,aL as ie,y as ae,bD as ne,bE as oe,bi as se,R as le,ar as de,aA as ce,K as x,bm as ue,bl as pe,bs as fe,bF as he,bt as ge,bu as me,F as ve}from"./index.7HEH_7fJ.js";import{a as V}from"./index.DW_MHI2K.js";import{F as Se}from"./FormClearHelper.BkPbs0OF.js";import{U as L}from"./UploadFileInfo.C-jY39rj.js";import{P as ye,S as be}from"./ProgressBar.CSZV-k_M.js";var N=M.forwardRef(function(t,l){var r={fill:"currentColor",xmlns:"http://www.w3.org/2000/svg"};return M.createElement(T,O({iconAttrs:r,iconVerticalAlign:"middle",iconViewBox:"0 0 8 8"},t,{ref:l}),M.createElement("path",{d:"M.5 1c-.28 0-.5.23-.5.5v4c0 .28.23.5.5.5h5c.28 0 .5-.22.5-.5V4l1 1h1V2H7L6 3V1.5c0-.28-.22-.5-.5-.5h-5z"}))});N.displayName="Video";var D=M.forwardRef(function(t,l){var r={fill:"currentColor",xmlns:"http://www.w3.org/2000/svg"};return M.createElement(T,O({iconAttrs:r,iconVerticalAlign:"middle",iconViewBox:"0 0 8 8"},t,{ref:l}),M.createElement("path",{d:"M1.41 0L0 1.41l.72.72L2.5 3.94.72 5.72 0 6.41l1.41 1.44.72-.72 1.81-1.81 1.78 1.81.69.72 1.44-1.44-.72-.69-1.81-1.78 1.81-1.81.72-.72L6.41 0l-.69.72L3.94 2.5 2.13.72 1.41 0z"}))});D.displayName="X";var H=M.forwardRef(function(t,l){var r={fill:"currentColor",xmlns:"http://www.w3.org/2000/svg"};return M.createElement(T,O({iconAttrs:r,iconVerticalAlign:"middle",iconViewBox:"0 0 24 24"},t,{ref:l}),M.createElement("rect",{width:24,height:24,fill:"none"}),M.createElement("path",{d:"M20 5h-3.17l-1.24-1.35A1.99 1.99 0 0014.12 3H9.88c-.56 0-1.1.24-1.48.65L7.17 5H4c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm-1.35 8.35l-2.79 2.79c-.32.32-.86.1-.86-.35v-1.75H9v1.75c0 .45-.54.67-.85.35l-2.79-2.79c-.2-.2-.2-.51 0-.71l2.79-2.79a.5.5 0 01.85.36v1.83h6v-1.83c0-.45.54-.67.85-.35l2.79 2.79c.2.19.2.51.01.7z"}))});H.displayName="SwitchCamera";var k;(function(t){t.XSMALL="xsmall",t.SMALL="small",t.MEDIUM="medium",t.LARGE="large"})(k||(k={}));function Me(t,l){switch(t){case"xsmall":return{padding:`${l.spacing.twoXS} ${l.spacing.sm}`,fontSize:l.fontSizes.sm};case"small":return{padding:`${l.spacing.twoXS} ${l.spacing.md}`};case"large":return{padding:`${l.spacing.md} ${l.spacing.md}`};default:return{padding:`${l.spacing.xs} ${l.spacing.md}`}}}const G=I("div",{target:"e47j7ja0"})({position:"relative",overflow:"hidden",width:"100%",objectFit:"contain"}),W=I("div",{target:"e47j7ja1"})(({theme:t,width:l})=>({backgroundColor:t.colors.secondaryBg,borderRadius:`${t.radii.default} ${t.radii.default} 0 0`,width:"100%",height:l*9/16,display:"flex",flexDirection:"column",justifyContent:"center",alignItems:"center"})),we=I("p",{target:"e47j7ja2"})(({theme:t})=>({marginTop:t.spacing.sm,textAlign:"center"})),Ce=I("img",{target:"e47j7ja3"})(({theme:t,opacity:l})=>({borderRadius:`${t.radii.default} ${t.radii.default} 0 0`,objectFit:"contain",opacity:l})),Ue=I("a",{target:"e47j7ja4"})(({theme:t})=>({color:t.colors.primary,display:"block",textDecoration:"none"})),Ie=I("span",{target:"e47j7ja5"})({display:"flex",alignItems:"center"}),Ee=I("div",{target:"e47j7ja6"})(({theme:t})=>({position:"absolute",top:t.spacing.lg,right:t.spacing.lg,zIndex:t.zIndices.priority,color:t.colors.fadedText40,mixBlendMode:"difference",opacity:.6})),Fe=I("div",{target:"e47j7ja8"})({height:"fit-content",width:"100%",position:"absolute",bottom:0}),Pe=I("button",{target:"e47j7ja9"})(({theme:t})=>({position:"relative",display:"inline-flex",flexDirection:"column",alignItems:"center",justifyContent:"center",backgroundColor:t.colors.lightenedBg05,border:`${t.sizes.borderWidth} solid ${t.colors.borderColor}`,borderRadius:`0 0 ${t.radii.default} ${t.radii.default}`,"&:hover":{borderColor:t.colors.primary,color:t.colors.primary},"&:active":{color:t.colors.white,borderColor:t.colors.primary,backgroundColor:t.colors.primary},"&:focus:not(:active)":{borderColor:t.colors.primary,color:t.colors.primary},"&:disabled, &:disabled:hover, &:disabled:active":{color:t.colors.fadedText40},fontWeight:t.fontWeights.normal,padding:`${t.spacing.xs} ${t.spacing.md}`,margin:t.spacing.none,lineHeight:t.lineHeights.base,color:"inherit",width:"100%",userSelect:"none","&:focus":{outline:"none"},"&:focus-visible":{boxShadow:`0 0 0 0.2rem ${K(t.colors.primary,.5)}`},...Me("medium",t)}));function q({disabled:t,onClick:l,children:r,progress:n}){return P(Pe,{disabled:t||!1,onClick:l||(()=>{}),progress:n||null,"data-testid":"stCameraInputButton",children:[r,n&&h(Fe,{children:h(ye,{value:n,size:be.EXTRASMALL,overrides:{Bar:{style:{borderTopLeftRadius:0,borderTopRightRadius:0}},BarProgress:{style:{borderTopLeftRadius:0,borderTopRightRadius:0}},BarContainer:{style:{borderTopLeftRadius:0,borderTopRightRadius:0}}}})})]})}var F;(function(t){t.USER="user",t.ENVIRONMENT="environment"})(F||(F={}));const Re=({switchFacingMode:t})=>h(Ee,{"data-testid":"stCameraInputSwitchButton",children:h(Y,{content:"Switch camera",placement:$.TOP_RIGHT,children:h(Z,{kind:ee.MINIMAL,onClick:t,children:h(j,{content:H,size:"twoXL",color:z.white})})})});var _={exports:{}},xe=_.exports,B;function _e(){return B||(B=1,function(t,l){(function(n,a){t.exports=a(te())})(xe,function(r){return function(n){var a={};function o(s){if(a[s])return a[s].exports;var p=a[s]={i:s,l:!1,exports:{}};return n[s].call(p.exports,p,p.exports,o),p.l=!0,p.exports}return o.m=n,o.c=a,o.d=function(s,p,g){o.o(s,p)||Object.defineProperty(s,p,{enumerable:!0,get:g})},o.r=function(s){typeof Symbol<"u"&&Symbol.toStringTag&&Object.defineProperty(s,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(s,"__esModule",{value:!0})},o.t=function(s,p){if(p&1&&(s=o(s)),p&8||p&4&&typeof s=="object"&&s&&s.__esModule)return s;var g=Object.create(null);if(o.r(g),Object.defineProperty(g,"default",{enumerable:!0,value:s}),p&2&&typeof s!="string")for(var U in s)o.d(g,U,(function(C){return s[C]}).bind(null,U));return g},o.n=function(s){var p=s&&s.__esModule?function(){return s.default}:function(){return s};return o.d(p,"a",p),p},o.o=function(s,p){return Object.prototype.hasOwnProperty.call(s,p)},o.p="",o(o.s="./src/react-webcam.tsx")}({"./src/react-webcam.tsx":function(n,a,o){o.r(a);var s=o("react"),p=function(){var m=function(u,e){return m=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(i,d){i.__proto__=d}||function(i,d){for(var c in d)d.hasOwnProperty(c)&&(i[c]=d[c])},m(u,e)};return function(u,e){m(u,e);function i(){this.constructor=u}u.prototype=e===null?Object.create(e):(i.prototype=e.prototype,new i)}}(),g=function(){return g=Object.assign||function(m){for(var u,e=1,i=arguments.length;e<i;e++){u=arguments[e];for(var d in u)Object.prototype.hasOwnProperty.call(u,d)&&(m[d]=u[d])}return m},g.apply(this,arguments)},U=function(m,u){var e={};for(var i in m)Object.prototype.hasOwnProperty.call(m,i)&&u.indexOf(i)<0&&(e[i]=m[i]);if(m!=null&&typeof Object.getOwnPropertySymbols=="function")for(var d=0,i=Object.getOwnPropertySymbols(m);d<i.length;d++)u.indexOf(i[d])<0&&Object.prototype.propertyIsEnumerable.call(m,i[d])&&(e[i[d]]=m[i[d]]);return e};(function(){typeof window>"u"||(navigator.mediaDevices===void 0&&(navigator.mediaDevices={}),navigator.mediaDevices.getUserMedia===void 0&&(navigator.mediaDevices.getUserMedia=function(u){var e=navigator.getUserMedia||navigator.webkitGetUserMedia||navigator.mozGetUserMedia||navigator.msGetUserMedia;return e?new Promise(function(i,d){e.call(navigator,u,i,d)}):Promise.reject(new Error("getUserMedia is not implemented in this browser"))}))})();function C(){return!!(navigator.mediaDevices&&navigator.mediaDevices.getUserMedia)}var E=function(m){p(u,m);function u(e){var i=m.call(this,e)||this;return i.canvas=null,i.ctx=null,i.requestUserMediaId=0,i.unmounted=!1,i.state={hasUserMedia:!1},i}return u.prototype.componentDidMount=function(){var e=this,i=e.state,d=e.props;if(this.unmounted=!1,!C()){d.onUserMediaError("getUserMedia not supported");return}i.hasUserMedia||this.requestUserMedia(),d.children&&typeof d.children!="function"&&console.warn("children must be a function")},u.prototype.componentDidUpdate=function(e){var i=this.props;if(!C()){i.onUserMediaError("getUserMedia not supported");return}var d=JSON.stringify(e.audioConstraints)!==JSON.stringify(i.audioConstraints),c=JSON.stringify(e.videoConstraints)!==JSON.stringify(i.videoConstraints),b=e.minScreenshotWidth!==i.minScreenshotWidth,S=e.minScreenshotHeight!==i.minScreenshotHeight;(c||b||S)&&(this.canvas=null,this.ctx=null),(d||c)&&(this.stopAndCleanup(),this.requestUserMedia())},u.prototype.componentWillUnmount=function(){this.unmounted=!0,this.stopAndCleanup()},u.stopMediaStream=function(e){e&&(e.getVideoTracks&&e.getAudioTracks?(e.getVideoTracks().map(function(i){e.removeTrack(i),i.stop()}),e.getAudioTracks().map(function(i){e.removeTrack(i),i.stop()})):e.stop())},u.prototype.stopAndCleanup=function(){var e=this.state;e.hasUserMedia&&(u.stopMediaStream(this.stream),e.src&&window.URL.revokeObjectURL(e.src))},u.prototype.getScreenshot=function(e){var i=this,d=i.state,c=i.props;if(!d.hasUserMedia)return null;var b=this.getCanvas(e);return b&&b.toDataURL(c.screenshotFormat,c.screenshotQuality)},u.prototype.getCanvas=function(e){var i=this,d=i.state,c=i.props;if(!this.video||!d.hasUserMedia||!this.video.videoHeight)return null;if(!this.ctx){var b=this.video.videoWidth,S=this.video.videoHeight;if(!this.props.forceScreenshotSourceSize){var v=b/S;b=c.minScreenshotWidth||this.video.clientWidth,S=b/v,c.minScreenshotHeight&&S<c.minScreenshotHeight&&(S=c.minScreenshotHeight,b=S*v)}this.canvas=document.createElement("canvas"),this.canvas.width=(e==null?void 0:e.width)||b,this.canvas.height=(e==null?void 0:e.height)||S,this.ctx=this.canvas.getContext("2d")}var w=this,y=w.ctx,f=w.canvas;return y&&f&&(f.width=(e==null?void 0:e.width)||f.width,f.height=(e==null?void 0:e.height)||f.height,c.mirrored&&(y.translate(f.width,0),y.scale(-1,1)),y.imageSmoothingEnabled=c.imageSmoothing,y.drawImage(this.video,0,0,(e==null?void 0:e.width)||f.width,(e==null?void 0:e.height)||f.height),c.mirrored&&(y.scale(-1,1),y.translate(-f.width,0))),f},u.prototype.requestUserMedia=function(){var e=this,i=this.props,d=function(S,v){var w={video:typeof v<"u"?v:!0};i.audio&&(w.audio=typeof S<"u"?S:!0),e.requestUserMediaId++;var y=e.requestUserMediaId;navigator.mediaDevices.getUserMedia(w).then(function(f){e.unmounted||y!==e.requestUserMediaId?u.stopMediaStream(f):e.handleUserMedia(null,f)}).catch(function(f){e.handleUserMedia(f)})};if("mediaDevices"in navigator)d(i.audioConstraints,i.videoConstraints);else{var c=function(S){return{optional:[{sourceId:S}]}},b=function(S){var v=S.deviceId;return typeof v=="string"?v:Array.isArray(v)&&v.length>0?v[0]:typeof v=="object"&&v.ideal?v.ideal:null};MediaStreamTrack.getSources(function(S){var v=null,w=null;S.forEach(function(R){R.kind==="audio"?v=R.id:R.kind==="video"&&(w=R.id)});var y=b(i.audioConstraints);y&&(v=y);var f=b(i.videoConstraints);f&&(w=f),d(c(v),c(w))})}},u.prototype.handleUserMedia=function(e,i){var d=this.props;if(e||!i){this.setState({hasUserMedia:!1}),d.onUserMediaError(e);return}this.stream=i;try{this.video&&(this.video.srcObject=i),this.setState({hasUserMedia:!0})}catch{this.setState({hasUserMedia:!0,src:window.URL.createObjectURL(i)})}d.onUserMedia(i)},u.prototype.render=function(){var e=this,i=this,d=i.state,c=i.props,b=c.audio;c.forceScreenshotSourceSize;var S=c.disablePictureInPicture;c.onUserMedia,c.onUserMediaError,c.screenshotFormat,c.screenshotQuality,c.minScreenshotWidth,c.minScreenshotHeight,c.audioConstraints,c.videoConstraints,c.imageSmoothing;var v=c.mirrored,w=c.style,y=w===void 0?{}:w,f=c.children,R=U(c,["audio","forceScreenshotSourceSize","disablePictureInPicture","onUserMedia","onUserMediaError","screenshotFormat","screenshotQuality","minScreenshotWidth","minScreenshotHeight","audioConstraints","videoConstraints","imageSmoothing","mirrored","style","children"]),X=v?g(g({},y),{transform:(y.transform||"")+" scaleX(-1)"}):y,Q={getScreenshot:this.getScreenshot.bind(this)};return s.createElement(s.Fragment,null,s.createElement("video",g({autoPlay:!0,disablePictureInPicture:S,src:d.src,muted:!b,playsInline:!0,ref:function(J){e.video=J},style:X},R)),f&&f(Q))},u.defaultProps={audio:!1,disablePictureInPicture:!1,forceScreenshotSourceSize:!1,imageSmoothing:!0,mirrored:!1,onUserMedia:function(){},onUserMediaError:function(){},screenshotFormat:"image/webp",screenshotQuality:.92},u}(s.Component);a.default=E},react:function(n,a){n.exports=r}}).default})}(_)),_.exports}var Te=_e();const Oe=re(Te);var A;(function(t){t.PENDING="pending",t.SUCCESS="success",t.ERROR="error"})(A||(A={}));const je=({width:t})=>P(W,{width:t,children:[h(j,{size:"threeXL",color:z.gray60,content:N}),P(we,{children:["This app would like to use your camera.",h(Ue,{href:oe,rel:"noopener noreferrer",target:"_blank",children:"Learn how to allow access."})]})]}),We=({handleCapture:t,width:l,disabled:r,clearPhotoInProgress:n,setClearPhotoInProgress:a,facingMode:o,setFacingMode:s,testOverride:p})=>{const[g,U]=M.useState(p||"pending"),C=M.useRef(null),[E,m]=M.useState(l),u=M.useCallback(ie(1e3,m),[]);M.useEffect(()=>{u(l)},[l,u]);function e(){if(C.current!==null){const d=C.current.getScreenshot();t(d)}}const i=ae();return P(G,{"data-testid":"stCameraInputWebcamComponent",children:[g!=="success"&&!r&&!n?h(je,{width:E}):ne.isMobile&&h(Re,{switchFacingMode:s}),h(W,{"data-testid":"stCameraInputWebcamStyledBox",hidden:g!=="success"&&!r&&!n,width:E,children:!r&&h(Oe,{audio:!1,ref:C,screenshotFormat:"image/jpeg",screenshotQuality:1,width:E,height:E*9/16,style:{borderRadius:`${i.radii.default} ${i.radii.default} 0 0`},onUserMediaError:()=>{U("error")},onUserMedia:()=>{U("success"),a(!1)},videoConstraints:{width:{ideal:E},facingMode:o}})}),h(q,{onClick:e,disabled:g!=="success"||r||n,children:"Take Photo"})]})},Ve=150,Le=de.getLogger("CameraInput");class ke extends le.PureComponent{constructor(l){super(l),this.localFileIdCounter=1,this.RESTORED_FROM_WIDGET_STRING="RESTORED_FROM_WIDGET",this.formClearHelper=new Se,this.getProgress=()=>{if(this.state.files.length>0&&this.state.files[this.state.files.length-1].status.type==="uploading")return this.state.files[this.state.files.length-1].status.progress},this.setClearPhotoInProgress=r=>{this.setState({clearPhotoInProgress:r})},this.setFacingMode=()=>{this.setState(r=>({facingMode:r.facingMode===F.USER?F.ENVIRONMENT:F.USER}))},this.handleCapture=r=>{if(r===null)return Promise.resolve();this.setState({imgSrc:r,shutter:!0,minShutterEffectPassed:!1});const n=a=>new Promise(o=>setTimeout(o,a));return Be(r,`camera-input-${new Date().toISOString().replace(/:/g,"_")}.jpg`).then(a=>this.props.uploadClient.fetchFileURLs([a]).then(o=>({file:a,fileUrls:o[0]}))).then(({file:a,fileUrls:o})=>this.uploadFile(o,a)).then(()=>n(Ve)).then(()=>{this.setState((a,o)=>({imgSrc:r,shutter:a.shutter,minShutterEffectPassed:!0}))}).catch(a=>{Le.error(a)})},this.removeCapture=()=>{this.state.files.length!==0&&(this.state.files.forEach(r=>this.deleteFile(r.id)),this.setState({imgSrc:null,clearPhotoInProgress:!0}))},this.componentDidUpdate=()=>{if(this.status!=="ready")return;const r=this.createWidgetValue(),{element:n,widgetMgr:a,fragmentId:o}=this.props,s=a.getFileUploaderStateValue(n);ce(r,s)||a.setFileUploaderStateValue(n,r,{fromUi:!0},o)},this.onFormCleared=()=>{this.setState({files:[]},()=>{const r=this.createWidgetValue();if(x(r))return;this.setState({imgSrc:null});const{widgetMgr:n,element:a,fragmentId:o}=this.props;n.setFileUploaderStateValue(a,r,{fromUi:!0},o)})},this.deleteFile=r=>{const n=this.getFile(r);x(n)||(n.status.type==="uploading"&&n.status.cancelToken.cancel(),n.status.type==="uploaded"&&n.status.fileUrls.deleteUrl&&this.props.uploadClient.deleteFile(n.status.fileUrls.deleteUrl),this.removeFile(r))},this.addFile=r=>{this.setState(n=>({files:[...n.files,r]}))},this.removeFile=r=>{this.setState(n=>({files:n.files.filter(a=>a.id!==r)}))},this.getFile=r=>this.state.files.find(n=>n.id===r),this.updateFile=(r,n)=>{this.setState(a=>({files:a.files.map(o=>o.id===r?n:o)}))},this.onUploadComplete=(r,n)=>{this.setState(()=>({shutter:!1}));const a=this.getFile(r);x(a)||a.status.type!=="uploading"||this.updateFile(a.id,a.setStatus({type:"uploaded",fileId:n.fileId,fileUrls:n}))},this.onUploadProgress=(r,n)=>{const a=this.getFile(n);if(x(a)||a.status.type!=="uploading")return;const o=Math.round(r.loaded*100/r.total);a.status.progress!==o&&this.updateFile(n,a.setStatus({type:"uploading",cancelToken:a.status.cancelToken,progress:o}))},this.reset=()=>{this.setState({files:[],imgSrc:null})},this.uploadFile=(r,n)=>{const a=V.CancelToken.source(),o=new L(n.name,n.size,this.nextLocalFileId(),{type:"uploading",cancelToken:a,progress:1});this.addFile(o),this.props.uploadClient.uploadFile(this.props.element,r.uploadUrl,n,s=>this.onUploadProgress(s,o.id),a.token).then(()=>this.onUploadComplete(o.id,r)).catch(s=>{V.isCancel(s)||this.updateFile(o.id,o.setStatus({type:"error",errorMessage:s?s.toString():"Unknown error"}))})},this.state=this.initialValue}get initialValue(){const l={files:[],imgSrc:null,shutter:!1,minShutterEffectPassed:!0,clearPhotoInProgress:!1,facingMode:F.USER},{widgetMgr:r,element:n}=this.props,a=r.getFileUploaderStateValue(n);if(x(a))return l;const{uploadedFileInfo:o}=a;return x(o)||o.length===0?l:{files:o.map(s=>{const p=s.name,g=s.size,U=s.fileId,C=s.fileUrls;return new L(p,g,this.nextLocalFileId(),{type:"uploaded",fileId:U,fileUrls:C})}),imgSrc:o.length===0?"":this.RESTORED_FROM_WIDGET_STRING,shutter:!1,minShutterEffectPassed:!1,clearPhotoInProgress:!1,facingMode:F.USER}}componentWillUnmount(){this.formClearHelper.disconnect()}get status(){const l=r=>r.status.type==="uploading";return this.state.files.some(l)?"updating":"ready"}componentDidMount(){const l=this.createWidgetValue(),{element:r,widgetMgr:n,fragmentId:a}=this.props;n.getFileUploaderStateValue(r)===void 0&&n.setFileUploaderStateValue(r,l,{fromUi:!1},a)}createWidgetValue(){const l=this.state.files.filter(r=>r.status.type==="uploaded").map(r=>{const{name:n,size:a,status:o}=r;return new ue({fileId:o.fileId,fileUrls:o.fileUrls,name:n,size:a})});return new pe({uploadedFileInfo:l})}render(){var o;const{element:l,widgetMgr:r,disabled:n,width:a}=this.props;return this.formClearHelper.manageFormClearListener(r,l.formId,this.onFormCleared),P(G,{className:"stCameraInput","data-testid":"stCameraInput",children:[h(me,{label:l.label,disabled:n,labelVisibility:fe((o=l.labelVisibility)==null?void 0:o.value),children:l.help&&h(he,{children:h(ge,{content:l.help,placement:$.TOP_RIGHT})})}),this.state.imgSrc?P(ve,{children:[h(W,{width:a,children:this.state.imgSrc!==this.RESTORED_FROM_WIDGET_STRING&&h(Ce,{src:this.state.imgSrc,alt:"Snapshot",opacity:this.state.shutter||!this.state.minShutterEffectPassed?"50%":"100%",width:a,height:a*9/16})}),h(q,{onClick:this.removeCapture,progress:this.getProgress(),disabled:!!this.getProgress()||n,children:this.getProgress()?"Uploading...":P(Ie,{children:[h(j,{content:D,margin:"0 xs 0 0",size:"sm"})," Clear photo"]})})]}):h(We,{handleCapture:this.handleCapture,width:a,disabled:n,clearPhotoInProgress:this.state.clearPhotoInProgress,setClearPhotoInProgress:this.setClearPhotoInProgress,facingMode:this.state.facingMode,setFacingMode:this.setFacingMode,testOverride:this.props.testOverride})]})}nextLocalFileId(){return this.localFileIdCounter++}}function Be(t,l){return fetch(t).then(r=>r.arrayBuffer()).then(r=>new File([r],l,{type:"image/jpeg"}))}const He=se(ke);export{He as default};
|