rushes 0.6.1 → 0.6.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.6.1",
4
+ "version": "0.6.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/AGENTS.md CHANGED
@@ -101,7 +101,7 @@ When the user makes stills, standalone images or carousels (posts), register the
101
101
 
102
102
  The user drags to mark a region on the picture, clicks for a point, or adds a note for the whole image, and sends a batch. `rushes_get_batch` and `rushes_list_notes` return each Visuals note with a `visual` object: the visual's id and name, its `version`, the `page`, the `ratio` as a label (null when the note is for every ratio), the `shape` (`region`, `pin` or `image`), the `region` or `pin` as fractions of the picture, `words` saying where it is ("left third, top third"), and the `file` to open. A note with no ratio is for every ratio: say in your reply which ratios you fixed.
103
103
 
104
- To answer feedback, change the marked pictures and register the result as a new version of the same visual: call `rushes_add_visual` with `visual` (its id or name) and `pages` listing only the pages that changed or are new, each with its `n`; every other page, and any ratio of a listed page you leave out, carries over from the version before. Pages can be added at the end and never removed. Then `rushes_reply` to each note with `fixVersion` set to that version. You never mark a note done: the user does, with the tick. Rushes keeps each note on the version it was made on, and shows it as "from v1" beside the newer one.
104
+ To answer feedback, change the marked pictures and register the result as a new version of the same visual: call `rushes_add_visual` with `visual` (its id or name) and `pages` listing only the pages that changed or are new, each with its `n`; every other page, and any ratio of a listed page you leave out, carries over from the version before. Pages can be added at the end and never removed. Then `rushes_reply` to each note you fixed with `status: "done"`, a one-line `reply` and `fixVersion` set to that version, as on every other tab. A note you did not fix stays `todo`, with the reason in `reply`. The user can open a note again with the tick. Rushes keeps each note on the version it was made on, and shows it as "from v1" beside the newer one.
105
105
 
106
106
  ## The loop
107
107
 
@@ -83,7 +83,7 @@ export function buildPrompt(project, stage, batchId, notes, sections, extra = []
83
83
  'Use rushes_get_batch and rushes_get_picks, fix each note (marks such as "Fall" or "Quieter 3 dB" are part of the note), register the new variant, then rushes_reply. The picks\' levels say where the user wants each lane to sit.'
84
84
  : stage === "visuals"
85
85
  ? // §25.5: the note's picture is named in the batch; the new picture goes in as a new version of the visual.
86
- "Use rushes_get_batch: each note names its visual, version, page and aspect ratio, where on the picture it is (a region or a point, as fractions and in words) and the file to open. Change each marked picture, register the result as a new version with rushes_add_visual (send only the pages that changed), then rushes_reply to each note with fixVersion set to that version. A note with no ratio is for every ratio: say in your reply which ratios you fixed."
86
+ "Use rushes_get_batch: each note names its visual, version, page and aspect ratio, where on the picture it is (a region or a point, as fractions and in words) and the file to open. Change each marked picture, register the result as a new version with rushes_add_visual (send only the pages that changed), then rushes_reply to each note you fixed with status \"done\" and fixVersion set to that version. A note with no ratio is for every ratio: say in your reply which ratios you fixed."
87
87
  : AUDIO_STAGES.includes(stage)
88
88
  ? 'Use rushes_get_batch and rushes_get_picks, fix each note (marks such as "Fall" or "Quieter 3 dB" are part of the note), register the new variant, then rushes_reply.'
89
89
  : "Use rushes_get_batch, fix each note, then rushes_reply with a fixT for each and rushes_add_version for the new cut.";
package/dist/mcp/tools.js CHANGED
@@ -187,7 +187,7 @@ export function createMcpServer(ctx) {
187
187
  }));
188
188
  server.registerTool("rushes_add_visual", {
189
189
  title: "Add a visual",
190
- description: "Register a still, a standalone image or a carousel so the user can mark it up in the Visuals tab: one visual per post. A new visual (`name`) lists every page in order, each page with its pictures, one per aspect ratio (a png, jpg, webp or gif inside the project; Rushes reads each ratio from the picture's own size). A new version of a visual you already registered (`visual`: its id or name) lists only the pages that changed or are new, each with its page number `n`; every other page, and every ratio of a listed page you leave out, carries over from the version before. Pages can be added at the end and never removed; a new aspect ratio needs a picture on every page. After feedback, fix the marked pictures, register them as a new version, then rushes_reply to each note with fixVersion set to that version (you never mark a note done: the user does). Returns the visual, the version (v1, v2 ...), the page count and the ratios. A notes batch for Visuals (rushes_get_batch) names each note's visual, version, page, ratio and where on the picture it is, with the file to open. Refused, with the reason and nothing changed: a picture outside the project or that is a link, one that is not an image or cannot be read, two pictures of one ratio on a page, pages that disagree about their ratios, a name already used, and a page that is missing for a ratio.",
190
+ description: "Register a still, a standalone image or a carousel so the user can mark it up in the Visuals tab: one visual per post. A new visual (`name`) lists every page in order, each page with its pictures, one per aspect ratio (a png, jpg, webp or gif inside the project; Rushes reads each ratio from the picture's own size). A new version of a visual you already registered (`visual`: its id or name) lists only the pages that changed or are new, each with its page number `n`; every other page, and every ratio of a listed page you leave out, carries over from the version before. Pages can be added at the end and never removed; a new aspect ratio needs a picture on every page. After feedback, fix the marked pictures, register them as a new version, then rushes_reply to each note you fixed with status \"done\" and fixVersion set to that version, as on every other tab (the user can open a note again); leave a note you did not fix as todo and say why in the reply. Returns the visual, the version (v1, v2 ...), the page count and the ratios. A notes batch for Visuals (rushes_get_batch) names each note's visual, version, page, ratio and where on the picture it is, with the file to open. Refused, with the reason and nothing changed: a picture outside the project or that is a link, one that is not an image or cannot be read, two pictures of one ratio on a page, pages that disagree about their ratios, a name already used, and a page that is missing for a ratio.",
191
191
  inputSchema: {
192
192
  project,
193
193
  name: z.string().trim().min(1).max(80).optional().describe("A new visual's name, e.g. \"Launch carousel\". Give this or `visual`, not both."),
@@ -33,7 +33,7 @@ import { buildState, planWarning } from "../core/plan.js";
33
33
  import { broughtInEvent, cutEvent, fileEvent, formatEvent, lineEvent, lockEvent, notesSentEvent, picksEvent, repliesEvent, scriptEvent, takeEvent, variantEvent, visualEvent, } from "../core/logEvents.js";
34
34
  import { LOG_AREAS, LOG_MAX, changeLogFileName, logText, recentChanges } from "../core/logText.js";
35
35
  import { defaultRunner, measureMix } from "./loudness.js";
36
- export const VERSION = "0.6.1";
36
+ export const VERSION = "0.6.2";
37
37
  async function body(c, schema) {
38
38
  let json;
39
39
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rushes",
3
- "version": "0.6.1",
3
+ "version": "0.6.2",
4
4
  "description": "A local review desk for video made with AI agents: timecoded notes, script edits and audio picks your agent can read and act on.",
5
5
  "keywords": [
6
6
  "video",
@@ -49,7 +49,7 @@ When a user starts briefing in the chat, offer to keep `brief.md` up to date as
49
49
 
50
50
  ## Visuals
51
51
 
52
- For stills, standalone images and carousels, register one visual per post with `rushes_add_visual`: a `name` and `pages`, each page with its pictures, one per aspect ratio, in every aspect ratio the post comes in (Rushes reads each ratio from the picture). The user marks a region, a point or the whole image in the Visuals tab and sends a batch; each note names its visual, version, page, ratio, where on the picture it is (`words`) and the `file` to open. A note with no ratio is for every ratio. Fix the pictures, register a new version with `rushes_add_visual` (`visual` and only the pages that changed, each with `n`), then `rushes_reply` to each note with `fixVersion` set to it. You never mark a note done. The full contract is in `AGENTS.md`.
52
+ For stills, standalone images and carousels, register one visual per post with `rushes_add_visual`: a `name` and `pages`, each page with its pictures, one per aspect ratio, in every aspect ratio the post comes in (Rushes reads each ratio from the picture). The user marks a region, a point or the whole image in the Visuals tab and sends a batch; each note names its visual, version, page, ratio, where on the picture it is (`words`) and the `file` to open. A note with no ratio is for every ratio. Fix the pictures, register a new version with `rushes_add_visual` (`visual` and only the pages that changed, each with `n`), then `rushes_reply` to each note you fixed with `status: "done"` and `fixVersion` set to it (a note you did not fix stays `todo`, with the reason in `reply`). The full contract is in `AGENTS.md`.
53
53
 
54
54
  ## Reviewing and fixing
55
55
 
@@ -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 ${G(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:[G(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}:_e(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:ve(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([]),[R,ee]=q(!1),z=(e.scopes??ns).includes(`range`),te=e.defaultScope??`point`,ne=`${e.film===void 0?o?.video??``:e.film??``}/${o?.version??``}`,re=X(ne);Y(()=>{re.current!==ne&&(re.current=ne,F(te))},[ne]);let ie=lt({range:M,marks:I,hasText:R});Y(()=>{m?.(ie)},[ie]),J(()=>()=>m?.(!1),[]);let ae=e=>h?h(e):{select:jt(a,e),gains:{}},B=X({select:{},gains:{}}),V=e=>{let t=B.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);B.current={select:{...t.select,...e.select},gains:{...t.gains,...e.gains}}},oe=ae(j);Y(()=>V(oe),[x,JSON.stringify(oe)]);let se=e.defaultOn??a.find(e=>e.picked)?.on??a[0]?.on??l[0]?.value??null,ce=l.some(e=>e.value===O)?O:se,le=l.find(e=>e.value===ce)??null,H=X(null),ue=X([]),de=X(null),U=X(null),fe=X(null),W=X(!1),pe=X(0),me=X(null),_e=e=>{if(P===`whole`)return t===`voice`?`Note on the whole read`:`Note on the whole track`;if(z){if(M.in!==null&&M.out===null)return`Set an Out point`;if(M.in!==null&&M.out!==null)return`Note on ${ve(M.in,M.out)}`;if(P===`range`)return`Set In and Out`}return`Note at ${G(le?.t??he(e,s))}`},ye=e=>{let t=x.length,n=`${t>0?Math.min(e,t)/t*100:0}%`;for(let e of ue.current)e.style.left=n;let r=G(e);de.current&&(de.current.textContent=r),U.current&&(U.current.textContent=r),me.current&&(me.current.placeholder=_e(e));let i=fe.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&&!W.current&&e>pe.current&&(W.current=!0,i.play().catch(()=>void 0)),pe.current=e},be=X(ye);be.current=ye,Y(()=>{ue.current=H.current?[...H.current.querySelectorAll(`.playhead`)]:[],ye(x.time)}),J(()=>x.subscribe(e=>be.current(e)),[x]),J(()=>{let e=fe.current;e&&(W.current=!1,C||(e.pause(),be.current(x.time)))},[C,o?.file]);let xe=()=>x.playing?x.pause():x.play(),Se=e=>{x.pause(),x.seek(ge(x.time,s,e,x.length))},Ce=()=>{z&&(N({in:he(x.time,s),out:null}),F(`range`))},we=()=>{if(!z)return;let e=he(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`)},Te=()=>{N(ts),L([]),P===`range`&&F(te)},Ee=e=>{(e!==`range`||z)&&(F(e),e!==`range`&&(N(ts),L([])))},De=t=>{D(t.key),V(ae(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(),xe()}else e.key===`ArrowLeft`?(e.preventDefault(),Se(e.shiftKey?-10:-1)):e.key===`ArrowRight`?(e.preventDefault(),Se(e.shiftKey?10:1)):t===`i`?Ce():t===`o`?we():t===`n`&&(e.preventDefault(),me.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=le?.t??he(x.time,s));await Z.post(`/api/notes`,{stage:t,video:o?.video??null,version:o?.version??null,on:le?.on??null,scope:P,t:n,tOut:r,text:e,marks:P===`range`?I:[]}),N(ts),L([]),F(te),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:z?e.tOut:null,status:e.status,text:e.text})}let Me=M.in===null?null:M.out===null?`${G(M.in)} →`:ve(M.in,M.out);return Q(`div`,{class:`astage`,ref:H,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:()=>Se(-1),children:Q($,{name:`prev`})}),Q(`button`,{class:`btn ib`,"data-tip":`Play Space`,"aria-label":C?`Pause`:`Play`,onClick:xe,children:Q($,{name:C?`pause`:`play`})}),Q(`button`,{class:`btn ghost ib`,"data-tip":`Forward one frame →`,"aria-label":`Forward one frame`,onClick:()=>Se(1),children:Q($,{name:`next`})}),Q(`span`,{class:`tc`,"aria-label":`Timecode`,children:[Q(`span`,{ref:de,children:G(x.time)}),Q(`small`,{children:[`/ `,G(w)]})]}),Q(`span`,{class:`sp`}),Me&&Q(`span`,{class:`chipx`,children:[Q(`span`,{class:`mono`,children:Me}),Q(`button`,{"aria-label":`Clear range`,onClick:Te,children:Q($,{name:`x`})})]}),z&&Q(S,{children:[Q(`button`,{class:`btn ghost ib`,"data-tip":`Set in I`,"aria-label":`Set in point`,onClick:Ce,children:Q($,{name:`in`})}),Q(`button`,{class:`btn ghost ib`,"data-tip":`Set out O`,"aria-label":`Set out point`,onClick:we,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:fe,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),be.current(x.time)},onSeeked:()=>be.current(x.time)}):Q(`div`,{class:`pvempty`,"aria-label":`No cut yet`,children:Q($,{name:`film`})}),Q(`div`,{class:`tcover`,ref:U,children:G(x.time)})]})}),Q(Zo,{notes:c,version:Ae,placeholder:_e(x.time),inputRef:me,toast:f,onAdd:ke,onChanged:p,onTextChange:ee,fixedTimes:!0,onSeek:e=>x.seek(e),on:{options:l,value:ce,onChange:k},scope:{value:P,onChange:Ee,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),R=JSON.stringify({want:L,levels:E,clips:Qt.map(e=>v[e].map(e=>[e.path,e.rev??``,e.offset]))}),[ee,z]=q({kind:`waiting`}),[te,ne]=q(!1),[re,ie]=q(0),ae=ee.kind===`timeout`||ee.kind===`error`,B=X(0);J(()=>{let e=++B.current;if(L.length===0){z({kind:`empty`}),ne(!1);return}z(e=>e.kind===`empty`||e.kind===`timeout`||e.kind===`error`?{kind:`waiting`}:e),ne(!0);let t=window.setTimeout(()=>{Z.post(`/api/mix/loudness`,{lanes:L}).then(t=>{e===B.current&&z({kind:`result`,result:t})},t=>{e===B.current&&z({kind:t instanceof kr&&t.status===504?`timeout`:`error`})}).finally(()=>{e===B.current&&ne(!1)})},500);return()=>window.clearTimeout(t)},[R,re]),J(()=>()=>void++B.current,[]);let V=Q(`div`,{class:ae?`meter retry`:`meter`,role:`group`,"aria-label":`Loudness`,"aria-busy":te,onClick:ae?()=>ie(e=>e+1):void 0,children:[pn(ee).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})]})),te&&Q(`span`,{class:`smk measuring`,"data-measuring":!0,"data-tip":`Measuring`,"aria-label":`Measuring`,children:Q($,{name:`gauge`})}),ae&&!te&&Q(`button`,{type:`button`,class:`btn ghost ib`,"data-tip":`Measure again`,"aria-label":`Measure again`,children:Q($,{name:`gauge`})})]}),oe=e.notes.notes.filter(e=>e.stage===`mix`),se=Se(n??void 0),ce=n&&se?{video:n.id,version:se.id,file:se.file,duration:se.duration}:null,le=e.project.fps||30;return Q(rs,{stage:`mix`,title:we.mix,belowLanes:V,rows:I,preview:ce,film:n?.id??null,fps:le,notes:oe,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=_e(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:ve(o.t,o.tOut)}),Q(`span`,{class:`ftag`,children:e.format?de(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,R=I??y.find(e=>e.primary)??null,ee=R?R.width/R.height:null,z=b!==null&&y.length>=2,te=y.find(e=>e.primary)?.id??null,ne=Qn(r,b),re=$n(r,b),[ie,ae]=q(`this`),[B,V]=q(ee??16/9),[oe,se]=q(!1),[ce,le]=q(null),[H,ue]=q({in:null,out:null}),[de,U]=q(!1),[W,pe]=q(null),[ye,be]=q({w:0,h:0}),[xe,Se]=q(null),[Ce,we]=q(null),[Te,Ee]=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(oe);J(()=>{Me.current=oe},[oe]);let Ne=X(!0);J(()=>()=>{Ne.current=!1},[]);let Pe=X(t.id);J(()=>{Pe.current=t.id},[t.id]),J(()=>{let e=H.in!==null||xe!==null||Te;return o?.(e),()=>o?.(!1)},[H.in,xe,Te]),J(()=>(xe!==null&&ae(`this`),w?.(xe!==null),()=>w?.(!1)),[xe]);let Fe=X(void 0);J(()=>{le(null),j(0),V(ee??16/9),ue({in:null,out:null}),Se(null),Fe.current!==void 0&&l(e.id,null),Fe.current=t.file,we(null),ae(`this`)},[t.file]);let Ie=xe?`this`:ie,Le=n=>fe(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(()=>{Ce&&!ne.some(e=>e.id===Ce)&&we(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=ce===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(!R||!e)return;let t=R.width/R.height;if(t===B)return;let n=e.getBoundingClientRect();$e.current={width:n.width,height:n.height},V(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`}))},[B]),J(()=>{let e=E.current;if(!e)return;let t=()=>le(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(!oe)return;let e=0,t=()=>{E.current&&(ot(E.current),j(E.current.currentTime)),e=requestAnimationFrame(t)};return e=requestAnimationFrame(t),()=>cancelAnimationFrame(e)},[oe]);let st=()=>Ze.current?.t??E.current?.currentTime??A,ct=()=>he(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(ge(st(),n,e,M))},ft=()=>ue({in:ct(),out:null}),pt=()=>{let e=ct(),t=H.in??0;if(e<=t)return i(`Out has to come after In`);ue({in:t,out:e})},mt=()=>ue({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=me(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=H.in!==null&&H.out!==null,o=i?H.in:ct();await Z.post(`/api/notes`,{stage:`picture`,video:e.id,version:t.id,scope:i?`range`:`point`,t:o,tOut:i?H.out:null,frame:me(o,n),text:r,box:xe,grab:c,...z?{format:Ie===`this`?b:null}:{}}),mt(),ae(`this`),Se(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`?U(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=()=>be(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(!de)return;let t=St(e);e.target.setPointerCapture(e.pointerId),pe({x0:t.x,y0:t.y,x1:t.x,y1:t.y,w:t.w,h:t.h})},wt=e=>{if(!W)return;let t=St(e);pe({...W,x1:t.x,y1:t.y})},Tt=e=>{if(!W)return;let t=St(e),n=at(W.x0,W.y0,t.x,t.y,W.w,W.h);pe(null),U(!1),ke.current=!0,n.w>.01&&n.h>.01&&Se(n)},Et=W?at(W.x0,W.y0,W.x1,W.y1,W.w,W.h):null,Dt=xt(ye.w,ye.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,he(A,n));J(()=>{Me.current&&jt!==null&&je.current[jt.n]?.scrollIntoView({block:`nearest`,inline:`nearest`})},[jt?.n]);let Mt=ne.map(e=>({n:e,at:_e(e,t.id)})).filter(({at:e})=>e.t!==null),Nt=ne.find(e=>e.id===Ce)??null,Pt=Nt?.box&&(!Nt.version||Nt.version===t.id)&&er(Nt,b,te)?Nt.box:null,Ft=H.in===null?null:H.out===null?`${G(H.in)} →`:ve(H.in,H.out),It=H.in!==null&&H.out===null?`Set an Out point`:`Note at ${Ft&&H.out!==null?Ft:G(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),le(e=>e===Ye?null:e),e.videoWidth&&e.videoHeight&&V(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 / ${B}))`},children:Q(`div`,{class:`frame`,ref:D,style:{aspectRatio:String(B),"--ar":String(B)},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),!oe&&!Ze.current&&j(t.currentTime)},onSeeked:e=>!Ze.current&&j(e.target.currentTime),onPlay:()=>se(!0),onPause:()=>se(!1),onEnded:()=>se(!1)}),Q(`div`,{ref:O,class:`overlay${de?` drawing`:``}`,onPointerDown:Ct,onPointerMove:wt,onPointerUp:Tt,onClick:()=>{ke.current?ke.current=!1:de||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)}),xe&&Q(`div`,{class:`bx`,style:Ot(xe)}),Et&&Q(`div`,{class:`bx`,style:Ot(Et)})]})}),Q(`div`,{class:`tcover`,children:[`f`,me(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":oe?`Pause`:`Play`,onClick:ut,children:Q($,{name:oe?`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:[G(A),Q(`small`,{children:[`/ `,G(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":de,onClick:()=>U(!de),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)}})),H.in!==null&&Q(`div`,{class:`span live`,style:{left:kt(H.in),width:kt((H.out??H.in+.2)-H.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,z);return Q(`div`,{class:`mk ${e.status}${z&&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:G(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:ne,version:t.id,selectedId:Ce,placeholder:It,inputRef:k,toast:i,onAdd:yt,onChanged:a,onTextChange:Ee,formatTag:e=>rr(e,z),cardExtra:z&&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:z&&I?{label:I.label,width:I.width,height:I.height,value:Ie,onChange:ae,lockedReason:xe?tr:null,hint:nr(I.label,Ie,xe!==null)}:void 0,listFooter:e=>{let n=re.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)=>{xe||(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),we(t.id)},attachments:(xe||c)&&Q(S,{children:[xe&&Q(`span`,{class:`chipx`,children:[Q($,{name:`box`}),`Box`,Q(`button`,{"aria-label":`Remove box`,onClick:()=>Se(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=ye(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:[G(e.start).replace(/\.\d+$/,``),`–`,G(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(be).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=Se(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:we[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=Se(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:we.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})}function vc(e,t){let n=[0,1,2].map(n=>Math.max(0,Math.min(e+t,(n+1)/3)-Math.max(e,n/3))*3>=.4);if(n.some(Boolean))return n;let r=Math.min(2,Math.max(0,Math.floor((e+t/2)*3)));return[r===0,r===1,r===2]}var yc=e=>e.map(e=>e?`1`:`0`).join(``),bc={100:`left third`,"010":`centre`,"001":`right third`,110:`left two thirds`,"011":`right two thirds`,111:`full width`,101:`full width`},xc={100:`top third`,"010":`middle`,"001":`bottom third`,110:`top two thirds`,"011":`bottom two thirds`,111:`full height`,101:`full height`};function Sc(e){let t=yc(vc(e.x,e.w)),n=yc(vc(e.y,e.h));return t===`111`&&n===`111`?`the whole picture`:t===`010`&&n===`010`?`the centre`:`${bc[t]}, ${xc[n]}`}function Cc(e){let t=Math.min(2,Math.max(0,Math.floor(e.x*3))),n=Math.min(2,Math.max(0,Math.floor(e.y*3)));return t===1&&n===1?`the centre`:`${[`left`,`centre`,`right`][t]}, ${[`top`,`middle`,`bottom`][n]}`}function wc(e,t,n=8){return Math.min(Math.max(0,e-1),Math.max(0,t-n))}var Tc=e=>Math.round(e*1e4)/1e4,Ec=e=>Tc(Math.max(0,Math.min(1,e))),Dc=.02;function Oc(e,t,n){if(!n)return{pin:{x:Ec(e.x),y:Ec(e.y)}};let[r,i,a,o]=[Ec(e.x),Ec(e.y),Ec(t.x),Ec(t.y)],s={x:Math.min(r,a),y:Math.min(i,o),w:Tc(Math.abs(a-r)),h:Tc(Math.abs(o-i))};return s.w<Dc||s.h<Dc?null:{box:s}}var kc=e=>e.versions[e.versions.length-1];function Ac(e){let t=kc(e);return{page:1,ratio:t.pages[0]?.images[0]?.ratio??``,ver:t.id}}var jc=(e,t)=>t.ver===kc(e).id;function Mc(e,t){return[e.name,e.kind===`carousel`?`page ${t.page}`:null,de(t.ratio),t.ver].filter(Boolean).join(` · `)}var Nc=e=>(e.on??``).slice(0,(e.on??``).lastIndexOf(`/`)),Pc=e=>Number((e.on??``).slice((e.on??``).lastIndexOf(`/`)+1))||0;function Fc(e,t){return e.filter(e=>e.stage===`visuals`&&Nc(e)===Nc(t)).findIndex(e=>e.id===t.id)+1}function Ic(e,t){let n=t.filter(e=>e.stage===`visuals`),r=[...e.map(e=>e.id),...new Set(n.map(Nc).filter(t=>!e.some(e=>e.id===t)))],i=[];for(let t of r){let r=n.filter(e=>Nc(e)===t);if(r.length===0)continue;let a=e.find(e=>e.id===t),o=[...new Set(r.map(Pc))].sort((e,t)=>e-t).map(e=>({page:e,notes:r.filter(t=>Pc(t)===e)}));i.push({visual:{id:t,name:a?.name??t},gone:!a,open:r.filter(e=>e.status===`todo`).length,pages:o})}return i}function Lc(e,t,n){return e.filter(e=>e.stage===`visuals`&&Nc(e)===t&&Pc(e)===n.page&&e.format===n.ratio&&e.version===n.ver&&(e.box!==null||e.pin!==null))}function Rc(e,t){let n={};for(let r of e)r.stage===`visuals`&&r.status===`todo`&&Nc(r)===t&&(n[Pc(r)]=(n[Pc(r)]??0)+1);return n}function zc(e,t,n){return{page:Pc(t),ratio:t.format??n.ratio,ver:t.version??n.ver}}function Bc(e,t,n){return!e||e.text.trim()===``||e.vis===t.vis&&e.page===t.page&&e.ratio===t.ratio&&e.ver===t.ver?null:`Finish or discard your draft on ${n} first.`}var Vc=e=>e instanceof HTMLElement&&(e.isContentEditable||/^(INPUT|TEXTAREA|SELECT)$/.test(e.tagName));function Hc(e){let t=X(null),[n,r]=q(null);return Y(()=>{let n=t.current;if(!n)return;let i=()=>{let t=n.getBoundingClientRect(),i=Math.min(t.width/e.w,t.height/e.h);r(i>0&&Number.isFinite(i)?{w:Math.floor(e.w*i),h:Math.floor(e.h*i)}:null)};i();let a=new ResizeObserver(i);return a.observe(n),()=>a.disconnect()},[e.w,e.h]),{box:t,size:n}}function Uc({notes:e,all:t,selected:n,draft:r}){return Q(S,{children:[e.map(e=>{let r=Fc(t,e),i=`${e.status===`done`?` done`:``}${n===e.id?` sel`:``}`;return e.pin?Q(`div`,{class:`vzpin${i}`,"data-note":e.id,style:{left:`${e.pin.x*100}%`,top:`${e.pin.y*100}%`},children:Q(`span`,{class:`no`,children:r})},e.id):e.box?Q(`div`,{class:`vzbox${i}`,"data-note":e.id,style:{left:`${e.box.x*100}%`,top:`${e.box.y*100}%`,width:`${e.box.w*100}%`,height:`${e.box.h*100}%`},children:Q(`span`,{class:`no`,children:r})},e.id):null}),r&&r.shape&&`pin`in r.shape&&Q(`div`,{class:`vzpin draft`,style:{left:`${r.shape.pin.x*100}%`,top:`${r.shape.pin.y*100}%`},children:Q(`span`,{class:`no`,children:t.filter(e=>e.stage===`visuals`&&Nc(e)===r.vis).length+1})}),r&&r.shape&&`box`in r.shape&&Q(`div`,{class:`vzbox draft`,style:{left:`${r.shape.box.x*100}%`,top:`${r.shape.box.y*100}%`,width:`${r.shape.box.w*100}%`,height:`${r.shape.box.h*100}%`},children:Q(`span`,{class:`no`,children:t.filter(e=>e.stage===`visuals`&&Nc(e)===r.vis).length+1})})]})}function Wc({file:e,alt:t,onBad:n}){return Q(`img`,{src:Nr(e),alt:t,draggable:!1,onError:n})}function Gc({visual:e,view:t,badges:n,onPage:r}){let i=e.versions.find(e=>e.id===t.ver)??kc(e),a=X(null);Y(()=>{let e=a.current;if(!e||e.children.length===0)return;let n=e.children[wc(t.page,i.pages.length)];n&&e.scrollTo({left:n.offsetLeft-e.children[0].offsetLeft,behavior:`auto`})},[t.page,i.pages.length]);let o=i.pages[0]?.images.find(e=>e.ratio===t.ratio)??i.pages[0]?.images[0],s=o?62*o.width/o.height:50;return Q(`div`,{class:`vzthumbs`,ref:a,style:{maxWidth:`${8*s+56+4}px`,"--vzth":`${s}px`},children:i.pages.map(e=>{let i=e.images.find(e=>e.ratio===t.ratio)??e.images[0];return Q(`button`,{class:`vzth`,style:{width:`${s}px`},"aria-label":`Page ${e.n}`,"aria-current":e.n===t.page?`true`:void 0,onClick:()=>r(e.n),children:[Q(`img`,{src:Nr(i.file),alt:``,draggable:!1,loading:`lazy`,decoding:`async`}),Q(`span`,{class:`pn`,children:e.n}),n[e.n]?Q(`span`,{class:`badge`,children:n[e.n]}):null]},e.n)})})}function Kc({visual:e,view:t,current:n,notes:r,selected:i,draft:a,verMenu:o,onSetView:s,onVerMenu:c,onFull:l,onPointer:u,onNotePick:d}){let f=e.versions.find(e=>e.id===t.ver)??kc(e),p=f.pages.find(e=>e.n===t.page)??f.pages[0],m=p.images.find(e=>e.ratio===t.ratio)??p.images[0],h=f.pages[0]?.images??[],{box:g,size:_}=Hc({w:m.width,h:m.height}),[v,y]=q(null),b=Lc(r,e.id,t),x=a&&a.vis===e.id&&a.page===t.page&&a.ratio===t.ratio&&a.ver===t.ver?a:null,C=!jc(e,t),w=String(t.page).padStart(2,`0`);return Q(`section`,{class:`vz${n?` cur`:``}`,"data-visual":e.id,"aria-label":e.name,"aria-current":n?`true`:void 0,children:[Q(`div`,{class:`vzhead`,children:[Q(`h2`,{children:e.name}),Q(`span`,{class:`vzkind`,children:[e.kind,e.kind===`carousel`?` · ${f.pages.length} pages`:``]}),e.versions.length>1?Q(`span`,{class:`vzver`,children:[Q(`button`,{class:`vzchip`,"aria-haspopup":`menu`,"aria-expanded":o,onClick:()=>c(!o),children:[t.ver,Q($,{name:`chev`})]}),o&&Q(`div`,{class:`vzvermenu`,role:`menu`,children:[...e.versions].reverse().map(n=>Q(`button`,{role:`menuitem`,"aria-current":n.id===t.ver?`true`:void 0,onClick:()=>{c(!1),s({ver:n.id})},children:[n.id,Q(`span`,{children:n.label||(n.id===kc(e).id?`newest`:`older`)})]},n.id))})]}):Q(`span`,{class:`vzchip static`,children:t.ver}),h.length>1?h.map(e=>Q(`button`,{class:`vzchip`,"aria-pressed":e.ratio===t.ratio,onClick:()=>s({ratio:e.ratio}),children:de(e.ratio)},e.ratio)):Q(`span`,{class:`vzchip static`,children:[m.width,`×`,m.height]}),C&&Q(`span`,{class:`vzbanner`,children:[`Viewing `,t.ver,`, an older version`]})]}),Q(`div`,{class:`vzfwrap`,ref:g,children:Q(`div`,{class:`vzframe`,"data-frame":e.id,role:`img`,"aria-label":`${Mc(e,t)}`,style:_?{width:`${_.w}px`,height:`${_.h}px`}:{visibility:`hidden`},onPointerDown:e=>u(e,e.currentTarget),children:[v===m.file?Q(`div`,{class:`vzbad`,children:[`Can't load page `,t.page,`: `,m.file]}):Q(Wc,{file:m.file,alt:`${e.name}, page ${t.page}`,onBad:()=>y(m.file)},m.file),Q(Uc,{notes:b,all:r,selected:i,draft:x})]})}),Q(`div`,{class:`vzfoot`,children:e.kind===`carousel`?Q(S,{children:[Q(`div`,{class:`vznav`,children:[Q(`button`,{class:`btn vzpill`,"aria-label":`Previous page`,disabled:t.page<=1,onClick:()=>s({page:t.page-1}),children:`Previous`}),Q(`span`,{class:`vzcount`,"aria-label":`Page ${t.page} of ${f.pages.length}`,children:[w,` / `,String(f.pages.length).padStart(2,`0`)]}),Q(`button`,{class:`btn vzpill`,onClick:l,children:`Full screen`}),Q(`button`,{class:`btn vzpill primary`,"aria-label":`Next page`,disabled:t.page>=f.pages.length,onClick:()=>s({page:t.page+1}),children:`Next`})]}),Q(Gc,{visual:e,view:t,badges:Rc(r,e.id),onPage:e=>s({page:e})})]}):Q(`div`,{class:`vznav`,children:[Q(`button`,{class:`btn vzpill`,onClick:l,children:`Full screen`}),Q(`span`,{class:`vzhint`,children:[`One page`,h.length>1?` · ${h.length} ratios`:``]})]})})]})}function qc({visual:e,view:t,notes:n,onPage:r,onClose:i}){let a=e.versions.find(e=>e.id===t.ver)??kc(e),o=a.pages.find(e=>e.n===t.page)??a.pages[0],s=o.images.find(e=>e.ratio===t.ratio)??o.images[0],{box:c,size:l}=Hc({w:s.width,h:s.height}),u=X(null);return J(()=>u.current?.focus(),[]),Q(`div`,{class:`vzfs`,role:`dialog`,"aria-label":`Full screen`,"aria-modal":`true`,tabIndex:-1,ref:u,children:[Q(`div`,{class:`stg`,ref:c,children:Q(`div`,{class:`vzframe`,"data-frame":e.id,style:l?{width:`${l.w}px`,height:`${l.h}px`}:{visibility:`hidden`},children:[Q(Wc,{file:s.file,alt:`${e.name}, page ${t.page}`,onBad:()=>void 0},s.file),Q(Uc,{notes:Lc(n,e.id,t),all:n,selected:null,draft:null})]})}),Q(`div`,{class:`bar`,children:[e.kind===`carousel`&&Q(S,{children:[Q(`button`,{class:`btn vzpill`,"aria-label":`Previous page`,disabled:t.page<=1,onClick:()=>r(t.page-1),children:`Previous`}),Q(`span`,{class:`vzcount`,children:[String(t.page).padStart(2,`0`),` / `,String(a.pages.length).padStart(2,`0`)]}),Q(`button`,{class:`btn vzpill primary`,"aria-label":`Next page`,disabled:t.page>=a.pages.length,onClick:()=>r(t.page+1),children:`Next`})]}),Q(`button`,{class:`btn vzpill`,onClick:i,children:`Close`})]})]})}function Jc({state:e,toast:t,onChanged:n,onPendingChange:r}){let i=e.visuals.visuals,a=e.notes.notes,[o,s]=q(i[0]?.id??``),[c,l]=q({}),[u,d]=q(null),[f,p]=q(null),[m,h]=q(null),[g,_]=q(null),v=X(null),y=X(null),b=e=>({...Ac(e),...c[e.id]}),x=i.find(e=>e.id===o)??i[0],S=(e,t)=>{l(n=>{let r={...b(e),...t},i=e.versions.find(e=>e.id===r.ver)??kc(e),a=Math.max(1,Math.min(i.pages.length,r.page)),o=i.pages[0]?.images.some(e=>e.ratio===r.ratio)?r.ratio:i.pages[0]?.images[0]?.ratio??r.ratio;return{...n,[e.id]:{page:a,ratio:o,...i.id===kc(e).id?{}:{ver:i.id}}}})};J(()=>{let e=v.current;if(!e)return;let t=new IntersectionObserver(e=>{for(let t of e)t.isIntersecting&&s(t.target.dataset.visual??``)},{root:e,rootMargin:`-50% 0px -50% 0px`,threshold:0});return e.querySelectorAll(`.vz`).forEach(e=>t.observe(e)),()=>t.disconnect()},[i.map(e=>e.id).join(`,`)]);let C=(e,t=!0)=>{let n=v.current?.querySelector(`.vz[data-visual="${e}"]`);n&&v.current.scrollTo({top:n.offsetTop,behavior:t?`smooth`:`instant`})};J(()=>(r(!!u&&u.text.trim()!==``),()=>r(!1)),[u?.text]);let w=(e,n,r)=>{if(e.button!==0)return;if(r.id!==o){C(r.id);return}let a=b(r);if(!jc(r,a))return t(`You're looking at ${a.ver}. Switch to the newest version to add notes.`);let s=Bc(u,{vis:r.id,...a},u?i.find(e=>e.id===u.vis)?.name??``:``);if(s)return t(s);e.preventDefault();let c=n.getBoundingClientRect(),l=(e,t)=>({x:(e-c.left)/c.width,y:(t-c.top)/c.height}),f=l(e.clientX,e.clientY),[p,m]=[e.clientX,e.clientY],h=!1,g=n.setPointerCapture?(n.setPointerCapture(e.pointerId),!0):!1,_=e=>{Math.hypot(e.clientX-p,e.clientY-m)>5&&(h=!0),h&&d(t=>({vis:r.id,text:t&&t.vis===r.id?t.text:``,...a,shape:Oc(f,l(e.clientX,e.clientY),!0)??{box:{x:f.x,y:f.y,w:0,h:0}}}))},v=u,x=()=>{n.removeEventListener(`pointermove`,_),n.removeEventListener(`pointerup`,S),n.removeEventListener(`pointercancel`,x),g&&n.releasePointerCapture?.(e.pointerId),d(v)},S=t=>{n.removeEventListener(`pointermove`,_),n.removeEventListener(`pointerup`,S),n.removeEventListener(`pointercancel`,x);let i=Oc(f,l(t.clientX,t.clientY),h);if(g&&n.releasePointerCapture?.(e.pointerId),!i)return d(e=>e&&e.text.trim()===``?null:e);d(e=>({vis:r.id,text:e&&e.vis===r.id?e.text:``,...a,shape:i})),queueMicrotask(()=>y.current?.focus())};n.addEventListener(`pointermove`,_),n.addEventListener(`pointerup`,S),n.addEventListener(`pointercancel`,x)},T=u?i.find(e=>e.id===u.vis):null,E=x?{vis:x.id,...b(x)}:null,D=!!(u&&E&&(u.vis!==E.vis||u.page!==E.page||u.ver!==E.ver||(u.shape||u.justThis)&&u.ratio!==E.ratio)),O=!!T&&T.versions.find(e=>e.id===u?.ver)?.pages[0]?.images.length>1,k=()=>{if(!x)return;let e=b(x);if(!jc(x,e))return t(`You're looking at ${e.ver}. Switch to the newest version to add notes.`);let n=Bc(u,{vis:x.id,...e},u?i.find(e=>e.id===u.vis)?.name??``:``);if(n)return t(n);d({vis:x.id,...e,shape:null,text:u?.text??``}),queueMicrotask(()=>y.current?.focus())},A=X(!1),[j,M]=q(!1),N=async()=>{if(A.current)return;let e=u??(x?{vis:x.id,...b(x),shape:null,text:``}:null);if(!e)return;let r=(y.current?.value??e.text).trim();if(!r)return t(`Write the note first.`),y.current?.focus();if(!jc(i.find(t=>t.id===e.vis),e))return t(`This note is for ${e.ver}, an older version. Switch to the newest version to add notes.`);let a=e.shape||e.justThis?e.ratio:null;A.current=!0,M(!0);try{let t=await Z.post(`/api/notes`,{stage:`visuals`,scope:`whole`,version:e.ver,on:`${e.vis}/${e.page}`,format:a,text:r,...e.shape&&`box`in e.shape?{box:e.shape.box}:{},...e.shape&&`pin`in e.shape?{pin:e.shape.pin}:{}});d(null),p(t.note.id),n()}catch(e){t((e instanceof kr,e.message))}finally{A.current=!1,M(!1)}},P=async e=>{try{await Z.patch(`/api/notes/${e.id}`,{status:e.status===`done`?`todo`:`done`}),n()}catch(e){t(e.message)}},F=e=>{let t=i.find(t=>t.id===Nc(e));t&&(p(e.id),S(t,zc(t,e,b(t))),C(t.id),s(t.id),setTimeout(()=>{let t=document.querySelector(`.vz [data-note="${e.id}"]`);t&&(t.classList.remove(`flash`),t.offsetWidth,t.classList.add(`flash`))},350))},I=X(()=>void 0);if(J(()=>{let e=e=>I.current(e);return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[]),I.current=e=>{if(e.metaKey||e.ctrlKey||e.altKey||!x)return;if(m){let t=i.find(e=>e.id===m);if(!t)return;e.key===`Escape`?h(null):t.kind===`carousel`&&(e.key===`ArrowRight`||e.key===`ArrowLeft`)&&(e.preventDefault(),S(t,{page:b(t).page+(e.key===`ArrowRight`?1:-1)}));return}if(Vc(e.target))return;let t=b(x),n=i.findIndex(e=>e.id===x.id);if(e.key===`ArrowRight`&&x.kind===`carousel`)e.preventDefault(),S(x,{page:t.page+1});else if(e.key===`ArrowLeft`&&x.kind===`carousel`)e.preventDefault(),S(x,{page:t.page-1});else if(e.key===`ArrowDown`&&n<i.length-1)e.preventDefault(),C(i[n+1].id);else if(e.key===`ArrowUp`&&n>0)e.preventDefault(),C(i[n-1].id);else if(e.key===`r`||e.key===`R`){let e=Yc(x,t);e.length>1&&S(x,{ratio:e[(e.indexOf(t.ratio)+1)%e.length]})}else e.key===`n`||e.key===`N`?(e.preventDefault(),y.current?.focus()):e.key===`Escape`&&d(null)},J(()=>{if(!g)return;let e=e=>{e.target.closest(`.vzver`)||_(null)};return document.addEventListener(`click`,e),()=>document.removeEventListener(`click`,e)},[g]),!x)return null;let L=Ic(i,a),R=a.filter(e=>e.stage===`visuals`&&e.status===`todo`).length,ee=new Set(a.filter(e=>e.stage===`visuals`&&e.status===`todo`).map(Nc)).size,z=m?i.find(e=>e.id===m):null;return Q(`div`,{class:`vzsplit`,children:[Q(`div`,{class:`vzscroll`,ref:v,children:i.map(e=>Q(Kc,{visual:e,view:b(e),current:e.id===o,notes:a,selected:f,draft:u,verMenu:g===e.id,onSetView:t=>S(e,t),onVerMenu:t=>_(t?e.id:null),onFull:()=>h(e.id),onPointer:(t,n)=>w(t,n,e),onNotePick:e=>p(e)},e.id))}),Q(`aside`,{class:`vznotes`,"aria-label":`Visual notes`,children:[Q(`div`,{class:`vznhead`,children:[Q(`h3`,{children:`Notes`}),Q(`span`,{children:[R,` open across `,ee,` visual`,ee===1?``:`s`]})]}),Q(`div`,{class:`vznlist`,children:[L.length===0&&Q(`div`,{class:`vzempty`,children:`No notes yet.`}),L.map(e=>Q(`div`,{class:`vzgrp${e.visual.id===o?` cur`:``}`,"data-grp":e.visual.id,children:[Q(`button`,{class:`vzghead`,onClick:()=>!e.gone&&C(e.visual.id),children:[e.visual.name,e.visual.id===o&&Q(`span`,{class:`here`,children:`looking at`}),Q(`span`,{class:`cnt`,children:[e.open,` open`]})]}),Q(`div`,{class:`vzpg`,children:e.pages.map(t=>Q(`div`,{children:[Q(`div`,{class:`vzpgh`,children:i.find(t=>t.id===e.visual.id)?.kind===`carousel`?`Page ${t.page}`:`Page 1`}),t.notes.map(t=>{let n=i.find(t=>t.id===e.visual.id),r=n&&t.version&&t.version!==kc(n).id;return Q(`div`,{class:`vznote${t.status===`done`?` done`:``}${f===t.id?` sel`:``}`,"data-note":t.id,role:`button`,tabIndex:0,onClick:()=>F(t),onKeyDown:e=>e.key===`Enter`&&F(t),children:[Q(`span`,{class:`no2`,children:Fc(a,t)}),Q(`div`,{class:`txt`,children:[Q(`span`,{class:`t`,children:t.text}),Q(`span`,{class:`tags`,children:[Q(`span`,{class:`tag`,children:t.format?de(t.format):`all ratios`}),Q(`span`,{class:`tag${r?` old`:``}`,children:r?`from ${t.version}`:t.version}),Q(`span`,{class:`tag`,title:t.box?Sc(t.box):t.pin?Cc(t.pin):void 0,children:t.box?`region`:t.pin?`point`:`whole image`})]}),t.reply&&Q(`div`,{class:`vzreply`,children:[Q(`b`,{children:`Agent`}),` `,t.reply,t.fixVersion&&n&&Q(`button`,{class:`vzlink`,onClick:e=>{e.stopPropagation(),p(t.id),S(n,{...zc(n,t,b(n)),ver:t.fixVersion}),C(n.id)},children:[`Show in `,t.fixVersion]})]})]}),Q(`button`,{class:`vztick`,"aria-label":t.status===`done`?`Reopen`:`Mark done`,"data-tip":t.status===`done`?`Reopen`:`Mark done`,onClick:e=>{e.stopPropagation(),P(t)},children:Q($,{name:t.status===`done`?`check`:`circle`})})]},t.id)})]},t.page))})]},e.visual.id))]}),Q(`div`,{class:`vzcomposer`,children:[Q(`div`,{class:`vztarget${D?` away`:``}`,children:[Q(`span`,{class:`lbl`,children:D?`Draft for`:`Adding to`}),Q(`b`,{children:D&&T?Mc(T,u):Mc(x,b(x))}),D&&Q(`button`,{class:`btn`,onClick:()=>C(u.vis),children:`Go to it`})]}),Q(`textarea`,{ref:y,"aria-label":`Note text`,placeholder:u?u.shape?`${u.shape&&`pin`in u.shape?`A point`:`A region`} is marked. Write what to change.`:`No region: this note is for the whole image.`:`Drag on the picture to mark a region, click for a point, or add a whole-image note.`,value:u?.text??``,onInput:e=>{let t=e.currentTarget.value;d(e=>e?{...e,text:t}:x?{vis:x.id,...b(x),shape:null,text:t}:e)},onKeyDown:e=>{e.key===`Enter`&&(e.metaKey||e.ctrlKey)&&N(),e.key===`Escape`&&(e.stopPropagation(),d(null),e.currentTarget.blur())}}),u&&!u.shape&&O&&Q(`label`,{class:`vzjust`,children:[Q(`input`,{type:`checkbox`,checked:!!u.justThis,onChange:e=>d({...u,justThis:e.currentTarget.checked})}),`Just `,de(u.ratio)]}),Q(`div`,{class:`vzcrow`,children:[Q(`button`,{class:`btn primary`,disabled:j,onClick:()=>void N(),children:`Add note`}),Q(`button`,{class:`btn`,onClick:k,children:`Whole image`}),Q(`button`,{class:`btn ghost`,disabled:!u,onClick:()=>d(null),children:u?.text?`Discard draft`:`Cancel`})]})]})]}),z&&Q(qc,{visual:z,view:b(z),notes:a,onPage:e=>S(z,{page:e}),onClose:()=>h(null)})]})}function Yc(e,t){return(e.versions.find(e=>e.id===t.ver)??kc(e)).pages[0]?.images.map(e=>e.ratio)??[]}var Xc=[[`all`,`All`],[`picture`,Gi.picture],[`voice`,Gi.voice],[`music`,Gi.music],[`sfx`,Gi.sfx],[`mix`,Gi.mix],[`visuals`,Gi.visuals],[`notes`,Gi.notes],[`assets`,Gi.assets]];function Zc(e){return Xc.some(([t])=>t===e)}var Qc={user:`added by you`,agent:`agent`,rushes:`Rushes`};function $c(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 el(e,t){return e===`all`||e===t}var tl=new Set([` `,`ArrowLeft`,`ArrowRight`,`ArrowUp`,`ArrowDown`,`Home`,`End`,`PageUp`,`PageDown`]);function nl(e){return tl.has(e.key)&&!e.altKey&&!e.ctrlKey&&!e.metaKey}var rl=[`script`,`picture`,`voice`,`music`,`sfx`,`mix`];function il(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&&rl.includes(e.tab)?{tab:e.tab}:e.area===`assets`?{tab:`assets`}:rl.includes(e.area)?{tab:e.area}:null}function al(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 ol(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 sl(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 cl(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 ll(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 ul(e,t){return`rushes:${e}:${t}`}function dl(e,t){try{return e?.getItem(t)??null}catch{return null}}function fl(e,t,n){try{e?.setItem(t,n)}catch{}}var pl=1e3,ml=40,hl=()=>{try{return window.sessionStorage}catch{return}},gl=()=>{try{return window.localStorage}catch{return}};function _l(e,t){let[n,r]=q(()=>dl(hl(),ul(e,`log-open`))===`1`),[i,a]=q(!1),[o,s]=q(()=>dl(gl(),ul(e,`log-seen`))),c=t?.mark??null,l=X(o);l.current=o;let u=t=>{s(t),fl(gl(),ul(e,`log-seen`),t)};return J(()=>{n&&c&&ll(c,o)&&u(c)},[n,c]),J(()=>{let t=ul(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&&ll(c,o),setOpen:t=>{r(t),a(t),fl(hl(),ul(e,`log-open`),t?`1`:`0`)},saw:e=>{ll(e,l.current)&&u(e)}}}function vl(){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 yl({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(vl,{}),Q(`span`,{class:`clabel`,children:`Change Log`}),e.dot&&Q(`span`,{class:`cdot`,"aria-hidden":`true`})]})}function bl(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 xl(e){return e.log.open?Q(Cl,{...e}):null}function Sl({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:Qc[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":sl(e,r),onClick:()=>n(t),children:i}):Q(`div`,{class:`lrow`,"data-entry":e.id,children:i})}function Cl({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=dl(hl(),ul(t,`log-filter`));return Zc(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)>ml,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(pl)});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(cl(`read`,e)):m(cl(`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(``),!el(h,i)){let e=Gi[i];s(`Added under ${e}. Choose All${Xc.some(([e])=>e===i)?` or ${e}`:``} to see it.`)}b.current&&(b.current.scrollTop=0),await O(!0)}catch(e){s(cl(`add`,e))}},M=e=>{g(e),fl(hl(),ul(t,`log-filter`),e)},N=(e,t)=>{let n=sa(e.key,t,Xc.length,!0);if(n===null)return;e.preventDefault();let r=Xc[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 R=X(e=>L.current(e)).current,ee=async()=>{try{s(`Saved to ${(await Z.post(`/api/exports/change-log`,{})).path}`)}catch(e){s(cl(`export`,e))}},z=yr(()=>l?$c(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(Sl,{entry:e,to:il(e,r),onGo:R})},e.id))})]},e.key)):null,[l,r,Qi(new Date)]),te=l&&d?al(l.entries,d.entries):0,ne=l!==null&&l.total===0&&l.undated.length===0,re=l!==null&&!ne&&l.entries.length===0&&l.undated.length===0;return Q(`aside`,{id:`changelog`,class:`drawer`,ref:y,"aria-label":`Change Log`,onKeyDown:e=>{nl(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:Xc.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:[te>0&&Q(`button`,{type:`button`,class:`dpill`,onClick:P,children:[te,` 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}),ne&&Q(`p`,{class:`dempty`,children:`Nothing yet. Rushes writes a line here whenever a cut, a take or a variant is added.`}),re&&Q(`p`,{class:`dempty`,children:`Nothing for this filter.`}),z,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?ol(l):``}),Q(`button`,{type:`button`,class:`btn`,onClick:()=>void ee(),children:`Export as Markdown`})]})]})}var wl=[`script`,`picture`,`voice`,`music`,`sfx`,`mix`,`visuals`],Tl=e=>e instanceof HTMLElement&&(e.isContentEditable||/^(INPUT|TEXTAREA|SELECT)$/.test(e.tagName));function El({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:Te[e],l=e===`assets`?`Assets`:e===`brief`?`Brief`:e===`storyboard`?`Storyboard`:we[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 Dl(){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,R]=q({}),ee=(e,t)=>R(n=>({...n,[e]:t})),[z,te]=q({}),[ne,re]=q({}),[ie,ae]=q(!1),B=X(new Set),V=(e,t=2400)=>{m(e),clearTimeout(N.current),N.current=window.setTimeout(()=>m(null),t)},[oe,se]=q({n:0,pending:!1}),[ce,le]=q(null),H=_l(Ar()??``,e?.log),ue=X(null);J(()=>{for(let e of Object.values(a))e.state!==`failed`||B.current.has(e.job)||(B.current.add(e.job),V(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 U=e?.project.videos.find(e=>e.id===l)??e?.project.videos[0],W=xe(U),pe=Se(U),G=U?.versions.find(e=>e.id===d)??pe,me=!!U?.lockedVersion,ge=G?.fps??e?.project.fps??30,_e=G?t.find(e=>e.kind===`cut`&&e.path===G.file):void 0,ve=e?.notes.notes.filter(e=>e.stage===`picture`&&(!e.video||e.video===U?.id))??[],ye=G?fe(G,ne[G.file]):[],be=U&&G?Un(U,G.id):void 0,Ee=Wn(ye,U?z[U.id]:void 0),De=new Set(t.filter(e=>e.kind===`cut`&&e.missing).map(e=>e.path)),Oe=G?Gn({views:ye,previous:be?fe(be):[],current:Ee,versionDuration:G.duration,notes:ve,missing:De}):[],ke=e=>!U||e===Ee?!1:ie?(V(`Add or clear your box on ${Ee?de(Ee):`this format`} first`),!1):(te(t=>({...t,[U.id]:e})),!0);J(()=>{T&&d===null&&pe?(f(pe.id),O(!0)):!T&&D&&d===pe?.id&&(f(null),O(!1))},[T,d,pe?.id]),J(()=>{!D&&d!==null&&d===pe?.id&&f(null)},[pe?.id,D,d]);let Pe=W&&G&&W.id!==G.id&&(me||D)?W.id:null,Fe=()=>{W&&f(W.id),O(!1)},ze=e=>{if(!U||e===U.id)return;if(T)return V(`Add or clear your note on ${U.name} first`);let t=F.current;t?.pause();let n=t?he(t.currentTime,ge):P.current.get(U.id)?.t??0;P.current.set(U.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(U&&G)try{await Z.put(`/api/videos/${U.id}/lock`,{version:U.lockedVersion?null:G.id}),i()}catch(e){V(e.message)}},Ue=t=>{if(T)return V(`Add or clear your note first`);if(t.tab===`assets`)return Xe();if(t.video&&t.video!==U?.id&&ze(t.video),t.version){let n=e?.project.videos.find(e=>e.id===(t.video??U?.id));f(t.version===Se(n)?.id?null:t.version),O(!1)}c(t.tab),g(null),t.row&&bl(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 V(`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 V(`Add or clear your note first`);c(`assets`),g(null)},Ze=e=>{if(T&&s!==`assets`)return V(`Add or clear your note first`);se(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`||Tl(t.target))return;t.preventDefault();let e=Kn(Oe,Ee,t.key===`ArrowRight`?1:-1);e&&ke(e);return}if(Tl(t.target)||t.metaKey||t.ctrlKey||t.altKey)return;let n=Number(t.key);if(n===1?Ye():n>=2&&n<=7?Je(wl[n-1]):n===8&&Xe(),(t.key===`[`||t.key===`]`)&&e){let n=Ce(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 V(`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,U?.name??null,t)}),w(!1);return}if(s===`storyboard`){if(!e)return;if(!e.storyboard.exists)return V(`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,U?.name??null,t)}),w(!1);return}try{let{batch:e}=await Z.post(`/api/batches`,{stage:s});g(e),w(!1),i()}catch(e){V(e instanceof kr&&e.code===`empty_batch`?`Nothing open on ${we[s]} to send`:e.message)}}},at=async()=>{if(h)try{await navigator.clipboard.writeText(h.prompt),w(!0)}catch{V(`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===U?.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:Te.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,U?.name??null)),V(`Prompt copied`)}catch{V(`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}),U&&e.project.videos.length===1&&Q(S,{children:[Q(`span`,{class:`slash`,children:`/`}),Q(`span`,{class:`sel`,children:U.name})]})]}),Ke!==null&&An(e.found)!==ce&&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})]}),U&&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===U.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`})]}))}),U&&Q(S,{children:[Q(`span`,{class:`plabel`,children:`Picture`}),G&&Q(Bs,{versions:U.versions,shown:G,lockedVersion:U.lockedVersion,onPick:e=>{f(e===pe?.id?null:e),O(!1)}}),G&&Q(`button`,{class:`btn ib lockbtn`,"aria-pressed":me,"aria-label":me?`Picture locked at ${U.lockedVersion} · unlock`:`Lock picture at ${G.id}`,"data-tip":me?`Picture locked at ${U.lockedVersion} · unlock`:`Lock picture at ${G.id}`,onClick:()=>void He(),children:Q($,{name:me?`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`&&G&&Oe.length>0&&Q(ro,{chips:Oe,versionId:G.id,prompt:Xn(e.project.name,U.name,G.id),onSelect:ke,toast:V})]}),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(yl,{log:H,buttonRef:ue}),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(xl,{log:H,projectId:Ar()??``,head:e.log,project:e.project,stage:s===`brief`||s===`storyboard`?`script`:s,header:et,buttonRef:ue,toast:V,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)}),wl.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 ${Te[e].ask}`,onClick:()=>Je(e),children:[Q($,{name:da[e]}),we[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 ${Te.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:oe,onFoundRequestUsed:()=>se(e=>e.pending?{n:e.n,pending:!1}:e),onFoundSeen:le,toast:V,onChanged:()=>void i()}):Q(El,{tab:`assets`,projectName:e.project.name,filmName:U?.name??null,found:e.found?.counts,onReview:Ze,toast:V}):ct?s===`picture`&&U&&G?Q(Ws,{video:U,version:G,fps:ge,notes:ot,toast:V,onChanged:()=>void i(),onPendingChange:E,startAt:k,grab:j[U.id]??null,onGrabChange:I,playerRef:F,ffmpeg:e.proxies?.ffmpeg??!1,autoProxy:e.project.autoProxy,proxyJob:a[gn(U.id,G.id)],noteProxyJob:o,source:L[U.id]??`proxy`,onSourceChange:ee,fileSize:_e?.size??null,fileRev:_e?qr(_e):void 0,formats:ye,format:Ee,formatMissing:!!Ee&&De.has(ye.find(e=>e.id===Ee)?.file??``),onPrimarySize:(e,t,n)=>re(r=>r[e]?r:{...r,[e]:{width:t,height:n}}),onBoxPendingChange:ae,onFormatChange:ke},U.id):s===`brief`?Q(to,{brief:e.brief,toast:V,onChanged:()=>void i(),settle:y}):s===`storyboard`?Q(Qs,{board:e.storyboard,brief:e.brief,toast:V,onChanged:()=>void i(),settle:y}):s===`visuals`?Q(Jc,{state:e,toast:V,onChanged:()=>void i(),onPendingChange:E}):s===`script`?Q(ic,{script:e.script,toast:V,onChanged:()=>void i()}):s===`voice`?Q(_c,{state:e,assets:t,video:U??null,toast:V,onChanged:()=>void i(),onPendingChange:E},`voice`):s===`mix`?Q(cs,{state:e,assets:t,video:U??null,toast:V,onChanged:()=>void i(),onPendingChange:E},`mix`):s===`music`||s===`sfx`?Q(lc,{stage:s,state:e,assets:t,video:U??null,toast:V,onChanged:()=>void i(),onPendingChange:E},s):null:Q(El,{tab:s,projectName:e.project.name,filmName:U?.name??null,found:e.found?.counts,onReview:Ze,toast:V})})]})}Ft(document),ie(Q(Dl,{}),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 ${G(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:[G(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}:_e(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:ve(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([]),[R,ee]=q(!1),z=(e.scopes??ns).includes(`range`),te=e.defaultScope??`point`,ne=`${e.film===void 0?o?.video??``:e.film??``}/${o?.version??``}`,re=X(ne);Y(()=>{re.current!==ne&&(re.current=ne,F(te))},[ne]);let ie=lt({range:M,marks:I,hasText:R});Y(()=>{m?.(ie)},[ie]),J(()=>()=>m?.(!1),[]);let ae=e=>h?h(e):{select:jt(a,e),gains:{}},B=X({select:{},gains:{}}),V=e=>{let t=B.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);B.current={select:{...t.select,...e.select},gains:{...t.gains,...e.gains}}},oe=ae(j);Y(()=>V(oe),[x,JSON.stringify(oe)]);let se=e.defaultOn??a.find(e=>e.picked)?.on??a[0]?.on??l[0]?.value??null,ce=l.some(e=>e.value===O)?O:se,le=l.find(e=>e.value===ce)??null,H=X(null),ue=X([]),de=X(null),U=X(null),fe=X(null),W=X(!1),pe=X(0),me=X(null),_e=e=>{if(P===`whole`)return t===`voice`?`Note on the whole read`:`Note on the whole track`;if(z){if(M.in!==null&&M.out===null)return`Set an Out point`;if(M.in!==null&&M.out!==null)return`Note on ${ve(M.in,M.out)}`;if(P===`range`)return`Set In and Out`}return`Note at ${G(le?.t??he(e,s))}`},ye=e=>{let t=x.length,n=`${t>0?Math.min(e,t)/t*100:0}%`;for(let e of ue.current)e.style.left=n;let r=G(e);de.current&&(de.current.textContent=r),U.current&&(U.current.textContent=r),me.current&&(me.current.placeholder=_e(e));let i=fe.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&&!W.current&&e>pe.current&&(W.current=!0,i.play().catch(()=>void 0)),pe.current=e},be=X(ye);be.current=ye,Y(()=>{ue.current=H.current?[...H.current.querySelectorAll(`.playhead`)]:[],ye(x.time)}),J(()=>x.subscribe(e=>be.current(e)),[x]),J(()=>{let e=fe.current;e&&(W.current=!1,C||(e.pause(),be.current(x.time)))},[C,o?.file]);let xe=()=>x.playing?x.pause():x.play(),Se=e=>{x.pause(),x.seek(ge(x.time,s,e,x.length))},Ce=()=>{z&&(N({in:he(x.time,s),out:null}),F(`range`))},we=()=>{if(!z)return;let e=he(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`)},Te=()=>{N(ts),L([]),P===`range`&&F(te)},Ee=e=>{(e!==`range`||z)&&(F(e),e!==`range`&&(N(ts),L([])))},De=t=>{D(t.key),V(ae(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(),xe()}else e.key===`ArrowLeft`?(e.preventDefault(),Se(e.shiftKey?-10:-1)):e.key===`ArrowRight`?(e.preventDefault(),Se(e.shiftKey?10:1)):t===`i`?Ce():t===`o`?we():t===`n`&&(e.preventDefault(),me.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=le?.t??he(x.time,s));await Z.post(`/api/notes`,{stage:t,video:o?.video??null,version:o?.version??null,on:le?.on??null,scope:P,t:n,tOut:r,text:e,marks:P===`range`?I:[]}),N(ts),L([]),F(te),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:z?e.tOut:null,status:e.status,text:e.text})}let Me=M.in===null?null:M.out===null?`${G(M.in)} →`:ve(M.in,M.out);return Q(`div`,{class:`astage`,ref:H,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:()=>Se(-1),children:Q($,{name:`prev`})}),Q(`button`,{class:`btn ib`,"data-tip":`Play Space`,"aria-label":C?`Pause`:`Play`,onClick:xe,children:Q($,{name:C?`pause`:`play`})}),Q(`button`,{class:`btn ghost ib`,"data-tip":`Forward one frame →`,"aria-label":`Forward one frame`,onClick:()=>Se(1),children:Q($,{name:`next`})}),Q(`span`,{class:`tc`,"aria-label":`Timecode`,children:[Q(`span`,{ref:de,children:G(x.time)}),Q(`small`,{children:[`/ `,G(w)]})]}),Q(`span`,{class:`sp`}),Me&&Q(`span`,{class:`chipx`,children:[Q(`span`,{class:`mono`,children:Me}),Q(`button`,{"aria-label":`Clear range`,onClick:Te,children:Q($,{name:`x`})})]}),z&&Q(S,{children:[Q(`button`,{class:`btn ghost ib`,"data-tip":`Set in I`,"aria-label":`Set in point`,onClick:Ce,children:Q($,{name:`in`})}),Q(`button`,{class:`btn ghost ib`,"data-tip":`Set out O`,"aria-label":`Set out point`,onClick:we,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:fe,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),be.current(x.time)},onSeeked:()=>be.current(x.time)}):Q(`div`,{class:`pvempty`,"aria-label":`No cut yet`,children:Q($,{name:`film`})}),Q(`div`,{class:`tcover`,ref:U,children:G(x.time)})]})}),Q(Zo,{notes:c,version:Ae,placeholder:_e(x.time),inputRef:me,toast:f,onAdd:ke,onChanged:p,onTextChange:ee,fixedTimes:!0,onSeek:e=>x.seek(e),on:{options:l,value:ce,onChange:k},scope:{value:P,onChange:Ee,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),R=JSON.stringify({want:L,levels:E,clips:Qt.map(e=>v[e].map(e=>[e.path,e.rev??``,e.offset]))}),[ee,z]=q({kind:`waiting`}),[te,ne]=q(!1),[re,ie]=q(0),ae=ee.kind===`timeout`||ee.kind===`error`,B=X(0);J(()=>{let e=++B.current;if(L.length===0){z({kind:`empty`}),ne(!1);return}z(e=>e.kind===`empty`||e.kind===`timeout`||e.kind===`error`?{kind:`waiting`}:e),ne(!0);let t=window.setTimeout(()=>{Z.post(`/api/mix/loudness`,{lanes:L}).then(t=>{e===B.current&&z({kind:`result`,result:t})},t=>{e===B.current&&z({kind:t instanceof kr&&t.status===504?`timeout`:`error`})}).finally(()=>{e===B.current&&ne(!1)})},500);return()=>window.clearTimeout(t)},[R,re]),J(()=>()=>void++B.current,[]);let V=Q(`div`,{class:ae?`meter retry`:`meter`,role:`group`,"aria-label":`Loudness`,"aria-busy":te,onClick:ae?()=>ie(e=>e+1):void 0,children:[pn(ee).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})]})),te&&Q(`span`,{class:`smk measuring`,"data-measuring":!0,"data-tip":`Measuring`,"aria-label":`Measuring`,children:Q($,{name:`gauge`})}),ae&&!te&&Q(`button`,{type:`button`,class:`btn ghost ib`,"data-tip":`Measure again`,"aria-label":`Measure again`,children:Q($,{name:`gauge`})})]}),oe=e.notes.notes.filter(e=>e.stage===`mix`),se=Se(n??void 0),ce=n&&se?{video:n.id,version:se.id,file:se.file,duration:se.duration}:null,le=e.project.fps||30;return Q(rs,{stage:`mix`,title:we.mix,belowLanes:V,rows:I,preview:ce,film:n?.id??null,fps:le,notes:oe,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=_e(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:ve(o.t,o.tOut)}),Q(`span`,{class:`ftag`,children:e.format?de(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,R=I??y.find(e=>e.primary)??null,ee=R?R.width/R.height:null,z=b!==null&&y.length>=2,te=y.find(e=>e.primary)?.id??null,ne=Qn(r,b),re=$n(r,b),[ie,ae]=q(`this`),[B,V]=q(ee??16/9),[oe,se]=q(!1),[ce,le]=q(null),[H,ue]=q({in:null,out:null}),[de,U]=q(!1),[W,pe]=q(null),[ye,be]=q({w:0,h:0}),[xe,Se]=q(null),[Ce,we]=q(null),[Te,Ee]=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(oe);J(()=>{Me.current=oe},[oe]);let Ne=X(!0);J(()=>()=>{Ne.current=!1},[]);let Pe=X(t.id);J(()=>{Pe.current=t.id},[t.id]),J(()=>{let e=H.in!==null||xe!==null||Te;return o?.(e),()=>o?.(!1)},[H.in,xe,Te]),J(()=>(xe!==null&&ae(`this`),w?.(xe!==null),()=>w?.(!1)),[xe]);let Fe=X(void 0);J(()=>{le(null),j(0),V(ee??16/9),ue({in:null,out:null}),Se(null),Fe.current!==void 0&&l(e.id,null),Fe.current=t.file,we(null),ae(`this`)},[t.file]);let Ie=xe?`this`:ie,Le=n=>fe(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(()=>{Ce&&!ne.some(e=>e.id===Ce)&&we(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=ce===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(!R||!e)return;let t=R.width/R.height;if(t===B)return;let n=e.getBoundingClientRect();$e.current={width:n.width,height:n.height},V(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`}))},[B]),J(()=>{let e=E.current;if(!e)return;let t=()=>le(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(!oe)return;let e=0,t=()=>{E.current&&(ot(E.current),j(E.current.currentTime)),e=requestAnimationFrame(t)};return e=requestAnimationFrame(t),()=>cancelAnimationFrame(e)},[oe]);let st=()=>Ze.current?.t??E.current?.currentTime??A,ct=()=>he(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(ge(st(),n,e,M))},ft=()=>ue({in:ct(),out:null}),pt=()=>{let e=ct(),t=H.in??0;if(e<=t)return i(`Out has to come after In`);ue({in:t,out:e})},mt=()=>ue({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=me(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=H.in!==null&&H.out!==null,o=i?H.in:ct();await Z.post(`/api/notes`,{stage:`picture`,video:e.id,version:t.id,scope:i?`range`:`point`,t:o,tOut:i?H.out:null,frame:me(o,n),text:r,box:xe,grab:c,...z?{format:Ie===`this`?b:null}:{}}),mt(),ae(`this`),Se(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`?U(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=()=>be(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(!de)return;let t=St(e);e.target.setPointerCapture(e.pointerId),pe({x0:t.x,y0:t.y,x1:t.x,y1:t.y,w:t.w,h:t.h})},wt=e=>{if(!W)return;let t=St(e);pe({...W,x1:t.x,y1:t.y})},Tt=e=>{if(!W)return;let t=St(e),n=at(W.x0,W.y0,t.x,t.y,W.w,W.h);pe(null),U(!1),ke.current=!0,n.w>.01&&n.h>.01&&Se(n)},Et=W?at(W.x0,W.y0,W.x1,W.y1,W.w,W.h):null,Dt=xt(ye.w,ye.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,he(A,n));J(()=>{Me.current&&jt!==null&&je.current[jt.n]?.scrollIntoView({block:`nearest`,inline:`nearest`})},[jt?.n]);let Mt=ne.map(e=>({n:e,at:_e(e,t.id)})).filter(({at:e})=>e.t!==null),Nt=ne.find(e=>e.id===Ce)??null,Pt=Nt?.box&&(!Nt.version||Nt.version===t.id)&&er(Nt,b,te)?Nt.box:null,Ft=H.in===null?null:H.out===null?`${G(H.in)} →`:ve(H.in,H.out),It=H.in!==null&&H.out===null?`Set an Out point`:`Note at ${Ft&&H.out!==null?Ft:G(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),le(e=>e===Ye?null:e),e.videoWidth&&e.videoHeight&&V(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 / ${B}))`},children:Q(`div`,{class:`frame`,ref:D,style:{aspectRatio:String(B),"--ar":String(B)},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),!oe&&!Ze.current&&j(t.currentTime)},onSeeked:e=>!Ze.current&&j(e.target.currentTime),onPlay:()=>se(!0),onPause:()=>se(!1),onEnded:()=>se(!1)}),Q(`div`,{ref:O,class:`overlay${de?` drawing`:``}`,onPointerDown:Ct,onPointerMove:wt,onPointerUp:Tt,onClick:()=>{ke.current?ke.current=!1:de||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)}),xe&&Q(`div`,{class:`bx`,style:Ot(xe)}),Et&&Q(`div`,{class:`bx`,style:Ot(Et)})]})}),Q(`div`,{class:`tcover`,children:[`f`,me(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":oe?`Pause`:`Play`,onClick:ut,children:Q($,{name:oe?`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:[G(A),Q(`small`,{children:[`/ `,G(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":de,onClick:()=>U(!de),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)}})),H.in!==null&&Q(`div`,{class:`span live`,style:{left:kt(H.in),width:kt((H.out??H.in+.2)-H.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,z);return Q(`div`,{class:`mk ${e.status}${z&&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:G(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:ne,version:t.id,selectedId:Ce,placeholder:It,inputRef:k,toast:i,onAdd:yt,onChanged:a,onTextChange:Ee,formatTag:e=>rr(e,z),cardExtra:z&&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:z&&I?{label:I.label,width:I.width,height:I.height,value:Ie,onChange:ae,lockedReason:xe?tr:null,hint:nr(I.label,Ie,xe!==null)}:void 0,listFooter:e=>{let n=re.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)=>{xe||(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),we(t.id)},attachments:(xe||c)&&Q(S,{children:[xe&&Q(`span`,{class:`chipx`,children:[Q($,{name:`box`}),`Box`,Q(`button`,{"aria-label":`Remove box`,onClick:()=>Se(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=ye(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:[G(e.start).replace(/\.\d+$/,``),`–`,G(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(be).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=Se(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:we[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=Se(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:we.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})}function vc(e,t){let n=[0,1,2].map(n=>Math.max(0,Math.min(e+t,(n+1)/3)-Math.max(e,n/3))*3>=.4);if(n.some(Boolean))return n;let r=Math.min(2,Math.max(0,Math.floor((e+t/2)*3)));return[r===0,r===1,r===2]}var yc=e=>e.map(e=>e?`1`:`0`).join(``),bc={100:`left third`,"010":`centre`,"001":`right third`,110:`left two thirds`,"011":`right two thirds`,111:`full width`,101:`full width`},xc={100:`top third`,"010":`middle`,"001":`bottom third`,110:`top two thirds`,"011":`bottom two thirds`,111:`full height`,101:`full height`};function Sc(e){let t=yc(vc(e.x,e.w)),n=yc(vc(e.y,e.h));return t===`111`&&n===`111`?`the whole picture`:t===`010`&&n===`010`?`the centre`:`${bc[t]}, ${xc[n]}`}function Cc(e){let t=Math.min(2,Math.max(0,Math.floor(e.x*3))),n=Math.min(2,Math.max(0,Math.floor(e.y*3)));return t===1&&n===1?`the centre`:`${[`left`,`centre`,`right`][t]}, ${[`top`,`middle`,`bottom`][n]}`}function wc(e,t,n=8){return Math.min(Math.max(0,e-1),Math.max(0,t-n))}var Tc=e=>Math.round(e*1e4)/1e4,Ec=e=>Tc(Math.max(0,Math.min(1,e))),Dc=.02;function Oc(e,t,n){if(!n)return{pin:{x:Ec(e.x),y:Ec(e.y)}};let[r,i,a,o]=[Ec(e.x),Ec(e.y),Ec(t.x),Ec(t.y)],s={x:Math.min(r,a),y:Math.min(i,o),w:Tc(Math.abs(a-r)),h:Tc(Math.abs(o-i))};return s.w<Dc||s.h<Dc?null:{box:s}}var kc=e=>e.versions[e.versions.length-1];function Ac(e){let t=kc(e);return{page:1,ratio:t.pages[0]?.images[0]?.ratio??``,ver:t.id}}function jc(e,t){let{ver:n,...r}=t;return n===kc(e).id?r:{...r,ver:n,since:kc(e).id}}function Mc(e,t){let{ver:n,since:r,...i}=t??{},a=n!==void 0&&r===kc(e).id;return{...Ac(e),...i,...a?{ver:n}:{}}}var Nc=(e,t)=>t.ver===kc(e).id;function Pc(e,t){return[e.name,e.kind===`carousel`?`page ${t.page}`:null,de(t.ratio),t.ver].filter(Boolean).join(` · `)}var Fc=e=>(e.on??``).slice(0,(e.on??``).lastIndexOf(`/`)),Ic=e=>Number((e.on??``).slice((e.on??``).lastIndexOf(`/`)+1))||0;function Lc(e,t){return e.filter(e=>e.stage===`visuals`&&Fc(e)===Fc(t)).findIndex(e=>e.id===t.id)+1}function Rc(e,t){let n=t.filter(e=>e.stage===`visuals`),r=[...e.map(e=>e.id),...new Set(n.map(Fc).filter(t=>!e.some(e=>e.id===t)))],i=[];for(let t of r){let r=n.filter(e=>Fc(e)===t);if(r.length===0)continue;let a=e.find(e=>e.id===t),o=[...new Set(r.map(Ic))].sort((e,t)=>e-t).map(e=>({page:e,notes:r.filter(t=>Ic(t)===e)}));i.push({visual:{id:t,name:a?.name??t},gone:!a,open:r.filter(e=>e.status===`todo`).length,pages:o})}return i}function zc(e,t,n){return e.filter(e=>e.stage===`visuals`&&Fc(e)===t&&Ic(e)===n.page&&e.format===n.ratio&&e.version===n.ver&&(e.box!==null||e.pin!==null))}function Bc(e,t){let n={};for(let r of e)r.stage===`visuals`&&r.status===`todo`&&Fc(r)===t&&(n[Ic(r)]=(n[Ic(r)]??0)+1);return n}function Vc(e,t,n){return{page:Ic(t),ratio:t.format??n.ratio,ver:t.version??n.ver}}function Hc(e,t,n){return!e||e.text.trim()===``||e.vis===t.vis&&e.page===t.page&&e.ratio===t.ratio&&e.ver===t.ver?null:`Finish or discard your draft on ${n} first.`}var Uc=e=>e instanceof HTMLElement&&(e.isContentEditable||/^(INPUT|TEXTAREA|SELECT)$/.test(e.tagName));function Wc(e){let t=X(null),[n,r]=q(null);return Y(()=>{let n=t.current;if(!n)return;let i=()=>{let t=n.getBoundingClientRect(),i=Math.min(t.width/e.w,t.height/e.h);r(i>0&&Number.isFinite(i)?{w:Math.floor(e.w*i),h:Math.floor(e.h*i)}:null)};i();let a=new ResizeObserver(i);return a.observe(n),()=>a.disconnect()},[e.w,e.h]),{box:t,size:n}}function Gc({notes:e,all:t,selected:n,draft:r}){return Q(S,{children:[e.map(e=>{let r=Lc(t,e),i=`${e.status===`done`?` done`:``}${n===e.id?` sel`:``}`;return e.pin?Q(`div`,{class:`vzpin${i}`,"data-note":e.id,style:{left:`${e.pin.x*100}%`,top:`${e.pin.y*100}%`},children:Q(`span`,{class:`no`,children:r})},e.id):e.box?Q(`div`,{class:`vzbox${i}`,"data-note":e.id,style:{left:`${e.box.x*100}%`,top:`${e.box.y*100}%`,width:`${e.box.w*100}%`,height:`${e.box.h*100}%`},children:Q(`span`,{class:`no`,children:r})},e.id):null}),r&&r.shape&&`pin`in r.shape&&Q(`div`,{class:`vzpin draft`,style:{left:`${r.shape.pin.x*100}%`,top:`${r.shape.pin.y*100}%`},children:Q(`span`,{class:`no`,children:t.filter(e=>e.stage===`visuals`&&Fc(e)===r.vis).length+1})}),r&&r.shape&&`box`in r.shape&&Q(`div`,{class:`vzbox draft`,style:{left:`${r.shape.box.x*100}%`,top:`${r.shape.box.y*100}%`,width:`${r.shape.box.w*100}%`,height:`${r.shape.box.h*100}%`},children:Q(`span`,{class:`no`,children:t.filter(e=>e.stage===`visuals`&&Fc(e)===r.vis).length+1})})]})}function Kc({file:e,alt:t,onBad:n}){return Q(`img`,{src:Nr(e),alt:t,draggable:!1,onError:n})}function qc({visual:e,view:t,badges:n,onPage:r}){let i=e.versions.find(e=>e.id===t.ver)??kc(e),a=X(null);Y(()=>{let e=a.current;if(!e||e.children.length===0)return;let n=e.children[wc(t.page,i.pages.length)];n&&e.scrollTo({left:n.offsetLeft-e.children[0].offsetLeft,behavior:`auto`})},[t.page,i.pages.length]);let o=i.pages[0]?.images.find(e=>e.ratio===t.ratio)??i.pages[0]?.images[0],s=o?62*o.width/o.height:50;return Q(`div`,{class:`vzthumbs`,ref:a,style:{maxWidth:`${8*s+56+4}px`,"--vzth":`${s}px`},children:i.pages.map(e=>{let i=e.images.find(e=>e.ratio===t.ratio)??e.images[0];return Q(`button`,{class:`vzth`,style:{width:`${s}px`},"aria-label":`Page ${e.n}`,"aria-current":e.n===t.page?`true`:void 0,onClick:()=>r(e.n),children:[Q(`img`,{src:Nr(i.file),alt:``,draggable:!1,loading:`lazy`,decoding:`async`}),Q(`span`,{class:`pn`,children:e.n}),n[e.n]?Q(`span`,{class:`badge`,children:n[e.n]}):null]},e.n)})})}function Jc({visual:e,view:t,current:n,notes:r,selected:i,draft:a,verMenu:o,onSetView:s,onVerMenu:c,onFull:l,onPointer:u,onNotePick:d}){let f=e.versions.find(e=>e.id===t.ver)??kc(e),p=f.pages.find(e=>e.n===t.page)??f.pages[0],m=p.images.find(e=>e.ratio===t.ratio)??p.images[0],h=f.pages[0]?.images??[],{box:g,size:_}=Wc({w:m.width,h:m.height}),[v,y]=q(null),b=zc(r,e.id,t),x=a&&a.vis===e.id&&a.page===t.page&&a.ratio===t.ratio&&a.ver===t.ver?a:null,C=!Nc(e,t),w=String(t.page).padStart(2,`0`);return Q(`section`,{class:`vz${n?` cur`:``}`,"data-visual":e.id,"aria-label":e.name,"aria-current":n?`true`:void 0,children:[Q(`div`,{class:`vzhead`,children:[Q(`h2`,{children:e.name}),Q(`span`,{class:`vzkind`,children:[e.kind,e.kind===`carousel`?` · ${f.pages.length} pages`:``]}),e.versions.length>1?Q(`span`,{class:`vzver`,children:[Q(`button`,{class:`vzchip`,"aria-haspopup":`menu`,"aria-expanded":o,onClick:()=>c(!o),children:[t.ver,Q($,{name:`chev`})]}),o&&Q(`div`,{class:`vzvermenu`,role:`menu`,children:[...e.versions].reverse().map(n=>Q(`button`,{role:`menuitem`,"aria-current":n.id===t.ver?`true`:void 0,onClick:()=>{c(!1),s({ver:n.id})},children:[n.id,Q(`span`,{children:n.label||(n.id===kc(e).id?`newest`:`older`)})]},n.id))})]}):Q(`span`,{class:`vzchip static`,children:t.ver}),h.length>1?h.map(e=>Q(`button`,{class:`vzchip`,"aria-pressed":e.ratio===t.ratio,onClick:()=>s({ratio:e.ratio}),children:de(e.ratio)},e.ratio)):Q(`span`,{class:`vzchip static`,children:[m.width,`×`,m.height]}),C&&Q(`span`,{class:`vzbanner`,children:[`Viewing `,t.ver,`, an older version`]})]}),Q(`div`,{class:`vzfwrap`,ref:g,children:Q(`div`,{class:`vzframe`,"data-frame":e.id,role:`img`,"aria-label":`${Pc(e,t)}`,style:_?{width:`${_.w}px`,height:`${_.h}px`}:{visibility:`hidden`},onPointerDown:e=>u(e,e.currentTarget),children:[v===m.file?Q(`div`,{class:`vzbad`,children:[`Can't load page `,t.page,`: `,m.file]}):Q(Kc,{file:m.file,alt:`${e.name}, page ${t.page}`,onBad:()=>y(m.file)},m.file),Q(Gc,{notes:b,all:r,selected:i,draft:x})]})}),Q(`div`,{class:`vzfoot`,children:e.kind===`carousel`?Q(S,{children:[Q(`div`,{class:`vznav`,children:[Q(`button`,{class:`btn vzpill`,"aria-label":`Previous page`,disabled:t.page<=1,onClick:()=>s({page:t.page-1}),children:`Previous`}),Q(`span`,{class:`vzcount`,"aria-label":`Page ${t.page} of ${f.pages.length}`,children:[w,` / `,String(f.pages.length).padStart(2,`0`)]}),Q(`button`,{class:`btn vzpill`,onClick:l,children:`Full screen`}),Q(`button`,{class:`btn vzpill primary`,"aria-label":`Next page`,disabled:t.page>=f.pages.length,onClick:()=>s({page:t.page+1}),children:`Next`})]}),Q(qc,{visual:e,view:t,badges:Bc(r,e.id),onPage:e=>s({page:e})})]}):Q(`div`,{class:`vznav`,children:[Q(`button`,{class:`btn vzpill`,onClick:l,children:`Full screen`}),Q(`span`,{class:`vzhint`,children:[`One page`,h.length>1?` · ${h.length} ratios`:``]})]})})]})}function Yc({visual:e,view:t,notes:n,onPage:r,onClose:i}){let a=e.versions.find(e=>e.id===t.ver)??kc(e),o=a.pages.find(e=>e.n===t.page)??a.pages[0],s=o.images.find(e=>e.ratio===t.ratio)??o.images[0],{box:c,size:l}=Wc({w:s.width,h:s.height}),u=X(null);return J(()=>u.current?.focus(),[]),Q(`div`,{class:`vzfs`,role:`dialog`,"aria-label":`Full screen`,"aria-modal":`true`,tabIndex:-1,ref:u,children:[Q(`div`,{class:`stg`,ref:c,children:Q(`div`,{class:`vzframe`,"data-frame":e.id,style:l?{width:`${l.w}px`,height:`${l.h}px`}:{visibility:`hidden`},children:[Q(Kc,{file:s.file,alt:`${e.name}, page ${t.page}`,onBad:()=>void 0},s.file),Q(Gc,{notes:zc(n,e.id,t),all:n,selected:null,draft:null})]})}),Q(`div`,{class:`bar`,children:[e.kind===`carousel`&&Q(S,{children:[Q(`button`,{class:`btn vzpill`,"aria-label":`Previous page`,disabled:t.page<=1,onClick:()=>r(t.page-1),children:`Previous`}),Q(`span`,{class:`vzcount`,children:[String(t.page).padStart(2,`0`),` / `,String(a.pages.length).padStart(2,`0`)]}),Q(`button`,{class:`btn vzpill primary`,"aria-label":`Next page`,disabled:t.page>=a.pages.length,onClick:()=>r(t.page+1),children:`Next`})]}),Q(`button`,{class:`btn vzpill`,onClick:i,children:`Close`})]})]})}function Xc({state:e,toast:t,onChanged:n,onPendingChange:r}){let i=e.visuals.visuals,a=e.notes.notes,[o,s]=q(i[0]?.id??``),[c,l]=q({}),[u,d]=q(null),[f,p]=q(null),[m,h]=q(null),[g,_]=q(null),v=X(null),y=X(null),b=e=>Mc(e,c[e.id]),x=i.find(e=>e.id===o)??i[0],S=(e,t)=>{l(n=>{let r={...b(e),...t},i=e.versions.find(e=>e.id===r.ver)??kc(e),a=Math.max(1,Math.min(i.pages.length,r.page)),o=i.pages[0]?.images.some(e=>e.ratio===r.ratio)?r.ratio:i.pages[0]?.images[0]?.ratio??r.ratio;return{...n,[e.id]:jc(e,{page:a,ratio:o,ver:i.id})}})};J(()=>{let e=v.current;if(!e)return;let t=new IntersectionObserver(e=>{for(let t of e)t.isIntersecting&&s(t.target.dataset.visual??``)},{root:e,rootMargin:`-50% 0px -50% 0px`,threshold:0});return e.querySelectorAll(`.vz`).forEach(e=>t.observe(e)),()=>t.disconnect()},[i.map(e=>e.id).join(`,`)]);let C=(e,t=!0)=>{let n=v.current?.querySelector(`.vz[data-visual="${e}"]`);n&&v.current.scrollTo({top:n.offsetTop,behavior:t?`smooth`:`instant`})};J(()=>(r(!!u&&u.text.trim()!==``),()=>r(!1)),[u?.text]);let w=(e,n,r)=>{if(e.button!==0)return;if(r.id!==o){C(r.id);return}let a=b(r);if(!Nc(r,a))return t(`You're looking at ${a.ver}. Switch to the newest version to add notes.`);let s=Hc(u,{vis:r.id,...a},u?i.find(e=>e.id===u.vis)?.name??``:``);if(s)return t(s);e.preventDefault();let c=n.getBoundingClientRect(),l=(e,t)=>({x:(e-c.left)/c.width,y:(t-c.top)/c.height}),f=l(e.clientX,e.clientY),[p,m]=[e.clientX,e.clientY],h=!1,g=n.setPointerCapture?(n.setPointerCapture(e.pointerId),!0):!1,_=e=>{Math.hypot(e.clientX-p,e.clientY-m)>5&&(h=!0),h&&d(t=>({vis:r.id,text:t&&t.vis===r.id?t.text:``,...a,shape:Oc(f,l(e.clientX,e.clientY),!0)??{box:{x:f.x,y:f.y,w:0,h:0}}}))},v=u,x=()=>{n.removeEventListener(`pointermove`,_),n.removeEventListener(`pointerup`,S),n.removeEventListener(`pointercancel`,x),g&&n.releasePointerCapture?.(e.pointerId),d(v)},S=t=>{n.removeEventListener(`pointermove`,_),n.removeEventListener(`pointerup`,S),n.removeEventListener(`pointercancel`,x);let i=Oc(f,l(t.clientX,t.clientY),h);if(g&&n.releasePointerCapture?.(e.pointerId),!i)return d(e=>e&&e.text.trim()===``?null:e);d(e=>({vis:r.id,text:e&&e.vis===r.id?e.text:``,...a,shape:i})),queueMicrotask(()=>y.current?.focus())};n.addEventListener(`pointermove`,_),n.addEventListener(`pointerup`,S),n.addEventListener(`pointercancel`,x)},T=u?i.find(e=>e.id===u.vis):null,E=x?{vis:x.id,...b(x)}:null,D=!!(u&&E&&(u.vis!==E.vis||u.page!==E.page||u.ver!==E.ver||(u.shape||u.justThis)&&u.ratio!==E.ratio)),O=!!T&&T.versions.find(e=>e.id===u?.ver)?.pages[0]?.images.length>1,k=()=>{if(!x)return;let e=b(x);if(!Nc(x,e))return t(`You're looking at ${e.ver}. Switch to the newest version to add notes.`);let n=Hc(u,{vis:x.id,...e},u?i.find(e=>e.id===u.vis)?.name??``:``);if(n)return t(n);d({vis:x.id,...e,shape:null,text:u?.text??``}),queueMicrotask(()=>y.current?.focus())},A=X(!1),[j,M]=q(!1),N=async()=>{if(A.current)return;let e=u??(x?{vis:x.id,...b(x),shape:null,text:``}:null);if(!e)return;let r=(y.current?.value??e.text).trim();if(!r)return t(`Write the note first.`),y.current?.focus();if(!Nc(i.find(t=>t.id===e.vis),e))return t(`This note is for ${e.ver}, an older version. Switch to the newest version to add notes.`);let a=e.shape||e.justThis?e.ratio:null;A.current=!0,M(!0);try{let t=await Z.post(`/api/notes`,{stage:`visuals`,scope:`whole`,version:e.ver,on:`${e.vis}/${e.page}`,format:a,text:r,...e.shape&&`box`in e.shape?{box:e.shape.box}:{},...e.shape&&`pin`in e.shape?{pin:e.shape.pin}:{}});d(null),p(t.note.id),n()}catch(e){t((e instanceof kr,e.message))}finally{A.current=!1,M(!1)}},P=async e=>{try{await Z.patch(`/api/notes/${e.id}`,{status:e.status===`done`?`todo`:`done`}),n()}catch(e){t(e.message)}},F=e=>{let t=i.find(t=>t.id===Fc(e));t&&(p(e.id),S(t,Vc(t,e,b(t))),C(t.id),s(t.id),setTimeout(()=>{let t=document.querySelector(`.vz [data-note="${e.id}"]`);t&&(t.classList.remove(`flash`),t.offsetWidth,t.classList.add(`flash`))},350))},I=X(()=>void 0);if(J(()=>{let e=e=>I.current(e);return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[]),I.current=e=>{if(e.metaKey||e.ctrlKey||e.altKey||!x)return;if(m){let t=i.find(e=>e.id===m);if(!t)return;e.key===`Escape`?h(null):t.kind===`carousel`&&(e.key===`ArrowRight`||e.key===`ArrowLeft`)&&(e.preventDefault(),S(t,{page:b(t).page+(e.key===`ArrowRight`?1:-1)}));return}if(Uc(e.target))return;let t=b(x),n=i.findIndex(e=>e.id===x.id);if(e.key===`ArrowRight`&&x.kind===`carousel`)e.preventDefault(),S(x,{page:t.page+1});else if(e.key===`ArrowLeft`&&x.kind===`carousel`)e.preventDefault(),S(x,{page:t.page-1});else if(e.key===`ArrowDown`&&n<i.length-1)e.preventDefault(),C(i[n+1].id);else if(e.key===`ArrowUp`&&n>0)e.preventDefault(),C(i[n-1].id);else if(e.key===`r`||e.key===`R`){let e=Zc(x,t);e.length>1&&S(x,{ratio:e[(e.indexOf(t.ratio)+1)%e.length]})}else e.key===`n`||e.key===`N`?(e.preventDefault(),y.current?.focus()):e.key===`Escape`&&d(null)},J(()=>{if(!g)return;let e=e=>{e.target.closest(`.vzver`)||_(null)};return document.addEventListener(`click`,e),()=>document.removeEventListener(`click`,e)},[g]),!x)return null;let L=Rc(i,a),R=a.filter(e=>e.stage===`visuals`&&e.status===`todo`).length,ee=new Set(a.filter(e=>e.stage===`visuals`&&e.status===`todo`).map(Fc)).size,z=m?i.find(e=>e.id===m):null;return Q(`div`,{class:`vzsplit`,children:[Q(`div`,{class:`vzscroll`,ref:v,children:i.map(e=>Q(Jc,{visual:e,view:b(e),current:e.id===o,notes:a,selected:f,draft:u,verMenu:g===e.id,onSetView:t=>S(e,t),onVerMenu:t=>_(t?e.id:null),onFull:()=>h(e.id),onPointer:(t,n)=>w(t,n,e),onNotePick:e=>p(e)},e.id))}),Q(`aside`,{class:`vznotes`,"aria-label":`Visual notes`,children:[Q(`div`,{class:`vznhead`,children:[Q(`h3`,{children:`Notes`}),Q(`span`,{children:[R,` open across `,ee,` visual`,ee===1?``:`s`]})]}),Q(`div`,{class:`vznlist`,children:[L.length===0&&Q(`div`,{class:`vzempty`,children:`No notes yet.`}),L.map(e=>Q(`div`,{class:`vzgrp${e.visual.id===o?` cur`:``}`,"data-grp":e.visual.id,children:[Q(`button`,{class:`vzghead`,onClick:()=>!e.gone&&C(e.visual.id),children:[e.visual.name,e.visual.id===o&&Q(`span`,{class:`here`,children:`looking at`}),Q(`span`,{class:`cnt`,children:[e.open,` open`]})]}),Q(`div`,{class:`vzpg`,children:e.pages.map(t=>Q(`div`,{children:[Q(`div`,{class:`vzpgh`,children:i.find(t=>t.id===e.visual.id)?.kind===`carousel`?`Page ${t.page}`:`Page 1`}),t.notes.map(t=>{let n=i.find(t=>t.id===e.visual.id),r=n&&t.version&&t.version!==kc(n).id;return Q(`div`,{class:`vznote${t.status===`done`?` done`:``}${f===t.id?` sel`:``}`,"data-note":t.id,role:`button`,tabIndex:0,onClick:()=>F(t),onKeyDown:e=>e.key===`Enter`&&F(t),children:[Q(`span`,{class:`no2`,children:Lc(a,t)}),Q(`div`,{class:`txt`,children:[Q(`span`,{class:`t`,children:t.text}),Q(`span`,{class:`tags`,children:[Q(`span`,{class:`tag`,children:t.format?de(t.format):`all ratios`}),Q(`span`,{class:`tag${r?` old`:``}`,children:r?`from ${t.version}`:t.version}),Q(`span`,{class:`tag`,title:t.box?Sc(t.box):t.pin?Cc(t.pin):void 0,children:t.box?`region`:t.pin?`point`:`whole image`})]}),t.reply&&Q(`div`,{class:`vzreply`,children:[Q(`b`,{children:`Agent`}),` `,t.reply,t.fixVersion&&n&&Q(`button`,{class:`vzlink`,onClick:e=>{e.stopPropagation(),p(t.id),S(n,{...Vc(n,t,b(n)),ver:t.fixVersion}),C(n.id)},children:[`Show in `,t.fixVersion]})]})]}),Q(`button`,{class:`vztick`,"aria-label":t.status===`done`?`Reopen`:`Mark done`,"data-tip":t.status===`done`?`Reopen`:`Mark done`,onClick:e=>{e.stopPropagation(),P(t)},children:Q($,{name:t.status===`done`?`check`:`circle`})})]},t.id)})]},t.page))})]},e.visual.id))]}),Q(`div`,{class:`vzcomposer`,children:[Q(`div`,{class:`vztarget${D?` away`:``}`,children:[Q(`span`,{class:`lbl`,children:D?`Draft for`:`Adding to`}),Q(`b`,{children:D&&T?Pc(T,u):Pc(x,b(x))}),D&&Q(`button`,{class:`btn`,onClick:()=>C(u.vis),children:`Go to it`})]}),Q(`textarea`,{ref:y,"aria-label":`Note text`,placeholder:u?u.shape?`${u.shape&&`pin`in u.shape?`A point`:`A region`} is marked. Write what to change.`:`No region: this note is for the whole image.`:`Drag on the picture to mark a region, click for a point, or add a whole-image note.`,value:u?.text??``,onInput:e=>{let t=e.currentTarget.value;d(e=>e?{...e,text:t}:x?{vis:x.id,...b(x),shape:null,text:t}:e)},onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&!e.isComposing&&(e.preventDefault(),e.currentTarget.value.trim()&&N()),e.key===`Escape`&&(e.stopPropagation(),d(null),e.currentTarget.blur())}}),u&&!u.shape&&O&&Q(`label`,{class:`vzjust`,children:[Q(`input`,{type:`checkbox`,checked:!!u.justThis,onChange:e=>d({...u,justThis:e.currentTarget.checked})}),`Just `,de(u.ratio)]}),Q(`div`,{class:`vzcrow`,children:[Q(`button`,{class:`btn primary`,disabled:j,onClick:()=>void N(),children:`Add note`}),Q(`button`,{class:`btn`,onClick:k,children:`Whole image`}),Q(`button`,{class:`btn ghost`,disabled:!u,onClick:()=>d(null),children:u?.text?`Discard draft`:`Cancel`})]})]})]}),z&&Q(Yc,{visual:z,view:b(z),notes:a,onPage:e=>S(z,{page:e}),onClose:()=>h(null)})]})}function Zc(e,t){return(e.versions.find(e=>e.id===t.ver)??kc(e)).pages[0]?.images.map(e=>e.ratio)??[]}var Qc=[[`all`,`All`],[`picture`,Gi.picture],[`voice`,Gi.voice],[`music`,Gi.music],[`sfx`,Gi.sfx],[`mix`,Gi.mix],[`visuals`,Gi.visuals],[`notes`,Gi.notes],[`assets`,Gi.assets]];function $c(e){return Qc.some(([t])=>t===e)}var el={user:`added by you`,agent:`agent`,rushes:`Rushes`};function tl(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 nl(e,t){return e===`all`||e===t}var rl=new Set([` `,`ArrowLeft`,`ArrowRight`,`ArrowUp`,`ArrowDown`,`Home`,`End`,`PageUp`,`PageDown`]);function il(e){return rl.has(e.key)&&!e.altKey&&!e.ctrlKey&&!e.metaKey}var al=[`script`,`picture`,`voice`,`music`,`sfx`,`mix`];function ol(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&&al.includes(e.tab)?{tab:e.tab}:e.area===`assets`?{tab:`assets`}:al.includes(e.area)?{tab:e.area}:null}function sl(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 cl(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 ll(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 ul(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 dl(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 fl(e,t){return`rushes:${e}:${t}`}function pl(e,t){try{return e?.getItem(t)??null}catch{return null}}function ml(e,t,n){try{e?.setItem(t,n)}catch{}}var hl=1e3,gl=40,_l=()=>{try{return window.sessionStorage}catch{return}},vl=()=>{try{return window.localStorage}catch{return}};function yl(e,t){let[n,r]=q(()=>pl(_l(),fl(e,`log-open`))===`1`),[i,a]=q(!1),[o,s]=q(()=>pl(vl(),fl(e,`log-seen`))),c=t?.mark??null,l=X(o);l.current=o;let u=t=>{s(t),ml(vl(),fl(e,`log-seen`),t)};return J(()=>{n&&c&&dl(c,o)&&u(c)},[n,c]),J(()=>{let t=fl(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&&dl(c,o),setOpen:t=>{r(t),a(t),ml(_l(),fl(e,`log-open`),t?`1`:`0`)},saw:e=>{dl(e,l.current)&&u(e)}}}function bl(){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 xl({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(bl,{}),Q(`span`,{class:`clabel`,children:`Change Log`}),e.dot&&Q(`span`,{class:`cdot`,"aria-hidden":`true`})]})}function Sl(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 Cl(e){return e.log.open?Q(Tl,{...e}):null}function wl({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:el[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":ll(e,r),onClick:()=>n(t),children:i}):Q(`div`,{class:`lrow`,"data-entry":e.id,children:i})}function Tl({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=pl(_l(),fl(t,`log-filter`));return $c(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)>gl,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(hl)});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(ul(`read`,e)):m(ul(`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(``),!nl(h,i)){let e=Gi[i];s(`Added under ${e}. Choose All${Qc.some(([e])=>e===i)?` or ${e}`:``} to see it.`)}b.current&&(b.current.scrollTop=0),await O(!0)}catch(e){s(ul(`add`,e))}},M=e=>{g(e),ml(_l(),fl(t,`log-filter`),e)},N=(e,t)=>{let n=sa(e.key,t,Qc.length,!0);if(n===null)return;e.preventDefault();let r=Qc[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 R=X(e=>L.current(e)).current,ee=async()=>{try{s(`Saved to ${(await Z.post(`/api/exports/change-log`,{})).path}`)}catch(e){s(ul(`export`,e))}},z=yr(()=>l?tl(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(wl,{entry:e,to:ol(e,r),onGo:R})},e.id))})]},e.key)):null,[l,r,Qi(new Date)]),te=l&&d?sl(l.entries,d.entries):0,ne=l!==null&&l.total===0&&l.undated.length===0,re=l!==null&&!ne&&l.entries.length===0&&l.undated.length===0;return Q(`aside`,{id:`changelog`,class:`drawer`,ref:y,"aria-label":`Change Log`,onKeyDown:e=>{il(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:Qc.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:[te>0&&Q(`button`,{type:`button`,class:`dpill`,onClick:P,children:[te,` 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}),ne&&Q(`p`,{class:`dempty`,children:`Nothing yet. Rushes writes a line here whenever a cut, a take or a variant is added.`}),re&&Q(`p`,{class:`dempty`,children:`Nothing for this filter.`}),z,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?cl(l):``}),Q(`button`,{type:`button`,class:`btn`,onClick:()=>void ee(),children:`Export as Markdown`})]})]})}var El=[`script`,`picture`,`voice`,`music`,`sfx`,`mix`,`visuals`],Dl=e=>e instanceof HTMLElement&&(e.isContentEditable||/^(INPUT|TEXTAREA|SELECT)$/.test(e.tagName));function Ol({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:Te[e],l=e===`assets`?`Assets`:e===`brief`?`Brief`:e===`storyboard`?`Storyboard`:we[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 kl(){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,R]=q({}),ee=(e,t)=>R(n=>({...n,[e]:t})),[z,te]=q({}),[ne,re]=q({}),[ie,ae]=q(!1),B=X(new Set),V=(e,t=2400)=>{m(e),clearTimeout(N.current),N.current=window.setTimeout(()=>m(null),t)},[oe,se]=q({n:0,pending:!1}),[ce,le]=q(null),H=yl(Ar()??``,e?.log),ue=X(null);J(()=>{for(let e of Object.values(a))e.state!==`failed`||B.current.has(e.job)||(B.current.add(e.job),V(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 U=e?.project.videos.find(e=>e.id===l)??e?.project.videos[0],W=xe(U),pe=Se(U),G=U?.versions.find(e=>e.id===d)??pe,me=!!U?.lockedVersion,ge=G?.fps??e?.project.fps??30,_e=G?t.find(e=>e.kind===`cut`&&e.path===G.file):void 0,ve=e?.notes.notes.filter(e=>e.stage===`picture`&&(!e.video||e.video===U?.id))??[],ye=G?fe(G,ne[G.file]):[],be=U&&G?Un(U,G.id):void 0,Ee=Wn(ye,U?z[U.id]:void 0),De=new Set(t.filter(e=>e.kind===`cut`&&e.missing).map(e=>e.path)),Oe=G?Gn({views:ye,previous:be?fe(be):[],current:Ee,versionDuration:G.duration,notes:ve,missing:De}):[],ke=e=>!U||e===Ee?!1:ie?(V(`Add or clear your box on ${Ee?de(Ee):`this format`} first`),!1):(te(t=>({...t,[U.id]:e})),!0);J(()=>{T&&d===null&&pe?(f(pe.id),O(!0)):!T&&D&&d===pe?.id&&(f(null),O(!1))},[T,d,pe?.id]),J(()=>{!D&&d!==null&&d===pe?.id&&f(null)},[pe?.id,D,d]);let Pe=W&&G&&W.id!==G.id&&(me||D)?W.id:null,Fe=()=>{W&&f(W.id),O(!1)},ze=e=>{if(!U||e===U.id)return;if(T)return V(`Add or clear your note on ${U.name} first`);let t=F.current;t?.pause();let n=t?he(t.currentTime,ge):P.current.get(U.id)?.t??0;P.current.set(U.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(U&&G)try{await Z.put(`/api/videos/${U.id}/lock`,{version:U.lockedVersion?null:G.id}),i()}catch(e){V(e.message)}},Ue=t=>{if(T)return V(`Add or clear your note first`);if(t.tab===`assets`)return Xe();if(t.video&&t.video!==U?.id&&ze(t.video),t.version){let n=e?.project.videos.find(e=>e.id===(t.video??U?.id));f(t.version===Se(n)?.id?null:t.version),O(!1)}c(t.tab),g(null),t.row&&Sl(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 V(`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 V(`Add or clear your note first`);c(`assets`),g(null)},Ze=e=>{if(T&&s!==`assets`)return V(`Add or clear your note first`);se(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`||Dl(t.target))return;t.preventDefault();let e=Kn(Oe,Ee,t.key===`ArrowRight`?1:-1);e&&ke(e);return}if(Dl(t.target)||t.metaKey||t.ctrlKey||t.altKey)return;let n=Number(t.key);if(n===1?Ye():n>=2&&n<=7?Je(El[n-1]):n===8&&Xe(),(t.key===`[`||t.key===`]`)&&e){let n=Ce(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 V(`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,U?.name??null,t)}),w(!1);return}if(s===`storyboard`){if(!e)return;if(!e.storyboard.exists)return V(`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,U?.name??null,t)}),w(!1);return}try{let{batch:e}=await Z.post(`/api/batches`,{stage:s});g(e),w(!1),i()}catch(e){V(e instanceof kr&&e.code===`empty_batch`?`Nothing open on ${we[s]} to send`:e.message)}}},at=async()=>{if(h)try{await navigator.clipboard.writeText(h.prompt),w(!0)}catch{V(`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===U?.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:Te.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,U?.name??null)),V(`Prompt copied`)}catch{V(`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}),U&&e.project.videos.length===1&&Q(S,{children:[Q(`span`,{class:`slash`,children:`/`}),Q(`span`,{class:`sel`,children:U.name})]})]}),Ke!==null&&An(e.found)!==ce&&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})]}),U&&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===U.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`})]}))}),U&&Q(S,{children:[Q(`span`,{class:`plabel`,children:`Picture`}),G&&Q(Bs,{versions:U.versions,shown:G,lockedVersion:U.lockedVersion,onPick:e=>{f(e===pe?.id?null:e),O(!1)}}),G&&Q(`button`,{class:`btn ib lockbtn`,"aria-pressed":me,"aria-label":me?`Picture locked at ${U.lockedVersion} · unlock`:`Lock picture at ${G.id}`,"data-tip":me?`Picture locked at ${U.lockedVersion} · unlock`:`Lock picture at ${G.id}`,onClick:()=>void He(),children:Q($,{name:me?`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`&&G&&Oe.length>0&&Q(ro,{chips:Oe,versionId:G.id,prompt:Xn(e.project.name,U.name,G.id),onSelect:ke,toast:V})]}),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(xl,{log:H,buttonRef:ue}),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(Cl,{log:H,projectId:Ar()??``,head:e.log,project:e.project,stage:s===`brief`||s===`storyboard`?`script`:s,header:et,buttonRef:ue,toast:V,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)}),El.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 ${Te[e].ask}`,onClick:()=>Je(e),children:[Q($,{name:da[e]}),we[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 ${Te.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:oe,onFoundRequestUsed:()=>se(e=>e.pending?{n:e.n,pending:!1}:e),onFoundSeen:le,toast:V,onChanged:()=>void i()}):Q(Ol,{tab:`assets`,projectName:e.project.name,filmName:U?.name??null,found:e.found?.counts,onReview:Ze,toast:V}):ct?s===`picture`&&U&&G?Q(Ws,{video:U,version:G,fps:ge,notes:ot,toast:V,onChanged:()=>void i(),onPendingChange:E,startAt:k,grab:j[U.id]??null,onGrabChange:I,playerRef:F,ffmpeg:e.proxies?.ffmpeg??!1,autoProxy:e.project.autoProxy,proxyJob:a[gn(U.id,G.id)],noteProxyJob:o,source:L[U.id]??`proxy`,onSourceChange:ee,fileSize:_e?.size??null,fileRev:_e?qr(_e):void 0,formats:ye,format:Ee,formatMissing:!!Ee&&De.has(ye.find(e=>e.id===Ee)?.file??``),onPrimarySize:(e,t,n)=>re(r=>r[e]?r:{...r,[e]:{width:t,height:n}}),onBoxPendingChange:ae,onFormatChange:ke},U.id):s===`brief`?Q(to,{brief:e.brief,toast:V,onChanged:()=>void i(),settle:y}):s===`storyboard`?Q(Qs,{board:e.storyboard,brief:e.brief,toast:V,onChanged:()=>void i(),settle:y}):s===`visuals`?Q(Xc,{state:e,toast:V,onChanged:()=>void i(),onPendingChange:E}):s===`script`?Q(ic,{script:e.script,toast:V,onChanged:()=>void i()}):s===`voice`?Q(_c,{state:e,assets:t,video:U??null,toast:V,onChanged:()=>void i(),onPendingChange:E},`voice`):s===`mix`?Q(cs,{state:e,assets:t,video:U??null,toast:V,onChanged:()=>void i(),onPendingChange:E},`mix`):s===`music`||s===`sfx`?Q(lc,{stage:s,state:e,assets:t,video:U??null,toast:V,onChanged:()=>void i(),onPendingChange:E},s):null:Q(Ol,{tab:s,projectName:e.project.name,filmName:U?.name??null,found:e.found?.counts,onReview:Ze,toast:V})})]})}Ft(document),ie(Q(kl,{}),document.getElementById(`app`));
@@ -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-BQtnzsUj.js"></script>
8
+ <script type="module" crossorigin src="/assets/index-MCrz9CYM.js"></script>
9
9
  <link rel="stylesheet" crossorigin href="/assets/index-V7YEFWgg.css">
10
10
  </head>
11
11
  <body>