1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[2487],{7093:(e,t,l)=>{l.d(t,{E:()=>r});var r=function(e){return e.DRAFT="draft",e.FAILED="failed",e.SYNCING="syncing",e.COMPLETED="completed",e.GENERATING="generating",e.SYNC_FAILED="sync-failed",e}({})},25174:(e,t,l)=>{l.d(t,{$4:()=>d,DL:()=>i,J3:()=>g,QS:()=>h,YS:()=>a,ZH:()=>c,Zj:()=>s,bf:()=>y,hL:()=>o,hq:()=>m,jo:()=>u,oz:()=>f,uM:()=>w,wC:()=>x});var r=l(34896);let n=r.F.injectEndpoints({endpoints:e=>({getRealClone:e.query({query:e=>{let{clone_id:t}=e;return{url:"/real-clones/".concat(t),method:"GET",params:{include:"media"}}}}),createRealClone:e.mutation({query:e=>({url:"/real-clones",method:"POST",body:e})}),updateRealClone:e.mutation({query:e=>{let{clone_id:t,voice_id:l,script:r,avatar_id:n,provider:a}=e;return{url:"/real-clones/".concat(t),method:"PATCH",body:{voice_id:l,script:r,avatar_id:n,provider:a}}}}),generateScriptForClone:e.mutation({query:e=>{let{clone_id:t,payload:l}=e;return{url:"/real-clones/".concat(t,"/scripts"),method:"PUT",body:l}}}),generateScriptForUrlToVideo:e.mutation({query:e=>{let{clone_id:t,payload:l}=e;return{url:"/real-clones/".concat(t,"/scrape"),method:"POST",body:l}}}),avatars:e.query({query:()=>({url:"/real-clones/avatars",method:"GET"}),providesTags:[r.j.PHOTO_AVATAR]}),generateRealClone:e.mutation({query:e=>{let{clone_id:t}=e;return{url:"/real-clones/".concat(t,"/generate"),method:"POST"}},invalidatesTags:[r.j.PROFILE]}),deleteRealClone:e.mutation({query:e=>{let{clone_id:t}=e;return{url:"/real-clones/".concat(t),method:"DELETE"}}}),deletePhotoAvatar:e.mutation({query:e=>{let{avatar:t}=e;return{url:"/real-clones/avatars/".concat(t),method:"DELETE"}},async onQueryStarted(e,t){let{avatar:l}=e,{dispatch:r,queryFulfilled:a}=t,i=r(n.util.updateQueryData("avatars",void 0,e=>{if(null==e?void 0:e.data)return null==e?void 0:e.data.filter(e=>e.id!==l)}));a.catch(()=>{i.undo()})},invalidatesTags:[r.j.PHOTO_AVATAR]}),voices:e.query({query:()=>({url:"/speeches/voices",method:"GET"}),transformResponse:e=>(e.data&&(e.data=e.data.sort((e,t)=>t.type.length-e.type.length)),e)}),filteredVoices:e.query({query:e=>({url:"/speeches/voices",method:"GET",params:function(e){let t={};for(let[l,r]of Object.entries(e))r&&(t["filter[".concat(l,"]")]=r);return t}(e)}),transformResponse:e=>(e.data&&(e.data=e.data.sort((e,t)=>t.type.length-e.type.length)),e)}),voiceFilterOptions:e.query({query:()=>({url:"/speeches/voices/filters",method:"GET"})}),getRealCloneStatus:e.query({query:e=>{let{clone_id:t}=e;return{url:"/real-clones/".concat(t,"/status"),method:"GET"}}}),retryRealClone:e.mutation({query:e=>{let{clone_id:t}=e;return{url:"/real-clones/".concat(t,"/retries"),method:"POST"}}})})}),{useCreateRealCloneMutation:a,useUpdateRealCloneMutation:i,useGenerateScriptForCloneMutation:o,useGenerateScriptForUrlToVideoMutation:s,useGenerateRealCloneMutation:c,useDeleteRealCloneMutation:d,useDeletePhotoAvatarMutation:u,useAvatarsQuery:h,useVoicesQuery:m,useFilteredVoicesQuery:f,useVoiceFilterOptionsQuery:x,useLazyGetRealCloneStatusQuery:g,useGetRealCloneQuery:p,useLazyGetRealCloneQuery:y,useRetryRealCloneMutation:w}=n},59519:(e,t,l)=>{l.d(t,{PE:()=>n,Xd:()=>i});var r=l(31249);let n=async e=>{try{let t=await fetch(e,{method:"GET",credentials:"include",headers:{ContentType:"application/json","X-Requested-With":"XMLHttpRequest","X-XSRF-TOKEN":decodeURIComponent((0,r.R)("XSRF-TOKEN"))}});if(!t.ok)throw Error("Failed to fetch the file: ".concat(t.statusText));let l=await t.json(),n=await fetch(l.url),i=await n.blob();return a(i,l.filename)}catch(e){console.error("Error downloading the file:",e)}},a=(e,t)=>{let l=window.URL.createObjectURL(e),r=document.createElement("a");r.href=l,r.download=t,document.body.appendChild(r),r.click(),document.body.removeChild(r),window.URL.revokeObjectURL(l)},i=async(e,t)=>{let l=await fetch(e),r=await l.blob(),n=window.URL.createObjectURL(r),a=document.createElement("a");a.href=n,a.download=t,document.body.appendChild(a),a.click(),document.body.removeChild(a),window.URL.revokeObjectURL(n)}},72487:(e,t,l)=>{l.r(t),l.d(t,{Editor:()=>eB,default:()=>eZ});var r=l(95729),n=l(66933),a=l(48120),i=l(25844),o=l(35927),s=l(62867),c=l(25321),d=l(33268),u=l(36458),h=l(7508),m=l(3730),f=l(5029),x=l(68757),g=l(48275),p=l(47278);function y(){let{playPreview:e,pausePreview:t,setTime:l,getTime:a,getVideoDuration:i}
1=(0,x.M)(),[o,s]=(0,n.useState)(!1);return(0,g.ft)(p.T.ON_PLAY,()=>{s(!0)}),(0,g.ft)(p.T.ON_PAUSE,()=>{s(!1)}),(0,r.jsxs)("div",{className:"flex gap-2 items-center",children:[(0,r.jsx)(f.Ay,{onClick:()=>{let e=a();e-10>=0?l(e-10):l(0)},type:"text",style:{padding:"0"},icon:(0,r.jsx)(m.g,{icon:h.dDM,className:"text-xl text-sgray-ten"})}),(0,r.jsx)(f.Ay,{onClick:()=>{if(o)return void t();e()},size:"large",type:"text",style:{padding:"0"},icon:(0,r.jsx)(m.g,{icon:o?h.SVv:h.e74,className:"text-4xl text-sgray-ten"})}),(0,r.jsx)(f.Ay,{onClick:()=>{let e=a(),t=i();e+10<=t?l(e+10):l(t)},size:"large",type:"text",style:{padding:"0"},icon:(0,r.jsx)(m.g,{icon:h.dxS,className:"text-xl text-sgray-ten"})})]})}var w=l(13566),v=l(20396),j=l(47112),b=l(51929),E=l(25174),k=l(42646);let T=(0,k.Mz)([e=>e.content.video],e=>{var t,l;return(null==e||null==(l=e.footage)||null==(t=l.real_clones)?void 0:t.length)?e.footage.real_clones:null});(0,k.Mz)([e=>e.content.video],e=>{var t;return(null==e||null==(t=e.footage.real_clones)?void 0:t.length)?e.footage.real_clones.reduce((e,t)=>(e[t.id]=t.status,e),{}):null});var C=l(99002),M=l(32283),S=l(7093),R=l(48975),N=l(52223),I=l(59519),A=l(20399);let O=(0,k.Mz)([e=>e.editor.timelineZoomLevel,e=>e.editor.timelineIntervalDuration],(e,t)=>Math.max(t*(1+(e-50)/99*2),1)),D=e=>{let t=(0,s.G)(O),[l,r]=(0,n.useState)(0),a=i.wL,o=(0,s.G)(e=>e.editor.tracks),c=Math.floor(l/i.cg),d=c*t,u=Math.floor(e/t),h=t/(i.Fk+1),[m,f]=(0,n.useState)(null),x=(0,n.useCallback)(e=>{let l=Math.floor(e/i.cg),r=e%i.cg/i.Tn;return l*t+r*h},[h,t]),g=(0,n.useCallback)(function(e){arguments.length>1&&void 0!==arguments[1]&&arguments[1];let l=Math.floor(e/t),r=e%t*1e3,n=r/(1e3*h),a=(n-Math.floor(n))*i.Tn,o=Math.floor(r/(1e3*h));return l*i.cg+o*i.Tn+a},[h,t]);return{numOfIntervals:e>d?u:c,intervalDuration:t,dotIntervalDuration:h,getTimeByXValue:x,getXValueByTime:g,MAX_DURATION:a,tracks:o,totalWidth:l,setTotalWidth:r}},P=e=>{let{getTimeByXValue:t,getXValueByTime:l,totalWidth:r,tracks:a}=e,o=(0,n.useCallback)((e,r,n)=>{if(r.x<i.Wu&&(r.x=i.Wu,r.width=e.width),(n.type===M.Z2.VIDEO||n.type===M.Z2.AUDIO)&&(null==n?void 0:n.name)){let t=(0,j.RT)(n.name,M.wW.DURATION),a=l(n.time)-l(n.trim_start||0),i=r.x<e.x;if(r.x<a&&i)return e;let o=l(Number(t));r.width=r.width>=o?o:r.width}let o=a.find(e=>e[0]===n.track);if(o){let a=o[1],s=(0,j.om)({elementID:n.id,startTime:t(r.x-i.Wu),endTime:t(r.x+r.width)},a);if(s){let t=(0,j.rx)(s),n=l(s.time)+i.Wu,a=l(t+s.time)+i.Wu;r.x<n?r.width=n-r.x:(r.x=a,r.width=e.width)}else if(Math.abs(r.width)<=i.x3)return e}return r.height=e.height,r},[t,l,a]);return{onElementTransformEnd:(0,n.useCallback)(async(e,l)=>{if(!l.id)return null;let r=e.currentTarget.getClientRect(),n=Math.abs(r.x-i.Wu+1),a=r.x+r.width-(i.Wu+1),o=t(n);o<.1&&(o=0);let s=t(a)-o;return{id:l.id,startTime:o,duration:s}},[t]),onElementTransform:(0,n.useCallback)((e,n)=>{var o,s;let c=e.currentTarget.getClientRect(),d=l((0,j.rx)(n)),u=Math.abs(c.x-(i.Wu+1)),h=c.x+c.width-(i.Wu+1),m=t(u),f=t(h),x=null==(s=a.reduce((e,t)=>[...e,...t[1]],[]))||null==(o=s.filter(e=>e.id!==n.id))?void 0:o.map(e=>({...e})),g=t(10),p=(0,j.S9)(x,m,f,g).map(e=>({...e,x:l(e.x),width:l(e.width),height:a.length*i.eb+i.eb})),y=c.x+c.width+40,w=d+10,v=c.width>w,b=c.width<w;return y>r?{width:y,guidelines:p,x:c.x,isIncreasing:v,isDecreasing:b}:{guidelines:p,x:c.x,isIncreasing:v,isDecreasing:b}},[t,l,r,a]),getElementTransformBoundaries:o}};var L=l(46391),U=l(80250);let W=e=>{let{tracks:t,getTimeByXValue:l,getXValueByTime:r,totalWidth:a}=e,{lastTrackPosition:o,firstTrackPosition:s}=(0,n.useMemo)(()=>{let e=(0,j.X0)(t);return e[e.length-1]?{lastTrackPosition:e[e.length-1],firstTrackPosition:e[0]}:{}},[t]),c=e=>Math.floor(e/(i.eb-i.aP))-1,d=(0,n.useCallback)((e,l)=>{var r;let{trackPosition:n,trackIndex:a}=(0,j.zB)(t,e),i=t.map(e=>e[0]),o=Math.max(...i),s=l,d=(null==(r=t.find(e=>e[0]===l))?void 0:r[1])||[],h=!1;if(a>-1)({trackNumber:s,isNewTrack:h}=u({trackIndex:a,trackPosition:n,maxTrackNumber:o,currentTrack:l,tracksNumbers:i,elementsInSameTrack:d}));else{let l=c(e);d=t[l]?t[l][1]:[],s=t[l]?t[l][0]:-1}return{trackNumber:s,elementsInSameTrack:d,isNewTrack:h,trackPosition:n}},[t]),u=e=>{let{trackIndex:t,trackPosition:l,maxTrackNumber:r,currentTrack:n,tracksNumbers:a,elementsInSameTrack:i}=e,o=n;return{trackNumber:l===M.c0.TOP?i.length>1?r+1:r:t>0?a.reverse()[t]:1,isNewTrack:!0}},h=(e,t)=>e<=0||!t,m=e=>e.type===U.M.AUDIO,f=e=>e.some(e=>e.type===U.M.AUDIO),x=e=>e.some(e=>e.type!==U.M.AUDIO),g=(0,n.useCallback)(e=>{let l=t.find(t=>t[0]===e);return l?l[1]:[]},[t]),p=(0,n.useCallback)((e,t)=>{let{elementsInSameTrack:l,trackNumber:r,isNewTrack:n}=t,a=m(e),i=f(l),o=x(l),s=n?g(a?r-1:r):[],c=a?x(s):f(s);return!a&&i||a&&o||c},[g]),y=e=>{let{element:t,trackNumber:l,startTime:r,duration:n}=e;return{id:t.id,track:l,time:r,duration:n}},w=(0,n.useCallback)(()=>t.flatMap(e=>e[1]),[t]),v=e=>{let t=Object.entries(e);t.sort((e,t)=>
1e[1]-t[1]);let l=1,r=-1,n={};return t.forEach(e=>{let[t,a]=e;a>r?(n[t]=l++,r=a):n[t]=l-1}),n},b=(0,n.useCallback)(e=>{let{allElements:t,element:l,trackNumber:r,trackPosition:n,elementsInSameTrack:a}=e;return v(t.sort((e,t)=>e.track-t.track).reduce((e,t)=>{if(t.id===l.id)e["".concat(t.id,".track")]=r;else{let i=a.find(e=>e.id===t.id);e["".concat(t.id,".track")]=E(t,r,l.track,n,void 0!==i)}return e},{}))},[]),E=(e,t,l,r,n)=>{let a=e.track;return r===M.c0.TOP?a=e.track-1:r===M.c0.BOTTOM?a=e.track+1:r===M.c0.BETWEEN&&e.track>=t&&(a=e.track+1),a},k=e=>e.reduce((e,t)=>(e["".concat(t.id,".time")]=t.time,e["".concat(t.id,".duration")]=t.duration,e["".concat(t.id,".track")]=t.track,e),{}),T=(0,n.useCallback)(e=>{let{draggedElementChanges:t,element:l,elementsInSameTrack:r,isNewTrack:n,trackNumber:a,trackPosition:i}=e,o={draggedElementChanges:t,isSnapped:!1,rearrangedElements:{}},s=w();if(n)o.rearrangedElements=b({allElements:s,element:l,trackNumber:a,trackPosition:i,elementsInSameTrack:r}),o.rearrangedElements["".concat(l.id,".time")]=t.time,o.rearrangedElements["".concat(l.id,".duration")]=t.duration;else{let e=r.filter(e=>e.id!==l.id).map(e=>structuredClone(e)),{elements:n,isSnapped:a}=(0,j.tf)({...l,...t},e),i=v([...s.filter(e=>-1===n.findIndex(t=>e.id===t.id)),...n].reduce((e,t)=>(e["".concat(t.id,".track")]=t.track,e),{}));o.rearrangedElements={...k(n),...i},o.isSnapped=a}return o},[w,b]),C=(0,n.useCallback)(async(e,t)=>{document.body.style.cursor="default";let r=(0,j.IZ)((0,j.rx)(t))||0,n=e.currentTarget.getClientRect(),a=l(Math.abs(n.x-i.Wu)),{trackNumber:o,trackPosition:s,elementsInSameTrack:c,isNewTrack:u}=d(n.y,t.track);return h(o,t.id)||p(t,{trackNumber:o,isNewTrack:u,elementsInSameTrack:c})?{rearrangedElements:{["".concat(t.id,".time")]:t.time,["".concat(t.id,".duration")]:t.duration,["".concat(t.id,".track")]:t.track,["".concat(t.id,".id")]:L.A()},isSnapped:!1}:T({draggedElementChanges:y({element:t,trackNumber:o,startTime:a,duration:r}),element:t,elementsInSameTrack:c,isNewTrack:u,trackNumber:o,trackPosition:s})},[T,d,l,p]);return{onElementDragMove:(0,n.useCallback)((e,n)=>{var o;let s=e.target.getClientRect(),c=Math.abs(s.x-i.Wu),d=c+s.width,u=l(c),h=l(d),m=null==(o=t.reduce((e,t)=>[...e,...t[1]],[]))?void 0:o.filter(e=>e.id!==n.id),f=(0,j.BX)(t,s.y),x=l(10),g=(0,j.S9)(m,u,h,x).map(e=>({...e,x:r(e.x),width:r(e.width),height:t.length*i.eb+i.eb})),p=s.x-50+s.width+.1;return p>a?{width:p,guidelines:g,trackGuidePosition:f,x:s.x}:{guidelines:g,trackGuidePosition:f,x:s.x}},[l,r,a,t]),onElementDragEnd:C,getElementDragBoundary:(e,t)=>{let l=e.y;return o&&l>=o?l=o:s&&l<=s&&(l=s),{x:e.x<=i.Wu?i.Wu+1:e.x,y:l}}}},F=(0,n.createContext)({timelineContainerRef:{current:null},stageRef:{current:null},layerRef:{current:null},activeElements:[],tracks:[],getXValueByTime:()=>0,getTimeByXValue:()=>0,onTimeChange:()=>{},getElementDragBoundary:()=>({x:0,y:0}),getElementTransformBoundaries:()=>({x:0,y:0,width:0,height:0,rotation:0}),handleElementTransformEnd:()=>{},handleElementTransform:()=>{},onElementSelect:()=>{},onElementDoubleClick:()=>{},downloadRealClone:()=>{},fitTimeline:()=>{},onZoomChange:()=>{},duration:30,intervalDuration:1,dotIntervalDuration:.1,numOfIntervals:30,totalHeight:0,realClonesInProgress:[],realClonesFailed:[],isPlaying:!1}),G=e=>{let{children:t}=e,l=N.l.getInstance(),a=(0,n.useRef)(null),o=(0,n.useRef)(null),c=(0,n.useRef)(null),d=(0,s.j)();(0,g.N)();let[u,h]=(0,n.useState)(!1);(0,g.ft)(p.T.ON_PLAY,()=>{h(!0)}),(0,g.ft)(p.T.ON_PAUSE,()=>{h(!1)});let f=(0,s.G)(T),x=(0,n.useMemo)(()=>null==f?void 0:f.reduce((e,t)=>{let l=t.status;return e[l]?e[l].push(t.id):e[l]=[t.id],e},{}),[f]),{activeElements:y,isEditorLoaded:w,duration:k,selectedTemplate:O}=(0,s.G)(e=>({activeElements:e.editor.activeElements,isEditorLoaded:e.editor.isLoaded,duration:e.editor.duration,selectedTemplate:e.editor.selectedTemplateID})),L=(0,n.useMemo)(()=>{if(!x)return[];let e=x[S.E.GENERATING]||[];return x[S.E.SYNCING]&&(e=e.concat(x[S.E.SYNCING])),e},[x]),U=(0,n.useMemo)(()=>x&&x[S.E.SYNC_FAILED]||[],[x]),{data:G,isLoading:Y,isFetching:_,isSuccess:X}=(0,E.QS)(),[q]=(0,E.$4)(),{getSource:V,getTracks:H,setTime:z,getTime:B,getAllElements:Z,loadRealClone:K,loadRealClonePlaceholder:J,removeRealClone:Q,updateTimeAndDurationForElement:$,setActiveElements:ee,duplicateCurrentElement:et,applyModifications:el,groupElements:er,findElementById:en,ungroupElements:ea}=(0,g.M4)(),{removeElement:ei}=(0,g.ps)(),{getXValueByTime:eo,getTimeByXValue:es,tracks:ec,numOfIntervals:ed,intervalDuration:eu,dotIntervalDuration:eh,totalWidth:em,setTotalWidth:ef}=D(k),{onElementTransform:ex,onElementTransformEnd:eg,getElementTransformBoundaries:ep}=P({getXValueByTime:eo,getTimeByXValue:es,totalWidth:em,tracks:ec}),{onElementDragEnd:ey,getElementDragBoundary:ew,onElementDragMove:ev}=W({getTimeByXValue:es,getXValueByTime:eo,tracks:ec,totalWidth:em}),ej=(0,n.useCallback)(()=>{var e;let t=Array.from(null!=(e=H().entries())?e:[]).reverse().map(e=>{let[t,l]=e;return[t,l.map(e=>e)]});d((0,C.$U)(t))},[d,H]),eb=(0,n.useCallback)(()=>Z().reduce((e,t)=>
1{if(!t.duration)return e;let l=(0,j.IZ)(t.time)+(0,j.IZ)(t.duration);return l>e?l:e},0),[Z]);(0,g.ft)(p.T.STATE_CHANGED,()=>{ej(),eE()}),(0,g.ft)(p.T.ACTIVE_COMPOSITION_CHANGE,()=>{ej()}),(0,n.useEffect)(()=>{w&&ej()},[V,ej,w,O]);let eE=(0,n.useCallback)(()=>{let e=eb();e&&d((0,C.rU)(e))},[d,eb]);(0,n.useEffect)(()=>{w&&eE()},[eE,w]);let ek=async e=>{await z(e)},eT=e=>{l.publish(p.T.GUIDELINES,e)},eC=e=>{l.publish(p.T.TRACK_GUIDELINE,e)},eM=function(e,t){let l=arguments.length>2&&void 0!==arguments[2]?arguments[2]:40,r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:10;if(a.current)if(t&&ef(t),a.current.scrollWidth>a.current.clientWidth){let n=a.current.scrollWidth-a.current.clientWidth;e<a.current.scrollLeft+l?a.current.scrollLeft-=r:e>n+l&&(a.current.scrollLeft+=(t||r)+25)}else e>a.current.clientWidth+l&&(a.current.scrollLeft+=(t||r)+25)},eS=async(e,t)=>{let l=await ey(e,t);return l?(await el(l.rearrangedElements),eE(),eT([]),eC(null),{updatedElements:l.rearrangedElements,isSnapped:l.isSnapped}):null},eR=()=>{var e;let t=Z(),l=null==t?void 0:t.find(e=>e.id===(null==y?void 0:y[0])),n=(null==l||null==(e=l.name)?void 0:e.includes(A.O.AVATAR))?(0,j.RT)(l.name,M.wW.UUID):null;b.aF.confirm({title:"Are you sure you want to remove this ".concat(n?"clone":"element","?"),okText:"Yes, Delete",cancelText:"No, Keep It",okButtonProps:{className:"!bg-fn-danger",icon:(0,r.jsx)(m.g,{icon:v.yLS})},onOk:()=>{ei(y),n&&q({clone_id:Number(n)})},centered:!0})},eN=async(e,t)=>{let l=await eg(e,t);if(!l)return;let{id:r,startTime:n,duration:a}=l;if(eT([]),r){let e=(t.trim_start||0)+(n-t.time),l={time:n,duration:a};(t.type===M.Z2.VIDEO||t.type===M.Z2.AUDIO)&&(l.trimStart=e>0?e:0,l.trimDuration=a),await $(r,l),eE()}},eI=(e,t,l)=>e<=l&&e>=t,eA=e=>e.type===i.MN.AUDIO||e.type===i.MN.VIDEO,eO=(e,t,l,r,n)=>e&&t&&(!eA(e)||!eI(l,r,n));(0,n.useEffect)(()=>{if(k){let e=k/eu*i.cg,t=window.innerWidth-140;ef(e>t?e+25:t)}},[k,eu,ef]),(0,n.useEffect)(()=>{if((null==a?void 0:a.current)&&k){let e=(a.current.clientWidth-50)/i.cg;if(eo(k)/i.cg>e){let t=Math.round(k/e);d((0,C.HR)(t))}}},[d,k,eo]);let eD=(0,n.useCallback)(e=>{var t;if(!e||!X)return;let l=null==G||null==(t=G.data)?void 0:t.find(t=>t.id===e.avatar_id);l&&J({name:l.name,previewImage:l.preview},e.id)},[null==G?void 0:G.data,X,J]),eP=(0,n.useCallback)(async()=>{if(f&&w)for(let t of f){var e;let l=null==t||null==(e=t.media)?void 0:e.find(e=>e.collection===R.ee.VIDEO);l?K(l,t.id):eD(t)}},[f,w,K,eD]);(0,n.useEffect)(()=>{eP()},[eP]),(0,n.useEffect)(function(){if(f&&w)for(let e of f)e.status===S.E.FAILED&&Q(e.id)},[f,w,Q]);let eL=ec.length*i.eb+3*i.eb,eU=[];if(y.length>0){var eW;let e=(null==(eW=en(y[0]))?void 0:eW.type)===i.MN.COMPOSITION;eU=[...eU,{key:"Duplicate",label:"Duplicate",icon:(0,r.jsx)(m.g,{icon:v.jPR}),onClick:e=>{et()}},{key:"Group",label:"Group",disabled:y.length<2||(null==y?void 0:y.some(e=>{var t;return(null==(t=en(e))?void 0:t.type)===i.MN.COMPOSITION})),icon:(0,r.jsx)(m.g,{icon:v.KKh}),onClick:e=>{er(y)}},{key:"Ungroup",label:"Ungroup",disabled:!e,icon:(0,r.jsx)(m.g,{icon:v.Ytq}),onClick:e=>{y.length&&ea(y[0])}},{key:"Delete",label:"Delete",icon:(0,r.jsx)(m.g,{icon:v.yLS}),onClick:e=>{eR()}}]}return(0,r.jsx)(F.Provider,{value:{timelineContainerRef:a,stageRef:o,layerRef:c,intervalDuration:eu,dotIntervalDuration:eh,numOfIntervals:ed,totalWidth:em,totalHeight:eL,contextMenuItems:eU,activeElements:y,tracks:ec,duration:k,realClonesInProgress:L,realClonesFailed:U,isPlaying:u,getTimeByXValue:es,getXValueByTime:eo,onTimeChange:ek,getElementDragBoundary:ew,handleDragMove:(e,t)=>{let l=ev(e,t);if(!l)return;let{width:r,guidelines:n,trackGuidePosition:a,x:i}=l;eT(n),eC(a||null),eM(i,r)},handleElementDragEnd:eS,getElementTransformBoundaries:ep,handleElementTransformEnd:eN,handleElementTransform:(e,t)=>{let l=ex(e,t);if(!l)return;let{width:r,guidelines:n,x:a,isIncreasing:i}=l;eT(n),i&&eM(a,r,0)},onElementSelect:(e,t)=>{let{updateTime:l=!1,isMultiSelect:r=!1,isSelected:n=!1,isRightClick:a=!1}=t,i=[e.id];(r||a)&&(i=n&&!a?y.filter(t=>t!==e.id):[...y,e.id]),ee(i)},onElementDoubleClick:(e,t)=>{let{updateTime:l=!1}=t,r=e.time,n=r+(0,j.rx)(e);
1if(eO(e,l,B(),r,n)){let t=(0,j.Zz)(e.name);z(t?(0,j.IZ)(t)+e.time:e.time)}},deleteRealCloneConfirmation:eR,downloadRealClone:e=>{var t;let l=null==f?void 0:f.find(t=>e.includes(t.id.toString()));l&&(null==l||null==(t=l.media)?void 0:t.length)&&(0,I.PE)(l.media[0].download_url)},fitTimeline:()=>{if(!(null==a?void 0:a.current))return;let e=(a.current.clientWidth-160)/i.cg,t=5>Math.round(k/e)?5:Math.round(k/e);d((0,C.HR)(t))},onZoomChange:e=>{d((0,C.fw)(e))}},children:t})},Y=()=>{let e=(0,n.useContext)(F);if(!e)throw Error("useTimelineContext must be used within a TimelineContext");return e},_=()=>{let{fitTimeline:e,onZoomChange:t}=Y(),[l,a]=(0,n.useState)(50),i=e=>{a(e),t(e<100?100-e:1)};return(0,r.jsxs)("div",{className:"flex items-center min-w-[60px] sm:min-w-[200px]",children:[(0,r.jsx)(m.g,{icon:v.YBE,onClick:()=>{l>0&&i(l-5)},className:"cursor-pointer mr-2 text-lg"}),(0,r.jsx)(w.A,{min:1,max:100,step:10,value:l,onChange:i,className:"mx-2 flex-auto hidden sm:block",tooltip:{formatter:null,open:!1}}),(0,r.jsx)(m.g,{icon:v.KmH,onClick:()=>{l<100&&i(l+5)},className:"cursor-pointer ml-2 text-lg"}),(0,r.jsx)(f.Ay,{type:"text",onClick:()=>{e(),i(50)},children:"Fit"})]})};var X=l(78614);let q=()=>{let e=(0,s.G)(e=>e.editor.activeElements),{applyModifications:t,getAllElements:l,getTime:r,getActiveElement:a,duplicateCurrentElement:i,pausePreview:o}=(0,g.M4)(),{deleteRealCloneConfirmation:c,downloadRealClone:d}=Y(),[u,h]=(0,n.useState)(!1),m=a(),f=null==m?void 0:m.type,x=null==m?void 0:m.time,y=(null==m?void 0:m.time)!==void 0?(null==m?void 0:m.time)+(0,j.rx)(m):0,w=(0,n.useCallback)(e=>{let t=f===U.M.VIDEO||f===U.M.AUDIO,l=e>x&&e<=y;h(t&&l)},[f,x,y,h]);(0,g.ft)(p.T.TIME_CHANGE,w),(0,n.useEffect)(()=>{w(r())},[e,w,r]);let v=async()=>{let n=await l(),a={...n.find(t=>e.includes(t.id))};if(a.type!==U.M.VIDEO&&a.type!==U.M.AUDIO)return;let i=await r(),s=n.filter(e=>e.id!==a.id),c=(0,j.IZ)(a.time)||0,d=(0,j.rx)(a),u={...a,id:(0,L.A)(),time:i,trim_start:Math.abs(i-a.time),trim_duration:Math.abs(a.time+d-i)};a.trim_duration=Math.abs(i-c),o(),await t({elements:[...s,a,u]})},b=async e=>{let l=a();if(!l)return;let r=l.x_scale,n=l.y_scale;"horizontal"===e?(r="-100%"===r?"100%":"-100%",await t({["".concat(l.id,".x_scale")]:r})):(n="-100%"===n?"100%":"-100%",await t({["".concat(l.id,".y_scale")]:n}))};return{split:v,canSplit:u,canFlip:!!f&&f!==U.M.AUDIO,canDownload:null!=m&&!!m.name&&(0,j.O1)(m.name),flip:b,fitToScreen:()=>{let e=a();e&&t({["".concat(e.id,".x")]:"50%",["".concat(e.id,".y")]:"50%",["".concat(e.id,".height")]:"100%",["".concat(e.id,".width")]:"100%",["".concat(e.id,".fit")]:"contain"})},showProperties:e.length>0,duplicateCurrentElement:i,onDownload:()=>{e.length&&(null==m?void 0:m.name)&&(0,j.O1)(m.name)&&d(m.name)},onDelete:()=>{e.length&&(null==c||c())}}};function V(){let{split:e,showProperties:t,canSplit:l,canFlip:n,canDownload:a,flip:i,fitToScreen:o,duplicateCurrentElement:s,onDelete:c,onDownload:d}=q();return t?(0,r.jsxs)("div",{className:"flex items-center gap-x-2",children:[a&&(0,r.jsx)(X.A,{title:"Download Avatar Video",children:(0,r.jsx)(f.Ay,{onClick:d,type:"text",icon:(0,r.jsx)(m.g,{icon:v.cbP}),children:"Download"})}),(0,r.jsx)(f.Ay,{onClick:e,type:"text",className:"!bg-transparent",icon:(0,r.jsx)(m.g,{icon:v.XGd}),disabled:!l,children:"Split"}),(0,r.jsx)(X.A,{title:"Duplicate",children:(0,r.jsx)(f.Ay,{onClick:s,type:"text",icon:(0,r.jsx)(m.g,{icon:v.jPR})})}),n&&(0,r.jsxs)("div",{className:"flex items-center gap-x-1",children:[(0,r.jsx)(X.A,{title:"Flip Horizontally",children:(0,r.jsx)(f.Ay,{type:"text",icon:(0,r.jsx)(m.g,{icon:v.$9V}),onClick:()=>i("horizontal")})}),(0,r.jsx)(X.A,{title:"Flip Vertically",children:(0,r.jsx)(f.Ay,{type:"text",icon:(0,r.jsx)(m.g,{icon:v.HK0}),onClick:()=>i("vertical")})}),(0,r.jsx)(X.A,{title:"Fit to Canvas",children:(0,r.jsx)(f.Ay,{type:"text",icon:(0,r.jsx)(m.g,{icon:v.NPP}),onClick:()=>o()})})]}),(0,r.jsx)(X.A,{title:"Delete",children:(0,r.jsx)(f.Ay,{onClick:c,type:"text",icon:(0,r.jsx)(m.g,{icon:v.yLS})})})]}):null}function H(){let{undo:e,redo:t}=(0,x.M)();return(0,r.jsxs)("div",{className:"flex items-center gap-x-1",children:[(0,r.jsx)(X.A,{title:"Undo
1- Ctrl + Z",children:(0,r.jsx)(f.Ay,{onClick:e,type:"text",className:"!flex !items-center !justify-center",icon:(0,r.jsx)(m.g,{icon:v.U23,className:"text-lg"})})}),(0,r.jsx)(X.A,{title:"Redo - Ctrl + Shift + Z",children:(0,r.jsx)(f.Ay,{onClick:t,type:"text",className:"!flex !items-center !justify-center",icon:(0,r.jsx)(m.g,{icon:v.yek,className:"text-lg"})})})]})}var z=l(65402),B=l(9023);function Z(e){let{ratio:t,className:l="",mode:n="dropdown"}=e,a="/images/icons/aspect-ratio/".concat(t.key.replace(":","-"),".svg");return(0,r.jsx)("div",{className:"flex flex-row justify-between gap-x-2 items-center py-2 max-w-52 ".concat(l),children:(0,r.jsxs)("div",{className:"flex items-center gap-x-2",children:[(0,r.jsx)(z.default,{src:a,alt:"",width:"dropdown"===n?30:24,height:"dropdown"===n?30:24}),(0,r.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,r.jsx)(B.A.Text,{className:"!whitespace-nowrap",children:"".concat(t.name)}),"dropdown"===n&&(0,r.jsx)(X.A,{title:t.tooltip,children:(0,r.jsx)(B.A.Text,{type:"secondary",ellipsis:!0,className:"!whitespace-nowrap text-xs !overflow-hidden text-ellipsis !max-w-40",children:"".concat(t.tooltip)})})]})]})})}var K=l(46352);let J=()=>{let{changeAspectRatio:e}=(0,g.fC)(),t=(0,s.G)(e=>e.editor.selectedAspectRatio?K.nT.find(t=>t.key===e.editor.selectedAspectRatio):K.nT[0]),l=K.nT.map((e,t)=>({key:e.key,label:(0,r.jsx)(Z,{ratio:e})})),n=async t=>{e(t.key)};return(0,r.jsx)(c.A,{menu:{items:l,selectable:!0,defaultSelectedKeys:[(null==t?void 0:t.key)||K.nT[0].key],onSelect:n},trigger:["click"],placement:"top",children:(0,r.jsx)("div",{title:"Change Aspect Ratio",className:"bg-sgray-one py-1 border-2 border-solid border-sgray-three rounded-xl",children:(0,r.jsx)(Z,{ratio:t||K.nT[0],className:"px-2 !py-0",mode:"view"})})})};function Q(){return(0,s.j)(),(0,r.jsxs)("div",{className:"flex items-center w-full py-3 bg-white px-4 md:px-0",children:[(0,r.jsxs)("div",{className:"flex-1 px-2 md:flex items-center gap-x-2 hidden",children:[(0,r.jsx)(J,{}),(0,r.jsx)(V,{})]}),(0,r.jsx)("div",{className:"flex-1 flex items-center justify-center order-1",children:(0,r.jsx)(y,{})}),(0,r.jsx)("div",{className:"md:flex-1 flex items-center justify-end md:px-6 gap-x-4 order-1",children:(0,r.jsx)(_,{})}),(0,r.jsx)("div",{className:"order-0 md:order-1",children:(0,r.jsx)(H,{})})]})}let $=e=>{let{onTimeChange:t,lineX:l,timelineHeight:n}=e;return(0,r.jsxs)(d.YJ,{draggable:!0,dragBoundFunc:e=>({x:e.x<i.Wu?i.Wu:e.x,y:0}),onDragMove:e=>{t(e.target.x())},onMouseOver:()=>{document.body.style.cursor="ew-resize"},x:l,onMouseOut:()=>{document.body.style.cursor="default"},children:[(0,r.jsx)(d.rw,{x:-5,y:0,width:10,height:n+10,fill:"transparent"}),(0,r.jsx)(d.rw,{x:-5,y:0,width:10,height:20,fill:u.Tj.dustred.six,cornerRadius:8}),(0,r.jsx)(d.N1,{points:[0,0,0,n],stroke:u.Tj.dustred.six,strokeWidth:2})]})};function ee(e){let t;return e%1==0?e:e.toFixed(1)}let et=()=>{let{duration:e,numOfIntervals:t,intervalDuration:l,dotIntervalDuration:a,totalHeight:o,getTimeByXValue:s,getXValueByTime:c,onTimeChange:h,totalWidth:m}=Y(),[f,x]=(0,n.useState)(0);(0,g.ft)(p.T.TIME_CHANGE,e=>{x(c(e,!0))});let y=[],w=[],v=e=>{h(s(e))};for(let e=0;e<=t;e++){let t=e*(i.Tn*(i.Fk+1));y.push((0,r.jsx)(d.N1,{points:[t,0,t,20],stroke:u.Tj.sgray.six,strokeWidth:1},"line-".concat(e)));let n=function(e){let t;if(e>=3600){let l=Math.floor(e/3600),r=Math.floor(e%3600/60);t=r?"".concat(l,"h ").concat(r,"m"):"".concat(l,"h")}else if(e>=60){let l=Math.floor(e/60),r=Math.floor(e%60);t=r?"".concat(l,"m ").concat(ee(r),"s"):"".concat(ee(l),"m")}else t="".concat(ee(e),"s");return t}(e*l);w.push((0,r.jsx)(d.EY,{x:t-5,y:25,text:n,fill:u.Tj.sgray.six,align:"center"},"label-".concat(e)));for(let l=1;l<=i.Fk;l++){let n=t+l*i.Tn;y.push((0,r.jsx)(d.N1,{points:[n,12,n,15],stroke:u.Tj.sgray.six,strokeWidth:2},"dot-".concat(e,"-").concat(l)))}}let j=e=>{let t=e.target.getStage();if(!t)return;let l=t.getPointerPosition();if(l){let e=l.x>=0?(null==l?void 0:l.x)-i.Wu:0;void 0!==e&&v(e)}},b=()=>{document.body.style.cursor="pointer"};return(0,r.jsxs)(d.Wd,{children:[y,w,(0,r.jsx)($,{onTimeChange:v,lineX:f,timelineHeight:o}),(0,r.jsx)(d.rw,{draggable:!0,dragBoundFunc:e=>({x:e.x<i.Wu?i.Wu:e.x,y:0}),x:0,y:0,width:m,height:40,fill:"transparent",onClick:j,onDragStart:()=>{document.body.style.cursor="ew-resize"},onDragEnd:b,onDragMove:j,onMouseOver:b,onMouseOut:()=>{document.body.style.cursor="default"}})]})},el=e=>{let{elements:t,y:l,trackWidth:n}=e;return(0,r.jsx)(d.YJ,{y:l,width:n,children:t.map(e=>(0,r.jsx)(r.Fragment,{children:(0,r.jsx)(eY,{element:e},e.id)}))})},er=e=>{let{y:t,trackWidth:l}=e;return(0,r.jsx)(d.YJ,{y:t,width:l,children:(0,r.jsx)(d.rw,{width:l,height:i.eb-10,fill:u.Tj.sgray.three})})},en=e=>new Promise((t,l)=>{let r=new window.Image;r.onload=()=>{t(r)},r.onerror=e=>{l(e)},r.src=e}),ea=e=>{let{height:t,element:l,strokeColor:a,elementRef:o,isSelected:s,opacity:c=1}
1=e,[u,h]=(0,n.useState)(void 0);(0,n.useEffect)(()=>((async()=>{try{let e=await en(l.source);h(e)}catch(e){console.error("Error loading image:",e)}})(),()=>{h(void 0)}),[l.source,o]);let m=(0,n.useMemo)(()=>(i.eb-10)/(u?u.width:1),[u]),f=(0,n.useMemo)(()=>(i.eb-10)/(u?u.height:1),[u]);return(0,r.jsx)(d.rw,{ref:o,height:t,fillPriority:"pattern",fillPatternImage:u,fillPatternRepeat:"repeat-x",fillPatternScaleX:m,fillPatternScaleY:f,stroke:a,strokeScaleEnabled:!1,cornerRadius:4,opacity:s?.8:c})};var ei=l(16964);let eo=e=>{let{position:{x:t,y:l}}=e,n=(0,ei.zh)({from:{angle:0},to:{angle:360},config:{duration:1e3,clamp:!0,mass:1},loop:!0});return(0,r.jsxs)(d.YJ,{children:[(0,r.jsx)(d.l5,{x:0,y:0,innerRadius:5,outerRadius:8,angle:360,fill:u.Tj.daybreakblue.four,opacity:.5}),(0,r.jsx)(ei.CS.Arc,{x:0,y:0,innerRadius:5,outerRadius:8,rotation:-90,angle:n.angle,fill:u.Tj.daybreakblue.seven})]})},es=e=>{let{position:t}=e;return(0,r.jsxs)(d.YJ,{x:t.x,y:t.y,children:[(0,r.jsx)(eo,{position:t}),(0,r.jsx)(d.EY,{fill:u.Tj.daybreakblue.seven,offsetX:-15,offsetY:5,text:"Generating Real Clone..."})]})},ec=e=>{let{position:t,cloneID:l}=e,n=(0,s.j)();return(0,r.jsxs)(d.YJ,{x:t.x,y:t.y,children:[(0,r.jsx)(d.EY,{text:"Oops! Real Clone Generation Failed.",fill:"Red",fontSize:16,offsetY:-5}),(0,r.jsxs)(d.YJ,{onClick:e=>{e.evt.stopPropagation(),n((0,C.yk)({id:l,failed:!0}))},offsetX:-275,onMouseOver:()=>{document.body.style.cursor="pointer"},onMouseLeave:()=>{document.body.style.cursor="default"},children:[(0,r.jsx)(d.rw,{width:80,height:25,fill:u.Tj.primary.DEFAULT,cornerRadius:4}),(0,r.jsx)(d.EY,{text:"Try Again",fill:"white",fontSize:14,offsetX:-10,offsetY:-6})]})]})},ed=e=>{let{width:t,height:l,text:n,fillColor:a,strokeColor:o,elementRef:s,isSelected:c}=e;return(0,r.jsxs)(d.YJ,{ref:s,children:[(0,r.jsx)(d.rw,{width:t,height:l,stroke:o,fill:a,strokeScaleEnabled:!1,cornerRadius:4,opacity:c?.8:1}),t>40&&(0,r.jsx)(d.EY,{text:n,width:t-50,height:i.eb/2,fill:u.Tj.magenta.seven,fontSize:12,align:"start",x:20,y:i.eb/2-15,verticalAlign:"middle",ellipsis:!0,wrap:"none",padding:5})]})};var eu=l(28541),eh=l(79512);let em="thumbnails",ef="audioWaveforms",ex=async()=>(0,eh.P2)("video-thumbnails-db",1,{upgrade(e){e.createObjectStore(em,{keyPath:"mediaId"}),e.createObjectStore(ef,{keyPath:"mediaId"})}}),eg=async(e,t,l)=>{let r=await ex(),n=await r.get(em,t);await r.put(em,{userId:e,mediaId:t,frames:l,previewFrame:null==n?void 0:n.previewFrame})},ep=async(e,t,l)=>{let r=await ex(),n=await r.get(em,t);await r.put(em,{userId:e,mediaId:t,frames:(null==n?void 0:n.frames)||[],previewFrame:l})},ey=async(e,t)=>{let l=await ex(),r=await l.get(em,t);return(null==r?void 0:r.frames)||[]},ew=async(e,t)=>{var l;let r=await ex(),n=await r.get(em,t);return(null==n||null==(l=n.frames)?void 0:l.length)?n.frames[0]:null==n?void 0:n.previewFrame},ev=async(e,t)=>{let l=await ex();await l.put(ef,{mediaId:e,waveform:t})},ej=async e=>(await ex()).get(ef,e).then(e=>null==e?void 0:e.waveform),eb=e=>{let{element:t,width:l}=e,[r,a]=(0,n.useState)(),o=(0,n.useRef)(null),s=(0,n.useMemo)(()=>Number((0,j.RT)(null==t?void 0:t.name,M.wW.DURATION)),[null==t?void 0:t.name]),c=(0,n.useMemo)(()=>(0,j.RT)(null==t?void 0:t.name,M.wW.UUID),[null==t?void 0:t.name]),d=(0,n.useCallback)(async()=>{let e=await ej(c);return!!e&&(a(await en(URL.createObjectURL(e))),!0)},[c]),h=(0,n.useCallback)(async()=>{if(!(null==t?void 0:t.source))return;let e=s*i.Tn,r=document.createElement("div");return r.setAttribute("id","audio-wave-container"),r.style.position="absolute",r.style.width="".concat(e,"px"),r.style.zIndex="-999999",document.body.appendChild(r),o.current=eu.A.create({container:r,waveColor:u.Tj.daybreakblue.four,progressColor:u.Tj.daybreakblue.four,cursorColor:"transparent",height:12,url:t.source,duration:s,width:l,minPxPerSec:l/s,fillParent:!1}),o.current.on("ready",async()=>{var e;let t=await (null==(e=o.current)?void 0:e.exportImage("image/png",1,"blob"));(null==t?void 0:t.length)&&(a(await en(URL.createObjectURL(t[0]))),ev(c,t[0])),document.body.removeChild(r)}),()=>{var e;null==(e=o.current)||e.destroy()}},[t.source,s,l,c]),m=(0,n.useCallback)(async()=>{!r&&(await d()||await h())},[r,d,h]);return(0,n.useEffect)(()=>{m()},[m]),{audioWaveImage:r}},eE=e=>{let{width:t,height:l,text:n,fillColor:a,strokeColor:o,elementRef:s,isSelected:c,element:h}=e,{audioWaveImage:m}=eb({element:h,width:t}),f=(0,j.RT)(n||"",M.wW.NAME),x=1;
1m&&(x=t/m.naturalWidth);let g=navigator.userAgent.toUpperCase().indexOf("MAC")>=0,p=localStorage.getItem("AUDIO_OFFSET")?Number(localStorage.getItem("AUDIO_OFFSET")):g?-4:-10;return(0,r.jsxs)(d.YJ,{ref:s,children:[(0,r.jsx)(d.rw,{width:t,height:l,stroke:o,fill:a,strokeScaleEnabled:!1,cornerRadius:4}),(0,r.jsx)(d.rw,{width:t,height:l,stroke:o,fill:a,strokeScaleEnabled:!1,cornerRadius:4,fillPriority:"pattern",fillPatternImage:m,fillPatternScaleX:x,fillPatternRepeat:"no-repeat",fillPatternOffsetY:p}),t>40&&(0,r.jsx)(d.EY,{text:f,width:t-50,height:i.eb/2,fill:u.Tj.daybreakblue.eight,fontSize:12,align:"start",x:24,y:i.eb/2-15,verticalAlign:"middle",ellipsis:!0,wrap:"none",padding:5})]})},ek=e=>{let{width:t,height:l,text:n="Group",fillColor:a,strokeColor:o,elementRef:s,isSelected:c}=e,h=n.includes("-")?(0,j.RT)(n,M.wW.NAME).replaceAll("-"," "):n;return(0,r.jsxs)(d.YJ,{ref:s,children:[(0,r.jsx)(d.rw,{width:t,height:l,stroke:o,fill:a,strokeScaleEnabled:!1,cornerRadius:4,opacity:c?.8:1}),h&&t>40&&(0,r.jsx)(d.EY,{text:h,width:t-50,height:i.eb/2,fill:u.Tj.daybreakblue.eight,fontSize:12,align:"start",x:24,y:i.eb/2-15,verticalAlign:"middle",ellipsis:!0,wrap:"none",padding:5})]})};var eT=l(52222);let eC=e=>{let{frame:t,index:l,endIndex:n,totalWidth:a,height:o,fillColor:s}=e,c=0===l,u=l===n-1,h=a-l*i.Tn,m=u?h:i.Tn;return(0,r.jsx)(d.rw,{width:m,height:o,fill:s,fillPriority:"pattern",fillPatternImage:t,fillPatternRepeat:u?"repeat-x":"no-repeat",fillPatternScaleX:1,fillPatternScaleY:1,x:l*i.Tn,cornerRadius:c?[4,0,0,4]:u?[0,4,4,0]:0},l)},eM=async e=>{let{videoSource:t,frameWidth:l,totalFrames:r,height:n,interval:a}=e,i=document.createElement("video");i.crossOrigin="Anonymous",i.src=t,await new Promise(e=>{i.addEventListener("loadedmetadata",e)});let o=i.duration,s=[],c=document.createElement("canvas"),d=c.getContext("2d");c.width=l,c.height=n;for(let e=0;e<r;e++){i.currentTime=Math.min(e*a,o),await new Promise(e=>{i.addEventListener("seeked",e,{once:!0})}),null==d||d.drawImage(i,0,0,l,n);let t=await new Promise(e=>{c.toBlob(e,"image/png")});s.push(t)}return s},eS=e=>{let{userId:t="",mediaId:l,element:r,width:a,height:o}
1=e,[s,c]=(0,n.useState)([]),[d,u]=(0,n.useState)(0),[h,m]=(0,n.useState)(),f=(0,n.useMemo)(()=>Number((0,j.RT)(null==r?void 0:r.name,M.wW.DURATION)),[null==r?void 0:r.name]),x=(0,n.useMemo)(()=>Math.round(i.Tn*f/Math.ceil(f)),[f]),g=e=>en(URL.createObjectURL(e)),p=(0,n.useCallback)(async()=>{let e=await ey(t,l);if(e.length){let t=await Promise.all(e.map(g));return c(t),u(a/Math.ceil(f)),t}return[]},[t,l,a,f]),y=(0,n.useCallback)(async()=>{try{let e=await eM({videoSource:r.source,frameWidth:x,totalFrames:Math.ceil(f),height:o,interval:1}),n=await Promise.all(e.map(g));await eg(t,l,e),c(n),u(a/Math.ceil(f))}catch(e){console.error("Error processing video with canvas:",e)}},[t,l,r.source,a,o,f,x]),w=(0,n.useCallback)(async()=>{(await p()).length||await y()},[p,y]);(0,n.useEffect)(()=>{w()},[w]);let v=(0,n.useCallback)(async()=>{let e=await ew(t,l);if(e)return void m(await en(URL.createObjectURL(e)));try{var n;let e=await (n=r.source,new Promise((e,t)=>{let l=document.createElement("video");function r(e,t){null==t||t.remove(),null==e||e.remove()}l.crossOrigin="Anonymous",l.src=n,l.currentTime=1,l.oncanplay=()=>{let n=document.createElement("canvas");n.width=l.videoWidth,n.height=l.videoHeight;let a=n.getContext("2d");a?(a.drawImage(l,0,0,n.width,n.height),n.toBlob(t=>{r(n,l),e(t)})):(r(n,l),t(Error("Failed to get canvas context for video preview frame")))},l.onerror=e=>{r(void 0,l),t(e)}}));if(!e)return;let a=await en(URL.createObjectURL(e));await ep(t,l,e),m(a)}catch(e){console.error("Error generating preview frame:",e)}},[r.source,l,t]);return(0,n.useEffect)(()=>{v()},[v]),{frames:s,frameWidth:d,previewFrame:h}},eR=e=>{let{frames:t,frameWidth:l,intervalDuration:r,trimStart:a}=e;return(0,n.useMemo)(()=>{if(!t.length||!l)return[];let e=r/5,n=[];for(let l=Math.max(0,Math.floor(a||0));l<t.length;l+=e){let e=Math.round(l);e>=0&&e<t.length&&n.push(t[e])}return n},[t,l,r,a])},eN=e=>{var t;let{width:l,height:a,element:o,strokeColor:c,elementRef:u,fillColor:h,isSelected:m}=e,{user:f}=(0,eT.U)(),x=(0,s.G)(O),{frames:g,frameWidth:p,previewFrame:y}=eS({userId:(null==f||null==(t=f.id)?void 0:t.toString())||"",mediaId:o.id,element:o,width:l,height:a}),w=eR({frames:g,frameWidth:p,intervalDuration:x,trimStart:o.trim_start||0}),v=(0,n.useMemo)(()=>Math.round(l/i.Tn),[l]);return(0,r.jsxs)(d.YJ,{ref:u,children:[null==w?void 0:w.map((e,t)=>t<v?(0,r.jsx)(eC,{frame:e,index:t,endIndex:v,totalWidth:l,height:a,fillColor:h},t):null),(0,r.jsx)(d.rw,{width:l,height:a,stroke:c,strokeScaleEnabled:!1,cornerRadius:4,fill:"transparent",opacity:m?.8:1,fillPriority:"pattern",fillPatternImage:w.length?void 0:y,fillPatternRepeat:"repeat-x",fillPatternScaleX:(null==y?void 0:y.width)?i.Tn/(null==y?void 0:y.width):1,fillPatternScaleY:(null==y?void 0:y.height)?a/(null==y?void 0:y.height):1})]})},eI=e=>{let{width:t,height:l,element:n,fillColor:a,strokeColor:i,elementRef:o,isSelected:s,opacity:c=1}=e;switch(n.type){case U.M.IMAGE:return(0,r.jsx)(ea,{element:n,elementRef:o,height:l,strokeColor:i,isSelected:s,opacity:c});case U.M.TEXT:return(0,r.jsx)(ed,{elementRef:o,width:t,height:l,text:n.text,fillColor:a,strokeColor:i,isSelected:s});case U.M.AUDIO:return(0,r.jsx)(eE,{elementRef:o,width:t,height:l,text:n.name,fillColor:a,strokeColor:i,isSelected:s,element:n});case U.M.COMPOSITION:return(0,r.jsx)(ek,{elementRef:o,width:t,height:l,text:n.name,fillColor:a,strokeColor:i,isSelected:s});case U.M.VIDEO:return(0,r.jsx)(eN,{width:t,height:l,element:n,strokeColor:i,elementRef:o,isSelected:s,fillColor:a});default:return(0,r.jsx)(d.rw,{ref:o,height:l,fill:a,stroke:i,strokeScaleEnabled:!1,cornerRadius:4})}},eA=e=>{let t=new window.Image;return t.src=e,t},eO={[i.MN.IMAGE]:eA("/images/icons/image.svg"),[i.MN.TEXT]:eA("/images/icons/text-height.svg"),[i.MN.VIDEO]:eA("/images/icons/video.svg"),[i.MN.AUDIO]:eA("/images/icons/file-audio.svg"),[i.MN.SHAPE]:eA("/images/icons/shapes.svg"),[i.MN.COMPOSITION]:eA("/images/icons/composition.svg")},eD=eA("/images/icons/circle-exclamation.svg"),eP=e=>{let{elementType:t,isCloneFailed:l,elementWidthBasedOnDuration:n}=e,a=l?eD:eO[t];return![i.MN.IMAGE,i.MN.VIDEO].includes(t)&&n>
120&&(0,r.jsx)(d._V,{image:a,width:14,height:14,offsetX:-6,offsetY:-10})},eL=e=>{let{element:t,trRef:l,width:n,getElementTransformBoundaries:a}=e;return(0,r.jsx)(d.Ge,{ref:l,flipEnabled:!1,rotateEnabled:!1,keepRatio:!1,anchorFill:u.Tj.syllaby.purple6,centeredScaling:!1,anchorStrokeWidth:4,anchorStroke:"transparent",enabledAnchors:["middle-left","middle-right"],borderStroke:"transparent",width:n,anchorStyleFunc:e=>{(e.hasName("middle-left")||e.hasName("middle-right"))&&(e.height(20),e.offsetY(15),e.width(4),e.cornerRadius(10),e.offsetX(3),e.offsetY(10)),e.hasName("middle-left")&&e.offsetX(1)},boundBoxFunc:(e,l)=>a(e,l,t)})};var eU=function(e){return e[e.Left=0]="Left",e[e.Middle=1]="Middle",e[e.Right=2]="Right",e}(eU||{});let eW=(e,t)=>{let{isSelected:l,lockElement:r,reDraw:n}=t,{handleDragMove:a,handleElementDragEnd:i,handleElementTransform:o,handleElementTransformEnd:s,getElementDragBoundary:c,getElementTransformBoundaries:d,onElementSelect:u,onElementDoubleClick:h,isPlaying:m}=Y();return{handleResize:t=>{o(t,e)},handleElementSelect:t=>{if(r)return;let n=2===t.evt.button;u(e,{updateTime:!1===m,isMultiSelect:t.evt.ctrlKey,isSelected:l,isRightClick:n})},handleElementDoubleClick:t=>{r||h(e,{updateTime:!1===m})},onDragMove:t=>{a&&a(t,e)},onDragEnd:async t=>{if(!i)return;let l=await i(t,e);(null==l?void 0:l.isSnapped)&&n()},handleElementTransformEnd:s,getElementDragBoundary:c,getElementTransformBoundaries:d}},eF=e=>{let{realClonesInProgress:t,realClonesFailed:l}=Y(),r=t.some(t=>{var l;return null==e||null==(l=e.name)?void 0:l.includes(t.toString())});return{isCloneProgress:r,isCloneFailed:l.some(t=>{var l;return null==e||null==(l=e.name)?void 0:l.includes(t.toString())}),realCloneID:l.find(t=>{var l;return null==e||null==(l=e.name)?void 0:l.includes(t.toString())})}},eG=(e,t)=>{let{isCloneProgress:l,isCloneFailed:r}=t,[a,o]=(0,n.useState)(null),s=a===e.id,{duration:c,getXValueByTime:d,activeElements:h}=Y(),m=l?i.MN.VIDEO:e.type,f=e.time?(0,j.IZ)(e.time):0,x=e.duration?(0,j.IZ)(e.duration):c;if(m===i.MN.AUDIO||m===i.MN.VIDEO){let t=(0,j.IZ)(e.trim_start)||0,l=(0,j.IZ)(e.trim_duration)||0;x=l>0?l:x-t}let g=d(f),p=d(x),y=r?u.Tj.dustred.one:i.uK[m].backgroundColor,w=r?u.Tj.dustred.six:i.uK[m].borderColor;return{elementType:m,startPosition:g,elementWidthBasedOnDuration:p,primaryColor:y,secondaryColor:w,isSelected:h.includes(e.id),lockElement:l||r,isHover:s,setHoveredElement:o}},eY=e=>{let{element:t}=e,l=(0,n.useRef)(null),a=(0,n.useRef)(null),o=(0,n.useRef)(null),{isCloneFailed:s,isCloneProgress:c,realCloneID:h}=eF(t),{elementType:m,isHover:f,isSelected:x,lockElement:g,startPosition:p,elementWidthBasedOnDuration:y,primaryColor:w,secondaryColor:v,setHoveredElement:j}=eG(t,{isCloneFailed:s,isCloneProgress:c});(0,n.useEffect)(function(){if(x&&o.current&&l.current){var e,t;o.current.nodes([l.current]),null==(t=o.current)||null==(e=t.getLayer())||e.batchDraw()}},[x]);let b=(0,n.useCallback)(()=>{if(y&&(0===p||p)&&a.current&&l.current){var e,t,r,n,i,s;l.current.x(p),l.current.width(y),a.current.width(y),l.current.scaleX(1),l.current.scaleY(1),a.current.scaleX(1),a.current.scaleY(1),l.current.y(0),o.current&&(o.current.width(y),o.current.height(l.current.height()),null==(s=o.current)||null==(i=s.getLayer())||i.batchDraw()),null==(t=l.current)||null==(e=t.getLayer())||e.batchDraw(),null==(n=a.current)||null==(r=n.getLayer())||r.batchDraw()}},[y,p]);(0,n.useEffect)(()=>{b()},[b]);let{getElementDragBoundary:E,getElementTransformBoundaries:k,handleElementSelect:T,handleElementDoubleClick:C,handleElementTransformEnd:M,handleResize:S,onDragEnd:R,onDragMove:N}=eW(t,{isSelected:x,lockElement:g,reDraw:b});return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(d.YJ,{ref:l,onMouseEnter:()=>{j(t.id),document.body.style.cursor="pointer"},onMouseLeave:()=>{j(null),document.body.style.cursor="auto"},onClick:T,onTap:T,onDblClick:C,onDblTap:C,draggable:!g,dragBoundFunc:e=>E(e,l),onDragStart:e=>{T(e),document.body.style.cursor="grabbing"},onDragEnd:R,onDragMove:N,onTransform:S,onTransformEnd:e=>M(e,t),y:0,children:[(0,r.jsx)(eI,{element:t,elementRef:a,width:y,height:i.eb-10,strokeColor:x||f?u.Tj.syllaby.purple6:v,isSelected:x,fillColor:w,opacity:c?.4:1}),c&&(0,r.jsx)(es,{position:{x:p+50,y:i.eb/2-5}}),s&&h&&(0,r.jsx)(ec,{position:{x:p+40,y:i.eb/2-18},cloneID:h}),(0,r.jsx)(eP,{elementType:m,isCloneFailed:s,elementWidthBasedOnDuration:y})]}),x&&!g&&(0,r.jsx)(eL,{element:t,trRef:o,width:y,getElementTransformBoundaries:k})]})},e_=e=>{let{config:t}=e;return({[M.Kj.START]:[[t.x,20,t.x,(null==t?void 0:t.height)||i.eb]],[M.Kj.END]:[[t.width,20,t.width,
1(null==t?void 0:t.height)||i.eb]],[M.Kj.BOTH]:[[t.x,20,t.x,(null==t?void 0:t.height)||i.eb],[t.width,20,t.width,(null==t?void 0:t.height)||i.eb]]})[t.placement].map((e,t)=>(0,r.jsx)(d.N1,{stroke:u.Tj.dustred.six,strokeWidth:2,points:e,dash:[5,3]},t))},eX=()=>{let[e,t]=(0,n.useState)([]);return(0,g.ft)(p.T.GUIDELINES,e=>{t(e)}),e.map((e,t)=>(0,r.jsx)(e_,{config:e},t))},eq=e=>{let{width:t}=e,[l,a]=(0,n.useState)(null);if((0,g.ft)(p.T.TRACK_GUIDELINE,e=>{a(e)}),null!==l)return(0,r.jsx)(d.N1,{stroke:u.Tj.daybreakblue.six,strokeWidth:2,points:[0,l,t,l]})};function eV(){(0,d.eD)(!0);let{timelineContainerRef:e,stageRef:t,layerRef:l,totalHeight:n,totalWidth:a,contextMenuItems:o,tracks:s}=Y();return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(Q,{}),(0,r.jsx)("div",{ref:e,className:"bg-white w-full overflow-auto h-full",children:a&&a>0&&(0,r.jsx)(c.A,{menu:{items:o,onContextMenu:e=>{}},onOpenChange:e=>{},trigger:["contextMenu"],children:(0,r.jsx)("div",{children:(0,r.jsxs)(d.BI,{ref:t,style:{background:u.Tj.sgray.one,padding:"0.5rem 1rem",minHeight:"100%"},dragDistance:5,width:a,height:n,x:i.Wu,children:[(0,r.jsxs)(d.Wd,{ref:l,y:20,children:[(0,r.jsx)(eq,{width:a}),s.map((e,t)=>{let[l]=e;return(0,r.jsx)(er,{y:(t+1)*40,trackWidth:a},l)}),s.map((e,t)=>{let[l,n]=e;return(0,r.jsx)(el,{y:(t+1)*40,elements:n,trackWidth:a},l)}),(0,r.jsx)(eX,{})]}),(0,r.jsx)(et,{})]})})})})]})}function eH(){return(0,r.jsx)(G,{children:(0,r.jsx)(eV,{})})}let ez=(0,a.default)(()=>Promise.all([l.e(2659),l.e(209),l.e(4557),l.e(5595)]).then(l.bind(l,61182)).then(e=>({default:e.CanvasEditor})),{loadableGenerated:{webpack:()=>[61182]},ssr:!1,loading:()=>(0,r.jsx)("div",{className:"flex items-center justify-center h-64",children:"Loading canvas editor..."})});function eB(){let[e,t]=(0,n.useState)(!1),l=(0,s.G)(e=>e.editor.showElementsPanel),a=(0,s.G)(e=>e.editor.isLoaded);return(0,r.jsx)("section",{className:"min-sm:px-3 px-0 pb-7 rounded-xl flex-1 flex gap-5 relative",children:(0,r.jsx)("div",{className:"w-full h-[calc(98vh-70px)] flex flex-row gap-x-5",children:(0,r.jsxs)("div",{className:"flex flex-col w-full flex-1 justify-center items-center",children:[(0,r.jsx)("div",{className:"w-full flex-1",children:(0,r.jsx)(ez,{disableEditor:e})}),a&&(0,r.jsx)("div",{className:"fixed bottom-0 ".concat(l?"w-[calc(100vw-500px)]":"w-[calc(100vw-120px)]"," ").concat(l?"left-[500px]":"left-[118px]"," max-md:left-0 max-md:w-full"),children:(0,r.jsx)(o.hs,{onResize:(e,l)=>{t(l)},minHeight:i.RA,maxHeight:i.X2,children:(0,r.jsx)(eH,{})})})]})})})}let eZ=eB}}]);
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.