1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[9139],{49139:function(e,t,a){a.r(t),a.d(t,{AudioRangeSelection:function(){return b}});var l=a(52322),r=a(2784),A=a(15644),i=a(16442),o=a(58845),n=a(35078),u=a(35954),d=a(21353),c=a(75590),s=a(18997),m=a(19994),f=a(83096),v=a(30118),w=a(51401),h=a(80920),D=a(65089),g=a(94133),x=a(38986),N=a(92428),y=a(10424),R=a(64281),S=a(19458),p=a(47182);let _=e=>e&&(0!==e.startRatio||1!==e.endRatio);function b(){var e,t;let{isAudioTrimming:a,setAudioTrimming:r}=(0,v._i)(),i=(0,h.Q5)(),o=(0,h.e1)(),n="".concat(null!=i?i:"default",":").concat(null!==(e=null==o?void 0:o.audioResourceId)&&void 0!==e?e:"no-resource",":").concat(null!==(t=null==o?void 0:o.audioFileName)&&void 0!==t?t:"no-audio");return(0,l.jsxs)(A.Q,{open:a,onClose:()=>r(!1),className:"sm:max-w-3xl my-16 sm:my-16",children:[(0,l.jsx)(c.Vq.Title,{as:"h3",className:"text-base font-semibold leading-6 text-gray-900",children:"Select a range for your sound wave"}),(0,l.jsx)("div",{className:"flex flex-col items-center justify-center w-full mt-4",children:(0,l.jsx)(I,{},n)})]})}let I=()=>{var e,t,a,A,c,b;let{audioElement:I}=(0,f.FI)(),k=(0,r.useRef)(null),T=(0,r.useRef)(null),U=(0,r.useRef)(null),[j,M]=(0,r.useState)(!1),[F,O]=(0,r.useState)(!1),[C,E]=(0,r.useState)(null),{updateEditorState:V,setAudioTrimming:W,isAudioTrimming:z,waveformConfig:L,selectedSource:q}=(0,v._i)(),{updateWaveform:Z}=(0,w.O)(),G=(0,h.Q5)(),Q=(0,h.e1)(),{getAudioBlob:X,setAudioBlob:H}=(0,D.o0)(),K=null!==(t=null==Q?void 0:Q.trim)&&void 0!==t?t:L.trim,P=(null==Q?void 0:Q.audioResourceId)||(G?"".concat(x.AUDIO_ORIGINAL_FILE_ID,"_").concat(G):x.AUDIO_ORIGINAL_FILE_ID),B=null!==(A=null!==(a=null==Q?void 0:Q.selectedSource)&&void 0!==a?a:q)&&void 0!==A?A:S.SourceType.AUDIO,Y=null!==(c=null==K?void 0:K.startRatio)&&void 0!==c?c:0,J=null!==(b=null==K?void 0:K.endRatio)&&void 0!==b?b:1,$=(0,D.Wf)(P),ee=B===S.SourceType.AUDIO&&(null==$?void 0:$.publicURL)||null,et=!!(ee&&(null==I?void 0:I.src)===ee),ea=(0,r.useMemo)(()=>{var e,t;return B===S.SourceType.AUDIO?C&&C.length>0?C:_(K)?[]:null!==(e=null==Q?void 0:Q.waveformData)&&void 0!==e?e:[]:null!==(t=null==Q?void 0:Q.waveformData)&&void 0!==t?t:[]},[null==Q?void 0:Q.waveformData,C,B,K]),el=(0,r.useMemo)(()=>ea.map(e=>(512-e)/512),[ea]),er=B===S.SourceType.STOCK?null===(e=(0,p.QP)(P.replace(/^stock_/,"")))||void 0===e?void 0:e.durationSec:void 0,eA=et&&Number.isFinite(null==I?void 0:I.duration)?null==I?void 0:I.duration:null!=er?er:100,ei=el.length>0,eo=(0,r.useCallback)(async()=>{let e=X(P);if(e)return e;if(!ee)return null;try{let e=await fetch(ee),t=await e.blob();return H(P,t),t}catch(e){return(0,s.H)(e,{extra:{audioResourceId:P,fetchUrl:ee}}),null}},[P,ee,X,H]);(0,r.useEffect)(()=>{U.current=null,T.current=null,M(!1),E(null)},[P,z,B]),(0,r.useEffect)(()=>{let e=!1;return(async()=>{if(!z||B!==S.SourceType.AUDIO){E(null);return}let t=await eo();if(t&&!e)try{let a=await (0,R.Q_)(t);!e&&a.length>0&&E(a)}catch(e){(0,s.H)(e,{extra:{action:"load_full_waveform_for_trim_modal",audioResourceId:P}})}})(),()=>{e=!0}},[z,B,P,eo]);let en=B===S.SourceType.AUDIO,eu=(0,r.useCallback)(async()=>{var e,t,a,l,r,A;let i=T.current,o=null!==(e=U.current)&&void 0!==e?e:eA;if(!i||!o)return;let n=Number.isNaN(i.start/o)?0:i.start/o,u=Number.isNaN(i.end/o)?1:i.end/o;if(en){let e=await eo();if(e){O(!0);try{let r=await (0,R.S$)(e,n,u);if(r.length>0){let e=(0,N.computeShownWaveformData)({waveformData:r,waveformConfig:L,trim:{startRatio:0,endRatio:1},width:L.reference.width,audioFileName:null!==(t=null==Q?void 0:Q.audioFileName)&&void 0!==t?t:"",source:null!==(l=null!==(a=null==Q?void 0:Q.selectedSource)&&void 0!==a?a:q)&&void 0!==l?l:S.SourceType.AUDIO});G?Z(G,{trim:{startRatio:n,endRatio:u},waveformData:r,shownWaveformData:e}):V({waveformData:r,shownWaveformData:e},!1)}}catch(e){(0,s.H)(e,{extra:{startRatio:n,endRatio:u}})}finally{O(!1)}}}else if(G){if(Q&&(0,y.hasWorkableWaveformData)(Q.waveformData)){let e=(0,N.computeShownWaveformData)({waveformData:Q.waveformData,waveformConfig:L,trim:{startRatio:n,endRatio:u},width:L.reference.width,audioFileName:null!==(r=Q.audioFileName)&&void 0!==r?r:"",source:null!==(A=Q.selectedSource)&&void 0!==A?A:B});Z(G,{trim:{startRatio:n,endRatio:u},shownWaveformData:e})}else Z(G,{trim:{startRatio:n,endRatio:u}})}W(!1),(0,s.Kz)("audio_trim_confirmed")},[en,eo,eA,q,B,Q,G,W,V,Z,L]),ed=(0,r.useCallback)(async()=>{var e,t,a,l,r;if(_(K)&&en){let l=await eo();if(l){O(!0);try{let r=await (0,R.Q_)(l);if(r.length>0){let l=(0,N.computeShownWaveformData)({waveformData:r,waveformConfig:L,trim:{startRatio:0,endRatio:1},width:L.reference.width,audioFileName:null!==(e=null==Q?void 0:Q.audioFileName)&&void 0!==e?e:"",source:null!==(a=null!==(t=null==Q?void 0:Q.selectedSource)&&void 0!==t?t:q)&&void 0!==a?a:S.SourceType.AUDIO});G?Z(G,{trim:{startRatio:0,endRatio:1},waveformData:r,shownWaveformData:l}):V({waveformData:r,shownWaveformData:l},!1)}}catch(e){(0,s.H)(e,{extra:{action:"resetTrim"}})}finally{O(!1)}}}else G&&(Q&&(0,y.hasWorkableWaveformData)(Q.waveformData)?Z(G,{trim:{startRatio:0,endRatio:1},shownWaveformData:(0,N.computeShownWaveformData)({waveformData:Q.waveformData,waveformConfig:L,trim:{startRatio:0,endRatio:1},width:L.reference.width,audioFileName:null!==(l=Q.audioFileName)&&void 0!==l?l:"",source:null!==(r=Q.selectedSource)&&void 0!==r?r:B})}):Z(G,{trim:{startRatio:0,endRatio:1}}));W(!1),(0,s.Kz)("audio_trim_reset")},[en,eo,q,B,Q,G,W,K,V,Z,L]);return(0,r.useEffect)(()=>
1{if(!z||!k.current||!ei)return;T.current=null,U.current=null,M(!1);let e=i.Z.create({container:k.current,url:ee||"data:audio/mp3;base64,SUQzBAAAAAAAI1RTU0UAAAAPAAADTGF2ZjU2LjM2LjEwMAAAAAAAAAAAAAAA//OEAAAAAAAAAAAAAAAAAAAAAAAASW5mbwAAAA8AAAAEAAABIADAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDV1dXV1dXV1dXV1dXV1dXV1dXV1dXV1dXV6urq6urq6urq6urq6urq6urq6urq6urq6v////////////////////////////////8AAAAATGF2YzU2LjQxAAAAAAAAAAAAAAAAJAAAAAAAAAAAASDs90hvAAAAAAAAAAAAAAAAAAAA//MUZAAAAAGkAAAAAAAAA0gAAAAATEFN//MUZAMAAAGkAAAAAAAAA0gAAAAARTMu//MUZAYAAAGkAAAAAAAAA0gAAAAAOTku//MUZAkAAAGkAAAAAAAAA0gAAAAANVVV",peaks:[el],duration:eA,normalize:!0,interact:!1,cursorWidth:0,waveColor:"#9333ea",progressColor:"rgb(100, 0, 100)",height:200});e.registerPlugin(n.Z.create({height:20,formatTimeCallback:u.c}));let t=e.registerPlugin(o.Z.create());return e.on("ready",()=>{let a=e.getDuration();U.current=a;let l=t.addRegion({start:Y*a,end:J*a,color:"#60a5fa55",resize:!0,minLength:.5});T.current=l,M(!0)}),()=>{T.current=null,U.current=null,M(!1);try{e.destroy()}catch(e){(0,s.H)("Error destroying wavesurfer",{extra:{error:e}})}}},[k,z,ei,ee,el,eA,J,Y]),(0,r.useEffect)(()=>{(0,s.Kz)("audio_trim_opened")},[]),(0,l.jsxs)(l.Fragment,{children:[(0,l.jsxs)("div",{className:"relative w-full",children:[(0,l.jsx)("div",{ref:k,className:"h-full w-full min-h-[200px]"}),(!ei||!j)&&(0,l.jsxs)("div",{className:"absolute inset-0 flex items-center justify-center text-lg",children:[(0,l.jsx)(g.p,{className:"mr-2",fontSize:32}),ei?"Loading waveform...":"Loading..."]})]}),(0,l.jsxs)("div",{className:"mt-4 flex gap-x-2",children:[(0,l.jsx)(d.z,{theme:"light",onClick:()=>W(!1),disabled:F,children:"Cancel"}),(0,l.jsx)(d.z,{theme:"info",onClick:ed,icon:m.oAZ,disabled:F,children:"Reset"}),(0,l.jsx)(d.z,{theme:"primary",onClick:eu,icon:m.tDd,disabled:F||!j,loading:F,children:F?"Trimming":"Trim"})]})]})}}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.