1import{o as e,c as t,b as a,f as r,h as l,t as n,e as o,l as s,D as i,x as d,y as u,F as c,r as m,Z as g,u as p,z as b,W as f,q as y,S as x,G as v,p as h,H as k,v as w,a1 as $,d as M,m as F}from"./CvqryXYF.js";import{createFfmpegInstance as A,loadFfmpegModules as C}from"./CNq4npPL.js";import"./DINTXmbT.js";const E={class:"w-full"},S=["aria-label"],R={class:"text-xl font-semibold text-gray-900 dark:text-white mb-2"},L={class:"text-gray-700 dark:text-gray-300 mb-4"},P={class:"px-6 py-3 bg-blue-700 hover:bg-blue-600 text-white font-medium rounded-lg transition-colors inline-block"},T={key:0,class:"text-sm text-blue-700 dark:text-blue-400 mt-4 flex items-center justify-center gap-1"},U={class:"text-sm text-gray-700 dark:text-gray-300 mt-2 flex items-center justify-center gap-1"},j=["accept","aria-label"],z={__name:"AudioFadeEditorUploader",props:{accept:{type:String,default:"audio/*,.mp3,.wav,.aac,.ogg,.flac,.m4a,.wma,.opus"},itemCount:{type:Number,default:0}},emits:["select"],setup(c,{expose:m,emit:g}){const p=g,b=u(null),f=u(!1),y=()=>{b.value&&b.value.click()},x=e=>{const t=Array.from(e.target.files||[]);t.length>0&&p("select",t),e.target.value=""},v=()=>{f.value=!0},h=()=>{f.value=!0},k=()=>{f.value=!1},w=e=>{f.value=!1;const t=Array.from(e.dataTransfer?.files||[]).filter(e=>!!e.type.startsWith("audio/")||/\.(mp3|wav|aac|ogg|flac|m4a|wma|opus|amr|aiff)$/i.test(e.name));t.length>0&&p("select",t)};return m({click:()=>y()}),(u,m)=>{const g=l;return e(),t("div",E,[a("button",{type:"button",class:d(["border-2 border-dashed border-gray-300 dark:border-gray-600 rounded-xl p-8 md:p-12 text-center hover:border-blue-500 dark:hover:border-blue-400 transition-colors w-full bg-white dark:bg-gray-800",{"border-blue-500 bg-blue-50 dark:bg-blue-900/20":f.value}]),"aria-label":u.$t("Add Audio Files"),onClick:y,onDragenter:i(v,["prevent"]),onDragover:i(h,["prevent"]),onDragleave:i(k,["prevent"]),onDrop:i(w,["prevent"])},[r(g,{name:"material-symbols:upload-file",class:"w-16 h-16 mx-auto text-blue-700 dark:text-blue-400 mb-4","aria-hidden":"true"}),a("h2",R,n(c.itemCount>0?u.$t("Add more audio files"):u.$t("Drop audio files here or click to browse")),1),a("p",L,n(u.$t("Supports MP3, WAV, AAC, OGG, FLAC, M4A, WMA, Opus and more")),1),a("span",P,n(u.$t("Add Audio Files")),1),c.itemCount>0?(e(),t("p",T,[r(g,{name:"material-symbols:playlist-add-check",class:"w-4 h-4","aria-hidden":"true"}),o(" "+n(c.itemCount)+" "+n(u.$t("files")),1)])):s("",!0),a("p",U,[r(g,{name:"material-symbols:lock-outline",class:"w-4 h-4","aria-hidden":"true"}),o(" "+n(u.$t("Browser-based Audio Processing")),1)])],42,S),a("input",{ref_key:"fileInputRef",ref:b,type:"file",class:"sr-only",accept:c.accept,multiple:"","aria-label":u.$t("Select audio files"),onChange:x},null,40,j)])}}},N={class:"flex items-center gap-3 mb-3"},_={class:"w-9 h-9 rounded-lg bg-blue-100 dark:bg-blue-900/30 flex items-center justify-center shrink-0"},O={class:"flex-1 min-w-0"},I=["title"],D={class:"text-xs text-gray-700 dark:text-gray-300 mt-0.5 flex items-center gap-2 flex-wrap"},V={class:"font-mono tabular-nums"},B={class:"font-mono tabular-nums"},q={key:0,class:"px-1.5 py-0.5 text-xs bg-green-100 dark:bg-green-900/30 text-green-700 dark:text-green-400 rounded font-mono uppercase"},H={class:"flex items-center gap-1 shrink-0"},K=["aria-label","title"],G=["aria-label","title"],W=["aria-label","title"],X={class:"relative h-16 bg-gray-50 dark:bg-gray-900 rounded-lg overflow-hidden border border-gray-200 dark:border-gray-700"},Z={key:0,class:"absolute inset-0 flex items-center justify-center"},Y={key:1,class:"absolute inset-0 flex items-center gap-px px-1"},J={key:2,class:"absolute inset-0 flex items-center justify-center text-xs text-gray-400 dark:text-gray-500"},Q={key:3,class:"absolute inset-0 bg-white/70 dark:bg-gray-900/70 flex items-center justify-center"},ee={class:"flex items-center gap-2 text-xs text-blue-700 dark:text-blue-400 font-medium"},te={key:0,class:"mt-3"},ae=["src","aria-label"],re={class:"text-xs text-gray-700 dark:text-gray-300 mt-1.5 flex items-center gap-2 flex-wrap"},le={class:"inline-flex items-center gap-1"},ne={class:"font-mono tabular-nums"},oe={key:1,class:"mt-3 text-xs text-red-700 dark:text-red-400 flex items-center gap-1.5"},se={__name:"AudioFadeEditorListItem",props:{item:{type:Object,required:!0},formatFileSize:{type:Function,required:!0},formatTimeShort:{type:Function,required:!0}},emits:["remove","download","re-process"],setup:i=>(u,p)=>{const b=l;return e(),t("div",{class:d(["bg-white dark:bg-gray-800 border border-gray-200 dark:border-gray-700 rounded-xl p-3 transition-colors",{"border-blue-700 dark:border-blue-400":i.item.processing,"border-red-300 dark:border-red-700":i.item.error}])},[a("div",N,[a("div",_,[r(b,{name:"material-symbols:music-note-rounded",class:"w-5 h-5 text-blue-700 dark:text-blue-400","aria-hidden":"true"})]),a("div",O,[a("p",{class:"text-sm font-medium text-gray-900 dark:text-white truncate",title:i.item.name},n(i.item.name),9,I),a("p",D,[a("span",V,n(i.formatFileSize(i.item.size)),1),p[3]||(p[3]=a("span",{class:"text-gray-400 dark:text-gray-500","aria-hidden":"true"},"·",-1)),a("span",B,n(i.formatTimeShort(i.item.duration)),1),i.item.resultExt?(e(),t("span",q,n(i.item.resultExt),1)):s("",!0)])]),a("div",H,[i.item.resultUrl&&!i.item.processing?(e(),t("button",{key:0,t
1ype:"button",class:"p-1.5 text-gray-700 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-700 rounded-lg transition-colors","aria-label":u.$t("Re-process"),title:u.$t("Re-process"),onClick:p[0]||(p[0]=e=>u.$emit("re-process",i.item.id))},[r(b,{name:"material-symbols:refresh-rounded",class:"w-4 h-4","aria-hidden":"true"})],8,K)):s("",!0),i.item.resultUrl?(e(),t("button",{key:1,type:"button",class:"p-1.5 text-blue-700 dark:text-blue-400 hover:bg-blue-50 dark:hover:bg-blue-900/20 rounded-lg transition-colors","aria-label":u.$t("Download"),title:u.$t("Download"),onClick:p[1]||(p[1]=e=>u.$emit("download",i.item.id))},[r(b,{name:"material-symbols:download-rounded",class:"w-4 h-4","aria-hidden":"true"})],8,G)):s("",!0),i.item.processing?s("",!0):(e(),t("button",{key:2,type:"button",class:"p-1.5 text-red-700 dark:text-red-400 hover:bg-red-50 dark:hover:bg-red-900/20 rounded-lg transition-colors","aria-label":u.$t("Remove"),title:u.$t("Remove"),onClick:p[2]||(p[2]=e=>u.$emit("remove",i.item.id))},[r(b,{name:"material-symbols:close-rounded",class:"w-4 h-4","aria-hidden":"true"})],8,W))])]),a("div",X,[i.item.loading?(e(),t("div",Z,[r(b,{name:"material-symbols:progress-activity",class:"w-5 h-5 text-gray-400 dark:text-gray-500 animate-spin","aria-hidden":"true"})])):i.item.peaks&&i.item.peaks.length>0?(e(),t("div",Y,[(e(!0),t(c,null,m(i.item.peaks,(a,r)=>(e(),t("div",{key:r,class:"flex-1 bg-blue-700 dark:bg-blue-400 rounded-sm",style:g({height:`${Math.max(2,100*a)}%`}),"aria-hidden":"true"},null,4))),128))])):(e(),t("div",J,n(u.$t("No waveform preview")),1)),i.item.processing?(e(),t("div",Q,[a("div",ee,[r(b,{name:"material-symbols:progress-activity",class:"w-4 h-4 animate-spin","aria-hidden":"true"}),o(" "+n(Math.round(100*(i.item.progress||0)))+"% ",1)])])):s("",!0)]),i.item.resultUrl?(e(),t("div",te,[(e(),t("audio",{key:i.item.resultUrl,src:i.item.resultUrl,controls:"",class:"w-full h-9","aria-label":u.$t("Faded audio preview")},null,8,ae)),a("p",re,[a("span",le,[r(b,{name:"material-symbols:check-circle-outline",class:"w-3.5 h-3.5 text-green-700 dark:text-green-400","aria-hidden":"true"}),o(" "+n(u.$t("Faded")),1)]),p[4]||(p[4]=a("span",{class:"text-gray-400 dark:text-gray-500","aria-hidden":"true"},"·",-1)),a("span",ne,n(i.formatFileSize(i.item.resultSize)),1)])])):s("",!0),i.item.error?(e(),t("p",oe,[r(b,{name:"material-symbols:error-outline-rounded",class:"w-4 h-4 shrink-0","aria-hidden":"true"}),o(" "+n(i.item.error),1)])):s("",!0)],2)}},ie={class:"bg-white dark:bg-gray-800 border border-gray-200 dark:border-gray-700 rounded-xl p-4 space-y-3"},de={key:0},ue={class:"flex items-center justify-between mb-2"},ce={class:"text-sm font-medium text-gray-900 dark:text-white flex items-center gap-2"},me={class:"text-xs text-gray-700 dark:text-gray-300 font-mono tabular-nums"},ge={class:"w-full h-2 bg-gray-200 dark:bg-gray-700 rounded-full overflow-hidden"},pe={class:"text-xs text-gray-700 dark:text-gray-300 mt-1.5"},be={key:1},fe={class:"flex items-center justify-between mb-2"},ye={class:"text-sm font-medium text-gray-900 dark:text-white flex items-center gap-2"},xe={class:"text-xs text-gray-700 dark:text-gray-300 font-mono tabular-nums"},ve={class:"w-full h-2 bg-gray-200 dark:bg-gray-700 rounded-full overflow-hidden"},he={key:2,class:"bg-red-50 dark:bg-red-900/20 border border-red-300 dark:border-red-700 rounded-lg p-3",role:"alert"},ke={class:"text-sm text-red-700 dark:text-red-400 flex items-start gap-2"},we={key:3,class:"text-xs"},$e={class:"cursor-pointer text-gray-700 dark:text-gray-300 hover:text-gray-900 dark:hover:text-white select-none"},Me={class:"mt-2 p-2 bg-gray-50 dark:bg-gray-900 border border-gray-200 dark:border-gray-700 rounded-lg text-xs text-gray-700 dark:text-gray-300 max-h-48 overflow-auto whitespace-pre-wrap font-mono"},Fe={__name:"AudioFadeEditorProcessingPanel",props:{ffmpegLoading:{type:Boolean,default:!1},ffmpegReady:{type:Boolean,default:!1},ffmpegPercent:{type:Number,default:0},ffmpegStage:{type:String,default:""},isProcessing:{type:Boolean,default:!1},processingPercent:{type:Number,default:0},ffmpegLog:{type:String,default:""},errorMessage:{type:String,default:""}},setup(i){const d=i,{t:u}=p(),c={starting:"Starting engine...","loading-modules":"Loading core modules...","verifying-cdn":"Verifying content delivery network...","downloading-wasm":"Downloading audio engine...","downloading-worker":"Preparing worker...","initializing-engine":"Initializing engine...",ready:"Engine ready"},m=b(()=>{if(!d.ffmpegStage)return u("Loading Engine");const e=c[d.ffmpegStage];return u(e||"Loading Engine")});return(d,u)=>{const c=l;return e(),t("div",ie,[i.ffmpegLoading&&!i.ffmpegReady?(e(),t("div",de,[a("div",ue,[a("p",ce,[r(c,{name:"material-symbols:cloud-download-outline",class:"w-4 h-4 text-blue-700 dark:text-blue-400","aria-hidden":"true"}),o(" "+n(d.$t("Loading Engine")),1)]),a("span",me,n(i.ffmpegPercent)+"% ",1)]),a("div",ge,[a("div",{class:"h-full bg-blue-700 dark:bg-blue-400 transition-all duration-200",style:g({width:`${i.ffmpegPercent}%`})},null,4)]),a("p",pe,n(m.value),1)])):s("",!0),i.isProcessing&&i.ffmpegReady?(e(),t("div",be,[a("div",fe,[a("p",ye,[r(c,{name:"material-symbols:graphic-eq-rounded",class:"w-4 h-4 text-blue-700 dark:text-blue-400 animate-pulse","aria-hidden":"true"}
1),o(" "+n(d.$t("Applying Fades...")),1)]),a("span",xe,n(i.processingPercent)+"% ",1)]),a("div",ve,[a("div",{class:"h-full bg-blue-700 dark:bg-blue-400 transition-all duration-200",style:g({width:`${i.processingPercent}%`})},null,4)])])):s("",!0),i.errorMessage?(e(),t("div",he,[a("p",ke,[r(c,{name:"material-symbols:error-outline-rounded",class:"w-4 h-4 shrink-0 mt-0.5","aria-hidden":"true"}),a("span",null,n(i.errorMessage),1)])])):s("",!0),i.ffmpegLog?(e(),t("details",we,[a("summary",$e,n(d.$t("Processing Log")),1),a("pre",Me,n(i.ffmpegLog),1)])):s("",!0)])}}},Ae={mp3:{ext:"mp3",mimeType:"audio/mpeg",label:"MP3",acodec:"libmp3lame",extraArgs:["-write_xing","0"]},wav:{ext:"wav",mimeType:"audio/wav",label:"WAV",acodec:"pcm_s16le",extraArgs:[]},aac:{ext:"aac",mimeType:"audio/aac",label:"AAC",acodec:"aac",extraArgs:["-strict","experimental"]},ogg:{ext:"ogg",mimeType:"audio/ogg",label:"OGG",acodec:"libvorbis",extraArgs:[]}},Ce=[{label:"Original",value:0},{label:"48000 Hz",value:48e3},{label:"44100 Hz",value:44100},{label:"32000 Hz",value:32e3},{label:"22050 Hz",value:22050},{label:"16000 Hz",value:16e3},{label:"11025 Hz",value:11025},{label:"8000 Hz",value:8e3}],Ee=[{label:"Auto",value:0},{label:"320 kbps",value:320},{label:"256 kbps",value:256},{label:"192 kbps",value:192},{label:"160 kbps",value:160},{label:"128 kbps",value:128},{label:"96 kbps",value:96},{label:"64 kbps",value:64}],Se=[{value:"linear",label:"Linear",ffmpegCurve:"tri",description:"Even, predictable ramp suitable for general-purpose fades"},{value:"exponential",label:"Exponential",ffmpegCurve:"exp",description:"Natural-sounding fade with smoother low-volume transition"},{value:"logarithmic",label:"Logarithmic",ffmpegCurve:"log",description:"Steep start with gentle tail for quick fade-ins"},{value:"sine",label:"Sine",ffmpegCurve:"sin",description:"Smooth sinusoidal curve for musical transitions"},{value:"scurve",label:"S-curve",ffmpegCurve:"qsin",description:"S-shape with steep mid-section for seamless crossfades"}],Re=e=>{const t=Se.find(t=>t.value===e);return t?t.ffmpegCurve:"tri"};let Le=null,Pe=null,Te=null;const Ue=async(e,t,a)=>{if(!Le)throw new Error("ffmpeg instance not loaded");const r=await a(e);return await Le.writeFile(t,r),r},je=async e=>{if(Le)try{await Le.deleteFile(e)}catch{}},ze=e=>`afe_${Date.now()}_${Math.random().toString(36).slice(2,8)}.${e}`,Ne=async e=>{const{outputName:t}=e;if(!Le)throw new Error("ffmpeg instance not loaded");await je(t);const a=(e=>{const{inputName:t,outputName:a,fades:r=[],format:l="mp3",bitrate:n=0,sampleRate:o=0,volume:s=100}=e,i=Ae[l]||Ae.mp3,d=[];d.push("-i",t),d.push("-vn"),d.push("-c:a",i.acodec),n>0&&"wav"!==l&&d.push("-b:a",`${n}k`),o>0&&d.push("-ar",String(o));const u=[];if(100!==s){const e=(s/100).toFixed(2);u.push(`volume=${e}`)}const c=[...r].sort((e,t)=>e.start-t.start);for(const m of c){if(!m.duration||m.duration<=0)continue;const e=Re(m.curve),t=Math.max(0,m.start).toFixed(3),a=m.duration.toFixed(3),r="out"===m.type?"out":"in";u.push(`afade=t=${r}:st=${t}:d=${a}:curve=${e}`)}return u.length>0&&d.push("-af",u.join(",")),i.extraArgs&&i.extraArgs.length>0&&d.push(...i.extraArgs),d.push("-y",a),d})(e);await Le.exec(a);const r=await(async e=>{if(!Le)throw new Error("ffmpeg instance not loaded");return await Le.readFile(e)})(t);return await je(t),r},_e=e=>{if(!e||e<=0)return"0 B";const t=["B","KB","MB","GB"];let a=0,r=e;for(;r>=1024&&a<t.length-1;)r/=1024,a++;return`${r.toFixed(0===a?0:2)} ${t[a]}`},Oe=e=>{if(!e||!isFinite(e)||e<0)return"00:00.000";const t=Math.floor(1e3*e)%1e3,a=Math.floor(e),r=a%60,l=Math.floor(a/60),n=l%60,o=Math.floor(l/60),s=(e,t=2)=>String(e).padStart(t,"0");return o>0?`${s(o)}:${s(n)}:${s(r)}.${s(t,3)}`:`${s(n)}:${s(r)}.${s(t,3)}`},Ie=e=>{if(!e||!isFinite(e)||e<0)return"00:00";const t=Math.floor(e),a=t%60,r=Math.floor(t/60),l=Math.floor(r/60),n=e=>String(e).padStart(2,"0");return l>0?`${n(l)}:${n(r%60)}:${n(a)}`:`${n(r)}:${n(a)}`},De=(e,t,a)=>{const r="out"===a?1-t:t,l=Math.max(0,Math.min(1,r));switch(e){case"linear":default:return l;case"exponential":return l<=0?0:(Math.exp(4*l)-1)/(Math.exp(4)-1);case"logarithmic":return l<=0?0:Math.log(1+9*l)/Math.log(10);case"sine":return.5-.5*Math.cos(Math.PI*l);case"scurve":return l*l*(3-2*l)}},Ve={class:"bg-white dark:bg-gray-800 border border-gray-200 dark:border-gray-700 rounded-xl p-4"},Be={class:"flex items-center justify-between mb-3 flex-wrap gap-2"},qe={class:"text-base font-semibold text-gray-900 dark:text-white flex items-center gap-2"},He={class:"flex items-center gap-2 flex-wrap"},Ke=["disabled","title"],Ge=["disabled","title"],We={key:0,class:"relative py-6"},Xe=["aria-label","aria-valuemax","aria-valuenow","aria-valuetext"],Ze={class:"absolute inset-0 flex items-center justify-center gap-[1px] px-1 pb-4 pt-2 pointer-events-none","aria-hidden":"true"},Ye={key:0,class:"flex items-center gap-2 text-blue-700 dark:text-blue-400"},Je=["title","onPointerdown","onKeydown"],Qe=["d"],et={class:"absolute bottom-0 inset-x-0 px-1 flex justify-between text-[10px] text-gray-700 dark:text-gray-300 pointer-events-none bg-white/60 dark:bg-gray-900/60"},tt={key:0},at={key:1},rt={key:2},lt={class:"absolute top-6 bottom-6 left-0 right-0 pointer-events-none z-20"},nt=["aria-label","aria-valuemax","aria-valuenow","aria-valuetext","onPointerdown","onKeydown"],ot=["aria-label","aria-valuemax","aria-valuenow","aria-valuetext","onPointerdown","onKeydown"],st={key:1,class:"h-32 bg-gray-100 dark:bg-gray-900 border border-gray-200 dark:border-gray-700 rounded-lg flex items-center justify-center text-sm text-gray-500 dark:text-gray-400"},it=["aria-label"],dt=["onClick"],ut={class:"col-span-12 sm:col-span-2 flex items-center gap-1.5"},ct={class:"text-xs font-medium text-gray-900 dark:text-white"},mt={class:"col-span-4 sm:col-span-3"},gt=["for"],pt=["id","value","max","onInput"],bt={class:"col-span-4 sm:col-span-3"},ft=["for"],yt=["id","value","max","onInput"],xt={class:"col-span-3 sm:col-span-3"},vt=["for"],ht=["id","value","onChange"],kt=["value"],wt={class:"col-span-1 flex justify-end"}
1,$t=["aria-label","title","onClick"],Mt={__name:"AudioFadeEditorTimeline",props:{duration:{type:Number,required:!0},currentTime:{type:Number,default:0},peaks:{type:Array,default:()=>[]},analyzing:{type:Boolean,default:!1},fades:{type:Array,required:!0},curves:{type:Array,required:!0},formatTimeShort:{type:Function,required:!0}},emits:["update:fade","add-fade","remove-fade","clear-fades","seek"],setup(p,{emit:x}){const v=p,h=x,k=u(null),w=u(""),$=u(null),M=u(0),F=u(!1),A=b(()=>v.peaks&&v.peaks.length>0?v.peaks:[]),C=b(()=>[...v.fades].sort((e,t)=>e.start-t.start)),E=b(()=>{const e=new Map;return C.value.forEach((t,a)=>{e.set(t.id,a+1)}),e}),S=e=>E.value.get(e.id)??0,R=e=>"in"===e.type?"bg-blue-700 dark:bg-blue-500":"bg-orange-600 dark:bg-orange-500",L=e=>w.value===e.id,P=e=>{w.value=e},T=e=>v.duration<=0?0:Math.max(0,Math.min(100,e.start/v.duration*100)),U=e=>{if(v.duration<=0)return 0;const t=e.start+e.duration;return Math.max(0,Math.min(100,t/v.duration*100))},j=e=>Math.max(0,U(e)-T(e)),z=b(()=>v.duration<=0?0:Math.max(0,Math.min(100,v.currentTime/v.duration*100))),N=e=>{const t=[];for(let a=0;a<=32;a++){const r=a/32,l=100*r,n=100-100*De(e.curve,r,e.type);t.push(`${0===a?"M":"L"} ${l.toFixed(2)} ${n.toFixed(2)}`)}return t.push("L 100 100"),t.push("L 0 100 Z"),t.join(" ")},_=e=>{if(!k.value)return 0;const t=k.value.getBoundingClientRect(),a=e-t.left;return Math.max(0,Math.min(1,a/t.width))},O=e=>Math.max(0,Math.min(v.duration,e*v.duration)),I=e=>{const t=_(e);h("seek",O(t))},D=e=>{void 0!==e.button&&0!==e.button||(w.value="",F.value=!0,I(e.clientX),window.addEventListener("pointermove",V),window.addEventListener("pointerup",B),window.addEventListener("pointercancel",B))},V=e=>{F.value&&I(e.clientX)},B=()=>{F.value=!1,window.removeEventListener("pointermove",V),window.removeEventListener("pointerup",B),window.removeEventListener("pointercancel",B)},q=(e,t,a)=>{$.value={id:e,edge:t},w.value=e,M.value=a.clientX,window.addEventListener("pointermove",H),window.addEventListener("pointerup",K),window.addEventListener("pointercancel",K)},H=e=>{if(!$.value)return;M.value=e.clientX;const t=_(e.clientX),a=O(t),{id:r,edge:l}=$.value,n=v.fades.find(e=>e.id===r);if(n)if("start"===l){const e=Math.max(0,n.start+n.duration-.1),t=Math.max(0,Math.min(a,e)),l=Math.max(.1,n.start+n.duration-t);h("update:fade",r,{start:t,duration:l})}else if("end"===l){const e=Math.max(n.start+.1,Math.min(v.duration,a)),t=Math.max(.1,e-n.start);h("update:fade",r,{duration:t})}},K=()=>{$.value=null,window.removeEventListener("pointermove",H),window.removeEventListener("pointerup",K),window.removeEventListener("pointercancel",K)},G=b(()=>$.value?Math.max(0,Math.min(100,100*_(M.value))):0),W=b(()=>{if(!$.value)return"";const e=_(M.value);return v.formatTimeShort(O(e))}),X=(e,t,a)=>{const r=v.fades.find(t=>t.id===e);if(r)if("start"===t){const t=Math.max(0,r.start+r.duration-.1),l=Math.max(0,Math.min(t,r.start+a)),n=Math.max(.1,r.start+r.duration-l);h("update:fade",e,{start:l,duration:n})}else if("end"===t){const t=Math.max(r.start+.1,Math.min(v.duration,r.start+r.duration+a)),l=Math.max(.1,t-r.start);h("update:fade",e,{duration:l})}},Z=e=>{h("seek",Math.max(0,Math.min(v.duration,v.currentTime+e)))},Y=(e,t,a)=>{const r=Number(a.target.value);if(Number.isNaN(r))return;const l=v.fades.find(t=>t.id===e);if(l)if("start"===t){const t=Math.max(0,l.start+l.duration-.1),a=Math.max(0,Math.min(t,r)),n=Math.max(.1,l.start+l.duration-a);h("update:fade",e,{start:a,duration:n})}else if("duration"===t){const t=Math.max(.1,Math.min(v.duration-l.start,r));h("update:fade",e,{duration:t})}};return f(()=>{K(),B()}),(u,b)=>{const f=l;return e(),t("div",Ve,[a("div",Be,[a("h2",qe,[r(f,{name:"material-symbols:timeline",class:"w-5 h-5 text-blue-700 dark:text-blue-400","aria-hidden":"true"}),o(" "+n(u.$t("Fade Timeline")),1)]),a("div",He,[a("button",{type:"button",class:"px-2.5 py-1.5 text-xs bg-blue-700 hover:bg-blue-600 text-white font-medium rounded-lg transition-colors flex items-center gap-1 disabled:opacity-50 disabled:cursor-not-allowed",disabled:p.duration<=0,title:u.$t("Add Fade In"),onClick:b[0]||(b[0]=e=>u.$emit("add-fade","in"))},[r(f,{name:"material-symbols:arrow-range-rounded",class:"w-4 h-4 rotate-90","aria-hidden":"true"}),o(" "+n(u.$t("Add Fade In")),1)],8,Ke),a("button",{type:"button",class:"px-2.5 py-1.5 text-xs bg-orange-600 hover:bg-orange-500 text-white font-medium rounded-lg transition-colors flex items-center gap-1 disabled:opacity-50 disabled:cursor-not-allowed",disabled:p.duration<=0,title:u.$t("Add Fade Out"),onClick:b[1]||(b[1]=e=>u.$emit("add-fade","out"))},[r(f,{name:"material-symbols:arrow-range-rounded",class:"w-4 h-4 -rotate-90","aria-hidden":"true"}),o(" "+n(u.$t("Add Fade Out")),1)],8,Ge),p.fades.length>
10?(e(),t("button",{key:0,type:"button",class:"px-2.5 py-1.5 text-xs border border-red-300 dark:border-red-700 text-red-700 dark:text-red-400 hover:bg-red-50 dark:hover:bg-red-900/20 font-medium rounded-lg transition-colors",onClick:b[2]||(b[2]=e=>u.$emit("clear-fades"))},[r(f,{name:"material-symbols:delete-outline-rounded",class:"w-4 h-4 inline -mt-0.5 mr-1","aria-hidden":"true"}),o(" "+n(u.$t("Clear Fades")),1)])):s("",!0)])]),p.duration>0?(e(),t("div",We,[a("div",{ref_key:"trackEl",ref:k,class:"relative h-32 bg-gray-100 dark:bg-gray-900 border border-gray-200 dark:border-gray-700 rounded-lg cursor-pointer select-none overflow-hidden touch-pan-y",role:"slider","aria-label":u.$t("Timeline position"),"aria-valuemin":0,"aria-valuemax":p.duration,"aria-valuenow":p.currentTime,"aria-valuetext":p.formatTimeShort(p.currentTime),tabindex:"0",onPointerdown:D,onKeydown:[b[3]||(b[3]=y(e=>Z(-.5),["left"])),b[4]||(b[4]=y(e=>Z(.5),["right"]))]},[a("div",Ze,[p.analyzing&&0===A.value.length?(e(),t("div",Ye,[r(f,{name:"material-symbols:progress-activity",class:"w-5 h-5 animate-spin"})])):s("",!0),(e(!0),t(c,null,m(A.value,(a,r)=>(e(),t("span",{key:r,class:"flex-1 max-w-[3px] rounded-sm bg-gray-400 dark:bg-gray-500",style:g({height:a+"%"})},null,4))),128))]),b[10]||(b[10]=a("div",{class:"absolute left-0 right-0 top-1/2 -translate-y-1/2 h-px bg-gray-300/40 dark:bg-gray-600/40 pointer-events-none","aria-hidden":"true",style:{"margin-top":"-8px"}},null,-1)),(e(!0),t(c,null,m(p.fades,r=>(e(),t("div",{key:r.id,class:"absolute inset-y-0"},[a("div",{class:d(["absolute inset-y-0 border-x-2 cursor-pointer transition-colors pointer-events-auto","in"===r.type?L(r)?"bg-blue-700/30 border-blue-700 dark:border-blue-400":"bg-blue-700/15 border-blue-700/60 dark:border-blue-500/50 hover:bg-blue-700/25":L(r)?"bg-orange-600/30 border-orange-600 dark:border-orange-400":"bg-orange-600/15 border-orange-600/60 dark:border-orange-500/50 hover:bg-orange-600/25"]),style:g({left:T(r)+"%",width:j(r)+"%"}),title:"in"===r.type?u.$t("Fade In"):u.$t("Fade Out"),onPointerdown:i(e=>P(r.id),["stop"]),onKeydown:y(i(e=>P(r.id),["prevent"]),["enter"])},null,46,Je),(e(),t("svg",{class:d(["absolute inset-y-0 pointer-events-none","in"===r.type?"text-blue-700 dark:text-blue-400":"text-orange-600 dark:text-orange-400"]),style:g({left:T(r)+"%",width:j(r)+"%",height:"100%"}),preserveAspectRatio:"none",viewBox:"0 0 100 100","aria-hidden":"true"},[a("path",{d:N(r),fill:"currentColor","fill-opacity":"0.25",stroke:"currentColor","stroke-width":"1.5","vector-effect":"non-scaling-stroke"},null,8,Qe)],6))]))),128)),p.duration>0?(e(),t("div",{key:0,class:"absolute top-0 bottom-0 w-0.5 bg-red-500 pointer-events-none z-10",style:g({left:z.value+"%"})},[...b[8]||(b[8]=[a("div",{class:"absolute -top-1 left-1/2 -translate-x-1/2 w-3 h-3 bg-red-500 rounded-full"},null,-1)])],4)):s("",!0),a("div",et,[b[9]||(b[9]=a("span",null,"0:00",-1)),p.duration>5?(e(),t("span",tt,n(p.formatTimeShort(p.duration/4)),1)):s("",!0),p.duration>5?(e(),t("span",at,n(p.formatTimeShort(p.duration/2)),1)):s("",!0),p.duration>5?(e(),t("span",rt,n(p.formatTimeShort(3*p.duration/4)),1)):s("",!0),a("span",null,n(p.formatTimeShort(p.duration)),1)])],40,Xe),a("div",lt,[(e(!0),t(c,null,m(p.fades,l=>(e(),t(c,{key:"h-"+l.id},[a("div",{class:d(["absolute top-0 -translate-x-1/2 pointer-events-auto cursor-ew-resize touch-none group focus:outline-none",[L(l)?"z-30":"z-20","hover:z-40"]]),style:g({left:T(l)+"%"}),role:"slider","aria-label":u.$t("Fade start handle")+" #"+S(l),"aria-valuemin":0,"aria-valuemax":p.duration,"aria-valuenow":l.start,"aria-valuetext":p.formatTimeShort(l.start),tabindex:"0",onPointerdown:i(e=>q(l.id,"start",e),["stop","prevent"]),onKeydown:[y(e=>X(l.id,"start",-.1),["left"]),y(e=>X(l.id,"start",.1),["right"])]},[a("div",{class:d(["absolute bottom-full left-1/2 -translate-x-1/2 mb-0.5 flex items-center gap-0.5 px-1 h-5 min-w-[1.75rem] rounded-md shadow-md ring-1 ring-black/5 text-white text-[10px] font-bold tabular-nums whitespace-nowrap transition-transform group-hover:scale-110 before:absolute before:inset-x-[-6px] before:inset-y-[-4px] before:content-['']",R(l)])},[r(f,{name:"material-symbols:chevron-left",class:"w-2.5 h-2.5","aria-hidden":"true"}),a("span",null,n(S(l)),1)],2),a("div",{class:d(["absolute top-0 left-1/2 -translate-x-1/2 w-1 h-3 rounded-b-full pointer-events-none",R(l)])},null,2)],46,nt),a("div",{class:d(["absolute bottom-0 -translate-x-1/2 pointer-events-auto cursor-ew-resize touch-none group focus:outline-none",[L(l)?"z-30":"z-20","hover:z-40"]]),style:g({left:U(l)+"%"}),role:"slider","aria-label":u.$t("Fade duration handle")+" #"+S(l),"aria-valuemin":0,"aria-valuemax":p.duration,"aria-valuenow":l.start+l.duration,"aria-valuetext":p.formatTimeShort(l.start+l.duration),tabindex:"0",onPointerdown:i(e=>q(l.id,"end",e),["stop","prevent"]),onKeydown:[y(e=>X(l.id,"end",-.1),["left"]),y(e=>X(l.id,"end",.1),["right"])]},[a("div",{class:d(["absolute bottom-0 left-1/2 -translate-x-1/2 w-1 h-3 rounded-t-full pointer-events-none",R(l)])},null,2),a("div",{class:d(["absolute top-full left-1/2 -translate-x-1/2 mt-0.5 flex items-center gap-0.5 px-1 h-5 min-w-[1.75rem] rounded-md shadow-md ring-1 ring-black/5 text-white text-[10px] font-bold tabular-nums whitespace-nowrap transition-transform group-hover:scale-110 before:absolute before:inset-x-[-6px] before:inset-y-[-4px] before:content-['']",R(l)])},[a("span",null,n(S(l)),1),r(f,{name:"material-symbols:chevron-right",class:"w-2.5 h-2.5","aria-hidden":"true"})],2)],46,ot)],64))),128))]),$.value?(e(),t("div",{key:0,class:"absolute z-40 top-1/2 -translate-x-1/2 -translate-y-1/2 ml-8 px-2 py-1 rounded-md bg-gray-900 dark:bg-gray-700 text-white text-xs font-mono tabular-nums pointer-events-none whitespace-nowrap shadow-lg",style:g({left:G.value+"%"}),"aria-hidden":"true"},[o(n(W.value)+" ",1),b[11]||(b[11]=a("div",{class:"absolute left-1/2 -translate-x-1/2 -bottom-1 w-2 h-2 rotate-45 bg-gray-900 dark:bg-gray-700"},null,-1))],4)):s("",!0)])):(e(),t("div",st,n(u.$t("Add an audio file to start editing fades")),1)),p.fades.length>0?(e(),t("div",{key:2,class:"mt-3 space-y-2",role:"group","aria-label":u.$t("Fade regions")},[(e(!0),t(c,null,m(C.value,(l,o)=>(e(),t("div",{key:l.id,class:d(["grid grid-cols-12 gap-2 items-center p-2 rounded-lg cursor-pointer transition-colors",L(l)?"bg-blue-50 dark:bg-blue-900/20 border border-blue-300 dark:border-blue-700":"bg-gray-50 dark:bg-gray-900 border border-gray-200 dark:border-gray-700 hover:border-gray-300 dark:hover:border-gray-600"]),onClick:e=>P(l.id)},[a("div",ut,[a("span",{class:d(["inline-block w-2 h-2 rounded-full","in"===l.type?"bg-blue-700":"bg-orange-600"]),"aria-hidden":"true"},null,2),a("span",ct," #"+n(o+1)+" "+n("in"===l.type?u.$t("Fade In"):u.$t("Fade Out")),1)]),a("div",mt,[a("label",{class:"block text-[10px] text-gray-700 dark:text-gray-300 mb-0.5",for:`fade-start-${l.id}`},n(u.$t("Start (seconds)")),9,gt),a("input",{id:`fade-start-${l.id}`,type:"number",value:Number(l.start.toFixed(3)),min:0,max:p.duration-.1,step:.1,class:"w-full px-2 py-1 text-xs border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-700 text-gray-900 dark:text-white rounded-md focus:outline-none focus:ring-1 focus:ring-blue-700",onInput:e=>Y(l.id,"start",e),onClick:b[5]||(b[5]=i(()=>{},["stop"]))},null,40,pt)]),a("div",bt,[a("label",{class:"block text-[10px] text-gray-700 dark:text-gray-300 mb-0.5",for:`fade-duration-${l.id}`},n(u.$t("Duration (seconds)")),9,ft),a("input",{id:`fade-duration-${l.id}`,type:"number",value:Number(l.duration.toFixed(3)),min:.1,max:p.duration,step:.1,class:"w-full px-2 py-1 text-xs border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-700 text-gray-900 dark:text-white rounded-md focus:outline-none focus:ring-1 focus:ring-blue-700",onInput:e=>Y(l.id,"duration",e),onClick:b[6]||(b[6]=i(()=>{},["stop"]))},null,40,yt)]),a("div",xt,[a("label",{class:"block text-[10px] text-gray-700 dark:text-gray-300 mb-0.5",for:`fade-curve-${l.id}`},n(u.$t("Curve")),9,vt),a("select",{id:`fade-curve-${l.id}`,value:l.curve,class:"w-full px-2 py-1 text-xs border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-700 text-gray-900 dark:text-white rounded-md focus:outline-none focus:ring-1 focus:ring-blue-700",onChange:e=>{return t=l.id,void h("update:fade",t,{curve:e.target.value});var t},onClick:b[7]||(b[7]=i(()=>{},["stop"]))},[(e(!0),t(c,null,m(p.curves,a=>(e(),t("option",{key:a.value,value:a.value},n(u.$t(a.label)),9,kt))),128))],40,ht)]),a("div",wt,[a("button",{type:"button",class:"p-1.5 text-red-700 dark:text-red-400 hover:bg-red-50 dark:hover:bg-red-900/20 rounded-md transition-colors","aria-label":u.$t("Remove fade"),title:u.$t("Remove fade"),onClick:i(e=>u.$emit("remove-fade",l.id),["stop"])}
1,[r(f,{name:"material-symbols:close-rounded",class:"w-4 h-4","aria-hidden":"true"})],8,$t)])],10,dt))),128))],8,it)):s("",!0)])}}},Ft={class:"bg-white dark:bg-gray-800 border border-gray-200 dark:border-gray-700 rounded-xl p-4"},At={class:"text-base font-semibold text-gray-900 dark:text-white flex items-center gap-2 mb-3"},Ct=["aria-label"],Et=["aria-checked","title","onClick"],St=["aria-label"],Rt={viewBox:"0 0 200 120",class:"w-full h-32",preserveAspectRatio:"none","aria-hidden":"true"},Lt=["d"],Pt=["d"],Tt=["d"],Ut=["d"],jt={class:"flex items-center justify-center gap-4 mt-2 text-xs"},zt={class:"flex items-center gap-1.5 text-gray-700 dark:text-gray-300"},Nt={class:"flex items-center gap-1.5 text-gray-700 dark:text-gray-300"},_t={key:0,class:"text-xs text-gray-700 dark:text-gray-300 mt-3 flex items-start gap-1.5"},Ot=110,It=50,Dt={__name:"AudioFadeEditorCurvePreview",props:{modelValue:{type:String,default:"linear"},curves:{type:Array,required:!0}},emits:["update:modelValue"],setup(i){const u=i,g=b(()=>u.curves.find(e=>e.value===u.modelValue)||u.curves[0]),p=b(()=>{const e=[];for(let t=0;t<=It;t++){const a=t/It,r=De(u.modelValue,a,"in"),l=t/It*200,n=Ot-100*r;e.push(`${0===t?"M":"L"} ${l.toFixed(2)} ${n.toFixed(2)}`)}return e.join(" ")}),f=b(()=>{const e=[];for(let t=0;t<=It;t++){const a=t/It,r=De(u.modelValue,a,"out"),l=t/It*200,n=Ot-100*r;e.push(`${0===t?"M":"L"} ${l.toFixed(2)} ${n.toFixed(2)}`)}return e.join(" ")});return(u,b)=>{const y=l;return e(),t("div",Ft,[a("h2",At,[r(y,{name:"material-symbols:line-axis-rounded",class:"w-5 h-5 text-blue-700 dark:text-blue-400","aria-hidden":"true"}),o(" "+n(u.$t("Fade Curve Preview")),1)]),a("div",{class:"grid grid-cols-2 sm:grid-cols-3 gap-2 mb-4",role:"radiogroup","aria-label":u.$t("Five Fade Curve Types")},[(e(!0),t(c,null,m(i.curves,a=>{return e(),t("button",{key:a.value,type:"button",role:"radio","aria-checked":i.modelValue===a.value,class:d(["px-3 py-2 text-xs font-medium rounded-lg border transition-colors flex items-center justify-center gap-1.5",i.modelValue===a.value?"border-blue-700 bg-blue-700 text-white":"border-gray-300 dark:border-gray-600 text-gray-800 dark:text-gray-200 hover:bg-gray-50 dark:hover:bg-gray-700"]),title:u.$t(a.description),onClick:e=>u.$emit("update:modelValue",a.value)},[r(y,{name:(l=a.value,{linear:"material-symbols:linear-scale",exponential:"material-symbols:trending-up-rounded",logarithmic:"material-symbols:show-chart-rounded",sine:"material-symbols:waves-rounded",scurve:"material-symbols:line-axis-rounded"}[l]||"material-symbols:line-axis-rounded"),class:"w-4 h-4","aria-hidden":"true"},null,8,["name"]),o(" "+n(u.$t(a.label)),1)],10,Et);var l}),128))],8,Ct),a("div",{class:"relative bg-gray-50 dark:bg-gray-900 border border-gray-200 dark:border-gray-700 rounded-lg p-3",role:"img","aria-label":u.$t("Fade Curve Preview")},[(e(),t("svg",Rt,[b[0]||(b[0]=a("line",{x1:"0",y1:"30",x2:"200",y2:"30",stroke:"currentColor","stroke-width":"0.5","stroke-dasharray":"2,2",class:"text-gray-300 dark:text-gray-600"},null,-1)),b[1]||(b[1]=a("line",{x1:"0",y1:"60",x2:"200",y2:"60",stroke:"currentColor","stroke-width":"0.5","stroke-dasharray":"2,2",class:"text-gray-300 dark:text-gray-600"},null,-1)),b[2]||(b[2]=a("line",{x1:"0",y1:"90",x2:"200",y2:"90",stroke:"currentColor","stroke-width":"0.5","stroke-dasharray":"2,2",class:"text-gray-300 dark:text-gray-600"},null,-1)),a("path",{d:p.value,fill:"none",stroke:"#1d4ed8","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"},null,8,Lt),a("path",{d:`${p.value} L 200 110 L 0 110 Z`,fill:"#1d4ed8","fill-opacity":"0.1"},null,8,Pt),a("path",{d:f.value,fill:"none",stroke:"#ea580c","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round","stroke-dasharray":"4,2"},null,8,Tt),a("path",{d:`${f.value} L 200 110 L 0 110 Z`,fill:"#ea580c","fill-opacity":"0.1"},null,8,Ut),b[3]||(b[3]=a("line",{x1:"0",y1:"110",x2:"200",y2:"110",stroke:"currentColor","stroke-width":"1",class:"text-gray-400 dark:text-gray-500"},null,-1)),b[4]||(b[4]=a("line",{x1:"0",y1:"10",x2:"200",y2:"10",stroke:"currentColor","stroke-width":"1",class:"text-gray-400 dark:text-gray-500"},null,-1))])),a("div",jt,[a("span",zt,[b[5]||(b[5]=a("span",{class:"inline-block w-4 h-0.5 bg-blue-700","aria-hidden":"true"},null,-1)),o(" "+n(u.$t("Fade In")),1)]),a("span",Nt,[b[6]||(b[6]=a("span",{class:"inline-block w-4 h-0.5 border-t-2 border-dashed border-orange-600","aria-hidden":"true"},null,-1)),o(" "+n(u.$t("Fade Out")),1)])])],8,St),g.value?(e(),t("p",_t,[r(y,{name:"material-symbols:info-outline",class:"w-3.5 h-3.5 mt-0.5 shrink-0 text-blue-700 dark:text-blue-400","aria-hidden":"true"}),a("span",null,n(u.$t(g.value.description)),1)])):s("",!0)])}}},Vt={class:"bg-white dark:bg-gray-800 border border-gray-200 dark:border-gray-700 rounded-xl p-4"},Bt={class:"text-base font-semibold text-gray-900 dark:text-white flex items-center gap-2 mb-4"},qt={class:"space-y-4"},Ht={class:"block text-xs font-medium text-gray-700 dark:text-gray-300 mb-2",for:"afe-format-select"},Kt=["value"],Gt={key:0},Wt={class:"block text-xs font-medium text-gray-700 dark:text-gray-300 mb-2",for:"afe-bitrate-select"},Xt=["value"],Zt={class:"block text-xs font-medium text-gray-700 dark:text-gray-300 mb-2",for:"afe-sample-rate-select"},Yt=["value"],Jt={class:"block text-xs font-medium text-gray-700 dark:text-gray-300 mb-2",for:"afe-volume-range"},Qt={class:"ml-2 text-gray-900 dark:text-white font-mono tabular-nums"},ea={__name:"AudioFadeEditorOutputSettings",props:{config:{type:Object,required:!0},outputFormats:{type:Object,required:!0},sampleRatePresets:{type:Array,required:!0},bitratePresets:{type:Array,required:!0}},emits:["update"],setup(i,{emit:d}){const u=i,g=d,p=x({format:u.config.format,bitrate:u.config.bitrate,sampleRate:u.config.sampleRate,volume:u.config.volume});v(()=>u.config,e=>{e&&(p.format=e.format,p.bitrate=e.bitrate,p.sampleRate=e.sampleRate,p.volume=e.volume)},{deep:!0});const b=()=>{g("update",{format:p.format,bitrate:p.bitrate,sampleRate:p.sampleRate,volume:p.volume})};return(d,u)=>{const g=l;return e(),t("div",Vt,[a("h2",Bt,[r(g,{name:"material-symbols:tune-rounded",class:"w-5 h-5 text-blue-700 dark:text-blue-400","aria-hidden":"true"}),o(" "+n(d.$t("Output Settings")),1)]),a("div",qt,[a("div",null,[a("label",Ht,n(d.$t("Format")),1),h(a("select",{id:"afe-format-select","onUpdate:modelValue":u[0]||(u[0]=e=>p.format=e),class:"w-full px-3 py-2 text-sm bg-white dark:bg-gray-900 border border-gray-300 dark:border-gray-600 text-gray-900 dark:text-white rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-700 focus:border-transparent",onChange:b},[(e(!0),t(c,null,m(i.outputFormats,(a,r)=>(e(),t("option",{key:r,value:r},n(d.$t(a.label)),9,Kt))),128))],544),[[k,p.format]])]),"wav"!==p.format?(e(),t("div",Gt,[a("label",Wt,n(d.$t("Bitrate")),1),h(a("select",{id:"afe-bitrate-select","onUpdate:modelValue":u[1]||(u[1]=e=>p.bitrate=e),class:"w-full px-3 py-2 text-sm bg-white dark:bg-gray-900 border border-gray-300 dark:border-gray-600 text-gray-900 dark:text-white rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-700 focus:border-transparent",onChange:b},[(e(!0),t(c,null,m(i.bitratePresets,a=>(e(),t("option",{key:a.value,value:a.value},n(d.$t(a.label)),9,Xt))),128))],544),[[k,p.bitrate]])])):s("",!0),a("div",null,[a("label",Zt,n(d.$t("Sample Rate")),1),h(a("select",{id:"afe-sample-rate-select","onUpdate:modelValue":u[2]||(u[2]=e=>p.sampleRate=e),class:"w-full px-3 py-2 text-sm bg-white dark:bg-gray-900 border border-gray-300 dark:border-gray-600 text-gray-900 dark:text-white rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-700 focus:border-transparent",onChange:b},[(e(!0),t(c,null,m(i.sampleRatePresets,a=>(e(),t("option",{key:a.value,value:a.value},n(d.$t(a.label)),9,Yt))),128))],544),[[k,p.sampleRate]])]),a("div",null,[a("label",Jt,[o(n(d.$t("Adjustable Output Volume"))+" ",1),a("span",Qt,n(p.volume)+"%",1)]),h(a("input",{id:"afe-volume-range","onUpdate:modelValue":u[3]||(u[3]=e=>p.volume=e),type:"range",min:"0",max:"200",step:"1",class:"w-full accent-blue-700 dark:accent-blue-400",onInput:b},null,544),[[w,p.volume,void 0,{number:!0}]]),u[4]||(u[4]=a("div",{class:"flex justify-between text-[10px] text-gray-700 dark:text-gray-300 mt-1"},[a("span",null,"0%"),a("span",null,"100%"),a("span",null,"200%")],-1))])])])}}},ta=(e=0)=>{const t=[];if(t.push({id:$(8),type:"in",start:0,duration:Math.min(2,Math.max(.5,.2*(e||10))),curve:"linear"}),e>4){const a=Math.min(3,.3*e);t.push({id:$(8),type:"out",start:Math.max(0,e-a),duration:a,curve:"linear"})}return t},aa=()=>{const{t:e}=p(),t=u([]),a=u([]),r=u(!1),l=u(!1),n=u(!1),o=u(0),s=u(""),i=u(""),d=u(""),c=u(""),m=u(0),g=x({format:"mp3",bitrate:0,sampleRate:0,volume:100});let f=null,y=null;const v=b(()=>t.value.length>0),h=b(()=>t.value.length),k=b(()=>Math.round(100*o.value)),w=b(()=>t.value.some(e=>!!e.resultUrl)),M=b(()=>{const e=t.value.filter(e=>e.processing);if(0===e.length)return 0;const a=e.reduce((e,t)=>
1e+(t.progress||0),0);return Math.round(a/e.length*100)}),F=b(()=>t.value.find(e=>e.id===c.value)||t.value[0]||null),E=b(()=>F.value&&F.value.duration>0?F.value.duration:0===t.value.length?0:Math.max(...t.value.map(e=>e.duration||0))),S=b(()=>F.value?.peaks||[]),R=b(()=>t.value.filter(e=>!!e.resultUrl).length),L=e=>{const t=/\.([a-zA-Z0-9]+)$/.exec(e);return t?t[1].toLowerCase():"mp3"},P=async r=>{if(!r)return null;if(!r.type.startsWith("audio/")&&!/\.(mp3|wav|aac|ogg|flac|m4a|wma|opus|amr|aiff)$/i.test(r.name))return d.value=e("Please add at least one audio file"),null;d.value="";const l=((e,t)=>({id:$(10),file:e,name:t,size:e.size||0,duration:0,peaks:[],loading:!0,tempName:"",outName:"",resultUrl:"",resultSize:0,resultExt:"",processing:!1,progress:0,error:""}))(r,r.name);t.value.push(l);const o=t.value[t.value.length-1];c.value||(c.value=o.id);try{if((async(e,t=120)=>{if(!e||!t||"undefined"==typeof window)return{peaks:[],duration:0};const a=window.AudioContext||window.webkitAudioContext;if(!a)return{peaks:[],duration:0};let r=null;try{const l=await e.arrayBuffer();r=new a;const n=await r.decodeAudioData(l),o=n.numberOfChannels,s=n.length;if(0===s||0===o)return{peaks:[],duration:n.duration||0};const i=[];for(let e=0;e<o;e++)i.push(n.getChannelData(e));const d=Math.max(1,Math.ceil(s/t)),u=[];for(let e=0;e<t;e++){const t=e*d,a=Math.min(t+d,s);if(t>=a){u.push(5);continue}let r=0,l=0;for(let e=t;e<a;e++){let t=0;for(let r=0;r<o;r++)t+=i[r][e];const a=t/o;r+=a*a,l++}const n=l>0?Math.sqrt(r/l):0,c=1e-4,m=Math.max(c,n),g=20*Math.log10(m),p=-80,b=(g-p)/(-6-p),f=Math.round(Math.max(5,Math.min(100,100*b)));u.push(f)}return{peaks:u,duration:n.duration||0}}catch(l){return{peaks:[],duration:0}}finally{if(r&&"function"==typeof r.close)try{await r.close()}catch{}}})(r,200).then(({peaks:e,duration:t})=>{o.peaks=e,t>0&&(o.duration=t),0===a.value.length&&o.duration>0&&(a.value=ta(o.duration))}).catch(()=>{o.peaks=[],(e=>new Promise(t=>{if("undefined"==typeof window||"undefined"==typeof document)return void t(0);const a=document.createElement("audio");a.preload="metadata",a.muted=!0;const r=URL.createObjectURL(e);let l=!1;const n=()=>{URL.revokeObjectURL(r),a.removeAttribute("src"),a.load()},o=()=>{l||(l=!0,n(),t(0))};a.addEventListener("loadedmetadata",()=>{if(l)return;l=!0;const e=a.duration||0;n(),t(e)}),a.addEventListener("error",o),a.src=r,setTimeout(()=>{l||o()},1e4)}))(r).then(e=>{e>0&&(o.duration=e,0===a.value.length&&(a.value=ta(e)))})}).finally(()=>{o.loading=!1}),0===a.value.length&&o.duration>0&&(a.value=ta(o.duration)),n.value&&f&&y)try{const e=L(r.name),t=ze(e);await Ue(r,t,y),o.tempName=t}catch(s){}}catch(s){d.value=e("Failed to load audio. Please try another file.");const a=t.value.findIndex(e=>e.id===o.id);return a>=0&&t.value.splice(a,1),null}return o},T=()=>{t.value.forEach(e=>{e.tempName&&je(e.tempName),e.outName&&je(e.outName),e.resultUrl&&URL.revokeObjectURL(e.resultUrl)}),t.value=[],c.value="",d.value=""},U=()=>{t.value.forEach(e=>{e.resultUrl&&(URL.revokeObjectURL(e.resultUrl),e.resultUrl=""),e.resultSize=0,e.resultExt="",e.progress=0,e.error="",e.outName&&(je(e.outName),e.outName="")})},j=async()=>{if(n.value&&f)return f;r.value=!0,o.value=0,s.value="starting",d.value="",i.value="";try{s.value="loading-modules";const{fetchFile:e}=await C(),r=await(async(e,t,a)=>{if(Le&&Le.loaded)return Le;if(Le&&!Le.loaded){try{Le.terminate()}catch{}Le=null,Pe=null}return Te||(Te=(async()=>{try{const r=await A(e,t,a);return Le=r.ffmpeg,Pe=r.terminate,Le}finally{Te=null}})(),Te)})(e=>{i.value=e},e=>{o.value=e},e=>{s.value=e});f=r,y=e,n.value=!0,s.value="ready";for(const l of t.value)if(!l.tempName&&l.file)try{const e=L(l.file.name),t=ze(e);await Ue(l.file,t,y),l.tempName=t}catch(a){}return f}catch(a){throw d.value=e("Failed to load audio processing engine. Please check your network and try again."),a}finally{r.value=!1}},z=async r=>{const l=t.value.find(e=>e.id===r);if(l&&l.file){n.value||await j(),l.processing=!0,l.progress=0,l.error="",l.resultUrl&&(URL.revokeObjectURL(l.resultUrl),l.resultUrl="",l.resultSize=0,l.resultExt=""),l.outName&&await je(l.outName);try{if(!l.tempName&&y){const e=L(l.file.name),t=ze(e);await Ue(l.file,t,y),l.tempName=t}const e=Ae[g.format]||Ae.mp3,t=ze(e.ext);l.outName=t;const r=({progress:e})=>{l.progress=e};f&&"function"==typeof f.on&&f.on("progress",r);
1const n=await Ne({inputName:l.tempName,outputName:t,duration:l.duration,fades:a.value,format:g.format,bitrate:g.bitrate,sampleRate:g.sampleRate,volume:g.volume});f&&"function"==typeof f.off&&f.off("progress",r);const{blob:o,url:s}=((e,t)=>{const a=new Blob([e],{type:t});return{blob:a,url:URL.createObjectURL(a)}})(n,e.mimeType);l.resultUrl=s,l.resultSize=o.size,l.resultExt=e.ext,l.progress=1}catch(o){l.error=e("Failed to process audio. Please try again.")}finally{l.processing=!1}}};return{items:t,fades:a,isLoading:r,isProcessing:l,ffmpegReady:n,loadingProgress:o,loadingStage:s,ffmpegLog:i,errorMessage:d,activeItemId:c,currentTime:m,outputConfig:g,hasItems:v,itemCount:h,ffmpegLoadPercent:k,processingPercent:M,hasAnyResult:w,activeItem:F,referenceDuration:E,referencePeaks:S,completedCount:R,addItems:async e=>{if(e&&0!==e.length){r.value=!0;try{for(const t of e)await P(t)}finally{r.value=!1}}},removeItem:e=>{const a=t.value.findIndex(t=>t.id===e);if(a<0)return;const r=t.value[a];r.tempName&&je(r.tempName),r.outName&&je(r.outName),r.resultUrl&&URL.revokeObjectURL(r.resultUrl),t.value.splice(a,1),c.value===e&&(c.value=t.value[0]?.id||"")},clearItems:T,clearResults:U,setActiveItem:e=>{t.value.find(t=>t.id===e)&&(c.value=e)},addFade:(e="in")=>{const t=E.value||10,r={id:$(8),type:"out"===e?"out":"in",start:"out"===e?Math.max(0,t-2):0,duration:2,curve:"linear"};return t>0&&(r.start=Math.min(r.start,t-r.duration),r.start=Math.max(0,r.start)),a.value.push(r),U(),r},removeFade:e=>{const t=a.value.findIndex(t=>t.id===e);t<0||(a.value.splice(t,1),U())},updateFade:(e,t)=>{const r=a.value.find(t=>t.id===e);if(!r)return;Object.assign(r,t);const l=E.value;void 0!==t.start&&l>0&&(r.start=Math.max(0,Math.min(r.start,l-.1))),void 0!==t.duration&&(r.duration=Math.max(.1,Math.min(r.duration,l||60))),l>0&&r.start+r.duration>l&&(r.duration=Math.max(.1,l-r.start)),U()},clearFades:()=>{a.value=[],U()},loadFfmpegEngine:j,processOne:z,processAll:async()=>{if(0!==t.value.length){n.value||await j(),l.value=!0,d.value="",i.value="";try{for(const e of t.value)await z(e.id)}finally{l.value=!1}}else d.value=e("Please add at least one audio file")},downloadItem:e=>{const a=t.value.find(t=>t.id===e);if(!a||!a.resultUrl)return;const r=a.name.replace(/\.[^.]+$/,""),l=document.createElement("a");l.href=a.resultUrl,l.download=`faded_${r}_${Date.now()}.${a.resultExt||"mp3"}`,document.body.appendChild(l),l.click(),document.body.removeChild(l)},downloadAll:()=>{t.value.forEach(e=>{if(e.resultUrl){const t=e.name.replace(/\.[^.]+$/,""),a=document.createElement("a");a.href=e.resultUrl,a.download=`faded_${t}_${Date.now()}.${e.resultExt||"mp3"}`,document.body.appendChild(a),a.click(),document.body.removeChild(a)}})},setCurrentTime:e=>{m.value=Math.max(0,Math.min(e,E.value))},cleanup:()=>{T(),a.value=[],Pe&&Pe(),Le=null,Pe=null,Te=null,f=null,y=null,n.value=!1},SUPPORTED_INPUT_FORMATS:".mp3,.wav,.aac,.ogg,.flac,.m4a,.wma,.opus,.amr,.aiff",OUTPUT_FORMATS:Ae,SAMPLE_RATE_PRESETS:Ce,BITRATE_PRESETS:Ee,FADE_CURVE_TYPES:Se,formatFileSize:_e,formatTime:Oe,formatTimeShort:Ie}},ra={class:"bg-gray-50 dark:bg-gray-900 p-4 md:p-6"},la={class:"mb-4 flex items-center justify-between flex-wrap gap-2"},na={class:"text-xl font-semibold text-gray-900 dark:text-white flex items-center gap-2"},oa={class:"flex items-center gap-2 text-xs text-gray-700 dark:text-gray-300"},sa={key:1,class:"grid grid-cols-1 lg:grid-cols-3 gap-4"},ia={class:"lg:col-span-2 space-y-4"},da={class:"bg-white dark:bg-gray-800 border border-gray-200 dark:border-gray-700 rounded-xl p-3"},ua=["aria-label"],ca={class:"flex items-center justify-between mb-3 gap-2 flex-wrap"},ma={class:"text-base font-semibold text-gray-900 dark:text-white flex items-center gap-2"},ga={class:"text-xs text-gray-700 dark:text-gray-300 font-normal font-mono tabular-nums"},pa={class:"flex items-center gap-2"},ba=["aria-label","disabled"],fa={class:"space-y-3"},ya={class:"bg-white dark:bg-gray-800 border border-gray-200 dark:border-gray-700 rounded-xl p-4"},xa={class:"flex flex-wrap items-center gap-3"},va=["disabled"],ha={key:1,class:"px-3 py-1.5 text-xs bg-green-100 dark:bg-green-900/30 text-green-700 dark:text-green-400 rounded-lg flex items-center gap-1"},ka=["disabled","title"],wa={class:"space-y-4"},$a={class:"bg-white dark:bg-gray-800 border border-gray-200 dark:border-gray-700 rounded-xl p-4"},Ma={class:"text-base font-semibold text-gray-900 dark:text-white flex items-center gap-2 mb-3"},Fa={class:"space-y-2 text-sm"},Aa={class:"flex items-center justify-between"},Ca={class:"text-gray-700 dark:text-gray-300"},Ea={class:"text-gray-900 dark:text-white font-mono tabular-nums"},Sa={class:"flex items-center justify-between"},Ra={class:"text-gray-700 dark:text-gray-300"},La={class:"text-gray-900 dark:text-white font-mono tabular-nums"},Pa={class:"flex items-center justify-between"},Ta={class:"text-gray-700 dark:text-gray-300"},Ua={class:"text-gray-900 dark:text-white font-mono tabular-nums"},ja={class:"flex items-center justify-between"},za={class:"text-gray-700 dark:text-gray-300"},Na={class:"text-gray-900 dark:text-white font-mono uppercase"},_a={class:"flex items-center justify-between"},Oa={class:"text-gray-700 dark:text-gray-300"},Ia={class:"text-gray-900 dark:text-white font-mono tabular-nums"},Da={class:"flex items-center justify-between"},Va={class:"text-gray-700 dark:text-gray-300"},Ba={class:"text-gray-900 dark:text-white font-mono tabular-nums"},qa={__name:"AudioFadeEditorApp",setup(i){const{items:d,fades:g,isLoading:p,isProcessing:b,ffmpegReady:y,loadingStage:x,ffmpegLog:h,errorMessage:k,currentTime:w,outputConfig:$,hasItems:A,itemCount:C,ffmpegLoadPercent:E,processingPercent:S,hasAnyResult:R,referenceDuration:L,referencePeaks:P,completedCount:T,addItems:U,removeItem:j,
1clearItems:N,clearResults:_,loadFfmpegEngine:O,processOne:I,processAll:D,downloadItem:V,downloadAll:B,setCurrentTime:q,addFade:H,removeFade:K,updateFade:G,clearFades:W,cleanup:X,OUTPUT_FORMATS:Z,SAMPLE_RATE_PRESETS:Y,BITRATE_PRESETS:J,FADE_CURVE_TYPES:Q,formatFileSize:ee,formatTimeShort:te}=aa(),ae=u(null),re=u("linear");v(()=>g.value.map(e=>`${e.id}:${e.curve}`).join("|"),()=>{g.value.length>0&&(re.value=g.value[0].curve)},{immediate:!0}),v(re,e=>{g.value.length>0&&g.value[0].curve!==e&&G(g.value[0].id,{curve:e})});const le=async e=>{await U(e),A.value&&!y.value&&O().catch(e=>{})},ne=e=>{j(e)},oe=()=>{N(),W()},ie=async()=>{try{await O()}catch(e){}},de=async()=>{await D()},ue=async e=>{await I(e)},ce=e=>{V(e)},me=()=>{B()},ge=e=>{H(e)},pe=e=>{K(e)},be=(e,t)=>{G(e,t)},fe=()=>{W()},ye=e=>{q(e)},xe=e=>{Object.assign($,e),_()};return f(()=>{X()}),(i,u)=>{const f=l,v=z,U=se,j=Fe,N=Mt,_=Dt,O=ea;return e(),t("div",ra,[a("div",la,[a("h2",na,[r(f,{name:"material-symbols:graphic-eq-rounded",class:"w-6 h-6 text-blue-700 dark:text-blue-400","aria-hidden":"true"}),o(" "+n(i.$t("Audio Fade Editor")),1)]),a("div",oa,[r(f,{name:"material-symbols:lock-outline",class:"w-4 h-4","aria-hidden":"true"}),o(" "+n(i.$t("Browser-based Audio Processing")),1)])]),M(A)?s("",!0):(e(),F(v,{key:0,ref_key:"uploaderRef",ref:ae,class:"mt-4",onSelect:le},null,512)),M(A)?(e(),t("div",sa,[a("div",ia,[a("div",da,[r(v,{ref_key:"uploaderRef",ref:ae,"item-count":M(C),onSelect:le},null,8,["item-count"])]),a("section",{class:"bg-white dark:bg-gray-800 border border-gray-200 dark:border-gray-700 rounded-xl p-4","aria-label":i.$t("Audio Files")},[a("div",ca,[a("h2",ma,[r(f,{name:"material-symbols:list-rounded",class:"w-5 h-5 text-blue-700 dark:text-blue-400","aria-hidden":"true"}),o(" "+n(i.$t("Audio Files"))+" ",1),a("span",ga," ("+n(M(C))+") ",1)]),a("div",pa,[M(R)?(e(),t("button",{key:0,type:"button",class:"px-3 py-1.5 text-xs border border-blue-300 dark:border-blue-700 text-blue-700 dark:text-blue-400 hover:bg-blue-50 dark:hover:bg-blue-900/20 font-medium rounded-lg transition-colors flex items-center gap-1.5",onClick:me},[r(f,{name:"material-symbols:download-rounded",class:"w-4 h-4","aria-hidden":"true"}),o(" "+n(i.$t("Download All")),1)])):s("",!0),a("button",{type:"button",class:"px-3 py-1.5 text-xs border border-red-300 dark:border-red-700 text-red-700 dark:text-red-400 hover:bg-red-50 dark:hover:bg-red-900/20 font-medium rounded-lg transition-colors flex items-center gap-1.5 disabled:opacity-50 disabled:cursor-not-allowed","aria-label":i.$t("Clear All"),disabled:M(b),onClick:oe},[r(f,{name:"material-symbols:cleaning-services-outline",class:"w-4 h-4","aria-hidden":"true"}),o(" "+n(i.$t("Clear All")),1)],8,ba)])]),a("div",fa,[(e(!0),t(c,null,m(M(d),t=>(e(),F(U,{key:t.id,item:t,"format-file-size":M(ee),"format-time-short":M(te),onRemove:ne,onDownload:ce,onReProcess:ue},null,8,["item","format-file-size","format-time-short"]))),128))])],8,ua),a("div",ya,[a("div",xa,[M(y)?(e(),t("span",ha,[r(f,{name:"material-symbols:check-circle-outline",class:"w-4 h-4","aria-hidden":"true"}),o(" "+n(i.$t("Ready")),1)])):(e(),t("button",{key:0,type:"button",class:"px-5 py-2.5 bg-gray-100 dark:bg-gray-700 hover:bg-gray-200 dark:hover:bg-gray-600 disabled:opacity-50 disabled:cursor-not-allowed text-gray-800 dark:text-gray-200 font-medium rounded-lg transition-colors flex items-center gap-2",disabled:M(p),onClick:ie},[r(f,{name:"material-symbols:cloud-download-outline",class:"w-5 h-5","aria-hidden":"true"}),o(" "+n(M(p)?i.$t("Loading Engine"):i.$t("Load Engine")),1)],8,va)),a("button",{type:"button",class:"px-5 py-2.5 bg-blue-700 hover:bg-blue-600 disabled:bg-gray-300 dark:disabled:bg-gray-700 disabled:cursor-not-allowed text-white font-medium rounded-lg transition-colors flex items-center gap-2",disabled:!M(A)||M(b)||0===M(g).length,title:0===M(g).length?i.$t("Add at least one fade region to process"):"",onClick:de},[r(f,{name:"material-symbols:graphic-eq-rounded",class:"w-5 h-5","aria-hidden":"true"}),o(" "+n(M(b)?i.$t("Applying Fades..."):i.$t("Apply Fades to All")),1)],8,ka)])]),r(j,{"ffmpeg-loading":M(p)&&!M(y),"ffmpeg-ready":
1M(y),"ffmpeg-percent":M(E),"ffmpeg-stage":M(x),"is-processing":M(b),"processing-percent":M(S),"ffmpeg-log":M(h),"error-message":M(k)},null,8,["ffmpeg-loading","ffmpeg-ready","ffmpeg-percent","ffmpeg-stage","is-processing","processing-percent","ffmpeg-log","error-message"])]),a("div",wa,[r(N,{duration:M(L),"current-time":M(w),peaks:M(P),analyzing:M(p),fades:M(g),curves:M(Q),"format-time-short":M(te),"onUpdate:fade":be,onAddFade:ge,onRemoveFade:pe,onClearFades:fe,onSeek:ye},null,8,["duration","current-time","peaks","analyzing","fades","curves","format-time-short"]),r(_,{modelValue:re.value,"onUpdate:modelValue":u[0]||(u[0]=e=>re.value=e),curves:M(Q)},null,8,["modelValue","curves"]),r(O,{config:M($),"output-formats":M(Z),"sample-rate-presets":M(Y),"bitrate-presets":M(J),onUpdate:xe},null,8,["config","output-formats","sample-rate-presets","bitrate-presets"]),a("div",$a,[a("h2",Ma,[r(f,{name:"material-symbols:info-outline",class:"w-5 h-5 text-blue-700 dark:text-blue-400","aria-hidden":"true"}),o(" "+n(i.$t("Overview")),1)]),a("div",Fa,[a("div",Aa,[a("span",Ca,n(i.$t("Files")),1),a("span",Ea,n(M(C)),1)]),a("div",Sa,[a("span",Ra,n(i.$t("Fade Regions")),1),a("span",La,n(M(g).length),1)]),a("div",Pa,[a("span",Ta,n(i.$t("Reference Duration")),1),a("span",Ua,n(M(te)(M(L))),1)]),a("div",ja,[a("span",za,n(i.$t("Output Format")),1),a("span",Na,n(M($).format),1)]),a("div",_a,[a("span",Oa,n(i.$t("Adjustable Output Volume")),1),a("span",Ia,n(M($).volume)+"%",1)]),a("div",Da,[a("span",Va,n(i.$t("Completed")),1),a("span",Ba,n(M(T))+" / "+n(M(C)),1)])])])])])):s("",!0)])}}};export{qa as default};
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.