PageSourceSearch

https://app.bhuman.ai/assets/_id_-aca89fb2.js

js bhuman.ai collected 2026-10-04 00:01:02 UTC 158,889 bytes, 6 lines download raw bytes

1import{H as li,I as ds,bj as Ir,L as Lr,K as cs,t as u,d as je,aj as kt,i,c as a,bo as Mr,S as E,e as M,G as lt,a as C,O as us,cB as x,h as Y,g4 as di,dY as Bt,cU as it,g5 as ci,g6 as gs,f7 as Ln,g7 as ps,cQ as nt,j as Je,cO as ms,s as te,ao as Qn,ew as fs,f0 as Ti,f2 as Kt,n as ht,f1 as hs,b as B,c1 as ui,bV as gi,y as Ae,aY as Ni,F as rt,cW as bs,g8 as vs,dW as Pr,o as Lt,l as zt,bM as bn,c5 as _s,aa as Mt,P as Ei,e2 as Mn,ea as xs,eb as ws,ec as $s,e7 as ys,ed as Ss,ee as Ai,k as Rr,aL as Jt,eO as Cs,eR as ks,g9 as ut,bx as Ts,c0 as Fr,ei as En,ga as jn,aH as Vi,eV as Kn,eU as Zn,gb as Ns,A as Es,dZ as As,f5 as Vs,gc as Is,gd as Xn,aG as Ls,ge as Ms,aE as Gn,aF as Ps,cy as Ii,E as Rs,e1 as sn,aN as Li,gf as Mi,cI as Pi,e3 as Ri,gg as zn,e0 as Fs,eT as Ds,au as Ws,cP as js}from"./index-a5b00a63.js";import{g as et,v as Ye,E as pi,r as vn,a as _n,F as Dr,c as mn,d as fn,I as Wr,U as mi,n as Qt,s as Vt,J as Gs,V as zs,G as ei,K as Fi,f as Pn,L as an,M as hn,e as ti,w as Di,b as Wi,N as Bs,O as Us,P as Os,Q as qs}from"./VariableMappings-0d2e1fbf.js";import{b as bt,d as gn,c as Hs,e as ni,f as Ht,g as pn,p as ii,s as ri,a as xt,h as yt,i as Ys,j as jt,k as Ot,l as Cn,m as ji,u as Gi,t as zi,n as Bi,o as Js,q as Qs,F as Ks}from"./store-2207a2e5.js";import{C as jr}from"./Check-abd84874.js";import{i as Le,d as Gr,t as Ui,m as Bn,a as Zs,b as Xs,u as ea,e as on,p as St,T as Oi,f as Un,h as Ct,j as qi,W as Hi,k as ta,l as na,n as ia}from"./templateSetupFlow-fba30bb3.js";import{T as ra}from"./Trash-9f61ad85.js";import{a as sa}from"./index-123f3325.js";import{g as aa}from"./webhook-79cbe812.js";import{h as oa,f as la,a as da}from"./privateGuidedSetup-84f9c13d.js";import{s as ca,R as ua}from"./createInstance-3809e6f6.js";import{D as Yi}from"./button-770cab64.js";import"./ChevronLeft-ff2bd643.js";import"./Email-13a6862e.js";import"./campaignSharing-f95bcc25.js";import"./index-1abd23c5.js";import"./interpolation-9bb58895.js";import"./index-0636f0a4.js";import"./Upload-8057589b.js";const ga=e=>li(ds("api/v2/voice/advanced_config",e,"https://voice.dev.bhuman.ai/")),pa=(e,t)=>li(Ir("api/ai_studio/segment/voice_config",{id:e,voice_config:t},"https://studio.dev.bhuman.ai/")),ma=e=>li(Lr(cs("api/ai_studio/campaigns",{video_instance_id:e}),"https://studio.dev.bhuman.ai/")),fa=u(`<div class="w-full p-4 flex flex-col justify-center items-center gap-20"><div class="flex flex-col justify-center gap-4 w-full max-w-[1100px] divide-y-1"><div class="flex items-center justify-between gap-8
2         rounded-[8px] w-full animate-pulse bg-gray-300 h-10"></div><div class="flex w-full flex-col justify-between gap-8 md:flex-row"><div class="flex w-full flex-col justify-between gap-3 max-h-max overflow-y-auto md:w-[60%]"><div class="w-full flex
3           items-center justify-center h-[400px] bg-gray-300 animate-pulse rounded-[8px]"></div><div class="h-16 rounded-[8px] bg-gray-300 animate-pulse"></div><div class="h-16 rounded-[8px] bg-gray-300 animate-pulse"></div></div><div class="flex w-full flex-col justify-between gap-2 max-h-max overflow-y-auto md:w-[40%]"><div class="flex flex-col gap-2 "><div class="flex flex-wrap gap-1 p-2 h-16 rounded-[8px] animate-pulse bg-gray-300"></div><div class="overflow-y-auto h-16 rounded-[8px] animate-pulse bg-gray-300"></div><div class="flex flex-col p-2 gap-10  h-16 rounded-[8px] animate-pulse bg-gray-300"></div></div></div></div></div></div>`),zr=()=>fa.cloneNode(!0),Ji=u("<div></div>"),ha=u(`<button class="flex justify-center items-center w-[284px] 
4          relative overflow-hidden gap-2 p-3 rounded-[8px] text-white
5         bg-[#187ee7] cursor-pointer "></button>`),ba=e=>(()=>{const t=ha.cloneNode(!0);return kt(t,"click",e.onClick,!0),i(t,a(E,{get when(){return e.loading},get fallback(){return(()=>{const n=Ji.cloneNode(!0);return i(n,()=>e.text),n})()},get children(){return[(()=>{const n=Ji.cloneNode(!0);return i(n,()=>e.fallbackText),n})(),a(Mr,{color:"white"})]}})),M(n=>{const r=e.loading||e.disabled,s={"opacity-70":e.loading||e.disabled,"hover:bg-[#186be7]":!e.loading&&!e.disabled};return r!==n._v$3&&(t.disabled=n._v$3=r),n._v$4=lt(t,s,n._v$4),n},{_v$3:void 0,_v$4:void 0}),t})();je(["input","click"]);const Br=e=>e.filter(t=>t.kind===-1&&!!t.name?.trim()).slice().sort((t,n)=>(t.highlight_si??Number.MAX_SAFE_INTEGER)-(n.highlight_si??Number.MAX_SAFE_INTEGER)||String(t.name).localeCompare(String(n.name))||String(t.id).localeCompare(String(n.id))),va=e=>{for(const t of e)if(String(t).startsWith("manual:"))return!1;return!0},_a=({segments:e,manualVariableStartTimes:t,savedValues:n,lipsyncEnabled:r})=>{const s=Br(e).map(m=>
5String(m.name).trim()),c=new Set(s),o=r?[]:Object.keys(t||{}).filter(m=>!!m.trim()&&!c.has(m)),g=[...s,...o],p=(n||[]).map(m=>String(m??""));return g.length?g.length!==p.length||p.some(m=>!m.trim())?{ok:!1,message:"The template variables changed after this attempt. Use Try sample to review them."}:{ok:!0,variables:g,values:p}:{ok:!1,message:"This template no longer has variables to retry."}},xa=new Set(["preparing","queued","processing","pending"]),wa=e=>String(e?.status||"").trim().toLowerCase(),Ur=e=>e.some(t=>xa.has(wa(t))),$a=(e,t)=>{const n=t.map(s=>String(s).trim()).filter(Boolean);return!(n.length===0||n.every(s=>e.some(c=>c?.id===s)))||Ur(e)},ya=async({state:e,trackedIds:t,refresh:n})=>{if(e.stopped||e.inFlight)return{kind:"skipped",videos:null};e.inFlight=!0;try{const r=await n();if(e.stopped)return{kind:"skipped",videos:null};const s=$a(r,t);return s||(e.stopped=!0),{kind:s?"active":"settled",videos:r}}finally{e.inFlight=!1}},Qi=e=>String(e||"").trim(),Ki=(e,t)=>{const n=Qi(t);return n?e.filter(r=>{if(!r||r.campaign_id!=null)return!1;const s=Qi(r.video_instance_id);return!s||s===n}).map(r=>({...r,video_instance_id:n})):[]},Sa=(e,t,n)=>{const r=new Map;return Ki(e,n).forEach(s=>{s.id&&r.set(s.id,s)}),Ki(t,n).forEach(s=>{s.id&&r.set(s.id,{...r.get(s.id),...s})}),Array.from(r.values()).sort((s,c)=>new Date(c.updated_at||c.created_at||0).getTime()-new Date(s.updated_at||s.created_at||0).getTime())},Ca=e=>String(e?.message||"").trim().toLowerCase().startsWith("audio preview"),[We,fi]=C([]),[wt,Or]=C("");us({});const Gt=new Map,hi=(e,t=wt())=>{const n=String(t||"").trim();if(!n||n!==wt())return We();let r=[];return fi(s=>(r=Sa(s,e.filter(c=>!Ca(c)),n),r)),r},qr=(e,t,n=x.id)=>{const r=new Date().toISOString();return hi(e.map(s=>({id:s,video_instance_id:n,status:"processing",created_at:r,updated_at:r,text:t,message:"Sample generation has started."})),n)},bi=e=>Ur(e),ka=async(e=x.id)=>{if(!e||e!==wt())return[];const t=await gs(e,0,20);return e!==wt()?[]:t?.code!==200?We():hi(t.result?.videos||[],e)},vi=(e,t=x.id)=>{if(typeof window>"u"||!t)return;const n=e.map(g=>String(g).trim()).filter(Boolean),r=Gt.get(t);if(r&&!r.state.stopped){n.forEach(g=>r.trackedIds.add(g)),n.length===0&&(r.trackAll=!0);return}r&&(window.clearInterval(r.intervalId),Gt.delete(t));const s={intervalId:0,state:{inFlight:!1,stopped:!1},trackedIds:new Set(n),trackAll:n.length===0},c=()=>{window.clearInterval(s.intervalId),Gt.get(t)===s&&Gt.delete(t)},o=async()=>{try{if(t!==wt()){s.state.stopped=!0,c();return}const g=await ya({state:s.state,trackedIds:s.trackAll?[]:Array.from(s.trackedIds),refresh:()=>ka(t)});g.videos&&t===wt()&&bt(bi(g.videos)),g.kind==="settled"&&c()}catch(g){console.error(g)}};s.intervalId=window.setInterval(o,5e3),Gt.set(t,s),o()},Hr=()=>{Gt.forEach(e=>{e.state.stopped=!0,window.clearInterval(e.intervalId)}),Gt.clear()},_i=e=>{const t=String(e||"").trim();!t||t===wt()||(Hr(),Or(t),fi([]),bt(!1))},Yr=(e=wt())=>{const t=String(e||"").trim();t&&t!==wt()||(Hr(),Or(""),fi([]),bt(!1))},Jr=e=>(Array.isArray(e)?e:Array.isArray(e?.ids)?e.ids:e?.id?[e.id]:[]).map(n=>String(n).trim()).filter(Boolean),Zi=async e=>{const t=String(x?.id||"").trim();if(!t){Y.error("Couldn’t identify this template. Please reload and try again.");return}const n=di();if(n.length>0){Y.error(`Reselect ${n.join(", ")} in the transcript before retrying.`);return}const r=et();let s=x?.segments||[];try{const o=await Bt.list({video_instance_id:t});o?.result?.length&&(s=o.result)}catch(o){console.warn("Couldn’t refresh template variables before retrying",o)}const c=_a({segments:s,manualVariableStartTimes:Ye(),savedValues:e?.text,lipsyncEnabled:r});if(!c.ok){Y.error(c.message);return}bt(!0);try{const o=r,g=pi({variableNames:c.variables,segments:s,manualStartTimes:Ye(),config:x?.variable_timing_config,requireNamedSegments:!0}),p=vn(x),m=_n(x),h=Dr(p,m);await it.update({id:t,enable_lipsync:o,variable_start_times:g.variable_start_times,variable_timing_config:mn(fn(g.variable_timing_config,p),m)});const d=await Wr({variables:c.variables,names:[c.values],video_instance_id:t,lipsync:o,enable_lipsync:o,variable_start_times:g.variable_start_times,audio_start_seconds:g.audio_start_seconds,audio_window_end_seconds:g.audio_window_end_seconds,audio_window_anchor:g.audio_window_anchor,audio_window_fit:g.audio_window_fit,generation_mode:p,lipsync_quality:m,render_qual
5ity:m,credit_multiplier:h,...ci()});if(!d||d.code!==200)throw new Error("Sample retry request failed.");const b=Jr(d.result);if(!b.length)throw new Error("Sample retry returned no generation IDs.");qr(b,c.values,t),vi(b,t)}catch(o){console.error(o),Y.error("Couldn’t retry this sample. Please try again."),bt(bi(We()))}},Qr=e=>{const t=String(e??x.id??"").trim();if(!t)return;Ln()&&Ln().close();const n=new Set,r=new Set(["preparing","queued","processing","pending"]);ps(t,s=>{if(wt()!==t)return;const c=s.generated_events,o=s?.percent_of_face;if(o==="failed"){Y.error("Face detection failed. Please try again."),gn(!1);return}o!==null&&o!==""&&nt({...x,video_percent_of_face:o??""}),c?.forEach(m=>{if(m?.campaign_id!=null||m?.video_instance_id&&m.video_instance_id!==t)return;const h={...m,video_instance_id:t},d=[...n].find(b=>b.id===h.id);d&&n.delete(d),n.add(h)});const g=Array.from(n).map(m=>{const d=(m?.message||"").trim().toLowerCase().includes("video generation has started");return m?.status==="failed"&&d?{...m,status:"processing"}:m}),p=g.length?hi(g,t):We();bt(p.some(m=>r.has(m?.status||""))||g.some(m=>r.has(m?.status||"")))},"instance")},Ta=u('<div class="flex min-w-0 shrink gap-2 rounded-[8px] border border-gray-300 px-4 py-2 text-[17px] items-center md:max-w-[60%] w-full md:w-auto"><div class="flex min-w-0 max-w-full cursor-text items-center gap-4 whitespace-nowrap leading-6 font-semibold outline-none"><span class="block min-w-0 truncate"></span><div class="cursor-pointer max-w-max"></div></div></div>'),Xi=e=>(()=>{const t=Ta.cloneNode(!0),n=t.firstChild,r=n.firstChild,s=r.nextSibling,c=e.instanceNameRef;return typeof c=="function"?Je(c,n):e.instanceNameRef=n,i(r,()=>x.name),s.$$click=async()=>{if(e.editInstance()){const o=await it.update({id:x.id,name:e.instanceNameRef.textContent});nt(o.result)}else e.instanceNameRef.focus();e.setEditInstance(!e.editInstance())},i(s,a(E,{get when(){return!e.editInstance()},get fallback(){return a(jr,{})},get children(){return a(ms,{})}})),M(o=>{const g=!!e.editInstance(),p=!!e.missingVariables(),m=e.editInstance();return g!==o._v$&&t.classList.toggle("border-[#187ee7]",o._v$=g),p!==o._v$2&&t.classList.toggle("border-[#e7183b]",o._v$2=p),m!==o._v$3&&te(n,"contenteditable",o._v$3=m),o},{_v$:void 0,_v$2:void 0,_v$3:void 0}),t})();je(["click"]);const Na=u("<div></div>"),Ea=u('<button type="button" data-microtip-position="bottom" data-microtip-size="medium"><span></span></button>'),On=e=>{const t="relative inline-flex min-h-[52px] items-center justify-center rounded-[8px] px-5 py-3 text-center text-[14px] font-semibold leading-none transition-colors",n=e.secondary?"border border-[#B8D3F6] bg-white text-[#111827] hover:border-[#187EE7] hover:bg-[#F8FBFF]":"bg-[#187EE7] text-white hover:bg-[#166FD0]",r=e.disabled?"cursor-not-allowed opacity-60":"cursor-pointer";return(()=>{const s=Ea.cloneNode(!0),c=s.firstChild;kt(s,"click",e.onClick,!0);const o=e.buttonRef;return typeof o=="function"?Je(o,s):e.buttonRef=s,Qn(s,`${`${t} ${n} ${r} w-full gap-2 whitespace-normal sm:whitespace-nowrap`||""} pointer-events-auto`),i(s,a(E,{get when(){return e.disabled},get children(){const g=Na.cloneNode(!0);return i(g,a(fs,{size:20})),g}}),c),i(c,()=>e.name),M(g=>{const p=!!e.missingVariables,m=e?.message,h=e?.disabled?"tooltip":"none",d=e.disabled;return p!==g._v$&&s.classList.toggle("opacity-50",g._v$=p),m!==g._v$2&&te(s,"aria-label",g._v$2=m),h!==g._v$3&&te(s,"role",g._v$3=h),d!==g._v$4&&(s.disabled=g._v$4=d),g},{_v$:void 0,_v$2:void 0,_v$3:void 0,_v$4:void 0}),s})()};je(["click"]);const Aa=u('<p class="sm:col-span-2 text-[12px] leading-5 text-[#8A5A00]"></p>'),Va=u('<div class="grid w-full grid-cols-1 gap-3 sm:grid-cols-2 md:w-auto md:min-w-[440px] md:max-w-[520px] md:justify-end"></div>'),er=e=>{const{missingVariables:t,missingVariablesMessage:n,setPreviewSampleModal:r,setCreateCampaignModal:s,setUploadTemplateModal:c,trySampleRef:o,createCampaignRef:g,suppressMissingVariablesNotice:p,secondaryActions:m}=e,h=()=>t()?n():hs;return(()=>{const d=Va.cloneNode(!0);return i(d,a(Kt,{get aria_label(){return h()},data_microtip_position:"bottom",data_microtip_size:"medium",get disabled(){return t()||Ti==!0},class:"w-full",get children(){return a(On,{name:"Try sample",buttonRef:o,onClick:()=>
5{if(t()){Y.error(n());return}r(!0)},secondary:!0,get missingVariables(){return t()},get message(){return h()},get disabled(){return t()}})}}),null),i(d,a(Kt,{get aria_label(){return h()},data_microtip_position:"bottom",data_microtip_size:"medium",get disabled(){return t()||Ti==!0},class:"w-full",get children(){return a(On,{name:"Create new campaign",buttonRef:g,onClick:()=>{if(t()){Y.error(n());return}s(!0)},secondary:m,get missingVariables(){return t()},get message(){return h()},get disabled(){return t()}})}}),null),i(d,a(E,{get when(){return!Le(x)&&ht?.userInfo?.user_id==="user-live-2aa9bbc7-b507-4825-bd22-a64de30b90f3"},get children(){return a(On,{name:"Upload Template",onClick:()=>{if(t()){Y.error("Your project is missing either a video or variable. Please complete it in order to continue");return}c(!0)},get missingVariables(){return t()},secondary:m})}}),null),i(d,a(E,{get when(){return n()&&!p},get children(){const b=Aa.cloneNode(!0);return i(b,n),b}}),null),d})()},Ia=u('<div class="flex w-full items-center justify-between gap-3 rounded-[8px] border border-border bg-card px-3 py-2"><div><p class="text-[13px] font-semibold text-foreground">Generated preview</p><p class="text-[12px] text-muted-foreground">Selected from the videos below</p></div><button type="button" class="shrink-0 rounded-[8px] px-3 py-2 text-[13px] font-semibold text-primary hover:bg-muted focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary">Back to template</button></div>'),La=u('<video class="mx-auto block h-auto max-h-[70vh] w-auto max-w-full flex-shrink-0 rounded-[8px] bg-black object-contain" controls playsinline></video>'),Ma=u('<div class="flex w-full max-h-max flex-col items-start justify-start gap-4"></div>'),Pa=u('<div class="w-full justify-center items-center"></div>'),Ra=u('<p role="status">Preparing your Welcome practice video…</p>'),tr=e=>{const t=()=>`https://s3.${ui}.amazonaws.com/${gi}/${x?.video_url}`,n=()=>e.selectedGeneratedVideo||t();return(()=>{const r=Ma.cloneNode(!0);return i(r,a(E,{get when(){return B(()=>!!x?.video_url)()&&e.isVideoAvailable()},get fallback(){return(()=>{const s=Pa.cloneNode(!0);return i(s,a(E,{get when(){return!Le(x)},get fallback(){return Ra.cloneNode(!0)},get children(){return a(mi,{type:"video",onUploadComplete:async c=>{if(!Le(x))try{const o=await it.update({id:x.id,video_id:c});nt(o.result),e.setIsVideoAvailable(!0)}catch(o){Y.error(o.message)}}})}})),s})()},get children(){return[a(E,{get when(){return e.selectedGeneratedVideo},get children(){const s=Ia.cloneNode(!0),c=s.firstChild,o=c.nextSibling;return kt(o,"click",e.onShowTemplate,!0),s}}),(()=>{const s=La.cloneNode(!0);s.addEventListener("ended",()=>{e.selectedGeneratedVideo&&e.onSampleEnded?.()});const c=e.videoRef;return typeof c=="function"?Je(c,s):e.videoRef=s,M(()=>te(s,"src",n())),s})()]}})),r})()};je(["click"]);const Fa=u('<div><svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M6.76733 7.74335L10.0007 10.9767L13.234 7.74335C13.3111 7.6662 13.4027 7.605 13.5035 7.56325C13.6043 7.52149 13.7124 7.5 13.8215 7.5C13.9306 7.5 14.0386 7.52149 14.1394 7.56325C14.2402 7.605 14.3318 7.6662 14.409 7.74335C14.4861 7.8205 14.5473 7.91209 14.5891 8.0129C14.6309 8.1137 14.6523 8.22174 14.6523 8.33085C14.6523 8.43996 14.6309 8.548 14.5891 8.6488C14.5473 8.74961 14.4861 8.8412 14.409 8.91835L10.584 12.7434C10.259 13.0684 9.73399 13.0684 9.40899 12.7434L5.58399 8.91835C5.50674 8.84126 5.44545 8.74968 5.40363 8.64887C5.36181 8.54806 5.34029 8.43999 5.34029 8.33085C5.34029 8.22171 5.36181 8.11364 5.40363 8.01283C5.44545 7.91202 5.50674 7.82045 5.58399 7.74335C5.90899 7.42668 6.44233 7.41835 6.76733 7.74335Z" fill="black"></path></svg></div>'),Da=u('<div><div class="flex justify-between w-full cursor-pointer"><div class="whitespace-nowrap flex w-full"></div><div class="cursor-pointer flex justify-end items-center"><div class="flex items-center text-[12px] shrink"></div></div></div><article></article></div>'),Rn=e=>{let t,n;function r(o){o?(t.classList.add("open"),n.style.maxHeight=n.scrollHeight+"px",setTimeout(()=>{n.style.maxHeight="unset"},200)):(e.onClose?.(),n.style.maxHeight=n.scrollHeight+"px",setTimeout(()=>{t.classList.remove("open"),n.style.maxHeight="0px"},200))}Ae(()=>{r(e.active)});const[s,c]=C(!1);return(()=>{const o=Da.cloneNode(!0),g=o.firstChild,p=g.firstChild,m=p.nextSibling,h=m.f
5irstChild,d=g.nextSibling;g.$$click=()=>{e.disabled||(c(!t.classList.contains("open")),r(s()),e.handleClick?.())},i(p,()=>e.title);const b=t;typeof b=="function"?Je(b,m):t=m,i(h,()=>e.value,null),i(h,a(E,{get when(){return e.showIcon},get children(){const _=Fa.cloneNode(!0);return M(y=>lt(_,{"rotate-180 transition-all":s()},y)),_}}),null);const l=n;return typeof l=="function"?Je(l,d):n=d,i(d,()=>e.children),M(_=>{const y=Ni("dropdown-container",e.wrapperStyles),S=!!e.landingPage,w=Ni(e.bodyStyles);return y!==_._v$&&Qn(o,_._v$=y),S!==_._v$2&&p.classList.toggle("justify-center",_._v$2=S),w!==_._v$3&&Qn(d,_._v$3=w),_},{_v$:void 0,_v$2:void 0,_v$3:void 0}),o})()};je(["click"]);const Wa=u('<div class="pt-4"><div class="divide-y divide-gray-100"></div></div>'),ja=u('<p class="text-[16px] font-semibold leading-none">Variables</p>'),Ga=u('<button type="button" class="min-h-[36px] shrink-0 rounded-[8px] border border-[#E8E8E6] bg-white px-3 text-[13px] font-semibold text-[#3A57D6] transition-colors hover:bg-[#F3F3F1]"></button>'),za=u('<button type="button" class="text-[13px] font-semibold text-[#3A57D6] hover:underline">View in transcript</button>'),Ba=u('<p class="text-[13px] leading-5 text-[#686B70]">Checking the saved transcript selection.</p>'),Ua=u('<div class="flex flex-wrap items-center gap-3"><button type="button" class="text-[13px] font-semibold text-[#3A57D6] hover:underline">Select transcript span</button><button type="button" class="text-[13px] font-semibold text-[#C4584E] hover:underline disabled:cursor-not-allowed disabled:opacity-50">Remove variable</button></div>'),Oa=u('<div class="mt-3 space-y-4 rounded-[8px] bg-[#F9F9F8] p-3"><div class="space-y-2"><p class="text-[12px] font-semibold uppercase tracking-[0.04em] text-[#686B70]">Transcript</p></div></div>'),qa=u('<div class="py-3 first:pt-0 last:pb-0"><div class="flex items-center justify-between gap-3"><div class="flex min-w-0 flex-wrap items-center gap-2"><p class="min-w-0 truncate text-[15px] font-semibold text-[#1C1D1F]"></p><span class="inline-flex min-h-[26px] items-center rounded-[6px] border px-2.5 text-[12px] font-medium"></span></div></div></div>'),nr=e=>{const{collapsedVariablesRef:t,variables:n}=e,[r,s]=C(new Set),[c,o]=C(null),g=B(()=>(x?.segments||[]).filter(_=>_.kind===-1).slice().sort((_,y)=>(_.highlight_si??0)-(y.highlight_si??0)||String(_.name??"").localeCompare(String(y.name??"")))),p=B(()=>Math.max(n()?.length??0,g().length)),m=B(()=>{const l=new Map;for(const _ of n()||[])l.set(_.id,_);return l}),h=l=>r().has(l),d=(l,_)=>{s(y=>{const S=new Set(y);return _?S.add(l):S.delete(l),S})},b=async l=>{if(!Le(x)&&!(!l.id||h(l.id))){d(l.id,!0);try{const _=await Gr({instance:x,variableName:l.name,enableLipsync:et(),variableStartTimes:Ye(),variableTimingConfig:Qt(x?.variable_timing_config),segmentIds:[l.id]});await nt({...x,segments:_.nextSegments,variable_start_times:_.parsedStartTimes,variable_timing_config:_.persistedTimingConfig}),Vt(_.nextStartTimes),bs(y=>y.filter(S=>S.id!==l.id)),c()===l.id&&o(null),Y.success(`${l.name} removed.`)}catch(_){console.error(_),Y.error(`Failed to remove ${l.name}.`)}finally{d(l.id,!1)}}};return a(Rn,{ref:t,get title(){return ja.cloneNode(!0)},get active(){return p()>0},wrapperStyles:"border rounded-[8px] bg-white p-4",showIcon:!0,get value(){return p()},get children(){return a(E,{get when(){return g().length>0},get children(){const l=Wa.cloneNode(!0),_=l.firstChild;return i(_,a(rt,{get each(){return g()},children:y=>{const S=()=>m().get(y.id)??null,w=()=>S()?.linked,I=()=>w()===!0,F=()=>w()===void 0,R=()=>!Le(x)&&c()===y.id,ee=`variable-editor-${y.id}`;return(()=>{const fe=qa.cloneNode(!0),H=fe.firstChild,be=H.firstChild,j=be.firstChild,ce=j.nextSibling;return i(j,()=>y.name),i(ce,(()=>{const W=B(()=>!!I());return()=>W()?"Linked to transcript":F()?"Checking transcript":"Needs transcript span"})()),i(H,a(E,{get when(){return!Le(x)},get children(){const W=Ga.cloneNode(!0);return W.$$click=()=>o(Q=>Q===y.id?null:y.id),te(W,"aria-controls",ee),i(W,()=>R()?"Done":"Edit"),M(()=>te(W,"aria-expanded",R())),W}}),null),i(fe,a(E,{get when(){return R()},get children(){const W=Oa.cloneNode(!0),Q=W.firstChild;return Q.firstChild,te(W,"id",ee),i(Q,a(E,{get when(){return I()},get children(){const A=za.cloneNode(!0);return A.$$click=()=>S()?.select(),A}}),null),i(Q,a(E,{get when(){return F()},get children(){return Ba.cloneNode(!0)}}),null),i(Q,a(E,{get when(){return w()===!1},get children(){const A=Ua.cloneNode(!0),G=A.firstChild,ne=G.nextSibling;return G.$$click=()=>{const Z=S();Z&&e.onRelinkRequest?.({id:Z.id,name:Z.name})},ne.$$click=()=>void b(y),M(()=>ne.disabled=h(y.id)),A}}),null),W}}
5),null),M(W=>lt(ce,{"border-[#C8E1D8] bg-[#ECF7F3] text-[#2C7B61]":I(),"border-[#EBD7B6] bg-[#FFF8E8] text-[#B77B1F]":w()===!1,"border-[#E8E8E6] bg-[#F9F9F8] text-[#686B70]":F()},W)),fe})()}})),l}})}})};je(["click"]);const Ha=u('<div class="w-full divide-y divide-[#E8E8E6]"></div>'),Ya=u('<div class="flex w-full flex-col self-start p-2"></div>'),Ja=u('<p class="text-[15px] font-semibold">Campaigns using this</p>'),Qa=u('<p class="py-2 text-[13px] text-[#686B70]">No campaigns use this template yet.</p>'),Ka=u('<img alt="" class="h-full w-full object-cover">'),Za=u('<button type="button" class="flex w-full items-center justify-between gap-4 py-3 text-left transition-colors hover:bg-[#F9F9F8] focus:outline-none focus:ring-2 focus:ring-inset focus:ring-[#3A57D6]"><span class="flex min-w-0 items-center gap-3"><span class="h-10 w-10 shrink-0 overflow-hidden rounded-[8px] border border-[#E8E8E6] bg-[#F3F3F1]"></span><span class="min-w-0"><span class="block truncate text-[14px] font-semibold text-[#1C1D1F]"></span><span class="mt-0.5 block text-[12px] text-[#686B70]"></span></span></span><span class="shrink-0 text-right"><span class="block text-[12px] font-semibold"></span><span class="mt-0.5 block text-[12px] text-[#3A57D6]"></span></span></button>'),ir=e=>{const{campaigns:t,navigate:n}=e;return a(Rn,{active:!1,get title(){return Ja.cloneNode(!0)},wrapperStyles:"p-2 border rounded-[8px] overflow-auto md:max-h-[220px] overflow-y-auto",showIcon:!0,get children(){const r=Ya.cloneNode(!0);return i(r,a(E,{get when(){return t().length!==0},get fallback(){return Qa.cloneNode(!0)},get children(){const s=Ha.cloneNode(!0);return i(s,a(rt,{get each(){return t()},children:c=>{const o=Gs(c);return(()=>{const g=Za.cloneNode(!0),p=g.firstChild,m=p.firstChild,h=m.nextSibling,d=h.firstChild,b=d.nextSibling,l=p.nextSibling,_=l.firstChild,y=_.nextSibling;return g.$$click=()=>n(o),i(m,a(E,{get when(){return c.thumbnail},get children(){const S=Ka.cloneNode(!0);return M(()=>te(S,"src",c.thumbnail)),S}})),i(d,()=>c.campaign_name||"Untitled campaign"),i(b,()=>Hs(c.updated_at)),i(_,()=>c.locked?"Generated":"Draft"),i(y,()=>c.locked?"View videos":"Continue setup"),M(S=>{const w=!!c.locked,I=!c.locked;return w!==S._v$&&_.classList.toggle("text-[#2C7B61]",S._v$=w),I!==S._v$2&&_.classList.toggle("text-[#686B70]",S._v$2=I),S},{_v$:void 0,_v$2:void 0}),g})()}})),s}})),r}})};je(["click"]);const Xa=u('<svg aria-hidden="true" viewBox="0 0 20 20" class="h-5 w-5" fill="currentColor"><circle cx="4" cy="10" r="1.4"></circle><circle cx="10" cy="10" r="1.4"></circle><circle cx="16" cy="10" r="1.4"></circle></svg>'),eo=u('<img alt="" class="h-full w-full object-cover">'),to=u('<button type="button" role="menuitem" class="flex w-full rounded-[6px] px-3 py-2 text-left text-[13px] font-medium text-foreground hover:bg-muted focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-primary">Download GIF</button>'),no=u('<details class="relative shrink-0"><summary class="flex h-9 w-9 cursor-pointer list-none items-center justify-center rounded-[8px] text-muted-foreground transition-colors hover:bg-card hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"></summary><div role="menu" class="absolute right-0 top-10 z-30 min-w-[168px] rounded-[8px] border border-border bg-card p-1 shadow-custom"><button type="button" role="menuitem" class="flex w-full rounded-[6px] px-3 py-2 text-left text-[13px] font-medium text-foreground hover:bg-muted focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-primary">Copy share link</button></div></details>'),io=u('<div class="group flex min-h-[84px] items-center gap-2 rounded-[8px] px-2 py-2 transition-colors duration-150"><button type="button" class="flex min-w-0 flex-1 items-center gap-3 rounded-[6px] text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary focus-visible:ring-offset-2"><span class="relative flex h-16 w-24 shrink-0 items-center justify-center overflow-hidden rounded-[8px] bg-muted"><span aria-hidden="true" class="absolute inset-0 flex items-center justify-center bg-black/10 o
5pacity-0 transition-opacity duration-150 group-hover:opacity-100 group-focus-within:opacity-100"><span class="flex h-8 w-8 items-center justify-center rounded-full bg-card/90 text-primary"><svg viewBox="0 0 20 20" class="ml-0.5 h-4 w-4" fill="currentColor"><path d="M6.5 4.6v10.8L15 10 6.5 4.6Z"></path></svg></span></span></span><span class="min-w-0 flex-1"><span class="block truncate text-[14px] font-semibold text-foreground"></span><span class="mt-0.5 block text-[12px] text-muted-foreground"></span></span><span class="inline-flex min-h-9 shrink-0 items-center justify-center rounded-[8px] px-3 text-[13px] font-semibold transition-colors" aria-hidden="true"></span></button></div>'),ro=e=>{const t=e.trim();return t?`${t.charAt(0).toUpperCase()}${t.slice(1)}`:"Sample"},so=()=>Xa.cloneNode(!0),ao=e=>{let t;const n=()=>ro(e.name),r=()=>e.shareUrl||e.videoUrl,s=async()=>{if(!navigator.clipboard||!r()){Y.error("Couldn’t copy the share link.");return}try{await navigator.clipboard.writeText(r()),t?.removeAttribute("open"),Y.success("Share link copied.")}catch{Y.error("Couldn’t copy the share link.")}};return(()=>{const c=io.cloneNode(!0),o=c.firstChild,g=o.firstChild,p=g.firstChild,m=g.nextSibling,h=m.firstChild,d=h.nextSibling,b=m.nextSibling;return kt(o,"click",e.onPlay,!0),i(g,a(E,{get when(){return e.thumbnail},get fallback(){return a(zs,{width:"34",height:"34"})},get children(){const l=eo.cloneNode(!0);return M(()=>te(l,"src",e.thumbnail)),l}}),p),i(h,n),i(d,()=>e.selected?"Playing above":"Ready to watch"),Je(l=>e.rowRef?.(l),b),i(b,()=>e.selected?"Now playing":"Watch"),i(c,a(E,{get when(){return e.gifUrl||r()},get children(){const l=no.cloneNode(!0),_=l.firstChild,y=_.nextSibling,S=y.firstChild,w=t;return typeof w=="function"?Je(w,l):t=l,i(_,a(so,{})),i(y,a(E,{get when(){return e.gifUrl},get children(){const I=to.cloneNode(!0);return I.$$click=()=>{t?.removeAttribute("open"),window.open(e.gifUrl,"_blank")},I}}),S),S.$$click=()=>void s(),M(()=>te(_,"aria-label",`More options for ${n()}`)),l}}),null),M(l=>{const _={"bg-accent-soft":!!e.selected,"hover:bg-muted":!e.selected},y=`${e.selected?"Replay":"Watch"} ${n()} generated video`,S=e.highlighted?"watch-sample":void 0,w={"bg-primary text-primary-foreground":!!e.highlighted&&!e.selected,"text-primary":!e.highlighted&&!e.selected,"text-muted-foreground":!!e.selected};return l._v$=lt(c,_,l._v$),y!==l._v$2&&te(o,"aria-label",l._v$2=y),S!==l._v$3&&te(b,"data-onboarding-action",l._v$3=S),l._v$4=lt(b,w,l._v$4),l},{_v$:void 0,_v$2:void 0,_v$3:void 0,_v$4:void 0}),c})()};je(["click"]);const oo=u('<div class="w-full divide-y divide-border"></div>'),lo=u('<button type="button" class="mt-2 min-h-9 w-full rounded-[8px] text-[13px] font-semibold text-primary hover:bg-muted focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"></button>'),co=u('<div class="flex w-full flex-col self-start p-2"></div>'),uo=u('<span class="text-[12px] font-medium text-muted-foreground"></span>'),go=u('<div class="flex items-center gap-2"><p class="text-[15px] font-semibold">Generated videos</p></div>'),po=u('<div class="rounded-[10px] border border-border bg-card p-3"></div>'),mo=u("<div>No samples generated yet.</div>"),fo=u('<div class="py-1.5 first:pt-0 last:pb-0"></div>'),rr=e=>{const{sampleGeneratedVideo:t}=e,[n,r]=C(!1),s=()=>n()?t():t().slice(0,6),c=()=>t().findIndex(p=>p?.status==="succeeded"&&!!p?.url),o=p=>(p?.status==="succeeded"||p?.status==="completed")&&!!(p?.url||p?.share_url),g=p=>[].concat(p?.text??[]).filter(Boolean).join(", ")||"Sample";return a(Rn,{get active(){return!!t().length||ni()},get title(){return(()=>{const p=go.cloneNode(!0);return p.firstChild,i(p,a(E,{get when(){return t().length},get children(){const m=uo.cloneNode(!0);return i(m,()=>t().length),m}}),null),p})()},wrapperStyles:"p-2 border rounded-[8px]",showIcon:!0,get children(){const p=co.cloneNode(!0),m=e.generatedVideosRef;return typeof m=="function"?Je(m,p):e.generatedVideosRef=p,i(p,a(E,{get when(){return t().length},get fallback(){return a(E,{get when(){return ni()},get fallback(){return mo.cloneNode(!0)},get children(){const h=po.cloneNode(!0);return i(h,a(ei,{status:"processing",videoName:["Sample"],compact:!0})),h}})},get children(){return[(()=>{const h=oo.cloneNode(!0);return i(h,a(rt,{get each(){return s()},children:d=>(()=>{const b=fo.cloneNode(!0);return i(b,a(E,{get when(){return o(d)},get fallback(){return a(ei,{get status(){return d?.status},get vimeoLink(){return d?.share_url},get s3Link(){return d?.url},get videoName(){return d?.text},get thumbnail(){return d?.thumbnail},get gifLink(){return d?.gif},get estimateTime(){return d?.estimate_time},get estimateUpdatedAt(){return d?.updated_at},get progress(){return d?.processing},get startedAt(){return d?.created_at},get error(){return d?.message},get execution_name(){return d?.execution_name},get trackingId(){return d?.id},onRetry:()=>e.onRetry?.(d),compact:!0})},get children(){return a(ao,{get name(){return g(d)},get videoUrl(){return d?.url||d?.share_url},get shareUrl(){return d?.share_url},get thumbnail(){return d?.thumbnail},get gifUrl(){return d?.gif},get selected(){return e.selectedVideo===(d?.url||d?.share_url)},onPlay:()=>{vs(d.id).catch(()=>{}),e.onPlay?.(d)},get rowRef(){return e.highlightWelcomeWatchLink&&t().indexOf(d)===c()?e.sampleWatchRef:void 0},get highlighted(){return B(()=>!!e.highlightWelcomeWatchLink)()&&t().indexOf(d)===c()}})}})),b})()})),h})(),a(E,{get when(){return t().length>6},get children(){const h=lo.cloneNode(!0);return h.$$click=()=>r(d=>!d),i(h,(()=>{const d=B(()=>!!n());return()=>d()?"Show fewer":`Show all ${t().length}`})()),h}})]}})),p}})};je(["click"]);const ho=u('<section class="border-t border-border first:border-t-0"><h3><button type="button" class="flex min-h-[48px] w-full items-center gap-3 rounded-[8px] px-2 py-3 text-left text-foreground hover:bg-muted focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"><span class="min-w-0 flex-1 text-[14px] font-semibold"></span><span class="max-w-[45%] text-right text-[12px] text-muted-foreground"></span><svg aria-hidden="true" viewBox="0 0 20 20" fill="none"><path d="m7 4 6 6-6 6" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"></path></svg></button></h3><div role="region" class="space-y-3 px-2 pb-4"></div></section>');function ln(e){const t=Pr();return(()=>{const n=ho.cloneNode(!0),r=n.firstChild,s=r.firstChild,c=s.firstChild,o=c.nextSibling,g=o.nextSibling,p=r.nextSibling;return kt(s,"click",e.onToggle,!0),te(s,"id",`${t}-trigger`),te(s,"aria-controls",`${t}-content`),i(c,()=>e.title),i(o,()=>e.summary),te(p,"id",`${t}-content`),te(p,"aria-labelledby",`${t}-trigger`),i(p,()=>e.children),M(m=>{const h=e.open,d=`h-4 w-4 shrink-0 ${e.open?"rotate-90":""}`,b=!e.open;return h!==m._v$&&te(s,"aria-expanded",m._v$=h),d!==m._v$2&&te(g,"class",m._v$2=d),b!==m._v$3&&(p.hidden=m._v$3=b),m},{_v$:void 0,_v$2:void 0,_v$3:void 0}),n})()}je(["click"]);const Kr="https://studio.dev.bhuman.ai/",Zr=e=>`api/ai_studio/templates/${encodeURIComponent(e)}/background-sound`;async function Xr(e){const t=await e;if(!t.ok)throw new Error("Could not update background sound. Please try again.");return t.json()}const bo=e=>Xr(Lr(Zr(e),Kr)),vo=(e,t)=>
5Xr(Ir(Zr(e),{preset:t},Kr)),es=e=>({off:"Off",subtle:"Subtle",more:"More background"})[e]||"Off",_o=u('<fieldset><legend class="sr-only">Background sound level</legend><div class="grid grid-cols-3 overflow-hidden rounded-[8px] border border-border"></div></fieldset>'),xo=u('<p class="text-[12px] leading-5 text-muted-foreground" role="status"></p>'),wo=u('<div class="space-y-1"><span class="text-[12px] text-muted-foreground">Listen with your original recording</span><audio class="h-10 w-full" controls preload="none" aria-label="Preview background sound with original recording"></audio></div>'),$o=u('<p role="alert" class="text-[12px] text-foreground"></p>'),yo=u('<button type="button" class="min-h-11 text-[12px] font-semibold text-primary disabled:opacity-50"></button>'),So=u('<div class="space-y-3"></div>'),Co=u('<p class="text-[12px] text-muted-foreground" role="status"></p>'),ko=u('<label class="relative flex min-h-11 items-center justify-center border-l border-border px-2 py-2 text-center text-[12px] first:border-l-0 focus-within:ring-2 focus-within:ring-inset focus-within:ring-primary"><input class="sr-only" type="radio"></label>');function To(e){const t=Pr(),[n,r]=C(),[s,c]=C(!1),[o,g]=C(!1),[p,m]=C("");let h,d=0,b=0,l=!1;Lt(()=>{l=!0,d++,h?.pause()}),zt(()=>{const S=I=>{I.target instanceof HTMLVideoElement&&h?.pause()},w=I=>{I.target instanceof HTMLDetailsElement&&!I.target.open&&h&&I.target.contains(h)&&h.pause()};document.addEventListener("play",S,!0),document.addEventListener("toggle",w,!0),Lt(()=>{document.removeEventListener("play",S,!0),document.removeEventListener("toggle",w,!0)})}),Ae(()=>{e.templateId,e.sourceId,d++,b=0,r(void 0),g(!1),m("")});async function _(){const S=++d,w=e.templateId;c(!0),m("");try{const I=await bo(w);if(l||S!==d)return;r(I),b=Date.now(),e.onSaved(I.preset)}catch{!l&&S===d&&(r(I=>I??{status:"unavailable",preset:e.savedPreset??"off"}),m("Could not load background sound. You can still choose Off."))}finally{!l&&S===d&&c(!1)}}Ae(()=>{const S=e.open;e.templateId,e.sourceId,S?Date.now()-b>12*60*1e3&&_():h?.pause()});async function y(S){if(o()||s()||S===n()?.preset)return;const w=d,I=e.templateId,F=n();r(R=>R&&{...R,preset:S}),g(!0),m(""),h?.pause();try{if(await vo(I,S),l||w!==d)return;r(R=>R&&{...R,preset:S}),e.onSaved(S)}catch{!l&&w===d&&(r(F),m("Could not save. Your previous choice is still selected."))}finally{!l&&w===d&&g(!1)}}return(()=>{const S=So.cloneNode(!0);return i(S,a(E,{get when(){return n()},get fallback(){return(()=>{const w=Co.cloneNode(!0);return i(w,()=>s()?"Loading background sound…":"Background sound unavailable."),w})()},get children(){return[(()=>{const w=_o.cloneNode(!0),I=w.firstChild,F=I.nextSibling;return te(w,"aria-describedby",`${t}-help`),i(F,a(rt,{each:["off","subtle","more"],children:R=>(()=>{const ee=ko.cloneNode(!0),fe=ee.firstChild;return fe.addEventListener("change",()=>void y(R)),te(fe,"name",`${t}-level`),fe.value=R,i(ee,()=>es(R),null),M(H=>{const be={"bg-primary/10 text-primary":n()?.preset===R,"text-muted-foreground":n()?.preset!==R,"opacity-50 cursor-not-allowed":R!=="off"&&n()?.status!=="ready","cursor-pointer":R==="off"||n()?.status==="ready"},j=R!=="off"&&n()?.status!=="ready";return H._v$=lt(ee,be,H._v$),j!==H._v$2&&(fe.disabled=H._v$2=j),H},{_v$:void 0,_v$2:void 0}),M(()=>fe.checked=n()?.preset===R),ee})()})),M(()=>w.disabled=s()||o()),w})(),(()=>{const w=xo.cloneNode(!0);return te(w,"id",`${t}-help`),i(w,(()=>{const I=B(()=>!!o());return()=>I()?"Saving…":(()=>{const F=B(()=>n()?.status==="ready");return()=>F()?"Applies to new samples and campaign videos.":(()=>{const R=B(()=>n()?.status==="preparing");return()=>R()?"Preparing your background sound. Check again shortly.":n()?.status==="missing_source"?"Upload the original video with voice isolation to use background sound.":"Background sound is unavailable for this video."})()})()})()),w})(),a(E,{get when(){return B(()=>n()?.status==="ready")()&&n()?.preview_urls?.[n().preset]},get children(){const w=wo.cloneNode(!0),I=w.firstChild,F=I.nextSibling;F.addEventListener("error",()=>m("Preview expired or could not play. Reload to try again.")),F.addEventListener("play",()=>document.querySelectorAll("video").forEach(ee=>ee.pause()));const R=h;return typeof R=="function"?Je(R,F):h=F,M(()=>te(F,"src",n()?.preview_urls?.[n().preset])),w}})]}}),null),i(S,a(E,{get when(){return p()},get children(){const w=$o.cloneNode(!0);return i(w,p),w}}),null),i(S,a(E,{get when(){return p()||n()?.status==="preparing"},get children(){const w=yo.cloneNode(!0);return w.$$click=()=>void _(),i(w,()=>s()?"Loading…":"Reload"),M(()=>w.disabled=s()||o()),w}}),null),M(()=>te(S,"aria-busy",s()||o())),S})()}je(["click"]);const xi=.05,It=(e,t)=>
5Number.isFinite(e)?e:t,Yt=(e,t,n,r,s=xi)=>{const c=Math.max(0,It(n,0)),o=Math.max(c+s,It(r,c+s)),g=Math.min(Math.max(It(e,c),c),o-s),p=Math.min(Math.max(It(t,g+s),g+s),o);return{start:g,end:p}},No=(e,t,n,r=1.5,s=2)=>{const c=It(n,0),o=c>0?c:It(t,0)+s,g=Math.max(0,It(e,0)-r),p=Math.min(o,Math.max(t+s,g+xi));return{start:g,end:p}},Eo=e=>{const t=Yt(e.selection.start,e.selection.end,e.viewport.start,e.viewport.end),n=Math.max(xi,e.replacement.end-e.replacement.start),r=t.end-t.start,s=[];if(t.start>e.viewport.start){const c=t.start-e.viewport.start;s.push({source:"template",sourceOffsetSeconds:e.viewport.start,sourceDurationSeconds:c,outputStartSeconds:0,outputDurationSeconds:c,playbackRate:1,gain:1})}if(s.push({source:e.hasPersonalizedAudio?"personalized":"template",sourceOffsetSeconds:e.hasPersonalizedAudio?e.replacement.start:t.start,sourceDurationSeconds:e.hasPersonalizedAudio?n:r,outputStartSeconds:t.start-e.viewport.start,outputDurationSeconds:r,playbackRate:e.hasPersonalizedAudio?n/r:1,gain:e.hasPersonalizedAudio?1:.08}),t.end<e.viewport.end){const c=e.viewport.end-t.end;s.push({source:"template",sourceOffsetSeconds:t.end,sourceDurationSeconds:c,outputStartSeconds:t.end-e.viewport.start,outputDurationSeconds:c,playbackRate:1,gain:1})}return s},Ao=(e,t,n,r)=>{const s=Math.max(1,Math.floor(r));if(!e.length||!(t>0)||!(n.end>n.start))return Array.from({length:s},()=>.12);const c=Math.max(0,Math.floor(n.start*t)),o=Math.min(e.length,Math.max(c+1,Math.ceil(n.end*t))),g=Math.max(1,Math.floor((o-c)/s));return Array.from({length:s},(p,m)=>{const h=Math.min(o-1,c+m*g),d=Math.min(o,h+g);let b=0;for(let l=h;l<d;l+=1)b=Math.max(b,Math.abs(e[l]??0));return Math.max(.08,Math.min(1,b))})},sr=e=>{const t=Math.max(0,It(e,0)),n=Math.floor(t/60),r=Math.floor(t%60);return`${n}:${String(r).padStart(2,"0")}`},dn=e=>String(e),ar=(e,t)=>{const n=Number(e.step);return!Number.isFinite(n)||!(n>0)?t:Math.max(t,n/2+Number.EPSILON*8)},Vo=e=>{const t=dn(e.viewport.start),n=dn(e.viewport.end),r=dn(e.stepSeconds);for(const s of[e.startInput,e.endInput])s.min=t,s.max=n,s.step=r;e.startInput.value=dn(e.selection.start),e.endInput.value=dn(e.selection.end)},Io=(e,t=5e-4)=>{const n=Number(e.startInput.value),r=Number(e.endInput.value),s=ar(e.startInput,t),c=ar(e.endInput,t);return Number.isFinite(n)&&Number.isFinite(r)&&Math.abs(n-e.selection.start)<=s&&Math.abs(r-e.selection.end)<=c};const Lo=u('<span class="pointer-events-none absolute inset-y-2 w-px bg-foreground
5/70"></span>'),Mo=u('<svg viewBox="0 0 20 20" aria-hidden="true" class="h-4 w-4 fill-current"><path d="M5.5 4.5h3.25v11H5.5zm5.75 0h3.25v11h-3.25z"></path></svg>'),Po=u('<p role="status" class="mt-3 text-[13px] text-destructive"></p>'),Ro=u('<p role="alert" class="mt-3 text-[13px] text-destructive"></p>'),Fo=u('<div class="flex max-h-[calc(100vh-2rem)] flex-col bg-white"><header class="flex items-start justify-between gap-4 border-b border-border px-5 py-4 sm:px-6 sm:py-5"><div><h2 id="audio-timing-modal-title" class="text-[20px] font-semibold leading-7 text-foreground">Adjust audio timing</h2><p class="mt-1 text-[14px] leading-5 text-muted-foreground">Drag the handles until the transition sounds natural.</p></div><button type="button" aria-label="Close audio timing" class="inline-flex h-9 w-9 shrink-0 items-center justify-center rounded-[8px] text-muted-foreground transition-colors hover:bg-muted hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"><svg viewBox="0 0 20 20" aria-hidden="true" class="h-5 w-5"><path d="m5.5 5.5 9 9m0-9-9 9" fill="none" stroke="currentColor" stroke-linecap="round" stroke-width="1.6"></path></svg></button></header><div class="overflow-y-auto px-5 py-5 sm:px-6 sm:py-6"><div class="flex items-center gap-2 text-[13px]"><span class="text-muted-foreground">Variable</span><span class="rounded-[6px] border border-border bg-white px-2 py-1 font-medium text-foreground"></span></div><p class="mt-5 text-center text-[15px] leading-6 text-foreground"><span></span><span class="rounded-[6px] bg-accent-soft px-1.5 py-0.5 font-medium text-primary"></span><span></span></p><div class="mt-5 rounded-[10px] border border-border bg-white p-3 sm:p-4"><div class="relative h-36 overflow-hidden rounded-[8px] bg-muted"><div class="absolute inset-x-3 top-1/2 flex h-[88px] -translate-y-1/2 items-center gap-[2px]" aria-hidden="true"></div><div class="pointer-events-none absolute inset-y-3 rounded-[6px] border-y border-primary/20 bg-accent-soft/55"><span class="absolute left-1/2 top-1 -translate-x-1/2 text-[11px] font-semibold text-primary"></span><span class="absolute inset-y-0 left-0 w-[6px] -translate-x-1/2 rounded-[3px] bg-primary shadow-[0_0_0_1px_white]"></span><span class="absolute inset-y-0 right-0 w-[6px] translate-x-1/2 rounded-[3px] bg-primary shadow-[0_0_0_1px_white]"></span></div><input aria-label="Start of personalized audio" type="range" class="audio-timing-range audio-timing-range-start" step="0.01"><input aria-label="End of personalized audio" type="range" class="audio-timing-range audio-timing-range-end" step="0.01"></div><div class="mt-3 flex flex-wrap items-center gap-x-4 gap-y-3"><button type="button" class="inline-flex h-10 w-10 shrink-0 items-center justify-center rounded-full bg-primary text-primary-foreground transition-colors hover:bg-primary-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-40"></button><span class="min-w-[74px] text-[13px] tabular-nums text-foreground"> / </span><label class="inline-flex cursor-pointer items-center gap-2 text-[13px] text-foreground"><input type="checkbox" class="peer sr-only"><span class="relative h-5 w-9 rounded-full bg-[#D1D5DB] transition-colors after:absolute after:left-0.5 after:top-0.5 after:h-4 after:w-4 after:rounded-full after:bg-white after:transition-transform peer-checked:bg-primary peer-checked:after:translate-x-4 peer-focus-visible:ring-2 peer-focus-visible:ring-primary peer-focus-visible:ring-offset-2"></span>Loop preview</label><span class="text-[13px] text-muted-foreground"></span></div></div><button type="button" class="mt-3 inline-flex min-h-9 items-center gap-2 rounded-[8px] px-2 text-[13px] font-medium text-muted-foreground transition-colors hover:bg-muted hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"><svg viewBox="0 0 20 20" aria-hidden="true" class="h-4 w-4"><path d="M4.8 7.1A6 6 0 1 1 4.2 12m.6-4.9V3.8m0 3.3h3.3" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5"></path></svg>Reset to automatic</button></div><footer class="flex items-center justify-end gap-2 border-t border-border px-5 py-4 sm:px-6"><button type="button" class="inline-flex h-10 items-center justify-center rounded-[8px] border border-border bg-white px-4 text-[14px] font-semibold text-foreground transition-colors hover:bg-muted focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary disabled:opacity-50">Cancel</button><button type="button" class="inline-flex h-10 items-center justify-center rounded-[8px] bg-primary px-4 text-[14px] font-semibold text-primary-foreground transition-colors hover:bg-primary-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50"></button></footer></div>'),Do=u('<span class="min-w-0 flex-1 rounded-[1px]"></span>'),Wo=u('<svg viewBox="0 0 20 20" aria-hidden="true" class="h-4 w-4 translate-x-px fill-current"><path d="M6.5 4.6v10.8L15 10 6.5 4.6Z"></path></svg>'),cn=.05,jo=.01,or=112,Go=.012,qn=new Map,lr=e=>{const t=String(e??"").trim();return t?/^https?:\/\//i.test(t)?t:`https://s3.${ui}.amazonaws.com/${gi}/${t.replace(/^\/+/,"")}`:""},dr=(e,t)=>
5{const n=qn.get(t);if(n)return n;const r=fetch(t).then(s=>{if(!s.ok)throw new Error(`Audio preview returned ${s.status}.`);return s.arrayBuffer()}).then(s=>e.decodeAudioData(s.slice(0))).catch(s=>{throw qn.delete(t),s});return qn.set(t,r),r},cr=e=>Number(e.toFixed(3)),zo=e=>e==="right"?"right":"left",Bo=e=>e==="speed_up_voice"?"speed_up_voice":e==="slow_down_video"?"slow_down_video":"both",Uo=(e,t)=>{const n=String(e?.segment??"").trim(),r=String(e?.highlight??"").trim();if(!n||!r)return{before:"",replacement:t,after:n};const s=n.toLowerCase().indexOf(r.toLowerCase());return s<0?{before:n,replacement:t,after:""}:{before:n.slice(0,s),replacement:t,after:n.slice(s+r.length)}},Oo=e=>{const[t,n]=C(0),[r,s]=C(.5),[c,o]=C(0),[g,p]=C(Array.from({length:or},()=>.12)),[m,h]=C(!1),[d,b]=C(""),[l,_]=C(!1),[y,S]=C(!1),[w,I]=C(!0),[F,R]=C(0),[ee,fe]=C(!1),[H,be]=C(""),[j,ce]=C(),[W,Q]=C();let A,G,ne,Z=[],ge=0,$e=0,ye=0,xe=0,ve=0;const Se=B(()=>lr(e.instance?.video_url)),we=B(()=>lr(e.personalizedAudioSrc)),q=B(()=>(e.instance?.segments||[]).find(V=>V.kind===-1&&V.name?.trim().toLowerCase()===String(e.variableName??"").trim().toLowerCase())),J=B(()=>String(e.previewValue??"").trim()||String(e.variableName??"").trim()||"variable"),K=B(()=>Uo(q(),J())),$=B(()=>e.automaticWindow??e.initialWindow),f=B(()=>{const V=$(),X=Number(V?.window_start_seconds??0),ue=Number(V?.window_end_seconds??X+.5);return No(X,ue,c())}),N=B(()=>{const V=f();return(t()-V.start)/(V.end-V.start)*100}),T=B(()=>{const V=f();return(r()-t())/(V.end-V.start)*100}),L=B(()=>{const V=f();return(F()-V.start)/(V.end-V.start)*100}),z=B(()=>f().end-f().start),re=()=>{if(A)return A;const V=window.AudioContext||window.webkitAudioContext;if(V)return A=new V,A},ae=()=>{$e+=1,window.clearTimeout(ve),Z.forEach(V=>{V.onended=null;try{V.stop()}catch{}}),Z=[],window.cancelAnimationFrame(ge)},Te=()=>{ae(),S(!1),R(f().start)},Oe=()=>{const V=f(),X=e.initialWindow??e.automaticWindow,ue=Yt(Number(X?.window_start_seconds??V.start),Number(X?.window_end_seconds??V.start+.5),V.start,V.end,cn);n(ue.start),s(ue.end),R(V.start),be("")},Re=()=>{G&&p(Ao(G.getChannelData(0),G.sampleRate,f(),or))},D=async()=>{const V=re(),X=Se(),ue=we(),Fe=++xe;if(G=void 0,ne=void 0,_(!1),b(""),!V||!X){b("Audio preview is unavailable for this template.");return}h(!0);try{const Pe=await dr(V,X);if(Fe!==xe||!e.open)return;if(G=Pe,o(Pe.duration),Oe(),Re(),ue)try{const Ue=await dr(V,ue);if(Fe!==xe||!e.open)return;ne=Ue,_(!0)}catch(Ue){console.warn("Personalized audio preview unavailable",Ue)}}catch(Pe){console.error(Pe),b("Audio preview could not be loaded. You can still adjust and save the timing.")}finally{Fe===xe&&h(!1)}},Ve=V=>{if(!A||V!==$e||!y())return;const X=A.currentTime-ye;R(Math.min(f().end,f().start+Math.max(0,X))),ge=window.requestAnimationFrame(()=>Ve(V))},le=(V,X)=>{if(!A||!G)return;const ue=V.source==="personalized"&&ne?ne:G,Fe=Math.min(V.sourceDurationSeconds,Math.max(0,ue.duration-V.sourceOffsetSeconds));if(!(Fe>0)||!(V.outputDurationSeconds>0))return;const Pe=A.createBufferSource(),Ue=A.createGain(),pt=Fe/V.outputDurationSeconds,st=X+V.outputStartSeconds,Tt=st+V.outputDurationSeconds,_e=Math.min(Go,V.outputDurationSeconds/3);return Pe.buffer=ue,Pe.playbackRate.value=pt,Ue.gain.setValueAtTime(0,st),Ue.gain.linearRampToValueAtTime(V.gain,st+_e),Ue.gain.setValueAtTime(V.gain,Math.max(st+_e,Tt-_e)),Ue.gain.linearRampToValueAtTime(0,Tt),Pe.connect(Ue).connect(A.destination),Pe.start(st,V.sourceOffsetSeconds,Fe),Z.push(Pe),Pe},Me=async()=>{const V=re();if(!V||!G||m())return;try{await V.resume()}catch(st){console.error(st),b("Your browser blocked audio playback. Press play again.");return}ae(),S(!0),b(""),R(f().start);const X=e.initialWindow??e.automaticWindow,ue=Yt(Number(X?.window_start_seconds??t()),Number(X?.window_end_seconds??r()),0,ne?.duration??G.duration,cn),Fe=Eo({viewport:f(),selection:{start:t(),end:r()},replacement:ue,hasPersonalizedAudio:!!ne}),Pe=++$e,Ue=V.currentTime+.025;ye=Ue;let pt;if(Fe.forEach(st=>{pt=le(st,Ue)??pt}),!pt){S(!1),b("Audio preview is unavailable for this timing window.");return}pt.onended=()=>
5{if(Pe===$e){if(w()){Me();return}S(!1),R(f().start)}},ge=window.requestAnimationFrame(()=>Ve(Pe))},pe=()=>{y()&&(window.clearTimeout(ve),ve=window.setTimeout(()=>void Me(),60))},de=V=>{const X=f(),ue=Yt(V,r(),X.start,X.end,cn);n(ue.start),be(""),pe()},se=V=>{const X=f(),ue=Yt(t(),V,X.start,X.end,cn);s(ue.end),be(""),pe()},Ce=()=>{const V=e.automaticWindow??e.initialWindow,X=f(),ue=Yt(Number(V?.window_start_seconds??X.start),Number(V?.window_end_seconds??X.start+.5),X.start,X.end,cn);n(ue.start),s(ue.end),be(""),pe()},Xe=()=>{const V=j(),X=W();if(!V||!X)return!1;const ue={start:t(),end:r()};return Vo({startInput:V,endInput:X,viewport:f(),selection:ue,stepSeconds:jo}),Io({startInput:V,endInput:X,selection:ue})},gt=async()=>{if(ee())return;if(!(r()>t())){be("The end handle must be after the start handle.");return}if(!Xe()){be("The timing handles are still syncing. Move the end handle and try again.");return}const V=e.initialWindow??e.automaticWindow;fe(!0);try{await e.onSave({window_start_seconds:cr(t()),window_end_seconds:cr(r()),anchor:zo(V?.anchor),fit_mode:Bo(V?.fit_mode)})&&Te()}finally{fe(!1)}},vt=()=>{ee()||(Te(),e.onClose())};return Ae(bn(()=>[e.open,e.variableName,Se(),we()],([V])=>{if(!V){xe+=1,Te();return}Oe(),D()})),Ae(()=>{f(),!(!e.open||!G)&&(Oe(),Re())}),Ae(()=>{e.open&&(f(),t(),r(),Xe())}),Lt(()=>{xe+=1,ae(),A?.close()}),a(_s,{get open(){return e.open},labelledBy:"audio-timing-modal-title",onClose:vt,class:"audio-timing-modal w-[min(900px,calc(100vw-2rem))] shadow-[0_20px_44px_rgba(25,36,74,0.12)]",get children(){const V=Fo.cloneNode(!0),X=V.firstChild,ue=X.firstChild,Fe=ue.nextSibling,Pe=X.nextSibling,Ue=Pe.firstChild,pt=Ue.firstChild,st=pt.nextSibling,Tt=Ue.nextSibling,_e=Tt.firstChild,at=_e.nextSibling,Qe=at.nextSibling,Pt=Tt.nextSibling,Zt=Pt.firstChild,Xt=Zt.firstChild,Rt=Xt.nextSibling,dt=Rt.firstChild,Ft=Rt.nextSibling,en=Ft.nextSibling,Ge=Zt.nextSibling,mt=Ge.firstChild,Dt=mt.nextSibling,Fn=Dt.firstChild,xn=Dt.nextSibling,tn=xn.firstChild,wn=xn.nextSibling,Dn=Pt.nextSibling,$n=Pe.nextSibling,nn=$n.firstChild,v=nn.nextSibling;return Fe.$$click=vt,i(st,()=>e.variableName),i(_e,()=>K().before),i(at,()=>K().replacement),i(Qe,()=>K().after),i(Xt,a(rt,{get each(){return g()},children:(k,U)=>{const me=()=>f().start+(U()+.5)/g().length*(f().end-f().start),ie=()=>me()>=t()&&me()<=r();return(()=>{const he=Do.cloneNode(!0);return M(Ie=>{const ze=!!ie(),Nt=!ie(),O=`${Math.max(10,k*100)}%`;return ze!==Ie._v$7&&he.classList.toggle("bg-primary",Ie._v$7=ze),Nt!==Ie._v$8&&he.classList.toggle("bg-[#9CA3AF]",Ie._v$8=Nt),O!==Ie._v$9&&he.style.setProperty("height",Ie._v$9=O),Ie},{_v$7:void 0,_v$8:void 0,_v$9:void 0}),he})()}})),i(dt,J),i(Zt,a(E,{get when(){return y()},get children(){const k=Lo.cloneNode(!0);return M(()=>k.style.setProperty("left",`${Math.max(0,Math.min(100,L()))}%`)),k}}),Ft),Ft.$$input=k=>de(Number(k.currentTarget.value)),Je(k=>ce(k),Ft),en.$$input=k=>se(Number(k.currentTarget.value)),Je(k=>Q(k),en),mt.$$click=()=>{if(y()){Te();return}Me()},i(mt,a(E,{get when(){return y()},get fallback(){return Wo.cloneNode(!0)},get children(){return Mo.cloneNode(!0)}})),i(Dt,()=>sr(Math.max(0,F()-f().start)),Fn),i(Dt,()=>sr(z()),null),tn.addEventListener("change",k=>I(k.currentTarget.checked)),i(wn,a(E,{get when(){return!m()},fallback:"Preparing audio preview…",get children(){return l()?"Preview updates as you drag.":"Boundary preview — generate a sample to hear the new voice."}})),Dn.$$click=Ce,i(Pe,a(E,{get when(){return d()},get children(){const k=Po.cloneNode(!0);return i(k,d),k}}),null),i(Pe,a(E,{get when(){return H()},get children(){const k=Ro.cloneNode(!0);return i(k,H),k}}),null),nn.$$click=vt,v.$$click=()=>void gt(),i(v,()=>ee()?"Saving…":"Save timing"),M(k=>{const U=`${N()}%`,me=`${T()}%`,ie=y()?"Pause audio preview":"Play audio preview",he=m()||!G,Ie=ee(),ze=ee();return U!==k._v$&&Rt.style.setProperty("left",k._v$=U),me!==k._v$2&&Rt.style.setProperty("width",k._v$2=me),ie!==k._v$3&&te(mt,"aria-label",k._v$3=ie),he!==k._v$4&&(mt.disabled=k._v$4=he),Ie!==k._v$5&&(nn.disabled=k._v$5=Ie),ze!==k._v$6&&(v.disabled=k._v$6=ze),k},{_v$:void 0,_v$2:void 0,_v$3:void 0,_v$4:void 0,_v$5:void 0,_v$6:void 0}),M(()=>tn.checked=w()),V}})};je(["click","input"]);const qo=(e,t,n)=>{const r=(e??"").trim(),s=t.trim().replace(/^s3:\/\//,"").replace(/\/+$/,""),c=n.trim();if(!r||!s)return"";if(/^(?:s3|https):\/\//i.test(r))return r;const o=`s3.${c}.amazonaws.com/`,g=`${s}.s3.${c}.amazonaws.com/`,p=`${s}.s3.amazonaws.com/`;if(c&&r.startsWith(o)||c&&r.startsWith(g)||r.startsWith(p)||r.startsWith("cdn.bhuman.ai/"))return`https://${r}`;const m=r.startsWith(`${s}/`)?r.slice(s.length+1):r.replace(/^\/+/,"");return`s3://${s}/${m}`},ts=1,ns=1/3,An=e=>{const t=e.timing_balance;return typeof t=="number"&&Number.isFinite(t)&&t>=0&&t<=1?t:ns},Ho=(e,t)=>({...e,timing_balance:An({timing_balance:t})}),ur=e=>{const t=e.map((n,r)=>({index:r,playable:typeof n.preview_url=="string"&&n.preview_url.trim().length>0,score:typeof n.prosody_score=="number"?n.prosody_score:Number.NaN})).filter(n=>n.playable&&Number.isFinite(n.score)&&n.score>=0);return t.length<2?-1:t.reduce((n,r)=>r.score<n.score?r:n).index},gr=e=>(e??"").trim().toLowerCase(),Yo=(e,t)=>{const n=e.filter(o=>o.kind===-1),r=n.find(o=>o.id===t.id);if(r)return r;const s=gr(t.name);if(!s)return null;const c=n.filter(o=>gr(o.name)===s);return c.length===1?c[0]:null},Vn=e=>{const t=(e??"").trim();if(!t)return{};try{const n=JSON.parse(t);return n&&typeof n=="object"?n:{}}catch{return{}}},si=e=>{const t=Vn(e).selected_prosody_reference;return t?.version!==ts||!t.source_url?.trim()||!t.transcript?.trim()||!Number.isFinite(t.duration_seconds)||t.duration_seconds<=0?null:t},Jo=(e,t)=>({...e,selected_prosody_reference:{...t,version:ts,source_url:t.source_url.trim(),transcript:t.transcript.trim(),sample_value:t.sample_value?.trim()||void 0}}),Qo=u('<span class="inline-flex h-4 w-4 items-center justify-center rounded-full border border-gray-400 text-[10px] font-semibold text-gray-600">i</span>'),Ko=u('<div class="space-y-1"><label class="text-[13px] font-medium text-black inline-flex items-center gap-1.5"><span> <span class="text-[12px] text-[#4d4d4d]"></span></span></label><input type="range" class="w-full"></div>'),Zo=u('<p class="text-[13px] text-[#4d4d4d]">Variable: <span class="font-medium text-black"></span></p>'),Xo=u('<div class="space-y-2"><label for="variable-style-timing-balance" class="block text-[13px] font-semibold text-foreground">Timing balance</label><p id="variable-style-timing-help" class="text-[12px] text-muted-foreground">Adjust only <!>. Video and audio speeds compensate for each other.</p><input id="variable-style-timing-balance" type="range" min="0" max="100" step="1" aria-describedby="variable-style-timing-help" class="h-10 w-full cursor-pointer accent-primary focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"><div class="flex justify-between gap-3 text-[12px] text-muted-foreground"><span>Natural voice · slower video</span><span>Normal video · faster voice</span></div><p class="text-[12px] text-muted-foreground">Speeds stay within safe limits; audio never speeds up beyond 1.2×. Regenerate a video sample to hear the timing change.</p></div>'),pr=u('<button type="button" class="px-3 py-2 rounded-[8px] border border-gray-300 text-sm font-medium hover:bg-gray-50 disabled:opacity-50"></button>'),el=u('<span class="text-[13px] text-[#4d4d4d]"> options</span>'),tl=u('<div class="border border-gray-200 rounded-[8px] p-2 space-y-2"></div>'),nl=u('<div class="flex max-h-[calc(100dvh-2rem)] min-h-0 flex-col"><div class="shrink-0 space-y-1 border-b border-gray-200 px-5 pb-4 pt-5 md:px-6 md:pt-6"><p class="text-[20px] font-semibold text-black">Choose speaking style</p><p class="text-[14px] text-[#4d4d4d]">Generate a few options, then choose the delivery that sounds most natural going into your original video.</p></div><div class="min-h-0 flex-1 space-y-5 overflow-y-auto px-5 py-4 md:px-6"><div class="space-y-1"><label class="text-[13px] font-medium text-black inline-flex items-center gap-1.5"><span>Sample value</span></label><input type="text" class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-[8px] focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5" placeholder="Enter a sample value"></div><details class="rounded-[8px] border border-gray-200 bg-[#FAFAFA] px-3 py-2"><summary class="cursor-pointer text-[13px] font-medium text-[#4d4d4d]">Fine-tune sample generation</summary><div class="mt-4 space-y-4"></div></details><div class="flex flex-wrap items-center gap-2"></div></div><div class="flex shrink-0 justify-end gap-2 border-t border-gray-200 bg-white px-5 py-4 md:px-6"><button type="button" class="px-3 py-2 rounded-[8px] border border-gray-300 text-sm font-medium hover:bg-gray-50 disabled:opacity-50">Cancel</button><button type="button" class="px-3 py-2 rounded-[8px] bg-blue-600 text-white text-sm font-medium hover:bg-blue-700 disabled:bg-blue-300"></button></div></div>
5'),il=u("<audio></audio>"),rl=u('<div class="border border-dashed border-gray-300 rounded-[8px] p-4 text-[13px] text-[#4d4d4d]"></div>'),sl=u('<span class="rounded-full bg-blue-50 px-2 py-0.5 text-[11px] font-semibold text-blue-700">Best match</span>'),al=u('<p class="text-[12px] text-red-600"></p>'),ol=u('<div class="w-full text-left rounded-[8px] border p-3"><div class="flex items-center justify-between gap-3"><div class="flex min-w-0 items-start gap-3"><input type="radio" name="speaking-style-option" class="mt-0.5 h-4 w-4 shrink-0 accent-blue-600"><div class="space-y-1"><p class="flex items-center gap-2 text-[14px] font-medium text-black"><span>Option </span></p><p class="text-[12px] text-[#4d4d4d]">Generated phrase → original video</p></div></div><button type="button" class="px-3 py-1.5 rounded-[8px] border border-gray-300 text-xs font-medium disabled:opacity-50 disabled:cursor-not-allowed hover:bg-gray-100"></button></div></div>'),is={stability:.5,similarity_boost:.75,style:0,use_speaker_boost:!0},tt={temperature:.7,topP:.7,latency:"normal",chunkLength:200,normalize:!0,speed:1,volume:0,normalizeLoudness:!0},In=(e,t,n)=>Math.max(t,Math.min(n,e)),un=(e,t,n,r)=>{const s=typeof e=="number"?e:Number(e);return Number.isFinite(s)?In(s,n,r):t},ll=e=>String(e||"").trim().toLowerCase()==="balanced"?"balanced":"normal",dl=(e,t)=>{const n=t.trim()||e.highlight||e.name||"Sample",r=(e.segment||"").trim();if(!r)return n;if(e.highlight&&r.includes(e.highlight))return r.replace(e.highlight,n);const s=`[${e.name}]`;return r.includes(s)?r.replace(s,n):r},ai=e=>(e?.preview_url??"").trim(),kn=e=>ai(e).length>0,cl=e=>(e?.preview_error??"").trim()||"Context preview unavailable for this option.",oi="This variable changed while the chooser was open. Close it and try again.",ul=e=>{if(e&&typeof e=="object"&&"result"in e){const t=e.result;if(typeof t?.error=="string"&&t.error.trim())return t.error.trim()}return e instanceof Error&&e.message===oi?oi:"Failed to save speaking style."},gl=(e,t)=>{const n=e?.variable_start_times;if(!n||typeof n!="object")return null;const r=n?.[t.name];if(r==null)return null;const s=typeof r=="number"?r:Number(String(r).trim());return!Number.isFinite(s)||s<0?null:s},mr=(e,t)=>{const n=Fi(String(t.start_time??"0")),r=Fi(String(t.end_time??"0")),s=Number.isFinite(n)&&n>=0?n:0,c=Math.max(.2,Number.isFinite(r)?r-s:0),g=gl(e,t)??s,p=g+c;return{durationSeconds:c,effectiveStartSeconds:g,startTime:Pn(g),endTime:Pn(p)}},pl=(e,t)=>new Promise(n=>{const r=new Audio;let s=!1;const c=g=>{if(s)return;s=!0,window.clearTimeout(o),r.removeAttribute("src"),r.load();const p=Number(g);n(Number.isFinite(p)&&p>=.05&&p<=60?Number(p.toFixed(3)):Number(Math.max(.05,t).toFixed(3)))},o=window.setTimeout(()=>c(),6e3);r.preload="metadata",r.onloadedmetadata=()=>c(r.duration),r.onerror=()=>c(),r.src=e}),fr=e=>a(Kt,{get aria_label(){return e.text},data_microtip_position:"top",data_microtip_size:"medium",enabled_tooltip:!0,class:"inline-flex items-center align-middle",get children(){return Qo.cloneNode(!0)}}),Hn=e=>({model_id:"premium",provider:"fish",...is,fish_temperature:un(e?.fish_temperature,tt.temperature,0,1),fish_top_p:un(e?.fish_top_p,tt.topP,0,1),fish_latency:ll(e?.fish_latency),fish_chunk_length:Math.round(un(e?.fish_chunk_length,tt.chunkLength,100,300)),fish_normalize:typeof e?.fish_normalize=="boolean"?e.fish_normalize:tt.normalize,fish_speed:un(e?.fish_speed,tt.speed,.5,2),fish_volume:un(e?.fish_volume,tt.volume,-20,20),fish_normalize_loudness:typeof e?.fish_normalize_loudness=="boolean"?e.fish_normalize_loudness:tt.normalizeLoudness}),ml=e=>{const[t,n]=C(""),[r,s]=C(tt.temperature),[c,o]=C(tt.topP),[g,p]=C(tt.latency),[m,h]=C(tt.chunkLength),[d,b]=C(tt.normalize),[l,_]=C(tt.speed),[y,S]=C(tt.normalizeLoudness),[w,I]=C([]),[F,R]=C(-1),[ee,fe]=C(!1),[H,be]=C(!1),[j,ce]=C(ns),W=()=>vn(e.instance)==="keep_original",Q=()=>W()&&j()!==An(Vn(e.segment?.voice_config)),[A,G]=C(-1),ne=B(()=>ur(w())),Z=async q=>{const J=String(e.instance?.id??"").trim();if(!J)return q;let K;try{K=await Bt.list({video_instance_id:J})}catch(f){return console.warn("Couldn’t refresh the speaking-style variable before saving",f),q}const $=Yo(K?.result??[],q);if(!$)throw new Error(oi);return $};let ge;const $e=()=>Hn({fish_temperature:r(),fish_top_p:c(),fish_latency:g(),fish_chunk_length:m(),fish_normalize:d(),fish_speed:l(),fish_volume:tt.volume,fish_normalize_loudne
5ss:y()}),ye=()=>{const q=e.segment;if(!q)return;const J=Vn(q.voice_config);ce(An(J));const K=Hn(J),$=si(q.voice_config);n($?.sample_value?.trim()||q.highlight?.trim()||q.name?.trim()||"Sample"),s(K.fish_temperature),o(K.fish_top_p),p(K.fish_latency),h(K.fish_chunk_length),b(K.fish_normalize),_(K.fish_speed),S(K.fish_normalize_loudness),I([]),R(-1),G(-1),ge&&(ge.pause(),ge.currentTime=0,ge.src="")},xe=async q=>{if(ee())return;const J=e.segment,K=e.instance;if(!J?.id||!K?.id||!K?.video_url){Y.error("Missing data to generate voice samples.");return}const $=t().trim();if(!$){Y.error("Enter a sample value before generating samples.");return}fe(!0);try{const f=dl(J,$),N=mr(K,J),T=await ga({count:4,persist:!1,instance_id:K.id,s3_url:qo(K.video_url,gi,ui),training_url:K.training_url??null,segments:[{segment_id:J.id,segment:f,start_time:N.startTime,end_time:N.endTime}],tuning:{...$e(),context_preview:!0,context_before_seconds:0,context_after_seconds:5}}),L=T?.result?.configs?.find(ae=>ae.segment_id===J.id)?.configs??T?.result?.configs?.[0]?.configs??[];if(!L.length)throw new Error("No samples returned.");const z=L.map(ae=>({...ae,calibration_text:f,calibration_value:$})),re=q?[...w(),...z]:z;I(re),R(ur(re))}catch(f){console.error(f),Y.error("Failed to generate voice samples.")}finally{fe(!1)}},ve=async(q,J)=>{if(!ge)return;const K=ai(q);if(K){if(A()===J){ge.pause(),ge.currentTime=0,G(-1);return}try{ge.pause(),ge.currentTime=0,ge.src=K,await ge.play(),R(J),G(J)}catch($){console.error($),G(-1),Y.error("Unable to play sample.")}}},Se=async()=>{if(H())return;const q=e.segment;if(!q?.id)return;const J=w()[F()],K=!!J&&kn(J);if(!K&&!Q()){Y.error("Select a sample before saving.");return}const $=j(),f=Q();be(!0);try{const N=await Z(q),T=mr(e.instance,N).durationSeconds,L=K?await pl(J.sample_url,T):T,z=Vn(N.voice_config||e.instance?.voice_config),re=K?Jo(Hn(J),{source_url:ai(J),transcript:J.calibration_text,duration_seconds:L,sample_value:J.calibration_value}):{...is,model_id:"premium",provider:"fish",...z},ae=JSON.stringify(f||z.timing_balance!==void 0?Ho(re,f?$:An(z)):re);await pa(N.id,ae),e.onSaved(q.id,N,ae),Y.success(K?"Speaking style saved.":"Timing saved. Generate a new sample to hear the change."),e.onClose()}catch(N){console.error(N),Y.error(ul(N))}finally{be(!1)}};Ae(bn(()=>[e.open,e.segment?.id],([q])=>{!q||!e.segment||ye()}));const we=q=>(()=>{const J=Ko.cloneNode(!0),K=J.firstChild,$=K.firstChild,f=$.firstChild,N=f.nextSibling,T=K.nextSibling;return i($,()=>q.label,f),i(N,()=>q.value().toFixed(q.decimals??2)),i(K,a(fr,{get text(){return q.help}}),null),T.$$input=L=>q.onChange(Number(L.currentTarget.value)),M(L=>{const z=q.min,re=q.max,ae=q.step;return z!==L._v$&&te(T,"min",L._v$=z),re!==L._v$2&&te(T,"max",L._v$2=re),ae!==L._v$3&&te(T,"step",L._v$3=ae),L},{_v$:void 0,_v$2:void 0,_v$3:void 0}),M(()=>T.value=q.value()),J})();return a(Mt,{get open(){return e.open},onClose:()=>{ee()||H()||e.onClose()},closeButton:!0,class:"max-h-[calc(100dvh-2rem)] w-[94vw] max-w-[920px]",get children(){return[(()=>{const q=nl.cloneNode(!0),J=q.firstChild;J.firstChild.nextSibling;const $=J.nextSibling,f=$.firstChild,N=f.firstChild;N.firstChild;const T=N.nextSibling,L=f.nextSibling,z=L.firstChild,re=z.nextSibling,ae=L.nextSibling,Te=$.nextSibling,Oe=Te.firstChild,Re=Oe.nextSibling;return i(J,a(E,{get when(){return e.segment},get children(){const D=Zo.cloneNode(!0),Ve=D.firstChild,le=Ve.nextSibling;return i(le,()=>e.segment?.name),D}}),null),i($,a(E,{get when(){return W()},get children(){const D=Xo.cloneNode(!0),Ve=D.firstChild,le=Ve.nextSibling,Me=le.firstChild,pe=Me.nextSibling;pe.nextSibling;const de=le.nextSibling;return i(le,()=>e.segment?.name,pe),de.$$input=se=>ce(Number(se.currentTarget.value)/100),M(se=>{const Ce=H()||ee(),Xe=`${Math.round((1-j())*100)}% preference for natural voice pace`;return Ce!==se._v$4&&(de.disabled=se._v$4=Ce),Xe!==se._v$5&&te(de,"aria-valuetext",se._v$5=Xe),se},{_v$4:void 0,_v$5:void 0}),M(()=>de.value=Math.round(j()*100)),D}}),f),i(N,a(fr,{text:"Use a realistic value, such as a typical first name."}),null),T.$$input=D=>
5n(D.currentTarget.value),i(re,a(we,{label:"Speed",value:l,onChange:D=>_(In(D,.5,2)),min:.5,max:2,step:.05,help:"Controls how quickly this variable is spoken."}),null),i(re,a(we,{label:"Variation",value:r,onChange:D=>s(In(D,0,1)),min:0,max:1,step:.01,help:"Higher values make delivery more varied. Lower values make it more consistent."}),null),i(re,a(we,{label:"Diversity",value:c,onChange:D=>o(In(D,0,1)),min:0,max:1,step:.01,help:"Controls how broadly possible speech patterns are sampled."}),null),i(ae,a(E,{get when(){return w().length>0},get fallback(){return(()=>{const D=pr.cloneNode(!0);return D.$$click=()=>void xe(!1),i(D,()=>ee()?"Generating...":"Generate 4 options"),M(()=>D.disabled=ee()||H()||!t().trim()),D})()},get children(){const D=pr.cloneNode(!0);return D.$$click=()=>void xe(!0),i(D,()=>ee()?"Generating...":"Try 4 more"),M(()=>D.disabled=ee()||H()||!t().trim()),D}}),null),i(ae,a(E,{get when(){return w().length>0},get children(){const D=el.cloneNode(!0),Ve=D.firstChild;return i(D,()=>w().length,Ve),D}}),null),i($,a(E,{get when(){return w().length>0},get fallback(){return(()=>{const D=rl.cloneNode(!0);return i(D,()=>ee()?"Generating audio options...":"Generate options to hear the personalized phrase flow into your original recording."),D})()},get children(){const D=tl.cloneNode(!0);return i(D,a(rt,{get each(){return w()},children:(Ve,le)=>{const Me=kn(Ve),pe=()=>Me&&F()===le(),de=A()===le();return(()=>{const se=ol.cloneNode(!0),Ce=se.firstChild,Xe=Ce.firstChild,gt=Xe.firstChild,vt=gt.nextSibling,V=vt.firstChild,X=V.firstChild;X.firstChild,V.nextSibling;const ue=Xe.nextSibling;return se.$$click=()=>{Me&&R(le())},gt.addEventListener("change",()=>R(le())),gt.disabled=!Me,i(X,()=>le()+1,null),i(V,a(E,{get when(){return ne()===le()},get children(){return sl.cloneNode(!0)}}),null),i(vt,a(E,{when:!Me,get children(){const Fe=al.cloneNode(!0);return i(Fe,()=>cl(Ve)),Fe}}),null),ue.$$click=Fe=>{Fe.stopPropagation(),Me&&ve(Ve,le())},ue.disabled=!Me,i(ue,de?"Pause":"Play"),M(Fe=>lt(se,{"border-blue-500":pe(),"bg-blue-50":pe(),"border-gray-200":!pe(),"hover:bg-gray-50":Me,"cursor-pointer":Me,"opacity-60":!Me,"cursor-not-allowed":!Me},Fe)),M(()=>gt.checked=pe()),se})()}})),D}}),null),Oe.$$click=()=>{ee()||H()||e.onClose()},Re.$$click=()=>void Se(),i(Re,(()=>{const D=B(()=>!!H());return()=>D()?"Saving...":kn(w()[F()])?"Use this style":"Save timing"})()),M(D=>{const Ve=H()||ee(),le=H()||ee()||!Q()&&!kn(w()[F()]);return Ve!==D._v$6&&(Oe.disabled=D._v$6=Ve),le!==D._v$7&&(Re.disabled=D._v$7=le),D},{_v$6:void 0,_v$7:void 0}),M(()=>T.value=t()),q})(),(()=>{const q=il.cloneNode(!0);q.addEventListener("pause",()=>G(-1)),q.addEventListener("ended",()=>G(-1));const J=ge;return typeof J=="function"?Je(J,q):ge=q,q})()]}})};je(["input","click"]);const fl=e=>{if(!e||e.is_free===!0)return!1;const t=String(e.name||"").trim().toLowerCase();return t.length>0&&t!=="free"&&t!=="free plan"},hl=(e,t)=>fl(e)||(sa(t)??0)>0,bl="Add AI Studio credits or upgrade your plan to choose a speaking style.",vl=u('<span class="inline-flex h-4 w-4 items-center justify-center rounded-full border border-gray-400 text-[10px] font-semibold leading-none text-gray-600 cursor-help">i</span>'),_l=u('<div><p class="mt-1 text-[12px] leading-5 text-muted-foreground">Hear generated speech flow into your original video, then choose the most natural delivery.</p></div>'),hr=u('<div class="divide-y divide-border overflow-hidden rounded-[8px] border border-border bg-white"></div>'),xl=u('<div class="flex items-center gap-2.5"><input id="enable-lipsync-advanced" type="checkbox" class="h-4 w-4 cursor-pointer accent-blue-600"><label for="enable-lipsync-advanced" class="cursor-pointer text-[14px] font-medium text-black">Enable lip sync</label></div>'),wl=u('<div class="mt-3 border-t border-gray-200 pl-6 pt-3"><div class="flex items-center gap-1.5"><label for="lipsync-quality-select" class="text-[12px] font-medium text-[#111827]">Smoothest quality</label></div><select id="lipsync-quality-select" name="lipsync-quality" class="mt-2 w-full rounded-[8px] border border-gray-200 bg-white px-3 py-2 text-[13px] font-medium text-[#111827] outline-none transition-colors focus:border-blue-500 focus:ring-2 focus:ring-blue-100"><option value="standard">480p - 1x credits</option><option value="premium">720p - 2x credits</option></select></div>'),$l=u('<details class="rounded-[8px] border border-gray-200 bg-[#FAFAFA] px-3 py-2"><summary class="cursor-pointer text-[13px] font-medium text-[#4d4d4d]">Video result</summary><fieldset class="mt-3 space-y-2"><legend class="sr-only">Choose a video result</legend><label for="generation-mode-keep-original" class="flex cursor-pointer items-start gap-2.5 rounded-[8px] border border-gray-200 bg-white p-3 transition-colors hover:border-gray-300"><input id="generation-mode-keep-original" type="radio" name="generation-mode" value="keep_original" class="mt-0.5 h-4 w-4 cursor-pointer accent-blue-600"><div class="min-w-0"><div class="flex flex-wrap items-center gap-2"><p class="text-[13px] font-medium text-[#111827]">Keep original video</p><span class="rounded-full bg-[#E8EEFF] px-2 py-0.5 text-[11px] font-semibold text-[#3A57D6]">Recommended</span></div><p class="mt-1 text-[12px] leading-5 text-[#6b7280]">Changes the personalized parts and keeps the rest of your original video.</p></div></label><div class="rounded-[8px] border border-gray-200 bg-white p-3 transition-colors hover:border-gray-300"><label for="generation-mode-full-script" class="flex cursor-pointer items-start gap-2.5"><input id="generation-mode-full-script" type="radio" name="generation-mode" value="full_script" class="mt-0.5 h-4 w-4 cursor-pointer accent-blue-600"><div class="min-w-0"><p class="text-[13px] font-medium text-[#111827]">Smoothest result</p><p class="mt-1 text-[12px] leading-5 text-[#6b7280]">Rebuilds the full video for smoother mouth movement. It may change more of the original.</p></div></label></div></fieldset></details>'),yl=u('<div class="flex items-start gap-1.5"><div><p class="mt-1 text-[12px] leading-5 text-muted-foreground">Fix transitions where a personalized word clips the next sound.</p></div></div>
5'),Sl=u('<div role="status" aria-live="polite" class="rounded-[8px] border border-border bg-muted px-3 py-2 text-[12px] leading-5 text-foreground">Timing saved. Generate a new sample to hear this change.</div>'),Cl=u('<details class="rounded-[8px] border border-border bg-muted px-3 py-2"><summary class="cursor-pointer text-[12px] font-medium text-muted-foreground">Add timing for another variable</summary><div class="mt-3 flex flex-col gap-2 sm:flex-row"><label class="sr-only" for="manual-audio-timing-variable">Variable name</label><input id="manual-audio-timing-variable" type="text" placeholder="Variable name" class="block h-10 min-w-0 flex-1 rounded-[8px] border border-border bg-white px-3 text-[13px] text-foreground outline-none focus:border-primary focus:ring-2 focus:ring-primary/15"><button type="button" class="inline-flex h-10 items-center justify-center rounded-[8px] border border-border bg-white px-3 text-[12px] font-semibold text-foreground transition-colors hover:bg-white/70 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary">Adjust timing</button></div></details>'),kl=u('<span class="flex items-center gap-2"><span>Audio</span></span>'),Tl=u('<div class="space-y-2"><p class="text-[14px] leading-6 text-[#4d4d4d]">Have more than one voice profile in your video? Upload an audio file so AI Studio can match the right voice in each variable replacement.</p><button type="button" class="inline-flex h-11 items-center justify-center rounded-[8px] border border-[#111827] px-4 text-[14px] font-semibold text-[#111827] transition-colors hover:bg-gray-50"></button></div>'),Nl=u('<section aria-label="Advanced settings" class="bg-white"></section>'),El=u('<p class="rounded-[8px] border border-border bg-muted px-3 py-3 text-[12px] leading-5 text-muted-foreground">Add a transcript variable first, then you can choose its speaking style here.</p>'),Al=u('<button type="button" class="inline-flex h-9 shrink-0 items-center justify-center rounded-[8px] border border-border bg-white px-3 text-[12px] font-semibold text-foreground transition-colors hover:bg-muted focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary disabled:cursor-not-allowed disabled:bg-muted disabled:text-muted-foreground"></button>'),Vl=u('<div class="flex min-h-14 items-center gap-3 px-3 py-2.5"><div class="min-w-0 flex-1"><p class="truncate text-[13px] font-semibold text-foreground"></p><p class="mt-0.5 text-[11px] text-muted-foreground"></p></div></div>'),Il=u('<p class="rounded-[8px] border border-border bg-muted px-3 py-3 text-[12px] leading-5 text-muted-foreground">Create a transcript variable first, then its audio timing will appear here.</p>'),Ll=u('<div class="flex min-h-14 items-center gap-3 px-3 py-2.5"><div class="min-w-0 flex-1"><p class="truncate text-[13px] font-semibold text-foreground"></p><p class="mt-0.5 text-[11px] text-muted-foreground"></p></div><button type="button" class="inline-flex h-9 shrink-0 items-center justify-center rounded-[8px] border border-border bg-white px-3 text-[12px] font-semibold text-foreground transition-colors hover:bg-muted focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary">Adjust timing</button><button type="button" title="Delete variable" class="inline-flex h-9 w-9 shrink-0 items-center justify-center rounded-[8px] text-muted-foreground transition-colors hover:bg-destructive/10 hover:text-destructive focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-destructive"></button></div>'),Yn=e=>a(Kt,{get aria_label(){return e.tip},data_microtip_position:"top",data_microtip_size:"medium",enabled_tooltip:!0,get class(){return e.class},get children(){return vl.cloneNode(!0)}}),br=e=>e.trim().toLowerCase().replace(/^[^a-z0-9]+|[^a-z0-9]+$/gi,""),Ml=(e,t)=>{const n=Mn()?.segments||[];if(n.length===0)return null;const r=br(e);if(!r)return null;const s=Math.max(0,t.window_start_seconds-.35),c=Math.max(s,t.window_end_seconds+.35);let o,g=Number.POSITIVE_INFINITY;if(n.forEach((l,_)=>{l.words.forEach((y,S)=>{if(br(y.word)!==r||y.end<s||y.start>c)return;const I=Math.abs(y.start-t.window_start_seconds);I<g&&(g=I,o={segmentIndex:_,wordIndex:S})})}),!o)return null;const p=n[o.segmentIndex],{start:m,end:h}=xs({words:p.words,selectionStart:o.wordIndex,selectionEnd:o.wordIndex,vadRanges:Mn()?.vad_ranges,pauseThresholdSeconds:ws,maxPhraseLetters:$s}
5),d=ys(p.words.slice(m,h+1).map(l=>l.word)),b=p.words[o.wordIndex]?.word?.trim();return!d||!b?null:{highlight:b,segment:d,highlight_si:o.segmentIndex*1e3+o.wordIndex,highlight_ei:Ss+o.wordIndex,start_time:Pn(Math.max(0,p.words[m].start-Ai())),end_time:Pn(p.words[h].end+Ai())}},vr=e=>{const{setTrainingAudioUpload:t,instance:n,sampleGeneratedVideo:r}=e,[s,c]=C("off");Ae(()=>{const $=e.instance?.variable_timing_config?.__background_sound?.preset;c($==="subtle"||$==="more"?$:"off")});const[o,g]=C(null),p=$=>g(f=>f===$?null:$);Ae(()=>{e.instance?.id,g(null)});const[m,h]=C(""),[d,b]=C(null),[l,_]=C(null),[y,S]=C(vn(n)),[w,I]=C(_n(n)),[F,R]=C({}),[ee,fe]=C(null);Ae(()=>{R(Qt(n?.variable_timing_config))});const H=B(()=>(n?.segments||[]).filter($=>$.kind===-1).slice().sort(($,f)=>($.highlight_si??0)-(f.highlight_si??0)||String($.name??"").localeCompare(String(f.name??"")))),be=B(()=>hl(Ei?.userPlan,Ei?.userWallet)),j=B(()=>H().find($=>$.id===l())??null);Ae(()=>{S(vn(n)),I(_n(n))});const ce=B(()=>{const $=(d()??"").trim();return $?an($,(n?.segments||[]).filter(f=>f.kind===-1),Ye(),F()):null}),W=B(()=>{const $=(d()??"").trim();return $?an($,(n?.segments||[]).filter(f=>f.kind===-1),{},{}):null}),Q=B(()=>{const $=(n?.segments||[]).filter(N=>N.kind===-1).map(N=>N.name),f=Object.keys(Ye()||{});return Array.from(new Set([...$,...f]))}),A=B(()=>(typeof r=="function"?r():[]).find(f=>(f?.status==="succeeded"||f?.status==="completed")&&(f?.url||f?.share_url))),G=B(()=>{const $=ee();return $===null?!1:String(A()?.id??"")===$}),ne=B(()=>{const $=(d()??"").trim(),f=Q().indexOf($);return f<0?$:A()?.text?.[f]||$}),Z=$=>{const f=(n?.segments||[]).filter(L=>L.kind===-1),N=an($,f,Ye(),F()),T=an($,f,{},{});return Math.abs(N.window_start_seconds-T.window_start_seconds)>.005||Math.abs(N.window_end_seconds-T.window_end_seconds)>.005},ge=($,f,N)=>{let T=!1;const L=(n?.segments||[]).map(z=>z.id!==$&&z.id!==f.id?z:(T=!0,{...f,voice_config:N}));T||L.push({...f,voice_config:N}),nt({...n,segments:L})},$e=($,f)=>{const N={...$},T={...Qt(f)},L=n?.segments||[];for(const z of Q()){const re=an(z,L,N,T);N[z]=String(Number(re.window_start_seconds.toFixed(3))),T[z]=re}return{nextTimes:N,nextConfig:T}},ye=($,f,N)=>{n?.id&&ti(n.id,{enable_lipsync:$,render_quality:w(),variable_start_times:f,variable_timing_config:N})},xe=async($,f,N,T=!0)=>{if(!n?.id)return!1;try{const L={},z=n?.segments||[],re=pi({variableNames:Q(),segments:z,manualStartTimes:f,config:N}),ae=re.variable_timing_config;for(const[de,se]of Object.entries(re.variable_start_times)){if(!Number.isFinite(se)||se<0){if(!T)continue;return Y.error(`Please enter a valid window start time for "${de}".`),!1}const Ce=ae[de];if(!Ce||!(Ce.window_end_seconds>Ce.window_start_seconds)){if(!T)continue;return Y.error(`Please enter a valid window end time for "${de}".`),!1}L[de]=se}const Te=[...n?.segments||[]],Oe=new Set(Te.filter(de=>de.kind===-1).map(de=>de.name));for(const de of Object.keys(L)){if(Oe.has(de))continue;const se=ae[de];if(!se)return Y.error(`Missing timing window for "${de}".`),!1;const Ce=Ml(de,se);if(!Ce)return Y.error(`Could not resolve the full phrase for "${de}" from the transcript. Create the variable from the transcript first.`),!1;const Xe=await Bt.create({name:de,kind:-1,start_time:Ce.start_time,end_time:Ce.end_time,video_instance_id:n.id,highlight_ei:Ce.highlight_ei,highlight_si:Ce.highlight_si,highlight:Ce.highlight,segment:Ce.segment});Xe?.result&&(Te.push(Xe.result),Oe.add(de))}const Re=mn(fn(ae,y()),w()),D=await it.update({id:n.id,enable_lipsync:$,variable_start_times:L,variable_timing_config:Re});if(D?.code!==200&&D?.code!==201)return Y.error("Failed to save lip sync settings."),!1;if(!D?.result)return Y.error("Failed to save lip sync settings."),!1;const Ve=D.result.variable_timing_config??Re,le=Qt(Ve),Me=Object.fromEntries(Object.keys(le).map(de=>[de,le[de].window_start_seconds]));nt({...n,enable_lipsync:$,variable_start_times:Me,variable_timing_config:Ve,segments:Te});const pe=Object.fromEntries(Object.entries(Me).map(([de,se])=>[de,String(se)]));return Vt(pe),R(le),ye($,pe,le),!0}catch(L){return console.error(L),Y.error(L instanceof Error?L.message:"Failed to save lip sync settings."),!1}},ve=async $=>{const f=y();if(S($),Di(n?.id,$),!n?.id)return;const N=mn(fn(F(),$),w());try{const T=await it.update({id:n.id,variable_timing_config:N});if(T?.code!==200&&T?.code!==201)throw new Error("Failed to save generation settings.");nt({...n,variable_timing_config:T.result?.variable_timing_config??N})}catch(T){console.error(T),S(f),Di(n?.id,f),Y.error("Failed to save generation settings.")}},Se=async $=>{const f=w();if(I($),Wi(n?.id,$),!n?.id)return;const N=mn(fn(F(),y()),$);try{const T=await it.update({id:n.id,variable_timing_config:N});if(T?.code!==200&&T?.code!==201)throw new Error("Failed to save lip sync quality.");nt({...n,variable_timing_config:T.result?.variable_timing_config??N}
5),ti(n.id,{enable_lipsync:et(),render_quality:$,variable_start_times:Ye(),variable_timing_config:F()})}catch(T){console.error(T),I(f),Wi(n?.id,f),Y.error("Failed to save lip sync quality.")}},we=$=>{const f=$.trim();if(!f){Y.error("Enter a variable name first.");return}const N=Q().find(T=>T.trim().toLowerCase()===f.toLowerCase())??f;b(N)},q=async($,f)=>{const N=f.fit_mode==="speed_up_voice"||f.fit_mode==="slow_down_video"||f.fit_mode==="both"?f.fit_mode:"both",T={window_start_seconds:Number(f.window_start_seconds.toFixed(3)),window_end_seconds:Number(f.window_end_seconds.toFixed(3)),anchor:f.anchor==="right"?"right":"left",fit_mode:N},L={...Ye(),[$]:String(T.window_start_seconds)},z={...F(),[$]:T};return Vt(L),R(z),ye(et(),L,z),await xe(et(),L,z,!0)?(m().trim().toLowerCase()===$.toLowerCase()&&h(""),fe(String(A()?.id??"")),e.onTimingSaved?.(),Y.success("Timing saved. Generate a new sample to hear the change."),!0):!1},J=()=>{we(m())},K=async $=>{try{const{nextSegments:f,nextStartTimes:N,nextTimingConfig:T,persistedTimingConfig:L,parsedStartTimes:z}=await Gr({instance:n,variableName:$,enableLipsync:et(),variableStartTimes:Ye(),variableTimingConfig:F()});nt({...n,segments:f,variable_start_times:z,variable_timing_config:L}),Vt(N),R(T),ye(et(),N,T),(d()??"").trim().toLowerCase()===$.trim().toLowerCase()&&b(null),m().trim().toLowerCase()===$.trim().toLowerCase()&&h(""),Y.success("Variable deleted.")}catch(f){console.error(f),Y.error("Failed to delete variable.")}};return(()=>{const $=Nl.cloneNode(!0);return $.style.setProperty("font-family","Manrope, sans-serif"),i($,a(ln,{title:"Speaking style",get summary(){return H().some(f=>
5!!si(f.voice_config))?"Custom":"Automatic"},get open(){return o()==="speaking-style"},onToggle:()=>p("speaking-style"),get children(){return[_l.cloneNode(!0),a(E,{get when(){return H().length>0},get fallback(){return El.cloneNode(!0)},get children(){const f=hr.cloneNode(!0);return i(f,a(rt,{get each(){return H()},children:N=>{const T=()=>!!si(N.voice_config);return(()=>{const L=Vl.cloneNode(!0),z=L.firstChild,re=z.firstChild,ae=re.nextSibling;return i(re,()=>N.name),i(ae,()=>T()?"Custom style saved":"Automatic"),i(L,a(Kt,{get disabled(){return!be()},get aria_label(){return be()?"":bl},data_microtip_position:"top",data_microtip_size:"medium",class:"inline-flex",get children(){const Te=Al.cloneNode(!0);return Te.$$click=()=>_(N.id),i(Te,()=>T()?"Change style":"Choose style"),M(()=>Te.disabled=!be()),Te}}),null),L})()}})),f}})]}}),null),i($,a(ln,{title:"Background sound",get summary(){return es(s())},get open(){return o()==="background-sound"},onToggle:()=>p("background-sound"),get children(){return a(To,{get templateId(){return e.instance.id},get sourceId(){return e.instance.video_id},get savedPreset(){return s()},get open(){return o()==="background-sound"},onSaved:c})}}),null),i($,a(ln,{title:"Lip sync",get summary(){return et()?"On":"Off"},get open(){return o()==="lip-sync"},onToggle:()=>p("lip-sync"),get children(){return[(()=>{const f=xl.cloneNode(!0),N=f.firstChild;return N.nextSibling,N.addEventListener("change",async T=>{const L=T.currentTarget.checked,z=L?{nextTimes:Ye(),nextConfig:F()}:$e(Ye(),F());L||(Vt(z.nextTimes),R(z.nextConfig)),hn(L),ye(L,L?Ye():z.nextTimes,L?F():z.nextConfig),await xe(L,z.nextTimes,z.nextConfig,!1)||(hn(!L),ye(!L,Ye(),F()))}),i(f,a(Yn,{tip:"When enabled, mouth movement is matched to generated speech. When disabled, variable audio is placed in timing windows below."}),null),M(()=>N.checked=et()),f})(),(()=>{const f=$l.cloneNode(!0),N=f.firstChild,T=N.nextSibling,L=T.firstChild,z=L.nextSibling,re=z.firstChild,ae=z.nextSibling,Te=ae.firstChild,Oe=Te.firstChild;return re.addEventListener("change",Re=>{Re.currentTarget.checked&&ve("keep_original")}),Oe.addEventListener("change",Re=>{Re.currentTarget.checked&&ve("full_script")}),i(ae,a(E,{get when(){return B(()=>!!et())()&&y()==="full_script"},get children(){const Re=wl.cloneNode(!0),D=Re.firstChild;D.firstChild;const Ve=D.nextSibling;return i(D,a(Yn,{tip:"480p uses 1x credits. 720p uses 2x credits."}),null),Ve.addEventListener("change",le=>Se(le.currentTarget.value)),M(()=>Ve.value=w()),Re}}),null),M(()=>re.checked=y()==="keep_original"),M(()=>Oe.checked=y()==="full_script"),f})()]}}),null),i($,a(ln,{title:"Audio timing",get summary(){return Q().some(Z)?"Adjusted":"Automatic"},get open(){return o()==="audio-timing"},onToggle:()=>p("audio-timing"),get children(){return[(()=>{const f=yl.cloneNode(!0);return f.firstChild,i(f,a(Yn,{class:"mt-0.5",tip:"Drag the start and end handles, then listen to the audio-only preview. Timing works with or without lip sync."}),null),f})(),a(E,{get when(){return G()},get children(){return Sl.cloneNode(!0)}}),a(E,{get when(){return Q().length>0},get fallback(){return Il.cloneNode(!0)},get children(){const f=hr.cloneNode(!0);return i(f,a(rt,{get each(){return Q()},children:N=>(()=>{const T=Ll.cloneNode(!0),L=T.firstChild,z=L.firstChild,re=z.nextSibling,ae=L.nextSibling,Te=ae.nextSibling;return i(z,N),i(re,()=>Z(N)?"Adjusted":"Automatic"),ae.$$click=()=>we(N),Te.$$click=()=>K(N),te(Te,"aria-label",`Delete ${N} variable`),i(Te,a(ra,{class:"h-4 w-4"})),T})()})),f}}),(()=>{const f=Cl.cloneNode(!0),N=f.firstChild,T=N.nextSibling,L=T.firstChild,z=L.nextSibling,re=z.nextSibling;return z.$$input=ae=>h(ae.currentTarget.value),re.$$click=J,M(()=>z.value=m()),f})()]}}),null),i($,a(ln,{title:"Voice profile",get summary(){return n?.training_url?"Uploaded audio":"From video"},get open(){return o()==="voice-profile"},onToggle:()=>p("voice-profile"),get children(){return[" ",(()=>{const f=Tl.cloneNode(!0),N=f.firstChild,T=N.nextSibling;return T.$$click=()=>{t(!0)},i(T,a(E,{get when(){return n?.training_url},get fallback(){return"Upload"},get children(){const L=kl.cloneNode(!0);return L.firstChild,i(L,a(jr,{}),null),L}})),f})()]}}),null),i($,a(Oo,{get open(){return!!d()},onClose:()=>b(null),instance:n,get variableName(){return d()},get initialWindow(){return ce()},get automaticWindow(){return W()},get personalizedAudioSrc(){return A()?.url||A()?.share_url},get previewValue(){return ne()},onSave:async f=>{const N=(d()??"").trim();if(!N)return!1;const T=await q(N,f);return T&&b(null),T}}),null),i($,a(ml,{get open(){return!!l()},onClose:()=>_(null),instance:n,get segment(){return j()},onSaved:ge}),null),$})()};je(["input","click"]);const wi=()=>new Error("Template-backed transcript editing was removed. Open Video E
5ditor and upload an independent source file.");async function Jn(e){}async function Pl(e){throw wi()}async function Rl(e){throw wi()}async function Fl(e){throw wi()}const Dl=u('<div data-campaign-guide="campaign-modal" class="flex flex-col justify-center items-center gap-2.5 p-8 rounded-[8px] bg-white"><div class="flex flex-col justify-start items-start gap-5"><div class="flex flex-col gap-1"><p class="leading-10 text-3xl font-semibold text-[#323232]">New Campaign</p><p class="leading-6 text-[17px] text-[#1f1f1f]/80">Let’s name your campaign</p></div><input class="leading-5 text-[15px] w-full h-[46px] outline-none pl-4 pr-2 py-2 rounded-[8px] bg-white border border-[#e4e4e4]" placeholder="Campaign name"><div class="flex max-w-[284px] w-full h-[46px] gap-3 pl-4 pr-2 py-2 rounded-[8px] bg-white border border-[#e4e4e4]"><select id="Select use case" class="w-full leading-5 text-[15px] text-left outline-none"><option value="0" disabled selected>Select webhook</option></select></div></div></div>'),Wl=u("<option></option>"),[qt,Tn]=C({name:"",webhook:""}),jl=()=>{const[e,t]=C(!1),[n,r]=C([]),s=Rr();return zt(async()=>{const c=Jt();c?.campaignGuide?.stage==="campaign"&&!qt().name&&Tn(o=>({...o,name:c.goal.slice(0,90)}));try{const o=await aa();o.result.push({name:"Zapier",webhook:"https://zapier"+(Cs==="dev"?".dev":"")+".bhuman.ai/api/zapier/new_video_callback"}),console.log(o.result),r(o.result)}catch(o){console.log(o)}}),Lt(()=>{Tn({name:"",industry:0,useCase:""})}),(()=>{const c=Dl.cloneNode(!0),o=c.firstChild,g=o.firstChild,p=g.nextSibling,m=p.nextSibling,h=m.firstChild;return h.firstChild,p.$$input=d=>{Tn(b=>({...b,name:d.target.value||b.name}))},h.addEventListener("change",d=>{Tn(b=>({...b,webhook:d.currentTarget.value}))}),i(h,a(rt,{get each(){return n()},children:d=>(()=>{const b=Wl.cloneNode(!0);return i(b,()=>d.name),M(()=>b.value=d.webhook),b})()}),null),i(o,a(ba,{text:"Create Campaign",get disabled(){return!qt().name},onClick:async()=>{if(!e()){if(!x?.use_case&&!x?.industry)try{await it.update({id:x.id,use_case:x.use_case,industry:x.industry})}catch(d){console.log(d)}t(!0);try{const d={campaign_name:qt().name||"",video_instance_id:x.id,...qt().webhook&&{webhook:qt().webhook}},b=await ks.create(d),l=String(b?.result?.id||"").trim();if(!l)throw new Error("Campaign creation returned no campaign id");const _=Jt();_?.status==="active"&&_.campaignGuide&&ut("onboarding_campaign_created",{video_instance_id:String(x.id),campaign_id:l}),oa(ht?.userInfo?.email)&&(la(String(x.id),l),Ts({eventType:"campaign_guide_completed",label:Jt()?.goal,metadata:{instance_id:String(x.id),campaign_id:l}})),Ht(!1),s(`../.././campaign/${l}`)}catch(d){console.error(d),Y.error("We couldn’t create the campaign. Your setup is saved — try again.")}finally{t(!1)}}},fallbackText:"Creating Campaign",get loading(){return e()}}),null),M(()=>p.value=qt().name||""),c})()};je(["input"]);const Gl=u('<div data-campaign-guide="campaign-modal"></div>'),_r=e=>a(Mt,{get open(){return e.open},get onClose(){return e.onClose},closeButton:!0,get children(){const t=Gl.cloneNode(!0);return i(t,a(jl,{})),t}}),zl="https://tmp-prod-0524.s3.us-east-2.amazonaws.com/mini-mode-bg/mini-mode-background.png",Bl=(e,t,n)=>{const r=e?.trim()??"";if(!r)throw new Error(`Missing ${t||"background"} asset at position ${n+1}. Choose a valid background and try again.`);try{const s=new URL(r);if(s.protocol!=="http:"&&s.protocol!=="https:")throw new Error("unsupported protocol")}catch{throw new Error(`Invalid ${t||"background"} asset at position ${n+1}. Use a complete http or https URL.`)}return r},xr=e=>{const[t,n="0"]=e.split(";");return t.split(":").reverse().reduce((r,s,c)=>r+ +s*60**c,0)+ +n/1e3},$i=(e="")=>{const t=e.trim();return!t||t.startsWith("http://")||t.startsWith("https://")?t:`https://${t}`},Ul=(e,t)=>{const n=e.trim();return n.startsWith("s3://")?`https://s3.${t}.amazonaws.com/${n.slice(5)}`:n},rs=(e,t="")=>{if(!e||e==="generic")return"";const n={link:"Add an image or video link, or upload a file.",site:"Enter the public website URL.",linkedin:"Enter the LinkedIn URL."},r=$i(t);if(!r)return n[e];try{const s=new URL(r);if(s.protocol!=="http:"&&s.protocol!=="https:")return"Enter a valid web address.";if(e==="linkedin"&&!/(^|\.)linkedin\.com$/i.test(s.hostname))return"Enter a linkedin.com URL."}catch{return"Enter a valid web address."}return""},ss=e=>{const t=as(e);for(const n of t.values()){const r=rs(n.bgType,n.backgroundValue);if(r)return r}return""},as=e=>new Map(Array.from(e).flatMap(([t,n])=>{const r=n.segment.start_time!==void 0&&n.segment.end_time!==void 0,s=n.bgType;return!r||!s?[]:[[t,{...n,bgType:s,backgroundValue:$i(n.backgroundValue)}]]})),Ol=e=>{const t=Array.from(as(e).values());if(!t.length)return;const n=t.map((r,s)=>Bl(r.bgType==="generic"?zl:$i(r.backgroundValue),r.bgType,s));return{canvas_aspect_ratio:"16:9",backgrounds:t.map(r=>({start:xr(r.segment.start_time)-1,end:r.segment.end_time==="-1"?3600:xr(r.segment.end_time)+1,config:{mode:"basic",orientation:"landscape",scale:.4,brightness:-.5,position:"bottom-right",positionX:1,positionY:1,sourceZoom:1,sourceX:0,sourceY:0,websiteBehavior:"still",presenterMoves:[],audio:!1}
5,kind:r.bgType==="site"||r.bgType==="linkedin"?r.bgType:"link",name:`${r.segment.name}-background`})),assets:[n]}},ql=u('<label class="flex flex-col gap-1.5"><span class="text-[12px] font-semibold text-[#494C52]"></span><input type="url" inputmode="url" class="h-[40px] w-full rounded-[8px] border border-[#D8DADC] bg-white px-3 text-[14px] text-[#1C1D1F] outline-none transition-colors focus:border-[#3A57D6]"><span class="text-[11px] leading-4"></span></label>'),Hl=u('<div class="flex flex-col gap-2 rounded-[8px] border border-[#E8E8E6] bg-white p-3"><div class="grid grid-cols-2 gap-1 rounded-[8px] bg-[#F3F3F1] p-1" role="group" aria-label="Image or video source"><button type="button" class="rounded-[6px] px-3 py-2 text-[12px] font-semibold transition-colors">Paste link</button><button type="button" class="rounded-[6px] px-3 py-2 text-[12px] font-semibold transition-colors">Upload file</button></div></div>'),Yl=u('<div class="flex w-full flex-col gap-2"><select class="h-[40px] w-full rounded-[8px] border border-[#D8DADC] bg-white px-3 text-[14px] text-[#1C1D1F] outline-none transition-colors focus:border-[#3A57D6]" aria-label="Background type"><option value="">No background</option><option value="generic">Generic Desktop</option><option value="link">Image or video</option><option value="site">Public website</option><option value="linkedin">LinkedIn profile</option></select></div>'),Jl=u('<div class="flex items-center justify-between gap-3 rounded-[8px] border border-[#D8DADC] px-3 py-2"><span class="min-w-0 truncate text-[12px] text-[#494C52]">File uploaded</span><button type="button" class="shrink-0 text-[12px] font-semibold text-[#3A57D6]">Change</button></div>'),Ql=e=>{const[t,n]=C("link"),r=B(()=>rs(e.backgroundType,e.backgroundValue)),s=o=>{n(o),e.onChange("link","")},c=(o,g,p)=>(()=>{const m=ql.cloneNode(!0),h=m.firstChild,d=h.nextSibling,b=d.nextSibling;return i(h,o),d.$$input=l=>e.onChange(e.backgroundType,l.currentTarget.value),te(d,"placeholder",g),i(b,()=>r()||p),M(l=>{const _=!!r(),y=!r();return _!==l._v$&&b.classList.toggle("text-[#C4584E]",l._v$=_),y!==l._v$2&&b.classList.toggle("text-[#686B70]",l._v$2=y),l},{_v$:void 0,_v$2:void 0}),M(()=>d.value=e.backgroundValue??""),m})();return(()=>{const o=Yl.cloneNode(!0),g=o.firstChild;return g.addEventListener("change",p=>e.onChange(p.currentTarget.value,"")),i(o,a(E,{get when(){return e.backgroundType==="site"},get children(){return c("Website URL","https://example.com","We’ll capture this public page for the background.")}}),null),i(o,a(E,{get when(){return e.backgroundType==="linkedin"},get children(){return c("LinkedIn URL","https://www.linkedin.com/in/name","Paste the public LinkedIn profile URL.")}}),null),i(o,a(E,{get when(){return e.backgroundType==="link"},get children(){const p=Hl.cloneNode(!0),m=p.firstChild,h=m.firstChild,d=h.nextSibling;return h.$$click=()=>s("link"),d.$$click=()=>s("upload"),i(p,a(E,{get when(){return t()==="link"},get fallback(){return a(E,{get when(){return e.backgroundValue},get fallback(){return a(mi,{type:"imageOrVideo",title:"Upload an image or video",helperText:"PNG, JPG, WebP, MP4, MOV, or WebM.",className:"!min-h-[180px] [&_label]:!p-4 [&_img]:!h-10 [&_img]:!w-10 [&_span]:!mt-2",uploadDiagnosticContext:{surface:"ai-studio-sample-background"},onUploadComplete:async b=>{const l=await Fr(b);if(l.code!==200&&l.code!==201||!l.result?.url)throw new Error("Could not load the uploaded background.");e.onChange("link",Ul(l.result.url,"us-east-2"))}})},get children(){const b=Jl.cloneNode(!0),l=b.firstChild,_=l.nextSibling;return _.$$click=()=>e.onChange("link",""),b}})},get children(){return c("Direct image or video link","https://example.com/background.mp4","The link must open the image or video file directly.")}}),null),M(b=>{const l={"bg-white text-[#1C1D1F]":t()==="link","text-[#686B70]":t()!=="link"},_=t()==="link",y={"bg-white text-[#1C1D1F]":t()==="upload","text-[#686B70]":t()!=="upload"},S=t()==="upload";return b._v$3=lt(h,l,b._v$3),_!==b._v$4&&te(h,"aria-pressed",b._v$4=_),b._v$5=lt(d,y,b._v$5),S!==b._v$6&&te(d,"aria-pressed",b._v$6=S),b},{_v$3:void 0,_v$4:void 0,_v$5:void 0,_v$6:void 0}),p}}),null),M(()=>g.value=e.backgroundType),o})()};je(["input","click"]);const Kl=["One personalized phrase is longer than 10 seconds. Choose Smoothest result for this template.","Keep original video supp
5orts up to 100 personalized sections per video. Choose Smoothest result for this template."];function Zl(e){if(!(e instanceof En)||![400,422].includes(e.status))return;const t=e.result,n=[t?.error,t?.result?.error,e.message];return Kl.find(r=>n.some(s=>typeof s=="string"&&s.includes(r)))}const Xl=u('<div class="pointer-events-none fixed z-[1100] rounded-[12px] border border-[#60a5fa] shadow-[0_0_0_6px_rgba(59,130,246,0.14),0_0_24px_rgba(59,130,246,0.35)] animate-pulse"></div>'),ed=u('<button type="button" class="mt-3 rounded-[8px] bg-[#187EE7] px-3 py-2 text-[12px] font-semibold text-white transition-colors hover:bg-[#166FD0]"></button>'),td=u('<div class="pointer-events-auto fixed z-[1110] w-[280px] rounded-[12px] border border-[#e5e7eb] bg-white p-4 text-[12px] text-[#111827] shadow-[0_12px_30px_rgba(15,23,42,0.15)] sm:w-[320px]"><div class="flex items-start justify-between gap-3"><div class="min-w-0 flex-1"><div class="flex items-center justify-between gap-3 text-[11px] font-medium uppercase tracking-[0.08em] text-[#2563eb]"><span>Tutorial</span><span>/</span></div><div class="mt-2 h-1.5 overflow-hidden rounded-full bg-[#dbeafe]"><div class="h-full rounded-full bg-[#2563eb] transition-all duration-300"></div></div></div><button type="button" class="inline-flex h-6 w-6 shrink-0 items-center justify-center rounded-full text-[16px] leading-none text-[#6b7280] transition-colors hover:bg-[#f3f4f6] hover:text-[#111827]" aria-label="Dismiss tip">×</button></div><div class="mt-3"><p class="text-[13px] font-semibold text-[#1d4ed8]"></p><div class="mt-1 text-[12px] text-[#4b5563]"></div></div></div>'),nd=u('<div class="w-full flex flex-col gap-3"></div>'),id=u('<div class="flex items-center gap-2 px-2"><input type="checkbox" id="enable-subtitles-sample" class="h-4 w-4 text-purple-600 cursor-pointer accent-purple-600"><label for="enable-subtitles-sample" class="text-sm font-medium text-gray-700 cursor-pointer flex items-center gap-1">Enable subtitles for this video<span class="bg-purple-600 text-white text-xs px-1 py-0.5 rounded">NEW</span></label></div>'),rd=u('<p class="text-center text-[12px] leading-5 text-[#C4584E]"></p>'),sd=u('<p role="alert" class="w-full text-center text-[12px] leading-5 text-[#C4584E]">Your account first name is missing. Add it in Settings, then try again.</p>'),ad=u('<p role="alert" class="w-full text-center text-[12px] leading-5 text-[#C4584E]"></p>'),od=u('<div class="flex flex-col justify-start items-start overflow-hidden gap-2.5 rounded bg-[#fafafe] p-4"><div class="flex flex-col w-full gap-4"><div class="flex w-full flex-col items-center justify-center gap-2"></div></div></div>'),ld=u('<div class="w-[300px] h-[120px] flex justify-center items-center"></div>'),dd=u('<div class="w-full p-2 text-sm text-gray-600">No transcript variables detected. Add timing in Advanced and fill values below.</div>'),cd=u("<div></div>"),wr=u('<p class="text-[12px] leading-5 text-[#686b70]">Using your account first name for this practice sample.</p>'),ud=u('<div class="flex justify-start items-start gap-2.5 p-4 rounded bg-[#fafafe]"><div class="flex flex-col gap-2.5"><p class="text-[15px] font-semibold text-[#1d1d1f]"></p><input type="text" class="h-[40px] rounded-[8px] border border-[#d9d9d9] px-4 text-[15px] text-[#1d1d1f]"></div></div>'),gd=u('<div class="flex justify-start items-start gap-2.5 p-4 rounded bg-[#fafafe]"><div class="flex flex-col gap-2.5 w-full"><p class="text-[15px] font-semibold text-[#1d1d1f]"></p><input type="text" class="h-[40px] rounded-[8px] border border-[#d9d9d9] px-4 text-[15px] text-[#1d1d1f]"></div></div>'),pd=u('<div class="w-full flex justify-center"></div>'),md=u('<span class="font-semibold text-[#1d4ed8]">Generate</span>'),fd=u('<span class="font-semibold text-[#1d4ed8]">Sample &amp; Other Generated Videos</span>'),hd=u('<span class="font-semibold text-[#1d4ed8]">Watch</span>'),bd=u('<div class="flex flex-col gap-6"></div>'),vd=u('<button type="button" class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded disabled:cursor-not-allowed disabled:opacity-50 disabled:hover:bg-blue-500"></button>'),_d=e=>[(()=>{const t=Xl.cloneNode(!0);return M(n=>{const r=`${e.rect.top-6}px`,s=`${e.rect.left-6}px`,c=`${e.rect.width+12}px`,o=`${e.rect.height+12}px`;return r!==n._v$&&t.style.setProperty("top",n._v$=r),s!==n._v$2&&t.style.setProperty("left",n._v$2=s),c!==n._v$3&&t.style.setProperty("width",n._v$3=c),o!==n._v$4&&t.style.setProperty("height",n._v$4=o),n},{_v$:void 0,_v$2:void 0,_v$3:void 0,_v$4:void 0}),t})(),(()=>{const t=td.cloneNode(!0),n=t.firstChild,r=n.firstChild,s=r.firstChild,c=s.firstChild,o=c.nextSibling,g=o.firstChild,p=s.nextSibling,m=p.firstChild,h=r.nextSibling,d=n.nextSibling,b=d.firstChild,l=b.nextSibling,_=e.bubbleRef;return typeof _=="function"?Je(_,t):e.bubbleRef=t,i(o,()=>Kn.trySample,g),i(o,Zn,null),kt(h,"click",e.onDismiss,!0),i(b,()=>e.title),i(l,()=>e.body),i(d,a(E,{get when(){return e.actionLabel&&e.onAction},get children(){const y=ed.cloneNode(!0);return kt(y,"click",e.onAction,!0),i(y,()=>e.actionLabel),y}}),null),M(y=>{const S=`${e.top}px`,w=`${e.left}px`,I=`${Kn.trySample/Zn*100}%`;return S!==y._v$5&&t.style.setProperty("top",y._v$5=S),w!==y._v$6&&t.style.setProperty("left",y._v$6=w),I!==y._v$7&&m.style.setProperty("width",y._v$7=I),y},{_v$5:void 0,_v$6:void 0,_v$7:void 0}),t})()],xd=e=>{const[t,n]=C([]),[r,s]=C(!1),[c,o]=C(null),[g,p]=C(null),[m,h]=C(null),[d,b]=C(new Map);let l,_,y;const S=()=>[ht?.userInfo?.first_name,ht?.userInfo?.last_name].map(j=>
5String(j||"").trim()).filter(Boolean).join(" "),w=(j,ce,W,Q="")=>{const A=new Map(d());A.set(j.id,{segment:j,bgType:ce,backgroundValue:Q,segmentValue:W}),b(A)};zt(async()=>{const j=await Bt.list({video_instance_id:x?.id});n(Br(j.result.filter(ce=>ce.kind===-1&&(!Le(x)||ce.name==="name")))),s(!0)});const I=B(()=>{if(Le(x))return[];if(et())return[];const j=new Set(t().map(ce=>ce.name));return Object.keys(Ye()||{}).filter(ce=>!!ce?.trim()&&!j.has(ce))});Ae(()=>{if(!e.showWelcomeTutorial&&!Le(x))return;const j=ht?.userInfo?.first_name,ce=[...t(),...I().map(W=>({id:`manual:${W}`,name:W,kind:-1}))];b(W=>{const Q=new Map(W);return ce.forEach(A=>{const G=jn(A.name,j,S());if(G===null)return;const ne=W.get(A.id);Q.set(A.id,{...ne,segment:A,bgType:ne?.bgType||"",segmentValue:G})}),Q})});const F=B(()=>[...t().map(j=>j.id),...I().map(j=>`manual:${j}`)]),R=B(()=>F().length>0&&F().every(j=>!!d().get(j)?.segmentValue?.trim())),ee=B(()=>(e.showWelcomeTutorial||Le(x))&&r()&&F().length>0&&!String(ht?.userInfo?.first_name||"").trim()),fe=B(()=>ss(d())),H=B(()=>e.showWelcomeTutorial?e.loading?"generating":R()?"generate":"input":null),be=()=>{const j=H(),ce=j==="input"?l:_??l;if(!e.showWelcomeTutorial||!j||!ce){o(null),p(null);return}const W=ce.getBoundingClientRect(),Q=l?.getBoundingClientRect(),A=y?.offsetWidth||320,G=y?.offsetHeight||148,ne=12,Z=20,ge=Se=>Math.min(Math.max(ne,Se),window.innerHeight-G-ne),$e=!!Q&&Q.right+Z+A<=window.innerWidth-ne,ye=!!Q&&Q.left-Z-A>=ne;if($e||ye){const Se=$e?Q.right+Z:Q.left-A-Z,we=ge(W.top+W.height/2-G/2);o(W),p({top:we,left:Se});return}const xe=Math.min(Math.max(ne,W.left+W.width/2-A/2),window.innerWidth-A-ne),ve=W.top-G-Z>=ne?W.top-G-Z:ge(W.bottom+Z);o(W),p({top:ve,left:xe})};return Ae(()=>{H(),d(),e.loading,t().length,I().length,window.setTimeout(be,0)}),zt(()=>{const j=()=>be();window.addEventListener("resize",j),window.addEventListener("scroll",j,!0),Lt(()=>{window.removeEventListener("resize",j),window.removeEventListener("scroll",j,!0)})}),(()=>{const j=od.cloneNode(!0),ce=j.firstChild,W=ce.firstChild,Q=l;return typeof Q=="function"?Je(Q,j):l=j,i(j,a(rt,{get each(){return t()},get fallback(){return a(E,{get when(){return!r()},get fallback(){return dd.cloneNode(!0)},get children(){const A=ld.cloneNode(!0);return i(A,a(Vi,{})),A}})},children:(A,G)=>{const[ne,Z]=C(""),[ge,$e]=C(""),[ye,xe]=C(""),ve=()=>d().get(A.id)?.segmentValue??ye(),Se=()=>d().get(A.id)?.backgroundValue??ge(),we=()=>(e.showWelcomeTutorial||Le(x))&&jn(A.name,ht?.userInfo?.first_name,S())!==null;return(()=>{const q=cd.cloneNode(!0);return i(q,(()=>{const J=B(()=>A.kind===-1);return()=>J()&&(()=>{const K=ud.cloneNode(!0),$=K.firstChild,f=$.firstChild,N=f.nextSibling;return i(f,()=>A.name),N.$$input=T=>{we()||(xe(T.currentTarget.value),w(A,ne(),T.currentTarget.value,Se()))},i($,a(E,{get when(){return we()},get children(){return wr.cloneNode(!0)}}),null),i($,a(E,{get when(){return B(()=>!e.showWelcomeTutorial)()&&!Le(x)},get children(){return a(Ql,{get backgroundType(){return ne()},get backgroundValue(){return Se()},onChange:(T,L)=>{Z(T),$e(L),w(A,T,ve(),L)}})}}),null),M(T=>{const L=we(),z=we(),re={"cursor-default bg-[#f3f3f1] text-[#686b70]":we(),"border-[#60a5fa] shadow-[0_0_0_4px_rgba(96,165,250,0.18),0_0_18px_rgba(59,130,246,0.2)]":e.showWelcomeTutorial&&H()==="input"&&G()===0},ae=e.showWelcomeTutorial?"Your account first name":"Enter value";return L!==T._v$8&&(N.readOnly=T._v$8=L),z!==T._v$9&&te(N,"aria-readonly",T._v$9=z),T._v$0=lt(N,re,T._v$0),ae!==T._v$1&&te(N,"placeholder",T._v$1=ae),T},{_v$8:void 0,_v$9:void 0,_v$0:void 0,_v$1:void 0}),M(()=>N.value=ve()),K})()})()),q})()}}),ce),i(j,a(E,{get when(){return I().length>0},get children(){const A=nd.cloneNode(!0);return i(A,a(rt,{get each(){return I()},children:(G,ne)=>{const Z=()=>(e.showWelcomeTutorial||Le(x))&&jn(G,ht?.userInfo?.first_name,S())!==null;return(()=>{const ge=gd.cloneNode(!0),$e=ge.firstChild,ye=$e.firstChild,xe=ye.nextSibling;return i(ye,G),xe.$$input=ve=>{if(Z())return;const Se=new Map(d()),we=`manual:${G}`;Se.set(we,{segment:{id:we,name:G,kind:-1},bgType:"",segmentValue:ve.currentTarget.value}),b(Se)},i($e,a(E,{get when(){return Z()},get children(){return wr.cloneNode(!0)}}),null),M(ve=>{const Se=Z(),we=Z(),q={"cursor-default bg-[#f3f3f1] text-[#686b70]":Z(),"border-[#60a5fa] shadow-[0_0_0_4px_rgba(96,165,250,0.18),0_0_18px_rgba(59,130,246,0.2)]":e.showWelcomeTutorial&&H()==="input"&&ne()===0&&t().length===0},J=e.showWelcomeTutorial?"Your account first name":"Enter value";return Se!==ve._v$10&&(xe.readOnly=ve._v$10=Se),we!==ve._v$11&&te(xe,"aria-readonly",ve._v$11=we),ve._v$12=lt(xe,q,ve._v$12),J!==ve._v$13&&te(xe,"placeholder",ve._v$13=J),ve},{_v$10:void 0,_v$11:void 0,_v$12:void 0,_v$13:void 0}),M(()=>xe.value=d().get(`manual:${G}`)?.segmentValue||""),ge})()}})),A}}),ce),i(ce,a(E,{get when(){return B(()=>!e.showWelcomeTutorial)()&&!Le(x)},get children(){const A=id.cloneNode(!0),G=A.firstChild;return G.addEventListener("change",ne=>e.setEnableSubtitles(ne.target.checked)),M(()=>G.checked=e.enableSubtitles),A}}),W),i(W,a(E,{get when(){return B(()=>!!R())()&&fe()},get children(){const A=rd.cloneNode(!0);return i(A,fe),A}}),null),i(W,a(E,{get when(){return ee()},get children(){return sd.cloneNode(!0)}}),null),i(W,a(E,{get when(){return e.errorMessage},get children(){const A=ad.cloneNode(!0);return i(A,()=>e.errorMessage),A}}),null),i(W,a($d,{buttonRef:A=>{_=A,be()},handleClick:()=>{const A=new Map;
5F().forEach(G=>{const ne=d().get(G);ne&&A.set(G,ne)}),e.handleGenerate(A)},get disabled(){return e.loading||(e.showWelcomeTutorial||Le(x))&&!R()||!!fe()},get children(){return a(E,{get when(){return!e.loading},get fallback(){return(()=>{const A=pd.cloneNode(!0);return i(A,a(Vi,{fill:"white"})),A})()},children:"Generate"})}}),null),i(j,a(E,{get when(){return B(()=>!!(e.showWelcomeTutorial&&H()&&m()!==H()&&c()))()&&!!g()},get children(){return a(_d,{bubbleRef:A=>{y=A,window.requestAnimationFrame(be)},get rect(){return c()},get top(){return g()?.top??0},get left(){return g()?.left??0},get title(){return B(()=>H()==="generate")()?"Generate your sample":H()==="generating"?"Generating your sample":"Fill in your sample"},get body(){return B(()=>H()==="generate")()?["Click ",md.cloneNode(!0)," ","to create a sample using your account first name."]:B(()=>H()==="generating")()?["We're generating one preview with your test value. When you land back in the editor, look in"," ",fd.cloneNode(!0)," ","and click ",hd.cloneNode(!0),"."]:"We use your account first name for this practice sample."},onDismiss:()=>h(H())})}}),null),j})()},wd=e=>{const[t,n]=C(!1),[r,s]=C(!1),[c,o]=C(""),g=h=>{o(h),Y.error(h)},p=()=>{bt(bi(We()))},m=h=>{const d=`OS-${typeof crypto<"u"&&"randomUUID"in crypto?crypto.randomUUID().replaceAll("-","").slice(0,8).toUpperCase():Date.now().toString(36).toUpperCase()}`,b=h instanceof En?h.status:void 0,l=h instanceof En?h.apiCode||(h.result&&typeof h.result=="object"&&"code"in h.result?String(h.result.code||""):""):"",_=h instanceof Error?h.message.toLowerCase():"",y=Zl(h),S=b===403?"guided_template_rejected":b===409?"guided_template_conflict":b===503?"service_unavailable":l||"sample_request_failed";return{message:`${y||(_.includes("first name")?"We couldn’t confirm your account first name. Refresh once and try again.":b===409?"Your practice sample is already in progress. Refresh to resume it.":b===503?"Sample generation is temporarily unavailable. Try again in a moment.":"We couldn’t start your sample. Refresh once and try again.")} Reference: ${d}`,metadata:{request_status:b,api_code:l||void 0,failure_reason:S,support_reference:d}}};return(()=>{const h=bd.cloneNode(!0);return i(h,a(xd,{get showWelcomeTutorial(){return e.showWelcomeTutorial},get errorMessage(){return c()},handleGenerate:async d=>{const b=String(x?.id||"").trim();if(o(""),!b){g("Couldn’t identify this template. Please reload and try again.");return}const l=di();if(l.length>0){g(`Reselect ${l.join(", ")} in the transcript before generating.`);return}const _=ss(d);if(_){g(_);return}const y=Ol(d),S=Array.from(d.values()).map(I=>I.segment.name),w=Array.from(d.values()).map(I=>I.segmentValue);if(!S.length){g("This template has no sample variable yet. Add one and try again.");return}if(w.some(I=>!I?.trim())){g(e.showWelcomeTutorial?"Your account first name is missing. Add it in Settings, then try again.":"Please fill all variable values.");return}e.showWelcomeTutorial&&ut("onboarding_sample_generate_clicked",{video_instance_id:b}),n(!0),bt(!0);try{const F=et();let R={},ee,fe,H,be,j;const ce=S.length>0?S:Object.keys(Ye()||{}),W=Array.from(d.values()).map(({segment:$e})=>$e),Q=pi({variableNames:ce,segments:W,manualStartTimes:Ye(),config:x?.variable_timing_config,requireNamedSegments:va(d.keys())});R=Q.variable_start_times,ee=Q.audio_start_seconds,fe=Q.audio_window_end_seconds,H=Q.audio_window_anchor,be=Q.audio_window_fit,j=Q.variable_timing_config;const A=vn(x),G=_n(x),ne=Dr(A,G);x?.id&&!e.showWelcomeTutorial&&!Le(x)&&await it.update({id:b,enable_lipsync:F,variable_start_times:R,variable_timing_config:mn(fn(j,A),G)});const Z=await Wr({variables:S,names:[w],video_instance_id:b,backgrounds:y?.backgrounds,assets:y?.assets,canvas_aspect_ratio:y?.canvas_aspect_ratio,lipsync:F,enable_lipsync:F,enable_subtitles:r(),variable_start_times:Le(x)?void 0:R,audio_start_seconds:Le(x)?void 0:ee,audio_window_end_seconds:Le(x)?void 0:fe,audio_window_anchor:Le(x)?void 0:H,audio_window_fit:Le(x)?void 0:be,generation_mode:A,lipsync_quality:G,render_quality:G,credit_multiplier:ne,onboarding_practice:e.showWelcomeTutorial||Le(x)||void 0,...Le(x)?{}:ci()});
5if(!Z||Z.code!==200){const $e=m(new En("Sample request failed",Number(Z?.code||500),Number(Z?.code||500),Z));g($e.message),e.showWelcomeTutorial&&ut("onboarding_sample_generation_failed",{video_instance_id:b,stage:"request",...$e.metadata}),p();return}e.showWelcomeTutorial&&ut("onboarding_sample_generation_started",{video_instance_id:b});const ge=Jr(Z.result);qr(ge,w,b),vi(ge,b),pn(!1)}catch(I){console.error(I);const F=m(I);g(F.message),e.showWelcomeTutorial&&ut("onboarding_sample_generation_failed",{video_instance_id:b,stage:"request",...F.metadata}),p()}finally{n(!1)}},get loading(){return t()},get enableSubtitles(){return r()},setEnableSubtitles:s})),h})()},$d=e=>(()=>{const t=vd.cloneNode(!0);kt(t,"click",e.handleClick,!0);const n=e.buttonRef;return typeof n=="function"?Je(n,t):e.buttonRef=t,i(t,()=>e.children),M(()=>t.disabled=e.disabled),t})();je(["click","input"]);const yd=u('<div class="flex flex-col gap-4 p-4"></div>'),$r=e=>a(Mt,{get open(){return e.open},get onClose(){return e.onClose},get children(){const t=yd.cloneNode(!0);return i(t,a(wd,{get videoRef(){return e.videoRef},get showWelcomeTutorial(){return e.showWelcomeTutorial}})),t}}),yr=e=>a(Ns,{get open(){return e.open},get onClose(){return e.onClose},get src(){return e.src},title:"Sample generated video"}),Sd=u('<section class="rounded-[8px] flex flex-col items-center justify-start gap-8 py-8 px-6 max-h-[800px] max-w-max overflow-auto"><div class="flex flex-col items-center w-full gap-2"><div class="flex justify-start items-center relative gap-2"><p class="text-3xl font-semibold text-center text-[#1d1d1f]"></p></div><p class="text-[17px] text-center text-[#656565]"></p></div></section>'),Cd=u('<div class="flex flex-col items-center w-full p-2 gap-10 rounded-[8px] h-full"><div class="grid grid-cols-3 gap-8 h-full w-full align-middle"></div><div class="flex justify-center items-center w-[191px] gap-2.5 px-4 py-3 rounded-[8px] bg-[#1d1d1f] cursor-pointer"><p class="text-[15px] font-semibold text-center text-white"></p></div></div>'),kd=u("<div></div>"),Td=u('<div class="w-[800px] h-screen flex items-center justify-center"></div>'),Nd=u('<div class="flex flex-col"><div class="bg-[#D9D9D9] flex flex-col items-center rounded-t-lg shadow-custom cursor-pointer"><span class="font-semibold">Model </span><span class="text-[13px]">click to select</span></div></div>'),Ed=u("<span></span>"),[Sr,Ad]=C([]),Vd=e=>(zt(async()=>{try{_i(String(x?.id||"")),await Qr(x?.id)}catch(t){console.error(t)}}),(()=>{const t=Sd.cloneNode(!0),n=t.firstChild,r=n.firstChild,s=r.firstChild,c=r.nextSibling;return i(s,()=>We().length?e.title:x?.video_percent_of_face!=null?"Fetching Samples":"Detecting face..."),i(c,a(E,{get when(){return x?.video_percent_of_face!=null},get children(){return e.description}})),i(t,a(Id,{get handleNext(){return e.handleNext},get buttonText(){return e.buttonText},get skipButtonText(){return e.skipButtonText},get loading(){return e.loading}}),null),t})()),Id=e=>{const[t,n]=C(null),[r,s]=C(),[c,o]=C(!1),g=async(p,m)=>{try{await Bs({variables:Sr().filter(h=>h.kind===-1).map(h=>h.name)??["name"],names:[Sr().filter(h=>h.kind===-1).map(()=>"Megan")],video_instance_id:x?.id,filter_complex:p,assets:m,...ci()}),await it.update({id:x?.id,videos_preview_flag:!0}),ca(!0)}catch{Y.error("Failed to generate video previews")}};return Ae(bn(()=>x?.video_percent_of_face,async()=>{try{if(!x?.video_percent_of_face)return;if(x?.id){const h=await Bt.list({video_instance_id:x?.id});Ad(h.result.filter(d=>d.kind===-1))}const p=localStorage.getItem("VideoInstance.serializedSignals");if(p&&JSON.parse(p)?.videoConfig===!0||x?.videos_preview_flag)return;const m=parseInt(x?.video_percent_of_face);if(m<=10){g();return}if(m>10){o(!0);return}}catch(p){console.log(p.message)}})),(()=>{const p=kd.cloneNode(!0);return i(p,a(E,{get when(){return We().length||c()},get fallback(){return(()=>{const m=Td.cloneNode(!0);return i(m,a(Es,{})),m})()},get children(){const m=Cd.cloneNode(!0),h=m.firstChild,d=h.nextSibling,b=d.firstChild;return i(h,a(rt,{get each(){return We().filter(l=>l.color_mode!==null).sort((l,_)=>l.color_mode-_.color_mode)},children:(l,_)=>(()=>{const y=Nd.cloneNode(!0),S=y.firstChild,w=S.firstChild;return w.firstChild,S.$$click=()=>{l?.status==="processing"||l?.status==="queued"||l?.status==="pending"||(n(l?.color_mode),s(_()+1))},i(w,()=>_()+1,null),i(y,a(ei,{get status(){return l?.status},get vimeoLink(){return l?.share_url},get s3Link(){return l?.url},get videoName(){return l?.text},get thumbnail(){return l?.thumbnail},get gifLink(){return l?.gif},get estimateTime(){return l?.estimate_time},get estimateUpdatedAt(){return l?.updated_at},get progress(){return l?.processing},get startedAt(){return l?.created_at},isVideoConfigPreview:!0}),null),M(I=>lt(S,{"cursor-not-allowed":l?.status==="processing"||l?.status==="queued"||l?.status==="pending","!bg-main-blue text-white":r()===_()+1},I)),y})()})),d.$$click=()=>{e.loading||e.handleNext(t())},i(b,a(E,{get when(){return t()!==null},get fallback(){return(()=>{const l=Ed.cloneNode(!0);return i(l,()=>e.skipButtonText??"Skip model selection"),l})()},get children(){return[B(()=>e.buttonText??"Save Model")," ",B(()=>r()),a(E,{get when(){return e?.loading},get children(){return a(As,{})}})]}})),m}}),null),i(p,a(Mt,{get open(){return ii()},onClose:()=>ri(!1),class:"w-auto",get children(){return a(Vs,{get src(){return xt()},text:""})}}),null),p})()};je(["click"]);const Cr=e=>a(Mt,{get open(){return e.open},class:"w-auto",get children(){return a(Vd,{handleNext:async t=>{try{let n;t?(n=await it.update({id:e.instance.id,color_mode:t}),Y.success("Model updated successfully on instance.")):n=await it.update({id:e.instance.id,color_mode:9}),e.setInstance(n.result),e.setSelectVideoConfig(!1)}catch(n){Y.error(n.message)}finally{}}
5,title:"Choose video model",skipButtonText:"Keep old model",description:"Select which model looks best, and we’ll save it for this template"})}}),Ld=u(`<section class="flex flex-col items-center justify-center gap-6 p-8"><div class="h-5 justify-center items-center gap-2 inline-flex"><div></div><div>Upload audio</div></div><div class="w-[375px] text-center text-black text-[21px] font-medium font-['Inter'] leading-7">Audio length should be 15-100s to ensure best audio quality</div><div class="border p-2 rounded-[8px]"></div></section>`),Md=e=>{const[t,n]=C(!1);return(()=>{const r=Ld.cloneNode(!0),s=r.firstChild,c=s.firstChild,o=s.nextSibling,g=o.nextSibling;return i(c,a(ua,{})),i(g,a(mi,{onUploadComplete:async p=>{try{const{result:m}=await Fr(p),h=await it.update({id:x.id,training_url:m.url});Is(h.result),e.setTrainingAudioUploader(!1),Y.success("Audio uploaded successfully")}catch(m){console.log(m)}finally{n(!1)}},audioLengthLowerLimit:15,audioLengthUpperLimit:100,mode:2,type:"audio"})),r})()},kr=e=>a(Mt,{get open(){return e.open},get onClose(){return e.onClose},class:"w-auto",get children(){return a(Md,{get setTrainingAudioUploader(){return e.setTrainingAudioUpload}})}}),Pd=u('<div class="w-full flex justify-center items-center gap-2 pointer-events-none"><span>Uploading</span></div>'),Rd=u('<div class="w-full h-auto flex justify-center sm:px-16 py-8"><div class="flex flex-col gap-6 items-center justify-center w-auto h-full"><div class="w-full"><button class="w-full px-6 h-[48px] bg-[#1d1d1f] rounded-[8px] text-white text-[15px] font-semibold leading-5"></button></div></div></div>'),Fd=u('<select class="w-80 h-5 text-[15px] font-normal leading-snug outline-none bg-transparent"></select>'),Dd=u('<textarea class="w-80 h-28 text-[15px] font-normal leading-snug outline-none bg-transparent resize-none overflow-hidden"></textarea>'),Wd=u('<div class=" bg-white border border-gray-300 rounded-md shadow-lg z-10 bottom-10"></div>'),jd=u('<div class="w-auto h-auto justify-center items-start gap-2 inline-flex"><div class="self-stretch flex-col justify-start items-start gap-3 inline-flex"><div class="justify-start items-start gap-0.5 flex"><div class="w-80 h-5 text-[15px] font-normal leading-snug outline-none bg-transparent cursor-pointer">Select Tags</div></div></div></div>'),Gd=u('<div class="w-[372px] h-auto justify-center items-start gap-2 inline-flex"><div class="self-stretch flex-col justify-start items-start gap-3 inline-flex"><div class="flex-col justify-start items-start gap-1 flex"><div class="w-[275px] h-5 text-black text-[15px] font-semibold leading-snug"></div><div class="w-[305px] h-4 text-zinc-500 text-[13px] font-normal leading-tight"></div></div><div class="p-4 bg-white rounded-tr-3xl rounded-bl-3xl rounded-br-3xl shadow border border-neutral-100 justify-center items-center gap-2.5 inline-flex"><div class="justify-start items-start gap-0.5 flex"></div></div></div></div>'),zd=u('<input class="w-80 h-5 text-[15px] font-normal leading-snug outline-none bg-transparent">'),Bd=u("<option></option>"),Ud=u('<div class="flex items-center px-4 py-2"><input type="checkbox" class="form-checkbox h-5 w-5 text-blue-600" name="tags"><span class="ml-2 text-gray-700"></span></div>'),Od=()=>{const[e,t]=C(""),[n,r]=C(""),[s,c]=C(Xn[0].id),[o,g]=C([]),[p,m]=C(!1);return(()=>{const h=Rd.cloneNode(!0),d=h.firstChild,b=d.firstChild,l=b.firstChild;return i(d,a(Nn,{label:"Template Name",subText:" Call it something descriptive, 50 characters max",placeHolder:" Ex: New biz sales outreach",inputSignal:e,onchange:t}),b),i(d,a(Nn,{label:"Description",subText:"Describe your template in a few sentences",placeHolder:"E.g. This is a great way to welcome new leads to your funnel. Bring a positive, happy and upbeat attitude to your customers with a personalized video today from a professional actress.",textArea:!0,inputSignal:n,onchange:r}),b),i(d,a(Nn,{label:"Set industry",subText:"Define the industry",placeHolder:"Ex: Marketing, top of the funnel, whitepaper",dropDown:!0,arrayItems:Xn,dropDownSignal:s,onchange:c}),b),i(d,a(Nn,{label:"Set tags",subText:"Define the tags",placeHolder:"Ex: Marketing, top of the funnel, whitepaper",multiSelectDropDown:!0,arrayItems:Ls,multiSelectDropDownSignal:o,onchange:g}),b),l.$$click=async()=>
5{if(!p()){m(!0),console.log(o());try{const{result:_}=await Bt.list({video_instance_id:x.id});await Ms({description:n(),name:e(),category:s(),tags:o(),actor_id:x?.actor_id,video_id:x?.video_id,segments:_.map(y=>y.id),created_at:"",creator_id:"",downloads:0,id:"",ratings:0,reviews:0,thumbnail:"",video_url:""}),Y.success("Template uploaded successfully")}catch(_){console.log(_),m(!1)}finally{m(!1)}}},i(l,a(E,{get when(){return p()},get fallback(){return"Upload Template"},get children(){const _=Pd.cloneNode(!0);return _.firstChild,i(_,a(Mr,{}),null),_}})),h})()},Nn=e=>{const[t,n]=C(!1),[r,s]=C([]),c=o=>{const g=parseInt(o.target.value),p=o.target.checked;s(p?[...r(),g]:r().filter(m=>m!==g)),e.onchange(r())};return(()=>{const o=Gd.cloneNode(!0),g=o.firstChild,p=g.firstChild,m=p.firstChild,h=m.nextSibling,d=p.nextSibling,b=d.firstChild;return i(m,()=>e.label),i(h,()=>e.subText),i(b,a(Ps,{get fallback(){return(()=>{const l=zd.cloneNode(!0);return l.$$input=_=>e.onchange(_.currentTarget.value),M(()=>te(l,"placeholder",e.placeHolder)),M(()=>l.value=e.dropDown?e.dropDownSignal():e.inputSignal()),l})()},get children(){return[a(Gn,{get when(){return e.dropDown},get children(){const l=Fd.cloneNode(!0);return l.$$input=_=>e.onchange(parseInt(_.currentTarget.value)),i(l,a(rt,{get each(){return e.arrayItems},children:(_,y)=>(()=>{const S=Bd.cloneNode(!0);return i(S,()=>_.name),M(()=>S.value=_.id),S})()})),M(()=>l.value=e.dropDown?e.dropDownSignal():e.inputSignal()),l}}),a(Gn,{get when(){return e.textArea},get children(){const l=Dd.cloneNode(!0);return l.$$input=_=>e.onchange(_.currentTarget.value),M(()=>te(l,"placeholder",e.placeHolder)),M(()=>l.value=e.dropDown?e.dropDownSignal():e.inputSignal()),l}}),a(Gn,{get when(){return e.multiSelectDropDown},get children(){const l=jd.cloneNode(!0),_=l.firstChild,y=_.firstChild,S=y.firstChild;return S.$$click=()=>n(!t()),i(y,a(Mt,{get open(){return t()},onClose:()=>n(!1),get children(){const w=Wd.cloneNode(!0);return i(w,a(rt,{each:Xn,children:I=>(()=>{const F=Ud.cloneNode(!0),R=F.firstChild,ee=R.nextSibling;return R.addEventListener("change",c),i(ee,()=>I.name),M(()=>R.value=I.id),M(()=>R.checked=r().includes(I.id)),F})()})),w}}),null),l}})]}})),o})()};je(["click","input"]);const Tr=e=>a(Mt,{get open(){return e.open},get onClose(){return e.onClose},class:"w-auto",get children(){return a(Od,{})}}),qd=u('<div class="rounded-[12px] border border-[#bfdbfe] bg-[#eff6ff] px-4 py-3 shadow-sm"><div class="flex items-center justify-between gap-3 text-[11px] font-medium uppercase tracking-[0.08em] text-[#2563eb]"><span>Tutorial</span><span>/</span></div><div class="mt-2 h-1.5 overflow-hidden rounded-full bg-[#dbeafe]"><div class="h-full rounded-full bg-[#2563eb] transition-all duration-300"></div></div><p class="mt-3 text-[13px] font-semibold text-[#2563eb]"></p><p class="mt-1 text-[13px] leading-5 text-[#475569]"></p></div>'),Hd=u('<details class="group rounded-[8px] border border-border bg-white p-2"><summary class="flex min-h-[44px] cursor-pointer list-none items-center justify-between gap-3 rounded-[8px] px-2 text-[15px] font-semibold text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary [&amp;::-webkit-details-marker]:hidden">Advanced<svg aria-hidden="true" viewBox="0 0 20 20" fill="none" class="h-4 w-4 group-open:rotate-180"><path d="m5 7 5 5 5-5" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"></path></svg></summary></details>'),Nr=u('<div class="pointer-events-none fixed z-[60] rounded-[10px] border-2 border-primary ring-4 ring-primary/15"></div>'),Er=u('<div class="pointer-events-auto fixed z-[70] w-[280px] rounded-[12px] border border-[#e5e7eb] bg-white p-3 text-[12px] text-[#111827] shadow-[0_12px_30px_rgba(15,23,42,0.15)]"><div class="flex items-start justify-between gap-3"><div class="min-w-0 flex-1"><div class="flex items-center justify-between gap-3 text-[11px] font-medium uppercase tracking-[0.08em] text-[#2563eb]"><span>Tutorial</span><span>/</span></div><div class="mt-2 h-1.5 overflow-hidden rounded-full bg-[#dbeafe]"><div class="h-full rounded-full bg-[#2563eb] transition-all duration-300"></div></div></div><button type="button" class="inline-flex h-6 w-6 shrink-0 items-center justify-center rounded-full text-[16px] leading-none text-[#6b7280] transition-colors hover:bg-[#f3f4f6] hover:text-[#111827]" aria-label="Minimize tutorial instructions">×</button></div><div class="mt-3"><p class="text-[13px] font-semibold text-[#1d4ed8]"></p><p class="mt-1 text-[12px] text-[#4b5563]"></p></div></div>'),Ar=u('<button type="button" class="pointer-events-auto fixed z-[70] inline-flex min-h-[40px] items-center gap-2 rounded-[10px] border border-[#bfdbfe] bg-white px-3 py-2 text-[12px] font-semibold text-[#1d4ed8] shadow-[0_8px_24px_rgba(15,23,42,0.14)] transition-colors hover:bg-[#eff6ff]" aria-label="Show tutorial instructions"><span aria-hidden="true">i</span><span>Tutorial <!>/<!> · Show instructions</span></button>'),Yd=u('<div class="flex h-auto w-full flex-col items-center justify-center gap-20 p-4"><div class="flex w-full flex-col justify-center gap-4 divide-y-1 md:max-w-[1100px]"><div class="flex w-full flex-col items-center justify-between gap-2 rounded-[8px] md:flex-row md:gap-8"></div><div class="flex w-full flex-col items-start justify-between gap-8 md:flex-row"><div class="flex w-full flex-col gap-3 md:min-w-[50%] md:max-w-[60%]"></div><div class="flex shrink-0 flex-col justify-between gap-3 md:min-w-[40%] md:max-w-[40%]"><div class="flex flex-col gap-3"><div></div></div></div></div></div></div>'),Jd=u('<p class="text-[15px] font-semibold">Transcript</p>
5'),Qd=u('<div role="status" aria-live="polite" class="mt-3 flex items-center justify-between gap-3 rounded-[8px] border border-[#D8DFF8] bg-[#F5F7FF] px-3 py-2"><div><p class="text-[13px] font-semibold text-[#243A9A]"></p><p class="mt-0.5 text-[12px] text-[#686B70]">You can leave this page. The updated preview will appear here.</p></div><span class="h-4 w-4 shrink-0 animate-spin rounded-full border-2 border-[#C7D1F7] border-t-[#3A57D6]"></span></div>'),Kd=u('<div class="mb-3 rounded-[10px] border border-[#BFDBFE] bg-[#EFF6FF] px-4 py-3"><div class="flex items-center justify-between gap-3 text-[11px] font-medium uppercase tracking-[0.08em] text-[#2563eb]"><span>Tutorial</span><span>/</span></div><div class="mt-2 h-1.5 overflow-hidden rounded-full bg-[#dbeafe]"><div class="h-full rounded-full bg-[#2563eb] transition-all duration-300"></div></div><p class="mt-3 text-[13px] font-semibold text-[#2563eb]"></p><p class="mt-1 text-[13px] leading-5 text-[#475569]"></p></div>'),Zd=u('<div class="mt-4 flex items-center justify-between gap-3 rounded-[8px] border px-3 py-2"><div><p class="text-[13px] font-semibold"></p><p class="mt-0.5 text-[12px] text-[#686B70]"></p></div><button type="button" class="shrink-0 rounded-[8px] px-2 py-1.5 text-[12px] font-semibold text-[#686B70] hover:bg-white hover:text-[#1C1D1F]">Preview cut</button></div>'),Xd=u('<div role="alert" class="mt-4 rounded-[8px] border border-[#E9C7C3] bg-[#FFF6F4] px-3 py-2 text-[12px] leading-5 text-[#8F3F38]"></div>'),ec=u('<button type="button" class="font-semibold text-[#8A5A00] hover:underline"> cut to preview</button>'),tc=u('<details class="border-t border-[#E8E8E6] pt-2"><summary class="cursor-pointer list-none py-1 text-[12px] font-semibold text-[#686B70] hover:text-[#1C1D1F]">Advanced</summary><div class="pt-2"></div></details>'),nc=u('<div class="min-h-full w-full bg-background px-4 py-5 lg:px-6"><div class="mx-auto flex w-full max-w-[1440px] flex-col gap-4"><header class="flex flex-col gap-3 border-b border-border pb-4 sm:flex-row sm:items-center sm:justify-between"><div class="flex items-center justify-end gap-2"><button type="button" class="min-h-[40px] rounded-[8px] px-3 text-[13px] font-semibold text-muted-foreground transition-colors hover:bg-card hover:text-foreground disabled:cursor-not-allowed disabled:opacity-40">Undo</button><button type="button" class="min-h-[42px] min-w-[132px] rounded-[8px] bg-primary px-4 text-[14px] font-semibold text-primary-foreground transition-colors hover:bg-primary-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-40"></button></div></header><main class="grid min-w-0 grid-cols-1 items-start gap-4 lg:grid-cols-[minmax(0,3fr)_minmax(360px,2fr)]"><section class="min-w-0 rounded-[10px] border border-border bg-card p-3 sm:p-4"></section><section class="min-w-0 overflow-hidden rounded-[10px] border border-border bg-card lg:sticky lg:top-4"><div class="flex items-center justify-between border-b border-border px-4 py-3"><div><h2 class="text-[16px] font-semibold text-foreground">Transcript</h2><p class="mt-0.5 text-[12px] text-muted-foreground">Select words to delete, rewrite, or personalize.</p></div><span class="text-[12px] font-medium text-muted-foreground"></span></div><div class="flex max-h-[calc(100vh-190px)] min-h-[520px] flex-col"><div class="flex-1 overflow-y-auto px-4 py-3"></div><div class="border-t border-border bg-background px-4 py-3"><div class="flex items-center justify-between gap-3 text-[12px] text-[#686B70]"><span></span></div><details class="mt-3 border-t border-[#E8E8E6] pt-2"><summary class="cursor-pointer list-none py-1 text-[12px] font-semibold text-[#686B70] hover:text-[#1C1D1F]">Personalization variables</summary><div class="pt-2"></div></details></div></div></section></main><section class="flex flex-col gap-3 border-t border-border pt-4 lg:flex-row lg:items-start lg:justify-between"><div class="w-full lg:w-auto"></div></section></div></div>'),Vr=()=>{if(typeof window>"u")return;const e=document.createElement("div"),t=["#2563eb","#60a5fa","#a855f7","#f59e0b","#34d399"],n=24;Object.assign(e.style,{position:"fixed",inset:"0",pointerEvents:"none",overflow:"hidden",zIndex:"9999"});for(let r=0;r<n;r+=1){const s=document.createElement("div"),c=(r/(n-1)-.5)*420,o=-180+r*18,g=180+r%5*26,p=c*.9;Object.assign(s.style,{position:"absolute",left:`calc(50% + ${c}px)`,top:"20%",width:r%3===0?"8px":"10px",height:r%2===0?"14px":"10px",borderRadius:"999px",background:t[r%t.length],opacity:"0.95",transform:"translate3d(0,
50,0) rotate(0deg)",boxShadow:"0 0 12px rgba(37,99,235,0.18)"}),e.appendChild(s),s.animate([{transform:"translate3d(0,0,0) rotate(0deg)",opacity:1},{transform:`translate3d(${p}px, ${g}px, 0) rotate(${o}deg)`,opacity:0}],{duration:1400+r%6*90,easing:"cubic-bezier(0.22, 1, 0.36, 1)",fill:"forwards"})}document.body.appendChild(e),window.setTimeout(()=>e.remove(),1800)},ic=e=>{const[t,n]=C(!1),[r,s]=C([]),[c,o]=C(!0),[g,p]=C(),[m,h]=C([]),[d,b]=C(!0),[l,_]=C(!1),[y,S]=C(null),[w,I]=C(null),[F,R]=C(null),[ee,fe]=C(null),[H,be]=C(Ii()),[j,ce]=C(!1),[W,Q]=C(Jt()),[A,G]=C(!1),[ne,Z]=C(""),[ge,$e]=C(!1);let ye,xe,ve,Se,we,q="",J=!1,K=!1,$=!1,f=!1,N=!1;const T=Rr(),L=Rs(),z=()=>!1,[re,ae]=C(!1),Te=()=>!!x?.video_id&&d(),Oe=()=>di(),Re=()=>m().some(v=>v?.kind===-1)||x?.segments?.some(v=>v?.kind===-1)||sn().some(v=>v.segment!==-1),D=()=>zn()?sn().some(v=>v.segment!==-1&&v.linked===!0):Re(),Ve=()=>Object.keys(Ye()||{}).length>0;Ae(()=>{const v=(x?.segments||[]).filter(k=>k?.kind===-1);h(v)});const le=()=>{if(!Te())return!0;if(x?.product_id===Hi&&Re())return!1;if(Re()&&!zn()||Oe().length>0)return!0;if(et()){if(!D())return!0}else if(!D()&&!Ve())return!0},Me=()=>Te()?Re()&&!zn()?"Checking transcript variables before generating.":Oe().length>0?`Reselect ${Oe().join(", ")} in the transcript to continue.`:Ri()&&!D()?"Transcribing video. You can add transcript variables when it finishes.":et()&&!D()?"Add at least one transcript variable to continue.":!et()&&!D()&&!Ve()?"Add at least one variable to continue.":"":"Upload a video to enable samples and campaigns.",pe=()=>x?.product_id===Hi,de=()=>Js(W(),x?.id),se=()=>W()?.buildMode==="guided"&&W()?.status==="active"&&!W()?.dismissed&&de(),Ce=()=>We().some(v=>v?.status==="succeeded"&&!!v?.url),Xe=()=>!Ce()&&We().some(v=>v?.status==="failed"),gt=()=>ni()||We().length>0,vt=()=>{const v=xt();return!v||se()&&ne()!==v?!1:We().some(k=>k?.status==="succeeded"&&(k?.url===v||k?.share_url===v))},V=()=>({pathname:L.pathname,instanceId:x?.id?String(x.id):void 0,sourceReady:Te(),variablesReady:!le(),sampleModalOpen:yt(),sampleSucceeded:Ce(),sampleFailed:Xe(),sampleActive:gt(),sampleWatched:vt(),starterWordSelected:ge()}),X=()=>pe()&&!H()||se(),ue=()=>(pe()||se())&&_e()?.key==="variables",Fe=()=>se()?W()?.variables[0]??"name":pe()?"name":void 0,Pe=()=>(pe()||se())&&!!le()&&!y(),Ue=()=>pe()&&!H()&&Ce()||se()&&_e()?.target==="sample_watch",pt=()=>pe()&&!H()||se(),st=()=>Ds(Li()),Tt=()=>{const v=W();if(v?.status==="completed"&&de())return[];if(v&&se())return v.steps.map((me,ie)=>{const he=Qs(v,me,V());return{key:me.key,stepNumber:ie+1,title:he.title,body:he.body,complete:me.status==="completed"||he.complete,totalSteps:v.steps.length,target:he.target}}).filter(me=>me.key!=="source");if(H())return[];if(!pe()&&r().length)return[];const k=st(),U=pe()?Zn:3;return pe()?[{key:"sample",stepNumber:Kn.trySample,title:yt()?"Generate your sample":Ce()?"Watch your sample":Xe()?"Generate another sample":gt()?"Your test is generating":"Try a sample",body:yt()?"We filled in your account first name. Click Generate to make your practice sample.":Ce()?"Your preview is ready below. Select the highlighted video to play it above and finish this tutorial.":Xe()?"That sample did not finish successfully. Click Try sample to generate another one.":gt()?"Your finished video will appear in Generated videos below. Watch it when it is ready, then we’ll take you to the next campaign step.":`Generate one sample to preview the video before you use it to ${k}.`,complete:H(),totalSteps:U}]:[{key:"variables",stepNumber:1,title:"Set a variable",body:"Variables are placeholders like {name} that get replaced per recipient. Select text in the transcript to create them.",complete:!le(),totalSteps:U},{key:"sample",stepNumber:2,title:"Try a sample",body:"Generate a quick sample to preview the result before launching.",complete:!!We().length,totalSteps:U},{key:"campaign",stepNumber:3,title:"Create a campaign",body:"When it looks right, launch a campaign to personalize at scale.",complete:r().length>0,totalSteps:U}]},_e=()=>Tt().find(v=>!v.complete)??null,at=()=>_e()?.stepNumber??0,Qe=()=>_e()?.totalSteps??0,Pt=()=>{const v=_e();return v?`${v.key}:${v.title}`:null},Zt=()=>{if(se())switch(_e()?.target){case"transcript":return ye;case"try_sample":return xe;case"generated_videos":return Se;case"sample_watch":return we??Se;default:return}switch(_e()?.key){case"variables":return ye;case"sample":if(pe()){if(yt())return;
5if(Ce())return we??Se;if(gt())return Se}return xe;case"campaign":return ve;default:return}},Xt=()=>!!w()&&!!_e()&&ee()!==Pt()&&!(ue()||(pe()||se())&&_e()?.key==="sample"&&yt()),Rt=()=>!!w()&&!!_e()&&ee()===Pt()&&!(ue()||(pe()||se())&&_e()?.key==="sample"&&yt()),dt=()=>{const v=Zt();if(!v){I(null),R(null);return}const k=v.getBoundingClientRect();I(k);const U=_e(),me=280,ie=196,he=12,Ie=Ee=>Math.min(Math.max(he,Ee),window.innerHeight-ie-he),ze=Ee=>Math.min(Math.max(he,Ee),window.innerWidth-me-he),O=(()=>{const Ee=k.bottom+12;if(Ee+ie<=window.innerHeight-he)return{top:Ee,placement:"below"};const Ke=k.top-ie-12;return Ke>=he?{top:Ke,placement:"above"}:{top:Ie(Ee),placement:"below"}})(),Ne=_e()?.target==="sample_watch"||_e()?.key==="sample"&&Ce();let qe=ze(Ne?k.right-me:k.left),He=O.top,De=O.placement;if(U?.key==="variables"){const Ee=k.left-me-16,Ke=k.right+16;Ee>=he?(qe=Ee,He=Ie(k.top+k.height/2-ie/2),De="left"):Ke+me<=window.innerWidth-he&&(qe=Ke,He=Ie(k.top+k.height/2-ie/2),De="right")}R({top:He,left:qe,placement:De})};Ae(()=>{le()&&!pe()&&_(!0)}),Ae(()=>{const v=y();if(!v)return;const k=sn().find(U=>U.id===v.id);(!k||k.linked===!0)&&S(null)}),Ae(bn([()=>x?.id],()=>{fe(null),be(Ii()),Q(Jt()),ce(!1),G(!1),Z(""),$e(!1),S(null),ae(!1),J=!1,K=!1,$=!1,f=!1,N=!1})),Ae(()=>{if(!pe()||!de()&&!N)return;yt()&&!J&&(J=!0,ut("onboarding_sample_opened",{video_instance_id:x?.id,guided_setup_id:W()?.id}));const v=We().find(U=>U?.status==="succeeded"&&!!(U?.url||U?.share_url));v&&!K&&(K=!0,ut("onboarding_sample_generation_succeeded",{video_instance_id:x?.id,generated_video_id:v.id,cache_hit:Boolean(v.render_cache_hit)}),v.render_cache_hit&&ut("onboarding_sample_cache_hit",{video_instance_id:x?.id,generated_video_id:v.id}));const k=We().find(U=>U?.status==="failed");k&&!$&&($=!0,ut("onboarding_sample_generation_failed",{video_instance_id:x?.id,generated_video_id:k.id,stage:"render"})),vt()&&!f&&(f=!0,ut("onboarding_sample_watched",{video_instance_id:x?.id}))}),Ae(()=>{const v=W(),k=x?.id;if(!v||v.status!=="active"||!k||!de())return;const U=Ys(v,V());if(U.changed){let me=U.run;const ie=Li();U.completedJourney&&me.sourceMethod==="welcome_template"&&ie&&ht?.userInfo?.email&&(me=da(me,ht.userInfo.email,ie)),Q(me)}if(U.completedJourney&&!A()){if(G(!0),v.sourceMethod==="welcome_template"){be(!0),Mi(!0);return}Vr(),Y.success("Your first personalized video is ready!",{duration:4e3})}}),Ae(()=>{const v=new URLSearchParams(L.search).get("newCampaign")==="1";re()||!v||c()||!x?.id||le()||(ae(!0),N=!0,ut("onboarding_campaign_started",{video_instance_id:x?.id,source:"guided_continuation"}),Ht(!0),window.history.replaceState(window.history.state,"",`${window.location.pathname}${window.location.hash}`))}),Ae(()=>{se()||pe()&&vt()&&(H()||j()||(ce(!0),be(!0),Mi(!0),Vr(),Y.success("Beginner tutorial complete!",{duration:4e3})))}),Ae(()=>{Tt(),dt()}),zt(()=>{const v=()=>dt(),k=()=>Q(Jt());window.addEventListener("resize",v),window.addEventListener("scroll",v,!0),window.addEventListener(Pi,k),window.addEventListener("storage",k),Lt(()=>{window.removeEventListener("resize",v),window.removeEventListener("scroll",v,!0),window.removeEventListener(Pi,k),window.removeEventListener("storage",k)})});let Ft,en,Ge,mt=!1;const Dt=()=>{jt(""),window.requestAnimationFrame(()=>Ge?.load())},Fn=async(v,k,U)=>{let me;try{return await Promise.race([v,new Promise((ie,he)=>{me=window.setTimeout(()=>{he(new Error(`${U} timed out after ${k}ms`))},k)})])}finally{me&&window.clearTimeout(me)}},xn=async v=>{if(v){q=v,_i(v),o(!0);try{if(Qr(v),vi([],v),!x?.video_id){Y.error(`Hey ${ht?.userInfo?.first_name}, we encountered an issue during file verification.
6           Could you please re-upload your video to ensure the best quality? Thank you for your understanding!`);return}const k=x?.segments??[];h(k),o(!1),Fn(ma(v),8e3,"getCampaignByInstance").then(({result:U})=>{x.id===v&&s(U)}).catch(U=>{console.error(U)}),x?.mode===0&&Fs({video_instance_id:v,variables:k.map(U=>U.name)}).catch(U=>{console.error(U)})}catch(k){console.log(k)}finally{o(!1)}}};Ae(bn([()=>x?.id],([v])=>{v&&xn(v)})),Lt(()=>{Ln()?.readyState===1&&Ln()?.close(),Yr(q),jt("")});const tn=()=>{switch(ta()){case"preparing":return"Preparing edits…";case"generating":return"Generating speech…";case"finalizing":return"Finishing video…";default:return"Update video"}},wn=async(v,k)=>
6{Ui()?.cuts||Un(),k.length&&await Pl(),await Fl(),await Jn(),nt({...x,segments:(x?.segments||[]).filter(U=>!k.includes(U.id))}),jt(""),na(),window.requestAnimationFrame(()=>Ge?.load()),Y.success("Video updated.")},Dn=async()=>{const v=St();if(!(!v.length||on())){if(!Mn()?.segments?.length){Y.error("Wait for the transcript to finish loading.");return}try{if(ia().length>0){bt(!0),await Rl({edits:v,transcript:Mn()});return}await wn(x.video_url,[])}catch(k){console.error(k),bt(!1),Bn(k instanceof Error?k.message:"The video could not be updated."),Y.error("The video could not be updated. Your edits are still here.")}}},$n=()=>{const v=Ct()[0]||Un()[0];if(!v||!Ge)return;const k=Math.max(0,v.startTime-.75),U=()=>{Ge.currentTime>=v.startTime&&(Ge.currentTime=v.endTime,Ge.removeEventListener("timeupdate",U))};Ge.addEventListener("timeupdate",U),Ge.currentTime=k,Ge.play().catch(()=>{}),window.setTimeout(()=>Ge?.removeEventListener("timeupdate",U),8e3)};Ae(()=>{const v=Ui();if(!v||mt||v.sourceId!==x?.id)return;const k=We().filter(ie=>v.generationIds.includes(String(ie.id))),U=k.find(ie=>ie.status==="succeeded"&&(ie.url||ie.share_url));if(U){mt=!0,wn(U.url||U.share_url,v.temporarySegmentIds).catch(async ie=>{console.error(ie),await Jn(v.temporarySegmentIds),Bn(ie instanceof Error?ie.message:"The generated video could not be saved."),Y.error("The generated video could not be saved. Your edits are still here.")}).finally(()=>{mt=!1});return}k.length===v.generationIds.length&&k.every(ie=>ie.status==="failed")&&(mt=!0,Jn(v.temporarySegmentIds).finally(()=>{Zs(null),Xs("error"),Bn("The rewritten speech could not be generated."),bt(!1),mt=!1}))});const nn=()=>(()=>{const v=Yd.cloneNode(!0),k=v.firstChild,U=k.firstChild,me=U.nextSibling,ie=me.firstChild,he=ie.nextSibling,Ie=he.firstChild,ze=Ie.firstChild;i(U,a(Xi,{editInstance:t,setEditInstance:n,instanceNameRef:en,missingVariables:le}),null),i(U,a(er,{missingVariables:le,missingVariablesMessage:Me,get setPreviewSampleModal(){return pn},setCreateCampaignModal:O=>{O&&se()&&!N&&(N=!0,ut("onboarding_campaign_started",{video_instance_id:x?.id,source:"editor_action"})),Ht(O)},get setUploadTemplateModal(){return Cn},get suppressMissingVariablesNotice(){return X()},trySampleRef:O=>{xe=O,dt()},createCampaignRef:O=>{ve=O,O.dataset.campaignGuide="create-campaign",dt()}}),null),i(ie,a(tr,{isVideoAvailable:d,setIsVideoAvailable:b,videoRef:Ge,setAudioSampleConfig:p,segmentList:m,get selectedGeneratedVideo(){return xt()},onSampleEnded:()=>Z(xt()),onShowTemplate:()=>{jt(""),window.requestAnimationFrame(()=>Ge?.load())}}),null),i(ie,a(rr,{sampleGeneratedVideo:We,onRetry:Zi,get selectedVideo(){return xt()},onPlay:O=>{const Ne=O?.url||O?.share_url;Ne&&(Z(Ne),jt(Ne),window.requestAnimationFrame(()=>{}))},generatedVideosRef:O=>{Se=O,dt()},sampleWatchRef:O=>{we=O,dt()},get highlightWelcomeWatchLink(){return Ue()}}),null),i(ie,a(ir,{campaigns:r,navigate:T}),null),i(Ie,a(nr,{collapsedVariablesRef:Ft,variables:sn,onRelinkRequest:O=>{S(O),_(!0),$e(!1),window.requestAnimationFrame(()=>{ye?.scrollIntoView({behavior:"smooth",block:"center"})})}}),ze),i(Ie,a(E,{get when(){return ue()},get children(){const O=qd.cloneNode(!0),Ne=O.firstChild,qe=Ne.firstChild,He=qe.nextSibling,De=He.firstChild,Ee=Ne.nextSibling,Ke=Ee.firstChild,ct=Ee.nextSibling,Et=ct.nextSibling;return i(He,at,De),i(He,Qe,null),i(ct,()=>_e()?.title),i(Et,()=>_e()?.body),M(()=>Ke.style.setProperty("width",`${Qe()?at()/Qe()*100:0}%`)),O}}),ze);const Nt=ye;return typeof Nt=="function"?Je(Nt,ze):ye=ze,i(ze,a(Kt,{aria_label:"",data_microtip_position:"bottom",data_microtip_size:"medium",disabled:!1,get children(){return a(Rn,{get title(){return Jd.cloneNode(!0)},get active(){return l()},wrapperStyles:"max-h-[420px] overflow-y-auto rounded-[8px] border p-2",showIcon:!0,disabled:!1,onClose:()=>_(!1),get children(){return a(Oi,{get videoRef(){return x.video_url&&Ge},get highlightWord(){return Fe()},get highlightWordActive(){return Pe()},onHighlightWordSelectionChange:O=>$e(O),get relinkTarget(){return y()},onRelinkComplete:()=>S(null),onRelinkCancel:()=>S(null)})}})}})),i(Ie,a(E,{get when(){return!pe()},get children(){const O=Hd.cloneNode(!0);return O.firstChild,i(O,a(vr,{get setTrainingAudioUpload(){return Ot},instance:x,sampleGeneratedVideo:We,onTimingSaved:Dt}),null),O}}),null),i(Ie,a(Yi,{variant:"compact"}),null),i(v,a(_r,{get open(){return ji()},onClose:()=>Ht(!1)}),null),i(v,a($r,{get open(){return yt()},onClose:()=>pn(!1),videoRef:Ge,get showWelcomeTutorial(){return pt()}}),null),i(v,a(yr,{get open(){return ii()},onClose:()=>ri(!1),get src(){return xt()}}),null),i(v,a(Tr,{get open(){return Gi()},onClose:()=>Cn(!1)}),null),i(v,a(kr,{get open(){return zi()},onClose:()=>Ot(!1),get setTrainingAudioUpload(){return Ot}}),null),i(v,a(Cr,{get open(){return Bi()},onClose:()=>gn(!1),instance:x,setInstance:nt,get setSelectVideoConfig(){return gn}}),null),i(v,a(E,{get when(){return Xt()},get children(){return[(()=>{const O=Nr.cloneNode(!0);return M(Ne=>{const qe=`${w().top-6}px`,He=`${w().left-6}px`,De=`${w().width+12}px`,Ee=`${w().height+12}px`;return qe!==Ne._v$&&O.style.setProperty("top",Ne._v$=qe),He!==Ne._v$2&&O.style.setProperty("left",Ne._v$2=He),De!==Ne._v$3&&O.style.setProperty("width",Ne._v$3=De),Ee!==Ne._v$4&&O.style.setProperty("height",Ne._v$4=Ee),Ne},{_v$:void 0,_v$2:void 0,_v$3:void 0,_v$4:void 0}),O})(),(()=>{const O=Er.cloneNode(!0),Ne=O.firstChild,qe=Ne.firstChild,He=qe.firstChild,De=He.firstChild,Ee=De.nextSibling,Ke=Ee.firstChild,ct=He.nextSibling,Et=ct.firstChild,Ut=qe.nextSibling,Wn=Ne.nextSibling,rn=Wn.firstChild,yn=rn.nextSibling;return i(Ee,at,Ke),i(Ee,Qe,null),Ut.$$click=()=>fe(Pt()),i(rn,()=>_e()?.title),i(yn,()=>_e()?.body),M(_t=>{const P=`${F()?.top??0}px`,oe=`${F()?.left??0}px`,ke=`${Qe()?at()/Qe()*100:0}%`;return P!==_t._v$5&&O.style.setProperty("top",_t._v$5=P),oe!==_t._v$6&&O.style.setProperty("left",_t._v$6=oe),ke!==_t._v$7&&Et.style.setProperty("width",_t._v$7=ke),_t},{_v$5:void 0,_v$6:void 0,_v$7:void 0}),O})()]}}),null),i(v,a(E,{get when(){return Rt()},get children(){const O=Ar.cloneNode(!0),Ne=O.firstChild,qe=Ne.nextSibling,He=qe.firstChild,De=He.nextSibling,Ee=De.nextSibling,Ke=Ee.nextSibling;return Ke.nextSibling,O.$$click=()=>fe(null),i(qe,at,De),i(qe,Qe,Ke),M(ct=>{const Et=`${F()?.top??12}px`,Ut=`${F()?.left??12}px`;return Et!==ct._v$8&&O.style.setProperty("top",ct._v$8=Et),Ut!==ct._v$9&&O.style.setProperty("left",ct._v$9=Ut),ct},{_v$8:void 0,_v$9:void 0}),O}}),null),v})();return a(E,{get when(){return!c()},get fallback(){return a(zr,{})},get children(){return a(E,{get when(){return z()},get fallback(){return nn()}
6,get children(){const v=nc.cloneNode(!0),k=v.firstChild,U=k.firstChild,me=U.firstChild,ie=me.firstChild,he=ie.nextSibling,Ie=U.nextSibling,ze=Ie.firstChild,Nt=ze.nextSibling,O=Nt.firstChild,Ne=O.firstChild,qe=Ne.nextSibling,He=O.nextSibling,De=He.firstChild,Ee=De.nextSibling,Ke=Ee.firstChild,ct=Ke.firstChild,Et=Ke.nextSibling,Ut=Et.firstChild,Wn=Ut.nextSibling,rn=Ie.nextSibling,yn=rn.firstChild;v.style.setProperty("font-family","Manrope, system-ui, sans-serif"),i(U,a(Xi,{editInstance:t,setEditInstance:n,instanceNameRef:en,missingVariables:le}),me),kt(ie,"click",ea,!0),he.$$click=()=>void Dn(),i(he,tn),i(ze,a(tr,{isVideoAvailable:d,setIsVideoAvailable:b,videoRef:Ge,setAudioSampleConfig:p,segmentList:m,get selectedGeneratedVideo(){return xt()},onSampleEnded:()=>Z(xt()),onShowTemplate:()=>{jt(""),window.requestAnimationFrame(()=>{})}}),null),i(ze,a(E,{get when(){return on()},get children(){const P=Qd.cloneNode(!0),oe=P.firstChild,ke=oe.firstChild;return i(ke,tn),P}}),null),i(ze,a(rr,{sampleGeneratedVideo:We,onRetry:Zi,get selectedVideo(){return xt()},onPlay:P=>{const oe=P?.url||P?.share_url;oe&&(Z(oe),jt(oe),window.requestAnimationFrame(()=>{}))},generatedVideosRef:P=>{Se=P,dt()},sampleWatchRef:P=>{we=P,dt()},get highlightWelcomeWatchLink(){return Ue()}}),null),i(ze,a(ir,{campaigns:r,navigate:T}),null),i(qe,(()=>{const P=B(()=>!!St().length);return()=>P()?`${St().length} ${St().length===1?"change":"changes"}`:"Saved"})());const _t=ye;return typeof _t=="function"?Je(_t,De):ye=De,i(De,a(E,{get when(){return ue()},get children(){const P=Kd.cloneNode(!0),oe=P.firstChild,ke=oe.firstChild,Ze=ke.nextSibling,ft=Ze.firstChild,Be=oe.nextSibling,At=Be.firstChild,ot=Be.nextSibling,$t=ot.nextSibling;return i(Ze,at,ft),i(Ze,Qe,null),i(ot,()=>_e()?.title),i($t,()=>_e()?.body),M(()=>At.style.setProperty("width",`${Qe()?at()/Qe()*100:0}%`)),P}}),null),i(De,a(Oi,{editorMode:!0,get videoRef(){return x.video_url&&Ge},get highlightWord(){return Fe()},get highlightWordActive(){return Pe()},onHighlightWordSelectionChange:P=>$e(P),get relinkTarget(){return y()},onRelinkComplete:()=>S(null),onRelinkCancel:()=>S(null)}),null),i(De,a(E,{get when(){return Un().length>0},get children(){const P=Zd.cloneNode(!0),oe=P.firstChild,ke=oe.firstChild,Ze=ke.nextSibling,ft=oe.nextSibling;return i(ke,()=>Ct().length?"Preview this cut":"Short cut ready"),i(Ze,()=>Ct().length?"Longer cuts are more likely to jump. Check it before updating.":"We’ll blend the transition when you update the video."),ft.$$click=$n,M(Be=>{const At={"border-[#E8D3AD] bg-[#FFF9EF]":Ct().length>0,"border-[#CFE3DA] bg-[#F3FAF7]":Ct().length===0},ot=Ct().length>0,$t=Ct().length===0;return Be._v$0=lt(P,At,Be._v$0),ot!==Be._v$1&&ke.classList.toggle("text-[#8A5A00]",Be._v$1=ot),$t!==Be._v$10&&ke.classList.toggle("text-[#2C7B61]",Be._v$10=$t),Be},{_v$0:void 0,_v$1:void 0,_v$10:void 0}),P}}),null),i(De,a(E,{get when(){return qi()},get children(){const P=Xd.cloneNode(!0);return i(P,qi),P}}),null),i(ct,(()=>{const P=B(()=>!!St().length);return()=>P()?`${St().length} pending ${St().length===1?"change":"changes"}`:"No pending changes"})()),i(Ke,a(E,{get when(){return Ct().length>0},get children(){const P=ec.cloneNode(!0),oe=P.firstChild;return P.$$click=$n,i(P,()=>Ct().length,oe),P}}),null),i(Wn,a(nr,{collapsedVariablesRef:Ft,variables:sn,onRelinkRequest:P=>{S(P),_(!0),$e(!1),window.requestAnimationFrame(()=>{ye?.scrollIntoView({behavior:"smooth",block:"center"})})}})),i(Ee,a(E,{get when(){return!pe()},get children(){const P=tc.cloneNode(!0),oe=P.firstChild,ke=oe.nextSibling;return i(ke,a(vr,{get setTrainingAudioUpload(){return Ot},instance:x,sampleGeneratedVideo:We,onTimingSaved:Dt})),P}}),null),i(rn,a(er,{secondaryActions:!0,missingVariables:le,missingVariablesMessage:Me,get setPreviewSampleModal(){return pn},get setCreateCampaignModal(){return Ht},get setUploadTemplateModal(){return Cn},get suppressMissingVariablesNotice(){return X()},trySampleRef:P=>{xe=P,dt()},createCampaignRef:P=>{ve=P,P.dataset.campaignGuide="create-campaign",dt()}}),yn),i(yn,a(Yi,{variant:"compact"})),i(v,a(_r,{get open(){return ji()},onClose:()=>Ht(!1)}),null),i(v,a($r,{get open(){return yt()},onClose:()=>pn(!1),videoRef:Ge,get showWelcomeTutorial(){return pt()}}),null),i(v,a(yr,{get open(){return ii()},onClose:()=>ri(!1),get src(){return xt()}}),null),i(v,a(Tr,{get open(){return Gi()},onClose:()=>Cn(!1)}),null),i(v,a(kr,{get open(){return zi()},onClose:()=>Ot(!1),get setTrainingAudioUpload(){return Ot}}),null),i(v,a(Cr,{get open(){return Bi()},onClose:()=>gn(!1),instance:x,setInstance:nt,get setSelectVideoConfig(){return gn}}),null),i(v,a(E,{get when(){return Xt()},get children(){return[(()=>{const P=Nr.cloneNode(!0);return M(oe=>{const ke=`${w().top-6}px`,Ze=`${w().left-6}px`,ft=`${w().width+12}px`,Be=`${w().height+12}px`;return ke!==oe._v$11&&P.style.setProperty("top",oe._v$11=ke),Ze!==oe._v$12&&P.style.setProperty("left",oe._v$12=Ze),ft!==oe._v$13&&P.style.setProperty("width",oe._v$13=ft),Be!==oe._v$14&&P.style.setProperty("height",oe._v$14=Be),oe},{_v$11:void 0,_v$12:void 0,_v$13:void 0,_v$14:void 0}),P})(),(()=>{const P=Er.cloneNode(!0),oe=P.firstChild,ke=oe.firstChild,Ze=ke.firstChild,ft=Ze.firstChild,Be=ft.nextSibling,At=Be.firstChild,ot=Ze.nextSibling,$t=ot.firstChild,Sn=ke.nextSibling,os=oe.nextSibling,yi=os.firstChild,ls=yi.nextSibling;return i(Be,at,At),i(Be,Qe,null),Sn.$$click=()=>fe(Pt()),i(yi,()=>
6_e()?.title),i(ls,()=>_e()?.body),M(Wt=>{const Si=`${F()?.top??0}px`,Ci=`${F()?.left??0}px`,ki=`${Qe()?at()/Qe()*100:0}%`;return Si!==Wt._v$15&&P.style.setProperty("top",Wt._v$15=Si),Ci!==Wt._v$16&&P.style.setProperty("left",Wt._v$16=Ci),ki!==Wt._v$17&&$t.style.setProperty("width",Wt._v$17=ki),Wt},{_v$15:void 0,_v$16:void 0,_v$17:void 0}),P})()]}}),null),i(v,a(E,{get when(){return Rt()},get children(){const P=Ar.cloneNode(!0),oe=P.firstChild,ke=oe.nextSibling,Ze=ke.firstChild,ft=Ze.nextSibling,Be=ft.nextSibling,At=Be.nextSibling;return At.nextSibling,P.$$click=()=>fe(null),i(ke,at,ft),i(ke,Qe,At),M(ot=>{const $t=`${F()?.top??12}px`,Sn=`${F()?.left??12}px`;return $t!==ot._v$18&&P.style.setProperty("top",ot._v$18=$t),Sn!==ot._v$19&&P.style.setProperty("left",ot._v$19=Sn),ot},{_v$18:void 0,_v$19:void 0}),P}}),null),M(P=>{const oe=!St().length||on(),ke=!St().length||on()||Ri(),Ze=on();return oe!==P._v$20&&(ie.disabled=P._v$20=oe),ke!==P._v$21&&(he.disabled=P._v$21=ke),Ze!==P._v$22&&te(he,"aria-busy",P._v$22=Ze),P},{_v$20:void 0,_v$21:void 0,_v$22:void 0}),v}})}})};je(["click"]);const rc=u('<div class="flex md:overflow-y-auto h-full items-start"></div>'),yc=()=>{const e=Ws(),[t,n]=C(!1),r=async(s,c,o)=>{let g;try{return await Promise.race([s,new Promise((p,m)=>{g=window.setTimeout(()=>{m(new Error(`${o} timed out after ${c}ms`))},c)})])}finally{g&&window.clearTimeout(g)}};return zt(async()=>{_i(e.id),n(!1);try{const s=await r(it.read({id:e.id}),8e3,"video_instances.read"),c=s.result?.id,o=Us(s.result?.variable_start_times),g=Os(s.result?.enable_lipsync,s.result?.variable_start_times),p=Qt(s.result?.variable_timing_config),m=_n({id:c,variable_timing_config:p}),h=c?qs(c):null,d=h?.variable_start_times||{},b=Qt(h?.variable_timing_config),l=Object.keys(d).length>0?!1:typeof h?.enable_lipsync=="boolean"?h.enable_lipsync:!0;if(!!h&&g===!0&&Object.keys(o).length===0&&Object.keys(p).length===0&&(l===!1||Object.keys(d).length>0)){hn(l),Vt(d);const y={};if(!l)for(const[S,w]of Object.entries(d)){const I=Number(w);!Number.isFinite(I)||I<0||(y[S]=I)}try{c&&await it.update({id:c,enable_lipsync:l,variable_start_times:l?{}:y,variable_timing_config:l?{}:b})}catch{}nt({...s.result,enable_lipsync:l,variable_start_times:l?{}:y,variable_timing_config:l?{}:b,segments:[]})}else nt({...s.result,segments:[]}),hn(g),Vt(o),c&&ti(c,{enable_lipsync:g,render_quality:m,variable_start_times:o,variable_timing_config:p});n(!0),r(Bt.list({video_instance_id:s.result?.id}),8e3,"segments.list").then(y=>{const S=y.result.filter(w=>w.kind===-1).slice().sort((w,I)=>(w.highlight_si??0)-(I.highlight_si??0)||String(w.name??"").localeCompare(String(I.name??"")));nt({...x,segments:S})}).catch(y=>{console.error(y)})}catch(s){console.error(s),n(!0)}finally{}}),Lt(()=>{Yr(e.id),n(!1),hn(!0),Vt({}),js()}),(()=>{const s=rc.cloneNode(!0);return i(s,a(E,{get when(){return t()},get fallback(){return a(zr,{})},get children(){return[a(ic,{get instanceID(){return e.id}}),a(Ks,{})]}})),s})()};export{yc as default};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.