rushes 0.7.3 → 0.8.1
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.
- package/.claude-plugin/plugin.json +1 -1
- package/AGENTS.md +2 -2
- package/README.md +1 -1
- package/dist/core/logEvents.js +11 -1
- package/dist/core/project.js +27 -4
- package/dist/core/schema.js +19 -6
- package/dist/mcp/tools.js +12 -3
- package/dist/server/app.js +28 -10
- package/package.json +1 -1
- package/skills/rushes/SKILL.md +2 -2
- package/web-dist/assets/index-DhS2fPd_.js +11 -0
- package/web-dist/assets/{index-D0PeJ_Di.css → index-jf-RHBPN.css} +1 -1
- package/web-dist/index.html +2 -2
- package/web-dist/assets/index-CaOchMcJ.js +0 -11
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
(function(){let e=document.createElement(`link`).relList;if(e&&e.supports&&e.supports(`modulepreload`))return;for(let e of document.querySelectorAll(`link[rel="modulepreload"]`))n(e);new MutationObserver(e=>{for(let t of e)if(t.type===`childList`)for(let e of t.addedNodes)e.tagName===`LINK`&&e.rel===`modulepreload`&&n(e)}).observe(document,{childList:!0,subtree:!0});function t(e){let t={};return e.integrity&&(t.integrity=e.integrity),e.referrerPolicy&&(t.referrerPolicy=e.referrerPolicy),t.credentials=e.crossOrigin===`use-credentials`?`include`:e.crossOrigin===`anonymous`?`omit`:`same-origin`,t}function n(e){if(e.ep)return;e.ep=!0;let n=t(e);fetch(e.href,n)}})();var e,t,n,r,i,a,o,s,c,l,u,d,f,p,m={},h=[],g=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i,_=Array.isArray;function v(e,t){for(var n in t)e[n]=t[n];return e}function y(e){e&&e.parentNode&&e.parentNode.removeChild(e)}function b(t,n,r){var i,a,o,s={};for(o in n)o==`key`?i=n[o]:o==`ref`?a=n[o]:s[o]=n[o];if(arguments.length>2&&(s.children=arguments.length>3?e.call(arguments,2):r),typeof t==`function`&&t.defaultProps!=null)for(o in t.defaultProps)s[o]===void 0&&(s[o]=t.defaultProps[o]);return x(t,s,i,a,null)}function x(e,r,i,a,o){var s={type:e,props:r,key:i,ref:a,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:o??++n,__i:-1,__u:0};return o==null&&t.vnode!=null&&t.vnode(s),s}function S(e){return e.children}function C(e,t){this.props=e,this.context=t}function w(e,t){if(t==null)return e.__?w(e.__,e.__i+1):null;for(var n;t<e.__k.length;t++)if((n=e.__k[t])!=null&&n.__e!=null)return n.__e;return typeof e.type==`function`?w(e):null}function T(e){if(e.__P&&e.__d){var n=e.__v,r=n.__e,i=[],a=[],o=v({},n);o.__v=n.__v+1,t.vnode&&t.vnode(o),ee(e.__P,o,n,e.__n,e.__P.namespaceURI,32&n.__u?[r]:null,i,r??w(n),!!(32&n.__u),a),o.__v=n.__v,o.__.__k[o.__i]=o,L(i,o,a),n.__e=n.__=null,o.__e!=r&&E(o)}}function E(e){if((e=e.__)!=null&&e.__c!=null)return e.__e=e.__c.base=null,e.__k.some(function(t){if(t!=null&&t.__e!=null)return e.__e=e.__c.base=t.__e}),E(e)}function D(e){(!e.__d&&(e.__d=!0)&&r.push(e)&&!O.__r++||i!=t.debounceRendering)&&((i=t.debounceRendering)||a)(O)}function O(){try{for(var e,t=1;r.length;)r.length>t&&r.sort(o),e=r.shift(),t=r.length,T(e)}finally{r.length=O.__r=0}}function k(e,t,n,r,i,a,o,s,c,l,u){var d,f,p,g,_,v,y=r&&r.__k||h,b=t.length;for(c=A(n,t,y,c,b),d=0;d<b;d++)(p=n.__k[d])!=null&&(f=p.__i!=-1&&y[p.__i]||m,p.__i=d,v=ee(e,p,f,i,a,o,s,c,l,u),g=p.__e,p.ref&&f.ref!=p.ref&&(f.ref&&R(f.ref,null,p),u.push(p.ref,p.__c||g,p)),_==null&&g!=null&&(_=g),4&p.__u?(c=j(p,c,e),f.__e&&(f.__e=null)):typeof p.type==`function`&&v!==void 0?c=v:g&&(c=g.nextSibling),p.__u&=-7);return n.__e=_,c}function A(e,t,n,r,i){var a,o,s,c,l,u=n.length,d=u,f=0;for(e.__k=Array(i),a=0;a<i;a++)(o=t[a])!=null&&typeof o!=`boolean`&&typeof o!=`function`?(typeof o==`string`||typeof o==`number`||typeof o==`bigint`||o.constructor==String?o=e.__k[a]=x(null,o,null,null,null):_(o)?o=e.__k[a]=x(S,{children:o},null,null,null):o.constructor===void 0&&o.__b>0?o=e.__k[a]=x(o.type,o.props,o.key,o.ref?o.ref:null,o.__v):e.__k[a]=o,c=a+f,o.__=e,o.__b=e.__b+1,s=null,(l=o.__i=M(o,n,c,d))!=-1&&(d--,(s=n[l])&&(s.__u|=2)),s==null||s.__v==null?(l==-1&&(i>u?f--:i<u&&f++),typeof o.type!=`function`&&(o.__u|=4)):l!=c&&(l==c-1?f--:l==c+1?f++:(l>c?f--:f++,o.__u|=4))):e.__k[a]=null;if(d)for(a=0;a<u;a++)(s=n[a])!=null&&!(2&s.__u)&&(s.__e==r&&(r=w(s)),re(s,s));return r}function j(e,t,n){var r,i;if(typeof e.type==`function`){for(r=e.__k,i=0;r&&i<r.length;i++)r[i]&&(r[i].__=e,t=j(r[i],t,n));return t}e.__e!=t&&(t&&e.type&&!t.parentNode&&(t=w(e)),t=n.insertBefore(e.__e,t||null));do t&&=t.nextSibling;while(t!=null&&t.nodeType==8);return t}function M(e,t,n,r){var i,a,o,s=e.key,c=e.type,l=t[n],u=l!=null&&!(2&l.__u);if(l===null&&s==null||u&&s==l.key&&c==l.type)return n;if(r>+!!u){for(i=n-1,a=n+1;i>=0||a<t.length;)if((l=t[o=i>=0?i--:a++])!=null&&!(2&l.__u)&&s==l.key&&c==l.type)return o}return-1}function N(e,t,n){t[0]==`-`?e.setProperty(t,n??``):e[t]=n==null?``:typeof n!=`number`||g.test(t)?n:n+`px`}function P(e,t,n,r,i){var a,o;n:if(t==`style`){if(typeof n==`string`)e.style.cssText=n;else{if(typeof r==`string`&&(e.style.cssText=r=``),r)for(t in r)n&&t in n||N(e.style,t,``);if(n)for(t in n)r&&n[t]==r[t]||N(e.style,t,n[t])}}else if(t[0]==`o`&&t[1]==`n`)a=t!=(t=t.replace(u,`$1`)),o=t.toLowerCase(),t=o in e||t==`onFocusOut`||t==`onFocusIn`?o.slice(2):t.slice(2),e.l||={},e.l[t+a]=n,n?r?n[l]=r[l]:(n[l]=d,e.addEventListener(t,a?p:f,a)):e.removeEventListener(t,a?p:f,a);else{if(i==`http://www.w3.org/2000/svg`)t=t.replace(/xlink(H|:h)/,`h`).replace(/sName$/,`s`);else if(t!=`width`&&t!=`height`&&t!=`href`&&t!=`list`&&t!=`form`&&t!=`tabIndex`&&t!=`download`&&t!=`rowSpan`&&t!=`colSpan`&&t!=`role`&&t!=`popover`&&t in e)try{e[t]=n??``;break n}catch{}typeof n==`function`||(n==null||!1===n&&t[4]!=`-`?e.removeAttribute(t):e.setAttribute(t,t==`popover`&&n==1?``:n))}}function F(e){return function(n){if(this.l){var r=this.l[n.type+e];if(n[c]==null)n[c]=d++;else if(n[c]<r[l])return;return r(t.event?t.event(n):n)}}}function ee(e,n,r,i,a,o,s,c,l,u){var d,f,p,m,g,b,x,T,E,D,O,A,j,M,N,P,F=n.type;if(n.constructor!==void 0)return null;128&r.__u&&(l=!!(32&r.__u),o=[c=n.__e=r.__e]),(d=t.__b)&&d(n);n:if(typeof F==`function`){f=s.length;try{if(E=n.props,D=F.prototype&&F.prototype.render,O=(d=F.contextType)&&i[d.__c],A=d?O?O.props.value:d.__:i,r.__c?T=(p=n.__c=r.__c).__=p.__E:(D?n.__c=p=new F(E,A):(n.__c=p=new C(E,A),p.constructor=F,p.render=ie),O&&O.sub(p),p.state||(p.state={}),p.__n=i,m=p.__d=!0,p.__h=[],p._sb=[]),D&&p.__s==null&&(p.__s=p.state),D&&F.getDerivedStateFromProps!=null&&(p.__s==p.state&&(p.__s=v({},p.__s)),v(p.__s,F.getDerivedStateFromProps(E,p.__s))),g=p.props,b=p.state,p.__v=n,m)D&&F.getDerivedStateFromProps==null&&p.componentWillMount!=null&&p.componentWillMount(),D&&p.componentDidMount!=null&&p.__h.push(p.componentDidMount);else{if(D&&F.getDerivedStateFromProps==null&&E!==g&&p.componentWillReceiveProps!=null&&p.componentWillReceiveProps(E,A),n.__v==r.__v||!p.__e&&p.shouldComponentUpdate!=null&&!1===p.shouldComponentUpdate(E,p.__s,A)){n.__v!=r.__v&&(p.props=E,p.state=p.__s,p.__d=!1),n.__e=r.__e,n.__k=r.__k,n.__k.some(function(e){e&&(e.__=n)}),h.push.apply(p.__h,p._sb),p._sb=[],p.__h.length&&s.push(p),c=w(r);break n}p.componentWillUpdate!=null&&p.componentWillUpdate(E,p.__s,A),D&&p.componentDidUpdate!=null&&p.__h.push(function(){p.componentDidUpdate(g,b,x)})}if(p.context=A,p.props=E,p.__P=e,p.__e=!1,j=t.__r,M=0,D)p.state=p.__s,p.__d=!1,j&&j(n),d=p.render(p.props,p.state,p.context),h.push.apply(p.__h,p._sb),p._sb=[];else do p.__d=!1,j&&j(n),d=p.render(p.props,p.state,p.context),p.state=p.__s;while(p.__d&&++M<25);p.state=p.__s,p.getChildContext!=null&&(i=v(v({},i),p.getChildContext())),D&&!m&&p.getSnapshotBeforeUpdate!=null&&(x=p.getSnapshotBeforeUpdate(g,b)),N=d!=null&&d.type===S&&d.key==null?te(d.props.children):d,c=k(e,_(N)?N:[N],n,r,i,a,o,s,c,l,u),p.base=n.__e,n.__u&=-161,p.__h.length&&s.push(p),T&&(p.__E=p.__=null)}catch(e){if(s.length=f,n.__v=null,l||o!=null){if(e.then){for(n.__u|=l?160:128;c&&c.nodeType==8&&c.nextSibling;)c=c.nextSibling;o!=null&&(o[o.indexOf(c)]=null),n.__e=c}else if(o!=null)for(P=o.length;P--;)y(o[P])}else n.__e=r.__e;n.__k??=r.__k||[],e.then||I(n),t.__e(e,n,r)}}else o==null&&n.__v==r.__v?(n.__k=r.__k,n.__e=r.__e):c=n.__e=ne(r.__e,n,r,i,a,o,s,l,u);return(d=t.diffed)&&d(n),128&n.__u?void 0:c}function I(e){e&&(e.__c&&(e.__c.__e=!0),e.__k&&e.__k.some(I))}function L(e,n,r){for(var i=0;i<r.length;i++)R(r[i],r[++i],r[++i]);t.__c&&t.__c(n,e),e.some(function(n){try{e=n.__h,n.__h=[],e.some(function(e){e.call(n)})}catch(e){t.__e(e,n.__v)}})}function te(e){return typeof e!=`object`||!e||e.__b>0?e:_(e)?e.map(te):e.constructor===void 0?v({},e):null}function ne(n,r,i,a,o,s,c,l,u){var d,f,p,h,g,v,b,x=i.props||m,S=r.props,C=r.type;if(C==`svg`?o=`http://www.w3.org/2000/svg`:C==`math`?o=`http://www.w3.org/1998/Math/MathML`:o||=`http://www.w3.org/1999/xhtml`,s!=null){for(d=0;d<s.length;d++)if((g=s[d])&&`setAttribute`in g==!!C&&(C?g.localName==C:g.nodeType==3)){n=g,s[d]=null;break}}if(n==null){if(C==null)return document.createTextNode(S);n=document.createElementNS(o,C,S.is&&S),l&&=(t.__m&&t.__m(r,s),!1),s=null}if(C==null)x===S||l&&n.data==S||(n.data=S);else{if(s=C==`textarea`&&S.defaultValue!=null?null:s&&e.call(n.childNodes),!l&&s!=null)for(x={},d=0;d<n.attributes.length;d++)x[(g=n.attributes[d]).name]=g.value;for(d in x)g=x[d],d==`dangerouslySetInnerHTML`?p=g:d==`children`||d in S||d==`value`&&`defaultValue`in S||d==`checked`&&`defaultChecked`in S||P(n,d,null,g,o);for(d in S)g=S[d],d==`children`?h=g:d==`dangerouslySetInnerHTML`?f=g:d==`value`?v=g:d==`checked`?b=g:l&&typeof g!=`function`||x[d]===g||P(n,d,g,x[d],o);if(f)l||p&&(f.__html==p.__html||f.__html==n.innerHTML)||(n.innerHTML=f.__html),r.__k=[];else if(p&&(n.innerHTML=``),k(r.type==`template`?n.content:n,_(h)?h:[h],r,i,a,C==`foreignObject`?`http://www.w3.org/1999/xhtml`:o,s,c,s?s[0]:i.__k&&w(i,0),l,u),s!=null)for(d=s.length;d--;)y(s[d]);l&&C!=`textarea`||(d=`value`,C==`progress`&&v==null?n.removeAttribute(`value`):v!=null&&(v!==n[d]||C==`progress`&&!v||C==`option`&&v!=x[d])&&P(n,d,v,x[d],o),d=`checked`,b!=null&&b!=n[d]&&P(n,d,b,x[d],o))}return n}function R(e,n,r){try{if(typeof e==`function`){var i=typeof e.__u==`function`;i&&e.__u(),i&&n==null||(e.__u=e(n))}else e.current=n}catch(e){t.__e(e,r)}}function re(e,n,r){var i,a;if(t.unmount&&t.unmount(e),(i=e.ref)&&(i.current&&i.current!=e.__e||R(i,null,n)),(i=e.__c)!=null){if(i.componentWillUnmount)try{i.componentWillUnmount()}catch(e){t.__e(e,n)}i.base=i.__P=i.__n=null}if(i=e.__k)for(a=0;a<i.length;a++)i[a]&&re(i[a],n,r||typeof e.type!=`function`);r||y(e.__e),e.__c=e.__=e.__e=void 0}function ie(e,t,n){return this.constructor(e,n)}function ae(n,r,i){var a,o,s,c;r==document&&(r=document.documentElement),t.__&&t.__(n,r),o=(a=typeof i==`function`)?null:i&&i.__k||r.__k,s=[],c=[],ee(r,n=(!a&&i||r).__k=b(S,null,[n]),o||m,m,r.namespaceURI,!a&&i?[i]:o?null:r.firstChild?e.call(r.childNodes):null,s,!a&&i?i:o?o.__e:r.firstChild,a,c),L(s,n,c),n.props.children=null}e=h.slice,t={__e:function(e,t,n,r){for(var i,a,o;t=t.__;)if((i=t.__c)&&!i.__)try{if((a=i.constructor)&&a.getDerivedStateFromError!=null&&(i.setState(a.getDerivedStateFromError(e)),o=i.__d),i.componentDidCatch!=null&&(i.componentDidCatch(e,r||{}),o=i.__d),o)return i.__E=i}catch(t){e=t}throw e}},n=0,C.prototype.setState=function(e,t){var n=this.__s!=null&&this.__s!=this.state?this.__s:this.__s=v({},this.state);typeof e==`function`&&(e=e(v({},n),this.props)),e&&v(n,e),e!=null&&this.__v&&(t&&this._sb.push(t),D(this))},C.prototype.forceUpdate=function(e){this.__v&&(this.__e=!0,e&&this.__h.push(e),D(this))},C.prototype.render=S,r=[],a=typeof Promise==`function`?Promise.prototype.then.bind(Promise.resolve()):setTimeout,o=function(e,t){return e.__v.__b-t.__v.__b},O.__r=0,s=Math.random().toString(8),c=`__d`+s,l=`__a`+s,u=/(PointerCapture)$|Capture$/i,d=0,f=F(!1),p=F(!0);var oe=[[1,1],[4,5],[5,4],[4,3],[3,4],[3,2],[2,3],[16,9],[9,16],[21,9],[9,21]],z=[`9x16`,`4x5`,`1x1`,`4x3`,`16x9`];function se(e,t){return[e,t].every(e=>Number.isInteger(e)&&e>=1&&e<=1e5)}function ce(e,t){for(;t;)[e,t]=[t,e%t];return e}var B=e=>String(Number(e.toFixed(2))),le=Math.log(1.01)+1e-12;function ue(e){let t=null,n=1/0;for(let r of oe){let i=Math.abs(Math.log(e/(r[0]/r[1])));i<n&&(n=i,t=r)}return{best:t,err:n}}function de(e,t){if(!se(e,t))throw RangeError(`Not a picture size: ${e}×${t}`);let{best:n,err:r}=ue(e/t);if(n&&r<=le)return`${n[0]}:${n[1]}`;let i=ce(e,t);return e/i<=32&&t/i<=32?`${e/i}:${t/i}`:e>=t?`${B(e/t)}:1`:`1:${B(t/e)}`}var V=e=>e.replace(`:`,`x`),fe=e=>e.replace(`x`,`:`);function pe(e){let t=e=>{let t=z.indexOf(e.id);return t===-1?z.length:t};return[...e].sort((e,n)=>t(e)-t(n)||e.width/e.height-n.width/n.height||e.id.localeCompare(n.id))}function me(e,t){let n=(e.width!==null&&e.height!==null&&se(e.width,e.height)?{width:e.width,height:e.height}:null)??(t&&se(t.width,t.height)?t:null),r=e.formats.map(e=>({id:e.id,label:e.label,file:e.file,width:e.width,height:e.height,duration:e.duration,fps:e.fps,primary:!1}));if(!n)return r;let i=de(n.width,n.height);return[{id:V(i),label:i,file:e.file,width:n.width,height:n.height,duration:e.duration,fps:e.fps,primary:!0},...r]}function he(e,t,n){return t===null||n===null||Math.abs(t-n)<=.1+1e-9?null:`${e} is ${t.toFixed(1)} s; the cut is ${n.toFixed(1)} s`}function H(e,t){return t===null||e.format===null||e.format===t}function U(e){let t=Math.round(Math.max(0,e)*100),n=Math.floor(t/6e3);return`${n}:${((t-n*6e3)/100).toFixed(2).padStart(5,`0`)}`}function ge(e,t){return Math.round(e*t)}function _e(e,t){return Math.round(ge(e,t)/t*1e6)/1e6}function W(e,t,n,r){let i=ge(e,t)+n;return Math.min(Math.max(0,i/t),r||1/0)}function ve(e,t){if(e.t===null)return{t:null,tOut:null,from:null};if(!e.version||e.version===t)return{t:e.t,tOut:e.tOut,from:null};let n=`${e.version} at ${U(e.t)}`;if(e.fixT!==null&&e.fixVersion===t){let t=e.tOut===null?null:e.tOut-e.t;return{t:e.fixT,tOut:t===null?null:e.fixT+t,from:n}}return{t:e.t,tOut:e.tOut,from:n}}function ye(e,t){return e===null?`Whole`:t===null?U(e):`${U(e)}–${U(t)}`}function be(e,t,n){let r=(e.trim().match(/\S+/g)??[]).length,i=r/n,a=t>0?i/t:1/0;return{words:r,seconds:i,ratio:a,state:a>1?`over`:a>.8?`tight`:`ok`}}function xe(e){return e.proposed!==null&&e.proposed.trim()!==e.current.trim()}function Se(e){return e?.versions[e.versions.length-1]}function G(e){if(e?.lockedVersion){let t=e.versions.find(t=>t.id===e.lockedVersion);if(t)return t}return Se(e)}var Ce=e=>!e.shelved;function we(e,t,n){let r=e.findIndex(e=>e.id===t);if(r===-1)return null;for(let t=r+n;t>=0&&t<e.length;t+=n)if(Ce(e[t]))return e[t].id;return null}function Te(e,t){let n=e.filter(Ce);return n.length>=2||n.length===1&&t!==n[0].id}function Ee(e,t){let n=e.findIndex(e=>e.id===t);if(n===-1)return null;let r=e.map((e,t)=>({v:e,j:t})).filter(({v:e,j:t})=>t!==n&&Ce(e));return(r.find(({j:e})=>e>n)??r[r.length-1])?.v.id??null}function De(e,t){let n=Math.floor(e/190),r=t===void 0?1/0:Math.floor((t-8-56)/26);return Math.max(t===void 0?3:2,Math.min(12,n,r))}function Oe(e,t,n){let r=Array.from({length:e},(e,t)=>t);if(e<=n)return r;let i=r.slice(0,n);return t<0||i.includes(t)?i:[...i.slice(0,n-1),t]}var ke={script:`Script`,picture:`Picture`,voice:`Voiceover`,music:`Music`,sfx:`Sound effects`,mix:`Mix`,visuals:`Visuals`},Ae={script:{what:`Read the VO line by line and suggest your own wording.`,unlocks:`Your agent adds the script.`,ask:`the script`},picture:{what:`Watch each cut, leave timecoded notes and lock the picture.`,unlocks:`Your agent adds a cut.`,ask:`a cut`},voice:{what:`Compare whole reads in rounds and pick one.`,unlocks:`Your agent adds voice reads.`,ask:`voice reads`},music:{what:`Compare music beds against the picture and pick one.`,unlocks:`Your agent adds music beds.`,ask:`music beds`},sfx:{what:`Compare SFX passes, cue by cue.`,unlocks:`Your agent adds an SFX pass.`,ask:`an SFX pass`},mix:{what:`Balance voice, music and effects and check loudness.`,unlocks:`Unlocks with a cut and any audio.`,ask:`a cut and some audio`},visuals:{what:`Mark up stills and carousels, region by region.`,unlocks:`Your agent registers a still or a carousel.`,ask:`a still or a carousel`},assets:{what:`Every file in the project in one place.`,unlocks:`Unlocks with the first cut, take, track or screenshot.`,ask:`files`}},K=(e,t)=>t?` ${e} "${t}"`:``,je={script:(e,t)=>`In Rushes project "${e}", add the voiceover script${K(`for`,t)} with rushes_set_script, one section per line with start and end times.`,picture:(e,t)=>`In Rushes project "${e}", add the latest cut${K(`of`,t)} with rushes_add_version.`,voice:(e,t)=>`In Rushes project "${e}", record two or three voice reads${K(`for`,t)} and add each with rushes_add_variant (stage "voice", round "Round 1 · Voices") with a one-line description.`,music:(e,t)=>`In Rushes project "${e}", make two or three music beds${K(`for`,t)} and add each with rushes_add_variant (stage "music") with a one-line description.`,sfx:(e,t)=>`In Rushes project "${e}", make a sound-effects pass${K(`for`,t)} and add it with rushes_add_variant (stage "sfx") with its cues.`,mix:(e,t)=>`In Rushes project "${e}", add a cut and at least one voice read, music bed or SFX pass${K(`for`,t)}.`,visuals:e=>`In Rushes project "${e}", register my stills and carousels with rushes_add_visual: one visual per post (a still, or a carousel), with each page's picture in every aspect ratio it comes in. Then tell me, and I'll mark them up in the Visuals tab.`,assets:(e,t)=>`In Rushes project "${e}", add the first cut${K(`of`,t)} with rushes_add_version.`};function Me(e,t,n){return je[e](t,n)}var Ne=[`brief`,`script`,`storyboard`],Pe=e=>e===`brief`||e===`script`||e===`storyboard`;function Fe(e,t,n){let r=t.filter(e=>e.status===`approved`).length;return{brief:e.exists&&e.status===`approved`?`ok`:`none`,script:t.length>0&&r===t.length?`ok`:r>0?`part`:`none`,storyboard:n.total>0&&n.approved===n.total?`ok`:n.approved>0?`part`:`none`}}var Ie={what:`Write down what this film is for before anything is built, and approve it.`,unlocks:`Your agent starts a brief for this film.`,ask:`a brief`},Le={what:`See each shot as a still, rewrite what happens, and approve it before anything is built.`,unlocks:`Your agent sketches the shots once the script is approved.`,ask:`a storyboard`};function Re(e,t){return`In Rushes project "${e}", start a brief${K(`for`,t)}: ask me up to three questions, each with a recommended answer, then write brief.md (see "Starting a film" in AGENTS.md).`}function ze(e,t){return`In Rushes project "${e}", sketch the shots${K(`for`,t)} from the approved script: write storyboard.md with one "## Shot 01 · Name" section per shot (Tag, Length, Still and Status: draft lines, then what happens), make a still for each, and save them under storyboard/ (see "Starting a film" in AGENTS.md).`}function Be(e,t){return`The plan is approved in Rushes project "${e}"${K(`for`,t)}. Build the film from brief.md and storyboard.md, name each scene after its planned shot, and register the cut with rushes_add_version.`}function Ve(e,t,n){let r=n.status===`approved`,i=n.sections.filter(e=>e.changed).map(e=>e.heading),a=[`In Rushes project "${e}"${K(`for`,t)}, the brief is ${r?`approved`:`still a draft`}.`];return i.length&&a.push(`I changed ${i.length===1?`this section`:`these sections`} in brief.md: ${i.join(`, `)}. Read the file again before you go on, and keep my wording.`),a.push(r?`Next: write the script with rushes_set_script.`:`Don't build anything until I approve it.`),a.join(` `)}function He(e,t,n){return e.reduce((e,t)=>e+t.todo,0)+t.changed+n.changed}function Ue(e,t,n){let r=n.shots.filter(e=>e.changed).map(e=>`Shot ${String(e.n).padStart(2,`0`)} · ${e.name}`),i=[`In Rushes project "${e}"${K(`for`,t)}, ${n.approved} of ${n.total} shots in storyboard.md are approved.`];return r.length&&i.push(`I changed ${r.length===1?`this shot`:`these shots`}: ${r.join(`, `)}. Read storyboard.md again before you go on, keep my wording, and update the still${r.length===1?``:`s`} if what happens has changed.`),i.push(n.approved===n.total&&n.total>0?`Next: build the film.`:`Don't build anything until I approve them all.`),i.join(` `)}function We(e){let t=e.sections.find(e=>/^length/i.test(e.heading)),n=t?/Length:\s*(\d+(?:\.\d+)?)/i.exec(t.yours):null,r=n?Number(n[1]):NaN;return Number.isFinite(r)&&r>0?r:null}function Ge(e,t){return e.find(e=>e.stage===`picture`)?.unlocked?`picture`:t.exists?`brief`:qe(e)}function Ke(e,t){return t[e]?e:Ne.find(e=>t[e])??e}function qe(e){return e.find(e=>e.stage===`picture`)?.unlocked?`picture`:e.find(e=>e.unlocked)?.stage??`picture`}function Je(e,t){let n=null;for(let r of e)r.start<=t&&(!n||r.start>n.start)&&(n=r);return n?{n:n.n,name:n.name}:null}function Ye(e){return String(e).padStart(2,`0`)}function Xe(e,t){return Math.ceil(e*t-1e-9)/t}function Ze(e){return e<1024?`${e} B`:e<1048576?`${Math.round(e/1024)} KB`:e<1073741824?`${(e/1048576).toFixed(1)} MB`:`${(e/1073741824).toFixed(1)} GB`}function Qe(e,t){let n=[];if(e&&n.push(e),t)for(let[e,r]of Object.entries(t))n.push(typeof r==`number`?`${r} ${e.toUpperCase()}`:String(r));return n.length>0?n.join(` · `):null}var $e=new Set([`md`,`txt`,`pdf`,`srt`,`vtt`,`png`,`jpg`,`jpeg`,`gif`,`webp`,`mp4`,`mov`,`m4v`,`webm`,`mkv`,`wav`,`mp3`,`m4a`,`aac`,`flac`,`ogg`,`prproj`,`drp`]),et=new Set([`mp4`,`mov`,`m4v`,`webm`,`mkv`]);function tt(e){let t=e.lastIndexOf(`.`);return t===-1?``:e.slice(t+1).toLowerCase()}var nt=[{id:`screenshot`,title:`Screenshots`,kinds:[`screenshot`],view:`grid`,filmFilter:!0,gridToggle:!0},{id:`cut`,title:`Cuts`,kinds:[`cut`],view:`grid`,filmFilter:!0,gridToggle:!0},{id:`proxy`,title:`Proxies`,kinds:[`proxy`],view:`list`,filmFilter:!0,gridToggle:!1},{id:`voiceover`,title:`Voiceover`,kinds:[`take`,`voice`],view:`list`,filmFilter:!1,gridToggle:!1},{id:`music`,title:`Music`,kinds:[`music`],view:`list`,filmFilter:!1,gridToggle:!1},{id:`sfx`,title:`Sound effects`,kinds:[`sfx`],view:`list`,filmFilter:!1,gridToggle:!1},{id:`doc`,title:`Scripts & docs`,kinds:[`doc`],view:`list`,filmFilter:!1,gridToggle:!1},{id:`image`,title:`Images`,kinds:[`image`],view:`grid`,filmFilter:!1,gridToggle:!0},{id:`caption`,title:`Captions`,kinds:[`caption`],view:`list`,filmFilter:!1,gridToggle:!1},{id:`export`,title:`Exports`,kinds:[`export`],view:`list`,filmFilter:!1,gridToggle:!1},{id:`delivery`,title:`Delivery`,kinds:[`delivery`],view:`grid`,filmFilter:!0,gridToggle:!0},{id:`edit`,title:`Edit files`,kinds:[`edit`],view:`list`,filmFilter:!1,gridToggle:!1}],rt=new Set([`doc`,`caption`,`export`,`edit`]),it=new Set([`md`,`txt`,`srt`,`vtt`]);function at(e){return it.has(tt(e.path))}function ot(e,t,n={}){let{query:r=``,sort:i=`newest`,film:a,videos:o=[]}=n,s=e.filter(e=>t.kinds.includes(e.kind));a&&(s=s.filter(e=>e.video===a));let c=r.trim().toLowerCase();c&&(s=s.filter(e=>{let t=o.find(t=>t.id===e.video),n=t?.versions.find(t=>t.id===e.version);return[e.name,e.path,e.note,n?.note,t?.name].filter(e=>!!e).some(e=>e.toLowerCase().includes(c))}));let l=e=>e.modified?new Date(e.modified).getTime():0,u=[...s];return i===`name`?u.sort((e,t)=>e.name.localeCompare(t.name)):i===`oldest`?u.sort((e,t)=>l(e)-l(t)):u.sort((e,t)=>l(t)-l(e)),t.kinds.includes(`cut`)?st(u):u}function st(e){let t=e=>e.kind===`cut`&&e.format!==void 0,n=e.filter(t),r=new Set,i=[];for(let a of e){if(t(a)){e.some(e=>e.kind===`cut`&&!t(e)&&e.video===a.video&&e.version===a.version)||(i.push(a),r.add(a));continue}if(i.push(a),a.kind!==`cut`)continue;let o=n.filter(e=>e.video===a.video&&e.version===a.version&&!r.has(e));for(let e of pe(o.map(e=>({id:e.format,width:e.width??1,height:e.height??1,s:e}))).map(e=>e.s))i.push(e),r.add(e)}return i}function ct(e,t=[]){let n=new Map;for(let r of e){let e=t.find(e=>e.id===r.video),i=e&&r.version?`${e.name} · ${r.version}`:null,a=i??`\0`,o=n.get(a);o||(o={heading:i,items:[]},n.set(a,o)),o.items.push(r)}return[...n.values()]}function lt(e,t,n,r){if(!(e>0&&t>0&&n>0&&r>0))return{x:0,y:0,w:Math.max(0,n),h:Math.max(0,r)};let i=Math.min(n/e,r/t),a=e*i,o=t*i;return{x:(n-a)/2,y:(r-o)/2,w:a,h:o}}function ut(e,t,n,r,i,a){let o=e=>Math.round(Math.min(1,Math.max(0,e))*1e4)/1e4,s=o(Math.min(e,n)/i),c=o(Math.min(t,r)/a),l=o(Math.max(e,n)/i),u=o(Math.max(t,r)/a);return{x:s,y:c,w:Math.round((l-s)*1e4)/1e4,h:Math.round((u-c)*1e4)/1e4}}var dt={point:`Point`,range:`Range`,whole:`Whole`},ft=[`point`,`range`,`whole`];function pt(e){return(e??ft).filter(e=>e in dt).map(e=>({value:e,label:dt[e]}))}function mt(e){return e.range.in!==null||e.marks.length>0||e.hasText}var ht={voice:[`Speaker`,`Pacing`,`Tone`,`Overall`],music:[`Tempo`,`Key`,`Energy`,`Ending`],sfx:[`Timing`,`Level`,`Swap sound`,`Remove`],mix:[`Level`,`Balance`,`Loudness`]},gt=[1,2,3,6,9],_t=[`rise`,`fall`,`louder`,`quieter`],vt={rise:`fall`,fall:`rise`,louder:`quieter`,quieter:`louder`},yt=e=>e===`louder`||e===`quieter`;function bt(e){let t=e.kind===`rise`?`Rise`:e.kind===`fall`?`Fall`:e.kind===`louder`?`Louder`:`Quieter`;return e.db===void 0?t:`${t} ${e.db} dB`}function xt(e){return e&&e.length>0?e.map(bt).join(` · `):null}function St(e,t,n=3){let r=e.some(e=>e.kind===t),i=e.filter(e=>e.kind!==t&&e.kind!==vt[t]);return r||i.push(yt(t)?{kind:t,db:n}:{kind:t}),i.sort((e,t)=>_t.indexOf(e.kind)-_t.indexOf(t.kind))}function Ct(e,t,n){return e.map(e=>e.kind===t&&yt(t)?{kind:t,db:n}:e)}function wt(e,t=0){let n=[],r=e?.description;return r!==void 0&&String(r).trim()?n.push(String(r)):(e?.bpm!==void 0&&n.push(`${e.bpm} BPM`),e?.key!==void 0&&n.push(String(e.key))),t>0&&n.push(`${t} cue${t===1?``:`s`}`),n.length>0?n.join(` · `):null}function Tt(e,t){let n=[];for(let r of e)if(r.stage===t)for(let e of r.variants)n.push({key:`${r.id}/${e.id}`,lane:r.id,laneName:r.name,variant:e.id,name:e.name,meta:wt(e.meta,t===`sfx`?e.cues.length:0),file:e.file,cues:e.cues,films:fr(e)});return n}function Et(e){return e}function Dt(e){let t=[];for(let n of e){let e=t[t.length-1];e&&(e.options[0].groupId??e.group)===(n.groupId??n.group)?e.options.push(n):t.push({group:n.group,options:[n]})}return t}var Ot=e=>e.key,kt=(e,t)=>`${e.key}:${t}`;function At(e,t){let n=e.map(e=>e.t);return n.map((e,r)=>{let i=n.filter((e,t)=>t!==r).map(t=>Math.abs(t-e));return t>0&&i.length?Math.min(.4,Math.min(...i)/t):.4})}function jt(e,t,n=!1){let r=e.map(e=>({value:`v:${e.key}`,label:t(e),on:Ot(e),row:e.key}));if(!n)return r;let i=new Set(r.map(e=>e.label));for(let n of e)for(let e of n.cues){let a=`Cue · ${e.name}`;i.has(a)&&(a=`${a} · ${t(n)}`),i.add(a),r.push({value:`c:${n.key}:${e.id}`,label:a,on:kt(n,e.id),t:e.t,row:n.key})}return r}function Mt(e,t){if(t===null||!t.includes(`/`))return null;let n=e.find(e=>Ot(e)===t);if(n)return{row:n,cue:null};let r=t.indexOf(`:`,t.indexOf(`/`));if(r===-1)return null;let i=t.slice(0,r),a=t.slice(r+1),o=e.find(e=>e.key===i&&e.cues.some(e=>e.id===a));return o?{row:o,cue:a}:null}function Nt(e,t){let n=e.find(e=>e.variant===t);if(n)return{row:n,cue:null};let r=t.indexOf(`:`);if(r>0){let n=t.slice(0,r),i=t.slice(r+1),a=e.find(e=>e.variant===n&&e.cues.some(e=>e.id===i));if(a)return{row:a,cue:i}}let i=e.find(e=>e.cues.some(e=>e.id===t));return i?{row:i,cue:t}:null}function Pt(e,t){if(t===null)return null;let n=Mt(e,t)??Nt(e,t);return n?{row:n.row.key,cue:n.cue}:null}function Ft(e,t){return Pt(e,t)?.row??null}function It(e,t,n){let r=Pt(e,n);if(!r)return null;let i=r.cue===null?`v:${r.row}`:`c:${r.row}:${r.cue}`;return t.find(e=>e.value===i)?.label??null}function Lt(e,t){let n={},r=e.find(e=>e.key===t)?.audition,i=e.map((e,t)=>({r:e,i:t})).sort((e,t)=>(e.r.order??e.i)-(t.r.order??t.i)).map(e=>e.r);for(let t of i){let i=t.audition;i&&n[i.lane]===void 0&&(r&&r.lane===i.lane?n[i.lane]=r.clip:n[i.lane]=(e.find(e=>e.picked&&e.audition?.lane===i.lane)??t).audition.clip)}return n}function Rt(e,t){let n=e=>{let n=(2166136261^t)>>>0;for(let t=0;t<e.length;t++)n=Math.imul(n^e.charCodeAt(t),16777619)>>>0;return n^=n>>>15,n=Math.imul(n,2246822507)>>>0,(n^n>>>13)>>>0};return[...e].sort((e,t)=>n(e)-n(t)||(e<t?-1:+(e>t)))}var zt=new WeakSet,Bt=!1;function Vt(e){Bt||(Bt=!0,e.addEventListener(`focusin`,e=>Ht(e.target),!0),e.addEventListener(`pointerdown`,e=>{let t=e.target?.closest?.(`button`);t&&zt.delete(t)},!0))}function Ht(e){let t=e;t&&typeof t.matches==`function`&&(t.matches(`:focus-visible`)?zt.add(t):zt.delete(t))}function Ut(e){let t=e;if(!t||typeof t.closest!=`function`)return!1;let n=t.closest(`button`);return!!n&&zt.has(n)&&!t.closest(`[data-player]`)}function Wt(e){let t=new URLSearchParams(e),n=t.get(`test`)===`1`;return{test:n,streamOver:n&&t.get(`streamOver`)===`1`}}function Gt(e){return e.toUpperCase()}var Kt=e=>`var:${e}`;function qt(e,t){let n=e.filter(e=>e.stage===`voice`&&e.variants.length>0);return n.map((e,r)=>{let i=Tt([e],`voice`),a=i.some(n=>n.variant===t[e.id])?t[e.id]:null;return{id:e.id,name:e.name,reads:i,pick:a,current:r===n.length-1}})}var Jt=e=>e.reads.find(t=>t.variant===e.pick)??null;function Yt(e){for(let t=e.length-1;t>=0;t--){let n=Jt(e[t]);if(n)return n}return null}function Xt(e){let t=e.find(e=>e.current);return t?Jt(t)??t.reads[0]??null:null}var Zt=e=>`${Kt(e.lane)}/${e.variant}`;function Qt(e,t){let n=e.flatMap(e=>e.reads),r=n.find(e=>e.key===t)??Xt(e),i={},a={};for(let e of n)i[Zt(e)]=e.key,a[Zt(e)]=+(e.key===r?.key);return{select:i,gains:a}}var $t=(e,t)=>!!e.sections?.some(e=>e.id===t);function en(e,t){if(t===null)return null;for(let n of e.rounds){let e=n.reads.find(e=>e.key===t);if(e)return{round:n,read:e}}if(t.includes(`/`)||t.includes(`:`)||t===`vo`||$t(e,t))return null;for(let n of e.rounds){let e=n.reads.find(e=>e.variant===t);if(e)return{round:n,read:e}}return null}function tn(e,t){return en(e,t.on)?.read.key??null}function nn(e,t=e=>e.name){let n=[];for(let r of[...e].reverse())for(let e of r.reads)n.push({value:`v:${e.key}`,label:t(e),full:`${r.name} · ${t(e)}`,group:r.name,groupId:r.id,on:Ot(e),row:e.key});return n}function rn(e,t,n=e=>e.name){let r=en(e,t);if(r)return r.round.current?n(r.read):`${r.round.name} · ${n(r.read)}`;if(t===null||t===`vo`)return`Assembled read`;if($t(e,t))return Gt(t);for(let n of e.sections??[]){let e=n.takes.findIndex(e=>`${n.id}:${e.id}`===t);if(e!==-1)return`${Gt(n.id)} · Take ${e+1}`}return null}var an=[`vo`,`music`,`sfx`],on={vo:`voice`,music:`music`,sfx:`sfx`};function sn(e,t){return an.filter(n=>e[n]&&(t[n]??1)>0).map(e=>on[e])}function cn(e,t){for(let n of[`music`,`sfx`]){let r=Mt(e.variants[n],t);if(r)return{lane:n,row:r.row}}if(t.includes(`/`))return null;for(let n of[`music`,`sfx`]){let r=e.heard[n].find(e=>e.variant===t);if(r)return{lane:n,row:r}}for(let n of[`music`,`sfx`]){let r=e.variants[n].find(e=>e.variant===t);if(r)return{lane:n,row:r}}return null}function ln(e,t){if(t===null)return`mix`;let n=t.includes(`/`)?cn(e,t):null;return n?n.lane:t===`vo`?`vo`:cn(e,t)?.lane??null}function un(e,t){let n=ln(e,t);return n===null||n===`mix`?[...an]:[n]}var dn={vo:`Voiceover`,music:`Music`,sfx:`Sound effects`};function fn(e,t){let n=ln(e,t);return n===null?null:n===`mix`?`Whole mix`:n===`vo`?dn.vo:`${dn[n]} · ${cn(e,t).row.name}`}function pn(e){let t=[{value:`mix`,label:`Whole mix`,on:null}];e.heard.vo&&t.push({value:`vo`,label:dn.vo,on:`vo`,row:`vo`});for(let n of[`music`,`sfx`])for(let r of e.heard[n])t.push({value:`${n}:${r.key}`,label:`${dn[n]} · ${r.name}`,on:Ot(r),row:n});return t}var mn=.5;function hn(e){let t=Math.round(e/mn)*mn;return Math.min(6,Math.max(-24,t))}function gn(e,t=1){let n=Math.abs(e).toFixed(t);return Number(n)===0?n:`${e<0?`−`:`+`}${n}`}var _n=`—`,vn=`Install ffmpeg for loudness`;function yn(e){let t=(e,t,n)=>[{id:`integrated`,label:`LUFS integrated`,value:e[0],tip:e[1]},{id:`truePeak`,label:`dBTP true peak`,value:t[0],tip:t[1]},{id:`musicUnderVo`,label:`Music under VO`,value:n[0],tip:n[1]}],n=e=>t([_n,e],[_n,e],[_n,e]);if(e.kind===`empty`)return n(`Nothing to measure`);if(e.kind===`waiting`)return n(null);if(e.kind===`timeout`)return n(`Measuring took too long · click to retry`);if(e.kind===`error`)return n(`Couldn't measure loudness · click to retry`);let r=e.result;if(!r.available)return n(vn);let i=e=>r.silent?[`−∞`,`The mix is silent`]:e===null?[_n,`Couldn't measure loudness`]:[gn(e),null],a=r.silent?[`−∞`,`The mix is silent`]:r.musicUnderVo===null?[_n,`Needs Voiceover and Music both playing`]:[`${gn(r.musicUnderVo,0)} dB`,null];return t(i(r.integrated),i(r.truePeak),a)}function bn(e){return Math.max(10,Math.round((Number.isFinite(e)?e:0)/10)*10)}function xn(e){return`Makes a lightweight 1080p copy on your drive so this cut previews smoothly. About ${bn(e)} MB. Your original isn't changed.`}var Sn=(e,t)=>`${e}/${t}`;function Cn(e,t){let n={job:e.id,video:e.video,version:e.version,pct:e.pct,state:e.state,at:t};return e.reason!==void 0&&(n.reason=e.reason),n}function wn(e,t){let n=Sn(t.video,t.version),r=e[n];if(r&&r.job===t.job){if(r.state!==`running`||t.state===`running`&&t.pct<=r.pct)return e}else if(r&&r.at>t.at)return e;return{...e,[n]:t}}function Tn(e,t,n,r){let i=new Set(t.map(e=>e.id)),a=null;for(let[t,o]of Object.entries(e))o.at>=n||(o.state===`running`&&!i.has(o.job)||o.state===`done`&&!r(o.video,o.version))&&(a??={...e},delete a[t]);let o=a??e;for(let e of t)o=wn(o,Cn(e,n));return o}function En(e){return e.ffmpeg?e.starting||e.job?.state===`running`||e.job?.state===`done`&&!e.hasProxy?`working`:e.hasProxy?e.watched&&e.job?.state===`done`?`done`:`none`:e.need||e.broken?`offer`:`none`:`none`}function Dn(e,t){return e||(t?`The browser couldn't play this file`:null)}function On(e){let t=[Ze(e.size??0)];return e.width&&e.height&&t.push(`${e.width}×${e.height}`),e.version&&t.push(`from ${e.version}`),t.join(` · `)}function kn(e){return/Mac|iPhone|iPad|iPod/.test(e)?`⌘C`:`Ctrl+C`}var An=[`voice`,`music`,`sfx`,`other`,`cut`],jn={voice:`Voiceover`,music:`Music`,sfx:`Sound effects`,other:`Other audio`,cut:`Cut`};function Mn(e){return e?e.voice+e.music+e.sfx+e.cut+e.other:0}var Nn={voice:{kind:`voice`,one:`voiceover file`,many:`voiceover files`},music:{kind:`music`,one:`music file`,many:`music files`},sfx:{kind:`sfx`,one:`sound effect file`,many:`sound effect files`}};function Pn(e,t){let n=Nn[e],r=n&&t?t[n.kind]:0;return!n||!(r>0)?null:{kind:n.kind,text:`${r} ${r===1?n.one:n.many} found in this project`,review:`Review ${n.many} in Found`}}function Fn(e){if(!e)return null;let t=e.broughtIn.length,n=Mn(e.counts);return t>0&&n>0?`${t} brought in · ${n} more found`:t>0?`${t} brought in`:n>0?`${n} found`:null}function In(e){return e?e.digest?`d:${e.digest}`:`${e.broughtIn.length}:${An.map(t=>e.counts[t]).join(`,`)}`:``}var Ln=(e,t)=>e.path===t.path&&e.kind===t.kind&&e.folder===t.folder&&e.size===t.size&&e.modified===t.modified&&e.duration===t.duration&&e.score===t.score&&e.suggested===t.suggested&&e.reasons.length===t.reasons.length&&e.reasons.every((e,n)=>e===t.reasons[n]);function Rn(e,t){let n=new Map(e.map(e=>[e.path,e])),r=t.map(e=>{let t=n.get(e.path);return t&&Ln(t,e)?t:e});return r.length===e.length&&r.every((t,n)=>t===e[n])?e:r}function zn(e){return e?e.split(`/`).map(e=>e.replace(/([a-z\d])([A-Z])/g,`$1 $2`).split(/[^\p{L}\p{N}]+/u).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(` `)).filter(Boolean).join(` / `):`Project folder`}var Bn=`\0cuts`;function Vn(e){let t=new Map,n=[];for(let r of e){if(r.kind===`cut`){n.push(r);continue}let e=t.get(r.folder);e||t.set(r.folder,e={key:r.folder,title:zn(r.folder),folder:r.folder,files:[]}),e.files.push(r)}let r=[...t.values()];return n.length&&r.push({key:Bn,title:`Other cuts`,folder:null,files:n}),r}function Hn(e,t,n){let r=n.trim().toLowerCase();return e.filter(e=>(t===`all`||e.kind===t)&&(!r||e.path.toLowerCase().includes(r)))}function Un(e){return An.map(t=>[t,e.filter(e=>e.kind===t).length]).filter(([,e])=>e>0)}function Wn(e){if(e===null||!Number.isFinite(e)||e<0)return`—`;let t=Math.round(e*10),n=Math.floor(t/600);return`${n}:${((t-n*600)/10).toFixed(1).padStart(4,`0`)}`}var Gn=e=>e.replace(/\.$/,``).replace(/^(\p{Lu})(?=\p{Ll})/u,e=>e.toLowerCase());function Kn(e,t){let n=e=>`${e} ${e===1?`file`:`files`}`;if(t.length===0)return`Brought in ${n(e)}`;let r=[...new Set(t.map(e=>Gn(e.reason)))].join(`; `);return`${e>0?`Brought in ${n(e)}.`:`Nothing was brought in.`} ${t.length} couldn't be added: ${r}.`}function qn(e,t){return t.map(t=>{let n=t.slice(t.lastIndexOf(`/`)+1);for(let r of e.lanes){let e=r.variants.find(e=>e.file===t);if(!e)continue;let i=e.meta.description;return{path:t,name:n,kind:r.stage,label:r.stage===`voice`&&r.name!==jn.voice?`Voiceover · ${r.name}`:jn[r.stage],reasons:typeof i==`string`?i:``,playable:!0}}for(let r of e.videos){let e=r.versions.find(e=>e.file===t);if(e)return{path:t,name:n,kind:`cut`,label:`Cut · ${r.name} ${e.id}`,reasons:``,playable:!1}}return e.files.some(e=>e.file===t)?{path:t,name:n,kind:`doc`,label:`Doc`,reasons:``,playable:!1}:{path:t,name:n,kind:null,label:``,reasons:``,playable:!1}})}function Jn(e,t){return e.item!==t.item||e.kind!==t.kind||e.ticked!==t.ticked||e.playing!==t.playing||e.failure!==t.failure}function Yn(e,t){let n=e.versions.findIndex(e=>e.id===t);return n>0?e.versions[n-1]:void 0}function Xn(e,t){return e.length<2?null:t&&e.some(e=>e.id===t)?t:(e.find(e=>e.primary)??e[0]).id}function Zn(e){if(e.views.length===0)return[];let t=e.views.length===1,n=new Set(e.views.map(e=>e.id));return pe([...e.views.map(e=>({...e,absent:!1})),...e.previous.filter(e=>!n.has(e.id)).map(e=>({...e,absent:!0}))]).map(n=>{let r=!n.absent&&!t,i=r?e.notes.filter(e=>e.status===`todo`&&(e.format===null||e.format===n.id)).length:0,a=n.absent||n.primary?null:e.missing.has(n.file)?`File not found`:he(n.label,n.duration,e.versionDuration);return{id:n.id,label:n.label,width:n.width,height:n.height,enabled:r,selected:!n.absent&&(t||n.id===e.current),count:i,warn:a,reason:n.absent?`absent`:t?`single`:null}})}function Qn(e,t,n){let r=e.filter(e=>e.enabled),i=r.findIndex(e=>e.id===t);return i===-1?null:r[i+n]?.id??null}function $n(e,t){let n=[e.label];return e.reason===`absent`&&n.push(`not in ${t}`),e.reason===`single`&&n.push(`the only format`),e.count>0&&n.push(`${e.count} open note${e.count===1?``:`s`}`),e.warn&&n.push(e.warn),n.join(`, `)}function er(e,t,n=14){let r=n/Math.max(e,t);return{width:Math.max(4,Math.round(e*r)),height:Math.max(4,Math.round(t*r))}}var tr=e=>`repeat(${e}, minmax(0, 1fr))`;function nr(e,t,n){return`In Rushes project "${e}", register the other shapes of "${t}" ${n} (the same cut rendered at other aspect ratios, such as 9:16, 1:1 and 4:5) with rushes_add_format, one call per file.`}function rr(e,t,n){return n||Math.abs(e.width-t.width)<1&&Math.abs(e.height-t.height)<1?null:[{width:`${e.width}px`,height:`${e.height}px`},{width:`${t.width}px`,height:`${t.height}px`}]}var ir=(e,t)=>e.filter(e=>H(e,t)),ar=(e,t)=>t===null?[]:e.filter(e=>!H(e,t));function or(e,t,n){return e.box?t===null?!0:e.format===null?t===n:e.format===t:!1}var sr=`A drawn box belongs to one frame, so this note stays on this format.`;function cr(e,t,n){return n?`A drawn box fixes this note to ${e}.`:t===`this`?`Shows only while you're viewing ${e}.`:`Shows on every format.`}function lr(e,t){return e.format===null?t?`All`:null:fe(e.format)}function ur(e,t,n){if(e.format===null)return null;let r=t.find(t=>t.id===e.format);return r?{kind:`show`,id:r.id,label:r.label}:!e.box&&!n.some(t=>t.id===e.format)?{kind:`restore`}:null}function dr(e,t){if(!t)return e;let n=e.videos?.[t];return{...e,lanes:{...n?.lanes??{}},levels:{...n?.levels??{}},sections:{},videos:{}}}function fr(e){return e.videos??(e.video===void 0?[]:[e.video])}function pr(e,t,n){return t?e.map(e=>({...e,variants:e.variants.filter(e=>{let r=fr(e);return r.length===0?n<=1:r.includes(t)})})).filter(e=>e.variants.length>0):e}function mr(e,t,n){if(n<=1)return[];let r=new Set(pr(e,t,n).flatMap(e=>e.variants.map(t=>`${e.id}/${t.id}`)));return e.map(e=>({...e,variants:e.variants.filter(t=>!r.has(`${e.id}/${t.id}`))})).filter(e=>e.variants.length>0)}function hr(e,t,n){return e.filter(e=>e.stage===t&&(!n||!e.video||e.video===n))}var gr,_r,vr,yr,br=0,xr=[],Sr=t,Cr=Sr.__b,wr=Sr.__r,Tr=Sr.diffed,Er=Sr.__c,Dr=Sr.unmount,Or=Sr.__;function kr(e,t){Sr.__h&&Sr.__h(_r,e,br||t),br=0;var n=_r.__H||(_r.__H={__:[],__h:[]});return e>=n.__.length&&n.__.push({}),n.__[e]}function q(e){return br=1,Ar(Br,e)}function Ar(e,t,n){var r=kr(gr++,2);if(r.t=e,!r.__c&&(r.__=[n?n(t):Br(void 0,t),function(e){var t=r.__N?r.__N[0]:r.__[0],n=r.t(t,e);t!==n&&(r.__N=[n,r.__[1]],r.__c.setState({}))}],r.__c=_r,!_r.__f)){var i=function(e,t,n){if(!r.__c.__H)return!0;var i=!1,o=r.__c.props!==e;if(r.__c.__H.__.some(function(e){if(e.__N){i=!0;var t=e.__[0];e.__=e.__N,e.__N=void 0,t!==e.__[0]&&(o=!0)}}),a){var s=a.call(this,e,t,n);return i?s||o:s}return!i||o};_r.__f=!0;var a=_r.shouldComponentUpdate,o=_r.componentWillUpdate;_r.componentWillUpdate=function(e,t,n){if(this.__e){var r=a;a=void 0,i(e,t,n),a=r}o&&o.call(this,e,t,n)},_r.shouldComponentUpdate=i}return r.__N||r.__}function J(e,t){var n=kr(gr++,3);!Sr.__s&&zr(n.__H,t)&&(n.__=e,n.u=t,_r.__H.__h.push(n))}function Y(e,t){var n=kr(gr++,4);!Sr.__s&&zr(n.__H,t)&&(n.__=e,n.u=t,_r.__h.push(n))}function X(e){return br=5,jr(function(){return{current:e}},[])}function jr(e,t){var n=kr(gr++,7);return zr(n.__H,t)&&(n.__=e(),n.__H=t,n.__h=e),n.__}function Mr(e,t){return br=8,jr(function(){return e},t)}function Nr(){var e=kr(gr++,11);if(!e.__){for(var t=_r.__v;t!==null&&!t.__m&&t.__!==null;)t=t.__;var n=t.__m||(t.__m=[0,0]);e.__=`P`+n[0]+`-`+n[1]++}return e.__}function Pr(){for(var e;e=xr.shift();){var t=e.__H;if(e.__P&&t)try{t.__h.some(Lr),t.__h.some(Rr),t.__h=[]}catch(n){t.__h=[],Sr.__e(n,e.__v)}}}Sr.__b=function(e){_r=null,Cr&&Cr(e)},Sr.__=function(e,t){e&&t.__k&&t.__k.__m&&(e.__m=t.__k.__m),Or&&Or(e,t)},Sr.__r=function(e){wr&&wr(e),gr=0;var t=(_r=e.__c).__H;t&&(vr===_r?(t.__h=[],_r.__h=[],t.__.some(function(e){e.__N&&(e.__=e.__N),e.u=e.__N=void 0})):(t.__h.some(Lr),t.__h.some(Rr),t.__h=[],gr=0)),vr=_r},Sr.diffed=function(e){Tr&&Tr(e);var t=e.__c;t&&t.__H&&(t.__H.__h.length&&(xr.push(t)!==1&&yr===Sr.requestAnimationFrame||((yr=Sr.requestAnimationFrame)||Ir)(Pr)),t.__H.__.some(function(e){e.u&&=(e.__H=e.u,void 0)})),vr=_r=null},Sr.__c=function(e,t){t.some(function(e){try{e.__h.some(Lr),e.__h=e.__h.filter(function(e){return!e.__||Rr(e)})}catch(n){t.some(function(e){e.__h&&=[]}),t=[],Sr.__e(n,e.__v)}}),Er&&Er(e,t)},Sr.unmount=function(e){Dr&&Dr(e);var t,n=e.__c;n&&n.__H&&(n.__H.__.some(function(e){try{Lr(e)}catch(e){t=e}}),n.__H=void 0,t&&Sr.__e(t,n.__v))};var Fr=typeof requestAnimationFrame==`function`;function Ir(e){var t,n=function(){clearTimeout(r),Fr&&cancelAnimationFrame(t),setTimeout(e)},r=setTimeout(n,35);Fr&&(t=requestAnimationFrame(n))}function Lr(e){var t=_r,n=e.__c;typeof n==`function`&&(e.__c=void 0,n()),_r=t}function Rr(e){var t=_r;e.__c=e.__(),_r=t}function zr(e,t){return!e||e.length!==t.length||t.some(function(t,n){return t!==e[n]})}function Br(e,t){return typeof t==`function`?t(e):t}var Vr=class extends Error{status;code;constructor(e,t,n){super(n),this.status=e,this.code=t}};function Hr(){let e=location.pathname.match(/\/p\/([a-z2-9]{8})\//);return e?e[1]:null}async function Ur(e,t,n,r={}){let i=Hr(),a={};n!==void 0&&(a[`content-type`]=`application/json`),i&&(a[`x-rushes-project`]=i);let o=await fetch(t,{method:e,headers:a,body:n===void 0?void 0:JSON.stringify(n),...r.keepalive?{keepalive:!0}:{}}),s=await o.text(),c=s?JSON.parse(s):{};if(!o.ok)throw new Vr(o.status,c.error??`error`,c.message??`Request failed (${o.status})`);return c}var Z={get:e=>Ur(`GET`,e),post:(e,t={})=>Ur(`POST`,e,t),patch:(e,t)=>Ur(`PATCH`,e,t),put:(e,t,n)=>Ur(`PUT`,e,t,n),del:(e,t={})=>Ur(`DELETE`,e,t)};async function Wr(e,t,n,r=null){let i=Hr(),a=await fetch(`/api/videos/${encodeURIComponent(e)}/versions/${encodeURIComponent(t)}/frame?t=${n}${r?`&format=${encodeURIComponent(r)}`:``}`,{headers:i?{"x-rushes-project":i}:{}});if(!a.ok){let e=await a.json().catch(()=>({}));throw new Vr(a.status,e.error??`error`,e.message??`Request failed (${a.status})`)}let o=Number(a.headers.get(`x-rushes-frame`)),s=await a.blob(),c=await new Promise((e,t)=>{let n=new FileReader;n.onload=()=>e(n.result),n.onerror=()=>t(n.error??Error(`Couldn't read the frame`)),n.readAsDataURL(s)});return{frame:Number.isInteger(o)&&o>=0?o:null,png:c}}function Gr(e){let t=Hr();return`/media?path=${encodeURIComponent(e)}${t?`&project=${t}`:``}`}function Kr(){let e=Hr();return`/api/events${e?`?project=${e}`:``}`}var qr=[`change`,`proxy`,`corrupt`],Jr=e=>`rushes-sse-v1-${e}`,Yr=e=>`rushes-v1-${e}`,Xr=4e4,Zr=5e3;function Qr(){return{locks:typeof navigator<`u`?navigator.locks:void 0,BroadcastChannel:typeof BroadcastChannel==`function`?BroadcastChannel:void 0,EventSource,page:typeof window<`u`?{window,document}:void 0}}function $r(e){if(typeof e!=`object`||!e)return!1;let{v:t,type:n,data:r}=e;return t===1?n===`open`||n===`error`||n===`ping`||qr.includes(n)&&typeof r==`string`:!1}function ei(e,t){t.type===`open`?e.open():t.type===`error`?e.error():`data`in t&&e[t.type](t.data)}function ti(e,t,n,r){let i=new e.EventSource(t),a=e=>{ei(n,e),r?.(e)};for(let e of qr)i.addEventListener(e,t=>a({v:1,type:e,data:String(t.data??``)}));return i.addEventListener(`ping`,()=>a({v:1,type:`ping`})),i.onopen=()=>a({v:1,type:`open`}),i.onerror=()=>a({v:1,type:`error`}),i}function ni(e,t,n,r=Qr()){let{locks:i,BroadcastChannel:a}=r;if(!i||!a){let e=ti(r,t,n);return{role:()=>`own`,close:()=>e.close()}}let o=r.random??Math.random,s=`follower`,c=!1,l=!1,u=null,d=null,f=0,p=0,m=null,h,g=new a(Yr(e)),_=e=>g.postMessage(e),v=()=>{u?.close(),u=null,p=0,s===`leader`&&(s=`follower`);let e=d;d=null,e?.()},y=()=>{clearTimeout(h),!(c||l||s!==`follower`)&&(h=setTimeout(S,Xr+o()*Zr))},b=e=>{p=e,s=`leader`,clearTimeout(h),u=ti(r,t,n,_)},x=(a=!1)=>{let o=++f;m?.abort();let h=new AbortController;m=h;let g=!1;i.request(Jr(e),a?{steal:!0}:{signal:h.signal},()=>new Promise(e=>{if(g=!0,c||l||o!==f)return e();d=e,b(o)})).catch(()=>{p===o?(v(),!c&&!l&&(x(),y())):a&&!g&&o===f&&!c&&!l&&(s=`own`,u=ti(r,t,n))})},S=()=>{c||l||s!==`follower`||(x(!0),n.resync())};g.onmessage=e=>{s===`follower`&&!l&&$r(e.data)&&(y(),ei(n,e.data))};let C=()=>{c||l||(l=!0,clearTimeout(h),f++,m?.abort(),m=null,v(),s===`own`&&(s=`follower`))},w=()=>{!c&&l&&(l=!1,x(),y(),n.resync())},T=e=>{e.persisted&&w()},E=r.page;return E?.window.addEventListener(`pagehide`,C),E?.window.addEventListener(`pageshow`,T),E?.document.addEventListener(`freeze`,C),E?.document.addEventListener(`resume`,w),x(),y(),{role:()=>s,close(){c||(c=!0,clearTimeout(h),m?.abort(),v(),g.close(),E?.window.removeEventListener(`pagehide`,C),E?.window.removeEventListener(`pageshow`,T),E?.document.removeEventListener(`freeze`,C),E?.document.removeEventListener(`resume`,w))}}}function ri(){let[e,t]=q(null),[n,r]=q([]),[i,a]=q(null),[o,s]=q(!1),[c,l]=q({}),u=X(void 0),d=X(0),f=X(0),p=X(!1),m=X(void 0),h=X(750),g=async()=>{let e=++d.current,n=performance.now(),[i,o]=await Promise.all([Z.get(`/api/state`).then(e=>({ok:!0,data:e}),e=>({ok:!1,error:e})),Z.get(`/api/assets`).then(e=>({ok:!0,assets:e.assets}),e=>({ok:!1,error:e}))]);if(e<f.current)return;f.current=e;let c=!1;if(i.ok){let e=i.data;t(e);let r=(t,n)=>!!e.project.videos.find(e=>e.id===t)?.versions.find(e=>e.id===n)?.proxy;l(t=>Tn(t,e.proxies?.jobs??[],n,r)),a(null),s(!1)}else i.error instanceof Vr&&i.error.code===`wrong_project`?(s(!0),c=!0):a(i.error.message);o.ok&&r(o.assets),clearTimeout(m.current),c||i.ok&&o.ok?h.current=750:(m.current=window.setTimeout(()=>void g(),h.current),h.current=Math.min(h.current*2,1e4))};return J(()=>{g();let e=ni(Hr()??``,Kr(),{change(){clearTimeout(u.current),u.current=window.setTimeout(()=>void g(),40)},proxy(e){let t=JSON.parse(e);l(e=>wn(e,{...t,at:performance.now()}))},corrupt(e){let{file:t}=JSON.parse(e);a(`${t} has an error and wasn't loaded. Fix or restore it, and Rushes will pick it up.`)},error(){a(`Lost touch with the Rushes server. Retrying…`),!p.current&&(p.current=!0,g().finally(()=>{p.current=!1}))},open(){p.current=!1,g()},resync(){g()}});return Wt(location.search).test&&(window.__rushesLive={role:()=>e.role()}),()=>{e.close(),clearTimeout(u.current),clearTimeout(m.current)}},[]),{state:e,assets:n,problem:i,wrongProject:o,refresh:g,proxyJobs:c,noteProxyJob:e=>l(t=>wn(t,Cn(e,performance.now())))}}function ii(e){return e.rev?`${e.path}#${e.rev}`:e.path}function ai(e){return e.modified?e.modified:e.size===null?void 0:String(e.size)}var oi=.05,si=6e4;function ci(e){return 10**(e/20)}function li(e){let t=e.some(e=>e.solo),n={};for(let r of e){let e=t?+!!r.solo:+!r.muted;n[r.id]=ci(r.level??0)*e}return n}function ui(e,t){return+(e===t)}function di(e,t){let n={};for(let r of e){let e=t[r.lane];n[r.id]=e===void 0?1:ui(e,r.id)}return n}function fi(e,t){let n=[];for(let r of e)r.duration>0&&(r.offset+r.duration<=t||(r.offset<=t?n.push({id:r.id,when:0,offset:t-r.offset}):n.push({id:r.id,when:r.offset-t,offset:0})));return n}function pi(e,t,n){return Math.abs(e-t)>1/n+1e-9}function mi(e,t){let n=Math.max(0,Math.floor(t)),r=new Float32Array(n),i=e.length;if(i===0)return r;for(let t=0;t<n;t++){let a=Math.min(i-1,Math.floor(t*i/n)),o=Math.min(i,Math.max(a+1,Math.floor((t+1)*i/n))),s=0;for(let t=a;t<o;t++){let n=Math.abs(e[t]);n>s&&(s=n)}r[t]=s}return r}function hi(e,t){let n=new Float32Array(Math.max(0,Math.floor(t)));for(let r of e){let e=mi(r,t);for(let t=0;t<n.length;t++)e[t]>n[t]&&(n[t]=e[t])}return n}function gi(e){return Math.min(si,Math.max(1,Math.round(e*50)))}function _i(e,t){return!t||e!==null&&e>vi}var vi=900;function yi(e){vi=e??900}function bi(e){return e!==null&&e>3456e5}function xi(e,t,n,r=1/0,i=oi){return e<0||e>=t?n.paused?`none`:`pause`:n.paused?`play`:n.seeking||n.readyState!==void 0&&n.readyState<3||r<.25?`none`:Math.abs(n.time-e)>i?`seek`:`none`}function Si(e,t){return e.map(e=>e.duration>0?e:{...e,duration:t[ii(e)]??0})}function Ci(e,t){if(e!==null&&e>0)return e;let n=0;for(let e of t)e.duration>0&&(n=Math.max(n,e.offset+e.duration));return n}var wi=null;function Ti(e,t){let n=wi,r={owner:e,stop:t};if(wi=r,n&&n.owner!==e)try{n.stop()}catch{}return()=>{wi===r&&(wi=null)}}function Ei(e){wi&&wi.owner===e&&(wi=null)}function Di(e){return e.replace(/&/g,`&`).replace(/</g,`<`).replace(/>/g,`>`).replace(/"/g,`"`).replace(/'/g,`'`)}function Oi(e){let t=[],n=e.replace(/`([^`]+)`/g,(e,n)=>(t.push(`<code>${n}</code>`),`\u0000${t.length-1}\u0000`));return n=n.replace(/\[([^\][]*)\]\((?:[^()]|\([^()]*\))*\)/g,`$1`),n=n.replace(/\*\*([^*]+)\*\*/g,`<strong>$1</strong>`),n=n.replace(/\*([^*]+)\*/g,`<em>$1</em>`),n=n.replace(/\u0000(\d+)\u0000/g,(e,n)=>t[Number(n)]),n}function ki(e){let t=/^( *)([-*]|\d+\.)[ \t]+(.*)$/.exec(e);return t?{indent:t[1].length,ordered:/\d/.test(t[2]),content:t[3]}:null}function Ai(e){let t=/^>\s?(.*)$/.exec(e);return t?t[1]:null}function ji(e){let t=Di(e).split(/\r\n|\r|\n|\u2028|\u2029/),n=[],r=[],i=null,a=()=>{r.length&&(n.push(`<p>${Oi(r.join(` `))}</p>`),r=[])},o=()=>{if(i){let e=i.ordered?`ol`:`ul`;n.push(`<${e}>${i.items.map(e=>`<li>${e}</li>`).join(``)}</${e}>`),i=null}},s=0;for(;s<t.length;){let e=t[s];if(/^```/.test(e)){a(),o();let e=[];for(s++;s<t.length&&!/^```/.test(t[s]);)e.push(t[s]),s++;s++,n.push(`<pre><code>${e.join(`
|
|
2
|
+
`)}</code></pre>`);continue}let c=/^(#{1,3})[ \t]+(.*)$/.exec(e);if(c){a(),o();let e=c[1].length;n.push(`<h${e}>${Oi(c[2])}</h${e}>`),s++;continue}let l=Ai(e);if(l!==null){a(),o();let e=[l];s++;let r;for(;s<t.length&&(r=Ai(t[s]))!==null;)e.push(r),s++;n.push(`<blockquote><p>${Oi(e.join(` `))}</p></blockquote>`);continue}let u=ki(e);if(u&&u.indent<2){a(),(!i||i.ordered!==u.ordered)&&(o(),i={ordered:u.ordered,items:[]});let e=Oi(u.content);s++;let n=[],r;for(;s<t.length&&(r=ki(t[s]))&&r.indent>=2;)n.push(r),s++;if(n.length){let t=n[0].ordered?`ol`:`ul`;e+=`<${t}>${n.map(e=>`<li>${Oi(e.content)}</li>`).join(``)}</${t}>`}i.items.push(e);continue}if(e.trim()===``){a(),o(),s++;continue}o(),r.push(e),s++}return a(),o(),n.join(`
|
|
3
|
+
`)}var Mi=/[\p{L}\p{N}]/u,Ni=/\s/,Pi=/[_\-/]/,Fi=/[\s,;:.\-–—(_/]+$/u,Ii=/^[\p{M}\u200d\ufe0f\u{1F3FB}-\u{1F3FF}\u{E0020}-\u{E007F}]$/u,Li=/^[\u{1F1E6}-\u{1F1FF}]$/u,Ri=/[\uD800-\uDFFF]/gu,zi=/[\p{Cc}\p{Zl}\p{Zp}]+/gu,Bi=/(?![\u200c\u200d\u{E0000}-\u{E007F}])\p{Cf}/gu,Vi=/(\u{1F3F4})([\u{E0000}-\u{E007F}]*)|[\u{E0000}-\u{E007F}]+/gu,Hi=/^[\p{Cf}\s\u034f\u115f\u1160\u17b4\u17b5\u2800\u3164\uffa0]*$/u;function Ui(e){let t=e.replace(Ri,`�`).replace(zi,` `).replace(Bi,``).replace(Vi,(e,t,n)=>t?t+n:``).replace(/\s+/g,` `).trim();return Hi.test(t)?``:t}function Wi(e){let t=[],n=!1,r=0;for(let i of e){let e=t.length-1;e>=0&&(n||Ii.test(i)||Li.test(i)&&r===1)?(t[e]+=i,r=Li.test(i)?r+1:r):(t.push(i),r=+!!Li.test(i)),n=i===``}return t}function Gi(e,t){for(let n=e.length-1;n>0;n--)if(t.test(e[n]))return n;return-1}function Ki(e,t){if(e.length<=t)return e;let n=Array.from(e);if(n.length<=t)return e;let r=Wi(n.slice(0,t+32)),i=[],a=0;for(let e of r){let n=Array.from(e).length;if(a+n>t-1)break;i.push(e),a+=n}let o=r.length>0?Array.from(r[0])[0]:``;if(i.length===0&&t>1&&o&&!Ii.test(o))return o+`…`;let s=i.length,c=r[i.length];if(c!==void 0&&!Ni.test(c)){let e=Gi(i,Ni);e<=0&&(e=Gi(i,Pi)),e>0&&(s=e)}return i.slice(0,s).join(``).replace(Fi,``)+`…`}var qi=[`;`,`. `,` — `,` (`],Ji=12;function Yi(e,t){let n=0,r=0;for(let i of e){if(r++>=t)break;n+=i.length}return n}function Xi(e,t){let n=Yi(e,Math.max(0,Ji-t)),r=e.length;for(let t of qi){let i=e.indexOf(t,n);i>=0&&i<r&&(r=i)}return e.slice(0,r).trim()}function Zi(e){let t=e.split(/[\\/]/).pop()??``,n=t.lastIndexOf(`.`);return Ui(n>0?t.slice(0,n):t)}var Qi=new Map;function $i(e){let t=e.replace(/^0+/,``)||`0`,n=Qi.get(t);return n||(Qi.size>=2e3&&Qi.clear(),n=ea(t),Qi.set(t,n)),n}function ea(e){return RegExp(`^v0*${e}(?![\\p{L}\\p{N}])(?:(?:\\s*[:,\\-–—]|\\.(?=\\s|$))[\\s:,.\\-–—]*|\\s*$|\\s+(?=\\(batch\\b))`,`iu`)}var ta=e=>e!==``&&e!==`…`;function na(e){let t=Ki(Ui(e.label??``),48);if(ta(t))return t;let n=Ui(e.note??``),r=n,i=/^v(\d+)$/i.exec(e.id)?.[1];i!==void 0&&(r=r.replace($i(i),``)),r=r.replace(/^\(batch\b[^)]*\)\s*:?\s*/i,``);let a=Array.from(n.slice(0,n.length-r.length)).length;if(r=Xi(r,a),Mi.test(r)){let e=Ki(r,48);if(ta(e))return e}let o=Ki(Zi(e.file),48);if(ta(o))return o;let s=Ki(Ui(e.id),48);return ta(s)?s:`Untitled`}var ra={script:`Script`,picture:`Picture`,voice:`Voice`,music:`Music`,sfx:`Sound effects`,mix:`Mix`,visuals:`Visuals`,notes:`Notes`,assets:`Files`,project:`Project`},ia=[`Sunday`,`Monday`,`Tuesday`,`Wednesday`,`Thursday`,`Friday`,`Saturday`],aa=[`January`,`February`,`March`,`April`,`May`,`June`,`July`,`August`,`September`,`October`,`November`,`December`],oa=e=>String(e).padStart(2,`0`),sa=e=>Number.isFinite(e.getTime());function ca(e,t){let n=Date.parse(e);if(!Number.isFinite(n))return null;let r=new Date(n),i=e=>Date.UTC(e.getFullYear(),e.getMonth(),e.getDate())/864e5;return i(t)-i(r)}function la(e){return sa(e)?`${oa(e.getHours())}:${oa(e.getMinutes())}`:`--:--`}function ua(e){return`${e.getFullYear()}-${oa(e.getMonth()+1)}-${oa(e.getDate())}`}function da(e,t,n){if(!sa(e))return`Date unknown`;if(!n)return`${ia[e.getDay()]} ${e.getDate()} ${aa[e.getMonth()]} ${e.getFullYear()}`;let r=ca(e.toISOString(),t);if(r===0)return`Today`;if(r===1)return`Yesterday`;let i=e.getFullYear()===t.getFullYear()?``:` ${e.getFullYear()}`;return`${ia[e.getDay()].slice(0,3)} ${e.getDate()} ${aa[e.getMonth()].slice(0,3)}${i}`}function fa(e){return!e||!((e.label??``).trim()||e.note.trim())?null:na(e)}var pa=[`January`,`February`,`March`,`April`,`May`,`June`,`July`,`August`,`September`,`October`,`November`,`December`];function ma(e,t){let n=ca(e,t);if(n===null)return null;let r=Math.max(0,(t.getTime()-Date.parse(e))/1e3);return r<60?{just:!0}:r<3600?{n:Math.floor(r/60),unit:`minute`}:n<=0?{n:Math.floor(r/3600),unit:`hour`}:n===1?{yesterday:!0}:n<7?{n,unit:`day`}:{date:new Date(Date.parse(e))}}function ha(e,t,n){if(!e)return``;if(`just`in e)return`just now`;if(`yesterday`in e)return`yesterday`;if(`date`in e){let r=e.date,i=n?pa[r.getMonth()].slice(0,3):pa[r.getMonth()];return`${r.getDate()} ${i}${r.getFullYear()===t.getFullYear()?``:` ${r.getFullYear()}`}`}return e.unit===`day`?`${e.n} days ago`:n?`${e.n} ${e.unit===`minute`?`min`:`h`} ago`:`${e.n} ${e.unit}${e.n===1?``:`s`} ago`}function ga(e,t){return ha(ma(e,t),t,!0)}function _a(e,t){return ha(ma(e,t),t,!1)}function va(e,t){let n=e=>e.replace(/^v/i,``);return e.find(e=>n(e)===t)??e.find(e=>n(e).startsWith(t))??null}function ya(e,t,n,r=!1){return n<=0?null:e===`ArrowDown`||r&&e===`ArrowRight`?t<0?0:(t+1)%n:e===`ArrowUp`||r&&e===`ArrowLeft`?t<0?n-1:(t-1+n)%n:e===`Home`?0:e===`End`?n-1:null}function ba(e,t){let n=[];e.duration!==null&&n.push(`${e.duration.toFixed(1)} s`),n.push(e.shots.length===0?`no shots`:`${e.shots.length} shot${e.shots.length===1?``:`s`}`);let r=ga(e.addedAt,t);return r&&n.push(r),n.join(` · `)}var xa=0;Array.isArray;function Q(e,n,r,i,a,o){n||={};var s,c,l=n;if(`ref`in l)for(c in l={},n)c==`ref`?s=n[c]:l[c]=n[c];var u={type:e,props:l,key:r,ref:s,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:--xa,__i:-1,__u:0,__source:a,__self:o};if(typeof e==`function`&&(s=e.defaultProps))for(c in s)l[c]===void 0&&(l[c]=s[c]);return t.vnode&&t.vnode(u),u}var Sa={circle:`<circle cx="12" cy="12" r="8"/>`,chev:`<path d="M6 9l6 6 6-6"/>`,story:`<rect x="3" y="4" width="11" height="8" rx="1.5"/><rect x="16" y="4" width="5" height="8" rx="1.5"/><rect x="3" y="14" width="5" height="6" rx="1.5"/><rect x="10" y="14" width="11" height="6" rx="1.5"/>`,brief:`<path d="M9 4h6v3H9z"/><path d="M7 5.5H6a1 1 0 0 0-1 1V20a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1V6.5a1 1 0 0 0-1-1h-1"/><path d="M9 12h6M9 16h4"/>`,kbd:`<rect x="2.5" y="6" width="19" height="12" rx="2.5"/><path d="M6.5 10h1M10.5 10h1M14.5 10h1M8 14h8"/>`,x:`<path d="M6 6l12 12M18 6L6 18"/>`,copy:`<rect x="9" y="9" width="11" height="11" rx="2"/><path d="M5 15V6a2 2 0 0 1 2-2h8"/>`,script:`<path d="M14 3H7a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V8z"/><path d="M14 3v5h5M9 13h6M9 17h4"/>`,film:`<rect x="3" y="4" width="18" height="16" rx="2.5"/><path d="M7 4v16M17 4v16M3 9h4M3 15h4M17 9h4M17 15h4"/>`,mic:`<rect x="9" y="3" width="6" height="11" rx="3"/><path d="M5 11a7 7 0 0 0 14 0M12 18v3"/>`,music:`<path d="M9 18V5l11-2v13"/><circle cx="6" cy="18" r="3"/><circle cx="17" cy="16" r="3"/>`,zap:`<path d="M13 3L5 13h6l-1 8 8-10h-6z"/>`,sliders:`<path d="M5 21v-7M5 10V3M12 21v-9M12 8V3M19 21v-5M19 12V3M2 14h6M9 8h6M16 16h6"/>`,lock:`<rect x="5" y="11" width="14" height="10" rx="2"/><path d="M8 11V8a4 4 0 0 1 8 0v3"/>`,unlock:`<rect x="5" y="11" width="14" height="10" rx="2"/><path d="M8 11V7a4 4 0 0 1 8 0v1"/>`,play:`<path d="M7 4.5v15l12-7.5z" fill="currentColor" stroke="none"/>`,pause:`<path d="M8 5v14M16 5v14"/>`,prev:`<path d="M15 6l-6 6 6 6"/>`,next:`<path d="M9 6l6 6-6 6"/>`,in:`<path d="M10 5H6v14h4"/><path d="M14 12h6M17 9l3 3-3 3"/>`,out:`<path d="M14 5h4v14h-4"/><path d="M4 12h6M7 9l3 3-3 3"/>`,box:`<path d="M4 8V5a1 1 0 0 1 1-1h3M16 4h3a1 1 0 0 1 1 1v3M20 16v3a1 1 0 0 1-1 1h-3M8 20H5a1 1 0 0 1-1-1v-3"/>`,camera:`<path d="M4 8h3l2-3h6l2 3h3a1 1 0 0 1 1 1v9a1 1 0 0 1-1 1H4a1 1 0 0 1-1-1V9a1 1 0 0 1 1-1z"/><circle cx="12" cy="13" r="3.5"/>`,check:`<path d="M5 12.5l4.5 4.5L19 7.5"/>`,flag:`<path d="M5 21V4M5 4h11l-2 4 2 4H5"/>`,undo:`<path d="M9 14L4 9l5-5"/><path d="M4 9h10a6 6 0 0 1 0 12h-3"/>`,send:`<path d="M5 12h14M13 6l6 6-6 6"/>`,reply:`<path d="M5 4v7a4 4 0 0 0 4 4h11"/><path d="M16 11l4 4-4 4"/>`,image:`<rect x="3" y="4" width="18" height="16" rx="2.5"/><circle cx="9" cy="10" r="2"/><path d="M21 16l-5-5-9 9"/>`,alert:`<path d="M12 3l9.5 17h-19z"/><path d="M12 10v4M12 17h.01"/>`,new:`<path d="M12 19V5M5 12l7-7 7 7"/>`,grid:`<rect x="3" y="3" width="8" height="8" rx="1.5"/><rect x="13" y="3" width="8" height="8" rx="1.5"/><rect x="3" y="13" width="8" height="8" rx="1.5"/><rect x="13" y="13" width="8" height="8" rx="1.5"/>`,download:`<path d="M12 4v11M7.5 11.5L12 16l4.5-4.5"/><path d="M5 19h14"/>`,save:`<path d="M5 4h11l3 3v13H5z"/><path d="M8 4v5h7V4"/><path d="M8 14h8v6H8z"/>`,folder:`<path d="M3 7a2 2 0 0 1 2-2h4l2 2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z"/>`,list:`<path d="M8 6h13M8 12h13M8 18h13"/><circle cx="3.5" cy="6" r="1.2" fill="currentColor" stroke="none"/><circle cx="3.5" cy="12" r="1.2" fill="currentColor" stroke="none"/><circle cx="3.5" cy="18" r="1.2" fill="currentColor" stroke="none"/>`,open:`<path d="M10 14L20 4"/><path d="M14 4h6v6"/><path d="M19 13v6a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"/>`,search:`<circle cx="10.5" cy="10.5" r="6.5"/><path d="M20 20l-5-5"/>`,eyeoff:`<path d="M3 3l18 18M10.6 6.1A10 10 0 0 1 12 6c5 0 9 6 9 6a17 17 0 0 1-3.2 3.7M6.6 6.6A17 17 0 0 0 3 12s4 6 9 6a9 9 0 0 0 4.4-1.1"/><path d="M9.9 9.9a3 3 0 0 0 4.2 4.2"/>`,gauge:`<path d="M4 17a8 8 0 1 1 16 0"/><path d="M12 17l3.5-5"/>`,trash:`<path d="M4 7h16M10 11v6M14 11v6"/><path d="M6 7l1 13h10l1-13M9 7V4h6v3"/>`,refresh:`<path d="M20 12a8 8 0 1 1-2.6-5.9"/><path d="M20 4v4h-4"/>`,stream:`<path d="M3 12h2l2-5 3 10 3-14 3 12 2-3h3"/>`,more:`<circle cx="5" cy="12" r="1.3"/><circle cx="12" cy="12" r="1.3"/><circle cx="19" cy="12" r="1.3"/>`,shelve:`<rect x="3" y="4" width="18" height="5" rx="1.5"/><path d="M5 9v9a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V9M10 13h4"/>`};function $({name:e,class:t}){return Q(`svg`,{class:`ic${t?` ${t}`:``}`,viewBox:`0 0 24 24`,"aria-hidden":`true`,dangerouslySetInnerHTML:{__html:Sa[e]??``}})}var Ca={script:`script`,picture:`film`,voice:`mic`,music:`music`,sfx:`zap`,mix:`sliders`,visuals:`image`},wa=typeof window<`u`&&`showSaveFilePicker`in window;function Ta(){let e=navigator.userAgent;return/Mac/.test(e)?`Show in Finder`:/Windows/.test(e)?`Show in Explorer`:`Open folder`}function Ea(e){return e?new Date(e).toLocaleDateString(void 0,{day:`numeric`,month:`short`,year:`numeric`}):``}function Da({asset:e,toast:t}){let[n,r]=q(!1),i=!e.missing&&$e.has(tt(e.path)),a=async()=>{if(n)return;r(!0);let i;try{let t=await window.showSaveFilePicker({suggestedName:e.name}),n=await fetch(Gr(e.path));if(!n.ok||!n.body)throw Error(`Couldn't read ${e.name}`);i=await t.createWritable(),await n.body.pipeTo(i)}catch(n){i&&await i.abort().catch(()=>void 0),n.name!==`AbortError`&&t(n.message||`Couldn't save ${e.name}`)}finally{r(!1)}},o=async()=>{try{await Z.post(`/api/reveal`,{path:e.path})}catch(e){t(e.message)}},s=async()=>{try{await navigator.clipboard.writeText(e.abs),t(`Path copied`)}catch{t(`Couldn't reach the clipboard`)}},c=async()=>{try{await Z.post(`/api/open`,{path:e.path})}catch(e){t(e.message)}};return Q(`div`,{class:`aact`,children:[Q(`a`,{class:`btn ghost ib`,"data-tip":`Download`,"aria-label":`Download`,"aria-disabled":e.missing,tabIndex:e.missing?-1:void 0,href:`${Gr(e.path)}&download=1`,download:e.name,onClick:t=>{e.missing&&t.preventDefault()},children:Q($,{name:`download`})}),wa&&Q(`button`,{class:`btn ghost ib`,"data-tip":`Save as…`,"aria-label":`Save as…`,"aria-disabled":e.missing||n,tabIndex:e.missing?-1:void 0,onClick:()=>{e.missing||a()},children:Q($,{name:`save`})}),i&&Q(`button`,{class:`btn ghost ib`,"data-tip":`Open`,"aria-label":`Open`,onClick:()=>void c(),children:Q($,{name:`open`})}),Q(`button`,{class:`btn ghost ib`,"data-tip":Ta(),"aria-label":Ta(),"aria-disabled":e.missing,tabIndex:e.missing?-1:void 0,onClick:()=>{e.missing||o()},children:Q($,{name:`folder`})}),Q(`button`,{class:`btn ghost ib`,"data-tip":`Copy path`,"aria-label":`Copy path`,"aria-disabled":e.missing,tabIndex:e.missing?-1:void 0,onClick:()=>{e.missing||s()},children:Q($,{name:`copy`})})]})}function Oa({tip:e=`Missing`}){return Q(`span`,{class:`amiss`,"data-tip":e,"aria-label":e,children:`●`})}function ka(e,t){let n=t.find(t=>t.id===e.video),r=n?.versions.find(t=>t.id===e.version),i=n&&e.version?`${n.name} · ${e.version}`:e.label??e.name;return{title:e.formatLabel?`${i} · ${e.formatLabel}`:i,subtitle:Aa(e)?null:fa(r)}}function Aa(e){return e.kind===`cut`&&e.format!==void 0}function ja({asset:e,videos:t,toast:n}){let r=e.kind===`cut`||e.kind===`delivery`?ka(e,t):null;return Q(`div`,{class:`arow${e.missing?` missing`:``}${Aa(e)?` sub`:``}`,children:[Q(`div`,{class:`ainfo`,children:[Q(`div`,{class:`atitle`,children:[r?r.title:e.label??e.name,e.missing&&Q(Oa,{})]}),r?.subtitle&&Q(`div`,{class:`asub`,children:r.subtitle}),Q(`div`,{class:`afolder mono`,children:e.path}),!e.missing&&Q(`div`,{class:`ameta`,children:[Ze(e.size??0),` · `,Ea(e.modified)]})]}),Q(Da,{asset:e,toast:n})]})}function Ma({asset:e,toast:t,onChanged:n}){let[r,i]=q(!1),[a,o]=q(!1),s=X(null);J(()=>{r&&s.current?.focus()},[r]);let c=async()=>{if(!a&&e.video&&e.version){o(!0);try{await Z.del(`/api/videos/${encodeURIComponent(e.video)}/versions/${encodeURIComponent(e.version)}/proxy`),n()}catch(e){t(e.message),i(!1)}finally{o(!1)}}};return Q(`div`,{class:`arow${e.missing?` missing`:``}`,children:[Q(`div`,{class:`ainfo`,children:[Q(`div`,{class:`atitle`,children:[e.name,e.missing&&Q(Oa,{})]}),Q(`div`,{class:`afolder mono`,children:e.path}),!e.missing&&Q(`div`,{class:`ameta`,children:On(e)})]}),Q(Da,{asset:e,toast:t}),r?Q(`div`,{class:`aconfirm`,role:`group`,"aria-label":`Delete this proxy?`,onKeyDown:e=>{e.key===`Escape`&&(e.stopPropagation(),i(!1))},children:[Q(`button`,{ref:s,type:`button`,class:`btn danger`,"aria-disabled":a,onClick:()=>void c(),children:`Delete`}),Q(`button`,{type:`button`,class:`btn ghost`,onClick:()=>i(!1),children:`Keep`})]}):Q(`button`,{type:`button`,class:`btn ghost ib`,"data-tip":`Delete proxy (the original is kept)`,"aria-label":`Delete proxy`,onClick:()=>i(!0),children:Q($,{name:`trash`})})]})}function Na({asset:e,playing:t,paused:n,onToggle:r,videos:i,toast:a}){let o=t&&!n,s=e.label??e.name,c=Qe(e.laneName,e.meta);return Q(`div`,{class:`arow${e.missing?` missing`:``}`,children:[Q(`button`,{type:`button`,class:`btn ghost ib`,"data-tip":o?`Pause`:`Play`,"aria-label":`Play ${s}`,"aria-pressed":o,"aria-disabled":e.missing,tabIndex:e.missing?-1:void 0,onClick:()=>{e.missing||r(e)},children:Q($,{name:o?`pause`:`play`})}),Q(`div`,{class:`ainfo`,children:[Q(`div`,{class:`atitle`,children:[s,e.missing&&Q(Oa,{})]}),c&&Q(`div`,{class:`atrackmeta`,children:c}),Q(`div`,{class:`afolder mono`,children:e.path}),!e.missing&&Q(`div`,{class:`ameta`,children:[Ze(e.size??0),` · `,Ea(e.modified)]})]}),Q(Da,{asset:e,toast:a})]})}function Pa({asset:e,selected:t,onSelect:n,videos:r,toast:i}){return Q(`div`,{class:`arow previewable${e.missing?` missing`:``}${t?` selected`:``}`,children:[Q(`div`,{class:`ainfo`,children:[Q(`button`,{type:`button`,class:`aselect atitle`,"aria-pressed":t,onClick:n,children:[e.label??e.name,e.missing&&Q(Oa,{})]}),e.note&&Q(`div`,{class:`asub`,children:e.note}),Q(`div`,{class:`afolder mono`,children:e.path}),!e.missing&&Q(`div`,{class:`ameta`,children:[Ze(e.size??0),` · `,Ea(e.modified)]})]}),Q(Da,{asset:e,toast:i})]})}function Fa({asset:e,videos:t,toast:n,onOpen:r}){let i=t.find(t=>t.id===e.video),a=e.t!==void 0&&e.frame!==void 0?`${U(e.t)} · f${e.frame}`:e.label??e.name,o=i&&e.version?`${i.name} · ${e.version}`:null;return Q(`div`,{class:`shot-tile${e.missing?` missing`:``}`,children:[Q(`button`,{type:`button`,class:`shot-thumb`,"aria-label":`Open ${e.name} full size`,onClick:e=>r(e.currentTarget),children:Q(`img`,{src:Gr(e.path),alt:e.name,loading:`lazy`})}),Q(`div`,{class:`shot-meta`,children:[Q(`div`,{class:`mono`,children:[a,e.missing&&Q(Oa,{})]}),o&&Q(`div`,{class:`asub`,children:o})]}),Q(Da,{asset:e,toast:n})]})}function Ia({asset:e}){let t=X(null),[n,r]=q(!1);return J(()=>{let e=t.current;if(!e)return;if(typeof IntersectionObserver>`u`){r(!0);return}let n=new IntersectionObserver(e=>{e.some(e=>e.isIntersecting)&&(r(!0),n.disconnect())},{rootMargin:`200px`});return n.observe(e),()=>n.disconnect()},[]),Q(`video`,{ref:t,muted:!0,preload:`metadata`,src:n?`${Gr(e.path)}#t=0.5`:void 0,"aria-label":`${e.name} poster frame`})}function La({asset:e,videos:t,toast:n}){let{title:r,subtitle:i}=ka(e,t),a=et.has(tt(e.path));return Q(`div`,{class:`shot-tile${e.missing?` missing`:``}${Aa(e)?` sub`:``}`,children:[Q(`div`,{class:`shot-thumb poster`,children:!e.missing&&(a?Q(Ia,{asset:e}):Q(`div`,{class:`file-tile`,children:Q(`span`,{class:`file-ext mono`,children:tt(e.path)||`file`})}))}),Q(`div`,{class:`shot-meta`,children:[Q(`div`,{class:`atitle`,children:[r,e.missing&&Q(Oa,{})]}),i&&Q(`div`,{class:`asub`,children:i}),Q(`div`,{class:`afolder mono`,children:e.path})]}),Q(Da,{asset:e,toast:n})]})}function Ra(e){return Array.from(e.querySelectorAll(`a[href], button, [tabindex]`)).filter(e=>{if(e.disabled)return!1;let t=e.getAttribute(`tabindex`);return t===null||Number(t)>=0})}function za({asset:e,onClose:t,toast:n}){let r=X(null),i=X(null);return J(()=>{i.current?.focus()},[]),Q(`div`,{class:`lightbox`,role:`dialog`,"aria-modal":`true`,"aria-label":e.name,ref:r,onKeyDown:e=>{if(e.key===`Escape`){e.stopPropagation(),t();return}if(e.key!==`Tab`||!r.current)return;let n=Ra(r.current);if(n.length===0)return;let i=n[0],a=n[n.length-1];e.shiftKey&&document.activeElement===i?(e.preventDefault(),a.focus()):!e.shiftKey&&document.activeElement===a&&(e.preventDefault(),i.focus())},onClick:e=>{e.target===e.currentTarget&&t()},children:Q(`div`,{class:`lbinner`,children:[Q(`img`,{src:Gr(e.path),alt:e.name}),Q(`div`,{class:`lbactions`,children:[Q(Da,{asset:e,toast:n}),Q(`button`,{ref:i,class:`btn ghost ib`,"aria-label":`Close`,onClick:t,children:Q($,{name:`x`})})]})]})})}var Ba=60,Va=`Up to 12 files of each kind at a time, so the tabs stay quick. Each voiceover folder becomes its own round.`,Ha=An.filter(e=>e!==`cut`),Ua=e=>e.slice(e.lastIndexOf(`/`)+1),Wa=e=>`Couldn't be added: ${e.replace(/\.$/,``).replace(/^(\p{Lu})(?=\p{Ll})/u,e=>e.toLowerCase())}`,Ga={voice:`var(--vo)`,music:`var(--music)`,sfx:`var(--sfx)`,other:`var(--text-3)`,cut:`var(--accent)`,doc:`var(--text-3)`};function Ka({kind:e}){return Q(`i`,{class:`kdot`,style:{background:e?Ga[e]:`var(--text-3)`}})}function qa({path:e,name:t,playing:n,onPlay:r}){return Q(`button`,{type:`button`,class:`fplay`,"aria-label":`Play ${t}`,"aria-pressed":n,"data-tip":n?`Pause`:`Play`,onClick:()=>r(e,t),children:Q($,{name:n?`pause`:`play`})})}function Ja({row:e,playing:t,onPlay:n}){return Q(`div`,{class:`frow in`,children:[Q(`span`,{}),e.playable?Q(qa,{path:e.path,name:e.name,playing:t,onPlay:n}):Q(`span`,{}),Q(`div`,{class:`fnm`,children:[Q(`b`,{class:`fname`,dir:`auto`,title:e.path,children:e.name}),e.reasons&&Q(`small`,{class:`freasons`,children:e.reasons})]}),Q(`span`,{class:`kind static`,title:e.label,children:[Q(Ka,{kind:e.kind}),Q(`span`,{class:`klabel`,children:e.label})]}),Q(`span`,{}),Q(`span`,{})]})}var Ya=class extends C{shouldComponentUpdate(e){return Jn(this.props,e)}render({item:e,kind:t,ticked:n,playing:r,failure:i,onTick:a,onKind:o,onPlay:s}){let c=Ua(e.path),l=e.kind===`cut`;return Q(`div`,{class:`frow${n?` on`:``}`,"data-path":e.path,children:[Q(`input`,{type:`checkbox`,"aria-label":`Tick ${c}`,checked:n,onChange:t=>a(e.path,t.target.checked)}),l?Q(`span`,{}):Q(qa,{path:e.path,name:c,playing:r,onPlay:s}),Q(`div`,{class:`fnm`,children:[Q(`b`,{class:`fname`,dir:`auto`,title:e.path,children:c}),e.reasons.length>0&&Q(`small`,{class:`freasons`,children:e.reasons.join(` · `)}),i&&Q(`small`,{class:`ffail`,children:Wa(i)})]}),l?Q(`span`,{class:`kind static`,children:[Q(Ka,{kind:`cut`}),jn.cut]}):Q(`label`,{class:`kind`,children:[Q(Ka,{kind:t}),Q(`select`,{"aria-label":`Kind of ${c}`,value:t,onChange:t=>o(e.path,t.target.value),children:Ha.map(e=>Q(`option`,{value:e,children:jn[e]}))}),Q($,{name:`chev`,class:`kchev`})]}),Q(`span`,{class:`fdur mono`,children:Wn(e.duration)}),Q(`span`,{class:`fsize mono`,children:Ze(e.size)})]})}};function Xa(e,t){let n=e.findIndex(e=>t.has(e));if(n===-1)return null;for(let r=n+1;r<e.length;r++)if(!t.has(e[r]))return e[r];for(let r=n-1;r>=0;r--)if(!t.has(e[r]))return e[r];return null}function Za({state:e,initialKind:t=`all`,playing:n,onPlay:r,onStop:i,toast:a,onChanged:o,onSeen:s}){let c=e.found,[l,u]=q(null),[d,f]=q(null),[p,m]=q(new Set),[h,g]=q({}),[_,v]=q({}),[y,b]=q(``),[x,S]=q(t),[C,w]=q(new Set),[T,E]=q(!0),[D,O]=q(!1),[k,A]=q(!1),[j,M]=q(!1),[N,P]=q([]),F=X(null),ee=X(null),I=X(!1),L=X(null),te=X({onPlay:r,onStop:i});te.current={onPlay:r,onStop:i};let ne=Mr((e,t)=>te.current.onPlay(e,t),[]),R=X(0),re=X(0),ie=async()=>{let e=++R.current;try{let t=await Z.get(`/api/found`);if(e<re.current)return;re.current=e,u(e=>{let n=Rn(e?.files??[],t.files??[]),r=t.hidden??[];return e&&n===e.files&&JSON.stringify(e.hidden)===JSON.stringify(r)?e:{files:n,hidden:r}}),f(null)}catch(t){e>=re.current&&f(t.message)}};J(()=>{ie()},[e]);let ae=In(c);J(()=>s(ae),[ae]);let oe=l?.files??[],z=l?.hidden??[],se=jr(()=>oe.map(e=>({...e,kind:h[e.path]??e.kind,raw:e})),[oe,h]),ce=jr(()=>Hn(se,x,y),[se,x,y]),B=jr(()=>Vn(ce),[ce]),le=jr(()=>Un(se),[se]);J(()=>{x!==`all`&&l&&!c.scanning&&!le.some(([e])=>e===x)&&S(`all`)},[le,l,c.scanning]);let ue=jr(()=>qn(e.project,c.broughtIn),[e.project,c.broughtIn]),de=jr(()=>B.filter(e=>!C.has(e.key)).flatMap(e=>e.files.map(e=>e.path)),[B,C]),V=jr(()=>new Set(de),[de]),fe=oe.filter(e=>p.has(e.path)),pe=fe.length,me=fe.filter(e=>V.has(e.path)),he=me.length,H=jr(()=>new Set([...ue.map(e=>e.path),...N]),[ue,N]);J(()=>{l&&n.path&&!n.paused&&(V.has(n.path)||T&&H.has(n.path)||te.current.onStop())},[l,n.path,n.paused,V,T,H]),J(()=>{let e=L.current;if(!e)return;let t=null;t=e===`search`?ee.current:`row`in e?F.current?.querySelector(`.frow[data-path="${CSS.escape(e.row)}"] input[type="checkbox"]`)??null:F.current?.querySelector(`.fhrow[data-path="${CSS.escape(e.restore)}"] button`)??null,t&&(t.focus(),L.current=null)});let U=Mr((e,t)=>{m(n=>{let r=new Set(n);return t?r.add(e):r.delete(e),r}),t||ge(e)},[]),ge=e=>v(t=>{if(!(e in t))return t;let{[e]:n,...r}=t;return r}),_e=Mr((e,t)=>{g(n=>({...n,[e]:t})),ge(e)},[]),W=e=>w(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),ve=e=>{let t=new Set(e),n=Xa(de,t);L.current=n===null?`search`:{row:n},re.current=++R.current,u(e=>e&&{...e,files:e.files.filter(e=>!t.has(e.path))}),m(e=>new Set([...e].filter(e=>!t.has(e))))},ye=async()=>{if(I.current||pe===0)return;I.current=!0,A(!0);let e=fe.slice(0,Ba);try{let t=await Z.post(`/api/found/bring-in`,{files:e.map(e=>{let t=h[e.path]??e.kind;return t===`other`?{path:e.path}:{path:e.path,kind:t}})});ve([...t.added.map(e=>e.path),...t.failed.filter(e=>e.code===`already`).map(e=>e.path)]),P(e=>[...e,...t.added.map(e=>e.path)]),v(e=>{let n={...e};for(let e of t.added)delete n[e.path];for(let e of t.failed)e.code!==`already`&&(n[e.path]=e.reason);return n});let n=fe.length-e.length,r=Kn(t.added.length,t.failed)+(n>0?` ${n} more ${n===1?`is`:`are`} still ticked.`:``);a(r,r.length>48?6500:void 0),o()}catch(e){a(e.message)}finally{I.current=!1,A(!1)}},be=async()=>{if(I.current||he===0)return;I.current=!0,A(!0);let e=me.map(e=>e.path);try{await Z.post(`/api/found/dismiss`,{paths:e}),ve(e),a(`Hid ${e.length} ${e.length===1?`file`:`files`}`),o(),ie()}catch(e){a(e.message)}finally{I.current=!1,A(!1)}},xe=async e=>{let t=z.map(e=>e.path),n=t.indexOf(e),r=t[n+1]??t[n-1];try{await Z.post(`/api/found/restore`,{paths:[e]}),L.current=r===void 0?{row:e}:{restore:r},z.length<=1&&O(!1),o(),ie()}catch(e){a(e.message)}},Se=async()=>{if(!j){M(!0);try{await Z.post(`/api/found/scan`,{}),o()}catch(e){a(e.message)}finally{M(!1)}}},G=e=>n.path===e&&!n.paused,Ce=Mn(c.counts),we=c.scanning;return Q(`section`,{class:`amain found`,"aria-label":`Found files`,ref:F,children:[Q(`header`,{class:`aheader`,children:[Q(`h2`,{children:[`Found `,Q(`span`,{class:`count`,children:Ce})]}),Q(`div`,{class:`acontrols`,children:[Q(`label`,{class:`search-wrap`,children:[Q($,{name:`search`}),Q(`input`,{ref:ee,class:`search`,type:`search`,"aria-label":`Search found files`,placeholder:`Search found files`,value:y,onInput:e=>b(e.target.value)})]}),le.length>0&&Q(`div`,{class:`seg`,role:`group`,"aria-label":`Kind`,children:[Q(`button`,{type:`button`,"aria-pressed":x===`all`,onClick:()=>S(`all`),children:[`All `,Q(`span`,{class:`n`,children:oe.length})]}),le.map(([e,t])=>Q(`button`,{type:`button`,"aria-pressed":x===e,onClick:()=>S(e),children:[jn[e],` `,Q(`span`,{class:`n`,children:t})]},e))]}),Q(`button`,{type:`button`,class:`btn ib`,"aria-label":`Look again`,"aria-busy":we||j,"data-tip":`Look through the project folder again`,onClick:()=>void Se(),children:Q($,{name:`refresh`})}),Q(`button`,{type:`button`,class:`btn`,disabled:he===0||k,"data-tip":`Hide the ticked files for good. You can restore them from Hidden.`,onClick:()=>void be(),children:`Not these`}),Q(`button`,{type:`button`,class:`btn primary`,disabled:pe===0||k,onClick:()=>void ye(),children:pe>0?`Bring in ${pe}`:`Bring in`})]})]}),we&&Q(`p`,{class:`fscan`,"aria-live":`polite`,children:[Q(`span`,{class:`fspin`}),`Looking through the folder…`]}),d&&!l&&Q(`p`,{class:`aempty`,children:d}),ue.length>0&&Q(`div`,{class:`fcard in`,children:[Q(`button`,{type:`button`,class:`gh`,"aria-expanded":T,onClick:()=>E(e=>!e),children:[Q($,{name:`chev`,class:`chev`}),Q(`b`,{children:`Brought in with this cut`}),Q(`small`,{children:ue.length}),Q(`span`,{class:`fdone`,children:[Q($,{name:`check`}),`in the project`]})]}),T&&ue.map(e=>Q(Ja,{row:e,playing:G(e.path),onPlay:ne},e.path))]}),l===null?!d&&Q(`p`,{class:`aempty`,children:`Loading…`}):oe.length===0?!we&&Q(`p`,{class:`aempty`,children:`Nothing else found in this folder.`}):ce.length===0?Q(`p`,{class:`aempty`,children:`Nothing matches.`}):B.map(e=>{let t=!C.has(e.key);return Q(`div`,{class:`fcard fgroup`,children:[Q(`button`,{type:`button`,class:`gh`,"aria-expanded":t,onClick:()=>W(e.key),title:e.folder??void 0,children:[Q($,{name:`chev`,class:`chev`}),Q(`b`,{children:e.title}),Q(`small`,{children:e.files.length})]}),t&&e.files.map(e=>Q(Ya,{item:e.raw,kind:e.kind,ticked:p.has(e.path),playing:G(e.path),failure:_[e.path],onTick:U,onKind:_e,onPlay:ne},e.path))]},e.key)}),D&&z.length>0&&Q(`div`,{class:`fcard fhidden`,children:[Q(`p`,{class:`fhead`,children:[Q(`b`,{children:`Hidden`}),Q(`small`,{children:z.length})]}),z.map(e=>{let t=Ua(e.path);return Q(`div`,{class:`fhrow`,"data-path":e.path,children:[Q(`div`,{class:`fnm`,children:[Q(`b`,{class:`fname`,dir:`auto`,title:e.path,children:t}),Q(`small`,{class:`freasons`,children:zn(e.folder)})]}),Q(`button`,{type:`button`,class:`btn`,"aria-label":`Restore ${t}`,onClick:()=>void xe(e.path),children:[Q($,{name:`undo`}),`Restore`]})]},e.path)})]}),Q(`div`,{class:`ffoot`,children:[Q(`p`,{class:`foot`,children:Va}),z.length>0&&Q(`button`,{type:`button`,class:`flink`,"aria-expanded":D,onClick:()=>O(e=>!e),children:[`Hidden (`,z.length,`)`]})]})]})}var Qa=new Set([`voiceover`,`music`,`sfx`]),$a=new Set([`cut`,`delivery`]),eo=1048576;function to(e){return`rushes.assets.view.${e}`}function no(e){try{let t=localStorage.getItem(to(e));return t===`grid`||t===`list`?t:null}catch{return null}}function ro(e,t){try{localStorage.setItem(to(e),t)}catch{}}function io(e){return e?e.gridToggle?no(e.id)??e.view:`list`:`grid`}async function ao(e){let t=await fetch(Gr(e));if(!t.ok)throw Error(`Couldn't load ${e}`);if(!t.body)return{text:await t.text(),truncated:!1};let n=t.body.getReader(),r=new TextDecoder,i=``,a=0,o=!1;for(;;){let{done:e,value:t}=await n.read();if(e)break;if(a+=t.byteLength,a>eo){let e=t.byteLength-(a-eo);e>0&&(i+=r.decode(t.subarray(0,e),{stream:!0})),o=!0,await n.cancel().catch(()=>void 0);break}i+=r.decode(t,{stream:!0})}return i+=r.decode(),{text:i,truncated:o}}function oo({assets:e,videos:t,state:n,foundRequest:r,onFoundRequestUsed:i,onFoundSeen:a,toast:o,onChanged:s}){let c=jr(()=>nt.filter(t=>t.id===`export`||e.some(e=>t.kinds.includes(e.kind))),[e]),l=c.find(e=>e.id!==`export`)?.id,u=Fn(n.found)!==null,[d,f]=q(()=>r.pending?`found`:l??(u?`found`:c[0]?.id??`found`)),p=X(r.pending);J(()=>{if(d===`found`)return;let e=!!d&&c.some(e=>e.id===d);if(p.current&&e)return;let t=l??(e?d:c[0]?.id??`found`);t!==d&&f(t)},[c,d]);let[m,h]=q(()=>({key:0,kind:r.pending?r.kind:void 0})),g=e=>{p.current=!0,f(e)},_=X(r.pending?r.n:-1);J(()=>{r.pending&&(_.current!==r.n&&(_.current=r.n,g(`found`),h(e=>({key:e.key+1,kind:r.kind}))),i())},[r.n,r.pending]);let v=d===`found`,y=v?null:c.find(e=>e.id===d)??null,[b,x]=q(``),[C,w]=q(`newest`),[T,E]=q(null),[D,O]=q(()=>io(y)),k=X(y?.id??null);y&&y.id!==k.current&&(k.current=y.id,x(``),E(null),w(`newest`),O(io(y)));let A=jr(()=>y?ot(e,y,{query:b,sort:C,film:T,videos:t}):[],[e,y,b,C,T,t]),j=e=>{y&&y.gridToggle&&(O(e),ro(y.id,e))},[M,N]=q(null),P=X(null),F=(e,t)=>{P.current=t,N(e)},ee=()=>{N(null),P.current?.focus()},I=X(null),[L,te]=q({path:null,paused:!0}),ne=X({}),R=()=>{I.current?.pause(),Ei(ne.current),te({path:null,paused:!0})},re=(e,t)=>{let n=I.current;if(n){if(L.path===e&&!L.paused){n.pause(),Ei(ne.current),te({path:e,paused:!0});return}L.path!==e&&(n.src=Gr(e)),Ti(ne.current,()=>{I.current?.pause(),te(e=>({...e,paused:!0}))}),te({path:e,paused:!1}),n.play().catch(n=>{n instanceof Error&&n.name===`AbortError`||(Ei(ne.current),te({path:e,paused:!0}),o(`Couldn't play ${t}`))})}},ie=e=>re(e.path,e.label??e.name);J(()=>R,[d,T]),J(()=>R,[]),J(()=>{s()},[d]),J(()=>{let e=()=>{document.visibilityState===`visible`&&s()};return document.addEventListener(`visibilitychange`,e),()=>document.removeEventListener(`visibilitychange`,e)},[]);let[ae,oe]=q(null),[z,se]=q(null),ce=!!y&&rt.has(y.id);J(()=>{if(!ce){oe(null);return}ae&&A.some(e=>e.path===ae&&at(e))||oe(A.find(at)?.path??null)},[ce,A]),J(()=>{if(!ae){se(null);return}let e=!1;return se({loading:!0,text:``,truncated:!1}),ao(ae).then(t=>{e||se({loading:!1,text:t.text,truncated:t.truncated})}).catch(t=>{e||se({loading:!1,text:``,truncated:!1,error:t.message})}),()=>{e=!0}},[ae]);let B=e=>{if(e.key!==`ArrowDown`&&e.key!==`ArrowUp`)return;let t=e.currentTarget,n=Array.from(t.querySelectorAll(`.afolder-btn`)),r=n.indexOf(document.activeElement);if(r===-1)return;e.preventDefault();let i=n[r+(e.key===`ArrowDown`?1:-1)];i&&(i.focus(),i.click())},le=async()=>{try{await Z.post(`/api/reveal`,{project:!0})}catch(e){o(e.message)}},ue=async()=>{try{let{path:e}=await Z.post(`/api/exports/notes`);o(`Saved to ${e}`),s()}catch(e){o(e.message)}},de=t=>e.filter(e=>t.kinds.includes(e.kind)).length,V=()=>y?y.id===`screenshot`&&C!==`name`?ct(A,t).map((e,n)=>Q(`section`,{class:`afilm-group`,children:[e.heading&&Q(`h3`,{class:`afilm-heading`,children:e.heading}),Q(`div`,{class:`shots-grid`,children:e.items.map(e=>Q(Fa,{asset:e,videos:t,toast:o,onOpen:t=>F(e,t)},e.path))})]},e.heading??`_${n}`)):$a.has(y.id)?Q(`div`,{class:`shots-grid`,children:A.map(e=>Q(La,{asset:e,videos:t,toast:o},e.path))}):Q(`div`,{class:`shots-grid`,children:A.map(e=>Q(Fa,{asset:e,videos:t,toast:o,onOpen:t=>F(e,t)},e.path))}):null,fe=()=>y?Qa.has(y.id)?Q(`div`,{class:`arows`,children:A.map(e=>Q(Na,{asset:e,playing:L.path===e.path,paused:L.paused,onToggle:ie,videos:t,toast:o},e.path))}):y.id===`proxy`?Q(`div`,{class:`arows`,children:A.map(e=>Q(Ma,{asset:e,toast:o,onChanged:s},e.path))}):ce?Q(`div`,{class:`arows`,children:A.map(e=>Q(Pa,{asset:e,selected:ae===e.path,onSelect:()=>oe(e.path),videos:t,toast:o},e.path))}):Q(`div`,{class:`arows`,children:A.map(e=>Q(ja,{asset:e,videos:t,toast:o},e.path))}):null,pe=ae?(ae.split(`.`).pop()??``).toLowerCase():``,me=jr(()=>ji(z?.text??``),[z?.text]);return Q(`div`,{class:`assets-lib`,children:[Q(`nav`,{class:`asidebar`,"aria-label":`Folders`,onKeyDown:B,children:[Q(`button`,{type:`button`,class:`afolder-btn afound`,"aria-current":v?`true`:void 0,onClick:()=>{v||h(e=>({key:e.key+1})),g(`found`)},children:[Q(`span`,{children:`Found`}),Q(`span`,{class:`count`,children:Mn(n.found?.counts)})]}),c.map(e=>Q(`button`,{type:`button`,class:`afolder-btn`,"aria-current":e.id===d?`true`:void 0,onClick:()=>g(e.id),children:[Q(`span`,{children:e.title}),Q(`span`,{class:`count`,children:de(e)})]},e.id)),Q(`button`,{type:`button`,class:`afolder-root`,onClick:()=>void le(),children:[Q($,{name:`folder`}),`Project folder`]})]}),v?Q(Za,{state:n,initialKind:m.kind,playing:L,onPlay:re,onStop:R,toast:o,onChanged:s,onSeen:a},m.key):y?Q(`div`,{class:`amain`,children:[Q(`header`,{class:`aheader`,children:[Q(`h2`,{children:[y.title,` `,Q(`span`,{class:`count`,children:A.length})]}),Q(`div`,{class:`acontrols`,children:[Q(`label`,{class:`search-wrap`,children:[Q($,{name:`search`}),Q(`input`,{class:`search`,type:`search`,"aria-label":`Search`,placeholder:`Search`,value:b,onInput:e=>x(e.target.value)})]}),y.filmFilter&&Q(`select`,{class:`sel`,"aria-label":`Film`,value:T??``,onChange:e=>E(e.target.value||null),children:[Q(`option`,{value:``,children:`All films`}),t.map(e=>Q(`option`,{value:e.id,children:e.name},e.id))]}),Q(`select`,{class:`sel`,"aria-label":`Sort`,value:C,onChange:e=>w(e.target.value),children:[Q(`option`,{value:`newest`,children:`Newest`}),Q(`option`,{value:`oldest`,children:`Oldest`}),Q(`option`,{value:`name`,children:`Name`})]}),y.gridToggle&&Q(`div`,{class:`seg`,role:`group`,"aria-label":`View`,children:[Q(`button`,{type:`button`,"aria-pressed":D===`grid`,"aria-label":`Grid view`,"data-tip":`Grid`,onClick:()=>j(`grid`),children:Q($,{name:`grid`})}),Q(`button`,{type:`button`,"aria-pressed":D===`list`,"aria-label":`List view`,"data-tip":`List`,onClick:()=>j(`list`),children:Q($,{name:`list`})})]}),y.id===`export`&&Q(`button`,{type:`button`,class:`btn`,onClick:()=>void ue(),children:[Q($,{name:`script`}),`Export notes`]})]})]}),Q(`div`,{class:`abody${ce?` split`:``}`,children:[Q(`div`,{class:`alist`,children:A.length===0?Q(`p`,{class:`aempty`,children:`Nothing here yet.`}):D===`grid`?V():fe()}),ce&&Q(`aside`,{class:`apreview`,children:!ae||!z?Q(`p`,{class:`aempty`,children:`Select a file to preview it here.`}):z.loading?Q(`p`,{class:`aempty`,children:`Loading…`}):z.error?Q(`p`,{class:`aempty`,children:z.error}):Q(S,{children:[pe===`md`?Q(`div`,{class:`markdown`,dangerouslySetInnerHTML:{__html:me}}):Q(`pre`,{class:`plain`,children:z.text}),z.truncated&&Q(`p`,{class:`atrunc`,children:`Showing the first 1 MB`})]})})]})]}):Q(`div`,{class:`empty`,children:[Q($,{name:`grid`}),Q(`h2`,{children:`Nothing to review in Assets yet`})]}),Q(`audio`,{ref:I,onEnded:()=>{Ei(ne.current),te(e=>({...e,paused:!0}))}}),M&&Q(za,{asset:M,toast:o,onClose:ee})]})}var so=class extends Error{};function co(e,t,n){let r=X(t.hash),i=X(t);i.current=t;let a=X(Promise.resolve()),o=X(null),s=X(0);J(()=>{r.current=t.hash},[t.hash]),J(()=>(n.settle.current=async()=>(await a.current.catch(()=>void 0),(await Z.get(`/api/state`))[e]),()=>{n.settle.current=null}),[]);let c=async(t,n)=>{let a=i.current;for(let i=0;;i++){let o=t(a,n||i>0);if(!o)throw Error(`that part is no longer in ${e}.md`);if(`refuse`in o)throw new so(o.refuse);try{let t=await Z.put(o.path,{...o.body,hash:r.current});r.current=t[e].hash;return}catch(t){if(t instanceof Vr&&t.code===`${e}_changed`&&i===0){a=(await Z.get(`/api/state`))[e],r.current=a.hash;continue}throw t}}},l=(t,r,i=!1)=>{let l=++s.current;o.current=null,a.current=a.current.catch(()=>void 0).then(()=>c(r,i)).catch(a=>{!i&&l===s.current&&a instanceof Vr&&a.code===`${e}_changed`&&(o.current={what:t,build:r}),n.toast(`Couldn't save ${t}: ${a.message}`)}).finally(n.onChanged)};return J(()=>{let e=o.current;e&&(o.current=null,l(e.what,e.build,!0))},[t.hash]),{latest:i,enqueue:l}}var lo=500;function uo(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())}}}function fo({section:e,save:t}){let[n,r]=q(e.yours),i=X(!1),a=X(null);J(()=>{i.current||r(e.yours)},[e.yours]),Y(()=>{let e=a.current;e&&(e.style.height=`auto`,e.style.height=`${e.scrollHeight+2}px`)},[n]);let o=uo(()=>{i.current=!1,n.trim()!==e.yours.trim()&&t.section(e,n)},lo),s=n.trim()!==e.current.trim();return Q(`div`,{class:`srow${s?` changed`:``}`,"data-section":e.heading,children:Q(`div`,{class:`sgrid bgrid`,children:[Q(`div`,{class:`blabel`,children:e.heading}),Q(`div`,{class:`cur`,children:e.current}),Q(`div`,{class:`byours`,children:[Q(`textarea`,{ref:a,class:`input`,"aria-label":`Your version of ${e.heading}`,value:n,onInput:e=>{i.current=!0,r(e.target.value),o.schedule()},onBlur:()=>o.flush()}),s&&Q(`button`,{class:`btn ghost ib`,"data-tip":`Revert to current`,"aria-label":`Revert ${e.heading}`,onClick:()=>{i.current=!1,r(e.current),t.section(e,e.current)},children:Q($,{name:`undo`})})]})]})})}var po=(e,t)=>e.slice(0,t).filter(n=>n.heading===e[t].heading).length;function mo({brief:e,toast:t,onChanged:n,settle:r}){let{latest:i,enqueue:a}=co(`brief`,e,{toast:t,onChanged:n,settle:r}),o={section:(e,t)=>{let n=po(i.current.sections,e.index);a(e.heading,r=>{let i=r.sections.filter(t=>t.heading===e.heading)[n];return i?{path:`/api/brief/sections/${i.index}`,body:{heading:e.heading,text:t}}:null})},status:t=>{let n=e.sections.map(e=>`${e.heading}\n${e.yours}`).join(`
|
|
4
|
+
|
|
5
|
+
`);a(`the brief's status`,(e,r)=>r&&t===`approved`&&e.sections.map(e=>`${e.heading}\n${e.yours}`).join(`
|
|
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(fo,{section:t,save:o},`${t.heading}#${po(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`]})})]})}function ho(e,t,n){Y(()=>{if(!e)return;let r=e=>{t.current?.contains(e.target)||n(!1)},i=e=>{e.key===`Escape`&&(e.preventDefault(),e.stopPropagation(),n(!0))};return document.addEventListener(`pointerdown`,r,!0),document.addEventListener(`focusin`,r,!0),window.addEventListener(`keydown`,i,!0),()=>{document.removeEventListener(`pointerdown`,r,!0),document.removeEventListener(`focusin`,r,!0),window.removeEventListener(`keydown`,i,!0)}},[e])}function go({video:e,onToggleShelved:t}){let[n,r]=q(!1),i=X(null),a=X(null),o=X(null),s=e=>{r(!1),e&&a.current?.focus()};ho(n,i,s),Y(()=>{n&&o.current?.focus()},[n]);let c=!!e?.shelved;return Q(`span`,{class:`fmwrap`,ref:i,children:[Q(`button`,{ref:a,type:`button`,class:`btn ghost ib tip-below`,"data-tip":e?`Film actions · ${e.name}`:`Film actions`,"aria-label":`Film actions`,"aria-haspopup":`menu`,"aria-expanded":n,disabled:!e,onClick:()=>r(!n),children:Q($,{name:`more`})}),n&&e&&Q(`div`,{class:`fmenu`,role:`menu`,"aria-label":`Film actions for ${e.name}`,children:[Q(`div`,{class:`fmtitle`,children:[`Film`,Q(`b`,{dir:`auto`,children:e.name})]}),Q(`button`,{ref:o,type:`button`,role:`menuitem`,class:`fmitem`,onClick:()=>{s(!0),t()},children:[Q($,{name:c?`undo`:`shelve`}),c?`Restore film`:`Shelve film`,Q(`kbd`,{children:`Shift+S`})]})]})]})}var _o=e=>new Date(e).toLocaleDateString(`en-GB`,{day:`numeric`,month:`short`});function vo(e){if(window.innerWidth<=1e3)return;let t=getComputedStyle(e),n=parseFloat(t.columnGap)||0,r=e.clientWidth-(parseFloat(t.paddingLeft)||0)-(parseFloat(t.paddingRight)||0),i=0;for(let t of Array.from(e.children)){let e=getComputedStyle(t);e.display!==`none`&&e.position!==`absolute`&&(i++,!t.classList.contains(`pack`)&&(r-=parseFloat(e.flexShrink)>0?parseFloat(e.minWidth)||0:t.getBoundingClientRect().width))}return r-Math.max(0,i-1)*n}function yo({films:e,currentId:t,headRef:n,hasTodo:r,onSwitch:i,onRestore:a,shelvedRequest:o}){let s=e.filter(Ce),c=e.filter(e=>!Ce(e)),l=Te(e,t),[u,d]=q(null),[f,p]=q(()=>n.current?.clientWidth??1440),[m,h]=q(void 0),g=X(null),_=X(null),v=X(null),y=X(null),b=()=>{let e=n.current;e&&(p(e.clientWidth),h(vo(e)))};Y(()=>{let e=n.current;if(!e)return;let t=new ResizeObserver(b);t.observe(e);for(let n of Array.from(e.children))t.observe(n);return()=>t.disconnect()},[l,c.length]),Y(b),ho(u!==null,u===`more`?v:y,e=>{let t=u;d(null),e&&(t===`more`?g:_).current?.focus()}),J(()=>{o>0&&d(`shelved`)},[o]),J(()=>{(u===`shelved`&&c.length===0||u===`more`&&!l)&&d(null)},[u,c.length,l]);let x=Oe(s.length,s.findIndex(e=>e.id===t),De(f,m)),C=x.map(e=>s[e]),w=s.filter((e,t)=>!x.includes(t)),T=C.length*26+8+(w.length>0?56:0),E=(e,n)=>Q(`button`,{type:`button`,class:`pill`,"aria-pressed":e.id===t,onClick:()=>i(e.id),children:[Q(`span`,{class:`n`,children:n}),Q(`span`,{class:`pname`,children:e.name}),r(e.id)&&Q(`span`,{class:`dot`})]});return Q(S,{children:[l&&Q(`nav`,{class:`pack`,"aria-label":`Films`,style:`--packmin: ${T}px`,children:[C.map(e=>E(e,s.indexOf(e)+1)),w.length>0&&Q(`span`,{class:`fpwrap`,ref:v,children:[Q(`button`,{ref:g,type:`button`,class:`pill fpmore`,"aria-label":`${w.length} more films`,"aria-haspopup":`true`,"aria-expanded":u===`more`,onClick:()=>d(u===`more`?null:`more`),children:[`+`,w.length,w.some(e=>r(e.id))&&Q(`span`,{class:`dot`}),Q($,{name:`chev`})]}),u===`more`&&Q(`div`,{class:`fpmenu`,role:`group`,"aria-label":`More films`,children:w.map(e=>Q(`button`,{type:`button`,class:`fprow`,onClick:()=>{d(null),i(e.id)},children:[Q(`span`,{class:`n`,children:s.indexOf(e)+1}),Q(`span`,{class:`pname`,dir:`auto`,children:e.name}),r(e.id)&&Q(`span`,{class:`dot`})]}))})]})]}),c.length>0&&Q(`span`,{class:`fpwrap fpshelfwrap`,ref:y,children:[Q(`button`,{ref:_,type:`button`,class:`fpshelf${c.some(e=>e.id===t)?` on`:``}`,"aria-haspopup":`true`,"aria-expanded":u===`shelved`,onClick:()=>d(u===`shelved`?null:`shelved`),children:[Q($,{name:`shelve`}),Q(`span`,{class:`fplabel`,children:`Shelved `}),`(`,c.length,`)`]}),u===`shelved`&&Q(`div`,{class:`fpmenu`,role:`group`,"aria-label":`Shelved films`,children:[Q(`h4`,{children:`Shelved`}),c.map(e=>Q(`div`,{class:`fprow shelved`,children:[Q(`button`,{type:`button`,class:`fpopen`,"aria-label":`Open ${e.name}`,onClick:()=>{d(null),i(e.id)},children:[Q(`span`,{class:`pname`,dir:`auto`,children:e.name}),Q(`span`,{class:`meta`,children:[e.versions.length,` `,e.versions.length===1?`cut`:`cuts`,` · `,_o(e.shelved)]})]}),Q(`button`,{type:`button`,class:`btn ghost ib fprestore`,"aria-label":`Restore ${e.name}`,"data-tip":`Restore film`,onClick:()=>{d(null),a(e.id)},children:Q($,{name:`undo`})})]}))]})]})]})}function bo({video:e,onRestore:t}){return Q(`div`,{class:`shbanner`,role:`region`,"aria-label":`Shelved film`,children:[Q($,{name:`shelve`}),Q(`span`,{class:`shtext`,children:[`Shelved `,Q(`b`,{dir:`auto`,children:e.name}),` on `,_o(e.shelved),`. View only.`]}),Q(`span`,{class:`sp`}),Q(`button`,{type:`button`,class:`btn`,onClick:t,children:[Q($,{name:`undo`}),`Restore film`]})]})}function xo({onOpen:e}){return Q(`div`,{class:`empty shempty`,children:[Q(`p`,{children:Q(`b`,{children:`All films are shelved`})}),Q(`p`,{children:`Nothing is in play. Restore a film to carry on.`}),Q(`button`,{type:`button`,class:`btn`,onClick:e,children:`Open the Shelved list`})]})}var So=150;function Co({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),So)};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:tr(e.length)},onKeyDown:e=>S(e),children:e.map(e=>{let n=er(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":$n(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 wo=.03,To=.004,Eo=15e3;function Do(e){return e.buffer?e.buffer.length*e.buffer.numberOfChannels*4:0}var Oo=0;function ko(){return Oo}var Ao=new Map;function jo(e){let t=Ao.get(e);return t&&(Ao.delete(e),Ao.set(e,t)),t}function Mo(e,t){for(Ao.delete(e),Ao.set(e,t);Ao.size>200;)Ao.delete(Ao.keys().next().value)}function No(){let e=Error(`The load was cancelled`);return e.name=`AbortError`,e}function Po(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),Eo)})}var Fo=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??Gr,fetch:t.fetch??((e,t)=>fetch(e,t)),probe:t.probe??Po(n),createMedia:n,raf:t.raf??(e=>requestAnimationFrame(e)),caf:t.caf??(e=>cancelAnimationFrame(e))},e&&(this.ctx=e,Oo++)}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 Ci(this.videoDuration,this.resolved())}inspect(){return{playing:this._playing,time:this.time,length:this.length,sources:this.voices.size,gains:di(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=ii({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)ii(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=>(_i(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(bi(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 No();let d;if(u&&!_i(u.duration,!0)){let e=jo(t);if(!e){let n=[];for(let e=0;e<u.numberOfChannels;e++)n.push(u.getChannelData(e));e=hi(n,gi(u.duration)),Mo(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 No();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)ii(t)===e&&this.holding.delete(t.id);if(this._playing){for(let t of this.resolved())ii(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(ii)),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+=Do(e.media);for(;this.idle.size>12||o>268435456;){let[e,t]=this.idle.entries().next().value;o-=Do(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=di(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(()=>{}),Ti(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(),Ei(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(),Ei(this),this.tickListeners.clear(),this.endedListeners.clear(),this.changeListeners.clear(),this.disposed=!0,this.ctx&&(this.ctx.close().catch(()=>{}),this.ctx=null,Oo--)}}ensureContext(){if(this.disposed)throw Error(`The audio engine was disposed`);return this.ctx||(this.ctx=this.opts.createContext(),Oo++),this.ctx}resolved(){let e={};for(let[t,n]of this.media)e[t]=n.duration;let t=Si(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+wo;let n=this.resolved(),r=new Map(n.map(e=>[e.id,e]));for(let t of fi(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+wo),r=this.startOffset+(n-this.startedAt);for(let t of fi([e],r))this.startVoice(e,n+t.when,t.offset)}startVoice(e,t,n){let r=this.media.get(ii(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(ii(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=xi(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=di([e],this.selection)[e.id],r.connect(this.laneNode(e.lane)),t={gain:r,seekedAt:-1/0},this.media.get(ii(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+To)}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(ii(e))&&!this.media.has(ii(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)Io(()=>e(t));if(t>=e){this.pause();for(let e of this.endedListeners)Io(e);return}this._playing&&this.frame===null&&(this.frame=this.opts.raf(this.tick))};emitChange(){for(let e of this.changeListeners)Io(e)}};function Io(e){try{e()}catch(e){console.error(e)}}var Lo=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,Ti(this,()=>this.stop()),this.set({path:e,playing:!0});try{await n.play()}catch(t){if(this.current.path===e&&this.current.playing)throw Ei(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(),Ei(this),this.current.playing&&this.set({...this.current,playing:!1})}element(){if(!this.el){let e=this.make();e.addEventListener(`ended`,()=>{Ei(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,Gr),Ro=e=>e.map(e=>[e.id,e.lane,e.path,e.rev??``,e.offset,e.duration].join(`\0`)).join(``);function zo(e,t=null){let n=X(null);n.current||=new Fo;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=>[ii(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,Ro(e)]),J(()=>{r.setVideoDuration(t)},[r,t]),{engine:r,playing:a,length:s,media:l}}function Bo(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 Vo(e){return e.name.trim()||`Untitled cue`}function Ho(e){return`${Vo(e)} at ${U(e.t)}`}function Uo(e,t){return`cue ${e} of ${t}`}function Wo(e){let t=new Map;for(let n of Bo(e)){let e=Vo(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 Go(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 Ko(e){return e.split(/[\\/]/).filter(Boolean).pop()??e}function qo(e,t){return`${((t>0?Math.min(1,Math.max(0,e/t)):0)*100).toFixed(3)}%`}function Jo(e,t){return`clamp(5px, ${qo(e,t)}, calc(100% - 5px))`}function Yo(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 Xo(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 Zo=`cue-card`;function Qo(){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 $o(e,t){return{onPointerEnter:n=>e.show(n.currentTarget,t),onPointerLeave:()=>e.hide()}}function es({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=Xo({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:Zo,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:[U(a.t),` · `,Uo(a.n,a.of)]}),a.file!==null&&Q(`span`,{class:`f`,style:{color:a.color},children:a.file})]})}function ts(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=Go(e.key,i.indexOf(r),i.length);a!==null&&(e.preventDefault(),e.stopPropagation(),i[a].focus())}function ns(){let[e,t]=q(Lo.state());return J(()=>Lo.subscribe(t),[]),e}function rs({id:e,name:t,cues:n,length:r,color:i,card:a,onSeek:o,toast:s}){let c=Bo(n),l=new Map(c.map((e,t)=>[e,t+1])),u=Wo(n),[d,f]=q({}),p=ns();J(()=>()=>Lo.stopIf(e),[e]);let m=async t=>{try{await Lo.toggle(t,e)}catch{s(`Couldn't play ${Ko(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:Jo(s.t,r)},"aria-label":Ho(s),"aria-describedby":p?Zo:void 0,...$o(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=>ts(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:Ko(s)})]}),t.moreFiles>0&&Q(`small`,{children:[`+`,t.moreFiles]})]})]},t.name)})})}function is({name:e,control:t}){let[n,r]=q(!1),i=X(null),a=X(null),o=X(null);ho(n,i,e=>{r(!1),e&&a.current?.focus()}),Y(()=>{n&&o.current?.focus()},[n]);let{on:s,films:c}=t,l=c.filter(e=>s.includes(e.id)).map(e=>e.name),u=s.length===0?`No film`:s.length===1?`1 film`:`${s.length} films`,d=e=>t.onChange(s.includes(e)?s.filter(t=>t!==e):c.filter(t=>t.id===e||s.includes(t.id)).map(e=>e.id));return Q(`span`,{class:`fmwrap films`,ref:i,onClick:e=>e.stopPropagation(),children:[Q(`button`,{ref:a,type:`button`,class:`btn ghost sm filmsbtn${s.length===0?` none`:``}`,"data-tip":l.length?`On ${l.join(`, `)}`:`On no film`,"aria-label":`Films for ${e}: ${l.length?l.join(`, `):`none`}`,"aria-haspopup":`true`,"aria-expanded":n,disabled:t.readOnly,onClick:()=>r(!n),children:[Q($,{name:`film`}),u]}),n&&Q(`div`,{class:`fmenu filmsmenu`,role:`group`,"aria-label":`Films for ${e}`,children:[Q(`div`,{class:`fmtitle`,children:[`Films it is on`,Q(`b`,{dir:`auto`,children:e})]}),c.map((e,t)=>Q(`label`,{class:`fmitem`,children:[Q(`input`,{ref:t===0?o:void 0,type:`checkbox`,checked:s.includes(e.id),onChange:()=>d(e.id)}),Q(`span`,{dir:`auto`,children:e.name}),e.here?Q(`kbd`,{children:`this film`}):e.shelved?Q(`kbd`,{children:`shelved`}):null]},e.id))]})]})}function as(e,t,n,r,i){return{on:e.films,films:[...t.filter(e=>!e.shelved),...t.filter(e=>e.shelved)].map(e=>({id:e.id,name:e.name,shelved:!!e.shelved,here:e.id===n?.id})),readOnly:!!n?.shelved,onChange:async t=>{try{await Z.put(`/api/variants/${encodeURIComponent(e.lane)}/${encodeURIComponent(e.variant)}/films`,{videos:t})}catch(e){r(`Couldn't change its films: ${e.message}`)}i()}}}var os=new Set;function ss(e,t,n,r){if(t.length===0)return[];let i=os.has(e),a=t.length,o=e===`voice`?a===1?`read`:`reads`:e===`music`?a===1?`bed`:`beds`:a===1?`pass`:`passes`,s=t.filter(e=>e.films.length===0).length,c=`Not on this film · ${a} ${o}${s?` · ${s} on no film`:``}`;return[{key:`loose:${e}`,name:`Not on this film`,color:`var(--text-3)`,clips:[],fold:{label:Q(S,{children:[Q(`b`,{children:`Not on this film`}),` · `,a,` `,o,s?Q(S,{children:[` · `,Q(`span`,{class:`fnone`,children:[s,` on no film`]})]}):null,` · use Films to put one on it`]}),text:c,open:i,dot:!1,onToggle:()=>{i?os.delete(e):os.add(e),r()}}},...i?t.map(n):[]]}var cs=0;function ls(){return cs}var us=3,ds=2;function fs({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;cs++,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/us),c=t*us/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*us,(i.h-s)/2,ds,s)}},o),Q(`canvas`,{ref:r,class:`wave`,"aria-hidden":`true`})}function ps(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 ms=(e,t)=>{let n=Object.keys(e);return n.length===Object.keys(t).length&&n.every(n=>e[n]===t[n])};function hs({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=ps(u.current);f(t=>ms(t,e)?t:e)}},m=e.map(e=>{let t=e.clips.map(e=>n[ii(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}=Qo(),[_,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=Bo(e.cues??[]),h=Yo(m),y=At(m,t),b=Math.min(_[e.key]??0,Math.max(0,m.length-1)),x=(t,n)=>({key:`m:${e.key}:${h[n]}`,name:Vo(t),t:t.t,n:n+1,of:m.length,file:t.file??null,color:e.color}),C=e.clips.map(e=>n[ii(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(Oa,{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(fs,{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},...$o(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":Ho(t),"aria-describedby":i?Zo:void 0,style:{left:l(t.t),color:e.color,maxWidth:`calc(${(y[n]*100).toFixed(3)}% - 8px)`},...$o(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=>ts(e,`button.cue`,g),onClick:n=>{n.stopPropagation(),s(t.t,e,t.id)},children:Q(`span`,{children:Vo(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.films&&Q(is,{name:e.name,control:e.films}),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(rs,{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(es,{shown:h,onHide:g.hide})]})}var gs=[`ArrowLeft`,`ArrowRight`,`ArrowUp`,`ArrowDown`,`Home`,`End`];function _s({label:e,width:t,height:n,value:r,onChange:i,lockedReason:a,name:o}){let s=er(t,n),c=Nr();return Q(`div`,{class:`fscope`,role:`radiogroup`,"aria-label":o,onKeyDown:e=>{if(e.altKey||e.metaKey||e.ctrlKey||!gs.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 vs=[{kind:`rise`,label:`Rise`},{kind:`fall`,label:`Fall`},{kind:`louder`,label:`Louder`},{kind:`quieter`,label:`Quieter`}],ys=e=>e.options.find(t=>t.value===e.value)?.full;function bs({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,readOnly:x}){let[S,C]=q(`all`),w=X(null),T=i??w,[E,D]=q(``),[O,k]=q(!1),A=e.filter(e=>e.status===`todo`).length,j=b?.(S)??null,M=e.map(e=>({n:e,at:h?{t:e.t,tOut:e.tOut,from:null}:ve(e,t)})).filter(({n:e})=>S===`all`||e.status===S).sort((e,t)=>(e.at.t??-1)-(t.at.t??-1)),N=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()},P=async()=>{let e=E.trim();if(e&&!O){k(!0);try{await o(e),D(``),l?.(!1)}catch(e){a(`Couldn't add the note: ${e.message}`)}finally{k(!1)}}},F=e=>{D(e),l?.(!0);let t=T.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":S===e,onClick:()=>C(e),children:[e===`all`?`All`:e===`todo`?`To do`:`Done`,e===`todo`&&A>0&&Q(`span`,{class:`n`,children:A})]}))})]}),Q(`div`,{class:`list`,children:[M.length===0&&Q(`div`,{class:`none`,children:S===`all`?j?`None on this format.`:`No notes yet.`:`Nothing here.`}),M.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 N(e),children:Q($,{name:`check`})}),Q(`div`,{class:`nt`,children:[Q(`button`,{class:`t`,onClick:()=>t.t!==null&&s?.(t.t,e),children:ye(t.t,t.tOut)}),m&&m(e)&&Q(`span`,{class:`on`,children:m(e)}),(()=>{let t=_?.(e)??null;return t&&Q(`span`,{class:`ftag${t===`All`?` all`:``}`,children:t})})(),t.from&&Q(`span`,{class:`from`,children:[`from `,t.from]})]}),xt(e.marks)&&Q(`div`,{class:`nmarks`,children:xt(e.marks)}),e.shot&&Q(`div`,{class:`shotref`,children:[`Shot `,Ye(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:Gr(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)),j]}),Q(`div`,{class:`comp`,hidden:x,children:[(u||d)&&Q(`div`,{class:`row`,children:[u&&Q(`span`,{class:`onwrap`,"data-tip":ys(u),children:[Q(`select`,{class:`sel onsel`,"aria-label":`Note on`,"data-tip":ys(u),value:u.value??``,onChange:e=>{let t=e.target;u.onChange(t.value),t.blur()},children:Dt(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:pt(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:()=>F(`${e}: `),children:e}))}),p&&d?.value===`range`&&Q(`div`,{class:`row`,role:`group`,"aria-label":`Marks`,children:vs.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(St(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(Ct(p.value,e,Number(n.value))),n.blur()},children:gt.map(e=>Q(`option`,{value:String(e),children:[e,` dB`]}))}),Q($,{name:`chev`})]})]})})}),y&&Q(`div`,{class:`row`,children:Q(_s,{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:T,class:`input`,rows:2,"aria-label":`New note`,placeholder:n,value:E,onInput:e=>{let t=e.target.value;D(t),l?.(t.trim()!==``)},onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),P()),e.key===`Escape`&&e.target.blur()}}),Q(`button`,{class:`btn primary ib sm send`,"data-tip":`Add note ↵`,"aria-label":`Add note`,onClick:()=>void P(),children:Q($,{name:`send`})})]}),y&&Q(`p`,{class:`fhint`,children:y.hint})]})]})}var xs=typeof location>`u`?{test:!1,streamOver:!1}:Wt(location.search);xs.streamOver&&yi(1);var Ss=xs.test?{engine:null,inspect(){return this.engine?this.engine.inspect():null},renders:0,draws:ls,liveContexts:ko,sample:()=>Lo.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;Ss&&(window.__rushesAudio=Ss);var Cs=e=>e instanceof HTMLElement&&(e.isContentEditable||/^(INPUT|TEXTAREA|SELECT)$/.test(e.tagName)),ws={in:null,out:null},Ts=[`point`,`range`,`whole`],Es={voice:`No voice reads for this film yet.`,music:`No music beds for this film yet.`,sfx:`No sound effects passes for this film yet.`,mix:`Nothing to mix for this film yet.`};function Ds(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;Ss&&Ss.renders++;let g=e.clips??Os(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}=zo(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(ws),[P,F]=q(e.defaultScope??`point`),[ee,I]=q([]),[L,te]=q(!1),ne=(e.scopes??Ts).includes(`range`),R=e.defaultScope??`point`,re=`${e.film===void 0?o?.video??``:e.film??``}/${o?.version??``}`,ie=X(re);Y(()=>{ie.current!==re&&(ie.current=re,F(R))},[re]);let ae=mt({range:M,marks:ee,hasText:L});Y(()=>{m?.(ae)},[ae]),J(()=>()=>m?.(!1),[]);let oe=e=>h?h(e):{select:Lt(a,e),gains:{}},z=X({select:{},gains:{}}),se=e=>{let t=z.current;for(let[n,r]of Object.entries(e.select))(!(n in t.select)||t.select[n]!==r)&&x.selectVariant(n,r);for(let[n,r]of Object.entries(e.gains))t.gains[n]!==r&&x.setLaneGain(n,r);z.current={select:{...t.select,...e.select},gains:{...t.gains,...e.gains}}},ce=oe(j);Y(()=>se(ce),[x,JSON.stringify(ce)]);let B=e.defaultOn??a.find(e=>e.picked)?.on??a[0]?.on??l[0]?.value??null,le=l.some(e=>e.value===O)?O:B,ue=l.find(e=>e.value===le)??null,de=X(null),V=X([]),fe=X(null),pe=X(null),me=X(null),he=X(!1),H=X(0),ge=X(null),ve=e=>{if(P===`whole`)return t===`voice`?`Note on the whole read`:`Note on the whole track`;if(ne){if(M.in!==null&&M.out===null)return`Set an Out point`;if(M.in!==null&&M.out!==null)return`Note on ${ye(M.in,M.out)}`;if(P===`range`)return`Set In and Out`}return`Note at ${U(ue?.t??_e(e,s))}`},be=e=>{let t=x.length,n=`${t>0?Math.min(e,t)/t*100:0}%`;for(let e of V.current)e.style.left=n;let r=U(e);fe.current&&(fe.current.textContent=r),pe.current&&(pe.current.textContent=r),ge.current&&(ge.current.placeholder=ve(e));let i=me.current;i&&i.readyState>=1&&!i.seeking&&pi(i.currentTime,e,s)&&(i.currentTime=Math.min(e,Number.isFinite(i.duration)?i.duration:e)),i&&x.playing&&!he.current&&e>H.current&&(he.current=!0,i.play().catch(()=>void 0)),H.current=e},xe=X(be);xe.current=be,Y(()=>{V.current=de.current?[...de.current.querySelectorAll(`.playhead`)]:[],be(x.time)}),J(()=>x.subscribe(e=>xe.current(e)),[x]),J(()=>{let e=me.current;e&&(he.current=!1,C||(e.pause(),xe.current(x.time)))},[C,o?.file]);let Se=()=>x.playing?x.pause():x.play(),G=e=>{x.pause(),x.seek(W(x.time,s,e,x.length))},Ce=()=>{ne&&(N({in:_e(x.time,s),out:null}),F(`range`))},we=()=>{if(!ne)return;let e=_e(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(ws),I([]),P===`range`&&F(R)},Ee=e=>{(e!==`range`||ne)&&(F(e),e!==`range`&&(N(ws),I([])))},De=t=>{D(t.key),se(oe(t.key)),A.current=t.on??null,t.on&&k(t.on),e.onSelect?.(t)},Oe=X(()=>void 0);Oe.current=e=>{if(Cs(e.target)||e.metaKey||e.ctrlKey||e.altKey)return;let t=e.key.toLowerCase();if(e.key===` `){if(Ut(e.target))return;e.preventDefault(),Se()}else e.key===`ArrowLeft`?(e.preventDefault(),G(e.shiftKey?-10:-1)):e.key===`ArrowRight`?(e.preventDefault(),G(e.shiftKey?10:1)):t===`i`?Ce():t===`o`?we():t===`n`&&(e.preventDefault(),ge.current?.focus())},Y(()=>{let e=e=>Oe.current(e);return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[]),Y(()=>{Ss&&(Ss.clips=g)}),J(()=>{if(Ss)return Ss.engine=x,()=>{Ss.engine===x&&(Ss.engine=null)}},[x]);let ke=async e=>{let n=null,r=null;if(P===`range`){if(M.in===null||M.out===null)throw Error(`set In and Out for a range`);n=M.in,r=M.out}else P===`point`&&(n=ue?.t??_e(x.time,s));await Z.post(`/api/notes`,{stage:t,video:o?.video??null,version:o?.version??null,on:ue?.on??null,scope:P,t:n,tOut:r,text:e,marks:P===`range`?ee:[]}),N(ws),I([]),F(R),p()},Ae=o?.version??null,K={};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)(K[n]??=[]).push({id:e.id,t:e.t,tOut:ne?e.tOut:null,status:e.status,text:e.text})}let je=M.in===null?null:M.out===null?`${U(M.in)} →`:ye(M.in,M.out);return Q(`div`,{class:`astage`,ref:de,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:()=>G(-1),children:Q($,{name:`prev`})}),Q(`button`,{class:`btn ib`,"data-tip":`Play Space`,"aria-label":C?`Pause`:`Play`,onClick:Se,children:Q($,{name:C?`pause`:`play`})}),Q(`button`,{class:`btn ghost ib`,"data-tip":`Forward one frame →`,"aria-label":`Forward one frame`,onClick:()=>G(1),children:Q($,{name:`next`})}),Q(`span`,{class:`tc`,"aria-label":`Timecode`,children:[Q(`span`,{ref:fe,children:U(x.time)}),Q(`small`,{children:[`/ `,U(w)]})]}),Q(`span`,{class:`sp`}),je&&Q(`span`,{class:`chipx`,children:[Q(`span`,{class:`mono`,children:je}),Q(`button`,{"aria-label":`Clear range`,onClick:Te,children:Q($,{name:`x`})})]}),ne&&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`})})]})]}),a.every(e=>e.key.startsWith(`loose`))&&Q(`p`,{class:`lanesnone`,children:Es[t]}),Q(hs,{rows:a,length:w,media:T,selected:j,marks:K,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:me,src:Gr(o.file),muted:!0,playsInline:!0,preload:`auto`,"aria-label":`Picture preview`,onLoadedMetadata:e=>{let t=e.target;Number.isFinite(t.duration)&&v(t.duration),t.videoWidth&&t.videoHeight&&b(t.videoWidth/t.videoHeight),xe.current(x.time)},onSeeked:()=>xe.current(x.time)}):Q(`div`,{class:`pvempty`,"aria-label":`No cut yet`,children:Q($,{name:`film`})}),Q(`div`,{class:`tcover`,ref:pe,children:U(x.time)})]})}),Q(bs,{notes:c,version:Ae,placeholder:ve(x.time),inputRef:ge,toast:f,onAdd:ke,onChanged:p,onTextChange:te,fixedTimes:!0,onSeek:e=>x.seek(e),on:{options:l,value:le,onChange:k},scope:{value:P,onChange:Ee,options:e.scopes},chips:(e.chipsFor??(()=>ht[t]))(P),marks:e.marks===!1?void 0:{value:ee,onChange:I},onLabel:d,readOnly:e.readOnly})]})]})}function Os(e){let t=new Set;return e.filter(e=>!t.has(e.id)&&(t.add(e.id),!0))}var ks={vo:`#4FD1C5`,music:`#A78BFA`,sfx:`#FB923C`},As={vo:`Voiceover`,music:`Music`,sfx:`Sound effects`},js={vo:{muted:!1,solo:!1},music:{muted:!1,solo:!1},sfx:{muted:!1,solo:!1}};function Ms({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?ai(t):void 0},c=e=>o(e)?.missing===!0,l=n?.id,u=dr(e.picks,l),d=u.lanes,f=pr(e.project.lanes,l,e.project.videos.length),p=Yt(qt(f,d)),m=p&&!c(p.file)?[{id:p.key,lane:`vo`,path:p.file,offset:0,duration:0,rev:s(p.file)}]:[],h=p?c(p.file):!1,g={music:Tt(f,`music`),sfx:Tt(f,`sfx`)},_=e=>e.filter(e=>d[e.lane]===e.variant),v={music:_(g.music),sfx:_(g.sfx)},y={music:v.music.filter(e=>!c(e.file)),sfx:v.sfx.filter(e=>!c(e.file))},b=e=>y[e].map(t=>({id:t.key,lane:e,path:t.file,offset:0,duration:0,rev:s(t.file)})),x={vo:m,music:b(`music`),sfx:b(`sfx`)},C={vo:m.length>0,music:x.music.length>0,sfx:x.sfx.length>0},w={variants:g,heard:{vo:C.vo,music:y.music,sfx:y.sfx}},T=pn(w),[E,D]=q(js),O=(e,t)=>D(n=>({...n,[e]:{...n[e],[t]:!n[e][t]}})),k=u.levels,A=e=>k[on[e]]??0,[j,M]=q(()=>({vo:A(`vo`),music:A(`music`),sfx:A(`sfx`)})),N=X({});J(()=>{M(e=>{let t=!1,n={...e};for(let e of an){if(N.current[e]!==void 0)continue;let r=A(e);n[e]!==r&&(n[e]=r,t=!0)}return t?n:e})},[`${l}:${JSON.stringify(k)}`]);let P=e=>{let t=N.current;for(let n of an){let r=t[n];r&&(window.clearTimeout(r.id),delete t[n],r.send(e))}};J(()=>{let e=()=>P(!0),t=()=>{document.visibilityState===`hidden`&&P(!0)};return window.addEventListener(`pagehide`,e),document.addEventListener(`visibilitychange`,t),()=>{window.removeEventListener(`pagehide`,e),document.removeEventListener(`visibilitychange`,t),P(!1)}},[]),J(()=>()=>P(!1),[l]);let F=(e,t)=>{let n=hn(t);M(t=>t[e]===n?t:{...t,[e]:n});let a=N.current;a[e]!==void 0&&window.clearTimeout(a[e].id);let o=(t=!1)=>void Z.put(`/api/picks`,{video:l,levels:{[on[e]]:n===0?null:n}},{keepalive:t}).then(i,e=>{r(e instanceof Vr?e.message:`Couldn't save the level`)});a[e]={id:window.setTimeout(()=>{delete a[e],o()},300),send:o}},ee=li(an.map(e=>({id:e,...E[e],level:j[e]}))),I=e=>e===`vo`?p?`${p.laneName} · ${p.name}`:null:v[e].map(e=>e.name).join(` · `)||null,L=e=>C[e]?null:e===`vo`?h?`Missing`:`Nothing picked`:v[e].length>0?`Missing`:`Nothing picked`,te=an.map(e=>({key:e,name:As[e],meta:I(e),color:ks[e],clips:x[e],cues:e===`sfx`?y.sfx.flatMap(e=>e.cues):void 0,on:T.find(t=>t.row===e)?.value,missing:L(e)??void 0,controls:Q(S,{children:[Q(`button`,{type:`button`,class:`ms`,"aria-pressed":E[e].muted,"aria-label":`Mute ${As[e]}`,"data-tip":`Mute`,onClick:()=>O(e,`muted`),children:`M`}),Q(`button`,{type:`button`,class:`ms`,"aria-pressed":E[e].solo,"aria-label":`Solo ${As[e]}`,"data-tip":`Solo`,onClick:()=>O(e,`solo`),children:`S`}),Q(`label`,{class:`level`,"data-tip":`Level for ${As[e]}. Double-click to reset.`,children:[Q(`input`,{type:`range`,min:-24,max:6,step:mn,value:j[e],"aria-label":`${As[e]} level`,"aria-valuetext":`${gn(j[e])} dB`,onInput:t=>F(e,Number(t.target.value)),onDblClick:()=>F(e,0)}),Q(`span`,{class:`db mono`,children:[gn(j[e]),` dB`]})]})]})})),ne=sn(C,ee),R=JSON.stringify({want:ne,film:l,levels:k,clips:an.map(e=>x[e].map(e=>[e.path,e.rev??``,e.offset]))}),[re,ie]=q({kind:`waiting`}),[ae,oe]=q(!1),[z,se]=q(0),ce=re.kind===`timeout`||re.kind===`error`,B=X(0);J(()=>{let e=++B.current;if(ne.length===0){ie({kind:`empty`}),oe(!1);return}ie(e=>e.kind===`empty`||e.kind===`timeout`||e.kind===`error`?{kind:`waiting`}:e),oe(!0);let t=window.setTimeout(()=>{Z.post(`/api/mix/loudness`,{lanes:ne,video:l}).then(t=>{e===B.current&&ie({kind:`result`,result:t})},t=>{e===B.current&&ie({kind:t instanceof Vr&&t.status===504?`timeout`:`error`})}).finally(()=>{e===B.current&&oe(!1)})},500);return()=>window.clearTimeout(t)},[R,z]),J(()=>()=>void++B.current,[]);let le=Q(`div`,{class:ce?`meter retry`:`meter`,role:`group`,"aria-label":`Loudness`,"aria-busy":ae,onClick:ce?()=>se(e=>e+1):void 0,children:[yn(re).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})]})),ae&&Q(`span`,{class:`smk measuring`,"data-measuring":!0,"data-tip":`Measuring`,"aria-label":`Measuring`,children:Q($,{name:`gauge`})}),ce&&!ae&&Q(`button`,{type:`button`,class:`btn ghost ib`,"data-tip":`Measure again`,"aria-label":`Measure again`,children:Q($,{name:`gauge`})})]}),ue=hr(e.notes.notes,`mix`,l),de=G(n??void 0),V=n&&de?{video:n.id,version:de.id,file:de.file,duration:de.duration}:null,fe=e.project.fps||30;return Q(Ds,{stage:`mix`,title:ke.mix,belowLanes:le,rows:te,preview:V,film:n?.id??null,readOnly:!!n?.shelved,fps:fe,notes:ue,onOptions:T,defaultOn:`mix`,listen:()=>({select:{},gains:ee}),noteRow:e=>un(w,e.on),onLabel:e=>fn(w,e.on),toast:r,onChanged:i,onPendingChange:a})}function Ns({notes:e,version:t,viewsHere:n,ownViews:r,onShow:i,onRestore:a}){let[o,s]=q(!1);return e.length===0?null:Q(`div`,{class:`otherfmts`,children:[Q(`button`,{type:`button`,class:`otherrow`,"aria-expanded":o,onClick:()=>s(e=>!e),children:[Q(`span`,{children:[`Other formats (`,e.length,`)`]}),Q(`span`,{class:`sp`}),Q(`span`,{class:`act`,"aria-hidden":`true`,children:o?`Hide`:`Show`})]}),o&&e.map(e=>{let o=ve(e,t),s=ur(e,n,r(e));return Q(`div`,{class:`note ro${e.status===`done`?` done`:``}`,"data-note":e.id,children:[Q(`span`,{"aria-hidden":`true`}),Q(`div`,{class:`nt`,children:[Q(`span`,{class:`t mono`,children:ye(o.t,o.tOut)}),Q(`span`,{class:`ftag`,children:e.format?fe(e.format):`All`}),o.from&&Q(`span`,{class:`from`,children:[`from `,o.from]})]}),Q(`div`,{class:`nx`,children:e.text}),s?.kind===`show`&&Q(`div`,{class:`nact`,children:Q(`button`,{type:`button`,class:`flink`,onClick:()=>i(s.id,e),children:[`Show on `,s.label]})}),s?.kind===`restore`&&Q(`div`,{class:`nact`,children:Q(`button`,{type:`button`,class:`flink`,onClick:()=>a(e),children:`Restore to all formats`})})]},e.id)})]})}var Ps=6e3,Fs=e=>/[.!?]$/.test(e)?e:`${e}.`;function Is({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=En({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),Ps);return()=>clearTimeout(e)},[x]),!n)return null;let C=x&&v===x?`none`:b,w=Dn(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 Vr&&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.`}),` `,Fs(w)]}),Q(`button`,{class:`btn primary tip-wrap tip-end`,"aria-label":`Create proxy`,"data-tip":xn(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}),` (`,Ze(t.proxy.bytes),`).`]}),Q(`button`,{class:`btn ghost ib`,"aria-label":`Dismiss`,"data-tip":`Dismiss`,onClick:()=>y(x),children:Q($,{name:`x`})})]}),A]})})}var Ls=2e3,Rs=8e3,zs={kind:`none`},Bs={kind:`pending`};async function Vs(e,t,n){let r;try{r=await t.fetch(e.peaksUrl,{signal:n})}catch(e){if(n.aborted)throw e;return Bs}if(r.status===202)return Bs;if(r.status===501)return Hs(e,t,n);if(r.status!==200)return zs;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))?zs:{kind:`wave`,wave:{peaks:Float32Array.from(t),duration:e.duration}}}catch(e){if(n.aborted)throw e;return zs}}async function Hs(e,t,n){if(e.size===null||!(e.size<1e8))return zs;try{let r=await e.duration();if(n.aborted)throw new DOMException(`aborted`,`AbortError`);if(r===null||!(r>0)||r>900)return zs;let i=await t.fetch(e.mediaUrl,{signal:n});if(!i.ok)return zs;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)?zs:{kind:`wave`,wave:{peaks:Us(hi(a,Math.min(Ls,s))),duration:o}}}catch(e){if(n.aborted)throw e;return zs}}function Us(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 Ws=40,Gs=new Map;function Ks(e,t,n,r){return`${e}/${t}/${n}#${r??``}`}function qs(e){return Gs.has(e)}function Js(e){return Gs.get(e)??null}function Ys(e,t){for(Gs.delete(e),Gs.set(e,t);Gs.size>Ws;)Gs.delete(Gs.keys().next().value)}function Xs(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 Zs=1500,Qs=15e3,$s=15e3,ec={fetch(e,t){let n=Hr();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,Rs).decodeAudioData(e),n=[];for(let e=0;e<t.numberOfChannels;e++)n.push(t.getChannelData(e));return{channels:n,duration:t.duration}}};function tc(e,t,n,r,i){let a=Ks(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),$s)}),[l,u]=q(()=>qs(a)?{key:a,wave:Js(a)}:null),d=X(null);return J(()=>{if(qs(a)){u({key:a,wave:Js(a)});return}let r=new AbortController,i,o=Zs,s={peaksUrl:`/api/videos/${encodeURIComponent(e)}/versions/${encodeURIComponent(t.id)}/peaks`,mediaUrl:Gr(t.file),size:n,duration:c},l=async()=>{d.current=null,clearTimeout(i);let e;try{e=await Vs(s,ec,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,Qs);return}let t=e.kind===`wave`?e.wave:null;Ys(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 nc=0;typeof location<`u`&&Wt(location.search).test&&(window.__rushesPicture={waveDraws:()=>nc});var rc=3,ic=2;function ac({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=Xs(window,t);return()=>{r.disconnect(),a()}},[]),J(()=>{let i=n.current;if(!i||r.w<=0||r.h<=0)return;nc++,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+=rc){let n=t/r.w*o;if(n>=e.duration)break;let i=(t+rc)/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,ic,f)}},[r,e,t]),Q(`canvas`,{ref:n,class:`pwave`,"aria-hidden":`true`})}function oc(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 sc=700,cc=16,lc=()=>typeof matchMedia==`function`&&matchMedia(`(hover: none)`).matches;function uc({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=na(t),w=e=>{c(e),u(null),m(null),f(lc()),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-cc;g(Math.max(0,Math.min(e.left+t.width-n,e.left-cc)))};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=ya(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<sc?x.current.text+e.key:e.key;x.current={text:t,at:e.timeStamp};let n=va(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":dc(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:na(e)}),Q(`span`,{class:`vwhen`,children:[e.id===n&&Q($,{name:`lock`}),ga(e.addedAt,S)]}),d&&p===e.id&&Q(`span`,{class:`vinline`,dir:`auto`,children:[Ui(e.note)||`No note.`,Q(`span`,{class:`vmeta`,children:ba(e,S)})]})]}))}),!d&&Q(`div`,{class:`vdetail`,id:`vdetail`,children:[Q(`h4`,{children:A.id}),Q(`p`,{dir:`auto`,children:Ui(A.note)||`No note.`}),Q(`span`,{class:`vmeta`,children:ba(A,S)})]})]})]})}function dc(e,t,n){return[e.id,na(e),e.id===t?`locked`:``,_a(e.addedAt,n)].filter(Boolean).join(`, `)}function fc({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=Ui(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 pc=e=>e instanceof HTMLElement&&(e.isContentEditable||/^(INPUT|TEXTAREA|SELECT)$/.test(e.tagName));function mc({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,readOnly:E=!1}){let D=X(null),O=X(null),k=X(null),A=X(null),[j,M]=q(0),[N,P]=q(t.duration??0),[F,ee]=q(t.duration?t.file:null),I=b?y.find(e=>e.id===b)??null:null,L=!I||I.primary,te=I??y.find(e=>e.primary)??null,ne=te?te.width/te.height:null,R=b!==null&&y.length>=2,re=y.find(e=>e.primary)?.id??null,ie=ir(r,b),ae=ar(r,b),[oe,z]=q(`this`),[se,ce]=q(ne??16/9),[B,le]=q(!1),[ue,de]=q(null),[V,fe]=q({in:null,out:null}),[pe,he]=q(!1),[H,be]=q(null),[xe,Se]=q({w:0,h:0}),[G,Ce]=q(null),[we,Te]=q(null),[Ee,De]=q(!1),Oe=X(null);oc(Oe);let ke=tc(e.id,t,_,v,F===t.file?N:t.duration??0),Ae=X(!1),K=X(!1),je=X({}),Me=X(B);J(()=>{Me.current=B},[B]);let Ne=X(!0);J(()=>()=>{Ne.current=!1},[]);let Pe=X(t.id);J(()=>{Pe.current=t.id},[t.id]),J(()=>{let e=!E&&(V.in!==null||G!==null||Ee);return o?.(e),()=>o?.(!1)},[V.in,G,Ee,E]),J(()=>(G!==null&&z(`this`),w?.(G!==null),()=>w?.(!1)),[G]);let Fe=X(void 0);J(()=>{de(null),M(0),ce(ne??16/9),fe({in:null,out:null}),Ce(null),Fe.current!==void 0&&l(e.id,null),Fe.current=t.file,Te(null),z(`this`)},[t.file]);let Ie=G?`this`:oe,Le=n=>me(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),Ue.current?.id===e.id&&(Ue.current=null),i(`Couldn't change that note: ${t.message}`)}a()}};J(()=>{we&&!ie.some(e=>e.id===we)&&Te(null)},[b,r]);let Ue=X(null),We=X(b);if(We.current!==b){We.current=b;let e=document.activeElement,t=e instanceof HTMLElement&&e.closest(`.nfmt`)?e.closest(`.list > .note[data-note]`):null;t&&!Ue.current&&(Ue.current={id:t.dataset.note,fallback:!0})}Y(()=>{let e=Ue.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?(Ue.current=null,n&&r.focus()):e.fallback&&(Ue.current=null,n&&document.querySelector(`.otherrow`)?.focus())},[b,r]);let Ge=L&&!!t.proxy&&h!==`original`,Ke=Gr(Ge?t.proxy.file:L?t.file:I.file),qe=ue===Ke,Ze=X(null),Qe=X(null);if(Qe.current&&Qe.current.src!==Ke){let e=D.current;Qe.current.cut===t.file?!Ze.current&&e&&(Ze.current={t:e.error?j:e.currentTime,play:!e.paused&&!e.error}):Ze.current=null}Qe.current={cut:t.file,src:Ke};let $e=X(null),et=X(null),tt=I?.id??`primary`,nt=X(!0);Y(()=>{if(nt.current){nt.current=!1;return}let e=O.current;if(!te||!e)return;let t=te.width/te.height;if(t===se)return;let n=e.getBoundingClientRect();$e.current={width:n.width,height:n.height},ce(t)},[tt]),Y(()=>{let e=$e.current,t=O.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=rr(e,{width:n.width,height:n.height},r);Wt(location.search).test&&(window.__rushesLastReshape={animated:i!==null,ms:i?160:0}),i&&(et.current=t.animate(i,{duration:160,easing:`ease-out`}))},[se]),J(()=>{let e=D.current;if(!e)return;let t=()=>de(Ke);return e.error&&t(),e.addEventListener(`error`,t),()=>e.removeEventListener(`error`,t)},[Ke]);let rt=X(null);rt.current=!L&&N>0?N:null;let it=e=>{let t=rt.current;t===null||e.paused||e.currentTime<t||(e.pause(),e.currentTime=t)};J(()=>{if(!B)return;let e=0,t=()=>{D.current&&(it(D.current),M(D.current.currentTime)),e=requestAnimationFrame(t)};return e=requestAnimationFrame(t),()=>cancelAnimationFrame(e)},[B]);let at=()=>Ze.current?.t??D.current?.currentTime??j,ot=()=>_e(at(),n),st=e=>{let t=D.current;if(!t)return;let n=Math.min(Math.max(0,e),N||t.duration||e);if(Ze.current){Ze.current.t=n,M(n);return}t.currentTime=n,M(t.currentTime)},ct=()=>{let e=D.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=>{D.current?.pause(),st(W(at(),n,e,N))},ft=()=>fe({in:ot(),out:null}),pt=()=>{let e=ot(),t=V.in??0;if(e<=t)return i(`Out has to come after In`);fe({in:t,out:e})},mt=()=>fe({in:null,out:null}),ht=X(0),[gt,_t]=q(0),vt=async()=>{let r=D.current,o=ot(),s=e.id,c=t.id,u=L?null:b,f=++ht.current,p=!1;try{let e=ge(o,n),t;if(d){p=!0,_t(e=>e+1);let n=await Wr(s,c,o,u);e=n.frame??e,t=n.png}else{if(!r||!r.videoWidth)return i(`Nothing to grab yet`);let e=document.createElement(`canvas`);e.width=r.videoWidth,e.height=r.videoHeight,e.getContext(`2d`).drawImage(r,0,0),t=e.toDataURL(`image/png`)}let m=await Z.post(`/api/grabs`,{video:s,version:c,frame:e,png:t,...u?{format:u}:{}});if(f!==ht.current){a();return}i(`Saved to ${m.grab}`),a(),Ne.current&&c===Pe.current&&l(s,m.grab)}catch(e){f===ht.current&&i(e.message)}finally{p&&Ne.current&&_t(e=>e-1)}},yt=async r=>{let i=V.in!==null&&V.out!==null,o=i?V.in:ot();await Z.post(`/api/notes`,{stage:`picture`,video:e.id,version:t.id,scope:i?`range`:`point`,t:o,tOut:i?V.out:null,frame:ge(o,n),text:r,box:G,grab:c,...R?{format:Ie===`this`?b:null}:{}}),mt(),z(`this`),Ce(null),l(e.id,null),a()},bt=X(()=>void 0);bt.current=e=>{if(pc(e.target)||e.metaKey||e.ctrlKey||e.altKey)return;let t=e.key.toLowerCase();if(e.key===` `){if(Ut(e.target))return;e.preventDefault(),ct()}else if(e.key===`ArrowLeft`)e.preventDefault(),dt(e.shiftKey?-10:-1);else if(e.key===`ArrowRight`)e.preventDefault(),dt(e.shiftKey?10:1);else if(E&&/^[iogbn]$/.test(t))return;else t===`i`?ft():t===`o`?pt():t===`g`&&!e.repeat?vt():t===`b`?he(e=>!e):t===`n`&&(e.preventDefault(),A.current?.focus())},J(()=>{let e=e=>bt.current(e);return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[]);let xt=(e,t)=>{let n=D.current;return lt(n?.videoWidth??0,n?.videoHeight??0,e,t)},St=e=>{let t=k.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=k.current;if(!e)return;let t=()=>Se(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(!pe)return;let t=St(e);e.target.setPointerCapture(e.pointerId),be({x0:t.x,y0:t.y,x1:t.x,y1:t.y,w:t.w,h:t.h})},wt=e=>{if(!H)return;let t=St(e);be({...H,x1:t.x,y1:t.y})},Tt=e=>{if(!H)return;let t=St(e),n=ut(H.x0,H.y0,t.x,t.y,H.w,H.h);be(null),he(!1),Ae.current=!0,n.w>.01&&n.h>.01&&Ce(n)},Et=H?ut(H.x0,H.y0,H.x1,H.y1,H.w,H.h):null,Dt=xt(xe.w,xe.h),Ot=e=>({left:`${e.x*100}%`,top:`${e.y*100}%`,width:`${e.w*100}%`,height:`${e.h*100}%`}),kt=e=>`${N?Math.min(100,Math.max(0,e/N*100)):0}%`,At=N?t.shots.filter(e=>e.start<N):t.shots,jt=Je(At,_e(j,n));J(()=>{Me.current&&jt!==null&&je.current[jt.n]?.scrollIntoView({block:`nearest`,inline:`nearest`})},[jt?.n]);let Mt=ie.map(e=>({n:e,at:ve(e,t.id)})).filter(({at:e})=>e.t!==null),Nt=ie.find(e=>e.id===we)??null,Pt=Nt?.box&&(!Nt.version||Nt.version===t.id)&&or(Nt,b,re)?Nt.box:null,Ft=V.in===null?null:V.out===null?`${U(V.in)} →`:ye(V.in,V.out),It=V.in!==null&&V.out===null?`Set an Out point`:`Note at ${Ft&&V.out!==null?Ft:U(j)}`,Lt=e=>{P(L?e.duration||t.duration||0:t.duration??I?.duration??(e.duration||0)),ee(t.file),L&&t.width===null&&e.videoWidth&&e.videoHeight&&C?.(t.file,e.videoWidth,e.videoHeight),de(e=>e===Ke?null:e),e.videoWidth&&e.videoHeight&&ce(e.videoWidth/e.videoHeight),K.current||(K.current=!0,s&&(e.currentTime=Math.min(s,e.duration||s),M(e.currentTime)));let n=Ze.current;n&&(Ze.current=null,e.currentTime=Math.min(n.t,e.duration||n.t),M(n.t),n.play&&e.play().catch(()=>void 0))},Rt=t=>{t!==h&&g?.(e.id,t)};return Q(`div`,{class:`split`,children:[Q(`div`,{class:`stack`,ref:Oe,children:[Q(`div`,{class:`framebox`,style:{height:`min(640px, 70vh, calc(100cqw / ${se}))`},children:Q(`div`,{class:`frame`,ref:O,style:{aspectRatio:String(se),"--ar":String(se)},children:[x&&!L&&Q(`div`,{class:`msg`,children:`File not found`}),qe&&!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.`}),qe&&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.`}),qe&&L&&d&&t.proxy&&!Ge&&Q(`div`,{class:`msg`,children:`This file won't play in a browser.`}),Q(`video`,{hidden:qe||x&&!L,ref:e=>{D.current=e,u&&(u.current=e),e&&e.readyState>=1&&Lt(e)},src:Ke,preload:`auto`,playsInline:!0,onLoadedMetadata:e=>Lt(e.target),onTimeUpdate:e=>{let t=e.target;it(t),!B&&!Ze.current&&M(t.currentTime)},onSeeked:e=>!Ze.current&&M(e.target.currentTime),onPlay:()=>le(!0),onPause:()=>le(!1),onEnded:()=>le(!1)}),Q(`div`,{ref:k,class:`overlay${pe?` drawing`:``}`,onPointerDown:Ct,onPointerMove:wt,onPointerUp:Tt,onClick:()=>{Ae.current?Ae.current=!1:pe||ct()},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)}),G&&Q(`div`,{class:`bx`,style:Ot(G)}),Et&&Q(`div`,{class:`bx`,style:Ot(Et)})]})}),Q(`div`,{class:`tcover`,children:[`f`,ge(j,n),jt&&` · shot ${Ye(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":Ge,"aria-label":`Proxy`,"data-tip":`Playing the lightweight copy. Notes and timings are the same.`,onClick:e=>{e.currentTarget.blur(),Rt(`proxy`)},children:`Proxy`}),Q(`button`,{type:`button`,class:`tip-below tip-start tip-wrap`,"aria-pressed":!Ge,"aria-label":`Original`,"data-tip":`Play the full-quality file. It may stutter.`,onClick:e=>{e.currentTarget.blur(),Rt(`original`)},children:`Original`})]})]})}),m&&Q(Is,{hidden:!L,video:e,version:t,ffmpeg:d,autoProxy:f,job:p,broken:qe&&!Ge,duration:N,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":B?`Pause`:`Play`,onClick:ct,children:Q($,{name:B?`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:[U(j),Q(`small`,{children:[`/ `,U(N)]})]}),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`,disabled:E,onClick:ft,children:Q($,{name:`in`})}),Q(`button`,{class:`btn ghost ib`,"data-tip":`Set out O`,"aria-label":`Set out point`,disabled:E,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":pe,disabled:E,onClick:()=>he(!pe),children:Q($,{name:`box`})}),Q(`button`,{class:`btn ghost ib`,"data-tip":`Grab frame G`,"aria-label":`Grab frame`,"aria-busy":gt>0,disabled:E,onClick:()=>void vt(),children:Q($,{name:`camera`})})]}),Q(`div`,{class:`track`,role:`slider`,"aria-label":`Timeline`,"aria-valuemin":0,"aria-valuemax":N,"aria-valuenow":j,onClick:e=>{let t=e.currentTarget.getBoundingClientRect();st((e.clientX-t.left)/t.width*N)},children:[ke&&Q(ac,{wave:ke,length:N}),Mt.map(({n:e,at:t})=>t.tOut!==null&&Q(`div`,{class:`span ${e.status}`,style:{left:kt(t.t),width:kt(t.tOut-t.t)}})),V.in!==null&&Q(`div`,{class:`span live`,style:{left:kt(V.in),width:kt((V.out??V.in+.2)-V.in)}}),At.filter(e=>e.start>0).map(e=>Q(`div`,{class:`tick`,style:{left:kt(e.start)}})),Mt.map(({n:e,at:t})=>{let n=lr(e,R);return Q(`div`,{class:`mk ${e.status}${R&&e.format===null?` ring`:``}`,style:{left:kt(t.t)},title:n?`${n} · ${e.text}`:e.text})}),Q(`div`,{class:`playhead`,style:{left:kt(j)}})]}),Q(`div`,{class:`ends`,children:[Q(`span`,{children:`0:00`}),Q(`span`,{children:U(N)})]}),Q(fc,{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:()=>{D.current?.pause(),st(Xe(e.start,n))},children:[Q(`span`,{class:`mono`,children:[Ye(e.n),` · `,e.start.toFixed(2),`s`]}),Q(`span`,{class:`name`,children:e.name}),e.tag&&Q(`span`,{class:`tag`,children:e.tag})]}))}),Q(bs,{readOnly:E,notes:ie,version:t.id,selectedId:we,placeholder:It,inputRef:A,toast:i,onAdd:yt,onChanged:a,onTextChange:De,formatTag:e=>lr(e,R),cardExtra:R&&I?e=>Q(_s,{name:`Note applies to`,label:I.label,width:I.width,height:I.height,value:Be(e)===null?`all`:`this`,lockedReason:e.box?sr:null,onChange:t=>void He(e,t===`all`?null:I.id)}):void 0,formatScope:R&&I?{label:I.label,width:I.width,height:I.height,value:Ie,onChange:z,lockedReason:G?sr:null,hint:cr(I.label,Ie,G!==null)}:void 0,listFooter:e=>{let n=ae.filter(t=>e===`all`||t.status===e);return n.length>0?Q(Ns,{notes:n,version:t.id,viewsHere:y,ownViews:Le,onShow:(e,t)=>{G||(Ue.current={id:t.id,fallback:!1}),T?.(e)},onRestore:e=>{Ue.current={id:e.id,fallback:!1},He(e,null)}}):null},onSeek:(e,t)=>{D.current?.pause(),st(e),Te(t.id)},attachments:(G||c)&&Q(S,{children:[G&&Q(`span`,{class:`chipx`,children:[Q($,{name:`box`}),`Box`,Q(`button`,{"aria-label":`Remove box`,onClick:()=>Ce(null),children:Q($,{name:`x`})})]}),c&&Q(`span`,{class:`chipx`,children:[Q($,{name:`image`}),`Frame `,c.match(/_f(\d+)\.png$/)?.[1],Q(`button`,{"aria-label":`Remove frame`,onClick:()=>l(e.id,null),children:Q($,{name:`x`})})]})]})})]})}var hc=500;function gc(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 _c=(e,t)=>e.slice(0,t).filter(n=>n.heading===e[t].heading).length,vc=e=>String(e).padStart(2,`0`);function yc({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:Gr(e.still),alt:`Still for shot ${e.n}, ${e.name}`,onError:()=>r(e.still)})}function bc({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=gc(()=>{s.current=!1,l()},hc),d=gc(()=>{s.current=!1,l()},hc),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(yc,{shot:e})}),Q(`div`,{class:`sbmeta`,children:[Q(`b`,{children:vc(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 xc({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(yc,{shot:e,large:!0})}),Q(`div`,{class:`sblcap`,children:[Q(`b`,{children:[vc(e.n),` · `,e.name]}),` `,e.tag&&Q(`span`,{class:`sbtag`,children:e.tag}),Q(`p`,{children:e.description})]})]})})}function Sc({board:e,brief:t,toast:n,onChanged:r,settle:i}){let{latest:a,enqueue:o}=co(`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:_c(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=We(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(bc,{shot:t,save:u,onZoom:()=>{l.current=document.activeElement,c(t.heading)}},`${t.heading}#${_c(e.shots,n)}`))}),f&&Q(xc,{shot:f,onClose:()=>{c(null),l.current?.focus()}})]})}function Cc({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 wc={approved:{color:`var(--done)`,label:`Approved`},flagged:{color:`var(--todo)`,label:`Flagged`},draft:{color:`var(--text-3)`,label:`Draft`}},Tc=500;function Ec(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 Dc({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=Ec(()=>{c.current=!1,u({proposed:i.trim()===e.current.trim()?null:i})},Tc),f=Ec(()=>{c.current=!1,u({direction:o})},Tc),p=e.end-e.start,m=be(i,p,t),h=i.trim()!==e.current.trim(),g=wc[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:[U(e.start).replace(/\.\d+$/,``),`–`,U(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 Oc({script:e,toast:t,onChanged:n}){let r=e.sections.filter(xe).length;return Q(`div`,{class:`col`,children:[Q(`div`,{class:`shead`,children:[Q(`h2`,{children:`Script`}),Q(`span`,{class:`meta`,children:[e.sections.length,` section`,e.sections.length===1?``:`s`,` · `,r,` changed`]})]}),Q(`div`,{class:`sgrid scols`,children:[Q(`span`,{}),Q(`span`,{children:`Current`}),Q(`span`,{children:`Yours`})]}),Q(`div`,{style:{display:`grid`,gap:`12px`},children:e.sections.map(r=>Q(Dc,{section:r,wps:e.wordsPerSecond,toast:t,onChanged:n},r.id))})]})}var kc={music:`#A78BFA`,sfx:`#FB923C`},Ac=Math.floor(Math.random()*2**31),jc=!1,Mc=new Set;function Nc({stage:e,state:t,assets:n,video:r,toast:i,onChanged:a,onPendingChange:o}){let[s,c]=q(e===`music`&&jc),l=e=>{jc=e,c(e)},[,u]=q(0),d=e=>{Mc.has(e)?Mc.delete(e):Mc.add(e),u(e=>e+1)},f=t.project.videos.length,p=Tt(pr(t.project.lanes,r?.id,f),e),m=r?Tt(mr(t.project.lanes,r.id,f),e):[],h=e=>f>1?as(e,t.project.videos,r,i,a):void 0,g=s?Rt(p.map(e=>e.key),Ac):p.map(e=>e.key),_=g.map(e=>p.find(t=>t.key===e)),v=e=>s?`Bed ${g.indexOf(e.key)+1}`:e.name,y=dr(t.picks,r?.id).lanes,b=async(e,t)=>{try{await Z.put(`/api/picks`,{video:r?.id,lanes:{[e.lane]:t}})}catch(e){i(`Couldn't ${t===null?`clear`:`set`} the pick: ${e.message}`)}a()},x=_.map(t=>{let r=n.find(e=>e.path===t.file),i=Et(e),a={id:t.key,lane:i,path:t.file,offset:0,duration:0,rev:r?ai(r):void 0},o=y[t.lane]===t.variant;return{key:t.key,name:v(t),meta:s?`·····`:t.meta,color:kc[e],clips:[a],cues:e===`sfx`?t.cues:void 0,layers:e===`sfx`?{open:Mc.has(t.key),onToggle:()=>d(t.key)}:void 0,audition:{lane:i,clip:t.key},picked:o,order:p.indexOf(t),use:{inUse:o,onUse:()=>void b(t,t.variant),onUnpick:()=>void b(t,null)},films:h(t),on:`v:${t.key}`}});x.push(...ss(e,m,t=>({key:`loose/${t.key}`,name:t.name,meta:t.meta,color:kc[e],clips:[],films:h(t)}),()=>u(e=>e+1)));let S=jt(_,v,e===`sfx`),C=hr(t.notes.notes,e,r?.id),w=G(r??void 0),T=r&&w?{video:r.id,version:w.id,file:w.file,duration:w.duration}:null,E=t.project.fps||30;return Q(Ds,{stage:e,film:r?.id??null,readOnly:!!r?.shelved,title:ke[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:x,preview:T,fps:E,notes:C,onOptions:S,noteRow:e=>Ft(_,e.on),onLabel:e=>It(_,S,e.on),toast:i,onChanged:a,onPendingChange:o})}var Pc=`#4FD1C5`,Fc=[`whole`,`point`],Ic={whole:ht.voice,point:[`Fix this`,`Keep this`]},Lc=Math.floor(Math.random()*2**31),Rc=!1,zc=new Map,Bc=new Set;function Vc({state:e,assets:t,video:n,toast:r,onChanged:i,onPendingChange:a}){let[o,s]=q(Rc),c=e=>{Rc=e,s(e)},l=n?.id??``,[,u]=q(0),d=zc.get(l)??Bc,f=e=>{let t=new Set(d);t.has(e)?t.delete(e):t.add(e),zc.set(l,t),u(e=>e+1)},p=e=>t.find(t=>t.path===e),m=e=>{let t=p(e);return t?ai(t):void 0},h=e=>p(e)?.missing===!0,g=e.project.videos.length,_=qt(pr(e.project.lanes,n?.id,g),dr(e.picks,n?.id).lanes),v=n?Tt(mr(e.project.lanes,n.id,g),`voice`):[],y=t=>g>1?as(t,e.project.videos,n,r,i):void 0,b=_.map(e=>{if(!o)return e;let t=Rt(e.reads.map(e=>e.key),Lc);return{...e,reads:t.map(t=>e.reads.find(e=>e.key===t))}}),x=new Map;for(let e of b)e.reads.forEach((e,t)=>x.set(e.key,t+1));let C=e=>o?`Read ${x.get(e.key)}`:e.name,w=async(e,t)=>{try{await Z.put(`/api/picks`,{video:n?.id,lanes:{[e.id]:t}})}catch(e){r(`Couldn't ${t===null?`clear`:`set`} the pick: ${e.message}`)}i()},T=e=>({id:e.key,lane:Zt(e),path:e.file,offset:0,duration:0,rev:m(e.file)}),E=_.filter(e=>e.current||d.has(e.id)).flatMap(e=>e.reads.filter(e=>!h(e.file)).map(T)),D=hr(e.notes.notes,`voice`,n?.id),O={rounds:_,sections:e.script.sections},k=(e,t)=>({key:t.key,name:C(t),meta:o?`·····`:t.meta,color:Pc,clips:h(t.file)?[]:[T(t)],use:{inUse:e.pick===t.variant,onUse:()=>void w(e,t.variant),onUnpick:()=>void w(e,null)},films:y(t),on:`v:${t.key}`,missing:h(t.file)}),A=[];for(let e of[...b].reverse()){if(e.current){e.reads.forEach((t,n)=>A.push(n===0?{...k(e,t),heading:e.name,tag:`current`}:k(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(A.push({key:`round:${e.id}`,name:e.name,color:Pc,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:D.some(e=>e.status===`todo`&&r.has(tn(O,e)??``)),onToggle:()=>f(e.id)}}),t)for(let t of e.reads)A.push(k(e,t))}A.push(...ss(`voice`,v,e=>({key:`loose/${e.key}`,name:`${e.laneName} · ${e.name}`,meta:e.meta,color:Pc,clips:[],films:y(e)}),()=>u(e=>e+1)));let j=nn(b,C),M=Xt(_),N=G(n??void 0),P=n&&N?{video:n.id,version:N.id,file:N.file,duration:N.duration}:null,F=e.project.fps||30;return Q(Ds,{stage:`voice`,film:n?.id??null,readOnly:!!n?.shelved,title:ke.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:A,clips:E,preview:P,fps:F,notes:D,onOptions:j,defaultOn:M?`v:${M.key}`:void 0,listen:e=>Qt(_,e),noteRow:e=>tn(O,e),onLabel:e=>rn(O,e.on,C),scopes:Fc,defaultScope:`whole`,chipsFor:e=>Ic[e===`point`?`point`:`whole`],marks:!1,toast:r,onChanged:i,onPendingChange:a})}function Hc(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 Uc=e=>e.map(e=>e?`1`:`0`).join(``),Wc={100:`left third`,"010":`centre`,"001":`right third`,110:`left two thirds`,"011":`right two thirds`,111:`full width`,101:`full width`},Gc={100:`top third`,"010":`middle`,"001":`bottom third`,110:`top two thirds`,"011":`bottom two thirds`,111:`full height`,101:`full height`};function Kc(e){let t=Uc(Hc(e.x,e.w)),n=Uc(Hc(e.y,e.h));return t===`111`&&n===`111`?`the whole picture`:t===`010`&&n===`010`?`the centre`:`${Wc[t]}, ${Gc[n]}`}function qc(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 Jc(e,t,n=8){return Math.min(Math.max(0,e-1),Math.max(0,t-n))}var Yc=e=>Math.round(e*1e4)/1e4,Xc=e=>Yc(Math.max(0,Math.min(1,e))),Zc=.02;function Qc(e,t,n){if(!n)return{pin:{x:Xc(e.x),y:Xc(e.y)}};let[r,i,a,o]=[Xc(e.x),Xc(e.y),Xc(t.x),Xc(t.y)],s={x:Math.min(r,a),y:Math.min(i,o),w:Yc(Math.abs(a-r)),h:Yc(Math.abs(o-i))};return s.w<Zc||s.h<Zc?null:{box:s}}var $c=e=>e.versions[e.versions.length-1];function el(e){let t=$c(e);return{page:1,ratio:t.pages[0]?.images[0]?.ratio??``,ver:t.id}}function tl(e,t){let{ver:n,...r}=t;return n===$c(e).id?r:{...r,ver:n,since:$c(e).id}}function nl(e,t){let{ver:n,since:r,...i}=t??{},a=n!==void 0&&r===$c(e).id;return{...el(e),...i,...a?{ver:n}:{}}}var rl=(e,t)=>t.ver===$c(e).id;function il(e,t){return[e.name,e.kind===`carousel`?`page ${t.page}`:null,fe(t.ratio),t.ver].filter(Boolean).join(` · `)}var al=e=>(e.on??``).slice(0,(e.on??``).lastIndexOf(`/`)),ol=e=>Number((e.on??``).slice((e.on??``).lastIndexOf(`/`)+1))||0;function sl(e,t){return e.filter(e=>e.stage===`visuals`&&al(e)===al(t)).findIndex(e=>e.id===t.id)+1}function cl(e,t){let n=t.filter(e=>e.stage===`visuals`),r=[...e.map(e=>e.id),...new Set(n.map(al).filter(t=>!e.some(e=>e.id===t)))],i=[];for(let t of r){let r=n.filter(e=>al(e)===t);if(r.length===0)continue;let a=e.find(e=>e.id===t),o=[...new Set(r.map(ol))].sort((e,t)=>e-t).map(e=>({page:e,notes:r.filter(t=>ol(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 ll(e,t,n){return e.filter(e=>e.stage===`visuals`&&al(e)===t&&ol(e)===n.page&&e.format===n.ratio&&e.version===n.ver&&(e.box!==null||e.pin!==null))}function ul(e,t){let n={};for(let r of e)r.stage===`visuals`&&r.status===`todo`&&al(r)===t&&(n[ol(r)]=(n[ol(r)]??0)+1);return n}function dl(e,t,n){return{page:ol(t),ratio:t.format??n.ratio,ver:t.version??n.ver}}function fl(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 pl=e=>e instanceof HTMLElement&&(e.isContentEditable||/^(INPUT|TEXTAREA|SELECT)$/.test(e.tagName));function ml(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 hl({notes:e,all:t,selected:n,draft:r}){return Q(S,{children:[e.map(e=>{let r=sl(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`&&al(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`&&al(e)===r.vis).length+1})})]})}function gl({file:e,alt:t,onBad:n}){return Q(`img`,{src:Gr(e),alt:t,draggable:!1,onError:n})}function _l({visual:e,view:t,badges:n,onPage:r}){let i=e.versions.find(e=>e.id===t.ver)??$c(e),a=X(null);Y(()=>{let e=a.current;if(!e||e.children.length===0)return;let n=e.children[Jc(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:Gr(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 vl({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)??$c(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:_}=ml({w:m.width,h:m.height}),[v,y]=q(null),b=ll(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=!rl(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===$c(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:fe(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":`${il(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(gl,{file:m.file,alt:`${e.name}, page ${t.page}`,onBad:()=>y(m.file)},m.file),Q(hl,{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(_l,{visual:e,view:t,badges:ul(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 yl({visual:e,view:t,notes:n,onPage:r,onClose:i}){let a=e.versions.find(e=>e.id===t.ver)??$c(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}=ml({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(gl,{file:s.file,alt:`${e.name}, page ${t.page}`,onBad:()=>void 0},s.file),Q(hl,{notes:ll(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 bl({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=>nl(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)??$c(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]:tl(e,{page:a,ratio:o,ver:i.id})}})},C=X(0);J(()=>{let e=v.current;if(!e)return;let t=0,n=()=>{t=0;let n=e.getBoundingClientRect().top+e.clientHeight/2;for(let t of Array.from(e.querySelectorAll(`.vz`))){let e=t.getBoundingClientRect();if(e.top<=n&&n<e.bottom)return void s(t.dataset.visual??``)}},r=()=>{t||=requestAnimationFrame(n)};e.addEventListener(`scroll`,r,{passive:!0});let i=()=>cancelAnimationFrame(C.current),a=[`wheel`,`touchstart`,`pointerdown`,`keydown`];for(let t of a)e.addEventListener(t,i,{passive:!0});let o=new ResizeObserver(r);return o.observe(e),e.querySelectorAll(`.vz`).forEach(e=>o.observe(e)),n(),()=>{e.removeEventListener(`scroll`,r);for(let t of a)e.removeEventListener(t,i);cancelAnimationFrame(C.current),o.disconnect(),t&&cancelAnimationFrame(t)}},[i.map(e=>e.id).join(`,`)]);let w=(e,t=!0)=>{let n=v.current,r=n?.querySelector(`.vz[data-visual="${e}"]`);if(!n||!r||(n.scrollTo({top:r.offsetTop,behavior:t?`smooth`:`instant`}),!t))return;cancelAnimationFrame(C.current);let i=n.scrollTop,a=0,o=0,s=()=>{if(o++,a=n.scrollTop===i?a+1:0,i=n.scrollTop,a>=15||o>180){let e=n.getBoundingClientRect().top+n.clientHeight/2,t=r.getBoundingClientRect();t.top<=e&&e<t.bottom||n.scrollTo({top:r.offsetTop,behavior:`instant`});return}C.current=requestAnimationFrame(s)};C.current=requestAnimationFrame(s)};J(()=>(r(!!u&&u.text.trim()!==``),()=>r(!1)),[u?.text]);let T=(e,n,r)=>{if(e.button!==0)return;if(r.id!==o){w(r.id);return}let a=b(r);if(!rl(r,a))return t(`You're looking at ${a.ver}. Switch to the newest version to add notes.`);let s=fl(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:Qc(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=Qc(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)},E=u?i.find(e=>e.id===u.vis):null,D=x?{vis:x.id,...b(x)}:null,O=!!(u&&D&&(u.vis!==D.vis||u.page!==D.page||u.ver!==D.ver||(u.shape||u.justThis)&&u.ratio!==D.ratio)),k=!!E&&E.versions.find(e=>e.id===u?.ver)?.pages[0]?.images.length>1,A=()=>{if(!x)return;let e=b(x);if(!rl(x,e))return t(`You're looking at ${e.ver}. Switch to the newest version to add notes.`);let n=fl(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())},j=X(!1),[M,N]=q(!1),P=async()=>{if(j.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(!rl(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;j.current=!0,N(!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 Vr,e.message))}finally{j.current=!1,N(!1)}},F=async e=>{try{await Z.patch(`/api/notes/${e.id}`,{status:e.status===`done`?`todo`:`done`}),n()}catch(e){t(e.message)}},ee=e=>{let t=i.find(t=>t.id===al(e));t&&(p(e.id),S(t,dl(t,e,b(t))),w(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(pl(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(),w(i[n+1].id);else if(e.key===`ArrowUp`&&n>0)e.preventDefault(),w(i[n-1].id);else if(e.key===`r`||e.key===`R`){let e=xl(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=cl(i,a),te=a.filter(e=>e.stage===`visuals`&&e.status===`todo`).length,ne=new Set(a.filter(e=>e.stage===`visuals`&&e.status===`todo`).map(al)).size,R=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(vl,{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)=>T(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:[te,` open across `,ne,` visual`,ne===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&&w(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!==$c(n).id;return Q(`div`,{class:`vznote${t.status===`done`?` done`:``}${f===t.id?` sel`:``}`,"data-note":t.id,role:`button`,tabIndex:0,onClick:()=>ee(t),onKeyDown:e=>e.key===`Enter`&&ee(t),children:[Q(`span`,{class:`no2`,children:sl(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?fe(t.format):`all ratios`}),Q(`span`,{class:`tag${r?` old`:``}`,children:r?`from ${t.version}`:t.version}),Q(`span`,{class:`tag`,title:t.box?Kc(t.box):t.pin?qc(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,{...dl(n,t,b(n)),ver:t.fixVersion}),w(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(),F(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${O?` away`:``}`,children:[Q(`span`,{class:`lbl`,children:O?`Draft for`:`Adding to`}),Q(`b`,{children:O&&E?il(E,u):il(x,b(x))}),O&&Q(`button`,{class:`btn`,onClick:()=>w(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()&&P()),e.key===`Escape`&&(e.stopPropagation(),d(null),e.currentTarget.blur())}}),u&&!u.shape&&k&&Q(`label`,{class:`vzjust`,children:[Q(`input`,{type:`checkbox`,checked:!!u.justThis,onChange:e=>d({...u,justThis:e.currentTarget.checked})}),`Just `,fe(u.ratio)]}),Q(`div`,{class:`vzcrow`,children:[Q(`button`,{class:`btn primary`,disabled:M,onClick:()=>void P(),children:`Add note`}),Q(`button`,{class:`btn`,onClick:A,children:`Whole image`}),Q(`button`,{class:`btn ghost`,disabled:!u,onClick:()=>d(null),children:u?.text?`Discard draft`:`Cancel`})]})]})]}),R&&Q(yl,{visual:R,view:b(R),notes:a,onPage:e=>S(R,{page:e}),onClose:()=>h(null)})]})}function xl(e,t){return(e.versions.find(e=>e.id===t.ver)??$c(e)).pages[0]?.images.map(e=>e.ratio)??[]}var Sl=[[`all`,`All`],[`picture`,ra.picture],[`voice`,ra.voice],[`music`,ra.music],[`sfx`,ra.sfx],[`mix`,ra.mix],[`visuals`,ra.visuals],[`notes`,ra.notes],[`assets`,ra.assets]];function Cl(e){return Sl.some(([t])=>t===e)}var wl={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=ua(e),a=n[n.length-1];a&&a.date===i?a.entries.push(r):n.push({key:i,date:i,heading:da(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 Dl=new Set([` `,`ArrowLeft`,`ArrowRight`,`ArrowUp`,`ArrowDown`,`Home`,`End`,`PageUp`,`PageDown`]);function Ol(e){return Dl.has(e.key)&&!e.altKey&&!e.ctrlKey&&!e.metaKey}var kl=[`script`,`picture`,`voice`,`music`,`sfx`,`mix`];function Al(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&&kl.includes(e.tab)?{tab:e.tab}:e.area===`assets`?{tab:`assets`}:kl.includes(e.area)?{tab:e.area}:null}function jl(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 Ml(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 Nl(e,t){let n=e.by===`user`?`added by you`:e.by===`agent`?`by the agent`:`by Rushes`;return`${e.text} (${ra[e.area]}, ${t}, ${n})`}function Pl(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 Fl(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 Il(e,t){return`rushes:${e}:${t}`}function Ll(e,t){try{return e?.getItem(t)??null}catch{return null}}function Rl(e,t,n){try{e?.setItem(t,n)}catch{}}var zl=1e3,Bl=40,Vl=()=>{try{return window.sessionStorage}catch{return}},Hl=()=>{try{return window.localStorage}catch{return}};function Ul(e,t){let[n,r]=q(()=>Ll(Vl(),Il(e,`log-open`))===`1`),[i,a]=q(!1),[o,s]=q(()=>Ll(Hl(),Il(e,`log-seen`))),c=t?.mark??null,l=X(o);l.current=o;let u=t=>{s(t),Rl(Hl(),Il(e,`log-seen`),t)};return J(()=>{n&&c&&Fl(c,o)&&u(c)},[n,c]),J(()=>{let t=Il(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&&Fl(c,o),setOpen:t=>{r(t),a(t),Rl(Vl(),Il(e,`log-open`),t?`1`:`0`)},saw:e=>{Fl(e,l.current)&&u(e)}}}function Wl(){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 Gl({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(Wl,{}),Q(`span`,{class:`clabel`,children:`Change Log`}),e.dot&&Q(`span`,{class:`cdot`,"aria-hidden":`true`})]})}function Kl(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 ql(e){return e.log.open?Q(Yl,{...e}):null}function Jl({entry:e,to:t,onGo:n}){let r=la(new Date(e.at)),i=Q(S,{children:[Q(`span`,{class:`ltime`,children:r}),Q(`span`,{class:`ltag ${e.area}`,children:ra[e.area]}),Q(`span`,{class:`ltext`,dir:`auto`,children:[e.text,Q(`span`,{class:`lby`,children:wl[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":Nl(e,r),onClick:()=>n(t),children:i}):Q(`div`,{class:`lrow`,"data-entry":e.id,children:i})}function Yl({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=Ll(Vl(),Il(t,`log-filter`));return Cl(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)>Bl,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(zl)});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(Pl(`read`,e)):m(Pl(`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=ra[i];s(`Added under ${e}. Choose All${Sl.some(([e])=>e===i)?` or ${e}`:``} to see it.`)}b.current&&(b.current.scrollTop=0),await O(!0)}catch(e){s(Pl(`add`,e))}},M=e=>{g(e),Rl(Vl(),Il(t,`log-filter`),e)},N=(e,t)=>{let n=ya(e.key,t,Sl.length,!0);if(n===null)return;e.preventDefault();let r=Sl[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)},ee=t=>{c(t),window.innerWidth<560&&(e.setOpen(!1),o.current?.focus())},I=X(ee);I.current=ee;let L=X(e=>I.current(e)).current,te=async()=>{try{s(`Saved to ${(await Z.post(`/api/exports/change-log`,{})).path}`)}catch(e){s(Pl(`export`,e))}},ne=jr(()=>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(Jl,{entry:e,to:Al(e,r),onGo:L})},e.id))})]},e.key)):null,[l,r,ua(new Date)]),R=l&&d?jl(l.entries,d.entries):0,re=l!==null&&l.total===0&&l.undated.length===0,ie=l!==null&&!re&&l.entries.length===0&&l.undated.length===0;return Q(`aside`,{id:`changelog`,class:`drawer`,ref:y,"aria-label":`Change Log`,onKeyDown:e=>{Ol(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:Sl.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:[R>0&&Q(`button`,{type:`button`,class:`dpill`,onClick:P,children:[R,` new`]}),Q(`div`,{class:`dlist`,ref:b,tabIndex:0,role:`group`,"aria-label":`Entries`,onScroll:F,children:[l===null&&!p&&Q(`p`,{class:`dempty`,children:`Loading…`}),l===null&&p&&Q(`p`,{class:`dempty dproblem`,role:`alert`,children:p}),re&&Q(`p`,{class:`dempty`,children:`Nothing yet. Rushes writes a line here whenever a cut, a take or a variant is added.`}),ie&&Q(`p`,{class:`dempty`,children:`Nothing for this filter.`}),ne,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?Ml(l):``}),Q(`button`,{type:`button`,class:`btn`,onClick:()=>void te(),children:`Export as Markdown`})]})]})}var Xl=[`script`,`picture`,`voice`,`music`,`sfx`,`mix`,`visuals`],Zl=new Set([`picture`,`voice`,`music`,`sfx`,`mix`]),Ql=e=>e instanceof HTMLElement&&(e.isContentEditable||/^(INPUT|TEXTAREA|SELECT)$/.test(e.tagName));function $l({tab:e,projectName:t,filmName:n,found:r,onReview:i,toast:a}){let o=e===`brief`||e===`storyboard`,{what:s,unlocks:c}=e===`brief`?Ie:e===`storyboard`?Le:Ae[e],l=e===`assets`?`Assets`:e===`brief`?`Brief`:e===`storyboard`?`Storyboard`:ke[e],u=e===`assets`?`grid`:e===`brief`?`brief`:e===`storyboard`?`story`:Ca[e],d=e===`brief`?Re(t,n):e===`storyboard`?ze(t,n):Me(e,t,n),f=o?null:Pn(e,r),p=X(null),m=async()=>{try{await navigator.clipboard.writeText(d),a(`Prompt copied`)}catch{p.current?.select(),a(`Prompt selected: press ${kn(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 eu(){let{state:e,assets:t,problem:n,wrongProject:r,refresh:i,proxyJobs:a,noteProxyJob:o}=ri(),[s,c]=q(null),[l,u]=q(null),[d,f]=q(null),[p,m]=q(null),[h,g]=q(null),[_,v]=q(null),[y,b]=q(`script`),x=X(null),[C,w]=q(!1),[T,E]=q(!1),[D,O]=q(!1),[k,A]=q(!1),[j,M]=q(0),[N,P]=q({}),F=X(void 0),ee=X(new Map),I=X(null),L=(e,t)=>P(n=>({...n,[e]:t})),[te,ne]=q({}),R=(e,t)=>ne(n=>({...n,[e]:t})),[re,ie]=q({}),[ae,oe]=q({}),[z,se]=q(!1),ce=X(new Set),B=(e,t=2400,n=null)=>{m(e),g(n),clearTimeout(F.current),F.current=window.setTimeout(()=>{m(null),g(null)},t)},[le,ue]=q({n:0,pending:!1}),[de,V]=q(null),pe=Ul(Hr()??``,e?.log),he=X(null);J(()=>{for(let e of Object.values(a))e.state!==`failed`||ce.current.has(e.job)||(ce.current.add(e.job),B(e.reason??`Couldn't make the proxy`))},[a]),J(()=>{if(!e)return;if(s===null){let t=Ge(e.tabs,e.brief);c(t),Pe(t)&&b(t)}let t=e.project.videos.find(Ce);l===null&&t&&u(t.id)},[e]),J(()=>{e?.project.name&&(document.title=`${e.project.name} · Rushes`)},[e?.project.name]);let H=e?.project.videos.find(e=>e.id===l)??e?.project.videos.find(Ce),U=Se(H),ge=G(H),W=H?.versions.find(e=>e.id===d)??ge,ve=!!H?.lockedVersion,ye=W?.fps??e?.project.fps??30,be=W?t.find(e=>e.kind===`cut`&&e.path===W.file):void 0,xe=e?.notes.notes.filter(e=>e.stage===`picture`&&(!e.video||e.video===H?.id))??[],De=W?me(W,ae[W.file]):[],Oe=H&&W?Yn(H,W.id):void 0,K=Xn(De,H?re[H.id]:void 0),je=new Set(t.filter(e=>e.kind===`cut`&&e.missing).map(e=>e.path)),Me=W?Zn({views:De,previous:Oe?me(Oe):[],current:K,versionDuration:W.duration,notes:xe,missing:je}):[],Ne=e=>!H||e===K?!1:z?(B(`Add or clear your box on ${K?fe(K):`this format`} first`),!1):(ie(t=>({...t,[H.id]:e})),!0);J(()=>{D&&d===null&&ge?(f(ge.id),A(!0)):!D&&k&&d===ge?.id&&(f(null),A(!1))},[D,d,ge?.id]),J(()=>{!k&&d!==null&&d===ge?.id&&f(null)},[ge?.id,k,d]);let Re=U&&W&&U.id!==W.id&&(ve||k)?U.id:null,ze=()=>{U&&f(U.id),A(!1)},We=e=>{if(e===H?.id)return;if(H&&D)return B(`Add or clear your note on ${H.name} first`);if(H){let e=I.current;e?.pause();let t=e?_e(e.currentTime,ye):ee.current.get(H.id)?.t??0;ee.current.set(H.id,{versionId:d,held:k,t})}let t=ee.current.get(e);u(e),f(t?.versionId??null),A(t?.held??!1),M(t?.t??0)},qe=async()=>{if(H&&W)try{await Z.put(`/api/videos/${H.id}/lock`,{version:H.lockedVersion?null:W.id}),i()}catch(e){B(e.message)}},[Je,Ye]=q(0),Xe=X(We);Xe.current=We;let Ze=async(t,n)=>{if(!e)return!1;if(n&&t.id===H?.id&&D)return B(`Add or clear your note on ${t.name} first`),!1;try{if(await Z.put(`/api/videos/${t.id}/shelve`,{shelved:n}),n&&t.id===H?.id){let n=Ee(e.project.videos,t.id);n?We(n):u(null)}return i(),n?B(`“${t.name}” shelved`,6e3,{label:`Undo`,run:()=>void Ze(t,!1).then(e=>e&&Xe.current(t.id))}):B(`“${t.name}” restored`),!0}catch(e){return B(e.message),!1}},Qe=()=>{H&&Ze(H,!H.shelved)},$e=t=>{if(D)return B(`Add or clear your note first`);if(t.tab===`assets`)return ot();if(t.video&&t.video!==H?.id&&We(t.video),t.version){let n=e?.project.videos.find(e=>e.id===(t.video??H?.id));f(t.version===G(n)?.id?null:t.version),A(!1)}c(t.tab),v(null),t.row&&Kl(t.row)},et=e?.tabs??[],tt=e=>et.find(t=>t.stage===e),nt=Fn(e?.found),rt=t.length>0||nt!==null,it=e=>{if(D&&e!==s)return B(`Add or clear your note first`);c(e),v(null),Pe(e)&&b(e)},at=()=>{let t={brief:!!e?.brief.exists,script:!!tt(`script`)?.unlocked,storyboard:!!e?.storyboard.exists};it(Ke(y,t))},ot=()=>{if(D&&s!==`assets`)return B(`Add or clear your note first`);c(`assets`),v(null)},st=e=>{if(D&&s!==`assets`)return B(`Add or clear your note first`);ue(t=>({n:t.n+1,kind:e,pending:!0})),c(`assets`),v(null)},ct=X(st);ct.current=st,J(()=>{Wt(location.search).test&&(window.__rushesOpenFound=e=>ct.current(e))},[]),Y(()=>{let t=t=>{if(t.altKey&&!t.metaKey&&!t.ctrlKey&&!t.shiftKey&&(t.key===`ArrowLeft`||t.key===`ArrowRight`)){if(s!==`picture`||Ql(t.target))return;t.preventDefault();let e=Qn(Me,K,t.key===`ArrowRight`?1:-1);e&&Ne(e);return}if(Ql(t.target)||t.metaKey||t.ctrlKey||t.altKey)return;let n=Number(t.key);if(n===1?at():n>=2&&n<=7?it(Xl[n-1]):n===8&&ot(),t.key===`S`&&t.shiftKey&&!t.repeat&&Qe(),(t.key===`[`||t.key===`]`)&&e){let n=we(e.project.videos,l,t.key===`]`?1:-1);n&&We(n)}t.key===`?`&&w(e=>!e),t.key===`Escape`&&(w(!1),v(null))};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)});let lt=X(null),ut=X(null),dt=X(null),ft=()=>{let e=lt.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(ft),J(()=>{let e=()=>ft();window.addEventListener(`resize`,e);let t=!0;return document.fonts?.ready.then(()=>{t&&ft()}),()=>{t=!1,window.removeEventListener(`resize`,e)}},[]);let pt=!!e&&!!s;J(()=>{if(!pt)return;let e=new ResizeObserver(()=>ft());for(let t of[ut.current,dt.current])t&&e.observe(t,{box:`border-box`});return()=>e.disconnect()},[pt]);let mt=async()=>{if(!e||!s)return;w(!1);let t=s===`brief`||s===`storyboard`?await x.current?.():void 0,n=(s===`brief`?t:void 0)??e.brief,r=(s===`storyboard`?t:void 0)??e.storyboard,a=[n.exists&&(s===`brief`||n.changed>0)?Ve(e.project.name,H?.name??null,n):null,r.exists&&(s===`storyboard`||r.changed>0)?Ue(e.project.name,H?.name??null,r):null].filter(e=>e!==null),o=null;try{o=(await Z.post(`/api/batches`,{})).batch}catch(e){if(!(e instanceof Vr&&e.code===`empty_batch`))return B(e.message)}if(!o&&a.length===0)return s===`brief`&&!n.exists?B(`There's no brief yet: copy the prompt on this page for your agent`):s===`storyboard`&&!r.exists?B(`There's no storyboard yet: copy the prompt on this page for your agent`):B(`Nothing open to send on any tab`);v(o?{id:o.id,prompt:[o.prompt,...a].join(`
|
|
8
|
+
|
|
9
|
+
`)}:{id:`plan`,title:`Message for your agent`,prompt:a.join(`
|
|
10
|
+
|
|
11
|
+
`)}),E(!1),o&&i()},ht=async()=>{if(_)try{await navigator.clipboard.writeText(_.prompt),E(!0)}catch{B(`Couldn't reach the clipboard. Select the text and copy it.`)}};if(!e||!s)return Q(`div`,{class:`shell`,children:n?Q(`div`,{class:`banner`,children:[Q($,{name:`alert`}),n]}):Q(`div`,{class:`empty`,children:Q(`p`,{children:`Loading…`})})});let gt=e.notes.notes.filter(e=>e.stage===`picture`&&(!e.video||e.video===H?.id)),_t=t=>e.notes.notes.some(e=>e.stage===`picture`&&e.status===`todo`&&(!e.video||e.video===t)),vt=s===`assets`?rt:s===`brief`?e.brief.exists:s===`storyboard`?e.storyboard.exists:tt(s)?.unlocked??!1,yt=He(et,e.brief,e.storyboard),bt=!!tt(`picture`)?.unlocked,xt=Fe(e.brief,e.script.sections,e.storyboard),St=e.build.started&&!bt,Ct=[{page:`brief`,name:`Brief`,icon:`brief`,unlocked:e.brief.exists,progress:St?xt.brief:null,ask:Ie.ask},{page:`script`,name:`Script`,icon:Ca.script,unlocked:!!tt(`script`)?.unlocked,progress:St&&tt(`script`)?.unlocked?xt.script:null,ask:Ae.script.ask},{page:`storyboard`,name:`Storyboard`,icon:`story`,unlocked:e.storyboard.exists,progress:St&&e.storyboard.exists?xt.storyboard:null,ask:Le.ask}],wt=e.brief.changed+e.storyboard.changed+(tt(`script`)?.todo??0),Tt=async()=>{try{await navigator.clipboard.writeText(Be(e.project.name,H?.name??null)),B(`Prompt copied`)}catch{B(`Couldn't reach the clipboard. Ask your agent to build the film from the approved plan.`)}};return Q(`div`,{class:`shell`,children:[Q(`header`,{class:`head`,ref:ut,children:[Q(`span`,{class:`logo`,children:Q(`svg`,{viewBox:`0 0 24 24`,children:Q(`path`,{d:`M8 5v14l11-7z`})})}),Q(`nav`,{class:`crumb`,"aria-label":`Project`,children:[Q(`span`,{children:e.project.name}),e.project.id&&Q(`span`,{class:`pid mono`,children:e.project.id}),H&&!Te(e.project.videos,H.id)&&Q(S,{children:[Q(`span`,{class:`slash`,children:`/`}),Q(`span`,{class:`sel`,children:H.name})]})]}),nt!==null&&In(e.found)!==de&&Q(`button`,{type:`button`,class:`foundchip`,"data-tip":`Open the other files found in this project`,onClick:()=>st(),children:[Q(`span`,{class:`dot`}),Q(`span`,{class:`ftext`,children:nt})]}),e.project.videos.length>0&&Q(yo,{films:e.project.videos,currentId:H?.id??null,headRef:ut,hasTodo:_t,onSwitch:We,onRestore:t=>{let n=e.project.videos.find(e=>e.id===t);n&&Ze(n,!1)},shelvedRequest:Je}),H&&Q(S,{children:[Q(`span`,{class:`plabel`,children:`Picture`}),W&&Q(uc,{versions:H.versions,shown:W,lockedVersion:H.lockedVersion,onPick:e=>{f(e===ge?.id?null:e),A(!1)}}),W&&Q(`button`,{class:`btn ib lockbtn`,"aria-pressed":ve,disabled:!!H.shelved,"aria-label":ve?`Picture locked at ${H.lockedVersion} · unlock`:`Lock picture at ${W.id}`,"data-tip":ve?`Picture locked at ${H.lockedVersion} · unlock`:`Lock picture at ${W.id}`,onClick:()=>void qe(),children:Q($,{name:ve?`lock`:`unlock`})}),Re&&Q(`button`,{class:`chipx go`,"aria-label":`${Re} is ready`,"data-tip":`Switch to the newest cut`,onClick:ze,children:[Q($,{name:`new`}),Re,` ready`]}),s===`picture`&&W&&Me.length>0&&Q(Co,{chips:Me,versionId:W.id,prompt:nr(e.project.name,H.name,W.id),onSelect:Ne,toast:B})]}),Q(`span`,{class:`sp`}),Q(go,{video:H,onToggleShelved:Qe}),Q(`button`,{class:`btn ghost ib tip-below`,"data-tip":`Shortcuts ?`,"aria-label":`Keyboard shortcuts`,onClick:()=>{v(null),w(!C)},children:Q($,{name:`kbd`})}),Q(Gl,{log:pe,buttonRef:he}),Q(`button`,{class:`btn primary tip-below`,"data-tip":`Every tab's open notes, on every film`,onClick:()=>void mt(),children:[`Send to agent`,yt>0&&Q(`span`,{class:`count`,children:yt})]})]}),Q(ql,{log:pe,projectId:Hr()??``,head:e.log,project:e.project,stage:s===`brief`||s===`storyboard`?`script`:s,header:ut,buttonRef:he,toast:B,onJump:$e}),_&&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:_.title??`Batch ${_.id} is ready`}),Q(`span`,{class:`sp`}),Q(`button`,{class:`btn ghost ib sm`,"aria-label":`Close`,onClick:()=>v(null),children:Q($,{name:`x`})})]}),Q(`pre`,{children:_.prompt}),Q(`div`,{style:{display:`flex`,justifyContent:`flex-end`},children:Q(`button`,{class:`btn primary`,onClick:()=>void ht(),children:[Q($,{name:`copy`}),T?`Copied`:`Copy prompt`]})})]}),C&&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:()=>w(!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,h&&Q(`button`,{type:`button`,class:`toastact`,onClick:()=>{m(null),g(null),h.run()},children:h.label})]}),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:dt,role:`tablist`,"aria-label":`Stages`,children:[Q(Cc,{selected:Pe(s)?s:null,rows:Ct,marks:St?xt:null,open:wt,locked:Ct.every(e=>!e.unlocked),ready:St&&e.build.ready,onCopyReady:()=>void Tt(),onPick:e=>it(e)}),Xl.filter(e=>e!==`script`).map(e=>{let t=tt(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 ${Ae[e].ask}`,onClick:()=>it(e),children:[Q($,{name:Ca[e]}),ke[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":rt?void 0:`true`,"data-tip":rt?void 0:`Locked: ask your agent for ${Ae.assets.ask}`,onClick:()=>ot(),children:[Q($,{name:`grid`}),`Assets`,!rt&&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]}),H?.shelved&&Zl.has(s)&&Q(bo,{video:H,onRestore:()=>void Ze(H,!1)}),Q(`main`,{class:`body${H?.shelved?` fshelved`:``}`,ref:lt,children:s===`assets`?vt?Q(oo,{assets:t,videos:e.project.videos,state:e,foundRequest:le,onFoundRequestUsed:()=>ue(e=>e.pending?{n:e.n,pending:!1}:e),onFoundSeen:V,toast:B,onChanged:()=>void i()}):Q($l,{tab:`assets`,projectName:e.project.name,filmName:H?.name??null,found:e.found?.counts,onReview:st,toast:B}):vt?s===`picture`&&!H?Q(xo,{onOpen:()=>Ye(e=>e+1)}):s===`picture`&&H&&W?Q(mc,{readOnly:!!H.shelved,video:H,version:W,fps:ye,notes:gt,toast:B,onChanged:()=>void i(),onPendingChange:O,startAt:j,grab:N[H.id]??null,onGrabChange:L,playerRef:I,ffmpeg:e.proxies?.ffmpeg??!1,autoProxy:e.project.autoProxy,proxyJob:a[Sn(H.id,W.id)],noteProxyJob:o,source:te[H.id]??`proxy`,onSourceChange:R,fileSize:be?.size??null,fileRev:be?ai(be):void 0,formats:De,format:K,formatMissing:!!K&&je.has(De.find(e=>e.id===K)?.file??``),onPrimarySize:(e,t,n)=>oe(r=>r[e]?r:{...r,[e]:{width:t,height:n}}),onBoxPendingChange:se,onFormatChange:Ne},H.id):s===`brief`?Q(mo,{brief:e.brief,toast:B,onChanged:()=>void i(),settle:x}):s===`storyboard`?Q(Sc,{board:e.storyboard,brief:e.brief,toast:B,onChanged:()=>void i(),settle:x}):s===`visuals`?Q(bl,{state:e,toast:B,onChanged:()=>void i(),onPendingChange:O}):s===`script`?Q(Oc,{script:e.script,toast:B,onChanged:()=>void i()}):s===`voice`?Q(Vc,{state:e,assets:t,video:H??null,toast:B,onChanged:()=>void i(),onPendingChange:O},`voice`):s===`mix`?Q(Ms,{state:e,assets:t,video:H??null,toast:B,onChanged:()=>void i(),onPendingChange:O},`mix`):s===`music`||s===`sfx`?Q(Nc,{stage:s,state:e,assets:t,video:H??null,toast:B,onChanged:()=>void i(),onPendingChange:O},s):null:Q($l,{tab:s,projectName:e.project.name,filmName:H?.name??null,found:e.found?.counts,onReview:st,toast:B})}),e.version&&Q(`span`,{class:`ver`,"aria-label":`Rushes version ${e.version}`,children:[`v`,e.version]})]})}Vt(document),ae(Q(eu,{}),document.getElementById(`app`));
|