PageSourceSearch

https://studioeditor.io/assets/VideoProcess-DJK4v8xa.js

js studioeditor.io collected 2026-10-06 18:09:22 UTC 103,108 bytes, 85 lines download raw bytes

1var Gr=Object.defineProperty;var qr=(t,r,o)=>r in t?Gr(t,r,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[r]=o;var ne=(t,r,o)=>qr(t,typeof r!="symbol"?r+"":r,o);import{E as bt,r as s,j as e,D as Be,a as He,b as Ge,c as qe,d as We,e as Qt,f as Ye,B as W,L as Qe,h as wt,k as Kt,u as k,s as U,o as Wr,A as Yr,p as Qr,q as Kr,v as Jr,w as Zr,x as ea,y as ta,z as ra,C as aa,I as Mt,g as de,M as sa,N as oa,O as Xe,Q as na,R as ia,S as At,U as la,V as ca,i as da,W as Pt,F as ua}from"./index-DoP99lyW.js";import{S as Dt}from"./SEOHead-DD8_AQT4.js";import{u as ma,c as fa,a as pa,b as ha,K as xa,S as It,E as ga,M as va,R as ba,T as wa,W as ya,d as ja,g as Sa,e as Na,i as Ta,j as Ea,k as _a,l as Ca,m as ka,n as Ft,F as Ra,o as Ma,p as Aa,q as Lt,C as Pa,r as Da,s as Ia}from"./MyProjectsPanel-Dwq0b8Th.js";import{P as Fa}from"./ProjectSetupDialog-BEgN1pN4.js";import{u as La,A as Ua}from"./AuthModal-CW9dLByT.js";import{S as $a}from"./StudioEditorWaveBackground-CEyBkJB1.js";import{V as Oa,u as za,F as Va}from"./Projects-1cnm7d6X.js";import{a as Xa,s as Ba,b as Ha,w as Ga,T as qa,c as Wa,r as Ya,l as Qa,d as Ka,e as pt}from"./media-duration-BuXuUxHz.js";import{R as Jt,a as Zt}from"./usePlaybackController-C-Y8DVP4.js";import{D as Ke}from"./download-DuoI3hLh.js";import{f as ht}from"./subscription-tiers-TAnjPr50.js";import{D as Ut,a as $t,b as Ot,c as Ja,d as $e,e as Za,F as es,f as er,A as ts,C as rs,G as as,L as ss,I as os,g as ns,R as is,h as ls,i as cs,S as ds,j as us,k as ms,l as fs,P as ps,m as hs}from"./dropdown-menu-CLaqmHf0.js";import{A as xs}from"./AccountDropdown-DCapx6I7.js";import{C as gs}from"./card-DnnKzh4_.js";import{S as vs}from"./switch-Bf8Uwxoj.js";import{P as tr}from"./progress-B2Muoo-v.js";import{A as rr}from"./arrow-left-DVBawCjI.js";import{C as zt,S as bs,a as ws,b as ys,c as js,d as xt}from"./select-CkyXO985.js";import{S as Vt,T as Ss}from"./triangle-alert-CTWIKtNM.js";import{C as Ns}from"./circle-alert-DMQzFytX.js";import{R as Ts}from"./refresh-cw-C_IlKnYg.js";import{R as ar}from"./scroll-area-CTg5ryCD.js";import{C as Es}from"./chevron-right-BkS_OClq.js";import{C as _s}from"./skeleton-Buy_A8-M.js";import{T as Cs}from"./trash-2-C1bRfcgy.js";import{U as ks}from"./upload-DZELKTq5.js";import{F as Rs}from"./FileUpload-CrL4Gna2.js";import{C as Ms}from"./circle-check-BOnjXo4t.js";import{S as Xt}from"./sparkles-BFSabei0.js";import{C as As}from"./captions-Hnq_I39n.js";import"./supported-formats-B-MrtbO_.js";import"./scissors-B9By3ECd.js";import"./recording-media-B94LVhnX.js";import"./EpisodeSummaryDialog-vhQ7Oyy4.js";import"./copy-CbmELz0K.js";import"./LanguageSelector-Ut1Sde2M.js";import"./search-DQ6bIU8Y.js";import"./popover-D8Z48UnK.js";import"./audio-slice-BRJV2CCY.js";import"./rhythm-edit-40qtxofj.js";import"./mic-C7GVOl89.js";import"./plus-B497et9r.js";import"./zap-vo5_rN_l.js";import"./AudioContext-DjKfL9kR.js";import"./usePodcastProcessing-D2-AtFbN.js";import"./badge-Ca-qhLZ9.js";import"./tabs-BSSQtE4B.js";import"./index-DllM-jzo.js";import"./index-CdOc2iml.js";import"./useUpgradePlan-CsGyHAZq.js";import"./edge-function-error-_fwFW5E8.js";import"./free-tool-audio-CHrJe42i.js";import"./wand-sparkles-BoyqFEjo.js";import"./circle-check-big-BIa3Smis.js";import"./external-link-CEGw9DTQ.js";import"./index-BdQq_4o_.js";import"./jszip.min-Cs8iQ98g.js";import"./credit-card-BOXkQ0w8.js";/**
2 * @license lucide-react v0.462.0 - ISC
3 *
4 * This source code is licensed under the ISC license.
5 * See the LICENSE file in the root directory of this source tree.
6 */const Ps=bt("Clock",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["polyline",{points:"12 6 12 12 16 14",key:"68esgv"}]]);/**
7 * @license lucide-react v0.462.0 - ISC
8 *
9 * This source code is licensed under the ISC license.
10 * See the LICENSE file in the root directory of this source tree.
11 */const Ds=bt("FilePlus",[["path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z",key:"1rqfz7"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"M9 15h6",key:"cctwl0"}],["path",{d:"M12 18v-6",key:"17g6i2"}]]);/**
12 * @license lucide-react v0.462.0 - ISC
13 *
14 * This source code is licensed under the ISC license.
15 * See the LICENSE file in the root directory of this source tree.
16 */const Is=bt("FileVideo",[["path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z",key:"1rqfz7"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"m10 11 5 3-5 3v-6Z",key:"7ntvm4"}]]),Fs=[{value:"480p",label:"SD",resolution:"854 × 480",description:"Smaller file, good for previews and quick sharing.",mbPerMinute:8},{value:"720p",label:"HD",resolution:"1280 × 720",description:"Balanced quality and file size. Recommended for most uses.",mbPerMinute:18},{value:"1080p",label:"Full HD",resolution:"1920 × 1080",description:"Highest quality, larger file. Best for final delivery.",mbPerMinute:35}
16],Ls=t=>t<1?"< 1 MB":t>=1024?`~${(t/1024).toFixed(1)} GB`:`~${Math.round(t)} MB`;function Us({open:t,onOpenChange:r,onDownload:o,isDownloading:a=!1,downloadProgress:i=0,durationSeconds:h=0}){const[u,v]=s.useState("1080p"),b=h/60,D=()=>{o(u)};return e.jsx(Be,{open:t,onOpenChange:r,children:e.jsxs(He,{className:"sm:max-w-md bg-card border-border",children:[e.jsxs(Ge,{children:[e.jsxs(qe,{className:"flex items-center gap-2 text-foreground",children:[e.jsx(Oa,{className:"w-5 h-5 text-primary"}),"Download MP4"]}),e.jsx(We,{className:"text-muted-foreground",children:"Choose the video quality for your download."})]}),e.jsx(Jt,{value:u,onValueChange:d=>v(d),className:"grid gap-3 py-4",children:Fs.map(d=>{const S=b>0?Ls(b*d.mbPerMinute):d.label;return e.jsxs("div",{className:"relative",children:[e.jsx(Zt,{value:d.value,id:`quality-${d.value}`,className:"peer sr-only"}),e.jsxs(Qt,{htmlFor:`quality-${d.value}`,className:"flex items-start gap-4 rounded-lg border-2 border-border bg-background/50 p-4 cursor-pointer hover:bg-accent/10 peer-data-[state=checked]:border-primary peer-data-[state=checked]:bg-primary/5 transition-all",children:[e.jsxs("div",{className:"flex flex-col items-center justify-center min-w-[56px] rounded-md bg-muted/40 px-2 py-1.5",children:[e.jsx("span",{className:"text-sm font-semibold text-foreground leading-none",children:d.value}),e.jsx("span",{className:"text-[10px] text-muted-foreground mt-1",children:d.label})]}),e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("span",{className:"font-semibold text-foreground",children:["MP4 · ",d.resolution]}),e.jsx("span",{className:"text-sm text-muted-foreground",children:S})]}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:d.description})]})]})]},d.value)})}),e.jsxs(Ye,{children:[e.jsx(W,{variant:"outline",onClick:()=>r(!1),disabled:a,children:"Cancel"}),e.jsx(W,{onClick:D,disabled:a,className:"min-w-[140px]",children:a?e.jsxs(e.Fragment,{children:[e.jsx(Qe,{className:"w-4 h-4 mr-2 animate-spin"}),i>0?`${Math.round(i)}%`:"Rendering…"]}):e.jsxs(e.Fragment,{children:[e.jsx(Ke,{className:"w-4 h-4 mr-2"}),"Download MP4"]})})]})]})})}function $s(t){var r;return t?t.localMedia.some(o=>o.bucketId==="local-session")||(r=t.videoSlices)!=null&&r.some(o=>(o==null?void 0:o.bucketId)==="local-session")?!0:t.slices.some(o=>o.bucketId==="local-session"):!1}function Os(){var Rt;const t=wt(),[r]=Kt(),o=r.get("type"),a=o==="transcription",i=r.get("podcast"),h=r.get("edit")==="true";r.get("new");const[u,v]=s.useState(!1),[b,D]=s.useState([]),[d,S]=s.useState(null),[g,A]=s.useState(["youtube"]),[j,L]=s.useState(!1),[B,p]=s.useState({singleSpeaker:!1,isolateSpeech:!1,denoise:!0,denoiseMethod:"dynamic",denoiseAmount:70,dehum:!0,dehumAmount:60,dereverb:!1,dereverbAmount:30,normloudness:!0,backgroundSuppression:!1,suppressionLevel:"medium",hipfilter:!0,leveler:!0,vocalQuality:"autoeq_natural",masterMix:100,denoiseMix:100,dehumMix:100,dereverbMix:100,normloudnessMix:100,suppressionMix:100,hipfilterMix:100,autoReframe:!1,reframeMode:"face"});s.useState(!1);const[x,R]=s.useState(i),[I,T]=s.useState(()=>!!(i&&h)||!i),[w,$]=s.useState(""),[X,l]=s.useState(!1),[_,c]=s.useState(!1),[y,m]=s.useState(""),f=s.useRef(null),F=s.useCallback((n="")=>{var E;return(E=f.current)==null||E.call(f,null),m(n),c(!0),new Promise(H=>{f.current=H})},[]),[z,J]=s.useState(!1),[se,re]=s.useState(!1),[ee,ae]=s.useState(!1),[Y,te]=s.useState(!1),[ie,ue]=s.useState(""),[Oe,Pe]=s.useState(!1),[we,me]=s.useState(!1),[Ee,_e]=s.useState(!1),[nt,Je]=s.useState(!1);s.useState(!1);const[ze,Ve]=s.useState("upload"),[jt,ve]=s.useState(null),[it,De]=s.useState(!1),[ye,Ze]=s.useState(""),[lt,Ce]=s.useState(!1),[et,ke]=s.useState(""),[je,Re]=s.useState([]),Me=s.useRef(null),Se=s.useRef(null),Ie=s.useRef(i),Fe=s.useRef(i??"guest"),[N,P]=s.useState(!1),[V,Q]=s.useState(!1),[Z,le]=s.useState(!1),be=ma(),he=s.useRef(null),ce=s.useRef(null),Le=s.useRef(null),ct=s.useRef(!1),St=s.useCallback(()=>{if(he.current){he.current();return}k.error("Editor not ready. Please wait for the editor to load, then try again.")},[]);s.useEffect(()=>{},[z]),s.useState(!1);const{progress:Nt,status:dt,isProcessing:Ho,errorMessage:Tt,isReadyForClientProcessing:Go,updateClientProgress:qo,completeProcessing:Wo,failProcessing:Yo,resetError:Mr}=fa(x),fe=pa();ha(b.length>0?b[0]:null);const{requireAuth:tt,isModalOpen:Ar,closeModal:Pr,onAuthSuccess:Dr,isAuthenticated:Ae}=La(),[Ir,ut]=s.useState(void 0),{showPopup:Et,setShowPopup:_t,quota:Ne,isFirstTimeUser:Ct,setIsFirstTimeUser:Fr}=za();s.useEffect(()=>{},[o]),s.useEffect(()=>{I&&we&&me(!1)},[I,we]);const Lr=fe.isWhitelisted||fe.limitSeconds===1/0||fe.limitSeconds>=999999999;s.useEffect(()=>{U.auth.getUser().then(({data:{user:n}})=>{if(n){const E=Wr(n)||n.email||"";$(E)}})},[]);const mt=s.useCallback(async(n,E,H)=>{try{const{data:{user:M}}=await U.auth.getUser();if(!M){ve("auth_required"),v(!1);return}const C=(n||"").trim();if(!C){k.error("Please name your project before saving"),v(!1);return}const O=o==="video"?"video":"audio",q=H==="auto"?null:H,K={user_id:M.id,podcast_name:C,title:C,original_filename:"",status:"pending",media_type:O,platform:E||"youtube",language:q},{data:G,error:oe}=await U.from("podcasts").insert(K).select().single();if(oe||!G){console.error("[Process] Failed to create empty project:",oe),k.error("Failed to create project"),v(!1);return}t(`${o==="video"?"/video":"/"}?type=${o??"audio"}&podcast=${G.id}&edit=true`,{replace:!0}),R(G.id),T(!0),v(!1)}catch(M){console.error("[Process] Error creating empty project:",M),k.error("Failed to create project"),v(!1)}},[o,t]),Ur=s.useCallback(async()=>{var n,E;try{const{data:{user:H}}=await U.auth.getUser();if(!H)return k.error("Please log in first"),null;if(x)return x;let M=(ie||"").trim()||((E=(n=b[0])==null?void 0:n.name)==null?void 0:E.replace(/\.[^/.]+$/,"").trim())||"";if(!M){const K=await F("");if(!K)return null;M=K,ue(K)}const C={user_id:H.id,podcast_name:M,title:M,original_filename:"",status:"pending",media_type:o==="video"?"video":"audio",platform:g[0]||"youtube",language:d||null},{data:O,error:q}=await U.from("podcasts").insert(C).select().single();return q||!O?(console.error("[Process] handleEnsureProject failed:",q),k.error("Failed to create project"),null):(Se.current=O.
16id,R(O.id),t(`${o==="video"?"/video":"/"}?type=${o??"audio"}&podcast=${O.id}&edit=true`,{replace:!0}),O.id)}catch(H){return console.error("[Process] handleEnsureProject error:",H),k.error("Failed to create project"),null}},[x,ie,b,g,d,o,t,F]);s.useEffect(()=>{var M;const n=r.get("podcast"),E=r.get("edit")==="true";if(r.get("new")==="true"&&!n){const C=((M=r.get("project"))==null?void 0:M.trim())||"",O=r.get("platform")||"",q=r.get("lang");if(O&&A([O]),S(q),!C){(async()=>{const K=await F("");if(!K){t("/projects",{replace:!0});return}ue(K),mt(K,O,q)})();return}ue(C),mt(C,O,q);return}if(n){if(R(n),E){T(!0);return}(async()=>{try{const{data:C}=await U.from("processing_jobs").select("status, progress, error_message").eq("podcast_id",n).maybeSingle();(C==null?void 0:C.status)==="completed"&&(C==null?void 0:C.progress)===100?T(!0):(C==null||C.status,T(!1))}catch{T(!1)}})();return}R(null),T(!0),D([]),S(null),A(["youtube"])},[r]),s.useEffect(()=>{x&&(async()=>{const{data:n}=await U.from("podcasts").select("platforms, platform, media_type, title").eq("id",x).single();if(n){if(n.title&&ue(n.title),n.platforms&&Array.isArray(n.platforms)&&n.platforms.length>0)n.media_type!=="video"&&A(n.platforms);else if(n.platform){const E=[n.platform];n.media_type!=="video"&&A(E),await U.from("podcasts").update({platforms:E}).eq("id",x)}}})()},[x]),s.useEffect(()=>{b.length===0?Ve("upload"):Ve("ready_for_setup")},[b]);const ft=()=>{R(null),T(!0),ct.current=!1,D([]),S(null),A(["youtube"]),L(!1),Pe(!1),ue(""),t(o==="video"?"/video?type=video":`/?type=${o??"audio"}`,{replace:!0})},$r=()=>{l(!1),ft(),m(""),c(!0)},Or=()=>{const n=y.trim();if(n){if(c(!1),m(""),f.current){const E=f.current;f.current=null,E(n);return}tt(async()=>{ft(),await mt(n,g[0],d)})}},zr=async n=>{ve(null),me(!0);const E=(n==null?void 0:n.projectName)??ie,H=(n==null?void 0:n.language)??d;n==null||n.skipTranscription;try{const{data:{user:M}}=await U.auth.getUser();if(!M){ve("account_error"),k.error("Please log in to continue."),me(!1);return}if(!M.email_confirmed_at){ve("email_unverified"),k.error("Please verify your email first."),me(!1);return}if(fe.error||fe.isQuotaExceeded){ve(fe.error?"missing_quota":"no_minutes"),k.error("Account setup issue. Please refresh and try again."),me(!1);return}if(await U.functions.invoke("account-actions",{body:{action:"ensureQuota"}}),b.length===0){k.error("Please upload a file."),me(!1);return}const C=o==="audio"||!o;let O=B;n!=null&&n.skipLeveling&&C&&(O={...B,normloudness:!1,leveler:!1},p(O));const q=E.trim();if(!q){k.error("Please name your project before continuing"),me(!1);return}const K={user_id:M.id,podcast_name:q,title:q,original_filename:b[0].name,language:H,platform:((n==null?void 0:n.platforms)??g)[0]||"youtube",platforms:(n==null?void 0:n.platforms)??g,status:"pending",enhancement_settings:O,media_type:"audio"},{data:G,error:oe}=await U.from("podcasts").insert(K).select().single();if(oe||!G)throw new Error(`Failed to create podcast: ${oe==null?void 0:oe.message}`);R(G.id),k.success(`Project created: "${G.title}"`);const xe=b[0],Te=`${M.id}/${Date.now()}_${xe.name}`,{error:ge}=await U.storage.from("podcast-uploads").upload(Te,xe);if(ge)throw new Error(`Failed to upload: ${ge.message}`);await U.from("audio_files").insert({podcast_id:G.id,file_type:"original",storage_path:Te,file_size:xe.size}),t(`${o==="video"?"/video":"/"}?type=${o??"audio"}&podcast=${G.id}&edit=true`,{replace:!0}),T(!0),me(!1)}catch(M){console.error("❌ [CONTINUE] Error:",M),k.error(M instanceof Error?M.message:"Failed to prepare editor"),me(!1)}},Vr=async n=>{te(!0),ve(null);try{const{data:{user:E}}=await U.auth.getUser();if(!E){ve("account_error"),k.error("Please log in."),te(!1);return}if(!E.email_confirmed_at){ve("email_unverified"),k.error("Please verify your email."),te(!1);return}const H=await Ya(n.file);await U.functions.invoke("account-actions",{body:{action:"ensureQuota"}});const M={user_id:E.id,podcast_name:n.projectName.trim()||null,title:n.projectName.trim()||`Transcription ${new Date().toLocaleDateString()}`,original_filename:n.file.name,language:n.sourceLanguage,platform:"youtube",source_language:n.sourceLanguage,output_language:n.outputLanguage,is_enhanced_for_transcription:n.enhanceBeforeTranscription,status:"pending",media_type:n.file.type.startsWith("video/")?"video":"audio"},{data:C,error:O}=await U.from("podcasts").insert(M).select().single();if(O||!C)throw new Error(`Failed to create project: ${O==null?void 0:O.message}`);R(C.id);const q=`${E.id}/${Date.now()}_${n.file.name}`,{error:K}=await U.storage.from("podcast-uploads").upload(q,n.file);if(K)throw new Error(`Failed to upload: ${K.message}`);await U.from("audio_files").insert({podcast_id:C.id,file_type:"original",storage_path:q,file_size:n.file.size,duration:H}),await U.from("processing_jobs").insert({podcast_id:C.id,status:"pending",progress:0});let G=q;if(n.enhanceBeforeTranscription){const{data:xe,error:Te}=await U.functions.invoke("enhance-audio",{body:{podcastId:C.id,storagePath:q,settings:{denoise:!0,denoiseAmount:70,dehum:!0,dehumAmount:60,normloudne
16ss:!0,leveler:!0}}});!Te&&(xe!=null&&xe.processedPath)&&(G=xe.processedPath)}const{error:oe}=await U.functions.invoke("transcribe-audio",{body:{podcastId:C.id,storagePath:G,language:n.sourceLanguage,targetLanguage:n.outputLanguage,speakerLabels:n.separateSpeakers!==!1,durationSeconds:H}});if(oe)throw new Error(`Transcription failed: ${oe.message}`);n.outputLanguage&&n.outputLanguage!==n.sourceLanguage&&await U.functions.invoke("translate-transcription",{body:{podcastId:C.id,sourceLanguage:n.sourceLanguage,targetLanguage:n.outputLanguage}}),await U.functions.invoke("update-processing-job",{body:{podcastId:C.id,status:"completed",progress:100}}),k.success("Transcription ready!"),ae(!1),te(!1),t(`/?type=transcription&podcast=${C.id}&edit=true`,{replace:!0}),T(!0)}catch(E){console.error("❌ [TEXT TOOL] Error:",E),k.error(E instanceof Error?E.message:"Failed to process"),te(!1)}};s.useEffect(()=>{if(a&&!x&&!I&&!ee){const n=setTimeout(()=>ae(!0),100);return()=>clearTimeout(n)}},[a,x,I,ee]);const Xr=s.useCallback(async()=>{if(!x){k.error("No project loaded");return}const n=await Xa(Ba(ie||"transcription"));if(n.kind!=="cancelled"){Q(!0);try{const{data:E,error:H}=await U.from("transcriptions").select("content, word_timestamps").eq("podcast_id",x).maybeSingle();if(H)throw H;if(!(E!=null&&E.content)&&!(E!=null&&E.word_timestamps)){k.error("No transcription found for this project");return}const M=await Ha({content:E.content,wordTimestamps:E.word_timestamps}),C=await Ga(M,n);C==="saved"?k.success("PDF saved"):C==="downloaded"&&k.success("PDF download started")}catch(E){console.error("[Process] PDF transcription export failed:",E),k.error("Failed to export transcription")}finally{Q(!1)}}},[x,ie]),kt=async()=>{var n;if(!ye.trim()){k.error("Please enter a name");return}try{const{data:{user:E}}=await U.auth.getUser();if(!E){k.error("Please log in");return}if(!x){k.error("No project loaded");return}if(ce.current)try{await ce.current()}catch{k.error("Failed to save current state");return}const H=(n=Le.current)==null?void 0:n.call(Le);if($s(H)){k.error("Please save once more after media finishes attaching to the project.");return}const{data:M}=await U.from("podcasts").select("*").eq("id",x).single();if(!M){k.error("Project not found");return}const C={user_id:E.id,podcast_name:ye.trim(),title:ye.trim(),original_filename:M.original_filename,status:M.status,media_type:M.media_type,platform:M.platform,language:M.language,enhancement_settings:M.enhancement_settings,platforms:M.platforms,playback_source:M.playback_source,information:M.information,episode_number:M.episode_number,episode_name:M.episode_name,is_public:M.is_public,audio_slices:M.audio_slices,audio_tracks:M.audio_tracks,video_slices:M.video_slices},{data:O,error:q}=await U.from("podcasts").insert(C).select().single();if(q||!O){k.error("Failed to duplicate project");return}const[{data:K,error:G},{data:oe,error:xe}]=await Promise.all([U.from("audio_files").select("storage_path, file_type, file_size, duration, peaks_data, enhancement_stats").eq("podcast_id",x),U.from("user_jingles").select("*").eq("podcast_id",x)]);if(G)console.error("[VideoProcess] Failed to copy audio files for Save As:",G),k.error("Project copy created, but its media could not be attached");else if(K&&K.length>0){const Te=K.map(Ue=>({podcast_id:O.id,storage_path:Ue.storage_path,file_type:Ue.file_type,file_size:Ue.file_size,duration:Ue.duration,peaks_data:Ue.peaks_data,enhancement_stats:Ue.enhancement_stats})),{error:ge}=await U.from("audio_files").insert(Te);ge&&(console.error("[VideoProcess] Failed to insert copied audio files:",ge),k.error("Project copy created, but its media could not be attached"))}if(xe&&console.error("[VideoProcess] Failed to copy jingles for Save As:",xe),oe&&oe.length>0){const Te=oe.map(ge=>({user_id:E.id,podcast_id:O.id,name:ge.name,storage_path:ge.storage_path,duration:ge.duration,original_filename:ge.original_filename,bucket_id:ge.bucket_id}));await U.from("user_jingles").insert(Te)}R(O.id),ue(ye.trim()),De(!1),k.success(`Project saved as "${ye.trim()}"`),t(`${o==="video"?"/video":"/"}?type=${o??"audio"}&podcast=${O.id}&edit=true`)}catch(E){console.error("[VideoProcess] Save As failed:",E),k.error("Failed to duplicate")}},Br=async()=>
16{if(x){Pe(!0),Mr();try{const{data:n,error:E}=await U.from("podcasts").select("*").eq("id",x).single();if(E||!n)throw new Error("Failed to fetch podcast data");const{data:H,error:M}=await U.from("audio_files").select("storage_path").eq("podcast_id",x).eq("file_type","original").single();if(M||!H)throw new Error("Failed to fetch original file");await U.functions.invoke("update-processing-job",{body:{podcastId:x,status:"pending",progress:0}});const{data:C,error:O}=await U.functions.invoke("process-podcast",{body:{podcastId:x,language:n.language,platform:n.platform,enhancements:n.enhancement_settings,skipTranscription:!1,skipEnhancement:!1,transcriptionStoragePath:H.storage_path}});if(O||C!=null&&C.error){const q=C==null?void 0:C.code,K=(C==null?void 0:C.error)||(O==null?void 0:O.message)||"Processing failed";throw q==="ENHANCEMENT_CREDITS_EXCEEDED"?new Error("Audio enhancement service temporarily unavailable."):new Error(K)}k.success("Retrying processing...")}catch(n){console.error("❌ [RETRY] Error:",n),k.error(n instanceof Error?n.message:"Failed to retry"),Pe(!1)}}};s.useEffect(()=>{ct.current||dt==="completed"&&Nt===100&&(ct.current=!0,T(!0),Pe(!1),Je(!1),k.success("Processing complete!"))},[dt,Nt]),x!==Ie.current&&(Ie.current===null&&x!==null&&Se.current===x||(Fe.current=x??"guest",Se.current!==x&&(Se.current=null)),Ie.current=x);const Hr=Fe.current;return e.jsxs("div",{className:"editor-workbench relative isolate min-h-screen overflow-hidden bg-black flex flex-col",children:[e.jsx($a,{className:"fixed inset-0 z-0 opacity-100"}),(we||u)&&e.jsx("div",{className:"fixed inset-0 z-[100] bg-black flex items-center justify-center",children:e.jsxs("div",{className:"flex flex-col items-center gap-4",children:[e.jsx(Qe,{className:"w-8 h-8 text-white animate-spin"}),e.jsx("span",{className:"text-white text-sm font-medium",children:"Preparing Editor..."})]})}),e.jsx("header",{className:"sticky top-0 z-50 h-16 bg-[hsl(215_30%_8%/0.72)] backdrop-blur-md border-b border-white/[0.10]",children:e.jsxs("div",{className:"h-full px-8 flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(W,{variant:"ghost",size:"sm",className:"h-8 w-8 p-0 rounded-md",onClick:()=>t("/video"),title:"Back to editor selection","aria-label":"Back to editor selection",children:e.jsx(rr,{className:"h-4 w-4"})}),e.jsx("h1",{className:"text-xl font-bold tracking-tight text-foreground",style:{fontFamily:"'Montserrat', sans-serif"},children:e.jsx(Yr,{})}),I&&ie&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-muted-foreground/50",children:"/"}),e.jsx("span",{className:"text-sm font-medium text-muted-foreground truncate max-w-[200px]",title:ie,children:ie})]})]}),e.jsxs("div",{className:"flex items-center gap-4",children:[!fe.isLoading&&!fe.isWhitelisted&&fe.percentUsed>50&&e.jsx("div",{className:"hidden md:flex items-center gap-3 px-4 py-2 rounded-lg bg-muted border border-border",children:e.jsxs("div",{className:"flex flex-col gap-1 min-w-[140px]",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:"VIDEO"}),e.jsxs("span",{className:`text-xs font-medium ${fe.isQuotaExceeded?"text-destructive":"text-foreground"}`,children:[ht(Math.floor(fe.minutesUsed))," / ",ht(Math.floor(fe.minutesLimit??0))]})]}),e.jsx(tr,{value:fe.percentUsed,className:"h-1.5"})]})}),e.jsx(xa,{}),Ae&&e.jsxs(W,{variant:"ghost",size:"sm",className:"h-8 px-3 text-xs",disabled:!x,onClick:()=>Ce(!0),children:[e.jsx(It,{className:"w-3.5 h-3.5 mr-1.5"}),"My Notes"]}),Ae?e.jsxs(Ut,{children:[e.jsx($t,{asChild:!0,children:e.jsxs(W,{variant:"ghost",size:"sm",className:"h-8 px-3 text-xs",children:[e.jsx(Ke,{className:"w-3.5 h-3.5 mr-1.5"}),"Export",e.jsx(zt,{className:"w-3 h-3 ml-1 opacity-60"})]})}),e.jsxs(Ot,{align:"end",className:"z-50 bg-background border w-64",children:[e.jsx(Ja,{className:"text-[10px] text-muted-foreground",children:"Export Type"}),o==="audio"||!o?e.jsxs(e.Fragment,{children:[e.jsx($e,{onClick:St,children:"Audio"}),e.jsx($e,{onClick:()=>P(!0),children:"Transcription"})]}):e.jsxs(e.Fragment,{children:[e.jsx($e,{onClick:()=>le(!0),children:"Video with Audio"}),e.jsx($e,{onClick:St,children:"Audio Only"}),e.jsx($e,{onClick:()=>P(!0),children:"Transcription"})]})]})]}):e.jsxs(W,{variant:"ghost",size:"sm",className:"h-8 px-3 text-xs",onClick:()=>{ut("Sign up to export your project"),tt(()=>{})},children:[e.jsx(Ke,{className:"w-3.5 h-3.5 mr-1.5"}),"Export"]}),Ae?e.jsxs("div",{className:"flex items-center",children:[e.jsxs(W,{variant:"ghost",size:"sm",className:"h-8 px-3 text-xs rounded-r-none",disabled:Ee,onClick:async()=>{var E,H;if(Ee)return;_e(!0);const n=k.loading(x?"Saving project…":"Creating project…");try{if(x){if(ce.current)try{await ce.current()}catch(M){console.error("[VideoProcess] Timeline save failed:",M),k.error("Failed to save project",{id:n});return}else await U.from("podcasts").update({updated_at:new Date().toISOString()}).eq("id",x);k.success("Project saved",{id:n})}else{const{data:{user:M}}=await U.auth.getUser();if(!M){k.error("Please log in to save");return}let C=(ie==null?void 0:ie.trim())||((H=(E=b[0])==null?void 0:E.name)==null?void 0:H.replace(/\.[^/.]+$/,"").trim())||"";if(!C){const G=await F("");if(!G)return;C=G,ue(G)}const O=d==="auto"?null:d,{data:q,error:K}
16=await U.from("podcasts").insert({user_id:M.id,podcast_name:C,title:C,original_filename:"",status:"pending",media_type:o==="video"?"video":"audio",platform:(g==null?void 0:g[0])||"youtube",platforms:g||["youtube"],language:O}).select().single();if(K||!q)throw K||new Error("Insert failed");Se.current=q.id,R(q.id),k.success("Project created. Attaching timeline media…",{id:n}),t(`${o==="video"?"/video":"/"}?type=${o??"audio"}&podcast=${q.id}&edit=true`,{replace:!0})}}catch(M){console.error("[VideoProcess] Save failed:",M),k.error("Failed to save",{id:n})}finally{_e(!1)}},children:[Ee?e.jsx(Qe,{className:"w-3.5 h-3.5 mr-1.5 animate-spin"}):e.jsx(Vt,{className:"w-3.5 h-3.5 mr-1.5"}),Ee?"Saving…":"Save"]}),e.jsxs(Ut,{children:[e.jsx($t,{asChild:!0,children:e.jsx(W,{variant:"ghost",size:"sm",className:"h-8 px-1.5 rounded-l-none border-l border-border",children:e.jsx(zt,{className:"w-3 h-3 opacity-60"})})}),e.jsxs(Ot,{align:"end",className:"z-50 bg-background border",children:[e.jsx($e,{onClick:async()=>{if(x){const{data:n}=await U.from("podcasts").select("title, podcast_name").eq("id",x).single();Ze(`${(n==null?void 0:n.title)||(n==null?void 0:n.podcast_name)||"Project"} (Copy)`),De(!0)}else re(!0),J(!0)},children:"Save project as"}),e.jsx(Za,{}),e.jsxs("div",{className:"flex items-center justify-between px-2 py-1.5 cursor-pointer hover:bg-accent rounded-sm",onClick:n=>{n.preventDefault(),be.setAutosaveEnabled(!be.autosaveEnabled)},children:[e.jsx("span",{className:"text-sm",children:"Autosave"}),e.jsx(vs,{checked:be.autosaveEnabled,onCheckedChange:be.setAutosaveEnabled,className:"scale-75"})]})]})]})]}):e.jsxs(W,{variant:"ghost",size:"sm",className:"h-8 px-3 text-xs",onClick:()=>{ut("Sign up to save your project"),tt(()=>{})},children:[e.jsx(Vt,{className:"w-3.5 h-3.5 mr-1.5"}),"Save"]}),Ae&&e.jsxs(W,{variant:"ghost",size:"sm",className:"h-8 px-3 text-xs",onClick:()=>{x||b.length>0?l(!0):(m(""),c(!0))},children:[e.jsx(Ds,{className:"w-3.5 h-3.5 mr-1.5"}),"New"]}),Ae&&e.jsx(ga,{isLoading:fe.isLoading,isUnlimited:Lr,remainingCredits:fe.minutesRemaining}),Ae&&e.jsx(va,{mediaType:"video",trigger:e.jsxs(W,{variant:"ghost",size:"sm",className:"gap-1.5 rounded-none border-0 bg-transparent shadow-none hover:bg-transparent",children:[e.jsx(es,{className:"w-4 h-4"}),"My Projects"]})}),Ae?e.jsx(xs,{triggerClassName:"rounded-none border-0 bg-transparent shadow-none hover:bg-transparent data-[state=open]:bg-transparent"}):e.jsx(W,{variant:"outline",size:"sm",onClick:()=>tt(()=>{}),children:"Sign in"})]})]})}),e.jsxs("main",{className:"relative z-10 flex-1 p-0 bg-[transparent]",children:[dt==="failed"&&Tt&&e.jsx(gs,{className:"mb-8 border-destructive/50 bg-destructive/5 max-w-4xl mx-auto",children:e.jsx("div",{className:"p-8",children:e.jsxs("div",{className:"flex items-start gap-6",children:[e.jsx("div",{className:"p-3 rounded-full bg-destructive/10",children:e.jsx(Ns,{className:"w-7 h-7 text-destructive"})}),e.jsxs("div",{className:"flex-1 space-y-3",children:[e.jsx("h3",{className:"text-xl font-semibold text-foreground",children:"Processing Failed"}),e.jsx("p",{className:"text-base text-muted-foreground",children:Tt}),e.jsxs("div",{className:"flex gap-3 pt-3",children:[e.jsx(W,{variant:"default",onClick:Br,disabled:Oe,children:Oe?e.jsxs(e.Fragment,{children:[e.jsx(Qe,{className:"w-4 h-4 mr-2 animate-spin"}),"Retrying..."]}):e.jsxs(e.Fragment,{children:[e.jsx(Ts,{className:"w-4 h-4 mr-2"}),"Retry Processing"]})}),e.jsx(W,{variant:"outline",onClick:ft,disabled:Oe,children:"Start Over"})]})]})]})})}),e.jsx(ba,{podcastId:x,onMarkersChange:Re,onSeekFnReady:n=>{Me.current=n},onFullMixDownloadReady:n=>{he.current=n},onSaveNowReady:n=>{ce.current=n},onPersistableStateReady:n=>{Le.current=n},onEnsureProject:Ur},Hr)]}),e.jsx(Qr,{open:X,onOpenChange:l,children:e.jsxs(Kr,{children:[e.jsxs(Jr,{children:[e.jsx(Zr,{children:"Discard unsaved changes?"}),e.jsx(ea,{children:"You have unsaved form data. Are you sure you want to start a new project?"})]}),e.jsxs(ta,{children:[e.jsx(ra,{children:"Cancel"}),e.jsx(aa,{onClick:$r,children:"Continue"})]})]})}),e.jsx(Fa,{open:z,onOpenChange:n=>{J(n),n||re(!1)},onConfirm:async n=>{if(ue(n.projectName),S(n.language),L(n.skipTranscription),A(n.platforms||[n.platform]),se){J(!1),re(!1);try{const{data:{user:E}}=await U.auth.getUser();if(!E){k.error("Please log in to save");return}const H=n.language==="auto"?null:n.language,M=n.projectName.trim();if(!M){k.error("Please name your project before saving");return}const{data:C,error:O}=await U.from("podcasts").insert({user_id:E.id,podcast_name:M,title:M,original_filename:"",status:"pending",media_type:"video",platform:(n.platforms||[n.platform])[0]||"youtube",platforms:n.platforms||[n.platform],language:H}).select().single();if(O||!C)throw O||new Error("Insert failed");R(C.id),k.success("Project saved"),t(`${o==="video"?"/video":"/"}?type=${o??"video"}&podcast=${C.id}&edit=true`,{replace:!0})}catch(E){console.error("[VideoProcess] Save (create empty project) failed:",E),k.error("Failed to save project")}return}J(!1),zr(n)},workflowType:o==="transcription"?"transcription":"audio",defaultFileName:(Rt=b[0])==null?void 0:Rt.name,isLoading:we,saveMode:se}),e.jsx(wa,{open:ee,onOpenChange:ae,onConfirm:Vr,isLoading:Y}),e.jsx(Ua,{open:Ar,onOpenChange:n=>{n||(Pr(),ut(void 0))},onSuccess:Dr,subtitle:Ir}),e.jsx(Va,{open:Et&&Ct,onClose:()=>{_t(!1),Fr(!1)}}),e.jsx(ya,{open:Et&&!Ct,onClose:()=>_t(!1),remainingCredits:Ne?ht(Math.floor((Ne.limitSeconds-Ne.totalSecondsUsed)/60)):"60 credits",isOutOfMinutes:Ne?Ne.totalSecondsUsed>=Ne.limitSeconds:!1,isUnlimited:Ne?Ne.limitSeconds>=999999999:!1}),e.jsx(Be,{open:it,onOpenChange:De,children:e.jsxs(He,{className:"sm:max-w-md",children:[e.jsxs(Ge,{children:[e.jsx(qe,{children:"Save Project As"}),e.jsx(We,{children:"Enter a name for your new project copy."})]}),e.jsx("div",{className:"py-4",children:e.jsx(Mt,{value:ye,onChange:n=>Ze(n.target.value),placeholder:"Project name",className:"w-full",autoFocus:!0,onKeyDown:n=>{n.key==="Enter"&&(n.preventDefault(),kt())}})}),e.jsxs(Ye,{children:[e.jsx(W,{variant:"outline",onClick:()=>De(!1),children:"Cancel"}),e.jsx(W,{onClick:kt,children:"Save"})]})]})}),e.jsx(Be,{open:lt,onOpenChange:Ce,children:e.jsxs(He,{className:"sm:max-w-lg max-h-[80vh] overflow-hidden flex flex-col",children:[e.jsxs(Ge,{children:[e.jsxs(qe,{className:"flex items-center gap-2",children:[e.jsx(It,{className:"w-5 h-5 text-amber-400"}),"My Notes"]}),e.jsx(We,{children:"Add personal notes for this project."})]}),e.jsxs("div",{className:"py-4 flex-1 overflow-y-auto space-y-4",children:[e.jsx("textarea",{value:et,onChange:n=>ke(n.target.value),placeholder:"Add your notes here...",className:"w-full h-32 px-3 py-2 text-sm bg-muted border border-border rounded-md resize-none focus:outline-none focus:ring-2 focus:ring-primary"}),je.filter(n=>n.notes).length>0&&e.jsxs("div",{className:"border-t border-border pt-3",children:[e.jsxs("h4",{className:"text-xs font-medium text-amber-400 mb-2 flex items-center gap-1.5",children:[e.jsx(Ps,{className:"w-3 h-3"}),"Timeline Markers"]}),e.jsx("div",{className:"space-y-1",children:je.filter(n=>n.notes).sort((n,E)=>n.time-E.time).map(n=>e.jsxs("div",{className:"flex gap-2 py-1.5 text-sm hover:bg-muted/50 rounded px-2 cursor-pointer transition-colors",onClick:()=>{var E;(E=Me.current)==null||E.call(Me,n.time),Ce(!1)},children:[e.jsxs("span",{className:"text-amber-400 font-mono text-xs w-14 flex-shrink-0",children:[Math.floor(n.time/60),":",String(Math.floor(n.time%60)).padStart(2,"0")]}),e.jsx("span",{className:"text-muted-foreground text-xs",children:n.notes})]},n.id))})]})]}),e.jsxs(Ye,{children:[e.jsx(W,{variant:"outline",onClick:()=>Ce(!1),children:"Close"}),e.jsx(W,{onClick:()=>{localStorage.setItem(`project-notes-${x}`,et),k.success("Notes saved"),Ce(!1)},children:"Save Notes"})]})]})}),e.jsx(qa,{open:N,onOpenChange:P,hasCaptions:!0,onDownload:async n=>{if(!x){k.error("No project loaded");return}if(n==="pdf"){await Xr();return}try{const{data:E,error:H}=await U.from("transcriptions").select("content, word_timestamps").eq("podcast_id",x).maybeSingle();if(H)throw H;if(!E){k.error("No transcription found — transcribe speech first");return}const M=E.word_timestamps;let C=[];if(M&&typeof M=="object"&&!Array.isArray(M)&&"words"in M?C=M.words||[]:Array.isArray(M)&&(C=M),n==="srt"){if(!C.length){k.error("No word timestamps — transcribe speech first");return}ja(Sa(C),`${ie}.srt`)}else if(n==="vtt"){if(!C.length){k.error("No word timestamps — transcribe speech first");return}Na(Ta(C),`${ie}.vtt`)}else if(n==="txt"){const O=C.length>0?C.map(oe=>oe.word).join(" "):E.content,q=new Blob([O],{type:"text/plain;charset=utf-8"}),K=URL.createObjectURL(q),G=document.createElement("a");G.href=K,G.download=`${ie}.txt`,document.body.appendChild(G),G.click(),document.body.removeChild(G),URL.revokeObjectURL(K)}else if(n==="docx"){const O=C.length>0?C.map(oe=>oe.word).join(" "):E.content,q=await Wa({content:O||""}),K=URL.createObjectURL(q),G=document.createElement("a");G.href=K,G.download=`${ie}.docx`,document.body.appendChild(G),G.click(),document.body.removeChild(G),window.setTimeout(()=>URL.revokeObjectURL(K),1e3)}k.success(`${n.toUpperCase()} downloaded`)}catch(E){console.error("[Process] Transcription download failed:",E),k.error("Failed to download transcription")}}}),e.jsx(Us,{open:Z,onOpenChange:le,onDownload:n=>{he.current?(he.current(),k.success(`Preparing MP4 (${n})…`)):k.error("Editor not ready. Please wait for the editor to load, then try again."),le(!1)}}),e.jsx(Be,{open:_,onOpenChange:n=>{if(c(n),!n&&f.current){const E=f.current;f.current=null,E(null)}},children:e.jsxs(He,{className:"sm:max-w-md",children:[e.jsxs(Ge,{children:[e.jsx(qe,{children:"Name your project"}),e.jsx(We,{children:"A project name is required before it can be saved."})]}),e.jsxs("form",{onSubmit:n=>{n.preventDefault(),Or()},children:[e.jsx(Mt,{autoFocus:!0,placeholder:"My Podcast Episode",value:y,onChange:n=>m(n.target.value),className:"mb-4 focus-visible:border-white/40 focus-visible:ring-0 focus-visible:ring-offset-0"}),e.jsxs(Ye,{children:[e.jsx(W,{type:"button",variant:"ghost",onClick:()=>
16{if(c(!1),f.current){const n=f.current;f.current=null,n(null)}},children:"Cancel"}),e.jsx(W,{type:"submit",disabled:!y.trim(),children:"Save project"})]})]})]})})]})}const zs=`#version 300 es
17in vec2 a_pos;
18in vec2 a_uv;
19out vec2 v_uv;
20uniform vec2 u_uvOffset;
21uniform vec2 u_uvScale;
22uniform vec2 u_shake;
23void main() {
24  v_uv = u_uvOffset + (a_uv * u_uvScale);
25  gl_Position = vec4(a_pos + u_shake, 0.0, 1.0);
26}`,Vs=`#version 300 es
27precision highp float;
28in vec2 v_uv;
29out vec4 outColor;
30uniform sampler2D u_video;
31uniform sampler2D u_overlay;
32uniform float u_blur;        // pixel radius
33uniform vec2 u_texel;        // 1/size
34uniform float u_overlayAlpha;
35uniform vec4 u_colorAdjust;  // brightness, contrast, saturation, hueDegrees
36uniform float u_sepia;
37
38vec3 hueRotate(vec3 color, float degrees) {
39  float angle = radians(degrees);
40  float s = sin(angle);
41  float c = cos(angle);
42  mat3 m = mat3(
43    0.213 + c * 0.787 - s * 0.213, 0.715 - c * 0.715 - s * 0.715, 0.072 - c * 0.072 + s * 0.928,
44    0.213 - c * 0.213 + s * 0.143, 0.715 + c * 0.285 + s * 0.140, 0.072 - c * 0.072 - s * 0.283,
45    0.213 - c * 0.213 - s * 0.787, 0.715 - c * 0.715 + s * 0.715, 0.072 + c * 0.928 + s * 0.072
46  );
47  return clamp(m * color, 0.0, 1.0);
48}
49
50vec3 applyAutoColor(vec3 color) {
51  color *= u_colorAdjust.x;
52  color = (color - 0.5) * u_colorAdjust.y + 0.5;
53  float luma = dot(color, vec3(0.2126, 0.7152, 0.0722));
54  color = mix(vec3(luma), color, u_colorAdjust.z);
55  color = hueRotate(color, u_colorAdjust.w);
56  vec3 sepiaColor = vec3(
57    dot(color, vec3(0.393, 0.769, 0.189)),
58    dot(color, vec3(0.349, 0.686, 0.168)),
59    dot(color, vec3(0.272, 0.534, 0.131))
60  );
61  return clamp(mix(color, sepiaColor, u_sepia), 0.0, 1.0);
62}
63
64vec4 blur5(sampler2D tex, vec2 uv, vec2 texel, float radius) {
65  vec4 sum = vec4(0.0);
66  float total = 0.0;
67  for (int x = -2; x <= 2; x++) {
68    for (int y = -2; y <= 2; y++) {
69      float w = exp(-float(x*x + y*y) * 0.5);
70      sum += texture(tex, uv + vec2(float(x), float(y)) * texel * radius) * w;
71      total += w;
72    }
73  }
74  return sum / total;
75}
76
77void main() {
78  vec4 base = u_blur > 0.5
79    ? blur5(u_video, v_uv, u_texel, u_blur)
80    : texture(u_video, v_uv);
81  base.rgb = applyAutoColor(base.rgb);
82  vec4 ov = texture(u_overlay, vec2(v_uv.x, 1.0 - v_uv.y));
83  outColor = mix(base, ov, ov.a * u_overlayAlpha);
84}`;function Bt(t,r,o){const a=t.createShader(r);if(t.shaderSource(a,o),t.compileShader(a),!t.getShaderParameter(a,t.COMPILE_STATUS)){const i=t.getShaderInfoLog(a);throw t.deleteShader(a),new Error(`Shader compile error: ${i}`)}return a}function Xs(t){const r=Bt(t,t.VERTEX_SHADER,zs),o=Bt(t,t.FRAGMENT_SHADER,Vs),a=t.createProgram();if(t.attachShader(a,r),t.attachShader(a,o),t.linkProgram(a),!t.getProgramParameter(a,t.LINK_STATUS))throw new Error(`Program link error: ${t.getProgramInfoLog(a)}`);return{program:a,attribs:{a_pos:t.getAttribLocation(a,"a_pos"),a_uv:t.getAttribLocation(a,"a_uv")},uniforms:{u_video:t.getUniformLocation(a,"u_video"),u_overlay:t.getUniformLocation(a,"u_overlay"),u_uvOffset:t.getUniformLocation(a,"u_uvOffset"),u_uvScale:t.getUniformLocation(a,"u_uvScale"),u_shake:t.getUniformLocation(a,"u_shake"),u_blur:t.getUniformLocation(a,"u_blur"),u_texel:t.getUniformLocation(a,"u_texel"),u_overlayAlpha:t.getUniformLocation(a,"u_overlayAlpha"),u_colorAdjust:t.getUniformLocation(a,"u_colorAdjust"),u_sepia:t.getUniformLocation(a,"u_sepia")}}}class Bs{constructor(r,o){ne(this,"gl");ne(this,"shader");ne(this,"vao");ne(this,"videoTex");ne(this,"overlayTex");ne(this,"overlayCanvas");ne(this,"overlayCtx");ne(this,"rafId",null);ne(this,"videoFrameCallbackId",null);ne(this,"freezeFrame",null);ne(this,"freezeFrameCtx",null);ne(this,"videoTextureWidth",0);ne(this,"videoTextureHeight",0);ne(this,"overlayHadContent",!1);ne(this,"overlaySignature","");ne(this,"getState");ne(this,"destroyed",!1);const a=r.getContext("webgl2",{premultipliedAlpha:!1,antialias:!0});if(!a)throw new Error("WebGL2 not supported");this.gl=a,this.getState=o,this.shader=Xs(a);const i=new Float32Array([-1,-1,0,0,1,-1,1,0,-1,1,0,1,1,1,1,1]);this.vao=a.createVertexArray(),a.bindVertexArray(this.vao);const h=a.createBuffer();a.bindBuffer(a.ARRAY_BUFFER,h),a.bufferData(a.ARRAY_BUFFER,i,a.STATIC_DRAW),a.enableVertexAttribArray(this.shader.attribs.a_pos),a.vertexAttribPointer(this.shader.attribs.a_pos,2,a.FLOAT,!1,16,0),a.enableVertexAttribArray(this.shader.attribs.a_uv),a.vertexAttribPointer(this.shader.attribs.a_uv,2,a.FLOAT,!1,16,8),a.bindVertexArray(null),this.videoTex=a.createTexture(),a.bindTexture(a.TEXTURE_2D,this.videoTex),a.texParameteri(a.TEXTURE_2D,a.TEXTURE_MIN_FILTER,a.LINEAR),a.texParameteri(a.TEXTURE_2D,a.TEXTURE_MAG_FILTER,a.LINEAR),a.texParameteri(a.TEXTURE_2D,a.TEXTURE_WRAP_S,a.CLAMP_TO_EDGE),a.texParameteri(a.TEXTURE_2D,a.TEXTURE_WRAP_T,a.CLAMP_TO_EDGE),a.texImage2D(a.TEXTURE_2D,0,a.RGBA,1,1,0,a.RGBA,a.UNSIGNED_BYTE,new Uint8Array([0,0,0,255])),this.overlayTex=a.createTexture(),a.bindTexture(a.TEXTURE_2D,this.overlayTex),a.texParameteri(a.TEXTURE_2D,a.TEXTURE_MIN_FILTER,a.LINEAR),a.texParameteri(a.TEXTURE_2D,a.TEXTURE_MAG_FILTER,a.LINEAR),a.texParameteri(a.TEXTURE_2D,a.TEXTURE_WRAP_S,a.CLAMP_TO_EDGE),a.texParameteri(a.TEXTURE_2D,a.TEXTURE_WRAP_T,a.CLAMP_TO_EDGE),a.texImage2D(a.TEXTURE_2D,0,a.RGBA,1,1,0,a.RGBA,a.UNSIGNED_BYTE,new Uint8Array([0,0,0,0])),this.overlayCanvas=document.createElement("canvas"),this.overlayCanvas.width=r.width,this.overlayCanvas.height=r.height,this.overlayCtx=this.overlayCanvas.getContext("2d")}start(){this.stop(),this.scheduleNextFrame()}scheduleNextFrame(){if(this.destroyed)return;const o=this.getState().videoEl;if(o&&!o.paused&&"requestVideoFrameCallback"in o&&o.readyState>=HTMLMediaElement.HAVE_CURRENT_DATA){this.videoFrameCallbackId=o.requestVideoFrameCallback(()=>{this.videoFrameCallbackId=null,!this.destroyed&&(this.draw(),this.scheduleNextFrame())});return}this.rafId=requestAnimationFrame(()=>{this.rafId=null,!this.destroyed&&(this.draw(),this.scheduleNextFrame())})}stop(){this.rafId!=null&&cancelAnimationFrame(this.rafId),this.rafId=null;const r=this.getState().videoEl;this.videoFrameCallbackId!=null&&r&&"cancelVideoFrameCallback"in r&&r.cancelVideoFrameCallback(this.videoFrameCallbackId),this.videoFrameCallbackId=null}destroy(){this.destroyed=!0,this.stop();const r=this.gl;r.deleteTexture(this.videoTex),r.deleteTexture(this.overlayTex),r.deleteProgram(this.shader.program)}resize(r,o){this.gl.canvas.width=r,this.gl.canvas.height=o,this.overlayCanvas.width=r,this.overlayCanvas.height=o,this.gl.viewport(0,0,r,o)}activeEffects(r){const{effects:o}=this.getState();return o.filter(a=>a.enabled&&r>=a.timelineStart&&r<a.timelineStart+a.duration)}activeCaption(r){const{captions:o}=this.getState();return o.find(a=>r>=a.timelineStart&&r<a.timelineStart+a.duration)}uploadVideoTexture(r,o,a){const i=this.gl;i.bindTexture(i.TEXTURE_2D,this.videoTex);try{this.videoTextureWidth===o&&this.videoTextureHeight===a?i.texSubImage2D(i.TEXTURE_2D,0,0,0,i.RGBA,i.UNSIGNED_BYTE,r):(i.texImage2D(i.TEXTURE_2D,0,i.RGBA,i.RGBA,i.UNSIGNED_BYTE,r),this.videoTextureWidth=o,this.videoTextureHeight=a)}catch{try{i.texImage2D(i.TEXTURE_2D,0,i.RGBA,i.RGBA,i.UNSIGNED_BYTE,r),this.videoTextureWidth=o,this.videoTextureHeight=a}catch{}}}draw(){var T,w,$,X;const r=this.gl,o=this.getState(),a=o.currentTime,i=this.activeEffects(a),h=o.videoEl;i.find(l=>l.effectType==="freeze")?(!this.freezeFrame&&h&&h.videoWidth>0&&(this.freezeFrame=document.createElement("canvas"),this.freezeFrame.width=h.videoWidth,this.freezeFrame.height=h.videoHeight,this.freezeFrameCtx=this.freezeFrame.getContext("2d"),this.freezeFrameCtx.drawImage(h,0,0)),this.freezeFrame&&this.uploadVideoTexture(this.freezeFrame,this.freezeFrame.width,this.freezeFrame.height)):(this.freezeFrame&&(this.freezeFrame=null,this.freezeFrameCtx=null),h&&h.videoWidth>0&&!h.paused?this.uploadVideoTexture(h,h.videoWidth,h.videoHeight):h&&h.videoWidth>0&&this.uploadVideoTexture(h,h.videoWidth,h.videoHeight));let v=[0,0],b=[1,1],D=[0,0],d=0;for(const l of i)switch(l.effectType){case"zoom":{const _=l.config.zoomLevel??1.3,c=l.config.zoomDirection??"in",y=(a-l.timelineStart)/l.duration;let m=_;c==="in"?m=1+(_-1)*y:c==="out"?m=_-(_-1)*y:c==="in-out"&&(m=1+(_-1)*Math.sin(y*Math.PI));const f=1/m;b=[f,f],v=[(1-f)/2,(1-f)/2];break}case"shake":{const _=(l.config.intensity??5)/1e3,c=l.config.frequency??30,y=(a-l.timelineStart)*c;
84D=[Math.sin(y*6.283)*_,Math.cos(y*5.13)*_];break}case"blur":{d=l.config.blurAmount??10;break}}const S=o.clipTransform;if(S&&(S.scale!==1||S.offsetX!==0||S.offsetY!==0)){const _=1/Math.max(.1,S.scale),c=b[0]*_,y=b[1]*_,m=v[0]+(b[0]-c)/2,f=v[1]+(b[1]-y)/2;b=[c,y],v=[m-S.offsetX*c/2,f+S.offsetY*y/2]}const g=this.overlayCanvas.width,A=this.overlayCanvas.height,j=i.filter(l=>l.effectType==="text"),L=this.activeCaption(a),B=j.length>0||!!L,p=j.length>0,x=L?`caption:${L.id}:${L.text}:${L.timelineStart}:${L.duration}:${((T=o.captionStyles)==null?void 0:T.fontFamily)||""}:${((w=o.captionStyles)==null?void 0:w.textColor)||""}:${(($=o.captionStyles)==null?void 0:$.backgroundColor)||""}:${((X=o.captionStyles)==null?void 0:X.fontWeight)||""}:${g}:${A}`:"",R=p||B&&x!==this.overlaySignature;if(B&&R){this.overlayCtx.clearRect(0,0,g,A);for(const l of j){const _=l.config.text??"Text",c=l.config.fontSize??48,y=(a-l.timelineStart)/l.duration;let m=1,f=1,F=0;switch(l.config.animation??"pop"){case"pop":f=Math.min(1,y*4);break;case"fade":m=Math.min(1,y*3)*Math.min(1,(1-y)*3);break;case"slide-up":F=(1-Math.min(1,y*3))*60;break;case"bounce":f=1+Math.sin(y*Math.PI*4)*.05;break}const z=this.overlayCtx;z.save(),z.globalAlpha=m,z.font=`bold ${c*f}px system-ui, -apple-system, sans-serif`,z.fillStyle="white",z.strokeStyle="rgba(0,0,0,0.85)",z.lineWidth=6,z.textAlign="center",z.textBaseline="middle",z.strokeText(_,g/2,A/2+F),z.fillText(_,g/2,A/2+F),z.restore()}if(L){const l=this.overlayCtx,_=Math.round(A*.05),c=o.captionStyles,y=(c==null?void 0:c.fontFamily)||"system-ui",m=(c==null?void 0:c.fontWeight)||700;l.save(),l.font=`${m} ${_}px "${y}", system-ui, -apple-system, sans-serif`,l.textAlign="center",l.textBaseline="bottom";const f=A*.92,F=L.text,z=l.measureText(F),J=18,se=10,re=z.width+J*2,ee=_+se*2;l.fillStyle=(c==null?void 0:c.backgroundColor)||"rgba(0,0,0,0.65)";const ae=8,Y=g/2-re/2,te=f-ee+se*.2;l.beginPath(),l.moveTo(Y+ae,te),l.lineTo(Y+re-ae,te),l.quadraticCurveTo(Y+re,te,Y+re,te+ae),l.lineTo(Y+re,te+ee-ae),l.quadraticCurveTo(Y+re,te+ee,Y+re-ae,te+ee),l.lineTo(Y+ae,te+ee),l.quadraticCurveTo(Y,te+ee,Y,te+ee-ae),l.lineTo(Y,te+ae),l.quadraticCurveTo(Y,te,Y+ae,te),l.closePath(),l.fill(),l.fillStyle=(c==null?void 0:c.textColor)||"white",l.fillText(F,g/2,f),l.restore()}r.bindTexture(r.TEXTURE_2D,this.overlayTex),r.texImage2D(r.TEXTURE_2D,0,r.RGBA,r.RGBA,r.UNSIGNED_BYTE,this.overlayCanvas),this.overlayHadContent=!0,this.overlaySignature=p?"":x}else!B&&this.overlayHadContent&&(this.overlayCtx.clearRect(0,0,g,A),r.bindTexture(r.TEXTURE_2D,this.overlayTex),r.texImage2D(r.TEXTURE_2D,0,r.RGBA,r.RGBA,r.UNSIGNED_BYTE,this.overlayCanvas),this.overlayHadContent=!1,this.overlaySignature="");r.viewport(0,0,r.canvas.width,r.canvas.height),r.clearColor(0,0,0,1),r.clear(r.COLOR_BUFFER_BIT),r.useProgram(this.shader.program),r.bindVertexArray(this.vao),r.activeTexture(r.TEXTURE0),r.bindTexture(r.TEXTURE_2D,this.videoTex),r.uniform1i(this.shader.uniforms.u_video,0),r.activeTexture(r.TEXTURE1),r.bindTexture(r.TEXTURE_2D,this.overlayTex),r.uniform1i(this.shader.uniforms.u_overlay,1);const I=o.colorAdjust;r.uniform2f(this.shader.uniforms.u_uvOffset,v[0],v[1]),r.uniform2f(this.shader.uniforms.u_uvScale,b[0],b[1]),r.uniform2f(this.shader.uniforms.u_shake,D[0],D[1]),r.uniform1f(this.shader.uniforms.u_blur,d),r.uniform2f(this.shader.uniforms.u_texel,1/r.canvas.width,1/r.canvas.height),r.uniform1f(this.shader.uniforms.u_overlayAlpha,1),r.uniform4f(this.shader.uniforms.u_colorAdjust,(I==null?void 0:I.brightness)??1,(I==null?void 0:I.contrast)??1,(I==null?void 0:I.saturation)??1,(I==null?void 0:I.hueRotateDeg)??0),r.uniform1f(this.shader.uniforms.u_sepia,(I==null?void 0:I.sepia)??0),r.drawArrays(r.TRIANGLE_STRIP,0,4),r.bindVertexArray(null)}}const rt={scale:1,offsetX:0,offsetY:0},Hs={"16:9":{w:960,h:540},"9:16":{w:540,h:960},"1:1":{w:720,h:720}},Gs={"16:9":"aspect-video","9:16":"aspect-[9/16]","1:1":"aspect-square"},qs=.2,Ws=6,at=1,gt=(t,r,o)=>Math.min(o,Math.max(r,t));function Ys({setVideoEl:t,aspectRatio:r,effects:o,captions:a,captionStyles:i,currentTimeRef:h,colorAdjust:u,clipTransform:v,onClipTransformChange:b,canTransform:D,className:d}){const S=s.useRef(null),g=s.useRef(null),A=s.useRef(null),j=s.useRef({videoEl:null,effects:[],captions:[],captionStyles:null,currentTime:0,aspectRatio:r,colorAdjust:null,clipTransform:null});j.current.effects=o,j.current.captions=a,j.current.captionStyles=i??null,j.current.aspectRatio=r,j.current.colorAdjust=u??null,j.current.clipTransform=v??null,s.useEffect(()=>{Qa(i==null?void 0:i.customFontStoragePath,i==null?void 0:i.customFontFamily).c
84atch(m=>{console.error("[FxVideoPlayer] Failed to load subtitle font:",m)})},[i==null?void 0:i.customFontStoragePath,i==null?void 0:i.customFontFamily]),s.useEffect(()=>(t(g.current),j.current.videoEl=g.current,()=>t(null)),[t]),s.useEffect(()=>{if(!S.current)return;const m=Hs[r];S.current.width=m.w,S.current.height=m.h;try{const f=new Bs(S.current,()=>({...j.current,currentTime:h.current}));return A.current=f,f.start(),()=>{f.destroy(),A.current=null}}catch(f){console.error("[FxVideoPlayer] WebGL init failed:",f)}},[r,h]);const L=s.useRef(null),B=s.useRef(null),[p,x]=s.useState(!1),R=s.useRef(v??rt);R.current=v??rt;const I=s.useCallback(m=>{const f={scale:gt(m.scale,qs,Ws),offsetX:gt(m.offsetX,-at,at),offsetY:gt(m.offsetY,-at,at)};b==null||b(f)},[b]),T=s.useCallback(m=>{if(!D||!L.current||m.button!==0)return;const f=L.current.getBoundingClientRect();L.current.setPointerCapture(m.pointerId),B.current={pointerId:m.pointerId,startX:m.clientX,startY:m.clientY,startTransform:{...R.current},rectW:f.width,rectH:f.height}},[D]),w=s.useCallback(m=>{const f=B.current;if(!f||f.pointerId!==m.pointerId)return;const F=m.clientX-f.startX,z=m.clientY-f.startY,J=f.startTransform.offsetX+F/f.rectW*2,se=f.startTransform.offsetY+z/f.rectH*2;I({...f.startTransform,offsetX:J,offsetY:se})},[I]),$=s.useCallback(m=>{var F;const f=B.current;if(!(!f||f.pointerId!==m.pointerId)){try{(F=L.current)==null||F.releasePointerCapture(m.pointerId)}catch{}B.current=null}},[]),X=s.useCallback(m=>{if(!D)return;m.preventDefault();const f=Math.exp(-m.deltaY*.0015),F={...R.current,scale:R.current.scale*f};I(F)},[D,I]);s.useEffect(()=>{const m=L.current;if(m)return m.addEventListener("wheel",X,{passive:!1}),()=>m.removeEventListener("wheel",X)},[X]);const l=s.useCallback(()=>{D&&I({...rt})},[D,I]),_=!!D,c=v??rt,y=c.scale!==1||c.offsetX!==0||c.offsetY!==0;return e.jsx("div",{className:de("relative w-full h-full flex items-center justify-center bg-transparent rounded-md overflow-hidden",d),children:e.jsxs("div",{ref:L,onPointerDown:T,onPointerMove:w,onPointerUp:$,onPointerCancel:$,onMouseEnter:()=>x(!0),onMouseLeave:()=>x(!1),className:de("relative max-w-full max-h-full bg-black flex items-center justify-center",Gs[r],_&&(B.current?"cursor-grabbing":"cursor-grab")),style:{height:r==="9:16"?"100%":"auto",width:r==="9:16"?"auto":"100%"},children:[e.jsx("canvas",{ref:S,className:"w-full h-full object-contain pointer-events-none"}),e.jsx("video",{ref:g,className:"absolute inset-0 w-1 h-1 opacity-0 pointer-events-none",playsInline:!0,muted:!0,preload:"auto",crossOrigin:"anonymous"}),_&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:de("pointer-events-none absolute top-2 left-2 px-2 py-1 rounded-md bg-black/55 backdrop-blur-sm border border-white/15 text-[10px] uppercase tracking-wider text-white/80 transition-opacity",p||y?"opacity-100":"opacity-0"),children:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Ea,{className:"h-3 w-3"})," Drag to reposition · Scroll to scale"]})}),e.jsxs("div",{className:"absolute bottom-2 right-2 flex items-center gap-1.5",children:[e.jsxs("div",{className:de("pointer-events-none px-2 py-1 rounded-md bg-black/55 backdrop-blur-sm border border-white/15 text-[10px] font-mono text-white/80 transition-opacity",y?"opacity-100":"opacity-0"),children:[Math.round(c.scale*100),"%"]}),y&&e.jsx(W,{size:"icon",variant:"ghost",onClick:l,className:"h-7 w-7 rounded-md bg-black/55 backdrop-blur-sm border border-white/15 text-white/80 hover:text-white hover:bg-black/70",title:"Reset clip framing",children:e.jsx(ar,{className:"h-3.5 w-3.5"})})]})]})]})})}const Ht=new Map,Qs=80,Ks=45,vt=2;function Js(t,r){const[o,a]=s.useState([]),[i,h]=s.useState(!1),u=s.useRef(!0);return s.useEffect(()=>(u.current=!0,()=>{u.current=!1}),[]),s.useEffect(()=>{if(!t){a([]);return}const v=`${t}:${r}`,b=Ht.get(v);if(b){a(b);return}let D=!1;const d=document.createElement("video");return d.crossOrigin="anonymous",d.muted=!0,d.preload="metadata",(async()=>{h(!0);const g=[];try{if(d.src=t,await new Promise((p,x)=>{d.onloadedmetadata=()=>p(),d.onerror=()=>x(new Error("Failed to load video")),setTimeout(()=>x(new Error("Video load timeout")),1e4)}),D)return;const A=d.duration;if(!A||!isFinite(A))throw new Error("Invalid video duration");const j=document.createElement("canvas"),L=j.getContext("2d");if(!L)return;j.width=Qs,j.height=Ks;const B=Math.max(1,Math.ceil(A/vt));for(let p=0;p<B&&!D;p++){const x=Math.min(p*vt,A-.1);if(d.currentTime=x,await new Promise(R=>{d.onseeked=()=>R(),setTimeout(R,2e3)}),D)break;L.drawImage(d,0,0,j.width,j.height),g.push(j.toDataURL("image/jpeg",.6))}!D&&u.current&&g.length>0&&(Ht.set(v,g),a(g))}catch(A){console.warn("[useSliceThumbnails] Failed to generate thumbnails:",A),!D&&u.current&&a([])}finally{u.current&&h(!1)}})(),()=>{D=!0,d.src=""}},[t,r]),{thumbnails:o,thumbnailInterval:vt,isLoading:i}}
84var yt="ContextMenu",[Zs,ri]=sa(yt,[er]),pe=er(),[eo,sr]=Zs(yt),or=t=>{const{__scopeContextMenu:r,children:o,onOpenChange:a,dir:i,modal:h=!0}=t,[u,v]=s.useState(!1),b=pe(r),D=na(a),d=s.useCallback(S=>{v(S),D(S)},[D]);return e.jsx(eo,{scope:r,open:u,onOpenChange:d,modal:h,children:e.jsx(hs,{...b,dir:i,open:u,onOpenChange:d,modal:h,children:o})})};or.displayName=yt;var nr="ContextMenuTrigger",ir=s.forwardRef((t,r)=>{const{__scopeContextMenu:o,disabled:a=!1,...i}=t,h=sr(nr,o),u=pe(o),v=s.useRef({x:0,y:0}),b=s.useRef({getBoundingClientRect:()=>DOMRect.fromRect({width:0,height:0,...v.current})}),D=s.useRef(0),d=s.useCallback(()=>window.clearTimeout(D.current),[]),S=g=>{v.current={x:g.clientX,y:g.clientY},h.onOpenChange(!0)};return s.useEffect(()=>d,[d]),s.useEffect(()=>void(a&&d()),[a,d]),e.jsxs(e.Fragment,{children:[e.jsx(ts,{...u,virtualRef:b}),e.jsx(oa.span,{"data-state":h.open?"open":"closed","data-disabled":a?"":void 0,...i,ref:r,style:{WebkitTouchCallout:"none",...t.style},onContextMenu:a?t.onContextMenu:Xe(t.onContextMenu,g=>{d(),S(g),g.preventDefault()}),onPointerDown:a?t.onPointerDown:Xe(t.onPointerDown,st(g=>{d(),D.current=window.setTimeout(()=>S(g),700)})),onPointerMove:a?t.onPointerMove:Xe(t.onPointerMove,st(d)),onPointerCancel:a?t.onPointerCancel:Xe(t.onPointerCancel,st(d)),onPointerUp:a?t.onPointerUp:Xe(t.onPointerUp,st(d))})]})});ir.displayName=nr;var to="ContextMenuPortal",lr=t=>{const{__scopeContextMenu:r,...o}=t,a=pe(r);return e.jsx(ps,{...a,...o})};lr.displayName=to;var cr="ContextMenuContent",dr=s.forwardRef((t,r)=>{const{__scopeContextMenu:o,...a}=t,i=sr(cr,o),h=pe(o),u=s.useRef(!1);return e.jsx(rs,{...h,...a,ref:r,side:"right",sideOffset:2,align:"start",onCloseAutoFocus:v=>{var b;(b=t.onCloseAutoFocus)==null||b.call(t,v),!v.defaultPrevented&&u.current&&v.preventDefault(),u.current=!1},onInteractOutside:v=>{var b;(b=t.onInteractOutside)==null||b.call(t,v),!v.defaultPrevented&&!i.modal&&(u.current=!0)},style:{...t.style,"--radix-context-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-context-menu-content-available-width":"var(--radix-popper-available-width)","--radix-context-menu-content-available-height":"var(--radix-popper-available-height)","--radix-context-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-context-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});dr.displayName=cr;var ro="ContextMenuGroup",ao=s.forwardRef((t,r)=>{const{__scopeContextMenu:o,...a}=t,i=pe(o);return e.jsx(as,{...i,...a,ref:r})});ao.displayName=ro;var so="ContextMenuLabel",ur=s.forwardRef((t,r)=>{const{__scopeContextMenu:o,...a}=t,i=pe(o);return e.jsx(ss,{...i,...a,ref:r})});ur.displayName=so;var oo="ContextMenuItem",mr=s.forwardRef((t,r)=>{const{__scopeContextMenu:o,...a}=t,i=pe(o);return e.jsx(os,{...i,...a,ref:r})});mr.displayName=oo;var no="ContextMenuCheckboxItem",fr=s.forwardRef((t,r)=>{const{__scopeContextMenu:o,...a}=t,i=pe(o);return e.jsx(ns,{...i,...a,ref:r})});fr.displayName=no;var io="ContextMenuRadioGroup",lo=s.forwardRef((t,r)=>{const{__scopeContextMenu:o,...a}=t,i=pe(o);return e.jsx(is,{...i,...a,ref:r})});lo.displayName=io;var co="ContextMenuRadioItem",pr=s.forwardRef((t,r)=>{const{__scopeContextMenu:o,...a}=t,i=pe(o);return e.jsx(ls,{...i,...a,ref:r})});pr.displayName=co;var uo="ContextMenuItemIndicator",hr=s.forwardRef((t,r)=>{const{__scopeContextMenu:o,...a}=t,i=pe(o);return e.jsx(cs,{...i,...a,ref:r})});hr.displayName=uo;var mo="ContextMenuSeparator",xr=s.forwardRef((t,r)=>{const{__scopeContextMenu:o,...a}=t,i=pe(o);return e.jsx(ds,{...i,...a,ref:r})});xr.displayName=mo;var fo="ContextMenuArrow",po=s.forwardRef((t,r)=>{const{__scopeContextMenu:o,...a}=t,i=pe(o);return e.jsx(us,{...i,...a,ref:r})});po.displayName=fo;var ho="ContextMenuSubTrigger",gr=s.forwardRef((t,r)=>{const{__scopeContextMenu:o,...a}=t,i=pe(o);return e.jsx(ms,{...i,...a,ref:r})});gr.displayName=ho;var xo="ContextMenuSubContent",vr=s.forwardRef((t,r)=>{const{__scopeContextMenu:o,...a}=t,i=pe(o);return e.jsx(fs,{...i,...a,ref:r,style:{...t.style,"--radix-context-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-context-menu-content-available-width":"var(--radix-popper-available-width)","--radix-context-menu-content-available-height":"var(--radix-popper-available-height)","--radix-context-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-context-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});vr.displayName=xo;function st(t){return r=>r.pointerType!=="mouse"?t(r):void 0}var go=or,vo=ir,bo=lr,br=dr,wr=ur,yr=mr,jr=fr,Sr=pr,Nr=hr,Tr=xr,Er=gr,_r=vr;const wo=go,yo=vo,jo=s.forwardRef(({className:t,inset:r,children:o,...a},i)=>e.jsxs(Er,{ref:i,className:de("flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none data-[state=open]:bg-accent data-[state=open]:text-accent-foreground focus:bg-accent focus:text-accent-foreground",r&&"pl-8",t),...a,children:[o,e.jsx(Es,{className:"ml-auto h-4 w-4"})]}));jo.displayName=Er.displayName;const So=s.forwardRef(({className:t,...r},o)=>e.jsx(_r,{ref:o,className:de("z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:sli
84de-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",t),...r}));So.displayName=_r.displayName;const Cr=s.forwardRef(({className:t,...r},o)=>e.jsx(bo,{children:e.jsx(br,{ref:o,className:de("z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md animate-in fade-in-80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",t),...r})}));Cr.displayName=br.displayName;const ot=s.forwardRef(({className:t,inset:r,...o},a)=>e.jsx(yr,{ref:a,className:de("relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 focus:bg-accent focus:text-accent-foreground",r&&"pl-8",t),...o}));ot.displayName=yr.displayName;const No=s.forwardRef(({className:t,children:r,checked:o,...a},i)=>e.jsxs(jr,{ref:i,className:de("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 focus:bg-accent focus:text-accent-foreground",t),checked:o,...a,children:[e.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:e.jsx(Nr,{children:e.jsx(ia,{className:"h-4 w-4"})})}),r]}));No.displayName=jr.displayName;const To=s.forwardRef(({className:t,children:r,...o},a)=>e.jsxs(Sr,{ref:a,className:de("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 focus:bg-accent focus:text-accent-foreground",t),...o,children:[e.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:e.jsx(Nr,{children:e.jsx(_s,{className:"h-2 w-2 fill-current"})})}),r]}));To.displayName=Sr.displayName;const Eo=s.forwardRef(({className:t,inset:r,...o},a)=>e.jsx(wr,{ref:a,className:de("px-2 py-1.5 text-sm font-semibold text-foreground",r&&"pl-8",t),...o}));Eo.displayName=wr.displayName;const kr=s.forwardRef(({className:t,...r},o)=>e.jsx(Tr,{ref:o,className:de("-mx-1 my-1 h-px bg-border",t),...r}));kr.displayName=Tr.displayName;function _o({slice:t,pixelsPerSecond:r,selected:o,onSelect:a,onDragStart:i,onResizeStart:h,onOpenColorCorrection:u,onRemove:v,onResetTransform:b,dragOffsetPx:D=0,dragOffsetY:d=0}){const S=t.timelineStart*r,g=Math.max(20,t.duration*r),{thumbnails:A,thumbnailInterval:j}=Js(t.hasVideo?t.sourceUrl:null,t.sourceId),L=Math.max(0,Math.floor(t.sourceIn/j)),B=A.slice(L),p=e.jsxs("div",{role:"button",tabIndex:0,onPointerDown:w=>{if(!(w.target instanceof HTMLElement&&w.target.dataset.role==="resize")){if(w.button===2){a();return}a(),i(w)}},onContextMenu:()=>{a()},onClick:()=>{t.hasVideo&&(u==null||u())},className:de("absolute top-1 bottom-1 rounded-md overflow-hidden border cursor-grab active:cursor-grabbing select-none",t.hasVideo?"bg-blue-500/30 border-blue-400/60":"bg-primary/25 border-primary/50",o&&"ring-2 ring-primary"),style:{left:S,width:g,transform:D||d?`translate3d(${D}px, ${d}px, 0)`:void 0,willChange:D||d?"transform":void 0,opacity:D||d?.85:void 0,zIndex:D||d?50:void 0,pointerEvents:D||d?"none":void 0},children:[t.hasVideo&&B.length>0&&e.jsx("div",{className:"absolute inset-0 flex",children:B.map((w,$)=>e.jsx("img",{src:w,alt:"",className:"h-full object-cover",style:{width:j*r,minWidth:j*r},draggable:!1},$))}),e.jsx("div",{className:"absolute inset-x-0 top-0 px-1.5 py-0.5 text-[10px] font-medium text-white/95 bg-black/40 truncate pointer-events-none",children:t.name}),e.jsx("div",{"data-role":"resize",onPointerDown:w=>{w.stopPropagation(),h("in",w)},className:"absolute left-0 top-0 bottom-0 w-1.5 cursor-ew-resize bg-white/20 hover:bg-white/60"}),e.jsx("div",{"data-role":"resize",onPointerDown:w=>{w.stopPropagation(),h("out",w)},className:"absolute right-0 top-0 bottom-0 w-1.5 cursor-ew-resize bg-white/20 hover:bg-white/60"})]}),x=t.hasVideo&&!!u,R=!!v,T=t.hasVideo&&!!t.transform&&(t.transform.scale!==1||t.transform.offsetX!==0||t.transform.offsetY!==0)&&!!b;return!x&&!R&&!T?p:e.jsxs(wo,{children:[e.jsx(yo,{asChild:!0,children:p}),e.jsxs(Cr,{className:"w-52",children:[x&&e.jsxs(ot,{onSelect:()=>u==null?void 0:u(),children:[e.jsx(_a,{className:"mr-2 h-4 w-4"}
84),"Color adjustments…"]}),T&&e.jsxs(ot,{onSelect:()=>b==null?void 0:b(),children:[e.jsx(ar,{className:"mr-2 h-4 w-4"}),"Reset framing"]}),R&&(x||T)&&e.jsx(kr,{}),R&&e.jsxs(ot,{onSelect:()=>v==null?void 0:v(),className:"text-destructive focus:text-destructive",children:[e.jsx(Cs,{className:"mr-2 h-4 w-4"}),"Remove clip"]})]})]})}const Co=3;function ko({track:t,slices:r,pixelsPerSecond:o,selectedSliceId:a,onSelect:i,onMove:h,onResize:u,onDropMedia:v,onOpenColorCorrection:b,onRemoveSlice:D,onResetSliceTransform:d}){const S=s.useRef(null),[g,A]=s.useState(null),j=s.useCallback(p=>x=>{const R=x.clientX,I=x.clientY,T=p.timelineStart;let w=!1,$=0,X=t.id;const l=(y,m)=>{var F;const f=document.elementsFromPoint(y,m);for(const z of f){const J=(F=z.dataset)==null?void 0:F.videoTrackId;if(J)return J}return null},_=y=>{const m=y.clientX-R,f=y.clientY-I;!w&&Math.hypot(m,f)<Co||(w=!0,$=m,X=l(y.clientX,y.clientY)??t.id,A({sliceId:p.id,deltaPx:m,deltaY:f,targetTrackId:X}))},c=()=>{if(window.removeEventListener("pointermove",_),window.removeEventListener("pointerup",c),window.removeEventListener("pointercancel",c),A(null),w){const y=Math.max(0,T+$/o),m=X&&X!==p.trackId?X:void 0;h(p.id,y,m)}};window.addEventListener("pointermove",_),window.addEventListener("pointerup",c),window.addEventListener("pointercancel",c)},[o,h,t.id]),L=s.useCallback(p=>(x,R)=>{const I=R.clientX;let T=0,w=null,$=0;const X=()=>{if($=0,w===null)return;const c=w;w=null,u(p.id,x,c-T),T=c},l=c=>{w=(c.clientX-I)/o,$||($=requestAnimationFrame(X))},_=()=>{window.removeEventListener("pointermove",l),window.removeEventListener("pointerup",_),window.removeEventListener("pointercancel",_),$&&(cancelAnimationFrame($),X())};window.addEventListener("pointermove",l),window.addEventListener("pointerup",_),window.addEventListener("pointercancel",_)},[o,u]),B=p=>{if(!v||!S.current)return;p.preventDefault(),p.stopPropagation();const x=S.current.getBoundingClientRect(),R=p.clientX-x.left,I=Math.max(0,R/Math.max(1,o));v(p,t.id,I)};return e.jsxs("div",{className:"flex border-b border-white/5",children:[e.jsx("div",{className:de("w-16 shrink-0 px-2 py-1 text-[11px] font-mono uppercase tracking-wide text-muted-foreground border-r border-white/5 flex items-center",t.type==="video"?"bg-blue-950/30":"bg-primary/10"),children:t.label}),e.jsx("div",{ref:S,"data-video-track-id":t.id,className:de("relative flex-1 h-14",t.type==="video"?"bg-blue-950/10":"bg-primary/5",(g==null?void 0:g.targetTrackId)===t.id&&"ring-1 ring-primary/40"),onClick:p=>{p.target===p.currentTarget&&i(null)},onDragOver:p=>{p.preventDefault()},onDrop:B,children:r.map(p=>{const x=(g==null?void 0:g.sliceId)===p.id;return e.jsx(_o,{slice:p,pixelsPerSecond:o,selected:a===p.id,onSelect:()=>i(p.id),onDragStart:j(p),onResizeStart:L(p),onOpenColorCorrection:p.hasVideo?()=>b==null?void 0:b(p.id):void 0,onRemove:D?()=>D(p.id):void 0,onResetTransform:d?()=>d(p.id):void 0,dragOffsetPx:x?g.deltaPx:0,dragOffsetY:x?g.deltaY:0},p.id)})})]})}const Ro=t=>{if(!isFinite(t))return"00:00";const r=Math.floor(t/60).toString().padStart(2,"0"),o=Math.floor(t%60).toString().padStart(2,"0");return`${r}:${o}`};function Mo({tracks:t,slices:r,duration:o,currentTime:a,pixelsPerSecond:i,onSeek:h,selectedSliceId:u,onSelect:v,onMove:b,onResize:D,onDropMedia:d,onOpenColorCorrection:S,onRemoveSlice:g,onResetSliceTransform:A}){const j=s.useRef(null),L=s.useMemo(()=>{const w=t.filter(X=>X.type==="video").sort((X,l)=>l.index-X.index),$=t.filter(X=>X.type==="audio").sort((X,l)=>X.index-l.index);return[...w,...$]},[t]),B=5,p=[];for(let w=0;w<=Math.max(o,30);w+=B)p.push(w);const x=w=>{if(!j.current)return;const $=j.current.getBoundingClientRect();h(Math.max(0,(w.clientX-$.left)/i))},R=a*i,I=Math.max(800,(o+30)*i),T=L.map(w=>w.id);return e.jsxs("div",{className:"flex flex-col bg-card/40 rounded-md border border-white/10 overflow-hidden",children:[e.jsxs("div",{className:"flex",children:[e.jsx("div",{className:"w-16 shrink-0 border-r border-white/10 bg-card/60"}),e.jsx("div",{ref:j,onClick:x,className:"relative flex-1 h-7 bg-card/40 cursor-pointer overflow-hidden",style:{width:I},children:p.map(w=>e.jsx("div",{className:"absolute top-0 bottom-0 border-l border-white/10 text-[10px] text-muted-foreground pl-1",style:{left:w*i},children:Ro(w)},w))})]}
84),e.jsxs("div",{"data-video-timeline-scroller":"true",className:"relative overflow-x-auto overflow-y-auto",style:{maxHeight:"100%"},children:[e.jsx("div",{style:{width:I+64},children:L.map((w,$)=>{var l;const X=w.type==="video"&&((l=L[$+1])==null?void 0:l.type)==="audio";return e.jsx("div",{className:de(X&&"border-b-2 border-white/20"),children:e.jsx(ko,{track:w,slices:r.filter(_=>_.trackId===w.id),pixelsPerSecond:i,selectedSliceId:u,onSelect:v,onMove:b,onResize:D,allTrackIds:T,onDropMedia:d,onOpenColorCorrection:w.type==="video"?S:void 0,onRemoveSlice:g,onResetSliceTransform:w.type==="video"?A:void 0})},w.id)})}),e.jsx("div",{className:"pointer-events-none absolute top-0 bottom-0 w-px bg-primary",style:{left:64+R},children:e.jsx("div",{className:"absolute -top-0 -left-1.5 w-3 h-3 bg-primary rotate-45"})})]})]})}function Ao({items:t,onImport:r,onDragStart:o}){const a=s.useRef(null),[i,h]=s.useState(!1);return e.jsxs("div",{className:"h-full flex flex-col bg-background/50 rounded-md border border-white/10",children:[e.jsxs("div",{className:"flex items-center justify-between px-3 py-2 border-b border-white/10",children:[e.jsx("h3",{className:"text-xs font-semibold tracking-wide uppercase text-muted-foreground",children:"Media Pool"}),e.jsxs(W,{size:"sm",variant:"ghost",className:"h-7 gap-1.5 text-xs",onClick:()=>{var u;return(u=a.current)==null?void 0:u.click()},children:[e.jsx(ks,{className:"h-3.5 w-3.5"})," Import"]}),e.jsx("input",{ref:a,type:"file",accept:"video/*,audio/*",multiple:!0,className:"hidden",onChange:u=>{u.target.files&&r(u.target.files),u.currentTarget.value=""}})]}),e.jsx("div",{className:de("flex-1 overflow-auto p-2 space-y-1",i&&"bg-primary/10"),onDragOver:u=>{u.preventDefault(),h(!0)},onDragLeave:()=>h(!1),onDrop:u=>{var v;u.preventDefault(),h(!1),(v=u.dataTransfer.files)!=null&&v.length&&r(u.dataTransfer.files)},children:t.length===0?e.jsxs("div",{className:"text-xs text-muted-foreground text-center py-8 px-2",children:["Drop video or audio files here, or click ",e.jsx("span",{className:"text-foreground",children:"Import"}),"."]}):t.map(u=>e.jsxs("div",{draggable:!0,onDragStart:v=>{v.dataTransfer.setData("application/x-video-media-id",u.id),v.dataTransfer.effectAllowed="copy",o(v,u)},className:"flex items-center gap-2 px-2 py-1.5 rounded-md hover:bg-white/5 cursor-grab active:cursor-grabbing border border-transparent hover:border-white/10",children:[u.hasVideo?e.jsx(Is,{className:"h-4 w-4 text-blue-400 shrink-0"}):e.jsx(Rs,{className:"h-4 w-4 text-primary shrink-0"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"text-xs font-medium truncate",children:u.name}),e.jsxs("div",{className:"text-[10px] text-muted-foreground",children:[Math.floor(u.duration/60),":",String(Math.floor(u.duration%60)).padStart(2,"0")]})]})]},u.id))})]})}const Po=[{value:"480p",label:"SD",resolution:"854 × 480"},{value:"720p",label:"HD",resolution:"1280 × 720"},{value:"1080p",label:"Full HD",resolution:"1920 × 1080",note:"Max quality"}],Gt={idle:0,submitting:5,queued:15,fetching:30,rendering:60,saving:90,done:100,failed:0};function Do({open:t,onOpenChange:r,slices:o,effects:a,captions:i,captionStyles:h,aspectRatio:u}){const[v,b]=s.useState("idle"),[D,d]=s.useState(null),[S,g]=s.useState(null),[A,j]=s.useState(null),[L,B]=s.useState("1080p"),p=s.useRef(null);s.useEffect(()=>{t||(b("idle"),d(null),g(null),j(null),p.current&&window.clearTimeout(p.current))},[t]),s.useEffect(()=>{if(!D||v==="done"||v==="failed")return;let T=!1;const w=async()=>{try{const{data:$,error:X}=await U.functions.invoke("render-video",{method:"GET",body:void 0,headers:void 0}),_=`https://ukbpvxhhabdvdhpfvjhe.supabase.co/functions/v1/render-video?id=${encodeURIComponent(D)}`,y=await(await fetch(_,{headers:{apikey:"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InVrYnB2eGhoYWJkdmRocGZ2amhlIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NzQxMTA5NDYsImV4cCI6MjA4OTY4Njk0Nn0.AbzUbeNh83bu1BhHeISAgpDE9RuJ0O_T3tZJB7AV8cs"}})).json();if(T)return;if(y!=null&&y.error){b("failed"),j(y.error);return}const m=y==null?void 0:y.status;if(m&&b(m),m==="done"&&y.url){g(y.url);return}if(m==="failed"){j(y.error??"Render failed");return}p.current=window.setTimeout(w,4e3)}catch($){console.error("[ExportVideo] poll failed",$),T||(p.current=window.setTimeout(w,6e3))}};return p.current=window.setTimeout(w,2e3),()=>{T=!0,p.current&&window.clearTimeout(p.current)}},[D,v]);const x=async T=>{const w=new Map,$=Array.from(new Set(T.map(c=>c.sourceUrl).filter(c=>!/^https?:\/\//.test(c))));if($.length===0)return w;const{data:X,error:l}=await U.auth.getUser();if(l||!X.user)throw new Error("Sign in required to upload clips for server render.");const _=X.user.id;b("submitting");for(let c=0;c<$.length;c++){const y=$[c],m=T.find(ae=>ae.sourceUrl===y),f=((m==null?void 0:m.name)??`clip-${c}.mp4`).replace(/\s+/g,"_"),F=f.includes(".")?f.split(".").pop():"mp4",z=`${_}/${Date.now()}-${c}-${crypto.randomUUID()}.${F}`,J=await fetch(y).then(ae=>ae.blob()),{error:se}=await U.storage.from("video-uploads").upload(z,J,{cacheControl:"3600",upsert:!1,contentType:J.type||(F==="mp3"||F==="wav"?`audio/${F}`:`video/${F}`)});if(se)throw new Error(`Upload failed for ${f}: ${se.message}`);const{data:re,error:ee}=await U.storage.from("video-uploads").createSignedUrl(z,60*60*24);if(ee||!(re!=null&&re.signedUrl))throw new Error(`Failed to sign URL for ${f}: ${(ee==null?void 0:ee.message)??"unknown error"}`);w.set(y,re.signedUrl),k.message(`Uploaded ${c+1}/${$.length} clip${$.length>
841?"s":""}`)}return w},R=async()=>{j(null),b("submitting");try{const T=await x(o),w=o.map(c=>({...c,sourceUrl:T.get(c.sourceUrl)??c.sourceUrl})),$=w.filter(c=>!/^https?:\/\//.test(c.sourceUrl));if($.length>0)throw new Error(`${$.length} clip(s) still missing a public URL after upload.`);const X=h!=null&&h.customFontStoragePath?await Ka(h.customFontStoragePath):null,{data:l,error:_}=await U.functions.invoke("render-video",{body:{slices:w.map(c=>({sourceUrl:c.sourceUrl,timelineStart:c.timelineStart,duration:c.duration,sourceIn:c.sourceIn,hasVideo:c.hasVideo,hasAudio:c.hasAudio,trackId:c.trackId,transform:c.transform})),effects:a.map(c=>({effectType:c.effectType,timelineStart:c.timelineStart,duration:c.duration,config:c.config,enabled:c.enabled})),captions:i.map(c=>({text:c.text,timelineStart:c.timelineStart,duration:c.duration})),captionStyles:{fontFamily:(h==null?void 0:h.fontFamily)||"Open Sans",fontWeight:(h==null?void 0:h.fontWeight)||700,textColor:(h==null?void 0:h.textColor)||"#ffffff",customFontUrl:X},aspectRatio:u,enableFaceReframe:u==="9:16",quality:L}});if(_)throw _;if(l!=null&&l.error)throw new Error(l.error);if(!(l!=null&&l.id))throw new Error("No render id returned");d(l.id),b("queued"),k.success("Render started — this can take a few minutes.")}catch(T){console.error("[ExportVideo] startRender failed",T),b("failed"),j((T==null?void 0:T.message)??"Failed to start render")}},I=v!=="idle"&&v!=="done"&&v!=="failed";return e.jsx(Be,{open:t,onOpenChange:r,children:e.jsxs(He,{children:[e.jsxs(Ge,{children:[e.jsx(qe,{children:"Export video"}),e.jsxs(We,{children:["Renders your timeline through the Shotstack cloud renderer. Effects, subtitles and the ",u," aspect ratio will be rendered into the MP4."]})]}),e.jsxs("div",{className:"space-y-3 py-2",children:[e.jsxs("div",{className:"text-xs text-muted-foreground space-y-1",children:[e.jsxs("div",{children:["Clips: ",o.length]}),e.jsxs("div",{children:["FX: ",a.filter(T=>T.enabled).length]}),e.jsxs("div",{children:["Subtitles: ",i.length]}),e.jsxs("div",{children:["Aspect: ",u]})]}),v==="idle"&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"text-xs font-medium text-foreground",children:"Quality"}),e.jsx(Jt,{value:L,onValueChange:T=>B(T),className:"grid grid-cols-3 gap-2",children:Po.map(T=>e.jsxs("div",{children:[e.jsx(Zt,{value:T.value,id:`export-q-${T.value}`,className:"peer sr-only"}),e.jsxs(Qt,{htmlFor:`export-q-${T.value}`,className:"flex flex-col items-center justify-center gap-0.5 rounded-md border border-border bg-background/50 px-2 py-2 cursor-pointer hover:bg-accent/10 peer-data-[state=checked]:border-primary peer-data-[state=checked]:bg-primary/5 transition-colors",children:[e.jsx("span",{className:"text-sm font-semibold text-foreground leading-none",children:T.value}),e.jsx("span",{className:"text-[10px] text-muted-foreground",children:T.label}),e.jsx("span",{className:"text-[10px] text-muted-foreground",children:T.resolution}),T.note&&e.jsx("span",{className:"text-[10px] text-primary mt-0.5",children:T.note})]})]},T.value))})]}),v!=="idle"&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex justify-between text-xs",children:[e.jsx("span",{className:"capitalize",children:v}),e.jsxs("span",{children:[Gt[v],"%"]})]}),e.jsx(tr,{value:Gt[v]})]}),A&&e.jsxs("div",{className:"flex items-start gap-2 text-xs text-destructive bg-destructive/10 border border-destructive/20 rounded-md p-2",children:[e.jsx(Ss,{className:"h-4 w-4 shrink-0 mt-0.5"}),e.jsx("div",{children:A})]}),S&&e.jsxs("div",{className:"flex items-center gap-2 text-xs text-blue-300 bg-primary/10 border border-primary/20 rounded-md p-2",children:[e.jsx(Ms,{className:"h-4 w-4 shrink-0"}),e.jsx("span",{children:"Render complete!"})]})]}),e.jsxs(Ye,{children:[v==="idle"&&e.jsx(W,{onClick:R,children:"Start render"}),I&&e.jsxs(W,{disabled:!0,className:"gap-2",children:[e.jsx(Qe,{className:"h-4 w-4 animate-spin"})," Rendering…"]}),v==="done"&&S&&e.jsx(W,{asChild:!0,className:"gap-2",children:e.jsxs("a",{href:S,target:"_blank",rel:"noreferrer",download:!0,children:[e.jsx(Ke,{className:"h-4 w-4"})," Download MP4"]})}),v==="failed"&&e.jsx(W,{variant:"outline",onClick:()=>{b("idle"),j(null)},children:"Try again"})]})]})})}const Io=[{id:"v2",type:"video",label:"V2",index:1},{id:"v1",type:"video",label:"V1",index:0},{id:"a1",type:"audio",label:"A1",index:0,volume:1},{id:"a2",type:"audio",label:"A2",index:1,volume:1},{id:"a3",type:"audio",label:"A3",index:2,volume:1}];let Fo=0;const qt=()=>`vs_${Date.now().toString(36)}_${(Fo++).toString(36)}`;function Lo(){const[t]=s.useState(Io),[r,o]=s.useState([]),[a,i]=s.useState(null),h=s.useCallback(d=>{const S=qt();return o(g=>[...g,{...d,id:S}]),S},[]);s.useCallback(d=>{o(S=>S.filter(g=>g.id!==d)),i(S=>S===d?null:S)},[]),s.useCallback((d,S,g)=>{o(A=>A.map(j=>j.id===d?{...j,timelineStart:Math.max(0,S),trackId:g??j.trackId}:j))},[]);const u=s.useCallback((d,S,g)=>{o(A=>A.map(j=>{if(j.id!==d)return j;if(S==="in"){const L=Math.max(0,Math.min(j.sourceOut-.1,j.sourceIn+g)),B=L-j.sourceIn;return{...j,sourceIn:L,timelineStart:j.timelineStart+B,duration:j.sourceOut-L}}else{const L=Math.max(j.sourceIn+.1,Math.min(j.sourceDuration,j.sourceOut+g));return{...j,sourceOut:L,duration:L-j.sourceIn}}}))},[]),v=s.useCallback((d,S)=>{o(g=>{const A=g.find(R=>R.id===d);if(!A)return g;const j=S-A.timelineStart;if(j<=.05||j>=A.duration-.05)return g;const L=A.linkId,B=L?g.filter(R=>R.linkId===L&&S>R.timelineStart+.05&&S<R.timelineStart+R.duration-.05):[A],p=new Set(B.map(R=>R.id)),x=L?`av_${Date.now().toString(36)}_${Math.random().toString(36).slice(2,7)}`:void 0;return g.flatMap(R=>{if(!p.has(R.id))return[R];const I=S-R.timelineStart;if(I<=.05||I>=R.duration-.05)return[R];const T=R.sourceIn+I,w={...R,sourceOut:T,duration:T-R.sourceIn},$={...R,id:qt(),sourceIn:T,timelineStart:R.timelineStart+(T-R.sourceIn),duration:R.sourceOut-T,linkId:x};return[w,$]})})},[]),b=s.useCallback((d,S,g)=>{o(A=>{const j=A.find(p=>p.id===d);if(!j)return A;const L=Math.max(0,S)-j.timelineStart;if(L===0&&(!g||g===j.trackId))return A;const B=j.linkId;return A.map(p=>p.id===d?{...p,timelineStart:Math.max(0,S),trackId:g??p.trackId}:B&&p.linkId===B?{...p,timelineStart:Math.max(0,p.timelineStart+L)}:p)})},[]),D=s.useCallback(d=>{o(S=>{const g=S.find(j=>j.id===d);if(!g)return S;const A=g.linkId;return S.filter(j=>!(j.id===d||A&&j.linkId===A))}),i(S=>S===d?null:S)},[]);return{tracks:t,slices:r,addSlice:h,removeSlice:D,moveSlice:b,resizeSlice:u,splitSlice:v,setSlices:o,selectedSliceId:a,setSelectedSliceId:i}}const Uo=50,$o=.05;function Oo({slices:t,duration:r}){const[o,a]=s.useState(!1),[i,h]=s.useState(0),u=s.useRef(0),v=s.useRef(null),b=s.useRef(null),D=s.useRef(0),d=s.useRef(0),S=s.useRef(!1),g=s.useRef(null),A=s.useRef(t),[j,L]=s.useState(null);s.useEffect(()=>{S.current=o},[o]),s.useEffect(()=>{A.current=t},[t]);const B=s.useCallback(l=>{v.current=l},[]),p=s.useCallback((l,_)=>{let c=null,y=-1;for(const m of _){if(!m.hasVideo||l<m.timelineStart||l>=m.timelineStart+m.duration)continue;const f=m.trackId==="v2"?1:0;f>y&&(c=m,y=f)}return c},[]),x=s.useCallback(l=>{g.current=l,L(_=>_===l?_:l)},[]),R=s.useCallback(l=>{const _=v.current;return _?l?_.src!==l.sourceUrl?(_.src=l.sourceUrl,!1):!0:(_.paused||_.pause(),!1):!1},[]),I=s.useCallback((l,_,c)=>{const y=v.current;if(!y)return;
84if(!l){y.paused||y.pause();return}const m=R(l),f=l.sourceIn+Math.max(0,_-l.timelineStart);if(!Number.isFinite(f))return;const F=()=>{var z,J;try{Math.abs(y.currentTime-f)>$o&&(y.currentTime=f)}catch{}c?(z=y.play)==null||z.call(y).catch(()=>{}):y.paused||(J=y.pause)==null||J.call(y)};if(m&&y.readyState>=HTMLMediaElement.HAVE_METADATA)F();else{const z=()=>{y.removeEventListener("loadedmetadata",z),F()};y.addEventListener("loadedmetadata",z)}},[R]);s.useEffect(()=>{if(S.current)return;const l=p(u.current,t);x(l),I(l,u.current,!1)},[t,p,x,I]),s.useEffect(()=>{if(!o){b.current&&cancelAnimationFrame(b.current),b.current=null,d.current=0;const c=v.current;c&&!c.paused&&c.pause();return}const l=p(u.current,A.current);x(l),I(l,u.current,!0),D.current=performance.now(),d.current=D.current;const _=c=>{const y=A.current,m=v.current,f=g.current;let F;if(f&&m&&!m.paused&&m.readyState>=HTMLMediaElement.HAVE_CURRENT_DATA){const J=m.currentTime;F=f.timelineStart+(J-f.sourceIn)}else{const J=(c-D.current)/1e3;F=u.current+J}if(D.current=c,F>=r){F=r,u.current=F,h(F),m&&!m.paused&&m.pause(),x(p(F,y)),a(!1);return}u.current=F;const z=p(F,y);if(z!==f)x(z),(z==null?void 0:z.id)!==(f==null?void 0:f.id)&&(I(z,F,!0),D.current=performance.now());else if(f&&z&&(m?m.currentTime:0)>=z.sourceOut-.01){const se=p(F+.001,y);x(se),I(se,F,!0),D.current=performance.now()}c-d.current>=Uo&&(d.current=c,h(F)),b.current=requestAnimationFrame(_)};return b.current=requestAnimationFrame(_),()=>{b.current&&cancelAnimationFrame(b.current),b.current=null}},[o,r]);const T=s.useCallback(()=>{u.current>=r&&(u.current=0,h(0)),a(!0)},[r]),w=s.useCallback(()=>{a(!1),h(u.current);const l=v.current;l&&!l.paused&&l.pause()},[]),$=s.useCallback(()=>{S.current?w():T()},[w,T]),X=s.useCallback(l=>{const _=Math.max(0,Math.min(r,l));u.current=_,h(_);const c=p(_,A.current);x(c),I(c,_,S.current),D.current=performance.now()},[r,p,x,I]);return{isPlaying:o,currentTime:i,currentTimeRef:u,play:T,pause:w,toggle:$,seek:X,setVideoEl:B,activeVideoSlice:j}}const zo=t=>new Promise(r=>{const o=t.type.startsWith("video/"),a=URL.createObjectURL(t);if(o){const i=document.createElement("video");i.preload="metadata",i.muted=!0,i.src=a;const h=()=>r({duration:isFinite(i.duration)?i.duration:0,hasVideo:i.videoWidth>0,hasAudio:!0});i.onloadedmetadata=h,i.onerror=()=>r({duration:0,hasVideo:!0,hasAudio:!0}),setTimeout(h,8e3)}else{const i=document.createElement("audio");i.preload="metadata",i.src=a;const h=()=>r({duration:isFinite(i.duration)?i.duration:0,hasVideo:!1,hasAudio:!0});i.onloadedmetadata=h,i.onerror=()=>r({duration:0,hasVideo:!1,hasAudio:!0}),setTimeout(h,8e3)}});function Vo({podcastId:t,initialProjectName:r}){const o=wt(),[a]=s.useState(r??"Untitled video project"),[i,h]=s.useState("16:9"),[u,v]=s.useState(40),[b,D]=s.useState([]),[d]=s.useState([]),[S,g]=s.useState(!1),[A,j]=s.useState(!1),[L,B]=s.useState(pt),[p,x]=s.useState(null),[R,I]=s.useState("clip");s.useEffect(()=>{if(B(pt),!t)return;let N=!1;return(async()=>{try{const{data:P,error:V}=await U.from("transcriptions").select("caption_styles").eq("podcast_id",t).maybeSingle();if(V)throw V;!N&&(P!=null&&P.caption_styles)&&typeof P.caption_styles=="object"&&B({...pt,...P.caption_styles})}catch(P){console.error("[VideoEditorLayout] Failed to load subtitle font:",P)}})(),()=>{N=!0}},[t]);const{tracks:T,slices:w,addSlice:$,moveSlice:X,resizeSlice:l,selectedSliceId:_,setSelectedSliceId:c,splitSlice:y,removeSlice:m,setSlices:f}=Lo(),F=s.useMemo(()=>w.length===0?60:Math.max(...w.map(N=>N.timelineStart+N.duration),30),[w]),{isPlaying:z,currentTime:J,currentTimeRef:se,toggle:re,seek:ee,setVideoEl:ae,activeVideoSlice:Y}=Oo({slices:w,duration:F}),te=(Y==null?void 0:Y.colorAdjust)??null,ie=(Y==null?void 0:Y.transform)??null,ue=s.useMemo(()=>w.find(N=>N.id===p&&N.hasVideo)??null,[p,w]),Oe=s.useCallback(N=>{const P=Y==null?void 0:Y.id;P&&f(V=>V.map(Q=>Q.id===P?{...Q,transform:N}:Q))},[Y==null?void 0:Y.id,f]),Pe=s.useCallback(N=>{f(P=>P.map(V=>V.id===N?{...V,transform:void 0}:V))},[f]),{effects:we,selectedFxId:me,selectFx:Ee,addFx:_e,moveFx:nt,resizeFx:Je,deleteFx:ze,updateFxConfig:Ve}=Ca({podcastId:t??null,duration:F}),jt=s.useCallback(async N=>{const P=[];for(const V of Array.from(N))try{const Q=await zo(V),Z=URL.createObjectURL(V),le={id:`m_${Date.now()}_${Math.random().toString(36).slice(2,7)}`,name:V.name,url:Z,duration:Q.duration,hasVideo:Q.hasVideo,hasAudio:Q.hasAudio};P.push(le)}catch(Q){console.error("[VideoEditor] probe failed",Q),k.error(`Could not import ${V.name}`)}P.length&&(D(V=>[...V,...P]),k.success(`Imported ${P.length} file${P.length>
841?"s":""}`))},[]),ve=s.useCallback((N,P,V)=>{const Q=N.dataTransfer.getData("application/x-video-media-id"),Z=b.find(ce=>ce.id===Q);if(!Z)return;const le=T.find(ce=>ce.id===P);if(!le)return;if(le.type==="video"&&!Z.hasVideo){k.error("Only video clips can be placed on video tracks.");return}if(le.type==="audio"&&!Z.hasAudio){k.error("Only audio clips can be placed on audio tracks.");return}const be=le.type==="video"&&Z.hasVideo&&Z.hasAudio,he=be?`av_${Date.now().toString(36)}_${Math.random().toString(36).slice(2,7)}`:void 0;if($({trackId:P,sourceUrl:Z.url,sourceId:Z.id,sourceDuration:Z.duration,sourceIn:0,sourceOut:Z.duration,timelineStart:V,duration:Z.duration,name:Z.name,hasVideo:le.type==="video"&&Z.hasVideo,hasAudio:le.type==="audio"&&Z.hasAudio,colorAdjust:le.type==="video"?Z.colorAdjust:void 0,linkId:he}),be){const ce=T.find(Le=>Le.type==="audio");ce&&$({trackId:ce.id,sourceUrl:Z.url,sourceId:Z.id,sourceDuration:Z.duration,sourceIn:0,sourceOut:Z.duration,timelineStart:V,duration:Z.duration,name:Z.name,hasVideo:!1,hasAudio:!0,linkId:he})}},[b,T,$]),it=s.useCallback(N=>{const P=w.find(V=>V.id===N);P!=null&&P.hasVideo&&(c(N),I("clip"),x(N),ee(Math.min(F,P.timelineStart+Math.min(P.duration/2,.05))))},[ee,c,w,F]),De=s.useCallback(N=>{p&&f(P=>{const V=P.find(Q=>Q.id===p);return V?P.map(Q=>(R==="track"?Q.trackId===V.trackId:Q.id===p)?{...Q,colorAdjust:N}:Q):P})},[R,p,f]),ye=s.useCallback((N,P)=>{N.dataTransfer.setData("application/x-fx-effect-type",P),N.dataTransfer.effectAllowed="copy"},[]),Ze=s.useCallback(N=>{N.dataTransfer.types.includes("application/x-fx-effect-type")&&(N.preventDefault(),N.dataTransfer.dropEffect="copy")},[]),lt=s.useCallback(N=>{const P=N.dataTransfer.getData("application/x-fx-effect-type");if(!P||P==="text")return;N.preventDefault();const V=N.currentTarget.getBoundingClientRect(),Q=N.clientX-V.left,Z=Math.max(0,Q/u);_e(P,Z,P==="freeze"?1.5:2),k.success(`Added ${P} FX`)},[u,_e]),Ce=s.useCallback(N=>{(N.dataTransfer.types.includes("application/x-fx-effect-type")||N.dataTransfer.types.includes("application/x-fx-effect"))&&(N.preventDefault(),N.dataTransfer.dropEffect="copy")},[]),et=s.useCallback(N=>{if((N.dataTransfer.getData("application/x-fx-effect-type")||N.dataTransfer.getData("application/x-fx-effect"))!=="text")return;N.preventDefault();const V=N.currentTarget.getBoundingClientRect(),Q=N.clientX-V.left,Z=Math.max(0,Q/u);let le,be=3;try{const he=N.dataTransfer.getData("application/x-fx-config");if(he){const ce=JSON.parse(he);ce.config&&(le=ce.config),typeof ce.defaultDuration=="number"&&(be=ce.defaultDuration)}}catch{}_e("text",Z,be,le),k.success("Added title")},[u,_e]),ke=s.useRef(null),je=s.useRef(null),Re=s.useRef(null),Me=s.useRef(!1),Se=s.useRef(!1),Ie=s.useRef(!1);At.useEffect(()=>{const N=document.querySelector('[data-video-timeline-scroller="true"]');if(!N)return;const P=()=>{const V=N.scrollLeft;ke.current&&ke.current.scrollLeft!==V&&(Me.current=!0,ke.current.scrollLeft=V),je.current&&je.current.scrollLeft!==V&&(Se.current=!0,je.current.scrollLeft=V),Re.current&&Re.current.scrollLeft!==V&&(Ie.current=!0,Re.current.scrollLeft=V)};return N.addEventListener("scroll",P,{passive:!0}),()=>N.removeEventListener("scroll",P)},[d.length]);const Fe=s.useCallback(N=>{const P=N==="fx"?Me:N==="title"?Se:Ie,V=N==="fx"?ke.current:N==="title"?je.current:Re.current;if(P.current){P.current=!1;return}if(!V)return;const Q=document.querySelector('[data-video-timeline-scroller="true"]');Q&&Q.scrollLeft!==V.scrollLeft&&(Q.scrollLeft=V.scrollLeft)},[]);return At.useEffect(()=>{const N=P=>{P.target instanceof HTMLInputElement||P.target instanceof HTMLTextAreaElement||(P.code==="Space"?(P.preventDefault(),re()):P.key.toLowerCase()==="s"&&_?y(_,J):(P.key==="Delete"||P.key==="Backspace")&&(me?ze(me):_&&m(_)))};return window.addEventListener("keydown",N),()=>window.removeEventListener("keydown",N)},[re,_,y,J,m,me,ze]),e.jsxs("div",{className:"h-screen w-full flex flex-col bg-background text-foreground",children:[e.jsxs("div",{className:"flex items-center justify-between px-5 py-2.5 shrink-0 border-b border-border/60 relative",style:{background:"linear-gradient(180deg, hsl(var(--background-elevated)) 0%, hsl(var(--background)) 100%)",boxShadow:"0 1px 0 hsl(0 0% 100% / 0.04) inset, 0 1px 12px hsl(215 50% 5% / 0.25)"},children:[e.jsx("div",{className:"pointer-events-none absolute inset-x-0 top-0 h-px bg-gradient-to-r from-transparent via-primary/30 to-transparent"}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs(W,{variant:"ghost",size:"sm",onClick:()=>o("/choose"),className:"tactile-button h-8 gap-1.5 rounded-md text-xs font-medium px-3",children:[e.jsx(rr,{className:"h-3.5 w-3.5"})," Switch editor"]}),e.jsx("div",{className:"h-5 w-px bg-border/70"}),e.jsx("div",{className:"text-sm font-semibold tracking-tight heading-premium",children:a}),e.jsx("span",{className:"text-[10px] uppercase tracking-[0.12em] font-semibold px-2 py-0.5 rounded-full text-primary border border-primary/40",style:{background:"linear-gradient(135deg, hsl(var(--primary) / 0.18), hsl(var(--primary) / 0.08))",boxShadow:"0 0 0 1px hsl(var(--primary) / 0.1) inset, 0 0 12px hsl(var(--primary) / 0.15)"},children:"Video editor"})]}),e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsxs(bs,{value:i,onValueChange:N=>h(N),children:[e.jsx(ws,{className:"tactile-button h-8 w-[130px] text-xs font-medium rounded-md border-0",children:e.jsx(ys,{})}),e.jsxs(js,{children:[e.jsx(xt,{value:"16:9",children:"16:9 Landscape"}),e.jsx(xt,{value:"9:16",children:"9:16 Vertical"}),e.jsx(xt,{value:"1:1",children:"1:1 Square"})]})]}),e.jsx(W,{size:"sm",variant:"outline",className:"h-8 px-3 text-xs",onClick:()=>j(!0),disabled:!t,children:"Subtitle font"}),e.jsxs(W,{size:"sm",className:"bake-cta h-8 gap-1.5 px-4 text-xs",onClick:()=>g(!0),disabled:w.length===0,children:[e.jsx(Ke,{className:"h-3.5 w-3.5"})," Export"]})]})]}),e.jsxs(ka,{direction:"horizontal",className:"flex-1 min-h-0",children:[e.jsx(Ft,{defaultSize:20,minSize:14,children:e.jsxs("div",{className:"h-full flex flex-col border-r border-white/10",children:[e.jsx("div",{className:"flex-1 min-h-0 p-2",children:e.jsx(Ao,{items:b,onImport:jt,onDragStart:()=>{}})}),e.jsxs("div",{className:"h-[40%] min-h-[180px] border-t border-white/10",children:[e.jsxs("div",{className:"px-3 py-2 text-[10px] uppercase tracking-wider text-white/50 flex items-center gap-1.5",children:[e.jsx(Xt,{className:"h-3 w-3"})," Drag effects to FX track"]}),e.jsx("div",{className:"h-[calc(100%-32px)]",children:e.jsx(Ra,{onDragStart:ye})})]})]})}),e.jsx(Ma,{}),e.jsx(Ft,{defaultSize:80,children:e.jsxs("div",{className:"h-full flex flex-col p-2 gap-2",children:[e.jsx("div",{className:"flex-1 min-h-0",children:e.jsx(Ys,{setVideoEl:ae,aspectRatio:i,effects:we,captions:d,captionStyles:L,currentTimeRef:se,colorAdjust:te,clipTransform:ie,canTransform:!!Y,onClipTransformChange:Oe})}),e.jsxs("div",{className:"flex items-center gap-3 px-2 py-1 bg-card/40 border border-white/10 rounded-md",children:[e.jsx(W,{size:"icon",variant:"ghost",onClick:re,className:"h-8 w-8",children:z?e.jsx(la,{className:"h-4 w-4"}):e.jsx(ca,{className:"h-4 w-4"})}),e.jsxs("div",{className:"text-xs font-mono text-muted-foreground tabular-nums",children:[Wt(J)," / ",Wt(F)]}),e.jsx("input",{type:"range",min:0,max:F,step:.05,value:J,onChange:N=>ee(parseFloat(N.target.value)),className:"flex-1 accent-primary"}),e.jsx("div",{className:"text-[10px] text-muted-foreground",children:"Zoom"}),e.jsx("input",{type:"range",min:10,max:200,step:1,value:u,onChange:N=>v(parseInt(N.target.value,10)),className:"w-24 accent-primary"})]})]})})]}),e.jsxs("div",{className:"h-[40%] min-h-[300px] shrink-0 p-2 border-t border-white/10 flex flex-col gap-1.5",children:[e.jsxs("div",{className:"shrink-0",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] uppercase tracking-wider text-white/50 mb-1 px-1",children:[e.jsx(Aa,{className:"h-3 w-3 text-primary"})," Title Track"]}),e.jsx("div",{ref:je,onScroll:()=>Fe("title"),className:"h-12 overflow-x-auto",children:e.jsx(Lt,{effects:we.filter(N=>N.effectType==="text"),duration:Math.max(F,30),currentTimeRef:se,pixelsPerSecond:u,selectedFxId:me,onFxSelect:Ee,onFxMove:nt,onFxResize:Je,onFxDelete:ze,onFxConfigChange:Ve,onSeek:ee,onDragOver:Ce,onDrop:et,emptyMessage:"Drag titles here from the titles library"})})]}),e.jsxs("div",{className:"shrink-0",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] uppercase tracking-wider text-white/50 mb-1 px-1",children:[e.jsx(Xt,{className:"h-3 w-3 text-primary"})," FX Track"]}),e.jsx("div",{ref:ke,onScroll:()=>Fe("fx"),className:"h-12 overflow-x-auto",children:e.jsx(Lt,{effects:we.filter(N=>N.effectType!=="text"),duration:Math.max(F,30),currentTimeRef:se,pixelsPerSecond:u,selectedFxId:me,onFxSelect:Ee,onFxMove:nt,onFxResize:Je,onFxDelete:ze,onFxConfigChange:Ve,onSeek:ee,onDragOver:Ze,onDrop:lt,emptyMessage:"Drag FX here from the FX library"})})]}),d.length>0&&e.jsxs("div",{className:"shrink-0",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] uppercase tracking-wider text-white/50 mb-1 px-1",children:[e.jsx(As,{className:"h-3 w-3 text-primary"})," Subtitles"]}),e.jsx("div",{ref:Re,onScroll:()=>Fe("cap"),className:"h-10 overflow-x-auto",children:e.jsx(Pa,{captions:d,duration:Math.max(F,30),currentTimeRef:se,pixelsPerSecond:u,selectedCaptionId:null,onCaptionSelect:()=>{},onCaptionMove:()=>{},onCaptionResize:()=>{},onCaptionSplit:()=>{},onCaptionDelete:()=>{},onCaptionTextChange:()=>{},onSeek:ee})})]}),e.jsx("div",{className:"flex-1 min-h-0",children:e.jsx(Mo,{tracks:T,slices:w,duration:F,currentTime:J,pixelsPerSecond:u,onSeek:ee,selectedSliceId:_,onSelect:c,onMove:X,onResize:l,onDropMedia:ve,onOpenColorCorrection:it,onRemoveSlice:m,onResetSliceTransform:Pe})})]}),e.jsx(Do,{open:S,onOpenChange:g,slices:w,effects:we,captions:d,captionStyles:L,aspectRatio:i}),e.jsx(Da,{open:A,onOpenChange:j,podcastId:t||null,styles:L,onStylesChange:B}),ue&&e.jsx(Ia,{open:!!ue,onOpenChange:N=>{N||x(null)},clipName:ue.name,sourceUrl:ue.sourceUrl,value:ue.colorAdjust,onChange:De,applyScope:R,onApplyScopeChange:I,trackLabel:ue.trackId.toUpperCase()})]})}function Wt(t){if(!isFinite(t))return"00:00";const r=Math.floor(t/60).toString().padStart(2,"0"),o=Math.floor(t%60).toString().padStart(2,"0"),a=Math.floor(t%1*100).toString().padStart(2,"0");return`${r}:${o}.${a}`}const Yt="studioeditor:lastEditor",Rr="Edit video podcasts in your browser with synchronized audio and video, Speaker AutoCut, transcript-based cuts, person-centered auto reframe, subtitles and Full HD export.",Xo="StudioEditor Video Podcast Editor is a browser-based multitrack video and audio editor for video podcasts, interviews and multi-camera conversations. Transcribe first to enable text-based video editing: likely filler words are selected for review, and deleting any selected word, sentence or transcript range cut
84s the linked audio and video together. Speaker AutoCut aligns participant videos from their audio and switches the program view according to who is speaking. Auto reframe analyzes the timeline for people, zooms each camera angle and centers the detected speaker using pose landmarks. Media files land at the chosen timeline drop position, and finished video can be exported at up to Full HD 1080p. Optional tools include clip stabilization, profanity censoring, speech enhancement and a complete content package.",Bo={"@context":"https://schema.org","@type":"SoftwareApplication",name:"StudioEditor Video Podcast Editor",alternateName:["StudioEditor Video Editor","StudioEditor Video Podcast Editor"],url:"https://studioeditor.io/video",description:Rr,applicationCategory:"MultimediaApplication",applicationSubCategory:"Browser-based video podcast editor",operatingSystem:"Web",browserRequirements:"Requires a modern desktop browser: Chrome, Edge, Firefox or Safari.",featureList:["Browser-based multitrack video and audio timeline editing","Text-based video editing that cuts linked audio and video together","Automatic filler-word selection for transcript review","Audio-based synchronization for participant video recordings","Speaker AutoCut that switches video according to the active speaker","Synchronized Remotion preview and program rendering","Precise media placement at the selected timeline drop position","Video export up to Full HD 1080p","Person-centered auto reframe, clip stabilization and optional profanity censoring","Speech gating, enhancement, transcription, subtitles, automixing, AutoDuck and EQ"],audience:{"@type":"Audience",audienceType:"Podcasters, video podcasters, interviewers and creators editing multi-camera conversations"}};function ai(){const[t]=Kt(),r=da(),o=wt();s.useLayoutEffect(()=>(document.documentElement.classList.add("studioeditor-video-editor"),()=>{document.documentElement.classList.remove("studioeditor-video-editor")}),[]),s.useEffect(()=>{if(t.get("type")==="video")try{localStorage.setItem(Yt,"video")}catch{}},[t]);const a=t.get("next")==="1";
84if(t.get("type")==="audio"){const i=new URLSearchParams(r.search);return i.set("type","audio"),e.jsx(Pt,{to:`/?${i.toString()}`,replace:!0})}if(!t.get("type")){const i=h=>{try{localStorage.setItem(Yt,h)}catch{}const u=new URLSearchParams(r.search);if(u.set("type",h),h==="audio"){o(`/?${u.toString()}`);return}o(`/video?${u.toString()}`)};return e.jsxs(e.Fragment,{children:[e.jsx(Dt,{title:"Choose editor — StudioEditor.io",description:"Choose whether to open the podcast editor or the video podcast editor.",path:"/video"}),e.jsx("div",{className:"min-h-screen w-full bg-background text-foreground",children:e.jsxs("div",{className:"mx-auto flex min-h-screen w-full max-w-5xl flex-col items-center justify-center px-5 py-12 sm:px-8",children:[e.jsx("div",{className:"mb-10 text-center",children:e.jsx("h1",{className:"text-4xl font-semibold leading-tight tracking-tight text-foreground sm:text-5xl",children:"Choose your weapon"})}),e.jsxs("div",{className:"grid w-full max-w-4xl gap-3 sm:grid-cols-2",children:[e.jsxs("button",{type:"button",onClick:()=>i("video"),className:"group flex min-h-[250px] flex-col justify-between rounded-lg border border-primary/30 bg-primary/[0.07] p-6 text-left shadow-2xl shadow-black/20 outline-none backdrop-blur-xl transition-all duration-200 hover:-translate-y-0.5 hover:border-primary/50 hover:bg-primary/[0.1] focus-visible:ring-2 focus-visible:ring-primary/70",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-xl font-semibold tracking-tight",children:"Video podcast editor"}),e.jsx("p",{className:"mt-3 text-sm leading-6 text-muted-foreground",children:"Edit linked audio and video from a transcript, switch speakers with AutoCut, auto reframe, stabilize clips, censor profanity, enhance speech and generate subtitles."})]}),e.jsx("span",{className:"mt-7 inline-flex h-9 w-fit items-center rounded-md border border-white/[0.12] bg-white/[0.055] px-4 text-sm font-medium text-foreground shadow-sm shadow-black/10 transition-colors group-hover:border-primary/35 group-hover:bg-primary/[0.09]",children:"Open"})]}),e.jsxs("button",{type:"button",onClick:()=>i("audio"),className:"group flex min-h-[250px] flex-col justify-between rounded-lg border border-white/[0.09] bg-white/[0.04] p-6 text-left shadow-2xl shadow-black/20 outline-none backdrop-blur-xl transition-all duration-200 hover:-translate-y-0.5 hover:border-primary/35 hover:bg-white/[0.06] focus-visible:ring-2 focus-visible:ring-primary/70",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-xl font-semibold tracking-tight",children:"Podcast editor"}),e.jsx("p",{className:"mt-3 text-sm leading-6 text-muted-foreground",children:"Multitrack audio editing with automatic speech enhancement, autogain, automixing, speech-pause removal, multilingual transcription, subtitles and more."})]}),e.jsx("span",{className:"mt-7 inline-flex h-9 w-fit items-center rounded-md border border-white/[0.12] bg-white/[0.055] px-4 text-sm font-medium text-foreground shadow-sm shadow-black/10 transition-colors group-hover:border-primary/35 group-hover:bg-primary/[0.09]",children:"Open"})]})]})]})})]})}
84if(t.get("type")!=="video"){const i=new URLSearchParams(r.search);return i.set("type","video"),e.jsx(Pt,{to:`/video?${i.toString()}`,replace:!0})}return e.jsxs(e.Fragment,{children:[e.jsx(Dt,{title:"Online Video Podcast Editor with Speaker AutoCut | StudioEditor",description:Rr,path:"/video",keywords:"online video podcast editor, video podcast editor, podcast video editor, online video editor, browser video editor, Full HD video editor, 1080p video export, text based video editing, transcript based video editing, edit video by editing text, remove filler words from video, linked audio and video cuts, speaker autocut, active speaker video editing, automatic multicamera editing, synchronize video by audio, multitrack video editor, podcast video editing, person centered auto reframe, auto reframe video, video clip stabilization, profanity censoring video, Remotion video editor, audio and video timeline editor",aiDescription:Xo,jsonLd:Bo,imageAlt:"StudioEditor browser-based video podcast editor"}),a?e.jsx(Vo,{podcastId:t.get("podcast"),initialProjectName:t.get("project")??void 0}):e.jsx(Os,{}),e.jsx(ua,{})]})}export{ai as default};
85//# sourceMappingURL=VideoProcess-DJK4v8xa.js.map

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.