rushes 0.5.1 → 0.5.2
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.
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rushes",
|
|
3
3
|
"description": "A local review desk for video made with AI agents: timecoded notes, script edits and audio picks your agent reads and acts on.",
|
|
4
|
-
"version": "0.5.
|
|
4
|
+
"version": "0.5.2",
|
|
5
5
|
"author": { "name": "Red Morley Hewitt" },
|
|
6
6
|
"homepage": "https://github.com/iamredmh/rushes",
|
|
7
7
|
"repository": "https://github.com/iamredmh/rushes",
|
package/dist/core/storyboard.js
CHANGED
|
@@ -95,6 +95,8 @@ export function editShot(text, index, heading, edit) {
|
|
|
95
95
|
* The shots as a cut's shot list: each `start` is the running total of the lengths before it. A shot with
|
|
96
96
|
* no usable Length counts as one second, so two shots never start together.
|
|
97
97
|
*/
|
|
98
|
+
/** No shot is planned longer than a day: a typo of 1e17 seconds must not swallow every start after it. */
|
|
99
|
+
const MAX_SHOT_SECONDS = 86_400;
|
|
98
100
|
export function cutShots(shots) {
|
|
99
101
|
let start = 0;
|
|
100
102
|
let last = -1;
|
|
@@ -103,7 +105,7 @@ export function cutShots(shots) {
|
|
|
103
105
|
const at = Math.max(Math.round(start * 1000) / 1000, last + 0.001);
|
|
104
106
|
const out = { name: s.name.slice(0, 80), start: Math.round(at * 1000) / 1000, tag: s.tag.slice(0, 24) };
|
|
105
107
|
last = out.start;
|
|
106
|
-
start += s.length ?? 1;
|
|
108
|
+
start += Math.min(s.length ?? 1, MAX_SHOT_SECONDS);
|
|
107
109
|
return out;
|
|
108
110
|
});
|
|
109
111
|
}
|
package/dist/server/app.js
CHANGED
|
@@ -31,7 +31,7 @@ import { buildState, planWarning } from "../core/plan.js";
|
|
|
31
31
|
import { broughtInEvent, cutEvent, fileEvent, formatEvent, lineEvent, lockEvent, notesSentEvent, picksEvent, repliesEvent, scriptEvent, takeEvent, variantEvent, } from "../core/logEvents.js";
|
|
32
32
|
import { LOG_AREAS, LOG_MAX, changeLogFileName, logText, recentChanges } from "../core/logText.js";
|
|
33
33
|
import { defaultRunner, measureMix } from "./loudness.js";
|
|
34
|
-
export const VERSION = "0.5.
|
|
34
|
+
export const VERSION = "0.5.2";
|
|
35
35
|
async function body(c, schema) {
|
|
36
36
|
let json;
|
|
37
37
|
try {
|
package/dist/server/record.js
CHANGED
|
@@ -128,9 +128,10 @@ export class RecordFile {
|
|
|
128
128
|
const tick = async () => {
|
|
129
129
|
try {
|
|
130
130
|
const st = await lstat(this.path).catch(() => null);
|
|
131
|
-
|
|
131
|
+
// Only a regular file counts as "there was a file": changes inside a folder at this path are none of our business.
|
|
132
|
+
const sig = st ? `${st.isFile() ? "f" : "x"}:${st.mtimeMs}:${st.size}:${st.ino}` : "";
|
|
132
133
|
if (sig !== last) {
|
|
133
|
-
const hadFile = last
|
|
134
|
+
const hadFile = last?.startsWith("f:") ?? false;
|
|
134
135
|
last = sig;
|
|
135
136
|
await this.sync();
|
|
136
137
|
// A file that is deleted, or becomes a folder or a link, changes nothing in `.rushes/` by itself. Forget what was
|
package/package.json
CHANGED
|
@@ -4,4 +4,4 @@
|
|
|
4
4
|
|
|
5
5
|
`);a(`the brief's status`,(e,r)=>r&&t===`approved`&&e.sections.map(e=>`${e.heading}\n${e.yours}`).join(`
|
|
6
6
|
|
|
7
|
-
`)!==n?{refuse:`the agent changed the brief while you were looking at it. Read it again, then approve.`}:{path:`/api/brief/status`,body:{status:t}})}},s=e.status===`approved`;return Q(`div`,{class:`col`,children:[Q(`div`,{class:`shead`,children:[Q(`h2`,{children:`Brief`}),Q(`span`,{class:`meta`,children:[e.title,e.title&&e.sections.length>0?` · `:``,e.sections.length>0&&`${e.sections.length} section${e.sections.length===1?``:`s`} · ${e.changed} changed`]})]}),e.sections.length===0&&Q(`p`,{class:`sbnone`,children:"brief.md has no ## sections yet. Your agent adds them as `## Purpose`, `## Audience` and so on."}),Q(`div`,{class:`sgrid bgrid scols`,children:[Q(`span`,{}),Q(`span`,{children:`Current`}),Q(`span`,{children:`Yours`})]}),Q(`div`,{style:{display:`grid`,gap:`12px`},children:e.sections.map(t=>Q($a,{section:t,save:o},`${t.heading}#${eo(e.sections,t.index)}`))}),Q(`div`,{class:`bfoot`,children:Q(`button`,{class:`btn bapprove${s?` approved`:``}`,"aria-pressed":s,onClick:()=>o.status(s?`draft`:`approved`),children:[Q($,{name:`check`}),s?`Approved`:`Approve brief`]})})]})}var no=150;function ro({chips:e,versionId:t,prompt:n,onSelect:r,toast:i}){let a=X(null),o=e.some(e=>e.reason===`single`),s=e.filter(e=>e.enabled),c=e.find(e=>e.selected)?.id??null;Y(()=>{let e=a.current,t=document.activeElement;if(!e||!c||!(t instanceof HTMLElement)||!e.contains(t))return;let n=e.querySelector(`[data-format="${c}"]`);n&&n!==t&&n.focus()},[c]);let[l,u]=q(!1),[d,f]=q(!1),[p,m]=q(!1),[h,g]=q(!1),_=X(void 0),v=X(!1),y=()=>{clearTimeout(_.current),u(!0),m(!1)},b=()=>{clearTimeout(_.current),_.current=window.setTimeout(()=>u(!1),no)};J(()=>()=>clearTimeout(_.current),[]);let x=o&&(l||d)&&!p&&!h;if(J(()=>{if(!x)return;let e=e=>{e.key===`Escape`&&m(!0)};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[x]),e.length===0)return null;let S=e=>{if(e.altKey||e.metaKey||e.ctrlKey||s.length===0)return;let t=Math.max(0,s.findIndex(e=>e.selected)),n=null;e.key===`ArrowRight`||e.key===`ArrowDown`?n=(t+1)%s.length:e.key===`ArrowLeft`||e.key===`ArrowUp`?n=(t-1+s.length)%s.length:e.key===`Home`?n=0:e.key===`End`&&(n=s.length-1),n!==null&&(e.preventDefault(),e.stopPropagation(),r(s[n].id)!==!1&&a.current?.querySelector(`[data-format="${s[n].id}"]`)?.focus())},C=async()=>{try{await navigator.clipboard.writeText(n),i(`Prompt copied`)}catch{i(`Couldn't reach the clipboard. Ask your agent to register the other shapes with rushes_add_format.`)}};return Q(`div`,{class:`fmtwrap`,children:[Q(`div`,{ref:a,class:`fmts`,role:`radiogroup`,"aria-label":`Format`,style:{gridTemplateColumns:Yn(e.length)},onKeyDown:e=>S(e),children:e.map(e=>{let n=Jn(e.width,e.height),i=e.reason===`absent`?`Not in ${t}`:e.warn??void 0,a=e.reason===`single`;return Q(`button`,{type:`button`,role:`radio`,"data-format":e.id,"aria-checked":e.selected,"aria-disabled":e.enabled?void 0:`true`,tabIndex:e.enabled&&e.selected?0:-1,"aria-label":qn(e,t),class:i?`tip-below`:void 0,"data-tip":i,onMouseEnter:a?y:()=>g(!0),onMouseLeave:a?b:()=>g(!1),onClick:t=>{e.enabled&&(t.detail>0&&t.currentTarget.blur(),r(e.id))},children:[Q(`span`,{class:`shape`,"aria-hidden":`true`,style:{width:`${n.width}px`,height:`${n.height}px`}}),Q(`span`,{class:`lbl`,"data-label":e.label,children:e.label}),e.warn&&Q(`span`,{class:`warn`,"aria-hidden":`true`,children:`!`}),!o&&Q(`span`,{class:`n${e.count>0?``:` none`}`,"aria-hidden":`true`,children:e.count>0?e.count:``})]},e.id)})}),o&&Q(`div`,{class:`fmtpop${x?` open`:``}`,onMouseEnter:y,onMouseLeave:b,children:[Q(`p`,{children:[`One format. Your agent can add more with `,Q(`code`,{children:`rushes_add_format`}),`.`]}),Q(`button`,{type:`button`,class:`btn ghost`,onPointerDown:()=>{v.current=!0},onFocus:()=>{v.current||f(!0),v.current=!1},onBlur:()=>{f(!1),m(!1)},onClick:e=>{v.current=!1,e.detail>0&&e.currentTarget.blur(),C()},children:[Q($,{name:`copy`}),`Copy a prompt for your agent`]})]})]})}var io=.03,ao=.004,oo=15e3;function so(e){return e.buffer?e.buffer.length*e.buffer.numberOfChannels*4:0}var co=0;function lo(){return co}var uo=new Map;function fo(e){let t=uo.get(e);return t&&(uo.delete(e),uo.set(e,t)),t}function po(e,t){for(uo.delete(e),uo.set(e,t);uo.size>200;)uo.delete(uo.keys().next().value)}function mo(){let e=Error(`The load was cancelled`);return e.name=`AbortError`,e}function ho(e){return(t,n)=>new Promise(r=>{let i=e(t),a,o=!1,s=e=>{o||(o=!0,clearTimeout(a),n.removeEventListener(`abort`,c),i.removeAttribute(`src`),i.load(),r(e))},c=()=>s(null);if(n.aborted)return s(null);n.addEventListener(`abort`,c),i.preload=`metadata`,i.addEventListener(`loadedmetadata`,()=>s(Number.isFinite(i.duration)?i.duration:null),{once:!0}),i.addEventListener(`error`,()=>s(null),{once:!0}),a=setTimeout(()=>s(null),oo)})}var go=class{ctx=null;disposed=!1;opts;clips=[];videoDuration=null;media=new Map;loads=new Map;idle=new Map;holding=new Map;selection={};laneTargets={};laneNodes=new Map;clipNodes=new Map;voices=new Map;serials=new WeakMap;serial=0;_playing=!1;startOffset=0;startedAt=0;frame=null;tickListeners=new Set;endedListeners=new Set;changeListeners=new Set;constructor(e,t={}){let n=t.createMedia??(e=>new Audio(e));this.opts={createContext:t.createContext??(()=>new AudioContext),url:t.url??Nr,fetch:t.fetch??((e,t)=>fetch(e,t)),probe:t.probe??ho(n),createMedia:n,raf:t.raf??(e=>requestAnimationFrame(e)),caf:t.caf??(e=>cancelAnimationFrame(e))},e&&(this.ctx=e,co++)}get playing(){return this._playing}get time(){if(!this._playing||!this.ctx)return this.startOffset;let e=this.startOffset+Math.max(0,this.ctx.currentTime-this.startedAt),t=this.length;return t>0?Math.min(e,t):e}get length(){return di(this.videoDuration,this.resolved())}inspect(){return{playing:this._playing,time:this.time,length:this.length,sources:this.voices.size,gains:$r(this.clips,this.selection),lanes:{...this.laneTargets},media:[...this.media.keys()],streamed:[...this.media].filter(([,e])=>e.streamed).map(([e])=>e),idle:[...this.idle.keys()],voices:Object.fromEntries([...this.voices].map(([e,t])=>[e,this.serials.get(t)??0]))}}onTick(e){return this.tickListeners.add(e),()=>this.tickListeners.delete(e)}onEnded(e){return this.endedListeners.add(e),()=>this.endedListeners.delete(e)}onChange(e){return this.changeListeners.add(e),()=>this.changeListeners.delete(e)}subscribe(e){let t=this.onTick(e),n=this.onChange(()=>e(this.time));return()=>{t(),n()}}load(e,t){if(this.disposed)return Promise.reject(Error(`The audio engine was disposed`));let n=Kr({path:e,rev:t}),r=this.loads.get(n)??this.idle.get(n)?.load;if(r)return r.promise;let i=new AbortController,a=this.loadOnce(e,n,i.signal),o={path:e,promise:a,abort:i};return this.loads.set(n,o),a.catch(()=>{this.loads.get(n)===o&&this.loads.delete(n);for(let e of this.clips)Kr(e)===n&&this.holding.delete(e.id)}),a}async loadOnce(e,t,n){let r=this.ensureContext(),i=this.opts.url(e),a=new AbortController,o=()=>a.abort();n.addEventListener(`abort`,o);let s=!1,c=()=>{s=!0,a.abort()},l=this.opts.probe(i,n).then(e=>(ai(e,!0)&&c(),e),()=>null),u=null;try{let e=await this.opts.fetch(i,{signal:a.signal});if(!e.ok)throw Error(`HTTP ${e.status}`);let t=e.headers?.get(`content-length`)??null;if(ci(t!==null&&Number.isFinite(Number(t))?Number(t):null)&&c(),!s){let t=await e.arrayBuffer();!s&&!n.aborted&&(u=await r.decodeAudioData(t))}}catch{u=null}finally{n.removeEventListener(`abort`,o)}if(n.aborted||this.disposed)throw mo();let d;if(u&&!ai(u.duration,!0)){let e=fo(t);if(!e){let n=[];for(let e=0;e<u.numberOfChannels;e++)n.push(u.getChannelData(e));e=ri(n,ii(u.duration)),po(t,e)}this.media.set(t,{duration:u.duration,buffer:u,streamed:!1}),d={duration:u.duration,peaks:e,streamed:!1}}else{let r=u?u.duration:await l;if(n.aborted||this.disposed)throw mo();if(r===null||!(r>0))throw Error(`Couldn't load ${e}`);this.media.set(t,{duration:r,buffer:null,streamed:!0}),d={duration:r,peaks:new Float32Array,streamed:!0}}return this.afterLoad(t),d}afterLoad(e){for(let t of this.clips)Kr(t)===e&&this.holding.delete(t.id);if(this._playing){for(let t of this.resolved())Kr(t)===e&&!this.voices.has(t.id)&&this.startLate(t);this.syncStreams(this.rawClock())}this.emitChange()}setClips(e){let t=new Map(e.map(e=>[e.id,e])),n=this.resolved(),r=new Map(this.clips.map(e=>[e.id,e]));for(let e of this.clips){let n=t.get(e.id);n&&n.lane===e.lane&&n.path===e.path&&n.rev===e.rev&&n.offset===e.offset&&n.duration===e.duration||this.dropClip(e.id)}for(let e of n){let n=t.get(e.id),i=r.get(e.id);n&&n.path===i.path&&n.rev!==i.rev&&e.duration>0&&this.holding.set(e.id,e.duration)}for(let e of[...this.holding.keys()])t.has(e)||this.holding.delete(e);let i=new Set(e.map(Kr)),a=new Set(e.map(e=>e.path));for(let[e,t]of this.loads){if(i.has(e))continue;let n=this.media.get(e);!n||a.has(t.path)?t.abort.abort():this.idle.set(e,{media:n,load:t}),this.loads.delete(e),this.media.delete(e)}for(let e of[...this.media.keys()])i.has(e)||this.media.delete(e);for(let[e,t]of this.idle)!i.has(e)&&a.has(t.load.path)&&this.idle.delete(e);for(let e of i){let t=this.idle.get(e);t&&(this.idle.delete(e),this.media.set(e,t.media),this.loads.set(e,t.load))}let o=0;for(let e of this.idle.values())o+=so(e.media);for(;this.idle.size>12||o>268435456;){let[e,t]=this.idle.entries().next().value;o-=so(t.media),this.idle.delete(e)}if(this.clips=e.slice(),this._playing){for(let e of this.resolved())this.voices.has(e.id)||this.startLate(e);this.syncStreams(this.rawClock())}this.emitChange()}setVideoDuration(e){this.videoDuration=e,this._playing||(this.startOffset=this.clampTime(this.startOffset)),this.emitChange()}setLaneGain(e,t){this.laneTargets[e]=t;let n=this.laneNodes.get(e);n&&this.ramp(n.gain,t)}selectVariant(e,t){t===null?delete this.selection[e]:this.selection[e]=t;let n=$r(this.clips,this.selection);for(let t of this.clips){if(t.lane!==e)continue;let r=this.clipNodes.get(t.id);r&&this.ramp(r.gain.gain,n[t.id])}}play(e=this.time){if(this.disposed)return;let t=this.ensureContext(),n=this.length;if(n<=0)return;let r=this.clampTime(e);r>=n&&(r=0),t.state===`suspended`&&t.resume().catch(()=>{}),pi(this,()=>this.pause()),this._playing=!0,this.restart(r),this.startLoop(),this.emitChange()}pause(){this._playing&&(this.startOffset=this.time,this._playing=!1,this.stopVoices(),this.pauseStreams(),this.stopLoop(),mi(this),this.emitChange())}seek(e){if(this.disposed)return;let t=this.clampTime(e);this._playing?this.restart(t):this.startOffset=t,this.emitChange()}dispose(){if(!this.disposed){this._playing=!1,this.stopLoop(),this.stopVoices();for(let e of this.loads.values())e.abort.abort();this.loads.clear(),this.idle.clear(),this.holding.clear();for(let e of[...this.clipNodes.keys()])this.dropClip(e);for(let e of this.laneNodes.values())e.disconnect();this.laneNodes.clear(),this.media.clear(),mi(this),this.tickListeners.clear(),this.endedListeners.clear(),this.changeListeners.clear(),this.disposed=!0,this.ctx&&(this.ctx.close().catch(()=>{}),this.ctx=null,co--)}}ensureContext(){if(this.disposed)throw Error(`The audio engine was disposed`);return this.ctx||(this.ctx=this.opts.createContext(),co++),this.ctx}resolved(){let e={};for(let[t,n]of this.media)e[t]=n.duration;let t=ui(this.clips,e);return this.holding.size===0?t:t.map(e=>e.duration>0?e:{...e,duration:this.holding.get(e.id)??0})}clampTime(e){let t=this.length,n=Math.max(0,Number.isFinite(e)?e:0);return t>0?Math.min(n,t):n}rawClock(){return!this._playing||!this.ctx?this.startOffset:this.startOffset+(this.ctx.currentTime-this.startedAt)}restart(e){let t=this.ctx;this.stopVoices(),this.startOffset=e,this.startedAt=t.currentTime+io;let n=this.resolved(),r=new Map(n.map(e=>[e.id,e]));for(let t of ei(n,e))this.startVoice(r.get(t.id),this.startedAt+t.when,t.offset);this.syncStreams(this.rawClock(),!0)}startLate(e){let t=this.ctx;if(!t)return;let n=Math.max(this.startedAt,t.currentTime+io),r=this.startOffset+(n-this.startedAt);for(let t of ei([e],r))this.startVoice(e,n+t.when,t.offset)}startVoice(e,t,n){let r=this.media.get(Kr(e));if(!this.ctx||!r||r.streamed||!r.buffer)return;let i=this.ctx.createBufferSource();i.buffer=r.buffer,i.connect(this.nodesFor(e).gain),i.onended=()=>{this.voices.get(e.id)===i&&(this.voices.delete(e.id),i.disconnect())},i.start(t,n,e.duration-n),this.voices.set(e.id,i),this.serials.set(i,++this.serial)}stopSource(e){e.onended=null;try{e.stop()}catch{}e.disconnect()}stopVoices(){for(let e of this.voices.values())this.stopSource(e);this.voices.clear()}syncStreams(e,t=!1){let n=this.ctx?.currentTime??0;for(let r of this.resolved()){if(!this.media.get(Kr(r))?.streamed)continue;let i=this.clipNodes.get(r.id),a=i?.el,o=e-r.offset,s=a?{time:a.currentTime,paused:a.paused,seeking:a.seeking,readyState:a.readyState}:{time:0,paused:!0},c=li(o,r.duration,s,i?n-i.seekedAt:1/0);if(t&&o>=0&&o<r.duration&&(c=s.paused?`play`:`seek`),c===`none`)continue;let l=i??this.nodesFor(r),u=l.el;if(c===`pause`){u.pause();continue}u.currentTime=o,l.seekedAt=n,c===`play`&&u.play().catch(()=>{})}}pauseStreams(){for(let e of this.clipNodes.values())e.el?.pause()}laneNode(e){let t=this.laneNodes.get(e);return t||(t=this.ctx.createGain(),t.gain.value=this.laneTargets[e]??1,t.connect(this.ctx.destination),this.laneNodes.set(e,t)),t}nodesFor(e){let t=this.clipNodes.get(e.id);if(!t){let n=this.ctx,r=n.createGain();if(r.gain.value=$r([e],this.selection)[e.id],r.connect(this.laneNode(e.lane)),t={gain:r,seekedAt:-1/0},this.media.get(Kr(e))?.streamed){let i=this.opts.createMedia(this.opts.url(e.path));i.preload=`auto`,t.el=i,t.elSource=n.createMediaElementSource(i),t.elSource.connect(r)}this.clipNodes.set(e.id,t)}return t}dropClip(e){let t=this.voices.get(e);t&&(this.stopSource(t),this.voices.delete(e));let n=this.clipNodes.get(e);n&&(n.elSource?.disconnect(),n.el&&(n.el.pause(),n.el.removeAttribute(`src`),n.el.load()),n.gain.disconnect(),this.clipNodes.delete(e))}ramp(e,t){let n=this.ctx.currentTime,r=e;typeof r.cancelAndHoldAtTime==`function`?r.cancelAndHoldAtTime(n):(e.cancelScheduledValues(n),e.setValueAtTime(e.value,n)),e.linearRampToValueAtTime(t,n+ao)}startLoop(){this.frame===null&&(this.frame=this.opts.raf(this.tick))}stopLoop(){this.frame!==null&&this.opts.caf(this.frame),this.frame=null}tick=()=>{if(this.frame=null,!this._playing)return;let e=this.length;if(e<=0){if(this.clips.some(e=>this.loads.has(Kr(e))&&!this.media.has(Kr(e)))){this.frame=this.opts.raf(this.tick);return}this.pause();return}let t=this.time;this.syncStreams(this.rawClock());for(let e of this.tickListeners)_o(()=>e(t));if(t>=e){this.pause();for(let e of this.endedListeners)_o(e);return}this._playing&&this.frame===null&&(this.frame=this.opts.raf(this.tick))};emitChange(){for(let e of this.changeListeners)_o(e)}};function _o(e){try{e()}catch(e){console.error(e)}}var vo=new class{el=null;current={path:null,playing:!1};by=null;failed=!1;listeners=new Set;make;url;constructor(e,t){this.make=e,this.url=t}state(){return this.current}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}async toggle(e,t){if(this.current.playing&&this.current.path===e)return this.stop();let n=this.element();n.pause(),(this.current.path!==e||this.failed)&&(n.src=this.url(e)),this.failed=!1,this.by=t??null,n.currentTime=0,pi(this,()=>this.stop()),this.set({path:e,playing:!0});try{await n.play()}catch(t){if(this.current.path===e&&this.current.playing)throw mi(this),this.failed=!0,this.set({path:e,playing:!1}),t}}stopIf(e){this.current.playing&&this.by===e&&this.stop()}stop(){this.el?.pause(),mi(this),this.current.playing&&this.set({...this.current,playing:!1})}element(){if(!this.el){let e=this.make();e.addEventListener(`ended`,()=>{mi(this),this.set({...this.current,playing:!1})}),this.el=e}return this.el}set(e){this.current=e;for(let t of this.listeners)t(e)}}(()=>new Audio,Nr),yo=e=>e.map(e=>[e.id,e.lane,e.path,e.rev??``,e.offset,e.duration].join(`\0`)).join(``);function bo(e,t=null){let n=X(null);n.current||=new go;let r=n.current,i=X(!0),[a,o]=q(!1),[s,c]=q(0),[l,u]=q({});return J(()=>{i.current=!0;let e=r.onChange(()=>{o(r.playing),c(r.length)});return()=>{i.current=!1,e(),r.dispose(),n.current===r&&(n.current=null)}},[r]),J(()=>{r.setClips(e);let t=new Map(e.map(e=>[Kr(e),e]));u(e=>{let n=Object.fromEntries(Object.entries(e).filter(([e])=>t.has(e)));return Object.keys(n).length===Object.keys(e).length?e:n});for(let[e,n]of t)r.load(n.path,n.rev).then(t=>i.current&&u(n=>n[e]===t?n:{...n,[e]:t}),t=>{i.current&&t.name!==`AbortError`&&u(t=>({...t,[e]:`error`}))})},[r,yo(e)]),J(()=>{r.setVideoDuration(t)},[r,t]),{engine:r,playing:a,length:s,media:l}}function xo(e){return e.map((e,t)=>({c:e,i:t})).sort((e,t)=>e.c.t-t.c.t||e.i-t.i).map(e=>e.c)}function So(e){return e.name.trim()||`Untitled cue`}function Co(e){return`${So(e)} at ${W(e.t)}`}function wo(e,t){return`cue ${e} of ${t}`}function To(e){let t=new Map;for(let n of xo(e)){let e=So(n),r=t.get(e);r||(r={name:e,cues:[],file:null,moreFiles:0},t.set(e,r)),r.cues.push(n)}for(let e of t.values()){let t=[...new Set(e.cues.flatMap(e=>e.file?[e.file]:[]))];e.file=t[0]??null,e.moreFiles=Math.max(0,t.length-1)}return[...t.values()]}function Eo(e,t,n){return n<=0?null:e===`ArrowLeft`?Math.max(0,t-1):e===`ArrowRight`?Math.min(n-1,t+1):e===`Home`?0:e===`End`?n-1:null}function Do(e){return e.split(/[\\/]/).filter(Boolean).pop()??e}function Oo(e,t){return`${((t>0?Math.min(1,Math.max(0,e/t)):0)*100).toFixed(3)}%`}function ko(e,t){return`clamp(5px, ${Oo(e,t)}, calc(100% - 5px))`}function Ao(e){let t=new Map;return e.map(e=>{let n=(t.get(e.id)??0)+1;return t.set(e.id,n),n===1?e.id:`${e.id}#${n}`})}function jo(e,t,n){let r=e.left+e.width/2-t.width/2,i=Math.max(16,Math.min(r,n.width-16-t.width)),a=e.top+e.height+8,o=a+t.height<=n.height-16?a:Math.max(16,e.top-8-t.height);return{left:Math.round(i),top:Math.round(o)}}var Mo=`cue-card`;function No(){let[e,t]=q(null);return{shown:e,api:{shown:e?.cue.key??null,show:(e,n)=>t(t=>t&&t.anchor===e&&t.cue.key===n.key?t:{anchor:e,cue:n}),hide:()=>t(null)}}}function Po(e,t){return{onPointerEnter:n=>e.show(n.currentTarget,t),onPointerLeave:()=>e.hide()}}function Fo({shown:e,onHide:t}){let n=X(null),[r,i]=q(null);if(Y(()=>{if(i(null),!e)return;let t=()=>{let t=n.current;if(!t)return;let r=e.anchor.getBoundingClientRect(),a=jo({left:r.left,top:r.top,width:r.width,height:r.height},{width:t.offsetWidth,height:t.offsetHeight},{width:document.documentElement.clientWidth,height:document.documentElement.clientHeight});i(e=>e&&e.left===a.left&&e.top===a.top?e:a)};return t(),window.addEventListener(`scroll`,t,!0),window.addEventListener(`resize`,t),()=>{window.removeEventListener(`scroll`,t,!0),window.removeEventListener(`resize`,t)}},[e]),Y(()=>{e&&!e.anchor.isConnected&&t()}),!e)return null;let a=e.cue;return Q(`div`,{ref:n,id:Mo,class:`cuecard`,role:`tooltip`,style:r?{left:`${r.left}px`,top:`${r.top}px`}:{left:`0px`,top:`0px`,visibility:`hidden`},children:[Q(`b`,{children:a.name}),Q(`span`,{class:`m`,children:[W(a.t),` · `,wo(a.n,a.of)]}),a.file!==null&&Q(`span`,{class:`f`,style:{color:a.color},children:a.file})]})}function Io(e,t,n){if(e.key===`Escape`){n.shown!==null&&(e.preventDefault(),e.stopPropagation(),n.hide());return}if(e.metaKey||e.ctrlKey||e.altKey)return;let r=e.currentTarget,i=[...r.parentElement?.querySelectorAll(`:scope > ${t}`)??[]],a=Eo(e.key,i.indexOf(r),i.length);a!==null&&(e.preventDefault(),e.stopPropagation(),i[a].focus())}function Lo(){let[e,t]=q(vo.state());return J(()=>vo.subscribe(t),[]),e}function Ro({id:e,name:t,cues:n,length:r,color:i,card:a,onSeek:o,toast:s}){let c=xo(n),l=new Map(c.map((e,t)=>[e,t+1])),u=To(n),[d,f]=q({}),p=Lo();J(()=>()=>vo.stopIf(e),[e]);let m=async t=>{try{await vo.toggle(t,e)}catch{s(`Couldn't play ${Do(t)}`)}};return Q(`div`,{class:`clayers`,id:e,role:`group`,"aria-label":`Layers for ${t}`,style:`--lane: ${i}`,children:u.map(t=>{let n=Math.min(d[t.name]??0,t.cues.length-1),s=t.file,u=s!==null&&p.playing&&p.path===s;return Q(`div`,{class:`clayer`,"data-layer":t.name,children:[Q(`div`,{class:`clname`,children:[Q(`span`,{children:t.name}),Q(`em`,{children:[`×`,t.cues.length]})]}),Q(`div`,{class:`cltrack`,children:[t.cues.map((s,u)=>{let d={key:`l:${e}:${s.id}`,name:t.name,t:s.t,n:l.get(s)??u+1,of:c.length,file:s.file??null,color:i},p=a.shown===d.key;return Q(`button`,{type:`button`,class:`ltick${p?` hot`:``}`,tabIndex:u===n?0:-1,style:{left:ko(s.t,r)},"aria-label":Co(s),"aria-describedby":p?Mo:void 0,...Po(a,d),onFocus:e=>{f(e=>e[t.name]===u?e:{...e,[t.name]:u}),a.show(e.currentTarget,d)},onBlur:()=>a.hide(),onKeyDown:e=>Io(e,`button.ltick`,a),onClick:()=>o(s.t,s.id)},s.id)}),Q(`div`,{class:`playhead`})]}),Q(`div`,{class:`clfile`,children:[s!==null&&Q(`button`,{type:`button`,"aria-pressed":u,"aria-label":`Play ${s}`,onClick:()=>void m(s),children:[Q($,{name:u?`pause`:`play`}),Q(`span`,{children:Do(s)})]}),t.moreFiles>0&&Q(`small`,{children:[`+`,t.moreFiles]})]})]},t.name)})})}var zo=0;function Bo(){return zo}var Vo=3,Ho=2;function Uo({segments:e,length:t,color:n}){let r=X(null),[i,a]=q({w:0,h:0,dpr:1});J(()=>{let e=r.current;if(!e)return;let t=()=>{let t=e.getBoundingClientRect(),n=window.devicePixelRatio||1;a(e=>e.w===t.width&&e.h===t.height&&e.dpr===n?e:{w:t.width,h:t.height,dpr:n})};t();let n=new ResizeObserver(t);return n.observe(e),()=>n.disconnect()},[]);let o=[i,t,n];for(let t of e)o.push(t.offset,t.duration,t.peaks);return J(()=>{let a=r.current;if(!a||i.w<=0||i.h<=0)return;zo++,a.width=Math.round(i.w*i.dpr),a.height=Math.round(i.h*i.dpr);let o=a.getContext(`2d`);if(!o||(o.setTransform(i.dpr,0,0,i.dpr,0,0),o.clearRect(0,0,i.w,i.h),!(t>0)))return;o.fillStyle=n;let s=Math.floor(i.w/Vo),c=t*Vo/i.w;for(let t=0;t<s;t++){let n=t*c,r=n+c,a=-1;for(let t of e){if(!(t.duration>0)||r<=t.offset||n>=t.offset+t.duration)continue;if(!t.peaks||t.peaks.length===0){a=Math.max(a,.04);continue}let e=t.peaks.length,i=Math.max(0,Math.floor((n-t.offset)/t.duration*e)),o=Math.min(e,Math.max(i+1,Math.ceil((r-t.offset)/t.duration*e)));for(let e=i;e<o;e++)a=Math.max(a,t.peaks[e])}if(a<0)continue;let s=Math.max(1.5,Math.min(1,a)*i.h*.92);o.globalAlpha=.9,o.fillRect(t*Vo,(i.h-s)/2,Ho,s)}},o),Q(`canvas`,{ref:r,class:`wave`,"aria-hidden":`true`})}function Wo(e){let t={},n=e=>e!==null&&e.scrollWidth>e.clientWidth;for(let r of e.querySelectorAll(`.lane[data-row]`)){let e=(n(r.querySelector(`[data-name]`))?`n`:``)+(n(r.querySelector(`[data-meta-text]`))?`m`:``);e&&(t[r.dataset.row]=e)}for(let r of e.querySelectorAll(`.rhead[data-heading]`))n(r.querySelector(`.rname`))&&(t[`h:${r.dataset.heading}`]=`h`);for(let r of e.querySelectorAll(`.fold[data-row]`))n(r.querySelector(`.flabel`))&&(t[`f:${r.dataset.row}`]=`f`);return t}var Go=(e,t)=>{let n=Object.keys(e);return n.length===Object.keys(t).length&&n.every(n=>e[n]===t[n])};function Ko({rows:e,length:t,media:n,selected:r,marks:i,range:a,onSelect:o,onSeek:s,toast:c}){let l=e=>`${t>0?e/t*100:0}%`,u=X(null),[d,f]=q({}),p=()=>{if(u.current){let e=Wo(u.current);f(t=>Go(t,e)?t:e)}},m=e.map(e=>{let t=e.clips.map(e=>n[Kr(e)]);return(t.some(e=>e!==void 0&&e!==`error`&&e.streamed)?`s`:``)+(t.some(e=>e===`error`)?`b`:``)});Y(p,[JSON.stringify(e.map((e,t)=>[e.key,e.name,e.meta??``,e.heading??``,e.fold?e.fold.text:null,e.missing??!1,m[t],+!!e.layers]))]),J(()=>(window.addEventListener(`resize`,p),document.fonts?.ready.then(p),()=>window.removeEventListener(`resize`,p)),[]);let{shown:h,api:g}=No(),[_,v]=q({});return Q(`div`,{class:`lanes`,ref:u,children:[e.map(e=>{let u=e.heading!==void 0&&Q(`div`,{class:`rhead`,"data-heading":e.key,"data-tip":d[`h:${e.key}`]?e.heading:void 0,children:[Q(`span`,{class:`rname`,children:e.heading}),e.tag&&Q(`span`,{class:`rtag`,children:e.tag})]});if(e.fold){let t=e.fold;return Q(S,{children:[u,Q(`button`,{type:`button`,class:`fold`,"data-row":e.key,"data-tip":d[`f:${e.key}`]?t.text:void 0,"aria-expanded":t.open,"aria-description":t.dot?`Open notes`:void 0,onClick:t.onToggle,children:[Q($,{name:`chev`}),Q(`span`,{class:`flabel`,children:t.label}),t.dot&&Q(`span`,{class:`fdot`,"data-dot":!0,"data-tip":`Open notes`})]})]},e.key)}let f=e.key===r,p=d[e.key]??``,m=xo(e.cues??[]),h=Ao(m),y=wt(m,t),b=Math.min(_[e.key]??0,Math.max(0,m.length-1)),x=(t,n)=>({key:`m:${e.key}:${h[n]}`,name:So(t),t:t.t,n:n+1,of:m.length,file:t.file??null,color:e.color}),C=e.clips.map(e=>n[Kr(e)]),w=C.some(e=>e!==void 0&&e!==`error`&&e.streamed),T=C.some(e=>e===`error`),E=e.clips.map((e,t)=>{let n=C[t],r=n!==void 0&&n!==`error`?n:null;return{offset:e.offset,duration:e.duration>0?e.duration:r?.duration??0,peaks:r?r.peaks:null}}),D=i[e.key]??[],O=Q(`button`,{type:`button`,class:`nm`,"data-player":!0,"aria-current":f?`true`:`false`,"aria-label":e.name,"aria-description":e.missing?typeof e.missing==`string`?e.missing:`Missing`:void 0,onClick:()=>o(e),children:[Q(`b`,{"data-tip":p.includes(`n`)?e.name:void 0,children:[Q(`i`,{style:{background:e.color}}),Q(`span`,{"data-name":!0,children:e.name}),e.missing&&Q(ga,{tip:typeof e.missing==`string`?e.missing:void 0})]}),Q(`small`,{"data-meta":!0,"data-tip":p.includes(`m`)&&e.meta?e.meta:void 0,children:[T?Q(`span`,{class:`smk bad`,"data-tip":`This file won't play in a browser`,children:Q($,{name:`alert`})}):w?Q(`span`,{class:`smk`,"data-tip":`Long file: switching isn't sample-exact`,children:Q($,{name:`stream`})}):null,Q(`span`,{"data-meta-text":!0,children:e.meta??``})]})]});return Q(S,{children:[u,Q(`div`,{class:`lane`,"data-row":e.key,"aria-current":f?`true`:void 0,children:[e.layers?Q(`div`,{class:`nmc`,children:[Q(`button`,{type:`button`,class:`chev tip-start`,"aria-expanded":e.layers.open,"aria-controls":e.layers.open&&m.length>0?`cl-${e.key}`:void 0,"aria-label":`Layers for ${e.name}`,"aria-description":m.length===0?`No cues in this pass`:void 0,"data-tip":m.length===0?`No cues in this pass`:e.layers.open?`Hide the layers`:`Show the layers`,disabled:m.length===0,onClick:e.layers.onToggle,children:Q($,{name:`chev`})}),O]}):O,Q(`div`,{class:`track`,onClick:n=>{let r=n.currentTarget.getBoundingClientRect();s((n.clientX-r.left)/r.width*t,e)},children:[Q(Uo,{segments:E,length:t,color:e.color}),m.map((t,n)=>Q(`i`,{class:`cue-tick${g.shown===`m:${e.key}:${h[n]}`?` hot`:``}`,"aria-hidden":`true`,style:{left:l(t.t),color:e.color},...Po(g,x(t,n)),onClick:n=>{n.stopPropagation(),s(t.t,e,t.id)}},`t${h[n]}:${t.t}:${t.name}`)),m.map((t,n)=>{let r=x(t,n),i=g.shown===r.key;return Q(`button`,{type:`button`,class:`cue${i?` hot`:``}`,"data-cue":t.id,tabIndex:n===b?0:-1,"aria-label":Co(t),"aria-describedby":i?Mo:void 0,style:{left:l(t.t),color:e.color,maxWidth:`calc(${(y[n]*100).toFixed(3)}% - 8px)`},...Po(g,r),onFocus:t=>{v(t=>t[e.key]===n?t:{...t,[e.key]:n}),g.show(t.currentTarget,r)},onBlur:()=>g.hide(),onKeyDown:e=>Io(e,`button.cue`,g),onClick:n=>{n.stopPropagation(),s(t.t,e,t.id)},children:Q(`span`,{children:So(t)})},`c${h[n]}:${t.t}:${t.name}`)}),D.map(e=>e.tOut!==null&&Q(`div`,{class:`span ${e.status}`,"data-note":e.id,style:{left:l(e.t),width:l(e.tOut-e.t)}})),D.map(e=>Q(`div`,{class:`mk ${e.status}`,"data-note":e.id,style:{left:l(e.t)},title:e.text})),a.in!==null&&Q(`div`,{class:`span live`,style:{left:l(a.in),width:l((a.out??a.in+Math.max(.2,t/200))-a.in)}}),Q(`div`,{class:`playhead`})]}),Q(`div`,{class:`ctl`,children:[e.use&&Q(`button`,{type:`button`,class:`use`,"aria-pressed":e.use.inUse,"aria-label":`Use ${e.name}`,onClick:t=>{t.stopPropagation(),e.use.onUse()},children:e.use.inUse?Q(S,{children:[Q($,{name:`check`}),`In use`]}):`Use`}),e.use?.inUse&&e.use.onUnpick&&Q(`button`,{type:`button`,class:`btn ghost ib sm unpick`,"data-tip":`Unpick`,"aria-label":`Unpick ${e.name}`,onClick:t=>{t.stopPropagation(),e.use.onUnpick()},children:Q($,{name:`x`})}),e.controls]})]}),e.layers?.open&&m.length>0&&Q(Ro,{id:`cl-${e.key}`,name:e.name,cues:m,length:t,color:e.color,card:g,onSeek:(t,n)=>s(t,e,n),toast:c??(()=>void 0)})]},e.key)}),Q(Fo,{shown:h,onHide:g.hide})]})}var qo=[`ArrowLeft`,`ArrowRight`,`ArrowUp`,`ArrowDown`,`Home`,`End`];function Jo({label:e,width:t,height:n,value:r,onChange:i,lockedReason:a,name:o}){let s=Jn(t,n),c=xr();return Q(`div`,{class:`fscope`,role:`radiogroup`,"aria-label":o,onKeyDown:e=>{if(e.altKey||e.metaKey||e.ctrlKey||!qo.includes(e.key))return;e.preventDefault(),e.stopPropagation();let t=e.key===`Home`||e.key===`ArrowLeft`||e.key===`ArrowUp`?`this`:`all`;t===`all`&&a||(t!==r&&i(t),e.currentTarget.querySelector(`[data-scope="${t}"]`)?.focus())},children:[[{v:`this`,text:`This format`,disabled:!1},{v:`all`,text:`All formats`,disabled:a!==null}].map(t=>Q(`button`,{type:`button`,role:`radio`,"data-scope":t.v,"aria-checked":r===t.v,"aria-disabled":t.disabled?`true`:void 0,"aria-describedby":t.disabled?c:void 0,tabIndex:r===t.v?0:-1,"aria-label":t.v===`this`?`This format, ${e}`:`All formats`,class:t.disabled?`tip-wrap tip-below tip-end`:void 0,"data-tip":t.disabled?a:void 0,onClick:()=>{!t.disabled&&t.v!==r&&i(t.v)},children:[t.v===`this`&&Q(`span`,{class:`shape`,"aria-hidden":`true`,style:{width:`${s.width}px`,height:`${s.height}px`}}),t.text]},t.v)),a&&Q(`span`,{id:c,hidden:!0,children:a})]})}var Yo=[{kind:`rise`,label:`Rise`},{kind:`fall`,label:`Fall`},{kind:`louder`,label:`Louder`},{kind:`quieter`,label:`Quieter`}],Xo=e=>e.options.find(t=>t.value===e.value)?.full;function Zo({notes:e,version:t,placeholder:n,attachments:r,inputRef:i,toast:a,onAdd:o,onSeek:s,onChanged:c,onTextChange:l,on:u,scope:d,chips:f,marks:p,onLabel:m,fixedTimes:h,selectedId:g,formatTag:_,cardExtra:v,formatScope:y,listFooter:b}){let[x,S]=q(`all`),C=X(null),w=i??C,[T,E]=q(``),[D,O]=q(!1),k=e.filter(e=>e.status===`todo`).length,A=b?.(x)??null,j=e.map(e=>({n:e,at:h?{t:e.t,tOut:e.tOut,from:null}:ve(e,t)})).filter(({n:e})=>x===`all`||e.status===x).sort((e,t)=>(e.at.t??-1)-(t.at.t??-1)),M=async e=>{try{await Z.patch(`/api/notes/${e.id}`,{status:e.status===`done`?`todo`:`done`})}catch(e){a(`Couldn't update that note: ${e.message}`)}c()},N=async()=>{let e=T.trim();if(e&&!D){O(!0);try{await o(e),E(``),l?.(!1)}catch(e){a(`Couldn't add the note: ${e.message}`)}finally{O(!1)}}},P=e=>{E(e),l?.(!0);let t=w.current;t&&(t.value=e,t.focus(),t.setSelectionRange(e.length,e.length))};return Q(`aside`,{class:`panel side`,"aria-label":`Notes`,children:[Q(`div`,{class:`ph`,children:[Q(`h3`,{children:`Notes`}),Q(`span`,{class:`sp`}),Q(`div`,{class:`seg`,role:`group`,"aria-label":`Filter notes`,children:[`all`,`todo`,`done`].map(e=>Q(`button`,{"aria-pressed":x===e,onClick:()=>S(e),children:[e===`all`?`All`:e===`todo`?`To do`:`Done`,e===`todo`&&k>0&&Q(`span`,{class:`n`,children:k})]}))})]}),Q(`div`,{class:`list`,children:[j.length===0&&Q(`div`,{class:`none`,children:x===`all`?A?`None on this format.`:`No notes yet.`:`Nothing here.`}),j.map(({n:e,at:t})=>Q(`div`,{class:`note${e.status===`done`?` done`:``}`,"data-note":e.id,"aria-current":g===e.id?`true`:void 0,children:[Q(`button`,{class:`chk`,"aria-label":e.status===`done`?`Reopen`:`Mark done`,title:e.status===`done`?`Reopen`:`Mark done`,onClick:()=>void M(e),children:Q($,{name:`check`})}),Q(`div`,{class:`nt`,children:[Q(`button`,{class:`t`,onClick:()=>t.t!==null&&s?.(t.t,e),children:ye(t.t,t.tOut)}),m&&m(e)&&Q(`span`,{class:`on`,children:m(e)}),(()=>{let t=_?.(e)??null;return t&&Q(`span`,{class:`ftag${t===`All`?` all`:``}`,children:t})})(),t.from&&Q(`span`,{class:`from`,children:[`from `,t.from]})]}),gt(e.marks)&&Q(`div`,{class:`nmarks`,children:gt(e.marks)}),e.shot&&Q(`div`,{class:`shotref`,children:[`Shot `,We(e.shot.n),` · `,e.shot.name]}),Q(`div`,{class:`nx`,children:e.text}),e.grab&&Q(`div`,{class:`att`,children:Q(`img`,{class:`thumb`,src:Nr(e.grab),alt:`Frame grab`})}),e.reply&&Q(`div`,{class:`rp`,children:[Q($,{name:`reply`}),Q(`span`,{children:e.reply})]}),g===e.id&&v&&Q(`div`,{class:`nfmt`,children:v(e)})]},e.id)),A]}),Q(`div`,{class:`comp`,children:[(u||d)&&Q(`div`,{class:`row`,children:[u&&Q(`span`,{class:`onwrap`,"data-tip":Xo(u),children:[Q(`select`,{class:`sel onsel`,"aria-label":`Note on`,"data-tip":Xo(u),value:u.value??``,onChange:e=>{let t=e.target;u.onChange(t.value),t.blur()},children:xt(u.options).map(e=>e.group===void 0?e.options.map(e=>Q(`option`,{value:e.value,children:e.label})):Q(`optgroup`,{label:e.group,children:e.options.map(e=>Q(`option`,{value:e.value,children:e.label}))}))}),Q($,{name:`chev`})]}),Q(`span`,{class:`sp`}),d&&Q(`div`,{class:`seg`,role:`group`,"aria-label":`Scope`,children:ct(d.options).map(e=>Q(`button`,{type:`button`,"aria-pressed":d.value===e.value,onClick:()=>d.onChange(e.value),children:e.label}))})]}),f&&f.length>0&&!(p&&d?.value===`range`)&&Q(`div`,{class:`row`,role:`group`,"aria-label":`Start a note`,children:f.map(e=>Q(`button`,{type:`button`,class:`chip`,onClick:()=>P(`${e}: `),children:e}))}),p&&d?.value===`range`&&Q(`div`,{class:`row`,role:`group`,"aria-label":`Marks`,children:Yo.map(({kind:e,label:t})=>{let n=p.value.find(t=>t.kind===e);return Q(`span`,{class:`markc`,children:[Q(`button`,{type:`button`,class:`chip`,"aria-pressed":!!n,onClick:()=>p.onChange(_t(p.value,e)),children:t}),n?.db!==void 0&&Q(`span`,{class:`onwrap`,children:[Q(`select`,{class:`sel dbsel`,"aria-label":`${t} by`,value:String(n.db),onChange:t=>{let n=t.target;p.onChange(vt(p.value,e,Number(n.value))),n.blur()},children:dt.map(e=>Q(`option`,{value:String(e),children:[e,` dB`]}))}),Q($,{name:`chev`})]})]})})}),y&&Q(`div`,{class:`row`,children:Q(Jo,{name:`This note applies to`,label:y.label,width:y.width,height:y.height,value:y.value,onChange:y.onChange,lockedReason:y.lockedReason})}),r&&Q(`div`,{class:`row`,children:r}),Q(`div`,{class:`cbox`,children:[Q(`textarea`,{ref:w,class:`input`,rows:2,"aria-label":`New note`,placeholder:n,value:T,onInput:e=>{let t=e.target.value;E(t),l?.(t.trim()!==``)},onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),N()),e.key===`Escape`&&e.target.blur()}}),Q(`button`,{class:`btn primary ib sm send`,"data-tip":`Add note ↵`,"aria-label":`Add note`,onClick:()=>void N(),children:Q($,{name:`send`})})]}),y&&Q(`p`,{class:`fhint`,children:y.hint})]})]})}var Qo=typeof location>`u`?{test:!1,streamOver:!1}:Rt(location.search);Qo.streamOver&&si(1);var $o=Qo.test?{engine:null,inspect(){return this.engine?this.engine.inspect():null},renders:0,draws:Bo,liveContexts:lo,sample:()=>vo.state(),clips:[],heard(){let e=this.engine?.inspect();return e?this.clips.filter(t=>(e.gains[t.id]??1)*(e.lanes[t.lane]??1)>0).map(e=>({id:e.id,lane:e.lane,path:e.path,offset:e.offset})):[]}}:null;$o&&(window.__rushesAudio=$o);var es=e=>e instanceof HTMLElement&&(e.isContentEditable||/^(INPUT|TEXTAREA|SELECT)$/.test(e.tagName)),ts={in:null,out:null},ns=[`point`,`range`,`whole`];function rs(e){let{stage:t,title:n,headerExtra:r,belowLanes:i,rows:a,preview:o,fps:s,notes:c,onOptions:l,noteRow:u,onLabel:d,toast:f,onChanged:p,onPendingChange:m,listen:h}=e;$o&&$o.renders++;let g=e.clips??is(a.flatMap(e=>e.clips)),[_,v]=q(null),[y,b]=q(16/9);J(()=>{v(null),b(16/9)},[o?.file]);let{engine:x,playing:C,length:w,media:T}=bo(g,o?o.duration??_:null),[E,D]=q(null),[O,k]=q(null),A=X(null),j=a.some(e=>e.key===E)?E:null;Y(()=>{E!==null&&j===null&&(D(null),A.current!==null&&O===A.current&&k(null),A.current=null)},[j]);let[M,N]=q(ts),[P,F]=q(e.defaultScope??`point`),[I,L]=q([]),[ee,te]=q(!1),R=(e.scopes??ns).includes(`range`),ne=e.defaultScope??`point`,re=`${e.film===void 0?o?.video??``:e.film??``}/${o?.version??``}`,ie=X(re);Y(()=>{ie.current!==re&&(ie.current=re,F(ne))},[re]);let ae=lt({range:M,marks:I,hasText:ee});Y(()=>{m?.(ae)},[ae]),J(()=>()=>m?.(!1),[]);let oe=e=>h?h(e):{select:jt(a,e),gains:{}},z=X({select:{},gains:{}}),B=e=>{let t=z.current;for(let[n,r]of Object.entries(e.select))(!(n in t.select)||t.select[n]!==r)&&x.selectVariant(n,r);for(let[n,r]of Object.entries(e.gains))t.gains[n]!==r&&x.setLaneGain(n,r);z.current={select:{...t.select,...e.select},gains:{...t.gains,...e.gains}}},se=oe(j);Y(()=>B(se),[x,JSON.stringify(se)]);let ce=e.defaultOn??a.find(e=>e.picked)?.on??a[0]?.on??l[0]?.value??null,le=l.some(e=>e.value===O)?O:ce,ue=l.find(e=>e.value===le)??null,V=X(null),de=X([]),fe=X(null),H=X(null),pe=X(null),U=X(!1),me=X(0),he=X(null),ve=e=>{if(P===`whole`)return t===`voice`?`Note on the whole read`:`Note on the whole track`;if(R){if(M.in!==null&&M.out===null)return`Set an Out point`;if(M.in!==null&&M.out!==null)return`Note on ${ye(M.in,M.out)}`;if(P===`range`)return`Set In and Out`}return`Note at ${W(ue?.t??ge(e,s))}`},be=e=>{let t=x.length,n=`${t>0?Math.min(e,t)/t*100:0}%`;for(let e of de.current)e.style.left=n;let r=W(e);fe.current&&(fe.current.textContent=r),H.current&&(H.current.textContent=r),he.current&&(he.current.placeholder=ve(e));let i=pe.current;i&&i.readyState>=1&&!i.seeking&&ti(i.currentTime,e,s)&&(i.currentTime=Math.min(e,Number.isFinite(i.duration)?i.duration:e)),i&&x.playing&&!U.current&&e>me.current&&(U.current=!0,i.play().catch(()=>void 0)),me.current=e},xe=X(be);xe.current=be,Y(()=>{de.current=V.current?[...V.current.querySelectorAll(`.playhead`)]:[],be(x.time)}),J(()=>x.subscribe(e=>xe.current(e)),[x]),J(()=>{let e=pe.current;e&&(U.current=!1,C||(e.pause(),xe.current(x.time)))},[C,o?.file]);let Se=()=>x.playing?x.pause():x.play(),Ce=e=>{x.pause(),x.seek(_e(x.time,s,e,x.length))},we=()=>{R&&(N({in:ge(x.time,s),out:null}),F(`range`))},Te=()=>{if(!R)return;let e=ge(x.time,s),t=M.in??0;if(e<=t)return f(`Out has to come after In`);N({in:t,out:e}),F(`range`)},Ee=()=>{N(ts),L([]),P===`range`&&F(ne)},G=e=>{(e!==`range`||R)&&(F(e),e!==`range`&&(N(ts),L([])))},De=t=>{D(t.key),B(oe(t.key)),A.current=t.on??null,t.on&&k(t.on),e.onSelect?.(t)},Oe=X(()=>void 0);Oe.current=e=>{if(es(e.target)||e.metaKey||e.ctrlKey||e.altKey)return;let t=e.key.toLowerCase();if(e.key===` `){if(Lt(e.target))return;e.preventDefault(),Se()}else e.key===`ArrowLeft`?(e.preventDefault(),Ce(e.shiftKey?-10:-1)):e.key===`ArrowRight`?(e.preventDefault(),Ce(e.shiftKey?10:1)):t===`i`?we():t===`o`?Te():t===`n`&&(e.preventDefault(),he.current?.focus())},Y(()=>{let e=e=>Oe.current(e);return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[]),Y(()=>{$o&&($o.clips=g)}),J(()=>{if($o)return $o.engine=x,()=>{$o.engine===x&&($o.engine=null)}},[x]);let ke=async e=>{let n=null,r=null;if(P===`range`){if(M.in===null||M.out===null)throw Error(`set In and Out for a range`);n=M.in,r=M.out}else P===`point`&&(n=ue?.t??ge(x.time,s));await Z.post(`/api/notes`,{stage:t,video:o?.video??null,version:o?.version??null,on:ue?.on??null,scope:P,t:n,tOut:r,text:e,marks:P===`range`?I:[]}),N(ts),L([]),F(ne),p()},Ae=o?.version??null,je={};for(let e of c){if(e.scope===`whole`||e.t===null)continue;let t=u(e);for(let n of t===null?[]:typeof t==`string`?[t]:t)(je[n]??=[]).push({id:e.id,t:e.t,tOut:R?e.tOut:null,status:e.status,text:e.text})}let Me=M.in===null?null:M.out===null?`${W(M.in)} →`:ye(M.in,M.out);return Q(`div`,{class:`astage`,ref:V,children:[Q(`div`,{class:`stack`,children:[Q(`div`,{class:`ahead`,children:[Q(`h2`,{children:n}),r,Q(`span`,{class:`sp`})]}),Q(`div`,{class:`bar`,children:[Q(`button`,{class:`btn ghost ib`,"data-tip":`Back one frame ←`,"aria-label":`Back one frame`,onClick:()=>Ce(-1),children:Q($,{name:`prev`})}),Q(`button`,{class:`btn ib`,"data-tip":`Play Space`,"aria-label":C?`Pause`:`Play`,onClick:Se,children:Q($,{name:C?`pause`:`play`})}),Q(`button`,{class:`btn ghost ib`,"data-tip":`Forward one frame →`,"aria-label":`Forward one frame`,onClick:()=>Ce(1),children:Q($,{name:`next`})}),Q(`span`,{class:`tc`,"aria-label":`Timecode`,children:[Q(`span`,{ref:fe,children:W(x.time)}),Q(`small`,{children:[`/ `,W(w)]})]}),Q(`span`,{class:`sp`}),Me&&Q(`span`,{class:`chipx`,children:[Q(`span`,{class:`mono`,children:Me}),Q(`button`,{"aria-label":`Clear range`,onClick:Ee,children:Q($,{name:`x`})})]}),R&&Q(S,{children:[Q(`button`,{class:`btn ghost ib`,"data-tip":`Set in I`,"aria-label":`Set in point`,onClick:we,children:Q($,{name:`in`})}),Q(`button`,{class:`btn ghost ib`,"data-tip":`Set out O`,"aria-label":`Set out point`,onClick:Te,children:Q($,{name:`out`})})]})]}),Q(Ko,{rows:a,length:w,media:T,selected:j,marks:je,range:M,onSelect:De,onSeek:(e,t,n)=>{De(t);let r=n===void 0?void 0:l.find(e=>e.value===`c:${t.key}:${n}`);r&&(A.current=r.value,k(r.value)),x.seek(e)},toast:f}),i]}),Q(`div`,{class:`acol`,children:[Q(`div`,{class:`pv`,children:Q(`div`,{class:`frame`,style:{aspectRatio:String(y)},children:[o?Q(`video`,{ref:pe,src:Nr(o.file),muted:!0,playsInline:!0,preload:`auto`,"aria-label":`Picture preview`,onLoadedMetadata:e=>{let t=e.target;Number.isFinite(t.duration)&&v(t.duration),t.videoWidth&&t.videoHeight&&b(t.videoWidth/t.videoHeight),xe.current(x.time)},onSeeked:()=>xe.current(x.time)}):Q(`div`,{class:`pvempty`,"aria-label":`No cut yet`,children:Q($,{name:`film`})}),Q(`div`,{class:`tcover`,ref:H,children:W(x.time)})]})}),Q(Zo,{notes:c,version:Ae,placeholder:ve(x.time),inputRef:he,toast:f,onAdd:ke,onChanged:p,onTextChange:te,fixedTimes:!0,onSeek:e=>x.seek(e),on:{options:l,value:le,onChange:k},scope:{value:P,onChange:G,options:e.scopes},chips:(e.chipsFor??(()=>ut[t]))(P),marks:e.marks===!1?void 0:{value:I,onChange:L},onLabel:d})]})]})}function is(e){let t=new Set;return e.filter(e=>!t.has(e.id)&&(t.add(e.id),!0))}var as={vo:`#4FD1C5`,music:`#A78BFA`,sfx:`#FB923C`},os={vo:`Voiceover`,music:`Music`,sfx:`Sound effects`},ss={vo:{muted:!1,solo:!1},music:{muted:!1,solo:!1},sfx:{muted:!1,solo:!1}};function cs({state:e,assets:t,video:n,toast:r,onChanged:i,onPendingChange:a}){let o=e=>t.find(t=>t.path===e),s=e=>{let t=o(e);return t?qr(t):void 0},c=e=>o(e)?.missing===!0,l=e.picks.lanes,u=Ut(Vt(e.project.lanes,l)),d=u&&!c(u.file)?[{id:u.key,lane:`vo`,path:u.file,offset:0,duration:0,rev:s(u.file)}]:[],f=u?c(u.file):!1,p={music:bt(e.project.lanes,`music`),sfx:bt(e.project.lanes,`sfx`)},m=e=>e.filter(e=>l[e.lane]===e.variant),h={music:m(p.music),sfx:m(p.sfx)},g={music:h.music.filter(e=>!c(e.file)),sfx:h.sfx.filter(e=>!c(e.file))},_=e=>g[e].map(t=>({id:t.key,lane:e,path:t.file,offset:0,duration:0,rev:s(t.file)})),v={vo:d,music:_(`music`),sfx:_(`sfx`)},y={vo:d.length>0,music:v.music.length>0,sfx:v.sfx.length>0},b={variants:p,heard:{vo:y.vo,music:g.music,sfx:g.sfx}},x=sn(b),[C,w]=q(ss),T=(e,t)=>w(n=>({...n,[e]:{...n[e],[t]:!n[e][t]}})),E=e.picks.levels,D=e=>E[$t[e]]??0,[O,k]=q(()=>({vo:D(`vo`),music:D(`music`),sfx:D(`sfx`)})),A=X({});J(()=>{k(e=>{let t=!1,n={...e};for(let e of Qt){if(A.current[e]!==void 0)continue;let r=D(e);n[e]!==r&&(n[e]=r,t=!0)}return t?n:e})},[JSON.stringify(E)]);let j=e=>{let t=A.current;for(let n of Qt){let r=t[n];r&&(window.clearTimeout(r.id),delete t[n],r.send(e))}};J(()=>{let e=()=>j(!0),t=()=>{document.visibilityState===`hidden`&&j(!0)};return window.addEventListener(`pagehide`,e),document.addEventListener(`visibilitychange`,t),()=>{window.removeEventListener(`pagehide`,e),document.removeEventListener(`visibilitychange`,t),j(!1)}},[]);let M=(e,t)=>{let n=ln(t);k(t=>t[e]===n?t:{...t,[e]:n});let a=A.current;a[e]!==void 0&&window.clearTimeout(a[e].id);let o=(t=!1)=>void Z.put(`/api/picks`,{levels:{[$t[e]]:n===0?null:n}},{keepalive:t}).then(i,e=>{r(e instanceof kr?e.message:`Couldn't save the level`)});a[e]={id:window.setTimeout(()=>{delete a[e],o()},300),send:o}},N=Zr(Qt.map(e=>({id:e,...C[e],level:O[e]}))),P=e=>e===`vo`?u?`${u.laneName} · ${u.name}`:null:h[e].map(e=>e.name).join(` · `)||null,F=e=>y[e]?null:e===`vo`?f?`Missing`:`Nothing picked`:h[e].length>0?`Missing`:`Nothing picked`,I=Qt.map(e=>({key:e,name:os[e],meta:P(e),color:as[e],clips:v[e],cues:e===`sfx`?g.sfx.flatMap(e=>e.cues):void 0,on:x.find(t=>t.row===e)?.value,missing:F(e)??void 0,controls:Q(S,{children:[Q(`button`,{type:`button`,class:`ms`,"aria-pressed":C[e].muted,"aria-label":`Mute ${os[e]}`,"data-tip":`Mute`,onClick:()=>T(e,`muted`),children:`M`}),Q(`button`,{type:`button`,class:`ms`,"aria-pressed":C[e].solo,"aria-label":`Solo ${os[e]}`,"data-tip":`Solo`,onClick:()=>T(e,`solo`),children:`S`}),Q(`label`,{class:`level`,"data-tip":`Level for ${os[e]}. Double-click to reset.`,children:[Q(`input`,{type:`range`,min:-24,max:6,step:cn,value:O[e],"aria-label":`${os[e]} level`,"aria-valuetext":`${un(O[e])} dB`,onInput:t=>M(e,Number(t.target.value)),onDblClick:()=>M(e,0)}),Q(`span`,{class:`db mono`,children:[un(O[e]),` dB`]})]})]})})),L=en(y,N),ee=JSON.stringify({want:L,levels:E,clips:Qt.map(e=>v[e].map(e=>[e.path,e.rev??``,e.offset]))}),[te,R]=q({kind:`waiting`}),[ne,re]=q(!1),[ie,ae]=q(0),oe=te.kind===`timeout`||te.kind===`error`,z=X(0);J(()=>{let e=++z.current;if(L.length===0){R({kind:`empty`}),re(!1);return}R(e=>e.kind===`empty`||e.kind===`timeout`||e.kind===`error`?{kind:`waiting`}:e),re(!0);let t=window.setTimeout(()=>{Z.post(`/api/mix/loudness`,{lanes:L}).then(t=>{e===z.current&&R({kind:`result`,result:t})},t=>{e===z.current&&R({kind:t instanceof kr&&t.status===504?`timeout`:`error`})}).finally(()=>{e===z.current&&re(!1)})},500);return()=>window.clearTimeout(t)},[ee,ie]),J(()=>()=>void++z.current,[]);let B=Q(`div`,{class:oe?`meter retry`:`meter`,role:`group`,"aria-label":`Loudness`,"aria-busy":ne,onClick:oe?()=>ae(e=>e+1):void 0,children:[pn(te).map(e=>Q(`div`,{"data-cell":e.id,children:[Q(`b`,{"data-value":!0,"data-tip":e.tip??void 0,"aria-description":e.tip??void 0,children:e.value}),Q(`span`,{children:e.label})]})),ne&&Q(`span`,{class:`smk measuring`,"data-measuring":!0,"data-tip":`Measuring`,"aria-label":`Measuring`,children:Q($,{name:`gauge`})}),oe&&!ne&&Q(`button`,{type:`button`,class:`btn ghost ib`,"data-tip":`Measure again`,"aria-label":`Measure again`,children:Q($,{name:`gauge`})})]}),se=e.notes.notes.filter(e=>e.stage===`mix`),ce=Ce(n??void 0),le=n&&ce?{video:n.id,version:ce.id,file:ce.file,duration:ce.duration}:null,ue=e.project.fps||30;return Q(rs,{stage:`mix`,title:Te.mix,belowLanes:B,rows:I,preview:le,film:n?.id??null,fps:ue,notes:se,onOptions:x,defaultOn:`mix`,listen:()=>({select:{},gains:N}),noteRow:e=>rn(b,e.on),onLabel:e=>on(b,e.on),toast:r,onChanged:i,onPendingChange:a})}function ls({notes:e,version:t,viewsHere:n,ownViews:r,onShow:i,onRestore:a}){let[o,s]=q(!1);return e.length===0?null:Q(`div`,{class:`otherfmts`,children:[Q(`button`,{type:`button`,class:`otherrow`,"aria-expanded":o,onClick:()=>s(e=>!e),children:[Q(`span`,{children:[`Other formats (`,e.length,`)`]}),Q(`span`,{class:`sp`}),Q(`span`,{class:`act`,"aria-hidden":`true`,children:o?`Hide`:`Show`})]}),o&&e.map(e=>{let o=ve(e,t),s=ir(e,n,r(e));return Q(`div`,{class:`note ro${e.status===`done`?` done`:``}`,"data-note":e.id,children:[Q(`span`,{"aria-hidden":`true`}),Q(`div`,{class:`nt`,children:[Q(`span`,{class:`t mono`,children:ye(o.t,o.tOut)}),Q(`span`,{class:`ftag`,children:e.format?fe(e.format):`All`}),o.from&&Q(`span`,{class:`from`,children:[`from `,o.from]})]}),Q(`div`,{class:`nx`,children:e.text}),s?.kind===`show`&&Q(`div`,{class:`nact`,children:Q(`button`,{type:`button`,class:`flink`,onClick:()=>i(s.id,e),children:[`Show on `,s.label]})}),s?.kind===`restore`&&Q(`div`,{class:`nact`,children:Q(`button`,{type:`button`,class:`flink`,onClick:()=>a(e),children:`Restore to all formats`})})]},e.id)})]})}var us=6e3,ds=e=>/[.!?]$/.test(e)?e:`${e}.`;function fs({video:e,version:t,ffmpeg:n,autoProxy:r,job:i,broken:a,duration:o,toast:s,onChanged:c,noteProxyJob:l,hidden:u=!1}){let[d,f]=q(!1),[p,m]=q(!1),[h,g]=q(r);J(()=>g(r),[r]);let _=X(new Set);i?.state===`running`&&_.current.add(i.job);let[v,y]=q(null),b=bn({ffmpeg:n,need:t.proxyNeed,broken:a,hasProxy:!!t.proxy,job:i,starting:d,watched:!!i&&_.current.has(i.job)}),x=b===`done`&&i?i.job:null;if(J(()=>{if(!x)return;let e=window.setTimeout(()=>y(x),us);return()=>clearTimeout(e)},[x]),!n)return null;let C=x&&v===x?`none`:b,w=xn(t.proxyNeed,a),T=i?.state===`running`?i.pct:i?.state===`done`?100:0,E=i?.state===`running`?i:null,D=async()=>{if(!d){f(!0);try{let{job:n}=await Z.post(`/api/videos/${encodeURIComponent(e.id)}/versions/${encodeURIComponent(t.id)}/proxy`);_.current.add(n.id),l(n)}catch(e){s(e.message)}finally{f(!1)}}},O=async()=>{if(E&&!p){m(!0);try{let{job:e}=await Z.del(`/api/proxy-jobs/${encodeURIComponent(E.job)}`);l(e)}catch(e){e instanceof kr&&e.code===`not_found`?c():s(e.message)}finally{m(!1)}}},k=async e=>{g(e);try{await Z.put(`/api/project/settings`,{autoProxy:e}),c()}catch(t){g(!e),s(t.message)}},A=Q(`label`,{class:`check`,children:[Q(`input`,{type:`checkbox`,checked:h,onChange:e=>{let t=e.currentTarget;t.blur(),k(t.checked)}}),`Create proxies for new cuts like this automatically`]});return Q(`div`,{class:`proxybar${C===`none`?` quiet`:``}`,hidden:u,children:Q(`div`,{class:`proxyrow${C===`none`?``:` ${C}`}`,children:[C===`offer`&&w&&Q(S,{children:[Q(`span`,{class:`why`,children:[Q(`b`,{children:`This cut may play slowly.`}),` `,ds(w)]}),Q(`button`,{class:`btn primary tip-wrap tip-end`,"aria-label":`Create proxy`,"data-tip":hn(t.duration??o),onClick:()=>void D(),children:`Create proxy`})]}),C===`working`&&Q(S,{children:[Q(`span`,{children:`Creating proxy`}),Q(`div`,{class:`pbar`,role:`progressbar`,"aria-label":`Proxy progress`,"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":T,children:Q(`i`,{style:{width:`${T}%`}})}),Q(`span`,{class:`mono`,children:[T,`%`]}),Q(`button`,{class:`btn`,"aria-disabled":!E||p,onClick:()=>void O(),children:`Cancel`})]}),C===`done`&&t.proxy&&Q(S,{children:[Q(`span`,{class:`ok`,children:`✓ Proxy ready`}),Q(`span`,{class:`why`,children:[`Saved to `,Q(`span`,{class:`mono`,children:t.proxy.file}),` (`,Ke(t.proxy.bytes),`).`]}),Q(`button`,{class:`btn ghost ib`,"aria-label":`Dismiss`,"data-tip":`Dismiss`,onClick:()=>y(x),children:Q($,{name:`x`})})]}),A]})})}var ps=2e3,ms=8e3,hs={kind:`none`},gs={kind:`pending`};async function _s(e,t,n){let r;try{r=await t.fetch(e.peaksUrl,{signal:n})}catch(e){if(n.aborted)throw e;return gs}if(r.status===202)return gs;if(r.status===501)return vs(e,t,n);if(r.status!==200)return hs;try{let e=await r.json(),t=e.peaks;return!Array.isArray(t)||t.length===0||typeof e.duration!=`number`||!(e.duration>0)||!t.every(e=>typeof e==`number`&&Number.isFinite(e))?hs:{kind:`wave`,wave:{peaks:Float32Array.from(t),duration:e.duration}}}catch(e){if(n.aborted)throw e;return hs}}async function vs(e,t,n){if(e.size===null||!(e.size<1e8))return hs;try{let r=await e.duration();if(n.aborted)throw new DOMException(`aborted`,`AbortError`);if(r===null||!(r>0)||r>900)return hs;let i=await t.fetch(e.mediaUrl,{signal:n});if(!i.ok)return hs;let{channels:a,duration:o}=await t.decode(await i.arrayBuffer());if(n.aborted)throw new DOMException(`aborted`,`AbortError`);let s=a[0]?.length??0;return s===0||!(o>0)?hs:{kind:`wave`,wave:{peaks:ys(ri(a,Math.min(ps,s))),duration:o}}}catch(e){if(n.aborted)throw e;return hs}}function ys(e){let t=0;for(let n of e)n>t&&(t=n);if(t>0)for(let n=0;n<e.length;n++)e[n]/=t;return e}var bs=40,xs=new Map;function Ss(e,t,n,r){return`${e}/${t}/${n}#${r??``}`}function Cs(e){return xs.has(e)}function ws(e){return xs.get(e)??null}function Ts(e,t){for(xs.delete(e),xs.set(e,t);xs.size>bs;)xs.delete(xs.keys().next().value)}function Es(e,t){let n=()=>void 0,r=()=>{let i=e.matchMedia(`(resolution: ${e.devicePixelRatio}dppx)`),a=()=>{n(),t(e.devicePixelRatio),r()};i.addEventListener(`change`,a),n=()=>i.removeEventListener(`change`,a)};return r(),()=>n()}var Ds=1500,Os=15e3,ks=15e3,As={fetch(e,t){let n=Ar();return fetch(e,{signal:t.signal,headers:n?{"x-rushes-project":n}:{}})},async decode(e){let t=await new(window.OfflineAudioContext??window.webkitOfflineAudioContext)(1,1,ms).decodeAudioData(e),n=[];for(let e=0;e<t.numberOfChannels;e++)n.push(t.getChannelData(e));return{channels:n,duration:t.duration}}};function js(e,t,n,r,i){let a=Ss(e,t.id,t.file,r),o=X(i),s=X([]);J(()=>{if(o.current=i,i>0)for(let e of s.current.splice(0))e(i)},[i]);let c=()=>o.current>0?Promise.resolve(o.current):new Promise(e=>{s.current.push(e),window.setTimeout(()=>e(null),ks)}),[l,u]=q(()=>Cs(a)?{key:a,wave:ws(a)}:null),d=X(null);return J(()=>{if(Cs(a)){u({key:a,wave:ws(a)});return}let r=new AbortController,i,o=Ds,s={peaksUrl:`/api/videos/${encodeURIComponent(e)}/versions/${encodeURIComponent(t.id)}/peaks`,mediaUrl:Nr(t.file),size:n,duration:c},l=async()=>{d.current=null,clearTimeout(i);let e;try{e=await _s(s,As,r.signal)}catch{return}if(r.signal.aborted)return;if(e.kind===`pending`){d.current=()=>void l(),i=window.setTimeout(()=>void l(),o),o=Math.min(o*2,Os);return}let t=e.kind===`wave`?e.wave:null;Ts(a,t),u({key:a,wave:t})};return l(),()=>{r.abort(),clearTimeout(i),d.current=null}},[a]),J(()=>{d.current?.()},[t]),l&&l.key===a?l.wave:null}var Ms=0;typeof location<`u`&&Rt(location.search).test&&(window.__rushesPicture={waveDraws:()=>Ms});var Ns=3,Ps=2;function Fs({wave:e,length:t}){let n=X(null),[r,i]=q({w:0,h:0,dpr:1});return J(()=>{let e=n.current;if(!e)return;let t=()=>{let t=e.getBoundingClientRect(),n=window.devicePixelRatio||1;i(e=>e.w===t.width&&e.h===t.height&&e.dpr===n?e:{w:t.width,h:t.height,dpr:n})};t();let r=new ResizeObserver(t);r.observe(e);let a=Es(window,t);return()=>{r.disconnect(),a()}},[]),J(()=>{let i=n.current;if(!i||r.w<=0||r.h<=0)return;Ms++,i.width=Math.round(r.w*r.dpr),i.height=Math.round(r.h*r.dpr);let a=i.getContext(`2d`);if(!a)return;a.setTransform(r.dpr,0,0,r.dpr,0,0),a.clearRect(0,0,r.w,r.h);let o=t>0?t:e.duration,s=e.peaks.length;if(!(o>0)||!(e.duration>0)||s===0)return;a.fillStyle=getComputedStyle(i).color;let c=e.duration/s;for(let t=0;t<r.w;t+=Ns){let n=t/r.w*o;if(n>=e.duration)break;let i=(t+Ns)/r.w*o,l=Math.min(s-1,Math.floor(n/c)),u=Math.min(s,Math.max(l+1,Math.ceil(i/c))),d=0;for(let t=l;t<u;t++)e.peaks[t]>d&&(d=e.peaks[t]);let f=Math.max(1,Math.min(1,d)*r.h);a.fillRect(t,(r.h-f)/2,Ps,f)}},[r,e,t]),Q(`canvas`,{ref:n,class:`pwave`,"aria-hidden":`true`})}function Is(e){J(()=>{let t=e.current;if(!t)return;let n=()=>{let e=[...t.children].filter(e=>e.getClientRects().length>0);if(e.length===0)return;let n=e.find(e=>e.classList.contains(`framebox`)),r=Math.min(...e.map(e=>e.getBoundingClientRect().top)),i=Math.max(...e.map(e=>e.getBoundingClientRect().bottom))-r-(n?n.getBoundingClientRect().height:0),a=`${Math.ceil(i+(n?200:0))}px`;t.style.getPropertyValue(`--player-floor`)!==a&&t.style.setProperty(`--player-floor`,a)},r=new ResizeObserver(n),i=()=>{r.disconnect();for(let e of t.children)r.observe(e);n()},a=new MutationObserver(i);return a.observe(t,{childList:!0}),i(),()=>{r.disconnect(),a.disconnect()}},[])}var Ls=700,Rs=16,zs=()=>typeof matchMedia==`function`&&matchMedia(`(hover: none)`).matches;function Bs({versions:e,shown:t,lockedVersion:n,onPick:r}){let i=[...e].reverse(),[a,o]=q(!1),[s,c]=q(t.id),[l,u]=q(null),[d,f]=q(!1),[p,m]=q(null),[h,g]=q(0),_=X(null),v=X(null),y=X(null),b=X({}),x=X({text:``,at:-1/0}),S=new Date,C=Wi(t),w=e=>{c(e),u(null),m(null),f(zs()),o(!0)},T=e=>{o(!1),m(null),e&&v.current?.focus()},E=e=>{T(!0),e!==t.id&&r(e)},D=a&&!e.some(e=>e.id===s);Y(()=>{D?T(!0):a&&b.current[s]?.focus()},[a,s,D]),Y(()=>{if(!a)return;let e=()=>{let e=_.current?.getBoundingClientRect(),t=y.current?.getBoundingClientRect();if(!e||!t)return;let n=document.documentElement.clientWidth-Rs;g(Math.max(0,Math.min(e.left+t.width-n,e.left-Rs)))};return e(),window.addEventListener(`resize`,e),()=>window.removeEventListener(`resize`,e)},[a]),J(()=>{if(!a)return;let e=e=>{_.current?.contains(e.target)||T(!1)};return document.addEventListener(`pointerdown`,e,!0),document.addEventListener(`focusin`,e,!0),()=>{document.removeEventListener(`pointerdown`,e,!0),document.removeEventListener(`focusin`,e,!0)}},[a]);let O=e=>{if(e.key===`Tab`){T(!1);return}if(e.metaKey||e.ctrlKey||e.altKey)return;let t=i.findIndex(e=>e.id===s),n=sa(e.key,t,i.length);if(n!==null){e.preventDefault(),e.stopPropagation(),u(null),c(i[n].id);return}if(e.key===`Escape`){e.preventDefault(),e.stopPropagation(),T(!0);return}if(e.key===`Enter`||e.key===` `){e.preventDefault(),e.stopPropagation(),E(s);return}if(e.key===`ArrowLeft`||e.key===`ArrowRight`){e.preventDefault(),e.stopPropagation();return}if(/^\d$/.test(e.key)){e.preventDefault(),e.stopPropagation();let t=e.timeStamp-x.current.at<Ls?x.current.text+e.key:e.key;x.current={text:t,at:e.timeStamp};let n=oa(i.map(e=>e.id),t);n&&(u(null),c(n));return}e.key.length===1&&e.stopPropagation()},k=e=>{if(d&&p!==e){m(e),c(e);return}E(e)},A=i.find(e=>e.id===(l??s))??t;return Q(`div`,{class:`vwrap`,ref:_,children:[Q(`button`,{ref:v,type:`button`,class:`vbtn`,"data-version":t.id,"aria-haspopup":`listbox`,"aria-expanded":a,"aria-controls":a?`vlist`:void 0,"aria-label":`Version: ${t.id} · ${C}`,onClick:()=>a?T(!1):w(t.id),onKeyDown:e=>{!a&&(e.key===`ArrowDown`||e.key===`ArrowUp`)&&(e.preventDefault(),e.stopPropagation(),w(t.id))},children:[Q(`span`,{class:`vid`,children:t.id}),Q(`span`,{class:`vlbl`,dir:`auto`,children:C}),Q($,{name:`chev`})]}),a&&Q(`div`,{ref:y,class:`vmenu${d?` touch`:``}`,style:h?{left:`${-h}px`}:void 0,children:[Q(`div`,{class:`vlist`,id:`vlist`,role:`listbox`,"aria-label":`Versions`,onKeyDown:O,onMouseLeave:()=>u(null),children:i.map(e=>Q(`button`,{type:`button`,role:`option`,class:`vrow`,"data-version":e.id,"data-on":e.id===(l??s)?`true`:`false`,"aria-selected":e.id===t.id,"aria-label":Vs(e,n,S),"aria-describedby":!d&&e.id===A.id?`vdetail`:void 0,tabIndex:e.id===s?0:-1,ref:t=>{b.current[e.id]=t},onMouseEnter:()=>u(e.id),onClick:()=>k(e.id),children:[Q(`span`,{class:`vid`,children:e.id}),Q(`span`,{class:`vlbl`,dir:`auto`,children:Wi(e)}),Q(`span`,{class:`vwhen`,children:[e.id===n&&Q($,{name:`lock`}),ia(e.addedAt,S)]}),d&&p===e.id&&Q(`span`,{class:`vinline`,dir:`auto`,children:[ji(e.note)||`No note.`,Q(`span`,{class:`vmeta`,children:ca(e,S)})]})]}))}),!d&&Q(`div`,{class:`vdetail`,id:`vdetail`,children:[Q(`h4`,{children:A.id}),Q(`p`,{dir:`auto`,children:ji(A.note)||`No note.`}),Q(`span`,{class:`vmeta`,children:ca(A,S)})]})]})]})}function Vs(e,t,n){return[e.id,Wi(e),e.id===t?`locked`:``,aa(e.addedAt,n)].filter(Boolean).join(`, `)}function Hs({version:e}){let[t,n]=q(!1),[r,i]=q(!1),a=X(null);Y(()=>{let e=a.current;if(!e)return;let t=()=>i(e.scrollHeight>e.clientHeight+1);t();let n=new ResizeObserver(t);return n.observe(e),()=>n.disconnect()},[e.id,e.note,t]);let o=ji(e.note);if(!o)return null;let s=`vnote-${e.id}`;return Q(`div`,{class:`vnote`,children:[Q(`span`,{ref:a,id:s,class:t?`vtext`:`vtext vclamp`,dir:`auto`,children:o}),(r||t)&&Q(`button`,{type:`button`,class:`vmore`,"aria-expanded":t,"aria-controls":s,onClick:()=>n(!t),children:t?`Less`:`More`})]})}var Us=e=>e instanceof HTMLElement&&(e.isContentEditable||/^(INPUT|TEXTAREA|SELECT)$/.test(e.tagName));function Ws({video:e,version:t,fps:n,notes:r,toast:i,onChanged:a,onPendingChange:o,startAt:s,grab:c,onGrabChange:l,playerRef:u,ffmpeg:d=!1,autoProxy:f=!1,proxyJob:p,noteProxyJob:m,source:h=`proxy`,onSourceChange:g,fileSize:_=null,fileRev:v,formats:y=[],format:b=null,formatMissing:x=!1,onPrimarySize:C,onBoxPendingChange:w,onFormatChange:T}){let E=X(null),D=X(null),O=X(null),k=X(null),[A,j]=q(0),[M,N]=q(t.duration??0),[P,F]=q(t.duration?t.file:null),I=b?y.find(e=>e.id===b)??null:null,L=!I||I.primary,ee=I??y.find(e=>e.primary)??null,te=ee?ee.width/ee.height:null,R=b!==null&&y.length>=2,ne=y.find(e=>e.primary)?.id??null,re=Qn(r,b),ie=$n(r,b),[ae,oe]=q(`this`),[z,B]=q(te??16/9),[se,ce]=q(!1),[le,ue]=q(null),[V,de]=q({in:null,out:null}),[fe,H]=q(!1),[U,me]=q(null),[be,xe]=q({w:0,h:0}),[Se,Ce]=q(null),[we,Te]=q(null),[Ee,G]=q(!1),De=X(null);Is(De);let Oe=js(e.id,t,_,v,P===t.file?M:t.duration??0),ke=X(!1),Ae=X(!1),je=X({}),Me=X(se);J(()=>{Me.current=se},[se]);let Ne=X(!0);J(()=>()=>{Ne.current=!1},[]);let Pe=X(t.id);J(()=>{Pe.current=t.id},[t.id]),J(()=>{let e=V.in!==null||Se!==null||Ee;return o?.(e),()=>o?.(!1)},[V.in,Se,Ee]),J(()=>(Se!==null&&oe(`this`),w?.(Se!==null),()=>w?.(!1)),[Se]);let Fe=X(void 0);J(()=>{ue(null),j(0),B(te??16/9),de({in:null,out:null}),Ce(null),Fe.current!==void 0&&l(e.id,null),Fe.current=t.file,Te(null),oe(`this`)},[t.file]);let Ie=Se?`this`:ae,Le=n=>pe(e.versions.find(e=>e.id===n.version)??t),[Re,ze]=q({}),Be=e=>e.id in Re?Re[e.id]:e.format,Ve=e=>ze(t=>{if(!(e in t))return t;let{[e]:n,...r}=t;return r});J(()=>{ze(e=>{let t=Object.keys(e).filter(t=>r.some(n=>n.id===t&&n.format!==e[t]));return t.length===Object.keys(e).length?e:Object.fromEntries(t.map(t=>[t,e[t]]))})},[r]);let He=async(e,t)=>{if(Be(e)!==t){ze(n=>({...n,[e.id]:t}));try{await Z.patch(`/api/notes/${e.id}`,{format:t})}catch(t){Ve(e.id),Ke.current?.id===e.id&&(Ke.current=null),i(`Couldn't change that note: ${t.message}`)}a()}};J(()=>{we&&!re.some(e=>e.id===we)&&Te(null)},[b,r]);let Ke=X(null),qe=X(b);if(qe.current!==b){qe.current=b;let e=document.activeElement,t=e instanceof HTMLElement&&e.closest(`.nfmt`)?e.closest(`.list > .note[data-note]`):null;t&&!Ke.current&&(Ke.current={id:t.dataset.note,fallback:!0})}Y(()=>{let e=Ke.current;if(!e)return;let t=document.activeElement,n=!t||t===document.body||!t.isConnected,r=document.querySelector(`.list > .note[data-note="${CSS.escape(e.id)}"] .t`);r?(Ke.current=null,n&&r.focus()):e.fallback&&(Ke.current=null,n&&document.querySelector(`.otherrow`)?.focus())},[b,r]);let Je=L&&!!t.proxy&&h!==`original`,Ye=Nr(Je?t.proxy.file:L?t.file:I.file),Xe=le===Ye,Ze=X(null),Qe=X(null);if(Qe.current&&Qe.current.src!==Ye){let e=E.current;Qe.current.cut===t.file?!Ze.current&&e&&(Ze.current={t:e.error?A:e.currentTime,play:!e.paused&&!e.error}):Ze.current=null}Qe.current={cut:t.file,src:Ye};let $e=X(null),et=X(null),tt=I?.id??`primary`,nt=X(!0);Y(()=>{if(nt.current){nt.current=!1;return}let e=D.current;if(!ee||!e)return;let t=ee.width/ee.height;if(t===z)return;let n=e.getBoundingClientRect();$e.current={width:n.width,height:n.height},B(t)},[tt]),Y(()=>{let e=$e.current,t=D.current;if($e.current=null,!e||!t)return;et.current?.cancel(),et.current=null;let n=t.getBoundingClientRect(),r=typeof matchMedia==`function`&&matchMedia(`(prefers-reduced-motion: reduce)`).matches,i=Zn(e,{width:n.width,height:n.height},r);Rt(location.search).test&&(window.__rushesLastReshape={animated:i!==null,ms:i?160:0}),i&&(et.current=t.animate(i,{duration:160,easing:`ease-out`}))},[z]),J(()=>{let e=E.current;if(!e)return;let t=()=>ue(Ye);return e.error&&t(),e.addEventListener(`error`,t),()=>e.removeEventListener(`error`,t)},[Ye]);let rt=X(null);rt.current=!L&&M>0?M:null;let ot=e=>{let t=rt.current;t===null||e.paused||e.currentTime<t||(e.pause(),e.currentTime=t)};J(()=>{if(!se)return;let e=0,t=()=>{E.current&&(ot(E.current),j(E.current.currentTime)),e=requestAnimationFrame(t)};return e=requestAnimationFrame(t),()=>cancelAnimationFrame(e)},[se]);let st=()=>Ze.current?.t??E.current?.currentTime??A,ct=()=>ge(st(),n),lt=e=>{let t=E.current;if(!t)return;let n=Math.min(Math.max(0,e),M||t.duration||e);if(Ze.current){Ze.current.t=n,j(n);return}t.currentTime=n,j(t.currentTime)},ut=()=>{let e=E.current;e&&(e.paused?(rt.current!==null&&e.currentTime>=rt.current-.001&&(e.currentTime=0),e.play().catch(()=>i(`Couldn't play this file`))):e.pause())},dt=e=>{E.current?.pause(),lt(_e(st(),n,e,M))},ft=()=>de({in:ct(),out:null}),pt=()=>{let e=ct(),t=V.in??0;if(e<=t)return i(`Out has to come after In`);de({in:t,out:e})},mt=()=>de({in:null,out:null}),ht=X(0),[gt,_t]=q(0),vt=async()=>{let r=E.current,o=ct(),s=e.id,c=t.id,u=L?null:b,f=++ht.current,p=!1;try{let e=he(o,n),t;if(d){p=!0,_t(e=>e+1);let n=await Mr(s,c,o,u);e=n.frame??e,t=n.png}else{if(!r||!r.videoWidth)return i(`Nothing to grab yet`);let e=document.createElement(`canvas`);e.width=r.videoWidth,e.height=r.videoHeight,e.getContext(`2d`).drawImage(r,0,0),t=e.toDataURL(`image/png`)}let m=await Z.post(`/api/grabs`,{video:s,version:c,frame:e,png:t,...u?{format:u}:{}});if(f!==ht.current){a();return}i(`Saved to ${m.grab}`),a(),Ne.current&&c===Pe.current&&l(s,m.grab)}catch(e){f===ht.current&&i(e.message)}finally{p&&Ne.current&&_t(e=>e-1)}},yt=async r=>{let i=V.in!==null&&V.out!==null,o=i?V.in:ct();await Z.post(`/api/notes`,{stage:`picture`,video:e.id,version:t.id,scope:i?`range`:`point`,t:o,tOut:i?V.out:null,frame:he(o,n),text:r,box:Se,grab:c,...R?{format:Ie===`this`?b:null}:{}}),mt(),oe(`this`),Ce(null),l(e.id,null),a()},bt=X(()=>void 0);bt.current=e=>{if(Us(e.target)||e.metaKey||e.ctrlKey||e.altKey)return;let t=e.key.toLowerCase();if(e.key===` `){if(Lt(e.target))return;e.preventDefault(),ut()}else e.key===`ArrowLeft`?(e.preventDefault(),dt(e.shiftKey?-10:-1)):e.key===`ArrowRight`?(e.preventDefault(),dt(e.shiftKey?10:1)):t===`i`?ft():t===`o`?pt():t===`g`&&!e.repeat?vt():t===`b`?H(e=>!e):t===`n`&&(e.preventDefault(),k.current?.focus())},J(()=>{let e=e=>bt.current(e);return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[]);let xt=(e,t)=>{let n=E.current;return it(n?.videoWidth??0,n?.videoHeight??0,e,t)},St=e=>{let t=O.current.getBoundingClientRect(),n=xt(t.width,t.height);return{x:e.clientX-t.left-n.x,y:e.clientY-t.top-n.y,w:n.w,h:n.h}};J(()=>{let e=O.current;if(!e)return;let t=()=>xe(t=>t.w===e.clientWidth&&t.h===e.clientHeight?t:{w:e.clientWidth,h:e.clientHeight});t();let n=new ResizeObserver(t);return n.observe(e),()=>n.disconnect()},[]);let Ct=e=>{if(!fe)return;let t=St(e);e.target.setPointerCapture(e.pointerId),me({x0:t.x,y0:t.y,x1:t.x,y1:t.y,w:t.w,h:t.h})},wt=e=>{if(!U)return;let t=St(e);me({...U,x1:t.x,y1:t.y})},Tt=e=>{if(!U)return;let t=St(e),n=at(U.x0,U.y0,t.x,t.y,U.w,U.h);me(null),H(!1),ke.current=!0,n.w>.01&&n.h>.01&&Ce(n)},Et=U?at(U.x0,U.y0,U.x1,U.y1,U.w,U.h):null,Dt=xt(be.w,be.h),Ot=e=>({left:`${e.x*100}%`,top:`${e.y*100}%`,width:`${e.w*100}%`,height:`${e.h*100}%`}),kt=e=>`${M?Math.min(100,Math.max(0,e/M*100)):0}%`,At=M?t.shots.filter(e=>e.start<M):t.shots,jt=Ue(At,ge(A,n));J(()=>{Me.current&&jt!==null&&je.current[jt.n]?.scrollIntoView({block:`nearest`,inline:`nearest`})},[jt?.n]);let Mt=re.map(e=>({n:e,at:ve(e,t.id)})).filter(({at:e})=>e.t!==null),Nt=re.find(e=>e.id===we)??null,Pt=Nt?.box&&(!Nt.version||Nt.version===t.id)&&er(Nt,b,ne)?Nt.box:null,Ft=V.in===null?null:V.out===null?`${W(V.in)} →`:ye(V.in,V.out),It=V.in!==null&&V.out===null?`Set an Out point`:`Note at ${Ft&&V.out!==null?Ft:W(A)}`,zt=e=>{N(L?e.duration||t.duration||0:t.duration??I?.duration??(e.duration||0)),F(t.file),L&&t.width===null&&e.videoWidth&&e.videoHeight&&C?.(t.file,e.videoWidth,e.videoHeight),ue(e=>e===Ye?null:e),e.videoWidth&&e.videoHeight&&B(e.videoWidth/e.videoHeight),Ae.current||(Ae.current=!0,s&&(e.currentTime=Math.min(s,e.duration||s),j(e.currentTime)));let n=Ze.current;n&&(Ze.current=null,e.currentTime=Math.min(n.t,e.duration||n.t),j(n.t),n.play&&e.play().catch(()=>void 0))},Bt=t=>{t!==h&&g?.(e.id,t)};return Q(`div`,{class:`split`,children:[Q(`div`,{class:`stack`,ref:De,children:[Q(`div`,{class:`framebox`,style:{height:`min(640px, 70vh, calc(100cqw / ${z}))`},children:Q(`div`,{class:`frame`,ref:D,style:{aspectRatio:String(z),"--ar":String(z)},children:[x&&!L&&Q(`div`,{class:`msg`,children:`File not found`}),Xe&&!L&&!x&&Q(`div`,{class:`msg`,children:`This file won't play in a browser. Ask your agent for an H.264 MP4 of this format.`}),Xe&&L&&!d&&Q(`div`,{class:`msg`,children:`This file won't play in a browser. Ask your agent for an H.264 MP4 of this cut.`}),Xe&&L&&d&&t.proxy&&!Je&&Q(`div`,{class:`msg`,children:`This file won't play in a browser.`}),Q(`video`,{hidden:Xe||x&&!L,ref:e=>{E.current=e,u&&(u.current=e),e&&e.readyState>=1&&zt(e)},src:Ye,preload:`auto`,playsInline:!0,onLoadedMetadata:e=>zt(e.target),onTimeUpdate:e=>{let t=e.target;ot(t),!se&&!Ze.current&&j(t.currentTime)},onSeeked:e=>!Ze.current&&j(e.target.currentTime),onPlay:()=>ce(!0),onPause:()=>ce(!1),onEnded:()=>ce(!1)}),Q(`div`,{ref:O,class:`overlay${fe?` drawing`:``}`,onPointerDown:Ct,onPointerMove:wt,onPointerUp:Tt,onClick:()=>{ke.current?ke.current=!1:fe||ut()},children:Q(`div`,{class:`pic`,style:{left:`${Dt.x}px`,top:`${Dt.y}px`,width:`${Dt.w}px`,height:`${Dt.h}px`},children:[Pt&&Q(`div`,{class:`bx saved`,style:Ot(Pt)}),Se&&Q(`div`,{class:`bx`,style:Ot(Se)}),Et&&Q(`div`,{class:`bx`,style:Ot(Et)})]})}),Q(`div`,{class:`tcover`,children:[`f`,he(A,n),jt&&` · shot ${We(jt.n)}`]}),t.proxy&&L&&Q(`div`,{class:`srcswitch`,role:`group`,"aria-label":`Which file plays`,children:[Q(`button`,{type:`button`,class:`tip-below tip-start tip-wrap`,"aria-pressed":Je,"aria-label":`Proxy`,"data-tip":`Playing the lightweight copy. Notes and timings are the same.`,onClick:e=>{e.currentTarget.blur(),Bt(`proxy`)},children:`Proxy`}),Q(`button`,{type:`button`,class:`tip-below tip-start tip-wrap`,"aria-pressed":!Je,"aria-label":`Original`,"data-tip":`Play the full-quality file. It may stutter.`,onClick:e=>{e.currentTarget.blur(),Bt(`original`)},children:`Original`})]})]})}),m&&Q(fs,{hidden:!L,video:e,version:t,ffmpeg:d,autoProxy:f,job:p,broken:Xe&&!Je,duration:M,toast:i,onChanged:a,noteProxyJob:m},t.id),Q(`div`,{class:`bar`,children:[Q(`button`,{class:`btn ghost ib`,"data-tip":`Back one frame ←`,"aria-label":`Back one frame`,onClick:()=>dt(-1),children:Q($,{name:`prev`})}),Q(`button`,{class:`btn ib`,"data-tip":`Play Space`,"aria-label":se?`Pause`:`Play`,onClick:ut,children:Q($,{name:se?`pause`:`play`})}),Q(`button`,{class:`btn ghost ib`,"data-tip":`Forward one frame →`,"aria-label":`Forward one frame`,onClick:()=>dt(1),children:Q($,{name:`next`})}),Q(`span`,{class:`tc`,"aria-label":`Timecode`,children:[W(A),Q(`small`,{children:[`/ `,W(M)]})]}),Q(`span`,{class:`sp`}),Ft&&Q(`span`,{class:`chipx`,children:[Q(`span`,{class:`mono`,children:Ft}),Q(`button`,{"aria-label":`Clear range`,onClick:mt,children:Q($,{name:`x`})})]}),Q(`button`,{class:`btn ghost ib`,"data-tip":`Set in I`,"aria-label":`Set in point`,onClick:ft,children:Q($,{name:`in`})}),Q(`button`,{class:`btn ghost ib`,"data-tip":`Set out O`,"aria-label":`Set out point`,onClick:pt,children:Q($,{name:`out`})}),Q(`span`,{class:`vsep`}),Q(`button`,{class:`btn ghost ib`,"data-tip":`Draw a box B`,"aria-label":`Draw a box`,"aria-pressed":fe,onClick:()=>H(!fe),children:Q($,{name:`box`})}),Q(`button`,{class:`btn ghost ib`,"data-tip":`Grab frame G`,"aria-label":`Grab frame`,"aria-busy":gt>0,onClick:()=>void vt(),children:Q($,{name:`camera`})})]}),Q(`div`,{class:`track`,role:`slider`,"aria-label":`Timeline`,"aria-valuemin":0,"aria-valuemax":M,"aria-valuenow":A,onClick:e=>{let t=e.currentTarget.getBoundingClientRect();lt((e.clientX-t.left)/t.width*M)},children:[Oe&&Q(Fs,{wave:Oe,length:M}),Mt.map(({n:e,at:t})=>t.tOut!==null&&Q(`div`,{class:`span ${e.status}`,style:{left:kt(t.t),width:kt(t.tOut-t.t)}})),V.in!==null&&Q(`div`,{class:`span live`,style:{left:kt(V.in),width:kt((V.out??V.in+.2)-V.in)}}),At.filter(e=>e.start>0).map(e=>Q(`div`,{class:`tick`,style:{left:kt(e.start)}})),Mt.map(({n:e,at:t})=>{let n=rr(e,R);return Q(`div`,{class:`mk ${e.status}${R&&e.format===null?` ring`:``}`,style:{left:kt(t.t)},title:n?`${n} · ${e.text}`:e.text})}),Q(`div`,{class:`playhead`,style:{left:kt(A)}})]}),Q(`div`,{class:`ends`,children:[Q(`span`,{children:`0:00`}),Q(`span`,{children:W(M)})]}),Q(Hs,{version:t},t.id)]}),At.length>0&&Q(`div`,{class:`shots`,"data-player":!0,children:At.map(e=>Q(`button`,{type:`button`,class:`shot`,ref:t=>{je.current[e.n]=t},"aria-current":jt?.n===e.n?`true`:void 0,onClick:()=>{E.current?.pause(),lt(Ge(e.start,n))},children:[Q(`span`,{class:`mono`,children:[We(e.n),` · `,e.start.toFixed(2),`s`]}),Q(`span`,{class:`name`,children:e.name}),e.tag&&Q(`span`,{class:`tag`,children:e.tag})]}))}),Q(Zo,{notes:re,version:t.id,selectedId:we,placeholder:It,inputRef:k,toast:i,onAdd:yt,onChanged:a,onTextChange:G,formatTag:e=>rr(e,R),cardExtra:R&&I?e=>Q(Jo,{name:`Note applies to`,label:I.label,width:I.width,height:I.height,value:Be(e)===null?`all`:`this`,lockedReason:e.box?tr:null,onChange:t=>void He(e,t===`all`?null:I.id)}):void 0,formatScope:R&&I?{label:I.label,width:I.width,height:I.height,value:Ie,onChange:oe,lockedReason:Se?tr:null,hint:nr(I.label,Ie,Se!==null)}:void 0,listFooter:e=>{let n=ie.filter(t=>e===`all`||t.status===e);return n.length>0?Q(ls,{notes:n,version:t.id,viewsHere:y,ownViews:Le,onShow:(e,t)=>{Se||(Ke.current={id:t.id,fallback:!1}),T?.(e)},onRestore:e=>{Ke.current={id:e.id,fallback:!1},He(e,null)}}):null},onSeek:(e,t)=>{E.current?.pause(),lt(e),Te(t.id)},attachments:(Se||c)&&Q(S,{children:[Se&&Q(`span`,{class:`chipx`,children:[Q($,{name:`box`}),`Box`,Q(`button`,{"aria-label":`Remove box`,onClick:()=>Ce(null),children:Q($,{name:`x`})})]}),c&&Q(`span`,{class:`chipx`,children:[Q($,{name:`image`}),`Frame `,c.match(/_f(\d+)\.png$/)?.[1],Q(`button`,{"aria-label":`Remove frame`,onClick:()=>l(e.id,null),children:Q($,{name:`x`})})]})]})})]})}var Gs=500;function Ks(e,t){let n=X(void 0),r=X(e);return r.current=e,J(()=>()=>{n.current!==void 0&&(clearTimeout(n.current),r.current())},[]),{schedule(){clearTimeout(n.current),n.current=window.setTimeout(()=>{n.current=void 0,r.current()},t)},flush(){n.current!==void 0&&(clearTimeout(n.current),n.current=void 0,r.current())}}}var qs=(e,t)=>e.slice(0,t).filter(n=>n.heading===e[t].heading).length,Js=e=>String(e).padStart(2,`0`);function Ys({shot:e,large:t}){let[n,r]=q(null);return!e.still||n===e.still?Q(`span`,{class:`nostill`,children:t?`No still for this shot yet`:`No still`}):Q(`img`,{src:Nr(e.still),alt:`Still for shot ${e.n}, ${e.name}`,onError:()=>r(e.still)})}function Xs({shot:e,save:t,onZoom:n}){let[r,i]=q(e.description),[a,o]=q(e.direction),s=X(!1),c=X(null);J(()=>{s.current||i(e.description)},[e.description]),J(()=>{s.current||o(e.direction)},[e.direction]),Y(()=>{let e=c.current;e&&(e.style.height=`auto`,e.style.height=`${e.scrollHeight+2}px`)},[r]);let l=Ks(()=>{s.current=!1,r.trim()!==e.description.trim()&&t.shot(e,{description:r})},Gs),u=Ks(()=>{s.current=!1,a.trim()!==e.direction.trim()&&t.shot(e,{direction:a})},Gs),d=r.trim()!==e.current.trim()||a.trim()!==e.directionCurrent.trim(),f=e.status===`approved`;return Q(`div`,{class:`sbrow${d?` changed`:``}`,"data-shot":e.heading,children:[Q(`div`,{class:`sbid`,children:[Q(`button`,{class:`sbstill`,"aria-label":`Enlarge the still for shot ${e.n}`,"data-tip":`Enlarge`,onClick:n,children:Q(Ys,{shot:e})}),Q(`div`,{class:`sbmeta`,children:[Q(`b`,{children:Js(e.n)}),Q(`span`,{children:e.length===null?`no length`:`${e.length.toFixed(1)} s`}),e.tag&&Q(`span`,{class:`sbtag`,children:e.tag})]})]}),Q(`div`,{class:`cur`,children:[Q(`b`,{class:`sbname`,children:e.name}),e.current]}),Q(`textarea`,{ref:c,class:`input`,"aria-label":`Your version of shot ${e.n}`,value:r,onInput:e=>{s.current=!0,i(e.target.value),l.schedule()},onBlur:()=>l.flush()}),Q(`div`,{class:`sblow`,children:[Q(`input`,{class:`sbdir`,placeholder:`Direction`,"aria-label":`Direction for shot ${e.n}`,value:a,onInput:e=>{s.current=!0,o(e.target.value),u.schedule()},onBlur:()=>u.flush()}),d&&Q(`button`,{class:`btn ghost ib`,"data-tip":`Revert to current`,"aria-label":`Revert shot ${e.n}`,onClick:()=>{s.current=!1,i(e.current),o(e.directionCurrent),t.shot(e,{description:e.current,direction:e.directionCurrent})},children:Q($,{name:`undo`})}),Q(`button`,{class:`btn ib okd${f?` on`:``}`,"data-tip":f?`Unapprove`:`Approve`,"aria-label":`Approve shot ${e.n}`,"aria-pressed":f,onClick:()=>t.shot(e,{status:f?`draft`:`approved`}),children:Q($,{name:`check`})})]})]})}function Zs({shot:e,onClose:t}){let n=X(null);return Y(()=>{n.current?.focus()},[]),Q(`div`,{class:`sblight`,role:`dialog`,"aria-modal":`true`,"aria-label":`Shot ${e.n}, ${e.name}`,tabIndex:-1,ref:n,onClick:t,onKeyDown:e=>{e.key===`Escape`?(e.preventDefault(),e.stopPropagation(),t()):e.key===`Tab`&&e.preventDefault()},children:Q(`div`,{class:`sblbx`,children:[Q(`div`,{class:`sbbig`,children:Q(Ys,{shot:e,large:!0})}),Q(`div`,{class:`sblcap`,children:[Q(`b`,{children:[Js(e.n),` · `,e.name]}),` `,e.tag&&Q(`span`,{class:`sbtag`,children:e.tag}),Q(`p`,{children:e.description})]})]})})}function Qs({board:e,brief:t,toast:n,onChanged:r,settle:i}){let{latest:a,enqueue:o}=Xa(`storyboard`,e,{toast:n,onChanged:r,settle:i}),[s,c]=q(null),l=X(null),u={shot:(e,t)=>{let n=a.current.shots.findIndex(t=>t.index===e.index),r=n<0?0:qs(a.current.shots,n),i=t.status===`approved`&&t.description===void 0&&t.direction===void 0;o(`shot ${e.n}`,(n,a)=>{let o=n.shots.filter(t=>t.heading===e.heading)[r];if(!o){let t=n.shots.filter(t=>t.name===e.name);t.length===1&&(o=t[0])}return o&&a&&i&&(o.description!==e.description||o.direction!==e.direction)?{refuse:`the agent changed this shot while you were looking at it. Read it again, then approve.`}:o?{path:`/api/storyboard/shots/${o.index}`,body:{heading:o.heading,...t}}:null})}},d=ze(t),f=e.shots.find(e=>e.heading===s);return Q(`div`,{class:`col`,children:[Q(`div`,{class:`shead`,children:[Q(`h2`,{children:`Storyboard`}),Q(`span`,{class:`meta`,children:e.total>0&&`${e.total} shot${e.total===1?``:`s`} · ${e.changed} changed`})]}),Q(`div`,{class:`sbtotal mono`,"aria-label":`Planned length`,children:[Q(`span`,{children:d?`${e.plannedLength.toFixed(1)} / ${d} s planned`:`${e.plannedLength.toFixed(1)} s planned`}),d&&Q(`span`,{class:`bar`,children:Q(`i`,{style:{width:`${Math.min(100,e.plannedLength/d*100)}%`}})})]}),e.total===0&&Q(`p`,{class:`sbnone`,children:"storyboard.md has no shots yet. Your agent adds them as `## Shot 01 · Name` sections."}),Q(`div`,{class:`sbhead`,children:[Q(`span`,{}),Q(`span`,{children:`Current`}),Q(`span`,{children:`Yours`})]}),Q(`div`,{style:{display:`grid`,gap:`12px`},children:e.shots.map((t,n)=>Q(Xs,{shot:t,save:u,onZoom:()=>{l.current=document.activeElement,c(t.heading)}},`${t.heading}#${qs(e.shots,n)}`))}),f&&Q(Zs,{shot:f,onClose:()=>{c(null),l.current?.focus()}})]})}function $s({selected:e,rows:t,marks:n,open:r,locked:i,ready:a,onCopyReady:o,onPick:s}){let[c,l]=q(!1),[u,d]=q(0),[f,p]=q({left:0,top:0}),m=X(null),h=X(null),g=X([]),_=()=>{let n=h.current?.getBoundingClientRect();n&&p({left:Math.max(8,n.left),top:n.bottom}),d(Math.max(0,t.findIndex(t=>t.page===e))),l(!0)},v=e=>{l(!1),e&&h.current?.focus()};Y(()=>{c&&g.current[u]?.focus()},[c,u]),J(()=>{if(!c)return;let e=e=>{m.current?.contains(e.target)||v(!1)};return document.addEventListener(`pointerdown`,e,!0),document.addEventListener(`focusin`,e,!0),()=>{document.removeEventListener(`pointerdown`,e,!0),document.removeEventListener(`focusin`,e,!0)}},[c]);let y=e=>{if(e.key===`Tab`)return v(!1);if(e.metaKey||e.ctrlKey||e.altKey)return;if(e.key===`ArrowLeft`||e.key===`ArrowRight`){e.preventDefault(),e.stopPropagation();return}let n=e.key===`ArrowDown`?1:e.key===`ArrowUp`?-1:e.key===`Home`?-t.length:e.key===`End`?t.length:0;n===0?e.key===`Escape`?(e.preventDefault(),e.stopPropagation(),v(!0)):e.key.length===1&&e.stopPropagation():(e.preventDefault(),e.stopPropagation(),d(e=>Math.min(t.length-1,Math.max(0,e+n))))},b=e=>Q(`i`,{class:`pm ${e}`});return Q(`span`,{class:`plan`,ref:m,children:[Q(`button`,{ref:h,class:`tab`,role:`tab`,"aria-selected":e!==null,"aria-haspopup":`menu`,"aria-expanded":c,"data-locked":i?`true`:void 0,onClick:()=>c?v(!1):_(),onKeyDown:e=>{e.key===`ArrowDown`&&!c&&(e.preventDefault(),_())},children:[Q($,{name:`list`}),`Planning`,n?Q(`span`,{class:`pmarks`,title:a?`Ready to build`:`Brief, script and storyboard`,children:a?Q($,{name:`check`,class:`pready`}):Q(S,{children:[b(n.brief),b(n.script),b(n.storyboard)]})}):i?Q($,{name:`lock`,class:`lk`}):r>0&&Q(`span`,{class:`dot`,title:`${r} open`}),Q($,{name:`chev`,class:`chev`})]}),c&&Q(`div`,{class:`planmenu`,role:`menu`,"aria-label":`Planning`,style:{left:`${f.left}px`,top:`${f.top}px`},onKeyDown:y,children:[t.map((t,n)=>Q(`button`,{ref:e=>{g.current[n]=e},role:`menuitem`,class:`planitem${t.page===e?` cur`:``}`,"data-locked":t.unlocked?void 0:`true`,tabIndex:n===u?0:-1,"data-tip":t.unlocked?void 0:`Locked: ask your agent for ${t.ask}`,onClick:()=>{v(!0),s(t.page)},children:[Q($,{name:t.icon}),Q(`span`,{children:t.name}),t.unlocked?t.progress===null?null:t.progress===`ok`?Q($,{name:`check`,class:`pi`}):Q(`i`,{class:`pm ${t.progress}`}):Q($,{name:`lock`,class:`lk`})]},t.page)),a&&Q(`div`,{class:`planready`,children:[Q(`div`,{class:`rd`,children:[Q($,{name:`check`}),`Ready to build`]}),Q(`button`,{role:`menuitem`,class:`btn`,tabIndex:-1,onClick:()=>{v(!1),o()},children:[Q($,{name:`copy`}),`Copy prompt for your agent`]})]})]})]})}var ec={approved:{color:`var(--done)`,label:`Approved`},flagged:{color:`var(--todo)`,label:`Flagged`},draft:{color:`var(--text-3)`,label:`Draft`}},tc=500;function nc(e,t){let n=X(void 0),r=X(e);return r.current=e,J(()=>()=>{n.current!==void 0&&(clearTimeout(n.current),r.current())},[]),{schedule(){clearTimeout(n.current),n.current=window.setTimeout(()=>r.current(),t)},flush(){n.current!==void 0&&(clearTimeout(n.current),n.current=void 0,r.current())}}}function rc({section:e,wps:t,toast:n,onChanged:r}){let[i,a]=q(e.proposed??e.current),[o,s]=q(e.direction),c=X(!1),l=X(null);J(()=>{c.current||a(e.proposed??e.current)},[e.proposed,e.current]),J(()=>{c.current||s(e.direction)},[e.direction]),Y(()=>{let e=l.current;e&&(e.style.height=`auto`,e.style.height=`${e.scrollHeight+2}px`)},[i]);let u=async t=>{try{await Z.patch(`/api/script/${encodeURIComponent(e.id)}`,t)}catch(t){n(`Couldn't save ${e.id.toUpperCase()}: ${t.message}`)}r()},d=nc(()=>{c.current=!1,u({proposed:i.trim()===e.current.trim()?null:i})},tc),f=nc(()=>{c.current=!1,u({direction:o})},tc),p=e.end-e.start,m=be(i,p,t),h=i.trim()!==e.current.trim(),g=ec[e.status];return Q(`div`,{class:`srow${h?` changed`:``}`,"data-section":e.id,children:[Q(`div`,{class:`sgrid`,children:[Q(`div`,{class:`when`,children:[Q(`b`,{children:e.id.toUpperCase()}),Q(`span`,{children:[W(e.start).replace(/\.\d+$/,``),`–`,W(e.end).replace(/\.\d+$/,``)]}),Q(`span`,{class:`stat`,"aria-label":g.label,"data-tip":g.label,title:g.label,children:Q(`i`,{style:{background:g.color}})})]}),Q(`div`,{class:`cur`,children:e.current}),Q(`textarea`,{ref:l,class:`input`,"aria-label":`Your version of ${e.id}`,value:i,onInput:e=>{c.current=!0,a(e.target.value),d.schedule()},onBlur:()=>d.flush()})]}),Q(`div`,{class:`sfoot`,children:[Q(`div`,{class:`fit${m.state===`ok`?``:` ${m.state}`}`,title:`${m.words} words · ${m.seconds.toFixed(1)} s of ${p.toFixed(1)} s`,children:Q(`i`,{style:{width:`${Math.min(100,m.ratio*100)}%`}})}),Q(`input`,{class:`dirin`,placeholder:`Direction`,"aria-label":`Direction for ${e.id}`,value:o,onInput:e=>{c.current=!0,s(e.target.value),f.schedule()},onBlur:()=>f.flush()}),Q(`div`,{class:`sact`,children:[h&&Q(`button`,{class:`btn ghost ib`,"data-tip":`Revert to current`,"aria-label":`Revert`,onClick:()=>{a(e.current),u({proposed:null})},children:Q($,{name:`undo`})}),Q(`button`,{class:`btn ib flagd${e.status===`flagged`?``:` ghost`}`,"data-tip":e.status===`flagged`?`Unflag`:`Flag`,"aria-label":`Flag`,"aria-pressed":e.status===`flagged`,onClick:()=>void u({status:e.status===`flagged`?`draft`:`flagged`}),children:Q($,{name:`flag`})}),Q(`button`,{class:`btn ib okd`,"data-tip":e.status===`approved`?`Unapprove`:`Approve`,"aria-label":`Approve`,"aria-pressed":e.status===`approved`,onClick:()=>void u({status:e.status===`approved`?`draft`:`approved`}),children:Q($,{name:`check`})})]})]})]})}function ic({script:e,toast:t,onChanged:n}){let r=e.sections.filter(xe).length;return Q(`div`,{class:`col`,children:[Q(`div`,{class:`shead`,children:[Q(`h2`,{children:`Script`}),Q(`span`,{class:`meta`,children:[e.sections.length,` section`,e.sections.length===1?``:`s`,` · `,r,` changed`]})]}),Q(`div`,{class:`sgrid scols`,children:[Q(`span`,{}),Q(`span`,{children:`Current`}),Q(`span`,{children:`Yours`})]}),Q(`div`,{style:{display:`grid`,gap:`12px`},children:e.sections.map(r=>Q(rc,{section:r,wps:e.wordsPerSecond,toast:t,onChanged:n},r.id))})]})}var ac={music:`#A78BFA`,sfx:`#FB923C`},oc=Math.floor(Math.random()*2**31),sc=!1,cc=new Set;function lc({stage:e,state:t,assets:n,video:r,toast:i,onChanged:a,onPendingChange:o}){let[s,c]=q(e===`music`&&sc),l=e=>{sc=e,c(e)},[,u]=q(0),d=e=>{cc.has(e)?cc.delete(e):cc.add(e),u(e=>e+1)},f=bt(t.project.lanes,e),p=s?Mt(f.map(e=>e.key),oc):f.map(e=>e.key),m=p.map(e=>f.find(t=>t.key===e)),h=e=>s?`Bed ${p.indexOf(e.key)+1}`:e.name,g=t.picks.lanes,_=async(e,t)=>{try{await Z.put(`/api/picks`,{lanes:{[e.lane]:t}})}catch(e){i(`Couldn't ${t===null?`clear`:`set`} the pick: ${e.message}`)}a()},v=m.map(t=>{let r=n.find(e=>e.path===t.file),i={id:t.key,lane:t.lane,path:t.file,offset:0,duration:0,rev:r?qr(r):void 0},a=g[t.lane]===t.variant;return{key:t.key,name:h(t),meta:s?`·····`:t.meta,color:ac[e],clips:[i],cues:e===`sfx`?t.cues:void 0,layers:e===`sfx`?{open:cc.has(t.key),onToggle:()=>d(t.key)}:void 0,audition:{lane:t.lane,clip:t.key},picked:a,order:f.indexOf(t),use:{inUse:a,onUse:()=>void _(t,t.variant),onUnpick:()=>void _(t,null)},on:`v:${t.key}`}}),y=Tt(m,h,e===`sfx`),b=t.notes.notes.filter(t=>t.stage===e),x=Ce(r??void 0),S=r&&x?{video:r.id,version:x.id,file:x.file,duration:x.duration}:null,C=t.project.fps||30;return Q(rs,{stage:e,film:r?.id??null,title:Te[e],headerExtra:e===`music`&&Q(`button`,{class:`btn ghost ib`,"aria-label":`Blind`,"aria-pressed":s,"data-tip":s?`Show names`:`Blind: hide names`,onClick:()=>l(!s),children:Q($,{name:`eyeoff`})}),rows:v,preview:S,fps:C,notes:b,onOptions:y,noteRow:e=>kt(m,e.on),onLabel:e=>At(m,y,e.on),toast:i,onChanged:a,onPendingChange:o})}var uc=`#4FD1C5`,dc=[`whole`,`point`],fc={whole:ut.voice,point:[`Fix this`,`Keep this`]},pc=Math.floor(Math.random()*2**31),mc=!1,hc=new Map,gc=new Set;function _c({state:e,assets:t,video:n,toast:r,onChanged:i,onPendingChange:a}){let[o,s]=q(mc),c=e=>{mc=e,s(e)},l=n?.id??``,[,u]=q(0),d=hc.get(l)??gc,f=e=>{let t=new Set(d);t.has(e)?t.delete(e):t.add(e),hc.set(l,t),u(e=>e+1)},p=e=>t.find(t=>t.path===e),m=e=>{let t=p(e);return t?qr(t):void 0},h=e=>p(e)?.missing===!0,g=Vt(e.project.lanes,e.picks.lanes),_=g.map(e=>{if(!o)return e;let t=Mt(e.reads.map(e=>e.key),pc);return{...e,reads:t.map(t=>e.reads.find(e=>e.key===t))}}),v=new Map;for(let e of _)e.reads.forEach((e,t)=>v.set(e.key,t+1));let y=e=>o?`Read ${v.get(e.key)}`:e.name,b=async(e,t)=>{try{await Z.put(`/api/picks`,{lanes:{[e.id]:t}})}catch(e){r(`Couldn't ${t===null?`clear`:`set`} the pick: ${e.message}`)}i()},x=e=>({id:e.key,lane:Gt(e),path:e.file,offset:0,duration:0,rev:m(e.file)}),C=g.filter(e=>e.current||d.has(e.id)).flatMap(e=>e.reads.filter(e=>!h(e.file)).map(x)),w=e.notes.notes.filter(e=>e.stage===`voice`),T={rounds:g,sections:e.script.sections},E=(e,t)=>({key:t.key,name:y(t),meta:o?`·····`:t.meta,color:uc,clips:h(t.file)?[]:[x(t)],use:{inUse:e.pick===t.variant,onUse:()=>void b(e,t.variant),onUnpick:()=>void b(e,null)},on:`v:${t.key}`,missing:h(t.file)}),D=[];for(let e of[..._].reverse()){if(e.current){e.reads.forEach((t,n)=>D.push(n===0?{...E(e,t),heading:e.name,tag:`current`}:E(e,t)));continue}let t=d.has(e.id),n=e.reads.find(t=>t.variant===e.pick),r=new Set(e.reads.map(e=>e.key)),i=e.reads.length;if(D.push({key:`round:${e.id}`,name:e.name,color:uc,clips:[],fold:{label:Q(S,{children:[Q(`b`,{children:e.name}),` · `,i,` `,i===1?`read`:`reads`,` ·`,` `,n?Q(`span`,{class:`fpk`,children:[`picked `,o?`a read`:n.name]}):`nothing picked`]}),text:`${e.name} · ${i} ${i===1?`read`:`reads`} · ${n?`picked ${o?`a read`:n.name}`:`nothing picked`}`,open:t,dot:w.some(e=>e.status===`todo`&&r.has(Yt(T,e)??``)),onToggle:()=>f(e.id)}}),t)for(let t of e.reads)D.push(E(e,t))}let O=Xt(_,y),k=Wt(g),A=Ce(n??void 0),j=n&&A?{video:n.id,version:A.id,file:A.file,duration:A.duration}:null,M=e.project.fps||30;return Q(rs,{stage:`voice`,film:n?.id??null,title:Te.voice,headerExtra:Q(`button`,{class:`btn ghost ib`,"aria-label":`Blind`,"aria-pressed":o,"data-tip":o?`Show names`:`Blind: hide names`,onClick:()=>c(!o),children:Q($,{name:`eyeoff`})}),rows:D,clips:C,preview:j,fps:M,notes:w,onOptions:O,defaultOn:k?`v:${k.key}`:void 0,listen:e=>Kt(g,e),noteRow:e=>Yt(T,e),onLabel:e=>Zt(T,e.on,y),scopes:dc,defaultScope:`whole`,chipsFor:e=>fc[e===`point`?`point`:`whole`],marks:!1,toast:r,onChanged:i,onPendingChange:a})}var vc=[[`all`,`All`],[`picture`,Gi.picture],[`voice`,Gi.voice],[`music`,Gi.music],[`sfx`,Gi.sfx],[`mix`,Gi.mix],[`notes`,Gi.notes],[`assets`,Gi.assets]];function yc(e){return vc.some(([t])=>t===e)}var bc={user:`added by you`,agent:`agent`,rushes:`Rushes`};function xc(e,t){let n=[];for(let r of e){let e=new Date(r.at),i=Qi(e),a=n[n.length-1];a&&a.date===i?a.entries.push(r):n.push({key:i,date:i,heading:$i(e,t,!0),entries:[r]})}let r=new Map;for(let e=n.length-1;e>=0;e--){let t=(r.get(n[e].date)??0)+1;r.set(n[e].date,t),t>1&&(n[e].key=`${n[e].date}~${t}`)}return n.map(({key:e,heading:t,entries:n})=>({key:e,heading:t,entries:n}))}function Sc(e,t){return e===`all`||e===t}var Cc=new Set([` `,`ArrowLeft`,`ArrowRight`,`ArrowUp`,`ArrowDown`,`Home`,`End`,`PageUp`,`PageDown`]);function wc(e){return Cc.has(e.key)&&!e.altKey&&!e.ctrlKey&&!e.metaKey}var Tc=[`script`,`picture`,`voice`,`music`,`sfx`,`mix`];function Ec(e,t){if(e.kind===`entry`&&!e.video&&!e.version&&!e.ref)return null;let n=e.video?t.videos.find(t=>t.id===e.video):void 0;if(n)return e.version&&n.versions.some(t=>t.id===e.version)?{tab:`picture`,video:n.id,version:e.version}:{tab:`picture`,video:n.id};let r=e.ref?e.ref.indexOf(`/`):-1,i=r>0?t.lanes.find(t=>t.id===e.ref.slice(0,r)):void 0;return i?{tab:i.stage,row:e.ref}:e.tab&&Tc.includes(e.tab)?{tab:e.tab}:e.area===`assets`?{tab:`assets`}:Tc.includes(e.area)?{tab:e.area}:null}function Dc(e,t){let n=new Set(e.map(e=>`${e.id}@${e.at}`));return t.filter(e=>!n.has(`${e.id}@${e.at}`)).length}function Oc(e){let t=e.entries.length+e.earlier,n=e.earlier>0?`Showing the newest ${e.entries.length} of ${t}`:`${t} entr${t===1?`y`:`ies`}`;return e.dropped>0?`${n} · Earlier entries were removed`:n}function kc(e,t){let n=e.by===`user`?`added by you`:e.by===`agent`?`by the agent`:`by Rushes`;return`${e.text} (${Gi[e.area]}, ${t}, ${n})`}function Ac(e,t){let n=typeof t?.status==`number`?t.status:null,r=`Run rushes doctor to see why.`;return n===null?`${e===`read`?`The Change Log couldn't be loaded`:e===`add`?`That line wasn't added`:`The Markdown wasn't saved`}: Rushes didn't answer. Check it's still running, then try again.`:e===`add`?n<500?`That line wasn't added: it needs a few words of text.`:`That line wasn't added: the Change Log couldn't be written. ${r}`:e===`export`?`The Markdown wasn't saved: the Change Log couldn't be read or written. ${r}`:n<500?`The Change Log couldn't show that filter. Choose All and try again.`:`The Change Log couldn't be read. ${r}`}function jc(e,t){if(!e||e===t)return!1;if(!t)return!0;let n=e=>Date.parse(e.slice(e.lastIndexOf(`@`)+1)),r=n(e),i=n(t);return!(Number.isFinite(r)&&Number.isFinite(i)&&r<i)}function Mc(e,t){return`rushes:${e}:${t}`}function Nc(e,t){try{return e?.getItem(t)??null}catch{return null}}function Pc(e,t,n){try{e?.setItem(t,n)}catch{}}var Fc=1e3,Ic=40,Lc=()=>{try{return window.sessionStorage}catch{return}},Rc=()=>{try{return window.localStorage}catch{return}};function zc(e,t){let[n,r]=q(()=>Nc(Lc(),Mc(e,`log-open`))===`1`),[i,a]=q(!1),[o,s]=q(()=>Nc(Rc(),Mc(e,`log-seen`))),c=t?.mark??null,l=X(o);l.current=o;let u=t=>{s(t),Pc(Rc(),Mc(e,`log-seen`),t)};return J(()=>{n&&c&&jc(c,o)&&u(c)},[n,c]),J(()=>{let t=Mc(e,`log-seen`),n=e=>{e.key===t&&e.newValue&&s(e.newValue)};return window.addEventListener(`storage`,n),()=>window.removeEventListener(`storage`,n)},[e]),{open:n,focusOnOpen:i,dot:!n&&jc(c,o),setOpen:t=>{r(t),a(t),Pc(Lc(),Mc(e,`log-open`),t?`1`:`0`)},saw:e=>{jc(e,l.current)&&u(e)}}}function Bc(){return Q(`svg`,{class:`ic`,viewBox:`0 0 24 24`,"aria-hidden":`true`,fill:`none`,stroke:`currentColor`,"stroke-width":`1.75`,"stroke-linecap":`round`,"stroke-linejoin":`round`,children:[Q(`path`,{d:`M3 12a9 9 0 1 0 3-6.7L3 8`}),Q(`path`,{d:`M3 3v5h5`}),Q(`path`,{d:`M12 7v5l3 2`})]})}function Vc({log:e,buttonRef:t}){return Q(`button`,{ref:t,type:`button`,class:`btn clog tip-below`,"data-tip":`Change Log`,"aria-label":e.dot?`Change Log (new entries)`:`Change Log`,"aria-expanded":e.open,"aria-controls":e.open?`changelog`:void 0,onClick:()=>e.setOpen(!e.open),children:[Q(Bc,{}),Q(`span`,{class:`clabel`,children:`Change Log`}),e.dot&&Q(`span`,{class:`cdot`,"aria-hidden":`true`})]})}function Hc(e){let t=0,n=()=>{let r=document.querySelector(`.lane[data-row="${CSS.escape(e)}"] .nm`);if(r){r.scrollIntoView({block:`nearest`}),r.focus({preventScroll:!0});return}++t<60&&requestAnimationFrame(n)};requestAnimationFrame(n)}function Uc(e){return e.log.open?Q(Gc,{...e}):null}function Wc({entry:e,to:t,onGo:n}){let r=Zi(new Date(e.at)),i=Q(S,{children:[Q(`span`,{class:`ltime`,children:r}),Q(`span`,{class:`ltag ${e.area}`,children:Gi[e.area]}),Q(`span`,{class:`ltext`,dir:`auto`,children:[e.text,Q(`span`,{class:`lby`,children:bc[e.by]})]}),Q(`span`,{class:`lgo`,"aria-hidden":`true`,children:t?`›`:``})]});return t?Q(`button`,{type:`button`,class:`lrow`,"data-entry":e.id,"data-go":``,"aria-label":kc(e,r),onClick:()=>n(t),children:i}):Q(`div`,{class:`lrow`,"data-entry":e.id,children:i})}function Gc({log:e,projectId:t,head:n,project:r,stage:i,header:a,buttonRef:o,toast:s,onJump:c}){let[l,u]=q(null),[d,f]=q(null),[p,m]=q(null),[h,g]=q(()=>{let e=Nc(Lc(),Mc(t,`log-filter`));return yc(e)?e:`all`}),[_,v]=q(``),y=X(null),b=X(null),x=X(null),S=X({}),C=X(null);C.current=l;let w=X(h);w.current=h;let T=X(0),E=()=>(b.current?.scrollTop??0)>Ic,D=t=>{u(t),f(null),w.current===`all`&&t.entries[0]&&e.saw(`${t.entries[0].id}@${t.entries[0].at}`)},O=async(e=!1)=>{let t=++T.current,n=new URLSearchParams({limit:String(Fc)});w.current!==`all`&&n.set(`area`,w.current);try{let r=await Z.get(`/api/log?${n}`);if(t!==T.current)return;m(null),!e&&C.current&&E()?f(r):D(r)}catch(e){if(t!==T.current)return;C.current?s(Ac(`read`,e)):m(Ac(`read`,e))}};J(()=>{b.current&&(b.current.scrollTop=0),f(null),O(!0)},[h]);let k=X(!0);J(()=>{if(k.current){k.current=!1;return}O()},[n?.rev,n?.mark]),Y(()=>{let e=a.current;if(!e)return;let t=()=>{y.current&&(y.current.style.top=`${Math.max(0,Math.round(e.getBoundingClientRect().bottom))}px`)};t();let n=new ResizeObserver(t);return n.observe(e),window.addEventListener(`resize`,t),window.addEventListener(`scroll`,t,{passive:!0}),()=>{n.disconnect(),window.removeEventListener(`resize`,t),window.removeEventListener(`scroll`,t)}},[]),Y(()=>{e.focusOnOpen&&x.current?.focus()},[]);let A=()=>{e.setOpen(!1),o.current?.focus()};Y(()=>{let e=e=>{if(e.key!==`Escape`||e.defaultPrevented)return;let t=e.target;(!t||t===document.body||t===document.documentElement||t===o.current||y.current?.contains(t))&&(e.preventDefault(),A())};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[]);let j=async()=>{let e=_.trim();if(e)try{if(await Z.post(`/api/log`,{text:e,area:i}),v(``),!Sc(h,i)){let e=Gi[i];s(`Added under ${e}. Choose All${vc.some(([e])=>e===i)?` or ${e}`:``} to see it.`)}b.current&&(b.current.scrollTop=0),await O(!0)}catch(e){s(Ac(`add`,e))}},M=e=>{g(e),Pc(Lc(),Mc(t,`log-filter`),e)},N=(e,t)=>{let n=sa(e.key,t,vc.length,!0);if(n===null)return;e.preventDefault();let r=vc[n][0];M(r),S.current[r]?.focus()},P=()=>{d&&(D(d),b.current&&(b.current.scrollTop=0),requestAnimationFrame(()=>{let e=b.current?.querySelector(`.lrow`);(e instanceof HTMLButtonElement?e:b.current)?.focus({preventScroll:!0})}))},F=()=>{d&&!E()&&D(d)},I=t=>{c(t),window.innerWidth<560&&(e.setOpen(!1),o.current?.focus())},L=X(I);L.current=I;let ee=X(e=>L.current(e)).current,te=async()=>{try{s(`Saved to ${(await Z.post(`/api/exports/change-log`,{})).path}`)}catch(e){s(Ac(`export`,e))}},R=yr(()=>l?xc(l.entries,new Date).map(e=>Q(`div`,{class:`dgroup`,children:[Q(`h3`,{class:`dday`,children:e.heading}),Q(`ul`,{children:e.entries.map(e=>Q(`li`,{children:Q(Wc,{entry:e,to:Ec(e,r),onGo:ee})},e.id))})]},e.key)):null,[l,r,Qi(new Date)]),ne=l&&d?Dc(l.entries,d.entries):0,re=l!==null&&l.total===0&&l.undated.length===0,ie=l!==null&&!re&&l.entries.length===0&&l.undated.length===0;return Q(`aside`,{id:`changelog`,class:`drawer`,ref:y,"aria-label":`Change Log`,onKeyDown:e=>{wc(e)&&e.stopPropagation()},children:[Q(`div`,{class:`dhead`,children:[Q(`h2`,{children:`Change Log`}),Q(`span`,{class:`dquiet`,children:`newest first`}),Q(`button`,{type:`button`,class:`btn dclose`,"aria-label":`Close the change log`,onClick:A,children:`Close`})]}),Q(`form`,{class:`dadd`,onSubmit:e=>{e.preventDefault(),j()},children:[Q(`input`,{ref:x,value:_,maxLength:160,placeholder:`Add a line to the log`,"aria-label":`Add a line to the log`,onInput:e=>v(e.target.value)}),Q(`button`,{type:`submit`,class:`btn`,children:`Add`})]}),Q(`div`,{class:`dchips`,role:`radiogroup`,"aria-label":`Show`,children:vc.map(([e,t],n)=>Q(`button`,{type:`button`,role:`radio`,"aria-checked":h===e,tabIndex:h===e?0:-1,ref:t=>{S.current[e]=t},onClick:()=>M(e),onKeyDown:e=>N(e,n),children:t}))}),Q(`div`,{class:`dwrap`,children:[ne>0&&Q(`button`,{type:`button`,class:`dpill`,onClick:P,children:[ne,` new`]}),Q(`div`,{class:`dlist`,ref:b,tabIndex:0,role:`group`,"aria-label":`Entries`,onScroll:F,children:[l===null&&!p&&Q(`p`,{class:`dempty`,children:`Loading…`}),l===null&&p&&Q(`p`,{class:`dempty dproblem`,role:`alert`,children:p}),re&&Q(`p`,{class:`dempty`,children:`Nothing yet. Rushes writes a line here whenever a cut, a take or a variant is added.`}),ie&&Q(`p`,{class:`dempty`,children:`Nothing for this filter.`}),R,l&&l.undated.length>0&&Q(`section`,{class:`dbefore`,"aria-label":`Before the log`,children:[Q(`h3`,{children:`Before the log`}),Q(`ul`,{children:l.undated.map((e,t)=>Q(`li`,{children:e.text},t))})]})]})]}),Q(`div`,{class:`dfoot`,children:[Q(`span`,{children:l?Oc(l):``}),Q(`button`,{type:`button`,class:`btn`,onClick:()=>void te(),children:`Export as Markdown`})]})]})}var Kc=[`script`,`picture`,`voice`,`music`,`sfx`,`mix`],qc=e=>e instanceof HTMLElement&&(e.isContentEditable||/^(INPUT|TEXTAREA|SELECT)$/.test(e.tagName));function Jc({tab:e,projectName:t,filmName:n,found:r,onReview:i,toast:a}){let o=e===`brief`||e===`storyboard`,{what:s,unlocks:c}=e===`brief`?Me:e===`storyboard`?Ne:Ee[e],l=e===`assets`?`Assets`:e===`brief`?`Brief`:e===`storyboard`?`Storyboard`:Te[e],u=e===`assets`?`grid`:e===`brief`?`brief`:e===`storyboard`?`story`:da[e],d=e===`brief`?Pe(t,n):e===`storyboard`?Fe(t,n):Oe(e,t,n),f=o?null:On(e,r),p=X(null),m=async()=>{try{await navigator.clipboard.writeText(d),a(`Prompt copied`)}catch{p.current?.select(),a(`Prompt selected: press ${Cn(navigator.platform)}`)}};return Q(`div`,{class:`empty locked`,children:[Q($,{name:u}),Q(`h2`,{children:l}),Q(`p`,{children:s}),Q(`p`,{children:c}),Q(`textarea`,{class:`promptbox mono`,readOnly:!0,rows:4,ref:p,value:d,"aria-label":`Prompt for your agent`}),Q(`button`,{class:`btn primary`,onClick:()=>void m(),children:[Q($,{name:`copy`}),`Copy prompt for your agent`]}),f&&Q(`p`,{class:`foundline`,children:[Q(`span`,{children:f.text}),Q(`button`,{type:`button`,class:`btn`,"aria-label":f.review,onClick:()=>i(f.kind),children:`Review`})]})]})}function Yc(){let{state:e,assets:t,problem:n,wrongProject:r,refresh:i,proxyJobs:a,noteProxyJob:o}=Gr(),[s,c]=q(null),[l,u]=q(null),[d,f]=q(null),[p,m]=q(null),[h,g]=q(null),[_,v]=q(`script`),y=X(null),[b,x]=q(!1),[C,w]=q(!1),[T,E]=q(!1),[D,O]=q(!1),[k,A]=q(0),[j,M]=q({}),N=X(void 0),P=X(new Map),F=X(null),I=(e,t)=>M(n=>({...n,[e]:t})),[L,ee]=q({}),te=(e,t)=>ee(n=>({...n,[e]:t})),[R,ne]=q({}),[re,ie]=q({}),[ae,oe]=q(!1),z=X(new Set),B=(e,t=2400)=>{m(e),clearTimeout(N.current),N.current=window.setTimeout(()=>m(null),t)},[se,ce]=q({n:0,pending:!1}),[le,ue]=q(null),V=zc(Ar()??``,e?.log),de=X(null);J(()=>{for(let e of Object.values(a))e.state!==`failed`||z.current.has(e.job)||(z.current.add(e.job),B(e.reason??`Couldn't make the proxy`))},[a]),J(()=>{if(e){if(s===null){let t=Be(e.tabs,e.brief);c(t),Ae(t)&&v(t)}l===null&&e.project.videos[0]&&u(e.project.videos[0].id)}},[e]),J(()=>{e?.project.name&&(document.title=`${e.project.name} · Rushes`)},[e?.project.name]);let H=e?.project.videos.find(e=>e.id===l)??e?.project.videos[0],U=Se(H),me=Ce(H),W=H?.versions.find(e=>e.id===d)??me,he=!!H?.lockedVersion,_e=W?.fps??e?.project.fps??30,ve=W?t.find(e=>e.kind===`cut`&&e.path===W.file):void 0,ye=e?.notes.notes.filter(e=>e.stage===`picture`&&(!e.video||e.video===H?.id))??[],be=W?pe(W,re[W.file]):[],xe=H&&W?Un(H,W.id):void 0,G=Wn(be,H?R[H.id]:void 0),De=new Set(t.filter(e=>e.kind===`cut`&&e.missing).map(e=>e.path)),Oe=W?Gn({views:be,previous:xe?pe(xe):[],current:G,versionDuration:W.duration,notes:ye,missing:De}):[],ke=e=>!H||e===G?!1:ae?(B(`Add or clear your box on ${G?fe(G):`this format`} first`),!1):(ne(t=>({...t,[H.id]:e})),!0);J(()=>{T&&d===null&&me?(f(me.id),O(!0)):!T&&D&&d===me?.id&&(f(null),O(!1))},[T,d,me?.id]),J(()=>{!D&&d!==null&&d===me?.id&&f(null)},[me?.id,D,d]);let Pe=U&&W&&U.id!==W.id&&(he||D)?U.id:null,Fe=()=>{U&&f(U.id),O(!1)},ze=e=>{if(!H||e===H.id)return;if(T)return B(`Add or clear your note on ${H.name} first`);let t=F.current;t?.pause();let n=t?ge(t.currentTime,_e):P.current.get(H.id)?.t??0;P.current.set(H.id,{versionId:d,held:D,t:n});let r=P.current.get(e);u(e),f(r?.versionId??null),O(r?.held??!1),A(r?.t??0)},He=async()=>{if(H&&W)try{await Z.put(`/api/videos/${H.id}/lock`,{version:H.lockedVersion?null:W.id}),i()}catch(e){B(e.message)}},Ue=t=>{if(T)return B(`Add or clear your note first`);if(t.tab===`assets`)return Xe();if(t.video&&t.video!==H?.id&&ze(t.video),t.version){let n=e?.project.videos.find(e=>e.id===(t.video??H?.id));f(t.version===Ce(n)?.id?null:t.version),O(!1)}c(t.tab),g(null),t.row&&Hc(t.row)},We=e?.tabs??[],Ge=e=>We.find(t=>t.stage===e),Ke=kn(e?.found),qe=t.length>0||Ke!==null,Je=e=>{if(T&&e!==s)return B(`Add or clear your note first`);c(e),g(null),Ae(e)&&v(e)},Ye=()=>{let t={brief:!!e?.brief.exists,script:!!Ge(`script`)?.unlocked,storyboard:!!e?.storyboard.exists};Je(Ve(_,t))},Xe=()=>{if(T&&s!==`assets`)return B(`Add or clear your note first`);c(`assets`),g(null)},Ze=e=>{if(T&&s!==`assets`)return B(`Add or clear your note first`);ce(t=>({n:t.n+1,kind:e,pending:!0})),c(`assets`),g(null)},Qe=X(Ze);Qe.current=Ze,J(()=>{Rt(location.search).test&&(window.__rushesOpenFound=e=>Qe.current(e))},[]),Y(()=>{let t=t=>{if(t.altKey&&!t.metaKey&&!t.ctrlKey&&!t.shiftKey&&(t.key===`ArrowLeft`||t.key===`ArrowRight`)){if(s!==`picture`||qc(t.target))return;t.preventDefault();let e=Kn(Oe,G,t.key===`ArrowRight`?1:-1);e&&ke(e);return}if(qc(t.target)||t.metaKey||t.ctrlKey||t.altKey)return;let n=Number(t.key);if(n===1?Ye():n>=2&&n<=6?Je(Kc[n-1]):n===7&&Xe(),(t.key===`[`||t.key===`]`)&&e){let n=we(e.project.videos,l,t.key===`]`?1:-1);n&&ze(n)}t.key===`?`&&x(e=>!e),t.key===`Escape`&&(x(!1),g(null))};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)});let $e=X(null),et=X(null),tt=X(null),nt=()=>{let e=$e.current;if(!e)return;let t=`${Math.round(e.getBoundingClientRect().top+window.scrollY)}px`,n=document.documentElement.style;n.getPropertyValue(`--body-top`)!==t&&n.setProperty(`--body-top`,t)};Y(nt),J(()=>{let e=()=>nt();window.addEventListener(`resize`,e);let t=!0;return document.fonts?.ready.then(()=>{t&&nt()}),()=>{t=!1,window.removeEventListener(`resize`,e)}},[]);let rt=!!e&&!!s;J(()=>{if(!rt)return;let e=new ResizeObserver(()=>nt());for(let t of[et.current,tt.current])t&&e.observe(t,{box:`border-box`});return()=>e.disconnect()},[rt]);let it=async()=>{if(s&&s!==`assets`){if(x(!1),s===`brief`){if(!e)return;if(!e.brief.exists)return B(`There's no brief yet: copy the prompt on this page for your agent`);let t=await y.current?.()??e.brief;g({id:`brief`,title:`Message for your agent`,prompt:Le(e.project.name,H?.name??null,t)}),w(!1);return}if(s===`storyboard`){if(!e)return;if(!e.storyboard.exists)return B(`There's no storyboard yet: copy the prompt on this page for your agent`);let t=await y.current?.()??e.storyboard;g({id:`storyboard`,title:`Message for your agent`,prompt:Re(e.project.name,H?.name??null,t)}),w(!1);return}try{let{batch:e}=await Z.post(`/api/batches`,{stage:s});g(e),w(!1),i()}catch(e){B(e instanceof kr&&e.code===`empty_batch`?`Nothing open on ${Te[s]} to send`:e.message)}}},at=async()=>{if(h)try{await navigator.clipboard.writeText(h.prompt),w(!0)}catch{B(`Couldn't reach the clipboard. Select the text and copy it.`)}};if(!e||!s)return Q(`div`,{class:`shell`,children:n?Q(`div`,{class:`banner`,children:[Q($,{name:`alert`}),n]}):Q(`div`,{class:`empty`,children:Q(`p`,{children:`Loading…`})})});let ot=e.notes.notes.filter(e=>e.stage===`picture`&&(!e.video||e.video===H?.id)),st=t=>e.notes.notes.some(e=>e.stage===`picture`&&e.status===`todo`&&(!e.video||e.video===t)),ct=s===`assets`?qe:s===`brief`?e.brief.exists:s===`storyboard`?e.storyboard.exists:Ge(s)?.unlocked??!1,lt=s===`assets`?0:s===`brief`?e.brief.changed:s===`storyboard`?e.storyboard.changed:Ge(s)?.todo??0,ut=!!Ge(`picture`)?.unlocked,dt=je(e.brief,e.script.sections,e.storyboard),ft=e.build.started&&!ut,pt=[{page:`brief`,name:`Brief`,icon:`brief`,unlocked:e.brief.exists,progress:ft?dt.brief:null,ask:Me.ask},{page:`script`,name:`Script`,icon:da.script,unlocked:!!Ge(`script`)?.unlocked,progress:ft&&Ge(`script`)?.unlocked?dt.script:null,ask:Ee.script.ask},{page:`storyboard`,name:`Storyboard`,icon:`story`,unlocked:e.storyboard.exists,progress:ft&&e.storyboard.exists?dt.storyboard:null,ask:Ne.ask}],mt=e.brief.changed+e.storyboard.changed+(Ge(`script`)?.todo??0),ht=async()=>{try{await navigator.clipboard.writeText(Ie(e.project.name,H?.name??null)),B(`Prompt copied`)}catch{B(`Couldn't reach the clipboard. Ask your agent to build the film from the approved plan.`)}};return Q(`div`,{class:`shell`,children:[Q(`header`,{class:`head`,ref:et,children:[Q(`span`,{class:`logo`,children:Q(`svg`,{viewBox:`0 0 24 24`,children:Q(`path`,{d:`M8 5v14l11-7z`})})}),Q(`nav`,{class:`crumb`,"aria-label":`Project`,children:[Q(`span`,{children:e.project.name}),e.project.id&&Q(`span`,{class:`pid mono`,children:e.project.id}),H&&e.project.videos.length===1&&Q(S,{children:[Q(`span`,{class:`slash`,children:`/`}),Q(`span`,{class:`sel`,children:H.name})]})]}),Ke!==null&&An(e.found)!==le&&Q(`button`,{type:`button`,class:`foundchip`,"data-tip":`Open the other files found in this project`,onClick:()=>Ze(),children:[Q(`span`,{class:`dot`}),Q(`span`,{class:`ftext`,children:Ke})]}),H&&e.project.videos.length>1&&Q(`nav`,{class:`pack`,"aria-label":`Films`,children:e.project.videos.map((e,t)=>Q(`button`,{class:`pill`,"aria-pressed":e.id===H.id,onClick:()=>ze(e.id),children:[Q(`span`,{class:`n`,children:t+1}),Q(`span`,{class:`pname`,children:e.name}),st(e.id)&&Q(`span`,{class:`dot`})]}))}),H&&Q(S,{children:[Q(`span`,{class:`plabel`,children:`Picture`}),W&&Q(Bs,{versions:H.versions,shown:W,lockedVersion:H.lockedVersion,onPick:e=>{f(e===me?.id?null:e),O(!1)}}),W&&Q(`button`,{class:`btn ib lockbtn`,"aria-pressed":he,"aria-label":he?`Picture locked at ${H.lockedVersion} · unlock`:`Lock picture at ${W.id}`,"data-tip":he?`Picture locked at ${H.lockedVersion} · unlock`:`Lock picture at ${W.id}`,onClick:()=>void He(),children:Q($,{name:he?`lock`:`unlock`})}),Pe&&Q(`button`,{class:`chipx go`,"aria-label":`${Pe} is ready`,"data-tip":`Switch to the newest cut`,onClick:Fe,children:[Q($,{name:`new`}),Pe,` ready`]}),s===`picture`&&W&&Oe.length>0&&Q(ro,{chips:Oe,versionId:W.id,prompt:Xn(e.project.name,H.name,W.id),onSelect:ke,toast:B})]}),Q(`span`,{class:`sp`}),Q(`button`,{class:`btn ghost ib tip-below`,"data-tip":`Shortcuts ?`,"aria-label":`Keyboard shortcuts`,onClick:()=>{g(null),x(!b)},children:Q($,{name:`kbd`})}),Q(Vc,{log:V,buttonRef:de}),Q(`button`,{class:`btn primary`,"aria-disabled":s===`assets`,tabIndex:s===`assets`?-1:void 0,"data-tip":s===`assets`?`Nothing to send from Assets`:void 0,onClick:()=>void it(),children:[`Send to agent`,lt>0&&Q(`span`,{class:`count`,children:lt})]})]}),Q(Uc,{log:V,projectId:Ar()??``,head:e.log,project:e.project,stage:s===`brief`||s===`storyboard`?`script`:s,header:et,buttonRef:de,toast:B,onJump:Ue}),h&&Q(`div`,{class:`pop`,role:`dialog`,"aria-label":`Sent to agent`,children:[Q(`div`,{style:{display:`flex`,alignItems:`center`,gap:`8px`},children:[Q(`h3`,{children:h.title??`Batch ${h.id} is ready`}),Q(`span`,{class:`sp`}),Q(`button`,{class:`btn ghost ib sm`,"aria-label":`Close`,onClick:()=>g(null),children:Q($,{name:`x`})})]}),Q(`pre`,{children:h.prompt}),Q(`div`,{style:{display:`flex`,justifyContent:`flex-end`},children:Q(`button`,{class:`btn primary`,onClick:()=>void at(),children:[Q($,{name:`copy`}),C?`Copied`:`Copy prompt`]})})]}),b&&Q(`div`,{class:`pop`,role:`dialog`,"aria-label":`Keyboard shortcuts`,style:{width:`300px`},children:[Q(`div`,{style:{display:`flex`,alignItems:`center`},children:[Q(`h3`,{children:`Shortcuts`}),Q(`span`,{class:`sp`}),Q(`button`,{class:`btn ghost ib sm`,"aria-label":`Close`,onClick:()=>x(!1),children:Q($,{name:`x`})})]}),Q(`div`,{class:`keys`,children:[Q(`span`,{children:Q(`kbd`,{children:`Space`})}),Q(`span`,{children:`Play or pause`}),Q(`span`,{children:[Q(`kbd`,{children:`←`}),` `,Q(`kbd`,{children:`→`})]}),Q(`span`,{children:`Step one frame (Shift: ten)`}),Q(`span`,{children:[Q(`kbd`,{children:`I`}),` `,Q(`kbd`,{children:`O`})]}),Q(`span`,{children:`Set in and out`}),Q(`span`,{children:Q(`kbd`,{children:`B`})}),Q(`span`,{children:`Draw a box`}),Q(`span`,{children:Q(`kbd`,{children:`G`})}),Q(`span`,{children:`Grab frame`}),Q(`span`,{children:Q(`kbd`,{children:`N`})}),Q(`span`,{children:`New note`}),Q(`span`,{children:[Q(`kbd`,{children:`1`}),`–`,Q(`kbd`,{children:`7`})]}),Q(`span`,{children:`Switch tab`}),Q(`span`,{children:[Q(`kbd`,{children:`[`}),` `,Q(`kbd`,{children:`]`})]}),Q(`span`,{children:`Previous or next film`}),Q(`span`,{children:[Q(`kbd`,{children:`Alt`}),` `,Q(`kbd`,{children:`←`}),` `,Q(`kbd`,{children:`→`})]}),Q(`span`,{children:`Previous or next format`}),Q(`span`,{children:Q(`kbd`,{children:`?`})}),Q(`span`,{children:`Shortcuts`}),Q(`span`,{children:Q(`kbd`,{children:`Esc`})}),Q(`span`,{children:`Close`})]})]}),p&&Q(`div`,{class:`toast`,role:`status`,children:p}),r&&Q(`div`,{class:`banner lost`,role:`alert`,children:[Q($,{name:`alert`}),`This tab is for ${e.project.name}, which isn't running here any more. Ask your agent to open it again.`]}),Q(`nav`,{class:`tabs`,ref:tt,role:`tablist`,"aria-label":`Stages`,children:[Q($s,{selected:Ae(s)?s:null,rows:pt,marks:ft?dt:null,open:mt,locked:pt.every(e=>!e.unlocked),ready:ft&&e.build.ready,onCopyReady:()=>void ht(),onPick:e=>Je(e)}),Kc.filter(e=>e!==`script`).map(e=>{let t=Ge(e);return Q(`button`,{class:`tab`,role:`tab`,"aria-selected":s===e,"data-locked":t?.unlocked?void 0:`true`,"data-tip":t?.unlocked?void 0:`Locked: ask your agent for ${Ee[e].ask}`,onClick:()=>Je(e),children:[Q($,{name:da[e]}),Te[e],t?.unlocked?t.todo>0&&Q(`span`,{class:`dot`,title:`${t.todo} open`}):Q(S,{children:[Q($,{name:`lock`,class:`lk`}),Q(`span`,{class:`vh`,children:` Locked`})]})]})}),Q(`button`,{class:`tab`,role:`tab`,"aria-selected":s===`assets`,"data-locked":qe?void 0:`true`,"data-tip":qe?void 0:`Locked: ask your agent for ${Ee.assets.ask}`,onClick:()=>Xe(),children:[Q($,{name:`grid`}),`Assets`,!qe&&Q(S,{children:[Q($,{name:`lock`,class:`lk`}),Q(`span`,{class:`vh`,children:` Locked`})]})]})]}),n&&!r&&Q(`div`,{class:`banner`,children:[Q($,{name:`alert`}),n]}),Q(`main`,{class:`body`,ref:$e,children:s===`assets`?ct?Q(Ja,{assets:t,videos:e.project.videos,state:e,foundRequest:se,onFoundRequestUsed:()=>ce(e=>e.pending?{n:e.n,pending:!1}:e),onFoundSeen:ue,toast:B,onChanged:()=>void i()}):Q(Jc,{tab:`assets`,projectName:e.project.name,filmName:H?.name??null,found:e.found?.counts,onReview:Ze,toast:B}):ct?s===`picture`&&H&&W?Q(Ws,{video:H,version:W,fps:_e,notes:ot,toast:B,onChanged:()=>void i(),onPendingChange:E,startAt:k,grab:j[H.id]??null,onGrabChange:I,playerRef:F,ffmpeg:e.proxies?.ffmpeg??!1,autoProxy:e.project.autoProxy,proxyJob:a[gn(H.id,W.id)],noteProxyJob:o,source:L[H.id]??`proxy`,onSourceChange:te,fileSize:ve?.size??null,fileRev:ve?qr(ve):void 0,formats:be,format:G,formatMissing:!!G&&De.has(be.find(e=>e.id===G)?.file??``),onPrimarySize:(e,t,n)=>ie(r=>r[e]?r:{...r,[e]:{width:t,height:n}}),onBoxPendingChange:oe,onFormatChange:ke},H.id):s===`brief`?Q(to,{brief:e.brief,toast:B,onChanged:()=>void i(),settle:y}):s===`storyboard`?Q(Qs,{board:e.storyboard,brief:e.brief,toast:B,onChanged:()=>void i(),settle:y}):s===`script`?Q(ic,{script:e.script,toast:B,onChanged:()=>void i()}):s===`voice`?Q(_c,{state:e,assets:t,video:H??null,toast:B,onChanged:()=>void i(),onPendingChange:E},`voice`):s===`mix`?Q(cs,{state:e,assets:t,video:H??null,toast:B,onChanged:()=>void i(),onPendingChange:E},`mix`):s===`music`||s===`sfx`?Q(lc,{stage:s,state:e,assets:t,video:H??null,toast:B,onChanged:()=>void i(),onPendingChange:E},s):null:Q(Jc,{tab:s,projectName:e.project.name,filmName:H?.name??null,found:e.found?.counts,onReview:Ze,toast:B})})]})}Ft(document),ae(Q(Yc,{}),document.getElementById(`app`));
|
|
7
|
+
`)!==n?{refuse:`the agent changed the brief while you were looking at it. Read it again, then approve.`}:{path:`/api/brief/status`,body:{status:t}})}},s=e.status===`approved`;return Q(`div`,{class:`col`,children:[Q(`div`,{class:`shead`,children:[Q(`h2`,{children:`Brief`}),Q(`span`,{class:`meta`,children:[e.title,e.title&&e.sections.length>0?` · `:``,e.sections.length>0&&`${e.sections.length} section${e.sections.length===1?``:`s`} · ${e.changed} changed`]})]}),e.sections.length===0&&Q(`p`,{class:`sbnone`,children:"brief.md has no ## sections yet. Your agent adds them as `## Purpose`, `## Audience` and so on."}),Q(`div`,{class:`sgrid bgrid scols`,children:[Q(`span`,{}),Q(`span`,{children:`Current`}),Q(`span`,{children:`Yours`})]}),Q(`div`,{style:{display:`grid`,gap:`12px`},children:e.sections.map(t=>Q($a,{section:t,save:o},`${t.heading}#${eo(e.sections,t.index)}`))}),Q(`div`,{class:`bfoot`,children:Q(`button`,{class:`btn bapprove${s?` approved`:``}`,"aria-pressed":s,onClick:()=>o.status(s?`draft`:`approved`),children:[Q($,{name:`check`}),s?`Approved`:`Approve brief`]})})]})}var no=150;function ro({chips:e,versionId:t,prompt:n,onSelect:r,toast:i}){let a=X(null),o=e.some(e=>e.reason===`single`),s=e.filter(e=>e.enabled),c=e.find(e=>e.selected)?.id??null;Y(()=>{let e=a.current,t=document.activeElement;if(!e||!c||!(t instanceof HTMLElement)||!e.contains(t))return;let n=e.querySelector(`[data-format="${c}"]`);n&&n!==t&&n.focus()},[c]);let[l,u]=q(!1),[d,f]=q(!1),[p,m]=q(!1),[h,g]=q(!1),_=X(void 0),v=X(!1),y=()=>{clearTimeout(_.current),u(!0),m(!1)},b=()=>{clearTimeout(_.current),_.current=window.setTimeout(()=>u(!1),no)};J(()=>()=>clearTimeout(_.current),[]);let x=o&&(l||d)&&!p&&!h;if(J(()=>{if(!x)return;let e=e=>{e.key===`Escape`&&m(!0)};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[x]),e.length===0)return null;let S=e=>{if(e.altKey||e.metaKey||e.ctrlKey||s.length===0)return;let t=Math.max(0,s.findIndex(e=>e.selected)),n=null;e.key===`ArrowRight`||e.key===`ArrowDown`?n=(t+1)%s.length:e.key===`ArrowLeft`||e.key===`ArrowUp`?n=(t-1+s.length)%s.length:e.key===`Home`?n=0:e.key===`End`&&(n=s.length-1),n!==null&&(e.preventDefault(),e.stopPropagation(),r(s[n].id)!==!1&&a.current?.querySelector(`[data-format="${s[n].id}"]`)?.focus())},C=async()=>{try{await navigator.clipboard.writeText(n),i(`Prompt copied`)}catch{i(`Couldn't reach the clipboard. Ask your agent to register the other shapes with rushes_add_format.`)}};return Q(`div`,{class:`fmtwrap`,children:[Q(`div`,{ref:a,class:`fmts`,role:`radiogroup`,"aria-label":`Format`,style:{gridTemplateColumns:Yn(e.length)},onKeyDown:e=>S(e),children:e.map(e=>{let n=Jn(e.width,e.height),i=e.reason===`absent`?`Not in ${t}`:e.warn??void 0,a=e.reason===`single`;return Q(`button`,{type:`button`,role:`radio`,"data-format":e.id,"aria-checked":e.selected,"aria-disabled":e.enabled?void 0:`true`,tabIndex:e.enabled&&e.selected?0:-1,"aria-label":qn(e,t),class:i?`tip-below`:void 0,"data-tip":i,onMouseEnter:a?y:()=>g(!0),onMouseLeave:a?b:()=>g(!1),onClick:t=>{e.enabled&&(t.detail>0&&t.currentTarget.blur(),r(e.id))},children:[Q(`span`,{class:`shape`,"aria-hidden":`true`,style:{width:`${n.width}px`,height:`${n.height}px`}}),Q(`span`,{class:`lbl`,"data-label":e.label,children:e.label}),e.warn&&Q(`span`,{class:`warn`,"aria-hidden":`true`,children:`!`}),!o&&Q(`span`,{class:`n${e.count>0?``:` none`}`,"aria-hidden":`true`,children:e.count>0?e.count:``})]},e.id)})}),o&&Q(`div`,{class:`fmtpop${x?` open`:``}`,onMouseEnter:y,onMouseLeave:b,children:[Q(`p`,{children:[`One format. Your agent can add more with `,Q(`code`,{children:`rushes_add_format`}),`.`]}),Q(`button`,{type:`button`,class:`btn ghost`,onPointerDown:()=>{v.current=!0},onFocus:()=>{v.current||f(!0),v.current=!1},onBlur:()=>{f(!1),m(!1)},onClick:e=>{v.current=!1,e.detail>0&&e.currentTarget.blur(),C()},children:[Q($,{name:`copy`}),`Copy a prompt for your agent`]})]})]})}var io=.03,ao=.004,oo=15e3;function so(e){return e.buffer?e.buffer.length*e.buffer.numberOfChannels*4:0}var co=0;function lo(){return co}var uo=new Map;function fo(e){let t=uo.get(e);return t&&(uo.delete(e),uo.set(e,t)),t}function po(e,t){for(uo.delete(e),uo.set(e,t);uo.size>200;)uo.delete(uo.keys().next().value)}function mo(){let e=Error(`The load was cancelled`);return e.name=`AbortError`,e}function ho(e){return(t,n)=>new Promise(r=>{let i=e(t),a,o=!1,s=e=>{o||(o=!0,clearTimeout(a),n.removeEventListener(`abort`,c),i.removeAttribute(`src`),i.load(),r(e))},c=()=>s(null);if(n.aborted)return s(null);n.addEventListener(`abort`,c),i.preload=`metadata`,i.addEventListener(`loadedmetadata`,()=>s(Number.isFinite(i.duration)?i.duration:null),{once:!0}),i.addEventListener(`error`,()=>s(null),{once:!0}),a=setTimeout(()=>s(null),oo)})}var go=class{ctx=null;disposed=!1;opts;clips=[];videoDuration=null;media=new Map;loads=new Map;idle=new Map;holding=new Map;selection={};laneTargets={};laneNodes=new Map;clipNodes=new Map;voices=new Map;serials=new WeakMap;serial=0;_playing=!1;startOffset=0;startedAt=0;frame=null;tickListeners=new Set;endedListeners=new Set;changeListeners=new Set;constructor(e,t={}){let n=t.createMedia??(e=>new Audio(e));this.opts={createContext:t.createContext??(()=>new AudioContext),url:t.url??Nr,fetch:t.fetch??((e,t)=>fetch(e,t)),probe:t.probe??ho(n),createMedia:n,raf:t.raf??(e=>requestAnimationFrame(e)),caf:t.caf??(e=>cancelAnimationFrame(e))},e&&(this.ctx=e,co++)}get playing(){return this._playing}get time(){if(!this._playing||!this.ctx)return this.startOffset;let e=this.startOffset+Math.max(0,this.ctx.currentTime-this.startedAt),t=this.length;return t>0?Math.min(e,t):e}get length(){return di(this.videoDuration,this.resolved())}inspect(){return{playing:this._playing,time:this.time,length:this.length,sources:this.voices.size,gains:$r(this.clips,this.selection),lanes:{...this.laneTargets},media:[...this.media.keys()],streamed:[...this.media].filter(([,e])=>e.streamed).map(([e])=>e),idle:[...this.idle.keys()],voices:Object.fromEntries([...this.voices].map(([e,t])=>[e,this.serials.get(t)??0]))}}onTick(e){return this.tickListeners.add(e),()=>this.tickListeners.delete(e)}onEnded(e){return this.endedListeners.add(e),()=>this.endedListeners.delete(e)}onChange(e){return this.changeListeners.add(e),()=>this.changeListeners.delete(e)}subscribe(e){let t=this.onTick(e),n=this.onChange(()=>e(this.time));return()=>{t(),n()}}load(e,t){if(this.disposed)return Promise.reject(Error(`The audio engine was disposed`));let n=Kr({path:e,rev:t}),r=this.loads.get(n)??this.idle.get(n)?.load;if(r)return r.promise;let i=new AbortController,a=this.loadOnce(e,n,i.signal),o={path:e,promise:a,abort:i};return this.loads.set(n,o),a.catch(()=>{this.loads.get(n)===o&&this.loads.delete(n);for(let e of this.clips)Kr(e)===n&&this.holding.delete(e.id)}),a}async loadOnce(e,t,n){let r=this.ensureContext(),i=this.opts.url(e),a=new AbortController,o=()=>a.abort();n.addEventListener(`abort`,o);let s=!1,c=()=>{s=!0,a.abort()},l=this.opts.probe(i,n).then(e=>(ai(e,!0)&&c(),e),()=>null),u=null;try{let e=await this.opts.fetch(i,{signal:a.signal});if(!e.ok)throw Error(`HTTP ${e.status}`);let t=e.headers?.get(`content-length`)??null;if(ci(t!==null&&Number.isFinite(Number(t))?Number(t):null)&&c(),!s){let t=await e.arrayBuffer();!s&&!n.aborted&&(u=await r.decodeAudioData(t))}}catch{u=null}finally{n.removeEventListener(`abort`,o)}if(n.aborted||this.disposed)throw mo();let d;if(u&&!ai(u.duration,!0)){let e=fo(t);if(!e){let n=[];for(let e=0;e<u.numberOfChannels;e++)n.push(u.getChannelData(e));e=ri(n,ii(u.duration)),po(t,e)}this.media.set(t,{duration:u.duration,buffer:u,streamed:!1}),d={duration:u.duration,peaks:e,streamed:!1}}else{let r=u?u.duration:await l;if(n.aborted||this.disposed)throw mo();if(r===null||!(r>0))throw Error(`Couldn't load ${e}`);this.media.set(t,{duration:r,buffer:null,streamed:!0}),d={duration:r,peaks:new Float32Array,streamed:!0}}return this.afterLoad(t),d}afterLoad(e){for(let t of this.clips)Kr(t)===e&&this.holding.delete(t.id);if(this._playing){for(let t of this.resolved())Kr(t)===e&&!this.voices.has(t.id)&&this.startLate(t);this.syncStreams(this.rawClock())}this.emitChange()}setClips(e){let t=new Map(e.map(e=>[e.id,e])),n=this.resolved(),r=new Map(this.clips.map(e=>[e.id,e]));for(let e of this.clips){let n=t.get(e.id);n&&n.lane===e.lane&&n.path===e.path&&n.rev===e.rev&&n.offset===e.offset&&n.duration===e.duration||this.dropClip(e.id)}for(let e of n){let n=t.get(e.id),i=r.get(e.id);n&&n.path===i.path&&n.rev!==i.rev&&e.duration>0&&this.holding.set(e.id,e.duration)}for(let e of[...this.holding.keys()])t.has(e)||this.holding.delete(e);let i=new Set(e.map(Kr)),a=new Set(e.map(e=>e.path));for(let[e,t]of this.loads){if(i.has(e))continue;let n=this.media.get(e);!n||a.has(t.path)?t.abort.abort():this.idle.set(e,{media:n,load:t}),this.loads.delete(e),this.media.delete(e)}for(let e of[...this.media.keys()])i.has(e)||this.media.delete(e);for(let[e,t]of this.idle)!i.has(e)&&a.has(t.load.path)&&this.idle.delete(e);for(let e of i){let t=this.idle.get(e);t&&(this.idle.delete(e),this.media.set(e,t.media),this.loads.set(e,t.load))}let o=0;for(let e of this.idle.values())o+=so(e.media);for(;this.idle.size>12||o>268435456;){let[e,t]=this.idle.entries().next().value;o-=so(t.media),this.idle.delete(e)}if(this.clips=e.slice(),this._playing){for(let e of this.resolved())this.voices.has(e.id)||this.startLate(e);this.syncStreams(this.rawClock())}this.emitChange()}setVideoDuration(e){this.videoDuration=e,this._playing||(this.startOffset=this.clampTime(this.startOffset)),this.emitChange()}setLaneGain(e,t){this.laneTargets[e]=t;let n=this.laneNodes.get(e);n&&this.ramp(n.gain,t)}selectVariant(e,t){t===null?delete this.selection[e]:this.selection[e]=t;let n=$r(this.clips,this.selection);for(let t of this.clips){if(t.lane!==e)continue;let r=this.clipNodes.get(t.id);r&&this.ramp(r.gain.gain,n[t.id])}}play(e=this.time){if(this.disposed)return;let t=this.ensureContext(),n=this.length;if(n<=0)return;let r=this.clampTime(e);r>=n&&(r=0),t.state===`suspended`&&t.resume().catch(()=>{}),pi(this,()=>this.pause()),this._playing=!0,this.restart(r),this.startLoop(),this.emitChange()}pause(){this._playing&&(this.startOffset=this.time,this._playing=!1,this.stopVoices(),this.pauseStreams(),this.stopLoop(),mi(this),this.emitChange())}seek(e){if(this.disposed)return;let t=this.clampTime(e);this._playing?this.restart(t):this.startOffset=t,this.emitChange()}dispose(){if(!this.disposed){this._playing=!1,this.stopLoop(),this.stopVoices();for(let e of this.loads.values())e.abort.abort();this.loads.clear(),this.idle.clear(),this.holding.clear();for(let e of[...this.clipNodes.keys()])this.dropClip(e);for(let e of this.laneNodes.values())e.disconnect();this.laneNodes.clear(),this.media.clear(),mi(this),this.tickListeners.clear(),this.endedListeners.clear(),this.changeListeners.clear(),this.disposed=!0,this.ctx&&(this.ctx.close().catch(()=>{}),this.ctx=null,co--)}}ensureContext(){if(this.disposed)throw Error(`The audio engine was disposed`);return this.ctx||(this.ctx=this.opts.createContext(),co++),this.ctx}resolved(){let e={};for(let[t,n]of this.media)e[t]=n.duration;let t=ui(this.clips,e);return this.holding.size===0?t:t.map(e=>e.duration>0?e:{...e,duration:this.holding.get(e.id)??0})}clampTime(e){let t=this.length,n=Math.max(0,Number.isFinite(e)?e:0);return t>0?Math.min(n,t):n}rawClock(){return!this._playing||!this.ctx?this.startOffset:this.startOffset+(this.ctx.currentTime-this.startedAt)}restart(e){let t=this.ctx;this.stopVoices(),this.startOffset=e,this.startedAt=t.currentTime+io;let n=this.resolved(),r=new Map(n.map(e=>[e.id,e]));for(let t of ei(n,e))this.startVoice(r.get(t.id),this.startedAt+t.when,t.offset);this.syncStreams(this.rawClock(),!0)}startLate(e){let t=this.ctx;if(!t)return;let n=Math.max(this.startedAt,t.currentTime+io),r=this.startOffset+(n-this.startedAt);for(let t of ei([e],r))this.startVoice(e,n+t.when,t.offset)}startVoice(e,t,n){let r=this.media.get(Kr(e));if(!this.ctx||!r||r.streamed||!r.buffer)return;let i=this.ctx.createBufferSource();i.buffer=r.buffer,i.connect(this.nodesFor(e).gain),i.onended=()=>{this.voices.get(e.id)===i&&(this.voices.delete(e.id),i.disconnect())},i.start(t,n,e.duration-n),this.voices.set(e.id,i),this.serials.set(i,++this.serial)}stopSource(e){e.onended=null;try{e.stop()}catch{}e.disconnect()}stopVoices(){for(let e of this.voices.values())this.stopSource(e);this.voices.clear()}syncStreams(e,t=!1){let n=this.ctx?.currentTime??0;for(let r of this.resolved()){if(!this.media.get(Kr(r))?.streamed)continue;let i=this.clipNodes.get(r.id),a=i?.el,o=e-r.offset,s=a?{time:a.currentTime,paused:a.paused,seeking:a.seeking,readyState:a.readyState}:{time:0,paused:!0},c=li(o,r.duration,s,i?n-i.seekedAt:1/0);if(t&&o>=0&&o<r.duration&&(c=s.paused?`play`:`seek`),c===`none`)continue;let l=i??this.nodesFor(r),u=l.el;if(c===`pause`){u.pause();continue}u.currentTime=o,l.seekedAt=n,c===`play`&&u.play().catch(()=>{})}}pauseStreams(){for(let e of this.clipNodes.values())e.el?.pause()}laneNode(e){let t=this.laneNodes.get(e);return t||(t=this.ctx.createGain(),t.gain.value=this.laneTargets[e]??1,t.connect(this.ctx.destination),this.laneNodes.set(e,t)),t}nodesFor(e){let t=this.clipNodes.get(e.id);if(!t){let n=this.ctx,r=n.createGain();if(r.gain.value=$r([e],this.selection)[e.id],r.connect(this.laneNode(e.lane)),t={gain:r,seekedAt:-1/0},this.media.get(Kr(e))?.streamed){let i=this.opts.createMedia(this.opts.url(e.path));i.preload=`auto`,t.el=i,t.elSource=n.createMediaElementSource(i),t.elSource.connect(r)}this.clipNodes.set(e.id,t)}return t}dropClip(e){let t=this.voices.get(e);t&&(this.stopSource(t),this.voices.delete(e));let n=this.clipNodes.get(e);n&&(n.elSource?.disconnect(),n.el&&(n.el.pause(),n.el.removeAttribute(`src`),n.el.load()),n.gain.disconnect(),this.clipNodes.delete(e))}ramp(e,t){let n=this.ctx.currentTime,r=e;typeof r.cancelAndHoldAtTime==`function`?r.cancelAndHoldAtTime(n):(e.cancelScheduledValues(n),e.setValueAtTime(e.value,n)),e.linearRampToValueAtTime(t,n+ao)}startLoop(){this.frame===null&&(this.frame=this.opts.raf(this.tick))}stopLoop(){this.frame!==null&&this.opts.caf(this.frame),this.frame=null}tick=()=>{if(this.frame=null,!this._playing)return;let e=this.length;if(e<=0){if(this.clips.some(e=>this.loads.has(Kr(e))&&!this.media.has(Kr(e)))){this.frame=this.opts.raf(this.tick);return}this.pause();return}let t=this.time;this.syncStreams(this.rawClock());for(let e of this.tickListeners)_o(()=>e(t));if(t>=e){this.pause();for(let e of this.endedListeners)_o(e);return}this._playing&&this.frame===null&&(this.frame=this.opts.raf(this.tick))};emitChange(){for(let e of this.changeListeners)_o(e)}};function _o(e){try{e()}catch(e){console.error(e)}}var vo=new class{el=null;current={path:null,playing:!1};by=null;failed=!1;listeners=new Set;make;url;constructor(e,t){this.make=e,this.url=t}state(){return this.current}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}async toggle(e,t){if(this.current.playing&&this.current.path===e)return this.stop();let n=this.element();n.pause(),(this.current.path!==e||this.failed)&&(n.src=this.url(e)),this.failed=!1,this.by=t??null,n.currentTime=0,pi(this,()=>this.stop()),this.set({path:e,playing:!0});try{await n.play()}catch(t){if(this.current.path===e&&this.current.playing)throw mi(this),this.failed=!0,this.set({path:e,playing:!1}),t}}stopIf(e){this.current.playing&&this.by===e&&this.stop()}stop(){this.el?.pause(),mi(this),this.current.playing&&this.set({...this.current,playing:!1})}element(){if(!this.el){let e=this.make();e.addEventListener(`ended`,()=>{mi(this),this.set({...this.current,playing:!1})}),this.el=e}return this.el}set(e){this.current=e;for(let t of this.listeners)t(e)}}(()=>new Audio,Nr),yo=e=>e.map(e=>[e.id,e.lane,e.path,e.rev??``,e.offset,e.duration].join(`\0`)).join(``);function bo(e,t=null){let n=X(null);n.current||=new go;let r=n.current,i=X(!0),[a,o]=q(!1),[s,c]=q(0),[l,u]=q({});return J(()=>{i.current=!0;let e=r.onChange(()=>{o(r.playing),c(r.length)});return()=>{i.current=!1,e(),r.dispose(),n.current===r&&(n.current=null)}},[r]),J(()=>{r.setClips(e);let t=new Map(e.map(e=>[Kr(e),e]));u(e=>{let n=Object.fromEntries(Object.entries(e).filter(([e])=>t.has(e)));return Object.keys(n).length===Object.keys(e).length?e:n});for(let[e,n]of t)r.load(n.path,n.rev).then(t=>i.current&&u(n=>n[e]===t?n:{...n,[e]:t}),t=>{i.current&&t.name!==`AbortError`&&u(t=>({...t,[e]:`error`}))})},[r,yo(e)]),J(()=>{r.setVideoDuration(t)},[r,t]),{engine:r,playing:a,length:s,media:l}}function xo(e){return e.map((e,t)=>({c:e,i:t})).sort((e,t)=>e.c.t-t.c.t||e.i-t.i).map(e=>e.c)}function So(e){return e.name.trim()||`Untitled cue`}function Co(e){return`${So(e)} at ${W(e.t)}`}function wo(e,t){return`cue ${e} of ${t}`}function To(e){let t=new Map;for(let n of xo(e)){let e=So(n),r=t.get(e);r||(r={name:e,cues:[],file:null,moreFiles:0},t.set(e,r)),r.cues.push(n)}for(let e of t.values()){let t=[...new Set(e.cues.flatMap(e=>e.file?[e.file]:[]))];e.file=t[0]??null,e.moreFiles=Math.max(0,t.length-1)}return[...t.values()]}function Eo(e,t,n){return n<=0?null:e===`ArrowLeft`?Math.max(0,t-1):e===`ArrowRight`?Math.min(n-1,t+1):e===`Home`?0:e===`End`?n-1:null}function Do(e){return e.split(/[\\/]/).filter(Boolean).pop()??e}function Oo(e,t){return`${((t>0?Math.min(1,Math.max(0,e/t)):0)*100).toFixed(3)}%`}function ko(e,t){return`clamp(5px, ${Oo(e,t)}, calc(100% - 5px))`}function Ao(e){let t=new Map;return e.map(e=>{let n=(t.get(e.id)??0)+1;return t.set(e.id,n),n===1?e.id:`${e.id}#${n}`})}function jo(e,t,n){let r=e.left+e.width/2-t.width/2,i=Math.max(16,Math.min(r,n.width-16-t.width)),a=e.top+e.height+8,o=a+t.height<=n.height-16?a:Math.max(16,e.top-8-t.height);return{left:Math.round(i),top:Math.round(o)}}var Mo=`cue-card`;function No(){let[e,t]=q(null);return{shown:e,api:{shown:e?.cue.key??null,show:(e,n)=>t(t=>t&&t.anchor===e&&t.cue.key===n.key?t:{anchor:e,cue:n}),hide:()=>t(null)}}}function Po(e,t){return{onPointerEnter:n=>e.show(n.currentTarget,t),onPointerLeave:()=>e.hide()}}function Fo({shown:e,onHide:t}){let n=X(null),[r,i]=q(null);if(Y(()=>{if(i(null),!e)return;let t=()=>{let t=n.current;if(!t)return;let r=e.anchor.getBoundingClientRect(),a=jo({left:r.left,top:r.top,width:r.width,height:r.height},{width:t.offsetWidth,height:t.offsetHeight},{width:document.documentElement.clientWidth,height:document.documentElement.clientHeight});i(e=>e&&e.left===a.left&&e.top===a.top?e:a)};return t(),window.addEventListener(`scroll`,t,!0),window.addEventListener(`resize`,t),()=>{window.removeEventListener(`scroll`,t,!0),window.removeEventListener(`resize`,t)}},[e]),Y(()=>{e&&!e.anchor.isConnected&&t()}),!e)return null;let a=e.cue;return Q(`div`,{ref:n,id:Mo,class:`cuecard`,role:`tooltip`,style:r?{left:`${r.left}px`,top:`${r.top}px`}:{left:`0px`,top:`0px`,visibility:`hidden`},children:[Q(`b`,{children:a.name}),Q(`span`,{class:`m`,children:[W(a.t),` · `,wo(a.n,a.of)]}),a.file!==null&&Q(`span`,{class:`f`,style:{color:a.color},children:a.file})]})}function Io(e,t,n){if(e.key===`Escape`){n.shown!==null&&(e.preventDefault(),e.stopPropagation(),n.hide());return}if(e.metaKey||e.ctrlKey||e.altKey)return;let r=e.currentTarget,i=[...r.parentElement?.querySelectorAll(`:scope > ${t}`)??[]],a=Eo(e.key,i.indexOf(r),i.length);a!==null&&(e.preventDefault(),e.stopPropagation(),i[a].focus())}function Lo(){let[e,t]=q(vo.state());return J(()=>vo.subscribe(t),[]),e}function Ro({id:e,name:t,cues:n,length:r,color:i,card:a,onSeek:o,toast:s}){let c=xo(n),l=new Map(c.map((e,t)=>[e,t+1])),u=To(n),[d,f]=q({}),p=Lo();J(()=>()=>vo.stopIf(e),[e]);let m=async t=>{try{await vo.toggle(t,e)}catch{s(`Couldn't play ${Do(t)}`)}};return Q(`div`,{class:`clayers`,id:e,role:`group`,"aria-label":`Layers for ${t}`,style:`--lane: ${i}`,children:u.map(t=>{let n=Math.min(d[t.name]??0,t.cues.length-1),s=t.file,u=s!==null&&p.playing&&p.path===s;return Q(`div`,{class:`clayer`,"data-layer":t.name,children:[Q(`div`,{class:`clname`,children:[Q(`span`,{children:t.name}),Q(`em`,{children:[`×`,t.cues.length]})]}),Q(`div`,{class:`cltrack`,children:[t.cues.map((s,u)=>{let d={key:`l:${e}:${s.id}`,name:t.name,t:s.t,n:l.get(s)??u+1,of:c.length,file:s.file??null,color:i},p=a.shown===d.key;return Q(`button`,{type:`button`,class:`ltick${p?` hot`:``}`,tabIndex:u===n?0:-1,style:{left:ko(s.t,r)},"aria-label":Co(s),"aria-describedby":p?Mo:void 0,...Po(a,d),onFocus:e=>{f(e=>e[t.name]===u?e:{...e,[t.name]:u}),a.show(e.currentTarget,d)},onBlur:()=>a.hide(),onKeyDown:e=>Io(e,`button.ltick`,a),onClick:()=>o(s.t,s.id)},s.id)}),Q(`div`,{class:`playhead`})]}),Q(`div`,{class:`clfile`,children:[s!==null&&Q(`button`,{type:`button`,"aria-pressed":u,"aria-label":`Play ${s}`,onClick:()=>void m(s),children:[Q($,{name:u?`pause`:`play`}),Q(`span`,{children:Do(s)})]}),t.moreFiles>0&&Q(`small`,{children:[`+`,t.moreFiles]})]})]},t.name)})})}var zo=0;function Bo(){return zo}var Vo=3,Ho=2;function Uo({segments:e,length:t,color:n}){let r=X(null),[i,a]=q({w:0,h:0,dpr:1});J(()=>{let e=r.current;if(!e)return;let t=()=>{let t=e.getBoundingClientRect(),n=window.devicePixelRatio||1;a(e=>e.w===t.width&&e.h===t.height&&e.dpr===n?e:{w:t.width,h:t.height,dpr:n})};t();let n=new ResizeObserver(t);return n.observe(e),()=>n.disconnect()},[]);let o=[i,t,n];for(let t of e)o.push(t.offset,t.duration,t.peaks);return J(()=>{let a=r.current;if(!a||i.w<=0||i.h<=0)return;zo++,a.width=Math.round(i.w*i.dpr),a.height=Math.round(i.h*i.dpr);let o=a.getContext(`2d`);if(!o||(o.setTransform(i.dpr,0,0,i.dpr,0,0),o.clearRect(0,0,i.w,i.h),!(t>0)))return;o.fillStyle=n;let s=Math.floor(i.w/Vo),c=t*Vo/i.w;for(let t=0;t<s;t++){let n=t*c,r=n+c,a=-1;for(let t of e){if(!(t.duration>0)||r<=t.offset||n>=t.offset+t.duration)continue;if(!t.peaks||t.peaks.length===0){a=Math.max(a,.04);continue}let e=t.peaks.length,i=Math.max(0,Math.floor((n-t.offset)/t.duration*e)),o=Math.min(e,Math.max(i+1,Math.ceil((r-t.offset)/t.duration*e)));for(let e=i;e<o;e++)a=Math.max(a,t.peaks[e])}if(a<0)continue;let s=Math.max(1.5,Math.min(1,a)*i.h*.92);o.globalAlpha=.9,o.fillRect(t*Vo,(i.h-s)/2,Ho,s)}},o),Q(`canvas`,{ref:r,class:`wave`,"aria-hidden":`true`})}function Wo(e){let t={},n=e=>e!==null&&e.scrollWidth>e.clientWidth;for(let r of e.querySelectorAll(`.lane[data-row]`)){let e=(n(r.querySelector(`[data-name]`))?`n`:``)+(n(r.querySelector(`[data-meta-text]`))?`m`:``);e&&(t[r.dataset.row]=e)}for(let r of e.querySelectorAll(`.rhead[data-heading]`))n(r.querySelector(`.rname`))&&(t[`h:${r.dataset.heading}`]=`h`);for(let r of e.querySelectorAll(`.fold[data-row]`))n(r.querySelector(`.flabel`))&&(t[`f:${r.dataset.row}`]=`f`);return t}var Go=(e,t)=>{let n=Object.keys(e);return n.length===Object.keys(t).length&&n.every(n=>e[n]===t[n])};function Ko({rows:e,length:t,media:n,selected:r,marks:i,range:a,onSelect:o,onSeek:s,toast:c}){let l=e=>`${t>0?e/t*100:0}%`,u=X(null),[d,f]=q({}),p=()=>{if(u.current){let e=Wo(u.current);f(t=>Go(t,e)?t:e)}},m=e.map(e=>{let t=e.clips.map(e=>n[Kr(e)]);return(t.some(e=>e!==void 0&&e!==`error`&&e.streamed)?`s`:``)+(t.some(e=>e===`error`)?`b`:``)});Y(p,[JSON.stringify(e.map((e,t)=>[e.key,e.name,e.meta??``,e.heading??``,e.fold?e.fold.text:null,e.missing??!1,m[t],+!!e.layers]))]),J(()=>(window.addEventListener(`resize`,p),document.fonts?.ready.then(p),()=>window.removeEventListener(`resize`,p)),[]);let{shown:h,api:g}=No(),[_,v]=q({});return Q(`div`,{class:`lanes`,ref:u,children:[e.map(e=>{let u=e.heading!==void 0&&Q(`div`,{class:`rhead`,"data-heading":e.key,"data-tip":d[`h:${e.key}`]?e.heading:void 0,children:[Q(`span`,{class:`rname`,children:e.heading}),e.tag&&Q(`span`,{class:`rtag`,children:e.tag})]});if(e.fold){let t=e.fold;return Q(S,{children:[u,Q(`button`,{type:`button`,class:`fold`,"data-row":e.key,"data-tip":d[`f:${e.key}`]?t.text:void 0,"aria-expanded":t.open,"aria-description":t.dot?`Open notes`:void 0,onClick:t.onToggle,children:[Q($,{name:`chev`}),Q(`span`,{class:`flabel`,children:t.label}),t.dot&&Q(`span`,{class:`fdot`,"data-dot":!0,"data-tip":`Open notes`})]})]},e.key)}let f=e.key===r,p=d[e.key]??``,m=xo(e.cues??[]),h=Ao(m),y=wt(m,t),b=Math.min(_[e.key]??0,Math.max(0,m.length-1)),x=(t,n)=>({key:`m:${e.key}:${h[n]}`,name:So(t),t:t.t,n:n+1,of:m.length,file:t.file??null,color:e.color}),C=e.clips.map(e=>n[Kr(e)]),w=C.some(e=>e!==void 0&&e!==`error`&&e.streamed),T=C.some(e=>e===`error`),E=e.clips.map((e,t)=>{let n=C[t],r=n!==void 0&&n!==`error`?n:null;return{offset:e.offset,duration:e.duration>0?e.duration:r?.duration??0,peaks:r?r.peaks:null}}),D=i[e.key]??[],O=Q(`button`,{type:`button`,class:`nm`,"data-player":!0,"aria-current":f?`true`:`false`,"aria-label":e.name,"aria-description":e.missing?typeof e.missing==`string`?e.missing:`Missing`:void 0,onClick:()=>o(e),children:[Q(`b`,{"data-tip":p.includes(`n`)?e.name:void 0,children:[Q(`i`,{style:{background:e.color}}),Q(`span`,{"data-name":!0,children:e.name}),e.missing&&Q(ga,{tip:typeof e.missing==`string`?e.missing:void 0})]}),Q(`small`,{"data-meta":!0,"data-tip":p.includes(`m`)&&e.meta?e.meta:void 0,children:[T?Q(`span`,{class:`smk bad`,"data-tip":`This file won't play in a browser`,children:Q($,{name:`alert`})}):w?Q(`span`,{class:`smk`,"data-tip":`Long file: switching isn't sample-exact`,children:Q($,{name:`stream`})}):null,Q(`span`,{"data-meta-text":!0,children:e.meta??``})]})]});return Q(S,{children:[u,Q(`div`,{class:`lane`,"data-row":e.key,"aria-current":f?`true`:void 0,children:[e.layers?Q(`div`,{class:`nmc`,children:[Q(`button`,{type:`button`,class:`chev tip-start`,"aria-expanded":e.layers.open,"aria-controls":e.layers.open&&m.length>0?`cl-${e.key}`:void 0,"aria-label":`Layers for ${e.name}`,"aria-description":m.length===0?`No cues in this pass`:void 0,"data-tip":m.length===0?`No cues in this pass`:e.layers.open?`Hide the layers`:`Show the layers`,disabled:m.length===0,onClick:e.layers.onToggle,children:Q($,{name:`chev`})}),O]}):O,Q(`div`,{class:`track`,onClick:n=>{let r=n.currentTarget.getBoundingClientRect();s((n.clientX-r.left)/r.width*t,e)},children:[Q(Uo,{segments:E,length:t,color:e.color}),m.map((t,n)=>Q(`i`,{class:`cue-tick${g.shown===`m:${e.key}:${h[n]}`?` hot`:``}`,"aria-hidden":`true`,style:{left:l(t.t),color:e.color},...Po(g,x(t,n)),onClick:n=>{n.stopPropagation(),s(t.t,e,t.id)}},`t${h[n]}:${t.t}:${t.name}`)),m.map((t,n)=>{let r=x(t,n),i=g.shown===r.key;return Q(`button`,{type:`button`,class:`cue${i?` hot`:``}`,"data-cue":t.id,tabIndex:n===b?0:-1,"aria-label":Co(t),"aria-describedby":i?Mo:void 0,style:{left:l(t.t),color:e.color,maxWidth:`calc(${(y[n]*100).toFixed(3)}% - 8px)`},...Po(g,r),onFocus:t=>{v(t=>t[e.key]===n?t:{...t,[e.key]:n}),g.show(t.currentTarget,r)},onBlur:()=>g.hide(),onKeyDown:e=>Io(e,`button.cue`,g),onClick:n=>{n.stopPropagation(),s(t.t,e,t.id)},children:Q(`span`,{children:So(t)})},`c${h[n]}:${t.t}:${t.name}`)}),D.map(e=>e.tOut!==null&&Q(`div`,{class:`span ${e.status}`,"data-note":e.id,style:{left:l(e.t),width:l(e.tOut-e.t)}})),D.map(e=>Q(`div`,{class:`mk ${e.status}`,"data-note":e.id,style:{left:l(e.t)},title:e.text})),a.in!==null&&Q(`div`,{class:`span live`,style:{left:l(a.in),width:l((a.out??a.in+Math.max(.2,t/200))-a.in)}}),Q(`div`,{class:`playhead`})]}),Q(`div`,{class:`ctl`,children:[e.use&&Q(`button`,{type:`button`,class:`use`,"aria-pressed":e.use.inUse,"aria-label":`Use ${e.name}`,onClick:t=>{t.stopPropagation(),e.use.onUse()},children:e.use.inUse?Q(S,{children:[Q($,{name:`check`}),`In use`]}):`Use`}),e.use?.inUse&&e.use.onUnpick&&Q(`button`,{type:`button`,class:`btn ghost ib sm unpick`,"data-tip":`Unpick`,"aria-label":`Unpick ${e.name}`,onClick:t=>{t.stopPropagation(),e.use.onUnpick()},children:Q($,{name:`x`})}),e.controls]})]}),e.layers?.open&&m.length>0&&Q(Ro,{id:`cl-${e.key}`,name:e.name,cues:m,length:t,color:e.color,card:g,onSeek:(t,n)=>s(t,e,n),toast:c??(()=>void 0)})]},e.key)}),Q(Fo,{shown:h,onHide:g.hide})]})}var qo=[`ArrowLeft`,`ArrowRight`,`ArrowUp`,`ArrowDown`,`Home`,`End`];function Jo({label:e,width:t,height:n,value:r,onChange:i,lockedReason:a,name:o}){let s=Jn(t,n),c=xr();return Q(`div`,{class:`fscope`,role:`radiogroup`,"aria-label":o,onKeyDown:e=>{if(e.altKey||e.metaKey||e.ctrlKey||!qo.includes(e.key))return;e.preventDefault(),e.stopPropagation();let t=e.key===`Home`||e.key===`ArrowLeft`||e.key===`ArrowUp`?`this`:`all`;t===`all`&&a||(t!==r&&i(t),e.currentTarget.querySelector(`[data-scope="${t}"]`)?.focus())},children:[[{v:`this`,text:`This format`,disabled:!1},{v:`all`,text:`All formats`,disabled:a!==null}].map(t=>Q(`button`,{type:`button`,role:`radio`,"data-scope":t.v,"aria-checked":r===t.v,"aria-disabled":t.disabled?`true`:void 0,"aria-describedby":t.disabled?c:void 0,tabIndex:r===t.v?0:-1,"aria-label":t.v===`this`?`This format, ${e}`:`All formats`,class:t.disabled?`tip-wrap tip-below tip-end`:void 0,"data-tip":t.disabled?a:void 0,onClick:()=>{!t.disabled&&t.v!==r&&i(t.v)},children:[t.v===`this`&&Q(`span`,{class:`shape`,"aria-hidden":`true`,style:{width:`${s.width}px`,height:`${s.height}px`}}),t.text]},t.v)),a&&Q(`span`,{id:c,hidden:!0,children:a})]})}var Yo=[{kind:`rise`,label:`Rise`},{kind:`fall`,label:`Fall`},{kind:`louder`,label:`Louder`},{kind:`quieter`,label:`Quieter`}],Xo=e=>e.options.find(t=>t.value===e.value)?.full;function Zo({notes:e,version:t,placeholder:n,attachments:r,inputRef:i,toast:a,onAdd:o,onSeek:s,onChanged:c,onTextChange:l,on:u,scope:d,chips:f,marks:p,onLabel:m,fixedTimes:h,selectedId:g,formatTag:_,cardExtra:v,formatScope:y,listFooter:b}){let[x,S]=q(`all`),C=X(null),w=i??C,[T,E]=q(``),[D,O]=q(!1),k=e.filter(e=>e.status===`todo`).length,A=b?.(x)??null,j=e.map(e=>({n:e,at:h?{t:e.t,tOut:e.tOut,from:null}:ve(e,t)})).filter(({n:e})=>x===`all`||e.status===x).sort((e,t)=>(e.at.t??-1)-(t.at.t??-1)),M=async e=>{try{await Z.patch(`/api/notes/${e.id}`,{status:e.status===`done`?`todo`:`done`})}catch(e){a(`Couldn't update that note: ${e.message}`)}c()},N=async()=>{let e=T.trim();if(e&&!D){O(!0);try{await o(e),E(``),l?.(!1)}catch(e){a(`Couldn't add the note: ${e.message}`)}finally{O(!1)}}},P=e=>{E(e),l?.(!0);let t=w.current;t&&(t.value=e,t.focus(),t.setSelectionRange(e.length,e.length))};return Q(`aside`,{class:`panel side`,"aria-label":`Notes`,children:[Q(`div`,{class:`ph`,children:[Q(`h3`,{children:`Notes`}),Q(`span`,{class:`sp`}),Q(`div`,{class:`seg`,role:`group`,"aria-label":`Filter notes`,children:[`all`,`todo`,`done`].map(e=>Q(`button`,{"aria-pressed":x===e,onClick:()=>S(e),children:[e===`all`?`All`:e===`todo`?`To do`:`Done`,e===`todo`&&k>0&&Q(`span`,{class:`n`,children:k})]}))})]}),Q(`div`,{class:`list`,children:[j.length===0&&Q(`div`,{class:`none`,children:x===`all`?A?`None on this format.`:`No notes yet.`:`Nothing here.`}),j.map(({n:e,at:t})=>Q(`div`,{class:`note${e.status===`done`?` done`:``}`,"data-note":e.id,"aria-current":g===e.id?`true`:void 0,children:[Q(`button`,{class:`chk`,"aria-label":e.status===`done`?`Reopen`:`Mark done`,title:e.status===`done`?`Reopen`:`Mark done`,onClick:()=>void M(e),children:Q($,{name:`check`})}),Q(`div`,{class:`nt`,children:[Q(`button`,{class:`t`,onClick:()=>t.t!==null&&s?.(t.t,e),children:ye(t.t,t.tOut)}),m&&m(e)&&Q(`span`,{class:`on`,children:m(e)}),(()=>{let t=_?.(e)??null;return t&&Q(`span`,{class:`ftag${t===`All`?` all`:``}`,children:t})})(),t.from&&Q(`span`,{class:`from`,children:[`from `,t.from]})]}),gt(e.marks)&&Q(`div`,{class:`nmarks`,children:gt(e.marks)}),e.shot&&Q(`div`,{class:`shotref`,children:[`Shot `,We(e.shot.n),` · `,e.shot.name]}),Q(`div`,{class:`nx`,children:e.text}),e.grab&&Q(`div`,{class:`att`,children:Q(`img`,{class:`thumb`,src:Nr(e.grab),alt:`Frame grab`})}),e.reply&&Q(`div`,{class:`rp`,children:[Q($,{name:`reply`}),Q(`span`,{children:e.reply})]}),g===e.id&&v&&Q(`div`,{class:`nfmt`,children:v(e)})]},e.id)),A]}),Q(`div`,{class:`comp`,children:[(u||d)&&Q(`div`,{class:`row`,children:[u&&Q(`span`,{class:`onwrap`,"data-tip":Xo(u),children:[Q(`select`,{class:`sel onsel`,"aria-label":`Note on`,"data-tip":Xo(u),value:u.value??``,onChange:e=>{let t=e.target;u.onChange(t.value),t.blur()},children:xt(u.options).map(e=>e.group===void 0?e.options.map(e=>Q(`option`,{value:e.value,children:e.label})):Q(`optgroup`,{label:e.group,children:e.options.map(e=>Q(`option`,{value:e.value,children:e.label}))}))}),Q($,{name:`chev`})]}),Q(`span`,{class:`sp`}),d&&Q(`div`,{class:`seg`,role:`group`,"aria-label":`Scope`,children:ct(d.options).map(e=>Q(`button`,{type:`button`,"aria-pressed":d.value===e.value,onClick:()=>d.onChange(e.value),children:e.label}))})]}),f&&f.length>0&&!(p&&d?.value===`range`)&&Q(`div`,{class:`row`,role:`group`,"aria-label":`Start a note`,children:f.map(e=>Q(`button`,{type:`button`,class:`chip`,onClick:()=>P(`${e}: `),children:e}))}),p&&d?.value===`range`&&Q(`div`,{class:`row`,role:`group`,"aria-label":`Marks`,children:Yo.map(({kind:e,label:t})=>{let n=p.value.find(t=>t.kind===e);return Q(`span`,{class:`markc`,children:[Q(`button`,{type:`button`,class:`chip`,"aria-pressed":!!n,onClick:()=>p.onChange(_t(p.value,e)),children:t}),n?.db!==void 0&&Q(`span`,{class:`onwrap`,children:[Q(`select`,{class:`sel dbsel`,"aria-label":`${t} by`,value:String(n.db),onChange:t=>{let n=t.target;p.onChange(vt(p.value,e,Number(n.value))),n.blur()},children:dt.map(e=>Q(`option`,{value:String(e),children:[e,` dB`]}))}),Q($,{name:`chev`})]})]})})}),y&&Q(`div`,{class:`row`,children:Q(Jo,{name:`This note applies to`,label:y.label,width:y.width,height:y.height,value:y.value,onChange:y.onChange,lockedReason:y.lockedReason})}),r&&Q(`div`,{class:`row`,children:r}),Q(`div`,{class:`cbox`,children:[Q(`textarea`,{ref:w,class:`input`,rows:2,"aria-label":`New note`,placeholder:n,value:T,onInput:e=>{let t=e.target.value;E(t),l?.(t.trim()!==``)},onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),N()),e.key===`Escape`&&e.target.blur()}}),Q(`button`,{class:`btn primary ib sm send`,"data-tip":`Add note ↵`,"aria-label":`Add note`,onClick:()=>void N(),children:Q($,{name:`send`})})]}),y&&Q(`p`,{class:`fhint`,children:y.hint})]})]})}var Qo=typeof location>`u`?{test:!1,streamOver:!1}:Rt(location.search);Qo.streamOver&&si(1);var $o=Qo.test?{engine:null,inspect(){return this.engine?this.engine.inspect():null},renders:0,draws:Bo,liveContexts:lo,sample:()=>vo.state(),clips:[],heard(){let e=this.engine?.inspect();return e?this.clips.filter(t=>(e.gains[t.id]??1)*(e.lanes[t.lane]??1)>0).map(e=>({id:e.id,lane:e.lane,path:e.path,offset:e.offset})):[]}}:null;$o&&(window.__rushesAudio=$o);var es=e=>e instanceof HTMLElement&&(e.isContentEditable||/^(INPUT|TEXTAREA|SELECT)$/.test(e.tagName)),ts={in:null,out:null},ns=[`point`,`range`,`whole`];function rs(e){let{stage:t,title:n,headerExtra:r,belowLanes:i,rows:a,preview:o,fps:s,notes:c,onOptions:l,noteRow:u,onLabel:d,toast:f,onChanged:p,onPendingChange:m,listen:h}=e;$o&&$o.renders++;let g=e.clips??is(a.flatMap(e=>e.clips)),[_,v]=q(null),[y,b]=q(16/9);J(()=>{v(null),b(16/9)},[o?.file]);let{engine:x,playing:C,length:w,media:T}=bo(g,o?o.duration??_:null),[E,D]=q(null),[O,k]=q(null),A=X(null),j=a.some(e=>e.key===E)?E:null;Y(()=>{E!==null&&j===null&&(D(null),A.current!==null&&O===A.current&&k(null),A.current=null)},[j]);let[M,N]=q(ts),[P,F]=q(e.defaultScope??`point`),[I,L]=q([]),[ee,te]=q(!1),R=(e.scopes??ns).includes(`range`),ne=e.defaultScope??`point`,re=`${e.film===void 0?o?.video??``:e.film??``}/${o?.version??``}`,ie=X(re);Y(()=>{ie.current!==re&&(ie.current=re,F(ne))},[re]);let ae=lt({range:M,marks:I,hasText:ee});Y(()=>{m?.(ae)},[ae]),J(()=>()=>m?.(!1),[]);let oe=e=>h?h(e):{select:jt(a,e),gains:{}},z=X({select:{},gains:{}}),B=e=>{let t=z.current;for(let[n,r]of Object.entries(e.select))(!(n in t.select)||t.select[n]!==r)&&x.selectVariant(n,r);for(let[n,r]of Object.entries(e.gains))t.gains[n]!==r&&x.setLaneGain(n,r);z.current={select:{...t.select,...e.select},gains:{...t.gains,...e.gains}}},se=oe(j);Y(()=>B(se),[x,JSON.stringify(se)]);let ce=e.defaultOn??a.find(e=>e.picked)?.on??a[0]?.on??l[0]?.value??null,le=l.some(e=>e.value===O)?O:ce,ue=l.find(e=>e.value===le)??null,V=X(null),de=X([]),fe=X(null),H=X(null),pe=X(null),U=X(!1),me=X(0),he=X(null),ve=e=>{if(P===`whole`)return t===`voice`?`Note on the whole read`:`Note on the whole track`;if(R){if(M.in!==null&&M.out===null)return`Set an Out point`;if(M.in!==null&&M.out!==null)return`Note on ${ye(M.in,M.out)}`;if(P===`range`)return`Set In and Out`}return`Note at ${W(ue?.t??ge(e,s))}`},be=e=>{let t=x.length,n=`${t>0?Math.min(e,t)/t*100:0}%`;for(let e of de.current)e.style.left=n;let r=W(e);fe.current&&(fe.current.textContent=r),H.current&&(H.current.textContent=r),he.current&&(he.current.placeholder=ve(e));let i=pe.current;i&&i.readyState>=1&&!i.seeking&&ti(i.currentTime,e,s)&&(i.currentTime=Math.min(e,Number.isFinite(i.duration)?i.duration:e)),i&&x.playing&&!U.current&&e>me.current&&(U.current=!0,i.play().catch(()=>void 0)),me.current=e},xe=X(be);xe.current=be,Y(()=>{de.current=V.current?[...V.current.querySelectorAll(`.playhead`)]:[],be(x.time)}),J(()=>x.subscribe(e=>xe.current(e)),[x]),J(()=>{let e=pe.current;e&&(U.current=!1,C||(e.pause(),xe.current(x.time)))},[C,o?.file]);let Se=()=>x.playing?x.pause():x.play(),Ce=e=>{x.pause(),x.seek(_e(x.time,s,e,x.length))},we=()=>{R&&(N({in:ge(x.time,s),out:null}),F(`range`))},Te=()=>{if(!R)return;let e=ge(x.time,s),t=M.in??0;if(e<=t)return f(`Out has to come after In`);N({in:t,out:e}),F(`range`)},Ee=()=>{N(ts),L([]),P===`range`&&F(ne)},G=e=>{(e!==`range`||R)&&(F(e),e!==`range`&&(N(ts),L([])))},De=t=>{D(t.key),B(oe(t.key)),A.current=t.on??null,t.on&&k(t.on),e.onSelect?.(t)},Oe=X(()=>void 0);Oe.current=e=>{if(es(e.target)||e.metaKey||e.ctrlKey||e.altKey)return;let t=e.key.toLowerCase();if(e.key===` `){if(Lt(e.target))return;e.preventDefault(),Se()}else e.key===`ArrowLeft`?(e.preventDefault(),Ce(e.shiftKey?-10:-1)):e.key===`ArrowRight`?(e.preventDefault(),Ce(e.shiftKey?10:1)):t===`i`?we():t===`o`?Te():t===`n`&&(e.preventDefault(),he.current?.focus())},Y(()=>{let e=e=>Oe.current(e);return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[]),Y(()=>{$o&&($o.clips=g)}),J(()=>{if($o)return $o.engine=x,()=>{$o.engine===x&&($o.engine=null)}},[x]);let ke=async e=>{let n=null,r=null;if(P===`range`){if(M.in===null||M.out===null)throw Error(`set In and Out for a range`);n=M.in,r=M.out}else P===`point`&&(n=ue?.t??ge(x.time,s));await Z.post(`/api/notes`,{stage:t,video:o?.video??null,version:o?.version??null,on:ue?.on??null,scope:P,t:n,tOut:r,text:e,marks:P===`range`?I:[]}),N(ts),L([]),F(ne),p()},Ae=o?.version??null,je={};for(let e of c){if(e.scope===`whole`||e.t===null)continue;let t=u(e);for(let n of t===null?[]:typeof t==`string`?[t]:t)(je[n]??=[]).push({id:e.id,t:e.t,tOut:R?e.tOut:null,status:e.status,text:e.text})}let Me=M.in===null?null:M.out===null?`${W(M.in)} →`:ye(M.in,M.out);return Q(`div`,{class:`astage`,ref:V,children:[Q(`div`,{class:`stack`,children:[Q(`div`,{class:`ahead`,children:[Q(`h2`,{children:n}),r,Q(`span`,{class:`sp`})]}),Q(`div`,{class:`bar`,children:[Q(`button`,{class:`btn ghost ib`,"data-tip":`Back one frame ←`,"aria-label":`Back one frame`,onClick:()=>Ce(-1),children:Q($,{name:`prev`})}),Q(`button`,{class:`btn ib`,"data-tip":`Play Space`,"aria-label":C?`Pause`:`Play`,onClick:Se,children:Q($,{name:C?`pause`:`play`})}),Q(`button`,{class:`btn ghost ib`,"data-tip":`Forward one frame →`,"aria-label":`Forward one frame`,onClick:()=>Ce(1),children:Q($,{name:`next`})}),Q(`span`,{class:`tc`,"aria-label":`Timecode`,children:[Q(`span`,{ref:fe,children:W(x.time)}),Q(`small`,{children:[`/ `,W(w)]})]}),Q(`span`,{class:`sp`}),Me&&Q(`span`,{class:`chipx`,children:[Q(`span`,{class:`mono`,children:Me}),Q(`button`,{"aria-label":`Clear range`,onClick:Ee,children:Q($,{name:`x`})})]}),R&&Q(S,{children:[Q(`button`,{class:`btn ghost ib`,"data-tip":`Set in I`,"aria-label":`Set in point`,onClick:we,children:Q($,{name:`in`})}),Q(`button`,{class:`btn ghost ib`,"data-tip":`Set out O`,"aria-label":`Set out point`,onClick:Te,children:Q($,{name:`out`})})]})]}),Q(Ko,{rows:a,length:w,media:T,selected:j,marks:je,range:M,onSelect:De,onSeek:(e,t,n)=>{De(t);let r=n===void 0?void 0:l.find(e=>e.value===`c:${t.key}:${n}`);r&&(A.current=r.value,k(r.value)),x.seek(e)},toast:f}),i]}),Q(`div`,{class:`acol`,children:[Q(`div`,{class:`pv`,children:Q(`div`,{class:`frame`,style:{aspectRatio:String(y)},children:[o?Q(`video`,{ref:pe,src:Nr(o.file),muted:!0,playsInline:!0,preload:`auto`,"aria-label":`Picture preview`,onLoadedMetadata:e=>{let t=e.target;Number.isFinite(t.duration)&&v(t.duration),t.videoWidth&&t.videoHeight&&b(t.videoWidth/t.videoHeight),xe.current(x.time)},onSeeked:()=>xe.current(x.time)}):Q(`div`,{class:`pvempty`,"aria-label":`No cut yet`,children:Q($,{name:`film`})}),Q(`div`,{class:`tcover`,ref:H,children:W(x.time)})]})}),Q(Zo,{notes:c,version:Ae,placeholder:ve(x.time),inputRef:he,toast:f,onAdd:ke,onChanged:p,onTextChange:te,fixedTimes:!0,onSeek:e=>x.seek(e),on:{options:l,value:le,onChange:k},scope:{value:P,onChange:G,options:e.scopes},chips:(e.chipsFor??(()=>ut[t]))(P),marks:e.marks===!1?void 0:{value:I,onChange:L},onLabel:d})]})]})}function is(e){let t=new Set;return e.filter(e=>!t.has(e.id)&&(t.add(e.id),!0))}var as={vo:`#4FD1C5`,music:`#A78BFA`,sfx:`#FB923C`},os={vo:`Voiceover`,music:`Music`,sfx:`Sound effects`},ss={vo:{muted:!1,solo:!1},music:{muted:!1,solo:!1},sfx:{muted:!1,solo:!1}};function cs({state:e,assets:t,video:n,toast:r,onChanged:i,onPendingChange:a}){let o=e=>t.find(t=>t.path===e),s=e=>{let t=o(e);return t?qr(t):void 0},c=e=>o(e)?.missing===!0,l=e.picks.lanes,u=Ut(Vt(e.project.lanes,l)),d=u&&!c(u.file)?[{id:u.key,lane:`vo`,path:u.file,offset:0,duration:0,rev:s(u.file)}]:[],f=u?c(u.file):!1,p={music:bt(e.project.lanes,`music`),sfx:bt(e.project.lanes,`sfx`)},m=e=>e.filter(e=>l[e.lane]===e.variant),h={music:m(p.music),sfx:m(p.sfx)},g={music:h.music.filter(e=>!c(e.file)),sfx:h.sfx.filter(e=>!c(e.file))},_=e=>g[e].map(t=>({id:t.key,lane:e,path:t.file,offset:0,duration:0,rev:s(t.file)})),v={vo:d,music:_(`music`),sfx:_(`sfx`)},y={vo:d.length>0,music:v.music.length>0,sfx:v.sfx.length>0},b={variants:p,heard:{vo:y.vo,music:g.music,sfx:g.sfx}},x=sn(b),[C,w]=q(ss),T=(e,t)=>w(n=>({...n,[e]:{...n[e],[t]:!n[e][t]}})),E=e.picks.levels,D=e=>E[$t[e]]??0,[O,k]=q(()=>({vo:D(`vo`),music:D(`music`),sfx:D(`sfx`)})),A=X({});J(()=>{k(e=>{let t=!1,n={...e};for(let e of Qt){if(A.current[e]!==void 0)continue;let r=D(e);n[e]!==r&&(n[e]=r,t=!0)}return t?n:e})},[JSON.stringify(E)]);let j=e=>{let t=A.current;for(let n of Qt){let r=t[n];r&&(window.clearTimeout(r.id),delete t[n],r.send(e))}};J(()=>{let e=()=>j(!0),t=()=>{document.visibilityState===`hidden`&&j(!0)};return window.addEventListener(`pagehide`,e),document.addEventListener(`visibilitychange`,t),()=>{window.removeEventListener(`pagehide`,e),document.removeEventListener(`visibilitychange`,t),j(!1)}},[]);let M=(e,t)=>{let n=ln(t);k(t=>t[e]===n?t:{...t,[e]:n});let a=A.current;a[e]!==void 0&&window.clearTimeout(a[e].id);let o=(t=!1)=>void Z.put(`/api/picks`,{levels:{[$t[e]]:n===0?null:n}},{keepalive:t}).then(i,e=>{r(e instanceof kr?e.message:`Couldn't save the level`)});a[e]={id:window.setTimeout(()=>{delete a[e],o()},300),send:o}},N=Zr(Qt.map(e=>({id:e,...C[e],level:O[e]}))),P=e=>e===`vo`?u?`${u.laneName} · ${u.name}`:null:h[e].map(e=>e.name).join(` · `)||null,F=e=>y[e]?null:e===`vo`?f?`Missing`:`Nothing picked`:h[e].length>0?`Missing`:`Nothing picked`,I=Qt.map(e=>({key:e,name:os[e],meta:P(e),color:as[e],clips:v[e],cues:e===`sfx`?g.sfx.flatMap(e=>e.cues):void 0,on:x.find(t=>t.row===e)?.value,missing:F(e)??void 0,controls:Q(S,{children:[Q(`button`,{type:`button`,class:`ms`,"aria-pressed":C[e].muted,"aria-label":`Mute ${os[e]}`,"data-tip":`Mute`,onClick:()=>T(e,`muted`),children:`M`}),Q(`button`,{type:`button`,class:`ms`,"aria-pressed":C[e].solo,"aria-label":`Solo ${os[e]}`,"data-tip":`Solo`,onClick:()=>T(e,`solo`),children:`S`}),Q(`label`,{class:`level`,"data-tip":`Level for ${os[e]}. Double-click to reset.`,children:[Q(`input`,{type:`range`,min:-24,max:6,step:cn,value:O[e],"aria-label":`${os[e]} level`,"aria-valuetext":`${un(O[e])} dB`,onInput:t=>M(e,Number(t.target.value)),onDblClick:()=>M(e,0)}),Q(`span`,{class:`db mono`,children:[un(O[e]),` dB`]})]})]})})),L=en(y,N),ee=JSON.stringify({want:L,levels:E,clips:Qt.map(e=>v[e].map(e=>[e.path,e.rev??``,e.offset]))}),[te,R]=q({kind:`waiting`}),[ne,re]=q(!1),[ie,ae]=q(0),oe=te.kind===`timeout`||te.kind===`error`,z=X(0);J(()=>{let e=++z.current;if(L.length===0){R({kind:`empty`}),re(!1);return}R(e=>e.kind===`empty`||e.kind===`timeout`||e.kind===`error`?{kind:`waiting`}:e),re(!0);let t=window.setTimeout(()=>{Z.post(`/api/mix/loudness`,{lanes:L}).then(t=>{e===z.current&&R({kind:`result`,result:t})},t=>{e===z.current&&R({kind:t instanceof kr&&t.status===504?`timeout`:`error`})}).finally(()=>{e===z.current&&re(!1)})},500);return()=>window.clearTimeout(t)},[ee,ie]),J(()=>()=>void++z.current,[]);let B=Q(`div`,{class:oe?`meter retry`:`meter`,role:`group`,"aria-label":`Loudness`,"aria-busy":ne,onClick:oe?()=>ae(e=>e+1):void 0,children:[pn(te).map(e=>Q(`div`,{"data-cell":e.id,children:[Q(`b`,{"data-value":!0,"data-tip":e.tip??void 0,"aria-description":e.tip??void 0,children:e.value}),Q(`span`,{children:e.label})]})),ne&&Q(`span`,{class:`smk measuring`,"data-measuring":!0,"data-tip":`Measuring`,"aria-label":`Measuring`,children:Q($,{name:`gauge`})}),oe&&!ne&&Q(`button`,{type:`button`,class:`btn ghost ib`,"data-tip":`Measure again`,"aria-label":`Measure again`,children:Q($,{name:`gauge`})})]}),se=e.notes.notes.filter(e=>e.stage===`mix`),ce=Ce(n??void 0),le=n&&ce?{video:n.id,version:ce.id,file:ce.file,duration:ce.duration}:null,ue=e.project.fps||30;return Q(rs,{stage:`mix`,title:Te.mix,belowLanes:B,rows:I,preview:le,film:n?.id??null,fps:ue,notes:se,onOptions:x,defaultOn:`mix`,listen:()=>({select:{},gains:N}),noteRow:e=>rn(b,e.on),onLabel:e=>on(b,e.on),toast:r,onChanged:i,onPendingChange:a})}function ls({notes:e,version:t,viewsHere:n,ownViews:r,onShow:i,onRestore:a}){let[o,s]=q(!1);return e.length===0?null:Q(`div`,{class:`otherfmts`,children:[Q(`button`,{type:`button`,class:`otherrow`,"aria-expanded":o,onClick:()=>s(e=>!e),children:[Q(`span`,{children:[`Other formats (`,e.length,`)`]}),Q(`span`,{class:`sp`}),Q(`span`,{class:`act`,"aria-hidden":`true`,children:o?`Hide`:`Show`})]}),o&&e.map(e=>{let o=ve(e,t),s=ir(e,n,r(e));return Q(`div`,{class:`note ro${e.status===`done`?` done`:``}`,"data-note":e.id,children:[Q(`span`,{"aria-hidden":`true`}),Q(`div`,{class:`nt`,children:[Q(`span`,{class:`t mono`,children:ye(o.t,o.tOut)}),Q(`span`,{class:`ftag`,children:e.format?fe(e.format):`All`}),o.from&&Q(`span`,{class:`from`,children:[`from `,o.from]})]}),Q(`div`,{class:`nx`,children:e.text}),s?.kind===`show`&&Q(`div`,{class:`nact`,children:Q(`button`,{type:`button`,class:`flink`,onClick:()=>i(s.id,e),children:[`Show on `,s.label]})}),s?.kind===`restore`&&Q(`div`,{class:`nact`,children:Q(`button`,{type:`button`,class:`flink`,onClick:()=>a(e),children:`Restore to all formats`})})]},e.id)})]})}var us=6e3,ds=e=>/[.!?]$/.test(e)?e:`${e}.`;function fs({video:e,version:t,ffmpeg:n,autoProxy:r,job:i,broken:a,duration:o,toast:s,onChanged:c,noteProxyJob:l,hidden:u=!1}){let[d,f]=q(!1),[p,m]=q(!1),[h,g]=q(r);J(()=>g(r),[r]);let _=X(new Set);i?.state===`running`&&_.current.add(i.job);let[v,y]=q(null),b=bn({ffmpeg:n,need:t.proxyNeed,broken:a,hasProxy:!!t.proxy,job:i,starting:d,watched:!!i&&_.current.has(i.job)}),x=b===`done`&&i?i.job:null;if(J(()=>{if(!x)return;let e=window.setTimeout(()=>y(x),us);return()=>clearTimeout(e)},[x]),!n)return null;let C=x&&v===x?`none`:b,w=xn(t.proxyNeed,a),T=i?.state===`running`?i.pct:i?.state===`done`?100:0,E=i?.state===`running`?i:null,D=async()=>{if(!d){f(!0);try{let{job:n}=await Z.post(`/api/videos/${encodeURIComponent(e.id)}/versions/${encodeURIComponent(t.id)}/proxy`);_.current.add(n.id),l(n)}catch(e){s(e.message)}finally{f(!1)}}},O=async()=>{if(E&&!p){m(!0);try{let{job:e}=await Z.del(`/api/proxy-jobs/${encodeURIComponent(E.job)}`);l(e)}catch(e){e instanceof kr&&e.code===`not_found`?c():s(e.message)}finally{m(!1)}}},k=async e=>{g(e);try{await Z.put(`/api/project/settings`,{autoProxy:e}),c()}catch(t){g(!e),s(t.message)}},A=Q(`label`,{class:`check`,children:[Q(`input`,{type:`checkbox`,checked:h,onChange:e=>{let t=e.currentTarget;t.blur(),k(t.checked)}}),`Create proxies for new cuts like this automatically`]});return Q(`div`,{class:`proxybar${C===`none`?` quiet`:``}`,hidden:u,children:Q(`div`,{class:`proxyrow${C===`none`?``:` ${C}`}`,children:[C===`offer`&&w&&Q(S,{children:[Q(`span`,{class:`why`,children:[Q(`b`,{children:`This cut may play slowly.`}),` `,ds(w)]}),Q(`button`,{class:`btn primary tip-wrap tip-end`,"aria-label":`Create proxy`,"data-tip":hn(t.duration??o),onClick:()=>void D(),children:`Create proxy`})]}),C===`working`&&Q(S,{children:[Q(`span`,{children:`Creating proxy`}),Q(`div`,{class:`pbar`,role:`progressbar`,"aria-label":`Proxy progress`,"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":T,children:Q(`i`,{style:{width:`${T}%`}})}),Q(`span`,{class:`mono`,children:[T,`%`]}),Q(`button`,{class:`btn`,"aria-disabled":!E||p,onClick:()=>void O(),children:`Cancel`})]}),C===`done`&&t.proxy&&Q(S,{children:[Q(`span`,{class:`ok`,children:`✓ Proxy ready`}),Q(`span`,{class:`why`,children:[`Saved to `,Q(`span`,{class:`mono`,children:t.proxy.file}),` (`,Ke(t.proxy.bytes),`).`]}),Q(`button`,{class:`btn ghost ib`,"aria-label":`Dismiss`,"data-tip":`Dismiss`,onClick:()=>y(x),children:Q($,{name:`x`})})]}),A]})})}var ps=2e3,ms=8e3,hs={kind:`none`},gs={kind:`pending`};async function _s(e,t,n){let r;try{r=await t.fetch(e.peaksUrl,{signal:n})}catch(e){if(n.aborted)throw e;return gs}if(r.status===202)return gs;if(r.status===501)return vs(e,t,n);if(r.status!==200)return hs;try{let e=await r.json(),t=e.peaks;return!Array.isArray(t)||t.length===0||typeof e.duration!=`number`||!(e.duration>0)||!t.every(e=>typeof e==`number`&&Number.isFinite(e))?hs:{kind:`wave`,wave:{peaks:Float32Array.from(t),duration:e.duration}}}catch(e){if(n.aborted)throw e;return hs}}async function vs(e,t,n){if(e.size===null||!(e.size<1e8))return hs;try{let r=await e.duration();if(n.aborted)throw new DOMException(`aborted`,`AbortError`);if(r===null||!(r>0)||r>900)return hs;let i=await t.fetch(e.mediaUrl,{signal:n});if(!i.ok)return hs;let{channels:a,duration:o}=await t.decode(await i.arrayBuffer());if(n.aborted)throw new DOMException(`aborted`,`AbortError`);let s=a[0]?.length??0;return s===0||!(o>0)?hs:{kind:`wave`,wave:{peaks:ys(ri(a,Math.min(ps,s))),duration:o}}}catch(e){if(n.aborted)throw e;return hs}}function ys(e){let t=0;for(let n of e)n>t&&(t=n);if(t>0)for(let n=0;n<e.length;n++)e[n]/=t;return e}var bs=40,xs=new Map;function Ss(e,t,n,r){return`${e}/${t}/${n}#${r??``}`}function Cs(e){return xs.has(e)}function ws(e){return xs.get(e)??null}function Ts(e,t){for(xs.delete(e),xs.set(e,t);xs.size>bs;)xs.delete(xs.keys().next().value)}function Es(e,t){let n=()=>void 0,r=()=>{let i=e.matchMedia(`(resolution: ${e.devicePixelRatio}dppx)`),a=()=>{n(),t(e.devicePixelRatio),r()};i.addEventListener(`change`,a),n=()=>i.removeEventListener(`change`,a)};return r(),()=>n()}var Ds=1500,Os=15e3,ks=15e3,As={fetch(e,t){let n=Ar();return fetch(e,{signal:t.signal,headers:n?{"x-rushes-project":n}:{}})},async decode(e){let t=await new(window.OfflineAudioContext??window.webkitOfflineAudioContext)(1,1,ms).decodeAudioData(e),n=[];for(let e=0;e<t.numberOfChannels;e++)n.push(t.getChannelData(e));return{channels:n,duration:t.duration}}};function js(e,t,n,r,i){let a=Ss(e,t.id,t.file,r),o=X(i),s=X([]);J(()=>{if(o.current=i,i>0)for(let e of s.current.splice(0))e(i)},[i]);let c=()=>o.current>0?Promise.resolve(o.current):new Promise(e=>{s.current.push(e),window.setTimeout(()=>e(null),ks)}),[l,u]=q(()=>Cs(a)?{key:a,wave:ws(a)}:null),d=X(null);return J(()=>{if(Cs(a)){u({key:a,wave:ws(a)});return}let r=new AbortController,i,o=Ds,s={peaksUrl:`/api/videos/${encodeURIComponent(e)}/versions/${encodeURIComponent(t.id)}/peaks`,mediaUrl:Nr(t.file),size:n,duration:c},l=async()=>{d.current=null,clearTimeout(i);let e;try{e=await _s(s,As,r.signal)}catch{return}if(r.signal.aborted)return;if(e.kind===`pending`){d.current=()=>void l(),i=window.setTimeout(()=>void l(),o),o=Math.min(o*2,Os);return}let t=e.kind===`wave`?e.wave:null;Ts(a,t),u({key:a,wave:t})};return l(),()=>{r.abort(),clearTimeout(i),d.current=null}},[a]),J(()=>{d.current?.()},[t]),l&&l.key===a?l.wave:null}var Ms=0;typeof location<`u`&&Rt(location.search).test&&(window.__rushesPicture={waveDraws:()=>Ms});var Ns=3,Ps=2;function Fs({wave:e,length:t}){let n=X(null),[r,i]=q({w:0,h:0,dpr:1});return J(()=>{let e=n.current;if(!e)return;let t=()=>{let t=e.getBoundingClientRect(),n=window.devicePixelRatio||1;i(e=>e.w===t.width&&e.h===t.height&&e.dpr===n?e:{w:t.width,h:t.height,dpr:n})};t();let r=new ResizeObserver(t);r.observe(e);let a=Es(window,t);return()=>{r.disconnect(),a()}},[]),J(()=>{let i=n.current;if(!i||r.w<=0||r.h<=0)return;Ms++,i.width=Math.round(r.w*r.dpr),i.height=Math.round(r.h*r.dpr);let a=i.getContext(`2d`);if(!a)return;a.setTransform(r.dpr,0,0,r.dpr,0,0),a.clearRect(0,0,r.w,r.h);let o=t>0?t:e.duration,s=e.peaks.length;if(!(o>0)||!(e.duration>0)||s===0)return;a.fillStyle=getComputedStyle(i).color;let c=e.duration/s;for(let t=0;t<r.w;t+=Ns){let n=t/r.w*o;if(n>=e.duration)break;let i=(t+Ns)/r.w*o,l=Math.min(s-1,Math.floor(n/c)),u=Math.min(s,Math.max(l+1,Math.ceil(i/c))),d=0;for(let t=l;t<u;t++)e.peaks[t]>d&&(d=e.peaks[t]);let f=Math.max(1,Math.min(1,d)*r.h);a.fillRect(t,(r.h-f)/2,Ps,f)}},[r,e,t]),Q(`canvas`,{ref:n,class:`pwave`,"aria-hidden":`true`})}function Is(e){J(()=>{let t=e.current;if(!t)return;let n=()=>{let e=[...t.children].filter(e=>e.getClientRects().length>0);if(e.length===0)return;let n=e.find(e=>e.classList.contains(`framebox`)),r=Math.min(...e.map(e=>e.getBoundingClientRect().top)),i=Math.max(...e.map(e=>e.getBoundingClientRect().bottom))-r-(n?n.getBoundingClientRect().height:0),a=`${Math.ceil(i+(n?200:0))}px`;t.style.getPropertyValue(`--player-floor`)!==a&&t.style.setProperty(`--player-floor`,a)},r=new ResizeObserver(n),i=()=>{r.disconnect();for(let e of t.children)r.observe(e);n()},a=new MutationObserver(i);return a.observe(t,{childList:!0}),i(),()=>{r.disconnect(),a.disconnect()}},[])}var Ls=700,Rs=16,zs=()=>typeof matchMedia==`function`&&matchMedia(`(hover: none)`).matches;function Bs({versions:e,shown:t,lockedVersion:n,onPick:r}){let i=[...e].reverse(),[a,o]=q(!1),[s,c]=q(t.id),[l,u]=q(null),[d,f]=q(!1),[p,m]=q(null),[h,g]=q(0),_=X(null),v=X(null),y=X(null),b=X({}),x=X({text:``,at:-1/0}),S=new Date,C=Wi(t),w=e=>{c(e),u(null),m(null),f(zs()),o(!0)},T=e=>{o(!1),m(null),e&&v.current?.focus()},E=e=>{T(!0),e!==t.id&&r(e)},D=a&&!e.some(e=>e.id===s);Y(()=>{D?T(!0):a&&b.current[s]?.focus()},[a,s,D]),Y(()=>{if(!a)return;let e=()=>{let e=_.current?.getBoundingClientRect(),t=y.current?.getBoundingClientRect();if(!e||!t)return;let n=document.documentElement.clientWidth-Rs;g(Math.max(0,Math.min(e.left+t.width-n,e.left-Rs)))};return e(),window.addEventListener(`resize`,e),()=>window.removeEventListener(`resize`,e)},[a]),J(()=>{if(!a)return;let e=e=>{_.current?.contains(e.target)||T(!1)};return document.addEventListener(`pointerdown`,e,!0),document.addEventListener(`focusin`,e,!0),()=>{document.removeEventListener(`pointerdown`,e,!0),document.removeEventListener(`focusin`,e,!0)}},[a]);let O=e=>{if(e.key===`Tab`){T(!1);return}if(e.metaKey||e.ctrlKey||e.altKey)return;let t=i.findIndex(e=>e.id===s),n=sa(e.key,t,i.length);if(n!==null){e.preventDefault(),e.stopPropagation(),u(null),c(i[n].id);return}if(e.key===`Escape`){e.preventDefault(),e.stopPropagation(),T(!0);return}if(e.key===`Enter`||e.key===` `){e.preventDefault(),e.stopPropagation(),E(s);return}if(e.key===`ArrowLeft`||e.key===`ArrowRight`){e.preventDefault(),e.stopPropagation();return}if(/^\d$/.test(e.key)){e.preventDefault(),e.stopPropagation();let t=e.timeStamp-x.current.at<Ls?x.current.text+e.key:e.key;x.current={text:t,at:e.timeStamp};let n=oa(i.map(e=>e.id),t);n&&(u(null),c(n));return}e.key.length===1&&e.stopPropagation()},k=e=>{if(d&&p!==e){m(e),c(e);return}E(e)},A=i.find(e=>e.id===(l??s))??t;return Q(`div`,{class:`vwrap`,ref:_,children:[Q(`button`,{ref:v,type:`button`,class:`vbtn`,"data-version":t.id,"aria-haspopup":`listbox`,"aria-expanded":a,"aria-controls":a?`vlist`:void 0,"aria-label":`Version: ${t.id} · ${C}`,onClick:()=>a?T(!1):w(t.id),onKeyDown:e=>{!a&&(e.key===`ArrowDown`||e.key===`ArrowUp`)&&(e.preventDefault(),e.stopPropagation(),w(t.id))},children:[Q(`span`,{class:`vid`,children:t.id}),Q(`span`,{class:`vlbl`,dir:`auto`,children:C}),Q($,{name:`chev`})]}),a&&Q(`div`,{ref:y,class:`vmenu${d?` touch`:``}`,style:h?{left:`${-h}px`}:void 0,children:[Q(`div`,{class:`vlist`,id:`vlist`,role:`listbox`,"aria-label":`Versions`,onKeyDown:O,onMouseLeave:()=>u(null),children:i.map(e=>Q(`button`,{type:`button`,role:`option`,class:`vrow`,"data-version":e.id,"data-on":e.id===(l??s)?`true`:`false`,"aria-selected":e.id===t.id,"aria-label":Vs(e,n,S),"aria-describedby":!d&&e.id===A.id?`vdetail`:void 0,tabIndex:e.id===s?0:-1,ref:t=>{b.current[e.id]=t},onMouseEnter:()=>u(e.id),onClick:()=>k(e.id),children:[Q(`span`,{class:`vid`,children:e.id}),Q(`span`,{class:`vlbl`,dir:`auto`,children:Wi(e)}),Q(`span`,{class:`vwhen`,children:[e.id===n&&Q($,{name:`lock`}),ia(e.addedAt,S)]}),d&&p===e.id&&Q(`span`,{class:`vinline`,dir:`auto`,children:[ji(e.note)||`No note.`,Q(`span`,{class:`vmeta`,children:ca(e,S)})]})]}))}),!d&&Q(`div`,{class:`vdetail`,id:`vdetail`,children:[Q(`h4`,{children:A.id}),Q(`p`,{dir:`auto`,children:ji(A.note)||`No note.`}),Q(`span`,{class:`vmeta`,children:ca(A,S)})]})]})]})}function Vs(e,t,n){return[e.id,Wi(e),e.id===t?`locked`:``,aa(e.addedAt,n)].filter(Boolean).join(`, `)}function Hs({version:e}){let[t,n]=q(!1),[r,i]=q(!1),a=X(null);Y(()=>{let e=a.current;if(!e)return;let t=()=>i(e.scrollHeight>e.clientHeight+1);t();let n=new ResizeObserver(t);return n.observe(e),()=>n.disconnect()},[e.id,e.note,t]);let o=ji(e.note);if(!o)return null;let s=`vnote-${e.id}`;return Q(`div`,{class:`vnote`,children:[Q(`span`,{ref:a,id:s,class:t?`vtext`:`vtext vclamp`,dir:`auto`,children:o}),(r||t)&&Q(`button`,{type:`button`,class:`vmore`,"aria-expanded":t,"aria-controls":s,onClick:()=>n(!t),children:t?`Less`:`More`})]})}var Us=e=>e instanceof HTMLElement&&(e.isContentEditable||/^(INPUT|TEXTAREA|SELECT)$/.test(e.tagName));function Ws({video:e,version:t,fps:n,notes:r,toast:i,onChanged:a,onPendingChange:o,startAt:s,grab:c,onGrabChange:l,playerRef:u,ffmpeg:d=!1,autoProxy:f=!1,proxyJob:p,noteProxyJob:m,source:h=`proxy`,onSourceChange:g,fileSize:_=null,fileRev:v,formats:y=[],format:b=null,formatMissing:x=!1,onPrimarySize:C,onBoxPendingChange:w,onFormatChange:T}){let E=X(null),D=X(null),O=X(null),k=X(null),[A,j]=q(0),[M,N]=q(t.duration??0),[P,F]=q(t.duration?t.file:null),I=b?y.find(e=>e.id===b)??null:null,L=!I||I.primary,ee=I??y.find(e=>e.primary)??null,te=ee?ee.width/ee.height:null,R=b!==null&&y.length>=2,ne=y.find(e=>e.primary)?.id??null,re=Qn(r,b),ie=$n(r,b),[ae,oe]=q(`this`),[z,B]=q(te??16/9),[se,ce]=q(!1),[le,ue]=q(null),[V,de]=q({in:null,out:null}),[fe,H]=q(!1),[U,me]=q(null),[be,xe]=q({w:0,h:0}),[Se,Ce]=q(null),[we,Te]=q(null),[Ee,G]=q(!1),De=X(null);Is(De);let Oe=js(e.id,t,_,v,P===t.file?M:t.duration??0),ke=X(!1),Ae=X(!1),je=X({}),Me=X(se);J(()=>{Me.current=se},[se]);let Ne=X(!0);J(()=>()=>{Ne.current=!1},[]);let Pe=X(t.id);J(()=>{Pe.current=t.id},[t.id]),J(()=>{let e=V.in!==null||Se!==null||Ee;return o?.(e),()=>o?.(!1)},[V.in,Se,Ee]),J(()=>(Se!==null&&oe(`this`),w?.(Se!==null),()=>w?.(!1)),[Se]);let Fe=X(void 0);J(()=>{ue(null),j(0),B(te??16/9),de({in:null,out:null}),Ce(null),Fe.current!==void 0&&l(e.id,null),Fe.current=t.file,Te(null),oe(`this`)},[t.file]);let Ie=Se?`this`:ae,Le=n=>pe(e.versions.find(e=>e.id===n.version)??t),[Re,ze]=q({}),Be=e=>e.id in Re?Re[e.id]:e.format,Ve=e=>ze(t=>{if(!(e in t))return t;let{[e]:n,...r}=t;return r});J(()=>{ze(e=>{let t=Object.keys(e).filter(t=>r.some(n=>n.id===t&&n.format!==e[t]));return t.length===Object.keys(e).length?e:Object.fromEntries(t.map(t=>[t,e[t]]))})},[r]);let He=async(e,t)=>{if(Be(e)!==t){ze(n=>({...n,[e.id]:t}));try{await Z.patch(`/api/notes/${e.id}`,{format:t})}catch(t){Ve(e.id),Ke.current?.id===e.id&&(Ke.current=null),i(`Couldn't change that note: ${t.message}`)}a()}};J(()=>{we&&!re.some(e=>e.id===we)&&Te(null)},[b,r]);let Ke=X(null),qe=X(b);if(qe.current!==b){qe.current=b;let e=document.activeElement,t=e instanceof HTMLElement&&e.closest(`.nfmt`)?e.closest(`.list > .note[data-note]`):null;t&&!Ke.current&&(Ke.current={id:t.dataset.note,fallback:!0})}Y(()=>{let e=Ke.current;if(!e)return;let t=document.activeElement,n=!t||t===document.body||!t.isConnected,r=document.querySelector(`.list > .note[data-note="${CSS.escape(e.id)}"] .t`);r?(Ke.current=null,n&&r.focus()):e.fallback&&(Ke.current=null,n&&document.querySelector(`.otherrow`)?.focus())},[b,r]);let Je=L&&!!t.proxy&&h!==`original`,Ye=Nr(Je?t.proxy.file:L?t.file:I.file),Xe=le===Ye,Ze=X(null),Qe=X(null);if(Qe.current&&Qe.current.src!==Ye){let e=E.current;Qe.current.cut===t.file?!Ze.current&&e&&(Ze.current={t:e.error?A:e.currentTime,play:!e.paused&&!e.error}):Ze.current=null}Qe.current={cut:t.file,src:Ye};let $e=X(null),et=X(null),tt=I?.id??`primary`,nt=X(!0);Y(()=>{if(nt.current){nt.current=!1;return}let e=D.current;if(!ee||!e)return;let t=ee.width/ee.height;if(t===z)return;let n=e.getBoundingClientRect();$e.current={width:n.width,height:n.height},B(t)},[tt]),Y(()=>{let e=$e.current,t=D.current;if($e.current=null,!e||!t)return;et.current?.cancel(),et.current=null;let n=t.getBoundingClientRect(),r=typeof matchMedia==`function`&&matchMedia(`(prefers-reduced-motion: reduce)`).matches,i=Zn(e,{width:n.width,height:n.height},r);Rt(location.search).test&&(window.__rushesLastReshape={animated:i!==null,ms:i?160:0}),i&&(et.current=t.animate(i,{duration:160,easing:`ease-out`}))},[z]),J(()=>{let e=E.current;if(!e)return;let t=()=>ue(Ye);return e.error&&t(),e.addEventListener(`error`,t),()=>e.removeEventListener(`error`,t)},[Ye]);let rt=X(null);rt.current=!L&&M>0?M:null;let ot=e=>{let t=rt.current;t===null||e.paused||e.currentTime<t||(e.pause(),e.currentTime=t)};J(()=>{if(!se)return;let e=0,t=()=>{E.current&&(ot(E.current),j(E.current.currentTime)),e=requestAnimationFrame(t)};return e=requestAnimationFrame(t),()=>cancelAnimationFrame(e)},[se]);let st=()=>Ze.current?.t??E.current?.currentTime??A,ct=()=>ge(st(),n),lt=e=>{let t=E.current;if(!t)return;let n=Math.min(Math.max(0,e),M||t.duration||e);if(Ze.current){Ze.current.t=n,j(n);return}t.currentTime=n,j(t.currentTime)},ut=()=>{let e=E.current;e&&(e.paused?(rt.current!==null&&e.currentTime>=rt.current-.001&&(e.currentTime=0),e.play().catch(()=>i(`Couldn't play this file`))):e.pause())},dt=e=>{E.current?.pause(),lt(_e(st(),n,e,M))},ft=()=>de({in:ct(),out:null}),pt=()=>{let e=ct(),t=V.in??0;if(e<=t)return i(`Out has to come after In`);de({in:t,out:e})},mt=()=>de({in:null,out:null}),ht=X(0),[gt,_t]=q(0),vt=async()=>{let r=E.current,o=ct(),s=e.id,c=t.id,u=L?null:b,f=++ht.current,p=!1;try{let e=he(o,n),t;if(d){p=!0,_t(e=>e+1);let n=await Mr(s,c,o,u);e=n.frame??e,t=n.png}else{if(!r||!r.videoWidth)return i(`Nothing to grab yet`);let e=document.createElement(`canvas`);e.width=r.videoWidth,e.height=r.videoHeight,e.getContext(`2d`).drawImage(r,0,0),t=e.toDataURL(`image/png`)}let m=await Z.post(`/api/grabs`,{video:s,version:c,frame:e,png:t,...u?{format:u}:{}});if(f!==ht.current){a();return}i(`Saved to ${m.grab}`),a(),Ne.current&&c===Pe.current&&l(s,m.grab)}catch(e){f===ht.current&&i(e.message)}finally{p&&Ne.current&&_t(e=>e-1)}},yt=async r=>{let i=V.in!==null&&V.out!==null,o=i?V.in:ct();await Z.post(`/api/notes`,{stage:`picture`,video:e.id,version:t.id,scope:i?`range`:`point`,t:o,tOut:i?V.out:null,frame:he(o,n),text:r,box:Se,grab:c,...R?{format:Ie===`this`?b:null}:{}}),mt(),oe(`this`),Ce(null),l(e.id,null),a()},bt=X(()=>void 0);bt.current=e=>{if(Us(e.target)||e.metaKey||e.ctrlKey||e.altKey)return;let t=e.key.toLowerCase();if(e.key===` `){if(Lt(e.target))return;e.preventDefault(),ut()}else e.key===`ArrowLeft`?(e.preventDefault(),dt(e.shiftKey?-10:-1)):e.key===`ArrowRight`?(e.preventDefault(),dt(e.shiftKey?10:1)):t===`i`?ft():t===`o`?pt():t===`g`&&!e.repeat?vt():t===`b`?H(e=>!e):t===`n`&&(e.preventDefault(),k.current?.focus())},J(()=>{let e=e=>bt.current(e);return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[]);let xt=(e,t)=>{let n=E.current;return it(n?.videoWidth??0,n?.videoHeight??0,e,t)},St=e=>{let t=O.current.getBoundingClientRect(),n=xt(t.width,t.height);return{x:e.clientX-t.left-n.x,y:e.clientY-t.top-n.y,w:n.w,h:n.h}};J(()=>{let e=O.current;if(!e)return;let t=()=>xe(t=>t.w===e.clientWidth&&t.h===e.clientHeight?t:{w:e.clientWidth,h:e.clientHeight});t();let n=new ResizeObserver(t);return n.observe(e),()=>n.disconnect()},[]);let Ct=e=>{if(!fe)return;let t=St(e);e.target.setPointerCapture(e.pointerId),me({x0:t.x,y0:t.y,x1:t.x,y1:t.y,w:t.w,h:t.h})},wt=e=>{if(!U)return;let t=St(e);me({...U,x1:t.x,y1:t.y})},Tt=e=>{if(!U)return;let t=St(e),n=at(U.x0,U.y0,t.x,t.y,U.w,U.h);me(null),H(!1),ke.current=!0,n.w>.01&&n.h>.01&&Ce(n)},Et=U?at(U.x0,U.y0,U.x1,U.y1,U.w,U.h):null,Dt=xt(be.w,be.h),Ot=e=>({left:`${e.x*100}%`,top:`${e.y*100}%`,width:`${e.w*100}%`,height:`${e.h*100}%`}),kt=e=>`${M?Math.min(100,Math.max(0,e/M*100)):0}%`,At=M?t.shots.filter(e=>e.start<M):t.shots,jt=Ue(At,ge(A,n));J(()=>{Me.current&&jt!==null&&je.current[jt.n]?.scrollIntoView({block:`nearest`,inline:`nearest`})},[jt?.n]);let Mt=re.map(e=>({n:e,at:ve(e,t.id)})).filter(({at:e})=>e.t!==null),Nt=re.find(e=>e.id===we)??null,Pt=Nt?.box&&(!Nt.version||Nt.version===t.id)&&er(Nt,b,ne)?Nt.box:null,Ft=V.in===null?null:V.out===null?`${W(V.in)} →`:ye(V.in,V.out),It=V.in!==null&&V.out===null?`Set an Out point`:`Note at ${Ft&&V.out!==null?Ft:W(A)}`,zt=e=>{N(L?e.duration||t.duration||0:t.duration??I?.duration??(e.duration||0)),F(t.file),L&&t.width===null&&e.videoWidth&&e.videoHeight&&C?.(t.file,e.videoWidth,e.videoHeight),ue(e=>e===Ye?null:e),e.videoWidth&&e.videoHeight&&B(e.videoWidth/e.videoHeight),Ae.current||(Ae.current=!0,s&&(e.currentTime=Math.min(s,e.duration||s),j(e.currentTime)));let n=Ze.current;n&&(Ze.current=null,e.currentTime=Math.min(n.t,e.duration||n.t),j(n.t),n.play&&e.play().catch(()=>void 0))},Bt=t=>{t!==h&&g?.(e.id,t)};return Q(`div`,{class:`split`,children:[Q(`div`,{class:`stack`,ref:De,children:[Q(`div`,{class:`framebox`,style:{height:`min(640px, 70vh, calc(100cqw / ${z}))`},children:Q(`div`,{class:`frame`,ref:D,style:{aspectRatio:String(z),"--ar":String(z)},children:[x&&!L&&Q(`div`,{class:`msg`,children:`File not found`}),Xe&&!L&&!x&&Q(`div`,{class:`msg`,children:`This file won't play in a browser. Ask your agent for an H.264 MP4 of this format.`}),Xe&&L&&!d&&Q(`div`,{class:`msg`,children:`This file won't play in a browser. Ask your agent for an H.264 MP4 of this cut.`}),Xe&&L&&d&&t.proxy&&!Je&&Q(`div`,{class:`msg`,children:`This file won't play in a browser.`}),Q(`video`,{hidden:Xe||x&&!L,ref:e=>{E.current=e,u&&(u.current=e),e&&e.readyState>=1&&zt(e)},src:Ye,preload:`auto`,playsInline:!0,onLoadedMetadata:e=>zt(e.target),onTimeUpdate:e=>{let t=e.target;ot(t),!se&&!Ze.current&&j(t.currentTime)},onSeeked:e=>!Ze.current&&j(e.target.currentTime),onPlay:()=>ce(!0),onPause:()=>ce(!1),onEnded:()=>ce(!1)}),Q(`div`,{ref:O,class:`overlay${fe?` drawing`:``}`,onPointerDown:Ct,onPointerMove:wt,onPointerUp:Tt,onClick:()=>{ke.current?ke.current=!1:fe||ut()},children:Q(`div`,{class:`pic`,style:{left:`${Dt.x}px`,top:`${Dt.y}px`,width:`${Dt.w}px`,height:`${Dt.h}px`},children:[Pt&&Q(`div`,{class:`bx saved`,style:Ot(Pt)}),Se&&Q(`div`,{class:`bx`,style:Ot(Se)}),Et&&Q(`div`,{class:`bx`,style:Ot(Et)})]})}),Q(`div`,{class:`tcover`,children:[`f`,he(A,n),jt&&` · shot ${We(jt.n)}`]}),t.proxy&&L&&Q(`div`,{class:`srcswitch`,role:`group`,"aria-label":`Which file plays`,children:[Q(`button`,{type:`button`,class:`tip-below tip-start tip-wrap`,"aria-pressed":Je,"aria-label":`Proxy`,"data-tip":`Playing the lightweight copy. Notes and timings are the same.`,onClick:e=>{e.currentTarget.blur(),Bt(`proxy`)},children:`Proxy`}),Q(`button`,{type:`button`,class:`tip-below tip-start tip-wrap`,"aria-pressed":!Je,"aria-label":`Original`,"data-tip":`Play the full-quality file. It may stutter.`,onClick:e=>{e.currentTarget.blur(),Bt(`original`)},children:`Original`})]})]})}),m&&Q(fs,{hidden:!L,video:e,version:t,ffmpeg:d,autoProxy:f,job:p,broken:Xe&&!Je,duration:M,toast:i,onChanged:a,noteProxyJob:m},t.id),Q(`div`,{class:`bar`,children:[Q(`button`,{class:`btn ghost ib`,"data-tip":`Back one frame ←`,"aria-label":`Back one frame`,onClick:()=>dt(-1),children:Q($,{name:`prev`})}),Q(`button`,{class:`btn ib`,"data-tip":`Play Space`,"aria-label":se?`Pause`:`Play`,onClick:ut,children:Q($,{name:se?`pause`:`play`})}),Q(`button`,{class:`btn ghost ib`,"data-tip":`Forward one frame →`,"aria-label":`Forward one frame`,onClick:()=>dt(1),children:Q($,{name:`next`})}),Q(`span`,{class:`tc`,"aria-label":`Timecode`,children:[W(A),Q(`small`,{children:[`/ `,W(M)]})]}),Q(`span`,{class:`sp`}),Ft&&Q(`span`,{class:`chipx`,children:[Q(`span`,{class:`mono`,children:Ft}),Q(`button`,{"aria-label":`Clear range`,onClick:mt,children:Q($,{name:`x`})})]}),Q(`button`,{class:`btn ghost ib`,"data-tip":`Set in I`,"aria-label":`Set in point`,onClick:ft,children:Q($,{name:`in`})}),Q(`button`,{class:`btn ghost ib`,"data-tip":`Set out O`,"aria-label":`Set out point`,onClick:pt,children:Q($,{name:`out`})}),Q(`span`,{class:`vsep`}),Q(`button`,{class:`btn ghost ib`,"data-tip":`Draw a box B`,"aria-label":`Draw a box`,"aria-pressed":fe,onClick:()=>H(!fe),children:Q($,{name:`box`})}),Q(`button`,{class:`btn ghost ib`,"data-tip":`Grab frame G`,"aria-label":`Grab frame`,"aria-busy":gt>0,onClick:()=>void vt(),children:Q($,{name:`camera`})})]}),Q(`div`,{class:`track`,role:`slider`,"aria-label":`Timeline`,"aria-valuemin":0,"aria-valuemax":M,"aria-valuenow":A,onClick:e=>{let t=e.currentTarget.getBoundingClientRect();lt((e.clientX-t.left)/t.width*M)},children:[Oe&&Q(Fs,{wave:Oe,length:M}),Mt.map(({n:e,at:t})=>t.tOut!==null&&Q(`div`,{class:`span ${e.status}`,style:{left:kt(t.t),width:kt(t.tOut-t.t)}})),V.in!==null&&Q(`div`,{class:`span live`,style:{left:kt(V.in),width:kt((V.out??V.in+.2)-V.in)}}),At.filter(e=>e.start>0).map(e=>Q(`div`,{class:`tick`,style:{left:kt(e.start)}})),Mt.map(({n:e,at:t})=>{let n=rr(e,R);return Q(`div`,{class:`mk ${e.status}${R&&e.format===null?` ring`:``}`,style:{left:kt(t.t)},title:n?`${n} · ${e.text}`:e.text})}),Q(`div`,{class:`playhead`,style:{left:kt(A)}})]}),Q(`div`,{class:`ends`,children:[Q(`span`,{children:`0:00`}),Q(`span`,{children:W(M)})]}),Q(Hs,{version:t},t.id)]}),At.length>0&&Q(`div`,{class:`shots`,"data-player":!0,children:At.map(e=>Q(`button`,{type:`button`,class:`shot`,ref:t=>{je.current[e.n]=t},"aria-current":jt?.n===e.n?`true`:void 0,onClick:()=>{E.current?.pause(),lt(Ge(e.start,n))},children:[Q(`span`,{class:`mono`,children:[We(e.n),` · `,e.start.toFixed(2),`s`]}),Q(`span`,{class:`name`,children:e.name}),e.tag&&Q(`span`,{class:`tag`,children:e.tag})]}))}),Q(Zo,{notes:re,version:t.id,selectedId:we,placeholder:It,inputRef:k,toast:i,onAdd:yt,onChanged:a,onTextChange:G,formatTag:e=>rr(e,R),cardExtra:R&&I?e=>Q(Jo,{name:`Note applies to`,label:I.label,width:I.width,height:I.height,value:Be(e)===null?`all`:`this`,lockedReason:e.box?tr:null,onChange:t=>void He(e,t===`all`?null:I.id)}):void 0,formatScope:R&&I?{label:I.label,width:I.width,height:I.height,value:Ie,onChange:oe,lockedReason:Se?tr:null,hint:nr(I.label,Ie,Se!==null)}:void 0,listFooter:e=>{let n=ie.filter(t=>e===`all`||t.status===e);return n.length>0?Q(ls,{notes:n,version:t.id,viewsHere:y,ownViews:Le,onShow:(e,t)=>{Se||(Ke.current={id:t.id,fallback:!1}),T?.(e)},onRestore:e=>{Ke.current={id:e.id,fallback:!1},He(e,null)}}):null},onSeek:(e,t)=>{E.current?.pause(),lt(e),Te(t.id)},attachments:(Se||c)&&Q(S,{children:[Se&&Q(`span`,{class:`chipx`,children:[Q($,{name:`box`}),`Box`,Q(`button`,{"aria-label":`Remove box`,onClick:()=>Ce(null),children:Q($,{name:`x`})})]}),c&&Q(`span`,{class:`chipx`,children:[Q($,{name:`image`}),`Frame `,c.match(/_f(\d+)\.png$/)?.[1],Q(`button`,{"aria-label":`Remove frame`,onClick:()=>l(e.id,null),children:Q($,{name:`x`})})]})]})})]})}var Gs=500;function Ks(e,t){let n=X(void 0),r=X(e);return r.current=e,J(()=>()=>{n.current!==void 0&&(clearTimeout(n.current),r.current())},[]),{schedule(){clearTimeout(n.current),n.current=window.setTimeout(()=>{n.current=void 0,r.current()},t)},flush(){n.current!==void 0&&(clearTimeout(n.current),n.current=void 0,r.current())}}}var qs=(e,t)=>e.slice(0,t).filter(n=>n.heading===e[t].heading).length,Js=e=>String(e).padStart(2,`0`);function Ys({shot:e,large:t}){let[n,r]=q(null);return!e.still||n===e.still?Q(`span`,{class:`nostill`,children:t?`No still for this shot yet`:`No still`}):Q(`img`,{src:Nr(e.still),alt:`Still for shot ${e.n}, ${e.name}`,onError:()=>r(e.still)})}function Xs({shot:e,save:t,onZoom:n}){let[r,i]=q(e.description),[a,o]=q(e.direction),s=X(!1),c=X(null);J(()=>{s.current||i(e.description)},[e.description]),J(()=>{s.current||o(e.direction)},[e.direction]),Y(()=>{let e=c.current;e&&(e.style.height=`auto`,e.style.height=`${e.scrollHeight+2}px`)},[r]);let l=()=>{let n={};r.trim()!==e.description.trim()&&(n.description=r),a.trim()!==e.direction.trim()&&(n.direction=a),(n.description!==void 0||n.direction!==void 0)&&t.shot(e,n)},u=Ks(()=>{s.current=!1,l()},Gs),d=Ks(()=>{s.current=!1,l()},Gs),f=r.trim()!==e.current.trim()||a.trim()!==e.directionCurrent.trim(),p=e.status===`approved`;return Q(`div`,{class:`sbrow${f?` changed`:``}`,"data-shot":e.heading,children:[Q(`div`,{class:`sbid`,children:[Q(`button`,{class:`sbstill`,"aria-label":`Enlarge the still for shot ${e.n}`,"data-tip":`Enlarge`,onClick:n,children:Q(Ys,{shot:e})}),Q(`div`,{class:`sbmeta`,children:[Q(`b`,{children:Js(e.n)}),Q(`span`,{children:e.length===null?`no length`:`${e.length.toFixed(1)} s`}),e.tag&&Q(`span`,{class:`sbtag`,children:e.tag})]})]}),Q(`div`,{class:`cur`,children:[Q(`b`,{class:`sbname`,children:e.name}),e.current]}),Q(`textarea`,{ref:c,class:`input`,"aria-label":`Your version of shot ${e.n}`,value:r,onInput:e=>{s.current=!0,i(e.target.value),u.schedule()},onBlur:()=>u.flush()}),Q(`div`,{class:`sblow`,children:[Q(`input`,{class:`sbdir`,placeholder:`Direction`,"aria-label":`Direction for shot ${e.n}`,value:a,onInput:e=>{s.current=!0,o(e.target.value),d.schedule()},onBlur:()=>d.flush()}),f&&Q(`button`,{class:`btn ghost ib`,"data-tip":`Revert to current`,"aria-label":`Revert shot ${e.n}`,onClick:()=>{s.current=!1,i(e.current),o(e.directionCurrent),t.shot(e,{description:e.current,direction:e.directionCurrent})},children:Q($,{name:`undo`})}),Q(`button`,{class:`btn ib okd${p?` on`:``}`,"data-tip":p?`Unapprove`:`Approve`,"aria-label":`Approve shot ${e.n}`,"aria-pressed":p,onClick:()=>t.shot(e,{status:p?`draft`:`approved`}),children:Q($,{name:`check`})})]})]})}function Zs({shot:e,onClose:t}){let n=X(null);return Y(()=>{n.current?.focus()},[]),Q(`div`,{class:`sblight`,role:`dialog`,"aria-modal":`true`,"aria-label":`Shot ${e.n}, ${e.name}`,tabIndex:-1,ref:n,onClick:t,onKeyDown:e=>{e.key===`Escape`?(e.preventDefault(),e.stopPropagation(),t()):e.key===`Tab`&&e.preventDefault()},children:Q(`div`,{class:`sblbx`,children:[Q(`div`,{class:`sbbig`,children:Q(Ys,{shot:e,large:!0})}),Q(`div`,{class:`sblcap`,children:[Q(`b`,{children:[Js(e.n),` · `,e.name]}),` `,e.tag&&Q(`span`,{class:`sbtag`,children:e.tag}),Q(`p`,{children:e.description})]})]})})}function Qs({board:e,brief:t,toast:n,onChanged:r,settle:i}){let{latest:a,enqueue:o}=Xa(`storyboard`,e,{toast:n,onChanged:r,settle:i}),[s,c]=q(null),l=X(null),u={shot:(e,t)=>{let n=a.current.shots.findIndex(t=>t.index===e.index),r=n<0?0:qs(a.current.shots,n),i=t.status===`approved`&&t.description===void 0&&t.direction===void 0;o(`shot ${e.n}`,(n,a)=>{let o=n.shots.filter(t=>t.heading===e.heading)[r];if(!o){let t=n.shots.filter(t=>t.name===e.name);t.length===1&&(o=t[0])}return o&&a&&i&&(o.description!==e.description||o.direction!==e.direction)?{refuse:`the agent changed this shot while you were looking at it. Read it again, then approve.`}:o?{path:`/api/storyboard/shots/${o.index}`,body:{heading:o.heading,...t}}:null})}},d=ze(t),f=e.shots.find(e=>e.heading===s);return Q(`div`,{class:`col`,children:[Q(`div`,{class:`shead`,children:[Q(`h2`,{children:`Storyboard`}),Q(`span`,{class:`meta`,children:e.total>0&&`${e.total} shot${e.total===1?``:`s`} · ${e.changed} changed`})]}),Q(`div`,{class:`sbtotal mono`,"aria-label":`Planned length`,children:[Q(`span`,{children:d?`${e.plannedLength.toFixed(1)} / ${d} s planned`:`${e.plannedLength.toFixed(1)} s planned`}),d&&Q(`span`,{class:`bar`,children:Q(`i`,{style:{width:`${Math.min(100,e.plannedLength/d*100)}%`}})})]}),e.total===0&&Q(`p`,{class:`sbnone`,children:"storyboard.md has no shots yet. Your agent adds them as `## Shot 01 · Name` sections."}),Q(`div`,{class:`sbhead`,children:[Q(`span`,{}),Q(`span`,{children:`Current`}),Q(`span`,{children:`Yours`})]}),Q(`div`,{style:{display:`grid`,gap:`12px`},children:e.shots.map((t,n)=>Q(Xs,{shot:t,save:u,onZoom:()=>{l.current=document.activeElement,c(t.heading)}},`${t.heading}#${qs(e.shots,n)}`))}),f&&Q(Zs,{shot:f,onClose:()=>{c(null),l.current?.focus()}})]})}function $s({selected:e,rows:t,marks:n,open:r,locked:i,ready:a,onCopyReady:o,onPick:s}){let[c,l]=q(!1),[u,d]=q(0),[f,p]=q({left:0,top:0}),m=X(null),h=X(null),g=X([]),_=()=>{let n=h.current?.getBoundingClientRect();n&&p({left:Math.max(8,n.left),top:n.bottom}),d(Math.max(0,t.findIndex(t=>t.page===e))),l(!0)},v=e=>{l(!1),e&&h.current?.focus()};Y(()=>{c&&g.current[u]?.focus()},[c,u]),J(()=>{if(!c)return;let e=e=>{m.current?.contains(e.target)||v(!1)};return document.addEventListener(`pointerdown`,e,!0),document.addEventListener(`focusin`,e,!0),()=>{document.removeEventListener(`pointerdown`,e,!0),document.removeEventListener(`focusin`,e,!0)}},[c]);let y=e=>{if(e.key===`Tab`)return v(!1);if(e.metaKey||e.ctrlKey||e.altKey)return;if(e.key===`ArrowLeft`||e.key===`ArrowRight`){e.preventDefault(),e.stopPropagation();return}let n=e.key===`ArrowDown`?1:e.key===`ArrowUp`?-1:e.key===`Home`?-t.length:e.key===`End`?t.length:0;n===0?e.key===`Escape`?(e.preventDefault(),e.stopPropagation(),v(!0)):e.key.length===1&&e.stopPropagation():(e.preventDefault(),e.stopPropagation(),d(e=>Math.min(t.length-1,Math.max(0,e+n))))},b=e=>Q(`i`,{class:`pm ${e}`});return Q(`span`,{class:`plan`,ref:m,children:[Q(`button`,{ref:h,class:`tab`,role:`tab`,"aria-selected":e!==null,"aria-haspopup":`menu`,"aria-expanded":c,"data-locked":i?`true`:void 0,onClick:()=>c?v(!1):_(),onKeyDown:e=>{e.key===`ArrowDown`&&!c&&(e.preventDefault(),_())},children:[Q($,{name:`list`}),`Planning`,n?Q(`span`,{class:`pmarks`,title:a?`Ready to build`:`Brief, script and storyboard`,children:a?Q($,{name:`check`,class:`pready`}):Q(S,{children:[b(n.brief),b(n.script),b(n.storyboard)]})}):i?Q($,{name:`lock`,class:`lk`}):r>0&&Q(`span`,{class:`dot`,title:`${r} open`}),Q($,{name:`chev`,class:`chev`})]}),c&&Q(`div`,{class:`planmenu`,role:`menu`,"aria-label":`Planning`,style:{left:`${f.left}px`,top:`${f.top}px`},onKeyDown:y,children:[t.map((t,n)=>Q(`button`,{ref:e=>{g.current[n]=e},role:`menuitem`,class:`planitem${t.page===e?` cur`:``}`,"data-locked":t.unlocked?void 0:`true`,tabIndex:n===u?0:-1,"data-tip":t.unlocked?void 0:`Locked: ask your agent for ${t.ask}`,onClick:()=>{v(!0),s(t.page)},children:[Q($,{name:t.icon}),Q(`span`,{children:t.name}),t.unlocked?t.progress===null?null:t.progress===`ok`?Q($,{name:`check`,class:`pi`}):Q(`i`,{class:`pm ${t.progress}`}):Q($,{name:`lock`,class:`lk`})]},t.page)),a&&Q(`div`,{class:`planready`,children:[Q(`div`,{class:`rd`,children:[Q($,{name:`check`}),`Ready to build`]}),Q(`button`,{role:`menuitem`,class:`btn`,tabIndex:-1,onClick:()=>{v(!1),o()},children:[Q($,{name:`copy`}),`Copy prompt for your agent`]})]})]})]})}var ec={approved:{color:`var(--done)`,label:`Approved`},flagged:{color:`var(--todo)`,label:`Flagged`},draft:{color:`var(--text-3)`,label:`Draft`}},tc=500;function nc(e,t){let n=X(void 0),r=X(e);return r.current=e,J(()=>()=>{n.current!==void 0&&(clearTimeout(n.current),r.current())},[]),{schedule(){clearTimeout(n.current),n.current=window.setTimeout(()=>r.current(),t)},flush(){n.current!==void 0&&(clearTimeout(n.current),n.current=void 0,r.current())}}}function rc({section:e,wps:t,toast:n,onChanged:r}){let[i,a]=q(e.proposed??e.current),[o,s]=q(e.direction),c=X(!1),l=X(null);J(()=>{c.current||a(e.proposed??e.current)},[e.proposed,e.current]),J(()=>{c.current||s(e.direction)},[e.direction]),Y(()=>{let e=l.current;e&&(e.style.height=`auto`,e.style.height=`${e.scrollHeight+2}px`)},[i]);let u=async t=>{try{await Z.patch(`/api/script/${encodeURIComponent(e.id)}`,t)}catch(t){n(`Couldn't save ${e.id.toUpperCase()}: ${t.message}`)}r()},d=nc(()=>{c.current=!1,u({proposed:i.trim()===e.current.trim()?null:i})},tc),f=nc(()=>{c.current=!1,u({direction:o})},tc),p=e.end-e.start,m=be(i,p,t),h=i.trim()!==e.current.trim(),g=ec[e.status];return Q(`div`,{class:`srow${h?` changed`:``}`,"data-section":e.id,children:[Q(`div`,{class:`sgrid`,children:[Q(`div`,{class:`when`,children:[Q(`b`,{children:e.id.toUpperCase()}),Q(`span`,{children:[W(e.start).replace(/\.\d+$/,``),`–`,W(e.end).replace(/\.\d+$/,``)]}),Q(`span`,{class:`stat`,"aria-label":g.label,"data-tip":g.label,title:g.label,children:Q(`i`,{style:{background:g.color}})})]}),Q(`div`,{class:`cur`,children:e.current}),Q(`textarea`,{ref:l,class:`input`,"aria-label":`Your version of ${e.id}`,value:i,onInput:e=>{c.current=!0,a(e.target.value),d.schedule()},onBlur:()=>d.flush()})]}),Q(`div`,{class:`sfoot`,children:[Q(`div`,{class:`fit${m.state===`ok`?``:` ${m.state}`}`,title:`${m.words} words · ${m.seconds.toFixed(1)} s of ${p.toFixed(1)} s`,children:Q(`i`,{style:{width:`${Math.min(100,m.ratio*100)}%`}})}),Q(`input`,{class:`dirin`,placeholder:`Direction`,"aria-label":`Direction for ${e.id}`,value:o,onInput:e=>{c.current=!0,s(e.target.value),f.schedule()},onBlur:()=>f.flush()}),Q(`div`,{class:`sact`,children:[h&&Q(`button`,{class:`btn ghost ib`,"data-tip":`Revert to current`,"aria-label":`Revert`,onClick:()=>{a(e.current),u({proposed:null})},children:Q($,{name:`undo`})}),Q(`button`,{class:`btn ib flagd${e.status===`flagged`?``:` ghost`}`,"data-tip":e.status===`flagged`?`Unflag`:`Flag`,"aria-label":`Flag`,"aria-pressed":e.status===`flagged`,onClick:()=>void u({status:e.status===`flagged`?`draft`:`flagged`}),children:Q($,{name:`flag`})}),Q(`button`,{class:`btn ib okd`,"data-tip":e.status===`approved`?`Unapprove`:`Approve`,"aria-label":`Approve`,"aria-pressed":e.status===`approved`,onClick:()=>void u({status:e.status===`approved`?`draft`:`approved`}),children:Q($,{name:`check`})})]})]})]})}function ic({script:e,toast:t,onChanged:n}){let r=e.sections.filter(xe).length;return Q(`div`,{class:`col`,children:[Q(`div`,{class:`shead`,children:[Q(`h2`,{children:`Script`}),Q(`span`,{class:`meta`,children:[e.sections.length,` section`,e.sections.length===1?``:`s`,` · `,r,` changed`]})]}),Q(`div`,{class:`sgrid scols`,children:[Q(`span`,{}),Q(`span`,{children:`Current`}),Q(`span`,{children:`Yours`})]}),Q(`div`,{style:{display:`grid`,gap:`12px`},children:e.sections.map(r=>Q(rc,{section:r,wps:e.wordsPerSecond,toast:t,onChanged:n},r.id))})]})}var ac={music:`#A78BFA`,sfx:`#FB923C`},oc=Math.floor(Math.random()*2**31),sc=!1,cc=new Set;function lc({stage:e,state:t,assets:n,video:r,toast:i,onChanged:a,onPendingChange:o}){let[s,c]=q(e===`music`&&sc),l=e=>{sc=e,c(e)},[,u]=q(0),d=e=>{cc.has(e)?cc.delete(e):cc.add(e),u(e=>e+1)},f=bt(t.project.lanes,e),p=s?Mt(f.map(e=>e.key),oc):f.map(e=>e.key),m=p.map(e=>f.find(t=>t.key===e)),h=e=>s?`Bed ${p.indexOf(e.key)+1}`:e.name,g=t.picks.lanes,_=async(e,t)=>{try{await Z.put(`/api/picks`,{lanes:{[e.lane]:t}})}catch(e){i(`Couldn't ${t===null?`clear`:`set`} the pick: ${e.message}`)}a()},v=m.map(t=>{let r=n.find(e=>e.path===t.file),i={id:t.key,lane:t.lane,path:t.file,offset:0,duration:0,rev:r?qr(r):void 0},a=g[t.lane]===t.variant;return{key:t.key,name:h(t),meta:s?`·····`:t.meta,color:ac[e],clips:[i],cues:e===`sfx`?t.cues:void 0,layers:e===`sfx`?{open:cc.has(t.key),onToggle:()=>d(t.key)}:void 0,audition:{lane:t.lane,clip:t.key},picked:a,order:f.indexOf(t),use:{inUse:a,onUse:()=>void _(t,t.variant),onUnpick:()=>void _(t,null)},on:`v:${t.key}`}}),y=Tt(m,h,e===`sfx`),b=t.notes.notes.filter(t=>t.stage===e),x=Ce(r??void 0),S=r&&x?{video:r.id,version:x.id,file:x.file,duration:x.duration}:null,C=t.project.fps||30;return Q(rs,{stage:e,film:r?.id??null,title:Te[e],headerExtra:e===`music`&&Q(`button`,{class:`btn ghost ib`,"aria-label":`Blind`,"aria-pressed":s,"data-tip":s?`Show names`:`Blind: hide names`,onClick:()=>l(!s),children:Q($,{name:`eyeoff`})}),rows:v,preview:S,fps:C,notes:b,onOptions:y,noteRow:e=>kt(m,e.on),onLabel:e=>At(m,y,e.on),toast:i,onChanged:a,onPendingChange:o})}var uc=`#4FD1C5`,dc=[`whole`,`point`],fc={whole:ut.voice,point:[`Fix this`,`Keep this`]},pc=Math.floor(Math.random()*2**31),mc=!1,hc=new Map,gc=new Set;function _c({state:e,assets:t,video:n,toast:r,onChanged:i,onPendingChange:a}){let[o,s]=q(mc),c=e=>{mc=e,s(e)},l=n?.id??``,[,u]=q(0),d=hc.get(l)??gc,f=e=>{let t=new Set(d);t.has(e)?t.delete(e):t.add(e),hc.set(l,t),u(e=>e+1)},p=e=>t.find(t=>t.path===e),m=e=>{let t=p(e);return t?qr(t):void 0},h=e=>p(e)?.missing===!0,g=Vt(e.project.lanes,e.picks.lanes),_=g.map(e=>{if(!o)return e;let t=Mt(e.reads.map(e=>e.key),pc);return{...e,reads:t.map(t=>e.reads.find(e=>e.key===t))}}),v=new Map;for(let e of _)e.reads.forEach((e,t)=>v.set(e.key,t+1));let y=e=>o?`Read ${v.get(e.key)}`:e.name,b=async(e,t)=>{try{await Z.put(`/api/picks`,{lanes:{[e.id]:t}})}catch(e){r(`Couldn't ${t===null?`clear`:`set`} the pick: ${e.message}`)}i()},x=e=>({id:e.key,lane:Gt(e),path:e.file,offset:0,duration:0,rev:m(e.file)}),C=g.filter(e=>e.current||d.has(e.id)).flatMap(e=>e.reads.filter(e=>!h(e.file)).map(x)),w=e.notes.notes.filter(e=>e.stage===`voice`),T={rounds:g,sections:e.script.sections},E=(e,t)=>({key:t.key,name:y(t),meta:o?`·····`:t.meta,color:uc,clips:h(t.file)?[]:[x(t)],use:{inUse:e.pick===t.variant,onUse:()=>void b(e,t.variant),onUnpick:()=>void b(e,null)},on:`v:${t.key}`,missing:h(t.file)}),D=[];for(let e of[..._].reverse()){if(e.current){e.reads.forEach((t,n)=>D.push(n===0?{...E(e,t),heading:e.name,tag:`current`}:E(e,t)));continue}let t=d.has(e.id),n=e.reads.find(t=>t.variant===e.pick),r=new Set(e.reads.map(e=>e.key)),i=e.reads.length;if(D.push({key:`round:${e.id}`,name:e.name,color:uc,clips:[],fold:{label:Q(S,{children:[Q(`b`,{children:e.name}),` · `,i,` `,i===1?`read`:`reads`,` ·`,` `,n?Q(`span`,{class:`fpk`,children:[`picked `,o?`a read`:n.name]}):`nothing picked`]}),text:`${e.name} · ${i} ${i===1?`read`:`reads`} · ${n?`picked ${o?`a read`:n.name}`:`nothing picked`}`,open:t,dot:w.some(e=>e.status===`todo`&&r.has(Yt(T,e)??``)),onToggle:()=>f(e.id)}}),t)for(let t of e.reads)D.push(E(e,t))}let O=Xt(_,y),k=Wt(g),A=Ce(n??void 0),j=n&&A?{video:n.id,version:A.id,file:A.file,duration:A.duration}:null,M=e.project.fps||30;return Q(rs,{stage:`voice`,film:n?.id??null,title:Te.voice,headerExtra:Q(`button`,{class:`btn ghost ib`,"aria-label":`Blind`,"aria-pressed":o,"data-tip":o?`Show names`:`Blind: hide names`,onClick:()=>c(!o),children:Q($,{name:`eyeoff`})}),rows:D,clips:C,preview:j,fps:M,notes:w,onOptions:O,defaultOn:k?`v:${k.key}`:void 0,listen:e=>Kt(g,e),noteRow:e=>Yt(T,e),onLabel:e=>Zt(T,e.on,y),scopes:dc,defaultScope:`whole`,chipsFor:e=>fc[e===`point`?`point`:`whole`],marks:!1,toast:r,onChanged:i,onPendingChange:a})}var vc=[[`all`,`All`],[`picture`,Gi.picture],[`voice`,Gi.voice],[`music`,Gi.music],[`sfx`,Gi.sfx],[`mix`,Gi.mix],[`notes`,Gi.notes],[`assets`,Gi.assets]];function yc(e){return vc.some(([t])=>t===e)}var bc={user:`added by you`,agent:`agent`,rushes:`Rushes`};function xc(e,t){let n=[];for(let r of e){let e=new Date(r.at),i=Qi(e),a=n[n.length-1];a&&a.date===i?a.entries.push(r):n.push({key:i,date:i,heading:$i(e,t,!0),entries:[r]})}let r=new Map;for(let e=n.length-1;e>=0;e--){let t=(r.get(n[e].date)??0)+1;r.set(n[e].date,t),t>1&&(n[e].key=`${n[e].date}~${t}`)}return n.map(({key:e,heading:t,entries:n})=>({key:e,heading:t,entries:n}))}function Sc(e,t){return e===`all`||e===t}var Cc=new Set([` `,`ArrowLeft`,`ArrowRight`,`ArrowUp`,`ArrowDown`,`Home`,`End`,`PageUp`,`PageDown`]);function wc(e){return Cc.has(e.key)&&!e.altKey&&!e.ctrlKey&&!e.metaKey}var Tc=[`script`,`picture`,`voice`,`music`,`sfx`,`mix`];function Ec(e,t){if(e.kind===`entry`&&!e.video&&!e.version&&!e.ref)return null;let n=e.video?t.videos.find(t=>t.id===e.video):void 0;if(n)return e.version&&n.versions.some(t=>t.id===e.version)?{tab:`picture`,video:n.id,version:e.version}:{tab:`picture`,video:n.id};let r=e.ref?e.ref.indexOf(`/`):-1,i=r>0?t.lanes.find(t=>t.id===e.ref.slice(0,r)):void 0;return i?{tab:i.stage,row:e.ref}:e.tab&&Tc.includes(e.tab)?{tab:e.tab}:e.area===`assets`?{tab:`assets`}:Tc.includes(e.area)?{tab:e.area}:null}function Dc(e,t){let n=new Set(e.map(e=>`${e.id}@${e.at}`));return t.filter(e=>!n.has(`${e.id}@${e.at}`)).length}function Oc(e){let t=e.entries.length+e.earlier,n=e.earlier>0?`Showing the newest ${e.entries.length} of ${t}`:`${t} entr${t===1?`y`:`ies`}`;return e.dropped>0?`${n} · Earlier entries were removed`:n}function kc(e,t){let n=e.by===`user`?`added by you`:e.by===`agent`?`by the agent`:`by Rushes`;return`${e.text} (${Gi[e.area]}, ${t}, ${n})`}function Ac(e,t){let n=typeof t?.status==`number`?t.status:null,r=`Run rushes doctor to see why.`;return n===null?`${e===`read`?`The Change Log couldn't be loaded`:e===`add`?`That line wasn't added`:`The Markdown wasn't saved`}: Rushes didn't answer. Check it's still running, then try again.`:e===`add`?n<500?`That line wasn't added: it needs a few words of text.`:`That line wasn't added: the Change Log couldn't be written. ${r}`:e===`export`?`The Markdown wasn't saved: the Change Log couldn't be read or written. ${r}`:n<500?`The Change Log couldn't show that filter. Choose All and try again.`:`The Change Log couldn't be read. ${r}`}function jc(e,t){if(!e||e===t)return!1;if(!t)return!0;let n=e=>Date.parse(e.slice(e.lastIndexOf(`@`)+1)),r=n(e),i=n(t);return!(Number.isFinite(r)&&Number.isFinite(i)&&r<i)}function Mc(e,t){return`rushes:${e}:${t}`}function Nc(e,t){try{return e?.getItem(t)??null}catch{return null}}function Pc(e,t,n){try{e?.setItem(t,n)}catch{}}var Fc=1e3,Ic=40,Lc=()=>{try{return window.sessionStorage}catch{return}},Rc=()=>{try{return window.localStorage}catch{return}};function zc(e,t){let[n,r]=q(()=>Nc(Lc(),Mc(e,`log-open`))===`1`),[i,a]=q(!1),[o,s]=q(()=>Nc(Rc(),Mc(e,`log-seen`))),c=t?.mark??null,l=X(o);l.current=o;let u=t=>{s(t),Pc(Rc(),Mc(e,`log-seen`),t)};return J(()=>{n&&c&&jc(c,o)&&u(c)},[n,c]),J(()=>{let t=Mc(e,`log-seen`),n=e=>{e.key===t&&e.newValue&&s(e.newValue)};return window.addEventListener(`storage`,n),()=>window.removeEventListener(`storage`,n)},[e]),{open:n,focusOnOpen:i,dot:!n&&jc(c,o),setOpen:t=>{r(t),a(t),Pc(Lc(),Mc(e,`log-open`),t?`1`:`0`)},saw:e=>{jc(e,l.current)&&u(e)}}}function Bc(){return Q(`svg`,{class:`ic`,viewBox:`0 0 24 24`,"aria-hidden":`true`,fill:`none`,stroke:`currentColor`,"stroke-width":`1.75`,"stroke-linecap":`round`,"stroke-linejoin":`round`,children:[Q(`path`,{d:`M3 12a9 9 0 1 0 3-6.7L3 8`}),Q(`path`,{d:`M3 3v5h5`}),Q(`path`,{d:`M12 7v5l3 2`})]})}function Vc({log:e,buttonRef:t}){return Q(`button`,{ref:t,type:`button`,class:`btn clog tip-below`,"data-tip":`Change Log`,"aria-label":e.dot?`Change Log (new entries)`:`Change Log`,"aria-expanded":e.open,"aria-controls":e.open?`changelog`:void 0,onClick:()=>e.setOpen(!e.open),children:[Q(Bc,{}),Q(`span`,{class:`clabel`,children:`Change Log`}),e.dot&&Q(`span`,{class:`cdot`,"aria-hidden":`true`})]})}function Hc(e){let t=0,n=()=>{let r=document.querySelector(`.lane[data-row="${CSS.escape(e)}"] .nm`);if(r){r.scrollIntoView({block:`nearest`}),r.focus({preventScroll:!0});return}++t<60&&requestAnimationFrame(n)};requestAnimationFrame(n)}function Uc(e){return e.log.open?Q(Gc,{...e}):null}function Wc({entry:e,to:t,onGo:n}){let r=Zi(new Date(e.at)),i=Q(S,{children:[Q(`span`,{class:`ltime`,children:r}),Q(`span`,{class:`ltag ${e.area}`,children:Gi[e.area]}),Q(`span`,{class:`ltext`,dir:`auto`,children:[e.text,Q(`span`,{class:`lby`,children:bc[e.by]})]}),Q(`span`,{class:`lgo`,"aria-hidden":`true`,children:t?`›`:``})]});return t?Q(`button`,{type:`button`,class:`lrow`,"data-entry":e.id,"data-go":``,"aria-label":kc(e,r),onClick:()=>n(t),children:i}):Q(`div`,{class:`lrow`,"data-entry":e.id,children:i})}function Gc({log:e,projectId:t,head:n,project:r,stage:i,header:a,buttonRef:o,toast:s,onJump:c}){let[l,u]=q(null),[d,f]=q(null),[p,m]=q(null),[h,g]=q(()=>{let e=Nc(Lc(),Mc(t,`log-filter`));return yc(e)?e:`all`}),[_,v]=q(``),y=X(null),b=X(null),x=X(null),S=X({}),C=X(null);C.current=l;let w=X(h);w.current=h;let T=X(0),E=()=>(b.current?.scrollTop??0)>Ic,D=t=>{u(t),f(null),w.current===`all`&&t.entries[0]&&e.saw(`${t.entries[0].id}@${t.entries[0].at}`)},O=async(e=!1)=>{let t=++T.current,n=new URLSearchParams({limit:String(Fc)});w.current!==`all`&&n.set(`area`,w.current);try{let r=await Z.get(`/api/log?${n}`);if(t!==T.current)return;m(null),!e&&C.current&&E()?f(r):D(r)}catch(e){if(t!==T.current)return;C.current?s(Ac(`read`,e)):m(Ac(`read`,e))}};J(()=>{b.current&&(b.current.scrollTop=0),f(null),O(!0)},[h]);let k=X(!0);J(()=>{if(k.current){k.current=!1;return}O()},[n?.rev,n?.mark]),Y(()=>{let e=a.current;if(!e)return;let t=()=>{y.current&&(y.current.style.top=`${Math.max(0,Math.round(e.getBoundingClientRect().bottom))}px`)};t();let n=new ResizeObserver(t);return n.observe(e),window.addEventListener(`resize`,t),window.addEventListener(`scroll`,t,{passive:!0}),()=>{n.disconnect(),window.removeEventListener(`resize`,t),window.removeEventListener(`scroll`,t)}},[]),Y(()=>{e.focusOnOpen&&x.current?.focus()},[]);let A=()=>{e.setOpen(!1),o.current?.focus()};Y(()=>{let e=e=>{if(e.key!==`Escape`||e.defaultPrevented)return;let t=e.target;(!t||t===document.body||t===document.documentElement||t===o.current||y.current?.contains(t))&&(e.preventDefault(),A())};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[]);let j=async()=>{let e=_.trim();if(e)try{if(await Z.post(`/api/log`,{text:e,area:i}),v(``),!Sc(h,i)){let e=Gi[i];s(`Added under ${e}. Choose All${vc.some(([e])=>e===i)?` or ${e}`:``} to see it.`)}b.current&&(b.current.scrollTop=0),await O(!0)}catch(e){s(Ac(`add`,e))}},M=e=>{g(e),Pc(Lc(),Mc(t,`log-filter`),e)},N=(e,t)=>{let n=sa(e.key,t,vc.length,!0);if(n===null)return;e.preventDefault();let r=vc[n][0];M(r),S.current[r]?.focus()},P=()=>{d&&(D(d),b.current&&(b.current.scrollTop=0),requestAnimationFrame(()=>{let e=b.current?.querySelector(`.lrow`);(e instanceof HTMLButtonElement?e:b.current)?.focus({preventScroll:!0})}))},F=()=>{d&&!E()&&D(d)},I=t=>{c(t),window.innerWidth<560&&(e.setOpen(!1),o.current?.focus())},L=X(I);L.current=I;let ee=X(e=>L.current(e)).current,te=async()=>{try{s(`Saved to ${(await Z.post(`/api/exports/change-log`,{})).path}`)}catch(e){s(Ac(`export`,e))}},R=yr(()=>l?xc(l.entries,new Date).map(e=>Q(`div`,{class:`dgroup`,children:[Q(`h3`,{class:`dday`,children:e.heading}),Q(`ul`,{children:e.entries.map(e=>Q(`li`,{children:Q(Wc,{entry:e,to:Ec(e,r),onGo:ee})},e.id))})]},e.key)):null,[l,r,Qi(new Date)]),ne=l&&d?Dc(l.entries,d.entries):0,re=l!==null&&l.total===0&&l.undated.length===0,ie=l!==null&&!re&&l.entries.length===0&&l.undated.length===0;return Q(`aside`,{id:`changelog`,class:`drawer`,ref:y,"aria-label":`Change Log`,onKeyDown:e=>{wc(e)&&e.stopPropagation()},children:[Q(`div`,{class:`dhead`,children:[Q(`h2`,{children:`Change Log`}),Q(`span`,{class:`dquiet`,children:`newest first`}),Q(`button`,{type:`button`,class:`btn dclose`,"aria-label":`Close the change log`,onClick:A,children:`Close`})]}),Q(`form`,{class:`dadd`,onSubmit:e=>{e.preventDefault(),j()},children:[Q(`input`,{ref:x,value:_,maxLength:160,placeholder:`Add a line to the log`,"aria-label":`Add a line to the log`,onInput:e=>v(e.target.value)}),Q(`button`,{type:`submit`,class:`btn`,children:`Add`})]}),Q(`div`,{class:`dchips`,role:`radiogroup`,"aria-label":`Show`,children:vc.map(([e,t],n)=>Q(`button`,{type:`button`,role:`radio`,"aria-checked":h===e,tabIndex:h===e?0:-1,ref:t=>{S.current[e]=t},onClick:()=>M(e),onKeyDown:e=>N(e,n),children:t}))}),Q(`div`,{class:`dwrap`,children:[ne>0&&Q(`button`,{type:`button`,class:`dpill`,onClick:P,children:[ne,` new`]}),Q(`div`,{class:`dlist`,ref:b,tabIndex:0,role:`group`,"aria-label":`Entries`,onScroll:F,children:[l===null&&!p&&Q(`p`,{class:`dempty`,children:`Loading…`}),l===null&&p&&Q(`p`,{class:`dempty dproblem`,role:`alert`,children:p}),re&&Q(`p`,{class:`dempty`,children:`Nothing yet. Rushes writes a line here whenever a cut, a take or a variant is added.`}),ie&&Q(`p`,{class:`dempty`,children:`Nothing for this filter.`}),R,l&&l.undated.length>0&&Q(`section`,{class:`dbefore`,"aria-label":`Before the log`,children:[Q(`h3`,{children:`Before the log`}),Q(`ul`,{children:l.undated.map((e,t)=>Q(`li`,{children:e.text},t))})]})]})]}),Q(`div`,{class:`dfoot`,children:[Q(`span`,{children:l?Oc(l):``}),Q(`button`,{type:`button`,class:`btn`,onClick:()=>void te(),children:`Export as Markdown`})]})]})}var Kc=[`script`,`picture`,`voice`,`music`,`sfx`,`mix`],qc=e=>e instanceof HTMLElement&&(e.isContentEditable||/^(INPUT|TEXTAREA|SELECT)$/.test(e.tagName));function Jc({tab:e,projectName:t,filmName:n,found:r,onReview:i,toast:a}){let o=e===`brief`||e===`storyboard`,{what:s,unlocks:c}=e===`brief`?Me:e===`storyboard`?Ne:Ee[e],l=e===`assets`?`Assets`:e===`brief`?`Brief`:e===`storyboard`?`Storyboard`:Te[e],u=e===`assets`?`grid`:e===`brief`?`brief`:e===`storyboard`?`story`:da[e],d=e===`brief`?Pe(t,n):e===`storyboard`?Fe(t,n):Oe(e,t,n),f=o?null:On(e,r),p=X(null),m=async()=>{try{await navigator.clipboard.writeText(d),a(`Prompt copied`)}catch{p.current?.select(),a(`Prompt selected: press ${Cn(navigator.platform)}`)}};return Q(`div`,{class:`empty locked`,children:[Q($,{name:u}),Q(`h2`,{children:l}),Q(`p`,{children:s}),Q(`p`,{children:c}),Q(`textarea`,{class:`promptbox mono`,readOnly:!0,rows:4,ref:p,value:d,"aria-label":`Prompt for your agent`}),Q(`button`,{class:`btn primary`,onClick:()=>void m(),children:[Q($,{name:`copy`}),`Copy prompt for your agent`]}),f&&Q(`p`,{class:`foundline`,children:[Q(`span`,{children:f.text}),Q(`button`,{type:`button`,class:`btn`,"aria-label":f.review,onClick:()=>i(f.kind),children:`Review`})]})]})}function Yc(){let{state:e,assets:t,problem:n,wrongProject:r,refresh:i,proxyJobs:a,noteProxyJob:o}=Gr(),[s,c]=q(null),[l,u]=q(null),[d,f]=q(null),[p,m]=q(null),[h,g]=q(null),[_,v]=q(`script`),y=X(null),[b,x]=q(!1),[C,w]=q(!1),[T,E]=q(!1),[D,O]=q(!1),[k,A]=q(0),[j,M]=q({}),N=X(void 0),P=X(new Map),F=X(null),I=(e,t)=>M(n=>({...n,[e]:t})),[L,ee]=q({}),te=(e,t)=>ee(n=>({...n,[e]:t})),[R,ne]=q({}),[re,ie]=q({}),[ae,oe]=q(!1),z=X(new Set),B=(e,t=2400)=>{m(e),clearTimeout(N.current),N.current=window.setTimeout(()=>m(null),t)},[se,ce]=q({n:0,pending:!1}),[le,ue]=q(null),V=zc(Ar()??``,e?.log),de=X(null);J(()=>{for(let e of Object.values(a))e.state!==`failed`||z.current.has(e.job)||(z.current.add(e.job),B(e.reason??`Couldn't make the proxy`))},[a]),J(()=>{if(e){if(s===null){let t=Be(e.tabs,e.brief);c(t),Ae(t)&&v(t)}l===null&&e.project.videos[0]&&u(e.project.videos[0].id)}},[e]),J(()=>{e?.project.name&&(document.title=`${e.project.name} · Rushes`)},[e?.project.name]);let H=e?.project.videos.find(e=>e.id===l)??e?.project.videos[0],U=Se(H),me=Ce(H),W=H?.versions.find(e=>e.id===d)??me,he=!!H?.lockedVersion,_e=W?.fps??e?.project.fps??30,ve=W?t.find(e=>e.kind===`cut`&&e.path===W.file):void 0,ye=e?.notes.notes.filter(e=>e.stage===`picture`&&(!e.video||e.video===H?.id))??[],be=W?pe(W,re[W.file]):[],xe=H&&W?Un(H,W.id):void 0,G=Wn(be,H?R[H.id]:void 0),De=new Set(t.filter(e=>e.kind===`cut`&&e.missing).map(e=>e.path)),Oe=W?Gn({views:be,previous:xe?pe(xe):[],current:G,versionDuration:W.duration,notes:ye,missing:De}):[],ke=e=>!H||e===G?!1:ae?(B(`Add or clear your box on ${G?fe(G):`this format`} first`),!1):(ne(t=>({...t,[H.id]:e})),!0);J(()=>{T&&d===null&&me?(f(me.id),O(!0)):!T&&D&&d===me?.id&&(f(null),O(!1))},[T,d,me?.id]),J(()=>{!D&&d!==null&&d===me?.id&&f(null)},[me?.id,D,d]);let Pe=U&&W&&U.id!==W.id&&(he||D)?U.id:null,Fe=()=>{U&&f(U.id),O(!1)},ze=e=>{if(!H||e===H.id)return;if(T)return B(`Add or clear your note on ${H.name} first`);let t=F.current;t?.pause();let n=t?ge(t.currentTime,_e):P.current.get(H.id)?.t??0;P.current.set(H.id,{versionId:d,held:D,t:n});let r=P.current.get(e);u(e),f(r?.versionId??null),O(r?.held??!1),A(r?.t??0)},He=async()=>{if(H&&W)try{await Z.put(`/api/videos/${H.id}/lock`,{version:H.lockedVersion?null:W.id}),i()}catch(e){B(e.message)}},Ue=t=>{if(T)return B(`Add or clear your note first`);if(t.tab===`assets`)return Xe();if(t.video&&t.video!==H?.id&&ze(t.video),t.version){let n=e?.project.videos.find(e=>e.id===(t.video??H?.id));f(t.version===Ce(n)?.id?null:t.version),O(!1)}c(t.tab),g(null),t.row&&Hc(t.row)},We=e?.tabs??[],Ge=e=>We.find(t=>t.stage===e),Ke=kn(e?.found),qe=t.length>0||Ke!==null,Je=e=>{if(T&&e!==s)return B(`Add or clear your note first`);c(e),g(null),Ae(e)&&v(e)},Ye=()=>{let t={brief:!!e?.brief.exists,script:!!Ge(`script`)?.unlocked,storyboard:!!e?.storyboard.exists};Je(Ve(_,t))},Xe=()=>{if(T&&s!==`assets`)return B(`Add or clear your note first`);c(`assets`),g(null)},Ze=e=>{if(T&&s!==`assets`)return B(`Add or clear your note first`);ce(t=>({n:t.n+1,kind:e,pending:!0})),c(`assets`),g(null)},Qe=X(Ze);Qe.current=Ze,J(()=>{Rt(location.search).test&&(window.__rushesOpenFound=e=>Qe.current(e))},[]),Y(()=>{let t=t=>{if(t.altKey&&!t.metaKey&&!t.ctrlKey&&!t.shiftKey&&(t.key===`ArrowLeft`||t.key===`ArrowRight`)){if(s!==`picture`||qc(t.target))return;t.preventDefault();let e=Kn(Oe,G,t.key===`ArrowRight`?1:-1);e&&ke(e);return}if(qc(t.target)||t.metaKey||t.ctrlKey||t.altKey)return;let n=Number(t.key);if(n===1?Ye():n>=2&&n<=6?Je(Kc[n-1]):n===7&&Xe(),(t.key===`[`||t.key===`]`)&&e){let n=we(e.project.videos,l,t.key===`]`?1:-1);n&&ze(n)}t.key===`?`&&x(e=>!e),t.key===`Escape`&&(x(!1),g(null))};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)});let $e=X(null),et=X(null),tt=X(null),nt=()=>{let e=$e.current;if(!e)return;let t=`${Math.round(e.getBoundingClientRect().top+window.scrollY)}px`,n=document.documentElement.style;n.getPropertyValue(`--body-top`)!==t&&n.setProperty(`--body-top`,t)};Y(nt),J(()=>{let e=()=>nt();window.addEventListener(`resize`,e);let t=!0;return document.fonts?.ready.then(()=>{t&&nt()}),()=>{t=!1,window.removeEventListener(`resize`,e)}},[]);let rt=!!e&&!!s;J(()=>{if(!rt)return;let e=new ResizeObserver(()=>nt());for(let t of[et.current,tt.current])t&&e.observe(t,{box:`border-box`});return()=>e.disconnect()},[rt]);let it=async()=>{if(s&&s!==`assets`){if(x(!1),s===`brief`){if(!e)return;if(!e.brief.exists)return B(`There's no brief yet: copy the prompt on this page for your agent`);let t=await y.current?.()??e.brief;g({id:`brief`,title:`Message for your agent`,prompt:Le(e.project.name,H?.name??null,t)}),w(!1);return}if(s===`storyboard`){if(!e)return;if(!e.storyboard.exists)return B(`There's no storyboard yet: copy the prompt on this page for your agent`);let t=await y.current?.()??e.storyboard;g({id:`storyboard`,title:`Message for your agent`,prompt:Re(e.project.name,H?.name??null,t)}),w(!1);return}try{let{batch:e}=await Z.post(`/api/batches`,{stage:s});g(e),w(!1),i()}catch(e){B(e instanceof kr&&e.code===`empty_batch`?`Nothing open on ${Te[s]} to send`:e.message)}}},at=async()=>{if(h)try{await navigator.clipboard.writeText(h.prompt),w(!0)}catch{B(`Couldn't reach the clipboard. Select the text and copy it.`)}};if(!e||!s)return Q(`div`,{class:`shell`,children:n?Q(`div`,{class:`banner`,children:[Q($,{name:`alert`}),n]}):Q(`div`,{class:`empty`,children:Q(`p`,{children:`Loading…`})})});let ot=e.notes.notes.filter(e=>e.stage===`picture`&&(!e.video||e.video===H?.id)),st=t=>e.notes.notes.some(e=>e.stage===`picture`&&e.status===`todo`&&(!e.video||e.video===t)),ct=s===`assets`?qe:s===`brief`?e.brief.exists:s===`storyboard`?e.storyboard.exists:Ge(s)?.unlocked??!1,lt=s===`assets`?0:s===`brief`?e.brief.changed:s===`storyboard`?e.storyboard.changed:Ge(s)?.todo??0,ut=!!Ge(`picture`)?.unlocked,dt=je(e.brief,e.script.sections,e.storyboard),ft=e.build.started&&!ut,pt=[{page:`brief`,name:`Brief`,icon:`brief`,unlocked:e.brief.exists,progress:ft?dt.brief:null,ask:Me.ask},{page:`script`,name:`Script`,icon:da.script,unlocked:!!Ge(`script`)?.unlocked,progress:ft&&Ge(`script`)?.unlocked?dt.script:null,ask:Ee.script.ask},{page:`storyboard`,name:`Storyboard`,icon:`story`,unlocked:e.storyboard.exists,progress:ft&&e.storyboard.exists?dt.storyboard:null,ask:Ne.ask}],mt=e.brief.changed+e.storyboard.changed+(Ge(`script`)?.todo??0),ht=async()=>{try{await navigator.clipboard.writeText(Ie(e.project.name,H?.name??null)),B(`Prompt copied`)}catch{B(`Couldn't reach the clipboard. Ask your agent to build the film from the approved plan.`)}};return Q(`div`,{class:`shell`,children:[Q(`header`,{class:`head`,ref:et,children:[Q(`span`,{class:`logo`,children:Q(`svg`,{viewBox:`0 0 24 24`,children:Q(`path`,{d:`M8 5v14l11-7z`})})}),Q(`nav`,{class:`crumb`,"aria-label":`Project`,children:[Q(`span`,{children:e.project.name}),e.project.id&&Q(`span`,{class:`pid mono`,children:e.project.id}),H&&e.project.videos.length===1&&Q(S,{children:[Q(`span`,{class:`slash`,children:`/`}),Q(`span`,{class:`sel`,children:H.name})]})]}),Ke!==null&&An(e.found)!==le&&Q(`button`,{type:`button`,class:`foundchip`,"data-tip":`Open the other files found in this project`,onClick:()=>Ze(),children:[Q(`span`,{class:`dot`}),Q(`span`,{class:`ftext`,children:Ke})]}),H&&e.project.videos.length>1&&Q(`nav`,{class:`pack`,"aria-label":`Films`,children:e.project.videos.map((e,t)=>Q(`button`,{class:`pill`,"aria-pressed":e.id===H.id,onClick:()=>ze(e.id),children:[Q(`span`,{class:`n`,children:t+1}),Q(`span`,{class:`pname`,children:e.name}),st(e.id)&&Q(`span`,{class:`dot`})]}))}),H&&Q(S,{children:[Q(`span`,{class:`plabel`,children:`Picture`}),W&&Q(Bs,{versions:H.versions,shown:W,lockedVersion:H.lockedVersion,onPick:e=>{f(e===me?.id?null:e),O(!1)}}),W&&Q(`button`,{class:`btn ib lockbtn`,"aria-pressed":he,"aria-label":he?`Picture locked at ${H.lockedVersion} · unlock`:`Lock picture at ${W.id}`,"data-tip":he?`Picture locked at ${H.lockedVersion} · unlock`:`Lock picture at ${W.id}`,onClick:()=>void He(),children:Q($,{name:he?`lock`:`unlock`})}),Pe&&Q(`button`,{class:`chipx go`,"aria-label":`${Pe} is ready`,"data-tip":`Switch to the newest cut`,onClick:Fe,children:[Q($,{name:`new`}),Pe,` ready`]}),s===`picture`&&W&&Oe.length>0&&Q(ro,{chips:Oe,versionId:W.id,prompt:Xn(e.project.name,H.name,W.id),onSelect:ke,toast:B})]}),Q(`span`,{class:`sp`}),Q(`button`,{class:`btn ghost ib tip-below`,"data-tip":`Shortcuts ?`,"aria-label":`Keyboard shortcuts`,onClick:()=>{g(null),x(!b)},children:Q($,{name:`kbd`})}),Q(Vc,{log:V,buttonRef:de}),Q(`button`,{class:`btn primary`,"aria-disabled":s===`assets`,tabIndex:s===`assets`?-1:void 0,"data-tip":s===`assets`?`Nothing to send from Assets`:void 0,onClick:()=>void it(),children:[`Send to agent`,lt>0&&Q(`span`,{class:`count`,children:lt})]})]}),Q(Uc,{log:V,projectId:Ar()??``,head:e.log,project:e.project,stage:s===`brief`||s===`storyboard`?`script`:s,header:et,buttonRef:de,toast:B,onJump:Ue}),h&&Q(`div`,{class:`pop`,role:`dialog`,"aria-label":`Sent to agent`,children:[Q(`div`,{style:{display:`flex`,alignItems:`center`,gap:`8px`},children:[Q(`h3`,{children:h.title??`Batch ${h.id} is ready`}),Q(`span`,{class:`sp`}),Q(`button`,{class:`btn ghost ib sm`,"aria-label":`Close`,onClick:()=>g(null),children:Q($,{name:`x`})})]}),Q(`pre`,{children:h.prompt}),Q(`div`,{style:{display:`flex`,justifyContent:`flex-end`},children:Q(`button`,{class:`btn primary`,onClick:()=>void at(),children:[Q($,{name:`copy`}),C?`Copied`:`Copy prompt`]})})]}),b&&Q(`div`,{class:`pop`,role:`dialog`,"aria-label":`Keyboard shortcuts`,style:{width:`300px`},children:[Q(`div`,{style:{display:`flex`,alignItems:`center`},children:[Q(`h3`,{children:`Shortcuts`}),Q(`span`,{class:`sp`}),Q(`button`,{class:`btn ghost ib sm`,"aria-label":`Close`,onClick:()=>x(!1),children:Q($,{name:`x`})})]}),Q(`div`,{class:`keys`,children:[Q(`span`,{children:Q(`kbd`,{children:`Space`})}),Q(`span`,{children:`Play or pause`}),Q(`span`,{children:[Q(`kbd`,{children:`←`}),` `,Q(`kbd`,{children:`→`})]}),Q(`span`,{children:`Step one frame (Shift: ten)`}),Q(`span`,{children:[Q(`kbd`,{children:`I`}),` `,Q(`kbd`,{children:`O`})]}),Q(`span`,{children:`Set in and out`}),Q(`span`,{children:Q(`kbd`,{children:`B`})}),Q(`span`,{children:`Draw a box`}),Q(`span`,{children:Q(`kbd`,{children:`G`})}),Q(`span`,{children:`Grab frame`}),Q(`span`,{children:Q(`kbd`,{children:`N`})}),Q(`span`,{children:`New note`}),Q(`span`,{children:[Q(`kbd`,{children:`1`}),`–`,Q(`kbd`,{children:`7`})]}),Q(`span`,{children:`Switch tab`}),Q(`span`,{children:[Q(`kbd`,{children:`[`}),` `,Q(`kbd`,{children:`]`})]}),Q(`span`,{children:`Previous or next film`}),Q(`span`,{children:[Q(`kbd`,{children:`Alt`}),` `,Q(`kbd`,{children:`←`}),` `,Q(`kbd`,{children:`→`})]}),Q(`span`,{children:`Previous or next format`}),Q(`span`,{children:Q(`kbd`,{children:`?`})}),Q(`span`,{children:`Shortcuts`}),Q(`span`,{children:Q(`kbd`,{children:`Esc`})}),Q(`span`,{children:`Close`})]})]}),p&&Q(`div`,{class:`toast`,role:`status`,children:p}),r&&Q(`div`,{class:`banner lost`,role:`alert`,children:[Q($,{name:`alert`}),`This tab is for ${e.project.name}, which isn't running here any more. Ask your agent to open it again.`]}),Q(`nav`,{class:`tabs`,ref:tt,role:`tablist`,"aria-label":`Stages`,children:[Q($s,{selected:Ae(s)?s:null,rows:pt,marks:ft?dt:null,open:mt,locked:pt.every(e=>!e.unlocked),ready:ft&&e.build.ready,onCopyReady:()=>void ht(),onPick:e=>Je(e)}),Kc.filter(e=>e!==`script`).map(e=>{let t=Ge(e);return Q(`button`,{class:`tab`,role:`tab`,"aria-selected":s===e,"data-locked":t?.unlocked?void 0:`true`,"data-tip":t?.unlocked?void 0:`Locked: ask your agent for ${Ee[e].ask}`,onClick:()=>Je(e),children:[Q($,{name:da[e]}),Te[e],t?.unlocked?t.todo>0&&Q(`span`,{class:`dot`,title:`${t.todo} open`}):Q(S,{children:[Q($,{name:`lock`,class:`lk`}),Q(`span`,{class:`vh`,children:` Locked`})]})]})}),Q(`button`,{class:`tab`,role:`tab`,"aria-selected":s===`assets`,"data-locked":qe?void 0:`true`,"data-tip":qe?void 0:`Locked: ask your agent for ${Ee.assets.ask}`,onClick:()=>Xe(),children:[Q($,{name:`grid`}),`Assets`,!qe&&Q(S,{children:[Q($,{name:`lock`,class:`lk`}),Q(`span`,{class:`vh`,children:` Locked`})]})]})]}),n&&!r&&Q(`div`,{class:`banner`,children:[Q($,{name:`alert`}),n]}),Q(`main`,{class:`body`,ref:$e,children:s===`assets`?ct?Q(Ja,{assets:t,videos:e.project.videos,state:e,foundRequest:se,onFoundRequestUsed:()=>ce(e=>e.pending?{n:e.n,pending:!1}:e),onFoundSeen:ue,toast:B,onChanged:()=>void i()}):Q(Jc,{tab:`assets`,projectName:e.project.name,filmName:H?.name??null,found:e.found?.counts,onReview:Ze,toast:B}):ct?s===`picture`&&H&&W?Q(Ws,{video:H,version:W,fps:_e,notes:ot,toast:B,onChanged:()=>void i(),onPendingChange:E,startAt:k,grab:j[H.id]??null,onGrabChange:I,playerRef:F,ffmpeg:e.proxies?.ffmpeg??!1,autoProxy:e.project.autoProxy,proxyJob:a[gn(H.id,W.id)],noteProxyJob:o,source:L[H.id]??`proxy`,onSourceChange:te,fileSize:ve?.size??null,fileRev:ve?qr(ve):void 0,formats:be,format:G,formatMissing:!!G&&De.has(be.find(e=>e.id===G)?.file??``),onPrimarySize:(e,t,n)=>ie(r=>r[e]?r:{...r,[e]:{width:t,height:n}}),onBoxPendingChange:oe,onFormatChange:ke},H.id):s===`brief`?Q(to,{brief:e.brief,toast:B,onChanged:()=>void i(),settle:y}):s===`storyboard`?Q(Qs,{board:e.storyboard,brief:e.brief,toast:B,onChanged:()=>void i(),settle:y}):s===`script`?Q(ic,{script:e.script,toast:B,onChanged:()=>void i()}):s===`voice`?Q(_c,{state:e,assets:t,video:H??null,toast:B,onChanged:()=>void i(),onPendingChange:E},`voice`):s===`mix`?Q(cs,{state:e,assets:t,video:H??null,toast:B,onChanged:()=>void i(),onPendingChange:E},`mix`):s===`music`||s===`sfx`?Q(lc,{stage:s,state:e,assets:t,video:H??null,toast:B,onChanged:()=>void i(),onPendingChange:E},s):null:Q(Jc,{tab:s,projectName:e.project.name,filmName:H?.name??null,found:e.found?.counts,onReview:Ze,toast:B})})]})}Ft(document),ae(Q(Yc,{}),document.getElementById(`app`));
|
package/web-dist/index.html
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
6
6
|
<title>Rushes</title>
|
|
7
7
|
<link rel="icon" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Crect width='24' height='24' rx='6' fill='%237c93ff'/%3E%3Cpath d='M9 7v10l8-5z' fill='%230b1026'/%3E%3C/svg%3E" />
|
|
8
|
-
<script type="module" crossorigin src="/assets/index-
|
|
8
|
+
<script type="module" crossorigin src="/assets/index-g2XP_slY.js"></script>
|
|
9
9
|
<link rel="stylesheet" crossorigin href="/assets/index-DvA6CDxP.css">
|
|
10
10
|
</head>
|
|
11
11
|
<body>
|