animaquill 0.3.34 → 0.3.35

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -212,4 +212,4 @@ aq.sound(({ frames, sampleRate }) => {
212
212
  `,Vde=1.5;function Hde(e,t){return{sound:{name:e,entry:`sound.js`,runtime:1,params:[{id:`duration`,name:t.duration,type:`number`,default:Vde,min:.05,max:300},{id:`seed`,name:t.seed,type:`number`,default:1}]},files:{"sound.js":Bde}}}var Ude=6,Wde=32,Gde=24,u4=7,Kde=16,qde=10,d4=8,f4=48,Jde=.95,Yde=.8,Xde=240,p4=1.5,m4=.6,h4=3,g4=1.25,Zde=7,Qde=10,$de=300,efe=5,_4=96,v4=360,y4=[`#3f6fb5`,`#3f9a7a`,`#b57a3f`,`#8f5fb5`,`#b5536a`,`#5f8fa8`];function tfe(e,t,n){let r=Math.min(n,t/3),i=Math.max(e,0)+Math.max(Ude,r+1);return t>=Wde&&i+14<=e+t-r?i:void 0}var nfe=({track:e})=>e.name===void 0?{}:{name:e.name};function rfe(e,t){return{kind:t,number:e.rows.filter(({track:e,gone:n})=>e.kind===t&&!n).length+1}}var b4=e=>e!==void 0&&`join`in e,x4=40;function S4(e,t,n){let r=Math.max(t,1/n),i=Math.max(e,1)*Yde/r,a=n*Xde;return[Math.min(i,a),a]}function ife(e){if(e!==void 0)try{let t=JSON.parse(e),{pixelsPerSecond:n,scrollX:r,scrollY:i,frame:a}=t;return[n,r,i,a].every(e=>Number.isFinite(e)&&e>=0)?t:void 0}catch{return}}var C4=`timeline`,w4=1;function T4(e){if(typeof e!=`object`||!e)return;let{version:t,snapping:n,overwriting:r,multiSelecting:i,headerWidth:a}=e;if(t===w4&&typeof n==`boolean`&&typeof r==`boolean`)return{version:t,snapping:n,overwriting:r,multiSelecting:i===!0,headerWidth:typeof a==`number`?a:148}}var E4=(e,t,n)=>Math.min(Math.max(e,t),Math.max(t,n)),D4=(e,t)=>e.pixelsPerSecond===t.pixelsPerSecond&&e.scrollX===t.scrollX,O4=(e,t)=>e.size===t.size&&[...e].every(e=>t.has(e)),afe=class{#e;#t;#n;#r;#i=new sv;#a=new sv;#o=new sv;#s=new sv;#c=new sv;#l;#u;#d;#f={model:void 0,selection:new Set,transition:void 0,tool:`select`,snapping:!0,overwriting:!1,multiSelecting:!1,playing:!1,headerWidth:148,cut:new Set};#p=[];#m=[];#h;#g;#_;#v;#y={kind:`empty`};#b;#x=0;#S;#C=u4;#w;#T=0;#E=1;#D=0;#O=0;#k=0;#A=0;#j;#M;#N=Z$;#P;#F;constructor(e,t,n,r){this.#e=e,this.#t=t,this.#n=n,this.#r=r,e.subscribe(()=>this.#J()),this.#J()}async load(){let e=await xX(this.#n,C4,T4);e.kind===`ok`&&this.#I(e.value),this.#n.listen(C4,e=>{let t=T4(e);t&&this.#I(t)})}#I(e){let{snapping:t,overwriting:n,multiSelecting:r}=e,i=E4(e.headerWidth,_4,v4);this.#f={...this.#f,snapping:t,overwriting:n,multiSelecting:r,headerWidth:i},this.#i.emit()}#L(){let{snapping:e,overwriting:t,multiSelecting:n,headerWidth:r}=this.#f,i={version:w4,snapping:e,overwriting:t,multiSelecting:n,headerWidth:r};this.#n.save(C4,i).catch(e=>console.warn(`Timeline settings could not be saved`,e))}subscribe=this.#i.subscribe;getSnapshot=()=>this.#f;subscribeView=this.#a.subscribe;subscribeCopies=this.#o.subscribe;subscribeChoices=this.#s.subscribe;get model(){return this.#f.model}get frame(){return this.#x}get pixelsPerSecond(){return this.#T}get scrollX(){return this.#D}get scrollY(){return this.#O}get width(){return this.#k}get height(){return this.#A}get holdsDrag(){return this.preview!==void 0||this.#M?.holdsDrag===!0}get preview(){return this.#v}get extras(){return this.#M}setExtras(e){this.#M=e}setRoomBelow(e){e.size===this.#N.size&&[...e].every(([e,t])=>this.#N.get(e)===t)||(this.#N=e,this.#Y(),this.#U())}redraw(){this.#a.emit()}get hovered(){return this.#y}get razorAt(){return this.#b}get visibleDuration(){return this.#v?.end??this.model?.duration??0}get contentWidth(){let e=this.visibleDuration;for(let{end:t}of this.#v?.clips?.values()??[])e=Math.max(e,t);return Math.max(e*1.25*this.#T,this.#k)}get contentHeight(){return Math.max((this.model?.height??0)+28+f4,this.#A)}xAt(e){return e*this.#T-this.#D}timeAt(e){return(e+this.#D)/this.#T}laneAt(e){return e-28+this.#O}setViewport(e,t){(e!==this.#k||t!==this.#A)&&(this.#k=e,this.#A=t,e===0&&this.#Me(),this.#T===0&&e>0&&this.#H(),this.#U(),this.#G())}setScroll(e,t){(e!==this.#D||t!==this.#O)&&(this.#D=e,this.#O=t,this.#U(),this.#G())}zoomAround(e,t){if(this.#T===0)return;let n=this.timeAt(e);this.#T=this.#B(this.#T*t),this.#D=n*this.#T-e,this.#U(),this.#G()}zoomIn(){this.zoomAround(this.#V(),p4)}zoomOut(){this.zoomAround(this.#V(),1/p4)}get rowScale(){return this.#E}zoomRowsAround(e,t){if(this.#_)return;let n=E4(this.#E*t,m4,h4),r=n/this.#E;if(r===1)return;let i=this.laneAt(e);this.#E=n,this.#Y(),this.#O=i*r-(e-28),this.#U(),this.#G()}rowsTaller(){this.zoomRowsAround(28,g4)}rowsShorter(){this.zoomRowsAround(28,1/g4)}get isSnappedToPlayhead(){let{model:e,preview:t}=this;return!e||t?.snap===void 0?!1:Math.abs(t.snap-dq(this.#x,e.rate))<1e-9}zoomToFit(){if(this.#k===0)return;let e=this.#R(),t=this.#w;this.#w=void 0,t&&D4(t.fitted,e)?(this.#T=this.#B(t.from.pixelsPerSecond),this.#D=t.from.scrollX):(this.#H(),this.#D=0),this.#U();let n=this.#R();(!t&&!D4(e,n)||t&&!D4(t.fitted,e))&&(this.#w={from:e,fitted:n}),this.#G()}#R(){return{pixelsPerSecond:this.#T,scrollX:this.#D}}setTouchInput(e){this.#C=e?Kde:u4,this.#M?.setTouchInput(e)}get zoomLevel(){let[e,t]=this.#z();return this.#T===0||t<=e?0:E4(Math.log(this.#T/e)/Math.log(t/e),0,1)}setZoomLevel(e){let[t,n]=this.#z(),r=t*(n/t)**E4(e,0,1);this.zoomAround(this.#V(),r/this.#T)}#z(){let{model:e}=this;return S4(this.#k,e?.duration??1,e?.rate.fps??30)}#B(e){let[t,n]=this.#z();return E4(e,t,n)}#V(){let{model:e}=this;if(!e)return 0;let t=this.xAt(dq(this.#x,e.rate));return t>=0&&t<=this.#k?t:this.#k/2}#H(){let e=Math.max(this.model?.duration??0,1);this.#T=this.#B(this.#k*Jde/e)}#U(){this.#D=E4(this.#D,0,this.contentWidth-this.#k),this.#O=E4(this.#O,0,this.contentHeight-this.#A)}#W(e){let t=this.xAt(e),n=Math.min(f4,this.#k/4);t<n?this.#D+=t-n:t>this.#k-n&&(this.#D+=t-(this.#k-n)),this.#U()}#G(){this.#a.emit(),this.#K()}#K(){clearTimeout(this.#j),this.#j=setTimeout(()=>this.#q(),$de)}flush(){clearTimeout(this.#j),this.#q()}#q(){let e=this.#h&&JG(this.#h);if(e===void 0||this.#T===0)return;let t={rowScale:this.#E,pixelsPerSecond:this.#T,scrollX:this.#D,scrollY:this.#O,frame:this.#x};this.#t.write(`timeline.${e}`,JSON.stringify(t))}#J(){let{store:e}=this.#e;if(e===this.#h)return;this.#q(),this.#g?.(),this.#Me(),this.#h=e,this.#g=e?.subscribe(()=>this.#Y());let t=e?ife(this.#t.read(`timeline.${JG(e)}`)):void 0;this.#T=t?.pixelsPerSecond??0,this.#E=E4(t?.rowScale??1,m4,h4),this.#D=t?.scrollX??0,this.#O=t?.scrollY??0,this.#x=t?.frame??0,this.#f={...this.#f,selection:new Set,transition:void 0,cut:new Set},this.#p=[],this.#m=[],this.#w=void 0,this.pause(),this.#Y(),this.#T===0&&this.#k>0&&this.#H(),this.#U(),this.#a.emit()}#Y(){let e=this.model,t=this.#X();e&&t&&e.fps!==t.fps&&(this.#x=cq(dq(this.#x,e.rate),t.rate));let n=new Set(this.#Q(this.#f.selection,t)),r=O4(n,this.#f.selection),i=new Set(this.#$(this.#f.cut,t)),a=this.#f.transition,o=a&&(b4(a)?t?.joins.has(a.join)===!0:t?.boxes.get(a.clip)?.clip[a.edge]!==void 0);this.#f={...this.#f,model:t,selection:r?this.#f.selection:n,transition:o?a:void 0,cut:O4(i,this.#f.cut)?this.#f.cut:i},t&&(this.#x=Math.min(this.#x,cq(t.duration,t.rate))),t&&this.#_?.isStale?.(t)&&this.#Me(),this.#i.emit(),this.#a.emit()}#X(){let e=this.#h?.getState();if(!e)return;let t=e.manifest.timelines?.find(t=>e.timelines[t]),n=t===void 0?void 0:e.timelines[t];if(t===void 0||!n)return;let r=AA(e.manifest),i=this.model;return i?.id===t&&i.state===n&&i.assets===e.assets&&i.fps===r&&i.rowScale===this.#E&&i.roomBelow===this.#N?i:o1(t,n,r,this.#E,this.#N,e)}#Z(e){let t=this.#h;if(!t)return!1;let n=t.executeBatch(e);if(!n.ok)return this.#r.commandFailed(n.error.message),!1;let r=n.results.flatMap(e=>e?.joinsRemoved??[]);return r.length>0&&this.#r.joinsRemoved?.(r.length),!0}setTool(e){e!==this.#f.tool&&(this.#f={...this.#f,tool:e},this.#b=void 0,this.#i.emit(),this.#a.emit())}toggleSnapping(){this.#f={...this.#f,snapping:!this.#f.snapping},this.#i.emit(),this.#L()}toggleOverwriting(){this.#f={...this.#f,overwriting:!this.#f.overwriting},this.#i.emit(),this.#L()}toggleMultiSelecting(){let e=!this.#f.multiSelecting;this.#f={...this.#f,multiSelecting:e},this.#i.emit(),this.#L()}setHeaderWidth(e){let t=E4(Math.round(e),_4,v4);t!==this.#f.headerWidth&&(this.#f={...this.#f,headerWidth:t},this.#i.emit())}saveHeaderWidth(){this.#L()}#Q(e,t){return[...e].filter(e=>t?.boxes.has(e)===!0)}#$(e,t){return this.#Q(e,t).filter(e=>t?.rowOfClip.get(e)?.track.locked!==!0)}get canChangeSelection(){let{selection:e,transition:t}=this.#f;if(b4(t)){let e=this.model?.joins.get(t.join);return e!==void 0&&this.model?.state.tracks[e.join.track]?.locked!==!0}return t?this.#$([t.clip],this.model).length>0:this.#$(e,this.model).length>0}get canCut(){return this.#$(this.#f.selection,this.model).length>0}#ee(e){this.#te(e),this.#s.emit()}#te(e){let t=new Set(this.#Q(e,this.model)),{transition:n}=this.#f;(!O4(t,this.#f.selection)||n)&&(this.#f={...this.#f,selection:t,transition:void 0},this.#i.emit(),this.#a.emit())}selectTransition(e,t){if(this.model?.boxes.get(e)?.clip[t]===void 0)return;let{transition:n,selection:r}=this.#f;(!n||b4(n)||n.clip!==e||n.edge!==t||r.size!==0)&&(this.#f={...this.#f,selection:new Set,transition:{clip:e,edge:t}},this.#i.emit(),this.#a.emit())}selectJoin(e){if(!this.model?.joins.has(e))return;let{transition:t,selection:n}=this.#f;b4(t)&&t.join===e&&n.size===0||(this.#f={...this.#f,selection:new Set,transition:{join:e}},this.#i.emit(),this.#a.emit())}revealClip(e,t){let n=this.model,r=t?.join===void 0?void 0:n?.joins.get(t.join),i=n?.boxes.get(e)??r?.from;if(!n||!i&&!r)return!1;r&&t?.join!==void 0?this.selectJoin(t.join):i&&t?.edge!==void 0&&i.clip[t.edge]!==void 0?this.selectTransition(i.id,t.edge):i&&this.selectOnly(i.id);let a=r?r.start:i?.start??0;this.seek(cq(a,n.rate));let o=i&&n.rowOfClip.get(i.id);return o&&(o.top<this.#O?this.#O=o.top:o.top+o.height>this.#O+this.#A&&(this.#O=o.top+o.height-this.#A),this.#U(),this.#G()),!0}addToSelection(e){this.#ee(new Set([...this.#f.selection,...this.#Ae(new Set([e]))]))}selectOnly(e){this.#ee(this.#Ae(new Set([e])))}selectClipsOfKeys(e){this.#te(this.#Ae(new Set(e)))}selectAll(){let{model:e}=this;this.#ee(new Set(this.#$(e?.boxes.keys()??[],e)))}clearSelection(){this.#ee(new Set)}togglePlayback(){let{model:e}=this;e&&(this.#f.playing?this.pause():(this.#x>=cq(e.duration,e.rate)&&this.seek(0),this.#S=void 0,this.#ne(!0)))}pause(){this.#f.playing&&this.#ne(!1)}#ne(e){this.#f={...this.#f,playing:e},this.#i.emit()}get playbackStart(){return this.#S}tick(e){let{model:t}=this;if(!t||!this.#f.playing)return;this.#S??={frame:this.#x,since:e};let{frame:n,since:r}=this.#S,i=n+(e-r)/1e3*t.rate.fps,a=cq(t.duration,t.rate);this.#re(Math.min(i,a)),i>=a&&this.pause()}seek(e){this.#S=void 0,this.#re(e)}#re(e){let t=this.model;if(!t)return;let n=cq(this.visibleDuration,t.rate),r=E4(Math.round(e),0,Math.max(n,0));r!==this.#x&&(this.#x=r,this.#W(dq(r,t.rate)),this.#G())}stepFrames(e){this.seek(this.#x+e)}seekToStart(){this.seek(0)}seekToEnd(){let{model:e}=this;e&&this.seek(cq(e.duration,e.rate))}jumpToEdit(e){let{model:t}=this;if(!t)return;let n=[0,cq(t.duration,t.rate)];for(let e of t.boxes.values())n.push(cq(e.start,t.rate),cq(e.end,t.rate));let r=n.filter(t=>(t-this.#x)*e>0);r.length!==0&&this.seek(e>0?Math.min(...r):Math.max(...r))}deleteSelection(){let{model:e}=this,{transition:t}=this.#f;if(b4(t)){this.removeJoin(t.join);return}if(t){this.setTransition(t.clip,t.edge,null);return}let n=this.#$(this.#f.selection,e);e&&n.length!==0&&this.#Z([{type:`clip.remove`,params:{timeline:e.id,clips:n}}])}get hasClipboard(){return this.#p.length>0}copySelection(){this.#ie(this.#f.selection)}#ie(e){let{model:t}=this,n=[...e].flatMap(e=>t?.boxes.get(e)??[]);n.length!==0&&(this.#p=n.map(({clip:e})=>e),this.#m=t?R1(t,this.#p.map(({id:e})=>e)):[],this.#ae(new Set),this.#o.emit())}forgetClipboard(){(this.#p.length!==0||this.#f.cut.size!==0)&&(this.#p=[],this.#m=[],this.#ae(new Set))}cutSelection(){let e=new Set(this.#$(this.#f.selection,this.model));e.size!==0&&(this.#ie(e),this.#ae(e))}cancelCut(){return this.#f.cut.size!==0&&(this.#p=[],this.#m=[],this.#ae(new Set),!0)}#ae(e){this.#f={...this.#f,cut:e},this.#i.emit(),this.#a.emit()}paste(){let{model:e}=this,[t]=this.#p.toSorted((e,t)=>D(Q(e),Q(t)));if(!e||!t)return;let{cut:n}=this.#f,r=B1(this.#p),i=lq(this.#x,e.rate),a=k(i,Q(t)),o=new Map,s=t=>e.rows.find(({id:e,track:n,gone:r})=>e===t.track&&!n.locked&&!r)??e.rows.find(({track:e,gone:n})=>e.kind===RA(t)&&!e.locked&&!n),c=this.#p.flatMap(e=>{let t=s(e),n=O(u(Q(e),a)),r=O(u(jA(e),a));return t?[{row:t,start:n,end:r,exactStart:()=>u(Q(e),a),exactEnd:()=>u(jA(e),a)}]:[]}),{overwriting:l}=this.#f,d=l?void 0:S1(c,n,1),f=d?u(a,d.exact()):a,p=[],m=this.#p.map((t,i)=>{let a=RA(t),c=s(t)?.id??o.get(a);c||(c=xD(`track`),o.set(a,c),p.push({type:`track.add`,params:{timeline:e.id,id:c,kind:a}}));let d=r[i];return{type:`clip.add`,params:{timeline:e.id,track:c,clip:{...d,start:ze(u(Q(t),f))},...l?{overlap:`overwrite`}:{},...n.has(t.id)?{movedFrom:t.id}:{}}}}),h=n.size>0?[{type:`clip.remove`,params:{timeline:e.id,clips:[...n]}}]:[],g=this.#p.map(({id:e})=>e),_=z1(e.id,this.#m,g,r);this.#Z([...h,...p,...m,..._])&&(this.#ae(new Set),this.#ee(new Set(r.map(({id:e})=>e))))}#oe(e){let t=dq(this.#x,e.rate),n=lq(this.#x,e.rate);return e.rows.flatMap(e=>{let r=e.track.locked?void 0:f1(e,t);return r&&this.#f.selection.has(r.id)&&c1(r.clip,n)?[r]:[]})}get canSplit(){return this.model!==void 0&&this.#oe(this.model).length>0}splitAtPlayhead(){let{model:e}=this;if(!e)return;let t=new Set,n=ze(lq(this.#x,e.rate)),r=this.#oe(e).flatMap(r=>{let{link:i}=r.clip;return i!==void 0&&t.has(i)?[]:(i!==void 0&&t.add(i),[A1(e,r.clip,n)])});r.length>0&&this.#Z(r)}setEnd(e){let{model:t}=this,n=t&&kA(t.state).at(-1);if(!t||!n)return;let r=k(IA(t.state),j(n.duration)),i=lq(e,t.rate),a=[u(r,lq(1,t.rate))];for(let{clip:e}of t.boxes.values())a.push(jA(e));for(let e of a)D(e,i)>0&&(i=e);let o=ze(k(i,r));if(o===n.duration)return;let s={timeline:t.id,section:n.id,duration:o};this.#Z([{type:`section.update`,params:s}])}addAsset(e,t){return this.addMedia({kind:`asset`,id:e},t)}addScene(e,t){return this.addMedia({kind:`scene`,id:e},t)}addSound(e,t){return this.addMedia({kind:`sound`,id:e},t)}addMedia(e,t){let{model:n}=this,r=n&&this.#ce(n,e,[]);if(n&&r)return this.#fe(n,r,t??`free`)}createScene(e){let{model:t}=this,n=this.#h?.getState();if(!t||!n)return;let r=Object.keys(n.scenes).length+1,i=this.#r.sceneName?.(r)??`Scene ${r}`,a=xD(`scene`),o=[{type:`scene.add`,params:{id:a,...zde(i)}}],s=this.#le(t,{kind:`scene`,scene:a},i,o);return this.#fe(t,s,e??`playhead`)}createSound(e){let{model:t}=this,n=this.#h?.getState();if(!t||!n)return;let r=Object.keys(n.sounds).length+1,i=this.#r.soundName?.(r)??`Sound ${r}`,a=this.#r.soundWords?.()??{duration:`Length`,seed:`Seed`},o=xD(`sound`),s=[{type:`sound.add`,params:{id:o,...Hde(i,a)}}],c=this.#le(t,{kind:`sound`,sound:o},i,s);return this.#fe(t,c,e??`playhead`)}dropPlaceAt(e){return{lane:this.laneAt(e.y),seconds:this.timeAt(e.x),snap:this.#se(e)}}#se(e){return this.#f.snapping&&!e.alt&&this.#T>0?d4/this.#T:0}#ce(e,t,n){let r=this.#h?.getState();if(!r)return;if(t.kind===`scene`){let i=r.scenes[t.id];return i&&this.#le(e,{kind:`scene`,scene:t.id},i.name,n)}if(t.kind===`sound`){let i=r.sounds[t.id];return i&&this.#le(e,{kind:`sound`,sound:t.id},i.name,n)}let i=r.assets?.[t.id];if(!i)return;let a=i.info?.duration,o=a?Math.floor(O(j(a))*e.rate.fps):0,s=o>0?lq(o,e.rate):this.#ve(e),c={asset:t.id};return{parts:[...i.kind===`audio`?[]:[{kind:`video`,source:{kind:i.kind,media:c}}],...i.kind===`audio`||i.info?.hasAudio?[{kind:`audio`,source:{kind:`audio`,media:c}}]:[]],duration:s,before:n,...i.name===void 0?{}:{name:i.name}}}#le(e,t,n,r){let i=t.kind===`sound`?this.#ue(e,t.sound,r):void 0;return{parts:[{kind:t.kind===`sound`?`audio`:`video`,source:t}],duration:i?.duration??this.#ve(e),name:n,before:r,...i?.properties&&{properties:i.properties}}}#ue(e,t,n){let r=(n.flatMap(({type:e,params:t})=>e===`sound.add`?[t.sound]:[])[0]??this.#h?.getState().sounds[t])?.params?.find(({id:e})=>e===`duration`)?.default;if(typeof r==`number`&&r>0)return{duration:lq(Math.max(Math.floor(r*e.rate.fps),1),e.rate)};let i=this.#ve(e);return{duration:i,properties:{"param.duration":O(i)}}}#de(e,t,n){let{rate:r}=e,i=typeof n==`object`?n:void 0,a=n===`free`,o=Math.max(i?.seconds??dq(this.#x,r),0),s=lq(cq(o,r),r),c,l=i?.snap??0;if(l>0){let n=m1(e,this.#x,new Set),r=O(t.duration),i=n.nearest(o,l),a=n.nearest(o+r,l),u=i?Math.abs(i.seconds-o):1/0,d=a?Math.abs(a.seconds-o-r):1/0;a&&d<u&&D(a.exact(),t.duration)>=0?(s=k(a.exact(),t.duration),c=a.seconds):i&&(s=i.exact(),c=i.seconds)}let d=u(s,t.duration),f=t.parts.map(t=>({...t,row:a?this.#me(e,t.kind,s,d):this.#he(e,t.kind,i?.lane)})),p=f.flatMap(({row:e})=>e?[{row:e,start:O(s),end:O(d),exactStart:()=>s,exactEnd:()=>d}]:[]),m=!a&&this.#f.overwriting,h=m||a?void 0:S1(p,new Set,1),g=h?u(s,h.exact()):s;return h&&h.seconds>0&&(c=h.contact),{parts:f,at:g,duration:t.duration,overwriting:m,...c===void 0?{}:{line:c}}}#fe(e,t,n){let r=this.#de(e,t,n),i=r.parts.length>1?{link:xD(`link`)}:{},a=[],o=[],s=[],c=r.parts.map(({kind:n,source:c,row:l})=>{let u=l?.id;u||(u=xD(`track`),a.push({type:`track.add`,params:{timeline:e.id,id:u,kind:n}})),s.push(l?{kind:n,number:l.number,...nfe(l)}:rfe(e,n));let d=xD(`clip`);return o.push(d),{type:`clip.add`,params:{timeline:e.id,track:u,clip:{id:d,...t.name===void 0?{}:{name:t.name},start:ze(r.at),duration:ze(r.duration),source:c,...t.properties&&{properties:t.properties},...i},...r.overwriting?{overlap:`overwrite`}:{}}}});if(!this.#Z([...t.before,...a,...c]))return;this.#ee(new Set(o));let l=O(r.at),d=O(u(r.at,r.duration));return this.#pe(l,d,o),this.flash({clips:new Set(o)}),{clips:o,tracks:s,start:l,frame:cq(l,e.rate)}}showDrop(e,t){let{model:n}=this;if(!n)return;let r=e&&t?this.#ce(n,t,[]):void 0;if(e&&r){let t=this.#de(n,r,this.dropPlaceAt(e)),i=O(t.at),a=O(u(t.at,t.duration)),o=[],s=t.parts.map(({kind:e,row:n})=>(n&&t.overwriting&&d1(n,i,a,e=>{let t=Math.max(i,e.start),r=Math.min(a,e.end);r>t&&o.push({row:n,from:t,to:r})}),{kind:e,row:n?.id,start:i,end:a,label:r.name??``}));this.#v={adding:s,covered:o,...t.line===void 0?{}:{snap:t.line}},this.#a.emit();return}let i=e&&dq(cq(this.timeAt(e.x),n.rate),n.rate);this.#v=i===void 0?void 0:{snap:Math.max(i,0)},this.#a.emit()}#pe(e,t,n){let r=this.model;if(!r||this.#k===0||this.#T===0)return;let i=this.#D,a=this.#O,o=this.xAt(e);(this.xAt(t)<0||o>this.#k)&&(i=(e+t)/2*this.#T-this.#k/2);let s=n.flatMap(e=>{let t=r.rowOfClip.get(e);return t?[t]:[]})[0];if(s){let e=this.#A-28,t=s.top-this.#O;(t+s.height<=0||t>=e)&&(a=s.top+s.height/2-e/2)}this.setScroll(i,a)}#me(e,t,n,r){let i=e=>e.track.kind===t&&!e.track.locked&&!e.gone,a=O(n),o=O(r),s=e=>{let t=!1;return d1(e,a-1e-6,o+1e-6,({clip:e})=>{D(Q(e),r)<0&&D(jA(e),n)>0&&(t=!0)}),!t},c=new Set;for(let t of this.#f.selection){let n=e.boxes.get(t)?.clip.track;n!==void 0&&c.add(n)}let l=e.rows.filter(e=>c.has(e.id)&&i(e)),u=e.rows.filter(i).toSorted((e,t)=>e.number-t.number);return[...l,...u].find(s)}#he(e,t,n){let r=e=>e!==void 0&&e.track.kind===t&&!e.track.locked&&!e.gone,i=n===void 0?void 0:l1(e,n);return r(i)?i:e.rows.filter(r).toSorted((e,t)=>e.number-t.number)[0]}#ge(e,t){return e.rows.filter(({track:e,gone:n})=>e.kind===t&&!n)}trackDrop(e,t){let{model:n}=this,r=n?.rows.find(({id:t})=>t===e);if(!n||!r)return{index:0,line:0};let i=this.#ge(n,r.track.kind).filter(({id:t})=>t!==e),a=i.filter(({top:e,height:n})=>e+n/2<t).length,o=i[a],s=i[a-1];return{index:a,line:o?o.top:s?s.top+s.height:r.top}}moveTrack(e,t){let{model:n}=this,r=n?.rows.find(({id:t})=>t===e);if(!n||!r)return;let i=this.#ge(n,r.track.kind);if(i.indexOf(r)===t)return;let a=i.filter(({id:t})=>t!==e),o=r.track.kind!==`audio`,s=(o?a.toReversed():a)[o?a.length-t:t],c={timeline:n.id,track:e,...s?{before:s.id}:{}};this.#Z([{type:`track.move`,params:c}])}shiftTrack(e,t){let{model:n}=this,r=n?.rows.find(({id:t})=>t===e);if(!n||!r)return;let i=this.#ge(n,r.track.kind),a=i.indexOf(r)+t;a>=0&&a<i.length&&this.moveTrack(e,a)}addTrack(e){let{model:t}=this;t&&this.#Z([{type:`track.add`,params:{timeline:t.id,kind:e}}])}removeTrack(e){let{model:t}=this;t&&t.state.tracks[e]?.locked!==!0&&this.#Z([{type:`track.remove`,params:{timeline:t.id,track:e}}])}updateTrack(e,t){let{model:n}=this;n&&this.#Z([{type:`track.update`,params:{timeline:n.id,track:e,changes:t}}])}addColorClip(e){let{model:t}=this;if(!t)return;let{rate:n}=t,r=lq(cq(e?.seconds??dq(this.#x,n),n),n),i=(e?[e.row]:this.#_e(t)).find(e=>this.#ye(e,r,t)!==void 0);if(e&&!i)return;let a=xD(`clip`),o=i?.id??xD(`track`),s=(i&&this.#ye(i,r,t))??this.#ve(t),c=y4[t.boxes.size%y4.length];this.#Z([...i?[]:[{type:`track.add`,params:{timeline:t.id,id:o,kind:`video`}}],{type:`clip.add`,params:{timeline:t.id,track:o,clip:{id:a,start:ze(r),duration:ze(s),source:{kind:`color`,color:c}}}}])&&(this.#ee(new Set([a])),this.seek(cq(O(u(r,s)),n)))}#_e(e){return e.rows.filter(({track:e,gone:t})=>e.kind===`video`&&!e.locked&&!t).toSorted((e,t)=>e.number-t.number)}#ve({rate:e}){return lq(cq(efe,e),e)}#ye(e,t,n){if(e.track.locked)return;let r=this.#ve(n),i=u1(e,O(t));for(;e.clips[i]&&D(jA(e.clips[i].clip),t)<=0;)i+=1;let a=e.clips[i];if(!a)return r;let o=k(Q(a.clip),t);if(!(O(o)*n.rate.fps<.5))return D(o,r)<0?o:r}visibleClips(e){let{model:t}=this;if(!t)return[];let n=this.timeAt(0),r=this.timeAt(this.#k),i=[];for(let a of t.rows){let t=28-this.#O+a.top;t+a.height<=28||t>=this.#A||d1(a,n,r,n=>{if(i.length>=e)return;let r=Math.max(this.xAt(n.start),0),o=Math.min(this.xAt(n.end),this.#k);i.push({box:n,row:a,left:r,top:t,width:o-r,height:a.height})})}return i}hitAt({x:e,y:t}){let{model:n}=this;if(!n)return{kind:`empty`};if(t<28)return Math.abs(e-this.xAt(this.visibleDuration))<=Zde?{kind:`end`}:{kind:`ruler`};let r=l1(n,this.laneAt(t));if(!r)return{kind:`empty`};let i=this.timeAt(e),a=this.laneAt(t)-r.top<16,o=a&&this.#f.tool===`select`?this.#xe(r,e):void 0;if(o)return o;let s=f1(r,i);if(!s)return{kind:`lane`,row:r,seconds:i};let c=Math.min(this.#C,(s.end-s.start)*this.#T/3),l=e-this.xAt(s.start),u=this.xAt(s.end)-e;if(this.#De(s,r,e,t))return{kind:`clip`,row:r,box:s,expander:!0};let d=a?this.#Se(s,e):void 0;if(r.track.locked||this.#f.tool!==`select`){let e=this.#f.tool===`select`?d:void 0;return e?{kind:`clip`,row:r,box:s,transition:e}:{kind:`clip`,row:r,box:s}}let f=this.laneAt(t)-r.top<qde?this.#be(s,r,e):void 0;return f?{kind:`clip`,row:r,box:s,handle:f}:l<=c?{kind:`clip`,row:r,box:s,edge:`start`}:u<=c?{kind:`clip`,row:r,box:s,edge:`end`}:d?{kind:`clip`,row:r,box:s,transition:d}:{kind:`clip`,row:r,box:s}}#be(e,t,n){if(!q$(t.track))return;let r=Y$(e.clip),i=this.#C,a=t=>r[t]<=0||this.model?.joined.has(`${e.id} ${t}`)===!0,o=a(`enter`)?1/0:Math.abs(n-this.xAt(e.start+r.enter)),s=a(`exit`)?1/0:Math.abs(n-this.xAt(e.end-r.exit));if(!(o>i&&s>i))return o<=s?`enter`:`exit`}#xe(e,t){let n=s1(e,this.timeAt(t));if(!n)return;let r=n.join.transition.align??`center`,i=this.#C,a=e=>Math.abs(t-this.xAt(e))<=i,o=!e.track.locked&&n.trouble===void 0;return o&&r!==`after`&&a(n.start)?{kind:`join`,row:e,join:n,edge:`start`}:o&&r!==`before`&&a(n.end)?{kind:`join`,row:e,join:n,edge:`end`}:{kind:`join`,row:e,join:n}}#Se(e,t){let n=this.timeAt(t),r=Y$(e.clip);if(r.exit>0&&n>=e.end-r.exit)return`exit`;if(r.enter>0&&n<=e.start+r.enter)return`enter`}showsTransitionHandles(e){let{track:t}=e;return q$(t)&&t.locked!==!0&&this.#f.tool===`select`}setTransitionLength(e,t,n){let{model:r}=this,[i]=this.#$([e],r),a=i===void 0?void 0:r?.boxes.get(i);if(!r||!a)return!1;let o=j1(r.id,a.clip,t,n,r);return o!==void 0&&this.#Z([o])}setTransition(e,t,n){let{model:r}=this,[i]=this.#$([e],r);if(!r||i===void 0)return!1;let a={timeline:r.id,clip:i,[t]:n};return this.#Z([{type:`clip.setTransition`,params:a}])}transitionDropAt(e,t){let{model:n}=this;if(!n||e.y<28||this.#T<=0)return;let r=l1(n,this.laneAt(e.y)),i=Qde/this.#T;return ble(n,r,this.timeAt(e.x),i,t)}showTransitionDrop(e,t){let n=e&&t?this.transitionDropAt(e,t):void 0,r=n&&{row:n.row.id,start:n.start,end:n.end},i=this.#v?.transitionDrop;return i===r||i!==void 0&&r!==void 0&&i.row===r.row&&i.start===r.start&&i.end===r.end||(this.#v=r&&{transitionDrop:r},this.#a.emit()),n!==void 0}dropTransition(e,t){let{model:n}=this,r=n&&this.transitionDropAt(e,t);this.showTransitionDrop(void 0);let i=n&&r&&wle(n,r,t);if(!i||!this.#Z(i.calls))return!1;this.#Ce(i.calls);let{chosen:a}=i;return`join`in a?this.selectJoin(a.join):this.selectTransition(a.clip,a.edge),!0}get attachContext(){let{model:e,selection:t,transition:n}=this.#f,r=this.#F;if(r!==void 0&&r.model===e&&r.selection===t&&r.transition===n)return r.context;let i=Tle(e,t,n);return this.#F={model:e,selection:t,transition:n,context:i},i}attachProblem(e,t){return $1(this.model,this.attachContext,e,t)}attachTransition(e,t){let{model:n}=this;if(!n)return;let r=this.attachContext.kind===`edge`||this.attachContext.kind===`join`,i=Ole(n,this.attachContext,t,e);if(i.length===0||!this.#Z(i))return;let a=this.#Ce(i);return{edges:a.edges.size,joins:a.joins.size,replaced:r}}#Ce(e){let t=new Set,n=new Set;for(let{type:r,params:i}of e){let e=i;if(r===`clip.setTransition`)for(let n of K$)n in e&&t.add(`${String(e.clip)}:${n}`);else r===`join.add`?n.add(String(e.id)):r===`join.update`&&n.add(String(e.join))}this.flash({edges:t,joins:n});let r=this.model,i=[...[...t].flatMap(e=>{let[t=``,n]=e.split(`:`),i=r?.boxes.get(t);if(!i)return[];let a=Y$(i.clip)[n];return[{clip:t,span:n===`enter`?[i.start,i.start+a]:[i.end-a,i.end]}]}),...[...n].flatMap(e=>{let t=r?.joins.get(e);return t?[{clip:t.from.id,span:[t.start,t.end]}]:[]})],a=i.some(({clip:e,span:[t,n]})=>this.#Ee(t,n,e)),o=i[0];return!a&&o&&this.#pe(...o.span,[o.clip]),{edges:t,joins:n}}effectDropAt(e){let{model:t}=this;if(!(!t||e.y<28||this.#T<=0))return Fde(l1(t,this.laneAt(e.y)),this.timeAt(e.x))?.box}showEffectDrop(e){let{model:t}=this,n=e?this.effectDropAt(e):void 0,r=n&&t?.rowOfClip.get(n.id),i=n&&r&&{row:r.id,start:n.start,end:n.end},a=this.#v?.transitionDrop;return a===i||a!==void 0&&i!==void 0&&a.row===i.row&&a.start===i.start&&a.end===i.end||(this.#v=i&&{transitionDrop:i},this.#a.emit()),i!==void 0}dropEffect(e,t){let{model:n}=this,r=n&&this.effectDropAt(e);if(this.showEffectDrop(void 0),!n||!r)return!1;let{calls:i,added:a}=l4(n,[r],t);return this.#Z(i)?(this.#te(new Set([r.id])),this.#we(a),!0):!1}#we(e){this.#l={effects:e,at:(this.#l?.at??0)+1,time:Date.now()},this.#c.emit(),this.flash({bands:new Set(e.keys())}),this.#Te([...e.keys()])}#Te(e){let t=e.flatMap(e=>{let t=this.model?.boxes.get(e);return t?[t]:[]});if(t.some(e=>this.#Ee(e.start,e.end,e.id)))return;let n=t[0];n&&this.#pe(n.start,n.end,[n.id])}#Ee(e,t,n){let r=this.model?.rowOfClip.get(n);if(!r)return!1;let i=r.top-this.#O;return this.xAt(t)>0&&this.xAt(e)<this.#k&&i+r.height>0&&i<this.#A-28}get lastAdded(){return this.#l}subscribeAdded=this.#c.subscribe;flash(e){clearTimeout(this.#d);let t=Date.now();this.#u={targets:e,share:1};let n=()=>{let r=1-(Date.now()-t)/700;this.#u=r>0?{targets:e,share:r}:void 0,this.#a.emit(),r>0&&(this.#d=setTimeout(n,x4))};this.#a.emit(),this.#d=setTimeout(n,x4)}flashOf(e,t){let n=this.#u;return n?.targets[e]?.has(t)?n.share:0}flashesOn(e){let t=this.#u?.targets;if(!t)return!1;let{clips:n,bands:r,edges:i}=t;return n?.has(e)===!0||r?.has(e)===!0||K$.some(t=>i?.has(`${e}:${t}`)===!0)}get effectContext(){let{model:e,selection:t}=this.#f,n=this.#P;if(n&&n.model===e&&n.selection===t)return n.context;let r=Ide(e,t);return this.#P={model:e,selection:t,context:r},r}effectProblem(e){return c4(this.effectContext,e)}attachEffect(e){let{model:t}=this,n=this.effectContext;if(!t||c4(n,e)!==void 0)return 0;let{calls:r,added:i}=l4(t,n.boxes,e);return this.#Z(r)?(this.#we(i),i.size):0}setEffectRange(e,t,n,r){let{model:i}=this;if(!i||!this.canChangeEffects(e))return!1;let a=i.boxes.get(e),o=a&&bA(a.clip).find(({id:e})=>e===t);if(!o)return!1;let s={start:n===void 0?void 0:ze(n),end:r===void 0?void 0:ze(r)};if(s.start===o.start&&s.end===o.end)return!1;let c={timeline:i.id,clip:e,effect:t,start:s.start??null,end:s.end??null};return this.#Z([{type:`effect.update`,params:c}])}canChangeEffects(e){return this.#$([e],this.model).length>0}removeEffect(e,t){let{model:n}=this;if(!n||!this.canChangeEffects(e))return!1;let r={timeline:n.id,clip:e,effects:[t]};return this.#Z([{type:`effect.remove`,params:r}])}moveEffect(e,t,n){let{model:r}=this;if(!r||!this.canChangeEffects(e))return!1;let i={timeline:r.id,clip:e,effect:t,index:Math.max(n,0)};return this.#Z([{type:`effect.move`,params:i}])}setEffectEnabled(e,t,n){let{model:r}=this;if(!r||!this.canChangeEffects(e))return!1;let i={timeline:r.id,clip:e,effect:t,enabled:n};return this.#Z([{type:`effect.update`,params:i}])}updateJoin(e,t){let{model:n}=this;return n?this.#Z([{type:`join.update`,params:{timeline:n.id,join:e,changes:t}}]):!1}removeJoin(e){let{model:t}=this;return t?this.#Z([{type:`join.remove`,params:{timeline:t.id,joins:[e]}}]):!1}longestJoin(e,t=e.join.transition.align){let{model:n}=this;return n?ij(n.ends,e.from.clip,e.to.clip,t):M}showsExpander(e){let t=this.#M;return!t?.canOpen(e)||this.#f.tool!==`select`?!1:this.#f.selection.has(e.id)||t.isOpen(e)}expanderAt(e,t){return tfe(e,t,this.#C)}#De(e,t,n,r){let i=this.xAt(e.start),a=this.expanderAt(i,this.xAt(e.end)-i),o=a!==void 0&&n>=a&&n<a+14,s=t.top+t.height-this.laneAt(r);return o&&s<=Gde&&this.showsExpander(e)}hover(e){let t=this.#M?.hover(e);if(t!==void 0)return this.#y.kind!==`empty`&&this.leave(),t;let n=this.hitAt(e),r=this.#y;this.#y=n;let i=this.#f.tool===`razor`&&n.kind===`clip`?V1(this.#Ne,e).seconds:void 0;return(n.kind!==r.kind||n.kind===`join`&&r.kind===`join`&&(n.join!==r.join||n.edge!==r.edge)||n.kind===`clip`&&r.kind===`clip`&&(n.box!==r.box||n.edge!==r.edge||n.handle!==r.handle||n.transition!==r.transition)||i!==this.#b)&&(this.#b=i,this.#a.emit()),this.#Oe(n)}titleAt(e){if(e.y<28)return;let t=this.hitAt(e);if(t.kind!==`join`)return;let{join:n}=t;if(n.trouble)return`transition.why.join.${n.trouble}`;let r=this.timeAt(e.x),i=n.still.find(({from:e,to:t})=>r>=e&&r<=t);if(i)return i.to<=n.at?`transition.stillBefore`:`transition.stillAfter`}leave(){this.#y={kind:`empty`},this.#b=void 0,this.#a.emit()}#Oe(e){return e.kind===`end`?`ew-resize`:e.kind===`ruler`?`pointer`:e.kind===`join`?e.edge?`col-resize`:`default`:e.kind===`clip`?e.expander?`pointer`:this.#f.tool===`razor`?`crosshair`:e.handle?`col-resize`:e.edge?`ew-resize`:`default`:`default`}get isDragging(){return this.#_!==void 0}get dragCursor(){return this.#v?.copying?`copy`:``}touchAt(e){let t=this.#M?.touchAt(e);if(t)return t;let n=this.hitAt(e),{selection:r,tool:i,transition:a}=this.#f;if(n.kind===`join`)return b4(a)&&a.join===n.join.id&&n.edge?`grab`:`plain`;let o=n.kind===`clip`&&!n.row.track.locked&&i===`select`,s=o&&r.has(n.box.id),c=o&&a!==void 0&&!b4(a)&&a.clip===n.box.id,l=n.kind===`clip`&&n.handle!==void 0;return n.kind===`ruler`||n.kind===`end`||s&&n.kind===`clip`&&n.edge||(s||c)&&l?`grab`:s?`selected`:`plain`}hold(e){if(this.#M?.hold(e))return;let t=this.hitAt(e),{selection:n,multiSelecting:r}=this.#f;t.kind!==`clip`||n.has(t.box.id)||(r?this.addToSelection(t.box.id):this.selectOnly(t.box.id))}press(e){let{model:t}=this;if(!t||(this.#Me(),this.#_=this.#M?.press(e),this.#_))return;let n=this.hitAt(e),r=this.#Ne;if(n.kind===`ruler`)this.#_=new I1(r,e);else if(n.kind===`end`){let n=kA(t.state).at(-1);if(!n)return;let i=k(IA(t.state),j(n.duration));this.#_=new L1(r,{id:n.id,start:i},e)}else n.kind===`clip`?this.#je(n,e):n.kind===`join`?this.#ke(n,e):this.#_=new F1(r,e)}#ke(e,t){let{join:n,row:r,edge:i}=e;if(i){this.#_=new N1(this.#Ne,n,i,t);return}let a=()=>this.selectJoin(n.id),o=f1(r,this.timeAt(t.x));if(r.track.locked||!o){this.#_=new F1(this.#Ne,t,a);return}let s=()=>(this.#f.selection.has(o.id)||this.#ee(this.#Ae(new Set([o.id]))),new T1(this.#Ne,o,r,t,a));this.#_=new P1(t,s,a)}#Ae(e){let{model:t}=this,n=new Set(e);for(let r of e){let e=t?.boxes.get(r)?.clip.link;for(let r of e===void 0?[]:t?.links.get(e)??[])n.add(r)}return n}#je(e,t){let{box:n,row:r,edge:i,handle:a,transition:o}=e;if(this.#f.tool===`razor`){this.#_=new vle(this.#Ne,r,t);return}if(a){this.#_=new M1(this.#Ne,n,a,t);return}if(o){let e=()=>this.selectTransition(n.id,o);if(r.track.locked){this.#_=new F1(this.#Ne,t,e);return}let i=()=>(this.#f.selection.has(n.id)||this.#ee(this.#Ae(new Set([n.id]))),new T1(this.#Ne,n,r,t,e));this.#_=new P1(t,i,e);return}if(i){this.#ee(this.#Ae(new Set([n.id]))),this.#_=new E1(this.#Ne,n,r,i,t);return}let{selection:s}=this.#f,c=s.has(n.id),l=t.shift||t.mod||this.#f.multiSelecting,u=this.#Ae(new Set([n.id])),d=new Set(l?[...s,...u]:u),f=()=>{e.expander?this.#M?.toggle(n):l&&c?this.#ee(new Set([...s].filter(e=>!u.has(e)))):this.#ee(d)};r.track.locked?this.#_=new F1(this.#Ne,t,f):(c||this.#ee(d),this.#_=new T1(this.#Ne,n,r,t,f))}drag(e){this.#_?.move(e)}release(e){let t=this.#_;this.#_=void 0,t?.end(e)}cancelDrag(){return this.#_?(this.#Me(),!0):!1}#Me(){this.#_?.cancel(),this.#_=void 0}scrollDuringDrag(e,t,n){this.#_&&(this.#D+=t,this.#_.reachesRows&&(this.#O+=n),this.#U(),this.#_.move(e),this.#G())}get#Ne(){let e=()=>this.#f,t=()=>this.#x;return{get model(){return e().model},get selection(){return e().selection},get overwriting(){return e().overwriting},get multiSelecting(){return e().multiSelecting},get frame(){return t()},timeAt:e=>this.timeAt(e),laneAt:e=>this.laneAt(e),snapDistance:e=>this.#f.snapping&&!e.alt?d4/this.#T:0,setPreview:e=>{this.#v=e,this.#U(),this.#a.emit()},sourceLength:e=>{let t=this.#h?.getState();return t&&FA(t,e)},select:e=>this.#ee(this.#Ae(e)),selectTransition:(e,t)=>this.selectTransition(e,t),selectJoin:e=>this.selectJoin(e),seek:e=>this.seek(e),run:e=>this.#Z(e)}}},ofe=110,sfe=7,cfe=[1,2,5,10],lfe=[1,2,5,10,15,30,60,120,300,600,900,1800,3600,7200,18e3,36e3],ufe=[10,6,5,4,3,2];function dfe(e,t){let n=[...cfe.filter(e=>e<t/2),...t%2==0?[t/2]:[],...lfe.map(e=>e*t)],r=n.find(t=>t*e>=ofe)??n.at(-1),i=ufe.find(t=>r%t===0&&r/t*e>=sfe);return{major:r,minor:i===void 0?r:r/i}}function k4(e,t,n,r,i,a){e.fillStyle=i.background,e.fillRect(0,0,t.width,r),e.fillStyle=i.line,e.fillRect(0,r-1,t.width,1);let{major:o,minor:s}=dfe(t.pixelsPerSecond/n.fps,n.nominal),c=Math.max(t.timeAt(0)*n.fps,0),l=t.timeAt(t.width)*n.fps;e.fillStyle=i.tick;for(let i=Math.floor(c/s)*s;i<=l;i+=s){let s=a(t.xAt(i/n.fps)),c=i%o===0?10:5;e.fillRect(s,r-1-c,1,c)}e.fillStyle=i.label;for(let r=Math.floor(c/o)*o;r<=l;r+=o)e.fillText(pq(r,n),t.xAt(r/n.fps)+4,10)}function A4(e){let t=getComputedStyle(e),n=e=>t.getPropertyValue(`--aq-timeline-${e}`).trim();return{font:t.getPropertyValue(`--aq-font`),background:n(`background`),lane:n(`lane`),laneLocked:n(`lane-locked`),line:n(`line`),ruler:n(`ruler`),tick:n(`tick`),label:n(`label`),picture:n(`picture`),sound:n(`sound`),caption:n(`caption`),selected:n(`selected`),snap:n(`snap`),covered:n(`covered`),outside:n(`outside`),end:n(`end`),marquee:n(`marquee`),failed:t.getPropertyValue(`--aq-danger`).trim(),key:n(`key`),keyTried:t.getPropertyValue(`--aq-trial`).trim(),keySummary:n(`key-summary`),curve:n(`curve`),handle:n(`handle`),warning:t.getPropertyValue(`--aq-warning`).trim(),effect:n(`effect`),flash:n(`flash`)}}var j4=class{canvas;context;ratio=1;isWiped=!0;#e;constructor(e){let t=e.getContext(`2d`,{alpha:!1});if(!t)throw Error(`No 2D context`);this.canvas=e,this.context=t,e.addEventListener(`contextrestored`,()=>{this.isWiped=!0,this.invalidate()})}resize(e,t,n){this.ratio=n,this.isWiped=!0,this.canvas.width=Math.round(e*n),this.canvas.height=Math.round(t*n),this.canvas.style.width=`${e}px`,this.canvas.style.height=`${t}px`}invalidate(){this.#e??=requestAnimationFrame(()=>{this.#e=void 0,this.paint()})}paintNow(){this.dispose(),this.#e=void 0,this.paint()}dispose(){this.#e!==void 0&&cancelAnimationFrame(this.#e)}sharp(e){return Math.round(e*this.ratio)/this.ratio}},M4=[CF,CF],N4=[1-CF,1-CF],ffe=[1,1],P4=6,pfe=.01,F4=1e-12,I4=e=>Wt(e.time),L4=e=>e.value,R4=e=>e.interp===`bezier`&&e.out!==void 0,z4=(e,t,n)=>Math.min(Math.max(e,t),n),B4=(e,t)=>{let n=Number(e.toFixed(t));return n===0?0:n};function V4(e,t,n){let r=n===`out`?t:t-1,i=e[r],a=e[r+1];if(!(r<0||!i||!a||i.interp===`hold`)&&typeof i.value==`number`&&typeof a.value==`number`)return I4(a)>I4(i)?{from:r,to:r+1}:void 0}function H4(e,t,n){let r=V4(e,t,n);if(!r)return;let i=e[r.from];return R4(i)?n===`out`?i.out:e[r.to].in??ffe:n===`out`?M4:N4}function U4(e,t,n){let r=V4(e,t,n),i=H4(e,t,n);if(!r||!i)return;let a=e[r.from],o=e[r.to],s=I4(o)-I4(a),c=L4(o)-L4(a);return{t:I4(a)+i[0]*s,v:L4(a)+i[1]*c}}function mfe(e,t,n){return n===`out`?U4(e,t+1,`in`):U4(e,t-1,`out`)}var W4=e=>({t:I4(e),v:L4(e)});function G4(e,t){let n=e[t],r=e[t-1]??n,i=e[t+1]??n;return{t:I4(i)-I4(r)||1,v:Math.abs(L4(n)-L4(r))+Math.abs(L4(i)-L4(n))||1}}function hfe(e,t){let n=U4(e,t,`in`),r=U4(e,t,`out`);if(!n||!r)return!1;let i=W4(e[t]),a=G4(e,t),o={t:(n.t-i.t)/a.t,v:(n.v-i.v)/a.v},s={t:(r.t-i.t)/a.t,v:(r.v-i.v)/a.v},c=Math.hypot(o.t,o.v)*Math.hypot(s.t,s.v);if(c<F4)return!1;let l=(o.t*s.v-o.v*s.t)/c;return Math.abs(l)<pfe&&o.t*s.t+o.v*s.v<0}var K4=e=>Array.isArray(e);function q4(e,t,n){let r=e[t]?.value;if(!K4(r))return;if(n!==void 0)return n;let i=0,a=-1;return r.forEach((n,o)=>{let s=0;for(let n of[t-1,t+1]){let t=e[n]?.value,i=K4(t)?t[o]:void 0;typeof i==`number`&&(s+=Math.abs(i-r[o]))}s>a&&([i,a]=[o,s])}),i}function J4(e,t,n){let{tangent:r}=e[t];if(r)return r;let i=q4(e,t,n),a=i===void 0?e:vF(e,i);return a&&hfe(a,t)?`aligned`:`broken`}var Y4=(e,t,n)=>t.get(n)??e[n];function gfe(e){let{interp:t,out:n,preset:r,spring:i,...a}=e;return a}function X4(e,t,n,r,i){let a=n=>Y4(e,t,n),o=r===`out`?n:n-1,s=a(o),c=a(o+1),l=R4(s),u=M4.map(e=>B4(e,P4)),d=N4.map(e=>B4(e,P4));if(r===`out`||!l){let e=r===`out`?[...i]:u;t.set(o,{...l?s:gfe(s),interp:`bezier`,out:e})}r===`in`?t.set(o+1,{...c,in:[...i]}):l||t.set(o+1,{...c,in:d})}function Z4(e,t,n){let r=V4(e,t,n);if(!r)return!1;let i=L4(e[r.to])-L4(e[r.from]);return Math.abs(i)<F4}var Q4={t:1,v:0};function $4(e,t,n,r,i){let a=n=>Y4(e,t,n),o=[...e];for(let[e,n]of t)o[e]=n;let s=V4(o,n,r),c=H4(o,n,r);if(!s||!c)return;let l=a(s.from),u=a(s.to),d=I4(u)-I4(l),f=L4(u)-L4(l);if(Math.abs(f)<F4)return;let p=Math.abs(i.t)<F4;if(r===`out`){let e=B4(p?0:c[0]>F4?c[0]:CF,P4);return[e,B4(z4((p?Math.sign(i.v)*Math.abs(f)*CF:e*d*i.v/i.t)/f,-1,2),P4)]}let m=B4(p?1:c[0]<.999999999999?c[0]:1-CF,P4);return[m,B4(z4((f+(p?-Math.sign(i.v)*Math.abs(f)*CF:(m-1)*d*i.v/i.t))/f,-1,2),P4)]}function _fe({keys:e,index:t,side:n,to:r,mode:i}){let a=V4(e,t,n),o=H4(e,t,n);if(!a||!o)return;let s=e[a.from],c=e[a.to],l=I4(c)-I4(s),u=L4(c)-L4(s),d=n===`out`?`in`:`out`,f=i===`aligned`&&Z4(e,t,d),p=(r.t-I4(s))/l,m=(r.v-L4(s))/u,h=Math.abs(u)<F4?o[1]:f?n===`out`?0:1:m,g=z4(p,0,1),_=z4(h,-1,2),v=Math.abs(g-p)>1e-9||Math.abs(u)>=F4&&Math.abs(_-m)>1e-9,y=new Map;if(X4(e,y,t,n,[B4(g,P4),B4(_,P4)]),i===`aligned`){let r=Y4(e,y,t),i=[...e];for(let[e,t]of y)i[e]=t;let a=U4(i,t,n),o=n===`out`?1:-1,s=Z4(e,t,n)?Q4:{t:(a.t-I4(r))*o,v:(a.v-L4(r))*o},c=Math.hypot(s.t/l,s.v/(Math.abs(u)||1))>F4?$4(e,y,t,d,s):void 0;c&&X4(e,y,t,d,c)}let b=Y4(e,y,t);return y.set(t,{...b,tangent:i}),{changed:y,clamped:v}}function e3(e,t,n){let r=[...e];for(let[e,n]of t)r[e]=n;let i=U4(r,n,`in`),a=U4(r,n,`out`);if(!i||!a)return;let o=W4(r[n]),s=G4(r,n),c=(e,t)=>{let n=(e.t-o.t)/s.t*t,r=(e.v-o.v)/s.v*t,i=Math.hypot(n,r);return i<F4?{t:0,v:0}:{t:n/i,v:r/i}},l=c(i,-1),u=c(a,1),d=l.t+u.t,f=l.v+u.v;if(Math.hypot(d,f)<F4){let e=W4(r[n-1]),t=W4(r[n+1]);d=(t.t-e.t)/s.t,f=(t.v-e.v)/s.v}let p=Z4(r,n,`in`)||Z4(r,n,`out`)?Q4:{t:d*s.t,v:f*s.v};for(let i of[`in`,`out`]){let a=$4(e,t,n,i,p),o=H4(r,n,i),s=a&&o&&a[0]===o[0]&&a[1]===o[1];a&&!s&&X4(e,t,n,i,a)}}function vfe(e,t,n,r){let i=q4(e,n,r);if(i===void 0){e3(e,t,n);return}let a=[...e];for(let[e,n]of t)a[e]=n;let o=vF(a,i);if(!o)return;let s=new Map;e3(o,s,n);for(let[e,n]of s)t.set(e,SF(a[e],n,i))}function yfe(e,t,n,r){let i=new Map;for(let a of t){let t=e[a]?.value;if(typeof t!=`number`&&!K4(t))continue;n===`aligned`&&vfe(e,i,a,r);let o=Y4(e,i,a);(o.tangent!==n||i.has(a))&&i.set(a,{...o,tangent:n})}if(n!==`auto`)return i;let a=[...e];for(let[e,t]of i)a[e]=t;return AF({keys:a}).keys.forEach((e,t)=>{e!==a[t]&&i.set(t,e)}),i}var t3=class e{#e;size;constructor(e){this.#e=e;let t=0;for(let n of e.values())for(let e of n.values())t+=e.size;this.size=t}static of(t){let n=new Map;for(let{clip:e,path:r,time:i}of t){let t=n.get(e);t||n.set(e,t=new Map);let a=t.get(r);a||t.set(r,a=new Set),a.add(i)}return new e(n)}has({clip:e,path:t,time:n}){return this.#e.get(e)?.get(t)?.has(n)===!0}timesOf(e,t){return this.#e.get(e)?.get(t)}hasClip(e){return this.#e.has(e)}clips(){return this.#e.keys()}onClips(t){let n=new Map([...this.#e].filter(([e])=>t(e)));return n.size===this.#e.size?this:new e(n)}*channels(){for(let[e,t]of this.#e)for(let[n,r]of t)yield{clip:e,path:n,times:r}}*[Symbol.iterator](){for(let{clip:e,path:t,times:n}of this.channels())for(let r of n)yield{clip:e,path:t,time:r}}with(t){return e.of([...this,...t])}without(t){let n=e.of(t);return e.of([...this].filter(e=>!n.has(e)))}keeping(t){let n=[...this].filter(t);return n.length===this.size?this:e.of(n)}includes(e){return e.every(e=>this.has(e))}},n3=t3.of([]),r3=1e3,bfe=2e3,xfe=6,i3=6,a3=new WeakMap;function o3(e){if(!e)return new Map;let t=a3.get(e);return t||a3.set(e,t=new Map(e.map(e=>[e.time,e]))),t}function s3(e,t){let n=OM(e,j(t));return e[n]?.time===t?n:-1}var c3=(e,t)=>Math.min(Math.max(t,e.min??-1/0),e.max??1/0);function Sfe(e,t){if(t===0||!(e>0))return 0;let n=10**Math.floor(Math.log10(e));return Number((Math.round(t*e/n)*n).toFixed(i3))}var l3=(e,t,n)=>n===void 0?`${e} ${t}`:`${e} ${t} ${n}`;function Cfe(e,t,n,r,i){let a=D(t,M)===0?[]:u3(e,t),o=[];for(let{clip:e,path:a,component:s,spec:c,times:l}of n){let n=r.get(l3(e,a,s))??0;if(n===0)continue;let d=o3(i(e,a)),f=[];for(let e of l){let r=d.get(e),i=s===void 0?r?.value:bF(r?.value,s);if(!r||typeof i!=`number`)return;let a=Number(c3(c,i+n).toFixed(i3)),o=s===void 0?a:xF(r.value,s,a);f.push({...r,time:ze(u(j(e),t)),value:o})}o.push({owner:{clip:e},path:a,op:`putKeys`,keys:f})}return[...a,...o]}function u3(e,t){return e.map(({clip:e,path:n,times:r})=>({owner:{clip:e},path:n,op:`moveKey`,moves:r.map(e=>({from:e,to:ze(u(j(e),t))}))}))}function d3(e,t,n){let r=t.flatMap(({clip:e,path:t,times:n})=>n.map(n=>({clip:e,path:t,time:n}))),i=new Set(r.map(({clip:e,path:t,time:n})=>`${e} ${t} ${n}`));return[...[...e].filter(({clip:e,path:t,time:n})=>!i.has(`${e} ${t} ${n}`)),...r.map(e=>({...e,time:ze(u(j(e.time),n))}))]}function wfe(e){let t,n=1/0;for(let{times:r}of e)for(let e of r){let r=Wt(e);r<n&&([t,n]=[e,r])}return t===void 0?M:j(t)}var Tfe=class{reachesRows=!0;#e;#t;#n;#r;#i;#a;#o;#s;#c;#l;#u;#d=!1;#f=!1;#p;#m=new Map;constructor(e,t,n,r,i=[]){this.#e=e,this.#t=t,this.#n=n,this.#l=r,this.#a=i,this.#u=e.laneAt(n.y),this.#r=e.timeAt(n.x),this.#i=e.moving(),this.#o=m1(e.model,e.frame,new Set,e.snapTargets()),this.#c=k(t.exact(),wfe(this.#i));let a=this.#i.reduce((e,{times:t})=>e+t.length,0);this.#s=a<=bfe}move(e){if(this.#f||!this.#d&&!b1(this.#n,e))return;this.#d||this.#e.holdRanges(this.#a),this.#d=!0;let t=Math.abs(e.x-this.#n.x),n=this.#e.laneAt(e.y)-this.#u,r=!e.shift||t>=Math.abs(n),i=r?this.#x(e):this.#b(),a=e.shift&&r||Math.abs(n)<xfe?0:-n,o=new Map;for(let e of this.#a){let t=Sfe(this.#e.perPixel(e)??0,a);t!==0&&o.set(l3(e.clip,e.path,e.component),t)}let s=i.seconds-this.#t.seconds,c=this.#p,l=Efe(o,this.#m);if(this.#p=i,this.#m=o,!this.#s||c?.seconds===i.seconds&&l){this.#h(s,o,i);return}let u=this.#y(i),d=this.#g(u,o);d&&(this.#h(s,o,i),D(u,M)===0&&o.size===0?this.#e.cancelPreview():this.#e.preview(d))}#h(e,t,n){this.#e.show({shift:e,...t.size>0?{lift:t}:{},...n.line===void 0?{}:{snap:n.line}})}#g(e,t){let n=Cfe(this.#i,e,this.#a,t,(e,t)=>this.#e.keysOf(e,t));if(n)return n;this.#_()}#_(){this.#f=!0,this.#e.cancelPreview(),this.#e.show(void 0),this.#e.releaseRanges(),this.#e.gone()}#v(){return this.#i.every(({clip:e,path:t,times:n})=>{let r=o3(this.#e.keysOf(e,t));return n.every(e=>r.has(e))})}#y(e){return k(e.exact(),this.#t.exact())}#b(){return{seconds:this.#t.seconds,exact:()=>this.#t.exact()}}#x(e){let t=this.#t.seconds,n=t+this.#e.timeAt(e.x)-this.#r,r=this.#e.snapDistance(e);if(Math.abs(n-t)<r)return{seconds:t,exact:()=>this.#t.exact(),line:t};let i=O(this.#c),a=e.alt?this.#S(n):v1(this.#e,n,this.#o.nearest(n,r));return a.seconds<i?{seconds:i,exact:()=>this.#c}:a}#S(e){let t=Math.round(e*r3)/r3;return{seconds:t,exact:()=>We(Math.max(t,0))}}end(e){this.#f||(this.#d?(this.move(e),this.#f||(this.#C(),this.#e.show(void 0),this.#e.releaseRanges())):this.#l())}#C(){let e=this.#p,t=e&&this.#y(e),n=this.#m;if(!t||D(t,M)===0&&n.size===0){this.#e.cancelPreview();return}if(!this.#v()){this.#_();return}let r=this.#g(t,n);if(!r)return;let i=t3.of(d3(this.#e.selection,this.#i,t));this.#e.commit(r,i)||this.#e.cancelPreview()}cancel(){this.#e.cancelPreview(),this.#e.show(void 0),this.#e.releaseRanges()}isStale(e){return this.#i.some(({clip:t})=>!e.boxes.has(t))}},f3=class{reachesRows=!0;#e;#t;#n;#r;#i;#a;#o;#s=!1;constructor(e,t,n){this.#e=e,this.#a=t,this.#o=n,this.#t=e.selection;let r=t.shift||t.mod||e.multiSelecting;this.#n=r?e.selection:n3,this.#r=e.timeAt(t.x),this.#i=e.laneAt(t.y),!r&&!n&&e.select(n3)}move(e){if(!this.#s&&!b1(this.#a,e))return;this.#s=!0;let t=this.#e.timeAt(e.x),n=this.#e.laneAt(e.y),r={from:Math.min(t,this.#r),to:Math.max(t,this.#r),top:Math.min(n,this.#i),bottom:Math.max(n,this.#i)};this.#e.select(this.#n.with(this.#e.keysIn(r))),this.#e.show({marquee:r})}end(){this.#s||this.#o?.(),this.#e.show(void 0)}cancel(){this.#e.select(this.#t),this.#e.show(void 0)}},Efe=(e,t)=>e.size===t.size&&[...e].every(([e,n])=>t.get(e)===n),Dfe=class{#e;#t;#n;#r;#i=!1;#a=!1;#o;constructor(e,t,n){this.#e=e,this.#t=t,this.#n=n;let r=this.#s()??[],i=s3(r,t.time),a=i<0?`broken`:J4(r,i);this.#r=a===`broken`?`broken`:`aligned`}#s(){let{clip:e,path:t,component:n}=this.#t,r=this.#e.keysOf(e,t);return r&&n!==void 0?vF(r,n):r}move(e){if(this.#a||!this.#i&&!b1(this.#n,e))return;this.#i||this.#e.holdRanges([this.#t]),this.#i=!0;let{clip:t,path:n,component:r,time:i,side:a}=this.#t,o=this.#s(),s=o?s3(o,i):-1,c=this.#t.pointAt(e),l=e.alt?`broken`:e.mod?`aligned`:this.#r,u=o&&s>=0&&c&&_fe({keys:o,index:s,side:a,to:c,mode:l});if(!u){this.#l();return}let d=this.#c(u.changed);if(!d){this.#l();return}this.#o=d;let{clamped:f}=u,p=r===void 0?{}:{component:r},{x:m,y:h}=e;this.#e.show({handle:{clip:t,path:n,...p,time:i,side:a,clamped:f,x:m,y:h}}),this.#e.preview(this.#u(d))}#c(e){let{clip:t,path:n,component:r}=this.#t;if(r===void 0)return e;let i=this.#e.keysOf(t,n);if(!i)return;let a=new Map;for(let[t,n]of e){let e=i[t];if(!e)return;a.set(t,SF(e,n,r))}return a}#l(){this.#a=!0,this.#o=void 0,this.#e.cancelPreview(),this.#e.show(void 0),this.#e.releaseRanges(),this.#e.gone()}#u(e){let{clip:t,path:n}=this.#t;return[{owner:{clip:t},path:n,op:`putKeys`,keys:[...e.values()]}]}end(e){if(this.#a||(this.#i&&this.move(e),this.#a))return;let t=this.#o;t&&!this.#e.commit(this.#u(t),this.#e.selection)&&this.#e.cancelPreview(),this.#e.show(void 0),this.#e.releaseRanges()}cancel(){this.#e.cancelPreview(),this.#e.show(void 0),this.#e.releaseRanges()}isStale(e){return!e.boxes.has(this.#t.clip)}},Ofe=class{#e;#t;#n;#r;#i=!1;constructor(e,t,n,r){this.#e=e,this.#t=t,this.#n=n,this.#r=r}move(e){(this.#i||b1(this.#r,e))&&(this.#i=!0,this.#e(this.#n+e.y-this.#r.y))}end(e){this.move(e)}cancel(){this.#i&&this.#t()}},kfe=7,Afe=16,jfe=.1,Mfe={world:1080,deg:360,ratio:1,db:24,semitone:24};function Nfe(e,t){let{min:n,max:r,softMin:i,softMax:a,unit:o}=e;return n!==void 0&&r!==void 0&&r>n?r-n:i!==void 0&&a!==void 0&&a>i?a-i:Mfe[o??``]??Math.max(Math.abs(t)*2,2)}function Pfe(e,t,n){let r=Math.min(Math.max(n*jfe,kfe),Afe);if(e.max>e.min)return{height:n,padding:r,low:e.min,high:e.max};let i=Nfe(t,e.min)/2;return{height:n,padding:r,low:e.min-i,high:e.min+i}}var p3=({height:e,padding:t})=>Math.max(e-t*2,1);function m3(e,t){let{padding:n,low:r,high:i}=e;return n+p3(e)*(1-(t-r)/(i-r))}function Ffe(e,t){let{padding:n,low:r,high:i}=e;return r+(1-(t-n)/p3(e))*(i-r)}var Ife=e=>(e.high-e.low)/p3(e),Lfe=(e,t)=>t?{min:Math.min(e.min,t.min),max:Math.max(e.max,t.max)}:e;function Rfe(e,t,n,r,i){let a=t-e,o=e+n*a,s=e+r*a,c=o-e,l=s-o,u=t-s,d=c-2*l+u,f=2*(l-c),p=n=>{let r=1-n;return r*r*r*e+3*r*r*n*o+3*r*n*n*s+n*n*n*t},m=[];if(Math.abs(d)<1e-12)Math.abs(f)>1e-12&&m.push(-c/f);else{let e=f*f-4*d*c;if(e>=0){let t=Math.sqrt(e);m.push((-f+t)/(2*d),(-f-t)/(2*d))}}for(let e of m)e>0&&e<1&&i(p(e))}var h3=new WeakMap;function zfe(e){if(e.kind===`still`){let{value:t}=e;return typeof t==`number`?{min:t,max:t}:void 0}if(h3.has(e))return h3.get(e);let{values:t,shapes:n,handles:r}=e,i;if(t instanceof Float64Array){let e=1/0,a=-1/0,o=t=>{t<e&&(e=t),t>a&&(a=t)};t.forEach(o),n.forEach((e,n)=>{if(e!==Qt.bezier)return;let i=r[n*4+1],a=r[n*4+3];Rfe(t[n],t[n+1],i,a,o)}),i=Number.isFinite(e)&&Number.isFinite(a)?{min:e,max:a}:void 0}return h3.set(e,i),i}var g3=5,Bfe=4,_3=3,v3=Math.PI*2,y3=1,Vfe=2,Hfe=.75,Ufe=1.5,Wfe=4,b3=7,Gfe=24,x3=.4,Kfe=.35,qfe=`#00000033`,Jfe=.18,Yfe=.5,S3=3,Xfe=.85;function C3(e,t,n,r,i){if(t===2){let t=i-1;e.rect(n-t,r-t,t*2,t*2)}else t===1?(e.moveTo(n+i-.5,r),e.arc(n,r,i-.5,0,v3)):(e.moveTo(n,r-i),e.lineTo(n+i,r),e.lineTo(n,r+i),e.lineTo(n-i,r),e.closePath())}var w3=class{#e=new Map;in(e,t=1){let n=`${e} ${t}`,r=this.#e.get(n);return r||this.#e.set(n,r={color:e,alpha:t,path:new Path2D}),r.path}fill(e){let t=e.globalAlpha;for(let{color:t,alpha:n,path:r}of this.#e.values())e.fillStyle=t,e.globalAlpha=n,e.fill(r);e.globalAlpha=t}};function Zfe(e,t,n,r,i){if(t.kind===`still`){let a=n.y(t.value);e.moveTo(r,a),e.lineTo(i,a);return}let{times:a,shapes:o,handles:s,before:c,after:l}=t,u=t.values,d=a.length-1,f=e=>n.x(a[e]),p=e=>u[e],m=!1,h=(t,n)=>{m?e.lineTo(t,n):e.moveTo(t,n),m=!0},g=(e,r)=>{for(let i=e;i<r;i+=Vfe)h(i,n.y(nn(t,n.clockAt(i))));h(r,n.y(nn(t,n.clockAt(r))))},_=f(0);r<_&&(c===`hold`?h(r,n.y(p(0))):g(r,Math.min(_,i)));let v=Math.max(d2(a,n.clockAt(r))-1,0),y=Math.min(d2(a,n.clockAt(i)),d);for(h(f(v),n.y(p(v)));v<y;){let t=f(v),r=f(v+1);if(r-t<Hfe){let e=v+1,r=Math.min(p(v),p(e)),i=Math.max(p(v),p(e));for(;e<y&&f(e+1)-t<1;)e+=1,r=Math.min(r,p(e)),i=Math.max(i,p(e));h(t,n.y(r)),h(t,n.y(i)),h(f(e),n.y(p(e))),v=e;continue}let i=p(v),a=p(v+1),c=o[v];if(c===Qt.hold)h(r,n.y(i)),h(r,n.y(a));else if(c===Qt.bezier){let o=a-i,c=v*4,l=r-t;e.bezierCurveTo(t+s[c]*l,n.y(i+s[c+1]*o),t+s[c+2]*l,n.y(i+s[c+3]*o),r,n.y(a))}else h(r,n.y(a));v+=1}let b=f(d);i>b&&(l===`hold`?h(i,n.y(p(d))):g(Math.max(b,r),i))}var T3=class{#e;#t;constructor(e,t){this.#e=e,this.#t=t}paint(e,t,n){let r=this.#e,i=r.lanesBetween(r.laneY(28),r.laneY(r.screenHeight));if(i.length===0)return;let a=new w3,o={from:r.timeAt(0),to:r.timeAt(r.width)};for(let s of i){let i=r.screenY(s.top);this.#n(e,t,s,i,n,o),this.#r(e,t,s,{...o,y:i}),this.#c(t,a,s,{...o,y:i})}this.#u(e,t),a.fill(e)}#n(e,t,n,r,i,{from:a,to:o}){let s=this.#e,{width:c}=s,{height:l,box:u,row:d,node:f}=n;if(e.fillStyle=d.track.locked?t.laneLocked:t.lane,e.fillRect(0,r,c,l),f.kind!==`property`&&(e.fillStyle=qfe,e.fillRect(0,r,c,l)),u){let n=i(s.xAt(u.start)),a=i(s.xAt(u.end));e.fillStyle=t.outside,n>0&&e.fillRect(0,r,Math.min(n,c),l),a<c&&e.fillRect(Math.max(a,0),r,c,l),e.fillStyle=t.tick,n>=0&&n<=c&&e.fillRect(n,r,1,l),a>=0&&a<=c&&e.fillRect(a-1,r,1,l)}else{let i=e.globalAlpha;e.globalAlpha=i*Jfe,e.fillStyle=t.picture;let c=-1/0;d1(d,a,o,({id:t,start:i,end:a})=>{let o=s.xAt(a);if(o<=c||!n.listed.has(t))return;let u=Math.max(s.xAt(i),c);e.fillRect(u,r+2,Math.max(o-u,1),l-5),c=Math.max(o,u+1)}),e.globalAlpha=i}e.fillStyle=t.line,e.fillRect(0,i(r+l)-1,c,1)}#r(e,t,n,r){let{node:i,box:a,component:o}=n,s=Q2(n);if(i.kind!==`property`||!a||!s)return;let c=this.#e.keyframes.shownValue(a.clip,i.spec.path)??i.spec.default,l=p2(o?bF(c,o.index):c);if(!l)return;let u=i.rows[o?o.index+1:0];if(u?.band===`segments`){this.#i(e,t,n,i.spec,a,l,r);return}if(u?.band===`gradient`){this.#a(e,n,i.spec,a,l,r);return}if(u?.curve!==`value`)return;let d=this.#e.scaleOf(n,a),f=RF(l,s.type);d&&f&&(n.tall&&this.#s(e,t,s,a,d,r),this.#o(e,t,n,a,l,f,d,r))}#i(e,t,n,r,i,a,{y:o,from:s,to:c}){let l=this.#e,u=e.globalAlpha,d=[t.picture,t.sound,t.caption],f=o+3,p=n.height-7,{seconds:m}=u2(a),h=i.offset-i.start,g=Math.max(d2(m,s+h)-1,0);for(let n=g;n<m.length;n+=1){let o=m[n]-h;if(o>c)break;let s=m[n+1],g=l.xAt(o),_=Math.max(l.xAt(s===void 0?i.end:s-h),g),{value:v}=a.keys[n];if(e.globalAlpha=u*Yfe,e.fillStyle=v===!1?t.tick:d[n%d.length],e.fillRect(g,f,_-g,p),e.globalAlpha=u,_-g>=Gfe){e.save(),e.beginPath(),e.rect(g,f,_-g,p),e.clip(),e.fillStyle=t.label;let n=Math.max(g,0)+10;e.fillText(this.#t(r,v),n,f+p/2),e.restore()}}}#a(e,t,n,r,i,{y:a,from:o,to:s}){let c=RF(i,n.type);if(!c)return;let l=this.#e,u=r.offset-r.start,d=Math.max(l.xAt(Math.max(r.start,o)),0),f=Math.min(l.xAt(Math.min(r.end,s)),l.width),p=a+3,m=t.height-7,h=e.globalAlpha;e.globalAlpha=h*Xfe;for(let t=d;t<f;t+=S3){let n=nn(c,l.timeAt(t+S3/2)+u);typeof n==`string`&&(e.fillStyle=n,e.fillRect(t,p,Math.min(S3,f-t),m))}e.globalAlpha=h}#o(e,t,n,r,i,a,o,{y:s,from:c,to:l}){let u=this.#e,d=r.offset-r.start,{seconds:f}=u2(i),p=(f[0]??0)-d,m=(f.at(-1)??0)-d,h=Math.max(Math.min(r.start,p),c),g=Math.min(Math.max(r.end,m),l);if(!(g>h))return;let _={x:e=>u.xAt(e-d),clockAt:e=>u.timeAt(e)+d,y:e=>s+m3(o,e)},v=new Path2D;Zfe(v,a,_,u.xAt(h),u.xAt(g));let y=n.height-1;e.save(),e.beginPath(),e.rect(0,s,u.width,y),e.clip(),e.strokeStyle=t.curve,e.lineWidth=Ufe,e.lineJoin=`round`;let b=e.globalAlpha;e.globalAlpha=b*x3,e.stroke(v);let x=u.xAt(r.start);e.beginPath(),e.rect(x,s,u.xAt(r.end)-x,y),e.clip(),e.globalAlpha=b,e.stroke(v),e.restore()}#s(e,t,n,r,i,{y:a}){let o=this.#e,s=Math.round(a+m3(i,i.high)),c=Math.round(a+m3(i,i.low));e.save(),e.fillStyle=t.line,e.fillRect(0,s,o.width,1),e.fillRect(0,c,o.width,1),e.fillStyle=t.label,e.font=`11px ${t.font}`,e.textBaseline=`middle`;let l=Math.max(o.xAt(r.start),0)+Wfe;e.fillText(A2(i.high,n),l,s+b3),e.fillText(A2(i.low,n),l,c-b3),e.restore()}#c(e,t,n,r){let i=this.#e,{from:a,to:o}=r,s=g3/i.pixelsPerSecond,{keyframes:c}=i,l=Math.abs(c.preview?.shift??0),u=-1/0;i.forEachBox(n,a-s-l,o+s+l,a=>{let o=i.xAt(a.end);if(o<=u&&!c.selection.hasClip(a.id))return;let s=i.tableOf(n,a);s&&s.seconds.length!==0&&(this.#l(e,t,n,a,s,r),u=Math.max(o,i.xAt(a.start)+y3))})}#l(e,t,n,r,i,{y:a,from:o,to:s}){let c=this.#e,{keyframes:l,pixelsPerSecond:u,width:d}=c,{node:f}=n,p=f.kind!==`property`,m=p?Bfe:g3,h=p?e.keySummary:e.key,g=a+n.height/2,{seconds:_,marks:v}=i,y=r.offset-r.start,b=l.selectedSeconds(n,r),x=l.triedSeconds(n,r),{preview:S}=l,ee=S?.shift,C=l.canMove(r.id),w=c.scaleOf(n,r),te=w?i.numbers:void 0,ne=Q2(n),re=ne&&S?.lift?.get(l3(r.id,ne.path,n.component?.index)),ie=e=>te&&w?a+m3(w,te[e]):g,ae=10/u+Math.abs(ee??0),oe=d2(_,o+y-ae),se=s+y+ae;if(p){let e=Math.min(d2(_,se),_.length-1);if(e>oe){let n=c.xAt((_[oe]??0)-y),r=c.xAt((_[e]??0)-y),i=t.in(h,.45),a=Math.max(n,0);i.rect(a,g-.5,Math.min(r,d)-a,1)}}let ce=-1/0,le=-1/0;for(let i=oe;i<_.length;i+=1){let o=_[i];if(o>se)break;let s=o-y,l=c.xAt(s),d=ie(i),f=b!==void 0&&f2(b,o)>=0,p=x!==void 0&&f2(x,o)>=0;if(l-ce<y3&&(!te||Math.abs(d-le)<g3)&&!f&&!p){if(!te){let e=d2(_,c.timeAt(ce+y3)+y);e>i+1&&(i=e-1)}continue}ce=l,le=d;let g=c.markIn(n,v[i]),S=s<r.start||s>=r.end?x3:1;if(f&&C&&(ee!==void 0||re!==void 0)){let n=re!==void 0&&te&&w&&ne?a+m3(w,c3(ne,te[i]+re)):d;C3(t.in(h,Kfe),g,l,d,m),C3(t.in(e.selected),g,l+(ee??0)*u,n,m)}else C3(f?t.in(e.selected,S):p?t.in(e.keyTried,S):t.in(h,S),g,l,d,m)}}#u(e,t){let n=this.#e,r=n.visibleHandles();if(r.length===0)return;let{keyframes:i}=n,a=i.isPreviewOf(n)?i.preview?.handle:void 0,o=e=>a?.clamped===!0&&e.box.id===a.clip&&e.path===a.path&&e.component===a.component&&e.time===a.time&&e.side===a.side,s=new Path2D,c=new w3,l=c.in(t.handle),u;for(let e of r)o(e)?u=e:(s.moveTo(e.keyX,e.keyY),s.lineTo(e.x,e.y),l.moveTo(e.x+_3,e.y),l.arc(e.x,e.y,_3,0,v3));e.save(),e.lineWidth=1,e.strokeStyle=t.handle,e.stroke(s),c.fill(e),u&&a&&(e.strokeStyle=t.warning,e.fillStyle=t.warning,e.beginPath(),e.moveTo(u.keyX,u.keyY),e.lineTo(u.x,u.y),e.stroke(),e.setLineDash([3,3]),e.beginPath(),e.moveTo(u.x,u.y),e.lineTo(a.x,a.y),e.stroke(),e.setLineDash([]),e.beginPath(),e.arc(u.x,u.y,4,0,v3),e.fill()),e.restore()}},Qfe=class extends j4{#e;#t;#n;#r=[];constructor(e,t,n){super(e),this.#e=t,this.#t=new T3(t,n)}paint(){let e=this.#e,{model:t,width:n,height:r,pixelsPerSecond:i}=e;if(n===0||r===0||i===0||!this.canvas.isConnected)return;let a=e.whatIsDrawn;if(!this.isWiped&&a.every((e,t)=>e===this.#r[t]))return;this.#r=a,this.isWiped=!1,this.#n??=A4(this.canvas);let o=this.#n,{context:s,ratio:c}=this,l=e=>this.sharp(e);if(s.setTransform(c,0,0,c,0,0),s.fillStyle=o.background,s.fillRect(0,0,n,r),!t)return;s.font=`12px ${o.font}`,s.textBaseline=`middle`,s.save(),s.beginPath(),s.rect(0,28,n,r-28),s.clip(),this.#t.paint(s,o,l);let u=l(e.xAt(e.visibleDuration));u<n&&(s.fillStyle=o.outside,s.fillRect(Math.max(u,0),28,n,r)),E3(s,e,o),s.restore(),k4(s,e,t.rate,28,{...o,background:o.ruler},l),D3(s,e,o,l)}};function E3(e,t,n){let{keyframes:r}=t,i=r.isPreviewOf(t)?r.preview?.marquee:void 0;if(!i)return;let a=t.xAt(i.from),o=t.xAt(i.to)-a,s=t.screenY(i.top),c=i.bottom-i.top;e.fillStyle=n.marquee,e.globalAlpha=.2,e.fillRect(a,s,o,c),e.globalAlpha=1,e.strokeStyle=n.marquee,e.lineWidth=1,e.strokeRect(a+.5,s+.5,o-1,c-1)}function D3(e,t,n,r){let i=t.keyframes.preview?.snap;i!==void 0&&(e.fillStyle=n.snap,e.fillRect(r(t.xAt(i)),0,1,t.screenHeight))}var O3={file:(e,t)=>ZK(e,t),copy(e){let t=QK(e);return{content:t.content,hash:async()=>t.hash(),abandon:()=>{}}}},k3=33554432,A3=Symbol(`lost`);function $fe(){let e,t=typeof Worker>`u`,n=0,r=new Map,i=()=>{t=!0,e?.terminate(),e=void 0;let n=[...r.values()];r.clear();for(let e of n)e.lost()},a=()=>{if(!t){if(e)return e;try{e=new Worker(new URL(`/assets/hash-worker-DFBtzCrB.js`,``+import.meta.url),{type:`module`,name:`hashes`})}catch(e){console.warn(`Hashes are found out on the page itself`,e),t=!0;return}return e.addEventListener(`message`,e=>{let t=e.data,n=r.get(t.job);n&&(t.kind===`progress`?n.onProgress?.(t.bytes):t.kind===`took`?n.onTook?.(t.bytes):(r.delete(t.job),t.kind===`done`?n.resolve(t.hash):n.reject(new DOMException(t.message,t.name))))}),e.addEventListener(`error`,e=>{e.preventDefault(),console.warn(`The worker for hashes stopped`,e.message),i()}),e}},o=(e,t,n=[])=>e.postMessage(t,n),s=(e,t,{signal:i,onProgress:a})=>new Promise((s,c)=>{let l=n++,u=()=>{r.delete(l),o(e,{kind:`cancel`,job:l}),c(i?.reason)},d=()=>i?.removeEventListener(`abort`,u);r.set(l,{onProgress:a,resolve:e=>(d(),s(e)),reject:e=>(d(),c(e)),lost:()=>(d(),c(A3))}),i?.addEventListener(`abort`,u,{once:!0}),o(e,{kind:`file`,job:l,file:t})}),c=(e,t,n)=>{let i=0,a,s=()=>{a?.resolve(),a=void 0};return r.set(t,{onTook(e){i-=e,i<k3&&s()},resolve:e=>n(e),reject:()=>n(void 0),lost(){n(void 0),s()}}),o(e,{kind:`start`,job:t}),{async add(n){if(!r.has(t))return;let s=n.slice();if(i+=s.byteLength,o(e,{kind:`piece`,job:t,piece:s},[s.buffer]),i<k3)return;let c=()=>{},l=new Promise(e=>c=e);a={promise:l,resolve:c},await l},end(){r.has(t)&&o(e,{kind:`end`,job:t})},abandon(){r.delete(t)&&(o(e,{kind:`cancel`,job:t}),n(void 0),s())}}};return{async file(e,t={}){t.signal?.throwIfAborted();let n=a();if(!n)return ZK(e,t);try{return await s(n,e,t)}catch(n){if(n===A3)return ZK(e,t);throw n}},copy(e){let t=a();if(!t)return O3.copy(e);let r=Promise.resolve(void 0),i;return{content:new class extends Blob{stream(){i?.abandon();let a=()=>{};r=new Promise(e=>a=e);let o=c(t,n++,a);return i=o,e.stream().pipeThrough(new TransformStream({async transform(e,t){t.enqueue(e),await o.add(e)},flush:()=>o.end()}))}}([e],{type:e.type}),hash:()=>r,abandon:()=>i?.abandon()}}}}var j3=e=>wk(e)!==void 0,M3=e=>!jH(e)&&(j3(e)||XN(e)),epe=/^(?:timelines|scenes|sounds|code|locales)(?:\/|$)/,tpe=e=>epe.test(e)&&!e.split(`/`).some(kH),N3=(e,t)=>t===`folder`?tpe(e):M3(e);function npe(e){return e===`animaquill.json`?4:e===`notes.json`||/^timelines\/[^/]+\/overrides\//.test(e)?3:/^timelines\/[^/]+\/timeline\.json$/.test(e)?2:+!!/^(?:scenes|sounds)\/[^/]+\/(?:scene|sound)\.json$/.test(e)}function P3(e,t=!1){let n=new Map;for(let t of e){let e=npe(t);n.set(e,[...n.get(e)??[],t])}return[...n.keys()].toSorted((e,n)=>t?n-e:e-n).map(e=>(n.get(e)??[]).toSorted())}var rpe=new TextDecoder(`utf-8`,{fatal:!0,ignoreBOM:!0});function ipe(e){try{return rpe.decode(e)}catch{return}}var ape=(e,t)=>t===void 0||ope(e,t)||XN(e)&&/^\0*$/.test(t);function ope(e,t){let n=wk(e);return n!==void 0&&Tk(e,t.replace(/^/,``),n).problems.length>0}var spe=(e,t)=>!j3(e)&&t>KN;function F3(e){try{let t=JSON.parse(e.replace(/^\uFEFF/,``))?.formatVersion;return typeof t==`number`?t:void 0}catch{return}}function I3(e){try{let t=JSON.parse(e.replace(/^\uFEFF/,``))?.id;return typeof t==`string`?t:void 0}catch{return}}var L3=`assets`,R3={reading:[],waiting:[]},cpe=2e3,z3=65536;async function B3(e){let t=Math.max(0,Math.floor(e.size/2)-z3/2),n=Math.max(0,e.size-z3),r=new Blob([e.slice(0,z3),e.slice(t,t+z3),e.slice(n)]);return[...new Uint8Array(await crypto.subtle.digest(`SHA-256`,await r.arrayBuffer()))].map(e=>e.toString(16).padStart(2,`0`)).join(``)}var V3=e=>e.startsWith(`sha256-`),lpe=5e3,H3=e=>e.startsWith(`${L3}/`),U3=(e,t)=>e!==void 0&&e.size===t.size&&e.lastModified===t.lastModified,upe=6e4,W3=({hashedAt:e,lastModified:t})=>e===void 0||t>e-2e3&&t<e+upe,G3=(e,t)=>typeof e==`object`&&!!e&&e.name===t,K3=class{#e;#t;#n;#r=new Map;#i=new Map;#a=new Map;#o=new Map;#s;#c=new Map;#l=!1;constructor(e){this.#e=e,this.#t=e.hasher??O3,this.#n=e.now??Date.now}get#u(){return this.#e.folder()}stop(){this.#l=!0;for(let e of this.#c.values())clearTimeout(e);this.#c.clear()}#d(){let e=[...this.#a].map(([e,t])=>({path:e,percent:t})),t=[...this.#o.keys()].filter(e=>this.#a.has(e));this.#e.onProgress?.({reading:e,waiting:t,...this.#s&&{checked:this.#s}})}async fileAt(e,t={}){for(let n=1;;n++){let r;try{r=await this.#u.file(e)}catch(e){return e instanceof ba&&(e.reason===`missing`||e.reason===`refused`)?{kind:`missing`}:{kind:`unknown`}}try{return{kind:`there`,file:r,hash:await this.#f(e,r,t)}}catch(e){if(n===1&&G3(e,`NotReadableError`))continue;return G3(e,`NotFoundError`)?{kind:`missing`}:{kind:`unknown`}}}}async#f(e,t,{since:n}){let{bases:r,key:i}=this.#e,a=this.#r.get(e);if(!U3(a,t)){let n=await r.hashOf(i,e).catch(()=>void 0);U3(n,t)&&this.#r.set(e,n),a=n}if(U3(a,t)&&!W3(a)&&(n===void 0||(a.hashedAt??0)>=n)&&a.samples!==void 0&&a.samples===await B3(t)&&a)return a.hash;let o=await this.#p(e,t);return U3(a,t)&&!eq(a.hash,o.hash)&&this.#e.onChanged?.([e]),o.hash}async#p(e,t){let n=`${e}\n${t.size}\n${t.lastModified}`,r=this.#i.get(n);if(!r){let i=this.#n();this.#a.set(e,0),this.#d(),r=Promise.all([this.#t.file(t,{onProgress:n=>{let r=t.size>0?Math.floor(n/t.size*100):100;this.#a.get(e)!==r&&(this.#a.set(e,r),this.#d())}}),B3(t)]).then(([n,r])=>{let a={path:e,size:t.size,lastModified:t.lastModified,hash:n,samples:r,hashedAt:i};return this.#m(a),a}).finally(()=>{this.#i.delete(n),this.#a.delete(e),this.#d()}),this.#i.set(n,r)}return r}#m(e){if(this.#l)return;this.#r.set(e.path,e);let{bases:t,key:n}=this.#e;t.keepHash(n,e).catch(()=>{}),W3(e)&&this.#h(e)}#h({path:e,lastModified:t}){if(this.#l||this.#c.has(e))return;let n=Math.max(0,t+cpe-this.#n())+100;this.#c.set(e,setTimeout(()=>{this.#c.delete(e),this.#l||this.fileAt(e)},n))}async#g(e,t){this.#o.set(e,(this.#o.get(e)??0)+1),this.#d();try{return await this.fileAt(e,t)}finally{let t=(this.#o.get(e)??1)-1;t>0?this.#o.set(e,t):this.#o.delete(e),this.#d()}}media(e,t={}){let{browser:n}=this.#e;return{put:(e,t)=>V3(e)?Promise.reject(Error(`The file of an asset goes into the project folder`)):n.put(e,t),get:async r=>{if(!V3(r))return n.get(r);let i=Object.values(e()??{}).filter(e=>e.hash!==void 0&&eq(e.hash,r)).map(({path:e})=>e);for(let e of new Set(i)){let n=await this.#g(e,t);if(n.kind===`there`&&eq(n.hash,r))return n.file}},listMade:()=>n.listMade(),touchMade:e=>n.touchMade(e),removeMade:e=>n.removeMade(e)}}hashOutside(e,t={}){return this.#t.file(e,t)}async copyIn(e,{signal:t,onProgress:n}={}){let r=this.#u,i=new Set;for await(let e of r.list({includes:(e,t)=>t===`folder`&&e===`assets`||H3(e)}))i.add(e.slice(7).split(`/`)[0]);for(let a=1;;a++){let o=`${L3}/${fi(e.name,i,L3)}`,s=this.#n(),c=this.#t.copy(e),l;try{l=await r.write(o,c.content,{expected:`absent`,...t&&{signal:t},...n&&{onProgress:n}})}catch(e){if(c.abandon(),e instanceof ba&&(e.reason===`changed`||e.reason===`exists`||e.reason===`busy`)&&a<5){i.add(o.slice(7));continue}throw e}let u=await c.hash()??await this.#t.file(l),{size:d,lastModified:f}=l;return this.#m({path:o,size:d,lastModified:f,hash:u,samples:await B3(l),hashedAt:s}),{path:o,hash:u,written:l}}}async remove(e,t){await this.#u.remove(e,{expected:t}).catch(()=>{})}async check(e){let t=[],n=[],r=Object.entries(e.getState().assets??{});try{for(let[e,[i,{path:a,hash:o,size:s,storage:c}]]of r.entries()){if(this.#s={done:e,total:r.length},this.#d(),c===`remote`)continue;let l=await this.fileAt(a);if(l.kind!==`unknown`){if(l.kind===`missing`){let e=a.split(`/`).find(Gr);e===void 0?o!==void 0&&s!==void 0?n.push({asset:i,path:a,hash:o,size:s}):t.push({kind:`missing`,asset:i,path:a}):t.push({kind:`missing`,asset:i,path:a,hidden:e})}else o!==void 0&&!eq(o,l.hash)&&t.push({kind:`changed`,asset:i,path:a})}}}finally{this.#s=void 0,this.#d()}if(n.length>0){let r=await this.#_(n,e);for(let{asset:e,path:i,hash:a}of n){let n=r.get(a),o=await this.#e.browser.get(a).catch(()=>void 0);t.push({kind:`missing`,asset:e,path:i,...n!==void 0&&{found:n},...o&&{copy:!0}})}}return t}async#_(e,t){let n=new Set(e.map(({size:e})=>e)),r=new Set(Object.values(t.getState().assets??{}).map(({path:e})=>e)),i=new Map,a=0;try{for await(let t of this.#u.list({includes:(e,t)=>t===`folder`||!jH(e)&&!M3(e)})){if(++a>lpe)break;if(r.has(t))continue;let o;try{o=await this.#u.file(t)}catch{continue}if(!n.has(o.size))continue;let s=await this.#f(t,o,{}).catch(()=>void 0),c=s&&e.find(e=>eq(e.hash,s));if(c&&!i.has(c.hash)&&i.set(c.hash,t),i.size===e.length)break}}catch{}return i}async removeEmpty(e){let t=new Set(Object.values(e.getState().assets??{}).map(({path:e})=>e)),n=this.#u,r=[];try{for await(let e of n.list({includes:(e,t)=>t===`folder`&&e===`assets`||H3(e)})){if(t.has(e))continue;let i=await n.file(e).catch(()=>void 0);if(i?.size===0)try{await n.remove(e,{expected:i}),r.push(e)}catch{}}}catch{}return r}watch(e,t){let n=this.#u.watch({includes:(e,t)=>t===`folder`?e===`assets`||H3(e):H3(e)&&!jH(e),files:e,newTimes:!0,onChange:e=>t(e.map(({path:e})=>e)),onProblem:()=>{}});return n.ready.catch(()=>{}),()=>n.stop()}},q3,J3={start(e){q3=e,addEventListener(`dragend`,()=>J3.end(),{once:!0,capture:!0})},end(){q3=void 0},current(){return q3}},Y3={panel:`_panel_5iiqe_1`,dropping:`_dropping_5iiqe_2`,toolbar:`_toolbar_5iiqe_13`,browser:`_browser_5iiqe_40`},X3=`application/x-animaquill-asset`,Z3=`application/x-animaquill-scene`,Q3=`application/x-animaquill-sound`,dpe={asset:X3,scene:Z3,sound:Q3};function fpe(e,t){if(!t)return``;let n=pq(e,t);return e%t.nominal===0?n.replace(/\/\d+$/,``):n}var $3=e=>e.kind!==`asset`||e.asset.kind!==`font`;function e6(e,t){t.dataTransfer.setData(dpe[e.kind],e.id),t.dataTransfer.effectAllowed=`copy`,J3.start({kind:e.kind,id:e.id})}var t6=()=>()=>{},ppe=()=>R3;function mpe(){let e=U(),{media:t,timeline:n,resourceHabits:r}=e,{t:i}=F(),{store:a}=ev(),o=tv(a),s=(0,N.useSyncExternalStore)(t.subscribe,t.getImporting),c=(0,N.useSyncExternalStore)(t.subscribe,t.getCopying),l=e.projectFolders,u=(0,N.useSyncExternalStore)(l?.subscribe??t6,()=>l?.getSnapshot().open!==void 0),d=(0,N.useSyncExternalStore)(l?.subscribeProgress??t6,l?.getProgress??ppe),[f]=d.reading,[p,m]=(0,N.useState)(!1),[h,g]=p0(),_=(0,N.useMemo)(()=>o?H$(o,o.manifest.id).filter(({type:e})=>R$.has(e)):[],[o]),v=({data:e})=>$3(e)?void 0:{reason:i(`assetPanel.why.font`),draggable:!1},y=e=>{let{data:t}=e,a=n.addMedia({kind:t.kind,id:t.id});if(!a){g(e.id,i(`assetPanel.failed`),void 0,!0);return}r.used(e.id);let o=i(`assetPanel.added`,{tracks:a.tracks.map(({kind:e,number:t,name:n})=>n??i(`timeline.track.${e}`,{number:t})).join(`、`),start:fpe(a.frame,n.model?.rate)});g(e.id,`${e.name}${o}`,`✓ ${o}`)},b=e=>e.dataTransfer.types.includes(`Files`);return(0,L.jsxs)(`div`,{className:p?Y3.dropping:Y3.panel,onDragOver:e=>{b(e)&&(e.preventDefault(),m(!0))},onDragLeave:()=>m(!1),onDrop:t=>{b(t)&&(t.preventDefault(),m(!1),e.importDropped(t.dataTransfer))},children:[(0,L.jsxs)(`div`,{className:Y3.toolbar,children:[(0,L.jsxs)(`button`,{type:`button`,onClick:()=>void e.pickFiles(),children:[(0,L.jsx)(hf,{size:14}),i(`assets.import`)]}),(0,L.jsxs)(`button`,{type:`button`,onClick:()=>n.createScene(),children:[(0,L.jsx)(wd,{size:14}),i(`assets.newScene`)]}),(0,L.jsxs)(`button`,{type:`button`,onClick:()=>n.createSound(),children:[(0,L.jsx)(wd,{size:14}),i(`assets.newSound`)]}),s>0&&!c&&(0,L.jsx)(`span`,{role:`status`,children:i(`assets.importing`,{count:s})}),f&&(0,L.jsxs)(`span`,{role:`status`,title:d.reading.map(({path:e,percent:t})=>`${e} ${t}%`).join(`
213
213
  `),children:[d.checked&&i(`folder.checking.progress`,d.checked),` `,i(`folder.checking.reading`,{path:f.path,percent:f.percent,interpolation:{escapeValue:!1}})]}),c&&(0,L.jsxs)(`span`,{role:`status`,children:[i(`folder.copy.${c.stage}`,{name:c.name,percent:c.percent}),(0,L.jsx)(`button`,{type:`button`,onClick:c.stop,children:i(`folder.copy.stop`)})]})]}),(0,L.jsx)(`div`,{className:Y3.browser,children:(0,L.jsx)(x0,{tab:`assets`,label:i(`panel.assets.title`),searchLabel:i(`assetPanel.search`),resources:_,types:L$,defaultGrouping:`type`,typeName:e=>f0(i,e),empty:i(u?`assets.emptyFolder`:`assets.empty`),unavailable:v,Icon:d0,onActivate:y,notice:h,onDragStart:(e,t)=>e6(e.data,t),onDragEnd:(e,t)=>{t&&r.used(e.id)}})})]})}var n6=` · `;function r6(e){let t=bA(e);if(t.length===0)return;let n=t.filter(({enabled:e})=>e!==!1),r=n.length>0?n:t,i=O(j(e.duration)),a=e=>Math.min(Math.max(e,0),i),o=r.map(({type:e,start:t,end:n})=>({type:e,span:[t===void 0?0:a(O(j(t))),n===void 0?i:a(O(j(n)))]})).filter(({span:[e,t]})=>t>e),s=o.map(({span:e})=>e).toSorted((e,t)=>e[0]-t[0]),c=[];for(let[e,t]of s){let n=c.at(-1);n&&e<=n[1]?n[1]=Math.max(n[1],t):c.push([e,t])}return{spans:c,types:[...new Set(o.map(({type:e})=>e))],off:n.length===0}}var i6=2,a6=3,o6=28,s6=6,c6=3,l6=6,u6=13,d6=4,f6=34,hpe=20,p6=8,gpe={video:52,audio:44},_pe=`#00000066`,vpe=`#ffffffd9`,ype=`#000000a6`,bpe=`#000000d0`,xpe=`#ffffff59`,Spe=24,Cpe=5,wpe=`#ffffffa6`,Tpe=`#ffffff80`,m6=24,h6=6,Epe=8;function g6(e){let t=Number.parseInt(e.slice(1,7),16),[n,r,i]=[t>>16,t>>8&255,t&255];return n*.299+r*.587+i*.114>150?`#000000`:`#ffffff`}function Dpe(e,t,n){if(e.measureText(t).width<=n)return t;let r=0,i=t.length;for(;r<i;){let a=Math.ceil((r+i)/2);e.measureText(`${t.slice(0,a)}…`).width<=n?r=a:i=a-1}return r>0?`${t.slice(0,r)}…`:``}var _6=3,Ope=class extends j4{#e;#t;#n;#r;#i;#a;#o;#s;#c;#l;constructor(e,t,n,r,i,a,o,s,c,l){super(e),this.#e=t,this.#t=n,this.#n=o,this.#r=s,this.#i=r,this.#a=i,this.#o=a,this.#s=c,this.#c=l}paint(){let{model:e,width:t,height:n,pixelsPerSecond:r}=this.#e;if(t===0||n===0||r===0||!this.canvas.isConnected)return;this.#l??=A4(this.canvas);let{context:i,ratio:a}=this;i.setTransform(a,0,0,a,0,0),i.fillStyle=this.#l.background,i.fillRect(0,0,t,n),e&&(i.font=`12px ${this.#l.font}`,i.textBaseline=`middle`,i.save(),i.beginPath(),i.rect(0,28,t,n-28),i.clip(),this.#d(e),this.#f(e),this.#y(e),this.#p(),this.#c?.(i,this.#l,e=>this.sharp(e)),this.#N(),this.#P(),i.restore(),this.#F(e),this.#I())}#u(e){return 28-this.#e.scrollY+e.top}#d(e){let{width:t,height:n}=this.#e,{context:r}=this;for(let i of e.rows){let e=this.#u(i);e+i.height<28||e>n||(r.fillStyle=i.track.locked?this.#l.laneLocked:this.#l.lane,r.fillRect(0,e,t,i.height),r.fillStyle=this.#l.line,r.fillRect(0,this.sharp(e+i.height)-1,t,1))}}#f(e){let t=this.#e,{selection:n}=t.getSnapshot(),r=t.preview?.copying?void 0:t.preview?.clips,{cut:i}=t.getSnapshot(),a=t.timeAt(0),o=t.timeAt(t.width),{hovered:s}=t;for(let c of e.rows){let e=this.#u(c);e+c.height<28||e>t.height||d1(c,a,o,e=>{let t=r?.has(e.id)===!0,a=s.kind===`clip`&&s.box===e?s:void 0;this.context.globalAlpha=t||i.has(e.id)?.35:1,this.#g(e,{row:c,start:e.start,end:e.end,selected:!t&&n.has(e.id),edge:a?.edge,hovered:a!==void 0&&!t,handle:a?.handle,transition:a?.transition}),this.context.globalAlpha=1})}}#p(){let e=this.#e,{model:t,preview:n}=e;if(!t||!n)return;let{context:r}=this,i=e.timeAt(0),a=e.timeAt(e.width);for(let[e,{row:r,start:o,end:s}]of n.clips??[]){let n=t.boxes.get(e);n&&s>i&&o<a&&this.#g(n,{row:r,start:o,end:s,selected:!0})}r.fillStyle=this.#l.covered,r.globalAlpha=.7;for(let{row:t,from:o,to:s}of n.covered??[]){if(s<=i||o>=a)continue;let n=this.#u(t)+i6,c=e.xAt(o);r.fillRect(c,n,e.xAt(s)-c,t.height-4-1)}r.globalAlpha=1,this.#m(t,n.adding),this.#h(t,n.transitionDrop)}#m(e,t){if(!t)return;let n=this.#e,{context:r}=this;for(let i of t){let t=this.sharp(n.xAt(i.start)),a=Math.max(this.sharp(n.xAt(i.end))-t,2),o=i.row===void 0?void 0:e.rows.find(({id:e})=>e===i.row),s,c,l=i.label;if(o)s=this.#u(o)+i6,c=o.height-4-1;else{let t=e.rows.find(({track:e})=>e.kind===i.kind),a=i.kind===`video`&&t?t.top:e.height,o=this.sharp(28-n.scrollY+a);c=Math.round(gpe[i.kind]*e.rowScale),s=i.kind===`video`&&t?o-c:o,r.fillStyle=this.#l.selected,r.fillRect(0,o-1,n.width,2);let u=e.rows.filter(({track:e,gone:t})=>e.kind===i.kind&&!t),d=this.#s(i.kind,u.length+1);l=l?`${d} · ${l}`:d}r.save(),r.globalAlpha=.55,r.fillStyle=i.kind===`audio`?this.#l.sound:this.#l.picture,r.beginPath(),r.roundRect(t,s,a,c,a6),r.fill(),r.globalAlpha=1,r.strokeStyle=this.#l.selected,r.lineWidth=2,r.setLineDash([5,3]),r.beginPath(),r.roundRect(t+1,s+1,a-2,c-2,a6),r.stroke(),r.setLineDash([]),a>=o6&&l&&(r.beginPath(),r.rect(t,s,a,c),r.clip(),r.fillStyle=`#ffffff`,r.fillText(l,t+s6,s+Math.min(c/2,12))),r.restore()}}#h(e,t){let n=t&&e.rows.find(({id:e})=>e===t.row);if(!t||!n)return;let r=this.#e,{context:i}=this,a=this.#u(n)+i6,o=n.height-4-1,s=this.sharp(r.xAt(t.start)),c=Math.max(this.sharp(r.xAt(t.end))-s,p6);i.globalAlpha=.35,i.fillStyle=this.#l.selected,i.fillRect(s,a,c,o),i.globalAlpha=1,i.strokeStyle=this.#l.selected,i.lineWidth=2,i.strokeRect(s+1,a+1,c-2,o-2)}#g(e,t){let n=this.#e,{context:r}=this,{row:i}=t,a=this.#u(i)+i6,o=i.height-4-1,s=this.sharp(n.xAt(t.start)),c=this.sharp(n.xAt(t.end)),l=Math.max(c-s,1/this.ratio),u=this.#D(e),{track:d}=i,f=d.kind===`audio`?d.muted===!0:d.hidden===!0,p=r.globalAlpha;f&&(r.globalAlpha=p*.45),r.fillStyle=u,l<9?r.fillRect(s,a,l,o):(r.beginPath(),r.roundRect(s,a,l,o,a6),r.fill()),e.clip.source.kind===`video`&&this.#T(e,t,{left:s,right:c,top:a,height:o,width:l}),(e.clip.source.kind===`audio`||e.clip.source.kind===`sound`)&&this.#E(e,t,{left:s,right:c,top:a,height:o},u);let m=n.showsExpander(e)?n.expanderAt(s,l):void 0,h=this.#_(e);if(l>=o6){let r=t.start===e.start?i.joins.find(({to:t})=>t.id===e.id):void 0,c=Math.max(h.enter,r?r.end-e.start:0),d=c>0?n.xAt(t.start+c)-s:0;this.#M(e,s,a,l,o,u,d)}if(this.#v(e,t,h,{left:s,right:c,top:a,height:o,width:l}),this.#O(e,t,{left:s,right:c,top:a,height:o,width:l},m),m!==void 0&&this.#j(e,m,a+o,u),this.#k(e,{left:s,top:a,height:o,width:l}),this.#o(e.clip)&&(r.fillStyle=this.#l.failed,r.fillRect(s,a+o-_6,l,_6)),t.edge){r.fillStyle=`#ffffff66`;let e=t.edge===`start`?s:c-l6;r.fillRect(e,a,l6,o)}let g=n.getSnapshot().transition,_=g!==void 0&&!b4(g)&&g.clip===e.id;(t.selected||t.hovered||_)&&this.#w(e,t,h,{left:s,right:c,top:a}),t.selected&&(r.strokeStyle=this.#l.selected,r.lineWidth=1.5,r.beginPath(),r.roundRect(s+.75,a+.75,l-1.5,o-1.5,a6),r.stroke()),r.globalAlpha=p}#_(e){let t=this.#e.preview?.transition,n=Y$(e.clip);return t?.clip===e.id?{...n,[t.edge]:t.seconds}:n}#v(e,t,n,r){if(n.enter<=0&&n.exit<=0)return;let i=this.#e,{context:a}=this,{left:o,right:s,top:c,height:l,width:u}=r,{model:d}=i,f=i.getSnapshot().transition;a.save(),a.beginPath(),a.roundRect(o,c,u,l,a6),a.clip();for(let r of K$){let a=n[r];if(a<=0)continue;let u=e.clip[r]??{type:`fade`,duration:String(a)},[p,m]=r===`enter`?[o,Math.min(i.xAt(t.start+a),s)]:[Math.max(i.xAt(t.end-a),o),s];this.#S(r,u,{from:p,to:m,top:c,bottom:c+l});let h=!e.clip[r]||d!==void 0&&X$(d,e,r),g=f!==void 0&&!b4(f)&&f.clip===e.id&&f.edge===r;this.#C({from:p,to:m,top:c,label:this.#n(u,r,t.row),hovered:t.transition===r,chosen:g,works:h});let _=i.flashOf(`edges`,`${e.id}:${r}`);_>0&&this.#A(_,p,c,Math.max(m-p,4),16)}a.restore()}#y(e){let t=this.#e,{context:n}=this,r=t.preview?.clips,i=t.preview?.join,a=t.getSnapshot().transition,{hovered:o}=t,s=t.timeAt(0),c=t.timeAt(t.width);for(let l of e.rows){let e=this.#u(l)+i6;if(!(e+l.height<28||e>t.height||l.joins.length===0))for(let u of l.joins){if(r?.has(u.from.id)||r?.has(u.to.id))continue;let d=i?.id===u.id?i:u;if(d.end<s||d.start>c)continue;let f=t.xAt(d.start),p=Math.max(t.xAt(d.end),f+1),m=b4(a)&&a.join===u.id,h=o.kind===`join`&&o.join.id===u.id,g=e+l.height-4-1;this.#S(`join`,u.join.transition,{from:f,to:p,top:e,bottom:g}),this.#C({from:f,to:p,top:e,label:this.#n(u.join.transition,`join`,l),hovered:h,chosen:m,works:u.trouble===void 0,under:()=>{this.#b(u,d,e),n.fillStyle=Tpe,n.fillRect(this.sharp(t.xAt(u.at)),e,1,16)}}),m&&!l.track.locked&&this.#x(u,f,p,e);let _=t.flashOf(`joins`,u.id);_>0&&this.#A(_,f,e,Math.max(p-f,4),16)}}}#b(e,t,n){let r=this.#e,{context:i}=this;for(let a of e.still){let e=r.xAt(Math.max(a.from,t.start)),o=r.xAt(Math.min(a.to,t.end));if(!(o<=e)){i.save(),i.beginPath(),i.rect(e,n,o-e,16),i.clip(),i.strokeStyle=wpe,i.lineWidth=1,i.beginPath();for(let t=e-16;t<o;t+=Cpe)i.moveTo(t,n+16),i.lineTo(t+16,n);i.stroke(),i.restore()}}}#x(e,t,n,r){let{context:i}=this,a=e.join.transition.align??`center`,o=[...a===`after`?[]:[t],...a===`before`?[]:[n]];for(let e of o){let t=this.sharp(e-p6/4);i.fillStyle=this.#l.selected,i.fillRect(t,r,p6/2,16)}}#S(e,t,{from:n,to:r,top:i,bottom:a}){let{context:o}=this,s=t.curve,c=[];for(let t=0;t<=m6;t++){let o=t/m6,l=s?Math.min(Math.max(pn(...s,o),0),1):o,u=e===`exit`?1-l:l;c.push([n+(r-n)*o,a-(a-i)*u])}o.fillStyle=_pe,o.beginPath(),o.moveTo(n,i);for(let[e,t]of c)o.lineTo(e,t);o.lineTo(r,i),o.closePath(),o.fill(),o.strokeStyle=vpe,o.lineWidth=1,o.beginPath(),c.forEach(([e,t],n)=>n===0?o.moveTo(e,t):o.lineTo(e,t)),o.stroke()}#C(e){let{context:t}=this,{from:n,to:r,top:i,label:a,hovered:o,chosen:s,works:c,under:l}=e,u=Math.max(r-n,1);t.fillStyle=o?bpe:ype,t.fillRect(n,i,u,16),l&&(t.save(),t.beginPath(),t.rect(n,i,u,16),t.clip(),l(),t.restore()),t.lineWidth=s?1.5:1,t.strokeStyle=s?this.#l.selected:c?xpe:this.#l.warning,t.setLineDash(c||s?[]:[3,2]),t.strokeRect(n+.5,i+.5,u-1,15),t.setLineDash([]),u<Spe||(t.save(),t.beginPath(),t.rect(n,i,u,16),t.clip(),t.fillStyle=c?`#ffffff`:this.#l.warning,t.fillText(a,n+c6+2,i+8),t.restore())}#w(e,t,n,{left:r,right:i,top:a}){let o=this.#e;if(!o.showsTransitionHandles(t.row)||i-r<16)return;let{context:s}=this,c={enter:t.start+n.enter,exit:t.end-n.exit},l=o.model?.joined;for(let u of K$){if(n[u]<=0||l?.has(`${e.id} ${u}`)===!0)continue;let d=o.xAt(c[u]),f=Math.min(Math.max(d-p6/2,r),i-p6);s.fillStyle=t.handle===u?this.#l.selected:`#ffffff`,s.strokeStyle=`#000000b3`,s.lineWidth=1,s.fillRect(this.sharp(f),a+1,p6,p6),s.strokeRect(this.sharp(f)+.5,a+1.5,7,7)}}#T(e,t,n){let r=this.#a(e.clip);if(!r||r.duration<=0)return;let i=this.#e,{context:a}=this,{image:o,count:s,duration:c}=r,l=o.width/s,u=Math.max(n.height*l/o.height,8),d=t.end-t.start===e.end-e.start?t.start-e.start:0,{offset:f}=e;a.save(),a.beginPath(),a.roundRect(n.left,n.top,n.width,n.height,a6),a.clip(),a.globalAlpha*=.8;let p=Math.max(Math.floor(-n.left/u),0),m=Math.min(n.right,i.width);for(let t=n.left+p*u;t<m;t+=u){let r=f+i.timeAt(t+u/2)-d-e.start,p=Math.min(Math.max(Math.floor(r/c*s),0),s-1)*l;a.drawImage(o,p,0,l,o.height,t,n.top,u,n.height)}a.restore()}#E(e,t,n,r){let i=this.#i(e.clip);if(!i)return;let a=this.#e,{context:o}=this,s=t.end-t.start===e.end-e.start?t.start-e.start:0,{offset:c}=e,l=t=>Math.floor((c+a.timeAt(t)-s-e.start)*100),u=n.top+n.height/2,d=o.globalAlpha;o.globalAlpha=d*.6,o.fillStyle=g6(r),o.beginPath();let f=Math.max(Math.floor(n.left),0),p=Math.min(Math.ceil(n.right),a.width);for(let e=f;e<p;e+=1){let t=Math.max(l(e),0),r=Math.min(Math.max(l(e+1),t+1),i.length),a=Math.max(Math.floor((r-t)/Epe),1),s=0;for(let e=t;e<r;e+=a)s=Math.max(s,i[e]??0);if(s===0)continue;let c=Math.max(s/255*(n.height/2),.5);o.rect(e,u-c,1,c*2)}o.fill(),o.globalAlpha=d}#D({clip:e}){let{source:t}=e;return t.kind===`color`&&typeof t.color==`string`?t.color:t.kind===`caption`?this.#l.caption:[`audio`,`sound`,`music`].includes(t.kind)?this.#l.sound:this.#l.picture}#O(e,t,n,r){let i=r6(e.clip);if(!i||i.spans.length===0)return;let a=this.#e,{context:o}=this,{left:s,right:c,top:l,height:u,width:d}=n,f=u>=f6,p=f?u6:d6,m=l+u-p;o.save(),o.beginPath(),o.roundRect(s,l,d,u,a6),o.clip(),o.globalAlpha*=i.off?.4:1,o.fillStyle=this.#l.effect;let h;for(let[e,n]of i.spans){let r=Math.max(this.sharp(a.xAt(t.start+e)),s),i=Math.min(this.sharp(a.xAt(t.start+n)),c);i<=r||(o.fillRect(r,m,Math.max(i-r,1),p),(!h||i-r>h.to-h.from)&&(h={from:r,to:i}))}let g=this.#r(i.types);if(f&&h&&g){let e=r===void 0?h.from:r+14+2,t=Math.max(h.from,e)+4,n=h.to-t-4;n>=hpe&&(o.beginPath(),o.rect(t,m,n,p),o.clip(),o.fillStyle=`#ffffff`,o.font=`600 10px ${this.#l.font}`,o.textBaseline=`middle`,o.fillText(Dpe(o,g,n),t,m+p/2+.5))}o.restore()}#k(e,{left:t,top:n,height:r,width:i}){let a=this.#e,o=a.flashOf(`clips`,e.id);o>0&&this.#A(o,t,n,i,r);let s=a.flashOf(`bands`,e.id);if(s>0){let e=r>=f6?u6:d6;this.#A(s,t,n+r-e,i,e)}}#A(e,t,n,r,i){let{context:a}=this;a.save(),a.globalAlpha*=e*.4,a.fillStyle=`#ffffff`,a.beginPath(),a.roundRect(t,n,r,i,a6),a.fill(),a.globalAlpha=Math.min(e*1.5,1),a.strokeStyle=this.#l.flash,a.lineWidth=2,a.beginPath(),a.roundRect(t+1,n+1,r-2,i-2,a6),a.stroke(),a.restore()}#j(e,t,n,r){let{context:i}=this,a=this.#e.extras?.isOpen(e)===!0,o=t+7,s=n-10;i.save(),e.clip.source.kind===`video`&&this.#a(e.clip)!==void 0?(i.fillStyle=`#000000a6`,i.fillRect(t,s-8,14,16),i.fillStyle=`#ffffff`):i.fillStyle=g6(r),i.beginPath(),a?(i.moveTo(o-4,s-2),i.lineTo(o+4,s-2),i.lineTo(o,s+3)):(i.moveTo(o-2,s-4),i.lineTo(o+3,s),i.lineTo(o-2,s+4)),i.closePath(),i.fill(),i.restore()}#M(e,t,n,r,i,a,o){let{context:s}=this;s.save(),s.beginPath(),s.rect(t,n,r,i),s.clip();let c=Math.max(t,0)+s6+o,l=n+Math.min(i/2,12),u=this.#t(e),d=e.clip.source.kind===`video`&&this.#a(e.clip)!==void 0;if(d){s.fillStyle=`#000000a6`;let e=s.measureText(u).width+6;s.fillRect(c-c6,l-8,e,16)}s.fillStyle=d?`#ffffff`:g6(a),s.fillText(u,c,l),s.restore()}#N(){let e=this.#e,{context:t}=this,n=this.sharp(e.xAt(e.visibleDuration));n>=e.width||(t.fillStyle=this.#l.outside,t.fillRect(Math.max(n,0),28,e.width,e.height))}#P(){let e=this.#e,t=e.preview?.marquee;if(!t)return;let{context:n}=this,r=e.xAt(t.from),i=e.xAt(t.to)-r,a=28-e.scrollY+t.top,o=t.bottom-t.top;n.fillStyle=this.#l.marquee,n.globalAlpha=.2,n.fillRect(r,a,i,o),n.globalAlpha=1,n.strokeStyle=this.#l.marquee,n.lineWidth=1,n.strokeRect(r+.5,a+.5,i-1,o-1)}#F(e){let t=this.#e,{context:n}=this,r=this.#l,i={...r,background:r.ruler};k4(n,t,e.rate,28,i,e=>this.sharp(e));let a=this.sharp(t.xAt(t.visibleDuration));n.fillStyle=r.end,n.beginPath(),n.moveTo(a-h6,27),n.lineTo(a,27-h6*1.5),n.lineTo(a+h6,27),n.closePath(),n.fill()}#I(){let e=this.#e,{context:t}=this;t.fillStyle=this.#l.end;let n=this.sharp(e.xAt(e.visibleDuration));n>=0&&n<=e.width&&t.fillRect(n,28,1,e.height),t.fillStyle=this.#l.snap;for(let n of[e.preview?.snap,e.razorAt])n!==void 0&&t.fillRect(this.sharp(e.xAt(n)),0,1,e.height)}},kpe=10,Ape=400,jpe=.15,Mpe=3,v6=.95,y6=16,b6=({x:e,y:t})=>({x:e,y:t,shift:!1,alt:!1,mod:!1}),Npe=class{#e;#t;#n=new Map;#r=`over`;#i={x:0,y:0};#a=()=>{};#o=()=>{};#s;#c={x:0,y:0};#l=0;#u=!1;#d;constructor(e,t){this.#e=e,this.#t=t}down(e,t,n){this.#o(),this.#n.set(e,{x:t,y:n}),this.#n.size===1?this.#p({x:t,y:n}):this.#n.size===2&&this.#h()}move(e,t,n){let r=this.#n.get(e);if(!r)return;let i=t-r.x,a=n-r.y;r.x=t,r.y=n,this.#r===`pinching`?this.#g():((this.#r===`held`||this.#r===`waiting`&&this.#u)&&this.#f(r)&&(this.#a(),this.#e.press(b6(this.#i)),this.#r=`editing`),this.#r===`editing`?this.#e.drag(b6(r)):(this.#r===`waiting`&&this.#f(r)&&(this.#a(),this.#r=`swiping`,this.#s=Math.abs(t-this.#i.x)>Math.abs(n-this.#i.y)?`x`:`y`,this.#l=this.#t.now()),this.#r===`swiping`&&this.#_(i,a)))}up(e){let t=this.#n.get(e);t&&(this.#n.delete(e),this.#a(),this.#r===`pinching`?this.#r=`over`:this.#n.size===0&&this.#v(t))}cancel(e){this.#n.delete(e),this.#a(),this.#e.cancelDrag(),this.#r=`over`}#f({x:e,y:t}){return Math.hypot(e-this.#i.x,t-this.#i.y)>=kpe}#p(e){this.#i={...e};let t=b6(e),n=this.#e.touchAt(t);this.#u=n===`selected`,n===`grab`?(this.#r=`editing`,this.#e.press(t)):(this.#r=`waiting`,this.#a=this.#t.later(()=>this.#m(),Ape))}#m(){this.#r===`waiting`&&(this.#e.hold(b6(this.#i)),this.#r=`held`,this.#t.held())}#h(){if(this.#r===`editing`&&this.#e.holdsDrag)return;this.#a(),this.#e.cancelDrag();let[e,t]=[...this.#n.values()],n=Math.abs(e.x-t.x)>=Math.abs(e.y-t.y);this.#d={spread:x6(e,t),center:S6(e,t),axis:n?`x`:`y`},this.#r=`pinching`}#g(){let e=this.#d,[t,n]=[...this.#n.values()];if(!e||!n)return;let r=this.#e,i=S6(t,n),a=x6(t,n),o=a/Math.max(e.spread,1);e.axis===`x`?r.zoomAround(i.x,o):r.zoomRowsAround(i.y,o),r.setScroll(r.scrollX-(i.x-e.center.x),r.scrollY-(i.y-e.center.y)),this.#d={...e,spread:a,center:i}}#_(e,t){let n=this.#e,r=this.#s===`y`?0:e,i=this.#s===`x`?0:t;n.setScroll(n.scrollX-r,n.scrollY-i);let a=this.#t.now(),o=Math.max(a-this.#l,1),s=e=>Math.max(Math.min(e,Mpe),-3);this.#c={x:s(r/o),y:s(i/o)},this.#l=a}#v(e){let t=b6(e);this.#r===`waiting`?(this.#e.press(t),this.#e.release(t)):this.#r===`held`?this.#t.openMenu(t):this.#r===`editing`?this.#e.release(t):this.#r===`swiping`&&this.#y(),this.#r=`over`}#y(){let{x:e,y:t}=this.#c,n=()=>{if(Math.hypot(e,t)<jpe)return;let r=this.#e;r.setScroll(r.scrollX-e*y6,r.scrollY-t*y6),e*=v6,t*=v6,this.#o=this.#t.nextFrame(n)};this.#o=this.#t.nextFrame(n)}},x6=(e,t)=>Math.hypot(e.x-t.x,e.y-t.y),S6=(e,t)=>({x:(e.x+t.x)/2,y:(e.y+t.y)/2}),Ppe=16,Fpe=120,Ipe=40,Lpe=200,Rpe=.002,zpe=.01;function Bpe(e){if(e.lines)return!0;if(e.deltaX!==0&&e.deltaY!==0)return!1;if(e.wheelDelta!==0)return e.wheelDelta%Fpe===0;let t=Math.abs(e.deltaX||e.deltaY);return Number.isInteger(t)&&t>=Ipe}var C6=class{#e;#t=-1/0;get device(){return this.#e}read(e,t,n=`time`){return e.time-this.#t>Lpe&&(this.#e=void 0),this.#t=e.time,t?this.#e=t:Bpe(e)?this.#e??=`mouse`:this.#e=`trackpad`,this.#e===`mouse`?Vpe(e,n):Hpe(e,n)}};function Vpe({deltaX:e,deltaY:t,lines:n,ctrl:r,alt:i,shift:a},o){let s=(t||e)*(n?Ppe:1);return r||i?w6(a||o===`headers`,Math.exp(-s*Rpe)):(o===`time`?!a:a)?{kind:`scroll`,dx:s,dy:0}:{kind:`scroll`,dx:0,dy:s}}function Hpe({deltaX:e,deltaY:t,ctrl:n,alt:r,shift:i},a){return n||r?w6(i||a===`headers`,Math.exp(-(t||e)*zpe)):{kind:`scroll`,dx:e,dy:t}}var w6=(e,t)=>e?{kind:`zoomRows`,factor:t}:{kind:`zoom`,factor:t};function T6(e){let{wheelDeltaX:t,wheelDeltaY:n}=e;return{deltaX:e.deltaX,deltaY:e.deltaY,lines:e.deltaMode!==WheelEvent.DOM_DELTA_PIXEL,wheelDelta:n||t||0,ctrl:e.ctrlKey||e.metaKey,alt:e.altKey,shift:e.shiftKey,time:e.timeStamp}}var E6=32,Upe=900;function D6(e,t){let n=t.getBoundingClientRect();return{x:e.clientX-n.left,y:e.clientY-n.top,shift:e.shiftKey,alt:e.altKey,mod:e.ctrlKey||e.metaKey}}function O6(e,{stage:t,canvas:n,playhead:r},i){let{t:a}=F(),{input:o}=U(),s=(0,N.useRef)(void 0),c=(0,N.useRef)(void 0),l=(0,N.useRef)(void 0),u=(0,N.useRef)(i);(0,N.useLayoutEffect)(()=>{u.current=i}),(0,N.useLayoutEffect)(()=>{l.current=new Npe(e,{later(e,t){let n=setTimeout(e,t);return()=>clearTimeout(n)},nextFrame(e){let t=requestAnimationFrame(e);return()=>cancelAnimationFrame(t)},now:()=>performance.now(),openMenu:e=>u.current.openMenu(e),held:()=>navigator.vibrate?.(10)})},[e]),(0,N.useLayoutEffect)(()=>{let i=t.current,a=n.current,s=r.current,c=i&&u.current.wheelArea(i);if(!c||!i||!a||!s)return;let l=u.current.paint(a),d=u.current.repaintOn?.(()=>l.invalidate()),f=()=>{let{model:t}=e;if(t){let n=e.xAt(e.frame/t.rate.fps),r=n>=-1&&n<=e.width;s.style.visibility=r?`visible`:`hidden`,s.style.transform=`translateX(${Math.round(n)}px)`,s.classList.toggle(o2.snapped,e.isSnappedToPlayhead),s.setAttribute(`aria-valuenow`,String(e.frame)),s.setAttribute(`aria-valuetext`,pq(e.frame,t.rate))}l.invalidate()},p=()=>{let t=i.clientWidth,n=i.clientHeight;l.resize(t,n,devicePixelRatio),e.setViewport(t,n),f(),l.paintNow()},m=new C6,h=t=>{if(!(t instanceof WheelEvent))return;t.preventDefault();let n=i.getBoundingClientRect(),r=!(t.target instanceof Node&&i.contains(t.target))&&t.clientX<n.left?`headers`:`time`,a=m.read(T6(t),o.wheelDevice,r);m.device&&o.notice(m.device),a.kind===`zoom`?e.zoomAround(t.clientX-n.left,a.factor):a.kind===`zoomRows`?e.zoomRowsAround(t.clientY-n.top,a.factor):e.setScroll(e.scrollX+a.dx,e.scrollY+a.dy)},g=e.subscribeView(f),_=new ResizeObserver(p);_.observe(i),p(),c.addEventListener(`wheel`,h,{passive:!1});let v=()=>{},y=()=>{v();let e=matchMedia(`(resolution: ${devicePixelRatio}dppx)`),t=()=>{p(),y()};e.addEventListener(`change`,t),v=()=>e.removeEventListener(`change`,t)};return y(),()=>{e.cancelDrag(),v(),c.removeEventListener(`wheel`,h),_.disconnect(),g(),d?.(),l.dispose()}},[n,e,o,r,t]);let d=(t,n=t)=>{c.current=void 0;let r=s.current;if(!r||!e.isDragging)return;let i=(t-n)/1e3,a=e=>Math.max(0,Math.min(1,e/E6))*Upe*i,o=a(r.x-(e.width-E6))-a(E6-r.x),l=a(r.y-(e.height-E6))-a(E6+28-r.y);(o!==0||l!==0)&&e.scrollDuringDrag(r,o,l),c.current=requestAnimationFrame(e=>d(e,t))};return{onPointerDown:t=>{if(t.button!==0)return;let{currentTarget:n}=t;n.focus({preventScroll:!0}),n.setPointerCapture(t.pointerId),s.current=D6(t,n),o.noticePointer(t.pointerType);let r=o.isTouch(t.pointerType);e.setTouchInput(r),r?l.current?.down(t.pointerId,s.current.x,s.current.y):e.press(s.current),c.current??=requestAnimationFrame(e=>d(e))},onPointerMove:t=>{let{currentTarget:n}=t,r=D6(t,n),i=e.titleAt?.(r);n.title=r.y<28?a(`timeline.timeFormat`):i?a(i):``,s.current=r,o.isTouch(t.pointerType)?(l.current?.move(t.pointerId,r.x,r.y),c.current??=requestAnimationFrame(e=>d(e))):e.isDragging&&t.buttons===0?e.cancelDrag():e.isDragging?(e.drag(r),n.style.cursor=e.dragCursor):n.style.cursor=e.hover(r)},onPointerUp:t=>{o.isTouch(t.pointerType)?l.current?.up(t.pointerId):t.button===0&&e.release(D6(t,t.currentTarget))},onPointerCancel:t=>{o.isTouch(t.pointerType)?l.current?.cancel(t.pointerId):e.cancelDrag()},onLostPointerCapture:t=>{o.isTouch(t.pointerType)||e.cancelDrag()},onPointerLeave:()=>e.leave()}}function k6(e){let{name:t,usage:n,action:r,icon:i,text:a,pressed:o,isSwitch:s,unavailable:c,onClick:l}=e,{keybindings:u}=U(),d=r&&u.keysFor(`timeline.${r}`)[0];return(0,L.jsx)(bX,{name:t,usage:n,shortcut:d?rK(d,u.platform):void 0,children:(0,L.jsxs)(`button`,{type:`button`,className:s?o2.switch:o2.button,"aria-label":t,"aria-description":n,...c?{"aria-disabled":!0}:{},...o===void 0?{}:{"aria-pressed":o},onClick:e=>{c||l(e)},children:[(0,L.jsx)(i,{size:15}),a&&(0,L.jsx)(`span`,{className:o2.buttonLabel,children:a})]})})}var A6={barX:`_barX_er9sj_1`,barY:`_barY_er9sj_2`,thumb:`_thumb_er9sj_18`,handle:`_handle_er9sj_43`},Wpe=30,j6=16;function M6(e){let{axis:t,label:n,handleLabel:r,handleUsage:i,subscribe:a,read:o,scrollTo:s,beginZoom:c}=e,l=(0,N.useRef)(null),u=(0,N.useRef)(null),d=(0,N.useRef)(void 0),f=(0,N.useRef)(void 0),p=e=>t===`x`?e.clientWidth:e.clientHeight,m=e=>t===`x`?e.clientX:e.clientY,h=()=>{let{content:e,view:t,offset:n}=o(),r=l.current?p(l.current):0,i=Math.min(Math.max(t/e*r,Wpe),r),a=e-t;return{length:r,size:i,start:a>0?n/a*(r-i):0,room:a}};(0,N.useLayoutEffect)(()=>{let e=()=>{let e=u.current;if(!e)return;let n=o(),{content:r,view:i,offset:a}=n,s=f.current;if(s?.content===r&&s.view===i&&s.offset===a)return;f.current=n;let{size:c,start:d}=h();e.style[t===`x`?`width`:`height`]=`${c}px`,e.style.transform=t===`x`?`translateX(${d}px)`:`translateY(${d}px)`;let p=r>i?Math.round(a/(r-i)*100):0;l.current?.setAttribute(`aria-valuenow`,String(p))};return e(),a(e)});let g=(e,n)=>{if(e.pointerType!==`touch`||!c)return;let{size:r,start:i}=h(),a=e.currentTarget.getBoundingClientRect(),o=n-(t===`x`?a.left:a.top);if(Math.abs(o-i)<=j6)return`start`;if(Math.abs(o-(i+r))<=j6)return`end`},_=e=>{if(e.button!==0)return;e.preventDefault(),e.currentTarget.setPointerCapture(e.pointerId);let n=e.target,r=m(e),i=n.dataset.handle??g(e,r);if(i&&c)d.current={kind:`zoom`,from:r,edge:i,length:h().size,zoom:c(i)};else{if(n!==u.current){let{length:n,size:i,room:a}=h(),o=e.currentTarget.getBoundingClientRect(),c=r-(t===`x`?o.left:o.top);n>i&&s((c-i/2)/(n-i)*a)}d.current={kind:`thumb`,from:r,offset:o().offset}}},v=e=>{let t=d.current;if(!t)return;let n=m(e)-t.from;if(t.kind===`zoom`){let e=t.edge===`end`?n:-n;t.zoom(Math.max(t.length+e,1)/t.length);return}let{length:r,size:i,room:a}=h();r>i&&s(t.offset+n/(r-i)*a)},y=()=>{d.current=void 0},b=e=>c&&(0,L.jsx)(bX,{name:r??``,usage:i??``,children:(0,L.jsx)(`div`,{className:A6.handle,"data-handle":e})});return(0,L.jsx)(`div`,{ref:l,className:t===`x`?A6.barX:A6.barY,"data-bar":t,role:`scrollbar`,"aria-label":n,"aria-orientation":t===`x`?`horizontal`:`vertical`,"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":0,onPointerDown:_,onPointerMove:v,onPointerUp:y,onPointerCancel:y,onLostPointerCapture:y,children:(0,L.jsxs)(`div`,{ref:u,className:A6.thumb,children:[b(`start`),b(`end`)]})})}var Gpe=80,Kpe=200,N6=5,qpe=400;function P6(e,t){return(0,N.useSyncExternalStore)(e.subscribeView,t)}function F6(){let{t:e}=F(),{sounds:t}=U();return(0,N.useSyncExternalStore)(t.subscribe,t.getVersion),({clip:n})=>{let{kind:r}=n.source,i=n.name??e(`timeline.kind.${r}`,{defaultValue:r}),a=t.stateOf(n);return!a||a.state===`ready`?i:e(`sound.clip`,{name:i,state:e(`sound.state.${a.state}`)})}}function I6(){let{t:e}=F();return({track:t,number:n,gone:r})=>r?e(`timeline.goneTrack`):t.name??e(`timeline.track.${t.kind}`,{number:n})}function Jpe({editor:e}){let{t}=F(),{tool:n,snapping:r,overwriting:i,multiSelecting:a,headerWidth:o}=(0,N.useSyncExternalStore)(e.subscribe,e.getSnapshot),s=P6(e,()=>e.zoomLevel),c=P6(e,()=>e.canSplit);return(0,L.jsx)(`div`,{className:o2.toolbarArea,children:(0,L.jsxs)(`div`,{className:o2.toolbar,role:`toolbar`,"aria-label":t(`timeline.toolbar`),children:[(0,L.jsx)(`span`,{className:o2.axes,style:{width:o},children:t(`timeline.axes`)}),(0,L.jsxs)(`div`,{className:o2.middle,children:[(0,L.jsxs)(`div`,{className:o2.zone,role:`group`,"aria-label":t(`timeline.zone.tools`),children:[(0,L.jsx)(k6,{name:t(`timeline.action.toolSelect`),usage:t(`timeline.help.toolSelect`),action:`toolSelect`,icon:md,pressed:n===`select`,onClick:()=>e.setTool(`select`)}),(0,L.jsx)(k6,{name:t(`timeline.action.toolRazor`),usage:t(`timeline.help.toolRazor`),action:`toolRazor`,icon:Id,pressed:n===`razor`,onClick:()=>e.setTool(`razor`)})]}),(0,L.jsxs)(`div`,{className:o2.zone,role:`group`,"aria-label":t(`timeline.zone.switches`),children:[(0,L.jsx)(k6,{name:t(`timeline.snapping`),usage:t(`timeline.help.snapping`),action:`toggleSnapping`,icon:id,pressed:r,isSwitch:!0,onClick:()=>e.toggleSnapping()}),(0,L.jsx)(k6,{name:t(`timeline.overwriting`),usage:t(`timeline.help.overwriting`),action:`toggleOverwriting`,icon:Ed,pressed:i,isSwitch:!0,onClick:()=>e.toggleOverwriting()}),(0,L.jsx)(k6,{name:t(`timeline.multiSelecting`),usage:t(`timeline.help.multiSelecting`),action:`toggleMultiSelecting`,icon:Ju,pressed:a,isSwitch:!0,onClick:()=>e.toggleMultiSelecting()})]}),(0,L.jsxs)(`div`,{className:o2.zone,role:`group`,"aria-label":t(`timeline.zone.actions`),children:[(0,L.jsx)(k6,{name:t(`timeline.splitButton`),usage:t(`timeline.help.split`),action:`split`,icon:Qd,unavailable:!c,onClick:()=>e.splitAtPlayhead()}),(0,L.jsx)(k6,{name:t(`timeline.color`),usage:t(`timeline.help.addColor`),icon:wd,text:t(`timeline.color`),onClick:()=>e.addColorClip()}),(0,L.jsx)(k6,{name:t(`timeline.action.addScene`),usage:t(`timeline.help.addScene`),icon:wd,text:t(`timeline.scene`),onClick:()=>e.createScene()})]})]}),(0,L.jsxs)(`div`,{className:o2.zoneEnd,role:`group`,"aria-label":t(`timeline.zone.zoom`),children:[(0,L.jsx)(k6,{name:t(`timeline.action.zoomOut`),usage:t(`timeline.help.zoomOut`),action:`zoomOut`,icon:Tf,onClick:()=>e.zoomOut()}),(0,L.jsx)(bX,{name:t(`timeline.zoom`),usage:t(`timeline.help.zoom`),children:(0,L.jsx)(`input`,{className:o2.zoom,type:`range`,min:0,max:1,step:.001,value:s,"aria-label":t(`timeline.zoom`),onChange:t=>e.setZoomLevel(Number(t.target.value)),onPointerUp:e=>e.currentTarget.blur()})}),(0,L.jsx)(k6,{name:t(`timeline.action.zoomIn`),usage:t(`timeline.help.zoomIn`),action:`zoomIn`,icon:Cf,onClick:()=>e.zoomIn()}),(0,L.jsx)(k6,{name:t(`timeline.action.zoomToFit`),usage:t(`timeline.help.zoomToFit`),action:`zoomToFit`,icon:vu,onClick:()=>e.zoomToFit()})]})]})})}function Ype({name:e,onDone:t}){let{t:n}=F(),r=(0,N.useRef)(null);return(0,N.useLayoutEffect)(()=>r.current?.select(),[]),(0,L.jsx)(`input`,{ref:r,className:o2.headerInput,"aria-label":n(`timeline.trackName`),defaultValue:e,spellCheck:!1,autoFocus:!0,onBlur:e=>t(e.target.value.trim()||void 0),onKeyDown:e=>{e.nativeEvent.isComposing||(e.key===`Enter`&&e.currentTarget.blur(),e.key===`Escape`&&(e.stopPropagation(),t(void 0)))}})}function Xpe({editor:e,row:t,showMenu:n,onReorder:r}){let{t:i}=F(),a=I6(),o=(0,N.useRef)(void 0),{input:s}=U(),[c,l]=(0,N.useState)(!1),u=a(t),{track:d}=t,f=d.kind===`audio`,p=f?d.muted===!0:d.hidden===!0,m=f?{muted:!p}:{hidden:!p},h=f?`timeline.mute`:`timeline.hide`,g=f?`timeline.help.mute`:`timeline.help.hide`,_=p?f?yf:Ql:f?_f:eu,v=t=>t.clientY-o.current.listTop+e.scrollY;return(0,L.jsxs)(`div`,{className:o2.header,style:{height:t.height},onPointerDown:n=>{let i=n.target;if(n.button!==0||t.gone||c||i.closest(`button`))return;let a=n.currentTarget.parentElement?.parentElement?.getBoundingClientRect(),l=s.isTouch(n.pointerType),u={from:n.clientY,lastY:n.clientY,listTop:a?.top??0,active:!1,touch:l,timer:void 0};o.current=u,l&&(u.timer=setTimeout(()=>{u.active=!0,r(e.trackDrop(t.id,u.lastY-u.listTop+e.scrollY).line)},qpe))},onPointerMove:n=>{let i=o.current;if(!i)return;let a=Math.abs(n.clientY-i.from);!i.active&&i.touch?(a>=N6&&clearTimeout(i.timer),(a>=N6||i.timer===void 0)&&e.setScroll(e.scrollX,e.scrollY-(n.clientY-i.lastY))):!i.active&&a>=N6&&(n.currentTarget.setPointerCapture(n.pointerId),i.active=!0),i.lastY=n.clientY,i.active&&r(e.trackDrop(t.id,v(n)).line)},onPointerUp:n=>{let i=o.current;i&&(clearTimeout(i.timer),i.active&&e.moveTrack(t.id,e.trackDrop(t.id,v(n)).index),o.current=void 0,r(void 0))},onPointerCancel:()=>{clearTimeout(o.current?.timer),o.current=void 0,r(void 0)},onContextMenu:r=>{r.preventDefault(),t.gone||n({x:r.clientX,y:r.clientY,label:u,groups:[[{id:`rename`,label:i(`timeline.renameTrack`),run:()=>l(!0)},{id:`up`,label:i(`timeline.moveTrackUp`),run:()=>e.shiftTrack(t.id,-1)},{id:`down`,label:i(`timeline.moveTrackDown`),run:()=>e.shiftTrack(t.id,1)},{id:`remove`,label:i(`timeline.removeTrack`),disabled:d.locked===!0,run:()=>e.removeTrack(t.id)}]]})},children:[c?(0,L.jsx)(Ype,{name:u,onDone:n=>{l(!1),n!==void 0&&n!==u&&e.updateTrack(t.id,{name:n})}}):(0,L.jsx)(`span`,{className:o2.headerName,title:u,onDoubleClick:t.gone?void 0:()=>l(!0),children:u}),!t.gone&&(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(bX,{name:i(`timeline.lock`,{track:u}),usage:i(`timeline.help.lock`),children:(0,L.jsx)(`button`,{type:`button`,className:o2.headerButton,"aria-pressed":d.locked===!0,"aria-label":i(`timeline.lock`,{track:u}),onClick:()=>e.updateTrack(t.id,{locked:d.locked!==!0}),children:d.locked?(0,L.jsx)(ed,{size:14}):(0,L.jsx)(Qu,{size:14})})}),(0,L.jsx)(bX,{name:i(h,{track:u}),usage:i(g),children:(0,L.jsx)(`button`,{type:`button`,className:o2.headerButton,"aria-pressed":p,"aria-label":i(h,{track:u}),onClick:()=>e.updateTrack(t.id,m),children:(0,L.jsx)(_,{size:14})})})]})]})}function Zpe({editor:e,model:t,showMenu:n}){let{t:r}=F(),{keyframes:i}=U(),{headerWidth:a}=(0,N.useSyncExternalStore)(e.subscribe,e.getSnapshot),o=(0,N.useRef)(null),[s,c]=(0,N.useState)(),l=(0,N.useRef)(void 0);(0,N.useLayoutEffect)(()=>{let t=()=>{o.current&&(o.current.style.transform=`translateY(${-e.scrollY}px)`)};return t(),e.subscribeView(t)},[e]);let u=[`video`,`audio`,`caption`].map(t=>({id:t,label:r(`timeline.newTrack.${t}`),run:()=>e.addTrack(t)}));return(0,L.jsxs)(`div`,{className:o2.headers,style:{width:a},children:[(0,L.jsx)(`div`,{className:o2.headerDivider,role:`separator`,"aria-orientation":`vertical`,"aria-label":r(`timeline.resizeHeaders`),onPointerDown:e=>{e.currentTarget.setPointerCapture(e.pointerId),l.current={from:e.clientX,width:a}},onPointerMove:t=>{let n=l.current;n&&e.setHeaderWidth(n.width+t.clientX-n.from)},onPointerUp:()=>{l.current=void 0,e.saveHeaderWidth()},onPointerCancel:()=>{l.current=void 0}}),(0,L.jsx)(`div`,{className:o2.corner,style:{height:28},children:(0,L.jsx)(k6,{name:r(`timeline.addTrack`),usage:r(`timeline.help.addTrack`),icon:wd,text:r(`timeline.addTrack`),onClick:e=>{let{left:t,bottom:i}=e.currentTarget.getBoundingClientRect();n({x:t,y:i+4,label:r(`timeline.addTrack`),groups:[u]})}})}),(0,L.jsx)(`div`,{className:o2.headerList,onScroll:t=>{let n=t.currentTarget.scrollTop;n!==0&&(t.currentTarget.scrollTop=0,e.setScroll(e.scrollX,e.scrollY+n))},children:(0,L.jsxs)(`div`,{ref:o,children:[t.rows.map(t=>(0,L.jsxs)(N.Fragment,{children:[(0,L.jsx)(Xpe,{editor:e,row:t,showMenu:n,onReorder:c}),t.below>0&&(0,L.jsx)(`div`,{style:{height:t.below}})]},t.id)),(0,L.jsx)(o4,{area:i.inTimeline}),s!==void 0&&(0,L.jsx)(`div`,{className:o2.dropLine,style:{top:s}})]})})]})}function Qpe({editor:e}){let{t}=F(),n=I6(),r=P6(e,()=>e.preview),i=e.model,a=r?.adding?.[0],o=``;if(i&&a){let e=i.rows.find(({id:e})=>e===a.row),s=i.rows.filter(({track:e,gone:t})=>e.kind===a.kind&&!t),c=t(`timeline.track.${a.kind}`,{number:s.length+1}),l=e?n(e):t(`timeline.dropNewTrack`,{track:c}),u=pq(Math.round(a.start*i.rate.fps),i.rate),d=r?.covered?.length??0;o=t(`timeline.dropAt`,{track:l,start:u}),d>0&&(o+=t(`timeline.dropOver`,{count:d}))}return(0,L.jsx)(`p`,{className:o2.dropStatus,role:`status`,"data-drop":a?``:void 0,children:o})}function $pe({editor:e}){let{t}=F(),n=e=>{let n=bA(e.clip).length,r=r6(e.clip);if(n===0||!r)return{};let i=r.types.map(e=>F$(t,e)).join(n6),a=e=>Number(e.toFixed(3));return{"data-effects":n,"data-effect-band":r.spans.map(([e,t])=>`${a(e)}-${a(t)}`).join(` `),...r.off?{"data-effects-off":``}:{},"aria-description":t(`effect.mark`,{names:i})}},r=F6(),i=I6(),[a,o]=(0,N.useState)([]),{selection:s,model:c}=(0,N.useSyncExternalStore)(e.subscribe,e.getSnapshot);if((0,N.useEffect)(()=>{let t,n=()=>o(e.visibleClips(Kpe)),r=()=>{t===void 0&&(t=setTimeout(()=>{t=void 0,n()},Gpe))};n();let i=e.subscribeView(r);return()=>{clearTimeout(t),i()}},[e]),!c)return null;let l=e=>pq(Math.round(e*c.rate.fps),c.rate);return(0,L.jsx)(`div`,{className:o2.clipList,role:`listbox`,"aria-multiselectable":`true`,"aria-label":t(`timeline.clips`),children:a.map(({box:a,row:o,left:c,top:u,width:d,height:f})=>(0,L.jsx)(`div`,{className:o2.clipItem,role:`option`,"aria-selected":s.has(a.id),"aria-label":t(`timeline.clipLabel`,{name:r(a),track:i(o),start:l(a.start),end:l(a.end)}),...n(a),"data-flash":e.flashesOn(a.id)||void 0,style:{left:c,top:u,width:d,height:f}},a.id))})}function eme({editor:e,model:t,showMenu:n}){let{t:r}=F(),i=U(),{input:a,media:o,keyframes:s,sounds:c}=i,l=F6(),u=(0,N.useRef)(null),d=(0,N.useRef)(null),f=(0,N.useRef)(null),p=(0,N.useRef)(l),m=s.inTimeline,h=w2(m);(0,N.useLayoutEffect)(()=>{p.current=l});let g=O6(e,{stage:u,canvas:d,playhead:f},{paint:t=>{let n=new T3(m,s.labelOfValue);return new Ope(t,e,e=>p.current(e),e=>o.peaksOf(e),e=>o.stripOfClip(e),e=>c.stateOf(e)?.state===`failed`,(e,t,n)=>e0(r,e,t,RD(n.track.kind)),e=>e.map(e=>F$(r,e)).join(n6),(e,t)=>r(`timeline.dropNewTrack`,{track:r(`timeline.track.${e}`,{number:t})}),(e,t,r)=>{n.paint(e,t,r),m.paintRanges(e,t),E3(e,m,t),D3(e,m,t,r)})},repaintOn:e=>{let t=o.subscribe(e),n=c.subscribe(e);return()=>{t(),n()}},wheelArea:e=>e.closest(`.${o2.body}`),openMenu:e=>{u.current&&ee(e,u.current.getBoundingClientRect())}}),_=t=>{let n=M0.current(),r=D6(t,t.currentTarget);n&&e.showTransitionDrop(r,n)?(t.preventDefault(),t.dataTransfer.dropEffect=`copy`):t.dataTransfer.dropEffect=`none`},v=t=>{let n=D6(t,t.currentTarget);D0.current()!==void 0&&e.showEffectDrop(n)?(t.preventDefault(),t.dataTransfer.dropEffect=`copy`):t.dataTransfer.dropEffect=`none`},y=e=>e.dataTransfer.types.includes(`application/x-animaquill-asset`)||e.dataTransfer.types.includes(`application/x-animaquill-scene`)||e.dataTransfer.types.includes(`application/x-animaquill-sound`)||e.dataTransfer.types.includes(`Files`),b=t=>{t.dataTransfer.types.includes(`application/x-animaquill-transition`)?_(t):t.dataTransfer.types.includes(`application/x-animaquill-effect`)?v(t):y(t)&&(t.preventDefault(),t.dataTransfer.dropEffect=`copy`,e.showDrop(D6(t,t.currentTarget),J3.current()))},x=t=>{let n=M0.current();if(n&&t.dataTransfer.types.includes(`application/x-animaquill-transition`)){t.preventDefault(),e.dropTransition(D6(t,t.currentTarget),n),u.current?.focus({preventScroll:!0});return}let r=D0.current();if(r!==void 0&&t.dataTransfer.types.includes(`application/x-animaquill-effect`)){t.preventDefault(),e.dropEffect(D6(t,t.currentTarget),r),u.current?.focus({preventScroll:!0});return}if(!y(t))return;t.preventDefault();let a=e.dropPlaceAt(D6(t,t.currentTarget));e.showDrop(void 0),J3.end();let o=t.dataTransfer.getData(X3);if(o){e.addAsset(o,a);return}let s=t.dataTransfer.getData(Z3);if(s){e.addScene(s,a);return}let c=t.dataTransfer.getData(Q3);c?e.addSound(c,a):i.importDropped(t.dataTransfer).then(t=>{for(let n of t)e.addAsset(n,a)})},S=e=>{if(e.preventDefault(),a.isTouch(e.nativeEvent.pointerType??``))return;let t=e.currentTarget.getBoundingClientRect();ee(D6(e,e.currentTarget),t)},ee=(t,i)=>{if(h.open(t,i))return;let a=e.hitAt(t),o=t.x+i.left,s=t.y+i.top;if(a.kind===`join`){let{join:t,row:i}=a;if(e.selectJoin(t.id),i.track.locked)return;let c=t.join.transition.align??`center`;n({x:o,y:s,label:r(`transition.uses.join`),groups:[BD.map(n=>({id:`align-${n}`,label:r(`transition.align.${n}`),selected:c===n,run:()=>e.updateJoin(t.id,{align:n})})),[{id:`deleteJoin`,label:r(`transition.delete`),run:()=>e.removeJoin(t.id)}]]})}else if(a.kind===`clip`&&a.transition&&!a.row.track.locked){let{transition:t}=a;e.selectTransition(a.box.id,t),n({x:o,y:s,label:r(`transition.uses.${t}`),groups:[[{id:`deleteTransition`,label:r(`transition.delete`),run:()=>e.setTransition(a.box.id,t,null)}]]})}else if(a.kind===`clip`&&!a.row.track.locked){e.getSnapshot().selection.has(a.box.id)||e.selectOnly(a.box.id);let t=(e,t,n=!1)=>({id:e,label:r(`timeline.action.${e}`),run:t,disabled:n}),{extras:i}=e,l=i?.canOpen(a.box)===!0?[{id:`properties`,label:r(i.isOpen(a.box)?`timeline.closeProperties`:`timeline.openProperties`),run:()=>i.toggle(a.box)}]:[];n({x:o,y:s,label:r(`timeline.clips`),groups:[[t(`copy`,()=>e.copySelection()),t(`cut`,()=>e.cutSelection()),t(`paste`,()=>e.paste(),!e.hasClipboard)],...l.length>0?[l]:[],[t(`split`,()=>e.splitAtPlayhead(),!e.canSplit),t(`delete`,()=>e.deleteSelection())],...c.stateOf(a.box.clip)?.state===`failed`?[[{id:`retry`,label:r(`sound.retry`),run:()=>c.retry(a.box.clip)}]]:[]]})}else if(a.kind===`lane`&&!a.row.track.locked&&!a.row.gone){let t=a.row.track.kind===`video`?[{id:`add`,label:r(`timeline.color`),run:()=>e.addColorClip({row:a.row,seconds:a.seconds})},{id:`addScene`,label:r(`timeline.scene`),run:()=>e.createScene({lane:a.row.top+1,seconds:a.seconds})}]:[];n({x:o,y:s,label:r(`timeline.clips`),groups:[[...t,{id:`paste`,label:r(`timeline.action.paste`),run:()=>e.paste(),disabled:!e.hasClipboard}]]})}},C=()=>e.height-28;return(0,L.jsxs)(`div`,{className:o2.surface,children:[(0,L.jsxs)(`div`,{ref:u,className:o2.stage,tabIndex:0,role:`group`,"aria-label":r(`panel.timeline.title`),...g,onDoubleClick:e=>h.doubleClick(D6(e,e.currentTarget)),onContextMenu:S,onDragOver:b,onDragLeave:()=>{e.showDrop(void 0),e.showTransitionDrop(void 0),e.showEffectDrop(void 0)},onDrop:x,children:[(0,L.jsx)(`canvas`,{ref:d,className:o2.canvas}),(0,L.jsx)($pe,{editor:e}),(0,L.jsx)(Qpe,{editor:e}),(0,L.jsx)(_2,{area:m}),t.boxes.size===0&&(0,L.jsx)(`p`,{className:o2.hint,children:r(`timeline.emptyHint`)}),(0,L.jsx)(`div`,{ref:f,className:o2.playhead,role:`slider`,"aria-label":r(`timeline.playhead`),"aria-valuemin":0,"aria-valuemax":Math.round(t.duration*t.rate.fps),"aria-orientation":`horizontal`,tabIndex:-1})]}),(0,L.jsx)(`div`,{className:o2.barRight,style:{paddingTop:28},children:(0,L.jsx)(M6,{axis:`y`,label:r(`timeline.scrollY`),handleLabel:r(`timeline.handleY`),handleUsage:r(`timeline.help.zoomHandleY`),subscribe:e.subscribeView,read:()=>({content:e.contentHeight-28,view:C(),offset:e.scrollY}),scrollTo:t=>e.setScroll(e.scrollX,t),beginZoom:t=>{let n=e.rowScale,r=t===`start`?e.height:28;return t=>e.zoomRowsAround(r,n/t/e.rowScale)}})}),(0,L.jsx)(M6,{axis:`x`,label:r(`timeline.scrollX`),handleLabel:r(`timeline.handleX`),handleUsage:r(`timeline.help.zoomHandleX`),subscribe:e.subscribeView,read:()=>({content:e.contentWidth,view:e.width,offset:e.scrollX}),scrollTo:t=>e.setScroll(t,e.scrollY),beginZoom:t=>{let n=e.pixelsPerSecond,r=t===`start`?e.width:0;return t=>e.zoomAround(r,n/t/e.pixelsPerSecond)}}),h.element]})}function tme(){let{timeline:e,keyframes:t}=U(),{t:n}=F(),{model:r}=(0,N.useSyncExternalStore)(e.subscribe,e.getSnapshot),[i,a]=(0,N.useState)();return r?(0,L.jsxs)(`div`,{className:o2.panel,onKeyDown:n=>{n.key===`Escape`&&n.currentTarget.contains(n.target)&&(e.cancelDrag()||e.cancelCut()||(t.selection.size>0?t.clearSelection():e.clearSelection()))},children:[(0,L.jsx)(Jpe,{editor:e}),(0,L.jsxs)(`div`,{className:o2.body,children:[(0,L.jsx)(Zpe,{editor:e,model:r,showMenu:a}),(0,L.jsx)(eme,{editor:e,model:r,showMenu:a})]}),i&&(0,L.jsx)(ov,{...i,onClose:()=>a(void 0)})]}):(0,L.jsx)(`div`,{className:o2.missing,children:n(`timeline.missing`)})}var L6={panel:`_panel_1kbyx_1`,toolbar:`_toolbar_1kbyx_9`,event:`_event_1kbyx_18`,primary:`_primary_1kbyx_39`,elapsed:`_elapsed_1kbyx_44`,bad:`_bad_1kbyx_49`,about:`_about_1kbyx_53`,body:`_body_1kbyx_61`,stats:`_stats_1kbyx_75`,stat:`_stat_1kbyx_75`,columns:`_columns_1kbyx_103`,bars:`_bars_1kbyx_109`,track:`_track_1kbyx_124`,bar:`_bar_1kbyx_109`,slowBar:`_slowBar_1kbyx_132`,count:`_count_1kbyx_141`,quiet:`_quiet_1kbyx_146`,events:`_events_1kbyx_151`,when:`_when_1kbyx_180`,detail:`_detail_1kbyx_181`,finished:`_finished_1kbyx_192`,actions:`_actions_1kbyx_203`,errors:`_errors_1kbyx_229`,error:`_error_1kbyx_229`,errorLine:`_errorLine_1kbyx_249`,quietText:`_quietText_1kbyx_255`},nme=e=>{let t=Math.floor(e/1e3);return`${Math.floor(t/60)}:${String(t%60).padStart(2,`0`)}`};function rme({error:e}){let t=U(),{errors:n}=t,{t:r}=F(),[i,a]=(0,N.useState)(!1),{id:o,status:s,count:c,source:l,name:u,message:d,sentId:f}=e,p=n.canSend&&(s===`quiet`||s===`declined`||s===`failed`);return(0,L.jsxs)(`li`,{className:L6.error,children:[(0,L.jsxs)(`div`,{className:L6.errorLine,children:[(0,L.jsx)(`span`,{className:L6.when,children:nme(e.at)}),(0,L.jsx)(`span`,{children:r(`errors.source.${l}`)}),(0,L.jsx)(`span`,{className:L6.detail,title:d,children:d?r(`errors.what`,{name:u,message:d}):u}),c>1&&(0,L.jsx)(`span`,{className:L6.when,children:r(`errors.times`,{count:c})})]}),(0,L.jsxs)(`div`,{className:L6.actions,children:[(0,L.jsx)(`span`,{className:s===`failed`?L6.bad:L6.quietText,role:`status`,children:r(`errors.status.${s}`,{id:f})}),p&&(0,L.jsxs)(`button`,{type:`button`,onClick:()=>void n.send(o),children:[(0,L.jsx)(Bd,{size:13}),r(s===`failed`?`errors.retry`:`errors.send`)]}),(0,L.jsxs)(`button`,{type:`button`,onClick:()=>t.saveErrorReport(o),children:[(0,L.jsx)(Jl,{size:13}),r(`diagnostics.save`)]}),(0,L.jsx)(`button`,{type:`button`,"aria-expanded":i,onClick:()=>a(!i),children:r(i?`errors.hide`:`errors.show`)})]}),i&&(0,L.jsx)(`pre`,{"aria-label":r(`errors.content`),tabIndex:0,children:JSON.stringify(e.report,void 0,2)})]})}function ime(){let{errors:e}=U(),{t}=F(),{errors:n}=(0,N.useSyncExternalStore)(e.subscribe,e.getSnapshot);return(0,L.jsxs)(`section`,{className:L6.errors,"aria-label":t(`errors.title`),children:[(0,L.jsx)(`h3`,{children:t(`errors.heading`,{count:n.length})}),n.length===0?(0,L.jsx)(`p`,{className:L6.quiet,children:t(`errors.none`)}):(0,L.jsx)(`ul`,{children:n.map(e=>(0,L.jsx)(rme,{error:e},e.id))})]})}var ame=1e3,R6=/^[\w.:-]{1,60}$/;function ome(e){let t={};for(let[n,r]of Object.entries(e))R6.test(n)&&(typeof r==`number`?t[n]=Number.isFinite(r)?r:String(r):typeof r==`boolean`?t[n]=r:typeof r==`string`&&(t[n]=R6.test(r)?r:`?`));return t}function sme(e,t){let n=e=>Object.entries(e).filter(([e,t])=>typeof t!=`number`&&e!==`t`&&e!==`kind`).map(([e,t])=>`${e}=${String(t)}`).toSorted().join(`&`);return n(e)===n(t)}var cme=class{#e;#t;#n=[];constructor(e=200,t=()=>performance.now()){this.#e=e,this.#t=t}add(e,t={},n=!1){if(!R6.test(e))return;let r=Math.round(this.#t()),i=ome(t),a=this.#n.at(-1);n&&a&&a.kind===e&&r-a.t<=ame&&sme(a,i)?this.#n[this.#n.length-1]={...i,t:r,kind:e,times:(a.times??1)+1}:(this.#n.push({...i,t:r,kind:e}),this.#n.length>this.#e&&this.#n.shift())}entries(){return[...this.#n]}},lme=6e5,ume=6e3,dme=34,fme=5e3,pme=[8,16,33,50,100,250,1e3],z6=[`<=8`,`<=16`,`<=33`,`<=50`,`<=100`,`<=250`,`<=1000`,`more`],mme=250,hme=new Set([`memory`]),B6={status:`idle`,elapsedMs:0,limitReached:!1,counts:{slowFrames:0,cold:0,gaps:0,audioLate:0,errors:0},framesPerSecond:0,memoryMb:void 0,frameTimes:{},recent:[],report:void 0,sentId:void 0};function gme(){try{let e=document.createElement(`canvas`).getContext(`webgl`),t=e?.getExtension(`WEBGL_debug_renderer_info`);return t?String(e?.getParameter(t.UNMASKED_RENDERER_WEBGL)):void 0}catch{return}}function V6(){let{deviceMemory:e}=navigator;return{userAgent:navigator.userAgent,cores:navigator.hardwareConcurrency,memoryGb:e,screen:`${screen.width}x${screen.height}@${devicePixelRatio}`,window:`${innerWidth}x${innerHeight}`,graphicsCard:gme()}}var _me=class{trail=new cme;#e=new sv;#t;#n;#r;#i=0;#a=`idle`;#o=B6;#s;#c=[];#l=[];#u=0;#d=new Map;#f;#p=new Map;#m=new Map;#h=[];constructor(e,t=vme,n=V6){this.#t=e,this.#n=t,this.#r=n}subscribe=this.#e.subscribe;getSnapshot=()=>this.#o;getRecording=()=>this.#a===`recording`;start(){if(!this.getRecording()){this.#a=`recording`,this.#i=performance.now(),this.#c=[],this.#l=[],this.#u=0,this.#d=new Map,this.#f=this.#n((e,t)=>this.note(e,t)),this.#m=new Map;for(let[e,t]of this.#p)this.#g(e,t);this.#s=setInterval(()=>this.#_(),mme),this.#_()}}watch(e,t){this.#p.set(e,t),this.getRecording()&&this.#g(e,t)}#g(e,t){let n=t.get();this.#m.set(e,n),this.note(e,{on:n}),this.#h.push(t.subscribe(()=>{let r=t.get();r!==n&&(n=r,r&&this.#m.set(e,!0),this.note(e,{on:n}))}))}#_(e,t){let n=this.#l,r=performance.now(),i={slowFrames:0,cold:0,gaps:0,audioLate:0,errors:0},a,o=!1;for(let{kind:e,cold:t,mb:r}of n)e===`frame`&&(i.slowFrames+=1),e===`frame`&&typeof t==`number`&&(i.cold+=t),e===`gap`&&(i.gaps+=1),e===`audio.late`&&(i.audioLate+=1),e===`error`&&(i.errors+=1),e===`memory`&&typeof r==`number`&&(a=r),e===`limit`&&(o=!0);this.#c=this.#c.filter(e=>r-e<=1e3),this.#o={status:this.#a,elapsedMs:e?.durationMs??r-this.#i,limitReached:o,counts:i,framesPerSecond:e?this.#v(e):this.#c.length,memoryMb:a,frameTimes:Object.fromEntries(this.#d),recent:n.filter(({kind:e})=>!hme.has(e)).slice(-60).toReversed(),report:e,sentId:t},this.#e.emit()}#v({durationMs:e}){let t=[...this.#d.values()].reduce((e,t)=>e+t,0);return e>0?Math.round(t*1e3/e):0}#y(){this.#f?.(),this.#f=void 0;for(let e of this.#h.splice(0))e();clearInterval(this.#s),this.#s=void 0}discard(){this.#y(),this.#a=`idle`,this.#l=[],this.#o=B6,this.#e.emit()}mark(e,t={},n=!1){this.trail.add(e,t,n),this.note(e,t)}note(e,t={},n=performance.now()){if(!this.getRecording())return;if(this.#l.length>=ume){this.#u+=1;return}let r=Math.max(Math.round(n-this.#i),0);this.#l.push({...t,t:r,kind:e})}noteFrame(e,t,n){if(!this.getRecording())return;this.#c.push(performance.now());let r=pme.find(t=>e<=t),i=r===void 0?`more`:`<=${r}`;this.#d.set(i,(this.#d.get(i)??0)+1),n&&this.note(`frame`,{...t,ms:Math.round(e)})}finish(e){let t={format:1,version:this.#t,startedAt:new Date(Date.now()-(performance.now()-this.#i)).toISOString(),durationMs:Math.round(performance.now()-this.#i),device:this.#r(),project:e,frameTimes:Object.fromEntries(this.#d),events:this.#l,dropped:this.#u,during:Object.fromEntries(this.#m)};return this.#y(),this.#a=`finished`,this.#_(t),t}markSent(e){let{report:t}=this.#o;t&&this.#_(t,e)}};function vme(e){let t=performance.now(),n=requestAnimationFrame(function r(i){i-t>dme&&document.visibilityState===`visible`&&e(`gap`,{ms:Math.round(i-t)}),t=i,n=requestAnimationFrame(r)}),r=()=>e(`visibility`,{state:document.visibilityState});document.addEventListener(`visibilitychange`,r);let i=typeof PerformanceObserver<`u`&&PerformanceObserver.supportedEntryTypes.includes(`longtask`)?new PerformanceObserver(t=>{for(let n of t.getEntries())e(`longtask`,{ms:Math.round(n.duration)})}):void 0;i?.observe({type:`longtask`});let a=setInterval(()=>{let{memory:t}=performance;t&&e(`memory`,{mb:Math.round(t.usedJSHeapSize/1024**2)})},fme),o=()=>{cancelAnimationFrame(n),clearInterval(a),clearTimeout(s),i?.disconnect(),document.removeEventListener(`visibilitychange`,r)},s=setTimeout(()=>{e(`limit`,{}),o()},lme);return o}var yme=2,H6=e=>{let t=Math.floor(e/1e3);return`${Math.floor(t/60)}:${String(t%60).padStart(2,`0`)}`};function U6({label:e,value:t,bad:n}){return(0,L.jsxs)(`div`,{className:L6.stat,children:[(0,L.jsx)(`strong`,{className:n?L6.bad:void 0,children:t}),(0,L.jsx)(`span`,{children:e})]})}function bme({snapshot:e}){let{t}=F(),{counts:n,framesPerSecond:r,memoryMb:i}=e;return(0,L.jsxs)(`div`,{className:L6.stats,role:`group`,"aria-label":t(`diagnostics.stats`),children:[(0,L.jsx)(U6,{label:t(`diagnostics.framesPerSecond`),value:r}),(0,L.jsx)(U6,{label:t(`diagnostics.slowFrames`),value:n.slowFrames,bad:n.slowFrames>0}),(0,L.jsx)(U6,{label:t(`diagnostics.cold`),value:n.cold,bad:n.cold>0}),(0,L.jsx)(U6,{label:t(`diagnostics.gaps`),value:n.gaps,bad:n.gaps>0}),(0,L.jsx)(U6,{label:t(`diagnostics.audioLate`),value:n.audioLate,bad:n.audioLate>0}),(0,L.jsx)(U6,{label:t(`diagnostics.errors`),value:n.errors,bad:n.errors>0}),(0,L.jsx)(U6,{label:t(`diagnostics.memory`),value:i===void 0?`-`:`${i} MB`})]})}function xme({times:e}){let{t}=F(),n=z6.map(t=>e[t]??0),r=Math.max(...n,1);return(0,L.jsxs)(`section`,{"aria-label":t(`diagnostics.frameTimes`),children:[(0,L.jsx)(`h3`,{children:t(`diagnostics.frameTimes`)}),(0,L.jsx)(`ul`,{className:L6.bars,children:z6.map((e,i)=>(0,L.jsxs)(`li`,{children:[(0,L.jsx)(`span`,{children:t(`diagnostics.group.${e}`)}),(0,L.jsx)(`div`,{className:L6.track,children:(0,L.jsx)(`div`,{className:i>=yme?L6.slowBar:L6.bar,style:{width:`${(n[i]??0)/r*100}%`}})}),(0,L.jsx)(`span`,{className:L6.count,children:n[i]})]},e))})]})}function Sme({event:e}){let{timeline:t}=U(),{t:n}=F(),{kind:r,seconds:i,ms:a,cold:o,message:s,on:c,proxy:l}=e,{model:u}=t,d=typeof i==`number`&&u!==void 0,f=[typeof a==`number`?`${a} ms`:void 0,typeof o==`number`&&o>0?n(`diagnostics.coldNote`):void 0,typeof s==`string`?s:void 0,typeof c==`boolean`?n(c?`diagnostics.on`:`diagnostics.off`):void 0,typeof l==`boolean`?n(l?`diagnostics.proxyNote`:`diagnostics.originalNote`):void 0].filter(Boolean),p=(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(`span`,{className:L6.when,children:H6(e.t)}),(0,L.jsx)(`span`,{children:n(`diagnostics.kind.${r}`,{defaultValue:r})}),(0,L.jsx)(`span`,{className:L6.detail,children:f.join(`,`)})]});return d?(0,L.jsx)(`li`,{children:(0,L.jsx)(`button`,{type:`button`,className:L6.event,title:n(`diagnostics.jump`),onClick:()=>t.seek(cq(i,u.rate)),children:p})}):(0,L.jsx)(`li`,{className:L6.event,children:p})}function Cme({events:e}){let{t}=F();return(0,L.jsxs)(`section`,{"aria-label":t(`diagnostics.events`),children:[(0,L.jsx)(`h3`,{children:t(`diagnostics.events`)}),e.length===0?(0,L.jsx)(`p`,{className:L6.quiet,children:t(`diagnostics.noEvents`)}):(0,L.jsx)(`ul`,{className:L6.events,children:e.map((e,t)=>(0,L.jsx)(Sme,{event:e},`${e.t}-${t}`))})]})}function wme({snapshot:e}){let t=U(),{diagnostics:n}=t,{t:r}=F(),[i,a]=(0,N.useState)(!1),{report:o,sentId:s}=e;return o?(0,L.jsxs)(`section`,{className:L6.finished,children:[s===void 0?(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(`p`,{children:r(t.canSendDiagnostics?`diagnostics.sendNote`:`diagnostics.saveNote`)}),(0,L.jsxs)(`div`,{className:L6.actions,children:[t.canSendDiagnostics&&(0,L.jsxs)(`button`,{type:`button`,className:L6.primary,disabled:i,onClick:()=>{a(!0),t.sendDiagnostics().finally(()=>a(!1))},children:[(0,L.jsx)(Bd,{size:14}),r(i?`diagnostics.sending`:`diagnostics.send`)]}),(0,L.jsxs)(`button`,{type:`button`,onClick:()=>t.saveDiagnostics(),children:[(0,L.jsx)(Jl,{size:14}),r(`diagnostics.save`)]}),(0,L.jsxs)(`button`,{type:`button`,onClick:()=>n.discard(),children:[(0,L.jsx)(sf,{size:14}),r(`diagnostics.discard`)]})]})]}):(0,L.jsxs)(`div`,{className:L6.actions,children:[(0,L.jsx)(`span`,{role:`status`,children:r(`diagnostics.sent`,{id:s})}),(0,L.jsxs)(`button`,{type:`button`,onClick:()=>void navigator.clipboard?.writeText(s),children:[(0,L.jsx)(Hl,{size:14}),r(`diagnostics.copy`)]})]}),(0,L.jsxs)(`details`,{children:[(0,L.jsx)(`summary`,{children:r(`diagnostics.showReport`)}),(0,L.jsx)(`pre`,{children:JSON.stringify(o,void 0,2)})]})]}):null}function Tme(){let e=U(),{diagnostics:t}=e,{t:n}=F(),r=(0,N.useSyncExternalStore)(t.subscribe,t.getSnapshot),{status:i,elapsedMs:a,limitReached:o}=r,s=i===`recording`;return(0,L.jsxs)(`div`,{className:L6.panel,children:[(0,L.jsxs)(`div`,{className:L6.toolbar,children:[s?(0,L.jsxs)(`button`,{type:`button`,onClick:()=>e.finishDiagnostics(),children:[(0,L.jsx)(nf,{size:12,fill:`currentColor`}),n(`diagnostics.finish`)]}):(0,L.jsxs)(`button`,{type:`button`,className:L6.primary,onClick:()=>t.start(),children:[(0,L.jsx)(Ol,{size:12,fill:`currentColor`}),n(i===`idle`?`diagnostics.start`:`diagnostics.startAgain`)]}),s&&(0,L.jsx)(`button`,{type:`button`,onClick:()=>t.discard(),children:n(`diagnostics.discard`)}),i!==`idle`&&(0,L.jsx)(`span`,{className:L6.elapsed,role:`timer`,children:H6(a)}),o&&(0,L.jsx)(`span`,{className:L6.bad,children:n(`diagnostics.limitReached`)})]}),(0,L.jsxs)(`div`,{className:L6.body,children:[i===`idle`?(0,L.jsx)(`p`,{className:L6.about,children:n(`diagnostics.about`)}):(0,L.jsxs)(L.Fragment,{children:[i===`finished`&&(0,L.jsx)(wme,{snapshot:r}),(0,L.jsx)(bme,{snapshot:r}),(0,L.jsxs)(`div`,{className:L6.columns,children:[(0,L.jsx)(xme,{times:r.frameTimes}),(0,L.jsx)(Cme,{events:r.recent})]})]}),(0,L.jsx)(ime,{})]})]})}var W6={panel:`_panel_1o3md_1`,none:`_none_1o3md_8`,toolbar:`_toolbar_1o3md_18`,list:`_list_1o3md_40`,item:`_item_1o3md_49`,icon:`_icon_1o3md_61`,spin:`_spin_1o3md_1`,body:`_body_1o3md_91`,head:`_head_1o3md_99`,name:`_name_1o3md_106`,project:`_project_1o3md_113`,bar:`_bar_1o3md_119`,status:`_status_1o3md_138`,actions:`_actions_1o3md_148`,action:`_action_1o3md_148`,primary:`_primary_1o3md_155`},G6={interpolation:{escapeValue:!1}};function Eme(e,t,n,r,i){let a=(t,n)=>n>0?e(`export.queue.frames`,{done:t,total:n}):e(`export.queue.framesOnly`,{done:t});switch(t.status){case`running`:{if(!n)return e(`export.queue.status.running`,{percent:0});let{done:t,total:r,remainingMs:i}=n,o=r>0?Math.floor(t/r*100):0,s=n.stopping?e(`export.video.stopping`):n.writing?e(`export.video.writing`):n.pausing?e(`export.queue.status.pausing`):n.paused?e(`export.queue.status.windowClosed`):n.makingSound?e(`export.video.makingSound`):n.catchingUp===void 0?n.readingMedia?e(`export.queue.status.readingMedia`):n.hidden?e(`export.queue.status.hidden`):e(`export.queue.status.running`,{percent:o}):e(`export.resume.catchingUp`,{percent:Math.floor(n.catchingUp*100)}),c=i===void 0||n.paused?``:` · ${e(`export.video.remaining`,{time:nJ(i)})}`;return`${s} · ${a(t,r)}${c}`}case`waiting`:return i===void 0?t.restored?e(`export.queue.status.waitingRestored`):r<=1?e(`export.queue.status.waitingNext`):e(`export.queue.status.waiting`,{ahead:r}):e(`export.queue.status.otherProject`,{project:i,...G6});case`paused`:return`${e(t.needsPress?`export.queue.status.needsPress`:`export.queue.status.paused`)} · ${a(t.done,t.total)}`;case`failed`:return e(`export.queue.status.failed`,{failure:t.failure??``,...G6});case`interrupted`:return`${e(`export.queue.status.interrupted`)} · ${a(t.done,t.total)}`;case`done`:return e(`export.queue.status.done`)}}var Dme={waiting:Al,running:Xu,paused:Sl,failed:bl,interrupted:Sl,done:vl};function Ome({entry:e,projects:t}){let{videos:n}=U(),{store:r}=ev(),{t:i}=F(),a=(0,N.useSyncExternalStore)(n.subscribe,n.getSnapshot),o=e.status===`running`&&a?.id===e.id?a:void 0,s=r&&JG(r),c=t?.find(({id:t})=>t===e.project)?.name,l=e.project!==s,u=l&&(e.status===`waiting`||e.status===`interrupted`)&&!e.restored,d=Eme(i,e,o,n.queue.ahead(e.id),u?c??``:void 0),f=o?.done??e.done,p=o?.total??e.total,m=Dme[e.status],h=(t,n,r,i=!1)=>{let a=n;return(0,L.jsxs)(`button`,{type:`button`,className:i?W6.primary:W6.action,"aria-label":`${t}:${e.name}`,title:t,onClick:r,children:[(0,L.jsx)(a,{size:14}),(0,L.jsx)(`span`,{children:t})]})},g=e.status===`paused`||e.status===`interrupted`,_=e.status===`waiting`&&e.restored;return(0,L.jsxs)(`li`,{className:W6.item,"data-status":e.status,"aria-label":e.name,children:[(0,L.jsx)(m,{size:16,className:W6.icon,"aria-hidden":!0}),(0,L.jsxs)(`div`,{className:W6.body,children:[(0,L.jsxs)(`div`,{className:W6.head,children:[(0,L.jsx)(`span`,{className:W6.name,children:e.name}),l&&c&&(0,L.jsx)(`span`,{className:W6.project,children:c})]}),e.status!==`done`&&(0,L.jsx)(`progress`,{className:W6.bar,value:f,max:Math.max(p,1),"aria-hidden":!0}),(0,L.jsx)(`div`,{className:W6.status,role:`status`,children:d})]}),(0,L.jsxs)(`div`,{className:W6.actions,children:[e.status===`running`&&o&&!o.stopping&&!o.writing&&!o.pausing&&h(i(`export.queue.pause`),gd,()=>n.pause(e.id)),e.status===`running`&&o?.paused&&!o.stopping&&h(i(`export.window.resume`),Sd,()=>n.resume(),!0),e.status===`waiting`&&!e.restored&&h(i(`export.queue.pause`),gd,()=>n.pause(e.id)),(g||_)&&h(i(`export.queue.goOn`),Sd,()=>n.goOn(e.id),!0),e.status===`failed`&&h(i(`export.queue.retry`),Md,()=>n.retry(e.id),!0),e.status===`running`?!o?.stopping&&!o?.writing&&h(i(`export.video.cancel`),xf,()=>n.cancel(e.id)):h(i(`export.queue.remove`),xf,()=>void n.remove(e.id))]})]})}function kme(){let e=U(),{videos:t}=e,{t:n}=F(),r=(0,N.useSyncExternalStore)(t.queue.subscribe,t.queue.getSnapshot),[i,a]=(0,N.useState)();if((0,N.useEffect)(()=>{e.session.list().then(a,()=>a([]))},[e]),r.length===0)return(0,L.jsx)(`div`,{className:W6.none,children:n(`export.queue.empty`)});let o=r.some(({status:e,restored:t})=>e===`paused`||e===`interrupted`||e===`waiting`&&t),s=r.some(({status:e})=>e===`done`);return(0,L.jsxs)(`div`,{className:W6.panel,children:[(o||s)&&(0,L.jsxs)(`div`,{className:W6.toolbar,children:[o&&(0,L.jsx)(`button`,{type:`button`,onClick:()=>t.goOnWithAll(),children:n(`export.queue.goOnWithAll`)}),s&&(0,L.jsx)(`button`,{type:`button`,onClick:()=>t.clearDone(),children:n(`export.queue.clearDone`)})]}),(0,L.jsx)(`ul`,{className:W6.list,"aria-label":n(`export.queue.listLabel`),children:r.map(e=>(0,L.jsx)(Ome,{entry:e,projects:i},e.id))})]})}var K6={toolbar:`_toolbar_n436e_1`,corner:`_corner_n436e_11`,searchArea:`_searchArea_n436e_21`,firstZone:`_firstZone_n436e_31`,search:`_search_n436e_21`,ranges:`_ranges_n436e_53`,range:`_range_n436e_53`,rows:`_rows_n436e_80`},Ame=[`here`,`all`,`keyed`];function jme({view:e}){let{keyframes:t}=e,{timeline:n}=U(),{t:r}=F(),{selection:i,listWidth:a,query:o}=(0,N.useSyncExternalStore)(t.subscribe,t.getSnapshot),{snapping:s}=(0,N.useSyncExternalStore)(n.subscribe,n.getSnapshot),[c,l]=(0,N.useState)(),u=i.size>0,d=u&&t.canEase,f=r(u?d?`keyframes.interpHelp`:`keyframes.interpNeedsNumbers`:`keyframes.interpNeedsKeys`);return(0,L.jsxs)(`div`,{className:o2.toolbarArea,children:[(0,L.jsxs)(`div`,{className:K6.toolbar,role:`toolbar`,"aria-label":r(`keyframes.toolbar`),children:[(0,L.jsx)(`div`,{className:K6.searchArea,style:{width:a},children:(0,L.jsx)(`input`,{className:K6.search,type:`search`,placeholder:r(`keyframes.search`),"aria-label":r(`keyframes.search`),spellCheck:!1,value:o,onChange:e=>t.setQuery(e.target.value),onKeyDown:e=>{e.key===`Escape`&&o!==``&&(e.stopPropagation(),t.setQuery(``))}})}),(0,L.jsx)(`div`,{className:`${o2.zone} ${K6.firstZone}`,children:(0,L.jsx)(k6,{name:r(`timeline.snapping`),usage:r(`timeline.help.snapping`),action:`toggleSnapping`,icon:id,pressed:s,isSwitch:!0,onClick:()=>n.toggleSnapping()})}),(0,L.jsx)(`div`,{className:o2.zone,children:(0,L.jsx)(k6,{name:r(`keyframes.interp`),usage:f,icon:Xd,text:r(`keyframes.interp`),unavailable:!d,onClick:e=>l(e.currentTarget.getBoundingClientRect())})}),(0,L.jsx)(`div`,{className:o2.spacer}),(0,L.jsxs)(`div`,{className:o2.zoneEnd,role:`group`,"aria-label":r(`timeline.zone.zoom`),children:[(0,L.jsx)(k6,{name:r(`timeline.action.zoomOut`),usage:r(`timeline.help.zoomOut`),icon:Tf,onClick:()=>e.zoomOut()}),(0,L.jsx)(k6,{name:r(`timeline.action.zoomIn`),usage:r(`timeline.help.zoomIn`),icon:Cf,onClick:()=>e.zoomIn()}),(0,L.jsx)(k6,{name:r(`timeline.action.zoomToFit`),usage:r(`timeline.help.zoomToFit`),icon:vu,onClick:()=>e.zoomToFit()})]})]}),c&&(0,L.jsx)(C2,{keyframes:t,anchor:c,onClose:()=>l(void 0)})]})}function Mme({view:e}){let{keyframes:t}=e,{t:n}=F(),{range:r}=(0,N.useSyncExternalStore)(t.subscribe,t.getSnapshot);return(0,L.jsx)(`div`,{className:K6.corner,style:{height:28},children:(0,L.jsx)(`div`,{className:K6.ranges,role:`radiogroup`,"aria-label":n(`keyframes.rangeLabel`),children:Ame.map(e=>(0,L.jsx)(bX,{name:n(`keyframes.range.${e}`),usage:n(`keyframes.rangeHelp.${e}`),children:(0,L.jsx)(`button`,{type:`button`,role:`radio`,className:K6.range,"aria-checked":r===e,onClick:()=>t.setRange(e),children:n(`keyframes.range.${e}`)})},e))})})}function Nme({view:e}){let{keyframes:t}=e,{input:n}=U(),{t:r}=F(),{listWidth:i}=(0,N.useSyncExternalStore)(t.subscribe,t.getSnapshot),a=(0,N.useRef)(null),o=(0,N.useRef)(null),s=(0,N.useRef)(void 0),c=(0,N.useRef)(void 0);return(0,N.useLayoutEffect)(()=>{let n=()=>{o.current&&(o.current.style.transform=`translateY(${-e.scrollY}px)`)};return n(),t.subscribeView(n)},[t,e]),(0,N.useLayoutEffect)(()=>{let t=a.current,r=new C6,i=i=>{i.preventDefault();let a=r.read(T6(i),n.wheelDevice,`headers`);if(r.device&&n.notice(r.device),a.kind===`scroll`)e.setScroll(e.scrollX+a.dx,e.scrollY+a.dy);else{let n=t?.getBoundingClientRect();e.zoomRowsAround(i.clientY-(n?.top??0)+28,a.factor)}};return t?.addEventListener(`wheel`,i,{passive:!1}),()=>t?.removeEventListener(`wheel`,i)},[e,n]),(0,L.jsxs)(`div`,{className:o2.headers,style:{width:i},children:[(0,L.jsx)(`div`,{className:o2.headerDivider,role:`separator`,"aria-orientation":`vertical`,"aria-label":r(`keyframes.resizeList`),onPointerDown:e=>{e.currentTarget.setPointerCapture(e.pointerId),s.current={from:e.clientX,width:i}},onPointerMove:e=>{let n=s.current;n&&t.setListWidth(n.width+e.clientX-n.from)},onPointerUp:()=>{s.current=void 0,t.saveListWidth()},onPointerCancel:()=>{s.current=void 0}}),(0,L.jsx)(Mme,{view:e}),(0,L.jsx)(`div`,{ref:a,className:o2.headerList,role:`tree`,"aria-label":r(`keyframes.list`),onPointerDown:e=>{n.isTouch(e.pointerType)&&(c.current=e.clientY)},onPointerMove:t=>{c.current!==void 0&&(e.setScroll(e.scrollX,e.scrollY+c.current-t.clientY),c.current=t.clientY)},onPointerUp:()=>{c.current=void 0},onPointerCancel:()=>{c.current=void 0},onScroll:t=>{let n=t.currentTarget.scrollTop;n!==0&&(t.currentTarget.scrollTop=0,e.setScroll(e.scrollX,e.scrollY+n))},children:(0,L.jsx)(`div`,{ref:o,className:K6.rows,children:(0,L.jsx)(o4,{area:e,canPin:!0})})})]})}function Pme({view:e}){let{keyframes:t}=e,{t:n}=F(),r=(0,N.useSyncExternalStore)(e.subscribeLanes,e.getLanes),{range:i,query:a}=(0,N.useSyncExternalStore)(t.subscribe,t.getSnapshot);if(r.length>0)return null;let o=n(a===``?`keyframes.empty.${i}`:`keyframes.empty.search`);return(0,L.jsx)(`p`,{className:o2.hint,children:o})}function Fme({view:e}){let{keyframes:t}=e,{t:n}=F(),r=(0,N.useRef)(null),i=(0,N.useRef)(null),a=(0,N.useRef)(null),o=w2(e),s=O6(e,{stage:r,canvas:i,playhead:a},{paint:n=>new Qfe(n,e,t.labelOfValue),wheelArea:e=>e,openMenu:e=>{r.current&&o.open(e,r.current.getBoundingClientRect())}});(0,N.useLayoutEffect)(()=>()=>e.setViewport(0,0),[e]);let c=()=>e.height-28,{model:l}=e;return(0,L.jsxs)(`div`,{className:o2.surface,children:[(0,L.jsxs)(`div`,{ref:r,className:o2.stage,tabIndex:0,role:`group`,"aria-label":n(`panel.keyframes.title`),...s,onDoubleClick:e=>o.doubleClick(D6(e,e.currentTarget)),onContextMenu:e=>{e.preventDefault(),o.open(D6(e,e.currentTarget),e.currentTarget.getBoundingClientRect())},children:[(0,L.jsx)(`canvas`,{ref:i,className:o2.canvas}),(0,L.jsx)(_2,{area:e}),(0,L.jsx)(Pme,{view:e}),(0,L.jsx)(`div`,{ref:a,className:o2.playhead,role:`slider`,"aria-label":n(`timeline.playhead`),"aria-valuemin":0,"aria-valuemax":Math.round((l?.duration??0)*(l?.rate.fps??30)),"aria-orientation":`horizontal`,tabIndex:-1})]}),(0,L.jsx)(`div`,{className:o2.barRight,style:{paddingTop:28},children:(0,L.jsx)(M6,{axis:`y`,label:n(`timeline.scrollY`),handleLabel:n(`keyframes.handleY`),handleUsage:n(`keyframes.zoomHandleY`),subscribe:t.subscribeView,read:()=>({content:e.contentHeight-28,view:c(),offset:e.scrollY}),scrollTo:t=>e.setScroll(e.scrollX,t),beginZoom:t=>{let n=e.rowScale,r=t===`start`?e.height:28;return t=>e.zoomRowsAround(r,n/t/e.rowScale)}})}),(0,L.jsx)(M6,{axis:`x`,label:n(`timeline.scrollX`),handleLabel:n(`timeline.handleX`),handleUsage:n(`timeline.help.zoomHandleX`),subscribe:t.subscribeView,read:()=>({content:e.contentWidth,view:e.width,offset:e.scrollX}),scrollTo:t=>e.setScroll(t,e.scrollY),beginZoom:t=>{let n=e.pixelsPerSecond,r=t===`start`?e.width:0;return t=>e.zoomAround(r,n/t/e.pixelsPerSecond)}}),o.element]})}function Ime(){let{keyframes:e,timeline:t}=U(),{t:n}=F(),{model:r}=(0,N.useSyncExternalStore)(t.subscribe,t.getSnapshot),i=e.panel;return r?(0,L.jsxs)(`div`,{className:o2.panel,onKeyDown:t=>{t.key===`Escape`&&t.currentTarget.contains(t.target)&&(i.cancelDrag()||e.clearSelection())},children:[(0,L.jsx)(jme,{view:i}),(0,L.jsxs)(`div`,{className:o2.body,children:[(0,L.jsx)(Nme,{view:i}),(0,L.jsx)(Fme,{view:i})]})]}):(0,L.jsx)(`div`,{className:o2.missing,children:n(`timeline.missing`)})}var Lme=class{#e;#t;#n=new Map;#r=new Map;constructor(e){this.#e=e}subscribe=e=>{let{timeline:t,trials:n}=this.#e,r=[t.subscribeView(e),t.subscribe(e),n.subscribe(e)];return()=>{for(let e of r)e()}};#i(){let e=this.#e.state(),{model:t,frame:n}=this.#e.timeline,{trials:r}=this.#e,i=r.getSnapshot(),{look:a}=r,o=this.#t;return(o===void 0||o.state!==e||o.model!==t||o.frame!==n||o.tried!==i||o.look!==a)&&(this.#t={state:e,model:t,frame:n,tried:i,look:a},this.#n.clear(),this.#r.clear()),this.#t}inspect(e,t){return this.#a(e,t)?.inspected}#a(e,t){let n=this.#i(),r=n?.model?.boxes.get(e);if(!n?.state||!n.model||!r)return;let i=this.#n.get(e);i||this.#n.set(e,i=new WeakMap);let a=i.get(t);if(a)return a;let{state:o,model:s,frame:c,look:l,tried:u}=n,d=Y2(o,s,r,t,c,{look:l,comparing:u.comparing}),f={inspected:d,signature:Rme(d)};return i.set(t,f),f}signatureOf(e,t){return this.#a(e,t)?.signature??``}placeOf(e){let t=this.#i(),n=this.#r.get(e);if(n!==void 0)return n;let r=t?.model?.boxes.get(e);if(!t?.state||!t.model||!r)return``;let{state:i,model:a,frame:o,look:s,tried:c}=t,l=_de(i,a,r,o,{look:s,comparing:c.comparing}),u=`${l.blocked??``} ${l.firstFrame}`;return this.#r.set(e,u),u}};function Rme({row:e,blocked:t}){return JSON.stringify([e.value,e.stored===void 0,e.automatic,e.animated,e.keyTime,e.previousKey,e.nextKey,e.tried,e.changedElsewhere,t])}function zme(e){let[t=``,n=`0`]=e.split(` `);return{blocked:t===``?void 0:t,firstFrame:Number(n)}}var q6=`application/x-animaquill-effect-order`;function J6(e,t){let n=e.currentTarget.getBoundingClientRect();return e.clientY<n.top+n.height/2?t:t+1}var Y6=1600;function Bme(e){let{clip:t,effect:n,readOnly:r}=e,{timeline:i}=U(),{t:a}=F(),[o,s]=(0,N.useState)({}),[c,l]=(0,N.useState)(!1),u=i.model?.rate;if(!u)return null;let d=uq(j(t.duration),u),f=(e,t)=>e===void 0?t:Math.min(uq(j(e),u),d),p={start:f(n.start,0),end:f(n.end,d)},m=(e,r)=>{s(t=>({...t,[e]:void 0}));let a=r.trim()===``?e===`start`?0:d:mq(r,u),o={...p,[e]:a};a===void 0||o.start<0||o.end>d||o.start>=o.end?l(!0):(l(!1),i.setEffectRange(t.id,n.id,o.start<=0?void 0:lq(o.start,u),o.end>=d?void 0:lq(o.end,u)))},h=e=>{let t=a(`effect.${e}`);return(0,L.jsx)(`input`,{className:$.text,"aria-label":t,"aria-invalid":c||void 0,title:t,spellCheck:!1,readOnly:r,value:o[e]??pq(p[e],u),onChange:t=>{let{value:n}=t.currentTarget;s(t=>({...t,[e]:n}))},onKeyDown:t=>{if(!t.nativeEvent.isComposing){if(t.key===`Escape`)s(t=>({...t,[e]:void 0})),l(!1);else if(t.key!==`Enter`)return;t.preventDefault(),t.stopPropagation(),t.key===`Enter`&&m(e,t.currentTarget.value),t.currentTarget.closest(`[tabindex]`)?.focus({preventScroll:!0})}},onBlur:t=>{o[e]!==void 0&&m(e,t.currentTarget.value)}})};return(0,L.jsxs)(L.Fragment,{children:[(0,L.jsxs)(`div`,{className:$.row,role:`group`,"aria-label":a(`effect.range`),"data-effect-range":``,children:[(0,L.jsx)(`span`,{className:$.name,children:a(`effect.range`)}),(0,L.jsxs)(`div`,{className:$.rangeFields,children:[h(`start`),(0,L.jsx)(`span`,{"aria-hidden":!0,children:`–`}),h(`end`)]})]}),c&&(0,L.jsx)(`p`,{className:$.transitionInvalid,children:a(`effect.rangeInvalid`)}),!c&&p.start>=p.end&&(0,L.jsx)(`p`,{className:$.transitionHint,children:a(`effect.nowhere`)})]})}function Vme(e){let{timeline:t}=U(),n=(0,N.useSyncExternalStore)(t.subscribeAdded,()=>t.lastAdded),[r,i]=(0,N.useState)(()=>n&&Date.now()-n.time>Y6?n.at:void 0);return(0,N.useEffect)(()=>{if(!n)return;let e=Math.max(Y6-(Date.now()-n.time),0),t=setTimeout(()=>i(n.at),e);return()=>clearTimeout(t)},[n]),n&&r!==n.at?n.effects.get(e):void 0}function Hme({clip:e,objects:t,readOnly:n,rows:r}){let{timeline:i}=U(),{t:a}=F(),o=bA(e),[s,c]=(0,N.useState)(),[l,u]=(0,N.useState)(),d=Vme(e.id),f=(0,N.useRef)(null);if((0,N.useEffect)(()=>{d!==void 0&&(f.current?.querySelector(`[data-effect="${CSS.escape(d)}"]`))?.scrollIntoView?.({block:`nearest`,behavior:`smooth`})},[d]),o.length===0)return null;let p=new Map(t.map(e=>[e.id,e])),m=(t,n)=>{let r=o.findIndex(e=>e.id===t),a=n>r?n-1:n;a!==r&&i.moveEffect(e.id,t,a)},h=(t,r,a)=>{n||(t.key===`ArrowUp`&&a>0?(t.preventDefault(),i.moveEffect(e.id,r,a-1)):t.key===`ArrowDown`&&a<o.length-1&&(t.preventDefault(),i.moveEffect(e.id,r,a+1)))};return(0,L.jsxs)(`section`,{className:$.effects,"aria-label":a(`effect.section`),"data-object":eI,children:[(0,L.jsx)(`h3`,{className:$.objectName,children:a(`effect.section`)}),(0,L.jsx)(`ol`,{ref:f,className:$.effectList,children:o.map((t,o)=>{let{id:f,type:g,enabled:_}=t,v=F$(a,g),y=p.get(tI(f)),b=_!==!1,x=y!==void 0&&y.properties.length>0;return(0,L.jsxs)(`li`,{className:$.effect,"aria-label":v,"data-effect":f,"data-off":!b||void 0,"data-fresh":d===f||void 0,"data-dragged":s===f||void 0,"data-drop":l===o?`before`:l===o+1?`after`:void 0,onDragOver:e=>{s&&e.dataTransfer.types.includes(q6)&&(e.preventDefault(),e.dataTransfer.dropEffect=`move`,u(J6(e,o)))},onDragLeave:()=>u(void 0),onDrop:e=>{let t=e.dataTransfer.getData(q6);t&&(e.preventDefault(),m(t,J6(e,o)),u(void 0),c(void 0))},children:[(0,L.jsxs)(`div`,{className:$.effectHeader,children:[(0,L.jsx)(`button`,{type:`button`,className:$.effectGrip,"aria-label":a(`effect.reorder`,{name:v}),title:a(`effect.reorder`,{name:v}),draggable:!n,"aria-disabled":n||void 0,onDragStart:e=>{e.dataTransfer.setData(q6,f),e.dataTransfer.effectAllowed=`move`,c(f)},onDragEnd:()=>{c(void 0),u(void 0)},onKeyDown:e=>h(e,f,o),children:(0,L.jsx)(Pu,{size:13})}),(0,L.jsx)(`input`,{type:`checkbox`,className:$.effectToggle,checked:b,disabled:n,"aria-label":a(`effect.on`,{name:v}),onChange:t=>i.setEffectEnabled(e.id,f,t.target.checked)}),(0,L.jsx)(`span`,{className:$.effectName,children:v}),!b&&(0,L.jsx)(`span`,{className:$.effectOff,children:a(`effect.off`)}),(0,L.jsx)(B2,{name:a(`effect.remove`,{name:v}),usage:a(`effect.remove`,{name:v}),unavailable:n,onClick:()=>i.removeEffect(e.id,f),children:(0,L.jsx)(sf,{size:12})})]}),(0,L.jsx)(Bme,{clip:e,effect:t,readOnly:n}),x?r.get(y.id):(0,L.jsx)(`p`,{className:$.effectMissing,children:a(`effect.missing`)})]},f)})})]})}var X6=[`linear`,`easeIn`,`easeOut`,`easeInOut`],Z6=e=>e===`linear`?void 0:lae[e];function Ume(e){return!e||Q6(e)?`linear`:X6.find(t=>{let n=Z6(t);return n!==void 0&&n.every((t,n)=>t===e[n])})}var Q6=([e,t,n,r])=>e===t&&n===r,Wme=[1/3,1/3,2/3,2/3],$6=e=>e??Wme,e8=(e,t,n)=>Math.min(Math.max(e,t),n),t8=e=>Math.round(e*1e3)/1e3;function n8(e,t,n,r,i){let[a,o,s,c]=$6(e),l=[t8(e8(n,0,1)),t8(i?e8(r,-1,2):e8(r,0,1))];return t===0?[l[0],l[1],s,c]:[a,o,l[0],l[1]]}var r8=e=>Q6(e)?void 0:e,Gme=e=>e.closest(`[tabindex]`)?.focus({preventScroll:!0});function Kme(e,t,n){if(X$(e,t,n))return;let r=e.rowOfClip.get(t.id)?.track.kind;return r===`caption`?`caption`:e.joined.has(`${t.id} ${n}`)?`joined`:r===`audio`?`sound`:`unsupported`}var i8=(e,t)=>kD(t,e.type)?.overshoot===!0;function a8({disabled:e,onDelete:t}){let{t:n}=F();return(0,L.jsx)(`button`,{type:`button`,className:$.hintButton,disabled:e,onClick:t,children:n(`transition.delete`)})}function o8(e){let{label:t,frames:n,longest:r,rate:i,readOnly:a,onCommit:o}=e,{t:s}=F(),[c,l]=(0,N.useState)(),[u,d]=(0,N.useState)(!1),f=e=>{let t=mq(e,i);l(void 0),t===void 0?d(!0):(d(!1),t!==n&&o(Math.min(Math.max(t,0),r)))};return(0,L.jsxs)(L.Fragment,{children:[(0,L.jsxs)(`div`,{className:$.row,role:`group`,"aria-label":t,children:[(0,L.jsx)(`span`,{className:$.name,children:t}),(0,L.jsx)(`input`,{className:$.text,"aria-label":t,"aria-invalid":u||void 0,spellCheck:!1,readOnly:a,value:c??pq(n,i),onChange:e=>l(e.currentTarget.value),onKeyDown:e=>{if(!e.nativeEvent.isComposing){if(e.key===`Escape`)l(void 0),d(!1);else if(e.key!==`Enter`)return;e.preventDefault(),e.stopPropagation(),e.key===`Enter`&&f(e.currentTarget.value),Gme(e.currentTarget)}},onBlur:e=>{c!==void 0&&f(e.currentTarget.value)}})]}),(0,L.jsx)(`p`,{className:u?$.transitionInvalid:$.transitionHint,children:u?s(`transition.durationInvalid`):s(`transition.durationHint`,{longest:pq(r,i)})})]})}var s8=100,c8=8,l8=e=>c8+e*s8,u8=e=>c8+(1-e)*s8;function qme(e){let{curve:t,overshoot:n,readOnly:r,onCommit:i}=e,{t:a}=F(),[o,s]=(0,N.useState)(),c=(0,N.useRef)(void 0),l=e=>{c.current=e,s(e)},[u,d,f,p]=o?.curve??$6(t),m=e=>{let t=(e.currentTarget.ownerSVGElement??e.currentTarget).getBoundingClientRect(),n=t.width/116,r=(e.clientX-t.left)/n-c8,i=(e.clientY-t.top)/n-c8;return{x:r/s8,y:1-i/s8}},h=e=>n=>{r||n.button!==0||(n.preventDefault(),n.currentTarget.setPointerCapture(n.pointerId),l({handle:e,curve:$6(t)}))},g=e=>{let t=c.current;if(!t)return;let{x:r,y:i}=m(e);l({...t,curve:n8(t.curve,t.handle,r,i,n)})},_=()=>{let e=c.current;if(!e)return;l(void 0);let n=r8(e.curve);JSON.stringify(n)!==JSON.stringify(t)&&i(n)},v=e=>a=>{let o={ArrowLeft:[-.05,0],ArrowRight:[.05,0],ArrowUp:[0,.05],ArrowDown:[0,-.05]}[a.key];if(r||!o)return;a.preventDefault(),a.stopPropagation();let[s,c]=e===0?[u,d]:[f,p];i(r8(n8(t,e,s+o[0],c+o[1],n)))},y=`M ${l8(0)} ${u8(0)} C ${l8(u)} ${u8(d)}, ${l8(f)} ${u8(p)}, ${l8(1)} ${u8(1)}`,b=(e,t,n,i,s)=>(0,L.jsxs)(`g`,{children:[(0,L.jsx)(`line`,{className:$.curveHandleLine,x1:l8(i),y1:u8(s),x2:l8(t),y2:u8(n)}),(0,L.jsx)(`circle`,{className:$.curveHandle,cx:l8(t),cy:u8(n),r:4,role:`slider`,tabIndex:r?-1:0,"aria-label":a(e===0?`transition.handles.first`:`transition.handles.second`),"aria-valuetext":`${t}, ${n}`,"aria-disabled":r||void 0,"data-dragging":o?.handle===e||void 0,onPointerDown:h(e),onPointerMove:g,onPointerUp:_,onPointerCancel:()=>l(void 0),onLostPointerCapture:_,onKeyDown:v(e)})]},e);return(0,L.jsxs)(`svg`,{className:$.curve,viewBox:`0 0 116 116`,role:`group`,"aria-label":a(`transition.curve`),"data-readonly":r||void 0,children:[(0,L.jsx)(`rect`,{className:$.curveFrame,x:c8,y:c8,width:s8,height:s8}),(0,L.jsx)(`path`,{className:$.curveLine,d:y}),b(0,u,d,0,0),b(1,f,p,1,1)]})}function d8(e){let{curve:t,overshoot:n,readOnly:r,onCommit:i}=e,{t:a}=F(),o=Ume(t);return(0,L.jsxs)(L.Fragment,{children:[(0,L.jsxs)(`div`,{className:$.row,role:`group`,"aria-label":a(`transition.speed`),children:[(0,L.jsx)(`span`,{className:$.name,children:a(`transition.speed`)}),(0,L.jsx)(`div`,{className:$.presets,children:X6.map(e=>(0,L.jsx)(`button`,{type:`button`,className:$.preset,"aria-pressed":o===e,disabled:r,onClick:()=>{o!==e&&i(Z6(e))},children:a(`transition.presets.${e}`)},e))})]}),(0,L.jsxs)(`div`,{className:$.curveRow,children:[(0,L.jsx)(qme,{curve:t,overshoot:n,readOnly:r,onCommit:i}),(0,L.jsx)(`p`,{className:$.transitionHint,children:a(`transition.curveHint`)})]})]})}function Jme(e,t){return{spec:e,path:e.path,stored:t,value:t,automatic:!1,animated:!1,keyTime:void 0,previousKey:void 0,nextKey:void 0,tried:!1,changedElsewhere:!1}}function f8(e){let{media:t,transition:n,readOnly:r,onCommit:i}=e,{t:a}=F(),[o,s]=(0,N.useState)(),c=kD(t,n.type),l=c?OD(c):[];if(!c||l.length===0)return null;let u=AD(c,n.values),d=n.values??{},f=(e,t)=>{if(s(void 0),JSON.stringify(t)===JSON.stringify(u[e.path]))return;let{[e.path]:n,...r}=d,a=t===e.default?r:{...r,[e.path]:t};i(Object.keys(a).length>0?a:void 0)},p=e=>YX(a,`transition.properties.${e.path}.name`,e.path),m=(e,t)=>YX(a,`transition.properties.${e.path}.options.${t}`,t);return(0,L.jsxs)(L.Fragment,{children:[l.map(e=>{let t=p(e),n=u[e.path];if(e.type===`choice`&&(e.options?.length??0)<=4)return(0,L.jsxs)(`div`,{className:$.row,role:`radiogroup`,"aria-label":t,"data-transition-value":e.path,children:[(0,L.jsx)(`span`,{className:$.name,children:t}),(0,L.jsx)(`div`,{className:$.presets,children:e.options?.map(t=>(0,L.jsx)(`button`,{type:`button`,role:`radio`,className:$.preset,"aria-checked":n===t,"aria-pressed":n===t,disabled:r,onClick:()=>f(e,t),children:m(e,t)},t))})]},e.path);let i=z2[e.type];if(!i)return null;let a=o?.path===e.path?o.value:n;return(0,L.jsxs)(`div`,{className:$.row,role:`group`,"aria-label":t,"data-transition-value":e.path,children:[(0,L.jsx)(`span`,{className:$.name,children:t}),(0,L.jsx)(`div`,{className:$.valueCell,children:(0,L.jsx)(i,{row:Jme(e,a),label:t,readOnly:r,onPreview:t=>s({path:e.path,value:t}),onCommit:t=>f(e,t),onCancel:()=>s(void 0),format:t=>m(e,String(t))})})]},e.path)}),(0,L.jsx)(`p`,{className:$.transitionHint,children:a(`transition.valuesHint`)})]})}var p8=e=>e?[e[0],e[1],e[2],e[3]]:void 0;function Yme({choice:e}){return b4(e)?(0,L.jsx)(Zme,{join:e.join}):(0,L.jsx)(Xme,{clip:e.clip,edge:e.edge})}function Xme({clip:e,edge:t}){let{timeline:n}=U(),{t:r}=F(),{model:i}=(0,N.useSyncExternalStore)(n.subscribe,n.getSnapshot),a=i?.boxes.get(e),o=i?.rowOfClip.get(e),s=a?.clip[t];if(!i||!a||!o||!s)return null;let{rate:c}=i,l=RD(o.track.kind),u=e0(r,s,t,l),d=a.clip.name??YX(r,`timeline.kind.${a.clip.source.kind}`,a.clip.source.kind),f=o.track.locked===!0,p=Kme(i,a,t),m=Math.round(Y$(a.clip)[t]*c.fps),h=uq(k1(a.clip,t,i),c),g=e=>n.setTransition(a.id,t,e),_=e=>{let{curve:t,...n}=s,r=p8(e);return r?{...n,curve:r}:n};return(0,L.jsxs)(`section`,{className:$.transition,"aria-label":u,children:[(0,L.jsxs)(`header`,{className:$.header,children:[(0,L.jsx)(`span`,{className:$.title,children:u}),(0,L.jsx)(`span`,{className:$.kind,children:r(`transition.of`,{clip:d,use:r(`transition.uses.${t}`)})})]}),f&&(0,L.jsx)(`div`,{className:$.hint,role:`status`,children:(0,L.jsx)(`span`,{children:r(`transition.locked`)})}),p&&(0,L.jsx)(`div`,{className:$.hint,role:`status`,children:(0,L.jsx)(`span`,{children:r(`transition.why.${p}`)})}),(0,L.jsxs)(`div`,{className:$.hint,children:[(0,L.jsx)(`span`,{children:r(`transition.replaceHint`)}),(0,L.jsx)(a8,{disabled:f,onDelete:()=>n.setTransition(a.id,t,null)})]}),(0,L.jsxs)(`div`,{className:$.rows,children:[(0,L.jsx)(o8,{label:r(`transition.duration`),frames:m,longest:h,rate:c,readOnly:f,onCommit:e=>n.setTransitionLength(a.id,t,lq(e,c))}),(0,L.jsx)(d8,{curve:s.curve,overshoot:i8(s,l),readOnly:f,onCommit:e=>g(_(e))}),(0,L.jsx)(f8,{media:l,transition:s,readOnly:f,onCommit:e=>{let{values:t,...n}=s;g(e?{...n,values:e}:n)}})]})]})}var m8=(e,{clip:t})=>t.name??YX(e,`timeline.kind.${t.source.kind}`,t.source.kind);function Zme({join:e}){let{timeline:t}=U(),{t:n}=F(),{model:r}=(0,N.useSyncExternalStore)(t.subscribe,t.getSnapshot),i=r?.joins.get(e),a=i&&r?.rowOfClip.get(i.from.id);if(!r||!i||!a)return null;let{rate:o}=r,{transition:s}=i.join,c=RD(a.track.kind),l=e0(n,s,`join`,c),u=a.track.locked===!0,d=s.align??`center`,f=uq(j(s.duration),o),p=uq(t.longestJoin(i),o),m=n=>t.updateJoin(e,n),h={from:m8(n,i.from),to:m8(n,i.to)};return(0,L.jsxs)(`section`,{className:$.transition,"aria-label":l,children:[(0,L.jsxs)(`header`,{className:$.header,children:[(0,L.jsx)(`span`,{className:$.title,children:l}),(0,L.jsx)(`span`,{className:$.kind,children:n(`transition.between`,h)})]}),u&&(0,L.jsx)(`div`,{className:$.hint,role:`status`,children:(0,L.jsx)(`span`,{children:n(`transition.locked`)})}),i.trouble&&(0,L.jsx)(`div`,{className:$.hint,role:`status`,children:(0,L.jsx)(`span`,{children:n(`transition.why.join.${i.trouble}`)})}),i.still.length>0&&(0,L.jsx)(`div`,{className:$.hint,role:`status`,children:(0,L.jsx)(`span`,{children:n(`transition.still`)})}),(0,L.jsxs)(`div`,{className:$.hint,children:[(0,L.jsx)(`span`,{children:n(`transition.replaceHint`)}),(0,L.jsx)(a8,{disabled:u,onDelete:()=>t.removeJoin(e)})]}),(0,L.jsxs)(`div`,{className:$.rows,children:[(0,L.jsx)(o8,{label:n(`transition.duration`),frames:f,longest:p,rate:o,readOnly:u,onCommit:n=>{n<=0?t.removeJoin(e):m({duration:ze(lq(n,o))})}}),(0,L.jsxs)(`div`,{className:$.row,role:`group`,"aria-label":n(`transition.position`),children:[(0,L.jsx)(`span`,{className:$.name,children:n(`transition.position`)}),(0,L.jsx)(`div`,{className:$.presets,children:BD.map(e=>(0,L.jsx)(`button`,{type:`button`,className:$.preset,"aria-pressed":d===e,disabled:u,onClick:()=>{d!==e&&m({align:e})},children:n(`transition.align.${e}`)},e))})]}),(0,L.jsx)(d8,{curve:s.curve,overshoot:i8(s,c),readOnly:u,onCommit:e=>m({curve:p8(e)??null})}),(0,L.jsx)(f8,{media:c,transition:s,readOnly:u,onCommit:e=>m({values:e??null})})]})]})}var Qme=25,$me=28,ehe=`600px 0px`,the=4;function nhe(e,t){let[n,r]=(0,N.useState)(t);return(0,N.useEffect)(()=>{let t=e.current;if(!t||typeof IntersectionObserver>`u`)return;let n=t.closest(`[data-scroll]`),i=new IntersectionObserver(([e])=>r(e?.isIntersecting===!0),{root:n,rootMargin:ehe});return i.observe(t),()=>i.disconnect()},[e]),n}function rhe(e,t,n){return(0,N.useSyncExternalStore)(e.subscribe,()=>e.signatureOf(t,n)),e.inspect(t,n)}var ihe=(0,N.memo)(function({rows:e,clip:t,spec:n,startsGroup:r}){let{properties:i,trials:a}=U(),{t:o}=F(),[s,c]=(0,N.useState)(),l=rhe(e,t,n);if(!l)return null;let{row:u,blocked:d}=l,{path:f,tried:p}=u,m=XX(o,n),{group:h}=n,g=h===void 0?m:`${ZX(o,h)} ${m}`,_=d!==void 0,v=z2[n.type]??R2,y=()=>e.inspect(t,n)??l;return(0,L.jsxs)(L.Fragment,{children:[(0,L.jsxs)(`div`,{className:$.row,role:`group`,"aria-label":g,"data-tried":p||void 0,"data-readonly":_||void 0,onContextMenu:e=>{p&&(e.preventDefault(),c({x:e.clientX,y:e.clientY}))},children:[h===void 0?(0,L.jsx)(`span`,{className:$.name,children:m}):(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(`span`,{className:$.group,children:r?ZX(o,h):``}),(0,L.jsx)(`span`,{className:$.part,children:m})]}),(0,L.jsx)(v,{row:u,label:g,readOnly:_,onPreview:e=>{let{row:n,time:r}=y();i.preview([V2(t,n,r,e)])},onCommit:e=>{let{row:n,time:r,blocked:a}=y();a?i.cancel():i.commit([V2(t,n,r,e)])},onCancel:()=>i.cancel()}),(0,L.jsx)(ahe,{rows:e,clip:t,spec:n,animated:u.animated,onKey:u.keyTime!==void 0,previousKey:u.previousKey,nextKey:u.nextKey,canKey:!_&&H2(t,u,l.time)!==void 0,canReset:!_&&u.stored!==void 0})]}),u.changedElsewhere&&(0,L.jsx)(`p`,{className:$.elsewhere,children:o(`trial.changedElsewhere`)}),s&&(0,L.jsx)(ov,{label:g,x:s.x,y:s.y,groups:[[{id:`discard`,label:o(`trial.discardProperty`),run:()=>a.discardProperty(t,f)}]],onClose:()=>c(void 0)})]})}),ahe=(0,N.memo)(function(e){let{rows:t,clip:n,spec:r,animated:i,onKey:a,previousKey:o,nextKey:s,canKey:c,canReset:l}=e,{properties:u,timeline:d}=U(),{t:f}=F();return(0,L.jsxs)(`div`,{className:$.rowButtons,children:[r.animatable!==!1&&(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(B2,{name:f(`property.previousKey`),usage:f(`property.help.previousKey`),unavailable:o===void 0,onClick:()=>d.seek(o),children:(0,L.jsx)(ml,{size:13})}),(0,L.jsx)(B2,{name:f(a?`property.removeKey`:`property.addKey`),usage:f(i?`property.help.key`:`property.help.firstKey`),unavailable:!c,pressed:a,onClick:()=>{let e=t.inspect(n,r),i=e&&H2(n,e.row,e.time);i&&u.commit([i])},children:(0,L.jsx)(Wl,{size:12,className:i?$.keyed:void 0,...a?{fill:`currentColor`}:{}})}),(0,L.jsx)(B2,{name:f(`property.nextKey`),usage:f(`property.help.nextKey`),unavailable:s===void 0,onClick:()=>d.seek(s),children:(0,L.jsx)(gl,{size:13})})]}),(0,L.jsx)(B2,{name:f(`property.reset`),usage:f(`property.help.reset`),unavailable:!l,onClick:()=>u.commit([{owner:{clip:n},path:r.path,op:`clear`}]),children:(0,L.jsx)(Ad,{size:12})})]})}),h8=(0,N.memo)(function({rows:e,clip:t,object:n,name:r,eager:i}){let a=(0,N.useRef)(null),[o,s]=(0,N.useState)(!1),c=nhe(a,i)||o,{properties:l}=n,[u,d]=(0,N.useState)();(0,N.useEffect)(()=>{let e=a.current;if(!c||!e||typeof ResizeObserver>`u`)return;let t=new ResizeObserver(()=>d(e.offsetHeight));return t.observe(e),()=>t.disconnect()},[c]);let f=(r===void 0?0:$me)+l.length*Qme;return(0,L.jsxs)(`section`,{ref:a,className:$.object,...r!==void 0&&{"aria-label":r},style:c?void 0:{height:u??f},onFocus:()=>s(!0),onBlur:e=>{e.currentTarget.contains(e.relatedTarget)||s(!1)},children:[r!==void 0&&(0,L.jsx)(`h3`,{className:$.objectName,children:r}),c&&l.map((n,r)=>(0,L.jsx)(ihe,{rows:e,clip:t,spec:n,startsGroup:l[r-1]?.group!==n.group},n.path))]})});function ohe(e,t){return zme((0,N.useSyncExternalStore)(e.subscribe,()=>e.placeOf(t)))}function she({blocked:e,firstFrame:t}){let{timeline:n,trials:r}=U(),{t:i}=F();return(0,L.jsxs)(`div`,{className:$.hint,role:`status`,children:[(0,L.jsx)(`span`,{children:i(`property.blocked.${e}`)}),e===`outside`&&(0,L.jsx)(`button`,{type:`button`,className:$.hintButton,onClick:()=>n.seek(t),children:i(`property.goToClip`)}),e===`comparing`&&(0,L.jsx)(`button`,{type:`button`,className:$.hintButton,onClick:()=>r.toggleCompare(),children:i(`trial.backToTrial`)})]})}function che({clip:e}){let{sounds:t}=U(),{t:n}=F();(0,N.useSyncExternalStore)(t.subscribe,t.getVersion);let r=t.stateOf(e);return!r||r.state===`ready`?null:(0,L.jsxs)(`div`,{className:$.hint,role:`status`,children:[(0,L.jsx)(`span`,{children:n(`sound.state.${r.state}`)}),r.state===`failed`&&(0,L.jsx)(`button`,{type:`button`,className:$.hintButton,onClick:()=>t.retry(e),children:n(`sound.retry`)})]})}function g8(e,{type:t,name:n,id:r}){if(t!==`clip.visual`&&t!==`clip.sound`)return t===aI.params?e(`keyframes.objects.params`):t===aI.elements?e(`keyframes.objects.elements`):n??r}var lhe=4;function uhe(e,t,n){let r=g8(e,t);if(r===void 0)return;let i=[r],a=new Set([t.id]),o=t.parent===void 0?void 0:n.get(t.parent);for(;o&&!a.has(o.id)&&i.length<=lhe;)a.add(o.id),i.unshift(g8(e,o)??o.id),o=o.parent===void 0?void 0:n.get(o.parent);return i.join(` › `)}function dhe({selected:e,rows:t}){let{t:n}=F(),{box:r,objects:i}=e,{blocked:a,firstFrame:o}=ohe(t,r.id),s=new Map(i.map(e=>[e.id,e])),{kind:c}=r.clip.source,l=YX(n,`timeline.kind.${c}`,c),u=e=>e.type===$F.effects||e.type?.startsWith($F.prefix)===!0,d=i.filter(e=>e.properties.length>0&&!u(e)),f=new Map(i.filter(e=>u(e)&&e.properties.length>0).map(e=>[e.id,(0,L.jsx)(h8,{rows:t,clip:r.id,object:e,name:void 0,eager:!0},`${r.id} ${e.id}`)]));return(0,L.jsxs)(L.Fragment,{children:[(0,L.jsxs)(`header`,{className:$.header,children:[(0,L.jsx)(`span`,{className:$.title,children:r.clip.name??l}),r.clip.name!==void 0&&(0,L.jsx)(`span`,{className:$.kind,children:l})]}),c===`sound`&&(0,L.jsx)(che,{clip:r.clip}),a&&(0,L.jsx)(she,{blocked:a,firstFrame:o}),(0,L.jsxs)(`div`,{className:$.rows,"data-readonly":a!==void 0||void 0,children:[d.map((e,i)=>(0,L.jsx)(h8,{rows:t,clip:r.id,object:e,name:uhe(n,e,s),eager:i<the},`${r.id} ${e.id}`)),(0,L.jsx)(Hme,{clip:r.clip,objects:i,readOnly:a===`locked`||a===`comparing`,rows:f})]})]})}function _8({text:e}){return(0,L.jsxs)(`div`,{className:$.message,children:[(0,L.jsx)(Jd,{size:32}),(0,L.jsx)(`p`,{children:e})]})}function fhe(){let{timeline:e,trials:t,keyframes:n,registrations:r}=U(),{t:i}=F(),{store:a}=ev();tv(a);let{model:o,selection:s,transition:c}=(0,N.useSyncExternalStore)(e.subscribe,e.getSnapshot),{comparing:l}=(0,N.useSyncExternalStore)(t.subscribe,t.getSnapshot);(0,N.useSyncExternalStore)(r.subscribe,r.getVersion);let u=(0,N.useMemo)(()=>new Lme({timeline:e,trials:t,state:()=>a?.getState()}),[e,t,a]),{describe:d}=n,f=o?gde(o,s,{look:t.look,comparing:l,describe:d}):{kind:`nothing`};return c?(0,L.jsx)(`div`,{className:$.panel,tabIndex:-1,"data-scroll":!0,children:(0,L.jsx)(Yme,{choice:c})}):(0,L.jsxs)(`div`,{className:$.panel,tabIndex:-1,"data-scroll":!0,children:[f.kind===`nothing`&&(0,L.jsx)(_8,{text:i(`property.nothing`)}),f.kind===`no-properties`&&(0,L.jsx)(_8,{text:i(`property.noProperties`)}),f.kind===`several`&&(0,L.jsx)(_8,{text:i(`property.several`,{count:f.count})}),f.kind===`clip`&&(0,L.jsx)(dhe,{selected:f,rows:u})]})}var v8={panel:`_panel_1srs1_1`,toolbar:`_toolbar_1srs1_5`,search:`_search_1srs1_15`,hint:`_hint_1srs1_31`,row:`_row_1srs1_37`,name:`_name_1srs1_51`,keys:`_keys_1srs1_57`,key:`_key_1srs1_57`,add:`_add_1srs1_78`,none:`_none_1srs1_97`,reset:`_reset_1srs1_102`,recorder:`_recorder_1srs1_124`,prompt:`_prompt_1srs1_131`,warning:`_warning_1srs1_139`};function phe({action:e,onClose:t}){let{actions:n,keybindings:r}=U(),{t:i}=F(),[a,o]=(0,N.useState)(),[s,c]=(0,N.useState)(),l=(0,N.useRef)(null),{platform:u}=r;(0,N.useEffect)(()=>{let n=n=>{r.assign(e.id,n),t()},i=i=>{if(i.preventDefault(),i.stopPropagation(),i.isComposing||i.repeat)return;let s=tK(i,u);if(!s)return;if(s===`escape`)return t();if(s===`enter`&&a)return n(a.combo);if(o(void 0),c(void 0),!aK(s))return c(s);let l=r.ownerOf(s,e.scope);if(l===e.id)return t();if(l)return o({combo:s,owner:l});n(s)},s=e=>{l.current?.contains(e.target)||t()};return window.addEventListener(`keydown`,i,!0),window.addEventListener(`pointerdown`,s,!0),()=>{window.removeEventListener(`keydown`,i,!0),window.removeEventListener(`pointerdown`,s,!0)}},[e,a,r,t,u]);let d=a&&n.get(a.owner)?.title(i);return(0,L.jsxs)(`div`,{ref:l,className:v8.recorder,role:`status`,children:[(0,L.jsx)(`span`,{className:v8.prompt,children:i(`keys.recording`)}),s&&(0,L.jsx)(`span`,{className:v8.warning,children:i(`keys.reserved`,{key:rK(s,u)})}),a&&(0,L.jsxs)(`span`,{className:v8.warning,children:[i(`keys.conflict`,{key:rK(a.combo,u),action:d}),(0,L.jsx)(`button`,{type:`button`,onClick:()=>{r.assign(e.id,a.combo),t()},children:i(`keys.reassign`)}),(0,L.jsx)(`button`,{type:`button`,onClick:t,children:i(`keys.cancel`)})]})]})}function mhe({action:e,recording:t,onRecord:n}){let{keybindings:r}=U(),{t:i}=F(),a=(0,N.useRef)(null),o=(0,N.useRef)(!1),s=e.title(i),c=r.keysFor(e.id);return(0,N.useEffect)(()=>{o.current&&!t&&a.current?.focus(),o.current=t},[t]),(0,L.jsxs)(`div`,{className:v8.row,"data-action":e.id,children:[(0,L.jsx)(`span`,{className:v8.name,children:s}),(0,L.jsxs)(`div`,{className:v8.keys,children:[c.map(t=>{let n=rK(t,r.platform);return(0,L.jsxs)(`span`,{className:v8.key,children:[(0,L.jsx)(`kbd`,{children:n}),(0,L.jsx)(`button`,{type:`button`,"aria-label":i(`keys.remove`,{key:n}),onClick:()=>r.remove(e.id,t),children:(0,L.jsx)(xf,{size:12})})]},t)}),c.length===0&&!t&&(0,L.jsx)(`span`,{className:v8.none,children:i(`keys.none`)}),!t&&(0,L.jsx)(`button`,{ref:a,type:`button`,className:v8.add,"aria-label":i(`keys.add`,{action:s}),onClick:()=>n(e.id),children:(0,L.jsx)(wd,{size:14})}),t&&(0,L.jsx)(phe,{action:e,onClose:()=>n(void 0)})]}),r.isCustomized(e.id)&&(0,L.jsx)(`button`,{type:`button`,className:v8.reset,onClick:()=>r.reset(e.id),children:i(`keys.reset`)})]})}function hhe(){let{actions:e,keybindings:t}=U(),{t:n}=F(),[r,i]=(0,N.useState)(``),[a,o]=(0,N.useState)();(0,N.useSyncExternalStore)(t.subscribe,t.getSnapshot);let s=e.list().filter(e=>{let i=r.trim().toLowerCase();if(!i)return!0;let a=t.keysFor(e.id).map(e=>rK(e,t.platform).toLowerCase());return m0(r,e.title(n))!==void 0||a.some(e=>e.includes(i))});return(0,L.jsxs)(`div`,{className:v8.panel,children:[(0,L.jsxs)(`div`,{className:v8.toolbar,children:[(0,L.jsx)(`input`,{className:v8.search,type:`search`,"aria-label":n(`keys.search`),placeholder:n(`keys.search`),spellCheck:!1,value:r,onChange:e=>i(e.target.value)}),(0,L.jsx)(`button`,{type:`button`,className:v8.reset,disabled:!t.hasCustomizations,onClick:()=>t.resetAll(),children:n(`keys.resetAll`)})]}),(0,L.jsx)(`p`,{className:v8.hint,children:n(`keys.browserHint`)}),s.length===0&&(0,L.jsx)(`p`,{className:v8.hint,children:n(`keys.empty`)}),s.map(e=>(0,L.jsx)(mhe,{action:e,recording:a===e.id,onRecord:o},e.id))]})}var ghe=17,_he=100,vhe=8,yhe=/^[A-Za-z0-9][A-Za-z0-9_-]{0,63}$/;function bhe(e){if(!e||e.length===0)return;let t=e=>typeof e==`number`&&Number.isInteger(e)&&e>0?e:`?`;return e.slice(0,vhe).map(({layer:e,kind:n,width:r,height:i,standIn:a})=>{let o=typeof e==`string`&&yhe.test(e)?e:`?`,s=a===!0?` proxy`:``;return`${o} ${n===`video`?n:`?`} ${t(r)}x${t(i)}${s}`}).join(`, `)}var xhe=250,She=new Map;function Che(e,t,n){let r=ioe(e,t);return n!==void 0&&r&&RF(n,r.type)||null}function y8(e,t,r){let i={},a={},o,s=!1,c=!1;for(let l of new Set([...t?.keys()??[],...r?.keys()??[]])){let u=r?.has(l)===!0,d=r?.get(l);u&&t?.has(l)===!0&&t.get(l)===d||(s=!0,l===`fit`?o=u?VF(d===void 0?{}:{fit:d}):e.fit:e.content&&n(l)?(a[l]=(u?d:e.content[l])??null,c=!0):i[l]=u?Che(e,l,d):e.channels[l]??null)}if(s)return{channels:i,...o===void 0?{}:{fit:o},...c&&{content:a}}}function b8(e,t){if(t.size===0)return e;let n=e.layers.map(e=>{let n=y8(e,void 0,t.get(e.id));return n?Sn(e,n):e});return{...e,layers:n}}function x8(e,t){return t===1?e:{...e,...jX(e.width,e.height,t)}}function whe({layers:e}){let t=new Map;for(let{id:n,source:r}of e)r.kind===`scene`&&t.set(n,r.revision);return t}var The=class{#e;#t;#n;#r;#i;#a;#o;#s;#c;#l;#u;#d;#f;#p;#m;#h=new Map;#g;#_;#v;#y=new Map;#b=new Map;#x=new Map;#S=0;#C=new Map;#w;#T;#E=!1;#D=!1;#O;#k=new Map;#A;#j=She;#M=()=>{};constructor(e,t,n,r,i,a,o,s,c,l,u,d,f,p,m,h){this.#v=h,this.#m=f,this.#g=p,this.#_=m,this.#e=e,this.#t=t,this.#n=n,this.#r=r,this.#i=i,this.#a=a,this.#o=o,this.#s=c,this.#c=l,this.#l=new Lq(()=>e.contentWindow,(e,t)=>this.#N({type:`evict`,index:e,frames:t})),this.#u=new zq(e,e=>{this.#N({type:`focus-taken`,request:e})}),this.#d=new Uq(e=>this.#N({type:`ping`,nonce:e}),e=>c.hung(e)),this.#f=u.attach(),this.#p=d,addEventListener(`message`,this.#P);let g=r.subscribe(this.#R),_=t.subscribeView(this.#U),v=t.subscribe(this.#L),y=o.subscribe(this.#F),b=s.onRestored(e=>{this.#Y(e,!0),this.#K(e)}),x=n.subscribe(this.#z),S=d.subscribe(this.#R),ee=p?.subscribeWanted(this.#I),C=m?.subscribe(this.#J),w=d.subscribe(this.#J);this.#M=()=>{C?.(),w(),ee?.(),this.#u.dispose(),this.#d.dispose(),this.#f.dispose(),S(),d.noteSize(void 0),x(),g(),_(),v(),y(),b(),removeEventListener(`message`,this.#P)}}dispose(){this.#M()}#N(e){this.#e.contentWindow?.postMessage(e,`*`)}retryScene(e){this.#N({type:`scene-retry`,layer:e})}#P=e=>{let{source:t}=e;if(t!==this.#e.contentWindow){this.#l.note(t);return}let{data:n}=e;if(n.type===`ready`)this.#E=!0,this.#O=void 0,this.#A=void 0,this.#T=void 0,this.#B=void 0,this.#H=void 0,this.#D=!1,this.#w=void 0,this.#y.clear(),this.#b.clear(),this.#d.ready(),this.#s.forgetScenes(),this.#N({type:`setup`,...this.#c,retired:this.#s.retiredOrigins}),this.#L(),this.#F(),this.#I();else if(n.type===`pong`)this.#d.pong(n.nonce),this.#s.worked();else if(n.type===`focus-checked`)this.#u.checked(n.request);else if(n.type===`needs-scene`)this.#G(n.scene,n.revision);else if(n.type===`scene-status`)this.#s.noteScene(n.layer,n.status);else if(n.type===`scene-problem`){let e=this.#k.get(n.layer)?.source;e?.kind===`scene`&&e.revision===n.revision&&this.#s.noteProblem(n.layer,n.revision,n.problem)}else if(n.type===`scene-handles`)this.#g?.note(n.layer,n.revision,n.frame,n.handles);else if(n.type===`scene-objects`){let e=this.#m?.note(n.revision,n.registration);e!==void 0&&this.#h.set(n.layer,{revision:n.revision,params:e})}else if(n.type===`scene-objects-unsure`){let e=this.#h.get(n.layer);e?.revision===n.revision&&this.#m?.unsure(e.revision,e.params)}else if(n.type===`origin-retired`)this.#s.noteRetired(n.origin);else if(n.type===`frames`)for(let e of n.frames){let{ms:t,seconds:n,cold:r,behindMs:i,decodeMs:a,gettingReady:o,abandoned:s}=e,c=t>ghe||r>0,l=bhe(e.coldClips),u={seconds:n,cold:r,behindMs:Math.round(i),decodeMs:Math.round(a),gettingReady:o,abandoned:s,...l&&{coldClips:l}};this.#o.noteFrame(t,u,c)}else if(n.type===`long-tasks`){let e=performance.now();for(let{ms:t,ago:r}of n.tasks.slice(0,_he))Number.isFinite(t)&&Number.isFinite(r)&&this.#o.note(`compositor.longtask`,{ms:Math.round(t)},e-r)}else if(n.type===`painted`)this.#f.painted(n.ago);else if(n.type===`needs`)this.#Y(n.id);else if(n.type===`cannot-decode`)this.#a(n.id);else if(n.type===`slow-video`)this.#y.has(n.id)&&this.#y.get(n.id)===void 0&&this.#v?.(n.id);else if(n.type===`stand-in-failed`){let e=this.#y.get(n.id);if(!e||this.#x.get(n.id)!==n.serial)return;this.#b.set(n.id,e),this.#_?.failed(n.id),this.#Y(n.id,!0)}};#F=()=>{let e=this.#o.getRecording();this.#E&&e!==this.#D&&(this.#D=e,this.#N({type:`record`,on:e}))};#I=()=>{let e=this.#g?.wanted;this.#E&&e!==this.#w&&(this.#w=e,this.#N({type:`handles`,layer:e??null}))};#L=()=>{this.#R(),this.#U()};#R=()=>{let{model:e}=this.#t;if(!this.#E||!e)return;let t=this.#r.getState();this.#A=t;let n=XF(t,e.id),{scale:r}=this.#p.getSnapshot();if(!n||this.#O&&yoe(n,this.#O)&&r===this.#T)return;this.#O=n,this.#T=r,this.#k=new Map(n.layers.map(e=>[e.id,e])),this.#s.noteRevisions(whe(n)),this.#j=this.#n.getPreviewed();let i=b8(n,this.#j),a={width:n.width,height:n.height},o=x8(n,r);this.#N({type:`plan`,plan:i===n?o:x8(i,r),...i!==n&&{settled:o},full:a}),this.#p.noteSize({shown:{width:o.width,height:o.height},full:a})};#z=()=>{if(!this.#E)return;this.#A!==this.#r.getState()&&this.#R();let e=this.#n.getPreviewed();if(this.#O&&e!==this.#j){for(let t of new Set([...this.#j.keys(),...e.keys()])){let n=this.#k.get(t),r=n&&y8(n,this.#j.get(t),e.get(t));r&&this.#N({type:`channels`,layer:t,...r})}this.#j=e}};#B;#V;#H;#U=()=>{let{model:e,frame:t,playbackStart:n}=this.#t;if(!this.#E||!e)return;let{playing:r}=this.#t.getSnapshot(),i=r&&n&&n===this.#V;this.#V=n;let a=t/e.rate.fps;a!==this.#B&&(this.#B=a,this.#N({type:`seek`,seconds:a,jump:!i})),this.#W(r,!!i,a)};#W(e,t,n){let r=performance.now();if(!e){this.#H!==void 0&&this.#N({type:`pause`}),this.#H=void 0;return}let i=this.#H;if(t&&i!==void 0&&r-i<xhe)return;this.#H=r;let a=performance.timeOrigin+r;this.#N({type:`play`,seconds:n,at:a,rate:1,jump:!t})}async#G(e,t){let n=this.#i.media(JG(this.#r)),r=await Pq(this.#r.getState(),this.#O,{scene:e,revision:t},e=>n.get(e));r&&this.#N(r)}#K(e){let t=new Set;for(let{source:n}of this.#O?.layers??[]){if(n.kind!==`scene`||!n.assets.some(t=>t.file===e))continue;let r=`${n.scene}\n${n.revision}`;t.has(r)||(t.add(r),this.#G(n.scene,n.revision))}}#q(e){if(this.#p.getSnapshot().choice===`full`)return;let t=this.#_?.standInFor(e);if(t&&this.#b.get(e)!==t.file)return t}#J=()=>{for(let[e,t]of this.#y)this.#q(e)?.file!==t&&this.#Y(e,!0)};async#Y(e,t=!1){let n=this.#O?.layers??[];if(!n.some(({source:t})=>(t.kind===`image`||t.kind===`video`)&&t.file===e))return;let r=(this.#C.get(e)??0)+1;this.#C.set(e,r);let i=n.some(({source:t})=>t.kind===`video`&&t.file===e),a=i?this.#q(e):void 0;if(a){this.#X(e,a);return}let o=await this.#i.media(JG(this.#r)).get(e);if(this.#C.get(e)!==r)return;let s=i?this.#q(e):void 0;s?this.#X(e,s):o?(this.#y.set(e,void 0),this.#N({type:`file`,id:e,file:o}),i&&this.#Z(e)):t?(this.#y.delete(e),this.#N({type:`no-file`,id:e})):this.#a(e)}#X(e,{file:t,width:n,height:r}){this.#S+=1;let i=this.#S;this.#y.set(e,t),this.#x.set(e,i),this.#N({type:`file`,id:e,file:t,standIn:{width:n,height:r,serial:i}}),this.#o.note(`video.file`,{proxy:!0,width:n,height:r})}#Z(e){if(!this.#o.getRecording())return;let{width:t,height:n}=Object.values(this.#r.getState().assets??{}).find(t=>t.hash===e)?.info??{};this.#o.note(`video.file`,{proxy:!1,...t!==void 0&&{width:t},...n!==void 0&&{height:n}})}},S8={notices:`_notices_18ynb_1`,notice:`_notice_18ynb_1`,icon:`_icon_18ynb_28`,text:`_text_18ynb_33`};function C8({children:e,actions:t}){return(0,L.jsxs)(`div`,{className:S8.notice,role:`status`,children:[(0,L.jsx)(lf,{size:14,className:S8.icon}),(0,L.jsx)(`span`,{className:S8.text,children:e}),t]})}function Ehe(e){let{t}=F(),{store:n}=ev();return r=>vJ(e.model?.boxes.get(r)?.clip,n?.getState(),t)}function Dhe({onRetry:e}){let{preview:t,timeline:n}=U(),{t:r}=F(),{compositor:i,runScenes:a,scenes:o}=(0,N.useSyncExternalStore)(t.subscribe,t.getSnapshot),s=Ehe(n),c=(e,t)=>SJ(r,s(e),t),l=[...o],u=l.some(([,{state:e}])=>e===`unsupported`),d=l.some(([,{reason:e}])=>e===`no-origin`),f=l.filter(([,{state:e,reason:t}])=>t!==`no-origin`&&(e===`stopped`||e===`retrying`||e===`too-new`)),p=(0,L.jsx)(`button`,{type:`button`,onClick:()=>location.reload(),children:r(`preview.reload`)});return i===`unreachable`?(0,L.jsx)(`div`,{className:S8.notices,children:(0,L.jsx)(C8,{actions:p,children:r(`preview.unreachable`)})}):i===`stopped`?(0,L.jsx)(`div`,{className:S8.notices,children:(0,L.jsx)(C8,{actions:(0,L.jsxs)(L.Fragment,{children:[p,(0,L.jsx)(`button`,{type:`button`,onClick:()=>t.restart(),children:r(`preview.restart`)}),(0,L.jsx)(`button`,{type:`button`,onClick:()=>t.restart({runScenes:!1}),children:r(`preview.restartWithoutScenes`)})]}),children:r(`preview.stopped`)})}):(0,L.jsxs)(`div`,{className:S8.notices,children:[!a&&(0,L.jsx)(C8,{actions:(0,L.jsx)(`button`,{type:`button`,onClick:()=>t.restart({runScenes:!0}),children:r(`preview.restartWithScenes`)}),children:r(`preview.scenesOff`)}),u&&(0,L.jsx)(C8,{children:r(`preview.unsupported`)}),d&&(0,L.jsx)(C8,{actions:p,children:r(`preview.noOrigin`)}),f.map(([t,n])=>(0,L.jsx)(C8,{...n.state===`stopped`&&{actions:(0,L.jsx)(`button`,{type:`button`,onClick:()=>e(t),children:r(`preview.retry`)})},children:c(t,n)},t))]})}var Ohe=4,khe=1024;function Ahe(e,t,n){let r=t.x-e.x,i=t.y-e.y,a=0,o=1,s=[[-r,e.x-n.x],[r,n.x+n.width-e.x],[-i,e.y-n.y],[i,n.y+n.height-e.y]];for(let[e,t]of s){if(e===0){if(t<0)return;continue}let n=t/e;if(e<0?a=Math.max(a,n):o=Math.min(o,n),a>o)return}return[a,o]}var w8=(e,t,n)=>n===0?e:n===1?t:{x:e.x+(t.x-e.x)*n,y:e.y+(t.y-e.y)*n};function jhe(e,t,n){let r=n&&e.length>2?[...e,e[0]]:e,i=[],a;for(let e=1;e<r.length;e+=1){let n=r[e-1],o=r[e],s=Ahe(n,o,t);if(!s){a=void 0;continue}let[c,l]=s,u=w8(n,o,c),d=w8(n,o,l);(!a||c>0)&&(a=[u],i.push(a)),a.push(d),l<1&&(a=void 0)}return i}var Mhe=({x:e,y:t},n)=>e>=n.x&&t>=n.y&&e<=n.x+n.width&&t<=n.y+n.height;function Nhe(e,t,n){let r=[],i=(e,n,i,a,o)=>{if(Math.abs(e)>t)return;let s=Math.sqrt(t*t-e*e);for(let t of[-s,s]){let s=n+t;s<i||s>a||r.push(o?Math.atan2(t,e):Math.atan2(e,t))}};for(let t of[n.x,n.x+n.width])i(t-e.x,e.y,n.y,n.y+n.height,!0);for(let t of[n.y,n.y+n.height])i(t-e.y,e.x,n.x,n.x+n.width,!1);return r}function Phe(e,t,n){if(!(t>0)||!Number.isFinite(t))return[];let r=e.x-t,i=e.y-t,a=e.x+t,o=e.y+t;if(a<n.x||o<n.y||r>n.x+n.width||i>n.y+n.height)return[];if(r>=n.x&&i>=n.y&&a<=n.x+n.width&&o<=n.y+n.height)return`whole`;let s=Nhe(e,t,n).toSorted((e,t)=>e-t);if(s.length===0)return[];let c=[],l=n=>({x:e.x+Math.cos(n)*t,y:e.y+Math.sin(n)*t});for(let[e,r]of s.entries()){let i=s[e+1]??s[0]+Math.PI*2;if(!(i-r>1e-12)||!Mhe(l((r+i)/2),n))continue;let a=Math.min(Math.max(Math.ceil((i-r)*t/Ohe),1),khe),o=[];for(let e=0;e<=a;e+=1)o.push(l(r+(i-r)*e/a));c.push(o)}return c}function T8(e){let t=getComputedStyle(e),n=e=>t.getPropertyValue(`--aq-overlay-${e}`).trim();return{line:n(`line`),fill:n(`fill`),halo:n(`halo`),path:n(`path`),muted:n(`muted`)}}var E8=8,Fhe=7,D8=5,Ihe=7,Lhe=6,O8=10,Rhe=1.5,zhe=4;function k8(e,t,n,r){let i=jhe(n,t,r);if(i.length===0)return!1;e.beginPath();for(let t of i)t.forEach(({x:t,y:n},r)=>{r===0?e.moveTo(t,n):e.lineTo(t,n)});return!0}function Bhe(e,t,n,r){let i=Phe(n,r,t);return i===`whole`?(e.beginPath(),e.arc(n.x,n.y,r,0,Math.PI*2),!0):Vhe(e,i)}function Vhe(e,t){if(t.length===0)return!1;e.beginPath();for(let n of t)n.forEach(({x:t,y:n},r)=>{r===0?e.moveTo(t,n):e.lineTo(t,n)});return!0}var A8=({x:e,y:t},n)=>e>=n.x&&t>=n.y&&e<=n.x+n.width&&t<=n.y+n.height;function j8(e,t,n,r=!1){e.setLineDash([]),e.lineWidth=3,e.strokeStyle=t.halo,e.stroke(),e.setLineDash(r?[4,3]:[]),e.lineWidth=1,e.strokeStyle=n,e.stroke(),e.setLineDash([])}function Hhe(e,t,n,r){switch(r.kind){case`outline`:if(!k8(e,n,r.corners,!0))return;r.style===`target`?j8(e,t,t.line):j8(e,t,r.style===`locked`?t.muted:t.line,!0);return;case`stem`:k8(e,n,[r.from,r.to],!1)&&j8(e,t,t.line);return;case`path`:{k8(e,n,r.points,!1)&&j8(e,t,t.path);let i;e.fillStyle=t.path;for(let t of r.frames)A8(t,n)&&(i&&Math.hypot(t.x-i.x,t.y-i.y)<zhe||(i=t,e.beginPath(),e.arc(t.x,t.y,Rhe,0,Math.PI*2),e.fill()));return}case`bounds`:k8(e,n,r.corners,!0)&&j8(e,t,t.muted,!0);return;case`line`:k8(e,n,r.points,r.closed)&&j8(e,t,t.line);return;case`ring`:Bhe(e,n,r.at,Math.max(r.radius,1))&&j8(e,t,t.line,!0)}}function M8(e,{x:t,y:n},r,i){e.save(),e.translate(t,n),e.rotate(i),e.beginPath(),e.rect(-r/2,-r/2,r,r),e.restore()}function N8(e,t,n,r){e.lineWidth=3,e.strokeStyle=t.halo,e.stroke(),e.fillStyle=n,e.fill(),e.lineWidth=1,e.strokeStyle=r,e.stroke()}function Uhe(e,t,n,r){let{at:i,angle:a}=n,o=r?t.line:t.fill;switch(n.look){case`corner`:case`side`:M8(e,i,n.look===`corner`?E8:Fhe,a),N8(e,t,o,t.line);return;case`rotate`:case`point`:e.beginPath(),e.arc(i.x,i.y,D8,0,Math.PI*2),N8(e,t,o,t.line);return;case`knob`:e.beginPath(),e.arc(i.x,i.y,D8,0,Math.PI*2),N8(e,t,r?t.fill:t.line,t.fill);return;case`scale`:M8(e,i,E8,Math.PI/4),N8(e,t,o,t.line);return;case`key`:M8(e,i,Ihe,0),N8(e,t,r?t.path:t.halo,t.path);return;case`anchor`:{let n=r?t.line:t.fill;e.beginPath(),e.arc(i.x,i.y,Lhe,0,Math.PI*2),e.moveTo(i.x-O8,i.y),e.lineTo(i.x+O8,i.y),e.moveTo(i.x,i.y-O8),e.lineTo(i.x,i.y+O8),j8(e,t,n)}}}function Whe(e,t,{scene:n,hovered:r,dragging:i},a){let{canvas:o}=e;e.setTransform(1,0,0,1,0,0),e.clearRect(0,0,o.width,o.height),e.setTransform(a,0,0,a,0,0),e.lineJoin=`round`;let s={x:-16,y:-16,width:o.width/a+32,height:o.height/a+32};for(let r of n.marks)Hhe(e,t,s,r);for(let a of n.grips)A8(a.at,s)&&Uhe(e,t,a,a.id===(i??r))}var P8={overlay:`_overlay_1dja2_2`,canvas:`_canvas_1dja2_8`,list:`_list_1dja2_14`},F8=10;function I8(e,t){let n=t.getBoundingClientRect();return{x:e.clientX-n.left,y:e.clientY-n.top,shift:e.shiftKey,alt:e.altKey}}function L8(e,t){switch(t.role){case`scale`:return e(`overlay.grip.scale.${t.detail}`);case`key`:return e(`overlay.grip.key`,{time:t.detail});case`object`:return e(`overlay.grip.object`,{object:t.object??``,handle:t.detail});case`rotate`:return e(`overlay.grip.rotate`);case`anchor`:return e(`overlay.grip.anchor`)}}var Ghe=(e,{role:t})=>e(`overlay.usage.${t}`);function Khe(){let{overlay:e,input:t}=U(),{t:n}=F(),r=(0,N.useSyncExternalStore)(e.subscribe,e.getSnapshot),i=(0,N.useRef)(null),a=(0,N.useRef)(null),o=(0,N.useRef)(void 0),s=(0,N.useRef)(void 0),c=()=>{s.current=void 0;let t=a.current,n=t?.getContext(`2d`);t&&n&&(o.current??={theme:T8(t),ratio:devicePixelRatio},Whe(n,o.current.theme,e.getSnapshot(),o.current.ratio))};(0,N.useLayoutEffect)(()=>{let t=i.current,n=a.current;if(!t||!n)return;let r=()=>{let r=t.clientWidth,i=t.clientHeight,a=devicePixelRatio;n.width=Math.round(r*a),n.height=Math.round(i*a),n.style.width=`${r}px`,n.style.height=`${i}px`,o.current={theme:T8(n),ratio:a},e.setViewport(r,i),c()},l=new ResizeObserver(r);l.observe(t),r();let u=()=>{},d=()=>{u();let e=matchMedia(`(resolution: ${devicePixelRatio}dppx)`),t=()=>{r(),d()};e.addEventListener(`change`,t),u=()=>e.removeEventListener(`change`,t)};return d(),()=>{u(),l.disconnect(),e.cancel(),e.setViewport(0,0),s.current!==void 0&&cancelAnimationFrame(s.current)}},[e]),(0,N.useLayoutEffect)(()=>{s.current??=requestAnimationFrame(c)});let l=n=>{if(n.button!==0)return;let{currentTarget:r}=n;r.focus({preventScroll:!0}),r.setPointerCapture(n.pointerId),t.noticePointer(n.pointerType),e.setTouchInput(t.isTouch(n.pointerType)),e.press(I8(n,r))},u=t=>{let{currentTarget:r}=t,i=I8(t,r);if(e.isDragging){t.buttons===0?e.cancel():e.drag(i);return}r.style.cursor=e.hover(i);let{hovered:a,scene:o}=e.getSnapshot(),s=o.grips.find(({id:e})=>e===a);r.title=s?`${L8(n,s)}\n${Ghe(n,s)}`:``},d=t=>{t.key===`Escape`&&e.isDragging&&(t.preventDefault(),t.stopPropagation(),e.cancel())},{scene:f}=r,p=f.target,m=p&&qhe(p.corners);return(0,L.jsxs)(`div`,{ref:i,className:P8.overlay,children:[(0,L.jsx)(`canvas`,{ref:a,className:P8.canvas,tabIndex:-1,"aria-label":n(`overlay.label`),onPointerDown:l,onPointerMove:u,onPointerUp:t=>{t.button===0&&e.release(I8(t,t.currentTarget))},onPointerCancel:()=>e.cancel(),onLostPointerCapture:()=>e.cancel(),onPointerLeave:()=>e.leave(),onKeyDown:d}),(0,L.jsxs)(`ul`,{className:P8.list,"aria-label":n(`overlay.list`),children:[p&&m&&(0,L.jsx)(`li`,{"aria-label":n(`overlay.box`),style:{left:m.x,top:m.y,width:m.width,height:m.height}}),f.grips.map(e=>(0,L.jsx)(`li`,{"aria-label":L8(n,e),style:{left:e.at.x-F8/2,top:e.at.y-F8/2,width:F8,height:F8}},e.id))]})]})}function qhe(e){let t=e.map(({x:e})=>e),n=e.map(({y:e})=>e),r=Math.min(...t),i=Math.min(...n);return{x:r,y:i,width:Math.max(...t)-r,height:Math.max(...n)-i}}var R8={panel:`_panel_74bfj_1`,showing:`_showing_74bfj_9`,waiting:`_waiting_74bfj_21`,stage:`_stage_74bfj_42`,picture:`_picture_74bfj_49`,transport:`_transport_74bfj_59`,buttons:`_buttons_74bfj_71`,time:`_time_74bfj_76`};function Jhe({proxies:e,store:t,quality:n,notify:r,words:i},a){e&&n()!==`full`&&e.offer(a,()=>{if(n()===`full`)return;let o=Object.values(t.getState().assets??{}).find(e=>e.hash!==void 0&&eq(e.hash,a));r(i.text(o?.name??o?.path??``),[{label:i.make,run:()=>e.make(a)}])})}function Yhe({onLink:e}){let t=U(),{timeline:n,properties:r,projects:i,media:a,compositorUrl:o,notifications:s,diagnostics:c}=t,{preview:l,sceneOrigins:u,sceneStage:d,frameRate:f,previewQuality:p,registrations:m}=t,{sceneHandles:h,proxies:g}=t,{t:_}=F(),{store:v}=ev(),{runScenes:y}=(0,N.useSyncExternalStore)(l.subscribe,l.getSnapshot),b=(0,N.useRef)(null);return(0,N.useEffect)(()=>{let t=b.current;if(!t||!v)return;let x=new Set,S=e=>{x.has(e)||s.push(_(`notice.previewCannotDecode`)),x.add(e)},ee=new URL(o,location.href).origin,C=e=>Jhe({proxies:g,store:v,quality:()=>p.getSnapshot().choice,notify:(e,t)=>s.push(e,{stays:!0,actions:t}),words:{text:e=>_(`proxy.offer.text`,{name:e,interpolation:{escapeValue:!1}}),make:_(`proxy.offer.make`)}},e),w=new The(t,n,r,v,i,S,c,a,l,{origins:u,compositor:ee,run:y,...d&&{stage:d}},f,p,m,h,g,C);return e(w),t.src=o,()=>{w.dispose(),e(void 0)}},[o,c,f,a,s,e,l,p,i,r,g,m,y,h,u,d,v,_,n]),(0,L.jsx)(`iframe`,{ref:b,className:R8.picture,title:_(`panel.preview.title`),"data-compositor":`preview`,sandbox:`allow-scripts`,tabIndex:-1})}function Xhe(){let{projectFolders:e}=U(),{t}=F(),n=(0,N.useSyncExternalStore)(e?.subscribeProgress??Zhe,e?.getProgress??Qhe);return n.waiting.length===0?null:(0,L.jsx)(`div`,{className:R8.waiting,role:`status`,children:t(`folder.checking.waiting`,{paths:n.waiting.join(`、`),interpolation:{escapeValue:!1}})})}var Zhe=()=>()=>{},Qhe=()=>R3;function $he(){let{timeline:e,preview:t,trials:n}=U(),{t:r}=F(),{playing:i,model:a}=(0,N.useSyncExternalStore)(e.subscribe,e.getSnapshot),o=(0,N.useSyncExternalStore)(e.subscribeView,()=>e.frame),{compositor:s,generation:c}=(0,N.useSyncExternalStore)(t.subscribe,t.getSnapshot),{count:l,comparing:u}=(0,N.useSyncExternalStore)(n.subscribe,n.getSnapshot),d=(0,N.useRef)(void 0),f=(0,N.useCallback)(e=>{d.current=e},[]);return(0,L.jsxs)(`div`,{className:R8.panel,children:[(0,L.jsxs)(`div`,{className:R8.stage,children:[s!==`stopped`&&s!==`unreachable`&&(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(Yhe,{onLink:f},c),(0,L.jsx)(Khe,{})]}),(0,L.jsx)(Dhe,{onRetry:e=>d.current?.retryScene(e)}),(0,L.jsx)(Xhe,{}),l>0&&(0,L.jsx)(`div`,{className:R8.showing,"data-comparing":u||void 0,role:`status`,children:r(u?`trial.showingSaved`:`trial.showingTrial`)})]}),(0,L.jsxs)(`div`,{className:R8.transport,role:`toolbar`,"aria-label":r(`timeline.transport`),children:[(0,L.jsxs)(`div`,{className:R8.buttons,children:[(0,L.jsx)(k6,{name:r(`timeline.action.previousFrame`),usage:r(`timeline.help.previousFrame`),action:`previousFrame`,icon:Wd,onClick:()=>e.stepFrames(-1)}),(0,L.jsx)(k6,{name:r(i?`timeline.pause`:`timeline.play`),usage:r(`timeline.help.play`),action:`play`,icon:i?gd:Sd,onClick:()=>e.togglePlayback()}),(0,L.jsx)(k6,{name:r(`timeline.action.nextFrame`),usage:r(`timeline.help.nextFrame`),action:`nextFrame`,icon:Kd,onClick:()=>e.stepFrames(1)})]}),a&&(0,L.jsx)(bX,{name:r(`timeline.time`),usage:r(`timeline.timeFormat`),children:(0,L.jsxs)(`span`,{className:R8.time,children:[(0,L.jsx)(`output`,{"aria-live":`off`,children:pq(o,a.rate)}),(0,L.jsxs)(`span`,{children:[`| `,pq(cq(a.duration,a.rate),a.rate)]})]})}),(0,L.jsx)(BX,{})]})]})}var z8={section:`_section_ve6t1_1`,group:`_group_ve6t1_5`,help:`_help_ve6t1_12`,none:`_none_ve6t1_13`,warning:`_warning_ve6t1_14`,card:`_card_ve6t1_23`,head:`_head_ve6t1_33`,name:`_name_ve6t1_39`,kind:`_kind_ve6t1_45`,row:`_row_ve6t1_49`,link:`_link_ve6t1_89`,add:`_add_ve6t1_104`,limit:`_limit_ve6t1_105`};function ege(){let{ai:e,dialogs:t}=U(),{t:n}=F(),r=(0,N.useSyncExternalStore)(e.subscribe,e.getSnapshot),[i,a]=(0,N.useState)(kQ[0]?.id??``),o=async()=>{await t.confirm({title:n(`ai.removeAllKeys`),message:n(`ai.removeAllKeysConfirm`),confirm:n(`ai.removeAllKeys`),danger:!0})&&await e.removeAllKeys()};return(0,L.jsxs)(`section`,{className:z8.section,"aria-label":n(`ai.title`),children:[(0,L.jsx)(`h2`,{className:z8.group,children:n(`ai.title`)}),(0,L.jsx)(`p`,{className:z8.help,children:n(`ai.intro`)}),(0,L.jsxs)(`p`,{className:z8.help,"data-testid":`ai-keys-where`,children:[r.keysWhere?n(`ai.keysWhere`,{where:r.keysWhere}):n(`ai.keysNowhere`),` `,r.keyed.size>0&&(0,L.jsx)(`button`,{type:`button`,className:z8.link,onClick:()=>void o(),children:n(`ai.removeAllKeys`)})]}),(0,L.jsx)(`p`,{className:z8.help,children:n(`ai.noSubscription`)}),r.services.length===0&&(0,L.jsx)(`p`,{className:z8.none,children:n(`ai.none`)}),r.services.map(e=>(0,L.jsx)(tge,{service:e},e.id)),(0,L.jsxs)(`div`,{className:z8.add,children:[(0,L.jsxs)(`label`,{children:[(0,L.jsx)(`span`,{children:n(`ai.addKind`)}),(0,L.jsx)(`select`,{value:i,onChange:e=>a(e.target.value),children:kQ.map(e=>(0,L.jsx)(`option`,{value:e.id,children:e.name},e.id))})]}),(0,L.jsx)(`button`,{type:`button`,onClick:()=>{let t=AQ(i)?.name??i;e.add(i,t)},children:n(`ai.add`)})]}),(0,L.jsxs)(`label`,{className:z8.limit,children:[(0,L.jsx)(`span`,{children:n(`ai.limit`)}),(0,L.jsx)(`input`,{type:`number`,min:jQ.min,max:jQ.max,value:r.maxToolCalls,onChange:t=>e.setMaxToolCalls(Number(t.target.value))}),(0,L.jsx)(`span`,{children:n(`ai.times`)})]}),(0,L.jsx)(`p`,{className:z8.help,children:n(`ai.limitHelp`)})]})}function tge({service:e}){let{ai:t,dialogs:n}=U(),{t:r}=F(),i=(0,N.useSyncExternalStore)(t.subscribe,t.getSnapshot),a=AQ(e.kind),[o,s]=(0,N.useState)(e.baseUrl),[c,l]=(0,N.useState)(``),u=(0,N.useId)(),d=i.keyed.has(e.id),f=i.listings.get(e.id),p=t.modelsFor(e.id),m=o.trim()!==``&&IQ(o)===void 0,h=()=>{let n=IQ(o);n!==void 0&&n!==e.baseUrl&&t.update(e.id,{baseUrl:n})},g=async()=>{c.trim()&&(await t.setKey(e.id,c),l(``))},_=async()=>{await n.confirm({title:r(`ai.remove`),message:r(`ai.removeConfirm`,{name:e.name}),confirm:r(`ai.remove`),danger:!0})&&await t.remove(e.id)};return(0,L.jsxs)(`div`,{className:z8.card,"data-testid":`ai-service`,children:[(0,L.jsxs)(`div`,{className:z8.head,children:[(0,L.jsx)(`input`,{className:z8.name,"aria-label":r(`ai.name`),defaultValue:e.name,onBlur:n=>{let r=n.target.value.trim();r&&r!==e.name&&t.update(e.id,{name:r})}}),(0,L.jsx)(`span`,{className:z8.kind,children:a?.name}),(0,L.jsx)(`button`,{type:`button`,className:z8.link,onClick:()=>void _(),children:r(`ai.remove`)})]}),(0,L.jsxs)(`label`,{className:z8.row,children:[(0,L.jsx)(`span`,{children:r(`ai.baseUrl`)}),(0,L.jsx)(`input`,{value:o,placeholder:`https://`,spellCheck:!1,"aria-invalid":m,onChange:e=>s(e.target.value),onBlur:h,onKeyDown:e=>e.key===`Enter`&&h()})]}),m&&(0,L.jsx)(`p`,{className:z8.warning,children:r(`ai.baseUrlInvalid`)}),(0,L.jsxs)(`label`,{className:z8.row,children:[(0,L.jsx)(`span`,{children:r(`ai.key`)}),(0,L.jsx)(`input`,{type:`password`,autoComplete:`off`,spellCheck:!1,value:c,placeholder:r(d?`ai.keySaved`:`ai.keyPlaceholder`),onChange:e=>l(e.target.value),onBlur:()=>void g(),onKeyDown:e=>e.key===`Enter`&&void g()}),d&&(0,L.jsx)(`button`,{type:`button`,className:z8.link,onClick:()=>void t.removeKey(e.id),children:r(`ai.keyRemove`)})]}),(0,L.jsxs)(`label`,{className:z8.row,children:[(0,L.jsx)(`span`,{children:r(`ai.model`)}),(0,L.jsx)(`input`,{list:u,defaultValue:e.model,placeholder:r(`ai.modelPlaceholder`),spellCheck:!1,onFocus:()=>void t.loadKnown(e.kind),onBlur:n=>{let r=n.target.value.trim();r!==e.model&&t.update(e.id,{model:r})},onKeyDown:e=>e.key===`Enter`&&e.currentTarget.blur()},e.model),(0,L.jsx)(`datalist`,{id:u,children:p.map(e=>(0,L.jsx)(`option`,{value:e.id,children:e.name},e.id))}),(0,L.jsx)(`button`,{type:`button`,className:z8.link,disabled:f?.state===`loading`,onClick:()=>void t.fetchModels(e.id),children:f?.state===`loading`?r(`ai.fetchingModels`):r(`ai.fetchModels`)})]}),f?.state===`ok`&&(0,L.jsx)(`p`,{className:z8.help,children:r(`ai.fetchedModels`,{count:f.models.length})}),f?.state===`failed`&&(0,L.jsxs)(`p`,{className:z8.warning,"data-testid":`ai-models-failed`,children:[r(`chat.failed.${f.failure.kind}`),` `,r(`chat.detail`,{message:f.failure.message})]}),(0,L.jsxs)(`label`,{className:z8.row,children:[(0,L.jsx)(`span`,{children:r(`ai.route`)}),(0,L.jsxs)(`select`,{value:e.route,onChange:n=>t.update(e.id,{route:n.target.value===`relay`?`relay`:`direct`}),children:[(0,L.jsx)(`option`,{value:`direct`,children:r(`ai.routeDirect`)}),(0,L.jsx)(`option`,{value:`relay`,children:r(`ai.routeRelay`)})]})]}),e.route===`relay`&&(0,L.jsx)(`p`,{className:z8.warning,children:r(`ai.routeRelayHint`)}),e.route===`direct`&&a&&!a.tested&&!a.custom&&(0,L.jsx)(`p`,{className:z8.help,children:r(`ai.untested`)})]})}var B8={panel:`_panel_1vdjq_1`,group:`_group_1vdjq_8`,setting:`_setting_1vdjq_15`,help:`_help_1vdjq_39`,pending:`_pending_1vdjq_40`};function nge(){let{trials:e}=U(),{t}=F(),{enabled:n,count:r}=(0,N.useSyncExternalStore)(e.subscribe,e.getSnapshot);return(0,L.jsxs)(`div`,{className:B8.panel,children:[(0,L.jsx)(`h2`,{className:B8.group,children:t(`settings.editing`)}),(0,L.jsxs)(`label`,{className:B8.setting,children:[(0,L.jsx)(`input`,{type:`checkbox`,checked:n,onChange:t=>e.setEnabled(t.target.checked)}),(0,L.jsxs)(`span`,{children:[(0,L.jsx)(`strong`,{children:t(`settings.trial`)}),(0,L.jsx)(`span`,{className:B8.help,children:t(`settings.trialHelp`)}),!n&&r>0&&(0,L.jsx)(`span`,{className:B8.pending,children:t(`settings.trialPending`,{count:r})})]})]}),(0,L.jsx)(ege,{})]})}var V8=[`built-in`,`built-in.transitions`,`built-in.effects`,`project`,`project.media`,`project.scenes`,`project.sounds`,`project.transitions`,`project.effects`,`missing`,`libraries`],H8=e=>e.startsWith(`built-in.`)?`built-in`:e.startsWith(`project.`)?`project`:void 0;function U8(e){if(e.startsWith(`transition:built-in:`))return`built-in.transitions`;if(e.startsWith(`effect:built-in:`))return`built-in.effects`;let t=U$(e);if(t)return t.kind===`asset`?`project.media`:t.kind===`scene`?`project.scenes`:`project.sounds`}var rge=class{#e=new sv;#t={node:`project`,selected:void 0,revealed:0};subscribe=this.#e.subscribe;getSnapshot=()=>this.#t;choose(e){e!==this.#t.node&&this.#n({...this.#t,node:e})}select(e){e!==this.#t.selected&&this.#n({...this.#t,selected:e})}reveal(e,t=U8(e)){return t?(this.#n({node:t,selected:e,revealed:this.#t.revealed+1}),!0):!1}#n(e){this.#t=e,this.#e.emit()}},W8={explorer:`_explorer_15sml_1`,layout:`_layout_15sml_9`,tree:`_tree_15sml_22`,node:`_node_15sml_31`,main:`_main_15sml_88`,note:`_note_15sml_95`,browser:`_browser_15sml_102`},ige=[...L$,...t0,...P$,`transition`,`effect`,`library`];function age(){let e=U(),{explorer:t,timeline:n,resourceHabits:r}=e,{t:i}=F(),a=(0,N.useSyncExternalStore)(t.subscribe,t.getSnapshot),{transitions:o,effects:s,own:c,gone:l}=s0(),u=e=>{let t=e=>c.filter(({data:t})=>t.kind===`project`&&t.item.kind===e);switch(e){case`built-in`:return[...o,...s];case`built-in.transitions`:return o;case`built-in.effects`:return s;case`project`:return c;case`project.media`:return t(`asset`);case`project.scenes`:return t(`scene`);case`project.sounds`:return t(`sound`);case`missing`:return l;case`project.transitions`:case`project.effects`:case`libraries`:return[]}},{node:d}=a,f=(0,N.useMemo)(()=>u(d),[d,c,o,s,l]),p=z0(),m=t=>[[{id:`details`,label:i(`explorer.actions.details`),run:()=>e.openResourcePage(t.id,t.name)}],...p(t)],h=(e=>{if(e===`missing`)return f.length===0?i(`explorer.noMissing`):i(`explorer.notes.missing`);if(e.startsWith(`built-in`))return i(`explorer.notes.built-in`);if(e===`project.transitions`||e===`project.effects`||e===`libraries`)return YX(i,`explorer.notes.${e.replace(`.`,`_`)}`,e)})(d),g=e=>YX(i,`explorer.nodes.${e.replace(`.`,`_`)}`,e);return(0,L.jsx)(`div`,{className:W8.explorer,children:(0,L.jsxs)(`div`,{className:W8.layout,children:[(0,L.jsx)(oge,{node:d,missingCount:l.length,onChoose:e=>t.choose(e),nameOf:g}),(0,L.jsxs)(`div`,{className:W8.main,children:[h&&(0,L.jsx)(`p`,{className:W8.note,children:h}),d!==`libraries`&&d!==`project.transitions`&&d!==`project.effects`&&(0,L.jsx)(`div`,{className:W8.browser,children:(0,L.jsx)(x0,{tab:`explorer`,label:i(`explorer.list`,{node:g(d)}),searchLabel:i(`explorer.search`),resources:f,types:ige,defaultGrouping:`type`,typeName:e=>f0(i,e),unavailable:()=>void 0,Icon:R0,selected:a.selected,revealed:a.revealed,onSelect:e=>t.select(e.id),onActivate:t=>e.openResource(t.id,t.name),menu:m,...d===`missing`&&{empty:i(`explorer.noMissing`)},canDrag:({data:e})=>e.kind===`transition`||e.kind===`effect`||e.kind===`project`&&$3(e.item),onDragStart:({data:e,id:t},n)=>{e.kind===`project`?e6(e.item,n):e.kind===`transition`?P0(e.item,t,n):e.kind===`effect`&&k0(e.item,n)},onDragEnd:({data:e,id:t},i)=>{e.kind===`transition`?F0(n):e.kind===`effect`&&A0(n),i&&r.used(t)}})})]})]})})}function oge({node:e,missingCount:t,onChoose:n,nameOf:r}){let{t:i}=F(),a=(0,N.useRef)(null),o=t=>{let r=V8.indexOf(e),i=t.key===`ArrowDown`?V8[Math.min(r+1,V8.length-1)]:t.key===`ArrowUp`?V8[Math.max(r-1,0)]:t.key===`Home`?V8[0]:t.key===`End`?V8.at(-1):t.key===`ArrowLeft`?H8(e):void 0;i&&(t.preventDefault(),n(i),a.current?.querySelector(`[data-node="${i}"]`)?.focus())},s={"built-in":(0,L.jsx)(cl,{size:14,"aria-hidden":!0}),project:(0,L.jsx)(Eu,{size:14,"aria-hidden":!0}),missing:(0,L.jsx)(lf,{size:14,"aria-hidden":!0}),libraries:(0,L.jsx)(Ku,{size:14,"aria-hidden":!0})};return(0,L.jsx)(`div`,{ref:a,className:W8.tree,role:`tree`,"aria-label":i(`explorer.tree`),onKeyDown:o,children:V8.map(a=>{let o=H8(a)||a===`missing`?2:1,c=a===`missing`&&t>0?i(`explorer.missingCount`,{count:t}):r(a);return(0,L.jsxs)(`div`,{role:`treeitem`,"aria-level":o,"aria-selected":a===e,...(a===`built-in`||a===`project`)&&{"aria-expanded":!0},tabIndex:a===e?0:-1,"data-node":a,"data-missing":a===`missing`&&t>0?``:void 0,className:W8.node,style:{paddingLeft:6+(o-1)*14},onClick:()=>n(a),children:[s[a],(0,L.jsx)(`span`,{children:c})]},a)})})}var sge={placeholder:`_placeholder_xnvoj_1`};function G8(e,t,n,r={}){let i=n;function a(){let{t}=F();return(0,L.jsxs)(`div`,{className:sge.placeholder,children:[(0,L.jsx)(i,{size:32}),(0,L.jsx)(`h2`,{children:t(`panel.${e}.title`)}),(0,L.jsx)(`p`,{children:t(`panel.${e}.hint`)})]})}return{type:e,title:t=>t(`panel.${e}.title`),icon:n,area:t,component:a,planned:!0,...r}}var cge=[{type:`files`,title:e=>e(`panel.files.title`),icon:gu,area:`left`,component:Rue,keys:[`mod+shift+e`]},{type:`explorer`,title:e=>e(`panel.explorer.title`),icon:Eu,area:`left`,component:age},{type:`assets`,title:e=>e(`panel.assets.title`),icon:Bu,area:`left`,component:mpe},{type:`transitions`,title:e=>e(`panel.transitions.title`),icon:il,area:`left`,component:vue},{type:`effects`,title:e=>e(`panel.effects.title`),icon:OQ,area:`left`,component:hue},{type:`preview`,title:e=>e(`panel.preview.title`),icon:fd,area:`center`,component:$he,keepAlive:!0},{type:`code`,title:e=>e(`panel.code.title`),icon:Bl,area:`center`,component:Pue,keepAlive:!0,beside:`preview`},G8(`music`,`center`,Xl),G8(`recording`,`center`,ud),G8(`versions`,`center`,Mu),{type:`keybindings`,title:e=>e(`panel.keybindings.title`),icon:Hu,area:`center`,component:hhe},{type:`settings`,title:e=>e(`panel.settings.title`),icon:Hd,area:`center`,component:nge},{type:`properties`,title:e=>e(`panel.properties.title`),icon:Jd,area:`right`,component:fhe},{type:`chat`,title:e=>e(`panel.chat.title`),icon:cd,area:`right`,component:O$,keepAlive:!0},G8(`history`,`right`,Od),G8(`notes`,`right`,ol),G8(`annotations`,`right`,od),{type:`timeline`,title:e=>e(`panel.timeline.title`),icon:Pd,area:`bottom`,component:tme},{type:`keyframes`,title:e=>e(`panel.keyframes.title`),icon:Wl,area:`bottom`,component:Ime},G8(`differences`,`bottom`,Kl),{type:`problems`,title:e=>e(`panel.problems.title`),icon:lf,area:`bottom`,component:Vue,keys:[`mod+shift+m`]},{type:`exports`,title:e=>e(`panel.exports.title`),icon:Jl,area:`bottom`,component:kme},G8(`terminal`,`bottom`,ef,{keepAlive:!0,keys:["mod+`"]}),G8(`cache`,`bottom`,Iu),{type:`performance`,title:e=>e(`panel.performance.title`),icon:Au,area:`bottom`,component:Tme}],lge=12e4,K8=class extends Error{name=`DownloadFailed`;code;constructor(e,t){super(e),this.code=t}};async function uge(e,t,n){let r=e.connect(),i=[];try{return await new Promise((a,o)=>{let s=setTimeout(()=>o(new K8(`The project took too long to come`)),lge),c=e=>{clearTimeout(s),o(e)};r.closed.then(({code:e})=>c(new K8(`The platform closed the connection`,e))),n.signal?.addEventListener(`abort`,()=>{c(new K8(`Stopped`)),r.close(1e3,``)});let l=new da(ta.state);r.onMessage(e=>{let t=l.take(e);if(t===`more`)return;let n=t&&ga(t);if(!n){c(new K8(`The platform said something that makes no sense`));return}if(n.t===`update`&&i.push(n.payload),n.t!==`synced`)return;let{store:r}=sG.fromUpdates(i);!r||r.isMissingUpdates?c(new K8(`What came is not a whole project`)):(clearTimeout(s),a({state:r.encodeState(),head:n.head}),r.destroy())}),(async()=>{try{await r.opened;let i=await e.links.device();r.send(ca({t:`hello`,v:1,project:t,after:0,device:i,window:n.window,editor:n.editor,payload:new Uint8Array}))}catch{}})()})}finally{r.close(1e3,``)}}var dge={pingMs:15e3,deadMs:1e4,helloMs:3e4,firstRetryMs:1e3,longestRetryMs:3e4,steadyMs:1e4,scanMs:30,noteMs:1e3,answerMs:3e3},fge=()=>({isOnline:()=>typeof navigator>`u`||navigator.onLine!==!1,onWake(e){if(typeof addEventListener>`u`)return()=>{};let t=()=>{document.visibilityState===`visible`&&e()};return addEventListener(`online`,e),document.addEventListener(`visibilitychange`,t),()=>{removeEventListener(`online`,e),document.removeEventListener(`visibilitychange`,t)}},onOffline(e){return typeof addEventListener>`u`?()=>{}:(addEventListener(`offline`,e),()=>removeEventListener(`offline`,e))},setTimeout:(e,t)=>setTimeout(e,t),clearTimeout:e=>clearTimeout(e),now:()=>Date.now(),random:()=>Math.random()}),pge=262144,mge=200,hge=15e3,gge=500,_ge=4194304,vge=new Set([`cloud`,`merged`]),yge=3,bge=e=>e===`user`||e===`folder`||e===`ai`?e:`other`,q8=e=>vge.has(e.source?.kind??`other`),xge=e=>{switch(e){case na.signedOut:return{kind:`signed-out`};case na.forbidden:case na.missing:return{kind:`missing`};case na.outdated:return{kind:`outdated`};case na.protocol:return{kind:`rejected`,reason:`malformed`};case na.tooLarge:return{kind:`rejected`,reason:`too-large`};case na.quota:return{kind:`rejected`,reason:`quota`};default:return}},Sge=e=>typeof e==`object`&&!!e&&(e.kind===`ask`||e.kind===`refill`&&e.vector instanceof Uint8Array||e.kind===`status`&&typeof e.snapshot==`object`),Cge=class{#e;#t;#n;#r;#i;#a;#o;#s;#c;#l;#u;#d=new sv;#f;#p;#m=!1;#h=!1;#g;#_;#v;#y=!1;#b;#x=0;#S=!1;#C;#w;#T=new Set;#E=new Set;#D=0;#O;#k;#A;#j=!1;#M=!1;#N=[];#P;#F=`hello`;#I=0;#L=[];#R=0;#z=1;#B=new Map;#V=!1;#H=!1;#U=0;#W=!1;#G=!1;#K=0;#q;#J;#Y;#X;#Z;#Q;#$;#ee=!1;#te=new Set;#ne;#re=0;#ie=Promise.resolve();constructor(e){let{store:t,journal:n,cloud:r,link:i,timing:a,environment:o}=e;this.#e=t,this.#t=n,this.#n=r,this.#r=i.key,this.#i=i.project,this.#a=e.window,this.#o=e.editor,this.#u=e.create,this.#l=e.onSeq,this.#s={...dge,...a},this.#c=o??fge(),this.#g=i.seq,this.#_=i.digest??``,this.#v=i.seq,this.#C=i.pushed,this.#w=i.pushed,this.#O=i.syncedAt,this.#f=r.line(i.key),this.#p={state:`starting`,problem:void 0,here:!1,syncedAt:i.syncedAt,pending:0,retryAt:void 0,seq:i.seq}}subscribe=this.#d.subscribe;getSnapshot=()=>this.#p;get key(){return this.#r}get project(){return this.#i}start(){if(!(this.#h||this.#m)){if(this.#h=!0,this.#N.push(this.#t.onChange(()=>{this.#Oe(),this.#fe()}),this.#c.onWake(()=>this.#ae()),this.#c.onOffline(()=>this.#q?.({kind:`retry`}))),this.#f){let e=this.#f;this.#N.push(e.listen(t=>{Sge(t)&&(t.kind===`ask`&&this.#p.here?e.post({kind:`status`,snapshot:this.#p}):t.kind===`refill`&&this.#k?this.#t.refill(t.vector).catch(e=>{console.warn(`The log could not get all of the project again`,e)}):t.kind===`status`&&!this.#p.here&&!this.#k&&this.#se(t.snapshot))}))}this.#le().catch(e=>{console.warn(`The project does not sync any more`,e),this.#oe({state:`paused`,problem:{kind:`unsupported`}})})}}resume(){if(this.#m)return;this.#U=0,this.#K=0;let e=this.#ne;this.#ne=void 0,e?.(),this.#ae()}async resyncFromHere(){if(this.#m||!await this.#t.saved())return;let e=await this.#t.entries(this.#C)??[],t=e.at(-1)?.mark;if(t!==void 0){for(let t of e)this.#T.add(t.mark);this.#C=Math.max(this.#C,t),this.#re=Math.max(this.#re,t)}this.#S=!1,this.#G=!1,await this.#Fe().catch(()=>{}),this.resume()}#ae(){for(let e of this.#te)e()}async close(){if(!this.#m){this.#m=!0;for(let e of this.#N.splice(0))e();this.#A?.abort(),this.#q?.({kind:`closed`}),this.#ne?.(),this.#ae(),this.#c.clearTimeout(this.#Z),this.#c.clearTimeout(this.#Q),await this.#ie.catch(()=>{}),await this.#Fe().catch(()=>{}),this.#k?.release(),this.#k=void 0,this.#f?.close(),this.#oe({state:`closed`,here:!1})}}#oe(e){let t={...this.#p,...e},n=this.#p;(n.state!==t.state||n.problem!==t.problem||n.here!==t.here||n.syncedAt!==t.syncedAt||n.pending!==t.pending||n.retryAt!==t.retryAt||n.seq!==t.seq)&&(this.#p=t,t.here&&this.#f?.post({kind:`status`,snapshot:t}),this.#d.emit())}#se(e){e.seq>0&&this.#l?.(e.seq),this.#oe({state:e.state===`closed`?`starting`:e.state,problem:e.problem,here:!1,syncedAt:e.syncedAt,pending:e.pending,retryAt:e.retryAt,seq:e.seq})}#ce(e){let t=this.#ie.then(e);return this.#ie=t.then(()=>void 0,()=>void 0),t}async#le(){for(;!this.#m;){let e=await this.#de();if(!e||this.#m){e?.release();return}if(this.#k=e,this.#oe({here:!0}),await this.#t.readLog().catch(()=>{}),await this.#ue()?await this.#me(e):(this.#oe({state:`paused`,problem:{kind:`unlinked`}}),await new Promise(e=>{this.#ne=e})),e.release(),this.#k=void 0,this.#m)return;this.#oe({here:!1})}}async#ue(){let e;try{e=await this.#n.links.get(this.#r)}catch(e){return console.warn(`How far the project synced could not be read`,e),!0}return!e||e.project!==this.#i?!1:((e.seq!==this.#g||this.#v!==e.seq)&&(this.#g=e.seq,this.#_=e.digest??``,this.#v=e.seq),this.#C=Math.max(this.#C,e.pushed),this.#w=Math.max(this.#w,e.pushed),e.syncedAt!==void 0&&(this.#O=Math.max(this.#O??0,e.syncedAt)),this.#oe({seq:this.#g,syncedAt:this.#O}),!0)}async#de(){let e=this.#n.syncer(this.#r);for(;;){if(this.#m)return;if(this.#j){this.#j=!1;try{return await e.claim({steal:!0})}catch(e){console.warn(`Could not take over syncing the project`,e)}}let t=new AbortController;this.#A=t;let n=!1;try{let r=await e.claim({signal:t.signal,onWaiting:()=>{if(!(n||this.#m||this.#A!==t)&&(this.#oe({here:!1,state:`starting`}),this.#f?.post({kind:`ask`}),this.#t.damaged()>0)){let e=this.#e.stateVector();this.#f?.post({kind:`refill`,vector:e})}}});return n=!0,r}catch(e){if(!t.signal.aborted){if(e instanceof DOMException&&e.name===`AbortError`)return;console.warn(`Could not find out which window syncs the project`,e),await this.#pe(this.#s.longestRetryMs)}}finally{this.#A===t&&(this.#A=void 0)}}}#fe(){this.#k||this.#p.here||this.#M||this.#m||this.#A&&(this.#M=!0,(async()=>{try{if(await this.#pe(this.#s.scanMs),this.#k||this.#m||!this.#A||await this.#n.syncer(this.#r).answers(this.#s.answerMs)||this.#k||this.#m)return;this.#j=!0,this.#A?.abort()}finally{this.#M=!1}})())}#pe(e){return new Promise(t=>{let n=()=>{this.#te.delete(n),this.#c.clearTimeout(r),t()},r=this.#c.setTimeout(n,e);this.#te.add(n)})}async#me(e){let t={lost:!1};if(e.lost.then(()=>{t.lost=!0,this.#q?.({kind:`closed`}),this.#ae(),this.#ne?.()}),!this.#t.entries())this.#oe({state:`paused`,problem:{kind:`unsupported`}}),await new Promise(e=>{this.#ne=e});else for(this.#Oe();!this.#m&&!t.lost;){let e=this.#c.now(),n=await this.#he();if(this.#m||t.lost||n.kind===`closed`)return;if(n.kind===`pause`){this.#oe({state:`paused`,problem:n.problem,retryAt:void 0}),await new Promise(e=>{this.#ne=e}),this.#oe({problem:void 0});continue}if(n.kind===`resync`){if(this.#U+=1,this.#U>yge){this.#oe({state:`paused`,problem:{kind:`diverged`},retryAt:void 0}),await new Promise(e=>{this.#ne=e}),this.#oe({problem:void 0});continue}this.#W=!0}let r=this.#c.now()-e;if(this.#K=r>=this.#s.steadyMs?1:this.#K+1,n.kind===`resync`)continue;let i=this.#c.isOnline(),a=i?Math.min(this.#s.longestRetryMs,this.#s.firstRetryMs*2**Math.max(0,this.#K-1)):this.#s.longestRetryMs,o=a/2+this.#c.random()*a/2+(n.later?this.#c.random()*hge:0);this.#oe({state:i?`reconnecting`:`offline`,retryAt:this.#c.now()+o}),await this.#pe(o)}}async#he(){let e=this.#n.connect();this.#P=e,this.#F=`hello`,this.#be=1/0,this.#L=[],this.#R=0,this.#B.clear(),this.#E.clear(),this.#V=!1,this.#H=!1,this.#p.state!==`online`&&this.#oe({state:this.#K===0?`connecting`:`reconnecting`,retryAt:void 0});let t=()=>{},n=new Promise(e=>{t=e});this.#q=t;let r=()=>this.#P===e,i=new da(ta.state);e.onMessage(e=>{if(!r())return;this.#ve();let n=i.take(e);if(n===`more`)return;let a=n&&ga(n);a?this.#ce(async()=>{r()&&await this.#Se(a)}).catch(e=>{console.warn(`A message of the platform could not be taken in`,e),t({kind:`retry`})}):t(i.tooLarge?{kind:`pause`,problem:{kind:`rejected`,reason:`too-large`}}:{kind:`retry`})}),e.closed.then(({code:e})=>{let n=xge(e);t(n?{kind:`pause`,problem:n}:e===na.unavailable||e===na.tooMany?{kind:`retry`,later:!0}:{kind:`retry`})});try{await e.opened}catch{}if(r()&&!this.#m){let n=()=>{this.#xe()?this.#X=this.#c.setTimeout(n,this.#s.helloMs):t({kind:`retry`})};this.#X=this.#c.setTimeout(n,this.#s.helloMs),await this.#ce(()=>this.#_e(e)).catch(()=>{t({kind:`retry`})}),this.#ve()}let a=await n;return this.#q=void 0,this.#P=void 0,this.#F=`hello`,this.#c.clearTimeout(this.#X),this.#c.clearTimeout(this.#J),this.#c.clearTimeout(this.#Y),e.close(1e3,``),this.#B.clear(),this.#E.clear(),await this.#Fe().catch(()=>{}),a}#ge(e){let t=this.#P;if(t)for(let n of la(e))t.send(n)}async#_e(e){let t=await this.#n.links.device();if(this.#P!==e)return;let n=this.#u,r=n?this.#e.encodeWhole():new Uint8Array;if(r.length>ta.state){this.#q?.({kind:`pause`,problem:{kind:`rejected`,reason:`too-large`}});return}let i=this.#W?0:this.#g;this.#W=!1,this.#x=i,this.#ge({t:`hello`,v:1,project:this.#i,after:i,...i>0&&{digest:this.#_},device:t,window:this.#a,editor:this.#o,...n&&{create:n},payload:r})}#ve(){this.#c.clearTimeout(this.#J),this.#c.clearTimeout(this.#Y),this.#J=this.#c.setTimeout(()=>this.#ye(),this.#s.pingMs)}#ye(){if(this.#xe()){this.#J=this.#c.setTimeout(()=>this.#ye(),this.#s.pingMs);return}this.#ge({t:`ping`});let e=()=>{this.#xe()?this.#Y=this.#c.setTimeout(e,this.#s.deadMs):this.#q?.({kind:`retry`})};this.#Y=this.#c.setTimeout(e,this.#s.deadMs)}#be=1/0;#xe(){let e=this.#P?.buffered?.()??0,t=e>0&&e<this.#be;return this.#be=e>0?e:1/0,t}async#Se(e){switch(e.t){case`welcome`:this.#c.clearTimeout(this.#X),this.#F=`catching-up`,this.#I=e.head,this.#u=void 0,e.reset&&(this.#g=0,this.#_=``,this.#C=0,this.#re=0,this.#T.clear(),this.#E.clear(),this.#y=!0);return;case`update`:if(this.#F===`catching-up`){this.#L.push(e),this.#R+=e.payload.length,(this.#L.length>=gge||this.#R>=_ge)&&this.#Ce();return}if(!this.#e.applyCloud([e.payload],e.seq)){this.#q?.({kind:`resync`});return}this.#we(e.seq,e.digest),this.#Pe(),this.#F===`ready`&&this.#Te()&&this.#q?.({kind:`resync`});return;case`synced`:if(!this.#Ce())return;if(this.#F=`ready`,this.#we(e.head,e.digest),this.#e.isMissingUpdates){if(this.#x===0||this.#e.missingKey===this.#b)this.#b=this.#e.missingKey,this.#e.catchUp([]);else{this.#q?.({kind:`resync`});return}}this.#oe({state:`online`,retryAt:void 0,problem:void 0}),this.#Pe(),this.#G||await this.#ke(),this.#Ee();return;case`ack`:{let t=this.#B.get(e.id);if(!t)return;this.#B.delete(e.id);for(let e of t.marks)this.#E.delete(e),this.#T.add(e);this.#we(e.seq,e.digest),this.#Pe(),this.#B.size===0&&(this.#G&&this.#V&&(this.#G=!1,this.#U=0),this.#Oe(),this.#Ee());return}case`reject`:{let t=this.#B.get(e.id);this.#B.delete(e.id),e.reason===`too-large`&&(t?.marks.length??0)>1?(this.#S=!0,this.#q?.({kind:`retry`})):e.reason===`incomplete`?this.#G?this.#q?.({kind:`resync`}):(this.#G=!0,this.#q?.({kind:`retry`})):e.retry?this.#q?.({kind:`retry`}):this.#q?.({kind:`pause`,problem:{kind:`rejected`,reason:e.reason}});return}case`checked`:{this.#H=!1;let t=_a(e.payload);if(!t){this.#q?.({kind:`retry`});return}if(gW(t.stateVector,this.#e.stateVector())||!this.#e.applyCloud([t.deletions],e.head)){this.#q?.({kind:`resync`});return}this.#V=!0,(gW(this.#e.stateVector(),t.stateVector)||!AW(t.deletions,this.#e.deletions()))&&await this.#t.saved()&&this.#F===`ready`?this.#Ne(this.#e.diffSince(t.stateVector),{kind:`repair`,base:e.head,marks:[],behind:!0}):this.#G?(this.#G=!1,await this.#ke()):(this.#U=0,this.#De());return}case`pong`:return}}#Ce(){let e=this.#L,t=e.at(-1);return this.#L=[],this.#R=0,t?this.#e.applyCloud(e.map(e=>e.payload),t.seq)?(this.#we(t.seq,t.digest),this.#Pe(),!0):(this.#q?.({kind:`resync`}),!1):!0}#we(e,t){e<this.#g||(this.#g=e,this.#_=t,this.#l?.(this.#g),this.#oe({seq:this.#g}))}#Te(){return this.#e.isMissingUpdates&&this.#e.missingKey!==this.#b}#Ee(){this.#F!==`ready`||this.#V||this.#H||this.#B.size>0||(this.#H=!0,this.#ge({t:`check`}))}#De(){this.#F!==`ready`||!this.#V||this.#B.size>0||this.#D>0||(this.#O=this.#c.now(),this.#oe({syncedAt:this.#O}),this.#Pe())}#Oe(){if(this.#m)return;this.#c.clearTimeout(this.#Z);let e=this.#F===`ready`?this.#s.scanMs:this.#s.noteMs;this.#Z=this.#c.setTimeout(()=>{this.#ce(()=>this.#ke()).catch(e=>{console.warn(`The log of the project could not be read for syncing`,e)})},e)}async#ke(){return this.#$?(this.#ee=!0,this.#$):(this.#$=(async()=>{try{do this.#ee=!1,await this.#Ae();while(this.#ee&&!this.#m)}finally{this.#$=void 0}})(),this.#$)}async#Ae(){if(!this.#k)return;if(this.#F!==`ready`&&this.#re>this.#C){let e=await this.#t.entries(this.#re)??[];this.#re=e.at(-1)?.mark??this.#re,this.#D+=e.filter(e=>!q8(e)).length,this.#oe({pending:this.#D});return}let e=await this.#t.entries(this.#C)??[];this.#re=Math.max(this.#re,e.at(-1)?.mark??0);let t=this.#C,n=!0,r=[];for(let i of e){let e=q8(i)||this.#T.has(i.mark);e&&n?(t=i.mark,this.#T.delete(i.mark)):(n=!1,e||r.push(i))}if(this.#C=Math.max(this.#C,t),this.#D=r.length,this.#oe({pending:r.length}),this.#C>this.#w&&this.#Pe(),this.#F!==`ready`||this.#G)return;let i=r.filter(e=>!this.#E.has(e.mark));for(let e of this.#je(i))this.#Me(e);r.length===0&&this.#B.size===0&&this.#De()}*#je(e){let t=[],n=0,r=(e,t)=>e.source?.kind===t.source?.kind&&e.source?.window===t.source?.window&&e.source?.seq===t.source?.seq;for(let i of e){let e=t[0],a=this.#S||t.length>=mge||n+i.update.length>pge;e&&(!r(e,i)||a)&&(yield t,t=[],n=0),t.push(i),n+=i.update.length}t.length>0&&(yield t)}#Me(e){let t=e[0];if(!t)return;let n=e.filter(e=>vW(e.update)===`malformed`||!this.#e.hasAllOf(e.update));if(n.length>0){console.warn(`${n.length} changes in the log do not go to the platform`);for(let e of n)this.#T.add(e.mark);let t=e.filter(e=>!n.includes(e));t.length>0&&this.#Me(t);return}let r=e.length===1?t.update:eG(e.map(e=>e.update)),i=t.source?.seq??0;this.#Ne(r,{kind:bge(t.source?.kind??`other`),base:i,at:t.source?.at,window:t.source?.window,marks:e.map(e=>e.mark),behind:i<this.#I})}#Ne(e,{kind:t,base:n,at:r,window:i,marks:a,behind:o}){if(e.length>ta.update){this.#q?.({kind:`pause`,problem:{kind:`rejected`,reason:`too-large`}});return}let s=this.#z++;this.#B.set(s,{marks:a});for(let e of a)this.#E.add(e);this.#ge({t:`push`,id:s,kind:t,base:n,at:r??this.#c.now(),window:i??this.#a,behind:o,payload:e})}#Pe(){this.#Q!==void 0||this.#m||(this.#Q=this.#c.setTimeout(()=>{this.#Q=void 0,this.#ce(()=>this.#Fe()).catch(e=>{console.warn(`How far the project synced could not be noted down`,e)})},this.#s.noteMs))}async#Fe(){let e=this.#g,t=this.#_,n=this.#C,r=this.#O,i=this.#y;if(!i&&e===this.#v&&n===this.#w)return;let a=e>this.#v||i?!this.#Te()&&await this.#t.saved():!0;a||this.#Pe();let o;if(i){if(!a||this.#F!==`ready`)return;o=await this.#n.links.reset(this.#r,this.#i,{seq:e,digest:t,pushed:n}),o&&(this.#y=!1,this.#v=e,this.#w=n)}else{let i={...a&&e>this.#v&&{seq:e,digest:t},...n>this.#w&&{pushed:n},...r!==void 0&&{syncedAt:r}};if(Object.keys(i).length===0)return;o=await this.#n.links.update(this.#r,this.#i,i),o&&i.seq!==void 0&&(this.#v=i.seq),o&&i.pushed!==void 0&&(this.#w=i.pushed)}o||this.#q?.({kind:`pause`,problem:{kind:`unlinked`}})}},J8=`.animaquill/cloud.json`,wge=`.animaquill/.gitignore`,Tge=e=>`${JSON.stringify({version:1,platform:e.platform,project:e.project},null,2)}\n`;function Ege(e){try{let t=JSON.parse(e);return typeof t.platform!=`string`||typeof t.project!=`string`||!/^[A-Za-z0-9_-]{1,64}$/.test(t.project)?void 0:{platform:t.platform,project:t.project}}catch{return}}var Y8=(e,...t)=>e instanceof ba&&t.includes(e.reason),X8={kind:`none`},Dge=class{#e;#t=new sv;#n=X8;#r;#i;#a=0;#o=Promise.resolve();#s=new Set;#c;constructor(e){this.#e=e,e.account?.subscribe(()=>{let t=this.session;e.account?.getSnapshot().status===`signedIn`&&t&&t.getSnapshot().problem?.kind===`signed-out`&&t.resume()})}subscribe=this.#t.subscribe;getSnapshot=()=>this.#n;get platform(){return this.#e.cloud.platform}get session(){return this.#n.kind===`linked`?this.#n.session:void 0}#l(e){this.#n=e,this.#t.emit()}follow(){let{session:e}=this.#e,t=e.key,n=e.store;if(t===this.#r&&n===this.#i&&!this.#u())return this.#o;let r=++this.#a;return this.#o=this.#o.then(()=>this.#h(r)).catch(e=>{console.warn(`Whether the project syncs could not be found out`,e)}),this.#o}#u(){let e=this.#r;return e!==void 0&&this.#n.kind===`none`&&this.#e.isFolder(e)&&this.#d!==e&&this.#e.folderOf(e)!==void 0}#d;#f;#p(e){if(this.#f?.stop(),this.#f?.line.close(),this.#f=void 0,e===void 0)return;let t=this.#e.cloud.line(e);if(!t)return;let n=t.listen(t=>{t?.kind===`link`&&this.#e.session.key===e&&this.#b().then(()=>(this.#r=void 0,this.#i=void 0,this.follow()))});this.#f={line:t,stop:n}}#m(){this.#f?.line.post({kind:`link`})}async#h(e){if(e!==this.#a)return;let{session:t,cloud:n}=this.#e,r=t.key,i=t.store;if((r!==this.#r||i!==this.#i)&&(await this.#b(),this.#r=r,this.#i=i,this.#d=void 0,this.#p(r)),!r||!i)return;let a=this.#e.isFolder(r),o=this.#e.folderOf(r);if(a&&!o||(o&&(this.#d=r),this.#n.kind===`linked`))return;let s=await n.links.get(r).catch(()=>void 0),c=o?await this.#g(o):void 0;if(e===this.#a){if(s&&s.platform===n.platform)o&&(c?.project!==s.project||c.platform!==n.platform)&&await this.#_(o,s).catch(e=>{console.warn(`The folder could not say which project of the platform it is`,e)}),this.#v(s,i),s.creating&&this.#S(s,{quietly:!0});else if(c&&c.platform===n.platform){let e=(await n.links.withProject(n.platform,c.project)).some(e=>e.key!==r)?`copy`:`foreign`;this.#l({kind:`detached`,project:c.project,reason:e}),this.#s.has(r)||(this.#s.add(r),this.resolveDetached())}else this.#l(X8)}}async#g(e){try{return Ege(await e.readText(J8))}catch(e){Y8(e,`missing`,`not-text`,`refused`)||console.warn(`What the folder says about the platform could not be read`,e);return}}async#_(e,t){try{await e.write(wge,`*
214
214
  `,{expected:`absent`})}catch(e){if(!Y8(e,`changed`))throw e}await e.write(J8,Tge(t))}#v(e,t){let{cloud:n,session:r,window:i,editor:a,timing:o,environment:s}=this.#e,{name:c,id:l}=t.getState().manifest,u=e.creating?{name:c,projectId:l}:void 0,d=new Cge({store:t,journal:r.journal,cloud:n,link:e,window:i,editor:a,onSeq:e=>{r.store===t&&(r.cloudSeq=e)},...u&&{create:u},...o&&{timing:o},...s&&{environment:s}});r.cloudSeq=e.seq,this.#c=d.subscribe(()=>{this.#t.emit(),d.getSnapshot().problem?.kind===`unlinked`&&this.#y(d)}),this.#l({kind:`linked`,session:d,link:e}),d.start()}async#y(e){this.session===e&&(await this.#b(),this.#r=void 0,this.#i=void 0,await this.follow())}async#b(){let e=this.session;this.#c?.(),this.#c=void 0,this.#l(X8),await e?.close()}async close(){this.#a+=1,await this.#b(),this.#r=void 0,this.#i=void 0,this.#p(void 0)}get canConnect(){return this.#e.session.store!==void 0&&this.#n.kind!==`linked`}get canDisconnect(){return this.#n.kind===`linked`}async#x(e){let{account:t,dialogs:n,t:r}=this.#e;return t?(await t.refresh(),t.getSnapshot().status===`signedIn`||(await n.choose({title:e,message:r(`cloud.signInFirst`),choices:[{id:`signIn`,label:r(`account.signIn`),kind:`primary`}]})===`signIn`&&await this.#e.signIn(),!1)):!1}async connect({replace:e=!1}={}){let{session:t,cloud:n,dialogs:r,notifications:i,t:a}=this.#e,o=t.key,s=t.store;if(!o||!s)return;if(this.#n.kind===`linked`){i.push(a(`cloud.alreadyConnected`));return}if(!await this.#x(a(`cloud.connectTitle`,{name:s.getState().manifest.name})))return;let c={name:s.getState().manifest.name,interpolation:{escapeValue:!1}};if(!await r.confirm({title:a(e?`cloud.newTitle`:`cloud.connectTitle`,c),message:a(`cloud.connectMessage`),confirm:a(e?`cloud.newConfirm`:`cloud.connectConfirm`)})||t.store!==s)return;if(!await t.trySave()){i.push(a(`cloud.notSaved`));return}await t.readLog();let l=await t.journal.entries();if(!l){i.push(a(`cloud.unsupported`));return}let u=this.#e.isFolder(o)?this.#e.folderOf(o):void 0;if(this.#e.isFolder(o)&&!u){i.push(a(`cloud.folderNotReady`));return}let d={key:o,platform:n.platform,project:va(),seq:0,pushed:l.at(-1)?.mark??0,linkedAt:Date.now(),creating:!0};try{await n.links.put(d)}catch(e){console.warn(`The link to the platform could not be kept`,e),i.push(a(`cloud.connectFailed`));return}await this.#b(),this.#a+=1,this.#r=o,this.#i=s,u&&(this.#d=o,await this.#_(u,d).catch(e=>{console.warn(`The folder could not say which project of the platform it is`,e)})),this.#v(d,s),this.#m(),this.#S(d)}async#S(e,{quietly:t=!1}={}){let{cloud:n,notifications:r,t:i}=this.#e,a=this.session;a&&(await new Promise(e=>{let t=()=>{let t=a.getSnapshot();(t.state===`online`||t.state===`paused`||t.state===`closed`)&&e(t)},n=a.subscribe(t);t(),Promise.resolve().then(()=>{a.getSnapshot().state===`closed`&&n()})})).state===`online`&&(await n.links.update(e.key,e.project,{made:!0}).catch(()=>!1),t||r.push(i(`cloud.connected`)))}async resolveDetached(){let{dialogs:e,t,session:n}=this.#e,r=this.#n,i=n.key;if(r.kind!==`detached`||!i)return;let a=await e.choose({title:t(r.reason===`copy`?`cloud.copyTitle`:`cloud.foreignTitle`),message:t(r.reason===`copy`?`cloud.copyMessage`:`cloud.foreignMessage`),choices:[{id:`disconnect`,label:t(`cloud.letGo`)},{id:`new`,label:t(`cloud.makeNew`),kind:`primary`}]});n.key===i&&this.#n===r&&(a===`new`?await this.connect({replace:!0}):a===`disconnect`&&await this.#C(i))}async#C(e){let{notifications:t,t:n}=this.#e,r=this.#e.folderOf(e);if(r)try{await r.remove(J8),this.#l(X8),t.push(n(`cloud.letGoDone`))}catch(e){console.warn(`The folder could not let go of the platform`,e),t.push(n(`cloud.letGoFailed`))}}async disconnect(){let{session:e,dialogs:t,t:n}=this.#e,r=e.key,i=this.#n;r&&i.kind===`linked`&&await t.confirm({title:n(`cloud.disconnectTitle`),message:n(i.session.getSnapshot().pending>0?`cloud.disconnectPending`:`cloud.disconnectMessage`),confirm:n(`cloud.disconnect`),danger:!0})&&this.#n===i&&await this.#w(r)}async resolveStuck(){let{dialogs:e,t,session:n}=this.#e,r=n.key,i=this.#n;if(!r||i.kind!==`linked`)return;let a=await e.choose({title:t(`cloud.stuckTitle`),message:t(`cloud.stuckMessage`),choices:[{id:`disconnect`,label:t(`cloud.letGo`)},{id:`new`,label:t(`cloud.makeNew`)},{id:`resync`,label:t(`cloud.resync`),kind:`primary`}]});n.key===r&&this.#n===i&&(a===`resync`&&await i.session.resyncFromHere(),(a===`disconnect`||a===`new`)&&await this.#w(r),a===`new`&&this.getSnapshot().kind===`none`&&await this.connect({replace:!0}))}async#w(e){let{cloud:t,notifications:n,t:r}=this.#e;await this.#b();try{await t.links.remove(e)}catch(e){console.warn(`The link to the platform could not be taken away`,e),n.push(r(`cloud.disconnectFailed`)),this.follow();return}await(this.#e.isFolder(e)?this.#e.folderOf(e):void 0)?.remove(J8).catch(e=>{console.warn(`The folder still says which project of the platform it was`,e)}),this.#l(X8),this.#m(),n.push(r(`cloud.disconnected`))}async forget(e){await this.#e.cloud.links.remove(e).catch(e=>{console.warn(`The link of a project that is gone stays for now`,e)})}async openFromCloud(){let{cloud:e,dialogs:t,notifications:n,t:r,projects:i}=this.#e;if(!await this.#x(r(`cloud.openTitle`)))return;let a;try{a=await e.list()}catch(e){console.warn(`The projects on the platform could not be listed`,e),n.push(r(`cloud.listFailed`));return}if(a.length===0){n.push(r(`cloud.nothingThere`));return}let o=(await t.form({title:r(`cloud.openTitle`),notes:[r(`cloud.openNote`)],fields:[{id:`project`,label:r(`cloud.openField`),options:a.map(e=>({id:e.id,label:e.name})),value:a[0]?.id??``}],confirm:r(`cloud.openConfirm`)}))?.project;if(!o)return;let s=t.progress({title:r(`cloud.downloading`),cancel:r(`dialog.cancel`),stopping:r(`transfer.stopping`)}),c;try{c=await uge(e,o,{window:this.#e.window,editor:this.#e.editor,signal:s.signal})}catch(e){if(s.signal.aborted)return;console.warn(`The project could not come from the platform`,e),n.push(r(e instanceof K8&&e.code===na.outdated?`cloud.problem.outdated`:`cloud.downloadFailed`));return}finally{s.close()}if(s.signal.aborted)return;let{store:l}=sG.fromUpdates([c.state]);if(!l){n.push(r(`cloud.downloadFailed`));return}let{id:u,name:d}=l.getState().manifest;l.destroy();let f=(await i.list().catch(()=>[])).find(e=>e.id===u);if(f)(await e.links.get(u).catch(()=>void 0))?.project===o?await this.#e.openProject(u):n.push(r(`cloud.alreadyHere`,{name:f.name}));else{try{await i.create({id:u,name:d},c.state);let t=await i.open(u),n=(await t.entries?.())?.at(-1)?.mark??0;t.close(),await e.links.put({key:u,platform:e.platform,project:o,seq:c.head,pushed:n,linkedAt:Date.now()})}catch(e){console.warn(`The project from the platform could not be kept here`,e),n.push(r(`cloud.downloadFailed`));return}await this.#e.openProject(u)}}},Oge=500,kge=40,Age=()=>`chat-${Date.now().toString(36)}-${crypto.getRandomValues(new Uint32Array(1))[0]?.toString(36)}`,jge=class{#e;#t;#n=new sv;#r={conversation:void 0,id:void 0,saved:[],hold:void 0,undoTick:0};#i;#a;#o;#s;constructor(e){this.#e=e,this.#t=e.chats??er(),e.subscribeProject(()=>this.#l()),this.#l()}subscribe=this.#n.subscribe;getSnapshot=()=>this.#r;#c(e){this.#r={...this.#r,...e},this.#n.emit()}#l(){let e=this.#e.project();(e?.store!==this.#i?.store||e?.key!==this.#i?.key)&&(this.#r.conversation?.stop(),this.flush(),this.#i=e,this.#d([],void 0),e&&this.#u(e.key))}async#u(e){try{let t=await this.#t.list(e);if(this.#i?.key!==e)return;this.#c({saved:t});let n=t[0];n&&this.#r.conversation?.getSnapshot().entries.length===0&&await this.open(n.id)}catch(e){console.warn(`Conversations could not be read`,e)}}#d(e,t){this.#a?.();let n=new WQ({entries:e,system:YQ,tools:e=>this.#f(e)}),r=t??Age(),i=n.getSnapshot().entries;this.#a=n.subscribe(()=>{let e=n.getSnapshot().entries;e!==i&&(i=e,this.#p(r,e))}),this.#c({conversation:n,id:r,hold:void 0})}#f(e){let t=this.#i,n=t?.store.revision;return g$({store:()=>t&&this.#e.project()?.store===t.store?t.store:void 0,task:e,selection:this.#e.selection,seen:()=>n,saw:e=>n=e})}#p(e,t){let n=this.#i?.key;if(n===void 0||t.length===0)return;let r=t.find(e=>e.role===`user`),i=(r?.role===`user`?r.text:``).trim().slice(0,kge);this.#s=async()=>{let r={id:e,project:n,title:i,updatedAt:Date.now(),entries:t};try{if(await this.#t.save(r),this.#i?.key!==n)return;let t=this.#r.saved.filter(t=>t.id!==e),{entries:i,...a}=r;this.#c({saved:[a,...t]})}catch(e){console.warn(`The conversation could not be kept`,e)}},clearTimeout(this.#o),this.#o=setTimeout(()=>void this.flush(),Oge)}async flush(){clearTimeout(this.#o);let e=this.#s;this.#s=void 0,await e?.()}get running(){return this.#r.conversation?.running===!0}newConversation(){this.running||(this.flush(),this.#d([],void 0))}async open(e){let t=this.#i?.key;if(t===void 0||this.running)return;await this.flush();let n=await this.#t.load(t,e).catch(e=>{console.warn(`A conversation could not be read`,e)});if(!n||this.#i?.key!==t)return;let r=n.entries.map(JQ).filter(e=>e!==void 0);this.#d(r,e)}async remove(e){let t=this.#i?.key;if(t!==void 0){if(e===this.#r.id){if(this.running)return;this.#s=void 0,this.#d([],void 0)}await this.#t.remove(t,e).catch(e=>{console.warn(`A conversation could not be taken away`,e)}),this.#c({saved:this.#r.saved.filter(t=>t.id!==e)})}}async#m(){let e=this.#e.fake?.();if(e)return{endpoint:e,key:async()=>void 0};let{ai:t}=this.#e,n=t.current,r=n&&AQ(n.kind);return!n||!r?`noService`:n.model?n.baseUrl?n.route===`relay`?`relay`:{endpoint:{service:n.kind,protocol:r.protocol,baseUrl:n.baseUrl,model:n.model,catalog:r.catalog},key:()=>t.keyOf(n.id)}:`badUrl`:`noModel`}async send(e){let t=this.#r.conversation;if(!t||t.running||!e.trim())return;if(!this.#i){this.#c({hold:`noProject`});return}let n=await this.#m();if(typeof n==`string`){this.#c({hold:n});return}this.#c({hold:void 0});let r=this.#e.ai.getSnapshot().maxToolCalls;return t.send(e,{...n,maxToolCalls:r})}stop(){this.#r.conversation?.stop()}undoState(e){let t=this.#i?.store;if(t){if(t.canUndoOrigin(UN(e)))return`undo`;if(t.canRedoOrigin(UN(e)))return`redo`}}undoTask(e){let t=this.#i?.store;t&&(this.#e.undone(t.undoOrigin(UN(e))),this.#c({undoTick:this.#r.undoTick+1}))}redoTask(e){let t=this.#i?.store;t&&(this.#e.undone(t.redoOrigin(UN(e))),this.#c({undoTick:this.#r.undoTick+1}))}},Z8=`ai`,Mge=()=>`service-${[...crypto.getRandomValues(new Uint32Array(2))].map(e=>e.toString(36)).join(``)}`,Nge=class{#e;#t;#n;#r=new sv;#i;#a=new Map;#o=new Set;constructor(e,t,n){this.#e=e,this.#t=t??$n(),this.#n=n,this.#i={...MQ,keyed:new Set,listings:new Map,known:new Map,keysWhere:this.#t.where}}subscribe=this.#r.subscribe;getSnapshot=()=>this.#i;async load(){let e=await xX(this.#e,Z8,FQ);e.kind===`ok`&&this.#s(e.value),this.#e.listen(Z8,e=>{let t=FQ(e);t&&this.#s(t),this.#c()}),await this.#c()}get knownKeys(){return this.#o}serviceOf(e){return this.#i.services.find(t=>t.id===e)}get current(){return this.serviceOf(this.#i.current)}#s(e){this.#i={...this.#i,...e},this.#r.emit()}async#c(){try{let e=new Set(await this.#t.list());this.#i={...this.#i,keyed:e},this.#r.emit()}catch(e){console.warn(`Which services have a key could not be read`,e)}}#l(e){this.#s(e);let{services:t,current:n,maxToolCalls:r}=e;this.#e.save(Z8,{services:t,current:n,maxToolCalls:r}).catch(e=>{console.warn(`The AI services could not be saved`,e),this.#n.saveFailed()})}#u(){let{services:e,current:t,maxToolCalls:n}=this.#i;return{services:e,current:t,maxToolCalls:n}}add(e,t){let n=AQ(e);if(!n)return;let r=Mge(),i={id:r,kind:e,name:t,baseUrl:n.baseUrl,model:``,route:n.route},a=this.#u();return this.#l({...a,services:[...a.services,i],current:a.current??r}),r}update(e,t){let n=this.#u(),r=n.services.map(n=>n.id===e?{...n,...t}:n);this.#l({...n,services:r})}async remove(e){let t=this.#u(),n=t.services.filter(t=>t.id!==e),r=t.current===e?n[0]?.id:t.current;this.#l({...t,services:n,current:r}),await this.removeKey(e)}choose(e){this.serviceOf(e)&&this.#l({...this.#u(),current:e})}setMaxToolCalls(e){if(!Number.isInteger(e))return;let t=Math.min(jQ.max,Math.max(jQ.min,e));this.#l({...this.#u(),maxToolCalls:t})}async keyOf(e){try{let t=await this.#t.read(e);return this.#f(e,t),t}catch(e){console.warn(`A key could not be read`,e),this.#n.keyFailed();return}}async setKey(e,t){let n=t.trim();if(!n)return this.removeKey(e);this.#f(e,n);try{await this.#t.write(e,n)}catch(e){console.warn(`A key could not be kept`,e),this.#n.keyFailed()}await this.#c()}async removeKey(e){try{await this.#t.remove(e)}catch(e){console.warn(`A key could not be taken away`,e),this.#n.keyFailed()}await this.#c()}async removeAllKeys(){try{await this.#t.clear()}catch(e){console.warn(`The keys could not be taken away`,e),this.#n.keyFailed()}await this.#c()}async fetchModels(e){let t=this.serviceOf(e),n=t&&AQ(t.kind);if(!t||!n)return;this.#d(e,{state:`loading`});let r=await this.keyOf(e)??``,i=await VQ(n.protocol,t.baseUrl,r);this.#d(e,i.ok?{state:`ok`,models:i.models}:{state:`failed`,failure:i.failure})}#d(e,t){let n=new Map(this.#i.listings).set(e,t);this.#i={...this.#i,listings:n},this.#r.emit()}async loadKnown(e){let t=AQ(e);if(t&&!this.#i.known.has(e))try{let n=await _$(t.catalog,t.protocol),r=new Map(this.#i.known).set(e,n);this.#i={...this.#i,known:r},this.#r.emit()}catch(e){console.warn(`The models pi knows of could not be loaded`,e)}}modelsFor(e){let t=this.serviceOf(e),n=this.#i.listings.get(e);return n?.state===`ok`&&n.models.length>0?n.models:(t&&this.#i.known.get(t.kind))??[]}#f(e,t){t!==void 0&&this.#a.get(e)!==t&&(this.#a.set(e,t),this.#o=new Set([...this.#o,t]))}},Pge=5e3,Q8=class{#e;#t;#n;#r;#i;#a;#o=!1;#s=!1;#c=!1;#l=!1;#u=!1;#d;failed=!1;constructor(e,t,n,r){this.#e=e,this.#t=t,this.#n=n,this.#r=r,this.#f()}keep(){this.#s=!0,this.#f()}get isBusy(){return this.#a!==void 0||this.#s}pause(){this.#c=!0}resume(){this.#c&&(this.#c=!1,this.#s&&this.#f())}#f(){this.#c||this.#u||(this.#a??=this.#_().finally(()=>{this.#a=void 0}))}#p(e,t,n){this.failed||(console.warn(e,t),n()),this.failed=!0,clearTimeout(this.#d),this.#d=setTimeout(()=>this.#f(),Pge)}async#m(){try{this.#i??=await this.#t()}catch(e){this.#p(`There is no place to keep this`,e,()=>{this.#n.keepFailed()})}return this.#i}async#h(e){try{let t=await e.load();if(this.#l)return;this.#o=!0,this.#s||=this.failed,this.#r(t)}catch(e){this.#p(`What was kept could not be read`,e,()=>{this.#n.readFailed()})}}async#g(e){for(;this.#s&&!this.#c;){this.#s=!1;try{await e.save(this.#e()),this.failed&&this.#n.keepRecovered(),this.failed=!1}catch(e){this.#s=!0,this.#p(`This could not be kept`,e,()=>{this.#n.keepFailed()});return}}}async#_(){let e=await this.#m();e&&(this.#o||await this.#h(e),this.#o&&await this.#g(e))}async settled(){for(this.failed&&this.#f();this.#a;)await this.#a;return!this.failed}async close(){this.#l=!0,await this.settled(),this.#u=!0,clearTimeout(this.#d),this.#i?.close()}},$8=1,e5=100,Fge=3,Ige=e=>typeof e==`string`&&/^(scenes|sounds|code)\//.test(e)&&hD.safeParse(e).success,t5=e=>e.length*Fge<=KN;function Lge(e){let{version:t,drafts:n}=e??{};if(t!==$8||!Array.isArray(n))return{drafts:[],dropped:e===void 0?0:1};let r=[],i=new Set;for(let e of n.slice(0,e5)){let{path:t,text:n,base:a}=e??{},o=a===null||typeof a==`string`&&t5(a);Ige(t)&&typeof n==`string`&&t5(n)&&o&&!i.has(t)&&(i.add(t),r.push({path:t,text:n,base:a??void 0}))}return{drafts:r,dropped:n.length-r.length}}function Rge(e){return e.length===0?void 0:{version:$8,drafts:e.slice(0,e5).map(({path:e,text:t,base:n})=>({path:e,text:t,base:n??null}))}}var zge=class{#e;#t;#n;#r;#i;#a;#o=Promise.resolve();#s;constructor(e,t,n,r){this.#e=e,this.#t=t,this.#n=n,this.#r=r,t.subscribe(this.#c),e.subscribe(this.#l),this.#l()}async settle(){return await this.#a?.settled()!==!1}#c=()=>{let{documents:e}=this.#t.getSnapshot();e!==this.#s&&this.#e.store===this.#i&&(this.#s=e,this.#a?.keep())};#l=()=>{let{store:e}=this.#e;if(e===this.#i||(this.#o=this.#a?.close()??this.#o,this.#i=e,this.#a=void 0,!e))return;let t=JG(e),n=this.#o,r=new Q8(()=>Rge(this.#t.drafts),()=>n.then(()=>this.#n.open(t)),this.#r,e=>{if(this.#a!==r)return;let{drafts:t,dropped:n}=Lge(e),i=this.#t.restore(t);i>0&&this.#r.restored(i),n>0&&this.#r.dropped(n),(n>0||i!==t.length)&&r.keep()});this.#a=r}},n5=e=>e.slice(0,e.lastIndexOf(`/`)),Bge=class{#e=new sv;#t;#n;#r;#i;#a;#o;#s={selected:void 0,collapsed:new Set};constructor(e,t,n,r,i,a){this.#t=e,this.#n=t,this.#r=n,this.#i=r,this.#a=i,this.#o=a}subscribe=this.#e.subscribe;getSnapshot=()=>this.#s;get#c(){return this.#t.store}get tree(){let e=this.#c?.getState();if(!e)return[];let t=this.#o;return Iue(e,{scenes:t(`files.scenes`),sounds:t(`files.sounds`),shared:t(`files.shared`)})}get#l(){let{selected:e}=this.#s;return e===void 0?void 0:n2(this.tree,e)}#u(e=this.#l){return e?.kind===`file`?n5(e.path):e&&Q0(e)?e.path:`code`}select(e){this.#s.selected!==e&&(this.#s={...this.#s,selected:e},this.#e.emit())}setCollapsed(e,t){let n=new Set(this.#s.collapsed);t?n.add(e):n.delete(e),this.#s={...this.#s,collapsed:n},this.#e.emit()}#d(e){let t=this.#c?.executeBatch(e);return t?(t.ok||this.#a.push(this.#o(`notice.commandFailed`,{message:t.error.message})),t.ok):!1}async newFile(e){let t=this.#c;if(!t)return;let n=this.#o,r=this.#u(e),i=await this.#i.prompt({title:n(`files.newFileTitle`,{folder:r}),confirm:n(`files.create`)});if(!i)return;let a=`${r}/${i}`;Z(t.getState().files,a)===void 0?this.#d([{type:`file.write`,params:{path:a,text:``}}])&&(this.select(a),this.#r(a,!0)):this.#a.push(n(`files.exists`,{path:a}))}async rename(e=this.#l){if(!e||!$0(e))return;let t=this.#o,n=await this.#i.prompt({title:t(`files.renameTitle`,{name:e.name}),value:e.name,confirm:t(`files.rename`)});if(!n||n===e.name)return;if(e.kind===`folder`&&e.role===`scene`){let t={scene:e.id,changes:{name:n}};this.#d([{type:`scene.update`,params:t}]);return}let r=`${n5(e.path)}/${n}`,i=new Map(e2(e).map(t=>[t,r+t.slice(e.path.length)])),a=[...i].map(([e,t])=>({type:`file.rename`,params:{from:e,to:t}}));this.#n.moving(i,()=>this.#d(a))&&this.select(r)}async remove(e=this.#l){if(!e||!$0(e))return;let t=this.#o,n=e.kind===`folder`&&e.role===`scene`?e.id:void 0,r=e2(e);if(!await this.#i.confirm({title:t(`files.removeTitle`,{name:e.name}),message:e.kind===`file`?t(`files.removeWarning`):t(`files.removeFolderWarning`,{count:r.length}),confirm:t(`files.remove`),danger:!0}))return;let i=n===void 0?r.map(e=>({type:`file.remove`,params:{path:e}})):[{type:`scene.remove`,params:{scene:n}}];this.#d(i)&&this.select(void 0)}setEntry(e){let[,t=``,...n]=e.split(`/`);this.#d([{type:`scene.update`,params:{scene:t,changes:{entry:n.join(`/`)}}}])}activate(e){this.select(e.path),e.kind===`file`?this.#r(e.path,!1):this.setCollapsed(e.path,!this.#s.collapsed.has(e.path))}};function Vge(e,t,n){let r=()=>n.model!==void 0,i=()=>t.selection.size>0,a=(t,n,i={})=>e.register({id:`keyframes.${t}`,title:e=>e(`keyframes.command`,{action:e(`keyframes.action.${t}`)}),run:n,scope:`keyframes`,enabled:r,palette:!1,...i});a(`delete`,()=>t.deleteSelected(),{keys:[`delete`,`backspace`],enabled:i}),a(`selectAll`,()=>t.panel.selectAll(),{keys:[`mod+a`]}),a(`copy`,()=>t.copySelected(),{keys:[`mod+c`],enabled:i}),a(`cut`,()=>t.cutSelected(),{keys:[`mod+x`],enabled:i}),a(`paste`,()=>t.paste(),{keys:[`mod+v`],enabled:()=>t.getSnapshot().hasClipboard}),a(`toggleSnapping`,()=>n.toggleSnapping(),{keys:[`s`]}),a(`zoomIn`,()=>t.panel.zoomIn(),{keys:[`=`],repeats:!0}),a(`zoomOut`,()=>t.panel.zoomOut(),{keys:[`-`],repeats:!0}),a(`zoomToFit`,()=>t.panel.zoomToFit(),{keys:[`\\`]}),a(`rowsTaller`,()=>t.panel.rowsTaller(),{keys:[`shift+=`],repeats:!0}),a(`rowsShorter`,()=>t.panel.rowsShorter(),{keys:[`shift+-`],repeats:!0});let o=e=>()=>{t.hasMovableSelection?t.nudge(e):n.stepFrames(e)};a(`previousFrame`,o(-1),{keys:[`left`],repeats:!0}),a(`nextFrame`,o(1),{keys:[`right`],repeats:!0}),a(`backFiveFrames`,o(-5),{keys:[`shift+left`],repeats:!0}),a(`forwardFiveFrames`,o(5),{keys:[`shift+right`],repeats:!0})}var Hge=e=>b(e)?e.keys.map(e=>e.value):[e],r5=e=>e.split(`.`,1)[0],i5=e=>e.slice(e.lastIndexOf(`.`)+1);function Uge(e,t){let n=r5(e)===r5(t),r=i5(e)===i5(t);return(n?2:0)+ +!!r}function Wge(e,t,n,r){let i=FF(t),a=Z(i,n);if(a===void 0)return[];let o=[],s=(e,t)=>{if(e.kind===`property`){let{spec:s}=e;if(s.path===n||Z(i,s.path)!==void 0||Ht(a,s.type)===void 0||s.options&&!Hge(a).every(e=>s.options?.includes(e)))return;o.push({path:s.path,label:[...t,r(e)].join(` › `)});return}if(e.kind===`object`&&(e.orphans||e.pending))return;let c=[...t,r(e)];for(let t of e.children)s(t,c)};for(let t of e.children)s(t,[]);return o.map((e,t)=>({connection:e,index:t,score:Uge(n,e.path)})).toSorted((e,t)=>t.score-e.score||e.index-t.index).map(({connection:e})=>e)}var Gge=200,Kge=8,a5=2,o5=(e,t)=>`scene-objects ${e} ${t}`,s5=({params:e})=>JSON.stringify(Object.entries(e).toSorted(([e],[t])=>e<t?-1:1)),c5=e=>({...e,text:JSON.stringify(e.registration)}),qge=e=>typeof e==`string`?jt(e):ln(e),l5=class{#e;#t=new sv;#n=new Map;#r=new Map;#i;#a=0;constructor(e){this.#e=e}subscribe=this.#t.subscribe;getVersion=()=>this.#a;#o(){this.#a+=1,this.#t.emit()}open(e){e!==this.#i&&(this.#i=e,this.#n.clear(),this.#r.clear(),this.#o())}registrationOf(e,t){this.#c(e);let n=this.#n.get(e);if(!n)return;let r,i;for(let e of n.values())r=e,Object.entries(e.registration.params).every(([e,n])=>t(e)===n)&&(i=e);return i?{registration:i.registration,exact:!0}:r&&{registration:r.registration,exact:!1}}problemsOf(e){return[...this.#n.get(e)?.values()??[]].at(-1)?.problems??[]}note(e,t){let n=qge(t);if(!n)return;let r=s5(n.registration),i=c5(n);return this.#n.get(e)?.get(r)?.text===i.text||(this.#s(e,r,i),this.#c(e).then(()=>this.#l(e))),r}unsure(e,t){let n=this.#n.get(e)?.get(t);if(!n?.registration.complete)return;let r={...n.registration,complete:!1};this.#s(e,t,{...n,registration:r,text:JSON.stringify(r)}),this.#c(e).then(()=>this.#l(e))}#s(e,t,n){let r=this.#n.get(e)??new Map;r.delete(t),r.set(t,n);for(let e of r.keys()){if(r.size<=Kge)break;r.delete(e)}this.#n.delete(e),this.#n.set(e,r);for(let e of this.#n.keys()){if(this.#n.size<=Gge)break;this.#n.delete(e)}this.#o()}#c(e){let t=this.#i,n=this.#r.get(e);if(n)return n;if(!this.#e||t===void 0)return Promise.resolve();let r=this.#e.read(o5(t,e)).then(n=>{if(this.#i!==t)return;let{version:r,runs:i}=n??{};if(r!==a5||!Array.isArray(i))return;let a=!1;for(let t of i.slice(-8)){let n=ln(t);if(!n)continue;let r=s5(n.registration);if(this.#n.get(e)?.has(r))continue;let i=this.#n.get(e),o=new Map([[r,c5(n)],...i??[]]);this.#n.set(e,o),a=!0}a&&this.#o()});return this.#r.set(e,r),r}#l(e){let t=this.#i,n=this.#n.get(e);if(!this.#e||t===void 0||!n)return;let r=({registration:e})=>({...e,params:Object.fromEntries(Object.entries(e.params).map(([e,t])=>[e,JSON.parse(t)]))});this.#e.write(o5(t,e),{version:a5,runs:[...n.values()].map(r)})}},u5=(e,t)=>e===t||e!==void 0&&t!==void 0&&e.length===t.length&&e.every((e,n)=>e===t[n]),Jge=(e,t)=>u5(e?.map(({from:e,to:t})=>`${e} ${t}`),t?.map(({from:e,to:t})=>`${e} ${t}`)),Yge=(e,t)=>e.ran===t.ran&&u5(e.objects,t.objects)&&Jge(e.renames,t.renames),Xge=class{#e;#t=new WeakMap;constructor(e){this.#e=e}describe(e,t){let n=this.#t.get(t),r=t.source.kind===`scene`,i=this.#e.getVersion();if(n&&(!r||n.version===i&&n.state===e))return n.described;let a=Poe(e,t,this.#e),o=n&&Yge(n.described,a)?n.described:a;return this.#t.set(t,{version:i,state:e,described:o}),o}},d5=7,Zge=14,Qge=4,f5=5,p5=12,$ge=16,e_e=400,t_e=4e3,n_e=3,m5=(e,t)=>u(Q(e),k(j(t),MA(e))),h5=class{keyframes;#e=d5;#t=new WeakMap;constructor(e){this.keyframes=e}get whatIsDrawn(){let{keyframes:e,lanes:t,width:n,screenHeight:r,scrollX:i,scrollY:a,pixelsPerSecond:o}=this,{selection:s,preview:c,previewedValues:l,model:u,heldRanges:d}=e;return[o,i,a,n,r,t,u,s,c,l,d]}setTouch(e){this.#e=e?Zge:d5}tableOf(e,t){let n=this.keyframes.shown(t.clip),{node:r}=e;if(r.kind===`property`){let t=Z(FF(n),r.spec.path),i=e.component&&p2(bF(t,e.component.index))||p2(t);return i&&u2(i)}let i=e.listed.get(t.id);return i&&Jue(n,i)}markIn({node:e},t){return e.kind===`property`?Gue(t,e.spec.type):t}scaleOf(e,t){let{node:n}=e;if(n.kind!==`property`||!lt(n.spec.type))return;let{keyframes:r}=this,{path:i}=n.spec,a=r.shownValue(t.clip,i);if(!p2(a))return;let o=e.component?.index,s=r.rangeOf(t.id,i,a,n.spec,o),c=Q2(e);return s&&c&&Pfe(s,c,e.height)}keyY(e,t,n,r){let i=t.numbers?.[n];return r&&i!==void 0?m3(r,i):e.height/2}forEachBox(e,t,n,r){e.box?r(e.box):d1(e.row,t,n,t=>{e.listed.has(t.id)&&r(t)})}keysAt(e,t,n){let r=FF(this.keyframes.shown(t.clip));return(e.listed.get(t.id)??[]).flatMap(e=>{let i=p2(Z(r,e));if(!i)return[];let a=f2(u2(i).seconds,n),o=i.keys[a];return o?[{clip:t.id,path:e,time:o.time}]:[]})}keysBetween(e,t,n){let r=[];return this.forEachBox(e,t,n,i=>{let a=FF(this.keyframes.shown(i.clip)),o=t-i.start+i.offset,s=n-i.start+i.offset;for(let t of e.listed.get(i.id)??[]){let e=p2(Z(a,t));if(!e)continue;let{seconds:n}=u2(e);for(let a=d2(n,o);a<n.length&&!(n[a]>s);a+=1)r.push({clip:i.id,path:t,time:e.keys[a].time})}}),r}#n(e,t,n){let r=this.#e/this.pixelsPerSecond,i=this.timeAt(t),a=this.screenY(e.top),o;if(this.forEachBox(e,i-r,i+r,t=>{let s=this.tableOf(e,t);if(!s)return;let c=i-t.start+t.offset,l=e.tall?this.scaleOf(e,t):void 0;if(l){let i=Math.max(this.#e,e.keyHeight/2),{seconds:u}=s;for(let d=d2(u,c-r);d<u.length;d+=1){let f=u[d];if(f>c+r)break;let p=Math.abs(a+this.keyY(e,s,d,l)-n);if(p>i)continue;let m=Math.hypot((f-c)*this.pixelsPerSecond,p);(!o||m<o.distance)&&(o={box:t,clock:f,distance:m})}return}let u=s.seconds[Kue(s.seconds,c)];if(u===void 0)return;let d=Math.abs(u-c);d<=r&&(!o||d<o.distance)&&(o={box:t,clock:u,distance:d})}),!o)return;let{box:s,clock:c}=o,l=this.keysAt(e,s,c);return l.length>0?{lane:e,box:s,clock:c,keys:l}:void 0}hitAt(e){if(e.y<28)return{kind:`empty`};let t=this.#r(e);if(t)return{kind:`handle`,handle:t};let n=this.laneY(e.y),r=e4(this.lanes,n);if(!r)return{kind:`empty`};let i=r.top+r.height-n;if(r.tall&&i<=Qge)return{kind:`edge`,lane:r};let a=this.#n(r,e.x,e.y);return a?{kind:`key`,...a}:{kind:`lane`,lane:r,seconds:this.timeAt(e.x)}}isOnHandle(e){return e.y>=28&&this.#r(e)!==void 0}#r(e){let t,n=this.#e;for(let r of this.visibleHandles()){let i=Math.hypot(r.x-e.x,r.y-e.y);i<=n&&([t,n]=[r,i])}return t}cursorAt(e){let{kind:t}=this.hitAt(e);return t===`edge`?`ns-resize`:t===`key`||t===`handle`?`pointer`:`default`}pressLanes(e){let t=this.hitAt(e);if(t.kind===`key`)return this.#l(t,e);if(t.kind===`handle`)return this.#o(t.handle,e);if(t.kind===`edge`&&t.lane.node.kind===`property`&&t.lane.box){let{box:n,node:r,component:i}=t.lane,{keyframes:a}=this,{path:o}=r.spec,s=i?.index,c=a.tallHeightOf(n.id,o,s),l=e=>a.setTallHeight(n.id,o,e,s);return new Ofe(l,()=>l(c),t.lane.height,e)}return new f3(this.#m,e)}#i({clip:e,path:t,component:n}){let{lanes:r}=this,i=this.#t.get(r);if(!i){let e=new Map;for(let t of r)t.node.kind===`property`&&t.box&&e.set(l3(t.box.id,t.node.spec.path,t.component?.index),t);this.#t.set(r,i=e)}return i.get(l3(e,t,n))}#a(e){let t=this.#i(e),n=t?.box,r=t&&n?this.scaleOf(t,n):void 0;return t&&n&&r?{row:t,box:n,scale:r}:void 0}#o({box:e,path:t,time:n,side:r,component:i},a){let o={clip:e.id,path:t,component:i,time:n,side:r,pointAt:n=>{let r=this.#a({clip:e.id,path:t,component:i});if(!r)return;let{row:a,box:o,scale:s}=r;return{t:this.timeAt(n.x)+o.offset-o.start,v:Ffe(s,n.y-this.screenY(a.top))}}};return new Dfe(this.#m,o,a)}#s(e,t){let n=this.keyframes.model?.boxes.get(e),r=n&&FF(this.keyframes.shown(n.clip));return r&&p2(Z(r,t))?.keys}#c({box:e,clock:t,keys:n}){let[r]=n,i=this.keyframes.shown(e.clip);return{seconds:e.start+t-e.offset,exact:()=>m5(i,r.time)}}#l(e,t){let{keyframes:n}=this,{selection:r}=n,{keys:i,box:a}=e,o=r.includes(i),s=t.shift||t.mod||n.multiSelecting,c=s?r.with(i):t3.of(i),l=()=>{n.select(s&&o?r.without(i):c)};if(!n.canMove(a.id))return new f3(this.#m,t,l);o||n.select(c);let u=this.#u(e);return new Tfe(this.#m,this.#c(e),t,l,u)}#u({lane:e,box:t}){if(!e.tall||!this.scaleOf(e,t))return[];let n=e.component?.index;return this.keyframes.movingChannels().flatMap(({clip:e,path:t,times:r})=>{let i=this.#a({clip:e,path:t})??(n===void 0?void 0:this.#a({clip:e,path:t,component:n})),a=i&&Q2(i.row);if(!i?.row.tall||!a)return[];let o=i.row.component?.index,s=new Map((this.#s(e,t)??[]).map(e=>[e.time,e])),c=r.filter(e=>{let t=s.get(e)?.value;return o===void 0?typeof t==`number`:bF(t,o)!==void 0});return c.length===0?[]:[{clip:e,path:t,spec:a,times:c,...o===void 0?{}:{component:o}}]})}lanesBetween(e,t){let{lanes:n}=this,r=[];for(let i=t4(n,e);i<n.length;i+=1){let e=n[i];if(e.top>=t)break;r.push(e)}return r}#d({from:e,to:t,top:n,bottom:r}){return this.lanesBetween(n,r).flatMap(i=>(i.tall?this.#f(i,e,t,n,r):this.keysBetween(i,e,t)).filter(({clip:e})=>this.keyframes.canMove(e)))}#f(e,t,n,r,i){let{box:a,node:o}=e;if(!a||o.kind!==`property`)return[...this.keysBetween(e,t,n)];let s=this.scaleOf(e,a),c=this.tableOf(e,a),l=p2(Z(FF(this.keyframes.shown(a.clip)),o.spec.path));if(!c||!l)return[];let u=[],{seconds:d}=c,f=a.offset-a.start;for(let p=d2(d,t+f);p<d.length&&!(d[p]>n+f);p+=1){let t=e.top+this.keyY(e,c,p,s);t+f5<r||t-f5>i||u.push({clip:a.id,path:o.spec.path,time:l.keys[p].time})}return u}#p(){let{keyframes:e}=this,t=new Set(e.movingChannels().map(({clip:e,path:t})=>`${e} ${t}`)),n=[],[r,i]=[this.timeAt(0),this.timeAt(this.width)];for(let a of this.lanesBetween(this.laneY(0),this.laneY(this.screenHeight)))for(let o of this.keysBetween(a,r,i)){let r=e.model?.boxes.get(o.clip);if(!r||t.has(`${o.clip} ${o.path}`))continue;let i=r.start+Wt(o.time)-r.offset;if(n.push({seconds:i,exact:()=>m5(r.clip,o.time)}),n.length>=t_e)return n}return n}get#m(){let{keyframes:e}=this;return{get model(){return e.model},get frame(){return e.frame},get selection(){return e.selection},get multiSelecting(){return e.multiSelecting},timeAt:e=>this.timeAt(e),laneAt:e=>this.laneY(e),snapDistance:e=>this.snapDistance(e),snapTargets:()=>this.#p(),moving:()=>e.movingChannels(),keysIn:e=>this.#d(e),select:t=>e.select(t),show:t=>e.showPreview(t,this),preview:t=>e.previewEdits(t),cancelPreview:()=>e.cancelEdits(),commit:(t,n)=>e.commitMove(t,n),holdRanges:t=>e.holdRanges(t),releaseRanges:()=>e.releaseRanges(),keysOf:(e,t)=>this.#s(e,t),perPixel:e=>{let t=this.#a(e);return t&&Ife(t.scale)},gone:()=>e.tellGone()}}touchAtLanes(e){let t=this.hitAt(e);return t.kind===`edge`||t.kind===`handle`?`grab`:t.kind===`key`&&this.keyframes.selection.includes(t.keys)?`selected`:`plain`}holdLanes(e){let t=this.hitAt(e);if(t.kind!==`key`||this.keyframes.selection.includes(t.keys))return;let{keyframes:n}=this,{selection:r,multiSelecting:i}=n;n.select(i?r.with(t.keys):t3.of(t.keys))}selectSpot({keys:e}){this.keyframes.select(t3.of(e))}selectColumn(e,t){let n=e.box.start+e.clock-e.box.offset,r=this.lanes.flatMap(e=>e.depth===0?this.keysBetween(e,n-s2,n+s2):[]),{keyframes:i}=this;i.select(t?i.selection.with(r):t3.of(r))}selectAll(){let e=[-1/0,1/0],t=this.lanes.flatMap(t=>t.depth===0?this.keysBetween(t,...e).filter(({clip:e})=>this.keyframes.canMove(e)):[]);this.keyframes.select(t3.of(t))}selectLane(e,t){let n=this.keysBetween(e,-1/0,1/0),{keyframes:r}=this;r.select(t?r.selection.with(n):t3.of(n))}visibleHandles(){let{keyframes:e}=this;if(e.selection.size===0||e.preview?.shift!==void 0)return[];let t=[],n=this.timeAt(0),r=this.timeAt(this.width);for(let i of this.lanesBetween(this.laneY(28),this.laneY(this.screenHeight))){let{box:a}=i;if(a&&i.node.kind===`property`&&e.canMove(a.id)&&(this.#h(i,a,n,r,t),t.length>=e_e))return[]}return t}#h(e,t,n,r,i){let{keyframes:a}=this,o=a.selectedSeconds(e,t),s=o&&this.scaleOf(e,t);if(!o||!s||e.node.kind!==`property`)return;let{path:c}=e.node.spec,l=p2(a.shownValue(t.clip,c));if(!l)return;let u=e.component?.index,d=u===void 0?l.keys:vF(l.keys,u);if(!d)return;let{seconds:f}=u2(l),p=t.offset-t.start,m=this.screenY(e.top),h=({t:e,v:t})=>({x:this.xAt(e-p),y:m+m3(s,t)}),g=f[Math.max(d2(f,n+p)-1,0)]??0,_=f[Math.min(d2(f,r+p),f.length-1)]??0;for(let n=d2(o,g);n<o.length;n+=1){let r=o[n];if(r>_)break;let a=f2(f,r),s=d[a];if(!s||typeof s.value!=`number`)continue;let l=h({t:r,v:s.value});for(let n of[`in`,`out`]){let r=d[n===`out`?a+1:a-1],o=U4(d,a,n);if(!o||!r||typeof r.value!=`number`)continue;let f=h({t:Wt(r.time),v:r.value});if(Math.abs(f.x-l.x)<$ge)continue;let p=h(o);if(Math.hypot(p.x-l.x,p.y-l.y)<p5){let e=mfe(d,a,n),t=e?h(e):f,r=Math.hypot(t.x-l.x,t.y-l.y)>1?t:f,i=Math.hypot(r.x-l.x,r.y-l.y);if(i<1)continue;p={x:l.x+(r.x-l.x)/i*p5,y:l.y+(r.y-l.y)/i*p5}}let{width:m}=this;l.x<0&&p.x<0||l.x>m&&p.x>m||i.push({id:`${e.id} ${s.time} ${n}`,lane:e,box:t,path:c,...u===void 0?{}:{component:u},time:s.time,index:a,side:n,keyX:l.x,keyY:l.y,x:p.x,y:p.y})}}}visibleKeys(e){let t=[],{selection:n}=this.keyframes,r=this.timeAt(0),i=this.timeAt(this.width),a=this.laneY(0);for(let o of this.lanesBetween(a,this.laneY(this.screenHeight))){let a=this.screenY(o.top);this.forEachBox(o,r,i,s=>{let c=this.tableOf(o,s);if(!c)return;let l=this.scaleOf(o,s),{seconds:u,marks:d}=c,f=-1/0,p=d2(u,r-s.start+s.offset);for(let r=p;r<u.length&&t.length<e;r+=1){let e=s.start+u[r]-s.offset;if(e>i)break;let p=this.xAt(e);if(p-f<n_e)continue;f=p;let m=u[r],h=this.keysAt(o,s,m);t.push({id:`${o.id} ${s.id} ${m}`,lane:o,box:s,x:p,y:a+this.keyY(o,c,r,l),seconds:e,mark:this.markIn(o,d[r]),selected:h.length>0&&n.includes(h),tried:h.some(e=>this.keyframes.isTriedKey(e))})}})}return t}},r_e=10,g5=5,i_e=4;function a_e(e){let{node:t,box:n}=e;if(t.kind!==`object`||!n)return;let r=bA(n.clip).find(({id:e})=>tI(e)===t.object.id);return r&&{box:n,effect:r}}function _5(e,t){let n=j(e.clip.duration),r=e=>D(e,n)>0?n:e;return{from:t.start===void 0?M:r(j(t.start)),to:t.end===void 0?n:r(j(t.end))}}function o_e(e,t,n,r,i){let a=Q(e.clip),o=j(e.clip.duration),s=lq(1,i),c=e=>k(lq(cq(O(a)+e,i),i),a),l=(e,t)=>D(e,t)<0?t:e,d=(e,t)=>D(e,t)>0?t:e;if(n===`start`)return{from:l(d(c(O(t.from)+r),k(t.to,s)),M),to:t.to};if(n===`end`){let e=c(O(t.to)+r);return{from:t.from,to:d(l(e,u(t.from,s)),o)}}let f=k(t.to,t.from),p=l(c(O(t.from)+r),M);return D(u(p,f),o)>0&&(p=k(o,f)),{from:l(p,M),to:u(l(p,M),f)}}function v5(e,t,n,r){let i=a_e(e);if(!i)return;let{box:a,effect:o}=i,{from:s,to:c}=(r?.clip===a.id&&r.effect===o.id?r:void 0)??_5(a,o),l=n(a.start+O(s));return{left:l,right:Math.max(n(a.start+O(c)),l+i_e),top:t+e.keyHeight-5-2,box:a,effect:o}}function s_e(e,t,n){if(n<e.top+5-r_e||n>e.top+5+2||t<e.left-g5||t>e.right+g5)return;let r=Math.min(g5,(e.right-e.left)/3);return t<=e.left+r?`start`:t>=e.right-r?`end`:`move`}var c_e=e=>e===`move`?`grab`:`ew-resize`,l_e=class{#e;#t;#n;#r;#i;#a;#o;constructor(e,t,n,r,i){this.#e=e,this.#t=t,this.#n=n,this.#r=r,this.#i=_5(t,n),this.#o=this.#i,this.#a=i.x}move(e){let t=this.#e,n=t.timeAt(e.x)-t.timeAt(this.#a);this.#o=o_e(this.#t,this.#i,this.#r,n,t.rate),t.show({clip:this.#t.id,effect:this.#n.id,...this.#o})}end(e){this.move(e),this.#e.show(void 0);let{from:t,to:n}=this.#o;if(D(t,this.#i.from)===0&&D(n,this.#i.to)===0)return;let r=j(this.#t.clip.duration);this.#e.commit(this.#t.id,this.#n.id,D(t,M)<=0?void 0:t,D(n,r)>=0?void 0:n)}cancel(){this.#e.show(void 0)}};function u_e(e,t,n,r){e.save();for(let i of n){let n=v5(i,r.screenY(i.top),e=>r.xAt(e),r.preview);n&&(e.globalAlpha=n.effect.enabled===!1?.4:1,e.fillStyle=t.effect,e.beginPath(),e.roundRect(n.left,n.top,n.right-n.left,5,2),e.fill(),e.fillStyle=`#ffffffcc`,e.fillRect(n.left,n.top,2,5),e.fillRect(n.right-2,n.top,2,5))}e.restore()}var d_e=8,y5=[],b5=(e,t)=>{let n=e.at(-1);return n?n.top+n.height:t},f_e=class extends h5{#e;#t=new sv;#n=new Set;#r=y5;#i;constructor(e,t){super(e),this.#e=t}subscribeLanes=this.#t.subscribe;getLanes=()=>this.#r;get lanes(){return this.#r}get width(){return this.#e.width}get screenHeight(){return this.#e.height}get scrollX(){return this.#e.scrollX}get scrollY(){return this.#e.scrollY}get pixelsPerSecond(){return this.#e.pixelsPerSecond}xAt(e){return this.#e.xAt(e)}timeAt(e){return this.#e.timeAt(e)}laneY(e){return this.#e.laneAt(e)}screenY(e){return 28-this.#e.scrollY+e}snapDistance(e){let{snapping:t}=this.#e.getSnapshot();return t&&!e.alt?d_e/this.pixelsPerSecond:0}get opened(){return[...this.#n]}forgetAll(){this.#n.clear()}openAll(e){for(let t of e)this.#n.add(t)}get holdsDrag(){return this.#i!==void 0||this.keyframes.preview!==void 0&&this.keyframes.isPreviewOf(this)}get rangePreview(){return this.#i}#a(e){if(e.y<28)return;let t=e4(this.#r,this.laneY(e.y));if(!t||t.row.track.locked===!0)return;let n=v5(t,this.screenY(t.top),e=>this.xAt(e),this.#i),r=n&&s_e(n,e.x,e.y);return n&&r&&{...n,part:r}}#o(e){let t=this.#a(e),n=this.#e.model?.rate;if(t&&n)return new l_e({rate:n,timeAt:e=>this.timeAt(e),show:e=>{this.#i=e,this.#e.redraw()},commit:(e,t,n,r)=>{this.#e.setEffectRange(e,t,n,r)}},t.box,t.effect,t.part,e)}paintRanges(e,t){u_e(e,t,this.lanesBetween(this.laneY(28),this.laneY(this.screenHeight)),{screenY:e=>this.screenY(e),xAt:e=>this.xAt(e),preview:this.#i})}canOpen({clip:e}){return this.keyframes.nodeOf(this.keyframes.shown(e)).children.length>0}isOpen({id:e}){return this.#n.has(e)}toggle({id:e}){this.#n.delete(e)||this.#n.add(e),this.keyframes.toggleOpenInTimeline()}toggleLane(e){e.node.kind===`clip`&&e.box?this.toggle(e.box):this.keyframes.toggleOpen(e.id)}get#s(){let{laneRules:e}=this.keyframes;return{...e,isOpen:t=>t.kind===`clip`||e.isOpen(t)}}#c(e,t){return t.clips.flatMap(t=>{if(!this.#n.has(t.id))return[];let n=this.keyframes.nodeOf(this.keyframes.shown(t.clip));return n.children.length>0&&e.boxes.has(t.id)?[n]:[]})}#l(e,t,n){let r=[],i=n;for(let n of this.#c(e,t)){let a=xde(e,n,t,i,this.#s);r.push(...a),i=b5(a,i)}return r}relist(){let e=this.#e.model;if(!e){this.#u(y5);return}let t=new Map;for(let n of e.rows){let r=b5(this.#l(e,n,0),0);r>0&&t.set(n.id,r)}this.#e.setRoomBelow(t);let n=this.#e.model;if(!n)return;let r=n.rows.flatMap(e=>this.#l(n,e,e.top+e.height));this.#u(r)}#u(e){(e.length!==0||this.#r.length!==0)&&(this.#r=e,this.#t.emit(),this.#e.redraw())}shownClips=e=>this.#n.has(e);get hasSelection(){return this.keyframes.selection.size>0}get canChangeSelection(){return this.keyframes.movingChannels(this.shownClips).length>0}get hasClipboard(){return this.keyframes.getSnapshot().hasClipboard}nudge(e){this.keyframes.nudge(e,this.shownClips)}deleteSelected(){this.keyframes.deleteSelected(this.shownClips)}copySelected(){this.keyframes.copySelected(this.shownClips)}cutSelected(){this.keyframes.cutSelected(this.shownClips)}paste(){this.keyframes.paste()}#d(e){return e.y<28?!1:e4(this.#r,this.laneY(e.y))!==void 0||this.isOnHandle(e)}press(e){let t=this.#o(e);if(t)return t;if(this.#d(e))return this.pressLanes(e);e.y>=28&&this.keyframes.clearSelection()}hover(e){let t=this.#a(e);return t?c_e(t.part):this.#d(e)?this.cursorAt(e):void 0}touchAt(e){return this.#d(e)?this.touchAtLanes(e):void 0}hold(e){return this.#d(e)?(this.holdLanes(e),!0):!1}setTouchInput(e){this.setTouch(e)}},p_e=8,x5=1.5,m_e=48,h_e=.95,g_e=48,S5=20/24,C5=3,w5=1.25,T5=[],__e=class extends h5{#e;#t=new sv;#n=T5;#r=0;#i=0;#a=1;#o=!1;#s=0;#c=0;#l=0;#u;shownClips=()=>!0;constructor(e,t){super(e),this.#e=t}subscribeLanes=this.#t.subscribe;getLanes=()=>this.#n;get lanes(){return this.#n}subscribeView=e=>this.keyframes.subscribeView(e);get model(){return this.keyframes.model}get frame(){return this.keyframes.frame}get width(){return this.#s}get height(){return this.#c}get screenHeight(){return this.#c}get scrollY(){return this.#l}get scrollX(){return this.#i}get pixelsPerSecond(){return this.#r>0?this.#r:this.#d()}#d(){let{model:e}=this,t=Math.max(e?.duration??0,1),[n,r]=S4(this.#s,e?.duration??1,e?.rate.fps??30);return E4(Math.max(this.#s,1)*h_e/t,n,r)}get rowScale(){return this.#a}get#f(){return Math.round(24*this.#a)}xAt(e){return e*this.pixelsPerSecond-this.scrollX}timeAt(e){return(e+this.scrollX)/this.pixelsPerSecond}laneY(e){return e-28+this.#l}screenY(e){return 28-this.#l+e}snapDistance(e){let{snapping:t}=this.#e.getSnapshot();return t&&!e.alt?p_e/this.pixelsPerSecond:0}get visibleDuration(){return this.model?.duration??0}get contentWidth(){return Math.max(this.visibleDuration*1.25*this.pixelsPerSecond,this.#s)}get contentHeight(){let e=this.#n.at(-1),t=e?e.top+e.height:0;return Math.max(t+28+m_e,this.#c)}get isSnappedToPlayhead(){let{model:e}=this,t=this.keyframes.preview?.snap;return!e||t===void 0?!1:Math.abs(t-this.frame/e.rate.fps)<1e-9}get isDragging(){return this.#u!==void 0}get dragCursor(){return``}get holdsDrag(){return this.keyframes.preview!==void 0}toggleLane({id:e}){this.keyframes.toggleOpen(e)}relist(){let{model:e}=this;if(!e||this.#s===0){e||this.#p(T5);return}let{laneRules:t}=this.keyframes;this.#p(bde(e,this.keyframes.tracks(e),t,this.#f))}#p(e){e.length===this.#n.length&&e.every((e,t)=>{let n=this.#n[t];return e.id===n.id&&e.node===n.node&&e.row===n.row&&e.box===n.box&&e.top===n.top&&e.height===n.height&&e.keyHeight===n.keyHeight&&e.tall===n.tall&&e.open===n.open})||(this.#n=e,this.#m(),this.#t.emit(),this.keyframes.redrawTab())}setViewport(e,t){if(e===this.#s&&t===this.#c)return;let n=this.#s===0&&e>0;this.#s=e,this.#c=t,e===0&&this.cancelDrag(),n&&this.relist(),this.#r===0&&e>0&&(this.#r=this.#d()),this.#m(),this.#o&&this.#g(),this.keyframes.redrawTab()}#m(){this.#l=E4(this.#l,0,this.contentHeight-this.#c),this.#i=E4(this.#i,0,this.contentWidth-this.#s)}setScroll(e,t){this.#i=e,this.#l=t,this.#m(),this.#_()}zoomAround(e,t){if(this.#r===0)return;let{model:n}=this,r=this.timeAt(e),[i,a]=S4(this.#s,n?.duration??1,n?.rate.fps??30);this.#r=E4(this.#r*t,i,a),this.#i=r*this.#r-e,this.#m(),this.#_()}zoomIn(){this.zoomAround(this.#h(),x5)}zoomOut(){this.zoomAround(this.#h(),1/x5)}zoomToFit(){this.#s!==0&&(this.#r=this.#d(),this.#i=0,this.#m(),this.#_())}#h(){let{model:e}=this;if(!e)return 0;let t=this.xAt(this.frame/e.rate.fps);return t>=0&&t<=this.#s?t:this.#s/2}zoomRowsAround(e,t){if(this.#u)return;let n=E4(this.#a*t,S5,C5);if(n===this.#a)return;let r=this.laneY(Math.max(e,28)),i=e4(this.#n,r),a=i?(r-i.top)/i.height:0,o=this.#a;this.#a=n,this.relist();let s=i&&this.#n.find(({id:e})=>e===i.id),c=s?s.top+a*s.height:r*n/o;this.#l=c-(Math.max(e,28)-28),this.#m(),this.#_()}rowsTaller(){this.zoomRowsAround(28,w5)}rowsShorter(){this.zoomRowsAround(28,1/w5)}followPlayhead(){this.#g()}#g(){let{model:e}=this;if(this.#o=this.#s===0,!e||this.#o||this.#r===0)return;let t=this.xAt(this.frame/e.rate.fps),n=Math.min(g_e,this.#s/4),r=this.#i;t<n?this.#i+=t-n:t>this.#s-n&&(this.#i+=t-(this.#s-n)),this.#m(),this.#i!==r&&this.keyframes.rememberSoon()}#_(){this.keyframes.rememberSoon(),this.keyframes.redrawTab()}get ownView(){let e=this.#r;return e>0?{pixelsPerSecond:e,scrollX:this.#i}:void 0}adoptView(e,t){let n=e&&Number.isFinite(e.pixelsPerSecond)&&e.pixelsPerSecond>0?Number.isFinite(e.scrollX):!1;this.#r=n&&e?e.pixelsPerSecond:0,this.#i=n&&e?e.scrollX:0,this.#r===0&&this.#s>0&&(this.#r=this.#d()),this.#a=typeof t==`number`&&Number.isFinite(t)?E4(t,S5,C5):1,this.#l=0,this.#o=!1}setTouchInput(e){this.setTouch(e)}hover(e){return e.y<28?`pointer`:this.cursorAt(e)}leave(){}press(e){let{model:t}=this;t&&(this.#v(),this.#u=e.y<28?new I1(this.#y,e):this.pressLanes(e))}drag(e){this.#u?.move(e)}release(e){let t=this.#u;this.#u=void 0,t?.end(e)}cancelDrag(){return this.#u?(this.#v(),!0):!1}#v(){this.#u?.cancel(),this.#u=void 0}checkDrag(){let{model:e}=this;e&&this.#u?.isStale?.(e)&&this.#v()}scrollDuringDrag(e,t,n){if(!this.#u)return;let r=this.#u.reachesRows===!0;this.setScroll(this.scrollX+t,r?this.#l+n:this.#l),this.#u.move(e)}touchAt(e){return e.y<28?`grab`:this.touchAtLanes(e)}hold(e){this.holdLanes(e)}get#y(){let{keyframes:e}=this,t=this.#e;return{get model(){return e.model},get frame(){return e.frame},timeAt:e=>this.timeAt(e),snapDistance:e=>this.snapDistance(e),seek:e=>t.seek(e)}}},v_e=300,E5=`keyframes`,D5=1,y_e=320,b_e=220,x_e=640,O5=1e-6,k5=()=>!0,S_e=[`here`,`all`,`keyed`];function C_e(e){if(e===void 0)return{};try{let t=JSON.parse(e);return typeof t==`object`&&t?t:{}}catch{return{}}}var A5=e=>Array.isArray(e)?e.filter(e=>typeof e==`string`):[];function w_e(e){return Array.isArray(e)?e.filter(e=>Array.isArray(e)&&typeof e[0]==`string`&&typeof e[1]==`string`&&Number.isFinite(e[2])&&typeof e[3]==`boolean`&&(e[4]===void 0||Number.isInteger(e[4])&&e[4]>=0)):[]}var j5=e=>Math.min(Math.max(Math.round(e),40),480),M5=(e,t,n)=>n===void 0?`${e} ${t}`:`${e} ${t} ${n}`;function N5(e){if(typeof e!=`object`||!e)return;let{version:t,listWidth:n}=e;return t===D5&&typeof n==`number`?n:void 0}var P5=e=>Math.min(Math.max(Math.round(e),b_e),x_e),T_e=class{#e;#t;#n;#r;#i;#a;#o;#s;#c;#l=new sv;#u=new sv;panel;inTimeline;#d={range:`here`,query:``,pinned:new Set,selection:n3,listWidth:y_e,hasClipboard:!1};#f=new Set;#p=new Map;#m=new Map;#h=new WeakMap;#g;#_=[];#v;#y;#b=0;#x=0;#S=!1;#C;#w;#T=!1;#E;#D={state:void 0,frame:-1,changes:void 0,rows:new Map};#O=new Map;#k=new Map;#A=new WeakMap;#j=new WeakMap;#M=new WeakMap;#N;constructor(e,t,n,r,i,a,o,s,c=new l5){this.#e=e,this.#t=t,this.#n=n,this.#r=r,this.#i=i,this.#a=a,this.#o=o,this.#s=s,this.#c=new Xge(c),c.subscribe(this.#R),this.panel=new __e(this,t),this.inTimeline=new f_e(this,t),t.setExtras(this.inTimeline),t.subscribeCopies(()=>this.forgetClipboard()),t.subscribeChoices(()=>this.#J(n3)),e.subscribe(this.#F),t.subscribe(this.#I),t.subscribeView(this.#L),n.subscribe(this.#z),r.subscribe(this.redraw),this.#F()}subscribe=this.#l.subscribe;getSnapshot=()=>this.#d;subscribeView=this.#u.subscribe;async load(){let e=await xX(this.#a,E5,N5);e.kind===`ok`&&this.#P({listWidth:P5(e.value)}),this.#a.listen(E5,e=>{let t=N5(e);t!==void 0&&this.#P({listWidth:P5(t)})})}get model(){return this.#t.model}get frame(){return this.#t.frame}get state(){return this.#g?.getState()}get selection(){return this.#d.selection}get multiSelecting(){return this.#t.getSnapshot().multiSelecting}get preview(){return this.#v}isPreviewOf(e){return this.#y===e}get comparing(){return this.#n.getSnapshot().comparing}#P(e){this.#d={...this.#d,...e},this.#l.emit()}redraw=()=>{this.#t.redraw()};redrawTab(){this.#u.emit()}#F=()=>{let{store:e}=this.#e;if(e===this.#g)return;this.#te(),this.#g=e,this.#_=[],this.#k.clear(),this.#f.clear(),this.#p.clear(),this.#m=new Map,this.inTimeline.forgetAll();let t=e?C_e(this.#i.read(`keyframes.${JG(e)}`)):{},n=e=>e.filter(e=>this.#ne(e));for(let e of n(A5(t.toggled)))this.#f.add(e);for(let[e,n,r,i,a]of w_e(t.tall)){if(!this.#ne(e))continue;let t={clip:e,path:n,component:a,height:j5(r),on:i};this.#p.set(M5(e,n,a),t)}this.inTimeline.openAll(n(A5(t.open))),this.panel.adoptView(t.view,t.rows);let r=t.range;this.#P({range:r&&S_e.includes(r)?r:`here`,query:``,pinned:new Set(n(A5(t.pinned))),selection:n3,hasClipboard:!1}),this.#x=this.#t.frame,this.#b=this.#t.frame,this.#q()};#I=()=>{let{model:e,selection:t,playing:n}=this.#t.getSnapshot();if(e===this.#C&&t===this.#w&&n===this.#S)return;let r=e===this.#C&&n===this.#S;e!==this.#C&&(this.#k.clear(),this.#E=void 0),this.#C=e,this.#w=t,this.#S=n,n||(this.#b=this.#t.frame),this.panel.checkDrag(),r&&this.#d.range===`all`||this.#q(),this.#B()};#L=()=>{let{frame:e}=this.#t;if(e!==this.#x){this.#x=e,this.panel.followPlayhead();let{playing:t}=this.#t.getSnapshot();!t&&this.#d.range===`here`&&(this.#b=e,this.panel.relist())}this.#u.emit()};#R=()=>{this.#E=void 0,this.#q(),this.redraw(),this.#l.emit()};describe=e=>{let{state:t}=this;return t?this.#c.describe(t,e):void 0};nodeOf(e){return xI(e,this.describe(e))}#z=()=>{this.#k.clear(),this.#E=void 0,this.#q(),this.#B(),this.redraw(),this.#l.emit()};#B(){let{selection:e}=this.#d;if(e.size===0)return;let t=e.keeping(({clip:e,path:t,time:n})=>{let r=this.model?.boxes.get(e),i=r&&p2(Z(FF(this.shown(r.clip)),t));return i!==void 0&&Wue(i,n)});t!==e&&this.#J(t)}shown(e){let{look:t}=this.#n;if(!t)return e;let n=this.#k.get(e.id);if(n?.clip===e)return n.shown;let r=t.apply(e);return r!==e&&this.#k.set(e.id,{clip:e,shown:r}),r}shownValue(e,t){let n=this.#r.getPreviewed().get(e.id);return n?.has(t)?n.get(t):Z(FF(e),t)}get previewedValues(){return this.#r.getPreviewed()}canMove(e){let t=this.model;return!this.comparing&&t?.boxes.has(e)===!0&&t.rowOfClip.get(e)?.track.locked!==!0}isTried(e,t){return this.#n.look?.holds(e,t)===!0}isTriedKey({clip:e,path:t,time:n}){let r=this.model?.boxes.get(e);if(!r||this.#n.look?.holds(e,t)!==!0)return!1;let i=this.shown(r.clip),a=this.#M.get(i);a||this.#M.set(i,a=new Map);let o=a.get(t);if(!o){let e=new Map(this.#V(r.clip,t).map(e=>[e.time,e])),n=this.#V(i,t).filter(t=>!F5(t,e.get(t.time)));o=new Set(n.map(e=>e.time)),a.set(t,o)}return o.has(n)}#V(e,t){return p2(Z(FF(e),t))?.keys??[]}selectedSeconds(e,{id:t}){let{selection:n}=this;if(!n.hasClip(t))return;let r=this.#A.get(n);r||this.#A.set(n,r=new Map);let i=`${e.id} ${t}`;if(r.has(i))return r.get(i);let a=(e.listed.get(t)??[]).flatMap(e=>[...n.timesOf(t,e)??[]].map(Wt)),o=a.length>0?Float64Array.from(a).toSorted():void 0;return r.set(i,o),o}triedSeconds(e,{id:t,clip:n}){let{look:r}=this.#n;if(!r||this.#n.getSnapshot().count===0)return;let i=(e.listed.get(t)??[]).filter(e=>r.holds(t,e));if(i.length===0)return;let a=this.shown(n),o=this.#j.get(a);o||this.#j.set(a,o=new Map);let s=e.id;if(o.has(s))return o.get(s);let c=i.flatMap(e=>{let t=new Map(this.#V(n,e).map(e=>[e.time,e]));return this.#V(a,e).filter(e=>!F5(e,t.get(e.time))).map(({time:e})=>Wt(e))}),l=c.length>0?Float64Array.from(c).toSorted():void 0;return o.set(s,l),l}inspect(e,t){let n=this.state,{model:r}=this;if(!n||!r)return;let{look:i}=this.#n,{frame:a,comparing:o}=this,s=this.#D;(s.state!==n||s.frame!==a||s.changes!==i?.changes)&&(this.#D={state:n,frame:a,changes:i?.changes,rows:new Map});let{rows:c}=this.#D,l=`${e.id} ${t.path}`,u=c.get(l);if(u?.box===e)return u.inspected;let d=Y2(n,r,e,t,a,{look:i,comparing:o});return c.set(l,{box:e,inspected:d}),d}labelOfValue=(e,t)=>{let n=this.#o;if(typeof t==`boolean`)return n(t?`keyframes.on`:`keyframes.off`);let r=typeof t==`string`?t:JSON.stringify(t);return YX(n,`property.choice.${e.path}.${r}`,r)};nameOfNode(e,t){let n=this.#o;switch(e.kind){case`track`:return t?E_e(n,t):``;case`clip`:{let t=this.model?.boxes.get(e.clip)?.clip,r=t?.source.kind??``;return t?.name??YX(n,`timeline.kind.${r}`,r)}case`object`:{if(e.orphans)return n(`keyframes.orphans`);if(e.pending)return n(e.pending===`partial`?`keyframes.pendingPartial`:`keyframes.pending`);let{type:t}=e.object;return t===aI.params?n(`keyframes.objects.params`):t===aI.elements?n(`keyframes.objects.elements`):t===$F.effects?n(`keyframes.objects.effects`):t?.startsWith($F.prefix)?F$(n,t.slice($F.prefix.length)):e.object.name??e.object.id}case`group`:return ZX(n,e.group);case`property`:return XX(n,e.spec)}}nameOfLane({node:e,row:t,component:n}){return n?QX(n.name):this.nameOfNode(e,t)}labelOf({node:e,row:t,group:n,component:r}){let i=this.nameOfNode(e,t),a=n===void 0?i:`${ZX(this.#o,n)} ${i}`;return r?`${a} ${QX(r.name)}`:a}isOpen(e){if(this.#d.query!==``&&e.kind!==`property`)return!0;let t=this.#f.has(e.id);return e.kind===`track`||e.kind===`object`&&e.object.type===$F.effects?!t:t}#H={isOpen:e=>this.isOpen(e),tallHeight:(e,t)=>{let{clip:n,spec:r}=e;return this.isTall(n,r.path,t)?this.tallHeightOf(n,r.path,t):void 0}};get laneRules(){return this.#H}isTall(e,t,n){return this.#p.get(M5(e,t,n))?.on===!0}tallHeightOf(e,t,n){return this.#p.get(M5(e,t,n))?.height??120}toggleTall(e,t,n){let r=!this.isTall(e,t,n),i=this.tallHeightOf(e,t,n);this.#p.set(M5(e,t,n),{clip:e,path:t,component:n,height:i,on:r}),this.#q(),this.#ee()}setTallHeight(e,t,n,r){let i=j5(n),a=i===this.tallHeightOf(e,t,r);if(this.isTall(e,t,r)&&a)return;let o={clip:e,path:t,component:r,height:i,on:!0};this.#p.set(M5(e,t,r),o),this.#q(),this.#ee()}rangeOf(e,t,n,r,i){let a=i===void 0?void 0:bF(n,i),o=i===void 0&&xn(r.type),s=a===void 0?o?RF(n,r.type):void 0:RF(a,`number`),c=s&&zfe(s);return c&&Lfe(c,this.#m.get(M5(e,t,i)))}get heldRanges(){return this.#m}holdRanges(e){let t=new Map;for(let{clip:n,path:r,component:i}of e){let e=this.model?.boxes.get(n),a=e&&this.specOf(n,r),o=e&&this.shownValue(e.clip,r),s=a&&o!==void 0?this.rangeOf(n,r,o,a,i):void 0;s&&t.set(M5(n,r,i),s)}this.#m=t}releaseRanges(){this.#m.size!==0&&(this.#m=new Map,this.redraw())}specOf(e,t){let n=this.model?.boxes.get(e);if(!n)return;let r=this.nodeOf(this.shown(n.clip)),i=this.#h.get(r);if(!i){let e=new Map,t=n=>{if(n.kind===`property`)e.set(n.spec.path,n.spec);else for(let e of n.children)t(e)};for(let e of r.children)t(e);i=e,this.#h.set(r,i)}return i.get(t)}isGradual(e,t){let n=this.specOf(e,t);return n!==void 0&&lt(n.type)}toggleOpen(e){this.#f.has(e)?this.#f.delete(e):this.#f.add(e),this.#q(),this.#ee()}toggleOpenInTimeline(){this.#q(),this.#ee()}setRange(e){e!==this.#d.range&&(this.#P({range:e}),this.#b=this.#t.frame,this.#q(),this.#ee())}setQuery(e){e!==this.#d.query&&(this.#P({query:e}),this.#q())}togglePin(e){let t=new Set(this.#d.pinned);t.delete(e)||t.add(e),this.#P({pinned:t}),this.#q(),this.#ee()}setListWidth(e){let t=P5(e);t!==this.#d.listWidth&&this.#P({listWidth:t})}saveListWidth(){let{listWidth:e}=this.#d;this.#a.save(E5,{version:D5,listWidth:e}).catch(e=>console.warn(`Keyframe settings could not be saved`,e))}#U(e){if(this.#E)return this.#E;let t=new Set;for(let n of e.boxes.values())Xoe(this.nodeOf(this.shown(n.clip)))&&t.add(n.id);return this.#E=t,t}#W(e,t,n){let{pinned:r}=this.#d,i=new Set;d1(t,n-O5,n+O5,e=>i.add(e));let a=[...this.#t.getSnapshot().selection,...[...r].map(e=>e.split(`/`)[0]),...this.#U(e)];for(let n of a){let r=e.boxes.get(n);r&&e.rowOfClip.get(n)===t&&i.add(r)}return[...i].toSorted((e,t)=>e.start-t.start)}tracks(e){let{range:t,query:n,pinned:r}=this.#d,{selection:i}=this.#t.getSnapshot(),a=lq(this.#b,e.rate),o=this.#b/e.rate.fps,s=n.toLowerCase(),c={range:t,moment:a,always:e=>r.has(e)||i.has(e),...s===``?{}:{matches:e=>this.#K(e).includes(s)}};return e.rows.flatMap(n=>{let r=(t===`here`?this.#W(e,n,o):n.clips).map(({clip:e})=>this.shown(e)),i=r.length>0?Qoe(n.track,r,c,this.describe):void 0;return i?[i]:[]})}#G(e){if(e.kind===`group`)return`group ${e.group}`;if(e.kind===`property`&&e.spec.name===void 0)return`path ${e.spec.path}`;let t=e.kind===`clip`?this.model?.boxes.get(e.clip)?.clip:void 0;return t&&t.name===void 0?`kind ${t.source.kind}`:void 0}#K(e){let t=this.#G(e);if(t===void 0)return this.nameOfNode(e).toLowerCase();let n=this.#O.get(t);return n===void 0&&(n=this.nameOfNode(e).toLowerCase(),this.#O.set(t,n)),n}#q(){if(!this.#T){this.#T=!0;try{this.inTimeline.relist(),this.panel.relist()}finally{this.#T=!1}}}select(e){e!==this.#d.selection&&(this.#J(e),e.size>0&&this.#t.selectClipsOfKeys(e.clips()))}#J(e){e!==this.#d.selection&&(this.#P({selection:e}),this.redraw())}clearSelection(){this.select(n3)}tellGone(){this.#s.gone()}showPreview(e,t){this.#v=e,this.#y=e?t:void 0,this.redraw()}previewEdits(e){this.#r.preview(e)}cancelEdits(){this.#r.cancel()}commitMove(e,t){let n=this.#d.selection;this.#P({selection:t});let r=this.#r.commit(e);return r||this.#P({selection:n}),r}movingChannels(e=k5){let t=[];for(let{clip:n,path:r,times:i}of this.selection.channels())e(n)&&this.canMove(n)&&t.push({clip:n,path:r,times:[...i]});return t}get hasMovableSelection(){return this.movingChannels().length>0}#Y(e){let t=this.movingChannels(e);return t.length>0||this.selection.size===0||(this.selection.onClips(e).size===0?this.#s.notShown():this.comparing?this.#s.comparing():this.#s.locked()),t}nudge(e,t=k5){let{model:n}=this,r=this.movingChannels(t);if(!n||r.length===0)return;let i=lq(Math.abs(e),n.rate),a=e<0?k(M,i):i;if(!r.every(({times:e})=>e.every(e=>D(u(j(e),a),M)>=0)))return;let o=t3.of(d3(this.selection,r,a));this.commitMove(u3(r,a),o)}deleteSelected(e=k5){let t=this.#Y(e).flatMap(({clip:e,path:t,times:n})=>n.map(n=>({owner:{clip:e},path:t,op:`removeKey`,time:n})));t.length>0&&this.#r.commit(t)}cutSelected(e=k5){let t=this.#Y(e);if(t.length===0)return;let n=t.flatMap(({clip:e,path:t,times:n})=>n.map(n=>({clip:e,path:t,time:n})));this.#Q(n),this.deleteSelected(e)}#X(){return this.movingChannels().filter(({clip:e,path:t})=>this.isGradual(e,t))}get canEase(){for(let{clip:e,path:t}of this.selection.channels())if(this.isGradual(e,t))return!0;return!1}get selectedPreset(){let e=new Set;for(let{clip:t,path:n,times:r}of this.selection.channels()){if(!this.isGradual(t,n))continue;let i=this.model?.boxes.get(t),a=i&&p2(Z(FF(this.shown(i.clip)),n));if(a)for(let t of r){let n=OM(a.keys,j(t));if(e.add(Que(a.keys[n],a.keys[n+1])),e.size>1)return}}return[...e][0]}setEase(e){let t=this.#X().flatMap(({clip:t,path:n,times:r})=>{let i={owner:{clip:t},path:n,op:`setInterp`,times:[...r],ease:e},a=e.interp===`bezier`?this.#Z(t,n,r):void 0,o=new Map;for(let e of a?.indices??[])for(let t of[e,e+1]){let e=a?.keys[t];e?.tangent===`auto`&&o.set(t,{...e,tangent:`broken`})}return o.size===0?[i]:[{owner:{clip:t},path:n,op:`putKeys`,keys:[...o.values()]},i]});t.length>0&&this.#r.commit(t)}#Z(e,t,n){let r=this.model?.boxes.get(e),i=r&&p2(Z(FF(this.shown(r.clip)),t));if(!i)return;let a=[];for(let e of n){let t=OM(i.keys,j(e));i.keys[t]?.time===e&&a.push(t)}return{keys:i.keys,indices:a.toSorted((e,t)=>e-t)}}selectedTangent(e){let t=new Set;for(let{clip:n,path:r,times:i}of this.selection.channels()){if(!this.isGradual(n,r))continue;let a=this.#Z(n,r,i);for(let n of a?.indices??[])if(t.add(J4(a?.keys??[],n,e)),t.size>1)return}return[...t][0]}setTangent(e,t){let n=this.#X().flatMap(({clip:n,path:r,times:i})=>{let a=this.#Z(n,r,i);if(!a)return[];let o=yfe(a.keys,a.indices,e,t);return o.size>0?[{owner:{clip:n},path:r,op:`putKeys`,keys:[...o.values()]}]:[]});n.length>0&&this.#r.commit(n)}copySelected(e=k5){let t=this.selection.onClips(e);t.size===0?this.selection.size>0&&this.#s.notShown():this.#Q(t)}#Q(e){let t=[];for(let{clip:n,path:r,time:i}of e){let e=this.model?.boxes.get(n);if(!e)continue;let a=this.shown(e.clip),o=this.#V(a,r),s=o[OM(o,j(i))];s&&t.push({clip:n,path:r,moment:m5(a,i),key:s})}t.length!==0&&(this.#_=t,this.#P({hasClipboard:!0}),this.#t.forgetClipboard())}forgetClipboard(){this.#_.length!==0&&(this.#_=[],this.#P({hasClipboard:!1}))}#$(e){let{model:t}=this,n;for(let r of this.#t.getSnapshot().selection){let i=t?.boxes.get(r)?.clip;if(i&&(this.describe(i)?.objects??QF(i)).length!==0){if(n)return t?.boxes.get(e)?.clip;n=i}}return n??t?.boxes.get(e)?.clip}paste(){let e=this.#_,{model:t}=this,[n]=e;if(!t||!n)return;if(this.comparing){this.#s.comparing();return}let r=new Set(e.map(({clip:e})=>e)),i=e.reduce((e,{moment:t})=>D(t,e)<0?t:e,n.moment),a=k(lq(this.frame,t.rate),i),o=new Map,s=[],c=r.size===1?this.#$(n.clip):void 0;for(let{clip:n,path:i,moment:l,key:d}of e){let e=r.size===1?c:t.boxes.get(n)?.clip;if(!e||!this.canMove(e.id)){this.#s.pasteNowhere();return}let f=u(MA(e),k(u(l,a),Q(e)));if(D(f,M)<0){this.#s.pasteTooEarly();return}let p=ze(f),m=`${e.id} ${i}`,h=o.get(m)??{clip:e.id,path:i,keys:[]};h.keys.push({...d,time:p}),o.set(m,h),s.push({clip:e.id,path:i,time:p})}this.#r.commit([...o.values()].map(({clip:e,path:t,keys:n})=>({owner:{clip:e},path:t,op:`putKeys`,keys:n})))&&this.select(t3.of(s))}rememberSoon(){this.#ee()}#ee(){clearTimeout(this.#N),this.#N=setTimeout(()=>this.#te(),v_e)}flush(){clearTimeout(this.#N),this.#te()}#te(){let e=this.#g&&JG(this.#g);if(e===void 0)return;let{range:t,pinned:n}=this.#d,r=this.panel.ownView,i=e=>[...e].filter(e=>this.#ne(e)),a={range:t,toggled:i(this.#f),pinned:i(n),tall:[...this.#p.values()].flatMap(({clip:e,path:t,component:n,height:r,on:i})=>this.#ne(e)?[n===void 0?[e,t,r,i]:[e,t,r,i,n]]:[]),open:i(this.inTimeline.opened),...r?{view:r}:{},...this.panel.rowScale===1?{}:{rows:this.panel.rowScale}};this.#i.write(`keyframes.${e}`,JSON.stringify(a))}#ne(e){let{model:t}=this;if(!t)return!0;let n=/^track:(.+)$/.exec(e)?.[1];return n===void 0?t.boxes.has(e.split(`/`)[0]):t.rows.some(e=>e.track.id===n)}},E_e=(e,{track:t,number:n,gone:r})=>r?e(`timeline.goneTrack`):t.name??e(`timeline.track.${t.kind}`,{number:n}),F5=(e,t)=>JSON.stringify(e)===JSON.stringify(t),D_e=[`nw`,`n`,`ne`,`e`,`se`,`s`,`sw`,`w`];function I5(e,t){let n=(Math.atan2(t,e)*180/Math.PI%180+180)%180;return n<22.5||n>=157.5?`ew-resize`:n<67.5?`nwse-resize`:n<112.5?`ns-resize`:`nesw-resize`}var O_e=6;function L5(e,t){let n=Number(e.toFixed(O_e));return Math.min(Math.max(n===0?0:n,t.min??-1/0),t.max??1/0)}function R5(e,t,n){let r=e===void 0?void 0:RF(e,t.type),i=r?nn(r,n):t.default;return typeof i==`number`?i:void 0}var z5=1e-4,B5=1e-12,V5=e=>e!==void 0&&b(e)?e.keys:[];function H5(e){let{n:t,d:n}=j(e);return`${t}/${n}`}var U5=(e,t)=>D(j(e.time),j(t.time));function k_e(e){let{time:t,value:n,tangent:r,...i}=e;return i}function W5(e,t,n){let r=0;for(let i of n??[e.x,e.y]){if(Math.abs(i.perShare)<=B5)continue;let e=R5(i.after,i.spec,t)??0,n=R5(i.before,i.spec,t)??0;r+=i.perShare*(e-n)}return r}function A_e(e){let t=1/0,n=-1/0;for(let{after:r,at:i}of e){let e=V5(r),a=r,o=i===void 0?-1:e.findIndex(({time:e})=>H5(e)===H5(i)),s=(a.before??`hold`)===`hold`?e[o-1]:void 0,c=(a.after??`hold`)===`hold`?e[o+1]:void 0,l=o>=0;t=Math.min(t,l&&s?Wt(s.time):-1/0),n=Math.max(n,l&&c?Wt(c.time):1/0)}return[t,n]}function j_e(e,t,n){let r=e.findIndex(({time:e})=>H5(e)===H5(t)),i=e[r+1];return r>=0&&i!==void 0&&H5(i.time)===H5(n)}function M_e(e,t){let n=new Map;for(let t of e)V5(t.after).forEach((e,r)=>{let i=H5(e.time);n.has(i)||n.set(i,{key:e,side:t,index:r})});let r=[...n.values()].map(({key:e,side:n,index:r})=>{let i=V5(n.after),a=V5(n.before),o=i[r+1],s=i[r-1],{out:c,in:l,...u}=k_e(e),d=(e,t)=>e!==void 0&&t!==void 0&&!j_e(a,e.time,t.time),f=c&&(d(e,o)?[c[0],0]:c),p=s?.interp===`bezier`&&d(s,e)?[l?.[0]??1,1]:l;return{...u,...f&&{out:[f[0],f[1]]},...p&&{in:[p[0],p[1]]},time:e.time,value:t(Wt(e.time))}}).toSorted(U5),i=e[0]?.after;return{keys:r,...i.before&&{before:i.before},...i.after&&{after:i.after}}}function G5(e,t){let n=0,r=e.length;for(;n<r;){let i=n+r>>1;e[i]<=t+1e-9?n=i+1:r=i}return n-1}function K5(e,t,n,r){let i=AF(e),a=i.keys.map(({time:e})=>Wt(e)),o=new Set;for(let{clock:e}of n)Math.abs((R5(i,r,e)??0)-t(e))>z5&&o.add(G5(a,e));if(o.size===0)return i;let s=new Set(i.keys.map(({time:e})=>H5(e))),c=[];for(let{time:e,clock:i}of n)o.has(G5(a,i))&&!s.has(H5(e))&&c.push({time:e,value:L5(t(i),r)});let l=i.keys.map((e,t)=>{if(!o.has(t)&&!o.has(t-1))return e;let{interp:n,out:r,in:i,preset:a,spring:s,tangent:c,...l}=e;return l}),{before:u,after:d,...f}=i;return{...f,keys:[...l,...c].toSorted(U5),...u&&!o.has(-1)&&{before:u},...d&&!o.has(i.keys.length-1)&&{after:d}}}function q5(e,t){let{clip:n,path:r,spec:i,stored:a}=e,o={owner:{clip:n},path:r},s=[t.x,t.y].filter(e=>Math.abs(e.perShare)>B5&&V5(e.after).length>0),c=V5(a),l=W5(t,t.clock,[t.x,t.y].filter(e=>!s.includes(e)));if(s.length===0){if(Math.abs(l)<=z5)return[];if(c.length===0){let n=R5(a,i,t.clock)??0;return[e.write(L5(n+l,i))]}let n=c.flatMap(e=>typeof e.value==`number`?[{...e,value:L5(e.value+l,i)}]:[]);return[{...o,op:`putKeys`,keys:n}]}let u=e=>(R5(a,i,e)??0)+W5(t,e),[d,f]=A_e(s),p=t.frames(d,f);if(c.length===0){let e=M_e(s,e=>L5(u(e),i));return[{...o,op:`set`,value:K5(e,u,p,i)}]}let m=e=>e>d-1e-9&&e<f+1e-9,h=c.map(e=>{if(typeof e.value!=`number`)return e;let t=Wt(e.time);return{...e,value:L5(m(t)?u(t):e.value+l,i)}}),g={...a,keys:h},_=new Set(c.map(({time:e})=>H5(e)));for(let e of s)for(let{time:t}of V5(e.after)){let e=Wt(t);m(e)&&!_.has(H5(t))&&(_.add(H5(t)),g=GM(g,{op:`setKey`,time:t,value:L5(u(e),i)}))}let v=K5(g,u,p,i),y=new Map(c.map(e=>[H5(e.time),JSON.stringify(e)])),b=v.keys.filter(e=>y.get(H5(e.time))!==JSON.stringify(e));return b.length===0?[]:[{...o,op:`putKeys`,keys:b}]}var J5=({x:e,y:t})=>[e,t];function Y5(e,t,n,r){let i=J5(ue(t,r)),a=i,o=0;return{edits(r){let s=J5(ue(t,r));e.kind===`rotate`&&(o+=gse(e.at,a,s),a=s);let c=vse(e,{from:i,to:s,turned:o,shift:r.shift},e=>n.get(e)?.start),l=[];for(let[e,t]of c){let r=n.get(e),i=r?.now();if(!r||!i)return;l.push(i.write(L5(t,r.spec)))}return l}}}var X5=e=>e!==void 0&&b(e)?e.keys:[];function Z5(e,t){try{return{value:GM(e,t)}}catch(e){if(e instanceof mA)return;throw e}}function N_e(e,t,n){let{placement:r,toScreen:i,toWorld:a,clip:o}=e,{transform:s,box:c,matrix:l}=r,u=ue(i,{x:s.x,y:s.y}),d=e.stops.map(e=>ue(i,e)),[f,p,m,h]=l;return{edits(i){let s={x:u.x+i.x-n.x,y:u.y+i.y-n.y};if(!i.alt){let e=d.find(({x:e,y:t})=>Math.hypot(e-s.x,t-s.y)<=8);e&&(s=e)}let l=ese(r,ue(a,s)),{x:g,y:_,anchorX:v,anchorY:y}={x:t.x.now(),y:t.y.now(),anchorX:t.anchorX.now(),anchorY:t.anchorY.now()};if(!g||!_||!v||!y)return;if(!l)return[];let b=v.write(L5(l.anchorX,t.anchorX.spec)),x=y.write(L5(l.anchorY,t.anchorY.spec)),S=Z5(v.stored,v.write(l.anchorX)),ee=Z5(y.stored,y.write(l.anchorY));if(!S||!ee)return;let C=(e,t,n,r,i)=>({spec:e.spec,before:t.stored,after:n.value,at:r.op===`write`&&X5(n.value).length>0?r.time:void 0,perShare:i}),w=(n,r)=>({clock:e.clock,x:C(t.anchorX,v,S,b,n),y:C(t.anchorY,y,ee,x,r),frames:e.frames}),te=(e,t)=>({clip:o,path:e.path,spec:e.spec,stored:t.stored,write:t.write});return[b,x,...q5(te(t.x,g),w(f*c.width,m*c.height)),...q5(te(t.y,_),w(p*c.width,h*c.height))]}}}function P_e(e,t,n,r,i){let a=ue(n,i),o=j(t.time);return{edits(i){let s=ue(n,i),[c,l]=VI(s.x-a.x,s.y-a.y,i.shift),u=[];for(let[n,i,a,s]of[[r.x,c,t.hasX,t.x],[r.y,l,t.hasY,t.y]]){let r=n.now();if(!r)return;let c=X5(r.stored),l=c.find(({time:e})=>D(j(e),o)===0);if(a&&(!l||typeof l.value!=`number`))return;if(c.length===0)continue;let d=R5(r.stored,n.spec,Wt(t.time))??s,f=l?l.value:d,p={owner:{clip:e},path:n.path};u.push({...p,op:`setKey`,time:l?.time??t.time,value:L5(f+i,n.spec)})}return u}}}var F_e={nw:[0,0],n:[.5,0],ne:[1,0],e:[1,.5],se:[1,1],s:[.5,1],sw:[0,1],w:[0,.5]},Q5=({x:e,y:t})=>[e,t];function I_e(e,t){let{placement:n,toScreen:r,fits:i}=e,{picture:a,matrix:o,transform:s}=n,c=we(r,o),[l,u,d,f]=c,p=Math.atan2(u,l),m={x:s.x,y:s.y},h=ue(r,m),g=D_e.map(e=>{let[t,n]=F_e[e],i={x:a.x+a.width*t,y:a.y+a.height*n},s=ue(o,i),c=ue(r,s);return{id:`scale ${e}`,role:`scale`,detail:e,look:e.length===2?`corner`:`side`,at:c,angle:p,cursor:I5(c.x-h.x,c.y-h.y),handle:{kind:`scale`,id:e,at:Q5(s),center:Q5(m),bind:`transform.scale`}}}),_=Math.hypot(d,f);if(_>0){let e=ue(c,{x:a.x+a.width/2,y:a.y}),n=t=>({x:e.x-d/_*t,y:e.y-f/_*t}),r=n(24),o=n(-24),s=i(r)||!i(o)?r:o;t.push({kind:`stem`,from:e,to:s}),g.push({id:`rotate`,role:`rotate`,detail:`rotate`,look:`rotate`,at:s,angle:p,cursor:`grab`,handle:{kind:`rotate`,id:`rotate`,at:Q5(m),radius:1,bind:`transform.rotation`}})}return g.push({id:`anchor`,role:`anchor`,detail:`anchor`,look:`anchor`,at:h,angle:p,cursor:`crosshair`,solve:(t,i)=>{let a=t(`transform.x`,s.x),o=t(`transform.y`,s.y),c=t(`transform.anchorX`,s.anchorX),l=t(`transform.anchorY`,s.anchorY);if(!a||!o||!c||!l)return;let{clip:u,clock:d,frames:f,toWorld:p}=e,m=tse(n);return N_e({clip:u,placement:n,clock:d,toScreen:r,toWorld:p,stops:m,frames:f},{x:a,y:o,anchorX:c,anchorY:l},i)}}),g}var L_e=4e3;function R_e(e,t,n){let r=e.findIndex(e=>e.clock>=t);r<0&&(r=e.length);let i=r-1,a=[];for(let o=0;o<L_e&&a.length<200;o+=1){let o=e[i],s=e[r];if(!o&&!s)break;let c=o&&(!s||t-o.clock<=s.clock-t),l=c?o:s;c?--i:r+=1,n(l)&&a.push(l)}return a}function z_e(e,t){let{layer:n,placement:r,properties:i,toScreen:a,toWorld:o,fps:s,clip:c,fits:l}=e,u=ase(Z(i,`transform.x`),Z(i,`transform.y`),{from:En(n,n.start),to:En(n,n.end)},s,{x:r.transform.x,y:r.transform.y});if(!u)return[];let d=e=>ue(a,e);t.push({kind:`path`,points:u.points.map(d),frames:u.frames.map(d)});let f=new Map;return R_e(u.keys,e.clock,e=>{let t=d(u.at(e.clock));return f.set(e,t),l(t)}).toSorted((e,t)=>e.clock-t.clock).map(e=>{let t=u.at(e.clock),n=f.get(e);return{id:`key ${e.time}`,role:`key`,detail:e.time,look:`key`,at:n,angle:0,cursor:`move`,solve:(n,r)=>{let i=n(`transform.x`,t.x),a=n(`transform.y`,t.y),s={...e,...t};return i&&a?P_e(c,s,o,{x:i,y:a},r):void 0}}})}var B_e={objectType:`clip.visual`,handles(e){let t=[];return{marks:t,handles:[...z_e(e,t),...I_e(e,t)]}},body({placement:{transform:e}}){return{kind:`move`,id:`move`,at:[e.x,e.y],bind:{x:`transform.x`,y:`transform.y`}}}};function V_e(e,t,n){let r=Math.min(e.width,t.width),i=Math.min(e.height,t.height),a=Math.min(r/n.width,i/n.height),o=n.width*a,s=n.height*a;return{x:(e.width-r)/2+(r-o)/2,y:(e.height-i)/2+(i-s)/2,width:o,height:s}}function H_e(e,{frame:t,full:n,shown:r},i){if(!(t.width>0&&t.height>0&&r.width>0&&r.height>0))return;let a=V_e(t,n,r),o=[a.width/r.width,0,0,a.height/r.height,a.x,a.y],s=rn({width:r.width,height:r.height,camera:e.camera},i);return we(o,s)}var U_e=new Map([B_e].map(e=>[e.objectType,e])),W_e=4,$5=7,G_e=16,e7={marks:[],grips:[],bodies:[],target:void 0};function t7(e,t){let n=FF(e);if(!t||t.size===0)return n;let r={...n};for(let[e,n]of t)n===void 0?delete r[e]:r[e]=n;return r}function n7(e,t,n){let r=Z(e,t.path),i=r===void 0?void 0:RF(r,t.type),a=i?nn(i,n):t.default;return typeof a==`number`?a:void 0}var K_e=class{#e;#t=new sv;#n=0;#r=0;#i=!1;#a;#o={scene:e7,hovered:void 0,dragging:void 0};#s=[];#c;constructor(e){this.#e=e;let t=()=>this.#l(),{session:n,timeline:r,properties:i,trials:a,quality:o,handles:s,registrations:c}=e,l,u,d=()=>{n.store!==l&&(u?.(),l=n.store,u=l?.subscribe(t),t())},f=()=>{let e=this.#a;e&&(r.getSnapshot().playing||r.frame!==e.frame)&&this.cancel(),t()},p=[n.subscribe(d),r.subscribe(f),r.subscribeView(f),i.subscribe(t),a.subscribe(t),o.subscribe(t),s.subscribe(t),c.subscribe(t)];d(),this.#c=()=>{u?.();for(let e of p)e();s.want(void 0)}}subscribe=this.#t.subscribe;getSnapshot=()=>(this.#m(),this.#o);dispose(){this.cancel(),this.#c()}setViewport(e,t){(e!==this.#n||t!==this.#r)&&(this.#n=e,this.#r=t,this.#l())}setTouchInput(e){e!==this.#i&&(this.#i=e,this.#l())}get isDragging(){return this.#a!==void 0}#l(){this.#t.emit()}#u(e){let t={...this.#o,...e};(t.scene!==this.#o.scene||t.hovered!==this.#o.hovered||t.dragging!==this.#o.dragging)&&(this.#o=t,this.#t.emit())}hover(e){let t=this.#p(e);return this.#u({hovered:t?.what}),t?.cursor??`default`}leave(){this.#u({hovered:void 0})}press(e){this.cancel();let{timeline:t}=this.#e,n=this.#p(e),r=t.frame;if(!n)this.#a=this.#d(e,r,void 0,void 0,()=>t.clearSelection());else{if(n.select){if(e.shift){t.addToSelection(n.select);return}t.selectOnly(n.select)}this.#a=this.#d(e,r,n.what,n.begin?.(e),void 0),this.#u({dragging:n.what})}}#d(e,t,n,r,i){return{start:e,frame:t,what:n,gesture:r,unchanged:JSON.stringify(r?.edits(e)??[]),click:i,moved:!1,stopped:!1,edits:[]}}drag(e){let t=this.#a;if(!t||t.stopped)return;if(!t.moved){if(Math.hypot(e.x-t.start.x,e.y-t.start.y)<W_e)return;t.moved=!0}if(!t.gesture)return;let n=t.gesture.edits(e);n?(t.edits=n,this.#e.properties.preview(n)):this.#f(t)}#f(e){e.stopped=!0,e.edits=[],this.#e.properties.cancel(),this.#u({dragging:void 0}),this.#e.messages.gone()}release(e){let t=this.#a;if(!t)return;this.drag(e),this.#a=void 0,this.#u({dragging:void 0});let{properties:n}=this.#e;t.stopped||(t.moved?t.edits.length===0||JSON.stringify(t.edits)===t.unchanged?n.cancel():n.commit(t.edits):(n.cancel(),t.click?.()))}cancel(){this.#a&&(this.#a=void 0,this.#e.properties.cancel(),this.#u({dragging:void 0}))}#p(e){let{scene:t}=this.getSnapshot(),n=this.#i?G_e:$5,r,i=n;for(let n of t.grips){let t=Math.hypot(n.at.x-e.x,n.at.y-e.y);t<=i&&(r=n,i=t)}if(r)return{what:r.id,cursor:r.cursor,begin:r.begin};let{target:a}=t;if(a&&OI(a.corners,e))return{what:`body ${a.clip}`,cursor:`move`,begin:e=>this.#D(a.clip,e)};let o=t.bodies.find(({corners:t})=>OI(t,e));if(o)return{what:`body ${o.clip}`,cursor:`default`,select:o.clip,begin:e=>this.#D(o.clip,e)}}#m(){let{session:e,timeline:t,properties:n,trials:r,quality:i,handles:a,registrations:o}=this.#e,{model:s}=t,{selection:c,playing:l}=t.getSnapshot(),u=[e.store?.getState(),s,t.frame,c,l,n.getPreviewed(),r.getSnapshot(),i.getSnapshot().size,this.#n,this.#r,this.#i,a.getVersion(),o.getVersion()];if(u.length===this.#s.length&&u.every((e,t)=>e===this.#s[t]))return;this.#s=u;let d=this.#_();d!==this.#o.scene&&(this.#o={...this.#o,scene:d})}#h(){let{session:e,timeline:t,properties:n,quality:r}=this.#e,i=e.store?.getState(),{model:a}=t,o=r.getSnapshot().size;if(!i||!a||!o||t.getSnapshot().playing)return;let s=XF(i,a.id);if(!s)return;let c=t.frame,l=c/a.rate.fps,u=H_e(s,{frame:{width:this.#n,height:this.#r},...o},l),d=u&&Ft(u);if(u&&d)return{state:i,model:a,frame:c,seconds:l,plan:b8(s,n.getPreviewed()),settled:new Map(s.layers.map(e=>[e.id,e])),toScreen:u,toWorld:d}}#g(e,t){let n=e.model.boxes.get(t.id);if(!n)return;let r=uI(e.state,n.clip),i=$oe(t,e.seconds,r,e.plan.stage),a=we(e.toScreen,i.matrix);return{layer:t,box:n,placement:i,boxToScreen:a,corners:DI(a,i.picture)}}#_(){let e=this.#h(),{handles:t,timeline:n}=this.#e;if(!e)return t.want(void 0),e7;let{selection:r}=n.getSnapshot(),i=e.plan.layers.filter(t=>Le(t,e.seconds)).flatMap(t=>this.#g(e,t)??[]),a=i.filter(({layer:e})=>r.has(e.id)),o=e.plan.layers.filter(({id:e})=>r.has(e)).length,s=i.filter(({layer:t})=>r.has(t.id)||te(t,e.seconds)>0).map(({layer:e,corners:t})=>({clip:e.id,corners:t})).toReversed(),c=[],l=[],[u]=a,d=o===1&&u&&this.#y(u)?u:void 0;for(let t of a){if(t===d)continue;let n=e.model.rowOfClip.get(t.layer.id)?.track.locked===!0;c.push({kind:`outline`,clip:t.layer.id,corners:t.corners,style:n?`locked`:`selected`})}return d&&this.#b(e,d,c,l),t.want(d?.layer.source.kind===`scene`?d.layer.id:void 0),{marks:c,grips:l,bodies:s,target:d&&{clip:d.layer.id,corners:d.corners}}}#v({x:e,y:t}){return e>=$5&&t>=$5&&e<=this.#n-$5&&t<=this.#r-$5}#y({layer:e}){let{timeline:t,trials:n}=this.#e;return!n.getSnapshot().comparing&&t.model?.rowOfClip.get(e.id)?.track.locked!==!0}#b(e,t,n,r){let{layer:i,corners:a}=t;n.push({kind:`outline`,clip:i.id,corners:a,style:`target`});let o=this.#S(e,t);for(let{object:i,extension:a}of this.#x(t)){let s=a.handles(o);n.push(...s.marks);for(let n of s.handles)r.push(this.#C(e,t,i,o,n))}i.source.kind===`scene`&&this.#O(e,t,n,r)}#x({box:e}){return(this.#e.describe(e.clip)?.objects??QF(e.clip)).flatMap(e=>{let t=e.type===void 0?void 0:U_e.get(e.type);return t?[{object:e,extension:t}]:[]})}#S(e,t){let{layer:n,box:r,placement:i}=t,a=this.#e.properties.getPreviewed().get(n.id);return{clip:n.id,layer:n,placement:i,toScreen:e.toScreen,toWorld:e.toWorld,properties:t7(r.clip,a),clock:En(n,e.seconds),fps:e.model.rate.fps,frames:(t,n)=>X_e(r.clip,e.model.rate,t,n),fits:e=>this.#v(e)}}#C(e,t,n,r,i){let{id:a,role:o,detail:s,at:c,look:l,angle:u,cursor:d}=i;return{id:`${t.layer.id} ${a}`,role:o,detail:s,clip:t.layer.id,at:c,look:l,angle:u,cursor:d,begin:a=>{if(!i.handle)return i.solve?.(this.#w(e,t,n),a);let o=this.#T(e,t,i.handle,r7(n),r.properties);return o&&Y5(i.handle,e.toWorld,o,a)}}}#w(e,t,n){let r=r7(n);return(n,i)=>{let a=r(n);return a&&this.#E(e,t.box,a,i)}}#T(e,t,n,r,i){let a=En(t.layer,e.seconds),o=new Map;for(let s of i7(n)){let n=r(s),c=n&&n7(i,n,a),l=n&&c!==void 0&&this.#E(e,t.box,n,c);if(!l)return;o.set(s,l)}return o}#E(e,t,n,r){let i=()=>{let{trials:r,session:i,timeline:a}=this.#e,o=i.store?.getState(),{model:s}=a,c=s?.boxes.get(t.id);if(!o||!s||!c)return;let l={look:r.look,comparing:r.getSnapshot().comparing},{row:u,blocked:d,time:f}=Y2(o,s,c,n,e.frame,l);if(!d)return{stored:u.stored,write:e=>V2(t.id,u,f,e)}};return i()&&{path:n.path,spec:n,start:r,now:i}}#D(e,t){let n=this.#h(),r=n?.plan.layers.find(({id:t})=>t===e),i=n&&r&&this.#g(n,r);if(!n||!i||!this.#y(i))return;let a=this.#S(n,i);for(let{object:e,extension:r}of this.#x(i)){let o=r.body?.(a);if(!o)continue;let s=this.#T(n,i,o,r7(e),a.properties);return s&&Y5(o,n.toWorld,s,t)}}#O(e,t,n,r){let{layer:i,box:a,placement:o,boxToScreen:s}=t,{source:l}=i;if(l.kind!==`scene`)return;let{handles:u,registrations:d,describe:f}=this.#e,p=d.registrationOf(l.revision,e=>iI(a.clip,e))?.registration,m=In(En(i,e.seconds),e.plan.scenes.fps),h=e.settled.get(i.id)??i,g=Be(h,e.plan.stage),_=ose(g),v=u.of(i.id,l.revision,m,p,_);if(v.length===0||!p)return;let y=we(s,c(g,o.box)),b=Ft(y);if(!b)return;let x=f(a.clip)?.objects??[],S=t7(a.clip,this.#e.properties.getPreviewed().get(i.id)),ee=En(i,e.seconds),C=([e,t])=>ue(y,{x:e,y:t});for(let i of v){let a=p.objects.find(({id:e})=>e===i.object),o=x.find(({id:e})=>e===`object.${i.object}`);if(!a||!o)continue;let s=e=>J_e(p,a,o,e),c=e=>{let t=s(e);return t&&n7(S,t,ee)};if(i.bounds){let[e,t,r,a]=i.bounds;n.push({kind:`bounds`,corners:DI(y,{x:e,y:t,width:r,height:a})})}for(let o of i.handles){let l=this.#k(e,t,i,o,{name:a.name??a.id,onScreen:C,toScene:b,specOf:s,valueOf:c,shown:S,marks:n});l&&r.push(l)}}}#k(e,t,n,r,i){let{name:a,onScreen:o,toScene:s,specOf:c,valueOf:l,shown:u,marks:d}=i;if(`id`in r&&i7(r).some(e=>!c(e)))return;if(!(`id`in r)){if(r.kind===`circle`){let e=this.#A(o,r.at,r.radius);d.push({kind:`ring`,at:o(r.at),radius:e})}else d.push({kind:`line`,points:r.points.map(o),closed:!1});return}let f=o(r.at),p=r.kind===`move`?`point`:`scale`;if(r.kind===`rotate`){let e=(l(r.bind)??0)*Math.PI/180,[t,n]=r.at,i=this.#A(o,r.at,r.radius);d.push({kind:`ring`,at:o(r.at),radius:i}),f=o([t+Math.cos(e)*r.radius,n+Math.sin(e)*r.radius]),p=`knob`}let{layer:m}=t,h=r.kind===`scale`?I5(f.x-o(r.center).x,f.y-o(r.center).y):r.kind===`rotate`?`grab`:`move`;return{id:`${m.id} object ${n.object} ${r.id}`,role:`object`,detail:r.id,clip:m.id,object:a,at:f,look:p,angle:0,cursor:h,begin:n=>{let i=this.#T(e,t,r,c,u);return i&&Y5(r,s,i,n)}}}#A(e,[t,n],r){let i=e([t,n]),a=e([t+r,n]);return Math.hypot(a.x-i.x,a.y-i.y)}};function r7(e){let t=new Map(e.properties.map(e=>[e.path,e]));return e=>t.get(e)}function i7(e){let{bind:t}=e;return typeof t==`string`?[t]:[t.x,t.y].filter(e=>e!==void 0)}var a7=new WeakMap;function q_e(e){let t=a7.get(e);return t||(t=new Set(e.objects.flatMap(({id:e,properties:t})=>t.map(({path:t})=>gt(e,t)))),a7.set(e,t)),t}function J_e(e,t,n,r){let i=t.properties.findIndex(({path:e})=>e===r),a=t.properties[i],o=n.properties[i];if(!a||!o)return;if(o.path===gt(t.id,r))return o;let s=[r,...a.aliases??[]];return[...s.slice(1).map(e=>gt(t.id,e)),...(t.aliases??[]).flatMap(e=>s.map(t=>gt(e,t)))].includes(o.path)&&!q_e(e).has(o.path)?o:void 0}var Y_e=2e4;function X_e(e,t,n,r){let i=Q(e),a=jA(e),o=MA(e),s=O(i),c=s-O(o),l=Math.max(n+c,s),d=Math.min(r+c,O(a));if(!(d>=l))return[];let f=[],p=Math.max(Math.ceil(l*t.fps-1e-6),0),m=Math.min(Math.floor(d*t.fps+1e-6),p+Y_e);for(let e=p;e<=m;e+=1){let n=lq(e,t);if(D(n,i)<0||D(n,a)>=0)continue;let r=u(o,k(n,i));f.push({time:ze(r),clock:O(r)})}return f}var o7={burst:40,perSecond:40},Z_e=[];function Q_e(e){if(typeof requestAnimationFrame==`function`){let t=requestAnimationFrame(e);return()=>cancelAnimationFrame(t)}let t=setTimeout(e,16);return()=>clearTimeout(t)}var $_e=class{#e=new sv;#t=new sv;#n;#r;#i;#a;#o;#s;#c;#l=0;#u=!1;#d=o7.burst;#f;#p=new Set;constructor({schedule:e=Q_e,now:t,tooMany:n}={}){this.#n=e,this.#r=t??(()=>performance.now()),this.#i=n??(()=>{}),this.#f=this.#r()}subscribe=this.#e.subscribe;subscribeWanted=this.#t.subscribe;getVersion=()=>this.#l;get wanted(){return this.#a}want(e){e!==this.#a&&(this.#a=e,this.#d=o7.burst,this.#f=this.#r(),this.#t.emit())}note(e,t,n,r){if(e!==this.#a)return;if(!this.#h()){this.#g(e,t);return}let i={layer:e,revision:t,frame:n,raw:r};this.#s=i,this.#m(i)&&this.#_()}of(e,t,n,r,i){let a=this.#o;(a?.layer!==e||a.revision!==t||a.frame!==n)&&(this.#o={layer:e,revision:t,frame:n});let o=this.#s;if(!o||!r||!this.#m(o))return Z_e;let s=this.#c;if(s?.answer===o&&s.registration===r&&s.reach===i)return s.objects;let{objects:c}=mse(o.raw,r.objects,i);return this.#c={answer:o,registration:r,reach:i,objects:c},c}#m({layer:e,revision:t,frame:n}){let r=this.#o;return r?.layer===e&&r.revision===t&&r.frame===n}#h(){let e=this.#r(),t=Math.max(e-this.#f,0);this.#f=e;let n=this.#d+t/1e3*o7.perSecond;return this.#d=Math.min(n,o7.burst),this.#d<1?!1:(--this.#d,!0)}#g(e,t){let n=`${e}\n${t}`;this.#p.has(n)||(this.#p.add(n),this.#i(e,t))}#_(){this.#u||(this.#u=!0,this.#n(()=>{this.#u=!1,this.#l+=1,this.#e.emit()}))}};async function eve(e){let t=new OffscreenCanvas(e.width,e.height),n=t.getContext(`bitmaprenderer`);if(!n)throw Error(`No bitmap context`);return n.transferFromImageBitmap(e),t.convertToBlob({type:`image/png`})}function tve(e,t){return new Promise((n,r)=>{t.addEventListener(`abort`,()=>r(t.reason),{once:!0}),e.then(n,r)})}var nve=class{#e;constructor(e){this.#e=e}async run(){let{session:e,timeline:t,dialogs:n,notifications:r,t:i}=this.#e,{store:a}=e,{model:o,frame:s}=t;if(!a||!o)return;let c=a.getState(),l=XF(c,o.id);if(!l)return;let u=s/o.rate.fps,d=Z(c.timelines,o.id),f=(d?GF(d,l,void 0):[]).find(e=>Le(e,u));if(f){await this.#r(CJ(f),c);return}let p=n.progress({title:i(`export.frameRunning`),cancel:i(`dialog.cancel`),stopping:i(`export.frameStopping`)}),{signal:m}=p,h,g;try{h=this.#t(c,JG(a),l);let e=await tve(h.still(u),m),t=await(this.#e.encode??eve)(e);m.throwIfAborted();let n=i(`export.frameFile`,{name:c.manifest.name,frame:s,interpolation:{escapeValue:!1}});this.#e.folders.saveFile(t,n),r.push(i(`export.frameDone`,{file:n,interpolation:{escapeValue:!1}}))}catch(e){g=e}finally{h?.dispose(),p.close()}m.aborted?r.push(i(`export.frameCancelled`)):g!==void 0&&await this.#n(g,c)}#t(e,t,n){let r=Zq(this.#e,e,t,n);return this.#e.compositor?.(r)??new Xq(r)}async#n(e,t){e instanceof Tt||console.warn(`No still`,e),await this.#r(xt(e),t)}async#r(e,t){let{dialogs:n,t:r}=this.#e;await n.confirm({title:r(`export.frameFailed`),message:TJ(r,e,t,this.#e.timeline),confirm:r(`dialog.close`),noticeOnly:!0})}};function s7(e){let t=document.createElement(`iframe`);t.setAttribute(`sandbox`,`allow-scripts`),t.tabIndex=-1,t.hidden=!0,t.title=``;let n=new Promise(e=>{let n=r=>{r.source===t.contentWindow&&r.data.type===`ready`&&(removeEventListener(`message`,n),e())};addEventListener(`message`,n)});return t.src=e,document.body.append(t),{frame:t,ready:n}}var rve=6e4,c7=e=>Math.min(Math.max(Math.ceil(e??0),8),30),ive=class{#e;#t;#n=0;constructor(e){this.#e=e}async make(e,t){this.#t??=s7(this.#e);let{frame:n,ready:r}=this.#t;await r,this.#n+=1;let i=this.#n;return new Promise(r=>{let a=e=>{clearTimeout(o),removeEventListener(`message`,s),r(e)},o=setTimeout(()=>a(void 0),rve),s=e=>{if(e.source!==n.contentWindow)return;let{data:t}=e;t.type===`strip`&&t.request===i&&a(t.image)};addEventListener(`message`,s);let c={type:`strip`,request:i,file:e,count:t,height:54};n.contentWindow?.postMessage(c,`*`)})}};async function ave(e){let t=new OffscreenCanvas(e.width,e.height);return t.getContext(`2d`)?.drawImage(e,0,0),t.convertToBlob({type:`image/webp`,quality:.7})}var l7=e=>`peaks-1:${e}`,u7=e=>`strip-1:${e}`,d7=2*1024**3,f7=e=>e instanceof ba?e.reason===`too-long`||e.reason===`full`?e.reason:e.reason===`denied`||e.reason===`gone`?`folder`:`other`:`other`,p7=1024**3;async function m7(e,t,n){let r=await e.fileAt(t);return r.kind===`there`&&eq(r.hash,n)}async function h7(e){let t=await crypto.subtle.digest(`SHA-256`,await e.arrayBuffer());return YK(new Uint8Array(t))}var g7=e=>/\.([A-Za-z0-9]{1,8})$/.exec(e)?.[1]?.toLowerCase();function _7(e){let{duration:t,width:n,height:r,fps:i,sampleRate:a,hasAudio:o}=e;return{...t?{duration:ze(We(t))}:{},...n?{width:n}:{},...r?{height:r}:{},...i?{fps:String(Number(i.toFixed(3)))}:{},...a?{sampleRate:a}:{},...o===void 0?{}:{hasAudio:o}}}var ove=class{#e;#t;#n;#r=new sv;#i=new Map;#a=new Map;#o=Promise.resolve();#s=new Map;#c=Promise.resolve();#l;#u=new Set;#d;#f=0;#p;#m;#h=0;constructor(e,t,n,r,i=()=>void 0){this.#l=new ive(r),this.#e=e,this.#t=t,this.#n=n,this.#p=i,e.subscribe(()=>this.#g())}subscribe=this.#r.subscribe;getImporting=()=>this.#f;getCopying=()=>this.#m;getRestored=()=>this.#h;onRestored(e){return this.#u.add(e),()=>this.#u.delete(e)}#g(){if(this.#e.store!==this.#d){this.#d=this.#e.store,this.#m?.stop();for(let e of this.#i.keys())this.#A(e);this.#a.clear();for(let e of this.#s.values())e?.image.close();this.#s.clear()}}stripOf(e){let t=this.#d,n=t?.getState().assets?.[e];if(!t||n?.kind!==`video`||n.hash===void 0)return;let{hash:r}=n;if(!this.#s.has(r)){this.#s.set(r,void 0);let e=n.info?.duration,i=e===void 0?0:O(j(e));this.#c=this.#c.then(()=>this.#_(t,r,i))}return this.#s.get(r)}stripOfClip(e){let{media:t}=e.source;return t?.asset===void 0?void 0:this.stripOf(t.asset)}async#_(e,t,n){try{let r=await this.#v(e,t,c7(n));if(!r)return;if(e!==this.#d){r.close();return}this.#s.set(t,{image:r,count:c7(n),duration:n}),this.#r.emit()}catch(e){console.warn(`No frames for this video`,e)}}async#v(e,t,n){let r=this.#D(e),i=await r.get(u7(t));if(i)return createImageBitmap(i);let a=await r.get(t),o=a&&await this.#l.make(a,n);return o&&await r.put(u7(t),await ave(o)),o}#y(e,t){let n=e.getState();if(t.source.kind===`sound`)return NF(n,t)?.file;let{media:r}=t.source;return r?.asset===void 0?void 0:n.assets?.[r.asset]?.hash}peaksOfAsset(e){return this.peaksOf({source:{kind:`audio`,media:{asset:e}}})}peaksOf(e){let t=this.#d,n=t&&this.#y(t,e);if(t&&n!==void 0)return this.#a.has(n)||(this.#a.set(n,void 0),this.#o=this.#o.then(()=>this.#b(t,n))),this.#a.get(n)}async#b(e,t){try{let n=await this.#x(e,t);if(e!==this.#d||!n)return;this.#a.set(t,n),this.#r.emit()}catch(e){console.warn(`No waveform`,e)}}async#x(e,t){let n=this.#D(e),r=await n.get(l7(t));if(r)return new Uint8Array(await r.arrayBuffer());let i=await n.get(t);if(!i)return;let a=await lne(jb(i,0,1/0));return await n.put(l7(t),new Blob([a])),a}soundArrived(e){this.#a.delete(e),this.#r.emit()}pickFiles(){return new Promise(e=>{let t=document.createElement(`input`);t.type=`file`,t.multiple=!0,t.accept=`video/*,audio/*,image/*`,t.addEventListener(`change`,()=>{this.importFiles([...t.files??[]]).then(e)}),t.addEventListener(`cancel`,()=>e([])),t.click()})}chooseFile(e){return new Promise(t=>{let n=document.createElement(`input`);n.type=`file`,n.accept=e===`video`||e===`audio`||e===`image`?`${e}/*`:``,n.addEventListener(`change`,()=>t(n.files?.[0])),n.addEventListener(`cancel`,()=>t(void 0)),n.click()})}async hasFile(e){let t=this.#d,n=t?.getState().assets?.[e];return!t||!n?!1:n.storage===`remote`||n.hash!==void 0&&await this.#D(t).get(n.hash)!==void 0}async replaceFile(e,t){let n=this.#d,r=n?.getState().assets?.[e];if(!n||!r)return!1;let i=this.#p(),a,o;if(`path`in t){let e=i&&await i.fileAt(t.path);if(e?.kind!==`there`)return this.#n.readFailed(t.path),!1;a=e.file,o={path:t.path,hash:e.hash}}else a=t.file;let s=await oq(a);if(!s)return this.#n.unsupported(a.name),!1;if(s.kind!==r.kind)return this.#n.otherKind(a.name),!1;try{i?o??=await this.#C(n,i,a):o=await this.#S(n,e,r,a)}catch(e){return console.warn(`A file could not be taken for an asset`,e),this.#n.saveFailed(a.name),!1}if(!o||this.#e.store!==n)return!1;let c=n.execute({type:`asset.update`,params:{asset:e,changes:{path:o.path,hash:o.hash,size:a.size,info:_7(s)}}});return c.ok?(this.filesChanged([r.path,o.path]),!0):(this.#n.commandFailed(c.error.message),!1)}async#S(e,t,n,r){if(r.size>d7){this.#n.tooLarge(r.name);return}let i=await h7(r);await this.#D(e).put(i,r);let a=g7(r.name);return{path:g7(n.path)===a?n.path:`assets/${t}${a?`.${a}`:``}`,hash:i}}async#C(e,t,n){if(n.size>=p7&&!await this.#n.confirmCopy(n.name,n.size))return;let r=new AbortController,i=e=>{let t=n.size>0?Math.floor(e/n.size*100):100;this.#m?.percent!==t&&(this.#m={name:n.name,stage:`copying`,percent:t,stop:()=>r.abort()},this.#r.emit())};try{i(0);let a=await t.copyIn(n,{signal:r.signal,onProgress:i});if(this.#e.store!==e){await t.remove(a.path,a.written);return}return{path:a.path,hash:a.hash}}catch(e){if(r.signal.aborted)return;this.#n.copyFailed(n.name,f7(e));return}finally{this.#m=void 0,this.#r.emit()}}async importFiles(e){let t=this.#e.store,n=[];this.#w(this.#f+e.length);for(let[r,i]of e.entries()){if(this.#e.store!==t){this.#w(this.#f-(e.length-r));break}let a=await this.#T(i);a!==void 0&&this.#e.store===t&&n.push(a),this.#w(this.#f-1)}return n}#w(e){this.#f=e,this.#r.emit()}async importPaths(e){let t=this.#e.store,n=this.#p();if(!t||!n)return[];let r=[];this.#w(this.#f+e.length);for(let i of e)try{if(this.#e.store!==t)continue;let e=await n.fileAt(i);if(e.kind!==`there`){this.#n.readFailed(i);continue}let a=await oq(e.file);if(!a){this.#n.unsupported(e.file.name);continue}if(this.#e.store!==t)continue;let o=this.#k(t,e.file,i,e.hash,a);o!==void 0&&r.push(o)}finally{this.#w(this.#f-1)}return r}async#T(e){let t=this.#e.store;if(!t)return;let n=this.#p();if(n)return this.#O(t,n,e);if(e.size>d7){this.#n.tooLarge(e.name);return}let r=await oq(e);if(!r){this.#n.unsupported(e.name);return}let i=await h7(e),a=Object.entries(t.getState().assets??{}).filter(([,e])=>e.hash!==void 0&&eq(e.hash,i));try{if(a.length>0)return await this.#E(t,a,e),a[0]?.[0];await this.#D(t).put(i,e)}catch(t){console.warn(`A file could not be saved`,t),this.#n.saveFailed(e.name);return}let o=xD(`asset`),s=g7(e.name),c={name:e.name,kind:r.kind,path:`assets/${o}${s?`.${s}`:``}`,storage:`local`,hash:i,size:e.size,info:_7(r)},l=t.execute({type:`asset.add`,params:{id:o,asset:c}});if(l.ok)return o;this.#n.commandFailed(l.error.message)}async#E(e,t,n){let r=this.#D(e);for(let[e,{hash:i}]of t)if(!(i===void 0||await r.get(i))){await r.put(i,n),this.#A(e),this.#a.delete(i),this.#s.delete(i),this.#h+=1;for(let e of this.#u)e(i);this.#r.emit()}}#D(e){return this.#t.media(JG(e))}async#O(e,t,n){let r=await oq(n);if(!r){this.#n.unsupported(n.name);return}let i=new AbortController,{signal:a}=i,o=(e,t)=>{let r=n.size>0?Math.floor(t/n.size*100):100,a=this.#m;(a?.stage!==e||a.percent!==r||a.name!==n.name)&&(this.#m={name:n.name,stage:e,percent:r,stop:()=>i.abort()},this.#r.emit())};try{let i=Object.entries(e.getState().assets??{}).filter(([,e])=>e.size===n.size&&e.hash!==void 0);if(i.length>0){o(`checking`,0);let e=await t.hashOutside(n,{signal:a,onProgress:e=>o(`checking`,e)}),r=i.find(([,t])=>eq(t.hash,e));if(r&&await m7(t,r[1].path,e))return r[0]}if(this.#m=void 0,this.#r.emit(),n.size>=p7&&!await this.#n.confirmCopy(n.name,n.size))return;o(`copying`,0);let s=await t.copyIn(n,{signal:a,onProgress:e=>o(`copying`,e)});if(this.#e.store!==e){await t.remove(s.path,s.written);return}let c=Object.entries(e.getState().assets??{}).find(([,e])=>e.hash!==void 0&&eq(e.hash,s.hash));if(!c)return this.#k(e,n,s.path,s.hash,r);let[l,u]=c;if(await m7(t,u.path,s.hash))return await t.remove(s.path,s.written),l;let d=e.execute({type:`asset.update`,params:{asset:l,changes:{path:s.path}}});return d.ok||this.#n.commandFailed(d.error.message),this.filesChanged([s.path,u.path]),l}catch(e){if(a.aborted)return;console.warn(`A file could not be copied into the project folder`,e),this.#n.copyFailed(n.name,f7(e));return}finally{this.#m=void 0,this.#r.emit()}}#k(e,t,n,r,i){let a=Object.entries(e.getState().assets??{}).find(([,e])=>e.path===n);if(a)return a[0];let o=xD(`asset`),s={name:t.name,kind:i.kind,path:n,storage:`local`,hash:r,size:t.size,info:_7(i)},c=e.execute({type:`asset.add`,params:{id:o,asset:s}});if(c.ok)return o;this.#n.commandFailed(c.error.message)}async useNewFile(e){let t=this.#d,n=this.#p(),r=t?.getState().assets?.[e];if(!t||!n||!r)return!1;let i=r.name??r.path,a=await n.fileAt(r.path);if(a.kind!==`there`)return this.#n.readFailed(r.path),!1;let o=await oq(a.file);if(!o)return this.#n.unsupported(i),!1;if(o.kind!==r.kind)return this.#n.otherKind(i),!1;let s=t.execute({type:`asset.update`,params:{asset:e,changes:{hash:a.hash,size:a.file.size,info:_7(o)}}});return s.ok?(this.filesChanged([r.path]),!0):(this.#n.commandFailed(s.error.message),!1)}async usePlace(e,t){let n=this.#d,r=this.#p(),i=n?.getState().assets?.[e];if(!n||!r||!i?.hash)return!1;let a=await r.fileAt(t);if(a.kind!==`there`||!eq(a.hash,i.hash))return this.#n.readFailed(t),!1;let o=n.execute({type:`asset.update`,params:{asset:e,changes:{path:t}}});return o.ok?(this.filesChanged([t]),!0):(this.#n.commandFailed(o.error.message),!1)}filesChanged(e){let t=this.#d;if(!t)return;let n=new Set(e),r=new Set;for(let[e,i]of Object.entries(t.getState().assets??{})){if(!n.has(i.path))continue;this.#A(e);let{hash:t}=i;t!==void 0&&(r.add(t),this.#a.has(t)&&this.#a.get(t)===void 0&&this.#a.delete(t),this.#s.has(t)&&this.#s.get(t)===void 0&&this.#s.delete(t))}if(r.size!==0){this.#h+=1;for(let e of r)for(let t of this.#u)t(e);this.#r.emit()}}#A(e){let t=this.#i.get(e);t&&(this.#i.delete(e),t.url.then(e=>e&&URL.revokeObjectURL(e)))}urlOf(e){let t=this.#e.store?.getState().assets?.[e],n=`${t?.hash??``}\n${t?.path??``}`,r=this.#i.get(e);if(r?.key===n)return r.url;this.#A(e);let i=this.#j(e);return this.#i.set(e,{key:n,url:i}),i}async#j(e){let t=this.#e.store,n=t?.getState().assets?.[e]?.hash;if(!t||!n)return;let r=await this.#D(t).get(n);return r&&URL.createObjectURL(r)}},sve={maxAgeMs:6048e5,maxBytes:500*1024**2},cve=e=>e.replace(/^peaks-\d+:/,``);async function lve(e,t,n,r=sve){let i=(await e.listMade()).filter(({name:e})=>ya(e)),a=i.reduce((e,{size:t})=>e+t,0),o=i.filter(({name:e})=>!t(e)&&!t(cve(e))).toSorted((e,t)=>e.usedAt-t.usedAt),s=[];for(let{name:t,size:i,usedAt:c}of o)if(!(n-c<=r.maxAgeMs&&a<=r.maxBytes))try{await e.removeMade(t),a-=i,s.push(t)}catch(e){console.warn(`A made file could not be removed`,e)}return s}var uve=500,dve=3,fve=class{#e;#t;#n;#r=0;constructor(e){this.#e=e}#i(){if(!this.#t||!this.#n){let e=s7(this.#e.url);this.#t=e,this.#n=e.ready.then(()=>this.#a(e.frame,{type:`setup`,...this.#e.setup()}))}return{frame:this.#t.frame,started:this.#n}}#a(e,t){e.contentWindow?.postMessage(t,`*`)}#o(e){e.remove(),this.#t?.frame===e&&(this.#t=void 0,this.#n=void 0)}run=(e,t)=>{let{frame:n,started:r}=this.#i();this.#r+=1;let i=this.#r,{promise:a,resolve:o}=Promise.withResolvers(),s=e=>{clearTimeout(c),removeEventListener(`message`,l),o(e)},c=setTimeout(()=>{this.#o(n),s({ok:!1,reason:`silent`})},e.limitMs+on*3),l=r=>{if(r.source!==n.contentWindow)return;let{data:a}=r;if(a.type===`origin-retired`)this.#e.onRetired(a.origin);else if(a.type===`sound-problem`&&a.request===i)t(a.problem);else if(a.type===`sound-failed`&&a.request===i)s({ok:!1,reason:a.reason});else if(a.type===`sound-done`&&a.request===i){let t=zt({...a,type:`samples`},e);s(t?{ok:!0,...t}:{ok:!1,reason:`bad-result`})}};return addEventListener(`message`,l),r.then(()=>this.#a(n,{type:`sound-make`,request:i,load:e})),{outcome:a,cancel:()=>{this.#a(n,{type:`sound-cancel`,request:i}),s(void 0)},release:()=>this.#a(n,{type:`sound-release`,request:i})}}},v7=(e,t)=>`${e}\n${t}`,pve=class{#e;#t=new sv;#n=new Map;#r=new Map;#i=new Map;#a;#o=()=>{};#s;#c;#l=0;constructor(e){this.#e=e,e.session.subscribe(()=>this.#p()),this.#p()}subscribe=this.#t.subscribe;getVersion=()=>this.#l;retry(e){let t=this.#a&&NF(this.#a.getState(),e);t&&this.#n.get(t.file)?.state===`failed`&&(this.#n.delete(t.file),this.#l+=1,this.#t.emit(),this.#_())}cleaned=Promise.resolve();stateOf(e){let t=this.#a&&NF(this.#a.getState(),e);return t&&(this.#n.get(t.file)??{state:`waiting`})}whenMade(e,t,n,r){let i=this.#u(n)?this.#n.get(e.file):void 0;if(i?.state===`ready`||i?.state===`failed`)return Promise.resolve(i);if(r?.aborted)return Promise.reject(r.reason);let{promise:a,resolve:o,reject:s}=Promise.withResolvers(),c=v7(n,e.file),l=this.#i.get(c);l||(l={key:c,made:e,state:t,project:n,waiters:new Set},this.#i.set(c,l));let u=l;return u.waiters.add(o),r?.addEventListener(`abort`,()=>{s(r.reason),u.waiters.delete(o),u.waiters.size>0||this.#i.get(c)!==u||(this.#i.delete(c),this.#c?.hold===u&&this.#c.cancel())}),this.#_(),a}#u(e){return this.#a!==void 0&&JG(this.#a)===e}#d(e,t){this.#n.set(e,t),this.#l+=1,this.#t.emit()}#f({made:e,project:t},n){let r=v7(t,e.file),i=this.#i.get(r);if(i){this.#i.delete(r);for(let e of i.waiters)e(n)}}#p(){let{store:e}=this.#e.session;e!==this.#a&&(this.#o(),this.#c?.hold||(this.#c?.cancel(),this.#c=void 0),this.#n.clear(),this.#r=new Map,this.#a=e,this.#o=e?.subscribe(this.#h)??(()=>{}),this.#g(),e&&(this.cleaned=this.#m(e)))}async#m(e){let t=e.getState(),n=new Set;for(let e of Object.keys(t.timelines))for(let{file:r}of PF(t,e))n.add(r);for(let e of Object.values(t.assets??{}))e.hash!==void 0&&n.add(e.hash);let r=JG(e);for(let{made:e,project:t}of this.#i.values())t===r&&n.add(e.file);let i=this.#e.projects.media(r),a=this.#e.now?.()??Date.now();try{await lve(i,e=>n.has(e),a,this.#e.cacheRules)}catch(e){console.warn(`Sounds that nobody needs could not be cleaned up`,e)}}#h=()=>{clearTimeout(this.#s),this.#s=setTimeout(this.#g,this.#e.followDelayMs??uve)};#g=()=>{let e=this.#a?.getState();if(!e)return;let t=new Map;for(let n of Object.keys(e.timelines))for(let r of PF(e,n))t.set(r.file,r);this.#r=t;for(let e of this.#n.keys())t.has(e)||this.#n.delete(e);this.#c&&!this.#c.hold&&!t.has(this.#c.file)&&this.#c.cancel(),this.#l+=1,this.#t.emit(),this.#_()};#_(){if(this.#c)return;let[e]=this.#i.values();if(e){this.#v({made:e.made,state:e.state,project:e.project,hold:e});return}let t=this.#a,n=[...this.#r.values()].find(({file:e})=>!this.#n.has(e));n&&t&&(this.#n.set(n.file,{state:`waiting`}),this.#v({made:n,state:t.getState(),project:JG(t),store:t}))}#v(e){let t={file:e.made.file,...e.hold&&{hold:e.hold},cancel:()=>{}};this.#c=t,this.#S(e,t).catch(t=>{console.warn(`A sound could not be made`,t),this.#y(e)&&this.#x(e,`error`)}).finally(()=>{this.#c===t&&(this.#c=void 0,this.#_())})}#y({made:e,store:t,hold:n}){return n?this.#i.get(n.key)===n:this.#a===t&&this.#r.has(e.file)}#b(e){let{made:t,project:n}=e;this.#f(e,{state:`ready`}),this.#u(n)&&this.#r.has(t.file)&&(this.#d(t.file,{state:`ready`}),this.#e.arrived(t.file))}#x(e,t,n=!1){let{made:r,project:i}=e;this.#f(e,{state:`failed`,reason:t}),this.#u(i)&&(this.#r.has(r.file)&&this.#d(r.file,{state:`failed`,reason:t}),n||this.#e.messages.failed(r.sound,t))}async#S(e,t){let{made:n,state:r,project:i}=e,{file:a}=n,o=this.#e.projects.media(i),s=()=>this.#y(e),c=()=>this.#u(i),l=await o.get(a).catch(()=>void 0);if(!s())return;if(l){o.touchMade(a).catch(()=>{}),this.#b(e);return}if(n.runtime>1){this.#x(e,`too-new`);return}if(n.duration>300){this.#x(e,`over-limit`);return}c()&&this.#r.has(a)&&this.#d(a,{state:`making`});let u=0,d=this.#e.run(this.#w(r,n),e=>{u+=1,u<=dve&&c()&&this.#e.messages.problem(n.sound,e)});t.cancel=d.cancel;let f=await d.outcome;if(!f||!s())return;if(!f.ok){this.#x(e,f.reason,f.reason===`error`&&u>0);return}let p;try{p=await hne(f.samples,f.channels,f.frames,n.sampleRate)}finally{d.release()}if(!c()&&!await this.#C(i))this.#x(e,`error`);else{try{await o.put(a,p)}catch(t){console.warn(`A sound could not be saved`,t),this.#x(e,`save`);return}s()&&this.#b(e)}}async#C(e){return(await this.#e.projects.list().catch(()=>void 0))?.some(({id:t})=>t===e)??!1}#w(e,t){let n=HP(e,t.sound),{entry:r,duration:i,sampleRate:a,seed:o,params:s,output:c}=t;return{entry:r,files:new Map(n.map(t=>[t,new Blob([Z(e.files,t)??``])])),duration:i,frames:Math.max(Math.round(i*a),1),sampleRate:a,maxChannels:2,seed:o,params:s,...c!==void 0&&{output:c},limitMs:this.#e.limitMs??6e4}}},y7=500,b7={problems:[],errors:0,warnings:0,imported:!1},mve=({kind:e})=>e===`error`||e===`rejection`?`error`:`warning`,hve=({severity:e,text:t,file:n,line:r,column:i,place:a})=>JSON.stringify([e,t,n,r,i,a]),x7=e=>({...e,id:hve(e)});function gve(e,t){return e.file===void 0==(t.file===void 0)?(e.file??``).localeCompare(t.file??``)||(e.line??0)-(t.line??0)||(e.column??0)-(t.column??0):e.file===void 0?1:-1}var _ve=class{#e=new sv;#t=new Map;#n=new Map;#r=new Map;#i=[];#a=[];#o=[];#s=b7;subscribe=this.#e.subscribe;getSnapshot=()=>this.#s;#c(){let e=new Map,t=t=>{e.has(t.id)||e.set(t.id,t)};for(let{problem:e}of this.#t.values())t(e);for(let e of this.#n.values())t(e);for(let e of this.#r.values())e.forEach(t);this.#i.forEach(t),this.#a.forEach(t),this.#o.forEach(t);let n=[...e.values()].toSorted(gve),r=n.filter(({severity:e})=>e===`error`).length;this.#s={problems:n,errors:r,warnings:n.length-r,imported:this.#i.length>0},this.#e.emit()}noteScene(e,t,n){let r=x7(n),i=this.#t.get(r.id);i?i.clips.set(e,t):this.#t.size>=y7||(this.#t.set(r.id,{problem:r,clips:new Map([[e,t]])}),this.#c())}keepRevisions(e){let t=!1;for(let[n,{clips:r}]of this.#t){for(let[t,n]of r)e.get(t)!==n&&r.delete(t);r.size===0&&(this.#t.delete(n),t=!0)}for(let n of this.#n.keys())e.has(n)||(t=this.#n.delete(n)||t);t&&this.#c()}noteStopped(e,t){if(t)this.#n.set(e,x7(t));else if(!this.#n.delete(e))return;this.#c()}setFile(e,t){(t.length!==0||this.#r.has(e))&&(t.length>0?this.#r.set(e,t.slice(0,y7).map(x7)):this.#r.delete(e),this.#c())}setProperties(e){if(e.length===0&&this.#a.length===0)return;let t=e.slice(0,y7).map(x7),n=t.length===this.#a.length&&t.every((e,t)=>e.id===this.#a[t]?.id);this.#a=t,n&&t.every(e=>e.action===void 0)||this.#c()}setFolder(e){(e.length!==0||this.#o.length!==0)&&(this.#o=e.slice(0,y7).map(x7),this.#c())}noteImport(e){this.#i=e.slice(0,y7).map(x7),this.#c()}clearImport(){this.#i.length!==0&&(this.#i=[],this.#c())}clear(){this.#t.clear(),this.#n.clear(),this.#r.clear(),this.#i=[],this.#a=[],this.#o=[],this.#s!==b7&&(this.#s=b7,this.#e.emit())}},S7=1e3,vve=1e3,yve=.9,bve=250,xve=class{#e=[];#t=-1/0;add(e,t){for(let n of t)Number.isFinite(n)&&n>=0&&this.#e.push(e-n);this.#e.sort((e,t)=>e-t),this.#t=Math.max(this.#t,e);let n=e-2*S7,r=this.#e.findIndex(e=>e>n);this.#e=r===-1?[]:this.#e.slice(r)}read(e,t,n){let r=e-this.#t>1e3?e:Math.min(this.#t,e),i=Math.max(r-S7,t),a=r-i;if(a<bve||!(n>0))return;let o=0;for(let e of this.#e)e>i&&e<=r&&(o+=1);let s=Math.round(o*1e3/a);return{painted:s,fps:n,dropped:Math.max(Math.round(n*a/1e3-o),0),short:s<n*yve}}},Sve=(e,t)=>e===t||e!==void 0&&t!==void 0&&e.painted===t.painted&&e.fps===t.fps&&e.dropped===t.dropped,Cve=class{#e=new sv;#t;#n;#r=[];#i;#a;#o={state:`none`};constructor(e,t=()=>performance.now()){this.#t=e,this.#n=t,e.subscribe(this.#s)}subscribe=this.#e.subscribe;getSnapshot=()=>this.#o;attach(){let e={window:new xve};return this.#r.push(e),this.#s(),{painted:t=>e.window.add(this.#n(),t),dispose:()=>{this.#r=this.#r.filter(t=>t!==e),this.#s()}}}#s=()=>{this.#t.getSnapshot().playing&&this.#r.length>0?this.#i===void 0&&(this.#i=this.#n(),this.#l({state:`playing`,reading:void 0}),this.#a=setInterval(this.#c,vve)):(this.#i=void 0,clearInterval(this.#a),this.#a=void 0,this.#l(this.#r.length>0?{state:`paused`}:{state:`none`}))};#c=()=>{let e=this.#r.at(-1),t=this.#t.getSnapshot().model?.rate.fps;if(!e||this.#i===void 0||t===void 0)return;let n=e.window.read(this.#n(),this.#i,t),r=this.#o;r.state===`playing`&&Sve(r.reading,n)||this.#l({state:`playing`,reading:n})};#l(e){(this.#o.state!==e.state||e.state===`playing`)&&(this.#o=e,this.#e.emit())}},wve=({state:e})=>e!==`ready`&&e!==`closed`,Tve=class{#e=new sv;#t;#n=new Map;#r=new Set;#i=new Yt(un.strikes,un.forgiveAfterMs);#a={compositor:`running`,generation:0,runScenes:!0,scenes:new Map};constructor(e){this.#t=e}subscribe=this.#e.subscribe;getSnapshot=()=>this.#a;#o(e){this.#a={...this.#a,...e},this.#e.emit()}worked(){this.#i.worked(performance.now()),this.#a.compositor!==`running`&&this.#o({compositor:`running`})}hung(e=`running`){let{generation:t}=this.#a;e===`hello`?this.#o({compositor:`unreachable`,scenes:new Map}):this.#i.hung(performance.now())?(this.#o({compositor:`restarting`,generation:t+1,scenes:new Map}),this.#t.restarted()):this.#o({compositor:`stopped`,scenes:new Map})}restart({runScenes:e=this.#a.runScenes}={}){this.#i=new Yt(un.strikes,un.forgiveAfterMs);let{generation:t}=this.#a;this.#o({compositor:`running`,generation:t+1,runScenes:e,scenes:new Map})}noteScene(e,t){t.state===`opening`&&this.#n.delete(e),this.#t.stopped(e,t.state===`stopped`?t:void 0);let n=new Map(this.#a.scenes);if(wve(t))n.set(e,t);else if(!n.delete(e))return;this.#o({scenes:n})}forgetScenes(){this.#a.scenes.size>0&&this.#o({scenes:new Map})}get retiredOrigins(){return[...this.#r]}noteRetired(e){this.#r.add(e)}noteProblem(e,t,n){let r=this.#n.get(e)!==t;this.#n.set(e,t),this.#t.problem(e,t,n,r)}noteRevisions(e){this.#t.revisions(e)}},C7=300,w7=e=>({...e,interpolation:{escapeValue:!1}});function Eve(e){let t=e.find(e=>e.kind===`object`&&e.orphans);return t?.kind===`object`?t.children.flatMap(e=>e.kind===`property`?[e.spec.path]:[]):[]}function Dve(e){return e.objects.flatMap(({properties:e})=>e)}function Ove(e,t,r,i){let a=[],o=Object.values(Z(e.timelines,t)?.clips??{}),s=new Set;for(let t of o){if(a.length>=C7)break;let{source:o}=t;if(o.kind!==`scene`||typeof o.scene!=`string`)continue;let c=r.clipName(t),l=r.describe(t);if(!l)continue;let u=e=>({target:{clip:t.id,path:e},place:e});for(let e of Eve(xI(t,l).children)){if(!n(e))continue;let t=i(`problems.properties.${e.startsWith(`element.`)?`orphanElement`:`orphan`}`,w7({path:e}));a.push({severity:`warning`,text:t,origin:c,...u(e)})}for(let{from:e,to:n}of l.renames??[]){let o=i(`problems.properties.renamed`,w7({from:e,to:n})),s={label:i(`problems.properties.migrate`),run:()=>r.rename(t.id,e,n)};a.push({severity:`warning`,text:o,origin:c,...u(e),action:s})}let d=FF(t);for(let e of Dve(l)){if(!n(e.path))continue;let t=Z(d,e.path);if(t===void 0||Ht(t,e.type)!==void 0)continue;let r=i(`problems.properties.types.${e.type}`),o=i(`problems.properties.mismatch`,w7({path:e.path,type:r}));a.push({severity:`warning`,text:o,origin:c,...u(e.path)})}if(s.has(o.scene))continue;s.add(o.scene);for(let t of Z(e.scenes,o.scene)?.params??[]){if(Ge(t.id))continue;let e=i(`problems.properties.param`,w7({name:t.name}));a.push({severity:`warning`,text:e,origin:c})}let f=qP(e,o.scene)?.revision;for(let{code:e,target:t=``}of f?r.registered(f):[]){let n=i(`scene.problems.codes.${e}`,w7({target:t}));a.push({severity:`warning`,text:n,origin:c})}}return a.slice(0,C7)}var T7=`trial`,E7=1,D7=new Map,O7=new Map;function k7(e){if(typeof e!=`object`||!e)return;let{version:t,enabled:n}=e;return t===E7&&typeof n==`boolean`?n:void 0}var kve=class{#e;#t;#n;#r;#i;#a=new sv;#o={enabled:!0,count:0,conflicts:0,setAside:0,comparing:!1};#s;#c;#l;#u=O7;#d=O7;#f=D7;#p=Promise.resolve();constructor(e,t,n,r,i){this.#e=e,this.#t=t,this.#n=n,this.#r=r,this.#i=i,e.subscribe(()=>this.#m()),this.#m()}subscribe=this.#a.subscribe;getSnapshot=()=>this.#o;async load(){let e=await xX(this.#r,T7,k7);e.kind===`ok`&&this.#_({enabled:e.value}),this.#r.listen(T7,e=>{let t=k7(e);t!==void 0&&this.#_({enabled:t})})}setEnabled(e){this.#_({enabled:e}),this.#r.save(T7,{version:E7,enabled:e}).catch(e=>console.warn(`The setting could not be saved`,e))}get takesEdits(){let{enabled:e,count:t}=this.#o;return this.#c!==void 0&&(e||t>0)}get look(){return this.#o.comparing?void 0:this.#c}getValues=()=>this.#o.comparing?D7:this.#f;get notKept(){let e=this.#l,{count:t,setAside:n}=this.#o;return e!==void 0&&t+n>0&&(e.failed||e.isBusy)}write(e){let t=this.#c?.write(e);return t&&!t.ok&&this.#i.commandFailed(t.error.message),t?.ok&&this.#_({comparing:!1}),t?.ok===!0}save(){let e=this.#l;e?.pause();let t=this.#c?.save();return t?.ok===!1&&this.#i.commandFailed(t.error.message),t?.ok&&t.overwritten>0&&this.#i.overwrote(t.overwritten),t?.ok===!0&&this.#e.hasUnsavedChanges||e?.resume(),t?.ok!==!1}discard(){let{count:e,setAside:t}=this.#o;e+t!==0&&(this.#c?.discard(),this.#i.discarded(e+t))}discardProperty(e,t){this.#c?.discard({clip:e,path:t})}toggleCompare(){let{comparing:e,count:t}=this.#o;(t>0||e)&&this.#_({comparing:!e})}get canUndo(){return this.#c?.canUndo===!0}get canRedo(){return this.#c?.canRedo===!0}get undoesFirst(){return this.#c?.undoesFirst===!0}get redoesFirst(){return this.#c?.redoesFirst===!0}undo(){this.#c?.undo(),this.#_({comparing:!1})}redo(){this.#c?.redo(),this.#_({comparing:!1})}async settle(){return await this.#l?.settled()!==!1}#m(){let{store:e}=this.#e;if(e===this.#s){this.#e.hasUnsavedChanges||this.#l?.resume();return}this.#c?.dispose(),this.#p=this.#l?.close()??this.#p,this.#s=e,this.#c=void 0,this.#l=void 0;let t=this.#t.model?.id,n=e&&t!==void 0?this.#h(e,t):void 0;this.#u=n?.changes??O7,this.#d=n?.kept??O7,this.#f=D7,this.#_({count:0,conflicts:0,setAside:0,comparing:!1},!0)}#h(e,t){let n=new zG(e,t),r=JG(e),i=this.#p,a=()=>i.then(()=>this.#n.open(r));this.#c=n,n.subscribe(()=>this.#v()),n.onNotice(e=>this.#g(e));let o=new Q8(()=>n.toStored(),a,this.#i,e=>{let{restored:t,dropped:r,stale:i,unreadable:a}=n.restore(e);t>0&&this.#i.restored(t),(r>0||a)&&this.#i.dropped(r),(r>0||a||i>0)&&o.keep()});return this.#l=o,n}#g(e){e.kind===`aside`?this.#i.setAside(e.count):e.kind===`back`?this.#i.back(e.count):e.kind===`dropped`?this.#i.asideDropped(e.count):this.#i.unsure()}#_(e,t=!1){let n=this.#o,r={...n,...e},i=Object.keys(r);(t||!i.every(e=>r[e]===n[e]))&&(this.#o=r,this.#a.emit())}#v(){let e=this.#c,t=e?.changes??O7,n=e?.kept??O7,r=t!==this.#u;r&&(this.#u=t,this.#f=new Map([...t].map(([e,t])=>[e,new Map([...t].map(([e,{value:t}])=>[e,t]))]))),n!==this.#d&&(this.#d=n,this.#l?.keep());let i=e?.count??0,a=e?.conflicts??0,o=e?.setAside??0,s=this.#o.comparing&&i>0;this.#_({count:i,conflicts:a,setAside:o,comparing:s},r)}},A7=new Map,Ave=e=>e.op===`putKeys`&&e.keys.some(e=>e.tangent===`auto`)||e.op===`set`&&DF(e.value),jve=e=>e!==void 0&&b(e)?AF(e):e;function Mve(e){if(e===void 0||!b(e))return[];let t=AF(e);return t===e?[]:t.keys.filter((t,n)=>t!==e.keys[n])}function Nve(e,t){let n=new Map(e);for(let[r,i]of t)n.set(r,new Map([...e.get(r)??[],...i]));return n}var Pve=class{#e;#t;#n;#r;#i=new sv;#a=A7;#o=A7;constructor(e,t,n,r){this.#e=e,this.#t=t,this.#n=n,this.#r=r,n.subscribe(this.#s)}subscribe=this.#i.subscribe;getPreviewed=()=>this.#o;#s=()=>{let e=this.#n.getValues(),t=this.#a.size===0?e:Nve(e,this.#a);t!==this.#o&&(this.#o=t,this.#i.emit())};#c(e,t){return Z(FF(this.#n.look?.apply(e)??e),t)}preview(e){let t=this.#t.model?.state.clips,n=new Map;for(let r of e){let{path:e,owner:i}=r,a=t?.[i.clip];if(!a)continue;let o=n.get(a.id)??new Map;n.set(a.id,o);let s=o.has(e)?o.get(e):this.#c(a,e);try{o.set(e,GM(s,r))}catch(e){if(!(e instanceof mA))throw e}}for(let e of n.values())for(let[t,n]of e){let r=jve(n);r!==n&&e.set(t,r)}this.#a=n,this.#s()}#l(e){let t=this.#t.model?.state.clips,n=new Map;for(let t of e){let e=`${t.owner.clip} ${t.path}`,r=n.get(e);r?r.push(t):n.set(e,[t])}let r=[];for(let e of n.values()){let[{owner:n,path:i}]=e,a=t?.[n.clip];if(!a)continue;let o=this.#c(a,i);if(!DF(o)&&!e.some(Ave))continue;let s=o;try{for(let t of e)s=GM(s,t)}catch(e){if(!(e instanceof mA))throw e;continue}let c=Mve(s);c.length>0&&r.push({owner:n,path:i,op:`putKeys`,keys:c})}return r}cancel(){this.#a.size!==0&&(this.#a=A7,this.#s())}commit(e){if(this.#n.getSnapshot().comparing)return this.#r.comparing(),this.cancel(),!1;let t=[...e,...this.#l(e)],n=this.#n.takesEdits?this.#n.write(t):this.#u(t);return this.cancel(),n}#u(e){let t=this.#e.store,n=this.#t.model?.id;if(!t||n===void 0||e.length===0)return!1;let r=t.execute({type:`property.edit`,params:{timeline:n,edits:e}});return r.ok||this.#r.commandFailed(r.error.message),r.ok}};function Fve(e,t,n){let r=()=>t.model!==void 0,i=()=>n.hasSelection,a=()=>t.getSnapshot().selection.size>0,o=()=>{let{extras:e,model:n}=t,{selection:r}=t.getSnapshot(),i=[...r].flatMap(t=>{let r=n?.boxes.get(t);return r&&e?.canOpen(r)?[r]:[]}),a=i.some(t=>e?.isOpen(t));for(let t of i)e?.isOpen(t)===a&&e.toggle(t)},s=(t,n,{group:i,...a}={})=>e.register({id:`timeline.${t}`,title:e=>e(`timeline.command`,{action:e(`timeline.action.${t}`)}),run:n,scope:`timeline`,enabled:r,...i===void 0?{}:{menu:{name:`timeline`,group:i,title:e=>e(`timeline.action.${t}`)}},...a});s(`addColor`,()=>t.addColorClip(),{group:`add`}),s(`addScene`,()=>t.createScene(),{group:`add`}),s(`addSound`,()=>t.createSound(),{group:`add`}),s(`addVideoTrack`,()=>t.addTrack(`video`),{group:`add`}),s(`addAudioTrack`,()=>t.addTrack(`audio`),{group:`add`}),s(`addCaptionTrack`,()=>t.addTrack(`caption`),{group:`add`}),s(`split`,()=>t.splitAtPlayhead(),{keys:[`mod+k`],enabled:()=>t.canSplit,group:`edit`}),s(`delete`,()=>{i()?n.deleteSelected():t.deleteSelection()},{keys:[`delete`,`backspace`],enabled:()=>i()||t.canChangeSelection,group:`edit`}),s(`selectAll`,()=>t.selectAll(),{keys:[`mod+a`],group:`edit`}),s(`toggleProperties`,o,{keys:[`u`],enabled:a,group:`edit`}),s(`copy`,()=>{i()?n.copySelected():t.copySelection()},{keys:[`mod+c`],enabled:()=>r()&&(a()||i()),group:`clipboard`}),s(`cut`,()=>{i()?n.cutSelected():t.cutSelection()},{keys:[`mod+x`],enabled:()=>i()||t.canCut,group:`clipboard`}),s(`paste`,()=>{n.hasClipboard?n.paste():t.paste()},{keys:[`mod+v`],enabled:()=>r()&&(t.hasClipboard||n.hasClipboard),group:`clipboard`}),s(`toolSelect`,()=>t.setTool(`select`),{keys:[`v`],selected:()=>t.getSnapshot().tool===`select`,group:`tools`}),s(`toolRazor`,()=>t.setTool(`razor`),{keys:[`c`],selected:()=>t.getSnapshot().tool===`razor`,group:`tools`}),s(`toggleSnapping`,()=>t.toggleSnapping(),{keys:[`s`],group:`tools`}),s(`toggleOverwriting`,()=>t.toggleOverwriting(),{keys:[`o`],group:`tools`}),s(`toggleMultiSelecting`,()=>t.toggleMultiSelecting(),{group:`tools`}),s(`zoomIn`,()=>t.zoomIn(),{keys:[`=`],repeats:!0,group:`zoom`}),s(`zoomOut`,()=>t.zoomOut(),{keys:[`-`],repeats:!0,group:`zoom`}),s(`zoomToFit`,()=>t.zoomToFit(),{keys:[`\\`],group:`zoom`}),s(`rowsTaller`,()=>t.rowsTaller(),{keys:[`shift+=`],repeats:!0,group:`zoom`}),s(`rowsShorter`,()=>t.rowsShorter(),{keys:[`shift+-`],repeats:!0,group:`zoom`}),e.register({id:`timeline.play`,title:e=>e(`timeline.action.play`),run:()=>t.togglePlayback(),keys:[`space`],enabled:r,menu:{name:`timeline`,group:`play`}});for(let[n,i,a]of[[`previousFrame`,-1,`left`],[`nextFrame`,1,`right`]])e.register({id:`preview.${n}`,title:e=>e(`timeline.previewCommand`,{action:e(`timeline.action.${n}`)}),run:()=>t.stepFrames(i),keys:[a],scope:`preview`,repeats:!0,enabled:r});let c=e=>()=>{n.canChangeSelection?n.nudge(e):t.stepFrames(e)};s(`previousFrame`,c(-1),{keys:[`left`],repeats:!0}),s(`nextFrame`,c(1),{keys:[`right`],repeats:!0}),s(`backFiveFrames`,c(-5),{keys:[`shift+left`],repeats:!0}),s(`forwardFiveFrames`,c(5),{keys:[`shift+right`],repeats:!0}),s(`previousEdit`,()=>t.jumpToEdit(-1),{keys:[`up`],repeats:!0}),s(`nextEdit`,()=>t.jumpToEdit(1),{keys:[`down`],repeats:!0}),s(`start`,()=>t.seekToStart(),{keys:[`home`]}),s(`end`,()=>t.seekToEnd(),{keys:[`end`]})}var Ive=class{#e=new Map;#t=[];#n=[];#r=new Set;perform(e,t){for(let n of this.#r)n(e,t);e.run()}watch(e){return this.#r.add(e),()=>this.#r.delete(e)}register(e){if(this.#e.has(e.id))throw Error(`Action already registered: ${e.id}`);this.#e.set(e.id,e),this.#t.push(e)}provide(e){this.#n.push(e),this.#t.push(e)}get(e){let t=this.#e.get(e);if(t)return t;for(let t of this.#n){let n=t().find(t=>t.id===e);if(n)return n}}list(){return this.#t.flatMap(e=>typeof e==`function`?e():[e])}menu(e){let t=new Map;for(let n of this.list()){if(n.menu?.name!==e)continue;let r=t.get(n.menu.group);r?r.push(n):t.set(n.menu.group,[n])}return[...t.values()]}},Lve=class{#e=new sv;#t=1;#n;#r;subscribe=this.#e.subscribe;getSnapshot=()=>this.#n;prompt(e){return this.#i({kind:`prompt`,id:this.#t++,...e})}async confirm(e){return await this.#i({kind:`confirm`,id:this.#t++,...e})===!0}choose(e){return this.#i({kind:`choice`,id:this.#t++,...e})}form(e){return this.#i({kind:`form`,id:this.#t++,...e})}progress(e){this.answer(void 0);let t=this.#t++,n=new AbortController,r=e=>{let n=this.#n;n?.id===t&&n.kind===`progress`&&(this.#n={...n,...e},this.#e.emit())};return this.#n={kind:`progress`,id:t,...e,stopped:!1,stop:()=>{n.abort(),r({stopped:!0})}},this.#e.emit(),{signal:n.signal,update:r,close:()=>{this.#n?.id===t&&this.answer(void 0)}}}answer(e){let t=this.#r;this.#n=void 0,this.#r=void 0,this.#e.emit(),t?.(e)}#i(e){return this.answer(void 0),new Promise(t=>{this.#n=e,this.#r=t,this.#e.emit()})}},j7=`input`,M7=1,Rve=[`auto`,`mouse`,`trackpad`,`touch`];function N7(e){if(typeof e!=`object`||!e)return;let{version:t,choice:n}=e;return t===M7&&Rve.includes(n)?n:void 0}var zve=class{#e;#t=new sv;#n=`auto`;#r=`mouse`;#i={choice:`auto`,device:`mouse`};constructor(e){this.#e=e}subscribe=this.#t.subscribe;getSnapshot=()=>this.#i;async load(){let e=await xX(this.#e,j7,N7);e.kind===`ok`&&this.#a(e.value),this.#e.listen(j7,e=>{let t=N7(e);t&&this.#a(t)})}choose(e){this.#a(e),this.#e.save(j7,{version:M7,choice:e}).catch(e=>console.warn(`Input mode could not be saved`,e))}notice(e){e!==this.#r&&(this.#r=e,this.#o())}noticePointer(e){e===`touch`?this.notice(`touch`):this.#r===`touch`&&this.notice(`mouse`)}isTouch(e){return this.#n===`auto`?e===`touch`:this.#n===`touch`}get wheelDevice(){return this.#n===`mouse`||this.#n===`trackpad`?this.#n:void 0}#a(e){this.#n=e,this.#o()}#o(){let e=this.#n===`auto`?this.#r:this.#n;this.#i={choice:this.#n,device:e},this.#t.emit()}},P7=`keybindings`,F7=1;function I7(e){if(typeof e!=`object`||!e)return;let{version:t,overrides:n}=e;if(t!==F7||typeof n!=`object`||!n)return;let r=Object.entries(n).filter(([,e])=>Array.isArray(e)&&e.every(e=>typeof e==`string`));return{version:t,overrides:Object.fromEntries(r)}}var Bve=new Set([`range`,`checkbox`,`radio`,`button`,`color`,`file`]);function L7(e){let t=e;return t?.tagName?t.tagName===`INPUT`?!Bve.has(t.type??`text`):t.isContentEditable===!0||/^(TEXTAREA|SELECT)$/.test(t.tagName):!1}var Vve=new Set([`left`,`right`,`up`,`down`,`home`,`end`,`pageup`,`pagedown`]),Hve=e=>e?.type===`range`;function Uve(e){return e?.closest?.(`[data-panel]`)?.getAttribute(`data-panel`)??void 0}function Wve(e){return e?.closest?.(`[role="menu"], [role="dialog"]`)!=null}var Gve=(e,t)=>e.length===t.length&&e.every(e=>t.includes(e)),R7=(e,t)=>t===void 0?e:`${t} ${e}`,Kve=class{#e;#t;#n;#r=new sv;#i=new Map;#a=new Map;#o=new Map;#s;#c=0;#l=!1;platform;constructor(e,t,n,r){this.#e=e,this.#t=t,this.platform=n,this.#n=r}subscribe=this.#r.subscribe;getSnapshot=()=>this.#c;async load(){let e=await xX(this.#e,P7,I7);e.kind===`broken`&&this.#n.restoreFailed(),e.kind===`ok`&&this.#f(e.value),this.#m(),this.#e.listen(P7,e=>{let t=I7(e);t&&(this.#f(t),this.#m())})}refresh(){this.#m()}keysFor(e){return this.#a.get(e)??[]}ownerOf(e,t){return this.#o.get(R7(e,t))}isCustomized(e){return this.#i.has(e)}get hasCustomizations(){return this.#i.size>0}assign(e,t){let n=this.ownerOf(t,this.#t.get(e)?.scope);n!==e&&(n&&this.#p(n,this.keysFor(n).filter(e=>e!==t)),this.#p(e,[...this.keysFor(e),t]),this.#h())}remove(e,t){this.#p(e,this.keysFor(e).filter(e=>e!==t)),this.#h()}reset(e){this.#i.delete(e),this.#h()}resetAll(){this.#i.clear(),this.#h()}notePanel(e){this.#s=e}handle(e){if(e.defaultPrevented||e.isComposing)return;let t=tK(e,this.platform);if(!t)return;let n=this.#d(t,this.#u(e.target));!n||L7(e.target)&&!sK(t)||Hve(e.target)&&Vve.has(t)||(e.preventDefault(),(!e.repeat||n.repeats)&&this.#t.perform(n,`keys`))}#u(e){let t=Uve(e);if(t!==void 0||!L7(e)&&!Wve(e))return this.#s??t}#d(e,t){return[this.ownerOf(e,t),this.ownerOf(e)].map(e=>e===void 0?void 0:this.#t.get(e)).find(e=>e!==void 0&&e.enabled?.()!==!1)}#f(e){this.#i.clear();for(let[t,n]of Object.entries(e.overrides))this.#i.set(t,n)}#p(e,t){Gve(t,this.#t.get(e)?.keys??[])?this.#i.delete(e):this.#i.set(e,t)}#m(){let e=new Map,t=new Map,n=(n,r)=>{let{scope:i}=this.#t.get(n)??{},a=r.filter(t=>!e.has(R7(t,i)));for(let t of a)e.set(R7(t,i),n);t.set(n,a)};for(let[e,t]of this.#i)n(e,t);for(let e of this.#t.list())this.#i.has(e.id)||n(e.id,e.keys??[]);this.#o=e,this.#a=t,this.#c+=1,this.#r.emit()}#h(){this.#m(),this.#g()}async#g(){let e={version:F7,overrides:Object.fromEntries(this.#i)};try{await this.#e.save(P7,e),this.#l=!1}catch(e){console.warn(`Keybindings could not be saved`,e),this.#l||this.#n.saveFailed(),this.#l=!0}}},z7=`layout`,B7=`layout`,V7=3,qve=[1,2],H7=Symbol(`retired`),Jve=500,U7=e=>typeof e==`object`&&!!e,Yve=e=>Array.isArray(e)&&e.every(e=>typeof e==`string`);function W7(e){if(U7(e)&&U7(e.dock)&&Yve(e.panels))return{dock:e.dock,panels:e.panels}}function Xve(e){if(!U7(e))return;let{id:t,name:n,base:r}=e,i=W7(e.design);if(typeof t==`string`&&typeof n==`string`&&typeof r==`string`)return i&&{id:t,name:n,base:r,design:i}}function G7(e){if(!U7(e))return;if(qve.includes(e.version))return H7;let{version:t,current:n,custom:r,states:i}=e;if(t!==V7||typeof n!=`string`||!Array.isArray(r)||!U7(i))return;let a=[];for(let e of r){let t=Xve(e);if(!t)return;a.push(t)}let o={};for(let[e,t]of Object.entries(i)){let n=W7(t);if(!n)return;o[e]=n}return{version:t,current:n,custom:a,states:o}}function K7(e){return e.kind===`tabs`?[...e.panels]:e.children.flatMap(([,e])=>K7(e))}function q7(e,t){if(e.kind===`tabs`){let n=e.panels.filter(t);if(n.length===0)return;let{active:r,...i}=e;return r!==void 0&&n.includes(r)?{...i,panels:n,active:r}:{...i,panels:n}}let n=[];for(let[r,i]of e.children){let a=q7(i,t);if(a){if(a.kind===`split`&&a.direction===e.direction){let e=a.children.reduce((e,[t])=>e+t,0);for(let[t,i]of a.children)n.push([r*t/e,i])}else n.push([r,a])}}let[r]=n;if(r)return n.length===1?r[1]:{...e,children:n}}function J7(e,t){if(e.kind===`tabs`){let n=e.panels.indexOf(t);return n===-1?void 0:{before:e.panels.slice(0,n).toReversed(),after:e.panels.slice(n+1)}}for(let[,n]of e.children){let e=J7(n,t);if(e)return e}}function Y7(e){return e.replace(/\s+/g,` `).trim().slice(0,40)||void 0}var Zve=class{#e;#t;#n;#r;#i;#a;#o=new sv;#s;#c;#l;#u;#d;#f;#p;#m=!1;#h=``;constructor(e,t,n,r,i){let a=n[0];if(!a)throw Error(`At least one layout is required`);this.#e=e,this.#t=t,this.#n=n,this.#r=a,this.#i=r,this.#a=i,this.#c=a.id,this.#l={version:V7,current:a.id,custom:[],states:{}},this.#u=this.#g(),this.#d={layout:a.id,layouts:this.#u,visible:new Set,active:void 0}}subscribe=this.#o.subscribe;getSnapshot=()=>this.#d;async load(){let e=await xX(this.#e,z7,G7);e.kind===`broken`&&this.#a.restoreFailed(),e.kind===`ok`&&e.value!==H7&&this.#b(e.value),this.#c=this.#x(),this.#D(),this.#e.listen(z7,e=>this.#w(e))}attach(e){this.#f?.(),this.#s=e,this.#c=this.#x(),this.#t.write(B7,this.#c),this.#T(),this.#O(),this.#h=JSON.stringify(this.#l),this.#f=e.onChange(()=>{this.#D(),this.#A()})}async detach(){this.#k(),this.#s&&await this.#M(),this.#f?.(),this.#f=void 0,this.#s=void 0}switchLayout(e){e!==this.#c&&this.#_(e)&&(this.#O(),this.#C(e),this.#j())}resetLayout(){delete this.#l.states[this.#c],this.#T(),this.#A()}saveAs(e){let t=Y7(e);if(!t||!this.#s)return;this.#O();let n=this.#l.states[this.#c];if(!n)return;let r=`custom-${crypto.randomUUID()}`,i=this.#y(this.#c).id;return this.#l.custom=[...this.#l.custom,{id:r,name:t,base:i,design:n}],this.#l.states[r]=n,this.#u=this.#g(),this.#S(r),this.#D(),this.#j(),r}rename(e,t){let n=Y7(t);n&&this.#v(e)&&(this.#l.custom=this.#l.custom.map(t=>t.id===e?{...t,name:n}:t),this.#u=this.#g(),this.#D(),this.#j())}remove(e){this.#v(e)&&(this.#l.custom=this.#l.custom.filter(t=>t.id!==e),delete this.#l.states[e],this.#l.current===e&&(this.#l.current=this.#r.id),this.#u=this.#g(),this.#c===e?this.#C(this.#r.id):this.#D(),this.#j())}isCustom(e){return this.#v(e)!==void 0}openPanel(e){this.#s?.open(e)}async forget(){this.#k(),this.#l={...this.#l,current:this.#r.id,states:{}},this.#t.write(B7,this.#r.id),await this.#e.save(z7,this.#l)}async flush(){this.#p!==void 0&&(this.#k(),await this.#M())}#g(){return[...this.#n.map(({id:e,title:t})=>({id:e,title:t,custom:!1})),...this.#l.custom.map(({id:e,name:t})=>({id:e,title:()=>t,custom:!0}))]}#_(e){return this.#u.find(t=>t.id===e)}#v(e){return this.#l.custom.find(t=>t.id===e)}#y(e){let t=this.#v(e)?.base??e;return this.#n.find(e=>e.id===t)??this.#r}#b(e){this.#l=e,this.#u=this.#g(),this.#_(e.current)||(e.current=this.#r.id)}#x(){let e=this.#t.read(B7);return e!==void 0&&this.#_(e)?e:this.#l.current}#S(e){this.#c=e,this.#l.current=e,this.#t.write(B7,e)}#C(e){this.#S(e),this.#T()}#w(e){let t=G7(e);t&&t!==H7&&(this.#b(t),this.#h=JSON.stringify(t),this.#_(this.#c)?this.#D():this.#s?(this.#c=this.#r.id,this.#t.write(B7,this.#c),this.#T()):(this.#c=this.#x(),this.#D()))}#T(){let e=this.#s;if(!e)return;let t=this.#c,n=this.#y(t),r=this.#i(),i=!1,a;for(let n of[this.#l.states[t],this.#v(t)?.design])if(n)try{e.restore(n.dock),a=n;break}catch(e){console.warn(`Saved layout of ${t} is unusable`,e),n===this.#l.states[t]&&delete this.#l.states[t],i=!0}a?this.#E(e,a,n,r):e.arrange(q7(n.layout,e=>r.has(e))),i&&this.#a.restoreFailed(),this.#D()}#E(e,t,n,r){let i=new Set(t.panels),a=new Set(e.items().map(e=>e.type));for(let t of K7(n.layout)){if(!r.has(t)||i.has(t)||a.has(t))continue;let o=J7(n.layout,t);o&&e.add(t,o),a.add(t)}}#D(){let e=new Set;for(let t of this.#s?.items()??[])t.visible&&e.add(t.type);this.#d={layout:this.#c,layouts:this.#u,visible:e,active:this.#s?.active()},this.#o.emit()}#O(){this.#s&&this.#_(this.#c)&&(this.#l.states[this.#c]={dock:this.#s.serialize(),panels:[...this.#i()].toSorted()})}#k(){clearTimeout(this.#p),this.#p=void 0}#A(){clearTimeout(this.#p),this.#p=setTimeout(()=>{this.#p=void 0,this.#M()},Jve)}#j(){this.#k(),this.#M()}async#M(){this.#O();let e=JSON.stringify(this.#l);if(e!==this.#h)try{await this.#e.save(z7,this.#l),this.#h=e,this.#m=!1}catch(e){console.warn(`Layout could not be saved`,e),this.#m||this.#a.saveFailed(),this.#m=!0}}},Qve=1e4,$ve=class{#e=new sv;#t=[];#n=1;subscribe=this.#e.subscribe;getSnapshot=()=>this.#t;push(e,{stays:t=!1,actions:n}={}){let r=this.#n++;return this.#t=[...this.#t,{id:r,message:e,...n&&{actions:n}}],this.#e.emit(),t||setTimeout(()=>this.dismiss(r),Qve),r}dismiss(e){let t=this.#t.filter(t=>t.id!==e);t.length!==this.#t.length&&(this.#t=t,this.#e.emit())}};function eye(e){let[t=``,n=``]=e;return[`files`,`timelines`,`scenes`,`sounds`,`transitions`,`effects`].includes(t)?`${t}/${n}`:t}function tye(e){let t=new Set;for(let n of e){let e=n.indexOf(`properties`),r=e>=0?n[e+1]:void 0;r!==void 0&&t.add(r)}return[...t]}var nye=e=>e===`user`?`you`:e.startsWith(WN(``))?`folder`:`ai`,rye=class{#e=new sv;#t;#n;#r=0;#i=1;#a=[];#o=[];#s=!1;constructor(e){let t=()=>this.#c(e.getSnapshot().store);e.subscribe(t),t()}subscribe=this.#e.subscribe;getSnapshot=()=>this.#o;#c(e){e!==this.#t&&(this.#n?.(),this.#t=e,this.#a=[],this.#r=e?.revision??0,this.#n=e?.subscribe(()=>this.#l(e)),this.#p())}#l(e){if(e.revision===this.#r)return;this.#r=e.revision;let{change:t}=e;if(!t){this.#d({source:`other`,origin:void 0,commands:[],properties:[],count:1});return}let{origin:n,takesBack:r,step:i,back:a}=t,o=nye(n);if(r){let e=r===`undo`,t=o===`you`?this.#a.find(e=>e.source===`you`&&e.step===a):this.#a.findLast(e=>e.origin===n);t&&this.#f(t,{...t,undone:e,step:i}),this.#p();return}o===`you`&&(this.#a=this.#a.filter(e=>e.source!==`you`||!e.undone));let s=e.revision;this.#u(()=>{let t=e.history.findLast(e=>e.revision===s),r=t?.commands??[],a=t?.patches.map(({path:e})=>e)??[],c=tye(a);if(o===`you`){this.#d({source:o,origin:n,commands:r,properties:c,count:1,step:i});return}let l=this.#a.findLast(e=>e.origin===n),u=new Set(a.map(eye)).size,d=o===`folder`?u:r.length;if(l){this.#a=this.#a.filter(e=>e!==l);let e=new Set([...l.properties,...c]);this.#d({source:o,origin:n,commands:[...l.commands,...r],properties:[...e],count:l.count+d})}else this.#d({source:o,origin:n,commands:r,properties:c,count:d})})}#u(e){let t=this.#t;queueMicrotask(()=>{this.#t===t&&e()})}#d(e){this.#a.push({step:0,...e,id:this.#i++,time:Date.now(),undone:!1}),this.#a.length>60&&(this.#a=this.#a.slice(-60)),this.#p()}#f(e,t){this.#a=this.#a.map(n=>n===e?t:n)}#p(){this.#s||(this.#s=!0,queueMicrotask(()=>{this.#s=!1,this.#o=this.#a.toReversed().slice(0,30),this.#e.emit()}))}canUndoTo(e){let t=this.#t;return!t||e.source!==`you`||e.undone?!1:t.canUndo&&e.step<=t.lastStep}get redoable(){if(this.#t?.canRedo===!0)return this.#a.filter(({source:e,undone:t})=>e===`you`&&t).reduce((e,t)=>e&&e.step>t.step?e:t,void 0)}canUndoOrigin(e){let{origin:t}=e;return t!==void 0&&this.#t?.canUndoOrigin(t)===!0}canRedoOrigin(e){let{origin:t}=e;return t!==void 0&&this.#t?.canRedoOrigin(t)===!0}get last(){return this.#o[0]}destroy(){this.#n?.()}},X7=`palette`,Z7=1,iye=6,aye=.5;function oye(e){if(typeof e!=`object`||!e)return;let{version:t,recent:n}=e;if(t===Z7&&Array.isArray(n))return{version:t,recent:n.filter(e=>typeof e==`string`)}}var sye=class{#e;#t;#n=new sv;#r=!1;#i=[];constructor(e,t){this.#e=e,this.#t=t}subscribe=this.#n.subscribe;isOpen=()=>this.#r;async load(){let e=await xX(this.#e,X7,oye);e.kind===`ok`&&(this.#i=e.value.recent)}toggle(){this.#a(!this.#r)}close(){this.#a(!1)}run(e){this.#a(!1),this.#i=[e.id,...this.#i.filter(t=>t!==e.id)].slice(0,iye),this.#e.save(X7,{version:Z7,recent:this.#i}).catch(e=>console.warn(`Recent commands could not be saved`,e)),this.#t.perform(e,`palette`)}#a(e){e!==this.#r&&(this.#r=e,this.#n.emit())}search(e,t){let n=e=>{let t=this.#i.indexOf(e.id);return t===-1?this.#i.length:t},r=this.#t.list().filter(e=>e.palette!==!1&&e.enabled?.()!==!1);if(!e.trim())return r.map(e=>({action:e,title:e.title(t),positions:[],recent:this.#i.includes(e.id)})).toSorted((e,t)=>n(e.action)-n(t.action));let i=[];for(let n of r){let r=n.title(t),a=m0(e,r),o=m0(e,n.id),s=o?o.score*aye:void 0;if(a===void 0&&s===void 0)continue;let c=a!==void 0&&(s===void 0||a.score>=s);i.push({action:n,title:r,positions:c?a.positions:[],recent:!1,score:c?a.score:s})}return i.toSorted((e,t)=>t.score-e.score||n(e.action)-n(t.action))}},Q7=`resources`,$7=1,e9=40,cye={version:$7,recent:[],grouping:{},collapsed:{}},lye=[],t9=e=>typeof e==`object`&&!!e;function n9(e){if(typeof e!=`object`||!e)return;let{version:t,recent:n,grouping:r,collapsed:i}=e;if(t!==$7||!Array.isArray(n))return;let a=Object.entries(t9(r)?r:{}),o=Object.entries(t9(i)?i:{}).flatMap(([e,t])=>Array.isArray(t)?[[e,t.filter(e=>typeof e==`string`).slice(-100)]]:[]);return{version:t,recent:n.filter(e=>typeof e==`string`).slice(0,e9),grouping:Object.fromEntries(a.filter(([,e])=>h0.includes(e))),collapsed:Object.fromEntries(o)}}var uye=class{#e;#t=new sv;#n=cye;constructor(e){this.#e=e}subscribe=this.#t.subscribe;getSnapshot=()=>this.#n;async load(){let e=await xX(this.#e,Q7,n9);e.kind===`ok`&&this.#r(e.value),this.#e.listen(Q7,e=>{let t=n9(e);t&&this.#r(t)})}get recent(){return this.#n.recent}groupingOf(e,t){return this.#n.grouping[e]??t}collapsedIn(e){return this.#n.collapsed[e]??lye}setCollapsed(e,t,n){let r=this.collapsedIn(e);if(r.includes(t)===n)return;let i=n?[...r,t].slice(-100):r.filter(e=>e!==t);this.#i({...this.#n,collapsed:{...this.#n.collapsed,[e]:i}})}used(e){this.#n.recent[0]!==e&&this.#i({...this.#n,recent:Xle(this.#n.recent,e,e9)})}setGrouping(e,t){this.#n.grouping[e]!==t&&this.#i({...this.#n,grouping:{...this.#n.grouping,[e]:t}})}#r(e){this.#n=e,this.#t.emit()}#i(e){this.#r(e),this.#e.save(Q7,e).catch(e=>console.warn(`Resource habits could not be saved`,e))}},r9={tabs:[],page:void 0},i9=e=>e.getSnapshot().documents.map(({path:e})=>e),dye=class{#e=new sv;#t;#n;#r=r9;#i;#a;constructor(e,t){this.#n=e,this.#t=t,this.#i=i9(t),this.#a=e.store,this.#r={...r9,tabs:this.#i.map(e=>({kind:`code`,path:e}))},t.subscribe(this.#c),e.subscribe(this.#s)}subscribe=this.#e.subscribe;getSnapshot=()=>this.#r;get showsCode(){return this.#r.page===void 0}#o(e){e.page===this.#r.page&&e.tabs.length===this.#r.tabs.length&&e.tabs.every((e,t)=>e===this.#r.tabs[t])||(this.#r=e,this.#e.emit())}#s=()=>{this.#n.store!==this.#a&&(this.#a=this.#n.store,this.#i=i9(this.#t),this.#o({tabs:this.#i.map(e=>({kind:`code`,path:e})),page:void 0}))};#c=()=>{let e=this.#i,t=i9(this.#t);if(t.length===e.length&&t.every((t,n)=>t===e[n]))return;this.#i=t;let n=new Set(t),r=new Set(e),i=new Map;e.forEach((e,a)=>{let o=t[a];!n.has(e)&&o!==void 0&&!r.has(o)&&i.set(e,o)});let a=this.#r.tabs.flatMap(e=>{if(e.kind===`resource`||n.has(e.path))return[e];let t=i.get(e.path);return t===void 0?[]:[{kind:`code`,path:t}]}),o=new Set(a.flatMap(e=>e.kind===`code`?[e.path]:[]));for(let e of t)o.has(e)||a.push({kind:`code`,path:e});let{page:s}=this.#r;s===void 0&&t.length===0&&(s=this.#l(a)),this.#o({tabs:a,page:s})};#l(e){let t=e.findLast(e=>e.kind===`resource`);return t?.kind===`resource`?t.id:void 0}open(e,t){let n=this.#r.tabs.some(t=>t.kind===`resource`&&t.id===e)?this.#r.tabs:[...this.#r.tabs,{kind:`resource`,id:e,name:t}];this.#o({tabs:n,page:e})}show(e){this.#r.tabs.some(t=>t.kind===`resource`&&t.id===e)&&this.#o({...this.#r,page:e})}showCode(e){e!==void 0&&this.#t.activate(e),this.#i.length>0&&this.#o({...this.#r,page:void 0})}close(e){let{tabs:t,page:n}=this.#r,r=t.findIndex(t=>t.kind===`resource`&&t.id===e);if(r===-1)return;let i=t.filter((e,t)=>t!==r);if(n!==e){this.#o({tabs:i,page:n});return}let a=i[Math.min(r,i.length-1)];a?.kind===`code`?(this.#t.activate(a.path),this.#o({tabs:i,page:void 0})):this.#o({tabs:i,page:a?.id})}},a9=new Map,fye=class{#e;#t;#n;#r=new sv;#i=a9;#a=0;#o;#s;#c=0;constructor(e,t,n){this.#e=e,this.#t=t,this.#n=n}subscribe=e=>{let t=this.#r.subscribe(e);return this.#a+=1,this.#a===1&&this.#l(),()=>{t(),--this.#a,this.#a===0&&(this.#o?.(),this.#o=void 0,this.#s=void 0)}};getSnapshot=()=>this.#i;#l(){let e,t,n=()=>{this.#e.store!==t&&(e?.(),t=this.#e.store,e=t?.subscribe(()=>this.#u())),this.#u()},r=[this.#e.subscribe(n),this.#t.subscribe(()=>this.#u()),...this.#n?[this.#n.subscribe(()=>this.#u())]:[]];n(),this.#o=()=>{e?.();for(let e of r)e()}}#u(){let e=this.#e.store,t=e?.getState().assets,n=this.#n?.assets()?this.#n:void 0;if(n){this.#s=void 0,this.#d(pye(n.assetIssues,t));return}let r=this.#t.getRestored(),i=this.#s;if(i&&i.store===e&&i.assets===t&&i.restored===r)return;this.#s={store:e,assets:t,restored:r},this.#c+=1;let a=this.#c;!e||!t?this.#d(a9):Promise.all(Object.entries(t).map(async([e,{path:t}])=>await this.#t.hasFile(e).catch(()=>!0)?[]:[{asset:e,path:t}])).then(e=>{a===this.#c&&this.#d(new Map(e.flat().map(e=>[e.asset,e])))})}#d(e){mye(e,this.#i)||(this.#i=e,this.#r.emit())}};function pye(e,t){let n=t??{},r=new Map;for(let t of e){if(t.kind!==`missing`||!Object.hasOwn(n,t.asset))continue;let{asset:e,path:i,found:a,hidden:o}=t;r.set(e,{asset:e,path:i,...a!==void 0&&{found:a},...o!==void 0&&{hidden:o}})}return r}function mye(e,t){if(e.size!==t.size)return!1;for(let[n,r]of e){let e=t.get(n);if(!e||e.path!==r.path||e.found!==r.found||e.hidden!==r.hidden)return!1}return!0}var hye=8,o9=3,gye=`assets`,_ye=new TextEncoder,vye=new TextDecoder(`utf-8`,{fatal:!0,ignoreBOM:!0}),s9=({size:e,lastModified:t})=>({size:e,lastModified:t}),c9=(e,t)=>e instanceof ba&&e.reason===t,yye=e=>e instanceof ba?e.reason:e instanceof Error?e.name:`Error`;function bye(e){try{return vye.decode(e)}catch{return}}function l9(e){let t=e.split(`/`).slice(0,-1);return t.map((e,n)=>t.slice(0,n+1).join(`/`))}var u9=e=>e===``?0:e.split(`/`).length;async function xye(e,t,n){let r=0,i;if(await Promise.all(Array.from({length:Math.min(t,e.length)},async()=>{for(;r<e.length&&!i;)try{await n(e[r++])}catch(e){i??={error:e}}})),i)throw i.error}function Sye(e,t){return t?(t.throwIfAborted(),new Promise((n,r)=>{let i=()=>r(t.reason);t.addEventListener(`abort`,i,{once:!0}),e.then(n,r).finally(()=>t.removeEventListener(`abort`,i))})):e}var d9=e=>e.split(`/`).some(Gr),f9=e=>e.length<=120&&e.split(`/`).every(e=>e.length<=64);async function p9(e){for(let t=1;t<=o9;t++)try{return await e(),!0}catch(e){if(c9(e,`missing`))return!0;if(c9(e,`changed`)||t===o9)return!1;await new Promise(e=>setTimeout(e,100*t))}return!1}var m9=(e,t=!1)=>e.map(({asset:e,from:n,to:r})=>({type:`asset.update`,params:{asset:e,changes:{path:t?n:r}}}));async function h9(e,t){let n=await e.open(t),r;try{let e=await n.load();r=e.length===0?void 0:sG.fromUpdates(e).store}catch(e){throw n.close(),e}if(!r){n.close();return}let i=r,a=Promise.resolve(!0),o=i.onLocalUpdate(e=>{a=a.then(t=>n.append(e,i.getState().manifest.name).then(()=>t,()=>!1))});return{store:i,saved:()=>a,close(){o(),i.destroy(),n.close()}}}function Cye(e){let t=Object.entries(e.assets??{}),n=new Map,r=e=>{let t=e.split(`/`).slice(0,-1).join(`/`),r=n.get(t)??new Set;r.add(e.split(`/`).at(-1)),n.set(t,r)};for(let[,{path:e}]of t)r(e);for(let t of Object.keys(e.files))r(t);let i=new Map,a=[];for(let[e,{path:o}]of t){if(!d9(o)&&f9(o))continue;let t=i.get(o);if(t===void 0){let e=o.split(`/`).at(-1),a=o.split(`/`).slice(0,-1).join(`/`);for(let r of[a,gye]){if(r===``||d9(r)||!f9(r))continue;let i;try{i=`${r}/${fi(e,n.get(r)??[],r)}`}catch{continue}if(!d9(i)&&f9(i)){t=i;break}}if(t===void 0)continue;i.set(o,t),r(t)}a.push({asset:e,from:o,to:t})}return a}var wye=class{#e;#t;#n;#r;#i;constructor({folders:e,projects:t,t:n,hasher:r=O3,now:i=Date.now}){this.#e=e,this.#t=t,this.#n=n,this.#r=r,this.#i=i}async isFolder(e){return await this.#e.records.get(e)?!0:(await this.#t.list()).some(({id:t,folder:n})=>t===e&&n===!0)}async check(e,t,n){let r=await this.#c(e,t,n);return`refusal`in r?r.refusal:void 0}async run(e,t,n,r,i){let a=await this.#c(e,t,n);if(`refusal`in a)return{kind:`refused`,refusal:a.refusal};let o=await this.#a(e);if(!o)return{kind:`refused`,refusal:{kind:await this.isFolder(e)?`already`:`busy`}};try{return await this.isFolder(e)?{kind:`refused`,refusal:{kind:`already`}}:await this.#s(e,t,a,r,i)}finally{o.release()}}async settle(e){let{unfinished:t}=e;if(!t)return e;try{await e.folder.remove(DH,{expected:t})}catch(t){if(!c9(t,`changed`))return e}let{unfinished:n,...r}=e;return await this.#e.records.put(r).catch(()=>{}),r}async copiesOf(e){return(await this.#t.copies(e)).reduce((e,{size:t})=>e+t,0)}async release(e,t,n,{open:r}){let i=await this.#t.copies(e),a=[],o=[],s=[];for(let e of i){let i=Object.values(t).filter(({hash:t})=>t!==void 0&&eq(t,e.name));if(i.length===0){(r?s:a).push(e);continue}let c=!1;for(let{path:t}of i){let r=await n.fileAt(t);if(r.kind===`there`&&eq(r.hash,e.name)){c=!0;break}}(c?a:o).push(e)}return a.length>0&&(await this.#t.toFolder(e),await this.#t.dropCopies(e,a.map(({name:e})=>e))),{released:a.reduce((e,{size:t})=>e+t,0),missing:o,unused:s}}async#a(e){let t=new AbortController;try{return await this.#e.writer(e).claim({signal:t.signal,onWaiting:()=>queueMicrotask(()=>t.abort())})}catch(e){if(t.signal.aborted)return;throw e}}async#o(e,t){let{chosen:n,inside:r}=e,i=n,a=!1;if(r!==void 0){let e=await n.inside(r).catch(e=>{if(!c9(e,`missing`))throw e});a=e===void 0,i=e??await n.inside(r,{create:!0})}let o=new Map;if(a)return{target:i,made:a,place:e,kept:o};o.set(``,i);let s=[DH,...t.files.keys(),...t.copies.map(({path:e})=>e)],c=[...new Set(s.flatMap(l9))].toSorted((e,t)=>u9(e)-u9(t));for(let e of c){let t=e.split(`/`).slice(0,-1).join(`/`),n=o.get(t);if(!n)continue;let r=e.split(`/`).at(-1),i=await n.inside(r).catch(()=>void 0);i&&o.set(e,i)}return{target:i,made:a,place:e,kept:o}}async#s(e,t,n,r,{notice:i,signal:a,onStep:o,saved:s}){let c=this.#i(),l;try{l=await this.#o(r,n)}catch(e){let t=r.inside??r.chosen.name;return{kind:`stopped`,cancelled:!1,file:t,error:e,cleaned:!0,folder:t}}let{target:u}=l,d={notice:void 0,written:[],begun:new Set,damaged:new Map,file:DH},f=async(e,t)=>{let n=await this.#p(l,d);return{kind:`stopped`,cancelled:t,file:d.file,error:e,cleaned:n,folder:u.name}};try{await this.#u(l,n,i,d,{signal:a,onStep:o})}catch(e){return f(e,a?.aborted===!0)}let p;try{p=await this.#d(e,u,t,n,d,c,{signal:a,onStep:o})}catch(t){if(a?.aborted)return await this.#m(e),f(t,!0);p={mismatches:[{kind:`unreadable`,reason:yye(t),problems:[]}],seen:new Map}}if(p.mismatches.length>0)return await this.#m(e),{kind:`unverified`,folder:u.name,mismatches:p.mismatches,takeBack:()=>this.#p(l,d)};let m=n.renames.length>0,h=async r=>{await this.#m(e),m&&t.executeBatch(m9(n.renames,!0));let i=await this.#p(l,d);return{kind:`unswitched`,folder:u.name,error:r,cleaned:i}};if(m){let r=t.executeBatch(m9(n.renames));if(!r.ok){await this.#m(e);let t=await this.#p(l,d);return{kind:`unswitched`,folder:u.name,error:r.error,cleaned:t}}}let{bases:g,records:_}=this.#e;try{if(!await s())throw Error(`The log of the project cannot be written`);let t=await g.claim(e),r=[...n.files].map(([e,t])=>{let n=p.seen.get(e);return{path:e,base:t,...n&&{stat:n},synced:XK(t)}});if(!await g.save(e,t,{put:r,replace:!0}))throw Error(`Another window claimed the folder while the project moved`)}catch(e){return h(e)}let{id:v,name:y}=t.getState().manifest,b={id:e,folder:u,project:v,name:y,openedAt:this.#i(),...d.notice&&{unfinished:s9(d.notice)}};try{await _.put(b)}catch(e){return h(e)}await this.#t.toFolder(e).catch(e=>{console.warn(`The project moved, and the list of projects does not say so yet`,e)});let x=b;if(d.notice&&await p9(()=>u.remove(`导出未完成.txt`,{expected:d.notice}))){let{unfinished:e,...t}=b;x=t,await _.put(x).catch(()=>{})}let S=await this.copiesOf(e).catch(()=>0);return{kind:`moved`,record:x,missing:n.missing,damaged:[...d.damaged.values()],renamed:n.renames,copies:S}}async#c(e,t,n){if(await this.isFolder(e))return{refusal:{kind:`already`}};if(t.getState().manifest.formatVersion>1)return{refusal:{kind:`too-new`}};let r=Cye(t.getState());if(r.length===0)return this.#l(t,n,[]);let i=sG.fromUpdates([t.encodeState()]).store;if(!i)throw Error(`The project cannot be read as it is`);try{return i.executeBatch(m9(r)).ok?await this.#l(i,n,r):{refusal:{kind:`locked`,paths:[...new Set(r.map(({from:e})=>e))].toSorted()}}}finally{i.destroy()}}async#l(e,t,n){let r=e.getState(),{files:i,problems:a}=e.exportFiles(),o=a.filter(({severity:e})=>e===`error`);if(o.length>0)return{refusal:{kind:`invalid`,problems:o}};let s=new Set,c=new Set,l=new Set,u=new Map([[di(DH),{path:DH}]]),d=new Map;for(let[e,t]of i){d.set(e,_ye.encode(t).byteLength),d9(e)?s.add(e):f9(e)||c.add(e);let n=di(e);u.has(n)?l.add(e):u.set(n,{path:e})}let f=[],p=[],m=[];for(let[e,n]of Object.entries(r.assets??{})){let{path:r,hash:a}=n,o=n.name??r??e;d9(r)?s.add(r):f9(r)||c.add(r);let d=di(r),h=u.get(d);if(h){let e=i.get(h.path),t=h.hash??(e===void 0?void 0:XK(e));h.path===r&&a!==void 0&&t!==void 0&&eq(a,t)?h.hash===void 0&&p.push({path:r,hash:a}):l.add(r);continue}let g=a===void 0?void 0:await t.get(a);!g||a===void 0?m.push(o):(u.set(d,{path:r,hash:a}),f.push({path:r,file:g,hash:a,label:o}))}return s.size>0?{refusal:{kind:`refused`,paths:[...s].toSorted()}}:c.size>0?{refusal:{kind:`too-long`,paths:[...c].toSorted()}}:l.size>0?{refusal:{kind:`clashing`,paths:[...l].toSorted()}}:{files:i,sizes:d,copies:f,covered:p,missing:m,renames:n}}async#u(e,t,n,r,{signal:i,onStep:a}){let{target:o}=e,s=[...t.files.keys()].filter(e=>e!==Sk),c=1+t.copies.length+t.files.size,l=0;for(let{file:e}of t.copies)l+=e.size;for(let e of t.sizes.values())l+=e;let u=0,d=0,f=(e,t=0)=>a?.({phase:`writing`,file:e,files:u,totalFiles:c,bytes:d+t,totalBytes:l}),p=async(e,t,n,a=e)=>{r.file=a,r.begun.add(e),f(a);let s=await o.write(e,t,{expected:`absent`,...i&&{signal:i},onProgress:e=>f(a,e)});return r.written.push({path:e,file:s}),u+=1,d+=n,f(a),s};i?.throwIfAborted(),f(DH),r.notice=await o.write(DH,n,{expected:`absent`,...i&&{signal:i}}),u+=1;for(let{path:n,file:i,hash:a,label:o}of t.copies){let t=this.#r.copy(i),s;try{s=await p(n,t.content,i.size,o)}catch(e){throw t.abandon(),e}if(eq(await t.hash()??await this.#r.file(i),a))continue;let c=r.written.findIndex(e=>e.file===s);if(!await this.#f(e,n,s))throw new ba(`changed`,n);r.written.splice(c,1),r.damaged.set(n,o)}let m=e=>t.sizes.get(e)??0;for(let e of P3(s))await xye(e,hye,async e=>{await p(e,t.files.get(e),m(e))});await p(Sk,t.files.get(`animaquill.json`)??``,m(Sk))}async#d(e,t,n,r,i,a,{signal:o,onStep:s}){let c=[...r.copies.filter(({path:e})=>!i.damaged.has(e)).map(({path:e,hash:t,label:n,file:r})=>({path:e,hash:t,label:n,size:r.size})),...r.covered.map(({path:e,hash:t})=>({path:e,hash:t,label:e,size:0}))],l=r.files.size+c.length,u=c.reduce((e,{size:t})=>e+t,0),d=0,f=0,p=(e,t=0)=>s?.({phase:`checking`,file:e,files:d,totalFiles:l,bytes:f+t,totalBytes:u});p(t.name);let m=new Map,h={name:t.name,async*files(){for await(let e of t.list())e!==`导出未完成.txt`&&(yield{path:e,async read(){let n=await t.file(e),r=new Uint8Array(await n.arrayBuffer());return m.set(e,{content:r,stat:s9(n)}),d+=1,p(e),new File([r],n.name,{lastModified:n.lastModified})}})}},g;try{g=await bY(h,this.#n,o?{signal:o}:{})}catch(e){if(!(e instanceof hY))throw e;return{mismatches:[{kind:`unreadable`,reason:e.reason,problems:e.problems}],seen:new Map}}let _=[],v=new Set,y=e=>{v.has(e.file)||(v.add(e.file),_.push(e))};for(let{file:e,problems:t}of g.lost)y({kind:`lost`,file:e,problems:t});for(let[e,t]of r.files){let n=m.get(e);n?bye(n.content)!==t&&y({kind:`different`,file:e}):y({kind:`missing`,file:e})}for(let e of m.keys())r.files.has(e)||y({kind:`extra`,file:e});let b=kk(g.project);for(let[e,t]of Object.entries(g.sources))b.set(e,t);for(let e of new Set([...r.files.keys(),...b.keys()]))b.get(e)!==r.files.get(e)&&y({kind:`other`,file:e});g.project.manifest.id!==n.getState().manifest.id&&y({kind:`other`,file:Sk});let x,S=new K3({folder:()=>t,key:e,bases:this.#e.bases,browser:this.#t.media(e),hasher:this.#r,now:this.#i,onProgress:({reading:e})=>{let t=e[0]?.percent;x&&t!==void 0&&p(x.label,x.size*t/100)}});try{for(let e of c){o?.throwIfAborted(),x=e,p(e.label);let t=await Sye(S.fileAt(e.path,{since:a}),o);t.kind===`missing`?y({kind:`asset-missing`,file:e.path}):t.kind===`unknown`?y({kind:`asset-unreadable`,file:e.path}):eq(t.hash,e.hash)||y({kind:`asset-different`,file:e.path}),d+=1,f+=e.size,x=void 0,p(e.label)}}finally{S.stop()}return{mismatches:_,seen:new Map([...m].map(([e,{stat:t}])=>[e,t]))}}async#f(e,t,n){for(let r of[``,...l9(t)].toReversed()){let i=e.kept.get(r);if(!i)continue;let a=r===``?t:t.slice(r.length+1);return p9(()=>i.remove(a,{expected:n}))}let{chosen:r,inside:i}=e.place;return p9(()=>r.remove(`${i}/${t}`,{expected:n}))}async#p(e,t){let n=!0;for(let{path:r,file:i}of t.written.toReversed())await this.#f(e,r,i)||(n=!1);if(!n)return!1;let r=new Set(t.written.map(({path:e})=>e)),i=new Set;for(let n of t.begun)if(!r.has(n))for(let t of l9(n))e.kept.has(t)||i.add(t);let{chosen:a,inside:o}=e.place;for(let t of[...i].toSorted((e,t)=>u9(t)-u9(e))){let n=e.made?`${o}/${t}`:t;await(e.made?a:e.target).removeFolder(n).catch(()=>!1)}if(t.notice){if(!await this.#f(e,`导出未完成.txt`,t.notice))return!1;t.notice=void 0}return e.made&&o!==void 0&&await a.removeFolder(o).catch(()=>!1),!0}async#m(e){try{await this.#e.records.get(e)||await this.#e.bases.forget(e)}catch{}}};async function g9(e){let t=[];for await(let n of e)t.push(n);return t}var _9=e=>({name:e.name,async*files(){for await(let t of e.list())yield{path:t,read:()=>e.file(t)}}}),Tye=e=>new Set(e.map(e=>e.split(`/`)[0])),Eye=e=>M3(e)||e.startsWith(`assets/`),v9=async e=>(await g9(e.list())).filter(e=>!jH(e));async function y9(e){try{return await e.readText(Sk)}catch{return}}var Dye=class{#e;#t;#n;#r;#i;constructor({folders:e,projects:t,t:n,newKey:r=()=>crypto.randomUUID(),now:i=Date.now}){this.#e=e,this.#t=t,this.#n=n,this.#r=r,this.#i=i}get records(){return this.#e.records}statusOf(e){return e.folder.status().catch(()=>`gone`)}async mayBeProject(e){return await y9(e)!==void 0||(await g9(e.list({includes:(e,t)=>t===`folder`?!e.includes(`/`):e.endsWith(`animaquill.json`)}))).length>0||(await v9(e)).length===0}async look(e,t={}){let n=await this.#e.records.find(e);if(n){let t=await y9(e);if(t===void 0||I3(t)===n.project)return{kind:`known`,record:n}}let r=await v9(e);if(r.length===0)return{kind:`empty`,folder:e};let i;try{i=await bY(_9(e),this.#n,t)}catch(e){if(e instanceof hY)return{kind:`refused`,error:e};throw e}let{id:a,name:o}=i.project.manifest,s=r.includes(`animaquill.json`)?``:this.#a(r),c=s===``?e:await e.inside(s);if(s!==``&&(n=await this.#e.records.find(c),n?.project===a))return{kind:`known`,record:n};let l=await this.#s(c,a);return{kind:`project`,folder:c,reading:i,project:a,name:o,moved:l,replacing:n}}async placeFor(e,t){let n=await this.#e.records.find(e);if(n)return{kind:`known`,record:n};let r=await this.#o(e);if(r)return{kind:`inside`,record:r};let i=await v9(e);return i.length===0?{kind:`empty`}:i.includes(`导出未完成.txt`)?{kind:`incomplete`}:i.includes(`animaquill.json`)?{kind:`project`}:{kind:`other`,inside:fi(t,Tye(i)),clashes:i.filter(Eye)}}async create(e,t,n){let r=n===void 0?t:await t.inside(n,{create:!0});if(await this.#e.records.find(r))throw Error(`This browser knows that folder as the folder of another project`);let i=sG.create(ZD({name:e})),{id:a}=i.getState().manifest,o=i.encodeState();i.destroy();let s=this.#r();await this.#t.create({id:s,name:e,folder:!0},o);let c={id:s,folder:r,project:a,name:e,openedAt:this.#i()};return await this.#e.records.put(c),c}async adopt(e,t){e.replacing&&e.replacing.id!==t?.id&&await this.forget(e.replacing.id);let n=t?.id??this.#r(),r,{name:i}=e;await this.#c(n)||(r=await SY(e.reading,this.#t,{key:n,copyName:e=>e}),{name:i}=r);let a={id:n,folder:e.folder,project:e.project,name:i,openedAt:this.#i()};return await this.#e.records.put(a),{record:a,report:r}}async prepare(e,t={}){return await this.#c(e.id)?void 0:SY(await bY(_9(e.folder),this.#n,t),this.#t,{key:e.id,copyName:e=>e,...t})}async isTooNew(e){let t=await y9(e);return t!==void 0&&(F3(t)??0)>1}async hasUnwritten(e){try{let t=await this.#t.open(e.id),n;try{n=await t.load()}finally{t.close()}if(n.length===0)return!1;let{store:r}=sG.fromUpdates(n);if(!r)return!0;let{files:i}=r.exportFiles();r.destroy();let a=new Map((await this.#e.bases.load(e.id)).map(({path:e,base:t})=>[e,t]));if(a.size===0)return!0;for(let[e,t]of i)if(a.get(e)!==t)return!0;for(let[e,t]of a)if(t!==void 0&&!i.has(e))return!0;return!1}catch{return!0}}async opened(e,t=e.name){await this.#e.records.put({...e,name:t,openedAt:this.#i()})}async findAgain(e,t){let n=await this.#e.records.find(t);if(n&&n.id!==e.id)return`taken`;let r=await y9(t),i=r===void 0?void 0:I3(r);return i===void 0?`not-a-project`:i===e.project?(F3(r)??0)>1?`too-new`:(await this.#e.records.put({...e,folder:t,openedAt:this.#i()}),`found`):`other-project`}async relocate(e,t){let n=await this.#e.records.find(t);if(n&&n.id!==e.id)throw Error(`This browser knows that folder as the folder of another project`);await this.#e.bases.forget(e.id);let r={...e,folder:t,openedAt:this.#i()};return await this.#e.records.put(r),r}async forget(e){await this.#e.records.remove(e),await this.#e.bases.forget(e),await this.#t.remove(e,{folder:!0})}#a(e){return e.filter(e=>e.endsWith(`/animaquill.json`)&&e.split(`/`).length===2).map(e=>e.split(`/`)[0])[0]??``}async#o(e){for(let t of await this.#e.records.list())if(await t.folder.pathOf({kind:`folder`,folder:e}).catch(()=>void 0))return t}async#s(e,t){let n=await this.#e.records.withProject(t),r=[];for(let t of n)await t.folder.isSame(e).catch(()=>!1)||await this.statusOf(t)!==`ready`&&r.push(t);return r}async#c(e){let t=await this.#t.open(e);try{return(await t.load()).length>0}finally{t.close()}}},Oye={quietMs:1e3,longestMs:5e3,retryMs:5e3,settleMs:2e3,answerMs:3e3},b9=`.animaquill/recovered`,kye=`.animaquill/.gitignore`,x9=`absent`,Aye=16,jye=8,Mye=3,S9=new Set([`merge-would-break`,`merge-unsettled`]),Nye=new Set([`project-locked`,...S9]),Pye=new Set([`waits-with-timeline`,`needs-file`,`uses-removed`]),Fye=`\0`,C9=({size:e,lastModified:t})=>({size:e,lastModified:t}),w9=(e,t)=>e===x9||t===x9?e===t:e.size===t.size&&e.lastModified===t.lastModified,T9=e=>e.kind===`absent`?x9:e.stat,E9=e=>e.kind===`text`?e.text:void 0,D9=(e,t)=>e.kind===`text`?e.text===t:e.kind===`absent`&&t===void 0,O9=(e,t)=>t.kind===`text`?t.text===e:t.kind===`absent`&&e===void 0,k9=(e,t)=>e.kind===`absent`||t.kind===`absent`?e.kind===t.kind:e.kind!==t.kind||!w9(e.stat,t.stat)?!1:e.kind!==`text`||e.text===t.text;function A9(e,t){return e.kind===`text`||t.kind===`text`?e.kind===`text`&&t.kind===`text`&&e.text===t.text:k9(e,t)}var j9=new TextEncoder,Iye=(e,t)=>`${t} ${j9.encode(e).length}`,M9=e=>e.split(` `)[0]??``,Lye=(e,t)=>e===x9?t.kind===`absent`:t.kind===`text`&&XK(t.text)===M9(e);function Rye(e,t){if(e===x9||t.kind===`absent`)return!1;let n=Number(e.split(` `)[1]);return t.stat.size===0||t.stat.size===n}function N9(e){if(e.kind===`absent`)return x9;if(e.kind===`text`)return`${XK(e.text)} ${e.stat.size} ${e.stat.lastModified}`}function zye(e,t){if(e===x9)return t.kind===`absent`;if(t.kind!==`text`)return!1;let[n=``,r=``,i=``]=e.split(` `);return t.stat.size===Number(r)&&t.stat.lastModified===Number(i)&&XK(t.text)===n}function Bye(e,t){if(!e)return t===void 0;let{synced:n}=e;return n?t===void 0||n.hash===x9?t===void 0&&n.hash===x9:n.text===void 0?n.hash===XK(t)&&(n.text=t,!0):n.text===t:!1}var P9=e=>e===void 0?{hash:x9,text:void 0}:{hash:XK(e),text:e},F9=(e,...t)=>e instanceof ba&&t.includes(e.reason);function I9(e){for(let t=e;t instanceof Error;t=t.cause)if(t.name===`VersionError`)return!0;return!1}async function Vye(e){let t=[];for await(let n of e)t.push(n);return t}async function L9(e,t,n){let r=0;await Promise.all(Array.from({length:Math.min(t,e.length)},async()=>{for(;r<e.length;)await n(e[r++])}))}function Hye(e){let t=new Date(e),n=e=>String(e).padStart(2,`0`);return`${`${t.getFullYear()}-${n(t.getMonth()+1)}-${n(t.getDate())}`} ${n(t.getHours())}.${n(t.getMinutes())}.${n(t.getSeconds())}`}function Uye(e,t){let n=t.code===`not-text`?`这个文件不是 UTF-8 文本,编辑器读不懂,没有并入,也不会写回`:`代码文件不能超过 8 MiB,没有并入,也不会写回`;return{severity:`error`,code:t.code,file:e,message:n}}function R9(e,t){let n=e.problems?.filter(({file:e})=>e===t)??[];return n.length>0?n:[{severity:`error`,code:e.code,file:t,message:e.message}]}var Wye=0,Gye=()=>`${Date.now().toString(36)}-${(Wye+=1).toString(36)}`,Kye=class{#e;#t=0;#n=new Map;#r=new Map;#i=new Set;#a=new Set;#o;#s=new Map;#c=new Map;#l=new Set;#u=!1;#d=!1;#f=!1;#p;#m=Promise.resolve();#h=0;#g;#_=0;#v;#y;#b=!1;#x=0;#S=!0;#C=!1;#w=()=>{};ended;endReason=`lost`;trouble;writtenAt;unrecorded=!1;constructor(e){this.#e=e,this.ended=new Promise(e=>{this.#w=e})}get isOver(){return this.#C}get#T(){return this.#e.folder()}get work(){return this.#m}get#E(){let e=this.trouble?.reason;return e===`gone`||e===`replaced`||e===`too-new`}get troubleNow(){if(this.trouble)return this.trouble;let[e]=this.#a;return e===void 0?void 0:{reason:`busy`,path:e}}get status(){return this.troubleNow?`unsaved`:this.#h>0||this.#g!==void 0||this.#b?`saving`:this.#f?this.#S||this.#i.size>0?`saving`:`saved`:`unsaved`}get blocked(){return[...this.#r].map(([e,{problems:t,disk:n}])=>({path:e,problems:t,present:n.kind!==`absent`}))}start(){return this.#O(()=>this.#N())}stop(){this.#C=!0,this.#w(),clearTimeout(this.#g),clearTimeout(this.#y),clearTimeout(this.#o),this.#g=void 0,this.#p?.stop(),this.#p=void 0}#D(e){this.#C||(this.endReason=e,this.stop(),this.#e.changed())}changed(){if(!this.#C){for(let[e,{retry:t}]of this.#r)t&&this.#i.add(e);this.#S=!0,this.#v??=Date.now(),this.#k()}}async flush(){if(this.#C)return!1;this.#b=!1,clearTimeout(this.#y);for(let e=0;e<3&&!this.#C&&(clearTimeout(this.#g),this.#g=void 0,await this.#O(()=>this.#ie()),this.status===`saving`);e++);return this.status===`saved`}useEditorContent(e){return this.#O(()=>this.#_e(e))}async keep(e){let t;if(await this.#O(async()=>{try{let n=[];for(let t of e){let e=await this.#he(t);e!==void 0&&n.push(e)}t={kept:n}}catch(e){t={error:e}}}),t===void 0)throw new ba(`failed`,e[0]??``);if(`error`in t)throw t.error;return t.kept}reconnected(){return this.#O(async()=>{this.#j(void 0),this.#f=!1,await this.#P()})}#O(e){return this.#h+=1,this.#e.changed(),this.#m=this.#m.then(async()=>{if(!this.#C)try{await e()}catch(e){this.#M(e)}}).finally(()=>{--this.#h,this.#e.changed()}),this.#m}#k(e){if(this.#C||this.#E)return;let{quietMs:t,longestMs:n}=this.#e.timing,r=Date.now(),i=e===void 0?Math.min(r+t,(this.#v??r)+n):r+e;e!==void 0&&this.#g!==void 0&&this.#_<=i||(clearTimeout(this.#g),this.#_=i,this.#g=setTimeout(()=>{this.#g=void 0,this.#O(()=>this.#ie())},Math.max(0,i-r)),this.#e.changed())}#A(e){this.#a.add(e),this.#e.changed(),this.#o!==void 0||this.#C||(this.#o=setTimeout(()=>{this.#o=void 0;for(let e of this.#a)this.#i.add(e);this.#k(0)},this.#e.timing.retryMs))}#j(e){this.trouble=e,this.#e.changed(),this.#E&&this.#D(`park`)}#M(e){if(!this.#C){if(I9(e))this.#D(`outdated`);else{if(e instanceof ba){if(e.reason===`gone`){this.#j({reason:`gone`});return}this.#j({reason:e.reason,path:e.path})}else if(e instanceof DOMException&&e.name===`AbortError`)return;else console.warn(`The project folder could not be written`,e);this.#k(this.#e.timing.retryMs)}}}async#N(){let{bases:e,id:t,log:n}=this.#e,r;try{if(this.#t=await e.claim(t),this.#C)return;await n.caughtUp(),r=await e.load(t)}catch(e){I9(e)||console.warn(`The project folder cannot be compared now`,e),this.#D(I9(e)?`outdated`:`again`);return}if(!this.#C){this.#u=r.length===0;for(let{path:e,base:t,stat:n,synced:i,intent:a,replaced:o}of r)a!==void 0&&this.#c.set(e,a),(t!==void 0||o!==void 0)&&this.#n.set(e,{base:t,stat:n??x9,synced:i===void 0?void 0:{hash:i,text:void 0},replaced:o});await this.#P()}}async#P(){this.#p?.stop();let e=this.#T.watch({includes:N3,files:()=>this.#n.keys(),onChange:(e,t)=>this.#V(e,t.stillChanging),onProblem:e=>this.#U(e)});this.#p=e,await e.ready,this.#C||(await this.#F(),this.#C||(this.#f=!0))}async#F(){let e=this.#T;this.#r.clear();let t=await Vye(e.list({includes:N3})),n=this.#e.store.exportFiles().files,r=[...new Set([Sk,...t,...this.#n.keys(),...this.#c.keys(),...this.#s.keys()])].filter(M3),i=new Set([...r,...[...n.keys()].filter(M3)]);await e.removeLeftovers(i).catch(()=>[]);let a=await this.#G(r,n);this.#C||(a&&(this.#d=!0,this.#u=!1),await this.#te(),this.#S=!0,this.#k(0))}#I(e,t){let n=this.#n.get(e);if(!n)return;let r=T9(t);w9(n.stat,r)||(this.#n.set(e,{...n,stat:r}),this.#l.add(e))}#L(e){return Object.hasOwn(this.#e.store.getState().files,e)}#R(e){if(e?.kind!==`text`)return!0;if((F3(e.text)??0)>1)return this.#j({reason:`too-new`}),!1;let t=I3(e.text);return t===void 0||t===this.#e.store.getState().manifest.id||(this.#j({reason:`replaced`}),!1)}async#z(e){let t=new Map;return await L9(e,Aye,async e=>{t.set(e,await this.#B(e))}),t}async#B(e){for(let t=0;t<Mye;t++){let t;try{t=await this.#T.file(e)}catch(e){if(F9(e,`missing`,`refused`))return{kind:`absent`};if(F9(e,`gone`,`denied`))throw e;return}let n=C9(t);if(spe(e,t.size))return{kind:`unreadable`,stat:n,code:`file-too-large`};let r;try{r=new Uint8Array(await t.arrayBuffer())}catch{continue}let i=ipe(r);return i===void 0?{kind:`unreadable`,stat:n,code:`not-text`}:{kind:`text`,text:i,stat:n}}}async#V(e,t){if(!this.#C){this.#x+=1;for(let{path:t}of e)M3(t)&&this.#i.add(t);clearTimeout(this.#y),this.#y=void 0,t?(this.#b=!0,this.#y=setTimeout(()=>void this.#H(),this.#e.timing.settleMs),this.#e.changed()):(this.#b=!1,await this.#O(()=>this.#W()))}}async#H(){if(this.#y=void 0,this.#C)return;let e=this.#x;await this.#p?.flush().catch(()=>{}),this.#C||this.#x!==e||(this.#b=!1,this.#O(()=>this.#W()))}#U(e){this.#C||(e.reason===`gone`?this.#j({reason:`gone`}):e.reason===`denied`?(this.#j({reason:`denied`,path:e.path}),this.#k(this.#e.timing.retryMs)):console.warn(`The project folder could not be looked at`,e))}async#W(){if(!this.#f||this.#i.size===0||this.#E)return;let e=[...this.#i];this.#i.clear();try{await this.#G(e)}catch(t){for(let t of e)this.#i.add(t);throw t}await this.#te()}async#G(e,t){let n=await this.#z(e);if(this.#C)return!1;let r=n.get(Sk);if(r?.kind===`absent`&&this.#n.get(`animaquill.json`)?.base!==void 0)return this.#j({reason:`manifest-gone`}),!1;if(r&&!this.#R(r))return!1;if(this.trouble?.reason===`manifest-gone`){if(r?.kind!==`text`)return!1;if(this.#j(void 0),!t)return await this.#F(),!1}let i=!this.#d,a=this.#u?t??this.#e.store.exportFiles().files:void 0,o=[],s=[],c=!0;for(let t of e){let e=n.get(t);if(!e){c=!1,this.#A(t);continue}this.#a.delete(t);let r=this.#s.get(t);if(r){if(A9(r.disk,e)){this.#s.set(t,{...r,disk:e});continue}if(r.isKept||await this.#Z(t,r.disk),this.#s.delete(t),this.#C)return!1}let l=this.#n.get(t),u=this.#c.get(t),d=this.#r.get(t),f=l?l.base:a&&e.kind!==`absent`?a.get(t):void 0,p=()=>{this.#c.delete(t)&&this.#l.add(t),i&&l?.replaced!==void 0&&(this.#n.set(t,{...this.#n.get(t)??l,replaced:void 0}),this.#l.add(t))};if(i&&l?.replaced!==void 0&&zye(l.replaced,e))this.#s.set(t,{disk:e,isKept:!0}),this.#n.set(t,{...l,stat:T9(e),synced:void 0,replaced:void 0}),this.#l.add(t),this.#c.delete(t)&&this.#l.add(t);else{if(d){if(!d.retry&&k9(d.disk,e))continue}else if(D9(e,f)){l?this.#I(t,e):f!==void 0&&e.kind===`text`&&(this.#n.set(t,{base:f,stat:e.stat,synced:P9(f)}),this.#l.add(t)),p();continue}if(u!==void 0&&Lye(u,e)){let n=E9(e);this.#n.set(t,{base:n,stat:T9(e),synced:{hash:M9(u),text:n}}),this.#l.add(t),p()}else(u!==void 0&&Rye(u,e)||l!==void 0&&e.kind!==`absent`&&w9(l.stat,e.stat))&&e.kind!==`absent`&&ape(t,E9(e))?s.push([t,e]):(p(),e.kind===`unreadable`?(f!==void 0||j3(t)||this.#L(t))&&this.#q(t,e,[Uye(t,e)],!1,f):o.push({path:t,base:f,text:E9(e)}))}}for(let[e,t]of s)await this.#ge(e,t);if(o.length>0&&!this.#C){let e=new Map(n);for(let[t,{problems:n,disk:r}]of this.#r)n.every(({code:e})=>Pye.has(e))&&r.kind===`text`&&!e.has(t)&&(o.push({path:t,base:this.#n.get(t)?.base,text:r.text}),e.set(t,r));await this.#Y(o,e)}return c&&!this.#C}#K=e=>{let t=this.#r.get(e)?.disk??this.#s.get(e)?.disk;return t?t.kind===`text`?t.text:t.kind===`absent`?void 0:Fye:this.#n.get(e)?.base};#q(e,t,n,r,i){let a=t??{kind:`absent`};this.#r.set(e,{problems:n,disk:a,retry:r}),this.#s.delete(e),!this.#n.has(e)&&i!==void 0&&(this.#n.set(e,{base:i,stat:T9(a),synced:void 0}),this.#l.add(e)),this.#e.changed()}async#J(){return await this.#e.bases.turnOf(this.#e.id)===this.#t||(this.#D(`lost`),!1)}async#Y(e,t){let n;try{n=await this.#J()}catch(t){for(let{path:t}of e)this.#i.add(t);throw t}if(!n)return;let{store:r}=this.#e,i=WN(Gye()),a=e=>r.mergeFiles(e,{origin:i,baseOf:this.#K}),o=e,s=a(o);for(let e=0;e<3&&!s.ok&&S9.has(s.error.code)&&o.length>1;e++){let{error:e}=s,n=new Set((e.problems??[]).map(({file:e})=>e)),r=o.filter(({path:e})=>n.has(e));if(r.length===0||r.length===o.length)break;for(let{path:n,base:i}of r)this.#q(n,t.get(n),R9(e,n),!0,i);o=o.filter(({path:e})=>!n.has(e)),s=a(o)}if(!s.ok&&S9.has(s.error.code)&&o.length>1){for(let e of P3(o.map(({path:e})=>e)))for(let n of e){let e=o.filter(e=>e.path===n),r=a(e);r.ok?this.#$(r,e,t,i):this.#Q(r.error,e,t)}await this.#X()}else s.ok?(this.#$(s,o,t,i),await this.#X()):this.#Q(s.error,o,t)}async#X(){for(let[e,t]of this.#s)t.isKept||this.#C||await this.#Z(e,t.disk)&&this.#s.get(e)===t&&this.#s.set(e,{...t,isKept:!0})}async#Z(e,t){if(t.kind!==`text`)return!1;try{await this.#he(e,void 0,j9.encode(t.text))}catch(e){if(F9(e,`gone`,`denied`)||!(e instanceof ba))throw e;return console.warn(`What the folder had of a file could not be kept yet`,e),!1}if(this.#C)return!1;let n=this.#n.get(e);return this.#n.set(e,{base:t.text,stat:t.stat,synced:void 0,...n?.replaced!==void 0&&{replaced:n.replaced}}),this.#l.add(e),!0}#Q(e,t,n){if(e.code===`missing-updates`){for(let{path:e}of t)this.#i.add(e);this.#k(this.#e.timing.retryMs);return}e.code===`manifest-deleted`&&this.#j({reason:`manifest-gone`});let r=Nye.has(e.code);for(let{path:i,base:a}of t)this.#q(i,n.get(i),R9(e,i),r,a)}#$(e,t,n,r){let i=this.#e.store.exportFiles().files,a=new Map(t.map(({path:e,base:t})=>[e,t])),o=[];for(let t of e.files){let r=n.get(t.path);if(t.status===`blocked`){let n=e.problems.filter(({file:e})=>e===t.path),i=n.length>0?n:R9({code:`blocked`,message:`这个文件没有并入,等你处理`},t.path);this.#q(t.path,r,i,!1,a.get(t.path));continue}if(this.#r.delete(t.path),this.#s.delete(t.path),t.status===`ignored`){this.#n.delete(t.path)&&this.#l.add(t.path);continue}o.push(t.path);let s=e.conflicts.some(({file:e})=>e===t.path)||e.problems.some(({file:e})=>e===t.path);if(t.rewrite&&s&&r&&r.kind!==`absent`){this.#s.set(t.path,{disk:r,isKept:!1});let e=this.#n.get(t.path);e&&this.#n.set(t.path,{...e,synced:void 0});continue}let c=i.get(t.path);this.#n.set(t.path,{base:t.base,stat:r?T9(r):x9,synced:t.rewrite?void 0:P9(c)}),this.#l.add(t.path)}(e.patches.length>0||e.problems.length>0)&&this.#e.merged({origin:r,files:o,conflicts:e.conflicts,problems:e.problems}),e.files.some(({rewrite:e})=>e)&&this.#k(0)}#ee(e){let t=this.#n.get(e),n=this.#c.get(e);if(t?.base!==void 0||t?.replaced!==void 0||n!==void 0)return{path:e,...t?.base!==void 0&&{base:t.base},...t&&t.stat!==x9&&{stat:t.stat},...t?.synced&&{synced:t.synced.hash},...t?.replaced!==void 0&&{replaced:t.replaced},...n!==void 0&&{intent:n}}}async#te(e){if(this.#l.size===0)return;let t=e??await this.#e.log.saved();if(this.#C)return;if(!t){this.#k(this.#e.timing.retryMs);return}let n=[...this.#l],r=[],i=[];for(let e of n){let t=this.#ee(e);t?r.push(t):i.push(e)}this.#l.clear();try{if(!await this.#ne({put:r,remove:i}))return;this.unrecorded&&(this.unrecorded=!1,this.#e.changed())}catch(e){for(let e of n)this.#l.add(e);throw e}}async#ne(e){let t=await this.#e.bases.save(this.#e.id,this.#t,e);return t||this.#D(`lost`),t}async#re(){let e=this.#n.get(Sk),t=this.#r.get(`animaquill.json`)?.disk??this.#s.get(`animaquill.json`)?.disk,n;try{n=await this.#T.file(Sk)}catch(n){if(!F9(n,`missing`))throw n;(t?T9(t):e?.stat)!==x9&&this.#i.add(Sk);return}let r=C9(n),i=t?T9(t):e?.stat;i!==void 0&&i!==x9&&w9(i,r)||this.#i.add(Sk)}async#ie(){if(clearTimeout(this.#g),this.#g=void 0,this.#v=void 0,this.#C||this.#E||!this.#f&&(await this.#P(),!this.#f)||this.#b||(await this.#re(),this.#i.size>0&&await this.#W(),this.#C||this.#E))return;if(this.trouble?.reason===`manifest-gone`){await this.#te();return}this.#S=!1;let{files:e,problems:t}=this.#e.store.exportFiles(),n=this.#se(e,new Set(t.map(({file:e})=>e)));if(n.writes.size+n.removes.length+n.moves.length===0){await this.#te(),this.#C||this.#ae(n,void 0);return}let r=await this.#e.log.saved();if(this.#C)return;let i=new Map([...n.writes].map(([e,t])=>[e,XK(t)]));if(r){for(let[e,t]of i)this.#c.set(e,Iye(n.writes.get(e),t)),this.#l.add(e);for(let e of n.removes)this.#c.set(e,x9),this.#l.add(e);if(await this.#te(!0),this.#C)return}let a,o=!1,s=async(e,t)=>{await L9(e,jye,async e=>{if(this.#C)return;let n=this.#oe(e);try{!await t(e)&&n&&(o=!0)}catch(e){a??=e,n&&(o=!0)}})};await s(n.moves.map(([e])=>e),e=>this.#me(e,n.moves.find(([t])=>t===e)?.[1]));for(let e of P3(n.writes.keys())){if(o||this.#C)break;await s(e,e=>this.#fe(e,n.writes.get(e),i.get(e)))}for(let e of P3(n.removes,!0)){if(o||this.#C)break;await s(e,e=>this.#pe(e))}if(!this.#C){for(let e of[...n.writes.keys(),...n.removes])this.#c.delete(e)&&this.#l.add(e);r||(this.unrecorded=!0,this.#e.changed()),await this.#te(r||void 0),this.#C||(this.writtenAt=Date.now(),this.#ae(n,a),this.#i.size>0&&this.#k(0))}}#ae(e,t){t===void 0?this.#j(e.clash?{reason:`clash`,path:e.clash}:void 0):this.#M(t)}#oe(e){let t=this.#s.get(e)?.disk;if(t)return t.kind===`absent`;let n=this.#n.get(e);return!n||n.stat===x9}#se(e,t){let n=new Map,r=[],i=[],a=[],o,s=[...new Set([...e.keys(),...this.#n.keys(),...this.#s.keys()])].filter(M3).toSorted(),c=new Map;for(let t of s){if(!e.has(t))continue;let n=di(t);c.has(n)?o??=t:c.set(n,t)}for(let i of s){if(t.has(i)||this.#a.has(i))continue;let o=e.get(i),s=this.#r.get(i);if(s){O9(o,s.disk)&&this.#le(i,o,s.disk);continue}if(o!==void 0&&c.get(di(i))!==i)continue;let l=this.#n.get(i),u=this.#s.has(i);if(!u&&Bye(l,o))continue;if(o!==void 0){n.set(i,o);continue}if(i===`animaquill.json`)continue;if(!u&&(!l||l.stat===x9)){l&&l.replaced===void 0&&this.#ce(i);continue}let d=c.get(di(i));d===void 0?r.push(i):a.push([i,d])}for(let[e,t]of a)n.has(t)&&!this.#n.has(t)&&i.push([e,t]);return{writes:n,removes:r,moves:i,clash:o}}#ce(e){this.#n.delete(e),this.#l.add(e)}#le(e,t,n){this.#r.delete(e),this.#n.set(e,{base:E9(n),stat:T9(n),synced:P9(t)}),this.#l.add(e),this.#e.changed()}async#ue(e){let t=await this.#B(e);if(!t){this.#A(e);return}this.#a.delete(e);let n=this.#s.get(e);if(n){if(A9(n.disk,t))return this.#s.set(e,{...n,disk:t}),t}else if(D9(t,this.#n.get(e)?.base))return this.#I(e,t),t;this.#i.add(e)}async#de(e,t){let n=this.#s.get(e);if(!n||n.isKept||t.kind===`absent`)return!0;try{await this.#he(e,t.stat,t.kind===`text`?j9.encode(t.text):void 0)}catch(t){if(!F9(t,`changed`))throw t;return this.#s.delete(e),this.#i.add(e),!1}this.#s.set(e,{disk:t,isKept:!0});let r=this.#n.get(e);return this.#n.set(e,{base:E9(t),stat:t.stat,synced:void 0,...r?.replaced!==void 0&&{replaced:r.replaced}}),this.#l.add(e),await this.#te(),!this.#C}async#fe(e,t,n){let r=await this.#ue(e);if(!r||this.#C||!await this.#de(e,r))return!1;try{let i=await this.#T.write(e,t,{expected:T9(r)});return this.#C||(this.#n.set(e,{base:t,stat:C9(i),synced:{hash:n,text:t},replaced:N9(r)}),this.#s.delete(e),this.#l.add(e)),!0}catch(t){if(!F9(t,`changed`))throw t;return this.#i.add(e),!1}}async#pe(e){let t=await this.#ue(e);if(!t||this.#C)return!1;if(t.kind===`absent`)return this.#s.delete(e),this.#n.get(e)?.replaced===void 0&&this.#ce(e),!0;if(!await this.#de(e,t))return!1;try{return await this.#T.remove(e,{expected:t.stat}),this.#C||(this.#n.set(e,{base:void 0,stat:x9,synced:P9(void 0),replaced:N9(t)}),this.#s.delete(e),this.#l.add(e)),!0}catch(t){if(!F9(t,`changed`))throw t;return this.#i.add(e),!1}}async#me(e,t){let n=this.#n.get(e);if(!n||n.stat===x9)return!0;try{await this.#T.move(e,t,{expected:n.stat})}catch(n){if(!F9(n,`changed`,`exists`))throw n;return this.#i.add(e),this.#i.add(t),!1}if(this.#C)return!0;let r=await this.#B(t);return this.#ce(e),r?.kind===`text`&&(this.#n.set(t,{base:n.base,stat:r.stat,synced:void 0}),this.#l.add(t)),!0}async#he(e,t,n){let r=this.#T,i;if(n)i=n;else try{let n=await r.file(e);if(t&&!w9(C9(n),t))throw new ba(`changed`,e);i=new Uint8Array(await n.arrayBuffer())}catch(t){if(F9(t,`missing`))return;throw t instanceof ba?t:new ba(`changed`,e,{cause:t})}try{await r.write(kye,`*
215
- `,{expected:`absent`})}catch(e){if(!F9(e,`changed`))throw e}let a=Hye(Date.now()),o=e.split(`/`).at(-1);for(let t=1;t<=100;t++){let n=`${b9}/${a}${t===1?``:`-${t}`}`;for(let t of[`${n}/${e}`,`${n}/${o}`])try{return await r.write(t,i,{expected:`absent`}),t}catch(e){if(F9(e,`changed`,`exists`))break;if(F9(e,`too-long`,`refused`)&&t!==`${n}/${o}`)continue;throw e}}throw new ba(`failed`,e)}async#ge(e,t){try{await this.#he(e,t.kind===`absent`?void 0:t.stat)}catch(n){if(!(n instanceof ba))throw n;let r={severity:`error`,code:`not-kept`,file:e,message:`这个文件坏了,没能先备份到 .animaquill/recovered,所以没有重写`};this.#c.delete(e)&&this.#l.add(e),this.#q(e,t,[r],!1,this.#n.get(e)?.base);return}this.#s.set(e,{disk:t,isKept:!0});let n=N9(t),r=this.#n.get(e)??{base:void 0,stat:x9,synced:void 0};this.#n.set(e,{...r,synced:void 0,...n!==void 0&&{replaced:n}}),this.#l.add(e)}async#_e(e){let t=this.trouble?.reason===`manifest-gone`,{files:n}=this.#e.store.exportFiles(),r=e??(t?[...new Set([...n.keys(),...this.#n.keys(),...this.#r.keys()])].filter(M3):[...this.#r.keys()]);for(let e of r){if(!t&&!this.#r.has(e))continue;let r=await this.#B(e);if(!r){this.#A(e);continue}let i=n.get(e);this.#r.delete(e);let a=this.#n.get(e);O9(i,r)?(this.#s.delete(e),this.#n.set(e,{base:E9(r),stat:T9(r),synced:P9(i)}),this.#l.add(e)):(await this.#he(e,r.kind===`absent`?void 0:r.stat),this.#s.set(e,{disk:r,isKept:!0}),a&&this.#n.set(e,{...a,synced:void 0}))}t&&this.#j(void 0),this.#S=!0,this.#e.changed(),await this.#ie()}},qye=class{#e;#t;#n;#r;#i;#a;#o;#s=`starting`;#c;#l;#u;#d=!1;#f=!1;#p=!1;#m=()=>{};#h;#g;#_;#v=()=>{};#y=!1;#b;#x=new sv;#S=new Set;#C={role:`starting`,status:`saving`,trouble:void 0,blocked:[],writtenAt:void 0,unrecorded:!1,compared:!1};#w;constructor({store:e,folder:t,id:n,bases:r,writer:i,log:a,timing:o}){this.#e=e,this.#o=t,this.#t=n,this.#n=r,this.#r=i,this.#i=a,this.#a={...Oye,...o},this.#h=new Promise(e=>{this.#m=e}),this.#w=[e.subscribe(()=>this.#c?.changed()),e.onLocalUpdate(()=>this.#D())]}subscribe=this.#x.subscribe;getSnapshot=()=>this.#C;get folder(){return this.#o}onMerge(e){return this.#S.add(e),()=>this.#S.delete(e)}start(){if(!this.#g){let e=()=>{};this.#g=new Promise(t=>{e=t}),this.#T(e).catch(e=>console.warn(`The project folder is not kept any more`,e)).finally(e)}return this.#g}async flush(){let e=this.#c;return e?e.flush():!this.#_&&this.#i.saved()}async idle(){for(;;){let e=this.#c;if(!e)return;let t=e.work;if(await t,this.#c===e&&e.work===t)return}}async close(){if(!this.#p){await this.#c?.flush().catch(()=>!1),this.#p=!0,this.#m(),this.#v(),this.#u?.abort();for(let e of this.#w)e();this.#c?.stop(),this.#c=void 0,this.#l?.release(),this.#l=void 0,this.#O(`closed`)}}async useEditorContent(e){let t=this.#c;return t?(await t.useEditorContent(e),!0):!1}async keep(e){let t=this.#c;if(t)return t.keep(e)}async reconnect(e=this.#o){let t=await e.status().catch(()=>`gone`);if(t===`gone`)return`gone`;if(t!==`ready`)return`ask`;let n;try{n=await e.readText(Sk)}catch(e){return F9(e,`gone`)?`gone`:`not-a-project`}return I3(n)===this.#e.getState().manifest.id?(this.#o=e,this.#_&&this.#_.reason!==`outdated`?(this.#_=void 0,this.#v(),this.#k()):await this.#c?.reconnected(),`connected`):`other-project`}async#T(e){for(;!this.#p;){if(this.#_){if(this.#O(`stopped`),e(),this.#_.reason===`outdated`)return;await new Promise(e=>{this.#v=e});continue}let t=await this.#E(e);if(!t)return;if(this.#p){t.release();return}this.#l=t;let n=new Kye({store:this.#e,id:this.#t,bases:this.#n,log:this.#i,timing:this.#a,folder:()=>this.#o,changed:()=>this.#k(),merged:e=>{for(let t of this.#S)t(e)}});if(this.#c=n,this.#O(`writing`),await n.start(),n.isOver||(this.#b=n,this.#k()),e(),await Promise.race([t.lost,n.ended,this.#h]),n.stop(),t.release(),this.#y=n.unrecorded,this.#c===n&&(this.#c=void 0),this.#l=void 0,this.#p)return;n.endReason===`outdated`?this.#_={reason:`outdated`}:n.endReason===`park`?this.#_=n.trouble??{reason:`gone`}:(this.#O(`waiting`),n.endReason===`again`&&await Promise.race([new Promise(e=>setTimeout(e,this.#a.retryMs)),this.#h]))}}async#E(e){for(;;){if(this.#p)return;if(this.#d){this.#d=!1;try{return await this.#r.claim({steal:!0})}catch(e){console.warn(`Could not take over writing the project folder`,e)}}let t=new AbortController;this.#u=t;let n=!1;try{let r=await this.#r.claim({signal:t.signal,onWaiting:()=>{n||this.#p||this.#u!==t||(this.#O(`waiting`),e())}});return n=!0,r}catch(e){if(!t.signal.aborted){if(e instanceof DOMException&&e.name===`AbortError`)return;console.warn(`Could not find out which window writes the project folder`,e),await new Promise(e=>setTimeout(e,this.#a.retryMs))}}finally{this.#u===t&&(this.#u=void 0)}}}#D(){this.#s!==`waiting`||this.#f||this.#p||(this.#f=!0,(async()=>{try{if(await new Promise(e=>setTimeout(e,this.#a.quietMs)),this.#s!==`waiting`||this.#p||await this.#r.answers(this.#a.answerMs)||this.#s!==`waiting`||this.#p)return;this.#d=!0,this.#u?.abort()}finally{this.#f=!1}})())}#O(e){this.#s=e,this.#k()}#k(){let e=this.#s===`writing`?this.#c:void 0,t=e?e.status:this.#s===`waiting`?`elsewhere`:this.#s===`closed`?`saved`:this.#s===`stopped`?`unsaved`:`saving`,n=e?e.troubleNow:this.#s===`stopped`?this.#_:void 0,r=e?.blocked??[],i=e?.writtenAt??this.#C.writtenAt,a=e?e.unrecorded:this.#y,o=e!==void 0&&this.#b===e,s=this.#C,c=s.trouble===n||s.trouble?.reason===n?.reason&&s.trouble?.path===n?.path;s.role===this.#s&&s.status===t&&c&&s.writtenAt===i&&s.unrecorded===a&&s.compared===o&&s.blocked.length===r.length&&s.blocked.every((e,t)=>e.path===r[t]?.path&&e.problems===r[t]?.problems)||(this.#C={role:this.#s,status:t,trouble:n,blocked:r,writtenAt:i,unrecorded:a,compared:o},this.#x.emit())}},Jye=300,Yye=50,z9=4e3,Xye=100,Zye=100,B9=1e7,Qye=1e8,$ye=2,ebe={open:void 0,waiting:void 0,moves:0};function tbe(e,t){if(e===void 0)return t(`folder.theirsRemoved`);let n=typeof e==`string`?e:JSON.stringify(e,null,2);return n.length>z9?`${n.slice(0,z9)}…`:n}function V9(e,t,n){let r=n.slice(0,Xye),i=n.length-r.length;return{title:e(`transfer.listTitle`,{title:t,count:n.length}),items:i>0?[...r,e(`transfer.andMore`,{count:i})]:r}}var H9=(e,{file:t,path:n,message:r})=>e(`transfer.problem`,{place:n?`${t} ${n}`:t,message:r}),nbe=({files:e,totalFiles:t,bytes:n,totalBytes:r})=>{let i=r+t*B9;return i>0?Math.min(1,(n+e*B9)/i):1},rbe=class{projects;#e;#t=new sv;#n;#r;#i;#a=ebe;#o=[];#s=new Map;#c=[];#l=[];#u;#d=new sv;#f=R3;#p;#m=!1;#h=0;constructor(e){this.#e=e,this.projects=new Dye({folders:e.folders,projects:e.projects,t:e.t}),this.#p=new wye({folders:e.folders,projects:e.projects,t:e.t,...e.hasher&&{hasher:e.hasher}})}subscribe=this.#t.subscribe;getSnapshot=()=>this.#a;get session(){return this.#n?.session}assets(){let e=this.#u,{store:t}=this.#e.session;return e&&t&&JG(t)===e.key?e.assets:void 0}mediaFor(e,t){let n=this.#u;if(n?.key===e)return n.assets.media(()=>this.#e.session.store?.getState().assets,t===void 0?{}:{since:t})}subscribeProgress=this.#d.subscribe;getProgress=()=>this.#f;#g(e){this.#f=e,this.#d.emit()}async droppedFiles(e){return this.#_(await this.#e.folders.dropped(e))}async pickFiles(){let e=this.#n;if(!e)return;let t=await this.#e.folders.chooseFiles(e.session.folder);return t&&this.#_(t)}async#_(e){let t=this.#n?.session.folder,n=[],r=[],i=[];for(let a of e){if(a.kind===`folder`){i.push(a.folder.name);continue}let e=await t?.pathOf(a).catch(()=>void 0);if(e&&!M3(e)&&!jH(e))n.push(e);else try{r.push(await a.file.read())}catch(e){console.warn(`A file that people brought in cannot be read`,e),i.push(a.file.name)}}return{inside:n,files:r,unreadable:i}}#v(e){clearTimeout(e.checkTimer),e.checkTimer=setTimeout(()=>void this.#y(e),Jye)}async#y(e){return e.checking?(e.checkAgain=!0,e.checking):(e.checkAgain=!1,e.checkedAssets=e.store.getState().assets,e.checking=e.assets.check(e.store).catch(e=>(console.warn(`The files of the assets could not be looked at`,e),[])).then(t=>{if(this.#n!==e)return;let{t:n}=this.#e,r=e.relocated&&t.some(({kind:e})=>e===`missing`)?[{severity:`warning`,text:n(`folder.assetsLeftBehind`),origin:n(`folder.origin`)}]:[];this.#c=[...r,...t.map(t=>this.#b(e,t))],this.#l=t,this.#Y()}).finally(()=>{e.checking=void 0,e.checkAgain&&this.#n===e&&this.#y(e)}),e.checking)}get assetIssues(){return this.#l}checkAssetsSoon(){this.#n&&this.#v(this.#n)}async assetsChecked(){let e=this.#n;e&&(clearTimeout(e.checkTimer),await this.#y(e))}#b(e,t){let{t:n,assetFiles:r}=this.#e,i=t=>void t.then(t=>t&&this.#v(e)),a={file:t.path,origin:n(`folder.origin`),severity:`warning`};if(t.kind===`changed`)return{...a,text:n(`folder.asset.changed`),action:{label:n(`folder.asset.useNew`),run:()=>i(r.useNewFile(t.asset))}};if(t.hidden!==void 0)return{...a,text:n(`folder.asset.hidden`,{name:t.hidden})};let{found:o}=t;return o===void 0?t.copy?{...a,text:n(`folder.asset.missing`),action:{label:n(`folder.move.restoreCopy`),run:()=>void this.#x(e,t.asset,t.path)}}:{...a,text:n(`folder.asset.missing`)}:{...a,text:n(`folder.asset.moved`,{found:o}),action:{label:n(`folder.asset.usePlace`),run:()=>i(r.usePlace(t.asset,o))}}}async#x(e,t,n){let{notifications:r,projects:i,assetFiles:a,t:o}=this.#e;try{let r=e.store.getState().assets?.[t]?.hash,o=r===void 0?void 0:await i.media(e.record.id).get(r);if(!o)throw Error(`No copy of ${n} in the browser`);await e.session.folder.write(n,o,{expected:`absent`}),a.filesChanged([n]),this.#v(e)}catch(e){console.warn(`A copy could not go back into the project folder`,e),r.push(o(`folder.move.restoreFailed`,{path:n,reason:this.#K(e)}))}}#S(e){let{folder:t}=e.session;if(e.assetWatch?.folder===t)return;let n=e.assetWatch!==void 0;e.assetWatch?.stop(),e.assetWatch={folder:t,stop:e.assets.watch(()=>Object.values(e.store.getState().assets??{}).map(({path:e})=>e),t=>{this.#n===e&&(this.#e.assetFiles.filesChanged(t),this.#v(e))})},n&&(this.#e.assetFiles.filesChanged(Object.values(e.store.getState().assets??{}).map(({path:e})=>e)),this.#v(e))}async restore(){let e=this.#e.address.read();if(e===void 0)return!1;let t;try{t=await this.projects.records.get(e)}catch(e){return console.warn(`The folders this browser knows cannot be read`,e),this.#e.notifications.push(this.#e.t(`folder.recordsFailed`)),!0}return t?(this.#i=t,!0):(await this.#e.projects.list().catch(()=>[])).some(t=>t.id===e&&t.folder===!0)}async resume(){let e=this.#i;if(this.#i=void 0,!e)return;let t=await this.projects.statusOf(e);t===`ready`?await this.#e.changeProject(()=>this.#V(e)):this.#J({record:e,status:t})}async flush(){return await this.#n?.session.flush()??!0}async close(){let e=this.#n;if(!e||(await e.session.flush().catch(()=>!1),this.#n!==e))return;this.#n=void 0,this.#u?.assets===e.assets&&(this.#u=void 0),e.stop(),this.#g(R3),this.#o=[],this.#c=[],this.#l=[],this.#Y(),await e.session.close();let{name:t}=e.store.getState().manifest;t!==e.record.name&&await this.projects.opened(e.record,t).catch(()=>{})}followSession(){let{store:e}=this.#e.session,t=this.#n;t&&e!==t.store&&this.close(),e&&this.#r&&this.#J(void 0)}async create(){let e=await this.#j();if(!e)return;let t=await this.#M();t&&await this.#F(t,e)}async open(){let e=await this.#M();e&&await this.#I(e)}dropped(e){let{folders:t,notifications:n,t:r}=this.#e;t.dropped(e).then(async e=>{let t=e.find(e=>e.kind===`folder`);if(t?.kind!==`folder`){e.length>0&&n.push(r(`folder.droppedNoFolder`));return}let{folder:i}=t;await this.projects.mayBeProject(i)?await this.#I(i,await i.requestAccess()):await this.#q(r(`folder.refusedTitle`,{folder:i.name}),r(`folder.refused.not-a-project`))}).catch(e=>this.#N(e))}list(){return this.projects.records.list()}async openRecent(e){let t=await this.projects.statusOf(e);t===`gone`?await this.#B(e):t===`blocked`?this.#e.notifications.push(this.#e.t(`folder.blocked`,{name:e.name})):(t!==`ask`||await e.folder.requestAccess()===`granted`)&&(this.#J(void 0),await this.#e.changeProject(()=>this.#V(e)))}async findAgain(e){let{notifications:t,t:n}=this.#e,r=await this.#M();if(!r)return;let i=this.#n;if(i?.record.id===e.id){let a=await this.projects.records.find(r);if(a&&a.id!==e.id){t.push(n(`folder.reconnect.taken`,{name:e.name,other:a.name}));return}let o=await i.session.reconnect(r);o===`connected`?(i.record={...i.record,folder:r},await this.projects.opened(i.record).catch(()=>{}),this.#Y()):t.push(n(`folder.reconnect.${o}`,{name:e.name}));return}let a=await this.projects.findAgain(e,r).catch(()=>`not-a-project`);if(a!==`found`){let i=a===`taken`?await this.projects.records.find(r):void 0;t.push(n(`folder.reconnect.${a}`,{name:e.name,other:i?.name??``}))}else this.#J(void 0),await this.#e.changeProject(()=>this.#V({...e,folder:r}))}async saveElsewhere(e,{asked:t=!1}={}){let{dialogs:n,notifications:r,t:i}=this.#e;if(!t){let t=await n.choose({title:i(`folder.elsewhereTitle`,{name:e.name}),message:i(`folder.elsewhereMessage`),choices:[{id:`find`,label:i(`folder.findAgain`)},{id:`elsewhere`,label:i(`folder.chooseNewPlace`),kind:`primary`}]});if(t===`find`&&await this.findAgain(e),t!==`elsewhere`)return}let a=await this.#M();if(!a)return;let o=await this.#P(a,e.name);if(!o)return;let s,c;try{s=o.inside===void 0?a:await a.inside(o.inside,{create:!0}),c=await this.projects.relocate(e,s)}catch(e){console.warn(`A project could not be written to a new place`,e),r.push(i(`folder.createFailed`));return}this.#J(void 0),await this.#e.changeProject(()=>this.#V(c,{relocated:!0}))}async allowAgain(){let e=this.#n;e&&await e.record.folder.requestAccess()===`granted`&&await e.session.reconnect()}async writeEditorContent(e){await this.#n?.session.useEditorContent(e)}async remove(e){let{dialogs:t,notifications:n,t:r}=this.#e,i=await this.projects.statusOf(e)!==`ready`||await this.projects.hasUnwritten(e);if(!await t.confirm({title:r(`folder.removeTitle`,{name:e.name}),message:r(i?`folder.removeOnlyCopy`:`folder.removeMessage`),confirm:r(`folder.remove`),...i&&{danger:!0}}))return!1;try{return await this.#e.letGo(e.id),await this.projects.forget(e.id),this.#r?.record.id===e.id&&this.#J(void 0),!0}catch(e){return console.warn(`A folder could not be taken off the list`,e),n.push(r(`folder.removeFailed`)),!1}}get moving(){return this.#m}holds(e){return e!==void 0&&(this.#u?.key===e||this.#n?.record.id===e)}async moveToFolder(e){if(this.#m)return!1;this.#m=!0;try{return await this.#C(e)}finally{this.#m=!1}}async#C(e){let{session:t,projects:n,presence:r,dialogs:i,notifications:a,t:o}=this.#e,s=t.key===e?t.store:void 0,c=await r?.others(e).catch(()=>0)??0;if(c>0){let t=s?.getState().manifest.name??await this.#T(e);if(!await i.confirm({title:o(`folder.move.othersTitle`,{name:t,count:c}),message:o(`folder.move.othersMessage`,{count:c}),confirm:o(`folder.move.othersConfirm`)}))return!1}let l=await this.#M();if(!l)return!1;let u;try{s||(u=await h9(n,e));let c=s??u?.store;if(!c)return a.push(o(`notice.projectNotFound`)),!1;let d=s?()=>t.trySave():u.saved,{name:f}=c.getState().manifest;if(!await d())return await this.#q(o(`folder.move.refusedTitle`,{name:f}),o(`folder.move.unsaved`)),!1;let p=n.media(e),m=await this.#p.check(e,c,p);if(m)return await this.#k(f,m),!1;let h=await this.#P(l,f);if(!h)return!1;let g=i.progress({title:o(`folder.move.title`,{name:f}),cancel:o(`dialog.cancel`),stopping:o(`transfer.stopping`)}),_;try{_=await this.#p.run(e,c,p,{chosen:l,inside:h.inside},{notice:o(`folder.move.incompleteNotice`),signal:g.signal,onStep:this.#E(g),saved:d})}finally{g.close()}return _.kind===`moved`?(s&&t.store===s&&await this.#w(_.record,s),r?.moved(e),await this.#D(f,_),!0):(await this.#O(f,_),!1)}catch(e){return console.warn(`A project could not be moved into a folder`,e),a.push(o(`folder.move.failed`)),!1}finally{u?.close()}}async followMove(e){this.#h+=1,this.#Y();let{session:t,notifications:n,t:r}=this.#e,i=t.store;if(!i||t.key!==e||this.holds(e))return;let a=await this.projects.records.get(e).catch(()=>void 0);a&&t.store===i&&!this.holds(e)&&(await this.#w(a,i),n.push(r(`folder.move.movedElsewhere`,{name:i.getState().manifest.name,folder:a.folder.name})))}async#w(e,t){await this.#U(e,t,this.#H(e),!1),this.#e.assetFiles.filesChanged(Object.values(t.getState().assets??{}).map(({path:e})=>e))}async#T(e){return(await this.#e.projects.list().catch(()=>[])).find(({id:t})=>t===e)?.name??``}copiesOf(e){return this.#p.copiesOf(e.id).catch(()=>0)}async releaseCopies(e,{asked:t=!1}={}){let{dialogs:n,notifications:r,projects:i,folders:a,hasher:o,presence:s,session:c,t:l}=this.#e;if(!t){let t=EY(await this.copiesOf(e));if(!await n.confirm({title:l(`folder.move.releaseTitle`,{name:e.name}),message:l(`folder.move.releaseMessage`,{size:t}),confirm:l(`folder.move.release`,{size:t})}))return!1}let u=await this.projects.statusOf(e);if(u===`ask`&&await e.folder.requestAccess()===`granted`&&(u=`ready`),u!==`ready`)return r.push(l(`folder.move.releaseUnreachable`,{name:e.name})),!1;let d=this.#n?.record.id===e.id?this.#n:void 0,f=d?.assets??new K3({folder:()=>e.folder,key:e.id,bases:a.bases,browser:i.media(e.id),...o&&{hasher:o}}),p;try{d||(p=await h9(i,e.id));let t=d?.store??p?.store;if(!t)throw Error(`Nothing of project ${e.id} to compare its files with`);let n=c.key===e.id||(await s?.others(e.id).catch(()=>0)??0)>0,{released:a,missing:o,unused:u}=await this.#p.release(e.id,t.getState().assets??{},f,{open:n}),m=[l(`folder.move.released`,{size:EY(a)})];return o.length>0&&m.push(l(`folder.move.releasedMissing`,{count:o.length})),u.length>0&&m.push(l(`folder.move.releasedUnused`,{count:u.length})),r.push(m.join(``)),a>0}catch(e){return console.warn(`The copies in the browser could not be let go of`,e),r.push(l(`folder.move.releaseFailed`)),!1}finally{p?.close(),f!==d?.assets&&f.stop()}}#E(e){let{t}=this.#e,n=-1/0,r,i=0;return a=>{let o=performance.now();if(a.phase!==r&&(r=a.phase,i=o,n=-1/0),o-n<Zye)return;n=o;let s=nbe(a),c=(o-i)/1e3,l=c<$ye||s<=0?((a.totalFiles-a.files)*B9+a.totalBytes-a.bytes)/Qye:c*(1-s)/s,u=Math.ceil(l),d=t(`folder.move.${a.phase}`,{done:a.files,total:a.totalFiles});e.update({detail:a.file,ratio:s,amount:u>1?`${d}${t(`folder.move.left`,{seconds:u})}`:d})}}async#D(e,{record:t,missing:n,damaged:r,renamed:i,copies:a}){let{dialogs:o,t:s}=this.#e,c=s(`folder.move.movedTitle`),l=s(`folder.move.moved`,{name:e,folder:t.folder.name}),u=[V9(s,s(`folder.move.missing`),n),V9(s,s(`folder.move.damaged`),r),V9(s,s(`folder.move.renamed`),i.map(({from:e,to:t})=>s(`folder.move.renamedItem`,{from:e,to:t})))].filter(({items:e})=>e.length>0);if(a===0){await this.#q(c,l,u);return}let d=EY(a);await o.confirm({title:c,message:`${l}${s(`folder.move.copies`,{size:d})}`,confirm:s(`folder.move.release`,{size:d}),cancel:s(`folder.move.keep`),...u.length>0&&{details:u}})&&await this.releaseCopies(t,{asked:!0})}async#O(e,t){let{dialogs:n,notifications:r,t:i}=this.#e,a=i(`folder.move.failedTitle`,{name:e}),o=(e,t)=>e?i(`folder.move.nothingLeft`):i(`folder.move.leftBehind`,{folder:t,file:DH});switch(t.kind){case`refused`:await this.#k(e,t.refusal);return;case`stopped`:{if(t.cancelled&&t.cleaned){r.push(i(`folder.move.cancelled`,{name:e}));return}let n=t.cancelled?i(`folder.move.cancelled`,{name:e}):i(`folder.move.writeFailed`,{file:t.file,reason:this.#K(t.error)});await this.#q(a,`${n}${o(t.cleaned,t.folder)}`);return}case`unverified`:{if(!await n.confirm({title:a,message:i(`folder.move.unverified`,{folder:t.folder,file:`导出未完成.txt`}),confirm:i(`folder.move.discard`),cancel:i(`folder.move.keepFolder`),danger:!0,details:[V9(i,i(`folder.move.mismatchList`),t.mismatches.flatMap(e=>this.#A(e)))]}))return;let e=await t.takeBack().catch(()=>!1);r.push(e?i(`folder.move.discarded`,{folder:t.folder}):i(`folder.move.discardedPartly`,{folder:t.folder,file:DH}));return}case`unswitched`:console.warn(`A project in a folder could not be kept by it`,t.error),await this.#q(a,`${i(`folder.move.unswitched`,{folder:t.folder})}${o(t.cleaned,t.folder)}`);return}}async#k(e,t){let{notifications:n,t:r}=this.#e;if(t.kind===`already`||t.kind===`busy`){n.push(r(`folder.move.${t.kind}`,{name:e}));return}let i=t.kind===`invalid`?t.problems.map(e=>H9(r,e)):t.kind===`too-new`?[]:t.paths;await this.#q(r(`folder.move.refusedTitle`,{name:e}),r(`folder.move.refused.${t.kind}`),i.length>0?[V9(r,r(`folder.move.listTitle`),i)]:void 0)}#A(e){let{t}=this.#e;switch(e.kind){case`unreadable`:return[t(`folder.move.mismatch.unreadable`,{reason:e.reason}),...e.problems.map(e=>H9(t,e))];case`lost`:return[t(`folder.move.mismatch.lost`,{file:e.file,message:e.problems.map(({message:e})=>e).join(t(`folder.listSeparator`))})];default:return[t(`folder.move.mismatch.${e.kind}`,{file:e.file})]}}async#j(){let{dialogs:e,t}=this.#e;return e.prompt({title:t(`project.nameLabel`),value:t(`project.defaultName`),hint:t(`folder.chooseHint`),confirm:t(`folder.chooseFolder`)})}async#M(){try{return await this.#e.folders.choose()}catch(e){this.#N(e);return}}#N(e){console.warn(`A project folder could not be opened`,e),this.#e.notifications.push(this.#e.t(`folder.failed`))}async#P(e,t,n){let{dialogs:r,t:i}=this.#e,a;try{a=await this.projects.placeFor(e,t)}catch(e){this.#N(e);return}switch(a.kind){case`empty`:return{inside:void 0};case`project`:case`known`:await r.confirm({title:i(`folder.isProjectTitle`,{folder:e.name}),message:i(n?`folder.isProjectMessage`:`folder.isProjectElsewhere`),confirm:i(n?`folder.openIt`:`dialog.close`),...!n&&{noticeOnly:!0}})&&n&&(a.kind===`known`?await this.openRecent(a.record):await n(e));return;case`inside`:await this.#q(i(`folder.insideTitle`,{folder:e.name}),i(`folder.insideMessage`,{name:a.record.name}));return;case`incomplete`:await this.#q(i(`folder.incompleteTitle`),i(`folder.incompleteForNew`));return;case`other`:{let t=a.clashes.length>0?[{id:`inside`,label:i(`folder.putInside`,{inside:a.inside}),kind:`primary`}]:[{id:`here`,label:i(`folder.putHere`)},{id:`inside`,label:i(`folder.putInside`,{inside:a.inside}),kind:`primary`}],n=await r.choose({title:i(`folder.notEmptyTitle`,{folder:e.name}),message:a.clashes.length>0?i(`folder.notEmptyClashes`,{inside:a.inside,files:a.clashes.slice(0,5).join(`、`),count:a.clashes.length}):i(`folder.notEmptyMessage`,{inside:a.inside}),choices:t});return n===`inside`?{inside:a.inside}:n===`here`&&a.clashes.length===0?{inside:void 0}:void 0}}}async#F(e,t){let{notifications:n,t:r}=this.#e,i=await this.#P(e,t,e=>this.#I(e));if(!i)return;let a;try{a=await this.projects.create(t,e,i.inside)}catch(e){console.warn(`A project could not be made in a folder`,e),n.push(r(`folder.createFailed`));return}await this.#e.changeProject(()=>this.#V(a))}async#I(e,t=`granted`){let{dialogs:n,t:r}=this.#e,i=t;if(i===`needs-activation`){if(!await n.confirm({title:r(`folder.openTitle`,{name:e.name}),message:r(`folder.openMessage`),confirm:r(`folder.openButton`,{name:e.name})}))return;i=await e.requestAccess()}if(i!==`granted`)return;let a=await this.#z(e.name,t=>this.projects.look(e,t));if(a){if(a.kind===`known`)a.record.id!==this.#n?.record.id&&await this.openRecent(a.record);else if(a.kind===`empty`){if(!await n.confirm({title:r(`folder.emptyTitle`,{folder:e.name}),message:r(`folder.emptyMessage`),confirm:r(`folder.createHere`)}))return;let t=await n.prompt({title:r(`project.nameLabel`),value:r(`project.defaultName`),confirm:r(`project.create`)});t&&await this.#F(e,t)}else a.kind===`refused`?await this.#R(e,a.error):await this.#L(a)}}async#L(e){let{dialogs:t,t:n}=this.#e;if(e.replacing){let r=await this.projects.hasUnwritten(e.replacing);if(!await t.confirm({title:n(`folder.replacedTitle`,{folder:e.folder.name}),message:n(r?`folder.replacedOnlyCopy`:`folder.replacedMessage`,{old:e.replacing.name,name:e.name}),confirm:n(`folder.openOther`,{name:e.name}),...r&&{danger:!0}}))return}let r;for(let i of e.moved){let e=await t.choose({title:n(`folder.movedTitle`,{name:i.name}),message:n(`folder.movedMessage`),choices:[{id:`new`,label:n(`folder.movedNo`)},{id:`moved`,label:n(`folder.movedYes`),kind:`primary`}]});if(e===void 0)return;if(e===`moved`){r=i;break}}let i;try{i=await this.projects.adopt(e,r)}catch(e){this.#N(e);return}let{record:a,report:o}=i;o&&await this.#e.warnAboutCode(o),this.#J(void 0),await this.#e.changeProject(async()=>{await this.#V(a)&&o&&this.#e.noteArrival(o)})}async#R(e,t){let{t:n}=this.#e,{reason:r,problems:i}=t,a=i.length>0?[{title:n(`transfer.refusedList`),items:i.map(({file:e,path:t,message:r})=>n(`transfer.problem`,{place:t?`${e} ${t}`:e,message:r}))}]:void 0;await this.#q(n(`folder.refusedTitle`,{folder:e.name}),n(`folder.refused.${r}`),a)}async#z(e,t){let{dialogs:n,t:r}=this.#e,i=n.progress({title:r(`folder.reading`,{folder:e}),cancel:r(`dialog.cancel`),stopping:r(`transfer.stopping`)});try{return await t({signal:i.signal,onStep:({file:e})=>i.update({detail:e})})}catch(e){i.signal.aborted||this.#N(e);return}finally{i.close()}}async#B(e){let{dialogs:t,t:n}=this.#e,r=await t.choose({title:n(`folder.goneTitle`,{name:e.name}),message:n(`folder.goneMessage`),choices:[{id:`elsewhere`,label:n(`folder.saveElsewhere`)},{id:`find`,label:n(`folder.findAgain`),kind:`primary`}]});r===`find`&&await this.findAgain(e),r===`elsewhere`&&await this.saveElsewhere(e,{asked:!0})}async#V(e,{relocated:t=!1}={}){let{session:n,t:r}=this.#e,i=await this.#p.settle(e);if(await this.projects.isTooNew(i.folder).catch(()=>!1))return await this.#q(r(`folder.refusedTitle`,{folder:i.folder.name}),r(`folder.refused.too-new`)),!1;let a,o=await this.#z(i.folder.name,async e=>({report:await this.projects.prepare(i,e)}));if(!o)return!1;({report:a}=o),a&&await this.#e.warnAboutCode(a);let s=this.#H(i);if(!await n.open(i.id).catch(e=>{throw s.drop(),e}))return s.drop(),!1;let c=n.store;return await this.#U(i,c,s,t),await this.projects.opened(i,c.getState().manifest.name).catch(e=>{console.warn(`When the folder was opened could not be noted down`,e)}),a&&this.#e.noteArrival(a),!0}#H(e){let t,n=new K3({folder:()=>t?.folder??e.folder,key:e.id,bases:this.#e.folders.bases,browser:this.#e.projects.media(e.id),...this.#e.hasher&&{hasher:this.#e.hasher},onChanged:e=>{let t=this.#n;t?.assets===n&&(this.#e.assetFiles.filesChanged(e),this.#v(t))},onProgress:e=>{this.#u?.assets===n&&this.#g(e)}});return this.#u={key:e.id,assets:n},{assets:n,follow:e=>{t=e},drop:()=>{this.#u?.assets===n&&(this.#u=void 0)}}}async#U(e,t,n,r){let{session:i,folders:a,timing:o}=this.#e,{assets:s}=n,c=new qye({store:t,folder:e.folder,id:e.id,bases:a.bases,writer:a.writer(e.id),log:{saved:()=>i.trySave(),caughtUp:()=>i.readLog()},...o&&{timing:o}});n.follow(c);let l=[],u={session:c,store:t,assets:s,record:e,relocated:r,stop:()=>{for(let e of l)e();clearTimeout(u.checkTimer),u.assetWatch?.stop(),s.stop()}};l.push(c.subscribe(()=>{this.#n===u&&u.assetWatch&&this.#S(u),this.#Y()}),c.onMerge(e=>this.#W(t,e)),t.subscribe(()=>{t.getState().assets!==u.checkedAssets&&this.#v(u)})),this.#n=u,this.#Y(),await c.start(),this.#n===u&&(this.#S(u),this.#y(u),s.removeEmpty(t))}undoBatch(e){let t=this.#s.get(e);return t?(this.#G(t.store,t.merge),!0):!1}#W(e,t){let{notifications:n,t:r}=this.#e,{files:i,conflicts:a,problems:o}=t;if(i.length>0){this.#s.delete(t.origin),this.#s.set(t.origin,{store:e,merge:t});for(let e of this.#s.keys()){if(this.#s.size<=Yye)break;this.#s.delete(e)}}if(i.length===0&&a.length===0&&o.length===0)return;let s=a.length>0||o.length>0,c=i.length===0?r(`folder.notMerged`):r(s?`folder.mergedPartly`:`folder.merged`,{count:i.length});if(n.push(c,{actions:[...s?[{label:r(`folder.showMerged`),run:()=>this.#e.showProblems()}]:[],...i.length>0?[{label:r(`folder.undoMerge`),run:()=>void this.#G(e,t)}]:[]]}),!s)return;let l=r(`folder.keptIn`,{folder:b9}),u=[...a.map(e=>({severity:`warning`,text:`${r(`folder.conflict`)}${l}`,file:e.file,place:e.path.join(`.`),origin:r(`folder.origin`),action:{label:r(`folder.showTheirs`),run:()=>void this.#q(r(`folder.theirsTitle`,{file:e.file}),tbe(e.theirs,r))}})),...o.map(e=>({severity:e.severity===`error`?`error`:`warning`,text:`${e.message}${l}`,file:e.file,...e.path!==void 0&&{place:e.path},origin:r(`folder.origin`)}))];this.#o=[...this.#o,...u].slice(-200),this.#Y()}async#G(e,t){let{notifications:n,t:r}=this.#e,i=this.#n;if(i?.store!==e)return;let a;try{a=await i.session.keep(t.files)}catch(e){console.warn(`What the folder had could not be kept before taking it back`,e),n.push(r(`folder.undoNotKept`,{reason:this.#K(e)}));return}if(a===void 0){n.push(r(`folder.undoElsewhere`));return}let o=e.undoOrigin(t.origin);if(!o.ok){n.push(r(`folder.undoFailed`,{message:o.error.message}));return}let[s]=a,c=s?.split(`/`).slice(0,3).join(`/`);n.push(c===void 0?r(`folder.undoneNothingKept`):r(`folder.undone`,{folder:c}),{actions:[{label:r(`folder.redoMerge`),run:()=>{let i=e.redoOrigin(t.origin);i.ok||n.push(r(`folder.undoFailed`,{message:i.error.message}))}}]})}#K(e){let{t}=this.#e;return t(`folder.notKept.${(e instanceof ba?[`full`,`denied`,`busy`,`too-long`,`gone`].find(t=>t===e.reason):void 0)??`other`}`)}async#q(e,t,n){await this.#e.dialogs.confirm({title:e,message:t,confirm:this.#e.t(`dialog.close`),noticeOnly:!0,...n&&{details:n}})}#J(e){this.#r=e,this.#Y()}#Y(){let e=this.#n,t=e?.session.getSnapshot();this.#e.problems.setFolder([...this.#X(e,t),...this.#o,...this.#c]),this.#a={open:e&&t?{record:e.record,snapshot:t}:void 0,waiting:this.#r,moves:this.#h},this.#t.emit()}#X(e,t){let{t:n}=this.#e;if(!e||!t||t.blocked.length===0)return[];let{files:r}=e.store.exportFiles();return t.blocked.map(({path:e,problems:t})=>({severity:`error`,text:t.length>0?t.map(({message:e})=>e).join(n(`folder.listSeparator`)):n(`folder.waits`),file:e,origin:n(`folder.origin`),action:{label:r.has(e)?n(`folder.useEditorContent`):n(`folder.removeLikeEditor`),run:()=>void this.writeEditorContent([e])}}))}},ibe=class{#e=new Map;register(e){if(this.#e.has(e.type))throw Error(`Panel already registered: ${e.type}`);this.#e.set(e.type,e)}get(e){return this.#e.get(e)}list(){return[...this.#e.values()]}ready(){return new Set(this.list().flatMap(e=>e.planned?[]:[e.type]))}},abe=500,U9=150;function W9(e,t){let n=URL.createObjectURL(new Blob([JSON.stringify(e,void 0,2)])),r=document.createElement(`a`);r.href=n,r.download=`${t.replaceAll(`:`,`-`)}.json`,r.click(),URL.revokeObjectURL(n)}var obe=1e4,sbe=class{t;version;panels=new ibe;actions=new Ive;notifications=new $ve;layout;keybindings;palette;resourceHabits;explorer=new rge;missingFiles;dialogs=new Lve;session;timeline;trials;operations;properties;keyframes;sceneHandles;overlay;input;media;sounds;transfer;stills;videos;projectFolders;proxies;diagnostics;errors;#e;projects;account;windowId=va();cloud;#t=!1;#n;#r=0;compositorUrl;sceneOrigins;sceneStage;preview;frameRate;previewQuality;problems=new _ve;registrations;code;resourcePages;files;drafts;ai;chat;#i=!1;constructor(e){let{host:t,t:n,version:r,platform:i,panels:a,layouts:o,compositorUrl:s}=e;this.t=n,this.version=r;let c=t.projects;this.projects={list:()=>c.list(),create:(e,t)=>c.create(e,t),receive:e=>c.receive(e),open:e=>c.open(e),remove:(e,t)=>c.remove(e,t),media:e=>this.projectFolders?.mediaFor(e)??c.media(e),toFolder:e=>c.toFolder(e),copies:e=>c.copies(e),dropCopies:(e,t)=>c.dropCopies(e,t)};let l={...this.projects,media:e=>this.projectFolders?.mediaFor(e,this.#r)??c.media(e)};this.account=t.account,this.diagnostics=new _me(r),this.ai=new Nge(t.settings,t.keys,{saveFailed:()=>this.notifications.push(n(`ai.saveFailed`)),keyFailed:()=>this.notifications.push(n(`ai.keyFailed`))});let u=t.diagnostics;this.#e=u;let d;this.errors=new wQ({version:r,recorder:this.diagnostics,...u&&{send:e=>u.send(e)},origins:()=>typeof location>`u`?[]:[location.origin,new URL(s,location.href).origin],secrets:()=>{let e=this.session.store?.getState(),t=this.ai.knownKeys;return d&&d.state===e&&d.keys===t||(d={state:e,keys:t,found:new Set([...fQ(e),...t])}),d.found},device:V6}),this.compositorUrl=s,this.sceneOrigins=e.sceneOrigins??[],this.sceneStage=e.sceneStage,this.preview=new Tve({problem:(e,t,n,r)=>this.#l(e,t,n,r),stopped:(e,t)=>this.#u(e,t),revisions:e=>this.problems.keepRevisions(e),restarted:()=>this.notifications.push(n(`preview.restarted`))}),this.layout=new Zve(t.settings,t.windowMemory,o,()=>this.panels.ready(),{restoreFailed:()=>this.notifications.push(n(`notice.layoutRestoreFailed`)),saveFailed:()=>this.notifications.push(n(`notice.layoutSaveFailed`))}),this.keybindings=new Kve(t.settings,this.actions,i,{restoreFailed:()=>this.notifications.push(n(`notice.keybindingsRestoreFailed`)),saveFailed:()=>this.notifications.push(n(`notice.keybindingsSaveFailed`))});let f=this.layout.getSnapshot().layouts;this.layout.subscribe(()=>{let{active:e,layouts:t}=this.layout.getSnapshot();this.keybindings.notePanel(e),t!==f&&(f=t,this.keybindings.refresh())}),this.palette=new sye(t.settings,this.actions),this.resourceHabits=new uye(t.settings);let p=t.account?t.cloud:void 0;this.session=new XG(t.projects,t.address,{createFailed:()=>this.notifications.push(n(`notice.projectCreateFailed`)),notFound:()=>this.notifications.push(n(`notice.projectNotFound`)),openFailed:()=>this.notifications.push(n(`notice.projectOpenFailed`)),tooNew:()=>this.notifications.push(n(`notice.projectTooNew`)),damaged:()=>this.notifications.push(n(`notice.projectDamaged`)),saveFailed:()=>this.notifications.push(n(`notice.projectSaveFailed`)),saveRecovered:()=>this.notifications.push(n(`notice.projectSaveRecovered`))},{window:this.windowId,...p&&{compactThrough:async e=>{try{let t=await p.links.get(e);return t?t.pushed:void 0}catch{return 0}}}}),this.registrations=new l5(t.caches);let m=this.session.store;this.registrations.open(m&&JG(m)),this.session.subscribe(()=>{this.session.store!==m&&this.problems.clear(),m=this.session.store,this.registrations.open(m&&JG(m))}),this.code=new Eue(this.session,{commandFailed:e=>this.notifications.push(n(`notice.commandFailed`,{message:e})),closedRemoved:e=>this.notifications.push(n(`code.closedRemoved`,{path:e}))},{unsaved:e=>this.#p(e),overwrite:e=>this.#m(e)}),this.resourcePages=new dye(this.session,this.code),this.drafts=new zge(this.session,this.code,t.drafts,{restored:e=>this.notifications.push(n(`code.draftsRestored`,{count:e})),dropped:e=>this.notifications.push(n(`code.draftsDropped`,{count:e})),readFailed:()=>this.notifications.push(n(`code.draftsReadFailed`)),keepFailed:()=>this.notifications.push(n(`code.draftsKeepFailed`)),keepRecovered:()=>this.notifications.push(n(`code.draftsKeepRecovered`))}),this.files=new Bge(this.session,this.code,(e,t)=>this.#d(e,t),this.dialogs,this.notifications,n),this.input=new zve(t.settings),this.media=new ove(this.session,this.projects,{unsupported:e=>this.notifications.push(n(`notice.mediaUnsupported`,{name:e})),tooLarge:e=>this.notifications.push(n(`notice.mediaTooLarge`,{name:e})),saveFailed:e=>this.notifications.push(n(`notice.mediaSaveFailed`,{name:e})),commandFailed:e=>this.notifications.push(n(`notice.commandFailed`,{message:e})),confirmCopy:(e,t)=>this.dialogs.confirm({title:n(`folder.copy.title`,{name:e}),message:n(`folder.copy.message`,{size:EY(t)}),confirm:n(`folder.copy.confirm`)}),copyFailed:(e,t)=>this.notifications.push(n(`folder.copy.failed.${t}`,{name:e})),readFailed:e=>this.notifications.push(n(`folder.copy.readFailed`,{name:e})),otherKind:e=>this.notifications.push(n(`folder.asset.otherKind`,{name:e}))},s,()=>this.projectFolders?.assets());let h=new fve({url:s,setup:()=>({origins:this.sceneOrigins,retired:this.preview.retiredOrigins,compositor:new URL(s,location.href).origin,run:!1}),onRetired:e=>this.preview.noteRetired(e)});if(this.sounds=new pve({session:this.session,projects:this.projects,run:h.run,messages:{problem:(e,t)=>this.#v(e,t),failed:(e,t)=>{this.diagnostics.mark(`sound.failed`,{reason:t}),this.notifications.push(n(`sound.failed.${t}`,{name:this.#g(e),interpolation:{escapeValue:!1}}))}},arrived:e=>this.media.soundArrived(e),...e.soundLimitMs!==void 0&&{limitMs:e.soundLimitMs}}),this.transfer=new OY({folders:t.folders,projects:l,session:this.session,dialogs:this.dialogs,notifications:this.notifications,t:n}),this.timeline=new afe(this.session,t.windowMemory,t.settings,{commandFailed:e=>this.notifications.push(n(`notice.commandFailed`,{message:e})),joinsRemoved:e=>this.notifications.push(n(`timeline.joinsRemoved`,{count:e})),sceneName:e=>n(`scene.newName`,{number:e}),soundName:e=>n(`sound.newName`,{number:e}),soundWords:()=>({duration:n(`sound.param.duration`),seed:n(`sound.param.seed`)})}),this.chat=new jge({chats:t.chats,ai:this.ai,project:()=>{let{store:e,key:t}=this.session.getSnapshot();return e&&t!==void 0?{store:e,key:t}:void 0},subscribeProject:this.session.subscribe,selection:()=>{let{model:e,selection:t,transition:n}=this.timeline.getSnapshot();if(e)return{timeline:e.id,playhead:ze(lq(this.timeline.frame,e.rate)),clips:[...t],...n&&{transition:n}}},undone:e=>this.tellUndo(e)}),this.frameRate=new Cve(this.timeline),this.previewQuality=new MX(t.settings,this.frameRate),this.stills=new nve({session:this.session,timeline:this.timeline,projects:l,folders:t.folders,preview:this.preview,dialogs:this.dialogs,notifications:this.notifications,t:n,compositorUrl:s,sceneOrigins:this.sceneOrigins,sceneStage:this.sceneStage}),this.videos=new nY({session:this.session,timeline:this.timeline,projects:l,folders:t.folders,settings:t.settings,exports:t.exports,sounds:this.sounds,preview:this.preview,dialogs:this.dialogs,notifications:this.notifications,t:n,compositorUrl:s,sceneOrigins:this.sceneOrigins,sceneStage:this.sceneStage}),this.videos.cleanUp(),this.projectFolders=t.localFolders&&new rbe({folders:t.localFolders,projects:t.projects,session:this.session,address:t.address,dialogs:this.dialogs,notifications:this.notifications,problems:this.problems,t:n,changeProject:e=>this.#E(e),warnAboutCode:e=>this.transfer.warnAboutCode(e),noteArrival:e=>this.#f(e),letGo:async e=>{await this.videos.letGoOfProject(e),await this.cloud?.forget(e)},showProblems:()=>this.layout.openPanel(`problems`),assetFiles:{useNewFile:e=>this.media.useNewFile(e),usePlace:(e,t)=>this.media.usePlace(e,t),filesChanged:e=>this.media.filesChanged(e)},...e.hasher&&{hasher:e.hasher},...e.folderTiming&&{timing:e.folderTiming},...t.presence&&{presence:t.presence}}),this.session.subscribe(()=>this.projectFolders?.followSession()),this.cloud=p&&new Dge({cloud:p,session:this.session,projects:t.projects,folderOf:e=>this.projectFolders?.getSnapshot().open?.record.id===e?this.projectFolders.session?.folder??this.projectFolders.getSnapshot().open?.record.folder:void 0,isFolder:e=>this.projectFolders?.holds(e)===!0,account:t.account,dialogs:this.dialogs,notifications:this.notifications,t:n,window:this.windowId,editor:r,signIn:()=>this.signIn(),openProject:e=>this.openProject(e),...e.cloudTiming&&{timing:e.cloudTiming},...e.cloudEnvironment&&{environment:e.cloudEnvironment}}),this.cloud){let e=()=>void this.cloud?.follow();this.session.subscribe(e),this.projectFolders?.subscribe(e)}this.missingFiles=new fye(this.session,this.media,this.projectFolders),this.#x(t),this.proxies=this.projectFolders&&e.proxyMaker?this.#a(this.projectFolders,e.proxyMaker):void 0,this.diagnostics.watch(`hashing`,{get:()=>this.#C(),subscribe:e=>{let t=[this.media.subscribe(e),this.projectFolders?.subscribeProgress(e)];return()=>{for(let e of t)e?.()}}});let g=this.proxies;g&&this.diagnostics.watch(`proxies`,{get:()=>{let{making:e,paused:t}=g.getSnapshot();return e!==void 0&&!t},subscribe:e=>g.subscribe(e)}),this.trials=new kve(this.session,this.timeline,t.trials,t.settings,{commandFailed:e=>this.notifications.push(n(`notice.commandFailed`,{message:e})),overwrote:e=>this.notifications.push(n(`notice.trialOverwrote`,{count:e})),discarded:e=>this.notifications.push(n(`notice.trialDiscarded`,{count:e})),setAside:e=>this.notifications.push(n(`notice.trialSetAside`,{count:e})),back:e=>this.notifications.push(n(`notice.trialBack`,{count:e})),asideDropped:e=>this.notifications.push(n(`notice.trialAsideDropped`,{count:e})),unsure:()=>this.notifications.push(n(`notice.trialUnsure`)),restored:e=>this.notifications.push(n(`notice.trialRestored`,{count:e})),dropped:()=>this.notifications.push(n(`notice.trialDropped`)),readFailed:()=>this.notifications.push(n(`notice.trialReadFailed`)),keepFailed:()=>this.notifications.push(n(`notice.trialKeepFailed`)),keepRecovered:()=>this.notifications.push(n(`notice.trialKeepRecovered`))}),this.operations=new rye(this.session),this.properties=new Pve(this.session,this.timeline,this.trials,{commandFailed:e=>this.notifications.push(n(`notice.commandFailed`,{message:e})),comparing:()=>this.notifications.push(n(`notice.comparing`))}),this.keyframes=new T_e(this.session,this.timeline,this.trials,this.properties,t.windowMemory,t.settings,n,{pasteTooEarly:()=>this.notifications.push(n(`notice.keysPasteTooEarly`)),pasteNowhere:()=>this.notifications.push(n(`notice.keysPasteNowhere`)),comparing:()=>this.notifications.push(n(`notice.keysComparing`)),locked:()=>this.notifications.push(n(`notice.keysLocked`)),notShown:()=>this.notifications.push(n(`notice.keysNotShown`)),gone:()=>this.notifications.push(n(`notice.keysGone`))},this.registrations),this.sceneHandles=new $_e({tooMany:(e,t)=>this.preview.noteProblem(e,t,{kind:`api`,code:`handles-flood`,frame:0})}),this.overlay=new K_e({session:this.session,timeline:this.timeline,properties:this.properties,trials:this.trials,quality:this.previewQuality,handles:this.sceneHandles,registrations:this.registrations,describe:this.keyframes.describe,messages:{gone:()=>this.notifications.push(n(`notice.overlayGone`))}}),this.#o(),this.#s();for(let e of a)this.panels.register(e);this.#j(),this.#M(),this.#I(),this.#U(),this.#N(),Fve(this.actions,this.timeline,this.keyframes.inTimeline),Vge(this.actions,this.keyframes,this.timeline)}#a(e,t){return new dX({project:()=>{let{open:t}=e.getSnapshot(),n=e.session,r=e.assets(),i=this.session.store;if(t&&n&&r&&i)return{key:t.record.id,store:i,folder:n.folder,writes:t.snapshot.role===`writing`,elsewhere:t.snapshot.role===`waiting`,compared:t.snapshot.compared,async file(e){for(let t of Object.values(i.getState().assets??{})){if(t.hash===void 0||!eq(t.hash,e))continue;let n=await r.fileAt(t.path);if(n.kind===`there`&&eq(n.hash,e))return n.file}}}},subscribe:t=>{let n=[e.subscribe(t),this.session.subscribe(t)];return()=>{for(let e of n)e()}},maker:t,playing:()=>this.timeline.getSnapshot().playing,subscribePlaying:e=>this.timeline.subscribe(e)})}#o(){let{diagnostics:e}=this;this.actions.watch((t,n)=>e.mark(`action`,{id:t.id,way:n},!0));let t=this.layout.getSnapshot().active;this.layout.subscribe(()=>{let n=this.layout.getSnapshot().active;n!==t&&n!==void 0&&e.mark(`panel`,{id:n}),t=n});let n=this.preview.getSnapshot().compositor;this.preview.subscribe(()=>{let t=this.preview.getSnapshot().compositor;t!==n&&e.mark(`compositor`,{state:t}),n=t});let r=this.timeline.frame;this.timeline.subscribe(()=>{let t=this.timeline.frame;t!==r&&!this.timeline.getSnapshot().playing&&e.mark(`seek`,{frame:t},!0),r=t});let i,a,o=()=>{this.session.store!==i&&(a?.(),i=this.session.store,e.mark(`project`,{open:i!==void 0}),a=i?.watchCommands(({commands:t,by:n,ok:r,dryRun:i,code:a,error:o})=>{if(i&&r)return;let[s]=t;e.mark(`command`,{name:s,by:n,ok:r,...t.length>1&&{count:t.length},...a!==void 0&&{code:a},...i&&{dryRun:i}},!0),a===`threw`&&this.errors.capture(`command`,o,{commands:t})}))};this.session.subscribe(o),o()}#s(){let e,t=()=>{e=void 0;let t=this.session.store?.getState(),n=this.timeline.model?.id;if(!t||n===void 0){this.problems.setProperties([]);return}let r={describe:this.keyframes.describe,registered:e=>this.registrations.problemsOf(e),clipName:e=>vJ(e,t,this.t),rename:(e,t,n)=>this.renameProperty(e,t,n)};this.problems.setProperties(Ove(t,n,r,this.t))},n=()=>{e??=setTimeout(t,U9)},r,i,a=()=>{this.session.store!==r&&(i?.(),r=this.session.store,i=r?.subscribe(n),n())};this.session.subscribe(a),a(),this.registrations.subscribe(n),this.timeline.subscribe(n)}renameProperty(e,t,n){let r=this.session.store,i=this.timeline.model?.id;if(!r||i===void 0)return!1;let a=[{owner:{clip:e},from:t,to:n}],o=r.execute({type:`property.rename`,params:{timeline:i,renames:a}});return o.ok||this.notifications.push(this.t(`notice.commandFailed`,{message:o.error.message})),o.ok}async connectProperty(e,t){let n=this.timeline.model?.boxes.get(e);if(!n)return;let{t:r,keyframes:i}=this,a=Wge(i.nodeOf(n.clip),n.clip,t,e=>i.nameOfNode(e)),o={name:t,interpolation:{escapeValue:!1}};if(a.length===0){await this.dialogs.confirm({title:r(`keyframes.connect.title`,o),message:r(`keyframes.connect.none`),confirm:r(`dialog.close`),noticeOnly:!0});return}let s=(await this.dialogs.form({title:r(`keyframes.connect.title`,o),fields:[{id:`to`,label:r(`keyframes.connect.field`),options:a.map(({path:e,label:t})=>({id:e,label:t})),value:a[0].path}],confirm:r(`keyframes.connect.confirm`)}))?.to;s!==void 0&&this.renameProperty(e,t,s)}#c(e){let t=this.timeline.model?.boxes.get(e);return vJ(t?.clip,this.session.store?.getState(),this.t)}#l(e,t,n,r){this.#_(`scene.problem`,n);let{t:i}=this,a=this.#c(e),{line:o,...s}=n,{file:c,column:l}=n;if(this.problems.noteScene(e,t,{severity:mve(n),text:bJ(i,s),...c!==void 0&&{file:c},...o!==void 0&&{line:o},...l!==void 0&&{column:l},origin:a}),!r||this.layout.getSnapshot().visible.has(`problems`))return;let u={name:a,text:bJ(i,n),interpolation:{escapeValue:!1}};this.notifications.push(i(`scene.problem`,u))}#u(e,t){if(t){let{reason:e,phase:n}=t;this.diagnostics.mark(`scene.stopped`,{reason:e,phase:n})}if(!t){this.problems.noteStopped(e,void 0);return}let n=this.#c(e),r=SJ(this.t,n,t);this.problems.noteStopped(e,{severity:`error`,text:r,origin:n})}async replaceAssetFile(e){let t=this.session.store?.getState().assets?.[e];if(!t)return!1;let n=this.projectFolders,r,i=n?.assets()?await n.pickFiles():void 0;if(i){for(let e of i.unreadable)this.notifications.push(this.t(`notice.mediaUnsupported`,{name:e}));let[e]=i.inside,[t]=i.files;r=e===void 0?t&&{file:t}:{path:e}}else{let e=await this.media.chooseFile(t.kind);r=e&&{file:e}}if(!r)return!1;let a=await this.media.replaceFile(e,r);return a&&n?.checkAssetsSoon(),a}async moveAssetTo(e,t){let n=await this.media.usePlace(e,t);return n&&this.projectFolders?.checkAssetsSoon(),n}canRevealResource(e){return U8(e)!==void 0&&this.panels.get(`explorer`)!==void 0}revealResource(e){this.explorer.reveal(e)&&this.layout.openPanel(`explorer`)}goToUse(e){if(this.timeline.model?.id!==e.timeline)return!1;let t=this.timeline.revealClip(e.clip??``,{...e.edge&&{edge:e.edge},...e.join!==void 0&&{join:e.join}});return t&&this.layout.openPanel(`timeline`),t}goToProblem({file:e,line:t,column:n,target:r}){if(r){if(!this.timeline.model?.boxes.has(r.clip))return;this.timeline.selectOnly(r.clip),this.layout.openPanel(`keyframes`);return}if(e===void 0)return;let i=t===void 0?void 0:{line:t,...n&&{column:n}};this.showCode(e,i)||this.notifications.push(this.t(`problems.notInProject`,{file:e}))}#d(e,t){this.showCode(e,t?{line:1}:void 0),!t&&this.layout.getSnapshot().visible.has(`files`)&&this.layout.openPanel(`files`)}showCode(e,t){let n=this.code.open(e,t);return n&&(this.resourcePages.showCode(),this.layout.openPanel(`code`)),n}openResource(e,t){let n=U$(e),r=this.session.store?.getState();if(n&&n.kind!==`asset`&&r){let e=n.kind===`scene`?r.scenes[n.id]:r.sounds[n.id],t=n.kind===`scene`?`scenes`:`sounds`;if(e&&this.showCode(`${t}/${n.id}/${e.entry}`))return}this.openResourcePage(e,t)}openResourcePage(e,t){this.resourcePages.open(e,t),this.layout.openPanel(`code`)}#f({missing:e,damaged:t,skipped:n,lost:r,warnings:i}){let{t:a}=this,o=a(`problems.origin.import`),s=(e,t)=>t.map(t=>({severity:`warning`,text:a(`problems.import.${e}`,{name:t,interpolation:{escapeValue:!1}}),origin:o}));this.problems.noteImport([...r.map(e=>({severity:`warning`,text:e,origin:o})),...s(`missing`,e),...s(`damaged`,t),...s(`skipped`,n),...i.map(({severity:e,message:t,file:n,path:r})=>({severity:e,text:t,file:n,...r&&{place:r},origin:o}))])}#p(e){let{t}=this;return this.dialogs.choose({title:t(`code.unsavedTitle`,{path:e}),message:t(`code.unsavedMessage`),choices:[{id:`discard`,label:t(`code.discard`),kind:`danger`},{id:`save`,label:t(`code.save`),kind:`primary`}]})}#m(e){let{t}=this;return this.dialogs.choose({title:t(`code.overwriteTitle`,{path:e}),message:t(`code.overwriteMessage`),choices:[{id:`theirs`,label:t(`code.takeTheirs`)},{id:`overwrite`,label:t(`code.overwrite`),kind:`danger`}]})}async#h(){let e=this.code.unsaved.length;if(e===0)return!0;let{t}=this,n=await this.dialogs.choose({title:t(`code.leaveTitle`,{count:e}),message:t(`code.unsavedMessage`),choices:[{id:`discard`,label:t(`code.discard`),kind:`danger`},{id:`save`,label:t(`code.saveAll`),kind:`primary`}]});return n===void 0?!1:n===`save`?this.code.saveAll():(this.code.discardAll(),!0)}#g(e){return this.session.store?.getState().sounds[e]?.name??this.t(`timeline.kind.sound`)}#_(e,{kind:t,code:n}){this.diagnostics.mark(e,{type:t,...n!==void 0&&{code:n}})}#v(e,t){this.#_(`sound.problem`,t);let n={name:this.#g(e),interpolation:{escapeValue:!1}},r=bJ(this.t,t);this.notifications.push(this.t(`scene.problem`,{...n,text:r}))}async load(){await Promise.all([this.layout.load(),this.keybindings.load(),this.palette.load(),this.resourceHabits.load(),this.timeline.load(),this.keyframes.load(),this.input.load(),this.previewQuality.load(),this.trials.load(),this.ai.load()]),await this.projectFolders?.restore()||await this.session.restore(),this.account&&this.#y(this.account)}async#y(e){await e.refresh();let t=e.takeOutcome();t&&this.#b(t,e.getSnapshot())}#b(e,t){let{t:n}=this;if(e!==`signedIn`){this.notifications.push(n(`account.outcome.${e}`));return}if(t.status!==`signedIn`)return;let r={name:t.name,interpolation:{escapeValue:!1}};t.appInstalled?this.notifications.push(n(`account.signedIn`,r)):this.notifications.push(n(`account.signedInWithoutApp`,r),{stays:!0,actions:[{label:n(`account.install`),run:()=>void this.installApp()}]})}get leavingPage(){return this.#t}async leavePage(){let{t:e}=this,t=this.videos.getSnapshot()!==void 0;if(this.transfer.running||t||this.projectFolders?.moving===!0)return await this.dialogs.confirm({title:e(`app.leaveBusyTitle`),message:e(`app.leaveBusyMessage`),confirm:e(`dialog.close`),noticeOnly:!0}),!1;typeof document<`u`&&document.activeElement instanceof HTMLInputElement&&document.activeElement.matches(`[role="spinbutton"]`)&&document.activeElement.blur(),this.timeline.flush(),this.keyframes.flush();let[n,r,i]=await Promise.all([this.session.trySave(),this.trials.settle(),this.drafts.settle(),this.layout.flush()]),a=await(this.projectFolders?.flush()??Promise.resolve(!0)).catch(e=>(console.warn(`The project folder could not be written before leaving`,e),!1));if(!n||!r||!i){if(!await this.dialogs.confirm({title:e(`app.leaveUnsavedTitle`),message:e(`app.leaveUnsavedMessage`),confirm:e(`app.leaveAnyway`),danger:!0}))return!1}else if(!a&&!await this.dialogs.confirm({title:e(`app.leaveFolderTitle`),message:e(`app.leaveFolderMessage`),confirm:e(`app.leaveAnyway`)}))return!1;return this.#t=!0,clearTimeout(this.#n),this.#n=setTimeout(()=>this.#t=!1,obe),!0}async signIn(){let{account:e}=this;e&&await this.leavePage()&&e.signIn()}async installApp(){let{account:e}=this;e&&await this.leavePage()&&e.installApp()}async signOut(){let{account:e,t}=this;if(e)try{await e.signOut(),this.notifications.push(t(`account.signedOut`))}catch(e){console.warn(`Signing out failed`,e),this.notifications.push(t(`account.signOutFailed`))}}async resume(){await this.projectFolders?.resume()}async newProject(){if(this.projectFolders){await this.projectFolders.create();return}let{t:e}=this,t=await this.dialogs.prompt({title:e(`project.nameLabel`),value:e(`project.defaultName`),confirm:e(`project.create`)});t&&await this.#E(()=>this.session.create(t))}async openProject(e){let t=await this.projectFolders?.projects.records.get(e).catch(()=>void 0);t?await this.projectFolders?.openRecent(t):await this.#E(()=>this.session.open(e))}#x(e){let{presence:t}=e;if(!t)return;let n,r=()=>{let{key:e}=this.session;n?.key!==e&&(n?.leave(),n=e===void 0?void 0:{key:e,leave:t.enter(e)})};this.session.subscribe(r),r(),t.onMoved(e=>void this.projectFolders?.followMove(e))}async closeProject(){await this.#E()}async importDropped(e){let t=this.projectFolders;return t?.assets()?this.#S(await t.droppedFiles(e)):this.media.importFiles([...e.files])}async pickFiles(){let e=this.projectFolders,t=e?.assets()?await e.pickFiles():void 0;return t?this.#S(t):this.media.pickFiles()}async#S({inside:e,files:t,unreadable:n}){for(let e of n)this.notifications.push(this.t(`notice.mediaUnsupported`,{name:e}));return[...await this.media.importPaths(e),...await this.media.importFiles(t)]}async openFolder(){await this.projectFolders?.open()}async moveToFolder(e=this.session.key){return!this.projectFolders||e===void 0?!1:this.projectFolders.moveToFolder(e)}async importProject(){this.diagnostics.mark(`import`,{step:`start`});let e=await this.transfer.importProject().finally(()=>this.diagnostics.mark(`import`,{step:`end`}));e&&(await this.transfer.warnAboutCode(e),await this.openProject(e.id),this.session.key===e.id&&this.#f(e),await this.transfer.announceImport(e))}async renameProject(){let{store:e}=this.session;if(!e)return;let{t}=this,n=await this.dialogs.prompt({title:t(`project.nameLabel`),value:e.getState().manifest.name,confirm:t(`project.rename`)});if(!n)return;let r=e.execute({type:`project.rename`,params:{name:n}});r.ok||this.notifications.push(t(`notice.commandFailed`,{message:r.error.message}))}applyFrameRate(e){return this.session.store?.execute({type:`project.setFrameRate`,params:{fps:e.trim()}})?.ok===!0}async setFrameRate(){let{store:e}=this.session;if(!e)return;let{t}=this,n=await this.dialogs.prompt({title:t(`project.frameRateLabel`),value:AA(e.getState().manifest),confirm:t(`project.frameRateConfirm`)});n&&!this.applyFrameRate(n)&&this.notifications.push(t(`notice.frameRateInvalid`))}#C(){let e=this.projectFolders?.getProgress();return this.media.getImporting()>0||this.media.getCopying()!==void 0||e!==void 0&&(e.reading.length>0||e.checked!==void 0)}#w(){let e=this.session.store?.getState();if(!e)return;let t=Object.values(e.timelines);return{storage:this.projectFolders?.getSnapshot().open?`folder`:`browser`,fps:e.manifest.fps,formats:e.manifest.formats.map(({width:e,height:t,fps:n})=>({width:e,height:t,fps:n})),tracks:t.reduce((e,{tracks:t})=>e+Object.keys(t).length,0),clips:t.reduce((e,{clips:t})=>e+Object.keys(t).length,0),layout:t.flatMap(({clips:e})=>Object.values(e).slice(0,abe).map(e=>({id:e.id,kind:e.source.kind,track:e.track,start:O(Q(e)),end:O(jA(e)),offset:O(MA(e))}))),assets:Object.entries(e.assets??{}).map(([e,{kind:t,size:n,info:r}])=>{let i=this.proxies?.stateOf(e)?.kind,a=this.proxies?.madeOf(e);return{kind:t,size:n,info:r,...i!==void 0&&{proxy:i},...a&&{proxyMade:a}}}),previewQuality:this.previewQuality.getSnapshot().choice}}get canSendDiagnostics(){return this.#e!==void 0}finishDiagnostics(){this.diagnostics.finish(this.#w())}saveDiagnostics(){let{report:e}=this.diagnostics.getSnapshot();e&&W9(e,`animaquill-diagnostics-${e.startedAt}`)}saveErrorReport(e){let t=this.errors.getSnapshot().errors.find(t=>t.id===e);t&&W9(t.report,`animaquill-error-${t.report.at}`)}async sendDiagnostics(){let{report:e}=this.diagnostics.getSnapshot();if(e&&this.#e)try{this.diagnostics.markSent(await this.#e.send(e))}catch(e){console.warn(`The report did not arrive`,e),this.notifications.push(this.t(`diagnostics.sendFailed`))}}async showAbout(){let{t:e,version:t}=this;await this.dialogs.confirm({title:e(`about.title`),message:e(`about.message`,{version:t}),confirm:e(`about.close`),noticeOnly:!0})}async removeProject(e){let{t}=this;if(await this.#T(e.id))return this.notifications.push(t(`folder.move.removeIsFolder`,{name:e.name})),!1;if(!await this.dialogs.confirm({title:t(`project.removeTitle`,{name:e.name}),message:t(`project.removeWarning`),confirm:t(`project.remove`),danger:!0}))return!1;try{await this.videos.letGoOfProject(e.id),await this.session.remove(e.id),await this.cloud?.forget(e.id);let n=(await this.videos.unfinished()).filter(t=>t.project===e.id);return n.length>0&&this.notifications.push(t(`export.queue.leftElsewhere`,{count:n.length})),!0}catch(e){return console.warn(`Project could not be removed`,e),this.notifications.push(t(`notice.projectRemoveFailed`)),!1}}async#T(e){return await this.projectFolders?.projects.records.get(e).catch(()=>void 0)?!0:(await this.projects.list().catch(()=>[])).some(t=>t.id===e&&t.folder===!0)}async#E(e){if(!this.#i){this.#i=!0;try{await this.#A()&&await e?.()}finally{this.#i=!1}}}async save(){typeof document<`u`&&document.activeElement instanceof HTMLInputElement&&document.activeElement.matches(`[role="spinbutton"]`)&&document.activeElement.blur(),this.trials.getSnapshot().count>0?this.trials.save():await this.session.trySave(),await this.projectFolders?.flush()}async#D(){let{t:e}=this;this.#r=Date.now();let{count:t}=this.trials.getSnapshot();if(t===0)return!0;let n=await this.dialogs.choose({title:e(`trial.exportTitle`,{count:t}),message:e(`trial.exportMessage`),choices:[{id:`saved`,label:e(`trial.exportSaved`)},{id:`save`,label:e(`trial.exportWithTrial`),kind:`primary`}]});return n!==void 0&&(n!==`save`||this.trials.save())}async exportProject(){if(await this.#D()){this.diagnostics.mark(`export`,{step:`start`});try{await this.transfer.exportProject()}finally{this.diagnostics.mark(`export`,{step:`end`})}}}async exportFrame(){await this.#D()&&await this.stills.run()}async exportVideo(){await this.#D()&&await this.videos.start()}async#O(){await this.trials.settle();let{count:e}=this.trials.getSnapshot();if(e===0)return!this.trials.notKept||this.#k();let{t}=this,n=await this.dialogs.choose({title:t(`trial.leaveTitle`,{count:e}),message:t(`trial.leaveMessage`),choices:[{id:`discard`,label:t(`trial.discard`),kind:`danger`},{id:`keep`,label:t(`trial.keep`)},{id:`save`,label:t(`trial.save`),kind:`primary`}]});return n===void 0?!1:n===`save`?this.trials.save():n===`discard`?(this.trials.discard(),!0):await this.trials.settle()||this.#k()}#k(){let{t:e}=this;return this.dialogs.confirm({title:e(`trial.notKeptTitle`),message:e(`trial.notKeptMessage`),confirm:e(`project.leaveAnyway`),danger:!0})}async#A(){if(!this.session.store)return!0;if(!await this.#h()||!await this.#O())return!1;if(!await this.session.trySave()){let{t:e}=this;if(!await this.dialogs.confirm({title:e(`project.unsavedTitle`),message:e(`project.unsavedWarning`),confirm:e(`project.leaveAnyway`),danger:!0}))return!1}return await this.layout.detach(),await this.cloud?.close(),await this.projectFolders?.close(),await this.session.close(),!0}#j(){let e=()=>this.session.store!==void 0;if(this.actions.register({id:`project.new`,title:e=>e(`project.new`),run:()=>void this.newProject(),menu:{name:`file`,group:`open`}}),this.projectFolders&&this.actions.register({id:`project.openFolder`,title:e=>e(`folder.openAction`),run:()=>void this.openFolder(),menu:{name:`file`,group:`open`}}),this.actions.register({id:`project.close`,title:e=>e(`project.close`),run:()=>void this.closeProject(),menu:{name:`file`,group:`open`},enabled:e}),this.actions.register({id:`project.save`,title:e=>e(`project.save`),run:()=>void this.save(),keys:[`mod+s`],menu:{name:`file`,group:`project`},enabled:e}),this.actions.register({id:`project.rename`,title:e=>e(`project.renameAction`),run:()=>void this.renameProject(),menu:{name:`file`,group:`project`},enabled:e}),this.actions.register({id:`project.importMedia`,title:e=>e(`assets.importAction`),run:()=>void this.pickFiles(),menu:{name:`file`,group:`project`},enabled:e}),this.actions.register({id:`project.frameRate`,title:e=>e(`project.frameRate`),run:()=>void this.setFrameRate(),menu:{name:`file`,group:`project`},enabled:e}),!this.projectFolders)this.actions.register({id:`project.importFolder`,title:e=>e(`transfer.importAction`),run:()=>void this.importProject(),menu:{name:`file`,group:`folder`}});else{let t=this.projectFolders;this.actions.register({id:`project.moveToFolder`,title:e=>e(`folder.move.action`),run:()=>void this.moveToFolder(),menu:{name:`file`,group:`folder`},enabled:()=>e()&&!t.holds(this.session.key)})}this.actions.register({id:`project.exportFolder`,title:e=>e(`transfer.exportAction`),run:()=>void this.exportProject(),menu:{name:`file`,group:`folder`},enabled:e});let t=this.cloud;t&&(this.actions.register({id:`cloud.connect`,title:e=>e(`cloud.connectAction`),run:()=>void t.connect(),menu:{name:`file`,group:`cloud`},enabled:()=>t.canConnect}),this.actions.register({id:`cloud.disconnect`,title:e=>e(`cloud.disconnectAction`),run:()=>void t.disconnect(),menu:{name:`file`,group:`cloud`},enabled:()=>t.canDisconnect}),this.actions.register({id:`cloud.open`,title:e=>e(`cloud.openAction`),run:()=>void t.openFromCloud(),menu:{name:`file`,group:`cloud`}})),this.actions.register({id:`project.exportVideo`,title:e=>e(`export.video.action`),run:()=>void this.exportVideo(),menu:{name:`file`,group:`export`},enabled:e}),this.actions.register({id:`project.exportFrame`,title:e=>e(`export.frameAction`),run:()=>void this.exportFrame(),menu:{name:`file`,group:`export`},enabled:e})}#M(){let e=()=>this.files.getSnapshot().selected!==void 0;this.actions.register({id:`code.save`,title:e=>e(`code.saveFile`),run:()=>void this.code.save().then(()=>this.projectFolders?.flush()),keys:[`mod+s`],scope:`code`,enabled:()=>this.code.getSnapshot().active!==void 0&&this.resourcePages.showsCode}),this.actions.register({id:`files.rename`,title:e=>e(`files.renameAction`),run:()=>void this.files.rename(),keys:[`f2`],scope:`files`,enabled:e}),this.actions.register({id:`files.remove`,title:e=>e(`files.removeAction`),run:()=>void this.files.remove(),keys:[`delete`],scope:`files`,enabled:e})}#N(){this.actions.register({id:`help.about`,title:e=>e(`about.title`),run:()=>void this.showAbout(),menu:{name:`help`,group:`about`}}),this.actions.register({id:`help.diagnostics`,title:e=>e(`panel.performance.title`),run:()=>this.layout.openPanel(`performance`),menu:{name:`help`,group:`diagnostics`}})}#P(e){let{store:t}=this.session;t&&this.tellUndo(e(t))}tellUndo(e){let t=this.#F(e);t!==void 0&&this.notifications.push(t)}#F(e){return e.ok?e.obstacle?this.t(`notice.undoPartly.${e.obstacle}`):void 0:e.error.obstacle?this.t(`notice.undoBlocked.${e.error.obstacle}`):this.t(`notice.commandFailed`,{message:e.error.message})}undoTo(e){let{store:t}=this.session;if(t&&this.operations.canUndoTo(e))for(let n=0;n<2e3&&t.lastStep>=e.step;n++){if(this.trials.undoesFirst){this.trials.undo();continue}let e=t.lastStep,n=t.undo(),r=this.#F(n);if(r!==void 0)return r;if(t.lastStep===e)break}}redoLast(){let{store:e}=this.session;if(e){if(this.trials.redoesFirst)this.trials.redo();else return this.#F(e.redo())}}undoOperation(e,t){let{store:n}=this.session;if(!n||e.origin===void 0||e.source===`folder`&&t===`undo`&&this.projectFolders?.undoBatch(e.origin))return;let r=t===`undo`?n.undoOrigin(e.origin):n.redoOrigin(e.origin);return this.#F(r)}#I(){this.actions.register({id:`edit.undo`,title:e=>e(`edit.undo`),run:()=>{this.trials.undoesFirst?this.trials.undo():this.#P(e=>e.undo())},keys:[`mod+z`],menu:{name:`edit`,group:`history`},enabled:()=>this.session.store?.canUndo===!0||this.trials.canUndo}),this.actions.register({id:`edit.redo`,title:e=>e(`edit.redo`),run:()=>{this.trials.redoesFirst?this.trials.redo():this.#P(e=>e.redo())},keys:[`mod+shift+z`,`mod+y`],menu:{name:`edit`,group:`history`},enabled:()=>this.session.store?.canRedo===!0||this.trials.canRedo}),this.actions.register({id:`trial.compare`,title:e=>e(`trial.action.compare`),run:()=>this.trials.toggleCompare(),menu:{name:`edit`,group:`trial`},enabled:()=>this.trials.getSnapshot().count>0}),this.actions.register({id:`trial.discard`,title:e=>e(`trial.action.discard`),run:()=>this.trials.discard(),menu:{name:`edit`,group:`trial`},enabled:()=>{let{count:e,setAside:t}=this.trials.getSnapshot();return e+t>0}})}#L(e){let t;this.actions.provide(()=>{let{layouts:n}=this.layout.getSnapshot();return t?.from!==n&&(t={from:n,actions:this.#R(n,e)}),t.actions});let n=()=>e()&&this.layout.isCustom(this.layout.getSnapshot().layout);this.actions.register({id:`layout.saveAs`,title:e=>e(`layout.saveAs`),run:()=>void this.#B(),menu:{name:`layout`,group:`manage`},enabled:e}),this.actions.register({id:`layout.rename`,title:e=>e(`layout.renameAction`),run:()=>void this.#V(),menu:{name:`layout`,group:`manage`,title:e=>e(`layout.rename`)},enabled:n}),this.actions.register({id:`layout.delete`,title:e=>e(`layout.deleteAction`),run:()=>void this.#H(),menu:{name:`layout`,group:`manage`,title:e=>e(`layout.delete`)},enabled:n}),this.actions.register({id:`layout.reset`,title:e=>e(`layout.reset`),run:()=>this.layout.resetLayout(),menu:{name:`layout`,group:`reset`},enabled:e})}#R(e,t){return e.map((e,n)=>({id:`layout.switch.${e.id}`,title:t=>t(`action.switchLayout`,{layout:e.title(t)}),run:()=>this.layout.switchLayout(e.id),...n<9&&{keys:[`alt+shift+${n+1}`]},menu:{name:`layout`,group:e.custom?`custom`:`presets`,title:e.title},selected:()=>this.layout.getSnapshot().layout===e.id,enabled:t}))}#z(){let{layout:e,layouts:t}=this.layout.getSnapshot();return t.find(t=>t.id===e)?.title(this.t)??``}async#B(){let{t:e}=this,t=this.layout.getSnapshot().layouts.filter(e=>e.custom).length,n=await this.dialogs.prompt({title:e(`layout.saveAsTitle`),value:e(`layout.newName`,{number:t+1}),hint:e(`layout.saveAsHint`),confirm:e(`layout.saveAsConfirm`)});n!==void 0&&this.layout.saveAs(n)}async#V(){let{t:e}=this,{layout:t}=this.layout.getSnapshot();if(!this.layout.isCustom(t))return;let n=await this.dialogs.prompt({title:e(`layout.renameTitle`),value:this.#z(),confirm:e(`layout.renameConfirm`)});n!==void 0&&this.layout.rename(t,n)}async#H(){let{t:e}=this,{layout:t,layouts:n}=this.layout.getSnapshot();if(!this.layout.isCustom(t))return;let r=n[0]?.title(e)??``;await this.dialogs.confirm({title:e(`layout.deleteTitle`,{name:this.#z()}),message:e(`layout.deleteMessage`,{first:r}),confirm:e(`layout.deleteConfirm`),danger:!0})&&this.layout.remove(t)}#U(){let e=()=>this.session.store!==void 0;this.#L(e),this.actions.register({id:`view.commandPalette`,title:e=>e(`palette.title`),run:()=>this.palette.toggle(),keys:[`mod+shift+p`,`f1`],menu:{name:`view`,group:`commands`},palette:!1});for(let t of this.panels.list())this.actions.register({id:`view.open.${t.type}`,title:e=>e(`action.openPanel`,{panel:t.title(e)}),run:()=>this.layout.openPanel(t.type),...t.keys?{keys:t.keys}:{},menu:{name:`view`,group:`panels.${t.area}`,title:t.title},enabled:e})}},G9=(...e)=>({kind:`split`,direction:`row`,children:e}),K9=(...e)=>({kind:`split`,direction:`column`,children:e}),q9=(e,t=!1)=>(...n)=>({kind:`tabs`,panels:n,strip:e,pinned:t}),J9=q9(`top`),Y9=q9(`left`),X9=q9(`right`),cbe=[{id:`edit`,title:e=>e(`layout.edit`),layout:K9([60,G9([22,{...Y9(`files`,`explorer`,`assets`,`transitions`,`effects`),active:`assets`}],[52,J9(`preview`,`code`,`music`,`recording`,`versions`)],[26,X9(`properties`,`chat`,`history`,`notes`)])],[40,Y9(`timeline`,`keyframes`,`problems`,`terminal`)])},{id:`animate`,title:e=>e(`layout.animate`),layout:K9([50,G9([21,Y9(`explorer`,`assets`,`transitions`,`effects`,`files`)],[28,J9(`preview`)],[28,J9(`code`)],[23,X9(`properties`,`chat`,`history`)])],[50,Y9(`keyframes`,`timeline`,`problems`)])},{id:`audio`,title:e=>e(`layout.audio`),layout:K9([55,G9([22,Y9(`assets`,`explorer`,`effects`)],[52,J9(`music`,`recording`,`preview`)],[26,X9(`properties`,`history`)])],[45,Y9(`timeline`,`problems`)])},{id:`ai`,title:e=>e(`layout.ai`),layout:G9([76,K9([60,G9([28,Y9(`explorer`,`assets`,`transitions`,`effects`,`files`)],[72,J9(`preview`,`code`)])],[40,Y9(`timeline`,`keyframes`,`problems`)])],[24,X9(`chat`,`history`,`notes`,`properties`)])}],Z9=()=>new DOMException(`The proxy was not wanted any more`,`AbortError`),lbe=3;function ube({frameMs:e}={}){let t,n=typeof Worker>`u`?new RY(`unsupported`):void 0,r=0,i=0,a=new Map,o=(e,t,n=[])=>e.postMessage(t,n),s=(e,i)=>{if(t!==e)return;e.terminate(),t=void 0,r+=1,r>=lbe&&(n=new RY(`encoder`,{cause:`Workers for proxies kept breaking: ${i}`}));let o=[...a.values()];a.clear();for(let e of o)e.reject(new RY(`encoder`,{cause:i}))},c=()=>{if(n)return;if(t)return t;try{t=new Worker(new URL(`/assets/proxy-worker-DJwICOHC.js`,``+import.meta.url),{type:`module`,name:`proxies`})}catch(e){console.warn(`Proxies cannot be made in this browser`,e),n=new RY(`unsupported`,{cause:e});return}let e=t;return e.addEventListener(`message`,t=>{let n=t.data,r=a.get(n.job);if(r)switch(n.kind){case`write`:r.request.write(new Uint8Array(n.data),n.position).then(()=>o(e,{kind:`written`,job:n.job,write:n.write}),t=>{a.delete(n.job),o(e,{kind:`cancel`,job:n.job}),r.reject(t)});break;case`progress`:r.request.onProgress?.(n.share);break;case`done`:a.delete(n.job),r.resolve(n.result);break;case`failed`:{a.delete(n.job);let{reason:e,message:t,acceleration:i}=n;r.reject(e===`cancelled`?Z9():new RY(e,{cause:t,...i&&{acceleration:i}}));break}}}),e.addEventListener(`error`,t=>{t.preventDefault(),console.warn(`The worker for proxies stopped`,t.message),s(e,t.message)}),e};return{make(t){let r=()=>{},s=()=>{},l=new Promise((e,t)=>{r=e,s=t}),u=c(),d=i++;if(!u)return s(n??new RY(`unsupported`)),{done:l,pause(){},resume(){},cancel(){}};a.set(d,{request:t,resolve:r,reject:s});let{file:f,spec:p,encoders:m}=t;o(u,{kind:`make`,job:d,file:f,spec:p,encoders:[...m],...e!==void 0&&{frameMs:e}});let h=e=>{a.has(d)&&o(u,{kind:e,job:d})};return{done:l,pause:()=>h(`pause`),resume:()=>h(`resume`),cancel(){let e=a.get(d);e&&(a.delete(d),o(u,{kind:`cancel`,job:d}),e.reject(Z9()))}}}}}async function dbe(e,t){let n=await DQ(),r=new sbe({host:t.host,t:n.t,version:t.version,platform:/Mac/.test(navigator.platform)?`mac`:`other`,panels:[...cge,...t.panels??[]],layouts:cbe,compositorUrl:t.compositorUrl,sceneOrigins:t.sceneOrigins??[],...t.sceneStage&&{sceneStage:t.sceneStage},...t.soundLimitMs!==void 0&&{soundLimitMs:t.soundLimitMs},hasher:$fe(),proxyMaker:ube({frameMs:t.proxyFrameMs})}),i=TQ(r.errors,r.diagnostics,t.compositorUrl);await r.load(),t.onWorkbench?.(r);let a=(0,ys.createRoot)(e);a.render((0,L.jsx)(N.StrictMode,{children:(0,L.jsx)(LZ,{workbench:r,i18n:n})})),r.resume();let o=()=>{document.visibilityState===`hidden`&&(r.layout.flush(),r.timeline.flush(),r.keyframes.flush(),r.projectFolders?.flush())};document.addEventListener(`visibilitychange`,o);let s=()=>{r.proxies?.lookAgain(),r.account?.refresh()};window.addEventListener(`focus`,s);let c=e=>{r.dialogs.getSnapshot()||r.keybindings.handle(e)};window.addEventListener(`keydown`,c);let l=e=>{e.dataTransfer?.types.includes(`Files`)&&e.preventDefault()},u=e=>{let t=e.dataTransfer;if(!t?.types.includes(`Files`))return;let n=e.defaultPrevented;e.preventDefault(),!n&&!r.dialogs.getSnapshot()&&r.projectFolders?.dropped(t)};window.addEventListener(`dragover`,l),window.addEventListener(`drop`,u);let d=e=>{if(r.leavingPage)return;let{code:t,session:n,transfer:i,trials:a,videos:o,projectFolders:s}=r,c=o.getSnapshot()!==void 0,l=s?.moving===!0;(n.hasUnsavedChanges||i.running||a.notKept||c||l||t.hasUnsaved)&&e.preventDefault()};return window.addEventListener(`beforeunload`,d),()=>{window.removeEventListener(`drop`,u),window.removeEventListener(`dragover`,l),window.removeEventListener(`beforeunload`,d),window.removeEventListener(`keydown`,c),document.removeEventListener(`visibilitychange`,o),window.removeEventListener(`focus`,s),r.proxies?.dispose(),a.unmount(),i()}}var fbe=7651,Q9={editor:`animaquill.localhost`,compositor:`animaquill-sandbox.localhost`,scene:e=>`animaquill-scene-${e}.localhost`};function pbe(e=fbe){if(!Number.isInteger(e)||e<1||e>65535)throw RangeError(`Not a port: ${e}`);let t=t=>new URL(`http://${t}:${e}`).origin;return{editor:t(Q9.editor),compositor:t(Q9.compositor),scenes:Array.from({length:8},(e,n)=>t(Q9.scene(n)))}}var mbe=`/compositor.html`;async function hbe({root:e,sites:t,version:n,host:r}){navigator.serviceWorker?.register(`/sw.js`).catch(e=>{console.warn(`The editor cannot be installed as an app here`,e)}),await dbe(e,{host:{...us(),...r},version:n,compositorUrl:`${t.compositor}${mbe}`,sceneOrigins:t.scenes})}var $9=document.querySelector(`#root`);$9&&await hbe({root:$9,sites:pbe(Number(location.port||80)),version:{BASE_URL:`/`,DEV:!1,MODE:`production`,PROD:!0,SSR:!1,VITE_VERSION:`0.3.34`}.VITE_VERSION??`local`});
215
+ `,{expected:`absent`})}catch(e){if(!F9(e,`changed`))throw e}let a=Hye(Date.now()),o=e.split(`/`).at(-1);for(let t=1;t<=100;t++){let n=`${b9}/${a}${t===1?``:`-${t}`}`;for(let t of[`${n}/${e}`,`${n}/${o}`])try{return await r.write(t,i,{expected:`absent`}),t}catch(e){if(F9(e,`changed`,`exists`))break;if(F9(e,`too-long`,`refused`)&&t!==`${n}/${o}`)continue;throw e}}throw new ba(`failed`,e)}async#ge(e,t){try{await this.#he(e,t.kind===`absent`?void 0:t.stat)}catch(n){if(!(n instanceof ba))throw n;let r={severity:`error`,code:`not-kept`,file:e,message:`这个文件坏了,没能先备份到 .animaquill/recovered,所以没有重写`};this.#c.delete(e)&&this.#l.add(e),this.#q(e,t,[r],!1,this.#n.get(e)?.base);return}this.#s.set(e,{disk:t,isKept:!0});let n=N9(t),r=this.#n.get(e)??{base:void 0,stat:x9,synced:void 0};this.#n.set(e,{...r,synced:void 0,...n!==void 0&&{replaced:n}}),this.#l.add(e)}async#_e(e){let t=this.trouble?.reason===`manifest-gone`,{files:n}=this.#e.store.exportFiles(),r=e??(t?[...new Set([...n.keys(),...this.#n.keys(),...this.#r.keys()])].filter(M3):[...this.#r.keys()]);for(let e of r){if(!t&&!this.#r.has(e))continue;let r=await this.#B(e);if(!r){this.#A(e);continue}let i=n.get(e);this.#r.delete(e);let a=this.#n.get(e);O9(i,r)?(this.#s.delete(e),this.#n.set(e,{base:E9(r),stat:T9(r),synced:P9(i)}),this.#l.add(e)):(await this.#he(e,r.kind===`absent`?void 0:r.stat),this.#s.set(e,{disk:r,isKept:!0}),a&&this.#n.set(e,{...a,synced:void 0}))}t&&this.#j(void 0),this.#S=!0,this.#e.changed(),await this.#ie()}},qye=class{#e;#t;#n;#r;#i;#a;#o;#s=`starting`;#c;#l;#u;#d=!1;#f=!1;#p=!1;#m=()=>{};#h;#g;#_;#v=()=>{};#y=!1;#b;#x=new sv;#S=new Set;#C={role:`starting`,status:`saving`,trouble:void 0,blocked:[],writtenAt:void 0,unrecorded:!1,compared:!1};#w;constructor({store:e,folder:t,id:n,bases:r,writer:i,log:a,timing:o}){this.#e=e,this.#o=t,this.#t=n,this.#n=r,this.#r=i,this.#i=a,this.#a={...Oye,...o},this.#h=new Promise(e=>{this.#m=e}),this.#w=[e.subscribe(()=>this.#c?.changed()),e.onLocalUpdate(()=>this.#D())]}subscribe=this.#x.subscribe;getSnapshot=()=>this.#C;get folder(){return this.#o}onMerge(e){return this.#S.add(e),()=>this.#S.delete(e)}start(){if(!this.#g){let e=()=>{};this.#g=new Promise(t=>{e=t}),this.#T(e).catch(e=>console.warn(`The project folder is not kept any more`,e)).finally(e)}return this.#g}async flush(){let e=this.#c;return e?e.flush():!this.#_&&this.#i.saved()}async idle(){for(;;){let e=this.#c;if(!e)return;let t=e.work;if(await t,this.#c===e&&e.work===t)return}}async close(){if(!this.#p){await this.#c?.flush().catch(()=>!1),this.#p=!0,this.#m(),this.#v(),this.#u?.abort();for(let e of this.#w)e();this.#c?.stop(),this.#c=void 0,this.#l?.release(),this.#l=void 0,this.#O(`closed`)}}async useEditorContent(e){let t=this.#c;return t?(await t.useEditorContent(e),!0):!1}async keep(e){let t=this.#c;if(t)return t.keep(e)}async reconnect(e=this.#o){let t=await e.status().catch(()=>`gone`);if(t===`gone`)return`gone`;if(t!==`ready`)return`ask`;let n;try{n=await e.readText(Sk)}catch(e){return F9(e,`gone`)?`gone`:`not-a-project`}return I3(n)===this.#e.getState().manifest.id?(this.#o=e,this.#_&&this.#_.reason!==`outdated`?(this.#_=void 0,this.#v(),this.#k()):await this.#c?.reconnected(),`connected`):`other-project`}async#T(e){for(;!this.#p;){if(this.#_){if(this.#O(`stopped`),e(),this.#_.reason===`outdated`)return;await new Promise(e=>{this.#v=e});continue}let t=await this.#E(e);if(!t)return;if(this.#p){t.release();return}this.#l=t;let n=new Kye({store:this.#e,id:this.#t,bases:this.#n,log:this.#i,timing:this.#a,folder:()=>this.#o,changed:()=>this.#k(),merged:e=>{for(let t of this.#S)t(e)}});if(this.#c=n,this.#O(`writing`),await n.start(),n.isOver||(this.#b=n,this.#k()),e(),await Promise.race([t.lost,n.ended,this.#h]),n.stop(),t.release(),this.#y=n.unrecorded,this.#c===n&&(this.#c=void 0),this.#l=void 0,this.#p)return;n.endReason===`outdated`?this.#_={reason:`outdated`}:n.endReason===`park`?this.#_=n.trouble??{reason:`gone`}:(this.#O(`waiting`),n.endReason===`again`&&await Promise.race([new Promise(e=>setTimeout(e,this.#a.retryMs)),this.#h]))}}async#E(e){for(;;){if(this.#p)return;if(this.#d){this.#d=!1;try{return await this.#r.claim({steal:!0})}catch(e){console.warn(`Could not take over writing the project folder`,e)}}let t=new AbortController;this.#u=t;let n=!1;try{let r=await this.#r.claim({signal:t.signal,onWaiting:()=>{n||this.#p||this.#u!==t||(this.#O(`waiting`),e())}});return n=!0,r}catch(e){if(!t.signal.aborted){if(e instanceof DOMException&&e.name===`AbortError`)return;console.warn(`Could not find out which window writes the project folder`,e),await new Promise(e=>setTimeout(e,this.#a.retryMs))}}finally{this.#u===t&&(this.#u=void 0)}}}#D(){this.#s!==`waiting`||this.#f||this.#p||(this.#f=!0,(async()=>{try{if(await new Promise(e=>setTimeout(e,this.#a.quietMs)),this.#s!==`waiting`||this.#p||await this.#r.answers(this.#a.answerMs)||this.#s!==`waiting`||this.#p)return;this.#d=!0,this.#u?.abort()}finally{this.#f=!1}})())}#O(e){this.#s=e,this.#k()}#k(){let e=this.#s===`writing`?this.#c:void 0,t=e?e.status:this.#s===`waiting`?`elsewhere`:this.#s===`closed`?`saved`:this.#s===`stopped`?`unsaved`:`saving`,n=e?e.troubleNow:this.#s===`stopped`?this.#_:void 0,r=e?.blocked??[],i=e?.writtenAt??this.#C.writtenAt,a=e?e.unrecorded:this.#y,o=e!==void 0&&this.#b===e,s=this.#C,c=s.trouble===n||s.trouble?.reason===n?.reason&&s.trouble?.path===n?.path;s.role===this.#s&&s.status===t&&c&&s.writtenAt===i&&s.unrecorded===a&&s.compared===o&&s.blocked.length===r.length&&s.blocked.every((e,t)=>e.path===r[t]?.path&&e.problems===r[t]?.problems)||(this.#C={role:this.#s,status:t,trouble:n,blocked:r,writtenAt:i,unrecorded:a,compared:o},this.#x.emit())}},Jye=300,Yye=50,z9=4e3,Xye=100,Zye=100,B9=1e7,Qye=1e8,$ye=2,ebe={open:void 0,waiting:void 0,moves:0};function tbe(e,t){if(e===void 0)return t(`folder.theirsRemoved`);let n=typeof e==`string`?e:JSON.stringify(e,null,2);return n.length>z9?`${n.slice(0,z9)}…`:n}function V9(e,t,n){let r=n.slice(0,Xye),i=n.length-r.length;return{title:e(`transfer.listTitle`,{title:t,count:n.length}),items:i>0?[...r,e(`transfer.andMore`,{count:i})]:r}}var H9=(e,{file:t,path:n,message:r})=>e(`transfer.problem`,{place:n?`${t} ${n}`:t,message:r}),nbe=({files:e,totalFiles:t,bytes:n,totalBytes:r})=>{let i=r+t*B9;return i>0?Math.min(1,(n+e*B9)/i):1},rbe=class{projects;#e;#t=new sv;#n;#r;#i;#a=ebe;#o=[];#s=new Map;#c=[];#l=[];#u;#d=new sv;#f=R3;#p;#m=!1;#h=0;constructor(e){this.#e=e,this.projects=new Dye({folders:e.folders,projects:e.projects,t:e.t}),this.#p=new wye({folders:e.folders,projects:e.projects,t:e.t,...e.hasher&&{hasher:e.hasher}})}subscribe=this.#t.subscribe;getSnapshot=()=>this.#a;get session(){return this.#n?.session}assets(){let e=this.#u,{store:t}=this.#e.session;return e&&t&&JG(t)===e.key?e.assets:void 0}mediaFor(e,t){let n=this.#u;if(n?.key===e)return n.assets.media(()=>this.#e.session.store?.getState().assets,t===void 0?{}:{since:t})}subscribeProgress=this.#d.subscribe;getProgress=()=>this.#f;#g(e){this.#f=e,this.#d.emit()}async droppedFiles(e){return this.#_(await this.#e.folders.dropped(e))}async pickFiles(){let e=this.#n;if(!e)return;let t=await this.#e.folders.chooseFiles(e.session.folder);return t&&this.#_(t)}async#_(e){let t=this.#n?.session.folder,n=[],r=[],i=[];for(let a of e){if(a.kind===`folder`){i.push(a.folder.name);continue}let e=await t?.pathOf(a).catch(()=>void 0);if(e&&!M3(e)&&!jH(e))n.push(e);else try{r.push(await a.file.read())}catch(e){console.warn(`A file that people brought in cannot be read`,e),i.push(a.file.name)}}return{inside:n,files:r,unreadable:i}}#v(e){clearTimeout(e.checkTimer),e.checkTimer=setTimeout(()=>void this.#y(e),Jye)}async#y(e){return e.checking?(e.checkAgain=!0,e.checking):(e.checkAgain=!1,e.checkedAssets=e.store.getState().assets,e.checking=e.assets.check(e.store).catch(e=>(console.warn(`The files of the assets could not be looked at`,e),[])).then(t=>{if(this.#n!==e)return;let{t:n}=this.#e,r=e.relocated&&t.some(({kind:e})=>e===`missing`)?[{severity:`warning`,text:n(`folder.assetsLeftBehind`),origin:n(`folder.origin`)}]:[];this.#c=[...r,...t.map(t=>this.#b(e,t))],this.#l=t,this.#Y()}).finally(()=>{e.checking=void 0,e.checkAgain&&this.#n===e&&this.#y(e)}),e.checking)}get assetIssues(){return this.#l}checkAssetsSoon(){this.#n&&this.#v(this.#n)}async assetsChecked(){let e=this.#n;e&&(clearTimeout(e.checkTimer),await this.#y(e))}#b(e,t){let{t:n,assetFiles:r}=this.#e,i=t=>void t.then(t=>t&&this.#v(e)),a={file:t.path,origin:n(`folder.origin`),severity:`warning`};if(t.kind===`changed`)return{...a,text:n(`folder.asset.changed`),action:{label:n(`folder.asset.useNew`),run:()=>i(r.useNewFile(t.asset))}};if(t.hidden!==void 0)return{...a,text:n(`folder.asset.hidden`,{name:t.hidden})};let{found:o}=t;return o===void 0?t.copy?{...a,text:n(`folder.asset.missing`),action:{label:n(`folder.move.restoreCopy`),run:()=>void this.#x(e,t.asset,t.path)}}:{...a,text:n(`folder.asset.missing`)}:{...a,text:n(`folder.asset.moved`,{found:o}),action:{label:n(`folder.asset.usePlace`),run:()=>i(r.usePlace(t.asset,o))}}}async#x(e,t,n){let{notifications:r,projects:i,assetFiles:a,t:o}=this.#e;try{let r=e.store.getState().assets?.[t]?.hash,o=r===void 0?void 0:await i.media(e.record.id).get(r);if(!o)throw Error(`No copy of ${n} in the browser`);await e.session.folder.write(n,o,{expected:`absent`}),a.filesChanged([n]),this.#v(e)}catch(e){console.warn(`A copy could not go back into the project folder`,e),r.push(o(`folder.move.restoreFailed`,{path:n,reason:this.#K(e)}))}}#S(e){let{folder:t}=e.session;if(e.assetWatch?.folder===t)return;let n=e.assetWatch!==void 0;e.assetWatch?.stop(),e.assetWatch={folder:t,stop:e.assets.watch(()=>Object.values(e.store.getState().assets??{}).map(({path:e})=>e),t=>{this.#n===e&&(this.#e.assetFiles.filesChanged(t),this.#v(e))})},n&&(this.#e.assetFiles.filesChanged(Object.values(e.store.getState().assets??{}).map(({path:e})=>e)),this.#v(e))}async restore(){let e=this.#e.address.read();if(e===void 0)return!1;let t;try{t=await this.projects.records.get(e)}catch(e){return console.warn(`The folders this browser knows cannot be read`,e),this.#e.notifications.push(this.#e.t(`folder.recordsFailed`)),!0}return t?(this.#i=t,!0):(await this.#e.projects.list().catch(()=>[])).some(t=>t.id===e&&t.folder===!0)}async resume(){let e=this.#i;if(this.#i=void 0,!e)return;let t=await this.projects.statusOf(e);t===`ready`?await this.#e.changeProject(()=>this.#V(e)):this.#J({record:e,status:t})}async flush(){return await this.#n?.session.flush()??!0}async close(){let e=this.#n;if(!e||(await e.session.flush().catch(()=>!1),this.#n!==e))return;this.#n=void 0,this.#u?.assets===e.assets&&(this.#u=void 0),e.stop(),this.#g(R3),this.#o=[],this.#c=[],this.#l=[],this.#Y(),await e.session.close();let{name:t}=e.store.getState().manifest;t!==e.record.name&&await this.projects.opened(e.record,t).catch(()=>{})}followSession(){let{store:e}=this.#e.session,t=this.#n;t&&e!==t.store&&this.close(),e&&this.#r&&this.#J(void 0)}async create(){let e=await this.#j();if(!e)return;let t=await this.#M();t&&await this.#F(t,e)}async open(){let e=await this.#M();e&&await this.#I(e)}dropped(e){let{folders:t,notifications:n,t:r}=this.#e;t.dropped(e).then(async e=>{let t=e.find(e=>e.kind===`folder`);if(t?.kind!==`folder`){e.length>0&&n.push(r(`folder.droppedNoFolder`));return}let{folder:i}=t;await this.projects.mayBeProject(i)?await this.#I(i,await i.requestAccess()):await this.#q(r(`folder.refusedTitle`,{folder:i.name}),r(`folder.refused.not-a-project`))}).catch(e=>this.#N(e))}list(){return this.projects.records.list()}async openRecent(e){let t=await this.projects.statusOf(e);t===`gone`?await this.#B(e):t===`blocked`?this.#e.notifications.push(this.#e.t(`folder.blocked`,{name:e.name})):(t!==`ask`||await e.folder.requestAccess()===`granted`)&&(this.#J(void 0),await this.#e.changeProject(()=>this.#V(e)))}async findAgain(e){let{notifications:t,t:n}=this.#e,r=await this.#M();if(!r)return;let i=this.#n;if(i?.record.id===e.id){let a=await this.projects.records.find(r);if(a&&a.id!==e.id){t.push(n(`folder.reconnect.taken`,{name:e.name,other:a.name}));return}let o=await i.session.reconnect(r);o===`connected`?(i.record={...i.record,folder:r},await this.projects.opened(i.record).catch(()=>{}),this.#Y()):t.push(n(`folder.reconnect.${o}`,{name:e.name}));return}let a=await this.projects.findAgain(e,r).catch(()=>`not-a-project`);if(a!==`found`){let i=a===`taken`?await this.projects.records.find(r):void 0;t.push(n(`folder.reconnect.${a}`,{name:e.name,other:i?.name??``}))}else this.#J(void 0),await this.#e.changeProject(()=>this.#V({...e,folder:r}))}async saveElsewhere(e,{asked:t=!1}={}){let{dialogs:n,notifications:r,t:i}=this.#e;if(!t){let t=await n.choose({title:i(`folder.elsewhereTitle`,{name:e.name}),message:i(`folder.elsewhereMessage`),choices:[{id:`find`,label:i(`folder.findAgain`)},{id:`elsewhere`,label:i(`folder.chooseNewPlace`),kind:`primary`}]});if(t===`find`&&await this.findAgain(e),t!==`elsewhere`)return}let a=await this.#M();if(!a)return;let o=await this.#P(a,e.name);if(!o)return;let s,c;try{s=o.inside===void 0?a:await a.inside(o.inside,{create:!0}),c=await this.projects.relocate(e,s)}catch(e){console.warn(`A project could not be written to a new place`,e),r.push(i(`folder.createFailed`));return}this.#J(void 0),await this.#e.changeProject(()=>this.#V(c,{relocated:!0}))}async allowAgain(){let e=this.#n;e&&await e.record.folder.requestAccess()===`granted`&&await e.session.reconnect()}async writeEditorContent(e){await this.#n?.session.useEditorContent(e)}async remove(e){let{dialogs:t,notifications:n,t:r}=this.#e,i=await this.projects.statusOf(e)!==`ready`||await this.projects.hasUnwritten(e);if(!await t.confirm({title:r(`folder.removeTitle`,{name:e.name}),message:r(i?`folder.removeOnlyCopy`:`folder.removeMessage`),confirm:r(`folder.remove`),...i&&{danger:!0}}))return!1;try{return await this.#e.letGo(e.id),await this.projects.forget(e.id),this.#r?.record.id===e.id&&this.#J(void 0),!0}catch(e){return console.warn(`A folder could not be taken off the list`,e),n.push(r(`folder.removeFailed`)),!1}}get moving(){return this.#m}holds(e){return e!==void 0&&(this.#u?.key===e||this.#n?.record.id===e)}async moveToFolder(e){if(this.#m)return!1;this.#m=!0;try{return await this.#C(e)}finally{this.#m=!1}}async#C(e){let{session:t,projects:n,presence:r,dialogs:i,notifications:a,t:o}=this.#e,s=t.key===e?t.store:void 0,c=await r?.others(e).catch(()=>0)??0;if(c>0){let t=s?.getState().manifest.name??await this.#T(e);if(!await i.confirm({title:o(`folder.move.othersTitle`,{name:t,count:c}),message:o(`folder.move.othersMessage`,{count:c}),confirm:o(`folder.move.othersConfirm`)}))return!1}let l=await this.#M();if(!l)return!1;let u;try{s||(u=await h9(n,e));let c=s??u?.store;if(!c)return a.push(o(`notice.projectNotFound`)),!1;let d=s?()=>t.trySave():u.saved,{name:f}=c.getState().manifest;if(!await d())return await this.#q(o(`folder.move.refusedTitle`,{name:f}),o(`folder.move.unsaved`)),!1;let p=n.media(e),m=await this.#p.check(e,c,p);if(m)return await this.#k(f,m),!1;let h=await this.#P(l,f);if(!h)return!1;let g=i.progress({title:o(`folder.move.title`,{name:f}),cancel:o(`dialog.cancel`),stopping:o(`transfer.stopping`)}),_;try{_=await this.#p.run(e,c,p,{chosen:l,inside:h.inside},{notice:o(`folder.move.incompleteNotice`),signal:g.signal,onStep:this.#E(g),saved:d})}finally{g.close()}return _.kind===`moved`?(s&&t.store===s&&await this.#w(_.record,s),r?.moved(e),await this.#D(f,_),!0):(await this.#O(f,_),!1)}catch(e){return console.warn(`A project could not be moved into a folder`,e),a.push(o(`folder.move.failed`)),!1}finally{u?.close()}}async followMove(e){this.#h+=1,this.#Y();let{session:t,notifications:n,t:r}=this.#e,i=t.store;if(!i||t.key!==e||this.holds(e))return;let a=await this.projects.records.get(e).catch(()=>void 0);a&&t.store===i&&!this.holds(e)&&(await this.#w(a,i),n.push(r(`folder.move.movedElsewhere`,{name:i.getState().manifest.name,folder:a.folder.name})))}async#w(e,t){await this.#U(e,t,this.#H(e),!1),this.#e.assetFiles.filesChanged(Object.values(t.getState().assets??{}).map(({path:e})=>e))}async#T(e){return(await this.#e.projects.list().catch(()=>[])).find(({id:t})=>t===e)?.name??``}copiesOf(e){return this.#p.copiesOf(e.id).catch(()=>0)}async releaseCopies(e,{asked:t=!1}={}){let{dialogs:n,notifications:r,projects:i,folders:a,hasher:o,presence:s,session:c,t:l}=this.#e;if(!t){let t=EY(await this.copiesOf(e));if(!await n.confirm({title:l(`folder.move.releaseTitle`,{name:e.name}),message:l(`folder.move.releaseMessage`,{size:t}),confirm:l(`folder.move.release`,{size:t})}))return!1}let u=await this.projects.statusOf(e);if(u===`ask`&&await e.folder.requestAccess()===`granted`&&(u=`ready`),u!==`ready`)return r.push(l(`folder.move.releaseUnreachable`,{name:e.name})),!1;let d=this.#n?.record.id===e.id?this.#n:void 0,f=d?.assets??new K3({folder:()=>e.folder,key:e.id,bases:a.bases,browser:i.media(e.id),...o&&{hasher:o}}),p;try{d||(p=await h9(i,e.id));let t=d?.store??p?.store;if(!t)throw Error(`Nothing of project ${e.id} to compare its files with`);let n=c.key===e.id||(await s?.others(e.id).catch(()=>0)??0)>0,{released:a,missing:o,unused:u}=await this.#p.release(e.id,t.getState().assets??{},f,{open:n}),m=[l(`folder.move.released`,{size:EY(a)})];return o.length>0&&m.push(l(`folder.move.releasedMissing`,{count:o.length})),u.length>0&&m.push(l(`folder.move.releasedUnused`,{count:u.length})),r.push(m.join(``)),a>0}catch(e){return console.warn(`The copies in the browser could not be let go of`,e),r.push(l(`folder.move.releaseFailed`)),!1}finally{p?.close(),f!==d?.assets&&f.stop()}}#E(e){let{t}=this.#e,n=-1/0,r,i=0;return a=>{let o=performance.now();if(a.phase!==r&&(r=a.phase,i=o,n=-1/0),o-n<Zye)return;n=o;let s=nbe(a),c=(o-i)/1e3,l=c<$ye||s<=0?((a.totalFiles-a.files)*B9+a.totalBytes-a.bytes)/Qye:c*(1-s)/s,u=Math.ceil(l),d=t(`folder.move.${a.phase}`,{done:a.files,total:a.totalFiles});e.update({detail:a.file,ratio:s,amount:u>1?`${d}${t(`folder.move.left`,{seconds:u})}`:d})}}async#D(e,{record:t,missing:n,damaged:r,renamed:i,copies:a}){let{dialogs:o,t:s}=this.#e,c=s(`folder.move.movedTitle`),l=s(`folder.move.moved`,{name:e,folder:t.folder.name}),u=[V9(s,s(`folder.move.missing`),n),V9(s,s(`folder.move.damaged`),r),V9(s,s(`folder.move.renamed`),i.map(({from:e,to:t})=>s(`folder.move.renamedItem`,{from:e,to:t})))].filter(({items:e})=>e.length>0);if(a===0){await this.#q(c,l,u);return}let d=EY(a);await o.confirm({title:c,message:`${l}${s(`folder.move.copies`,{size:d})}`,confirm:s(`folder.move.release`,{size:d}),cancel:s(`folder.move.keep`),...u.length>0&&{details:u}})&&await this.releaseCopies(t,{asked:!0})}async#O(e,t){let{dialogs:n,notifications:r,t:i}=this.#e,a=i(`folder.move.failedTitle`,{name:e}),o=(e,t)=>e?i(`folder.move.nothingLeft`):i(`folder.move.leftBehind`,{folder:t,file:DH});switch(t.kind){case`refused`:await this.#k(e,t.refusal);return;case`stopped`:{if(t.cancelled&&t.cleaned){r.push(i(`folder.move.cancelled`,{name:e}));return}let n=t.cancelled?i(`folder.move.cancelled`,{name:e}):i(`folder.move.writeFailed`,{file:t.file,reason:this.#K(t.error)});await this.#q(a,`${n}${o(t.cleaned,t.folder)}`);return}case`unverified`:{if(!await n.confirm({title:a,message:i(`folder.move.unverified`,{folder:t.folder,file:`导出未完成.txt`}),confirm:i(`folder.move.discard`),cancel:i(`folder.move.keepFolder`),danger:!0,details:[V9(i,i(`folder.move.mismatchList`),t.mismatches.flatMap(e=>this.#A(e)))]}))return;let e=await t.takeBack().catch(()=>!1);r.push(e?i(`folder.move.discarded`,{folder:t.folder}):i(`folder.move.discardedPartly`,{folder:t.folder,file:DH}));return}case`unswitched`:console.warn(`A project in a folder could not be kept by it`,t.error),await this.#q(a,`${i(`folder.move.unswitched`,{folder:t.folder})}${o(t.cleaned,t.folder)}`);return}}async#k(e,t){let{notifications:n,t:r}=this.#e;if(t.kind===`already`||t.kind===`busy`){n.push(r(`folder.move.${t.kind}`,{name:e}));return}let i=t.kind===`invalid`?t.problems.map(e=>H9(r,e)):t.kind===`too-new`?[]:t.paths;await this.#q(r(`folder.move.refusedTitle`,{name:e}),r(`folder.move.refused.${t.kind}`),i.length>0?[V9(r,r(`folder.move.listTitle`),i)]:void 0)}#A(e){let{t}=this.#e;switch(e.kind){case`unreadable`:return[t(`folder.move.mismatch.unreadable`,{reason:e.reason}),...e.problems.map(e=>H9(t,e))];case`lost`:return[t(`folder.move.mismatch.lost`,{file:e.file,message:e.problems.map(({message:e})=>e).join(t(`folder.listSeparator`))})];default:return[t(`folder.move.mismatch.${e.kind}`,{file:e.file})]}}async#j(){let{dialogs:e,t}=this.#e;return e.prompt({title:t(`project.nameLabel`),value:t(`project.defaultName`),hint:t(`folder.chooseHint`),confirm:t(`folder.chooseFolder`)})}async#M(){try{return await this.#e.folders.choose()}catch(e){this.#N(e);return}}#N(e){console.warn(`A project folder could not be opened`,e),this.#e.notifications.push(this.#e.t(`folder.failed`))}async#P(e,t,n){let{dialogs:r,t:i}=this.#e,a;try{a=await this.projects.placeFor(e,t)}catch(e){this.#N(e);return}switch(a.kind){case`empty`:return{inside:void 0};case`project`:case`known`:await r.confirm({title:i(`folder.isProjectTitle`,{folder:e.name}),message:i(n?`folder.isProjectMessage`:`folder.isProjectElsewhere`),confirm:i(n?`folder.openIt`:`dialog.close`),...!n&&{noticeOnly:!0}})&&n&&(a.kind===`known`?await this.openRecent(a.record):await n(e));return;case`inside`:await this.#q(i(`folder.insideTitle`,{folder:e.name}),i(`folder.insideMessage`,{name:a.record.name}));return;case`incomplete`:await this.#q(i(`folder.incompleteTitle`),i(`folder.incompleteForNew`));return;case`other`:{let t=a.clashes.length>0?[{id:`inside`,label:i(`folder.putInside`,{inside:a.inside}),kind:`primary`}]:[{id:`here`,label:i(`folder.putHere`)},{id:`inside`,label:i(`folder.putInside`,{inside:a.inside}),kind:`primary`}],n=await r.choose({title:i(`folder.notEmptyTitle`,{folder:e.name}),message:a.clashes.length>0?i(`folder.notEmptyClashes`,{inside:a.inside,files:a.clashes.slice(0,5).join(`、`),count:a.clashes.length}):i(`folder.notEmptyMessage`,{inside:a.inside}),choices:t});return n===`inside`?{inside:a.inside}:n===`here`&&a.clashes.length===0?{inside:void 0}:void 0}}}async#F(e,t){let{notifications:n,t:r}=this.#e,i=await this.#P(e,t,e=>this.#I(e));if(!i)return;let a;try{a=await this.projects.create(t,e,i.inside)}catch(e){console.warn(`A project could not be made in a folder`,e),n.push(r(`folder.createFailed`));return}await this.#e.changeProject(()=>this.#V(a))}async#I(e,t=`granted`){let{dialogs:n,t:r}=this.#e,i=t;if(i===`needs-activation`){if(!await n.confirm({title:r(`folder.openTitle`,{name:e.name}),message:r(`folder.openMessage`),confirm:r(`folder.openButton`,{name:e.name})}))return;i=await e.requestAccess()}if(i!==`granted`)return;let a=await this.#z(e.name,t=>this.projects.look(e,t));if(a){if(a.kind===`known`)a.record.id!==this.#n?.record.id&&await this.openRecent(a.record);else if(a.kind===`empty`){if(!await n.confirm({title:r(`folder.emptyTitle`,{folder:e.name}),message:r(`folder.emptyMessage`),confirm:r(`folder.createHere`)}))return;let t=await n.prompt({title:r(`project.nameLabel`),value:r(`project.defaultName`),confirm:r(`project.create`)});t&&await this.#F(e,t)}else a.kind===`refused`?await this.#R(e,a.error):await this.#L(a)}}async#L(e){let{dialogs:t,t:n}=this.#e;if(e.replacing){let r=await this.projects.hasUnwritten(e.replacing);if(!await t.confirm({title:n(`folder.replacedTitle`,{folder:e.folder.name}),message:n(r?`folder.replacedOnlyCopy`:`folder.replacedMessage`,{old:e.replacing.name,name:e.name}),confirm:n(`folder.openOther`,{name:e.name}),...r&&{danger:!0}}))return}let r;for(let i of e.moved){let e=await t.choose({title:n(`folder.movedTitle`,{name:i.name}),message:n(`folder.movedMessage`),choices:[{id:`new`,label:n(`folder.movedNo`)},{id:`moved`,label:n(`folder.movedYes`),kind:`primary`}]});if(e===void 0)return;if(e===`moved`){r=i;break}}let i;try{i=await this.projects.adopt(e,r)}catch(e){this.#N(e);return}let{record:a,report:o}=i;o&&await this.#e.warnAboutCode(o),this.#J(void 0),await this.#e.changeProject(async()=>{await this.#V(a)&&o&&this.#e.noteArrival(o)})}async#R(e,t){let{t:n}=this.#e,{reason:r,problems:i}=t,a=i.length>0?[{title:n(`transfer.refusedList`),items:i.map(({file:e,path:t,message:r})=>n(`transfer.problem`,{place:t?`${e} ${t}`:e,message:r}))}]:void 0;await this.#q(n(`folder.refusedTitle`,{folder:e.name}),n(`folder.refused.${r}`),a)}async#z(e,t){let{dialogs:n,t:r}=this.#e,i=n.progress({title:r(`folder.reading`,{folder:e}),cancel:r(`dialog.cancel`),stopping:r(`transfer.stopping`)});try{return await t({signal:i.signal,onStep:({file:e})=>i.update({detail:e})})}catch(e){i.signal.aborted||this.#N(e);return}finally{i.close()}}async#B(e){let{dialogs:t,t:n}=this.#e,r=await t.choose({title:n(`folder.goneTitle`,{name:e.name}),message:n(`folder.goneMessage`),choices:[{id:`elsewhere`,label:n(`folder.saveElsewhere`)},{id:`find`,label:n(`folder.findAgain`),kind:`primary`}]});r===`find`&&await this.findAgain(e),r===`elsewhere`&&await this.saveElsewhere(e,{asked:!0})}async#V(e,{relocated:t=!1}={}){let{session:n,t:r}=this.#e,i=await this.#p.settle(e);if(await this.projects.isTooNew(i.folder).catch(()=>!1))return await this.#q(r(`folder.refusedTitle`,{folder:i.folder.name}),r(`folder.refused.too-new`)),!1;let a,o=await this.#z(i.folder.name,async e=>({report:await this.projects.prepare(i,e)}));if(!o)return!1;({report:a}=o),a&&await this.#e.warnAboutCode(a);let s=this.#H(i);if(!await n.open(i.id).catch(e=>{throw s.drop(),e}))return s.drop(),!1;let c=n.store;return await this.#U(i,c,s,t),await this.projects.opened(i,c.getState().manifest.name).catch(e=>{console.warn(`When the folder was opened could not be noted down`,e)}),a&&this.#e.noteArrival(a),!0}#H(e){let t,n=new K3({folder:()=>t?.folder??e.folder,key:e.id,bases:this.#e.folders.bases,browser:this.#e.projects.media(e.id),...this.#e.hasher&&{hasher:this.#e.hasher},onChanged:e=>{let t=this.#n;t?.assets===n&&(this.#e.assetFiles.filesChanged(e),this.#v(t))},onProgress:e=>{this.#u?.assets===n&&this.#g(e)}});return this.#u={key:e.id,assets:n},{assets:n,follow:e=>{t=e},drop:()=>{this.#u?.assets===n&&(this.#u=void 0)}}}async#U(e,t,n,r){let{session:i,folders:a,timing:o}=this.#e,{assets:s}=n,c=new qye({store:t,folder:e.folder,id:e.id,bases:a.bases,writer:a.writer(e.id),log:{saved:()=>i.trySave(),caughtUp:()=>i.readLog()},...o&&{timing:o}});n.follow(c);let l=[],u={session:c,store:t,assets:s,record:e,relocated:r,stop:()=>{for(let e of l)e();clearTimeout(u.checkTimer),u.assetWatch?.stop(),s.stop()}};l.push(c.subscribe(()=>{this.#n===u&&u.assetWatch&&this.#S(u),this.#Y()}),c.onMerge(e=>this.#W(t,e)),t.subscribe(()=>{t.getState().assets!==u.checkedAssets&&this.#v(u)})),this.#n=u,this.#Y(),await c.start(),this.#n===u&&(this.#S(u),this.#y(u),s.removeEmpty(t))}undoBatch(e){let t=this.#s.get(e);return t?(this.#G(t.store,t.merge),!0):!1}#W(e,t){let{notifications:n,t:r}=this.#e,{files:i,conflicts:a,problems:o}=t;if(i.length>0){this.#s.delete(t.origin),this.#s.set(t.origin,{store:e,merge:t});for(let e of this.#s.keys()){if(this.#s.size<=Yye)break;this.#s.delete(e)}}if(i.length===0&&a.length===0&&o.length===0)return;let s=a.length>0||o.length>0,c=i.length===0?r(`folder.notMerged`):r(s?`folder.mergedPartly`:`folder.merged`,{count:i.length});if(n.push(c,{actions:[...s?[{label:r(`folder.showMerged`),run:()=>this.#e.showProblems()}]:[],...i.length>0?[{label:r(`folder.undoMerge`),run:()=>void this.#G(e,t)}]:[]]}),!s)return;let l=r(`folder.keptIn`,{folder:b9}),u=[...a.map(e=>({severity:`warning`,text:`${r(`folder.conflict`)}${l}`,file:e.file,place:e.path.join(`.`),origin:r(`folder.origin`),action:{label:r(`folder.showTheirs`),run:()=>void this.#q(r(`folder.theirsTitle`,{file:e.file}),tbe(e.theirs,r))}})),...o.map(e=>({severity:e.severity===`error`?`error`:`warning`,text:`${e.message}${l}`,file:e.file,...e.path!==void 0&&{place:e.path},origin:r(`folder.origin`)}))];this.#o=[...this.#o,...u].slice(-200),this.#Y()}async#G(e,t){let{notifications:n,t:r}=this.#e,i=this.#n;if(i?.store!==e)return;let a;try{a=await i.session.keep(t.files)}catch(e){console.warn(`What the folder had could not be kept before taking it back`,e),n.push(r(`folder.undoNotKept`,{reason:this.#K(e)}));return}if(a===void 0){n.push(r(`folder.undoElsewhere`));return}let o=e.undoOrigin(t.origin);if(!o.ok){n.push(r(`folder.undoFailed`,{message:o.error.message}));return}let[s]=a,c=s?.split(`/`).slice(0,3).join(`/`);n.push(c===void 0?r(`folder.undoneNothingKept`):r(`folder.undone`,{folder:c}),{actions:[{label:r(`folder.redoMerge`),run:()=>{let i=e.redoOrigin(t.origin);i.ok||n.push(r(`folder.undoFailed`,{message:i.error.message}))}}]})}#K(e){let{t}=this.#e;return t(`folder.notKept.${(e instanceof ba?[`full`,`denied`,`busy`,`too-long`,`gone`].find(t=>t===e.reason):void 0)??`other`}`)}async#q(e,t,n){await this.#e.dialogs.confirm({title:e,message:t,confirm:this.#e.t(`dialog.close`),noticeOnly:!0,...n&&{details:n}})}#J(e){this.#r=e,this.#Y()}#Y(){let e=this.#n,t=e?.session.getSnapshot();this.#e.problems.setFolder([...this.#X(e,t),...this.#o,...this.#c]),this.#a={open:e&&t?{record:e.record,snapshot:t}:void 0,waiting:this.#r,moves:this.#h},this.#t.emit()}#X(e,t){let{t:n}=this.#e;if(!e||!t||t.blocked.length===0)return[];let{files:r}=e.store.exportFiles();return t.blocked.map(({path:e,problems:t})=>({severity:`error`,text:t.length>0?t.map(({message:e})=>e).join(n(`folder.listSeparator`)):n(`folder.waits`),file:e,origin:n(`folder.origin`),action:{label:r.has(e)?n(`folder.useEditorContent`):n(`folder.removeLikeEditor`),run:()=>void this.writeEditorContent([e])}}))}},ibe=class{#e=new Map;register(e){if(this.#e.has(e.type))throw Error(`Panel already registered: ${e.type}`);this.#e.set(e.type,e)}get(e){return this.#e.get(e)}list(){return[...this.#e.values()]}ready(){return new Set(this.list().flatMap(e=>e.planned?[]:[e.type]))}},abe=500,U9=150;function W9(e,t){let n=URL.createObjectURL(new Blob([JSON.stringify(e,void 0,2)])),r=document.createElement(`a`);r.href=n,r.download=`${t.replaceAll(`:`,`-`)}.json`,r.click(),URL.revokeObjectURL(n)}var obe=1e4,sbe=class{t;version;panels=new ibe;actions=new Ive;notifications=new $ve;layout;keybindings;palette;resourceHabits;explorer=new rge;missingFiles;dialogs=new Lve;session;timeline;trials;operations;properties;keyframes;sceneHandles;overlay;input;media;sounds;transfer;stills;videos;projectFolders;proxies;diagnostics;errors;#e;projects;account;windowId=va();cloud;#t=!1;#n;#r=0;compositorUrl;sceneOrigins;sceneStage;preview;frameRate;previewQuality;problems=new _ve;registrations;code;resourcePages;files;drafts;ai;chat;#i=!1;constructor(e){let{host:t,t:n,version:r,platform:i,panels:a,layouts:o,compositorUrl:s}=e;this.t=n,this.version=r;let c=t.projects;this.projects={list:()=>c.list(),create:(e,t)=>c.create(e,t),receive:e=>c.receive(e),open:e=>c.open(e),remove:(e,t)=>c.remove(e,t),media:e=>this.projectFolders?.mediaFor(e)??c.media(e),toFolder:e=>c.toFolder(e),copies:e=>c.copies(e),dropCopies:(e,t)=>c.dropCopies(e,t)};let l={...this.projects,media:e=>this.projectFolders?.mediaFor(e,this.#r)??c.media(e)};this.account=t.account,this.diagnostics=new _me(r),this.ai=new Nge(t.settings,t.keys,{saveFailed:()=>this.notifications.push(n(`ai.saveFailed`)),keyFailed:()=>this.notifications.push(n(`ai.keyFailed`))});let u=t.diagnostics;this.#e=u;let d;this.errors=new wQ({version:r,recorder:this.diagnostics,...u&&{send:e=>u.send(e)},origins:()=>typeof location>`u`?[]:[location.origin,new URL(s,location.href).origin],secrets:()=>{let e=this.session.store?.getState(),t=this.ai.knownKeys;return d&&d.state===e&&d.keys===t||(d={state:e,keys:t,found:new Set([...fQ(e),...t])}),d.found},device:V6}),this.compositorUrl=s,this.sceneOrigins=e.sceneOrigins??[],this.sceneStage=e.sceneStage,this.preview=new Tve({problem:(e,t,n,r)=>this.#l(e,t,n,r),stopped:(e,t)=>this.#u(e,t),revisions:e=>this.problems.keepRevisions(e),restarted:()=>this.notifications.push(n(`preview.restarted`))}),this.layout=new Zve(t.settings,t.windowMemory,o,()=>this.panels.ready(),{restoreFailed:()=>this.notifications.push(n(`notice.layoutRestoreFailed`)),saveFailed:()=>this.notifications.push(n(`notice.layoutSaveFailed`))}),this.keybindings=new Kve(t.settings,this.actions,i,{restoreFailed:()=>this.notifications.push(n(`notice.keybindingsRestoreFailed`)),saveFailed:()=>this.notifications.push(n(`notice.keybindingsSaveFailed`))});let f=this.layout.getSnapshot().layouts;this.layout.subscribe(()=>{let{active:e,layouts:t}=this.layout.getSnapshot();this.keybindings.notePanel(e),t!==f&&(f=t,this.keybindings.refresh())}),this.palette=new sye(t.settings,this.actions),this.resourceHabits=new uye(t.settings);let p=t.account?t.cloud:void 0;this.session=new XG(t.projects,t.address,{createFailed:()=>this.notifications.push(n(`notice.projectCreateFailed`)),notFound:()=>this.notifications.push(n(`notice.projectNotFound`)),openFailed:()=>this.notifications.push(n(`notice.projectOpenFailed`)),tooNew:()=>this.notifications.push(n(`notice.projectTooNew`)),damaged:()=>this.notifications.push(n(`notice.projectDamaged`)),saveFailed:()=>this.notifications.push(n(`notice.projectSaveFailed`)),saveRecovered:()=>this.notifications.push(n(`notice.projectSaveRecovered`))},{window:this.windowId,...p&&{compactThrough:async e=>{try{let t=await p.links.get(e);return t?t.pushed:void 0}catch{return 0}}}}),this.registrations=new l5(t.caches);let m=this.session.store;this.registrations.open(m&&JG(m)),this.session.subscribe(()=>{this.session.store!==m&&this.problems.clear(),m=this.session.store,this.registrations.open(m&&JG(m))}),this.code=new Eue(this.session,{commandFailed:e=>this.notifications.push(n(`notice.commandFailed`,{message:e})),closedRemoved:e=>this.notifications.push(n(`code.closedRemoved`,{path:e}))},{unsaved:e=>this.#p(e),overwrite:e=>this.#m(e)}),this.resourcePages=new dye(this.session,this.code),this.drafts=new zge(this.session,this.code,t.drafts,{restored:e=>this.notifications.push(n(`code.draftsRestored`,{count:e})),dropped:e=>this.notifications.push(n(`code.draftsDropped`,{count:e})),readFailed:()=>this.notifications.push(n(`code.draftsReadFailed`)),keepFailed:()=>this.notifications.push(n(`code.draftsKeepFailed`)),keepRecovered:()=>this.notifications.push(n(`code.draftsKeepRecovered`))}),this.files=new Bge(this.session,this.code,(e,t)=>this.#d(e,t),this.dialogs,this.notifications,n),this.input=new zve(t.settings),this.media=new ove(this.session,this.projects,{unsupported:e=>this.notifications.push(n(`notice.mediaUnsupported`,{name:e})),tooLarge:e=>this.notifications.push(n(`notice.mediaTooLarge`,{name:e})),saveFailed:e=>this.notifications.push(n(`notice.mediaSaveFailed`,{name:e})),commandFailed:e=>this.notifications.push(n(`notice.commandFailed`,{message:e})),confirmCopy:(e,t)=>this.dialogs.confirm({title:n(`folder.copy.title`,{name:e}),message:n(`folder.copy.message`,{size:EY(t)}),confirm:n(`folder.copy.confirm`)}),copyFailed:(e,t)=>this.notifications.push(n(`folder.copy.failed.${t}`,{name:e})),readFailed:e=>this.notifications.push(n(`folder.copy.readFailed`,{name:e})),otherKind:e=>this.notifications.push(n(`folder.asset.otherKind`,{name:e}))},s,()=>this.projectFolders?.assets());let h=new fve({url:s,setup:()=>({origins:this.sceneOrigins,retired:this.preview.retiredOrigins,compositor:new URL(s,location.href).origin,run:!1}),onRetired:e=>this.preview.noteRetired(e)});if(this.sounds=new pve({session:this.session,projects:this.projects,run:h.run,messages:{problem:(e,t)=>this.#v(e,t),failed:(e,t)=>{this.diagnostics.mark(`sound.failed`,{reason:t}),this.notifications.push(n(`sound.failed.${t}`,{name:this.#g(e),interpolation:{escapeValue:!1}}))}},arrived:e=>this.media.soundArrived(e),...e.soundLimitMs!==void 0&&{limitMs:e.soundLimitMs}}),this.transfer=new OY({folders:t.folders,projects:l,session:this.session,dialogs:this.dialogs,notifications:this.notifications,t:n}),this.timeline=new afe(this.session,t.windowMemory,t.settings,{commandFailed:e=>this.notifications.push(n(`notice.commandFailed`,{message:e})),joinsRemoved:e=>this.notifications.push(n(`timeline.joinsRemoved`,{count:e})),sceneName:e=>n(`scene.newName`,{number:e}),soundName:e=>n(`sound.newName`,{number:e}),soundWords:()=>({duration:n(`sound.param.duration`),seed:n(`sound.param.seed`)})}),this.chat=new jge({chats:t.chats,ai:this.ai,project:()=>{let{store:e,key:t}=this.session.getSnapshot();return e&&t!==void 0?{store:e,key:t}:void 0},subscribeProject:this.session.subscribe,selection:()=>{let{model:e,selection:t,transition:n}=this.timeline.getSnapshot();if(e)return{timeline:e.id,playhead:ze(lq(this.timeline.frame,e.rate)),clips:[...t],...n&&{transition:n}}},undone:e=>this.tellUndo(e)}),this.frameRate=new Cve(this.timeline),this.previewQuality=new MX(t.settings,this.frameRate),this.stills=new nve({session:this.session,timeline:this.timeline,projects:l,folders:t.folders,preview:this.preview,dialogs:this.dialogs,notifications:this.notifications,t:n,compositorUrl:s,sceneOrigins:this.sceneOrigins,sceneStage:this.sceneStage}),this.videos=new nY({session:this.session,timeline:this.timeline,projects:l,folders:t.folders,settings:t.settings,exports:t.exports,sounds:this.sounds,preview:this.preview,dialogs:this.dialogs,notifications:this.notifications,t:n,compositorUrl:s,sceneOrigins:this.sceneOrigins,sceneStage:this.sceneStage}),this.videos.cleanUp(),this.projectFolders=t.localFolders&&new rbe({folders:t.localFolders,projects:t.projects,session:this.session,address:t.address,dialogs:this.dialogs,notifications:this.notifications,problems:this.problems,t:n,changeProject:e=>this.#E(e),warnAboutCode:e=>this.transfer.warnAboutCode(e),noteArrival:e=>this.#f(e),letGo:async e=>{await this.videos.letGoOfProject(e),await this.cloud?.forget(e)},showProblems:()=>this.layout.openPanel(`problems`),assetFiles:{useNewFile:e=>this.media.useNewFile(e),usePlace:(e,t)=>this.media.usePlace(e,t),filesChanged:e=>this.media.filesChanged(e)},...e.hasher&&{hasher:e.hasher},...e.folderTiming&&{timing:e.folderTiming},...t.presence&&{presence:t.presence}}),this.session.subscribe(()=>this.projectFolders?.followSession()),this.cloud=p&&new Dge({cloud:p,session:this.session,projects:t.projects,folderOf:e=>this.projectFolders?.getSnapshot().open?.record.id===e?this.projectFolders.session?.folder??this.projectFolders.getSnapshot().open?.record.folder:void 0,isFolder:e=>this.projectFolders?.holds(e)===!0,account:t.account,dialogs:this.dialogs,notifications:this.notifications,t:n,window:this.windowId,editor:r,signIn:()=>this.signIn(),openProject:e=>this.openProject(e),...e.cloudTiming&&{timing:e.cloudTiming},...e.cloudEnvironment&&{environment:e.cloudEnvironment}}),this.cloud){let e=()=>void this.cloud?.follow();this.session.subscribe(e),this.projectFolders?.subscribe(e)}this.missingFiles=new fye(this.session,this.media,this.projectFolders),this.#x(t),this.proxies=this.projectFolders&&e.proxyMaker?this.#a(this.projectFolders,e.proxyMaker):void 0,this.diagnostics.watch(`hashing`,{get:()=>this.#C(),subscribe:e=>{let t=[this.media.subscribe(e),this.projectFolders?.subscribeProgress(e)];return()=>{for(let e of t)e?.()}}});let g=this.proxies;g&&this.diagnostics.watch(`proxies`,{get:()=>{let{making:e,paused:t}=g.getSnapshot();return e!==void 0&&!t},subscribe:e=>g.subscribe(e)}),this.trials=new kve(this.session,this.timeline,t.trials,t.settings,{commandFailed:e=>this.notifications.push(n(`notice.commandFailed`,{message:e})),overwrote:e=>this.notifications.push(n(`notice.trialOverwrote`,{count:e})),discarded:e=>this.notifications.push(n(`notice.trialDiscarded`,{count:e})),setAside:e=>this.notifications.push(n(`notice.trialSetAside`,{count:e})),back:e=>this.notifications.push(n(`notice.trialBack`,{count:e})),asideDropped:e=>this.notifications.push(n(`notice.trialAsideDropped`,{count:e})),unsure:()=>this.notifications.push(n(`notice.trialUnsure`)),restored:e=>this.notifications.push(n(`notice.trialRestored`,{count:e})),dropped:()=>this.notifications.push(n(`notice.trialDropped`)),readFailed:()=>this.notifications.push(n(`notice.trialReadFailed`)),keepFailed:()=>this.notifications.push(n(`notice.trialKeepFailed`)),keepRecovered:()=>this.notifications.push(n(`notice.trialKeepRecovered`))}),this.operations=new rye(this.session),this.properties=new Pve(this.session,this.timeline,this.trials,{commandFailed:e=>this.notifications.push(n(`notice.commandFailed`,{message:e})),comparing:()=>this.notifications.push(n(`notice.comparing`))}),this.keyframes=new T_e(this.session,this.timeline,this.trials,this.properties,t.windowMemory,t.settings,n,{pasteTooEarly:()=>this.notifications.push(n(`notice.keysPasteTooEarly`)),pasteNowhere:()=>this.notifications.push(n(`notice.keysPasteNowhere`)),comparing:()=>this.notifications.push(n(`notice.keysComparing`)),locked:()=>this.notifications.push(n(`notice.keysLocked`)),notShown:()=>this.notifications.push(n(`notice.keysNotShown`)),gone:()=>this.notifications.push(n(`notice.keysGone`))},this.registrations),this.sceneHandles=new $_e({tooMany:(e,t)=>this.preview.noteProblem(e,t,{kind:`api`,code:`handles-flood`,frame:0})}),this.overlay=new K_e({session:this.session,timeline:this.timeline,properties:this.properties,trials:this.trials,quality:this.previewQuality,handles:this.sceneHandles,registrations:this.registrations,describe:this.keyframes.describe,messages:{gone:()=>this.notifications.push(n(`notice.overlayGone`))}}),this.#o(),this.#s();for(let e of a)this.panels.register(e);this.#j(),this.#M(),this.#I(),this.#U(),this.#N(),Fve(this.actions,this.timeline,this.keyframes.inTimeline),Vge(this.actions,this.keyframes,this.timeline)}#a(e,t){return new dX({project:()=>{let{open:t}=e.getSnapshot(),n=e.session,r=e.assets(),i=this.session.store;if(t&&n&&r&&i)return{key:t.record.id,store:i,folder:n.folder,writes:t.snapshot.role===`writing`,elsewhere:t.snapshot.role===`waiting`,compared:t.snapshot.compared,async file(e){for(let t of Object.values(i.getState().assets??{})){if(t.hash===void 0||!eq(t.hash,e))continue;let n=await r.fileAt(t.path);if(n.kind===`there`&&eq(n.hash,e))return n.file}}}},subscribe:t=>{let n=[e.subscribe(t),this.session.subscribe(t)];return()=>{for(let e of n)e()}},maker:t,playing:()=>this.timeline.getSnapshot().playing,subscribePlaying:e=>this.timeline.subscribe(e)})}#o(){let{diagnostics:e}=this;this.actions.watch((t,n)=>e.mark(`action`,{id:t.id,way:n},!0));let t=this.layout.getSnapshot().active;this.layout.subscribe(()=>{let n=this.layout.getSnapshot().active;n!==t&&n!==void 0&&e.mark(`panel`,{id:n}),t=n});let n=this.preview.getSnapshot().compositor;this.preview.subscribe(()=>{let t=this.preview.getSnapshot().compositor;t!==n&&e.mark(`compositor`,{state:t}),n=t});let r=this.timeline.frame;this.timeline.subscribe(()=>{let t=this.timeline.frame;t!==r&&!this.timeline.getSnapshot().playing&&e.mark(`seek`,{frame:t},!0),r=t});let i,a,o=()=>{this.session.store!==i&&(a?.(),i=this.session.store,e.mark(`project`,{open:i!==void 0}),a=i?.watchCommands(({commands:t,by:n,ok:r,dryRun:i,code:a,error:o})=>{if(i&&r)return;let[s]=t;e.mark(`command`,{name:s,by:n,ok:r,...t.length>1&&{count:t.length},...a!==void 0&&{code:a},...i&&{dryRun:i}},!0),a===`threw`&&this.errors.capture(`command`,o,{commands:t})}))};this.session.subscribe(o),o()}#s(){let e,t=()=>{e=void 0;let t=this.session.store?.getState(),n=this.timeline.model?.id;if(!t||n===void 0){this.problems.setProperties([]);return}let r={describe:this.keyframes.describe,registered:e=>this.registrations.problemsOf(e),clipName:e=>vJ(e,t,this.t),rename:(e,t,n)=>this.renameProperty(e,t,n)};this.problems.setProperties(Ove(t,n,r,this.t))},n=()=>{e??=setTimeout(t,U9)},r,i,a=()=>{this.session.store!==r&&(i?.(),r=this.session.store,i=r?.subscribe(n),n())};this.session.subscribe(a),a(),this.registrations.subscribe(n),this.timeline.subscribe(n)}renameProperty(e,t,n){let r=this.session.store,i=this.timeline.model?.id;if(!r||i===void 0)return!1;let a=[{owner:{clip:e},from:t,to:n}],o=r.execute({type:`property.rename`,params:{timeline:i,renames:a}});return o.ok||this.notifications.push(this.t(`notice.commandFailed`,{message:o.error.message})),o.ok}async connectProperty(e,t){let n=this.timeline.model?.boxes.get(e);if(!n)return;let{t:r,keyframes:i}=this,a=Wge(i.nodeOf(n.clip),n.clip,t,e=>i.nameOfNode(e)),o={name:t,interpolation:{escapeValue:!1}};if(a.length===0){await this.dialogs.confirm({title:r(`keyframes.connect.title`,o),message:r(`keyframes.connect.none`),confirm:r(`dialog.close`),noticeOnly:!0});return}let s=(await this.dialogs.form({title:r(`keyframes.connect.title`,o),fields:[{id:`to`,label:r(`keyframes.connect.field`),options:a.map(({path:e,label:t})=>({id:e,label:t})),value:a[0].path}],confirm:r(`keyframes.connect.confirm`)}))?.to;s!==void 0&&this.renameProperty(e,t,s)}#c(e){let t=this.timeline.model?.boxes.get(e);return vJ(t?.clip,this.session.store?.getState(),this.t)}#l(e,t,n,r){this.#_(`scene.problem`,n);let{t:i}=this,a=this.#c(e),{line:o,...s}=n,{file:c,column:l}=n;if(this.problems.noteScene(e,t,{severity:mve(n),text:bJ(i,s),...c!==void 0&&{file:c},...o!==void 0&&{line:o},...l!==void 0&&{column:l},origin:a}),!r||this.layout.getSnapshot().visible.has(`problems`))return;let u={name:a,text:bJ(i,n),interpolation:{escapeValue:!1}};this.notifications.push(i(`scene.problem`,u))}#u(e,t){if(t){let{reason:e,phase:n}=t;this.diagnostics.mark(`scene.stopped`,{reason:e,phase:n})}if(!t){this.problems.noteStopped(e,void 0);return}let n=this.#c(e),r=SJ(this.t,n,t);this.problems.noteStopped(e,{severity:`error`,text:r,origin:n})}async replaceAssetFile(e){let t=this.session.store?.getState().assets?.[e];if(!t)return!1;let n=this.projectFolders,r,i=n?.assets()?await n.pickFiles():void 0;if(i){for(let e of i.unreadable)this.notifications.push(this.t(`notice.mediaUnsupported`,{name:e}));let[e]=i.inside,[t]=i.files;r=e===void 0?t&&{file:t}:{path:e}}else{let e=await this.media.chooseFile(t.kind);r=e&&{file:e}}if(!r)return!1;let a=await this.media.replaceFile(e,r);return a&&n?.checkAssetsSoon(),a}async moveAssetTo(e,t){let n=await this.media.usePlace(e,t);return n&&this.projectFolders?.checkAssetsSoon(),n}canRevealResource(e){return U8(e)!==void 0&&this.panels.get(`explorer`)!==void 0}revealResource(e){this.explorer.reveal(e)&&this.layout.openPanel(`explorer`)}goToUse(e){if(this.timeline.model?.id!==e.timeline)return!1;let t=this.timeline.revealClip(e.clip??``,{...e.edge&&{edge:e.edge},...e.join!==void 0&&{join:e.join}});return t&&this.layout.openPanel(`timeline`),t}goToProblem({file:e,line:t,column:n,target:r}){if(r){if(!this.timeline.model?.boxes.has(r.clip))return;this.timeline.selectOnly(r.clip),this.layout.openPanel(`keyframes`);return}if(e===void 0)return;let i=t===void 0?void 0:{line:t,...n&&{column:n}};this.showCode(e,i)||this.notifications.push(this.t(`problems.notInProject`,{file:e}))}#d(e,t){this.showCode(e,t?{line:1}:void 0),!t&&this.layout.getSnapshot().visible.has(`files`)&&this.layout.openPanel(`files`)}showCode(e,t){let n=this.code.open(e,t);return n&&(this.resourcePages.showCode(),this.layout.openPanel(`code`)),n}openResource(e,t){let n=U$(e),r=this.session.store?.getState();if(n&&n.kind!==`asset`&&r){let e=n.kind===`scene`?r.scenes[n.id]:r.sounds[n.id],t=n.kind===`scene`?`scenes`:`sounds`;if(e&&this.showCode(`${t}/${n.id}/${e.entry}`))return}this.openResourcePage(e,t)}openResourcePage(e,t){this.resourcePages.open(e,t),this.layout.openPanel(`code`)}#f({missing:e,damaged:t,skipped:n,lost:r,warnings:i}){let{t:a}=this,o=a(`problems.origin.import`),s=(e,t)=>t.map(t=>({severity:`warning`,text:a(`problems.import.${e}`,{name:t,interpolation:{escapeValue:!1}}),origin:o}));this.problems.noteImport([...r.map(e=>({severity:`warning`,text:e,origin:o})),...s(`missing`,e),...s(`damaged`,t),...s(`skipped`,n),...i.map(({severity:e,message:t,file:n,path:r})=>({severity:e,text:t,file:n,...r&&{place:r},origin:o}))])}#p(e){let{t}=this;return this.dialogs.choose({title:t(`code.unsavedTitle`,{path:e}),message:t(`code.unsavedMessage`),choices:[{id:`discard`,label:t(`code.discard`),kind:`danger`},{id:`save`,label:t(`code.save`),kind:`primary`}]})}#m(e){let{t}=this;return this.dialogs.choose({title:t(`code.overwriteTitle`,{path:e}),message:t(`code.overwriteMessage`),choices:[{id:`theirs`,label:t(`code.takeTheirs`)},{id:`overwrite`,label:t(`code.overwrite`),kind:`danger`}]})}async#h(){let e=this.code.unsaved.length;if(e===0)return!0;let{t}=this,n=await this.dialogs.choose({title:t(`code.leaveTitle`,{count:e}),message:t(`code.unsavedMessage`),choices:[{id:`discard`,label:t(`code.discard`),kind:`danger`},{id:`save`,label:t(`code.saveAll`),kind:`primary`}]});return n===void 0?!1:n===`save`?this.code.saveAll():(this.code.discardAll(),!0)}#g(e){return this.session.store?.getState().sounds[e]?.name??this.t(`timeline.kind.sound`)}#_(e,{kind:t,code:n}){this.diagnostics.mark(e,{type:t,...n!==void 0&&{code:n}})}#v(e,t){this.#_(`sound.problem`,t);let n={name:this.#g(e),interpolation:{escapeValue:!1}},r=bJ(this.t,t);this.notifications.push(this.t(`scene.problem`,{...n,text:r}))}async load(){await Promise.all([this.layout.load(),this.keybindings.load(),this.palette.load(),this.resourceHabits.load(),this.timeline.load(),this.keyframes.load(),this.input.load(),this.previewQuality.load(),this.trials.load(),this.ai.load()]),await this.projectFolders?.restore()||await this.session.restore(),this.account&&this.#y(this.account)}async#y(e){await e.refresh();let t=e.takeOutcome();t&&this.#b(t,e.getSnapshot())}#b(e,t){let{t:n}=this;if(e!==`signedIn`){this.notifications.push(n(`account.outcome.${e}`));return}if(t.status!==`signedIn`)return;let r={name:t.name,interpolation:{escapeValue:!1}};t.appInstalled?this.notifications.push(n(`account.signedIn`,r)):this.notifications.push(n(`account.signedInWithoutApp`,r),{stays:!0,actions:[{label:n(`account.install`),run:()=>void this.installApp()}]})}get leavingPage(){return this.#t}async leavePage(){let{t:e}=this,t=this.videos.getSnapshot()!==void 0;if(this.transfer.running||t||this.projectFolders?.moving===!0)return await this.dialogs.confirm({title:e(`app.leaveBusyTitle`),message:e(`app.leaveBusyMessage`),confirm:e(`dialog.close`),noticeOnly:!0}),!1;typeof document<`u`&&document.activeElement instanceof HTMLInputElement&&document.activeElement.matches(`[role="spinbutton"]`)&&document.activeElement.blur(),this.timeline.flush(),this.keyframes.flush();let[n,r,i]=await Promise.all([this.session.trySave(),this.trials.settle(),this.drafts.settle(),this.layout.flush()]),a=await(this.projectFolders?.flush()??Promise.resolve(!0)).catch(e=>(console.warn(`The project folder could not be written before leaving`,e),!1));if(!n||!r||!i){if(!await this.dialogs.confirm({title:e(`app.leaveUnsavedTitle`),message:e(`app.leaveUnsavedMessage`),confirm:e(`app.leaveAnyway`),danger:!0}))return!1}else if(!a&&!await this.dialogs.confirm({title:e(`app.leaveFolderTitle`),message:e(`app.leaveFolderMessage`),confirm:e(`app.leaveAnyway`)}))return!1;return this.#t=!0,clearTimeout(this.#n),this.#n=setTimeout(()=>this.#t=!1,obe),!0}async signIn(){let{account:e}=this;e&&await this.leavePage()&&e.signIn()}async installApp(){let{account:e}=this;e&&await this.leavePage()&&e.installApp()}async signOut(){let{account:e,t}=this;if(e)try{await e.signOut(),this.notifications.push(t(`account.signedOut`))}catch(e){console.warn(`Signing out failed`,e),this.notifications.push(t(`account.signOutFailed`))}}async resume(){await this.projectFolders?.resume()}async newProject(){if(this.projectFolders){await this.projectFolders.create();return}let{t:e}=this,t=await this.dialogs.prompt({title:e(`project.nameLabel`),value:e(`project.defaultName`),confirm:e(`project.create`)});t&&await this.#E(()=>this.session.create(t))}async openProject(e){let t=await this.projectFolders?.projects.records.get(e).catch(()=>void 0);t?await this.projectFolders?.openRecent(t):await this.#E(()=>this.session.open(e))}#x(e){let{presence:t}=e;if(!t)return;let n,r=()=>{let{key:e}=this.session;n?.key!==e&&(n?.leave(),n=e===void 0?void 0:{key:e,leave:t.enter(e)})};this.session.subscribe(r),r(),t.onMoved(e=>void this.projectFolders?.followMove(e))}async closeProject(){await this.#E()}async importDropped(e){let t=this.projectFolders;return t?.assets()?this.#S(await t.droppedFiles(e)):this.media.importFiles([...e.files])}async pickFiles(){let e=this.projectFolders,t=e?.assets()?await e.pickFiles():void 0;return t?this.#S(t):this.media.pickFiles()}async#S({inside:e,files:t,unreadable:n}){for(let e of n)this.notifications.push(this.t(`notice.mediaUnsupported`,{name:e}));return[...await this.media.importPaths(e),...await this.media.importFiles(t)]}async openFolder(){await this.projectFolders?.open()}async moveToFolder(e=this.session.key){return!this.projectFolders||e===void 0?!1:this.projectFolders.moveToFolder(e)}async importProject(){this.diagnostics.mark(`import`,{step:`start`});let e=await this.transfer.importProject().finally(()=>this.diagnostics.mark(`import`,{step:`end`}));e&&(await this.transfer.warnAboutCode(e),await this.openProject(e.id),this.session.key===e.id&&this.#f(e),await this.transfer.announceImport(e))}async renameProject(){let{store:e}=this.session;if(!e)return;let{t}=this,n=await this.dialogs.prompt({title:t(`project.nameLabel`),value:e.getState().manifest.name,confirm:t(`project.rename`)});if(!n)return;let r=e.execute({type:`project.rename`,params:{name:n}});r.ok||this.notifications.push(t(`notice.commandFailed`,{message:r.error.message}))}applyFrameRate(e){return this.session.store?.execute({type:`project.setFrameRate`,params:{fps:e.trim()}})?.ok===!0}async setFrameRate(){let{store:e}=this.session;if(!e)return;let{t}=this,n=await this.dialogs.prompt({title:t(`project.frameRateLabel`),value:AA(e.getState().manifest),confirm:t(`project.frameRateConfirm`)});n&&!this.applyFrameRate(n)&&this.notifications.push(t(`notice.frameRateInvalid`))}#C(){let e=this.projectFolders?.getProgress();return this.media.getImporting()>0||this.media.getCopying()!==void 0||e!==void 0&&(e.reading.length>0||e.checked!==void 0)}#w(){let e=this.session.store?.getState();if(!e)return;let t=Object.values(e.timelines);return{storage:this.projectFolders?.getSnapshot().open?`folder`:`browser`,fps:e.manifest.fps,formats:e.manifest.formats.map(({width:e,height:t,fps:n})=>({width:e,height:t,fps:n})),tracks:t.reduce((e,{tracks:t})=>e+Object.keys(t).length,0),clips:t.reduce((e,{clips:t})=>e+Object.keys(t).length,0),layout:t.flatMap(({clips:e})=>Object.values(e).slice(0,abe).map(e=>({id:e.id,kind:e.source.kind,track:e.track,start:O(Q(e)),end:O(jA(e)),offset:O(MA(e))}))),assets:Object.entries(e.assets??{}).map(([e,{kind:t,size:n,info:r}])=>{let i=this.proxies?.stateOf(e)?.kind,a=this.proxies?.madeOf(e);return{kind:t,size:n,info:r,...i!==void 0&&{proxy:i},...a&&{proxyMade:a}}}),previewQuality:this.previewQuality.getSnapshot().choice}}get canSendDiagnostics(){return this.#e!==void 0}finishDiagnostics(){this.diagnostics.finish(this.#w())}saveDiagnostics(){let{report:e}=this.diagnostics.getSnapshot();e&&W9(e,`animaquill-diagnostics-${e.startedAt}`)}saveErrorReport(e){let t=this.errors.getSnapshot().errors.find(t=>t.id===e);t&&W9(t.report,`animaquill-error-${t.report.at}`)}async sendDiagnostics(){let{report:e}=this.diagnostics.getSnapshot();if(e&&this.#e)try{this.diagnostics.markSent(await this.#e.send(e))}catch(e){console.warn(`The report did not arrive`,e),this.notifications.push(this.t(`diagnostics.sendFailed`))}}async showAbout(){let{t:e,version:t}=this;await this.dialogs.confirm({title:e(`about.title`),message:e(`about.message`,{version:t}),confirm:e(`about.close`),noticeOnly:!0})}async removeProject(e){let{t}=this;if(await this.#T(e.id))return this.notifications.push(t(`folder.move.removeIsFolder`,{name:e.name})),!1;if(!await this.dialogs.confirm({title:t(`project.removeTitle`,{name:e.name}),message:t(`project.removeWarning`),confirm:t(`project.remove`),danger:!0}))return!1;try{await this.videos.letGoOfProject(e.id),await this.session.remove(e.id),await this.cloud?.forget(e.id);let n=(await this.videos.unfinished()).filter(t=>t.project===e.id);return n.length>0&&this.notifications.push(t(`export.queue.leftElsewhere`,{count:n.length})),!0}catch(e){return console.warn(`Project could not be removed`,e),this.notifications.push(t(`notice.projectRemoveFailed`)),!1}}async#T(e){return await this.projectFolders?.projects.records.get(e).catch(()=>void 0)?!0:(await this.projects.list().catch(()=>[])).some(t=>t.id===e&&t.folder===!0)}async#E(e){if(!this.#i){this.#i=!0;try{await this.#A()&&await e?.()}finally{this.#i=!1}}}async save(){typeof document<`u`&&document.activeElement instanceof HTMLInputElement&&document.activeElement.matches(`[role="spinbutton"]`)&&document.activeElement.blur(),this.trials.getSnapshot().count>0?this.trials.save():await this.session.trySave(),await this.projectFolders?.flush()}async#D(){let{t:e}=this;this.#r=Date.now();let{count:t}=this.trials.getSnapshot();if(t===0)return!0;let n=await this.dialogs.choose({title:e(`trial.exportTitle`,{count:t}),message:e(`trial.exportMessage`),choices:[{id:`saved`,label:e(`trial.exportSaved`)},{id:`save`,label:e(`trial.exportWithTrial`),kind:`primary`}]});return n!==void 0&&(n!==`save`||this.trials.save())}async exportProject(){if(await this.#D()){this.diagnostics.mark(`export`,{step:`start`});try{await this.transfer.exportProject()}finally{this.diagnostics.mark(`export`,{step:`end`})}}}async exportFrame(){await this.#D()&&await this.stills.run()}async exportVideo(){await this.#D()&&await this.videos.start()}async#O(){await this.trials.settle();let{count:e}=this.trials.getSnapshot();if(e===0)return!this.trials.notKept||this.#k();let{t}=this,n=await this.dialogs.choose({title:t(`trial.leaveTitle`,{count:e}),message:t(`trial.leaveMessage`),choices:[{id:`discard`,label:t(`trial.discard`),kind:`danger`},{id:`keep`,label:t(`trial.keep`)},{id:`save`,label:t(`trial.save`),kind:`primary`}]});return n===void 0?!1:n===`save`?this.trials.save():n===`discard`?(this.trials.discard(),!0):await this.trials.settle()||this.#k()}#k(){let{t:e}=this;return this.dialogs.confirm({title:e(`trial.notKeptTitle`),message:e(`trial.notKeptMessage`),confirm:e(`project.leaveAnyway`),danger:!0})}async#A(){if(!this.session.store)return!0;if(!await this.#h()||!await this.#O())return!1;if(!await this.session.trySave()){let{t:e}=this;if(!await this.dialogs.confirm({title:e(`project.unsavedTitle`),message:e(`project.unsavedWarning`),confirm:e(`project.leaveAnyway`),danger:!0}))return!1}return await this.layout.detach(),await this.cloud?.close(),await this.projectFolders?.close(),await this.session.close(),!0}#j(){let e=()=>this.session.store!==void 0;if(this.actions.register({id:`project.new`,title:e=>e(`project.new`),run:()=>void this.newProject(),menu:{name:`file`,group:`open`}}),this.projectFolders&&this.actions.register({id:`project.openFolder`,title:e=>e(`folder.openAction`),run:()=>void this.openFolder(),menu:{name:`file`,group:`open`}}),this.actions.register({id:`project.close`,title:e=>e(`project.close`),run:()=>void this.closeProject(),menu:{name:`file`,group:`open`},enabled:e}),this.actions.register({id:`project.save`,title:e=>e(`project.save`),run:()=>void this.save(),keys:[`mod+s`],menu:{name:`file`,group:`project`},enabled:e}),this.actions.register({id:`project.rename`,title:e=>e(`project.renameAction`),run:()=>void this.renameProject(),menu:{name:`file`,group:`project`},enabled:e}),this.actions.register({id:`project.importMedia`,title:e=>e(`assets.importAction`),run:()=>void this.pickFiles(),menu:{name:`file`,group:`project`},enabled:e}),this.actions.register({id:`project.frameRate`,title:e=>e(`project.frameRate`),run:()=>void this.setFrameRate(),menu:{name:`file`,group:`project`},enabled:e}),!this.projectFolders)this.actions.register({id:`project.importFolder`,title:e=>e(`transfer.importAction`),run:()=>void this.importProject(),menu:{name:`file`,group:`folder`}});else{let t=this.projectFolders;this.actions.register({id:`project.moveToFolder`,title:e=>e(`folder.move.action`),run:()=>void this.moveToFolder(),menu:{name:`file`,group:`folder`},enabled:()=>e()&&!t.holds(this.session.key)})}this.actions.register({id:`project.exportFolder`,title:e=>e(`transfer.exportAction`),run:()=>void this.exportProject(),menu:{name:`file`,group:`folder`},enabled:e});let t=this.cloud;t&&(this.actions.register({id:`cloud.connect`,title:e=>e(`cloud.connectAction`),run:()=>void t.connect(),menu:{name:`file`,group:`cloud`},enabled:()=>t.canConnect}),this.actions.register({id:`cloud.disconnect`,title:e=>e(`cloud.disconnectAction`),run:()=>void t.disconnect(),menu:{name:`file`,group:`cloud`},enabled:()=>t.canDisconnect}),this.actions.register({id:`cloud.open`,title:e=>e(`cloud.openAction`),run:()=>void t.openFromCloud(),menu:{name:`file`,group:`cloud`}})),this.actions.register({id:`project.exportVideo`,title:e=>e(`export.video.action`),run:()=>void this.exportVideo(),menu:{name:`file`,group:`export`},enabled:e}),this.actions.register({id:`project.exportFrame`,title:e=>e(`export.frameAction`),run:()=>void this.exportFrame(),menu:{name:`file`,group:`export`},enabled:e})}#M(){let e=()=>this.files.getSnapshot().selected!==void 0;this.actions.register({id:`code.save`,title:e=>e(`code.saveFile`),run:()=>void this.code.save().then(()=>this.projectFolders?.flush()),keys:[`mod+s`],scope:`code`,enabled:()=>this.code.getSnapshot().active!==void 0&&this.resourcePages.showsCode}),this.actions.register({id:`files.rename`,title:e=>e(`files.renameAction`),run:()=>void this.files.rename(),keys:[`f2`],scope:`files`,enabled:e}),this.actions.register({id:`files.remove`,title:e=>e(`files.removeAction`),run:()=>void this.files.remove(),keys:[`delete`],scope:`files`,enabled:e})}#N(){this.actions.register({id:`help.about`,title:e=>e(`about.title`),run:()=>void this.showAbout(),menu:{name:`help`,group:`about`}}),this.actions.register({id:`help.diagnostics`,title:e=>e(`panel.performance.title`),run:()=>this.layout.openPanel(`performance`),menu:{name:`help`,group:`diagnostics`}})}#P(e){let{store:t}=this.session;t&&this.tellUndo(e(t))}tellUndo(e){let t=this.#F(e);t!==void 0&&this.notifications.push(t)}#F(e){return e.ok?e.obstacle?this.t(`notice.undoPartly.${e.obstacle}`):void 0:e.error.obstacle?this.t(`notice.undoBlocked.${e.error.obstacle}`):this.t(`notice.commandFailed`,{message:e.error.message})}undoTo(e){let{store:t}=this.session;if(t&&this.operations.canUndoTo(e))for(let n=0;n<2e3&&t.lastStep>=e.step;n++){if(this.trials.undoesFirst){this.trials.undo();continue}let e=t.lastStep,n=t.undo(),r=this.#F(n);if(r!==void 0)return r;if(t.lastStep===e)break}}redoLast(){let{store:e}=this.session;if(e){if(this.trials.redoesFirst)this.trials.redo();else return this.#F(e.redo())}}undoOperation(e,t){let{store:n}=this.session;if(!n||e.origin===void 0||e.source===`folder`&&t===`undo`&&this.projectFolders?.undoBatch(e.origin))return;let r=t===`undo`?n.undoOrigin(e.origin):n.redoOrigin(e.origin);return this.#F(r)}#I(){this.actions.register({id:`edit.undo`,title:e=>e(`edit.undo`),run:()=>{this.trials.undoesFirst?this.trials.undo():this.#P(e=>e.undo())},keys:[`mod+z`],menu:{name:`edit`,group:`history`},enabled:()=>this.session.store?.canUndo===!0||this.trials.canUndo}),this.actions.register({id:`edit.redo`,title:e=>e(`edit.redo`),run:()=>{this.trials.redoesFirst?this.trials.redo():this.#P(e=>e.redo())},keys:[`mod+shift+z`,`mod+y`],menu:{name:`edit`,group:`history`},enabled:()=>this.session.store?.canRedo===!0||this.trials.canRedo}),this.actions.register({id:`trial.compare`,title:e=>e(`trial.action.compare`),run:()=>this.trials.toggleCompare(),menu:{name:`edit`,group:`trial`},enabled:()=>this.trials.getSnapshot().count>0}),this.actions.register({id:`trial.discard`,title:e=>e(`trial.action.discard`),run:()=>this.trials.discard(),menu:{name:`edit`,group:`trial`},enabled:()=>{let{count:e,setAside:t}=this.trials.getSnapshot();return e+t>0}})}#L(e){let t;this.actions.provide(()=>{let{layouts:n}=this.layout.getSnapshot();return t?.from!==n&&(t={from:n,actions:this.#R(n,e)}),t.actions});let n=()=>e()&&this.layout.isCustom(this.layout.getSnapshot().layout);this.actions.register({id:`layout.saveAs`,title:e=>e(`layout.saveAs`),run:()=>void this.#B(),menu:{name:`layout`,group:`manage`},enabled:e}),this.actions.register({id:`layout.rename`,title:e=>e(`layout.renameAction`),run:()=>void this.#V(),menu:{name:`layout`,group:`manage`,title:e=>e(`layout.rename`)},enabled:n}),this.actions.register({id:`layout.delete`,title:e=>e(`layout.deleteAction`),run:()=>void this.#H(),menu:{name:`layout`,group:`manage`,title:e=>e(`layout.delete`)},enabled:n}),this.actions.register({id:`layout.reset`,title:e=>e(`layout.reset`),run:()=>this.layout.resetLayout(),menu:{name:`layout`,group:`reset`},enabled:e})}#R(e,t){return e.map((e,n)=>({id:`layout.switch.${e.id}`,title:t=>t(`action.switchLayout`,{layout:e.title(t)}),run:()=>this.layout.switchLayout(e.id),...n<9&&{keys:[`alt+shift+${n+1}`]},menu:{name:`layout`,group:e.custom?`custom`:`presets`,title:e.title},selected:()=>this.layout.getSnapshot().layout===e.id,enabled:t}))}#z(){let{layout:e,layouts:t}=this.layout.getSnapshot();return t.find(t=>t.id===e)?.title(this.t)??``}async#B(){let{t:e}=this,t=this.layout.getSnapshot().layouts.filter(e=>e.custom).length,n=await this.dialogs.prompt({title:e(`layout.saveAsTitle`),value:e(`layout.newName`,{number:t+1}),hint:e(`layout.saveAsHint`),confirm:e(`layout.saveAsConfirm`)});n!==void 0&&this.layout.saveAs(n)}async#V(){let{t:e}=this,{layout:t}=this.layout.getSnapshot();if(!this.layout.isCustom(t))return;let n=await this.dialogs.prompt({title:e(`layout.renameTitle`),value:this.#z(),confirm:e(`layout.renameConfirm`)});n!==void 0&&this.layout.rename(t,n)}async#H(){let{t:e}=this,{layout:t,layouts:n}=this.layout.getSnapshot();if(!this.layout.isCustom(t))return;let r=n[0]?.title(e)??``;await this.dialogs.confirm({title:e(`layout.deleteTitle`,{name:this.#z()}),message:e(`layout.deleteMessage`,{first:r}),confirm:e(`layout.deleteConfirm`),danger:!0})&&this.layout.remove(t)}#U(){let e=()=>this.session.store!==void 0;this.#L(e),this.actions.register({id:`view.commandPalette`,title:e=>e(`palette.title`),run:()=>this.palette.toggle(),keys:[`mod+shift+p`,`f1`],menu:{name:`view`,group:`commands`},palette:!1});for(let t of this.panels.list())this.actions.register({id:`view.open.${t.type}`,title:e=>e(`action.openPanel`,{panel:t.title(e)}),run:()=>this.layout.openPanel(t.type),...t.keys?{keys:t.keys}:{},menu:{name:`view`,group:`panels.${t.area}`,title:t.title},enabled:e})}},G9=(...e)=>({kind:`split`,direction:`row`,children:e}),K9=(...e)=>({kind:`split`,direction:`column`,children:e}),q9=(e,t=!1)=>(...n)=>({kind:`tabs`,panels:n,strip:e,pinned:t}),J9=q9(`top`),Y9=q9(`left`),X9=q9(`right`),cbe=[{id:`edit`,title:e=>e(`layout.edit`),layout:K9([60,G9([22,{...Y9(`files`,`explorer`,`assets`,`transitions`,`effects`),active:`assets`}],[52,J9(`preview`,`code`,`music`,`recording`,`versions`)],[26,X9(`properties`,`chat`,`history`,`notes`)])],[40,Y9(`timeline`,`keyframes`,`problems`,`terminal`)])},{id:`animate`,title:e=>e(`layout.animate`),layout:K9([50,G9([21,Y9(`explorer`,`assets`,`transitions`,`effects`,`files`)],[28,J9(`preview`)],[28,J9(`code`)],[23,X9(`properties`,`chat`,`history`)])],[50,Y9(`keyframes`,`timeline`,`problems`)])},{id:`audio`,title:e=>e(`layout.audio`),layout:K9([55,G9([22,Y9(`assets`,`explorer`,`effects`)],[52,J9(`music`,`recording`,`preview`)],[26,X9(`properties`,`history`)])],[45,Y9(`timeline`,`problems`)])},{id:`ai`,title:e=>e(`layout.ai`),layout:G9([76,K9([60,G9([28,Y9(`explorer`,`assets`,`transitions`,`effects`,`files`)],[72,J9(`preview`,`code`)])],[40,Y9(`timeline`,`keyframes`,`problems`)])],[24,X9(`chat`,`history`,`notes`,`properties`)])}],Z9=()=>new DOMException(`The proxy was not wanted any more`,`AbortError`),lbe=3;function ube({frameMs:e}={}){let t,n=typeof Worker>`u`?new RY(`unsupported`):void 0,r=0,i=0,a=new Map,o=(e,t,n=[])=>e.postMessage(t,n),s=(e,i)=>{if(t!==e)return;e.terminate(),t=void 0,r+=1,r>=lbe&&(n=new RY(`encoder`,{cause:`Workers for proxies kept breaking: ${i}`}));let o=[...a.values()];a.clear();for(let e of o)e.reject(new RY(`encoder`,{cause:i}))},c=()=>{if(n)return;if(t)return t;try{t=new Worker(new URL(`/assets/proxy-worker-DJwICOHC.js`,``+import.meta.url),{type:`module`,name:`proxies`})}catch(e){console.warn(`Proxies cannot be made in this browser`,e),n=new RY(`unsupported`,{cause:e});return}let e=t;return e.addEventListener(`message`,t=>{let n=t.data,r=a.get(n.job);if(r)switch(n.kind){case`write`:r.request.write(new Uint8Array(n.data),n.position).then(()=>o(e,{kind:`written`,job:n.job,write:n.write}),t=>{a.delete(n.job),o(e,{kind:`cancel`,job:n.job}),r.reject(t)});break;case`progress`:r.request.onProgress?.(n.share);break;case`done`:a.delete(n.job),r.resolve(n.result);break;case`failed`:{a.delete(n.job);let{reason:e,message:t,acceleration:i}=n;r.reject(e===`cancelled`?Z9():new RY(e,{cause:t,...i&&{acceleration:i}}));break}}}),e.addEventListener(`error`,t=>{t.preventDefault(),console.warn(`The worker for proxies stopped`,t.message),s(e,t.message)}),e};return{make(t){let r=()=>{},s=()=>{},l=new Promise((e,t)=>{r=e,s=t}),u=c(),d=i++;if(!u)return s(n??new RY(`unsupported`)),{done:l,pause(){},resume(){},cancel(){}};a.set(d,{request:t,resolve:r,reject:s});let{file:f,spec:p,encoders:m}=t;o(u,{kind:`make`,job:d,file:f,spec:p,encoders:[...m],...e!==void 0&&{frameMs:e}});let h=e=>{a.has(d)&&o(u,{kind:e,job:d})};return{done:l,pause:()=>h(`pause`),resume:()=>h(`resume`),cancel(){let e=a.get(d);e&&(a.delete(d),o(u,{kind:`cancel`,job:d}),e.reject(Z9()))}}}}}async function dbe(e,t){let n=await DQ(),r=new sbe({host:t.host,t:n.t,version:t.version,platform:/Mac/.test(navigator.platform)?`mac`:`other`,panels:[...cge,...t.panels??[]],layouts:cbe,compositorUrl:t.compositorUrl,sceneOrigins:t.sceneOrigins??[],...t.sceneStage&&{sceneStage:t.sceneStage},...t.soundLimitMs!==void 0&&{soundLimitMs:t.soundLimitMs},hasher:$fe(),proxyMaker:ube({frameMs:t.proxyFrameMs})}),i=TQ(r.errors,r.diagnostics,t.compositorUrl);await r.load(),t.onWorkbench?.(r);let a=(0,ys.createRoot)(e);a.render((0,L.jsx)(N.StrictMode,{children:(0,L.jsx)(LZ,{workbench:r,i18n:n})})),r.resume();let o=()=>{document.visibilityState===`hidden`&&(r.layout.flush(),r.timeline.flush(),r.keyframes.flush(),r.projectFolders?.flush())};document.addEventListener(`visibilitychange`,o);let s=()=>{r.proxies?.lookAgain(),r.account?.refresh()};window.addEventListener(`focus`,s);let c=e=>{r.dialogs.getSnapshot()||r.keybindings.handle(e)};window.addEventListener(`keydown`,c);let l=e=>{e.dataTransfer?.types.includes(`Files`)&&e.preventDefault()},u=e=>{let t=e.dataTransfer;if(!t?.types.includes(`Files`))return;let n=e.defaultPrevented;e.preventDefault(),!n&&!r.dialogs.getSnapshot()&&r.projectFolders?.dropped(t)};window.addEventListener(`dragover`,l),window.addEventListener(`drop`,u);let d=e=>{if(r.leavingPage)return;let{code:t,session:n,transfer:i,trials:a,videos:o,projectFolders:s}=r,c=o.getSnapshot()!==void 0,l=s?.moving===!0;(n.hasUnsavedChanges||i.running||a.notKept||c||l||t.hasUnsaved)&&e.preventDefault()};return window.addEventListener(`beforeunload`,d),()=>{window.removeEventListener(`drop`,u),window.removeEventListener(`dragover`,l),window.removeEventListener(`beforeunload`,d),window.removeEventListener(`keydown`,c),document.removeEventListener(`visibilitychange`,o),window.removeEventListener(`focus`,s),r.proxies?.dispose(),a.unmount(),i()}}var fbe=7651,Q9={editor:`animaquill.localhost`,compositor:`animaquill-sandbox.localhost`,scene:e=>`animaquill-scene-${e}.localhost`};function pbe(e=fbe){if(!Number.isInteger(e)||e<1||e>65535)throw RangeError(`Not a port: ${e}`);let t=t=>new URL(`http://${t}:${e}`).origin;return{editor:t(Q9.editor),compositor:t(Q9.compositor),scenes:Array.from({length:8},(e,n)=>t(Q9.scene(n)))}}var mbe=`/compositor.html`;async function hbe({root:e,sites:t,version:n,host:r}){navigator.serviceWorker?.register(`/sw.js`).catch(e=>{console.warn(`The editor cannot be installed as an app here`,e)}),await dbe(e,{host:{...us(),...r},version:n,compositorUrl:`${t.compositor}${mbe}`,sceneOrigins:t.scenes})}var $9=document.querySelector(`#root`);$9&&await hbe({root:$9,sites:pbe(Number(location.port||80)),version:{BASE_URL:`/`,DEV:!1,MODE:`production`,PROD:!0,SSR:!1,VITE_VERSION:`0.3.35`}.VITE_VERSION??`local`});