rushes 0.10.1 → 0.12.0
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 +14 -4
- package/README.md +14 -8
- package/dist/cli/demo.js +3 -2
- package/dist/cli/main.js +33 -1
- package/dist/core/agentRules.js +7 -0
- package/dist/core/balance.js +238 -0
- package/dist/core/batches.js +29 -11
- package/dist/core/exportNotes.js +4 -2
- package/dist/core/films.js +114 -0
- package/dist/core/log.js +35 -3
- package/dist/core/logEvents.js +7 -7
- package/dist/core/notes.js +19 -1
- package/dist/core/schema.js +69 -14
- package/dist/core/script.js +67 -0
- package/dist/core/tabs.js +15 -7
- package/dist/core/takes.js +1 -1
- package/dist/mcp/tools.js +90 -23
- package/dist/server/agent/adapters.js +39 -8
- package/dist/server/agent/rules.js +106 -9
- package/dist/server/agent/runner.js +135 -35
- package/dist/server/agent/setupOnce.js +44 -0
- package/dist/server/app.js +348 -65
- package/dist/server/assets.js +40 -14
- package/dist/server/balance.js +103 -0
- package/dist/server/brief.js +9 -7
- package/dist/server/files.js +3 -2
- package/dist/server/films.js +43 -0
- package/dist/server/found.js +2 -1
- package/dist/server/logbook.js +28 -2
- package/dist/server/plans.js +68 -0
- package/dist/server/record.js +31 -13
- package/dist/server/start.js +15 -7
- package/dist/server/storyboard.js +8 -6
- package/dist/version.js +1 -1
- package/package.json +1 -1
- package/skills/rushes/SKILL.md +4 -4
- package/web-dist/assets/{index-BIJlv6zN.css → index-BCYA0Awp.css} +1 -1
- package/web-dist/assets/index-LPvsS2vO.js +70 -0
- package/web-dist/index.html +2 -2
- package/web-dist/assets/index-D430jOsg.js +0 -70
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
var e=(e,t)=>()=>(t||(e((t={exports:{}}).exports,t),e=null),t.exports);(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 t,n,r,i,a,o,s,c,l,u,d,f,p,m,h,g={},_=[],v=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i,y=Array.isArray;function b(e,t){for(var n in t)e[n]=t[n];return e}function x(e){e&&e.parentNode&&e.parentNode.removeChild(e)}function S(e,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?t.call(arguments,2):r),typeof e==`function`&&e.defaultProps!=null)for(o in e.defaultProps)s[o]===void 0&&(s[o]=e.defaultProps[o]);return C(e,s,i,a,null)}function C(e,t,i,a,o){var s={type:e,props:t,key:i,ref:a,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:o??++r,__i:-1,__u:0};return o==null&&n.vnode!=null&&n.vnode(s),s}function w(e){return e.children}function T(e,t){this.props=e,this.context=t}function E(e,t){if(t==null)return e.__?E(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`?E(e):null}function D(e){if(e.__P&&e.__d){var t=e.__v,r=t.__e,i=[],a=[],o=b({},t);o.__v=t.__v+1,n.vnode&&n.vnode(o),I(e.__P,o,t,e.__n,e.__P.namespaceURI,32&t.__u?[r]:null,i,r??E(t),!!(32&t.__u),a),o.__v=t.__v,o.__.__k[o.__i]=o,re(i,o,a),t.__e=t.__=null,o.__e!=r&&O(o)}}function O(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}),O(e)}function k(e){(!e.__d&&(e.__d=!0)&&i.push(e)&&!A.__r++||a!=n.debounceRendering)&&((a=n.debounceRendering)||o)(A)}function A(){try{for(var e,t=1;i.length;)i.length>t&&i.sort(s),e=i.shift(),t=i.length,D(e)}finally{i.length=A.__r=0}}function j(e,t,n,r,i,a,o,s,c,l,u){var d,f,p,m,h,v,y=r&&r.__k||_,b=t.length;for(c=ee(n,t,y,c,b),d=0;d<b;d++)(p=n.__k[d])!=null&&(f=p.__i!=-1&&y[p.__i]||g,p.__i=d,v=I(e,p,f,i,a,o,s,c,l,u),m=p.__e,p.ref&&f.ref!=p.ref&&(f.ref&&ae(f.ref,null,p),u.push(p.ref,p.__c||m,p)),h==null&&m!=null&&(h=m),4&p.__u?(c=M(p,c,e),f.__e&&(f.__e=null)):typeof p.type==`function`&&v!==void 0?c=v:m&&(c=m.nextSibling),p.__u&=-7);return n.__e=h,c}function ee(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]=C(null,o,null,null,null):y(o)?o=e.__k[a]=C(w,{children:o},null,null,null):o.constructor===void 0&&o.__b>0?o=e.__k[a]=C(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=N(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=E(s)),oe(s,s));return r}function M(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=M(r[i],t,n));return t}e.__e!=t&&(t&&e.type&&!t.parentNode&&(t=E(e)),t=n.insertBefore(e.__e,t||null));do t&&=t.nextSibling;while(t!=null&&t.nodeType==8);return t}function N(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 P(e,t,n){t[0]==`-`?e.setProperty(t,n??``):e[t]=n==null?``:typeof n!=`number`||v.test(t)?n:n+`px`}function F(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||P(e.style,t,``);if(n)for(t in n)r&&n[t]==r[t]||P(e.style,t,n[t])}}else if(t[0]==`o`&&t[1]==`n`)a=t!=(t=t.replace(d,`$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[u]=r[u]:(n[u]=f,e.addEventListener(t,a?m:p,a)):e.removeEventListener(t,a?m:p,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 te(e){return function(t){if(this.l){var r=this.l[t.type+e];if(t[l]==null)t[l]=f++;else if(t[l]<r[u])return;return r(n.event?n.event(t):t)}}}function I(e,t,r,i,a,o,s,c,l,u){var d,f,p,m,h,g,v,S,C,D,O,k,A,ee,M,N,P=t.type;if(t.constructor!==void 0)return null;128&r.__u&&(l=!!(32&r.__u),o=[c=t.__e=r.__e]),(d=n.__b)&&d(t);n:if(typeof P==`function`){f=s.length;try{if(C=t.props,D=P.prototype&&P.prototype.render,O=(d=P.contextType)&&i[d.__c],k=d?O?O.props.value:d.__:i,r.__c?S=(p=t.__c=r.__c).__=p.__E:(D?t.__c=p=new P(C,k):(t.__c=p=new T(C,k),p.constructor=P,p.render=se),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&&P.getDerivedStateFromProps!=null&&(p.__s==p.state&&(p.__s=b({},p.__s)),b(p.__s,P.getDerivedStateFromProps(C,p.__s))),h=p.props,g=p.state,p.__v=t,m)D&&P.getDerivedStateFromProps==null&&p.componentWillMount!=null&&p.componentWillMount(),D&&p.componentDidMount!=null&&p.__h.push(p.componentDidMount);else{if(D&&P.getDerivedStateFromProps==null&&C!==h&&p.componentWillReceiveProps!=null&&p.componentWillReceiveProps(C,k),t.__v==r.__v||!p.__e&&p.shouldComponentUpdate!=null&&!1===p.shouldComponentUpdate(C,p.__s,k)){t.__v!=r.__v&&(p.props=C,p.state=p.__s,p.__d=!1),t.__e=r.__e,t.__k=r.__k,t.__k.some(function(e){e&&(e.__=t)}),_.push.apply(p.__h,p._sb),p._sb=[],p.__h.length&&s.push(p),c=E(r);break n}p.componentWillUpdate!=null&&p.componentWillUpdate(C,p.__s,k),D&&p.componentDidUpdate!=null&&p.__h.push(function(){p.componentDidUpdate(h,g,v)})}if(p.context=k,p.props=C,p.__P=e,p.__e=!1,A=n.__r,ee=0,D)p.state=p.__s,p.__d=!1,A&&A(t),d=p.render(p.props,p.state,p.context),_.push.apply(p.__h,p._sb),p._sb=[];else do p.__d=!1,A&&A(t),d=p.render(p.props,p.state,p.context),p.state=p.__s;while(p.__d&&++ee<25);p.state=p.__s,p.getChildContext!=null&&(i=b(b({},i),p.getChildContext())),D&&!m&&p.getSnapshotBeforeUpdate!=null&&(v=p.getSnapshotBeforeUpdate(h,g)),M=d!=null&&d.type===w&&d.key==null?L(d.props.children):d,c=j(e,y(M)?M:[M],t,r,i,a,o,s,c,l,u),p.base=t.__e,t.__u&=-161,p.__h.length&&s.push(p),S&&(p.__E=p.__=null)}catch(e){if(s.length=f,t.__v=null,l||o!=null){if(e.then){for(t.__u|=l?160:128;c&&c.nodeType==8&&c.nextSibling;)c=c.nextSibling;o!=null&&(o[o.indexOf(c)]=null),t.__e=c}else if(o!=null)for(N=o.length;N--;)x(o[N])}else t.__e=r.__e;t.__k??=r.__k||[],e.then||ne(t),n.__e(e,t,r)}}else o==null&&t.__v==r.__v?(t.__k=r.__k,t.__e=r.__e):c=t.__e=ie(r.__e,t,r,i,a,o,s,l,u);return(d=n.diffed)&&d(t),128&t.__u?void 0:c}function ne(e){e&&(e.__c&&(e.__c.__e=!0),e.__k&&e.__k.some(ne))}function re(e,t,r){for(var i=0;i<r.length;i++)ae(r[i],r[++i],r[++i]);n.__c&&n.__c(t,e),e.some(function(t){try{e=t.__h,t.__h=[],e.some(function(e){e.call(t)})}catch(e){n.__e(e,t.__v)}})}function L(e){return typeof e!=`object`||!e||e.__b>0?e:y(e)?e.map(L):e.constructor===void 0?b({},e):null}function ie(e,r,i,a,o,s,c,l,u){var d,f,p,m,h,_,v,b=i.props||g,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((h=s[d])&&`setAttribute`in h==!!C&&(C?h.localName==C:h.nodeType==3)){e=h,s[d]=null;break}}if(e==null){if(C==null)return document.createTextNode(S);e=document.createElementNS(o,C,S.is&&S),l&&=(n.__m&&n.__m(r,s),!1),s=null}if(C==null)b===S||l&&e.data==S||(e.data=S);else{if(s=C==`textarea`&&S.defaultValue!=null?null:s&&t.call(e.childNodes),!l&&s!=null)for(b={},d=0;d<e.attributes.length;d++)b[(h=e.attributes[d]).name]=h.value;for(d in b)h=b[d],d==`dangerouslySetInnerHTML`?p=h:d==`children`||d in S||d==`value`&&`defaultValue`in S||d==`checked`&&`defaultChecked`in S||F(e,d,null,h,o);for(d in S)h=S[d],d==`children`?m=h:d==`dangerouslySetInnerHTML`?f=h:d==`value`?_=h:d==`checked`?v=h:l&&typeof h!=`function`||b[d]===h||F(e,d,h,b[d],o);if(f)l||p&&(f.__html==p.__html||f.__html==e.innerHTML)||(e.innerHTML=f.__html),r.__k=[];else if(p&&(e.innerHTML=``),j(r.type==`template`?e.content:e,y(m)?m:[m],r,i,a,C==`foreignObject`?`http://www.w3.org/1999/xhtml`:o,s,c,s?s[0]:i.__k&&E(i,0),l,u),s!=null)for(d=s.length;d--;)x(s[d]);l&&C!=`textarea`||(d=`value`,C==`progress`&&_==null?e.removeAttribute(`value`):_!=null&&(_!==e[d]||C==`progress`&&!_||C==`option`&&_!=b[d])&&F(e,d,_,b[d],o),d=`checked`,v!=null&&v!=e[d]&&F(e,d,v,b[d],o))}return e}function ae(e,t,r){try{if(typeof e==`function`){var i=typeof e.__u==`function`;i&&e.__u(),i&&t==null||(e.__u=e(t))}else e.current=t}catch(e){n.__e(e,r)}}function oe(e,t,r){var i,a;if(n.unmount&&n.unmount(e),(i=e.ref)&&(i.current&&i.current!=e.__e||ae(i,null,t)),(i=e.__c)!=null){if(i.componentWillUnmount)try{i.componentWillUnmount()}catch(e){n.__e(e,t)}i.base=i.__P=i.__n=null}if(i=e.__k)for(a=0;a<i.length;a++)i[a]&&oe(i[a],t,r||typeof e.type!=`function`);r||x(e.__e),e.__c=e.__=e.__e=void 0}function se(e,t,n){return this.constructor(e,n)}function ce(e,r,i){var a,o,s,c;r==document&&(r=document.documentElement),n.__&&n.__(e,r),o=(a=typeof i==`function`)?null:i&&i.__k||r.__k,s=[],c=[],I(r,e=(!a&&i||r).__k=S(w,null,[e]),o||g,g,r.namespaceURI,!a&&i?[i]:o?null:r.firstChild?t.call(r.childNodes):null,s,!a&&i?i:o?o.__e:r.firstChild,a,c),re(s,e,c),e.props.children=null}function le(e){function t(e){var n,r;return this.getChildContext||(n=new Set,(r={})[t.__c]=this,this.getChildContext=function(){return r},this.componentWillUnmount=function(){n=null},this.shouldComponentUpdate=function(e){this.props.value!=e.value&&n.forEach(function(e){e.__e=!0,k(e)})},this.sub=function(e){n.add(e);var t=e.componentWillUnmount;e.componentWillUnmount=function(){n&&n.delete(e),t&&t.call(e)}}),e.children}return t.__c=`__cC`+h++,t.__=e,t.Provider=t.__l=(t.Consumer=function(e,t){return e.children(t)}).contextType=t,t}t=_.slice,n={__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}},r=0,T.prototype.setState=function(e,t){var n=this.__s!=null&&this.__s!=this.state?this.__s:this.__s=b({},this.state);typeof e==`function`&&(e=e(b({},n),this.props)),e&&b(n,e),e!=null&&this.__v&&(t&&this._sb.push(t),k(this))},T.prototype.forceUpdate=function(e){this.__v&&(this.__e=!0,e&&this.__h.push(e),k(this))},T.prototype.render=w,i=[],o=typeof Promise==`function`?Promise.prototype.then.bind(Promise.resolve()):setTimeout,s=function(e,t){return e.__v.__b-t.__v.__b},A.__r=0,c=Math.random().toString(8),l=`__d`+c,u=`__a`+c,d=/(PointerCapture)$|Capture$/i,f=0,p=te(!1),m=te(!0),h=0;var ue=[[1,1],[4,5],[5,4],[4,3],[3,4],[3,2],[2,3],[16,9],[9,16],[21,9],[9,21]],de=/^\d+(?:\.\d+)?x\d+(?:\.\d+)?$/,fe=[`9x16`,`4x5`,`1x1`,`4x3`,`16x9`];function pe(e,t){return[e,t].every(e=>Number.isInteger(e)&&e>=1&&e<=1e5)}function me(e,t){for(;t;)[e,t]=[t,e%t];return e}var he=e=>String(Number(e.toFixed(2))),R=Math.log(1.01)+1e-12;function ge(e){let t=null,n=1/0;for(let r of ue){let i=Math.abs(Math.log(e/(r[0]/r[1])));i<n&&(n=i,t=r)}return{best:t,err:n}}function _e(e,t){if(!pe(e,t))throw RangeError(`Not a picture size: ${e}×${t}`);let{best:n,err:r}=ge(e/t);if(n&&r<=R)return`${n[0]}:${n[1]}`;let i=me(e,t);return e/i<=32&&t/i<=32?`${e/i}:${t/i}`:e>=t?`${he(e/t)}:1`:`1:${he(t/e)}`}var z=e=>e.replace(`:`,`x`),ve=e=>e.replace(`x`,`:`);function ye(e){let t=e=>{let t=fe.indexOf(e.id);return t===-1?fe.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 be(e,t){let n=(e.width!==null&&e.height!==null&&pe(e.width,e.height)?{width:e.width,height:e.height}:null)??(t&&pe(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=_e(n.width,n.height);return[{id:z(i),label:i,file:e.file,width:n.width,height:n.height,duration:e.duration,fps:e.fps,primary:!0},...r]}function xe(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 Se(e,t){return t===null||e.format===null||e.format===t}function Ce(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 we(e,t){return Math.round(e*t)}function Te(e,t){return Math.round(we(e,t)/t*1e6)/1e6}function Ee(e,t,n,r){let i=we(e,t)+n;return Math.min(Math.max(0,i/t),r||1/0)}function De(e,t){if(e.t===null)return{t:null,tOut:null,from:null};if(e.stage===`voice`||e.stage===`music`||e.stage===`sfx`||!e.version||e.version===t)return{t:e.t,tOut:e.tOut,from:null};let n=`${e.version} at ${Ce(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 Oe(e,t){return e===null?`Whole`:t===null?Ce(e):`${Ce(e)}–${Ce(t)}`}function ke(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 Ae(e){return e.proposed!==null&&e.proposed.trim()!==e.current.trim()}function je(e){return e?.versions[e.versions.length-1]}function Me(e){if(e?.lockedVersion){let t=e.versions.find(t=>t.id===e.lockedVersion);if(t)return t}return je(e)}var Ne=e=>!e.shelved;function Pe(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(Ne(e[t]))return e[t].id;return null}function Fe(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&&Ne(e));return(r.find(({j:e})=>e>n)??r[r.length-1])?.v.id??null}var Ie={script:`Script`,picture:`Picture`,voice:`Voiceover`,music:`Music`,sfx:`Sound effects`,mix:`Mix`,visuals:`Visuals`},Le={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`}},Re=(e,t)=>t?` ${e} "${t}"`:``,ze={script:(e,t)=>`In Rushes project "${e}", add the voiceover script${Re(`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${Re(`of`,t)} with rushes_add_version.`,voice:(e,t)=>`In Rushes project "${e}", record two or three voice reads${Re(`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${Re(`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${Re(`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${Re(`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${Re(`of`,t)} with rushes_add_version.`};function Be(e,t,n){return ze[e](t,n)}var Ve=[`brief`,`script`,`storyboard`],He=e=>e===`brief`||e===`script`||e===`storyboard`;function Ue(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 We={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`},Ge={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`},Ke={brief:`brief.md`,storyboard:`storyboard.md`};function qe(e,t,n=Ke){return`In Rushes project "${e}", start a brief${Re(`for`,t)}: ask me up to three questions, each with a recommended answer, then write ${n.brief} (see "Starting a film" in AGENTS.md).`}function Je(e,t,n=Ke){return`In Rushes project "${e}", sketch the shots${Re(`for`,t)} from the approved script: write ${n.storyboard} 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 Ye(e,t,n=Ke){return`The plan is approved in Rushes project "${e}"${Re(`for`,t)}. Build the film from ${n.brief} and ${n.storyboard}, name each scene after its planned shot, and register the cut with rushes_add_version.`}function Xe(e,t,n,r=Ke){let i=n.status===`approved`,a=n.sections.filter(e=>e.changed).map(e=>e.heading),o=[`In Rushes project "${e}"${Re(`for`,t)}, the brief is ${i?`approved`:`still a draft`}.`];return a.length&&o.push(`I changed ${a.length===1?`this section`:`these sections`} in ${r.brief}: ${a.join(`, `)}. Read the file again before you go on, and keep my wording.`),o.push(i?`Next: write the script with rushes_set_script.`:`Don't build anything until I approve it.`),o.join(` `)}function Ze(e,t,n,r=Ke){let i=n.shots.filter(e=>e.changed).map(e=>`Shot ${String(e.n).padStart(2,`0`)} · ${e.name}`),a=[`In Rushes project "${e}"${Re(`for`,t)}, ${n.approved} of ${n.total} shots in ${r.storyboard} are approved.`];return i.length&&a.push(`I changed ${i.length===1?`this shot`:`these shots`}: ${i.join(`, `)}. Read ${r.storyboard} again before you go on, keep my wording, and update the still${i.length===1?``:`s`} if what happens has changed.`),a.push(n.approved===n.total&&n.total>0?`Next: build the film.`:`Don't build anything until I approve them all.`),a.join(` `)}function B(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 Qe(e,t){return e.find(e=>e.stage===`picture`)?.unlocked?`picture`:t.exists?`brief`:et(e)}function $e(e,t){return t[e]?e:Ve.find(e=>t[e])??e}function et(e){return e.find(e=>e.stage===`picture`)?.unlocked?`picture`:e.find(e=>e.unlocked)?.stage??`picture`}function tt(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 nt(e){return String(e).padStart(2,`0`)}function rt(e,t){return Math.ceil(e*t-1e-9)/t}function it(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 at(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 ot=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`]),st=new Set([`mp4`,`mov`,`m4v`,`webm`,`mkv`]);function ct(e){let t=e.lastIndexOf(`.`);return t===-1?``:e.slice(t+1).toLowerCase()}var lt=[{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},{id:`visual`,title:`Visuals`,kinds:[`visual`],view:`grid`,filmFilter:!1,gridToggle:!0}],ut=(e,t)=>e.filmFilter||t>1,dt=new Set([`doc`,`caption`,`export`,`edit`]),ft=new Set([`md`,`txt`,`srt`,`vtt`]);function pt(e){return ft.has(ct(e.path))}function mt(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=>cr(e,a,o)));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`)?ht(u):u}function ht(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 ye(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 gt(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 _t(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 vt(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}}function yt(e){return e.range.in!==null||e.marks.length>0||e.hasText}var bt=[1,2,3,6,9],xt=[`rise`,`fall`,`louder`,`quieter`],St={rise:`fall`,fall:`rise`,louder:`quieter`,quieter:`louder`},Ct=e=>e===`louder`||e===`quieter`;function wt(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 Tt(e){return e&&e.length>0?e.map(wt).join(` · `):null}function Et(e,t,n=3){let r=e.some(e=>e.kind===t),i=e.filter(e=>e.kind!==t&&e.kind!==St[t]);return r||i.push(Ct(t)?{kind:t,db:n}:{kind:t}),i.sort((e,t)=>xt.indexOf(e.kind)-xt.indexOf(t.kind))}function Dt(e,t,n){return e.map(e=>e.kind===t&&Ct(t)?{kind:t,db:n}:e)}function Ot(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 kt(e,t=0){let n=e=>e!==void 0&&String(e).trim()?String(e).trim():null,r=[],i=n(e?.description);i&&r.push(i);let a=n(e?.bpm);a&&r.push(`${a} BPM`);let o=n(e?.key);if(o&&r.push(o),typeof e?.lufs==`number`&&Number.isFinite(e.lufs))r.push(`${String(e.lufs).replace(`-`,`−`)} LUFS`);else{let t=n(e?.lufs??e?.loudness);t&&r.push(t)}return t>0&&r.push(`${t} cue${t===1?``:`s`}`),r}function At(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:Ot(e.meta,t===`sfx`?e.cues.length:0),file:e.file,cues:e.cues,films:pr(e)});return n}var jt=e=>e.key,Mt=(e,t)=>`${e.key}:${t}`;function Nt(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 Pt(e,t,n=!1){let r=e.map(e=>({value:`v:${e.key}`,label:t(e),on:jt(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:Mt(n,e.id),t:e.t,row:n.key})}return r}function Ft(e,t){if(t===null||!t.includes(`/`))return null;let n=e.find(e=>jt(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 It(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 Lt(e,t){if(t===null)return null;let n=Ft(e,t)??It(e,t);return n?{row:n.row.key,cue:n.cue}:null}function Rt(e,t){return Lt(e,t)?.row??null}function zt(e,t,n){let r=Lt(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 V(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 Bt=new WeakSet,Vt=!1;function Ht(e){Vt||(Vt=!0,e.addEventListener(`focusin`,e=>Ut(e.target),!0),e.addEventListener(`pointerdown`,e=>{let t=e.target?.closest?.(`button`);t&&Bt.delete(t)},!0))}function Ut(e){let t=e;t&&typeof t.matches==`function`&&(t.matches(`:focus-visible`)?Bt.add(t):Bt.delete(t))}function Wt(e){let t=e;if(!t||typeof t.closest!=`function`)return!1;let n=t.closest(`button`);return!!n&&Bt.has(n)&&!t.closest(`[data-player]`)}function Gt(e){let t=new URLSearchParams(e),n=t.get(`test`)===`1`;return{test:n,streamOver:n&&t.get(`streamOver`)===`1`}}function Kt(e){return e.toUpperCase()}function qt(e,t){let n=e.filter(e=>e.stage===`voice`&&e.variants.length>0);return n.map((e,r)=>{let i=At([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}})}function Jt(e,t,n){let r=e?.[t];return r!==void 0&&r.lane===n.lane&&r.variant===n.variant}var Yt=(e,t)=>!!e.sections?.some(e=>e.id===t);function Xt(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`||Yt(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 Zt(e,t){return Xt(e,t.on)?.read.key??null}function Qt(e,t,n=e=>e.name){let r=Xt(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(Yt(e,t))return Kt(t);for(let n of e.sections??[]){let e=n.takes.findIndex(e=>`${n.id}:${e.id}`===t);if(e!==-1)return`${Kt(n.id)} · Take ${e+1}`}return null}var $t=[`vo`,`music`,`sfx`],en={vo:`voice`,music:`music`,sfx:`sfx`};function tn(e,t){return $t.filter(n=>e[n]&&(t[n]??1)>0).map(e=>en[e])}function nn(e,t){for(let n of[`music`,`sfx`]){let r=Ft(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 rn(e,t){if(t===null)return`mix`;let n=t.includes(`/`)?nn(e,t):null;return n?n.lane:t===`vo`?`vo`:nn(e,t)?.lane??null}var an={vo:`Voiceover`,music:`Music`,sfx:`Sound effects`};function on(e,t){let n=rn(e,t);return n===null?null:n===`mix`?`Whole mix`:n===`vo`?an.vo:`${an[n]} · ${nn(e,t).row.name}`}var sn=.5;function cn(e){let t=Math.round(e/sn)*sn;return Math.min(12,Math.max(-24,t))}function ln(e,t=1){let n=Math.abs(e).toFixed(t);return Number(n)===0?n:`${e<0?`−`:`+`}${n}`}var un=`—`,dn=`Install ffmpeg for loudness`;function fn(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([un,e],[un,e],[un,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(dn);let i=e=>r.silent?[`−∞`,`The mix is silent`]:e===null?[un,`Couldn't measure loudness`]:[ln(e),null],a=r.silent?[`−∞`,`The mix is silent`]:r.musicUnderVo===null?[un,`Needs Voiceover and Music both playing`]:[`${ln(r.musicUnderVo,0)} dB`,null];return t(i(r.integrated),i(r.truePeak),a)}function pn(e){return Math.max(10,Math.round((Number.isFinite(e)?e:0)/10)*10)}function mn(e){return`Makes a lightweight 1080p copy on your drive so this cut previews smoothly. About ${pn(e)} MB. Your original isn't changed.`}var hn=(e,t)=>`${e}/${t}`;function gn(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 _n(e,t){let n=hn(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 vn(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=_n(o,gn(e,n));return o}function yn(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 bn(e,t){return e||(t?`The browser couldn't play this file`:null)}function xn(e){let t=[it(e.size??0)];return e.width&&e.height&&t.push(`${e.width}×${e.height}`),e.version&&t.push(`from ${e.version}`),t.join(` · `)}function Sn(e){return/Mac|iPhone|iPad|iPod/.test(e)?`⌘C`:`Ctrl+C`}var Cn=[`voice`,`music`,`sfx`,`other`,`cut`],wn={voice:`Voiceover`,music:`Music`,sfx:`Sound effects`,other:`Other audio`,cut:`Cut`};function Tn(e){return e?e.voice+e.music+e.sfx+e.cut+e.other:0}var En={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 Dn(e,t){let n=En[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 On(e){if(!e)return null;let t=e.broughtIn.length,n=Tn(e.counts);return t>0&&n>0?`${t} brought in · ${n} more found`:t>0?`${t} brought in`:n>0?`${n} found`:null}function kn(e){return e?e.digest?`d:${e.digest}`:`${e.broughtIn.length}:${Cn.map(t=>e.counts[t]).join(`,`)}`:``}var An=(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 jn(e,t){let n=new Map(e.map(e=>[e.path,e])),r=t.map(e=>{let t=n.get(e.path);return t&&An(t,e)?t:e});return r.length===e.length&&r.every((t,n)=>t===e[n])?e:r}function Mn(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 Nn=`\0cuts`;function Pn(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:Mn(r.folder),folder:r.folder,files:[]}),e.files.push(r)}let r=[...t.values()];return n.length&&r.push({key:Nn,title:`Other cuts`,folder:null,files:n}),r}function Fn(e,t,n){let r=n.trim().toLowerCase();return e.filter(e=>(t===`all`||e.kind===t)&&(!r||e.path.toLowerCase().includes(r)))}function In(e){return Cn.map(t=>[t,e.filter(e=>e.kind===t).length]).filter(([,e])=>e>0)}function Ln(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 Rn=e=>e.replace(/\.$/,``).replace(/^(\p{Lu})(?=\p{Ll})/u,e=>e.toLowerCase());function zn(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=>Rn(e.reason)))].join(`; `);return`${e>0?`Brought in ${n(e)}.`:`Nothing was brought in.`} ${t.length} couldn't be added: ${r}.`}function Bn(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!==wn.voice?`Voiceover · ${r.name}`:wn[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 Vn(e,t){return e.item!==t.item||e.kind!==t.kind||e.ticked!==t.ticked||e.playing!==t.playing||e.failure!==t.failure}function Hn(e,t){let n=e.versions.findIndex(e=>e.id===t);return n>0?e.versions[n-1]:void 0}function Un(e,t){return e.length<2?null:t&&e.some(e=>e.id===t)?t:(e.find(e=>e.primary)??e[0]).id}function Wn(e){if(e.views.length===0)return[];let t=e.views.length===1,n=new Set(e.views.map(e=>e.id));return ye([...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`:xe(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 Gn(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 Kn(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 qn(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 Jn=e=>`repeat(${e}, minmax(0, 1fr))`;function Yn(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 Xn(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 Zn=(e,t)=>e.filter(e=>Se(e,t)),Qn=(e,t)=>t===null?[]:e.filter(e=>!Se(e,t));function $n(e,t,n){return e.box?t===null?!0:e.format===null?t===n:e.format===t:!1}var er=`A drawn box belongs to one frame, so this note stays on this format.`;function tr(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 nr(e,t){return e.format===null?t?`All`:null:ve(e.format)}function rr(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 ir(e,t){if(!t)return e;let n=e.videos?.[t];return{...e,lanes:{...n?.lanes??{}},levels:{...n?.levels??{}},use:{...n?.use??{}},balanced:n?.balanced,sections:{},videos:{}}}function ar(e){let t=[`voice`,`music`,`sfx`],n=e.balanced;return n?t.every(t=>(e.levels[t]??0)===(n.levels[t]??0)):t.every(t=>(e.levels[t]??0)===0)}function or(e,t,n){if(e.video)return[e.video];let r=e.ref??``;if(r.startsWith(`notes:`)){let e=new Set(r.slice(6).split(`,`));return[...new Set(n.filter(t=>e.has(t.id)&&t.video).map(e=>e.video))]}let i=r.indexOf(`/`);if(i>0){let e=t.lanes.find(e=>e.id===r.slice(0,i))?.variants.find(e=>e.id===r.slice(i+1));if(e)return pr(e)}return[]}function sr(e,t,n,r){if(!t||n.videos.length<2)return!0;let i=or(e,n,r);return i.length===0||i.includes(t)}function cr(e,t,n){return e.shared?!0:e.videos?.length?e.videos.includes(t):e.video?e.video===t:n.length===0||n[0].id===t}function lr(e,t,n){return!t||e.stage===`visuals`?!0:e.video?e.video===t:n.length===0||n[0].id===t}function ur(e,t){let n=t?e.films?.[t]:void 0;if(!t||!n)return e;let r=e.project.videos;return{...e,script:n.script,brief:n.brief,storyboard:n.storyboard,build:n.build,tabs:n.tabs,log:n.log,notes:{...e.notes,notes:e.notes.notes.filter(e=>lr(e,t,r))}}}function dr(e){let t=new URLSearchParams(e).get(`film`);return t&&t.length<=64?t:null}function fr(e,t){let n=new URLSearchParams(e);return n.set(`film`,t),`?${n.toString()}`}function pr(e){return e.videos??(e.video===void 0?[]:[e.video])}function mr(e,t,n){return t?e.map(e=>({...e,variants:e.variants.filter(e=>{let r=pr(e);return r.length===0?n.length===0||n[0].id===t:r.includes(t)})})).filter(e=>e.variants.length>0):e}function hr(e,t,n){if(n.length<=1)return[];let r=new Set(mr(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 gr(e,t,n,r=[]){return e.filter(e=>e.stage===t&&lr(e,n,r))}var _r=`rushes:theme`,vr=`rushes:theme`,yr=[`dark`,`light`,`system`];function br(e){try{let t=e?.getItem(_r);return yr.includes(t)?t:`dark`}catch{return`dark`}}function xr(e,t){return e===`system`?t?`dark`:`light`:e}function Sr(e){return yr[(yr.indexOf(e)+1)%yr.length]}var Cr={dark:`Dark`,light:`Light`,system:`Match the system`};function wr(){try{return window.localStorage}catch{return null}}function Tr(e){try{wr()?.setItem(_r,e)}catch{}}var Er=null;function Dr(e){Er?.(),Er=null;let t=typeof window.matchMedia==`function`?window.matchMedia(`(prefers-color-scheme: dark)`):null,n=()=>{let n=xr(e,!t||t.matches);document.documentElement.dataset.theme!==n&&(document.documentElement.dataset.theme=n,window.dispatchEvent(new Event(vr)))};n(),e===`system`&&t&&(t.addEventListener(`change`,n),Er=()=>t.removeEventListener(`change`,n))}function Or(e,t){let n=/^var\((--[a-z0-9-]+)\)$/.exec(t.trim());return n&&getComputedStyle(e).getPropertyValue(n[1]).trim()||t}var kr,Ar,jr,Mr,Nr=0,Pr=[],Fr=n,Ir=Fr.__b,Lr=Fr.__r,Rr=Fr.diffed,zr=Fr.__c,Br=Fr.unmount,Vr=Fr.__;function Hr(e,t){Fr.__h&&Fr.__h(Ar,e,Nr||t),Nr=0;var n=Ar.__H||(Ar.__H={__:[],__h:[]});return e>=n.__.length&&n.__.push({}),n.__[e]}function H(e){return Nr=1,Ur(ei,e)}function Ur(e,t,n){var r=Hr(kr++,2);if(r.t=e,!r.__c&&(r.__=[n?n(t):ei(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=Ar,!Ar.__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};Ar.__f=!0;var a=Ar.shouldComponentUpdate,o=Ar.componentWillUpdate;Ar.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)},Ar.shouldComponentUpdate=i}return r.__N||r.__}function U(e,t){var n=Hr(kr++,3);!Fr.__s&&$r(n.__H,t)&&(n.__=e,n.u=t,Ar.__H.__h.push(n))}function W(e,t){var n=Hr(kr++,4);!Fr.__s&&$r(n.__H,t)&&(n.__=e,n.u=t,Ar.__h.push(n))}function G(e){return Nr=5,Wr(function(){return{current:e}},[])}function Wr(e,t){var n=Hr(kr++,7);return $r(n.__H,t)&&(n.__=e(),n.__H=t,n.__h=e),n.__}function Gr(e,t){return Nr=8,Wr(function(){return e},t)}function Kr(e){var t=Ar.context[e.__c],n=Hr(kr++,9);return n.c=e,t?(n.__??(n.__=!0,t.sub(Ar)),t.props.value):e.__}function qr(){var e=Hr(kr++,11);if(!e.__){for(var t=Ar.__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 Jr(){for(var e;e=Pr.shift();){var t=e.__H;if(e.__P&&t)try{t.__h.some(Zr),t.__h.some(Qr),t.__h=[]}catch(n){t.__h=[],Fr.__e(n,e.__v)}}}Fr.__b=function(e){Ar=null,Ir&&Ir(e)},Fr.__=function(e,t){e&&t.__k&&t.__k.__m&&(e.__m=t.__k.__m),Vr&&Vr(e,t)},Fr.__r=function(e){Lr&&Lr(e),kr=0;var t=(Ar=e.__c).__H;t&&(jr===Ar?(t.__h=[],Ar.__h=[],t.__.some(function(e){e.__N&&(e.__=e.__N),e.u=e.__N=void 0})):(t.__h.some(Zr),t.__h.some(Qr),t.__h=[],kr=0)),jr=Ar},Fr.diffed=function(e){Rr&&Rr(e);var t=e.__c;t&&t.__H&&(t.__H.__h.length&&(Pr.push(t)!==1&&Mr===Fr.requestAnimationFrame||((Mr=Fr.requestAnimationFrame)||Xr)(Jr)),t.__H.__.some(function(e){e.u&&=(e.__H=e.u,void 0)})),jr=Ar=null},Fr.__c=function(e,t){t.some(function(e){try{e.__h.some(Zr),e.__h=e.__h.filter(function(e){return!e.__||Qr(e)})}catch(n){t.some(function(e){e.__h&&=[]}),t=[],Fr.__e(n,e.__v)}}),zr&&zr(e,t)},Fr.unmount=function(e){Br&&Br(e);var t,n=e.__c;n&&n.__H&&(n.__H.__.some(function(e){try{Zr(e)}catch(e){t=e}}),n.__H=void 0,t&&Fr.__e(t,n.__v))};var Yr=typeof requestAnimationFrame==`function`;function Xr(e){var t,n=function(){clearTimeout(r),Yr&&cancelAnimationFrame(t),setTimeout(e)},r=setTimeout(n,35);Yr&&(t=requestAnimationFrame(n))}function Zr(e){var t=Ar,n=e.__c;typeof n==`function`&&(e.__c=void 0,n()),Ar=t}function Qr(e){var t=Ar;e.__c=e.__(),Ar=t}function $r(e,t){return!e||e.length!==t.length||t.some(function(t,n){return t!==e[n]})}function ei(e,t){return typeof t==`function`?t(e):t}var ti=class extends Error{status;code;constructor(e,t,n){super(n),this.status=e,this.code=t}};function ni(){let e=location.pathname.match(/\/p\/([a-z2-9]{8})\//);return e?e[1]:null}async function ri(e,t,n,r={}){let i=ni(),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 ti(o.status,c.error??`error`,c.message??`Request failed (${o.status})`);return c}var K={get:e=>ri(`GET`,e),post:(e,t={})=>ri(`POST`,e,t),patch:(e,t)=>ri(`PATCH`,e,t),put:(e,t,n)=>ri(`PUT`,e,t,n),del:(e,t={})=>ri(`DELETE`,e,t)};function ii(e,t,n){return K.put(`/api/picks`,{video:e,lanes:{[t]:n}})}function ai(e,t,n){return K.put(`/api/variants/${encodeURIComponent(e)}/${encodeURIComponent(t)}/put-away`,{away:n})}async function oi(e,t,n,r=null){let i=ni(),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 ti(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 si(e){let t=ni();return`/media?path=${encodeURIComponent(e)}${t?`&project=${t}`:``}`}function ci(){let e=ni();return`/api/events${e?`?project=${e}`:``}`}function li(e){let t=Object.values(e).filter(e=>typeof e==`number`);return Object.entries(e).filter(([e,n])=>t.indexOf(+e)===-1).map(([e,t])=>t)}function ui(e,t=`|`){return e.map(e=>Fi(e)).join(t)}function di(e,t){return typeof t==`bigint`?t.toString():t}var fi=class{constructor(e){this._getter=e,this._value=void 0}get value(){let e=this._getter;return e!==void 0&&(this._value=e(),this._getter=void 0),this._value}};function pi(e){return new fi(e)}function mi(e){return e==null}function hi(e){let t=+!!e.startsWith(`^`),n=e.endsWith(`$`)?e.length-1:e.length;return e.slice(t,n)}function gi(e,t){let n=e/t,r=Math.round(n),i=4*2**-52*Math.max(Math.abs(n),1);return Math.abs(n-r)<i?0:n-r}function _i(e,t,n){Object.defineProperty(e,t,{value:n,writable:!0,enumerable:!0,configurable:!0})}function vi(e){let t=Object.getOwnPropertyDescriptor(e,`shape`);return t?.get?t.get.raw:t?.value}function yi(e){return vi(e._zod.def)??e._zod.def.shape}function bi(e,t,n){Object.defineProperty(e,t,{get(){let e=n();return _i(this,t,e),e},enumerable:!0,configurable:!0})}function xi(e,t,n){t in e?_i(e,t,n):e[t]=n}function Si(e,t,n,r){let i=yi(t);for(let a of n){let n=Object.getOwnPropertyDescriptor(i,a);n.enumerable&&(n.get?bi(e,a,()=>{let e=t._zod.def.shape[a];return r?r(e,a):e}):xi(e,a,r?r(n.value,a):n.value))}}function Ci(e,t){for(let n of Reflect.ownKeys(t)){let r=Object.getOwnPropertyDescriptor(t,n);r.enumerable&&(r.get?bi(e,n,()=>t[n]):xi(e,n,r.value))}}function wi(...e){let t={};for(let n of e){let e=Object.getOwnPropertyDescriptors(n);Object.assign(t,e)}return Object.defineProperties({},t)}function Ti(e){return JSON.stringify(e)}function Ei(e){return e.toLowerCase().trim().replace(/[^\w\s-]/g,``).replace(/[\s_-]+/g,`-`).replace(/^-+|-+$/g,``)}var Di=`captureStackTrace`in Error?Error.captureStackTrace:(...e)=>{};function Oi(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}var ki=pi(()=>{if(wa.jitless||typeof navigator<`u`&&navigator?.userAgent?.includes(`Cloudflare`))return!1;try{return Function(``),!0}catch{return!1}});function Ai(e){if(Oi(e)===!1)return!1;let t=e.constructor;if(t===void 0||typeof t!=`function`)return!0;let n=t.prototype;return Oi(n)!==!1&&Object.prototype.hasOwnProperty.call(n,`isPrototypeOf`)!==!1}function ji(e){return Ai(e)?{...e}:Array.isArray(e)?[...e]:e instanceof Map?new Map(e):e instanceof Set?new Set(e):e}var Mi=new Set([`string`,`number`,`symbol`]);function Ni(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function Pi(e,t,n){let r=new e._zod.constr(t??e._zod.def);return(!t||n?.parent)&&(r._zod.parent=e),r}function q(e){let t=e;if(!t)return{};if(typeof t==`string`)return{error:()=>t};if(t?.message!==void 0){if(t?.error!==void 0)throw Error("Cannot specify both `message` and `error` params");t.error=t.message}return delete t.message,typeof t.error==`string`?{...t,error:()=>t.error}:t}function Fi(e){return typeof e==`bigint`?e.toString()+`n`:typeof e==`string`?`"${e}"`:`${e}`}function Ii(e){return Object.keys(e).filter(t=>e[t]._zod.optin!==void 0&&e[t]._zod.optout===`optional`)}var Li={safeint:[-(2**53-1),2**53-1],int32:[-2147483648,2147483647],uint32:[0,4294967295],float32:[-34028234663852886e22,34028234663852886e22],float64:[-Number.MAX_VALUE,Number.MAX_VALUE]},Ri={int64:[BigInt(`-9223372036854775808`),BigInt(`9223372036854775807`)],uint64:[BigInt(0),BigInt(`18446744073709551615`)]};function zi(e,t){let n=e._zod.def,r=n.checks;if(r&&r.length>0)throw Error(`.pick() cannot be used on object schemas containing refinements`);let i={};return Si(i,e,Bi(e,t)),Pi(e,wi(n,{shape:i,checks:[]}))}function Bi(e,t){let n=yi(e),r=[];for(let e of Reflect.ownKeys(t)){if(!Object.getOwnPropertyDescriptor(n,e)?.enumerable)throw Error(`Unrecognized key: "${String(e)}"`);t[e]&&r.push(e)}return r}function Vi(e,t){let n=e._zod.def,r=n.checks;if(r&&r.length>0)throw Error(`.omit() cannot be used on object schemas containing refinements`);let i=new Set(Bi(e,t)),a={};return Si(a,e,Reflect.ownKeys(yi(e)).filter(e=>!i.has(e))),Pi(e,wi(n,{shape:a,checks:[]}))}function Hi(e,t){if(!Ai(t))throw Error(`Invalid input to extend: expected a plain object`);let n=e._zod.def.checks;if(n&&n.length>0){let n=yi(e);for(let e of Reflect.ownKeys(t))if(Object.getOwnPropertyDescriptor(n,e)!==void 0)throw Error("Cannot overwrite keys on object schemas containing refinements. Use `.safeExtend()` instead.")}return Pi(e,wi(e._zod.def,{shape:Ui(e,t)}))}function Ui(e,t){let n={};return Si(n,e,Reflect.ownKeys(yi(e))),Ci(n,t),n}function Wi(e,t){if(!Ai(t))throw Error(`Invalid input to safeExtend: expected a plain object`);return Pi(e,wi(e._zod.def,{shape:Ui(e,t)}))}function Gi(e,t){if(!t?._zod?.def)throw Error("Invalid input to merge: expected an object schema. To merge a plain shape, use `.extend()`.");if(e._zod.def.checks?.length)throw Error(`.merge() cannot be used on object schemas containing refinements. Use .safeExtend() instead.`);let n={};return Si(n,e,Reflect.ownKeys(yi(e))),Si(n,t,Reflect.ownKeys(yi(t))),Pi(e,wi(e._zod.def,{shape:n,get catchall(){return t._zod.def.catchall},checks:t._zod.def.checks??[]}))}function Ki(e,t,n,r=`partial`){let i=t._zod.def.checks;if(i&&i.length>0)throw Error(`.${r}() cannot be used on object schemas containing refinements`);let a=n?new Set(Bi(t,n)):void 0,o={};return Si(o,t,Reflect.ownKeys(yi(t)),e&&((t,n)=>a&&!a.has(n)?t:new e({type:`optional`,innerType:t}))),Pi(t,wi(t._zod.def,{shape:o,checks:[]}))}function qi(e,t,n){let r=n?new Set(Bi(t,n)):void 0,i={};return Si(i,t,Reflect.ownKeys(yi(t)),(t,n)=>r&&!r.has(n)?t:new e({type:`nonoptional`,innerType:t})),Pi(t,wi(t._zod.def,{shape:i}))}function Ji(e,t=0){if(e.aborted===!0)return!0;for(let n=t;n<e.issues.length;n++)if(e.issues[n]?.continue!==!0)return!0;return!1}function Yi(e,t=0){if(e.aborted===!0)return!0;for(let n=t;n<e.issues.length;n++)if(e.issues[n]?.continue===!1)return!0;return!1}function Xi(e,t){return t.map(t=>{var n;return(n=t).path??(n.path=[]),t.path.unshift(e),t})}function Zi(e){return typeof e==`string`?e:e?.message}function Qi(e,t,n){var r;for(let i=t;i<e.length;i++)(r=e[i]).schema??(r.schema=n)}function $i(e,t,n){var r;let i=e.inst?._zod?.traits;i?.has(`$ZodType`)&&(i.has(`$ZodCheck`)?(r=e).schema??(r.schema=e.inst):e.schema=e.inst);let a=e.schema===e.inst?void 0:e.schema?._zod.def?.error,o=e.message?e.message:Zi(e.inst?._zod.def?.error?.(e))??Zi(a?.(e))??Zi(t?.error?.(e))??Zi(n.customError?.(e))??Zi(n.localeError?.(e))??`Invalid input`,s={};for(let t of Object.keys(e))t!==`inst`&&t!==`schema`&&t!==`continue`&&t!==`input`&&t!==`__proto__`&&(s[t]=e[t]);return s.path??=[],s.message=o,t?.reportInput&&(s.input=e.input),s}var ea=/[\uD800-\uDBFF]/;function ta(e){let t=e.length;if(!ea.test(e))return t;let n=t;for(let r=0;r<t-1;r++)(e.charCodeAt(r)&64512)==55296&&(e.charCodeAt(r+1)&64512)==56320&&(n--,r++);return n}function na(e){return Array.isArray(e)?`array`:typeof e==`string`?`string`:`unknown`}function ra(e){let t=typeof e;switch(t){case`number`:return Number.isNaN(e)?`nan`:`number`;case`object`:{if(e===null)return`null`;if(Array.isArray(e))return`array`;let t=e;if(t&&Object.getPrototypeOf(t)!==Object.prototype&&`constructor`in t&&t.constructor)return t.constructor.name}}return t}function ia(...e){let[t,n,r]=e;return typeof t==`string`?{message:t,code:`custom`,input:n,inst:r}:{...t}}function aa(e,t){for(let n in t){let r=Object.getOwnPropertyDescriptor(t,n);r.get?Object.defineProperty(e,n,{...r,enumerable:!1}):la(e,n,r.value)}}function oa(e,t,n,r=!0){return Object.defineProperty(e,t,{configurable:!0,writable:!0,enumerable:r,value:n}),n}function sa(e,t,n){return oa(e,t,n,!1)}function ca(e,t){for(let n in e){let r=e[n];Object.defineProperty(t,n,{configurable:!0,enumerable:!0,get(){return oa(this,n,r(this))},set(e){oa(this,n,e)}})}return t}function la(e,t,n){Object.defineProperty(e,t,{configurable:!0,get(){return this==null?n:oa(this,t,n.bind(this))},set(e){oa(this,t,e)}})}function ua(e,t){let n=Object.getPrototypeOf(e);return t in n?void 0:n}var da,fa=!1,pa={configurable:!0,get(){fa=!0}};function ma(e,t,n){let r=Object.getPrototypeOf(e._zod);if(t in r&&da!==e._zod){da=void 0;return}da=e._zod,Object.defineProperty(r,t,{configurable:!0,get(){Object.defineProperty(this,t,pa);let e=fa;fa=!1;try{let r=n(this);return fa?delete this[t]:Object.defineProperty(this,t,{configurable:!0,writable:!0,value:r}),fa||=e,r}catch(n){throw delete this[t],fa||=e,n}},set(e){Object.defineProperty(this,t,{configurable:!0,writable:!0,value:e})}})}function ha(e,t,n,r){let i=ua(e,t);i&&Object.defineProperty(i,t,{configurable:!0,get(){let e={configurable:!0,writable:!0,enumerable:r,value:void 0};return Object.defineProperty(this,t,e),e.value=n(this),Object.defineProperty(this,t,e),e.value},set(e){Object.defineProperty(this,t,{configurable:!0,writable:!0,enumerable:r,value:e})}})}var ga=`~constantCatch`;function _a(e){let t=()=>e;return t[ga]=!0,t}var va,ya={value:void 0,enumerable:!1},ba=`captureStackTrace`in Error?Error:null;function xa(e){let t=ba;if(t){let n=t.stackTraceLimit;if(typeof n==`number`){try{t.stackTraceLimit=0}catch{return ba=null,new e}try{return new e}finally{t.stackTraceLimit=n}}}return new e}function J(e,t,n,r){let i={};function a(e){this.def=e,this.constr=d,this.traits=new Set}a.prototype=i;let o=n,s=o&&new WeakSet;function c(n,r){if(!n._zod){ya.value=new a(r);try{Object.defineProperty(n,"_zod",ya)}finally{ya.value=void 0}}else if(n._zod.traits.has(e))return;if(n._zod.traits.add(e),t(n,r),s){let e=Object.getPrototypeOf(n),t=n._zod.constr.prototype,r=e;for(;r&&r!==t;)r=Object.getPrototypeOf(r);let i=r??e;s.has(i)||(s.add(i),aa(i,o))}let i=d.prototype;for(let e in i)Object.prototype.hasOwnProperty.call(i,e)&&(e in n||(n[e]=i[e].bind(n)))}let l=r?.Parent??Object;class u extends l{}Object.defineProperty(u,"name",{value:e});function d(e){let t=r?.Parent?xa(u):this;c(t,e);let n=t._zod.deferred;if(n){for(let e of n)e();t._zod.deferred=void 0}let i=globalThis.__zod_globalConfig?.postProcessor;return i&&i(t),t}return Object.defineProperty(d,"init",{value:c}),Object.defineProperty(d,Symbol.hasInstance,{value:t=>r?.Parent&&t instanceof r.Parent?!0:t?._zod?.traits?.has(e)}),Object.defineProperty(d,"name",{value:e}),d}var Sa=class extends Error{constructor(){super(`Encountered Promise during synchronous parse. Use .parseAsync() instead.`)}},Ca=class extends Error{constructor(e){super(`Encountered unidirectional transform during encode: ${e}`),this.name=`ZodEncodeError`}};(va=globalThis).__zod_globalConfig??(va.__zod_globalConfig={});var wa=globalThis.__zod_globalConfig;function Ta(e){return e&&Object.assign(wa,e),wa}function Ea(){let e=this._zod;return e.message??=JSON.stringify(e.def,di,2),e.message}function Da(e){this._zod.message=e}var Oa={get:Ea,set:Da,enumerable:!0,configurable:!0},ka={value:void 0,enumerable:!1},Aa=new WeakSet([Object.prototype,Error.prototype]),ja=(e,t)=>{e.name=`$ZodError`,ka.value=t,Object.defineProperty(e,"issues",ka),ka.value=void 0,Object.defineProperty(e,"message",Oa);let n=Object.getPrototypeOf(e);Aa.has(n)||(Aa.add(n),Object.defineProperty(n,"toString",{configurable:!0,enumerable:!1,get(){let e=()=>this.message;return Object.defineProperty(this,"toString",{value:e,configurable:!0,writable:!0}),e},set(e){Object.defineProperty(this,"toString",{value:e,configurable:!0,writable:!0})}}))},Ma=J(`$ZodError`,ja);J(`$ZodError`,ja,void 0,{Parent:Error});function Na(e,t,n){return Object.prototype.hasOwnProperty.call(e,t)||(t===`__proto__`?Object.defineProperty(e,t,{value:n(),writable:!0,enumerable:!0,configurable:!0}):e[t]=n()),e[t]}function Pa(e,t=e=>e.message){let n={},r=[];for(let i of e.issues)i.path.length>0?Na(n,i.path[0],()=>[]).push(t(i)):r.push(t(i));return{formErrors:r,fieldErrors:n}}function Fa(e,t=e=>e.message){let n={_errors:[]},r=(e,i=[])=>{for(let a of e.issues)if(a.code===`invalid_union`&&a.errors.length)a.errors.map(e=>r({issues:e},[...i,...a.path]));else if(a.code===`invalid_key`)r({issues:a.issues},[...i,...a.path]);else if(a.code===`invalid_element`)r({issues:a.issues},[...i,...a.path]);else{let e=[...i,...a.path];if(e.length===0)n._errors.push(t(a));else{let r=n,i=0;for(;i<e.length;){let n=e[i],o=i===e.length-1;if(n===`_errors`){o&&r._errors.push(t(a)),i++;continue}Object.prototype.hasOwnProperty.call(r,n)||Object.defineProperty(r,n,{value:{_errors:[]},enumerable:!0,writable:!0,configurable:!0});let s=r[n];o&&s._errors.push(t(a)),r=s,i++}}}};return r(e),n}function Ia(e,t){return{callee:t?.callee??e,Err:t?.Err}}var La=e=>{let t=(n,r,i,a)=>{let o=i?{...i,async:!1}:{async:!1},s=n._zod.run({value:r,issues:[]},o);if(s instanceof Promise)throw new Sa;if(s.issues.length){let n=new((a?.Err)??e)(s.issues.map(e=>$i(e,o,Ta())));throw Di(n,a?.callee??t),n}return s.value};return t},Ra=e=>{let t=async(n,r,i,a)=>{let o=i?{...i,async:!0}:{async:!0},s=n._zod.run({value:r,issues:[]},o);if(s instanceof Promise&&(s=await s),s.issues.length){let n=new((a?.Err)??e)(s.issues.map(e=>$i(e,o,Ta())));throw Di(n,a?.callee??t),n}return s.value};return t},za=e=>(t,n,r)=>{let i=r?{...r,async:!1}:{async:!1},a=t._zod.run({value:n,issues:[]},i);if(a instanceof Promise)throw new Sa;return a.issues.length?Ba(e,a.issues,i):{success:!0,data:a.value}};function Ba(e,t,n){let r;return{success:!1,get error(){return r||(r=new e(t.map(e=>$i(e,n,Ta()))),t=void 0,n=void 0),r},set error(e){r=e,t=void 0,n=void 0}}}var Va=e=>async(t,n,r)=>{let i=r?{...r,async:!0}:{async:!0},a=t._zod.run({value:n,issues:[]},i);return a instanceof Promise&&(a=await a),a.issues.length?Ba(e,a.issues,i):{success:!0,data:a.value}},Ha=Symbol.for(`zod.compile.invalid`),Ua=Symbol.for(`zod.compile.fallback`),Wa=((e,t,n)=>{let r=e._zod.bag.validator;if(r!==void 0){if(r(t)!==Ha)return!0;if(r.definite===!0&&n===void 0)return!1}return Ga(e,t,n)});function Ga(e,t,n){let r=n?{...n,async:!1,abortEarly:!0}:{async:!1,abortEarly:!0},i=e._zod.bag.fallbackRun,a;if(i?(r[Ua]=!0,a=i({value:t,issues:[]},r)):a=e._zod.run({value:t,issues:[]},r),a instanceof Promise)throw new Sa;return a.issues.length===0}var Ka=async(e,t,n)=>{let r=n?{...n,async:!0,abortEarly:!0}:{async:!0,abortEarly:!0},i=e._zod.run({value:t,issues:[]},r);return i instanceof Promise&&(i=await i),i.issues.length===0},qa=e=>{let t=La(e),n=(e,r,i,a)=>{let o=i?{...i,direction:`backward`}:{direction:`backward`};return t(e,r,o,Ia(n,a))};return n},Ja=e=>{let t=La(e),n=(e,r,i,a)=>t(e,r,i,Ia(n,a));return n},Ya=e=>{let t=Ra(e),n=async(e,r,i,a)=>{let o=i?{...i,direction:`backward`}:{direction:`backward`};return await t(e,r,o,Ia(n,a))};return n},Xa=e=>{let t=Ra(e),n=async(e,r,i,a)=>await t(e,r,i,Ia(n,a));return n},Za=e=>(t,n,r)=>{let i=r?{...r,direction:`backward`}:{direction:`backward`};return za(e)(t,n,i)},Qa=e=>(t,n,r)=>za(e)(t,n,r),$a=e=>async(t,n,r)=>{let i=r?{...r,direction:`backward`}:{direction:`backward`};return Va(e)(t,n,i)},eo=e=>async(t,n,r)=>Va(e)(t,n,r),to=/^[cC][0-9a-z]{6,}$/,no=/^[0-9a-z]+$/,ro=/^[0-7][0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{25}$/,io=/^[0-9a-vA-V]{20}$/,ao=/^[A-Za-z0-9]{27}$/,oo=/^[a-zA-Z0-9_-]{21}$/;function so(e){return RegExp(`^[a-zA-Z0-9_-]{${e}}$`)}var co=/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/,lo=/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$/,uo=e=>e?RegExp(`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${e}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`):/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/,fo=/^(?:[A-Za-z0-9_'+\-]+\.)*[A-Za-z0-9_'+\-]*[A-Za-z0-9_+-]@(?:[A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/,po=`^(?=[\\s\\S]*[\\p{Extended_Pictographic}\\p{Regional_Indicator}\\u20E3])[\\p{Extended_Pictographic}\\p{Emoji_Component}]+$`;function mo(){return new RegExp(po,`u`)}var ho=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,go=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))$/,_o=/^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/([0-9]|[1-2][0-9]|3[0-2])$/,vo=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,yo=/^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/,bo=/^(?:[A-Za-z0-9_-]{4})*(?:[A-Za-z0-9_-]{2,3})?$/,xo=/^https?$/,So=/^\+[1-9]\d{6,14}$/,Co=`(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))`;function wo(e){return RegExp(`^${e}$`)}var To=wo(Co);function Eo(e){let t=`(?:[01]\\d|2[0-3]):[0-5]\\d`;return typeof e.precision==`number`?e.precision===-1?`${t}`:e.precision===0?`${t}:[0-5]\\d`:`${t}:[0-5]\\d\\.\\d{${e.precision}}`:e.seconds?`${t}:[0-5]\\d(?:\\.\\d+)?`:`${t}(?::[0-5]\\d(?:\\.\\d+)?)?`}function Do(e){return RegExp(`^${Eo(e)}$`)}function Oo(e){let t=[`Z`];e.offset&&t.push(`([+-](?:[01]\\d|2[0-3]):[0-5]\\d)`);let n=`${Eo({precision:e.precision,seconds:!0})}(?:${t.join(`|`)})`,r=e.local?`${n}|${Eo({precision:e.precision})}`:n;return RegExp(`^${Co}T(?:${r})$`)}var ko=/^[\s\S]{0,}$/,Ao=/^-?\d+$/,jo=/^-?\d+(?:\.\d+)?$/,Mo=/^(?:true|false)$/i,No=/^[^A-Z]*$/,Po=/^[^a-z]*$/,Fo=J(`$ZodCheck`,(e,t)=>{var n;e._zod??={},e._zod.def=t,(n=e._zod).onattach??(n.onattach=[])}),Io=e=>{let t=e.value;return!mi(t)&&t.length!==void 0},Lo={number:`number`,bigint:`bigint`,object:`date`},Ro=J(`$ZodCheckLessThan`,(e,t)=>{Fo.init(e,t);let n=Lo[typeof t.value];e._zod.check=r=>{(t.inclusive?r.value<=t.value:r.value<t.value)||r.issues.push({origin:Lo[typeof r.value]??n,code:`too_big`,maximum:typeof t.value==`object`?t.value.getTime():t.value,input:r.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),zo=J(`$ZodCheckGreaterThan`,(e,t)=>{Fo.init(e,t);let n=Lo[typeof t.value];e._zod.check=r=>{(t.inclusive?r.value>=t.value:r.value>t.value)||r.issues.push({origin:Lo[typeof r.value]??n,code:`too_small`,minimum:typeof t.value==`object`?t.value.getTime():t.value,input:r.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),Bo=J(`$ZodCheckMultipleOf`,(e,t)=>{Fo.init(e,t),e._zod.check=n=>{if(typeof n.value!=typeof t.value)throw Error(`Cannot mix number and bigint in multiple_of check.`);(typeof n.value==`bigint`?t.value!==BigInt(0)&&n.value%t.value===BigInt(0):gi(n.value,t.value)===0)||n.issues.push({origin:typeof n.value,code:`not_multiple_of`,divisor:t.value,input:n.value,inst:e,continue:!t.abort})}}),Vo=J(`$ZodCheckNumberFormat`,(e,t)=>{Fo.init(e,t),t.format=t.format||`float64`;let n=t.format?.includes(`int`),r=n?`int`:`number`,[i,a]=Li[t.format];e._zod.check=o=>{let s=o.value;if(n){if(!Number.isInteger(s)){o.issues.push({expected:r,format:t.format,code:`invalid_type`,continue:!1,input:s,inst:e});return}if(!Number.isSafeInteger(s)){s>0?o.issues.push({input:s,code:`too_big`,maximum:2**53-1,note:`Integers must be within the safe integer range.`,inst:e,origin:r,inclusive:!0,continue:!t.abort}):o.issues.push({input:s,code:`too_small`,minimum:-(2**53-1),note:`Integers must be within the safe integer range.`,inst:e,origin:r,inclusive:!0,continue:!t.abort});return}}s<i&&o.issues.push({origin:`number`,input:s,code:`too_small`,minimum:i,inclusive:!0,inst:e,continue:!t.abort}),s>a&&o.issues.push({origin:`number`,input:s,code:`too_big`,maximum:a,inclusive:!0,inst:e,continue:!t.abort})}}),Ho=J(`$ZodCheckMaxLength`,(e,t)=>{var n;Fo.init(e,t),(n=e._zod.def).when??(n.when=Io),e._zod.check=n=>{let r=n.value,i=r.length;if((typeof r==`string`&&i>t.maximum?ta(r):i)<=t.maximum)return;let a=na(r);n.issues.push({origin:a,code:`too_big`,maximum:t.maximum,inclusive:!0,input:r,inst:e,continue:!t.abort})}}),Uo=J(`$ZodCheckMinLength`,(e,t)=>{var n;Fo.init(e,t),(n=e._zod.def).when??(n.when=Io),e._zod.check=n=>{let r=n.value,i=r.length;if((typeof r==`string`&&i>=t.minimum&&i<t.minimum*2?ta(r):i)>=t.minimum)return;let a=na(r);n.issues.push({origin:a,code:`too_small`,minimum:t.minimum,inclusive:!0,input:r,inst:e,continue:!t.abort})}}),Wo=J(`$ZodCheckLengthEquals`,(e,t)=>{var n;Fo.init(e,t),(n=e._zod.def).when??(n.when=Io),e._zod.check=n=>{let r=n.value,i=r.length,a=typeof r==`string`&&i>=t.length&&i<=t.length*2?ta(r):i;if(a===t.length)return;let o=na(r),s=a>t.length;n.issues.push({origin:o,...s?{code:`too_big`,maximum:t.length}:{code:`too_small`,minimum:t.length},inclusive:!0,exact:!0,input:n.value,inst:e,continue:!t.abort})}}),Go=J(`$ZodCheckStringFormat`,(e,t)=>{var n,r;Fo.init(e,t),t.pattern?(n=e._zod).check??(n.check=n=>{t.pattern.lastIndex=0,!t.pattern.test(n.value)&&n.issues.push({origin:`string`,code:`invalid_format`,format:t.format,input:n.value,...t.pattern?{pattern:t.pattern.toString()}:{},inst:e,continue:!t.abort})}):(r=e._zod).check??(r.check=()=>{})}),Ko=J(`$ZodCheckRegex`,(e,t)=>{Go.init(e,t),e._zod.check=n=>{t.pattern.lastIndex=0,!t.pattern.test(n.value)&&n.issues.push({origin:`string`,code:`invalid_format`,format:`regex`,input:n.value,pattern:t.pattern.toString(),inst:e,continue:!t.abort})}}),qo=J(`$ZodCheckLowerCase`,(e,t)=>{t.pattern??=No,Go.init(e,t)}),Jo=J(`$ZodCheckUpperCase`,(e,t)=>{t.pattern??=Po,Go.init(e,t)}),Yo=J(`$ZodCheckIncludes`,(e,t)=>{Fo.init(e,t);let n=Ni(t.includes);t.pattern=new RegExp(typeof t.position==`number`?`^.{${t.position},}${n}`:n),e._zod.check=n=>{n.value.includes(t.includes,t.position)||n.issues.push({origin:`string`,code:`invalid_format`,format:`includes`,includes:t.includes,input:n.value,inst:e,continue:!t.abort})}}),Xo=J(`$ZodCheckStartsWith`,(e,t)=>{Fo.init(e,t);let n=RegExp(`^${Ni(t.prefix)}.*`);t.pattern??=n,e._zod.check=n=>{n.value.startsWith(t.prefix)||n.issues.push({origin:`string`,code:`invalid_format`,format:`starts_with`,prefix:t.prefix,input:n.value,inst:e,continue:!t.abort})}}),Zo=J(`$ZodCheckEndsWith`,(e,t)=>{Fo.init(e,t);let n=RegExp(`.*${Ni(t.suffix)}$`);t.pattern??=n,e._zod.check=n=>{n.value.endsWith(t.suffix)||n.issues.push({origin:`string`,code:`invalid_format`,format:`ends_with`,suffix:t.suffix,input:n.value,inst:e,continue:!t.abort})}}),Qo=J(`$ZodCheckOverwrite`,(e,t)=>{Fo.init(e,t),e._zod.check=e=>{e.value=t.tx(e.value)}}),$o=class{constructor(e=[],t={}){this.content=[],this.indent=0,this.args=e,this.closed=t}indented(e){this.indent+=1;try{e(this)}finally{--this.indent}}write(e){if(typeof e==`function`){e(this,{execution:`sync`}),e(this,{execution:`async`});return}let t=e.split(`
|
|
2
|
+
`).filter(e=>e),n=Math.min(...t.map(e=>e.length-e.trimStart().length)),r=t.map(e=>e.slice(n)).map(e=>` `.repeat(this.indent*2)+e);for(let e of r)this.content.push(e)}compile(){let e=Function,t=this?.content??[``];return new e(...Object.keys(this.closed),`return function (${this.args.join(`, `)}) {\n${t.join(`
|
|
3
|
+
`)}\n};`)(...Object.values(this.closed))}},es={major:4,minor:6,patch:5},ts=J(`$ZodType`,(e,t)=>{var n;e??={},e._zod.def=t,e._zod.bag=e._zod.bag||{},e._zod.version=es;let r=e._zod.def.checks,i=e._zod.traits.has(`$ZodCheck`)?[e,...r??[]]:r?.length?[...r]:[];for(let t of i)for(let n of t._zod.onattach)n(e);if(i.length===0)(n=e._zod).deferred??(n.deferred=[]),e._zod.deferred?.push(()=>{e._zod.run=e._zod.parse});else{let t=(t,n,r)=>{if(t.memo)return t;let i=Ji(t),a;for(let o of n){if(o._zod.def.when){if(Yi(t)||!o._zod.def.when(t))continue}else if(i)continue;let n=t.issues.length,s=o._zod.check(t);if(s instanceof Promise&&r?.async===!1)throw new Sa;if(a||s instanceof Promise)a=(a??Promise.resolve()).then(async()=>{await s,t.issues.length!==n&&(Qi(t.issues,n,e),i||=Ji(t,n))});else{if(t.issues.length===n)continue;Qi(t.issues,n,e),i||=Ji(t,n)}}return a?a.then(()=>t):t},n=(n,r,a)=>{if(Ji(n))return n.aborted=!0,n;let o=t(r,i,a);if(o instanceof Promise){if(a.async===!1)throw new Sa;return o.then(t=>e._zod.parse(t,a))}return e._zod.parse(o,a)};e._zod.run=(r,a)=>{if(a.skipChecks)return e._zod.parse(r,a);if(a.direction===`backward`){let t=e._zod.parse({value:r.value,issues:[]},{...a,skipChecks:!0});return t instanceof Promise?t.then(e=>n(e,r,a)):n(t,r,a)}let o=e._zod.parse(r,a);if(o instanceof Promise){if(a.async===!1)throw new Sa;return o.then(e=>t(e,i,a))}return t(o,i,a)}}},{get"~standard"(){return sa(this,`~standard`,is(this))},set"~standard"(e){oa(this,`~standard`,e)}}),ns=(e,t)=>e.issues.length?{issues:e.issues.map(e=>$i(e,t,Ta()))}:{value:e.value};async function rs(e,t){let n={async:!0};return ns(await e._zod.run({value:t,issues:[]},n),n)}function is(e){return{validate:t=>{let n={async:!1};try{let r=e._zod.run({value:t,issues:[]},n);if(!(r instanceof Promise))return ns(r,n)}catch{}return rs(e,t)},vendor:`zod`,version:1}}var as=J(`$ZodString`,(e,t)=>{ts.init(e,t),e._zod.pattern=t.pattern??ko,e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=String(n.value)}catch{}return typeof n.value==`string`||n.issues.push({expected:`string`,code:`invalid_type`,input:n.value,inst:e}),n}}),os=J(`$ZodStringFormat`,(e,t)=>{Go.init(e,t),as.init(e,t)}),ss=J(`$ZodGUID`,(e,t)=>{t.pattern??=lo,os.init(e,t)}),cs=J(`$ZodUUID`,(e,t)=>{if(t.version){let e={v1:1,v2:2,v3:3,v4:4,v5:5,v6:6,v7:7,v8:8}[t.version];if(e===void 0)throw Error(`Invalid UUID version: "${t.version}"`);t.pattern??=uo(e)}else t.pattern??=uo();os.init(e,t)}),ls=J(`$ZodEmail`,(e,t)=>{t.pattern??=fo,os.init(e,t)});function us(e){try{return typeof URL<`u`&&typeof URL.canParse==`function`?URL.canParse(e):(new URL(e),!0)}catch{return!1}}function ds(e,t){return!(`normalize`in t)&&!(`hostname`in t)&&!(`protocol`in t)?us(e)||2:fs(e,t)}function fs(e,t){if(!t.normalize&&t.protocol?.source===xo.source&&!/^https?:\/\//i.test(e))return 1;try{if(typeof URL<`u`){let t=URL;if(typeof t.parse==`function`)return t.parse(e)??2}return new URL(e)}catch{return 2}}var ps=/[\t\n\r]/g;function ms(e){return e.replace(ps,``)}function hs(e,t){return t.lastIndex=0,t.test(e.hostname)}function gs(e,t){return t.lastIndex=0,t.test(e.protocol.endsWith(`:`)?e.protocol.slice(0,-1):e.protocol)}var _s=J(`$ZodURL`,(e,t)=>{os.init(e,t),e._zod.check=n=>{try{let r=n.value.trim(),i=ds(r,t);if(i===1){n.issues.push({code:`invalid_format`,format:`url`,note:`Invalid URL format`,input:n.value,inst:e,continue:!t.abort});return}if(i===2){n.issues.push({code:`invalid_format`,format:`url`,input:n.value,inst:e,continue:!t.abort});return}if(i===!0){n.value=ms(r);return}t.hostname&&!hs(i,t.hostname)&&n.issues.push({code:`invalid_format`,format:`url`,note:`Invalid hostname`,pattern:t.hostname.source,input:n.value,inst:e,continue:!t.abort}),t.protocol&&!gs(i,t.protocol)&&n.issues.push({code:`invalid_format`,format:`url`,note:`Invalid protocol`,pattern:t.protocol.source,input:n.value,inst:e,continue:!t.abort}),n.value=t.normalize?i.href:ms(r);return}catch{n.issues.push({code:`invalid_format`,format:`url`,input:n.value,inst:e,continue:!t.abort})}}}),vs=J(`$ZodEmoji`,(e,t)=>{t.pattern??=mo(),os.init(e,t)}),ys=J(`$ZodNanoID`,(e,t)=>{if(t.length!==void 0&&(!Number.isInteger(t.length)||t.length<1))throw Error(`Invalid nanoid length: ${t.length}`);t.pattern??=t.length===void 0?oo:so(t.length),os.init(e,t)}),bs=J(`$ZodCUID`,(e,t)=>{t.pattern??=to,os.init(e,t)}),xs=J(`$ZodCUID2`,(e,t)=>{t.pattern??=no,os.init(e,t)}),Ss=J(`$ZodULID`,(e,t)=>{t.pattern??=ro,os.init(e,t)}),Cs=J(`$ZodXID`,(e,t)=>{t.pattern??=io,os.init(e,t)}),ws=J(`$ZodKSUID`,(e,t)=>{t.pattern??=ao,os.init(e,t)}),Ts=J(`$ZodISODateTime`,(e,t)=>{t.pattern??=Oo(t),os.init(e,t)}),Es=J(`$ZodISODate`,(e,t)=>{t.pattern??=To,os.init(e,t)}),Ds=J(`$ZodISOTime`,(e,t)=>{t.pattern??=Do(t),os.init(e,t)}),Os=J(`$ZodISODuration`,(e,t)=>{t.pattern??=co,os.init(e,t)}),ks=J(`$ZodIPv4`,(e,t)=>{t.pattern??=ho,os.init(e,t)}),As=/^[0-9a-fA-F:.]+$/;function js(e){return As.test(e)?us(`http://[${e}]`):!1}var Ms=J(`$ZodIPv6`,(e,t)=>{t.pattern??=go,os.init(e,t),e._zod.check=n=>{js(n.value)||n.issues.push({code:`invalid_format`,format:`ipv6`,input:n.value,inst:e,continue:!t.abort})}}),Ns=J(`$ZodCIDRv4`,(e,t)=>{t.pattern??=_o,os.init(e,t)});function Ps(e){let t=e.split(`/`);if(t.length!==2)return!1;let[n,r]=t;if(!r)return!1;let i=Number(r);return`${i}`!==r||i<0||i>128?!1:js(n)}var Fs=J(`$ZodCIDRv6`,(e,t)=>{t.pattern??=vo,os.init(e,t),e._zod.check=n=>{Ps(n.value)||n.issues.push({code:`invalid_format`,format:`cidrv6`,input:n.value,inst:e,continue:!t.abort})}});function Is(e){if(e===``)return!0;if(/\s/.test(e)||e.length%4!=0)return!1;try{return atob(e),!0}catch{return!1}}var Ls=/^[0-9a-zA-Z+/]*={0,2}$/,Rs=J(`$ZodBase64`,(e,t)=>{t.pattern??=Ls,os.init(e,t),e._zod.check=n=>{Is(n.value)||n.issues.push({code:`invalid_format`,format:`base64`,input:n.value,inst:e,continue:!t.abort})}}),zs=/^[A-Za-z0-9_-]*$/;function Bs(e){if(!zs.test(e))return!1;let t=e.replace(/[-_]/g,e=>e===`-`?`+`:`/`);return Is(t.padEnd(Math.ceil(t.length/4)*4,`=`))}var Vs=J(`$ZodBase64URL`,(e,t)=>{t.pattern??=zs,os.init(e,t),e._zod.check=n=>{Bs(n.value)||n.issues.push({code:`invalid_format`,format:`base64url`,input:n.value,inst:e,continue:!t.abort})}}),Hs=J(`$ZodE164`,(e,t)=>{t.pattern??=So,os.init(e,t)});function Us(e,t=null){try{let n=e.split(`.`);if(n.length!==3)return!1;let[r]=n;if(!r)return!1;let i=JSON.parse(atob(r));return!(`typ`in i&&i?.typ!==`JWT`||!i.alg||t&&(!(`alg`in i)||i.alg!==t))}catch{return!1}}var Ws=J(`$ZodJWT`,(e,t)=>{os.init(e,t),e._zod.check=n=>{Us(n.value,t.alg)||n.issues.push({code:`invalid_format`,format:`jwt`,input:n.value,inst:e,continue:!t.abort})}}),Gs=J(`$ZodNumber`,(e,t)=>{ts.init(e,t),e._zod.pattern=jo,e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=Number(n.value)}catch{}let i=n.value;if(typeof i==`number`&&!Number.isNaN(i)&&Number.isFinite(i))return n;let a=typeof i==`number`?Number.isNaN(i)?`NaN`:Number.isFinite(i)?void 0:String(i):void 0;return n.issues.push({expected:`number`,code:`invalid_type`,input:i,inst:e,...a?{received:a}:{}}),n}}),Ks=J(`$ZodNumberFormat`,(e,t)=>{Vo.init(e,t),Gs.init(e,t)}),qs=J(`$ZodBoolean`,(e,t)=>{ts.init(e,t),e._zod.pattern=Mo,e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=!!n.value}catch{}let i=n.value;return typeof i==`boolean`||n.issues.push({expected:`boolean`,code:`invalid_type`,input:i,inst:e}),n}}),Js=J(`$ZodUnknown`,(e,t)=>{ts.init(e,t),e._zod.parse=e=>e}),Ys=J(`$ZodNever`,(e,t)=>{ts.init(e,t),e._zod.parse=(t,n)=>(t.issues.push({expected:`never`,code:`invalid_type`,input:t.value,inst:e}),t)});function Xs(e,t,n){e.issues.length&&t.issues.push(...Xi(n,e.issues)),t.value[n]=e.value}var Zs=J(`$ZodArray`,(e,t)=>{ts.init(e,t);let n=wa.memoizer;n?.attach(e),e._zod.parse=(r,i)=>{let a=r.value;if(!Array.isArray(a))return r.issues.push({expected:`array`,code:`invalid_type`,input:a,inst:e}),r;r.value=n?n.alloc(e,r,Array(a.length),i):Array(a.length);let o=[],s=i?.abortEarly;for(let e=0;e<a.length;e++){let n=a[e],c=t.element._zod.run({value:n,issues:[]},i);if(c instanceof Promise)o.push(c.then(t=>Xs(t,r,e)));else if(Xs(c,r,e),s&&c.issues.length!==0&&Ji(c))break}return o.length?Promise.all(o).then(()=>r):r}});function Qs(e,t,n,r,i,a){let o=n in r,s=a===`optional`;if(o||!s||i!==`optional`){if(e.issues.length){if(i!==void 0&&s&&!o)return;t.issues.push(...Xi(n,e.issues))}if(!o&&i===void 0){e.issues.length||t.issues.push({code:`invalid_type`,expected:`nonoptional`,input:void 0,path:[n]});return}e.value===void 0?(o||i===`defaulted`&&!s)&&(t.value[n]=void 0):t.value[n]=e.value}}var $s=[];function ec(e){let t=Object.keys(e.shape),n=Object.getOwnPropertySymbols(e.shape),r=n.length?n:$s,i=r.length?[...t,...r]:t;for(let t of i)if(!e.shape?.[t]?._zod?.traits?.has(`$ZodType`))throw Error(`Invalid element at key "${String(t)}": expected a Zod schema`);let a=Ii(e.shape);return{...e,allKeys:i,symbolKeys:r,keySet:new Set(t),numKeys:t.length,optionalKeys:new Set(a)}}function tc(e,t,n,r,i,a,o){let s=[],c=i.keySet,l=i.catchall._zod,u=l.def.type,d=l.optin,f=l.optout,p=0;for(let i in t){if(o&&n.issues.length!==p){if(Ji(n,p))break;p=n.issues.length}if(c.has(i))continue;if(i===`__proto__`){u===`never`&&s.push(i);continue}if(u===`never`){s.push(i);continue}let a=l.run({value:t[i],issues:[]},r);a instanceof Promise?e.push(a.then(e=>Qs(e,n,i,t,d,f))):Qs(a,n,i,t,d,f)}return s.length&&n.issues.push({code:`unrecognized_keys`,keys:s,input:t,inst:a,continue:!0}),e.length?Promise.all(e).then(()=>n):n}var nc=J(`$ZodObject`,(e,t)=>{ts.init(e,t);let n=Object.getOwnPropertyDescriptor(t,`shape`),r=n?.get?n.get.raw:t.shape??{};if(r){let e=()=>{let n={...r};return Object.defineProperty(t,"shape",{value:n}),e.raw=n,n};e.raw=r,Object.defineProperty(t,"shape",{get:e})}let i=pi(()=>ec(t));ma(e,`propValues`,e=>{let t=e.def.shape,n={};for(let e in t){let r=t[e]._zod;if(r.values){Object.prototype.hasOwnProperty.call(n,e)||_i(n,e,new Set);for(let t of r.values)n[e].add(t);r.optin!==void 0&&n[e].add(void 0)}}return n});let a=Oi,o=t.catchall,s,c=wa.memoizer;c?.attach(e),e._zod.parse=(t,n)=>{s??=i.value;let r=t.value;if(!a(r))return t.issues.push({expected:`object`,code:`invalid_type`,input:r,inst:e}),t;t.value=c?c.alloc(e,t,{},n):{};let l=[],u=s.shape,d=n?.abortEarly,f=t.issues.length;for(let e of s.allKeys){if(d&&t.issues.length!==f){if(Ji(t,f))break;f=t.issues.length}if(e===`__proto__`)continue;let i=u[e],a=i._zod.optin,o=i._zod.optout,s=i._zod.run({value:r[e],issues:[]},n);s instanceof Promise?l.push(s.then(n=>Qs(n,t,e,r,a,o))):Qs(s,t,e,r,a,o)}return o?tc(l,r,t,n,i.value,e,d===!0):l.length?Promise.all(l).then(()=>t):t}}),rc=J(`$ZodObjectJIT`,(e,t)=>{nc.init(e,t);let n=e._zod.parse,r=pi(()=>ec(t)),i=wa.memoizer,a=t=>{let n=r.value,a=n.symbolKeys,o=new $o([`payload`,`ctx`],{shape:t,inst:e,memo:i,syms:a}),s=e=>`shape[${e}]._zod.run({ value: input[${e}], issues: [] }, ctx)`,c=(e,t)=>`
|
|
4
|
+
let ${e}_ab = false;
|
|
5
|
+
for (let i = 0; i < ${e}.issues.length; i++) {
|
|
6
|
+
const iss = ${e}.issues[i];
|
|
7
|
+
iss.path = iss.path ? [${t}, ...iss.path] : [${t}];
|
|
8
|
+
payload.issues.push(iss);
|
|
9
|
+
if (iss.continue !== true) ${e}_ab = true;
|
|
10
|
+
}
|
|
11
|
+
if (${e}_ab && ctx && ctx.abortEarly) {
|
|
12
|
+
payload.value = newResult;
|
|
13
|
+
return payload;
|
|
14
|
+
}`;o.write(`const input = payload.value;`);let l=Object.create(null),u=0;for(let e of n.allKeys)l[e]=`key_${u++}`;o.write(i?`const newResult = memo.alloc(inst, payload, {}, ctx);`:`const newResult = {};`);for(let e of n.allKeys){if(e===`__proto__`)continue;let n=l[e],r=typeof e==`symbol`?`syms[${a.indexOf(e)}]`:Ti(e),i=`${r} in input`,u=t[e],d=u?._zod?.optin,f=d!==void 0,p=u?._zod?.optout===`optional`;if(o.write(`const ${n} = ${s(r)};`),f&&p){let e=d===`optional`?`${n}_present`:`${n}.value !== undefined || ${n}_present`;o.write(`
|
|
15
|
+
const ${n}_present = ${i};
|
|
16
|
+
if (!${n}.issues.length || ${n}_present) {
|
|
17
|
+
if (${n}.issues.length) {${c(n,r)}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (${e}) {
|
|
21
|
+
newResult[${r}] = ${n}.value;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
`)}else f?(o.write(`
|
|
26
|
+
if (${n}.issues.length) {${c(n,r)}
|
|
27
|
+
}
|
|
28
|
+
`),d===`defaulted`?o.write(`newResult[${r}] = ${n}.value;`):o.write(`
|
|
29
|
+
if (${n}.value !== undefined || ${i}) {
|
|
30
|
+
newResult[${r}] = ${n}.value;
|
|
31
|
+
}
|
|
32
|
+
`)):o.write(`
|
|
33
|
+
const ${n}_present = ${i};
|
|
34
|
+
if (${n}.issues.length) {${c(n,r)}
|
|
35
|
+
}
|
|
36
|
+
if (!${n}_present && !${n}.issues.length) {
|
|
37
|
+
payload.issues.push({
|
|
38
|
+
code: "invalid_type",
|
|
39
|
+
expected: "nonoptional",
|
|
40
|
+
input: undefined,
|
|
41
|
+
path: [${r}]
|
|
42
|
+
});
|
|
43
|
+
if (ctx && ctx.abortEarly) {
|
|
44
|
+
payload.value = newResult;
|
|
45
|
+
return payload;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (${n}_present) {
|
|
50
|
+
newResult[${r}] = ${n}.value;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
`)}return o.write(`payload.value = newResult;`),o.write(`return payload;`),o.compile()},o,s=Oi,c=!wa.jitless,l=c&&ki.value,u=t.catchall,d;e._zod.parse=(i,f)=>{d??=r.value;let p=i.value;return s(p)?c&&l&&f?.async===!1&&f.jitless!==!0?(o||=a(t.shape),i=o(i,f),u?tc([],p,i,f,d,e,f?.abortEarly===!0):i):n(i,f):(i.issues.push({expected:`object`,code:`invalid_type`,input:p,inst:e}),i)}});function ic(e,t,n,r){for(let n of e)if(n.issues.length===0)return t.value=n.value,t;let i=e.filter(e=>!Ji(e));return i.length===1?(t.value=i[0].value,i[0]):(t.issues.push({code:`invalid_union`,input:t.value,inst:n,errors:e.map(e=>e.issues.map(e=>$i(e,r,Ta())))}),t)}var ac=J(`$ZodUnion`,(e,t)=>{ts.init(e,t),ma(e,`optin`,e=>e.def.options.some(e=>e._zod.optin===`defaulted`)?`defaulted`:e.def.options.some(e=>e._zod.optin!==void 0)?`optional`:void 0),ma(e,`optout`,e=>e.def.options.some(e=>e._zod.optout===`optional`)?`optional`:void 0),ma(e,`values`,e=>{if(e.def.options.every(e=>e._zod.values))return new Set(e.def.options.flatMap(e=>Array.from(e._zod.values)))}),ma(e,`pattern`,e=>{if(e.def.options.every(e=>e._zod.pattern)){let t=e.def.options.map(e=>e._zod.pattern);return RegExp(`^(${t.map(e=>hi(e.source)).join(`|`)})$`)}});let n=t.options.length===1?t.options[0]._zod.run:null;e._zod.parse=(r,i)=>{if(n)return n(r,i);let a=!1,o=[];for(let e of t.options){let t=e._zod.run({value:r.value,issues:[]},i);if(t instanceof Promise)o.push(t),a=!0;else{if(t.issues.length===0)return t;o.push(t)}}return a?Promise.all(o).then(t=>ic(t,r,e,i)):ic(o,r,e,i)}});function oc(e){let t=new Map;for(let n of e.options){let r=n._zod.propValues?.[e.discriminator];if(!r||r.size===0)throw Error(`Invalid discriminated union option at index "${e.options.indexOf(n)}"`);for(let e of r)if(t.has(e)){if(e!==void 0)throw Error(`Duplicate discriminator value "${String(e)}"`);t.set(e,null)}else t.set(e,n)}return t}var sc=J(`$ZodDiscriminatedUnion`,(e,t)=>{t.inclusive=!1,ac.init(e,t);let n=e._zod.parse;ma(e,`propValues`,e=>{let t={},n=0;for(let r of e.def.options){let i=r._zod.propValues;if(!i||Object.keys(i).length===0)throw Error(`Invalid discriminated union option at index "${e.def.options.indexOf(r)}"`);i[e.def.discriminator]?.has(void 0)&&n++;for(let[e,n]of Object.entries(i)){Object.prototype.hasOwnProperty.call(t,e)||_i(t,e,new Set);for(let r of n)t[e].add(r)}}return!e.def.unionFallback&&n>1&&t[e.def.discriminator]?.delete(void 0),t}),t.options.forEach((e,n)=>{let r=vi(e._zod.def);if(r&&!Object.prototype.hasOwnProperty.call(r,t.discriminator))throw Error(`Invalid discriminated union option at index "${n}"`)});let r=pi(()=>oc(t));e._zod.parse=(i,a)=>{let o=i.value;if(!Oi(o))return i.issues.push({code:`invalid_type`,expected:`object`,input:o,inst:e}),i;let s=o?.[t.discriminator],c=r.value.get(s);return c&&(s!==void 0||a.direction!==`backward`)?c._zod.run(i,a):t.unionFallback||a.direction===`backward`?n(i,a):(i.issues.push({code:`invalid_union`,errors:[],note:`No matching discriminator`,discriminator:t.discriminator,options:Array.from(r.value.keys()).filter(e=>r.value.get(e)!==null),input:o,path:[t.discriminator],inst:e}),i)}}),cc=J(`$ZodIntersection`,(e,t)=>{ts.init(e,t),e._zod.parse=(e,n)=>{let r=e.value,i=t.left._zod.run({value:r,issues:[]},n),a=t.right._zod.run({value:r,issues:[]},n);return i instanceof Promise||a instanceof Promise?Promise.all([i,a]).then(([t,n])=>uc(e,t,n)):uc(e,i,a)}});function lc(e,t){if(e===t||e instanceof Date&&t instanceof Date&&+e==+t)return{valid:!0,data:e};if(Ai(e)&&Ai(t)){let n=Object.keys(t),r=Object.keys(e).filter(e=>n.indexOf(e)!==-1),i={...e,...t};Object.prototype.hasOwnProperty.call(i,`__proto__`)&&delete i.__proto__;for(let n of r){if(n===`__proto__`)continue;let r=lc(e[n],t[n]);if(!r.valid)return{valid:!1,mergeErrorPath:[n,...r.mergeErrorPath]};i[n]=r.data}return{valid:!0,data:i}}if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return{valid:!1,mergeErrorPath:[]};let n=[];for(let r=0;r<e.length;r++){let i=e[r],a=t[r],o=lc(i,a);if(!o.valid)return{valid:!1,mergeErrorPath:[r,...o.mergeErrorPath]};n.push(o.data)}return{valid:!0,data:n}}return{valid:!1,mergeErrorPath:[]}}function uc(e,t,n){let r=new Map,i,a=new Map,o=(e,t)=>{let n;if(e.code===`unrecognized_keys`&&!e.path?.length)i??=e,n=e.keys;else if(e.code===`invalid_key`&&e.origin===`record`&&e.path?.length===1){let t=String(e.path[0]);a.has(t)||a.set(t,e),n=[t]}else return!1;for(let e of n)r.has(e)||r.set(e,{}),r.get(e)[t]=!0;return!0};for(let n of t.issues)o(n,`l`)||e.issues.push(n);for(let t of n.issues)o(t,`r`)||e.issues.push(t);let s=[...r].filter(([,e])=>e.l&&e.r).map(([e])=>e);if(s.length){let t=i?s.filter(e=>i.keys.includes(e)):[];t.length&&e.issues.push({...i,keys:t});for(let n of s)!t.includes(n)&&a.has(n)&&e.issues.push(a.get(n))}let c=lc(t.value,n.value);if(!c.valid){if(Ji(e))return e;throw Error(`Unmergable intersection. Error path: ${JSON.stringify(c.mergeErrorPath)}`)}return e.value=c.data,e}var dc=J(`$ZodRecord`,(e,t)=>{ts.init(e,t);let n=wa.memoizer;n?.attach(e),e._zod.parse=(r,i)=>{let a=r.value;if(!Ai(a))return r.issues.push({expected:`record`,code:`invalid_type`,input:a,inst:e}),r;let o=[],s=t.keyType._zod.values;if(s&&!t.partial){r.value=n?n.alloc(e,r,{},i):{};let c=new Set;for(let n of s)if(typeof n==`string`||typeof n==`number`||typeof n==`symbol`){if(c.add(typeof n==`number`?n.toString():n),n===`__proto__`)continue;let s=t.keyType._zod.run({value:n,issues:[]},i);if(s instanceof Promise)throw Error(`Async schemas not supported in object keys currently`);if(s.issues.length){r.issues.push({code:`invalid_key`,origin:`record`,issues:s.issues.map(e=>$i(e,i,Ta())),input:n,path:[n],inst:e});continue}let l=s.value;if(l===`__proto__`)continue;let u=t.valueType._zod.run({value:a[n],issues:[]},i);u instanceof Promise?o.push(u.then(e=>{e.issues.length&&r.issues.push(...Xi(n,e.issues)),r.value[l]=e.value})):(u.issues.length&&r.issues.push(...Xi(n,u.issues)),r.value[l]=u.value)}let l;for(let e in a)if(!c.has(e)){if(t.mode===`loose`){if(e===`__proto__`)continue;r.value[e]=a[e]}else l??=[],l.push(e)}l&&l.length>0&&r.issues.push({code:`unrecognized_keys`,input:a,inst:e,keys:l,continue:!0})}else{r.value=n?n.alloc(e,r,{},i):{};let c;for(let n of Reflect.ownKeys(a)){if(n===`__proto__`||!Object.prototype.propertyIsEnumerable.call(a,n))continue;let l=t.keyType._zod.run({value:n,issues:[]},i);if(l instanceof Promise)throw Error(`Async schemas not supported in object keys currently`);if(typeof n==`string`&&jo.test(n)&&l.issues.length){let e=t.keyType._zod.run({value:Number(n),issues:[]},i);if(e instanceof Promise)throw Error(`Async schemas not supported in object keys currently`);e.issues.length===0&&(l=e)}if(l.issues.length){t.mode===`loose`?r.value[n]=a[n]:s?(c??=[],c.push(n)):r.issues.push({code:`invalid_key`,origin:`record`,issues:l.issues.map(e=>$i(e,i,Ta())),input:n,path:[n],inst:e});continue}let u=l.value;if(u===`__proto__`)continue;let d=t.valueType._zod.run({value:a[n],issues:[]},i);d instanceof Promise?o.push(d.then(e=>{e.issues.length&&r.issues.push(...Xi(n,e.issues)),r.value[u]=e.value})):(d.issues.length&&r.issues.push(...Xi(n,d.issues)),r.value[u]=d.value)}c&&c.length>0&&r.issues.push({code:`unrecognized_keys`,input:a,inst:e,keys:c,continue:!0})}return o.length?Promise.all(o).then(()=>r):r}}),fc=J(`$ZodEnum`,(e,t)=>{ts.init(e,t);let n=li(t.entries),r=new Set(n);e._zod.values=r,ma(e,`pattern`,e=>{let t=li(e.def.entries).filter(e=>Mi.has(typeof e));return RegExp(t.length?`^(${t.map(e=>Ni(e.toString())).join(`|`)})$`:`^[^\\s\\S]$`)}),e._zod.parse=(t,i)=>{let a=t.value;return r.has(a)||t.issues.push({code:`invalid_value`,values:n,input:a,inst:e}),t}}),pc=J(`$ZodLiteral`,(e,t)=>{ts.init(e,t);let n=new Set(t.values);e._zod.values=n,ma(e,`pattern`,e=>{let t=e.def.values;return RegExp(t.length?`^(${t.map(e=>typeof e==`string`?Ni(e):e?Ni(e.toString()):String(e)).join(`|`)})$`:`^[^\\s\\S]$`)}),e._zod.parse=(r,i)=>{let a=r.value;return n.has(a)||r.issues.push({code:`invalid_value`,values:t.values,input:a,inst:e}),r}}),mc=J(`$ZodTransform`,(e,t)=>{ts.init(e,t),e._zod.optin=`optional`,wa.memoizer?.guard(e),e._zod.parse=(n,r)=>{if(r.direction===`backward`)throw new Ca(e.constructor.name);let i=t.transform(n.value,n);if(r.async)return(i instanceof Promise?i:Promise.resolve(i)).then(e=>(n.value=e,n));if(i instanceof Promise)throw new Sa;return n.value=i,n}});function hc(e,t){return e.value=t.issues.length?void 0:t.value,e}var gc=J(`$ZodOptional`,(e,t)=>{ts.init(e,t),ma(e,`optin`,e=>e.def.innerType._zod.optin===`defaulted`?`defaulted`:`optional`),e._zod.optout=`optional`,ma(e,`values`,e=>{let t=e.def.innerType._zod.values;return t?new Set([...t,void 0]):void 0}),ma(e,`pattern`,e=>{let t=e.def.innerType._zod.pattern;return t?RegExp(`^(${hi(t.source)})?$`):void 0}),e._zod.parse=(e,n)=>{if(e.value===void 0){if(t.innerType._zod.optin!==`defaulted`)return e;let r=t.innerType._zod.run({value:e.value,issues:[]},n);return r instanceof Promise?r.then(t=>hc(e,t)):hc(e,r)}return t.innerType._zod.run(e,n)}}),_c=J(`$ZodExactOptional`,(e,t)=>{gc.init(e,t),ma(e,`values`,e=>e.def.innerType._zod.values),ma(e,`pattern`,e=>e.def.innerType._zod.pattern),e._zod.parse=(e,n)=>t.innerType._zod.run(e,n)}),vc=J(`$ZodNullable`,(e,t)=>{ts.init(e,t),ma(e,`optin`,e=>e.def.innerType._zod.optin),ma(e,`optout`,e=>e.def.innerType._zod.optout),ma(e,`pattern`,e=>{let t=e.def.innerType._zod.pattern;return t?RegExp(`^(${hi(t.source)}|null)$`):void 0}),ma(e,`values`,e=>e.def.innerType._zod.values?new Set([...e.def.innerType._zod.values,null]):void 0),e._zod.parse=(e,n)=>e.value===null?e:t.innerType._zod.run(e,n)}),yc=J(`$ZodDefault`,(e,t)=>{ts.init(e,t),e._zod.optin=`defaulted`,ma(e,`values`,e=>e.def.innerType._zod.values),e._zod.parse=(e,n)=>{if(n.direction===`backward`)return t.innerType._zod.run(e,n);if(e.value===void 0)return e.value=t.defaultValue,e;let r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(e=>bc(e,t)):bc(r,t)}});function bc(e,t){return e.value===void 0&&(e.value=t.defaultValue),e}var xc=J(`$ZodPrefault`,(e,t)=>{ts.init(e,t),e._zod.optin=`defaulted`,ma(e,`values`,e=>e.def.innerType._zod.values),e._zod.parse=(e,n)=>(n.direction===`backward`||e.value===void 0&&(e.value=t.defaultValue),t.innerType._zod.run(e,n))}),Sc=J(`$ZodNonOptional`,(e,t)=>{ts.init(e,t),ma(e,`values`,e=>{let t=e.def.innerType._zod.values;return t?new Set([...t].filter(e=>e!==void 0)):void 0}),e._zod.parse=(n,r)=>{let i=t.innerType._zod.run(n,r);return i instanceof Promise?i.then(t=>Cc(t,e)):Cc(i,e)}});function Cc(e,t){return!e.issues.length&&e.value===void 0&&e.issues.push({code:`invalid_type`,expected:`nonoptional`,input:e.value,inst:t}),e}function wc(e,t,n,r){return t.issues.length?(e.value=n.catchValue({...t,value:e.value,error:{issues:t.issues.map(e=>$i(e,r,Ta()))},input:e.value}),e):(e.value=t.value,t.memo&&(e.memo=!0),e)}var Tc=J(`$ZodCatch`,(e,t)=>{ts.init(e,t),ma(e,`optin`,e=>e.def.innerType._zod.optin===`defaulted`?`defaulted`:`optional`),ma(e,`optout`,e=>e.def.innerType._zod.optout),ma(e,`values`,e=>e.def.innerType._zod.values),e._zod.parse=(e,n)=>{if(n.direction===`backward`)return t.innerType._zod.run(e,n);let r=t.innerType._zod.run({value:e.value,issues:[]},n);return r instanceof Promise?r.then(r=>wc(e,r,t,n)):wc(e,r,t,n)}}),Ec=J(`$ZodPipe`,(e,t)=>{ts.init(e,t),ma(e,`values`,e=>e.def.in._zod.values),ma(e,`optin`,e=>e.def.in._zod.optin),ma(e,`optout`,e=>e.def.out._zod.optout),ma(e,`propValues`,e=>e.def.in._zod.propValues),e._zod.parse=(e,n)=>{if(n.direction===`backward`){let r=t.out._zod.run(e,n);return r instanceof Promise?r.then(e=>Dc(e,t.in,n)):Dc(r,t.in,n)}let r=t.in._zod.run(e,n);return r instanceof Promise?r.then(e=>Dc(e,t.out,n)):Dc(r,t.out,n)}});function Dc(e,t,n){return e.issues.some(e=>e.code!==`unrecognized_keys`)?(e.aborted=!0,e):t._zod.run({value:e.value,issues:e.issues},n)}var Oc=J(`$ZodPreprocess`,(e,t)=>{Ec.init(e,t)}),kc=J(`$ZodReadonly`,(e,t)=>{ts.init(e,t),ma(e,`propValues`,e=>e.def.innerType._zod.propValues),ma(e,`values`,e=>e.def.innerType._zod.values),ma(e,`optin`,e=>e.def.innerType?._zod?.optin),ma(e,`optout`,e=>e.def.innerType?._zod?.optout),e._zod.parse=(e,n)=>{if(n.direction===`backward`)return t.innerType._zod.run(e,n);let r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(Ac):Ac(r)}});function Ac(e){return e.memo||(e.value=Object.freeze(e.value)),e}var jc=J(`$ZodCustom`,(e,t)=>{Fo.init(e,t),ts.init(e,t),e._zod.parse=(e,t)=>e,e._zod.check=n=>{let r=n.value,i=t.fn(r);if(i instanceof Promise)return i.then(t=>Mc(t,n,r,e));Mc(i,n,r,e)}});function Mc(e,t,n,r){if(!e){let e={code:`custom`,input:n,inst:r,path:[...r._zod.def.path??[]],continue:!r._zod.def.abort};r._zod.def.params&&(e.params=r._zod.def.params),t.issues.push(ia(e))}}var Nc=class extends Error{constructor(){super(`Cannot parse a reference cycle that closes through a transform`),this.name=`ZodCyclicError`}},Pc=`~memo`,Fc=[];function Ic(e){return typeof e==`object`&&!!e}function Lc(e){return e.map(e=>e.path?{...e,path:e.path.slice()}:{...e})}var Rc=new WeakMap,zc=0,Bc=1,Vc=2;function Hc(e,t,n){let r=Rc.get(e);if(r!==void 0)return r?Vc:zc;if(t.has(e))return Vc;t.add(e);let i=zc,a=e=>{if(i!==Vc&&e?._zod){let r=Hc(e,t,n);r>i&&(i=r)}},o=(e,r)=>{let i=zc;for(let a of Reflect.ownKeys(e)){let o=Object.getOwnPropertyDescriptor(e,a);if(r&&!o.enumerable)continue;let s=o.get?Bc:o.value?._zod?Hc(o.value,t,n):zc;s>i&&(i=s)}return i},s=e=>{e>i&&(i=e)},c=e._zod.def;switch(c.type){case`object`:{let e=vi(c);s(e?o(e,!0):Bc),a(c.catchall);break}case`array`:a(c.element);break;case`tuple`:for(let e of c.items)a(e);a(c.rest);break;case`record`:case`map`:a(c.keyType),a(c.valueType);break;case`set`:a(c.valueType);break;case`union`:for(let e of c.options)a(e);break;case`intersection`:a(c.left),a(c.right);break;case`optional`:case`nullable`:case`default`:case`prefault`:case`catch`:case`readonly`:case`nonoptional`:case`promise`:case`success`:a(c.innerType);break;case`pipe`:a(c.in),a(c.out);break;case`function`:a(c.input),a(c.output);break;case`lazy`:{let r=c._cachedInner??(n?e._zod.innerType:void 0);s(r?Hc(r,t,!1):Bc);break}case`template_literal`:case`string`:case`number`:case`int`:case`boolean`:case`bigint`:case`symbol`:case`undefined`:case`null`:case`void`:case`never`:case`any`:case`unknown`:case`date`:case`nan`:case`enum`:case`literal`:case`file`:case`transform`:case`custom`:break;default:for(let e in c){let t=Object.getOwnPropertyDescriptor(c,e);if(!t||t.get)continue;let n=t.value;if(n&&typeof n==`object`){if(n._zod)a(n);else if(Array.isArray(n))for(let e of n)a(e)}}}return t.delete(e),Uc(e,i)}function Uc(e,t){return t!==Bc&&Rc.set(e,t===Vc),t}function Wc(e,t){let n=e.buckets.get(t);return n||(n=new WeakMap,e.buckets.set(t,n)),n}var Gc,Kc=[],qc={alloc(e,t,n){let r=Gc;if(!r)return n;Gc=void 0;let i={value:n,issues:null};return r.set(t.value,i),Kc.push(i),n},guard(e){var t;(t=e._zod).deferred??(t.deferred=[]),e._zod.deferred.push(()=>{let t=e._zod.parse,n=(e,n)=>{if(n.direction!==`backward`&&Yc(n,e.value))throw new Nc;return t(e,n)};e._zod.parse=n,e._zod.run===t&&(e._zod.run=n)})},attach(e){var t;let n,r=!1,i,a;(t=e._zod).deferred??(t.deferred=[]),e._zod.deferred.push(()=>{let t=e._zod.parse,o=(s,c)=>{if(n===void 0){let i=Hc(e,new Set,!1);if(i===zc)return e._zod.parse=t,e._zod.run===o&&(e._zod.run=t),t(s,c);i===Vc||r?n=!0:r=!0}let l=s.value;if(!Ic(l))return t(s,c);let u=c[Pc];u||(u={buckets:new WeakMap,backEdges:void 0},c[Pc]=u);let d;i===c?d=a:(d=Wc(u,e),i=c,a=d);let f=d.get(l);if(f)return s.value=f.value,f.issues?f.issues.length&&s.issues.push(...Lc(f.issues)):(s.memo=!0,u.backEdges??(u.backEdges=new WeakSet),u.backEdges.add(f.value)),s;Gc=d;let p=Kc.length,m=t(s,c);Gc=void 0;let h=Kc.length>p?Kc.pop():void 0;return m instanceof Promise?m.then(e=>(h&&(h.issues=e.issues.length?Lc(e.issues):Fc),e)):(h&&(h.issues=m.issues.length?Lc(m.issues):Fc),m)};e._zod.parse=o,e._zod.run===t&&(e._zod.run=o)})}};function Jc(){return qc}function Yc(e,t){let n=e[Pc]?.backEdges;return n!==void 0&&Ic(t)&&n.has(t)}var Xc=()=>{let e={string:{unit:`characters`,verb:`to have`},file:{unit:`bytes`,verb:`to have`},array:{unit:`items`,verb:`to have`},set:{unit:`items`,verb:`to have`},map:{unit:`entries`,verb:`to have`}};function t(t){return e[t]??null}let n={regex:`input`,email:`email address`,url:`URL`,emoji:`emoji`,uuid:`UUID`,uuidv4:`UUIDv4`,uuidv6:`UUIDv6`,nanoid:`nanoid`,guid:`GUID`,cuid:`cuid`,cuid2:`cuid2`,ulid:`ULID`,xid:`XID`,ksuid:`KSUID`,datetime:`ISO datetime`,date:`ISO date`,time:`ISO time`,duration:`ISO duration`,ipv4:`IPv4 address`,ipv6:`IPv6 address`,mac:`MAC address`,cidrv4:`IPv4 range`,cidrv6:`IPv6 range`,base64:`base64-encoded string`,base64url:`base64url-encoded string`,json_string:`JSON string`,e164:`E.164 number`,currency_code:`currency code`,credit_card:`credit card number`,iban:`IBAN`,jwt:`JWT`,template_literal:`input`},r={nan:`NaN`};function i(e,t){return e===`number`&&typeof t==`number`&&!Number.isFinite(t)?String(t):r[e]??e}return e=>{switch(e.code){case`invalid_type`:return`Invalid input: expected ${i(e.expected)}, received ${i(ra(e.input),e.input)}`;case`invalid_value`:return e.values.length===1?`Invalid input: expected ${Fi(e.values[0])}`:`Invalid option: expected one of ${ui(e.values,`|`)}`;case`too_big`:{let n=e.exact?`exactly `:e.inclusive?`<=`:`<`,r=t(e.origin);return r?`Too big: expected ${e.origin??`value`} to have ${n}${e.maximum.toString()} ${r.unit??`elements`}`:`Too big: expected ${e.origin??`value`} to be ${n}${e.maximum.toString()}`}case`too_small`:{let n=e.exact?`exactly `:e.inclusive?`>=`:`>`,r=t(e.origin);return r?`Too small: expected ${e.origin} to have ${n}${e.minimum.toString()} ${r.unit}`:`Too small: expected ${e.origin} to be ${n}${e.minimum.toString()}`}case`invalid_format`:{let t=e;return t.format===`starts_with`?`Invalid string: must start with "${t.prefix}"`:t.format===`ends_with`?`Invalid string: must end with "${t.suffix}"`:t.format===`includes`?`Invalid string: must include "${t.includes}"`:t.format===`regex`?`Invalid string: must match pattern ${t.pattern}`:`Invalid ${n[t.format]??e.format}`}case`not_multiple_of`:return`Invalid number: must be a multiple of ${e.divisor}`;case`unrecognized_keys`:return`Unrecognized key${e.keys.length>1?`s`:``}: ${ui(e.keys,`, `)}`;case`invalid_key`:return`Invalid key in ${e.origin}`;case`invalid_union`:return e.options&&Array.isArray(e.options)&&e.options.length>0?`Invalid discriminator value. Expected ${e.options.map(e=>`'${e}'`).join(` | `)}`:e.inclusive===!1?`Invalid input: more than one option matched`:`Invalid input`;case`invalid_element`:return`Invalid value in ${e.origin}`;default:return`Invalid input`}}};function Zc(){return{localeError:Xc()}}var Qc,$c=class{constructor(){this._map=new WeakMap,this._idmap=new Map}add(e,...t){let n=t[0];return this._map.set(e,n),n&&typeof n==`object`&&`id`in n&&this._idmap.set(n.id,e),this}clear(){return this._map=new WeakMap,this._idmap=new Map,this}remove(e){let t=this._map.get(e);return t&&typeof t==`object`&&`id`in t&&this._idmap.delete(t.id),this._map.delete(e),this}get(e){let t=e._zod.parent;if(t){let n={...this.get(t)??{}};delete n.id;let r={...n,...this._map.get(e)};return Object.keys(r).length?r:void 0}return this._map.get(e)}has(e){return this._map.has(e)}};function el(){return new $c}(Qc=globalThis).__zod_globalRegistry??(Qc.__zod_globalRegistry=el());var tl=globalThis.__zod_globalRegistry;function nl(e){return e.checks&&=[...e.checks],e}function rl(e,t){return new e(nl({type:`string`,...q(t)}))}function il(e,t){return new e({type:`string`,format:`email`,check:`string_format`,abort:!1,...q(t)})}function al(e,t){return new e({type:`string`,format:`guid`,check:`string_format`,abort:!1,...q(t)})}function ol(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,...q(t)})}function sl(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v4`,...q(t)})}function cl(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v6`,...q(t)})}function ll(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v7`,...q(t)})}function ul(e,t){return new e({type:`string`,format:`url`,check:`string_format`,abort:!1,...q(t)})}function dl(e,t){return new e({type:`string`,format:`emoji`,check:`string_format`,abort:!1,...q(t)})}function fl(e,t){return new e({type:`string`,format:`nanoid`,check:`string_format`,abort:!1,...q(t)})}function pl(e,t){return new e({type:`string`,format:`cuid`,check:`string_format`,abort:!1,...q(t)})}function ml(e,t){return new e({type:`string`,format:`cuid2`,check:`string_format`,abort:!1,...q(t)})}function hl(e,t){return new e({type:`string`,format:`ulid`,check:`string_format`,abort:!1,...q(t)})}function gl(e,t){return new e({type:`string`,format:`xid`,check:`string_format`,abort:!1,...q(t)})}function _l(e,t){return new e({type:`string`,format:`ksuid`,check:`string_format`,abort:!1,...q(t)})}function vl(e,t){return new e({type:`string`,format:`ipv4`,check:`string_format`,abort:!1,...q(t)})}function yl(e,t){return new e({type:`string`,format:`ipv6`,check:`string_format`,abort:!1,...q(t)})}function bl(e,t){return new e({type:`string`,format:`cidrv4`,check:`string_format`,abort:!1,...q(t)})}function xl(e,t){return new e({type:`string`,format:`cidrv6`,check:`string_format`,abort:!1,...q(t)})}function Sl(e,t){return new e({type:`string`,format:`base64`,check:`string_format`,abort:!1,...q(t)})}function Cl(e,t){return new e({type:`string`,format:`base64url`,check:`string_format`,abort:!1,...q(t)})}function wl(e,t){return new e({type:`string`,format:`e164`,check:`string_format`,abort:!1,...q(t)})}function Tl(e,t){return new e({type:`string`,format:`jwt`,check:`string_format`,abort:!1,...q(t)})}function El(e,t){return new e({type:`string`,format:`datetime`,check:`string_format`,offset:!1,local:!1,precision:null,...q(t)})}function Dl(e,t){return new e({type:`string`,format:`date`,check:`string_format`,...q(t)})}function Ol(e,t){return new e({type:`string`,format:`time`,check:`string_format`,precision:null,...q(t)})}function kl(e,t){return new e({type:`string`,format:`duration`,check:`string_format`,...q(t)})}function Al(e,t){return new e(nl({type:`number`,checks:[],...q(t)}))}function jl(e,t){return new e({type:`number`,check:`number_format`,abort:!1,format:`safeint`,...q(t)})}function Ml(e,t){return new e({type:`boolean`,...q(t)})}function Nl(e){return new e({type:`unknown`})}function Pl(e,t){return new e({type:`never`,...q(t)})}function Fl(e,t){return new Ro({check:`less_than`,...q(t),value:e,inclusive:!1})}function Il(e,t){return new Ro({check:`less_than`,...q(t),value:e,inclusive:!0})}function Ll(e,t){return new zo({check:`greater_than`,...q(t),value:e,inclusive:!1})}function Rl(e,t){return new zo({check:`greater_than`,...q(t),value:e,inclusive:!0})}function zl(e,t){return new Bo({check:`multiple_of`,...q(t),value:e})}function Bl(e,t){return new Ho({check:`max_length`,...q(t),maximum:e})}function Vl(e,t){return new Uo({check:`min_length`,...q(t),minimum:e})}function Hl(e,t){return new Wo({check:`length_equals`,...q(t),length:e})}function Ul(e,t){return new Ko({check:`string_format`,format:`regex`,...q(t),pattern:e})}function Wl(e){return new qo({check:`string_format`,format:`lowercase`,...q(e)})}function Gl(e){return new Jo({check:`string_format`,format:`uppercase`,...q(e)})}function Kl(e,t){return new Yo({check:`string_format`,format:`includes`,...q(t),includes:e})}function ql(e,t){return new Xo({check:`string_format`,format:`starts_with`,...q(t),prefix:e})}function Jl(e,t){return new Zo({check:`string_format`,format:`ends_with`,...q(t),suffix:e})}function Yl(e){return new Qo({check:`overwrite`,tx:e})}function Xl(e){return Yl(t=>t.normalize(e))}function Zl(){return Yl(e=>e.trim())}function Ql(){return Yl(e=>e.toLowerCase())}function $l(){return Yl(e=>e.toUpperCase())}function eu(){return Yl(e=>Ei(e))}function tu(e,t,n){return new e({type:`array`,element:t,...q(n)})}function nu(e,t,n){return new e({type:`custom`,check:`custom`,fn:t,...q(n)})}function ru(e,t){let n=iu(t=>(t.addIssue=e=>{if(typeof e==`string`)t.issues.push(ia(e,t.value,n._zod.def));else{let r=e;r.fatal&&(r.continue=!1),r.code??=`custom`,`input`in r||(r.input=t.value),r.inst??=n,r.continue??=!n._zod.def.abort,t.issues.push(ia(r))}},e(t.value,t)),t);return n}function iu(e,t){let n=new Fo({check:`custom`,...q(t)});return n._zod.check=e,n}function au(e,...t){for(let n of t)for(let t of Reflect.ownKeys(n))Object.prototype.propertyIsEnumerable.call(n,t)&&_i(e,t,n[t]);return e}function ou(e){let t=e?.target??`draft-2020-12`;return t===`draft-4`&&(t=`draft-04`),t===`draft-7`&&(t=`draft-07`),{processors:e.processors??{},metadataRegistry:e?.metadata??tl,target:t,unrepresentable:e?.unrepresentable??`throw`,override:e?.override??(()=>{}),io:e?.io??`output`,counter:0,seen:new Map,sharedDefsExtractedFor:void 0,sharedEmitDoneFor:void 0,cycles:e?.cycles??`ref`,reused:e?.reused??`inline`,intersections:[],deferred:[],external:e?.external??void 0}}function su(e,t,n,r,i){let a=typeof t.unrepresentable==`function`?t.unrepresentable({zodSchema:e,path:r.path,message:i}):t.unrepresentable;if(a===`any`)return!1;if(a===void 0||a===`throw`)throw Error(i);return Object.assign(n,a),!0}function cu(e,t,n={path:[],schemaPath:[]}){var r;let i=e._zod.def,a=t.seen.get(e);if(a)return a.count++,n.schemaPath.includes(e)&&(a.cycle=n.path),a.schema;let o={schema:{},count:1,cycle:void 0,path:n.path};t.seen.set(e,o),t.sharedDefsExtractedFor=void 0,t.sharedEmitDoneFor=void 0;let s=e._zod.toJSONSchema?.();if(s)o.schema=s;else{let r={...n,schemaPath:[...n.schemaPath,e],path:n.path};if(e._zod.processJSONSchema)e._zod.processJSONSchema(t,o.schema,r);else{let n=o.schema,a=t.processors[i.type];if(!a)throw Error(`[toJSONSchema]: Non-representable type encountered: ${i.type}`);a(e,t,n,r)}let a=e._zod.parent;a&&(o.ref||=a,cu(a,t,r),t.seen.get(a).isParent=!0)}let c=t.metadataRegistry.get(e);return c&&au(o.schema,c),t.io===`input`&&vu(e)&&(delete o.schema.examples,delete o.schema.default),t.io===`input`&&`_prefault`in o.schema&&((r=o.schema).default??(r.default=o.schema._prefault)),delete o.schema._prefault,t.seen.get(e).schema}function lu(e){return e.replace(/~/g,`~0`).replace(/\//g,`~1`)}function uu(e,t){let n=e.seen.get(t);if(!n)throw Error(`Unprocessed schema. This is a bug in Zod.`);if(e.external&&e.sharedDefsExtractedFor===e.external)return;let r=new Map;for(let t of e.seen.entries()){let n=e.metadataRegistry.get(t[0])?.id;if(n){let e=r.get(n);if(e&&e!==t[0])throw Error(`Duplicate schema id "${n}" detected during JSON Schema conversion. Two different schemas cannot share the same id when converted together.`);r.set(n,t[0])}}let i=t=>{let r=e.target===`draft-2020-12`?`$defs`:`definitions`;if(e.external){let n=e.external.registry.get(t[0])?.id,i=e.external.uri??(e=>e);if(n)return{ref:i(n)};let a=t[1].defId??t[1].schema.id??`schema${e.counter++}`;return t[1].defId=a,{defId:a,ref:`${i(`__shared`)}#/${r}/${lu(a)}`}}let i=`#/${r}/`;if(t[1]===n&&!t[1].schema.id)return{ref:`#`};let a=t[1].schema.id??`__schema${e.counter++}`;return{defId:a,ref:i+lu(a)}},a=e=>{if(e[1].schema.$ref)return;let t=e[1],{ref:n,defId:r}=i(e);t.def={...t.schema},r&&(t.defId=r);let a=t.schema;for(let e in a)delete a[e];a.$ref=n};if(e.cycles===`throw`)for(let t of e.seen.entries()){let e=t[1];if(e.cycle)throw Error(`Cycle detected: #/${e.cycle?.join(`/`)}/<root>
|
|
54
|
+
|
|
55
|
+
Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.`)}for(let n of e.seen.entries()){let r=n[1];if(t===n[0]){a(n);continue}if(e.external){let r=e.external.registry.get(n[0])?.id;if(t!==n[0]&&r){a(n);continue}}if(e.metadataRegistry.get(n[0])?.id){a(n);continue}if(r.cycle){a(n);continue}r.count>1&&e.reused===`ref`&&a(n)}e.external&&(e.sharedDefsExtractedFor=e.external)}function du(e){let t=e.anyOf;if(!Array.isArray(t)||t.length===0||e.type!==void 0)return;let n=[];for(let e of t){if(!e||typeof e!=`object`)return;du(e);let t=Object.keys(e);if(t.length!==1||t[0]!==`type`)return;let r=e.type;for(let e of Array.isArray(r)?r:[r]){if(typeof e!=`string`)return;n.includes(e)||n.push(e)}}delete e.anyOf,e.type=n.length===1?n[0]:n}var fu=new Set([`type`,`properties`,`required`,`additionalProperties`]),pu=[`oneOf`,`anyOf`];function mu(e){let t=e.additionalProperties;return t===void 0||t===!1||typeof t!=`object`||!t?null:Object.keys(t).length?t:null}function hu(e){let t=[];for(let n of e){if(typeof n!=`object`||n.type!==`object`)return null;for(let e in n)if(!fu.has(e))return null;t.push(n)}let n={},r=new Set;for(let e of t){for(let r in e.properties){if(Object.prototype.hasOwnProperty.call(n,r))continue;let e=[];for(let n of t){let t=n.properties?.[r]??mu(n);t!=null&&(e.some(e=>JSON.stringify(e)===JSON.stringify(t))||e.push(t))}_i(n,r,e.length===1?e[0]:hu(e)??{allOf:e})}for(let t of e.required??[])r.add(t)}let i={type:`object`,properties:n};if(r.size&&(i.required=[...r]),t.every(e=>e.additionalProperties===!1))i.additionalProperties=!1;else{let e=[];for(let n of t){let t=mu(n);t&&!e.some(e=>JSON.stringify(e)===JSON.stringify(t))&&e.push(t)}e.length===1?i.additionalProperties=e[0]:e.length>1&&(i.additionalProperties={allOf:e})}return i}function gu(e){let t=e.allOf;if(!Array.isArray(t)||t.length<2)return;for(let t of fu)if(t in e)return;let n=t.filter(e=>pu.some(t=>Array.isArray(e[t]))),r=null;if(!n.length)r=hu(t);else{let e=n[0],i=pu.find(t=>Array.isArray(e[t]));if(Object.keys(e).length!==1)return;let a=t.filter(t=>t!==e),o=e[i].map(e=>hu([...a,e]));if(o.some(e=>!e))return;r={[i]:o}}r&&(delete e.allOf,au(e,r))}function _u(e,t){let n=e.seen.get(t);if(!n)throw Error(`Unprocessed schema. This is a bug in Zod.`);let r=t=>{let n=e.seen.get(t);if(n.ref===null)return;let i=n.def??n.schema,a={...i},o=n.ref;if(n.ref=null,o){r(o);let n=e.seen.get(o),s=n.schema;if(s.$ref&&(e.target===`draft-07`||e.target===`draft-04`||e.target===`openapi-3.0`)?(i.allOf=i.allOf??[],i.allOf.push(s)):au(i,s),au(i,a),t._zod.parent===o)for(let e in i)e!==`$ref`&&e!==`allOf`&&(e in a||delete i[e]);if(s.$ref&&n.def)for(let e in i)e!==`$ref`&&e!==`allOf`&&e in n.def&&JSON.stringify(i[e])===JSON.stringify(n.def[e])&&delete i[e]}let s=t._zod.parent;if(s&&s!==o){r(s);let t=e.seen.get(s);if(t?.schema.$ref&&(i.$ref=t.schema.$ref,t.def))for(let e in i)e!==`$ref`&&e!==`allOf`&&e in t.def&&JSON.stringify(i[e])===JSON.stringify(t.def[e])&&delete i[e]}e.override({zodSchema:t,jsonSchema:i,path:n.path??[]})};if(!e.external||e.sharedEmitDoneFor!==e.external){for(let t of[...e.seen.entries()].reverse())r(t[0]);if(e.target!==`openapi-3.0`)for(let t of e.seen.entries())du(t[1].def??t[1].schema);for(let t of e.deferred)t();if(e.intersections.length){let t=new Map;for(let n of e.seen.values())for(let e of[n.schema,n.def]){let n=e?.allOf;if(!Array.isArray(n))continue;let r=t.get(n);r?r.push(e):t.set(n,[e])}for(let n of e.intersections)for(let e of t.get(n)??[])gu(e)}}let i={};if(e.target===`draft-2020-12`?i.$schema=`https://json-schema.org/draft/2020-12/schema`:e.target===`draft-07`?i.$schema=`http://json-schema.org/draft-07/schema#`:e.target===`draft-04`?i.$schema=`http://json-schema.org/draft-04/schema#`:e.target,e.external?.uri){let n=e.external.registry.get(t)?.id;if(!n)throw Error("Schema is missing an `id` property");i.$id=e.external.uri(n)}au(i,n.defId?n.schema:n.def??n.schema);let a=e.metadataRegistry.get(t)?.id;a!==void 0&&i.id===a&&delete i.id;let o=e.external?.defs??{};if(!e.external||e.sharedEmitDoneFor!==e.external)for(let t of e.seen.entries()){let e=t[1];e.def&&e.defId&&(e.def.id===e.defId&&delete e.def.id,_i(o,e.defId,e.def))}e.external&&(e.sharedEmitDoneFor=e.external),e.external||Object.keys(o).length>0&&(e.target===`draft-2020-12`?i.$defs=o:i.definitions=o);try{let n=JSON.parse(JSON.stringify(i));return Object.defineProperty(n,"~standard",{value:{...t[`~standard`],jsonSchema:{input:bu(t,`input`,e.processors),output:bu(t,`output`,e.processors)}},enumerable:!1,writable:!1}),n}catch{throw Error(`Error converting schema to JSON.`)}}function vu(e,t){let n=t??{seen:new Set};if(n.seen.has(e))return!1;n.seen.add(e);let r=e._zod.def;if(r.type===`transform`)return!0;if(r.type===`array`)return vu(r.element,n);if(r.type===`set`)return vu(r.valueType,n);if(r.type===`lazy`)return vu(r.getter(),n);if(r.type===`promise`||r.type===`optional`||r.type===`nonoptional`||r.type===`nullable`||r.type===`readonly`||r.type==="default"||r.type===`prefault`||r.type===`catch`)return vu(r.innerType,n);if(r.type===`intersection`)return vu(r.left,n)||vu(r.right,n);if(r.type===`record`||r.type===`map`)return vu(r.keyType,n)||vu(r.valueType,n);if(r.type===`pipe`)return e._zod.traits.has(`$ZodCodec`)?!0:vu(r.in,n)||vu(r.out,n);if(r.type===`object`){for(let e in r.shape)if(vu(r.shape[e],n))return!0;return!1}if(r.type===`union`){for(let e of r.options)if(vu(e,n))return!0;return!1}if(r.type===`tuple`){for(let e of r.items)if(vu(e,n))return!0;return!!(r.rest&&vu(r.rest,n))}return!1}var yu=(e,t={})=>n=>{let r=ou({...n,processors:t});return cu(e,r),uu(r,e),_u(r,e)},bu=(e,t,n={})=>r=>{let{libraryOptions:i,target:a}=r??{},o=ou({...i??{},target:a,io:t,processors:n});return cu(e,o),uu(o,e),_u(o,e)},xu=(e,t,n)=>{(e[t]===void 0||n>e[t])&&(e[t]=n)},Su=(e,t,n)=>{(e[t]===void 0||n<e[t])&&(e[t]=n)},Cu=(e,t)=>{xu(e,`minimum`,t),Su(e,`maximum`,t)},wu=(e,t)=>{e.multipleOf??=[],e.multipleOf.includes(t)||e.multipleOf.push(t)},Tu=(e,t)=>{e.patterns??=new Set,e.patterns.add(t)},Eu=(e,t)=>{e.mime=e.mime?e.mime.filter(e=>t.includes(e)):[...t]},Du=(e,t)=>{e.format=t,t.includes(`int`)&&(e.isInt=!0)},Ou=(e,t)=>xu(e,`minimum`,t.minimum),ku=(e,t)=>Su(e,`maximum`,t.maximum),Au=e=>(t,n)=>{Du(t,n.format);let[r,i]=e[n.format];xu(t,`minimum`,r),Su(t,`maximum`,i)},ju={greater_than:(e,t)=>xu(e,t.inclusive?`minimum`:`exclusiveMinimum`,t.value),less_than:(e,t)=>Su(e,t.inclusive?`maximum`:`exclusiveMaximum`,t.value),multiple_of:(e,t)=>wu(e,t.value),number_format:Au(Li),bigint_format:Au(Ri),min_length:Ou,max_length:ku,length_equals:(e,t)=>Cu(e,t.length),min_size:Ou,max_size:ku,size_equals:(e,t)=>Cu(e,t.size),string_format:(e,t)=>{Du(e,t.format),t.pattern&&Tu(e,t.pattern),(t.format===`base64`||t.format===`base64url`)&&(e.contentEncoding=t.format),(t.local||t.precision===-1)&&(e.laxFormat=!0)},mime_type:(e,t)=>Eu(e,t.mime)};function Mu(e){let t={},n=e._zod.def,r=e._zod.traits.has(`$ZodCheck`)?[e,...n.checks??[]]:n.checks??[];for(let e of r)ju[e._zod.def.check]?.(t,e._zod.def);let i=e._zod.bag;i.minimum!==void 0&&xu(t,`minimum`,i.minimum),i.exclusiveMinimum!==void 0&&xu(t,`exclusiveMinimum`,i.exclusiveMinimum),i.maximum!==void 0&&Su(t,`maximum`,i.maximum),i.exclusiveMaximum!==void 0&&Su(t,`exclusiveMaximum`,i.exclusiveMaximum),i.multipleOf!==void 0&&wu(t,i.multipleOf),i.format!==void 0&&(t.format??=i.format,i.format.includes(`int`)&&(t.isInt=!0)),i.mime&&Eu(t,i.mime);for(let e of i.patterns??[])Tu(t,e);return t}var Nu={guid:`uuid`,url:`uri`,datetime:`date-time`,json_string:`json-string`,regex:``},Pu=new Map([[Ls,yo],[zs,bo]]),Fu=e=>Pu.get(e)??e,Iu=(e,t,n,r)=>{let i=n;i.type=`string`;let{minimum:a,maximum:o,format:s,patterns:c,contentEncoding:l,laxFormat:u}=Mu(e);if(typeof a==`number`&&(i.minLength=a),typeof o==`number`&&(i.maxLength=o),s&&(i.format=Nu[s]??s,i.format===``&&delete i.format,(s===`time`||u)&&delete i.format),l&&(i.contentEncoding=l),c&&c.size>0){let e=[...c].map(Fu);e.length===1?i.pattern=e[0].source:e.length>1&&(i.allOf=[...e.map(e=>({...t.target===`draft-07`||t.target===`draft-04`||t.target===`openapi-3.0`?{type:`string`}:{},pattern:e.source}))])}},Lu=(e,t,n,r)=>{let i=n,{minimum:a,maximum:o,multipleOf:s,exclusiveMaximum:c,exclusiveMinimum:l,isInt:u}=Mu(e);i.type=u?`integer`:`number`;let d=typeof l==`number`&&l>=(a??-1/0),f=typeof c==`number`&&c<=(o??1/0),p=t.target===`draft-04`||t.target===`openapi-3.0`;if(d?p?(i.minimum=l,i.exclusiveMinimum=!0):i.exclusiveMinimum=l:typeof a==`number`&&(i.minimum=a),f?p?(i.maximum=c,i.exclusiveMaximum=!0):i.exclusiveMaximum=c:typeof o==`number`&&(i.maximum=o),s){let n=new Set;for(let a of s)Number.isFinite(a)&&a!==0?n.add(Math.abs(a)):su(e,t,i,r,`A multipleOf divisor of ${a} cannot be represented in JSON Schema`);let[a,...o]=n;a!==void 0&&(i.multipleOf=a),o.length&&(i.allOf=[...i.allOf??[],...o.map(e=>({multipleOf:e}))])}},Ru=(e,t,n,r)=>{n.type=`boolean`},zu=(e,t,n,r)=>{n.not={}},Bu=(e,t,n,r)=>{let i=e._zod.def,a=li(i.entries);if(a.length===0){n.not={};return}a.every(e=>typeof e==`number`)&&(n.type=`number`),a.every(e=>typeof e==`string`)&&(n.type=`string`),n.enum=a},Vu=(e,t,n,r)=>{let i=e._zod.def;if(i.values.length===0){n.not={};return}let a=[];for(let o of i.values)if(o===void 0){if(su(e,t,n,r,"Literal `undefined` cannot be represented in JSON Schema"))return}else if(typeof o==`bigint`){if(su(e,t,n,r,`BigInt literals cannot be represented in JSON Schema`))return;a.push(Number(o))}else a.push(o);if(a.length!==0){if(a.length===1){let e=a[0];n.type=e===null?`null`:typeof e,t.target===`draft-04`||t.target===`openapi-3.0`?n.enum=[e]:n.const=e}else a.every(e=>typeof e==`number`)&&(n.type=`number`),a.every(e=>typeof e==`string`)&&(n.type=`string`),a.every(e=>typeof e==`boolean`)&&(n.type=`boolean`),a.every(e=>e===null)&&(n.type=`null`),n.enum=a}},Hu=(e,t,n,r)=>{su(e,t,n,r,`Custom types cannot be represented in JSON Schema`)},Uu=(e,t,n,r)=>{su(e,t,n,r,`Transforms cannot be represented in JSON Schema`)},Wu=(e,t,n,r)=>{let i=n,a=e._zod.def,{minimum:o,maximum:s}=Mu(e);typeof o==`number`&&(i.minItems=o),typeof s==`number`&&(i.maxItems=s),i.type=`array`,i.items=cu(a.element,t,{...r,path:[...r.path,`items`]})};function Gu(e){let t=e._zod.def;return t.type===`pipe`&&t.in._zod.traits.has(`$ZodTransform`)?Gu(t.out):t.type===`catch`?Gu(t.innerType):e._zod.optin}var Ku=(e,t,n,r)=>{let i=n,a=e._zod.def,o=a.shape;if(Object.getOwnPropertySymbols(o).length&&su(e,t,i,r,`Symbol keys cannot be represented in JSON Schema`))return;i.type=`object`,i.properties={};for(let e in o)_i(i.properties,e,cu(o[e],t,{...r,path:[...r.path,`properties`,e]}));let s=[];for(let e of Object.keys(o)){let n=a.shape[e];(t.io===`input`?Gu(n)===void 0:n._zod.optout===void 0)&&s.push(e)}s.length>0&&(i.required=s),a.catchall?._zod.def.type===`never`?i.additionalProperties=!1:a.catchall?a.catchall&&(i.additionalProperties=cu(a.catchall,t,{...r,path:[...r.path,`additionalProperties`]})):t.io===`output`&&(i.additionalProperties=!1)},qu=(e,t,n,r)=>{let i=e._zod.def,a=i.inclusive===!1,o=i.options.map((e,n)=>cu(e,t,{...r,path:[...r.path,a?`oneOf`:`anyOf`,n]}));a?n.oneOf=o:n.anyOf=o},Ju=(e,t,n,r)=>{let i=e._zod.def,a=cu(i.left,t,{...r,path:[...r.path,`allOf`,0]}),o=cu(i.right,t,{...r,path:[...r.path,`allOf`,1]}),s=e=>`allOf`in e&&Object.keys(e).length===1,c=[...s(a)?a.allOf:[a],...s(o)?o.allOf:[o]];n.allOf=c,t.intersections.push(c)};function Yu(e,t,n){if(t.$ref){if(n.has(t))return t;n.add(t);let r=e.get(t)?.def;if(!r)return t;let i=Yu(e,r,n);return i===r?t:i}for(let r of[`anyOf`,`oneOf`]){let i=t[r];if(!Array.isArray(i))continue;let a=i.map(t=>Yu(e,t,n));a.some((e,t)=>e!==i[t])&&(t={...t,[r]:a})}let r=Array.isArray(t.type)?t.type:[t.type],i=!r.includes(`string`)&&r.some(e=>e===`number`||e===`integer`),a=t.enum??(t.const===void 0?void 0:[t.const]);if(!i&&!a?.some(e=>typeof e==`number`))return t;let{minimum:o,maximum:s,exclusiveMinimum:c,exclusiveMaximum:l,multipleOf:u,format:d,id:f,...p}=t;return p.enum?p.enum=p.enum.map(e=>typeof e==`number`?String(e):e):typeof p.const==`number`&&(p.const=String(p.const)),i?(p.type=`string`,a||(p.pattern=(r.includes(`number`)?jo:Ao).source),p):p}var Xu=new WeakMap;function Zu(e){let t=new Map;for(let n of e.seen.values())n.def&&!t.has(n.schema)&&t.set(n.schema,n);let n=new Map;for(let r of Xu.get(e)??[]){let i=e.seen.get(r),a=(i?.def??i?.schema)?.propertyNames;if(!a||a===!0||n.has(a))continue;let o=Yu(t,a,new Set);o!==a&&n.set(a,o)}if(n.size)for(let t of e.seen.values())for(let e of[t.schema,t.def]){let t=e&&n.get(e.propertyNames);t&&(e.propertyNames=t)}}var Qu=(e,t,n,r)=>{let i=n,a=e._zod.def;i.type=`object`;let o=a.keyType,s=Mu(o).patterns;if(a.mode===`loose`&&s&&s.size>0){let e=cu(a.valueType,t,{...r,path:[...r.path,`patternProperties`,`*`]});i.patternProperties={};for(let t of s)_i(i.patternProperties,Fu(t).source,e)}else{if(t.target===`draft-07`||t.target===`draft-2020-12`){i.propertyNames=cu(a.keyType,t,{...r,path:[...r.path,`propertyNames`]});let n=Xu.get(t);n||(n=[],Xu.set(t,n),t.deferred.push(()=>Zu(t))),n.push(e)}i.additionalProperties=cu(a.valueType,t,{...r,path:[...r.path,`additionalProperties`]})}let c=o._zod.values,l=t.io===`input`&&Gu(a.valueType)!==void 0;if(c&&!a.partial&&!l){let e=[...c].filter(e=>typeof e==`string`||typeof e==`number`);e.length>0&&(i.required=e.map(String))}},$u=(e,t,n,r)=>{let i=e._zod.def,a=cu(i.innerType,t,r),o=t.seen.get(e);t.target===`openapi-3.0`?(o.ref=i.innerType,n.nullable=!0):n.anyOf=[a,{type:`null`}]},ed=(e,t,n,r)=>{let i=e._zod.def;cu(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType},td=Symbol();function nd(e,t,n,r,i){let a=!1,o=JSON.stringify(e,(e,t)=>typeof t==`bigint`?(a=!0,null):t);return a?(su(t,n,r,i,`BigInt defaults cannot be represented in JSON Schema`),td):JSON.parse(o)}var rd=(e,t,n,r)=>{let i=e._zod.def;cu(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType;let o=nd(i.defaultValue,e,t,n,r);o!==td&&(n.default=o)},id=(e,t,n,r)=>{let i=e._zod.def;cu(i.innerType,t,r);let a=t.seen.get(e);if(a.ref=i.innerType,t.io!==`input`)return;let o=nd(i.defaultValue,e,t,n,r);o!==td&&(n._prefault=o)},ad=(e,t,n,r)=>{let i=e._zod.def;cu(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType;let o;try{o=i.catchValue(void 0)}catch{su(e,t,n,r,`Dynamic catch values are not supported in JSON Schema`);return}n.default=o},od=(e,t,n,r)=>{let i=e._zod.def,a=i.in._zod.traits.has(`$ZodTransform`),o=t.io===`input`?a?i.out:i.in:i.out;cu(o,t,r);let s=t.seen.get(e);s.ref=o},sd=(e,t,n,r)=>{let i=e._zod.def;cu(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType,n.readOnly=!0},cd=(e,t,n,r)=>{let i=e._zod.def;cu(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType},ld=new WeakSet([Object.prototype,Error.prototype]);function ud(e,t,n){Object.defineProperty(e,t,{configurable:!0,enumerable:!1,get(){let e=n(this);return Object.defineProperty(this,t,{value:e,configurable:!0,writable:!0}),e},set(e){Object.defineProperty(this,t,{value:e,configurable:!0,writable:!0})}})}var dd=J(`ZodError`,(e,t)=>{Ma.init(e,t),e.name=`ZodError`;let n=Object.getPrototypeOf(e);ld.has(n)||(ld.add(n),ud(n,`format`,e=>t=>Fa(e,t)),ud(n,`flatten`,e=>t=>Pa(e,t)),ud(n,`addIssue`,e=>t=>{e.issues.push(t),e.message=JSON.stringify(e.issues,di,2)}),ud(n,`addIssues`,e=>t=>{e.issues.push(...t),e.message=JSON.stringify(e.issues,di,2)}),Object.defineProperty(n,"isEmpty",{configurable:!0,enumerable:!1,get(){return this.issues.length===0}}))},void 0,{Parent:Error}),fd=La(dd),pd=Ra(dd),md=za(dd),hd=Va(dd),gd=qa(dd),_d=Ja(dd),vd=Ya(dd),yd=Xa(dd),bd=Za(dd),xd=Qa(dd),Sd=$a(dd),Cd=eo(dd);function wd(){wa.localeError||Ta(Zc())}function Td(){wa.memoizer||Ta({memoizer:Jc()})}var Ed=J(`ZodType`,(e,t)=>(wd(),ts.init(e,t),e.def=t,e.type=t.type,e),{check(...e){let t=this.def;return this.clone(wi(t,{checks:[...t.checks??[],...e.map(e=>typeof e==`function`?{_zod:{check:e,def:{check:`custom`},onattach:[]}}:e)]}),{parent:!0})},with(...e){return this.check(...e)},clone(e,t){return Pi(this,e,t)},brand(){return this},register(e,t){return e.add(this,t),this},refine(e,t){return this.check(Jf(e,t))},superRefine(e,t){return this.check(Yf(e,t))},overwrite(e){return this.check(Yl(e))},optional(){return kf(this)},exactOptional(){return jf(this)},nullable(){return Nf(this)},nullish(){return kf(Nf(this))},nonoptional(e){return zf(this,e)},array(){return uf(this)},or(e){return hf([this,e])},and(e){return yf(this,e)},transform(e){return Uf(this,Df(e))},default(e){return Ff(this,e)},prefault(e){return Lf(this,e)},catch(e){return Vf(this,e)},pipe(e){return Uf(this,e)},readonly(){return Kf(this)},describe(e){let t=this.clone();return tl.add(t,{description:e}),t},meta(...e){if(e.length===0)return tl.get(this);let t=this.clone();return tl.add(t,e[0]),t},isOptional(){return this.safeParse(void 0).success},isNullable(){return this.safeParse(null).success},apply(e,...t){return t.length===0?e(this):e(this,...t)},get"~standard"(){return sa(this,`~standard`,{...is(this),jsonSchema:{input:bu(this,`input`),output:bu(this,`output`)}})},set"~standard"(e){oa(this,`~standard`,e)},parse:function e(t,n){return fd(this,t,n,{callee:e})},parseAsync:async function e(t,n){return await pd(this,t,n,{callee:e})},safeParse(e,t){return md(this,e,t)},async safeParseAsync(e,t){return hd(this,e,t)},get spa(){return this?.safeParseAsync},set spa(e){oa(this,`spa`,e)},validate(e,t){return Wa(this,e,t)},validateAsync(e,t){return Ka(this,e,t)},encode:function e(t,n){return gd(this,t,n,{callee:e})},decode:function e(t,n){return _d(this,t,n,{callee:e})},encodeAsync:async function e(t,n){return await vd(this,t,n,{callee:e})},decodeAsync:async function e(t,n){return await yd(this,t,n,{callee:e})},safeEncode(e,t){return bd(this,e,t)},safeDecode(e,t){return xd(this,e,t)},async safeEncodeAsync(e,t){return Sd(this,e,t)},async safeDecodeAsync(e,t){return Cd(this,e,t)},toJSONSchema(e){return yu(this,{})(e)},get description(){return tl.get(this)?.description},get _def(){return this._zod.def}}),Dd=J(`_ZodString`,(e,t)=>{as.init(e,t),Ed.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Iu(e,t,n,r)},ca({format:e=>Mu(e).format??null,minLength:e=>Mu(e).minimum??null,maxLength:e=>Mu(e).maximum??null},{regex(...e){return this.check(Ul(...e))},includes(...e){return this.check(Kl(...e))},startsWith(...e){return this.check(ql(...e))},endsWith(...e){return this.check(Jl(...e))},min(...e){return this.check(Vl(...e))},max(...e){return this.check(Bl(...e))},length(...e){return this.check(Hl(...e))},nonempty(...e){return this.check(Vl(1,...e))},lowercase(e){return this.check(Wl(e))},uppercase(e){return this.check(Gl(e))},trim(){return this.check(Zl())},normalize(...e){return this.check(Xl(...e))},toLowerCase(){return this.check(Ql())},toUpperCase(){return this.check($l())},slugify(){return this.check(eu())}})),Od=J(`ZodString`,(e,t)=>{as.init(e,t),Dd.init(e,t)},{email(e){return this.check(il(Pd,e))},url(e){return this.check(ul(Ld,e))},jwt(e){return this.check(Tl(Qd,e))},emoji(e){return this.check(dl(Rd,e))},guid(e){return this.check(al(Fd,e))},uuid(e){return this.check(ol(Id,e))},uuidv4(e){return this.check(sl(Id,e))},uuidv6(e){return this.check(cl(Id,e))},uuidv7(e){return this.check(ll(Id,e))},nanoid(e){return this.check(fl(zd,e))},cuid(e){return this.check(pl(Bd,e))},cuid2(e){return this.check(ml(Vd,e))},ulid(e){return this.check(hl(Hd,e))},base64(e){return this.check(Sl(Yd,e))},base64url(e){return this.check(Cl(Xd,e))},xid(e){return this.check(gl(Ud,e))},ksuid(e){return this.check(_l(Wd,e))},ipv4(e){return this.check(vl(Gd,e))},ipv6(e){return this.check(yl(Kd,e))},cidrv4(e){return this.check(bl(qd,e))},cidrv6(e){return this.check(xl(Jd,e))},e164(e){return this.check(wl(Zd,e))},datetime(e){return this.check(El(Ad,e))},date(e){return this.check(Dl(jd,e))},time(e){return this.check(Ol(Md,e))},duration(e){return this.check(kl(Nd,e))}});function Y(e){return rl(Od,e)}var kd=J(`ZodStringFormat`,(e,t)=>{os.init(e,t),Dd.init(e,t)}),Ad=J(`ZodISODateTime`,(e,t)=>{Ts.init(e,t),kd.init(e,t)}),jd=J(`ZodISODate`,(e,t)=>{Es.init(e,t),kd.init(e,t)}),Md=J(`ZodISOTime`,(e,t)=>{Ds.init(e,t),kd.init(e,t)}),Nd=J(`ZodISODuration`,(e,t)=>{Os.init(e,t),kd.init(e,t)}),Pd=J(`ZodEmail`,(e,t)=>{ls.init(e,t),kd.init(e,t)}),Fd=J(`ZodGUID`,(e,t)=>{ss.init(e,t),kd.init(e,t)}),Id=J(`ZodUUID`,(e,t)=>{cs.init(e,t),kd.init(e,t)}),Ld=J(`ZodURL`,(e,t)=>{_s.init(e,t),kd.init(e,t)}),Rd=J(`ZodEmoji`,(e,t)=>{vs.init(e,t),kd.init(e,t)}),zd=J(`ZodNanoID`,(e,t)=>{ys.init(e,t),kd.init(e,t)}),Bd=J(`ZodCUID`,(e,t)=>{bs.init(e,t),kd.init(e,t)}),Vd=J(`ZodCUID2`,(e,t)=>{xs.init(e,t),kd.init(e,t)}),Hd=J(`ZodULID`,(e,t)=>{Ss.init(e,t),kd.init(e,t)}),Ud=J(`ZodXID`,(e,t)=>{Cs.init(e,t),kd.init(e,t)}),Wd=J(`ZodKSUID`,(e,t)=>{ws.init(e,t),kd.init(e,t)}),Gd=J(`ZodIPv4`,(e,t)=>{ks.init(e,t),kd.init(e,t)}),Kd=J(`ZodIPv6`,(e,t)=>{Ms.init(e,t),kd.init(e,t)}),qd=J(`ZodCIDRv4`,(e,t)=>{Ns.init(e,t),kd.init(e,t)}),Jd=J(`ZodCIDRv6`,(e,t)=>{Fs.init(e,t),kd.init(e,t)}),Yd=J(`ZodBase64`,(e,t)=>{Rs.init(e,t),kd.init(e,t)}),Xd=J(`ZodBase64URL`,(e,t)=>{Vs.init(e,t),kd.init(e,t)}),Zd=J(`ZodE164`,(e,t)=>{Hs.init(e,t),kd.init(e,t)}),Qd=J(`ZodJWT`,(e,t)=>{Ws.init(e,t),kd.init(e,t)}),$d=J(`ZodNumber`,(e,t)=>{Gs.init(e,t),Ed.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Lu(e,t,n,r),e.isFinite=!0},ca({minValue:e=>{let{minimum:t,exclusiveMinimum:n}=Mu(e);return Math.max(t??-1/0,n??-1/0)},maxValue:e=>{let{maximum:t,exclusiveMaximum:n}=Mu(e);return Math.min(t??1/0,n??1/0)},isInt:e=>{let{isInt:t,multipleOf:n}=Mu(e);return!!t||!!n?.some(Number.isSafeInteger)},format:e=>Mu(e).format??null},{gt(e,t){return this.check(Ll(e,t))},gte(e,t){return this.check(Rl(e,t))},min(e,t){return this.check(Rl(e,t))},lt(e,t){return this.check(Fl(e,t))},lte(e,t){return this.check(Il(e,t))},max(e,t){return this.check(Il(e,t))},int(e){return this.check(tf(e))},safe(e){return this.check(tf(e))},positive(e){return this.check(Ll(0,e))},nonnegative(e){return this.check(Rl(0,e))},negative(e){return this.check(Fl(0,e))},nonpositive(e){return this.check(Il(0,e))},multipleOf(e,t){return this.check(zl(e,t))},step(e,t){return this.check(zl(e,t))},finite(){return this}}));function X(e){return Al($d,e)}var ef=J(`ZodNumberFormat`,(e,t)=>{Ks.init(e,t),$d.init(e,t)});function tf(e){return jl(ef,e)}var nf=J(`ZodBoolean`,(e,t)=>{qs.init(e,t),Ed.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Ru(e,t,n,r)});function rf(e){return Ml(nf,e)}var af=J(`ZodUnknown`,(e,t)=>{Js.init(e,t),Ed.init(e,t),e._zod.processJSONSchema=(e,t,n)=>void 0});function of(){return Nl(af)}var sf=J(`ZodNever`,(e,t)=>{Ys.init(e,t),Ed.init(e,t),e._zod.processJSONSchema=(t,n,r)=>zu(e,t,n,r)});function cf(e){return Pl(sf,e)}var lf=J(`ZodArray`,(e,t)=>{Td(),Zs.init(e,t),Ed.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Wu(e,t,n,r),e.element=t.element},{min(e,t){return this.check(Vl(e,t))},nonempty(e){return this.check(Vl(1,e))},max(e,t){return this.check(Bl(e,t))},length(e,t){return this.check(Hl(e,t))},unwrap(){return this.element}});function uf(e,t){return tu(lf,e,t)}var df=J(`ZodObject`,(e,t)=>{Td(),rc.init(e,t),Ed.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Ku(e,t,n,r),ha(e,`shape`,e=>e._zod.def.shape,!1)},{keyof(){return Cf(Object.keys(this._zod.def.shape))},catchall(e){return this.clone(wi(this._zod.def,{catchall:e}))},passthrough(){return this.clone(wi(this._zod.def,{catchall:of()}))},loose(){return this.clone(wi(this._zod.def,{catchall:of()}))},strict(){return this.clone(wi(this._zod.def,{catchall:cf()}))},strip(){return this.clone(wi(this._zod.def,{catchall:void 0}))},extend(e){return Hi(this,e)},safeExtend(e){return Wi(this,e)},merge(e){return Gi(this,e)},pick(e){return zi(this,e)},omit(e){return Vi(this,e)},partial(...e){return Ki(Of,this,e[0])},exactPartial(...e){return Ki(Af,this,e[0],`exactPartial`)},required(...e){return qi(Rf,this,e[0])}});function ff(e,t){return new df({type:`object`,shape:e??{},...q(t)})}function pf(e,t){return new df({type:`object`,shape:e,catchall:of(),...q(t)})}var mf=J(`ZodUnion`,(e,t)=>{ac.init(e,t),Ed.init(e,t),e._zod.processJSONSchema=(t,n,r)=>qu(e,t,n,r),e.options=t.options});function hf(e,t){return new mf({type:`union`,options:e,...q(t)})}var gf=J(`ZodDiscriminatedUnion`,(e,t)=>{mf.init(e,t),sc.init(e,t)});function _f(e,t,n){return new gf({type:`union`,options:t,discriminator:e,...q(n)})}var vf=J(`ZodIntersection`,(e,t)=>{cc.init(e,t),Ed.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Ju(e,t,n,r)});function yf(e,t){return new vf({type:`intersection`,left:e,right:t})}var bf=J(`ZodRecord`,(e,t)=>{Td(),dc.init(e,t),Ed.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Qu(e,t,n,r),e.keyType=t.keyType,e.valueType=t.valueType});function xf(e,t,n){return!t||!t._zod?new bf({type:`record`,keyType:Y(),valueType:e,...q(t)}):new bf({type:`record`,keyType:e,valueType:t,...q(n)})}var Sf=J(`ZodEnum`,(e,t)=>{fc.init(e,t),Ed.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Bu(e,t,n,r),e.enum=t.entries,e.options=[...e._zod.values];let n=new Set(Object.keys(t.entries));e.extract=(e,r)=>{let i={};for(let r of e)if(n.has(r))i[r]=t.entries[r];else throw Error(`Key ${r} not found in enum`);return new Sf({...t,checks:[],...q(r),entries:i})},e.exclude=(e,r)=>{let i={...t.entries};for(let t of e)if(n.has(t))delete i[t];else throw Error(`Key ${t} not found in enum`);return new Sf({...t,checks:[],...q(r),entries:i})}});function Cf(e,t){return new Sf({type:`enum`,entries:Array.isArray(e)?Object.fromEntries(e.map(e=>[e,e])):e,...q(t)})}var wf=J(`ZodLiteral`,(e,t)=>{pc.init(e,t),Ed.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Vu(e,t,n,r),e.values=new Set(t.values),Object.defineProperty(e,"value",{get(){if(t.values.length>1)throw Error("This schema contains multiple valid literal values. Use `.values` instead.");return t.values[0]}})});function Tf(e,t){return new wf({type:`literal`,values:Array.isArray(e)?e:[e],...q(t)})}var Ef=J(`ZodTransform`,(e,t)=>{Td(),mc.init(e,t),Ed.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Uu(e,t,n,r),e._zod.parse=(n,r)=>{if(r.direction===`backward`)throw new Ca(e.constructor.name);n.addIssue=r=>{if(typeof r==`string`)n.issues.push(ia(r,n.value,t));else{let t=r;t.fatal&&(t.continue=!1),t.code??=`custom`,`input`in t||(t.input=n.value),t.inst??=e,n.issues.push(ia(t))}};let i=t.transform(n.value,n);return i instanceof Promise?i.then(e=>(n.value=e,n)):(n.value=i,n)}});function Df(e){return new Ef({type:`transform`,transform:e})}var Of=J(`ZodOptional`,(e,t)=>{gc.init(e,t),Ed.init(e,t),e._zod.processJSONSchema=(t,n,r)=>cd(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function kf(e){return new Of({type:`optional`,innerType:e})}var Af=J(`ZodExactOptional`,(e,t)=>{_c.init(e,t),Ed.init(e,t),e._zod.processJSONSchema=(t,n,r)=>cd(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function jf(e){return new Af({type:`optional`,innerType:e})}var Mf=J(`ZodNullable`,(e,t)=>{vc.init(e,t),Ed.init(e,t),e._zod.processJSONSchema=(t,n,r)=>$u(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Nf(e){return new Mf({type:`nullable`,innerType:e})}var Pf=J(`ZodDefault`,(e,t)=>{yc.init(e,t),Ed.init(e,t),e._zod.processJSONSchema=(t,n,r)=>rd(e,t,n,r),e.unwrap=()=>e._zod.def.innerType,e.removeDefault=e.unwrap});function Ff(e,t){return new Pf({type:`default`,innerType:e,get defaultValue(){return typeof t==`function`?t():ji(t)}})}var If=J(`ZodPrefault`,(e,t)=>{xc.init(e,t),Ed.init(e,t),e._zod.processJSONSchema=(t,n,r)=>id(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Lf(e,t){return new If({type:`prefault`,innerType:e,get defaultValue(){return typeof t==`function`?t():ji(t)}})}var Rf=J(`ZodNonOptional`,(e,t)=>{Sc.init(e,t),Ed.init(e,t),e._zod.processJSONSchema=(t,n,r)=>ed(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function zf(e,t){return new Rf({type:`nonoptional`,innerType:e,...q(t)})}var Bf=J(`ZodCatch`,(e,t)=>{Tc.init(e,t),Ed.init(e,t),e._zod.processJSONSchema=(t,n,r)=>ad(e,t,n,r),e.unwrap=()=>e._zod.def.innerType,e.removeCatch=e.unwrap});function Vf(e,t){return new Bf({type:`catch`,innerType:e,catchValue:typeof t==`function`?t:_a(t)})}var Hf=J(`ZodPipe`,(e,t)=>{Ec.init(e,t),Ed.init(e,t),e._zod.processJSONSchema=(t,n,r)=>od(e,t,n,r),e.in=t.in,e.out=t.out});function Uf(e,t){return new Hf({type:`pipe`,in:e,out:t})}var Wf=J(`ZodPreprocess`,(e,t)=>{Hf.init(e,t),Oc.init(e,t)}),Gf=J(`ZodReadonly`,(e,t)=>{kc.init(e,t),Ed.init(e,t),e._zod.processJSONSchema=(t,n,r)=>sd(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Kf(e){return new Gf({type:`readonly`,innerType:e})}var qf=J(`ZodCustom`,(e,t)=>{jc.init(e,t),Ed.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Hu(e,t,n,r)});function Jf(e,t={}){return nu(qf,e,t)}function Yf(e,t){return ru(e,t)}function Xf(e,t){return new Wf({type:`pipe`,in:Df(e),out:t})}var Zf=/[\p{L}\p{N}]/u,Qf=/\s/,$f=/[_\-/]/,ep=/[\s,;:.\-–—(_/]+$/u,tp=/^[\p{M}\u200d\ufe0f\u{1F3FB}-\u{1F3FF}\u{E0020}-\u{E007F}]$/u,np=/^[\u{1F1E6}-\u{1F1FF}]$/u,rp=/[\uD800-\uDFFF]/gu,ip=/[\p{Cc}\p{Zl}\p{Zp}]+/gu,ap=/(?![\u200c\u200d\u{E0000}-\u{E007F}])\p{Cf}/gu,op=/(\u{1F3F4})([\u{E0000}-\u{E007F}]*)|[\u{E0000}-\u{E007F}]+/gu,sp=/^[\p{Cf}\s\u034f\u115f\u1160\u17b4\u17b5\u2800\u3164\uffa0]*$/u;function cp(e){let t=e.replace(rp,`�`).replace(ip,` `).replace(ap,``).replace(op,(e,t,n)=>t?t+n:``).replace(/\s+/g,` `).trim();return sp.test(t)?``:t}function lp(e){let t=[],n=!1,r=0;for(let i of e){let e=t.length-1;e>=0&&(n||tp.test(i)||np.test(i)&&r===1)?(t[e]+=i,r=np.test(i)?r+1:r):(t.push(i),r=+!!np.test(i)),n=i===``}return t}function up(e,t){for(let n=e.length-1;n>0;n--)if(t.test(e[n]))return n;return-1}function dp(e,t){if(e.length<=t)return e;let n=Array.from(e);if(n.length<=t)return e;let r=lp(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&&!tp.test(o))return o+`…`;let s=i.length,c=r[i.length];if(c!==void 0&&!Qf.test(c)){let e=up(i,Qf);e<=0&&(e=up(i,$f)),e>0&&(s=e)}return i.slice(0,s).join(``).replace(ep,``)+`…`}var fp=[`;`,`. `,` — `,` (`],pp=12;function mp(e,t){let n=0,r=0;for(let i of e){if(r++>=t)break;n+=i.length}return n}function hp(e,t){let n=mp(e,Math.max(0,pp-t)),r=e.length;for(let t of fp){let i=e.indexOf(t,n);i>=0&&i<r&&(r=i)}return e.slice(0,r).trim()}function gp(e){let t=e.split(/[\\/]/).pop()??``,n=t.lastIndexOf(`.`);return cp(n>0?t.slice(0,n):t)}var _p=new Map;function vp(e){let t=e.replace(/^0+/,``)||`0`,n=_p.get(t);return n||(_p.size>=2e3&&_p.clear(),n=yp(t),_p.set(t,n)),n}function yp(e){return RegExp(`^v0*${e}(?![\\p{L}\\p{N}])(?:(?:\\s*[:,\\-–—]|\\.(?=\\s|$))[\\s:,.\\-–—]*|\\s*$|\\s+(?=\\(batch\\b))`,`iu`)}var bp=e=>e!==``&&e!==`…`;function xp(e){let t=dp(cp(e.label??``),48);if(bp(t))return t;let n=cp(e.note??``),r=n,i=/^v(\d+)$/i.exec(e.id)?.[1];i!==void 0&&(r=r.replace(vp(i),``)),r=r.replace(/^\(batch\b[^)]*\)\s*:?\s*/i,``);let a=Array.from(n.slice(0,n.length-r.length)).length;if(r=hp(r,a),Zf.test(r)){let e=dp(r,48);if(bp(e))return e}let o=dp(gp(e.file),48);if(bp(o))return o;let s=dp(cp(e.id),48);return bp(s)?s:`Untitled`}var Sp=[`script`,`picture`,`voice`,`music`,`sfx`,`mix`,`visuals`,`notes`,`assets`,`project`],Cp=[`cut`,`variant`,`take`,`script`,`picks`,`notes-sent`,`replies`,`lock`,`files`,`entry`,`format`,`visual`,`film`],wp=[`user`,`agent`,`rushes`],Tp=5e3,Ep={script:`Script`,picture:`Picture`,voice:`Voice`,music:`Music`,sfx:`Sound effects`,mix:`Mix`,visuals:`Visuals`,notes:`Notes`,assets:`Files`,project:`Project`},Dp=[`Sunday`,`Monday`,`Tuesday`,`Wednesday`,`Thursday`,`Friday`,`Saturday`],Op=[`January`,`February`,`March`,`April`,`May`,`June`,`July`,`August`,`September`,`October`,`November`,`December`],kp=e=>String(e).padStart(2,`0`),Ap=e=>Number.isFinite(e.getTime());function jp(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 Mp(e){return Ap(e)?`${kp(e.getHours())}:${kp(e.getMinutes())}`:`--:--`}function Np(e){return`${e.getFullYear()}-${kp(e.getMonth()+1)}-${kp(e.getDate())}`}function Pp(e,t,n){if(!Ap(e))return`Date unknown`;if(!n)return`${Dp[e.getDay()]} ${e.getDate()} ${Op[e.getMonth()]} ${e.getFullYear()}`;let r=jp(e.toISOString(),t);if(r===0)return`Today`;if(r===1)return`Yesterday`;let i=e.getFullYear()===t.getFullYear()?``:` ${e.getFullYear()}`;return`${Dp[e.getDay()].slice(0,3)} ${e.getDate()} ${Op[e.getMonth()].slice(0,3)}${i}`}function Z(e){return pf(e)}var Fp=Cf([`script`,`picture`,`voice`,`music`,`sfx`,`mix`,`visuals`]),Ip=Cf([`voice`,`music`,`sfx`]),Lp=Y().min(1).max(64),Rp=X().nonnegative(),zp=Y().regex(/^[abcdefghjkmnpqrstuvwxyz23456789]{8}$/),Bp=Z({n:X().int().positive(),name:Y().trim().min(1).max(80),start:X().nonnegative(),tag:Y().trim().max(24).default(``)}),Vp=Z({file:Y().min(1),width:X().int().positive(),height:X().int().positive(),bytes:X().int().nonnegative(),createdAt:Y()}),Hp=Z({id:Y().max(16).regex(de),label:Y().min(3).max(16),file:Y().min(1),width:X().int().positive(),height:X().int().positive(),duration:Rp.nullable().default(null),fps:X().positive().nullable().default(null),addedAt:Y()}),Up=ff({id:Lp,file:Y().min(1),duration:Rp.nullable().default(null),fps:X().positive().nullable().default(null),addedAt:Y(),note:Y().default(``),label:Y().default(``),shots:uf(Bp).max(200).default([]),proxy:Vp.nullable().default(null),width:X().int().positive().nullable().default(null),height:X().int().positive().nullable().default(null),formats:uf(Hp).max(8).default([])}).superRefine((e,t)=>{let n=e.width!==null&&e.height!==null&&pe(e.width,e.height)?z(_e(e.width,e.height)):null,r=new Set(n?[n]:[]);e.formats.forEach((n,i)=>{n.label!==ve(n.id)&&t.addIssue({code:`custom`,path:[`formats`,i,`label`],message:`label "${n.label}" doesn't match id "${n.id}"`}),r.has(n.id)&&t.addIssue({code:`custom`,path:[`formats`,i,`id`],message:`${e.id} already has ${n.label}`}),r.add(n.id)})}),Wp=Z({id:Lp,name:Y().min(1),versions:uf(Up).default([]),lockedVersion:Y().nullable().default(null),shelved:Y().max(40).nullable().optional()}),Gp=Z({id:Lp,name:Y().min(1),t:Rp,file:Y().min(1).max(1024).optional()}),Kp=Z({id:Lp,name:Y().min(1),file:Y().min(1),meta:xf(Y(),hf([Y(),X()])).default({}),cues:uf(Gp).default([]),videos:uf(Lp).optional(),video:Lp.optional(),addedAt:Y().optional(),madeFor:xf(Y(),Y()).optional(),putAway:Y().optional()}),qp=Z({id:Lp,stage:Ip,name:Y().min(1),variants:uf(Kp).default([])}),Jp=Z({id:Lp,kind:Cf([`doc`,`image`,`caption`,`export`,`delivery`,`edit`]),file:Y().min(1),name:Y().min(1).max(120),note:Y().max(500).default(``),video:Y().nullable().default(null),addedAt:Y()});Z({schema:Tf(1),rev:X().int().nonnegative(),id:zp.optional(),name:Y().min(1),fps:X().positive().default(30),videos:uf(Wp).default([]),lanes:uf(qp).default([]),files:uf(Jp).default([]),autoProxy:rf().default(!1)});var Yp=Z({id:Lp,file:Y().min(1),duration:Rp.nullable().default(null),forText:Y()}),Xp=Cf([`draft`,`approved`,`flagged`]),Zp=ff({id:Lp,start:Rp,end:Rp,current:Y(),proposed:Y().nullable().default(null),direction:Y().default(``),status:Xp.default(`draft`),takes:uf(Yp).default([])}).refine(e=>e.end>e.start,{message:`end must be after start`,path:[`end`]}),Qp=Z({wordsPerSecond:X().positive().default(2.6),sections:uf(Zp).default([]),sectionCounter:X().int().nonnegative().optional()});_f(`schema`,[Z({schema:Tf(1),rev:X().int().nonnegative(),wordsPerSecond:X().positive().default(2.6),sections:uf(Zp).default([]),sectionCounter:X().int().nonnegative().optional()}),Z({schema:Tf(2),rev:X().int().nonnegative(),films:xf(Lp,Qp).default({})})]);var $p=Z({x:X().min(0).max(1),y:X().min(0).max(1),w:X().min(0).max(1),h:X().min(0).max(1)}),em=Z({x:X().min(0).max(1),y:X().min(0).max(1)}),tm=Z({kind:Cf([`rise`,`fall`,`louder`,`quieter`]),db:X().min(.5).max(24).optional()}),nm=[`voice`,`music`,`sfx`,`mix`],rm=ff({by:Cf([`agent`,`user`]),text:Y().trim().min(1),at:Y()});function im(e){if(typeof e!=`object`||!e||`replies`in e)return e;let t=e;return typeof t.reply!=`string`||t.reply.trim()===``||typeof t.createdAt!=`string`?e:{...t,replies:[{by:`agent`,text:t.reply,at:t.createdAt}]}}var am=Xf(im,ff({id:Lp,stage:Fp,video:Y().nullable().default(null),version:Y().nullable().default(null),on:Y().nullable().default(null).describe(`What the note is about: null (Picture, or the whole mix), "<lane>/<variant>", "<lane>/<variant>:<cue>", "vo", "<section>:<take>" or a section id.`),scope:Cf([`point`,`range`,`whole`]),t:Rp.nullable().default(null),tOut:Rp.nullable().default(null),frame:X().int().nonnegative().nullable().default(null),text:Y().trim().min(1).max(4e3),box:$p.nullable().default(null),pin:em.nullable().default(null),grab:Y().nullable().default(null),shot:Z({n:X().int().positive(),name:Y()}).nullable().default(null),marks:uf(tm).max(4).default([]),format:Y().max(16).regex(de).nullable().default(null),status:Cf([`todo`,`done`]).default(`todo`),reply:Y().default(``),replies:uf(rm).default([]),fixT:Rp.nullable().default(null),fixVersion:Y().nullable().default(null),batch:Y().nullable().default(null),createdAt:Y(),by:Cf([`user`,`agent`]).default(`user`)}).superRefine((e,t)=>{e.scope===`point`&&e.t===null&&t.addIssue({code:`custom`,path:[`t`],message:`a point note needs t`}),e.scope===`range`&&(e.t===null||e.tOut===null?t.addIssue({code:`custom`,path:[`tOut`],message:`a range note needs t and tOut`}):e.tOut<=e.t&&t.addIssue({code:`custom`,path:[`tOut`],message:`tOut must be after t`})),e.scope===`whole`&&(e.t!==null||e.tOut!==null)&&t.addIssue({code:`custom`,path:[`scope`],message:`a whole-track note has no t or tOut`}),e.pin!==null&&e.stage!==`visuals`&&t.addIssue({code:`custom`,path:[`pin`],message:`a point on an image belongs to a note on a visual`}),e.pin!==null&&e.box!==null&&t.addIssue({code:`custom`,path:[`pin`],message:`a note is a region or a point, not both`}),e.stage===`visuals`&&e.scope!==`whole`&&t.addIssue({code:`custom`,path:[`scope`],message:`a note on a visual has no time`}),e.marks.length>0&&!nm.includes(e.stage)&&t.addIssue({code:`custom`,path:[`marks`],message:`marks don't apply to the ${e.stage} stage`});let n=new Set;for(let r=0;r<e.marks.length;r++){let i=e.marks[r];(i.kind===`louder`||i.kind===`quieter`)&&i.db===void 0&&t.addIssue({code:`custom`,path:[`marks`,r,`db`],message:`${i.kind} needs a db amount`}),(i.kind===`rise`||i.kind===`fall`)&&i.db!==void 0&&t.addIssue({code:`custom`,path:[`marks`,r,`db`],message:`${i.kind} doesn't take a db amount`}),n.has(i.kind)&&t.addIssue({code:`custom`,path:[`marks`,r,`kind`],message:`duplicate mark "${i.kind}"`}),n.add(i.kind)}}));Z({schema:Tf(1),rev:X().int().nonnegative(),notes:uf(am).default([])});var om=Z({voice:X(),music:X(),sfx:X()}).partial().default({}),sm=Z({lane:Lp,variant:Lp,at:Y(),seen:xf(Y(),Y()).default({})}),cm=Z({voice:sm,music:sm,sfx:sm}).partial(),lm=Z({levels:om,at:Y()}),um=Z({lanes:xf(Y(),Y()).default({}),levels:om,use:cm.optional(),balanced:lm.optional()});Z({schema:Tf(1),rev:X().int().nonnegative(),lanes:xf(Y(),Y()).default({}),sections:xf(Y(),Y()).default({}),levels:om,use:cm.optional(),balanced:lm.optional(),videos:xf(Y(),um).default({})});var dm=Z({id:Lp,stage:Fp.nullable(),noteIds:uf(Y()).default([]),sectionIds:uf(Y()).default([]),sentAt:Y(),prompt:Y(),video:Y().nullable().optional(),undelivered:ff({at:Y(),why:Y()}).nullable().optional()});Z({schema:Tf(1),rev:X().int().nonnegative(),batches:uf(dm).default([])}),Z({schema:Tf(1),rev:X().int().nonnegative(),dismissed:uf(Y().max(1024)).max(1e4).default([]),settled:uf(Z({video:Y().max(200),version:Y().max(200),kinds:uf(Cf([`voice`,`music`,`sfx`,`cut`,`other`])).max(5)})).max(200).default([])});var fm=Z({id:Lp,at:Y(),area:Cf(Sp),kind:Cf(Cp),text:Y().min(1).max(160),video:Y().nullable().default(null),version:Y().nullable().default(null),ref:Y().max(300).nullable().default(null),by:Cf(wp),tab:Fp.nullable().default(null),n:X().int().positive().default(1),subject:Y().max(200).default(``)}),pm=Z({schema:Tf(1),rev:X().int().nonnegative(),backfilled:rf().default(!1),began:Y().optional(),undated:uf(Y().max(300)).max(Tp).default([]),dropped:X().int().nonnegative().default(0),entries:uf(fm).max(Tp).default([]),newer:Tf(!0).optional()}),mm=e=>typeof e==`object`&&!!e&&!Array.isArray(e);function hm(e){if(!mm(e)||!Array.isArray(e.entries))return e;let t=[],n=new Set,r=0;for(let i of e.entries){let e=fm.safeParse(mm(i)?gm(i):i);if(!e.success){r+=1;continue}let a=e.data.id;for(let t=2;n.has(a);t++)a=`${e.data.id.slice(0,58)}-${t}`;n.add(a),t.push({...e.data,id:a})}let i=Math.max(0,t.length-Tp),a=typeof e.dropped==`number`&&Number.isInteger(e.dropped)&&e.dropped>=0?e.dropped:0,o=Array.isArray(e.undated)?e.undated.filter(e=>typeof e==`string`&&e.length<=300).slice(0,Tp):e.undated,s=typeof e.rev==`number`&&Number.isInteger(e.rev)&&e.rev>=0?e.rev:0,c=typeof e.schema==`number`&&Number.isInteger(e.schema)&&e.schema>1;return{...e,schema:1,rev:s,newer:c?!0:void 0,undated:o,dropped:a+r+i,entries:t.slice(i)}}function gm(e){let t={...e};return typeof t.text==`string`&&(t.text=cp(t.text)),typeof t.subject==`string`&&(t.subject=cp(t.subject)),t}Xf(hm,pm),Z({schema:Tf(1),rev:X().int().nonnegative(),baseline:Y().max(1e6).default(``),seen:Y().max(64).default(``),films:xf(Lp,Z({baseline:Y().max(1e6).default(``),seen:Y().max(64).default(``)})).optional()});var _m=Z({ratio:Y().max(16).regex(de),file:Y().min(1),width:X().int().positive(),height:X().int().positive()}),vm=Z({n:X().int().positive(),images:uf(_m).min(1).max(8)}),ym=Z({id:Lp,addedAt:Y(),label:Y().default(``),pages:uf(vm).min(1).max(100)}),bm=Z({id:Lp,name:Y().trim().min(1).max(80),kind:Cf([`still`,`carousel`]),addedAt:Y(),versions:uf(ym).min(1)});Z({schema:Tf(1),rev:X().int().nonnegative(),visuals:uf(bm).default([])});var xm=[`claude`,`codex`],Sm=Cf([`ask-all`,`project-edits`,`auto`,`bypass`]),Cm=ff({kind:Y().max(32),command:Y().max(200).nullable()});Z({schema:Tf(1),rev:X().int(),on:rf().default(!1),agent:Cf(xm).nullable().default(null),session:Z({id:Y(),agent:Cf(xm),startedAt:Y()}).nullable().default(null)}).transform(e=>{let{always:t,permissions:n,asked:r,...i}=e;return i}),ff({permissions:Sm.default(`project-edits`),always:uf(Cm).max(50).default([]),setUp:rf().default(!1),agent:Cf(xm).nullable().default(null)}),ff({permissions:Sm.default(`project-edits`),always:uf(Cm).default([]).transform(e=>e.slice(-50)),setUp:rf().default(!1),agent:Cf(xm).nullable().default(null)}),ff({agent:Cf(xm).nullable().default(null),permissions:Sm.default(`project-edits`)}),e(((e,t)=>{t.exports={}}))();var wm={todo:`To do`,sent:`With your agent`,done:`Done`};function Tm(e){return e.status===`done`?`done`:e.batch===null?`todo`:`sent`}function Em(e){return Tm(e)===`sent`&&e.replies.at(-1)?.by===`agent`}function Dm(e){let t=e.current.trim().replace(/\s+/g,` `);return`${e.id.toUpperCase()} · ${t.length>48?`${t.slice(0,47).trimEnd()}…`:t}`}function Om(e,t){let{stage:n,on:r}=e;if(n===`script`){let e=r===null?void 0:t.script.sections.find(e=>e.id===r);return e?Dm(e):null}if(n!==`voice`&&n!==`music`&&n!==`sfx`&&n!==`mix`)return null;if(r===null)return n===`mix`?`Whole mix`:n===`voice`?`Assembled read`:null;let i=n===`mix`?[`music`,`sfx`]:[n],a=t.project.lanes.filter(e=>i.includes(e.stage)),o=(e,t)=>`${e.name} · ${t.name}`,s=(e,t,n)=>{let r=t.cues.find(e=>e.id===n);return r?`${o(e,t)} · Cue · ${r.name}`:null},c=r.indexOf(`/`);if(c>0){let e=r.indexOf(`:`,c),t=r.slice(0,c),n=r.slice(c+1,e===-1?void 0:e),i=a.find(e=>e.id===t),l=i?.variants.find(e=>e.id===n),u=i&&l?e===-1?o(i,l):s(i,l,r.slice(e+1)):null;if(u)return u}if(r===`vo`&&(n===`voice`||n===`mix`))return n===`mix`?`Voiceover`:`Assembled read`;if(n===`voice`){for(let e of t.script.sections){let t=e.takes.findIndex(t=>`${e.id}:${t.id}`===r);if(t!==-1)return`${e.id.toUpperCase()} · Take ${t+1}`}if(t.script.sections.some(e=>e.id===r))return r.toUpperCase()}let l=(e,n)=>t.picks?.lanes[e.id]===n.id,u=a.flatMap(e=>e.variants.map(t=>({l:e,v:t}))),d=(n===`mix`?[...u.filter(e=>l(e.l,e.v)),...u.filter(e=>!l(e.l,e.v))]:u).find(e=>e.v.id===r);if(d)return o(d.l,d.v);let f=r.indexOf(`:`);if(f>0){let e=u.find(e=>e.v.id===r.slice(0,f)&&e.v.cues.some(e=>e.id===r.slice(f+1)));if(e)return s(e.l,e.v,r.slice(f+1))}let p=u.find(e=>e.v.cues.some(e=>e.id===r));return p?s(p.l,p.v,r):null}function km(e,t){let n=e.madeFor?.[t.id];if(n===void 0)return!1;let r=t.versions[t.versions.length-1];return r!==void 0&&r.id!==n}function Am(e,t){return e.addedAt===void 0||e.putAway!==void 0?!1:t===void 0||e.addedAt>t.at}function jm(e,t,n){return n!==void 0&&n.lane===t&&n.variant===e.id?`in-use`:e.putAway===void 0?Am(e,n)?`new`:`earlier`:`put-away`}function Mm(e){switch(e){case`brief`:case`script`:case`storyboard`:return{workspace:`plan`,tab:null};case`voice`:case`music`:case`sfx`:return{workspace:`review`,tab:e};case`visuals`:return{workspace:`visuals`,tab:null};case`assets`:return{workspace:`assets`,tab:null};default:return{workspace:`review`,tab:`timeline`}}}var Nm={2:`picture`,3:`voice`,4:`music`,5:`sfx`,6:`picture`,7:`visuals`,8:`assets`};function Pm(e,t){return e===`1`?t:Nm[e]??null}function Fm(e){return e===`mix`?`picture`:e}var Im=(e,t)=>new Date(e).toLocaleDateString(`en-GB`,{day:`numeric`,month:`short`,timeZone:t});function Lm(e,t,n,r,i){let a={fresh:[],inUse:null,earlier:[],away:[]},o=e.filter(e=>e.stage===t),s=e=>new Date(e).toLocaleDateString(`en-CA`,{timeZone:i});for(let e=o.length-1;e>=0;e--){let c=o[e],l=[];if(c.id!==t)l.push({key:``,round:c.name,variants:c.variants});else{let e=new Map,t=[];for(let n of c.variants){if(n.addedAt===void 0){t.push(n);continue}let r=s(n.addedAt);e.has(r)||e.set(r,{key:r,round:Im(n.addedAt,i),variants:[]}),e.get(r).variants.push(n)}l.push(...[...e.values()].sort((e,t)=>e.key<t.key?1:e.key>t.key?-1:0)),t.length>0&&l.push({key:``,round:c.name,variants:t})}for(let e of l){let t=[];for(let i of e.variants){let o=jm(i,c.id,n),s=o===`in-use`,l={lane:c.id,round:e.round,roundKey:`${c.id}\n${e.key}`,variant:i,madeFor:(r&&i.madeFor?.[r.id])??null,stale:r?km(i,r):!1,inUse:s};o===`in-use`?a.inUse=l:o===`put-away`?a.away.push(l):o===`new`?a.fresh.push(l):t.push(l)}t.length>0&&a.earlier.push({round:e.round,takes:t})}}return a}var Rm=e=>`${e.lane}/${e.variant.id}`;function zm(e){return e.inUse??e.fresh[0]??e.earlier[0]?.takes[0]??null}var Bm={fresh:`New`,inUse:`In use`,earlier:`Earlier`};function Vm(e,t=e=>e){let n=[],r=(e,r,i)=>n.push({kind:e,heading:`${Bm[e]} · ${r}`,takes:t(i)}),i=[];for(let t of e.fresh)i.length>0&&i[0].roundKey!==t.roundKey&&(r(`fresh`,i[0].round,i),i=[]),i.push(t);i.length>0&&r(`fresh`,i[0].round,i),e.inUse&&r(`inUse`,e.inUse.round,[e.inUse]);for(let t of e.earlier)r(`earlier`,t.round,t.takes);return n}function Hm(e){let t=e.earlier.reduce((e,t)=>e+t.takes.length,0);return{all:e.fresh.length+ +!!e.inUse+t+e.away.length,fresh:e.fresh.length}}var Um=e=>String(e).padStart(2,`0`);function Wm(e,t){let n=Math.max(1,Math.round(t)),r=Math.round(Math.max(0,e)*n),i=r%n,a=Math.floor(r/n);return`${Um(Math.floor(a/3600))}:${Um(Math.floor(a/60)%60)}:${Um(a%60)}:${Um(i)}`}var Gm={voice:`Voice`,music:`Music`,sfx:`Effects`};function Km(e,t,n=30){let r=e=>Wm(e,n),i=(e,t)=>e==null?null:t==null?r(e):`${r(e)}–${r(t)}`,a=(e,t)=>({scope:e==null?`whole`:t==null?`point`:`range`,t:e??null,tOut:e==null?null:t??null}),o=e=>e?`${Um(e.n)} ${e.name}`:``,s=(e,t)=>({label:e&&t?`${e} · ${t}`:e??t,when:e,name:t});switch(e.kind){case`frame`:return{stage:`picture`,on:null,scope:`point`,t:e.t,tOut:null,...s(r(e.t),o(t))};case`range`:return{stage:`picture`,on:null,scope:`range`,t:e.t,tOut:e.tOut,...s(i(e.t,e.tOut),o(t))};case`shot`:return{stage:`picture`,on:null,scope:`point`,t:e.t,tOut:null,...s(r(e.t),o(e))};case`take`:return{stage:e.stage,on:e.on,...a(e.t,e.tOut),...s(i(e.t,e.tOut),`${Gm[e.stage]} · ${e.name}`)};case`mix`:return{stage:`mix`,on:null,...a(e.t,e.tOut),...s(i(e.t,e.tOut),`The whole mix`)};case`line`:return{stage:`script`,on:e.id,scope:`whole`,t:null,tOut:null,...s(null,e.label)}}}var qm=e=>t=>t.status===`todo`&&(!t.video||e.inPlay.has(t.video));function Jm(e){let t=qm(e),n=e.scriptTodo-e.notes.filter(e=>e.stage===`script`&&t(e)).length;return Math.max(0,n)+e.briefChanged+e.storyboardChanged}function Ym(e){let t=qm(e);return e.notes.filter(e=>t(e)&&e.batch===null).length+Jm(e)}function Xm(e,t){return e.filter(e=>!!e.undelivered).map(e=>({batch:e,notes:t.filter(t=>t.batch===e.id&&Tm(t)===`sent`).length})).filter(e=>e.notes>0)}var Zm=(e,t)=>e===`sent`?`${wm.sent} · ${t}`:t,Qm=(e,t)=>t>0?Math.min(100,Math.max(0,e/t*100)):0;function $m(e,t,n){let r=e=>n?rh(Math.min(t,Math.max(0,e)),n):Qm(e,t);return e.filter(e=>e.t!==null).map(e=>{let t=r(e.t);return{id:e.id,left:t,width:e.tOut===null?null:r(e.tOut)-t,status:Tm(e)}})}var eh=e=>Math.min(e,2),th=e=>({start:0,end:Math.max(0,e)}),nh=(e,t)=>e.start<=1e-6&&e.end>=t-1e-6;function rh(e,t){let n=t.end-t.start;return n>0?Math.min(110,Math.max(-10,(e-t.start)/n*100)):0}var ih=(e,t)=>t.start+Math.min(1,Math.max(0,e))*(t.end-t.start);function ah(e,t){if(!(t>0))return th(0);let n=Math.min(t,Math.max(eh(t),e.end-e.start)),r=Math.min(t-n,Math.max(0,e.start));return{start:r,end:r+n}}function oh(e,t,n,r=(e.start+e.end)/2){let i=Math.min(t,Math.max(eh(t),(e.end-e.start)*n)),a=e.end>e.start?(r-e.start)/(e.end-e.start):.5;return ah({start:r-a*i,end:r-a*i+i},t)}var sh=(e,t,n)=>ah({start:e.start+n,end:e.end+n},t);function ch(e,t,n){if(n>=e.start&&n<=e.end)return e;let r=e.end-e.start;return ah(n>e.end?{start:n,end:n+r}:{start:n-r*.1,end:n+r*.9},t)}var lh=[`change`,`proxy`,`corrupt`,`agent`],uh=e=>`rushes-sse-v1-${e}`,dh=e=>`rushes-v1-${e}`,fh=4e4,ph=5e3;function mh(){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 hh(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`||lh.includes(n)&&typeof r==`string`:!1}function gh(e,t){t.type===`open`?e.open():t.type===`error`?e.error():`data`in t&&e[t.type](t.data)}function _h(e,t,n,r){let i=new e.EventSource(t),a=e=>{gh(n,e),r?.(e)};for(let e of lh)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 vh(e,t,n,r=mh()){let{locks:i,BroadcastChannel:a}=r;if(!i||!a){let e=_h(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(dh(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,fh+o()*ph))},b=e=>{p=e,s=`leader`,clearTimeout(h),u=_h(r,t,n,_)},x=(a=!1)=>{let o=++f;m?.abort();let h=new AbortController;m=h;let g=!1;i.request(uh(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=_h(r,t,n))})},S=()=>{c||l||s!==`follower`||(x(!0),n.resync())};g.onmessage=e=>{s===`follower`&&!l&&hh(e.data)&&(y(),gh(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 yh(){let[e,t]=H(null),[n,r]=H([]),[i,a]=H(null),[o,s]=H(!1),[c,l]=H({}),[u,d]=H(null),f=G(void 0),p=G(0),m=G(0),h=G(0),g=G(!1),_=G(void 0),v=G(750),y=async()=>{let e=++m.current,n=performance.now(),[i,o]=await Promise.all([K.get(`/api/state`).then(e=>({ok:!0,data:e}),e=>({ok:!1,error:e})),K.get(`/api/assets`).then(e=>({ok:!0,assets:e.assets}),e=>({ok:!1,error:e}))]);if(e<h.current)return;h.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=>vn(t,e.proxies?.jobs??[],n,r)),a(null),s(!1)}else i.error instanceof ti&&i.error.code===`wrong_project`?(s(!0),c=!0):a(i.error.message);o.ok&&r(o.assets),clearTimeout(_.current),c||i.ok&&o.ok?v.current=750:(_.current=window.setTimeout(()=>void y(),v.current),v.current=Math.min(v.current*2,1e4))},b=async()=>{let e=++p.current;try{let{status:t}=await K.get(`/api/agent`);e===p.current&&d(t)}catch(t){e===p.current&&t instanceof ti&&t.status===404&&d(null)}};return U(()=>{y(),b();let e=vh(ni()??``,ci(),{change(){clearTimeout(f.current),f.current=window.setTimeout(()=>void y(),40)},proxy(e){let t=JSON.parse(e);l(e=>_n(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.`)},agent(e){p.current++,d(JSON.parse(e))},error(){a(`Lost touch with the Rushes server. Retrying…`),!g.current&&(g.current=!0,y().finally(()=>{g.current=!1}))},open(){g.current=!1,y(),b()},resync(){y(),b()}});return Gt(location.search).test&&(window.__rushesLive={role:()=>e.role()}),()=>{e.close(),clearTimeout(f.current),clearTimeout(_.current)}},[]),{state:e,assets:n,problem:i,wrongProject:o,refresh:y,proxyJobs:c,noteProxyJob:e=>l(t=>_n(t,gn(e,performance.now()))),agent:u,noteAgent:e=>{p.current++,d(e)}}}var bh=null;function xh(e,t){let n=bh,r={owner:e,stop:t};if(bh=r,n&&n.owner!==e)try{n.stop()}catch{}return()=>{bh===r&&(bh=null)}}function Sh(e){bh&&bh.owner===e&&(bh=null)}function Ch(e){return e.replace(/&/g,`&`).replace(/</g,`<`).replace(/>/g,`>`).replace(/"/g,`"`).replace(/'/g,`'`)}function wh(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 Th(e){let t=/^( *)([-*]|\d+\.)[ \t]+(.*)$/.exec(e);return t?{indent:t[1].length,ordered:/\d/.test(t[2]),content:t[3]}:null}function Eh(e){let t=/^>\s?(.*)$/.exec(e);return t?t[1]:null}function Dh(e){let t=Ch(e).split(/\r\n|\r|\n|\u2028|\u2029/),n=[],r=[],i=null,a=()=>{r.length&&(n.push(`<p>${wh(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(`
|
|
56
|
+
`)}</code></pre>`);continue}let c=/^(#{1,3})[ \t]+(.*)$/.exec(e);if(c){a(),o();let e=c[1].length;n.push(`<h${e}>${wh(c[2])}</h${e}>`),s++;continue}let l=Eh(e);if(l!==null){a(),o();let e=[l];s++;let r;for(;s<t.length&&(r=Eh(t[s]))!==null;)e.push(r),s++;n.push(`<blockquote><p>${wh(e.join(` `))}</p></blockquote>`);continue}let u=Th(e);if(u&&u.indent<2){a(),(!i||i.ordered!==u.ordered)&&(o(),i={ordered:u.ordered,items:[]});let e=wh(u.content);s++;let n=[],r;for(;s<t.length&&(r=Th(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>${wh(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(`
|
|
57
|
+
`)}function Oh(e){return!e||!((e.label??``).trim()||e.note.trim())?null:xp(e)}var kh=[`January`,`February`,`March`,`April`,`May`,`June`,`July`,`August`,`September`,`October`,`November`,`December`];function Ah(e,t){let n=jp(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 jh(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?kh[r.getMonth()].slice(0,3):kh[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 Mh(e,t){return jh(Ah(e,t),t,!0)}function Nh(e,t){return jh(Ah(e,t),t,!1)}function Ph(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 Fh(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 Ih(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=Mh(e.addedAt,t);return r&&n.push(r),n.join(` · `)}function Lh(e){let t=e.trim();if(!t)return{lead:``,points:[]};let n=t.split(/\r?\n/).map(e=>e.trim()).filter(Boolean),r=/^(?:[-*•]|\d+[.)])\s+/,i,a;if(n.some(e=>r.test(e))){let e=n.findIndex(e=>r.test(e));i=n.slice(0,e).join(` `),a=[];for(let t of n.slice(e))r.test(t)?a.push(t.replace(r,``)):a.length&&(a[a.length-1]+=` ${t}`)}else{let e=Rh(n.join(` `));i=e[0]??``,a=e.slice(1)}return{lead:i,points:a.map(e=>{let t=/^([^:.()]{1,28}):\s+(.+)$/s.exec(e);return t?{head:t[1],text:t[2]}:{head:null,text:e}})}}function Rh(e){let t=[],n=0,r=0;for(let i=0;i<e.length;i++){let a=e[i];if(a===`(`||a===`[`)n++;else if((a===`)`||a===`]`)&&n>0)n--;else if((a===`.`||a===`!`||a===`?`)&&n===0&&e[i+1]===` `&&/["'“A-Z0-9]/.test(e[i+2]??``)){if(a===`.`&&/\b(?:e\.g|i\.e|vs|etc|approx|cf)$/i.test(e.slice(r,i)))continue;t.push(e.slice(r,i+1).trim()),r=i+2}}let i=e.slice(r).trim();return i&&t.push(i),t}var zh=0;Array.isArray;function Q(e,t,r,i,a,o){t||={};var s,c,l=t;if(`ref`in l)for(c in l={},t)c==`ref`?s=t[c]:l[c]=t[c];var u={type:e,props:l,key:r,ref:s,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:--zh,__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 n.vnode&&n.vnode(u),u}var Bh={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:`<rect x="4" y="5" width="16" height="14" stroke-linecap="butt" stroke-linejoin="miter" stroke-dasharray="3 2"/>`,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"/>`,pointer:`<path d="M6 3.5l12 7.2-5.3 1.4-2.6 5.4z"/>`,note:`<path d="M5 4h14v11l-5 5H5z"/><path d="M14 20v-5h5"/>`,range:`<path d="M5 5v14M19 5v14M8 12h8"/><path d="M10.5 9.5L8 12l2.5 2.5M13.5 9.5L16 12l-2.5 2.5"/>`,volume:`<path d="M4 9.5h3.5L12 5.5v13l-4.5-4H4z"/><path d="M15.5 9a4 4 0 0 1 0 6M18 6.5a7.5 7.5 0 0 1 0 11"/>`,mute:`<path d="M4 9.5h3.5L12 5.5v13l-4.5-4H4z"/><path d="M16 9.5l5 5M21 9.5l-5 5"/>`,expand:`<path d="M14 4h6v6M20 4l-6.5 6.5M10 20H4v-6M4 20l6.5-6.5"/>`,fitrows:`<path d="M4 4h16M4 20h16"/><path d="M12 7v10M9 9.5L12 7l3 2.5M9 14.5l3 2.5 3-2.5"/>`,zoomin:`<circle cx="10.5" cy="10.5" r="6.5"/><path d="M20 20l-5-5M8 10.5h5M10.5 8v5"/>`,zoomout:`<circle cx="10.5" cy="10.5" r="6.5"/><path d="M20 20l-5-5M8 10.5h5"/>`,info:`<circle cx="12" cy="12" r="8.5"/><path d="M12 11v5.5M12 7.8h.01"/>`,stop:`<rect x="6.5" y="6.5" width="11" height="11" rx="2" fill="currentColor" stroke="none"/>`,spin:`<path d="M12 3.5a8.5 8.5 0 1 0 8.5 8.5"/>`};function $({name:e,class:t}){return Q(`svg`,{class:`ic${t?` ${t}`:``}`,viewBox:`0 0 24 24`,"aria-hidden":`true`,dangerouslySetInnerHTML:{__html:Bh[e]??``}})}var Vh={script:`script`,picture:`film`,voice:`mic`,music:`music`,sfx:`zap`,mix:`sliders`,visuals:`image`},Hh=typeof window<`u`&&`showSaveFilePicker`in window;function Uh(){let e=navigator.userAgent;return/Mac/.test(e)?`Show in Finder`:/Windows/.test(e)?`Show in Explorer`:`Open folder`}function Wh(e){return e?new Date(e).toLocaleDateString(void 0,{day:`numeric`,month:`short`,year:`numeric`}):``}function Gh({asset:e,toast:t}){let[n,r]=H(!1),i=!e.missing&&ot.has(ct(e.path)),a=async()=>{if(n)return;r(!0);let i;try{let t=await window.showSaveFilePicker({suggestedName:e.name}),n=await fetch(si(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 K.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 K.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:`${si(e.path)}&download=1`,download:e.name,onClick:t=>{e.missing&&t.preventDefault()},children:Q($,{name:`download`})}),Hh&&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":Uh(),"aria-label":Uh(),"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 Kh({tip:e=`Missing`}){return Q(`span`,{class:`amiss`,"data-tip":e,"aria-label":e,children:`●`})}function qh(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:Jh(e)?null:Oh(r)}}function Jh(e){return e.kind===`cut`&&e.format!==void 0}function Yh({asset:e,videos:t,toast:n}){let r=e.kind===`cut`||e.kind===`delivery`?qh(e,t):null;return Q(`div`,{class:`arow${e.missing?` missing`:``}${Jh(e)?` sub`:``}`,children:[Q(`div`,{class:`ainfo`,children:[Q(`div`,{class:`atitle`,children:[r?r.title:e.label??e.name,e.missing&&Q(Kh,{})]}),r?.subtitle&&Q(`div`,{class:`asub`,children:r.subtitle}),e.shared&&t.length>1&&Q($h,{}),Q(`div`,{class:`afolder mono`,children:e.path}),!e.missing&&Q(`div`,{class:`ameta`,children:[it(e.size??0),` · `,Wh(e.modified)]})]}),Q(Gh,{asset:e,toast:n})]})}function Xh({asset:e,toast:t,onChanged:n}){let[r,i]=H(!1),[a,o]=H(!1),s=G(null);U(()=>{r&&s.current?.focus()},[r]);let c=async()=>{if(!a&&e.video&&e.version){o(!0);try{await K.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(Kh,{})]}),Q(`div`,{class:`afolder mono`,children:e.path}),!e.missing&&Q(`div`,{class:`ameta`,children:xn(e)})]}),Q(Gh,{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 Zh({asset:e,playing:t,paused:n,onToggle:r,videos:i,toast:a}){let o=t&&!n,s=e.label??e.name,c=at(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(Kh,{})]}),c&&Q(`div`,{class:`atrackmeta`,children:c}),Q(`div`,{class:`afolder mono`,children:e.path}),!e.missing&&Q(`div`,{class:`ameta`,children:[it(e.size??0),` · `,Wh(e.modified)]})]}),Q(Gh,{asset:e,toast:a})]})}function Qh({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(Kh,{})]}),e.note&&Q(`div`,{class:`asub`,children:e.note}),Q(`div`,{class:`afolder mono`,children:e.path}),!e.missing&&Q(`div`,{class:`ameta`,children:[it(e.size??0),` · `,Wh(e.modified)]})]}),Q(Gh,{asset:e,toast:i})]})}function $h(){return Q(`div`,{class:`asub ashared`,"data-tip":`Visuals belong to the project: they show on every film`,children:`Shared`})}function eg({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?`${Ce(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:si(e.path),alt:e.name,loading:`lazy`})}),Q(`div`,{class:`shot-meta`,children:[Q(`div`,{class:`mono`,children:[a,e.missing&&Q(Kh,{})]}),o&&Q(`div`,{class:`asub`,children:o}),e.shared&&t.length>1&&Q($h,{})]}),Q(Gh,{asset:e,toast:n})]})}function tg({asset:e}){let t=G(null),[n,r]=H(!1);return U(()=>{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?`${si(e.path)}#t=0.5`:void 0,"aria-label":`${e.name} poster frame`})}function ng({asset:e,videos:t,toast:n}){let{title:r,subtitle:i}=qh(e,t),a=st.has(ct(e.path));return Q(`div`,{class:`shot-tile${e.missing?` missing`:``}${Jh(e)?` sub`:``}`,children:[Q(`div`,{class:`shot-thumb poster`,children:!e.missing&&(a?Q(tg,{asset:e}):Q(`div`,{class:`file-tile`,children:Q(`span`,{class:`file-ext mono`,children:ct(e.path)||`file`})}))}),Q(`div`,{class:`shot-meta`,children:[Q(`div`,{class:`atitle`,children:[r,e.missing&&Q(Kh,{})]}),i&&Q(`div`,{class:`asub`,children:i}),Q(`div`,{class:`afolder mono`,children:e.path})]}),Q(Gh,{asset:e,toast:n})]})}function rg(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 ig({asset:e,onClose:t,toast:n}){let r=G(null),i=G(null);return U(()=>{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=rg(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:si(e.path),alt:e.name}),Q(`div`,{class:`lbactions`,children:[Q(Gh,{asset:e,toast:n}),Q(`button`,{ref:i,class:`btn ghost ib`,"aria-label":`Close`,onClick:t,children:Q($,{name:`x`})})]})]})})}var ag=60,og=`Up to 12 files of each kind at a time, so the tabs stay quick. Each voiceover folder becomes its own round.`,sg=Cn.filter(e=>e!==`cut`),cg=e=>e.slice(e.lastIndexOf(`/`)+1),lg=e=>`Couldn't be added: ${e.replace(/\.$/,``).replace(/^(\p{Lu})(?=\p{Ll})/u,e=>e.toLowerCase())}`,ug={voice:`var(--vo)`,music:`var(--music)`,sfx:`var(--sfx)`,other:`var(--text-3)`,cut:`var(--accent)`,doc:`var(--text-3)`};function dg({kind:e}){return Q(`i`,{class:`kdot`,style:{background:e?ug[e]:`var(--text-3)`}})}function fg({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 pg({row:e,playing:t,onPlay:n}){return Q(`div`,{class:`frow in`,children:[Q(`span`,{}),e.playable?Q(fg,{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(dg,{kind:e.kind}),Q(`span`,{class:`klabel`,children:e.label})]}),Q(`span`,{}),Q(`span`,{})]})}var mg=class extends T{shouldComponentUpdate(e){return Vn(this.props,e)}render({item:e,kind:t,ticked:n,playing:r,failure:i,onTick:a,onKind:o,onPlay:s}){let c=cg(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(fg,{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:lg(i)})]}),l?Q(`span`,{class:`kind static`,children:[Q(dg,{kind:`cut`}),wn.cut]}):Q(`label`,{class:`kind`,children:[Q(dg,{kind:t}),Q(`select`,{"aria-label":`Kind of ${c}`,value:t,onChange:t=>o(e.path,t.target.value),children:sg.map(e=>Q(`option`,{value:e,children:wn[e]}))}),Q($,{name:`chev`,class:`kchev`})]}),Q(`span`,{class:`fdur mono`,children:Ln(e.duration)}),Q(`span`,{class:`fsize mono`,children:it(e.size)})]})}};function hg(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 gg({state:e,initialKind:t=`all`,playing:n,onPlay:r,onStop:i,toast:a,onChanged:o,onSeen:s}){let c=e.found,[l,u]=H(null),[d,f]=H(null),[p,m]=H(new Set),[h,g]=H({}),[_,v]=H({}),[y,b]=H(``),[x,S]=H(t),[C,w]=H(new Set),[T,E]=H(!0),[D,O]=H(!1),[k,A]=H(!1),[j,ee]=H(!1),[M,N]=H([]),P=G(null),F=G(null),te=G(!1),I=G(null),ne=G({onPlay:r,onStop:i});ne.current={onPlay:r,onStop:i};let re=Gr((e,t)=>ne.current.onPlay(e,t),[]),L=G(0),ie=G(0),ae=async()=>{let e=++L.current;try{let t=await K.get(`/api/found`);if(e<ie.current)return;ie.current=e,u(e=>{let n=jn(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>=ie.current&&f(t.message)}};U(()=>{ae()},[e]);let oe=kn(c);U(()=>s(oe),[oe]);let se=l?.files??[],ce=l?.hidden??[],le=Wr(()=>se.map(e=>({...e,kind:h[e.path]??e.kind,raw:e})),[se,h]),ue=Wr(()=>Fn(le,x,y),[le,x,y]),de=Wr(()=>Pn(ue),[ue]),fe=Wr(()=>In(le),[le]);U(()=>{x!==`all`&&l&&!c.scanning&&!fe.some(([e])=>e===x)&&S(`all`)},[fe,l,c.scanning]);let pe=Wr(()=>Bn(e.project,c.broughtIn),[e.project,c.broughtIn]),me=Wr(()=>de.filter(e=>!C.has(e.key)).flatMap(e=>e.files.map(e=>e.path)),[de,C]),he=Wr(()=>new Set(me),[me]),R=se.filter(e=>p.has(e.path)),ge=R.length,_e=R.filter(e=>he.has(e.path)),z=_e.length,ve=Wr(()=>new Set([...pe.map(e=>e.path),...M]),[pe,M]);U(()=>{l&&n.path&&!n.paused&&(he.has(n.path)||T&&ve.has(n.path)||ne.current.onStop())},[l,n.path,n.paused,he,T,ve]),U(()=>{let e=I.current;if(!e)return;let t=null;t=e===`search`?F.current:`row`in e?P.current?.querySelector(`.frow[data-path="${CSS.escape(e.row)}"] input[type="checkbox"]`)??null:P.current?.querySelector(`.fhrow[data-path="${CSS.escape(e.restore)}"] button`)??null,t&&(t.focus(),I.current=null)});let ye=Gr((e,t)=>{m(n=>{let r=new Set(n);return t?r.add(e):r.delete(e),r}),t||be(e)},[]),be=e=>v(t=>{if(!(e in t))return t;let{[e]:n,...r}=t;return r}),xe=Gr((e,t)=>{g(n=>({...n,[e]:t})),be(e)},[]),Se=e=>w(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),Ce=e=>{let t=new Set(e),n=hg(me,t);I.current=n===null?`search`:{row:n},ie.current=++L.current,u(e=>e&&{...e,files:e.files.filter(e=>!t.has(e.path))}),m(e=>new Set([...e].filter(e=>!t.has(e))))},we=async()=>{if(te.current||ge===0)return;te.current=!0,A(!0);let e=R.slice(0,ag);try{let t=await K.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}})});Ce([...t.added.map(e=>e.path),...t.failed.filter(e=>e.code===`already`).map(e=>e.path)]),N(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=R.length-e.length,r=zn(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{te.current=!1,A(!1)}},Te=async()=>{if(te.current||z===0)return;te.current=!0,A(!0);let e=_e.map(e=>e.path);try{await K.post(`/api/found/dismiss`,{paths:e}),Ce(e),a(`Hid ${e.length} ${e.length===1?`file`:`files`}`),o(),ae()}catch(e){a(e.message)}finally{te.current=!1,A(!1)}},Ee=async e=>{let t=ce.map(e=>e.path),n=t.indexOf(e),r=t[n+1]??t[n-1];try{await K.post(`/api/found/restore`,{paths:[e]}),I.current=r===void 0?{row:e}:{restore:r},ce.length<=1&&O(!1),o(),ae()}catch(e){a(e.message)}},De=async()=>{if(!j){ee(!0);try{await K.post(`/api/found/scan`,{}),o()}catch(e){a(e.message)}finally{ee(!1)}}},Oe=e=>n.path===e&&!n.paused,ke=Tn(c.counts),Ae=c.scanning;return Q(`section`,{class:`amain found`,"aria-label":`Found files`,ref:P,children:[Q(`header`,{class:`aheader`,children:[Q(`h2`,{children:[`Found `,Q(`span`,{class:`count`,children:ke})]}),Q(`div`,{class:`acontrols`,children:[Q(`label`,{class:`search-wrap`,children:[Q($,{name:`search`}),Q(`input`,{ref:F,class:`search`,type:`search`,"aria-label":`Search found files`,placeholder:`Search found files`,value:y,onInput:e=>b(e.target.value)})]}),fe.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:se.length})]}),fe.map(([e,t])=>Q(`button`,{type:`button`,"aria-pressed":x===e,onClick:()=>S(e),children:[wn[e],` `,Q(`span`,{class:`n`,children:t})]},e))]}),Q(`button`,{type:`button`,class:`btn ib`,"aria-label":`Look again`,"aria-busy":Ae||j,"data-tip":`Look through the project folder again`,onClick:()=>void De(),children:Q($,{name:`refresh`})}),Q(`button`,{type:`button`,class:`btn`,disabled:z===0||k,"data-tip":`Hide the ticked files for good. You can restore them from Hidden.`,onClick:()=>void Te(),children:`Not these`}),Q(`button`,{type:`button`,class:`btn primary`,disabled:ge===0||k,onClick:()=>void we(),children:ge>0?`Bring in ${ge}`:`Bring in`})]})]}),Ae&&Q(`p`,{class:`fscan`,"aria-live":`polite`,children:[Q(`span`,{class:`fspin`}),`Looking through the folder…`]}),d&&!l&&Q(`p`,{class:`aempty`,children:d}),pe.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:pe.length}),Q(`span`,{class:`fdone`,children:[Q($,{name:`check`}),`in the project`]})]}),T&&pe.map(e=>Q(pg,{row:e,playing:Oe(e.path),onPlay:re},e.path))]}),l===null?!d&&Q(`p`,{class:`aempty`,children:`Loading…`}):se.length===0?!Ae&&Q(`p`,{class:`aempty`,children:`Nothing else found in this folder.`}):ue.length===0?Q(`p`,{class:`aempty`,children:`Nothing matches.`}):de.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:()=>Se(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(mg,{item:e.raw,kind:e.kind,ticked:p.has(e.path),playing:Oe(e.path),failure:_[e.path],onTick:ye,onKind:xe,onPlay:re},e.path))]},e.key)}),D&&ce.length>0&&Q(`div`,{class:`fcard fhidden`,children:[Q(`p`,{class:`fhead`,children:[Q(`b`,{children:`Hidden`}),Q(`small`,{children:ce.length})]}),ce.map(e=>{let t=cg(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:Mn(e.folder)})]}),Q(`button`,{type:`button`,class:`btn`,"aria-label":`Restore ${t}`,onClick:()=>void Ee(e.path),children:[Q($,{name:`undo`}),`Restore`]})]},e.path)})]}),Q(`div`,{class:`ffoot`,children:[Q(`p`,{class:`foot`,children:og}),ce.length>0&&Q(`button`,{type:`button`,class:`flink`,"aria-expanded":D,onClick:()=>O(e=>!e),children:[`Hidden (`,ce.length,`)`]})]})]})}var _g=new Set([`voiceover`,`music`,`sfx`]),vg=new Set([`cut`,`delivery`]),yg=1048576;function bg(e){return`rushes.assets.view.${e}`}function xg(e){try{let t=localStorage.getItem(bg(e));return t===`grid`||t===`list`?t:null}catch{return null}}function Sg(e,t){try{localStorage.setItem(bg(e),t)}catch{}}function Cg(e){return e?e.gridToggle?xg(e.id)??e.view:`list`:`grid`}async function wg(e){let t=await fetch(si(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>yg){let e=t.byteLength-(a-yg);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 Tg({assets:e,videos:t,state:n,film:r=null,foundRequest:i,onFoundRequestUsed:a,onFoundSeen:o,toast:s,onChanged:c}){let l=t.length>1?r:null,u=Wr(()=>lt.filter(t=>t.id===`export`||e.some(e=>t.kinds.includes(e.kind))),[e]),d=u.find(e=>e.id!==`export`)?.id,f=On(n.found)!==null,[p,m]=H(()=>i.pending?`found`:d??(f?`found`:u[0]?.id??`found`)),h=G(i.pending);U(()=>{if(p===`found`)return;let e=!!p&&u.some(e=>e.id===p);if(h.current&&e)return;let t=d??(e?p:u[0]?.id??`found`);t!==p&&m(t)},[u,p]);let[g,_]=H(()=>({key:0,kind:i.pending?i.kind:void 0})),v=e=>{h.current=!0,m(e)},y=G(i.pending?i.n:-1);U(()=>{i.pending&&(y.current!==i.n&&(y.current=i.n,v(`found`),_(e=>({key:e.key+1,kind:i.kind}))),a())},[i.n,i.pending]);let b=p===`found`,x=b?null:u.find(e=>e.id===p)??null,[S,C]=H(``),[T,E]=H(`newest`),[D,O]=H(l),k=G(l);k.current!==l&&(k.current=l,O(l));let[A,j]=H(()=>Cg(x)),ee=G(x?.id??null);x&&x.id!==ee.current&&(ee.current=x.id,C(``),O(l),E(`newest`),j(Cg(x)));let M=Wr(()=>x?mt(e,x,{query:S,sort:T,film:x&&ut(x,t.length)?D:null,videos:t}):[],[e,x,S,T,D,t]),N=e=>{x&&x.gridToggle&&(j(e),Sg(x.id,e))},[P,F]=H(null),te=G(null),I=(e,t)=>{te.current=t,F(e)},ne=()=>{F(null),te.current?.focus()},re=G(null),[L,ie]=H({path:null,paused:!0}),ae=G({}),oe=()=>{re.current?.pause(),Sh(ae.current),ie({path:null,paused:!0})},se=(e,t)=>{let n=re.current;if(n){if(L.path===e&&!L.paused){n.pause(),Sh(ae.current),ie({path:e,paused:!0});return}L.path!==e&&(n.src=si(e)),xh(ae.current,()=>{re.current?.pause(),ie(e=>({...e,paused:!0}))}),ie({path:e,paused:!1}),n.play().catch(n=>{n instanceof Error&&n.name===`AbortError`||(Sh(ae.current),ie({path:e,paused:!0}),s(`Couldn't play ${t}`))})}},ce=e=>se(e.path,e.label??e.name);U(()=>oe,[p,D]),U(()=>oe,[]),U(()=>{c()},[p]),U(()=>{let e=()=>{document.visibilityState===`visible`&&c()};return document.addEventListener(`visibilitychange`,e),()=>document.removeEventListener(`visibilitychange`,e)},[]);let[le,ue]=H(null),[de,fe]=H(null),pe=!!x&&dt.has(x.id);U(()=>{if(!pe){ue(null);return}le&&M.some(e=>e.path===le&&pt(e))||ue(M.find(pt)?.path??null)},[pe,M]),U(()=>{if(!le){fe(null);return}let e=!1;return fe({loading:!0,text:``,truncated:!1}),wg(le).then(t=>{e||fe({loading:!1,text:t.text,truncated:t.truncated})}).catch(t=>{e||fe({loading:!1,text:``,truncated:!1,error:t.message})}),()=>{e=!0}},[le]);let me=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())},he=async()=>{try{await K.post(`/api/reveal`,{project:!0})}catch(e){s(e.message)}},R=async()=>{try{let{path:e}=await K.post(`/api/exports/notes`);s(`Saved to ${e}`),c()}catch(e){s(e.message)}},ge=n=>mt(e,n,{film:ut(n,t.length)?D:null,videos:t}).length,_e=()=>x?x.id===`screenshot`&&T!==`name`?gt(M,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(eg,{asset:e,videos:t,toast:s,onOpen:t=>I(e,t)},e.path))})]},e.heading??`_${n}`)):vg.has(x.id)?Q(`div`,{class:`shots-grid`,children:M.map(e=>Q(ng,{asset:e,videos:t,toast:s},e.path))}):Q(`div`,{class:`shots-grid`,children:M.map(e=>Q(eg,{asset:e,videos:t,toast:s,onOpen:t=>I(e,t)},e.path))}):null,z=()=>x?_g.has(x.id)?Q(`div`,{class:`arows`,children:M.map(e=>Q(Zh,{asset:e,playing:L.path===e.path,paused:L.paused,onToggle:ce,videos:t,toast:s},e.path))}):x.id===`proxy`?Q(`div`,{class:`arows`,children:M.map(e=>Q(Xh,{asset:e,toast:s,onChanged:c},e.path))}):pe?Q(`div`,{class:`arows`,children:M.map(e=>Q(Qh,{asset:e,selected:le===e.path,onSelect:()=>ue(e.path),videos:t,toast:s},e.path))}):Q(`div`,{class:`arows`,children:M.map(e=>Q(Yh,{asset:e,videos:t,toast:s},e.path))}):null,ve=le?(le.split(`.`).pop()??``).toLowerCase():``,ye=Wr(()=>Dh(de?.text??``),[de?.text]);return Q(`div`,{class:`assets-lib`,children:[Q(`nav`,{class:`asidebar`,"aria-label":`Folders`,onKeyDown:me,children:[Q(`button`,{type:`button`,class:`afolder-btn afound`,"aria-current":b?`true`:void 0,onClick:()=>{b||_(e=>({key:e.key+1})),v(`found`)},children:[Q(`span`,{children:`Found`}),Q(`span`,{class:`count`,children:Tn(n.found?.counts)})]}),u.map(e=>Q(`button`,{type:`button`,class:`afolder-btn`,"aria-current":e.id===p?`true`:void 0,onClick:()=>v(e.id),children:[Q(`span`,{children:e.title}),Q(`span`,{class:`count`,children:ge(e)})]},e.id)),Q(`button`,{type:`button`,class:`afolder-root`,onClick:()=>void he(),children:[Q($,{name:`folder`}),`Project folder`]})]}),b?Q(gg,{state:n,initialKind:g.kind,playing:L,onPlay:se,onStop:oe,toast:s,onChanged:c,onSeen:o},g.key):x?Q(`div`,{class:`amain`,children:[Q(`header`,{class:`aheader`,children:[Q(`h2`,{children:[x.title,` `,Q(`span`,{class:`count`,children:M.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:S,onInput:e=>C(e.target.value)})]}),ut(x,t.length)&&Q(`select`,{class:`sel`,"aria-label":`Film`,value:D??``,onChange:e=>O(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:T,onChange:e=>E(e.target.value),children:[Q(`option`,{value:`newest`,children:`Newest`}),Q(`option`,{value:`oldest`,children:`Oldest`}),Q(`option`,{value:`name`,children:`Name`})]}),x.gridToggle&&Q(`div`,{class:`seg`,role:`group`,"aria-label":`View`,children:[Q(`button`,{type:`button`,"aria-pressed":A===`grid`,"aria-label":`Grid view`,"data-tip":`Grid`,onClick:()=>N(`grid`),children:Q($,{name:`grid`})}),Q(`button`,{type:`button`,"aria-pressed":A===`list`,"aria-label":`List view`,"data-tip":`List`,onClick:()=>N(`list`),children:Q($,{name:`list`})})]}),x.id===`export`&&Q(`button`,{type:`button`,class:`btn`,onClick:()=>void R(),children:[Q($,{name:`script`}),`Export notes`]})]})]}),Q(`div`,{class:`abody${pe?` split`:``}`,children:[Q(`div`,{class:`alist`,children:M.length===0?Q(`p`,{class:`aempty`,children:`Nothing here yet.`}):A===`grid`?_e():z()}),pe&&Q(`aside`,{class:`apreview`,children:!le||!de?Q(`p`,{class:`aempty`,children:`Select a file to preview it here.`}):de.loading?Q(`p`,{class:`aempty`,children:`Loading…`}):de.error?Q(`p`,{class:`aempty`,children:de.error}):Q(w,{children:[ve===`md`?Q(`div`,{class:`markdown`,dangerouslySetInnerHTML:{__html:ye}}):Q(`pre`,{class:`plain`,children:de.text}),de.truncated&&Q(`p`,{class:`atrunc`,children:`Showing the first 1 MB`})]})})]})]}):Q(`div`,{class:`emptypage`,children:[Q($,{name:`grid`}),Q(`h2`,{children:`Nothing to review in Assets yet`})]}),Q(`audio`,{ref:re,onEnded:()=>{Sh(ae.current),ie(e=>({...e,paused:!0}))}}),P&&Q(ig,{asset:P,toast:s,onClose:ne})]})}var Eg=class extends Error{};function Dg(e,t,n){let r=async()=>(await K.get(`/api/${e}${n.video?`?video=${encodeURIComponent(n.video)}`:``}`))[e],i=G(t.hash),a=G(t);a.current=t;let o=G(Promise.resolve()),s=G(null),c=G(0);U(()=>{i.current=t.hash},[t.hash]),U(()=>(n.settle.current=async()=>(await o.current.catch(()=>void 0),r()),()=>{n.settle.current=null}),[]);let l=async(t,o)=>{let s=a.current;for(let a=0;;a++){let c=t(s,o||a>0);if(!c)throw Error(`that part is no longer in ${e}.md`);if(`refuse`in c)throw new Eg(c.refuse);try{let t=await K.put(c.path,{...c.body,...n.video?{video:n.video}:{},hash:i.current});i.current=t[e].hash;return}catch(t){if(t instanceof ti&&t.code===`${e}_changed`&&a===0){s=await r(),i.current=s.hash;continue}throw t}}},u=(t,r,i=!1)=>{let a=++c.current;s.current=null,o.current=o.current.catch(()=>void 0).then(()=>l(r,i)).catch(o=>{!i&&a===c.current&&o instanceof ti&&o.code===`${e}_changed`&&(s.current={what:t,build:r}),n.toast(`Couldn't save ${t}: ${o.message}`)}).finally(n.onChanged)};return U(()=>{let e=s.current;e&&(s.current=null,u(e.what,e.build,!0))},[t.hash]),{latest:a,enqueue:u}}function Og(e,t){let n=G(void 0),r=G(e);return r.current=e,U(()=>()=>{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 kg=`plan-page`,Ag=e=>`ptab-${e}`;function jg({rows:e,selected:t,onPick:n}){let r=G([]),i=Math.max(0,e.findIndex(e=>e.page===t));return Q(`nav`,{class:`rtabs ptabs`,role:`tablist`,"aria-label":`Plan`,onKeyDown:t=>{if(t.metaKey||t.ctrlKey||t.altKey||t.shiftKey)return;let n=r.current.findIndex(e=>e===document.activeElement);if(n<0)return;let i=t.key===`ArrowRight`?Math.min(e.length-1,n+1):t.key===`ArrowLeft`?Math.max(0,n-1):t.key===`Home`?0:t.key===`End`?e.length-1:-1;i<0||(t.preventDefault(),t.stopPropagation(),r.current[i]?.focus())},children:e.map((e,a)=>Q(`button`,{ref:e=>{r.current[a]=e},type:`button`,class:`tab`,role:`tab`,id:Ag(e.page),"aria-controls":kg,"aria-selected":t===e.page,tabIndex:a===i?0:-1,"data-locked":e.unlocked?void 0:`true`,"data-tip":e.unlocked?void 0:`Locked: ask your agent for ${e.ask}`,onClick:()=>n(e.page),children:[Q($,{name:e.icon}),e.name,e.unlocked?Q(w,{children:[e.approved&&Q(w,{children:[Q($,{name:`check`,class:`pready`}),Q(`span`,{class:`vh`,children:` Approved`})]}),e.open>0&&Q(`span`,{class:`dot`,title:`${e.open} not sent`})]}):Q(w,{children:[Q($,{name:`lock`,class:`lk`}),Q(`span`,{class:`vh`,children:` Locked`})]})]},e.page))})}function Mg(e){e.style.height=`auto`,e.style.height=`${e.scrollHeight+2}px`}function Ng({value:e,label:t,onInput:n,onBlur:r}){let i=G(null);return W(()=>{i.current&&Mg(i.current)},[e]),U(()=>{let e=i.current;if(!e||typeof ResizeObserver>`u`)return;let t=e.clientWidth,n=new ResizeObserver(()=>{e.clientWidth!==t&&(t=e.clientWidth,Mg(e))});return n.observe(e),()=>n.disconnect()},[]),Q(`textarea`,{ref:i,class:`input pfield`,rows:1,"aria-label":t,value:e,onInput:e=>n(e.target.value),onBlur:r})}function Pg({baseline:e,revertLabel:t,onRevert:n}){return Q(`div`,{class:`edited`,children:[Q(`div`,{class:`ehead`,children:[Q(`span`,{class:`etag`,children:`Edited by you`}),Q(`button`,{class:`btn ghost ib`,"data-tip":t,"aria-label":t,onClick:n,children:Q($,{name:`undo`})})]}),e.map(e=>Q(`p`,{class:`was`,children:[e.label&&Q(`span`,{class:`wl`,children:[e.label,`: `]}),Q(`del`,{children:e.text||`(none)`})]},e.label??`text`))]})}function Fg({counts:e,children:t}){return!e&&!t?null:Q(`div`,{class:`pfoot`,children:[e&&Q(`p`,{class:`pstatus`,children:[e.approved,` · `,e.edited,` edited`]}),t]})}var Ig=(e,t,n)=>`${e} of ${t} ${n}${t===1?``:`s`} approved`,Lg=500;function Rg({section:e,save:t}){let[n,r]=H(e.yours),i=G(!1);U(()=>{i.current||r(e.yours)},[e.yours]);let a=Og(()=>{i.current=!1,n.trim()!==e.yours.trim()&&t.section(e,n)},Lg),o=n.trim()!==e.current.trim();return Q(`div`,{class:`srow brow${o?` changed`:``}`,"data-section":e.heading,children:[Q(`div`,{class:`plabel`,children:e.heading}),Q(`div`,{class:`pbody`,children:[Q(Ng,{label:`Your version of ${e.heading}`,value:n,onInput:e=>{i.current=!0,r(e),a.schedule()},onBlur:()=>a.flush()}),o&&Q(Pg,{baseline:[{text:e.current}],revertLabel:`Revert ${e.heading}`,onRevert:()=>{i.current=!1,r(e.current),t.section(e,e.current)}})]})]})}var zg=(e,t)=>e.slice(0,t).filter(n=>n.heading===e[t].heading).length;function Bg({brief:e,video:t=null,toast:n,onChanged:r,settle:i}){let{latest:a,enqueue:o}=Dg(`brief`,e,{toast:n,onChanged:r,settle:i,video:t}),s={section:(e,t)=>{let n=zg(a.current.sections,e.index);o(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(`
|
|
58
|
+
|
|
59
|
+
`);o(`the brief's status`,(e,r)=>r&&t===`approved`&&e.sections.map(e=>`${e.heading}\n${e.yours}`).join(`
|
|
60
|
+
|
|
61
|
+
`)!==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}})}},c=e.status===`approved`;return Q(`div`,{class:`col ppage`,children:[Q(`div`,{class:`shead`,children:[Q(`h2`,{children:`Brief`}),e.title&&Q(`span`,{class:`meta`,children:e.title})]}),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:`prows`,children:e.sections.map(t=>Q(Rg,{section:t,save:s},`${t.heading}#${zg(e.sections,t.index)}`))}),Q(Fg,{counts:e.sections.length>0?{approved:c?`Brief approved`:`Brief not approved yet`,edited:e.changed}:null,children:Q(`button`,{class:`btn bapprove${c?` approved`:``}`,"aria-pressed":c,onClick:()=>s.status(c?`draft`:`approved`),children:[Q($,{name:`check`}),c?`Approved`:`Approve brief`]})})]})}var Vg=150;function Hg({chips:e,versionId:t,prompt:n,onSelect:r,toast:i}){let a=G(null),o=e.some(e=>e.reason===`single`),s=e.filter(e=>e.enabled),c=e.find(e=>e.selected)?.id??null;W(()=>{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]=H(!1),[d,f]=H(!1),[p,m]=H(!1),[h,g]=H(!1),_=G(void 0),v=G(!1),y=()=>{clearTimeout(_.current),u(!0),m(!1)},b=()=>{clearTimeout(_.current),_.current=window.setTimeout(()=>u(!1),Vg)};U(()=>()=>clearTimeout(_.current),[]);let x=o&&(l||d)&&!p&&!h;if(U(()=>{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())};return Q(`div`,{class:`fmtwrap`,children:[Q(`div`,{ref:a,class:`fmts`,role:`radiogroup`,"aria-label":`Format`,style:{gridTemplateColumns:Jn(e.length)},onKeyDown:e=>S(e),children:e.map(e=>{let n=qn(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":Kn(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(Ug,{prompt:n,toast:i,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()}})})]})}function Ug({prompt:e,toast:t,copyRef:n,onPointerDown:r,onFocus:i,onBlur:a,onClick:o}){let s=async()=>{try{await navigator.clipboard.writeText(e),t(`Prompt copied`)}catch{t(`Couldn't reach the clipboard. Ask your agent to register the other shapes with rushes_add_format.`)}};return Q(w,{children:[Q(`p`,{children:[`One format. Your agent can add more with `,Q(`code`,{children:`rushes_add_format`}),`.`]}),Q(`button`,{ref:n,type:`button`,class:`btn ghost`,onPointerDown:r,onFocus:i,onBlur:a,onClick:e=>{o?.(e),s()},children:[Q($,{name:`copy`}),`Copy a prompt for your agent`]})]})}var Wg=[`ArrowLeft`,`ArrowRight`,`ArrowUp`,`ArrowDown`,`Home`,`End`];function Gg({label:e,width:t,height:n,value:r,onChange:i,lockedReason:a,name:o}){let s=qn(t,n),c=qr();return Q(`div`,{class:`fscope`,role:`radiogroup`,"aria-label":o,onKeyDown:e=>{if(e.altKey||e.metaKey||e.ctrlKey||!Wg.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 Kg={read:`reads`,edit:`edits`,delete:`deletes`,move:`moves`,search:`searches`};function qg(e){return e.kind===`execute`?`Always for ${e.command??`commands`} here`:e.kind===`fetch`?`Always for web requests here`:`Always for ${Kg[e.kind]??`this`} here`}var Jg={claude:`Claude Code`,codex:`Codex`},Yg=e=>e?Jg[e]:`your agent`,Xg=new Set([`starting`,`working`,`waiting`]);function Zg(e,t){let n=e===null?null:t.find(t=>t.id===e)?.batch??null;if(n===null)return null;let r=t.filter(e=>e.batch===n);return`note ${r.findIndex(t=>t.id===e)+1} of ${r.length}`}function Qg(e,t){let n=Yg(e.agent),r;switch(e.phase){case`starting`:r=`Starting ${n}`;break;case`working`:{let i=Zg(e.current.note,t);r=i?`${n} · ${i}`:`${n} is working`;break}case`waiting`:r=`${n} is waiting for you`;break;case`question`:r=`${n} has a question`;break;case`finished`:r=`${n} finished`;break;case`failed`:r=`${n} didn't finish`;break;default:return null}return e.batches.length>1?`${r} · ${e.batches.length} batches`:r}var $g=6e5;function e_(e,t){return e.phase===`off`||e.phase===`idle`?!1:e.phase!==`finished`&&e.phase!==`failed`||e.lines.length===0||!(t-Math.max(...e.lines.map(e=>Date.parse(e.at)))>$g)}function t_(e){return e===`waiting`||e===`question`?`todo`:e===`finished`?`done`:e===`failed`?`over`:`busy`}var n_=e=>Xg.has(e);function r_(e,t){return!t||Tm(e)!==`sent`?!1:e.batch!==null&&t.batches.includes(e.batch)||Xg.has(t.phase)&&t.current.note===e.id||(t.followUps??[]).includes(e.id)}function i_(e,t){if(e.needsYou)return{kind:`needsYou`,text:`Needs you`};if(t&&t.current.note===e.id&&Xg.has(t.phase))return{kind:`working`,text:t.current.doing??`Working on it`};let n=Tm(e),r=r_(e,t)?t.agent:null;return n===`sent`?{kind:`with`,text:`With ${Yg(r)}`}:n===`done`&&e.fixVersion?{kind:`fixed`,text:`Fixed in ${e.fixVersion}`}:null}function a_(e){if(e===void 0)return`dialog`;let t=e;return e.handedTo===null&&!t.stopped&&!t.recalled?`dialog`:t.stopped?`stopped`:t.recalled?`recalled`:t.starting?`starting`:`handed`}function o_(e){let t=g_[e.permissions](Yg(e.agent));return e.session?`${t} · next Send continues the conversation`:t}var s_=(e,t=20)=>t>0?e.lines.slice(-t).reverse():[];function c_(e){return e.phase===`off`||e.phase===`idle`?null:e.phase===`finished`||e.phase===`failed`?e.lines.length>0?`ended`:null:`live`}var l_=e=>`Show the run (${e})`,u_=e=>H_(e.text),d_=e=>e.asked&&e.agent!==null,f_=e=>d_(e)?`Send to AI · ${Yg(e.agent)}`:`Set up Send to AI`,p_=e=>e.on?o_(e):`Copies a prompt for your own chat`,m_={sendTo:`Send notes to`,signedIn:`Signed in`,notSignedIn:`Not signed in`,signIn:`Sign in in Terminal`,fresh:`Start a fresh conversation`,may:`What it may do without asking`,always:`Always rules`,noRules:`No Always rules yet`,remove:`Remove`,footer:`Switch off: Send copies a prompt, as now`},h_=[{value:`ask-all`,label:`Manual`,hint:`Always ask`},{value:`project-edits`,label:`Accept edits`,hint:`Edit files in this project without asking`},{value:`auto`,label:`Auto`,hint:`The agent decides: its own safety check approves or refuses each step. Rushes sees only what it asks, and no longer guards .rushes and .git`},{value:`bypass`,label:`Bypass`,hint:`Accepts everything: nothing asks, nothing is checked, .rushes and .git included`}],g_={"ask-all":()=>`Asks before everything`,"project-edits":()=>`Edits files in this project, asks before commands`,auto:e=>`Auto: ${e} decides what to ask`,bypass:()=>`Bypass: nothing asks, nothing is checked`};function __(e,t){return(e??[]).filter(e=>e.installed).map(e=>({id:e.id,name:e.name,signedIn:e.signedIn,current:e.id===t.agent}))}var v_=e=>e.always.map(e=>({rule:e,label:qg(e)}));function y_(e,t){return t.reduce((e,t)=>e+(t.signedIn?1:2),0)+ +!!e.session+h_.length+e.always.length}function b_(e,t,n){let r=y_(e,t)-e.always.length,i=e.always.length-1;return n<i?r+n:i>0?r+i-1:0}var x_={who:`Who should get these notes?`,copy:`Copy a prompt, as now`,copyButton:`Copy a prompt`,next:`Next`,back:`Back`,cancel:`Cancel`,notInstalled:`Not installed`,noKey:`Rushes never sees a password or key. The agent uses your own sign-in.`,setUp:`Set up`},S_=e=>`What may ${Yg(e)} do without asking?`,C_=e=>`Send to ${Yg(e)}`,w_=e=>`Use ${Yg(e)}`;function T_(e){return[...(e??[]).map(e=>e.installed?e.signedIn?{pick:e.id,name:e.name,state:`ready`,note:m_.signedIn}:{pick:e.id,name:e.name,state:`signedOut`,note:m_.notSignedIn}:{pick:e.id,name:e.name,state:`missing`,note:x_.notInstalled}),{pick:`copy`,name:x_.copy,state:`copy`,note:null}]}function E_(e,t){let n=e.filter(e=>e.state===`ready`);return(n.find(e=>e.pick===t)??n[0])?.pick??`copy`}function D_(e,t){if(e===`copy`)return`copy`;let n=t.find(t=>t.pick===e)?.state;return n===`ready`?`may`:n===`signedOut`?`signedOut`:`missing`}var O_=e=>`${Yg(e)} is not signed in. Choose ${m_.signIn}, then try again.`,k_=(e,t)=>e.step===`may`?t?C_(e.agent):w_(e.agent):e.pick===`copy`?x_.copyButton:x_.next;function A_(e,t){let n={toast:null,dialog:!1,why:null,handed:!1},r=e&&`why`in e?e.why:null;switch(a_(e)){case`handed`:return{...n,toast:{text:`Sent to ${Yg(e.handedTo)}`,ms:2400},handed:!0};case`starting`:return{...n,toast:{text:`Starting ${Yg(e.handedTo)}`,ms:2400},handed:!0};case`recalled`:{let e=Yg(t?.agent??null),i=`${e} could not start: `,a=(r??``).replace(/\.$/,``);return{...n,toast:{text:`${e} couldn't start: ${a.startsWith(i)?a.slice(i.length):a}. The notes are back in to do.`,ms:6e3}}}case`stopped`:return n;default:return{...n,dialog:!0,why:t?.on&&r?r:null}}}var j_=(e,t)=>e?.handed?`${Yg(t?.agent??null)} has the notes. These lines aren't sent to it yet.`:null,M_={once:`Allow once`,no:`No`},N_=e=>`${Yg(e)} wants to:`,P_=`Run a command`,F_=e=>e.trim().replace(/^`+|`+$/g,``).replace(/\s+/g,` `).trim();function I_(e){return e.command&&F_(e.title)===F_(e.command)?P_:H_(e.title)}function L_(e){let t=e.always.trim()===``?[]:[{choice:`always`,label:e.always}];return[{choice:`once`,label:M_.once},...t,{choice:`no`,label:M_.no}]}var R_=(e,t)=>e.slice(0,t).join(` `),z_=RegExp(`[\\u0000-\\u0008\\u000B-\\u001F\\u007F-\\u009F\\u00AD\\u034F\\u061C\\u115F\\u1160\\u17B4\\u17B5\\u180B-\\u180F\\u200B-\\u200F\\u2028-\\u202E\\u2060-\\u206F\\u3164\\uFE00-\\uFE0F\\uFEFF\\uFFA0\\uFFF0-\\uFFFB\\u{E0000}-\\u{E0FFF}]`,`gu`),B_=e=>`<U+${e.codePointAt(0).toString(16).toUpperCase().padStart(4,`0`)}>`;function V_(e){let t=[],n=0;for(let r of e.matchAll(z_))r.index>n&&t.push({text:e.slice(n,r.index)}),t.push({hidden:B_(r[0])}),n=r.index+r[0].length;return n<e.length&&t.push({text:e.slice(n)}),t}var H_=e=>e.replace(z_,B_),U_=e=>({id:e.id,batch:e.batch,status:e.status,fixVersion:e.fixVersion,needsYou:Em(e)});function W_(e,t=!1){let n=e.replies.length>0?e.replies.map(e=>({by:e.by,text:e.text,time:Mp(new Date(e.at))})):e.reply.trim()===``?[]:[{by:`agent`,text:e.reply.trim(),time:``}];return t||n.length<=3?{lines:n,more:null}:{lines:n.slice(-3),more:`Show all (${n.length})`}}var G_=(e,t)=>!!e.needsYou||!!t?.on&&r_(e,t);function K_(e,t){return`Answer ${Yg(t?.on&&(r_(e,t)||e.needsYou&&t.session!==null)?t.agent:null)}`}function q_(e,t){return e.status!==`done`||!e.fixVersion?null:e.fixVersion===t?e.fixT===null?null:{kind:`seek`,t:e.fixT}:e.stage===`picture`&&e.video?{kind:`jump`,to:{tab:`picture`,video:e.video,version:e.fixVersion},t:e.fixT}:null}var J_=e=>H_(e.text),Y_=e=>e.split(`
|
|
62
|
+
`).map(V_);function X_(e,t){let n=new Set(e);for(let e=t.length-1;e>=0;e--)if(!n.has(t[e]))return t[e];return null}function Z_(e,t,n){return{memory:{film:t,versions:[...n]},arrived:e&&e.film===t?X_(e.versions,n):null}}function Q_(e,t,n){if(e===null)return null;let r=`${H_(e)} is in`;return n?t===e?{text:r,show:!1,offer:!1,dot:!1}:{text:r,show:!1,offer:!0,dot:!0}:{text:r,show:t!==e,offer:!1,dot:!1}}function $_(e,t,n,r){return!e||e.film!==t||e.id===n||!r.includes(e.id)?null:e.id}function ev(e,t,n){W(()=>{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])}var tv=700;function nv(e,t){let[n,r]=H(!1),[i,a]=H(0),o=G(null),s=G(null),c=G([]),l=G({text:``,at:-1/0}),u=G(null),d=e=>{r(!1),e&&o.current?.focus()},f=(t=0)=>{a(Math.max(0,Math.min(e-1,t))),l.current={text:``,at:-1/0},r(!0)};return ev(n,s,d),W(()=>{n&&c.current[i]?.focus()},[n,i]),W(()=>{let e=u.current;e!==null&&n&&(u.current=null,c.current[e]?.focus())}),{open:n,show:f,close:d,toggle:e=>n?d(!1):f(e),row:e=>t=>{c.current[e]=t},onKeyDown:n=>{if(n.key===`Tab`)return d(!1);if(n.metaKey||n.ctrlKey||n.altKey)return;let r=c.current.findIndex(e=>e===document.activeElement),o=Fh(n.key,r<0?i:r,e),s=e=>c.current[e]?.disabled===!0,u=n.key===`Home`?`ArrowDown`:n.key===`End`?`ArrowUp`:n.key;for(let t=0;o!==null&&t<e&&s(o);t++)o=Fh(u,o,e);if(o!==null&&s(o)&&(o=null),o!==null){n.preventDefault(),n.stopPropagation(),a(o),c.current[o]?.focus();return}if(n.key===`ArrowLeft`||n.key===`ArrowRight`){n.preventDefault(),n.stopPropagation();return}if(n.key===`Enter`||n.key===` `)return void n.stopPropagation();if(n.key.length===1){if(n.stopPropagation(),!t)return;let e=n.timeStamp-l.current.at<tv?l.current.text+n.key:n.key;l.current={text:e,at:n.timeStamp};let r=t(e.toLowerCase());r!==null&&(n.preventDefault(),a(r),c.current[r]?.focus())}},focus:t=>{u.current=Math.max(0,Math.min(e-1,t)),a(u.current)},button:o,wrap:s}}var rv=({on:e})=>Q(`span`,{class:`atick`,"aria-hidden":`true`,children:e&&Q($,{name:`check`})});function iv({menu:e,status:t,agents:n,refused:r,onPick:i,onSignIn:a,onFresh:o,onPermissions:s,onRemove:c}){let l=0,u=v_(t);return Q(`div`,{class:`dmenu amenu`,role:`menu`,"aria-label":`Send to AI`,onKeyDown:e.onKeyDown,children:[Q(`div`,{class:`hd`,children:m_.sendTo}),n.map(t=>Q(w,{children:[Q(`div`,{class:`mrow`,children:[Q(`button`,{ref:e.row(l++),type:`button`,role:`menuitemradio`,class:`mi`,tabIndex:-1,"aria-checked":t.current,onClick:()=>i(t.id),children:[Q(rv,{on:t.current}),Q(`span`,{class:`nm`,children:t.name}),Q(`span`,{class:`c fn${t.signedIn?``:` todo`}`,children:t.signedIn?m_.signedIn:`${m_.notSignedIn} ·`})]}),!t.signedIn&&Q(`button`,{ref:e.row(l++),type:`button`,role:`menuitem`,class:`mi alink`,tabIndex:-1,onClick:()=>a(t.id),children:m_.signIn})]}),r?.agent===t.id&&Q(`p`,{class:`aerr`,role:`alert`,children:r.message})]},t.id)),t.session&&Q(w,{children:[Q(`hr`,{}),Q(`button`,{ref:e.row(l++),type:`button`,role:`menuitem`,class:`mi`,tabIndex:-1,onClick:o,children:[Q($,{name:`refresh`}),Q(`span`,{class:`nm`,children:m_.fresh})]})]}),Q(`hr`,{}),Q(`div`,{class:`hd`,children:m_.may}),h_.map(n=>Q(`button`,{ref:e.row(l++),type:`button`,role:`menuitemradio`,class:`mi aperm`,tabIndex:-1,"aria-checked":t.permissions===n.value,"aria-label":n.label,"aria-describedby":`aperm-${n.value}`,onClick:()=>s(n.value),children:[Q(rv,{on:t.permissions===n.value}),Q(`span`,{class:`pm`,children:[Q(`span`,{class:`nm`,children:n.label}),Q(`small`,{id:`aperm-${n.value}`,children:n.hint})]})]},n.value)),t.permissions===`bypass`&&Q(`p`,{class:`awarn`,role:`note`,children:`Bypass: the agent runs every command and edits any file with nothing asked or checked, .rushes and .git included.`}),t.batches.length>0&&Q(`p`,{class:`anote`,children:`Applies from the next Send.`}),Q(`hr`,{}),Q(`div`,{class:`hd`,children:m_.always}),u.length===0&&Q(`p`,{class:`anote`,children:m_.noRules}),u.map(({rule:t,label:n})=>Q(`div`,{class:`mrow arule`,children:[Q(`span`,{class:`nm`,children:n}),Q(`button`,{ref:e.row(l++),type:`button`,role:`menuitem`,class:`mi alink`,tabIndex:-1,"aria-label":`${m_.remove} ${n}`,onClick:()=>c(t),children:m_.remove})]},`${t.kind} ${t.command??``}`)),Q(`hr`,{}),Q(`p`,{class:`anote`,children:m_.footer})]})}var av=e=>e instanceof ti&&e.status===409&&(e.code===`agent_not_signed_in`||e.code===`agent_not_installed`);function ov({status:e,onSetUp:t,menu:n,onStatus:r,toast:i}){let[a,o]=H(null),[s,c]=H(null),l=__(a,e),u=nv(y_(e,l)),d=e=>void K.get(`/api/agent/detect${e?`?fresh=1`:``}`).then(e=>o(e.agents)).catch(()=>void 0);U(()=>d(!1),[]);let f=()=>{c(null),d(!0),u.show(0)},p=G(f);p.current=f,U(()=>{let e=()=>p.current();return n.current=e,()=>{n.current===e&&(n.current=null)}},[n]);let m=async(e,t)=>{try{return r((await K.post(`/api/agent/setup`,e)).status),!0}catch(e){return av(e)&&t?(u.open||f(),c({agent:t,message:e.message})):i(e.message),!1}},h=async e=>{try{r((await e()).status)}catch(e){i(e.message)}},g=async t=>{if(c(null),t===e.agent&&e.on)return u.close(!0);await m({on:!0,agent:t},t)&&u.close(!0)},_=e=>void K.post(`/api/agent/sign-in`,{agent:e}).catch(e=>i(e.message)),v=async()=>{u.close(!0),await h(()=>K.post(`/api/agent/fresh`))},y=t=>void m({on:e.on,permissions:t},e.agent),b=async t=>{let n=e.always.findIndex(e=>e.kind===t.kind&&e.command===t.command),a=b_(e,l,Math.max(0,n));try{r((await K.del(`/api/agent/always`,t)).status),u.focus(a)}catch(e){i(e.message)}},x=f_(e),S=d_(e);return Q(`div`,{class:`agentrow`,children:[Q(`span`,{class:`mwrap`,ref:u.wrap,children:[Q(`button`,{ref:u.button,type:`button`,class:`aname`,"aria-haspopup":S?`menu`:void 0,"aria-expanded":u.open,onClick:()=>u.open?u.close(!1):S?f():t(),children:[Q(`span`,{class:`alabel`,children:x}),S&&Q($,{name:`chev`})]}),u.open&&Q(iv,{menu:u,status:e,agents:l,refused:s,onPick:e=>void g(e),onSignIn:_,onFresh:()=>void v(),onPermissions:y,onRemove:e=>void b(e)})]}),S&&Q(`button`,{type:`button`,role:`switch`,class:`aswitch`,"aria-label":`Send to AI`,"aria-checked":e.on,onClick:()=>void m({on:!e.on},e.agent)})]})}function sv(e){let t=G(!1),[n,r]=H(!1);return W(()=>{t.current=!1,r(!1);let e=setTimeout(()=>{t.current=!0,r(!0)},450);return()=>clearTimeout(e)},[e]),{ready:t,armed:n}}function cv({ask:e,place:t,latest:n,status:r,onStatus:i,toast:a}){let[o,s]=H(!1),c=G(!1),{ready:l,armed:u}=sv(t),d=N_(r.agent),f=I_(e),p=async t=>{if(c.current||!l.current)return;c.current=!0,s(!0);let r=n.current;try{let a=await K.post(`/api/agent/permission/${encodeURIComponent(e.id)}`,{choice:t});n.current===r&&i(a.status)}catch(e){if(e instanceof ti&&e.status===404)return;c.current=!1,s(!1),a(e.message)}};return Q(`section`,{class:`askcard`,"aria-label":f?`${d} ${f}`:d,"aria-busy":o,"data-armed":u?`true`:`false`,children:[Q(`p`,{class:`asklead`,children:d}),f&&Q(`p`,{class:`asktitle`,children:f}),e.command&&Q(`code`,{class:`askcmd`,children:V_(e.command).map(e=>`text`in e?e.text:Q(`span`,{class:`askhid`,children:e.hidden}))}),Q(`div`,{class:`askacts`,children:L_(e).map(e=>Q(`button`,{type:`button`,class:`btn`,disabled:o,onClick:()=>void p(e.choice),children:H_(e.label)},e.choice))})]})}function lv({status:e,onStatus:t,toast:n}){let r=G(e);r.current=e;let i=e.asks.map(e=>e.id);return Q(`div`,{class:`asks`,"aria-live":`polite`,children:e.asks.map((a,o)=>Q(cv,{ask:a,place:R_(i,o),latest:r,status:e,onStatus:t,toast:n},a.id))})}var uv=[[`all`,`All`],[`picture`,Ep.picture],[`voice`,Ep.voice],[`music`,Ep.music],[`sfx`,`Effects`],[`mix`,Ep.mix],[`visuals`,Ep.visuals],[`notes`,Ep.notes],[`assets`,Ep.assets]];function dv(e){return uv.some(([t])=>t===e)}var fv={user:`added by you`,agent:`agent`,rushes:`Rushes`};function pv(e,t){let n=[];for(let r of e){let e=new Date(r.at),i=Np(e),a=n[n.length-1];a&&a.date===i?a.entries.push(r):n.push({key:i,date:i,heading:Pp(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 mv(e,t){return e===`all`||e===t}var hv=new Set([` `,`ArrowLeft`,`ArrowRight`,`ArrowUp`,`ArrowDown`,`Home`,`End`,`PageUp`,`PageDown`]);function gv(e){return hv.has(e.key)&&!e.altKey&&!e.ctrlKey&&!e.metaKey}var _v=[`script`,`picture`,`voice`,`music`,`sfx`,`mix`];function vv(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&&_v.includes(e.tab)?{tab:e.tab}:e.area===`assets`?{tab:`assets`}:_v.includes(e.area)?{tab:e.area}:null}function yv(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 bv(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 xv(e,t){let n=e.by===`user`?`added by you`:e.by===`agent`?`by the agent`:`by Rushes`;return`${e.text} (${Ep[e.area]}, ${t}, ${n})`}function Sv(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 Cv(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 wv(e,t){return`rushes:${e}:${t}`}function Tv(e,t){try{return e?.getItem(t)??null}catch{return null}}function Ev(e,t,n){try{e?.setItem(t,n)}catch{}}function Dv({status:e,notes:t,onNote:n,elsewhere:r}){let[i,a]=H(!1),o=e?c_(e):null;if(!e||!o)return null;if(o===`ended`&&!i)return Q(`div`,{class:`lstrip ended`,children:Q(`button`,{type:`button`,class:`lshow`,"aria-expanded":`false`,onClick:()=>a(!0),children:l_(e.lines.length)})});let s=s_(e,20).filter(e=>e.note===null||!r?.(e.note));return Q(`section`,{class:`lstrip`,"aria-label":`The run`,children:[Q(`h3`,{class:`lhead`,children:[Q(`span`,{class:`lheadtext`,dir:`auto`,children:Qg(e,t)??``}),o===`ended`&&Q(`button`,{type:`button`,class:`lhide`,"aria-expanded":`true`,onClick:()=>a(!1),children:`Hide`})]}),Q(`ul`,{children:s.map((e,r)=>{let i=Mp(new Date(e.at)),a=e.note!==null&&t.some(t=>t.id===e.note),o=Q(w,{children:[Q(`span`,{class:`ltime`,children:i}),Q(`span`,{class:`lline`,dir:`auto`,title:u_(e),children:u_(e)})]});return Q(`li`,{children:a?Q(`button`,{type:`button`,class:`lsrow`,"data-note-line":e.note,onClick:()=>n(e.note),children:o}):Q(`div`,{class:`lsrow`,children:o})},`${e.at}-${r}`)})})]})}var Ov=2e3,kv=()=>document.querySelector(`.monitor:not(.spreview) .frame video`);function Av({n:e,agent:t,version:n,onSeek:r}){let i=i_(U_(e),t.status),a=G(null),o=G(r);if(o.current=r,U(()=>{let t=a.current;if(!t||t.version!==n||(a.current=null,Date.now()-t.at>Ov))return;let r=()=>o.current?.(t.t,e),i=kv();return!i||i.readyState>=1&&i.currentSrc!==t.from?r():(i.addEventListener(`loadedmetadata`,r,{once:!0}),()=>i.removeEventListener(`loadedmetadata`,r))},[n]),!i)return null;let s=J_(i);if(i.kind===`fixed`){let i=q_(e,n);return Q(`div`,{class:`nbadge fixed`,children:[Q($,{name:`check`}),i?Q(`button`,{type:`button`,class:`nfix`,dir:`auto`,onClick:()=>{i?.kind===`seek`?r?.(i.t,e):i?.kind===`jump`&&(a.current=i.t===null?null:{version:i.to.version,t:i.t,from:kv()?.currentSrc??``,at:Date.now()},t.onJump(i.to))},children:s}):Q(`span`,{dir:`auto`,children:s})]})}return Q(`div`,{class:`nbadge ${i.kind}`,children:[i.kind===`working`&&Q($,{name:`spin`,class:`nspin`}),i.kind===`needsYou`&&Q(`span`,{class:`ndot`,"aria-hidden":`true`}),Q(`span`,{dir:`auto`,children:s})]})}function jv({n:e}){let[t,n]=H(!1),{lines:r,more:i}=W_(e,t);return r.length===0?null:Q(`div`,{class:`nthread`,children:[i&&Q(`button`,{type:`button`,class:`nmore`,onClick:()=>n(!0),children:i}),r.map((e,t)=>Q(`div`,{class:`nline ${e.by}`,children:[e.by===`agent`?Q(`span`,{class:`nwho`,role:`img`,"aria-label":`Agent`,children:Q($,{name:`reply`})}):Q(`span`,{class:`nwho`,role:`img`,"aria-label":`You`,children:`Y`}),Q(`span`,{class:`ntext`,dir:`auto`,children:Y_(e.text).map((e,t)=>Q(w,{children:[t>0&&`
|
|
63
|
+
`,e.map(e=>`text`in e?e.text:Q(`span`,{class:`nhid`,children:e.hidden}))]}))}),e.time&&Q(`span`,{class:`ntime`,children:e.time})]},t))]})}var Mv=4;function Nv({n:e,status:t,toast:n,onChanged:r}){let[i,a]=H(``),[o,s]=H(!1),c=G(null),l=G_(U_(e),t);if(W(()=>{let e=c.current;if(!e)return;e.style.height=`auto`;let t=getComputedStyle(e),n=parseFloat(t.lineHeight)||20,r=parseFloat(t.paddingTop)+parseFloat(t.paddingBottom)+parseFloat(t.borderTopWidth)+parseFloat(t.borderBottomWidth),i=n*Mv+r;e.style.height=`${Math.min(e.scrollHeight+parseFloat(t.borderTopWidth)+parseFloat(t.borderBottomWidth),i)}px`,e.style.overflowY=e.scrollHeight+parseFloat(t.borderTopWidth)+parseFloat(t.borderBottomWidth)>i?`auto`:`hidden`},[i,l]),!l)return null;let u=async()=>{let t=i.trim();if(t&&!o){s(!0);try{await K.post(`/api/notes/${e.id}/replies`,{text:t}),a(``),r()}catch(e){n(e.message)}finally{s(!1)}}},d=K_(U_(e),t);return Q(`div`,{class:`nreply`,children:Q(`textarea`,{ref:c,class:`input`,rows:1,"aria-label":d,placeholder:d,"aria-busy":o,value:i,onInput:e=>a(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&!e.isComposing&&(e.preventDefault(),u()),e.key===`Escape`&&e.target.blur()}})})}function Pv({filter:e,onChange:t}){return Q(`span`,{class:`onwrap nfilter`,children:[Q(`select`,{class:`sel`,"aria-label":`Filter notes`,value:e,onChange:e=>{let n=e.target.value;(n===`all`||n===`todo`||n===`done`)&&t(n),e.target.blur()},children:[Q(`option`,{value:`all`,children:`All`}),Q(`option`,{value:`todo`,children:`To do`}),Q(`option`,{value:`done`,children:`Done`})]}),Q($,{name:`chev`})]})}function Fv({filter:e,onChange:t,todo:n}){return Q(`div`,{class:`seg`,role:`group`,"aria-label":`Filter notes`,children:[`all`,`todo`,`done`].map(r=>Q(`button`,{"aria-pressed":e===r,onClick:()=>t(r),children:[r===`all`?`All`:r===`todo`?`To do`:`Done`,r===`todo`&&n>0&&Q(`span`,{class:`n`,children:n})]}))})}var Iv=e=>e.status===`done`?`Reopen`:Zm(Tm(e),`Mark done`),Lv=[{kind:`rise`,label:`Rise`},{kind:`fall`,label:`Fall`},{kind:`louder`,label:`Louder`},{kind:`quieter`,label:`Quieter`}];function Rv({notes:e,version:t,placeholder:n,attachments:r,inputRef:i,toast:a,onAdd:o,onSeek:s,onChanged:c,onTextChange:l,target:u,marks:d,onLabel:f,fixedTimes:p,selectedId:m,formatTag:h,cardExtra:g,formatScope:_,listFooter:v,readOnly:y,instead:b,filter:x,agent:S}){let[C,w]=H(`all`),T=x??C,E=G(null),D=i??E,[O,k]=H(``),[A,j]=H(!1),ee=e.filter(e=>e.status===`todo`).length,M=v?.(T)??null,N=e.map(e=>({n:e,at:p?{t:e.t,tOut:e.tOut,from:null}:De(e,t)})).filter(({n:e})=>T===`all`||e.status===T).sort((e,t)=>(e.at.t??-1)-(t.at.t??-1)),P=async e=>{try{await K.patch(`/api/notes/${e.id}`,{status:e.status===`done`?`todo`:`done`})}catch(e){a(`Couldn't update that note: ${e.message}`)}c()},F=async()=>{let e=O.trim();if(e&&!A){j(!0);try{await o(e),k(``),l?.(!1)}catch(e){a(`Couldn't add the note: ${e.message}`)}finally{j(!1)}}};return Q(`div`,{class:`panel side notes`,role:`region`,"aria-label":`Notes`,children:[x===void 0&&Q(`div`,{class:`ph`,children:Q(Fv,{filter:T,onChange:w,todo:ee})}),Q(`div`,{class:`list`,children:[N.length===0&&Q(`div`,{class:`none`,children:T===`all`?M?`None on this format.`:`No notes yet.`:`Nothing here.`}),N.map(({n:e,at:n})=>Q(`div`,{class:`note${Tm(e)===`todo`?``:` ${Tm(e)}`}${S&&U_(e).needsYou?` needs`:``}`,"data-note":e.id,"aria-current":m===e.id?`true`:void 0,children:[Q(`button`,{class:`chk`,"aria-label":Iv(e),"data-tip":Iv(e),onClick:()=>void P(e),children:Q($,{name:`check`})}),Q(`div`,{class:`nt`,children:[Q(`button`,{class:`t`,onClick:()=>n.t!==null&&s?.(n.t,e),children:Oe(n.t,n.tOut)}),f&&f(e)&&Q(`span`,{class:`on`,children:f(e)}),(()=>{let t=h?.(e)??null;return t&&Q(`span`,{class:`ftag${t===`All`?` all`:``}`,children:t})})(),n.from&&Q(`span`,{class:`from`,children:[`from `,n.from]})]}),Tt(e.marks)&&Q(`div`,{class:`nmarks`,children:Tt(e.marks)}),e.shot&&Q(`div`,{class:`shotref`,children:[`Shot `,nt(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:si(e.grab),alt:`Frame grab`})}),S&&Q(Av,{n:e,agent:S,version:t,onSeek:s}),Q(jv,{n:e}),S&&!y&&Q(Nv,{n:e,status:S.status,toast:a,onChanged:c}),m===e.id&&g&&Q(`div`,{class:`nfmt`,children:g(e)})]},e.id)),M]}),Q(`div`,{class:`comp`,hidden:y,children:[u&&Q(`div`,{class:`row ntarget`,role:`group`,"aria-label":`Note target`,children:[u.menu?Q(`span`,{class:`onwrap`,children:[Q(`select`,{class:`sel ntsel`,"aria-label":`Aim the note at`,value:u.menu.value,onChange:e=>{let t=e.target;u.menu.onChange(t.value),t.blur()},children:u.menu.options.map(e=>Q(`option`,{value:e.value,children:e.label},e.value))}),Q($,{name:`chev`})]}):null,(()=>{let e=u.when??null,t=u.name??(e===null?u.label:``),n=t!==``&&t!==u.menu?.options.find(e=>e.value===u.menu.value)?.label;return e===null&&!n?null:Q(`span`,{class:`ntl`,"data-target":``,children:[e!==null&&Q(`span`,{class:`ntwhen`,children:e}),e!==null&&n&&Q(`span`,{class:`ntsep`,children:` · `}),n&&Q(`span`,{class:`ntname tip-wrap tip-start`,"data-tip":t,children:Q(`span`,{class:`ntclamp`,children:t})})]})})(),u.onClear&&Q(`button`,{type:`button`,class:`btn ghost ib sm ntclear`,"aria-label":`Clear the selection · Esc`,"data-tip":`Clear the selection · Esc`,onClick:u.onClear,children:Q($,{name:`x`})})]}),d&&Q(`div`,{class:`row`,role:`group`,"aria-label":`Marks`,children:Lv.map(({kind:e,label:t})=>{let n=d.value.find(t=>t.kind===e);return Q(`span`,{class:`markc`,children:[Q(`button`,{type:`button`,class:`chip`,"aria-pressed":!!n,onClick:()=>d.onChange(Et(d.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;d.onChange(Dt(d.value,e,Number(n.value))),n.blur()},children:bt.map(e=>Q(`option`,{value:String(e),children:[e,` dB`]}))}),Q($,{name:`chev`})]})]})})}),_&&Q(`div`,{class:`row`,children:Q(Gg,{name:`This note applies to`,label:_.label,width:_.width,height:_.height,value:_.value,onChange:_.onChange,lockedReason:_.lockedReason})}),r&&Q(`div`,{class:`row`,children:r}),Q(`div`,{class:`cbox`,children:[Q(`textarea`,{ref:D,class:`input`,rows:2,"aria-label":`New note`,placeholder:n,value:O,onInput:e=>{let t=e.target.value;k(t),l?.(t.trim()!==``)},onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),F()),e.key===`Escape`&&(O.trim()===``&&u?.onClear?.(),e.target.blur())}}),Q(`button`,{class:`btn primary ib sm send`,"data-tip":`Add note ↵`,"aria-label":`Add note`,onClick:()=>void F(),children:Q($,{name:`send`})})]}),_&&Q(`p`,{class:`fhint`,children:_.hint})]}),y&&b&&Q(`p`,{class:`ninstead`,children:b})]})}var zv=1e3,Bv=40,Vv=new Map,Hv=e=>`${e?.rev??``}:${e?.mark??``}`,Uv=()=>{try{return window.sessionStorage}catch{return}};function Wv({entry:e,to:t,onGo:n}){let r=Mp(new Date(e.at)),i=Q(w,{children:[Q(`span`,{class:`ltime`,children:r}),Q(`span`,{class:`ltag ${e.area}`,children:Ep[e.area]}),Q(`span`,{class:`ltext`,dir:`auto`,children:[e.text,Q(`span`,{class:`lby`,children:fv[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":xv(e,r),onClick:()=>n(t),children:i}):Q(`div`,{class:`lrow`,"data-entry":e.id,children:i})}function Gv({log:e,projectId:t,head:n,project:r,stage:i,film:a,notes:o,toast:s,onJump:c,live:l,onEscape:u}){let[d,f]=H(()=>{let e=Tv(Uv(),wv(t,`log-filter`));return dv(e)?e:`all`}),p=a!==null&&r.videos.length>1?a:null,m=e=>`${t}\n${e}\n${p??``}`,[h,g]=H(()=>Vv.get(m(d))?.view??null),[_,v]=H(null),[y,b]=H(null),x=G(n);x.current=n;let[S,C]=H(``),w=G(null),T=G(null),E=G(null);E.current=h;let D=G(d);D.current=d;let O=G(0),k=()=>(w.current?.scrollTop??0)>Bv,A=t=>{g(t),v(null),D.current===`all`&&t.entries[0]&&e.saw(`${t.entries[0].id}@${t.entries[0].at}`)},j=async(e=!1)=>{let t=++O.current,n=new URLSearchParams({limit:String(zv)}),r=D.current,i=Hv(x.current);r!==`all`&&n.set(`area`,r),p&&n.set(`video`,p);try{let a=await K.get(`/api/log?${n}`);if(Vv.set(m(r),{head:i,view:a}),t!==O.current)return;b(null),!e&&E.current&&k()?v(a):A(a)}catch(e){if(t!==O.current)return;E.current?s(Sv(`read`,e)):b(Sv(`read`,e))}},ee=G(!1);U(()=>{let e=!ee.current;ee.current=!0;let t=Vv.get(m(d));if(e&&t&&t.head===Hv(n)){A(t.view);return}w.current&&(w.current.scrollTop=0),v(null),j(!0)},[d,p]);let M=G(!0);U(()=>{if(M.current){M.current=!1;return}j()},[n?.rev,n?.mark]),W(()=>{e.focusOnOpen&&(T.current?.focus(),e.focused())},[]);let N=async()=>{let e=S.trim();if(e)try{if(await K.post(`/api/log`,{text:e,area:i,...p?{video:p}:{}}),C(``),!mv(d,i)){let e=Ep[i];s(`Added under ${e}. Choose All${uv.some(([e])=>e===i)?` or ${e}`:``} to see it.`)}w.current&&(w.current.scrollTop=0),await j(!0)}catch(e){s(Sv(`add`,e))}},P=e=>{f(e),Ev(Uv(),wv(t,`log-filter`),e)},F=()=>{_&&(A(_),w.current&&(w.current.scrollTop=0),requestAnimationFrame(()=>{let e=w.current?.querySelector(`.lrow`);(e instanceof HTMLButtonElement?e:w.current)?.focus({preventScroll:!0})}))},te=()=>{_&&!k()&&A(_)},I=G(c);I.current=c;let ne=G(e=>I.current(e)).current,re=async()=>{try{s(`Saved to ${(await K.post(`/api/exports/change-log`,{})).path}`)}catch(e){s(Sv(`export`,e))}},L=Np(new Date),ie=Wr(()=>h?h.entries.filter(e=>sr(e,a,r,o)):[],[h,a,r,o]),ae=Wr(()=>h?pv(ie,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(Wv,{entry:e,to:vv(e,r),onGo:ne})},e.id))})]},e.key)):null,[h,ie,r,L]),oe=h&&_?yv(h.entries,_.entries):0,se=h!==null&&h.total===0&&h.undated.length===0,ce=h!==null&&!se&&ie.length===0&&h.undated.length===0;return Q(`div`,{id:`changelog`,class:`activity`,onKeyDown:e=>{if(e.key===`Escape`&&!e.defaultPrevented){e.preventDefault(),e.stopPropagation(),u();return}gv(e)&&e.stopPropagation()},children:[Q(`form`,{class:`dadd`,onSubmit:e=>{e.preventDefault(),N()},children:[Q(`input`,{ref:T,value:S,maxLength:160,placeholder:`Add a line to the log`,"aria-label":`Add a line to the log`,onInput:e=>C(e.target.value)}),Q(`button`,{type:`submit`,class:`btn`,children:`Add`})]}),Q(`div`,{class:`dshow`,children:Q(`span`,{class:`onwrap`,children:[Q(`select`,{class:`sel`,"aria-label":`Show`,value:d,onChange:e=>{let t=e.target.value;dv(t)&&P(t)},children:uv.map(([e,t])=>Q(`option`,{value:e,children:t},e))}),Q($,{name:`chev`})]})}),Q(`div`,{class:`dwrap`,children:[oe>0&&Q(`button`,{type:`button`,class:`dpill`,onClick:F,children:[oe,` new`]}),Q(`div`,{class:`dlist`,ref:w,tabIndex:0,role:`group`,"aria-label":`Entries`,onScroll:te,children:[l,h===null&&!y&&Q(`p`,{class:`dempty`,children:`Loading…`}),h===null&&y&&Q(`p`,{class:`dempty dproblem`,role:`alert`,children:y}),se&&Q(`p`,{class:`dempty`,children:`Nothing yet. Rushes writes a line here whenever a cut, a take or a variant is added.`}),ce&&Q(`p`,{class:`dempty`,children:`Nothing for this filter.`}),ae,h&&h.undated.length>0&&Q(`section`,{class:`dbefore`,"aria-label":`Before the log`,children:[Q(`h3`,{children:`Before the log`}),Q(`ul`,{children:h.undated.map((e,t)=>Q(`li`,{children:e.text},t))})]})]})]}),Q(`div`,{class:`dfoot`,children:[Q(`span`,{children:h?bv(ie.length===h.entries.length?h:{entries:ie,earlier:0,dropped:h.dropped}):``}),Q(`button`,{type:`button`,class:`btn`,onClick:()=>void re(),children:`Export as Markdown`})]})]})}var Kv=le(null);function qv(e){let t=Kr(Kv);return()=>{t&&(!t.shown||t.log.open)?t.revealNotes(()=>e.current?.focus()):e.current?.focus()}}var Jv=`[role="dialog"], [role="menu"], [role="listbox"], .fmtpop.open`;function Yv(e){return e.key!==`Escape`||e.defaultPrevented||document.querySelector(Jv)!==null?!1:!(e.target instanceof Element?e.target:null)?.closest(`.npanel`)}var Xv=`rushes:notes-width`,Zv=`rushes:notes-hidden`;function Qv(e){try{return localStorage.getItem(e)}catch{return null}}function $v(e,t){try{t===null?localStorage.removeItem(e):localStorage.setItem(e,t)}catch{}}var ey=()=>typeof matchMedia==`function`?matchMedia(`(max-width: 1099px)`):null;function ty(){let[e,t]=H(()=>{let e=Number(Qv(Xv));return Qv(Xv)!==null&&Number.isFinite(e)?Math.min(560,Math.max(240,e)):360}),[n,r]=H(()=>Qv(Zv)===`1`),[i,a]=H(!1),[o,s]=H(()=>ey()?.matches??!1);U(()=>{let e=ey();if(!e)return;let t=()=>s(e.matches);return e.addEventListener(`change`,t),()=>e.removeEventListener(`change`,t)},[]);let c=o?i:!n,l=e=>{o?a(e):(r(!e),$v(Zv,e?null:`1`))};return{width:e,setWidth:(e,n)=>{t(e),n&&$v(Xv,e===360?null:String(e))},narrow:o,shown:c,setShown:l,toggle:()=>l(!c)}}var ny=`Hide the notes panel · \\`;function ry({shown:e,onToggle:t,buttonRef:n}){let r=e?`Hide the notes panel · \\`:`Show the notes panel · \\`;return Q(`button`,{ref:n,type:`button`,class:`ibtn ntoggle`,"aria-label":r,"data-tip":r,"aria-pressed":e,onClick:t,children:Q($,{name:`note`})})}function iy(e){let t=Kr(Kv),n=G(null),r=G(null),i=G(null),a=G(null),o=G(null),[s,c]=H(`all`);if(U(()=>{if(!t?.reveal||!t.shown)return;let e=i.current;t.onRevealed(),e&&(e.scrollIntoView({block:`nearest`}),e.focus())},[t?.reveal,t?.shown]),!t)return Q(Rv,{...e});let{log:l,activity:u,send:d,shown:f,narrow:p,agent:m}=t,h=d.count>0||!!d.always,g=d.again&&d.again.count>0?d.again:null,_=l.open?`activity`:`notes`,v=e.notes.filter(e=>e.status===`todo`).length,y=(e,t=!0)=>{e===`activity`!==l.open&&l.setOpen(e===`activity`,t)},b=e=>{if(e.key!==`ArrowLeft`&&e.key!==`ArrowRight`)return;e.preventDefault(),e.stopPropagation();let t=_===`notes`?`activity`:`notes`;y(t,!1),(t===`notes`?n:r).current?.focus()},x=e=>{y(`notes`,!1),c(`all`),requestAnimationFrame(()=>{let t=a.current?.querySelector(`[data-note="${CSS.escape(e)}"]`);t&&(t.scrollIntoView({block:`nearest`}),t.tabIndex=-1,t.focus({preventScroll:!0}))})},S=e=>{let n=o.current;if(!n)return null;let r=Math.round(Math.min(560,Math.max(240,n.right-e)));return t.setWidth(r,!1),r};return Q(`aside`,{class:`npanel${p?` drawer`:``}`,ref:a,"aria-label":`Notes panel`,hidden:!f,children:[!p&&Q(`div`,{class:`nresize`,role:`separator`,"aria-orientation":`vertical`,"aria-label":`Resize the notes panel`,"aria-valuemin":240,"aria-valuemax":560,"aria-valuenow":t.width,tabIndex:0,onPointerDown:e=>{e.button===0&&a.current&&(o.current={right:a.current.getBoundingClientRect().right},e.currentTarget.setPointerCapture(e.pointerId))},onPointerMove:e=>S(e.clientX),onPointerUp:e=>{let n=S(e.clientX);o.current=null,n!==null&&t.setWidth(n,!0)},onDblClick:()=>t.setWidth(360,!0),onKeyDown:e=>{(e.key===`ArrowLeft`||e.key===`ArrowRight`)&&(e.preventDefault(),e.stopPropagation(),t.setWidth(Math.min(560,Math.max(240,t.width+(e.key===`ArrowLeft`?16:-16))),!0))}}),Q(`div`,{class:`ntabs`,children:[Q(`div`,{class:`ntablist`,role:`tablist`,"aria-label":`Notes panel`,children:[Q(`button`,{ref:n,type:`button`,role:`tab`,id:`ntab-notes`,class:`ntab`,"aria-selected":_===`notes`,"aria-controls":`npanel-notes`,tabIndex:_===`notes`?0:-1,onClick:()=>y(`notes`),onKeyDown:b,children:[`Notes`,v>0&&Q(`span`,{class:`n`,children:v})]}),Q(`button`,{ref:r,type:`button`,role:`tab`,id:`ntab-activity`,class:`ntab`,"aria-selected":_===`activity`,"aria-controls":`npanel-activity`,"aria-label":l.dot?`Activity (new entries)`:`Activity`,tabIndex:_===`activity`?0:-1,onClick:()=>y(`activity`),onKeyDown:b,children:[`Activity`,l.dot&&Q(`span`,{class:`cdot`,"aria-hidden":`true`})]})]}),Q(`span`,{class:`sp`}),_===`notes`&&Q(Pv,{filter:s,onChange:c}),p&&Q(`button`,{type:`button`,class:`ibtn`,"aria-label":ny,"data-tip":ny,onClick:()=>t.setShown(!1),children:Q($,{name:`x`})})]}),m&&Q(lv,{...m}),Q(`div`,{class:`ntabpanel`,role:`tabpanel`,id:`npanel-notes`,"aria-labelledby":`ntab-notes`,hidden:_!==`notes`,children:Q(Rv,{...e,filter:s,agent:{status:m?.status??null,onJump:u.onJump}})}),_===`activity`&&Q(`div`,{class:`ntabpanel`,role:`tabpanel`,id:`npanel-activity`,"aria-label":`Activity`,children:Q(Gv,{...u,log:l,live:Q(Dv,{status:m?.status??null,notes:e.notes,onNote:x,elsewhere:e=>{let t=u.film,n=u.notes.find(t=>t.id===e)?.video;return t!==null&&u.project.videos.length>1&&!!n&&n!==t}}),onEscape:()=>r.current?.focus()})}),(h||m||g)&&Q(`div`,{class:`nfoot${m?` agentfoot`:``}`,children:[m&&Q(ov,{...m}),g&&Q(`div`,{class:`sendagain`,role:`status`,children:[Q(`p`,{class:`sendagain-why`,children:[g.count===1?`1 note didn't`:`${g.count} notes didn't`,` reach the agent`,g.why?`: ${g.why}`:``]}),Q(`button`,{type:`button`,class:`btn${h?``:` primary`} sendbtn`,"aria-label":`Send again ${g.count}`,"data-tip":`Hand these notes to the agent again`,onClick:g.onSendAgain,children:[`Send again`,Q(`span`,{class:`count`,children:g.count})]})]}),h&&Q(`button`,{ref:i,type:`button`,class:`btn primary sendbtn`,"aria-label":d.count>0?`Send ${d.count}`:`Send`,"data-tip":`Notes and edits on this film not sent yet, from every tab`,onClick:d.onSend,children:[`Send`,d.count>0&&Q(`span`,{class:`count`,children:d.count})]}),m&&Q(`p`,{class:`awho`,children:p_(m.status)})]})]})}function ay(e,t,n){return t.filter(t=>(t.stage===`voice`||t.stage===`music`||t.stage===`sfx`)&&(!t.video||t.video===n?.id)&&e.noteRow(t)!==null)}function oy({notes:e,version:t,viewsHere:n,ownViews:r,onShow:i,onRestore:a}){let[o,s]=H(!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=De(e,t),s=rr(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:Oe(o.t,o.tOut)}),Q(`span`,{class:`ftag`,children:e.format?ve(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 sy=6e3,cy=e=>/[.!?]$/.test(e)?e:`${e}.`;function ly({video:e,version:t,ffmpeg:n,job:r,broken:i,duration:a,toast:o,onChanged:s,noteProxyJob:c,hidden:l=!1}){let[u,d]=H(!1),[f,p]=H(!1),m=G(new Set);r?.state===`running`&&m.current.add(r.job);let[h,g]=H(null),_=yn({ffmpeg:n,need:t.proxyNeed,broken:i,hasProxy:!!t.proxy,job:r,starting:u,watched:!!r&&m.current.has(r.job)}),v=_===`done`&&r?r.job:null;if(U(()=>{if(!v)return;let e=window.setTimeout(()=>g(v),sy);return()=>clearTimeout(e)},[v]),!n)return null;let y=v&&h===v?`none`:_,b=bn(t.proxyNeed,i),x=r?.state===`running`?r.pct:r?.state===`done`?100:0,S=r?.state===`running`?r:null,C=y===`none`||y===`offer`&&!b||y===`done`&&!t.proxy,T=async()=>{if(!u){d(!0);try{let{job:n}=await K.post(`/api/videos/${encodeURIComponent(e.id)}/versions/${encodeURIComponent(t.id)}/proxy`);m.current.add(n.id),c(n)}catch(e){o(e.message)}finally{d(!1)}}},E=async()=>{if(S&&!f){p(!0);try{let{job:e}=await K.del(`/api/proxy-jobs/${encodeURIComponent(S.job)}`);c(e)}catch(e){e instanceof ti&&e.code===`not_found`?s():o(e.message)}finally{p(!1)}}};return Q(`div`,{class:`proxybar`,hidden:l||C,children:Q(`div`,{class:`proxyrow ${y}`,children:[y===`offer`&&b&&Q(w,{children:[Q(`span`,{class:`why`,children:[Q(`b`,{children:`This cut may play slowly.`}),` `,cy(b)]}),Q(`button`,{class:`btn primary tip-wrap tip-end`,"aria-label":`Create proxy`,"data-tip":mn(t.duration??a),onClick:()=>void T(),children:`Create proxy`})]}),y===`working`&&Q(w,{children:[Q(`span`,{children:`Creating proxy`}),Q(`div`,{class:`pbar`,role:`progressbar`,"aria-label":`Proxy progress`,"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":x,children:Q(`i`,{style:{width:`${x}%`}})}),Q(`span`,{class:`mono`,children:[x,`%`]}),Q(`button`,{class:`btn`,"aria-disabled":!S||f,onClick:()=>void E(),children:`Cancel`})]}),y===`done`&&t.proxy&&Q(w,{children:[Q(`span`,{class:`ok`,children:`✓ Proxy ready`}),Q(`span`,{class:`why`,children:[`Saved to `,Q(`span`,{class:`mono`,children:t.proxy.file}),` (`,it(t.proxy.bytes),`).`]}),Q(`button`,{class:`btn ghost ib`,"aria-label":`Dismiss`,"data-tip":`Dismiss`,onClick:()=>g(v),children:Q($,{name:`x`})})]})]})})}function uy({shots:e,duration:t,t:n,current:r,cutLabel:i,locked:a,onSeek:o,view:s,style:c,sizer:l}){let u=s??th(t),d=e=>rh(e,u),f=e.length>0?e.map((n,i)=>({key:String(n.n),start:n.start,end:e[i+1]?.start??t,short:nt(n.n),label:`${nt(n.n)} ${n.name}`,tag:n.tag,current:r===n.n})):[{key:`cut`,start:0,end:t,short:i,label:i,tag:``,current:!0}];return Q(`div`,{class:`trow ptrack`,role:`group`,"aria-label":`Picture track`,"data-row":`picture`,style:c,children:[Q(`div`,{class:`thead`,children:[Q(`span`,{children:`Picture`}),a&&Q(`span`,{class:`tlock`,role:`img`,"aria-label":`Picture locked`,"data-tip":`Picture locked`,children:Q($,{name:`lock`})})]}),Q(`div`,{class:`tlane`,children:[f.map(e=>Q(`button`,{type:`button`,class:`pblock`,"aria-current":e.current?`true`:void 0,"aria-label":e.label,"data-tip":e.tag?`${e.label} · ${e.tag}`:e.label,style:{left:`${d(e.start)}%`,width:`${Math.max(0,d(e.end)-d(e.start))}%`},onClick:t=>{t.detail>0&&t.currentTarget.blur(),o(e.start)},children:Q(`span`,{class:`plbl`,children:e.short})},e.key)),Q(`span`,{class:`playhead`,style:{left:`${d(n)}%`}})]}),l]})}var dy=[.5,1,2,5,10,15,30,60,120,300,600],fy=e=>`${Math.floor(e/60)}:${String(Math.floor(e%60)).padStart(2,`0`)}${e%1?`.${String(Math.round(e%1*10))}`:``}`;function py({duration:e,t,marks:n,live:r,onSeek:i,onMark:a,view:o}){let s=o??th(e),c=s.end-s.start,l=e=>rh(e,s),u=dy.find(e=>c/e<=8)??dy[dy.length-1],d=[];if(c>0){let t=u/2;for(let n=Math.floor(s.start/t)*t;n<Math.min(e,s.end+t)-1e-6;n+=t)n>=0&&d.push(Math.round(n*1e3)/1e3)}let f=e=>{let t=e.currentTarget.getBoundingClientRect();return t.width?ih((e.clientX-t.left)/t.width,s):0},[p,m]=H(null);return Q(`div`,{class:`ruler`,role:`slider`,"aria-label":`Timeline`,"aria-valuemin":0,"aria-valuemax":e,"aria-valuenow":t,onPointerDown:e=>{e.button===0&&(e.currentTarget.setPointerCapture(e.pointerId),i(f(e)))},onPointerMove:e=>{e.currentTarget.hasPointerCapture(e.pointerId)&&i(f(e)),e.pointerType===`mouse`&&m(f(e))},onPointerLeave:()=>m(null),children:[Q(`span`,{class:`rband`,"aria-hidden":`true`}),d.map(e=>{let t=Math.abs(e/u-Math.round(e/u))<1e-6;return Q(`span`,{class:`rtick${t?` major`:``}`,style:{left:`${l(e)}%`},children:t?Q(`span`,{class:`rlbl`,children:fy(e)}):null},e)}),n.map(e=>e.width!==null&&Q(`span`,{class:`span ${e.status}`,style:{left:`${e.left}%`,width:`${e.width}%`}},`s${e.id}`)),r&&Q(`span`,{class:`span live`,style:{left:`${r.left}%`,width:`${r.width}%`}}),p!==null&&Q(`span`,{class:`rhover`,"aria-hidden":`true`,style:{left:`${l(p)}%`},children:Q(`span`,{class:`rhtc`,children:fy(Math.round(p*10)/10)})}),n.map(e=>Q(`button`,{type:`button`,class:`mk ${e.status}${e.ring?` ring`:``}${e.left<25?` tstart`:e.left>75?` tend`:``}`,"data-note":e.id,style:{left:`${e.left}%`},"data-tip":Zm(e.status,e.title),"aria-label":Zm(e.status,e.title),tabIndex:-1,onPointerDown:e=>e.stopPropagation(),onClick:t=>{t.stopPropagation(),t.detail>0&&t.currentTarget.blur(),a(e.id)}},e.id)),Q(`span`,{class:`playhead`,style:{left:`${l(t)}%`}})]})}function my(e){return e.rev?`${e.path}#${e.rev}`:e.path}function hy(e){return e.modified?e.modified:e.size===null?void 0:String(e.size)}var gy=.05,_y=6e4;function vy(e){return 10**(e/20)}function yy(e){let t=e.some(e=>e.solo),n={};for(let r of e){let e=t?+!!r.solo:+!r.muted;n[r.id]=vy(r.level??0)*e}return n}function by(e,t){return+(e===t)}function xy(e,t){let n={};for(let r of e){let e=t[r.lane];n[r.id]=e===void 0?1:by(e,r.id)}return n}function Sy(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 Cy(e,t,n){return Math.abs(e-t)>1/n+1e-9}function wy(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 Ty(e,t){let n=new Float32Array(Math.max(0,Math.floor(t)));for(let r of e){let e=wy(r,t);for(let t=0;t<n.length;t++)e[t]>n[t]&&(n[t]=e[t])}return n}function Ey(e){return Math.min(_y,Math.max(1,Math.round(e*50)))}function Dy(e,t){return!t||e!==null&&e>Oy}var Oy=900;function ky(e){Oy=e??900}function Ay(e){return e!==null&&e>3456e5}function jy(e,t,n,r=1/0,i=gy){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 My(e,t,n,r){return n&&!r?`play`:!n&&r?`pause`:Math.abs(e-t)>.050000001?`seek`:null}function Ny(e,t){return e.map(e=>e.duration>0?e:{...e,duration:t[my(e)]??0})}function Py(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}function Fy(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 Iy(e){return e.name.trim()||`Untitled cue`}function Ly(e){return`${Iy(e)} at ${Ce(e.t)}`}function Ry(e,t){return`cue ${e} of ${t}`}function zy(e){let t=new Map;for(let n of Fy(e)){let e=Iy(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 By(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 Vy(e){return e.split(/[\\/]/).filter(Boolean).pop()??e}function Hy(e,t){return`${((t>0?Math.min(1,Math.max(0,e/t)):0)*100).toFixed(3)}%`}function Uy(e,t){return`clamp(5px, ${Hy(e,t)}, calc(100% - 5px))`}function Wy(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 Gy(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 Ky=`cue-card`;function qy(){let[e,t]=H(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 Jy(e,t){return{onPointerEnter:n=>e.show(n.currentTarget,t),onPointerLeave:()=>e.hide()}}function Yy({shown:e,onHide:t}){let n=G(null),[r,i]=H(null);if(W(()=>{if(i(null),!e)return;let t=()=>{let t=n.current;if(!t)return;let r=e.anchor.getBoundingClientRect(),a=Gy({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]),W(()=>{e&&!e.anchor.isConnected&&t()}),!e)return null;let a=e.cue;return Q(`div`,{ref:n,id:Ky,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:[Ce(a.t),` · `,Ry(a.n,a.of)]}),a.file!==null&&Q(`span`,{class:`f`,style:{color:a.color},children:a.file})]})}var Xy=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,xh(this,()=>this.stop()),this.set({path:e,playing:!0});try{await n.play()}catch(t){if(this.current.path===e&&this.current.playing)throw Sh(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(),Sh(this),this.current.playing&&this.set({...this.current,playing:!1})}element(){if(!this.el){let e=this.make();e.addEventListener(`ended`,()=>{Sh(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,si);function Zy(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=By(e.key,i.indexOf(r),i.length);a!==null&&(e.preventDefault(),e.stopPropagation(),i[a].focus())}function Qy(){let[e,t]=H(Xy.state());return U(()=>Xy.subscribe(t),[]),e}function $y({id:e,name:t,cues:n,length:r,color:i,card:a,onSeek:o,toast:s}){let c=Fy(n),l=new Map(c.map((e,t)=>[e,t+1])),u=zy(n),[d,f]=H({}),p=Qy();U(()=>()=>Xy.stopIf(e),[e]);let m=async t=>{try{await Xy.toggle(t,e)}catch{s(`Couldn't play ${Vy(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:Uy(s.t,r)},"aria-label":Ly(s),"aria-describedby":p?Ky:void 0,...Jy(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=>Zy(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:Vy(s)})]}),t.moreFiles>0&&Q(`small`,{children:[`+`,t.moreFiles]})]})]},t.name)})})}var eb=0;function tb(){return eb}var nb=3,rb=2;function ib({segments:e,length:t,color:n,from:r=0}){let i=G(null),[a,o]=H({w:0,h:0,dpr:1});U(()=>{let e=i.current;if(!e)return;let t=()=>{let t=e.getBoundingClientRect(),n=window.devicePixelRatio||1;o(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[s,c]=H(0);U(()=>{let e=()=>c(e=>e+1);return window.addEventListener(vr,e),()=>window.removeEventListener(vr,e)},[]);let l=[a,t,r,n,s];for(let t of e)l.push(t.offset,t.duration,t.peaks);return U(()=>{let o=i.current;if(!o||a.w<=0||a.h<=0)return;eb++,o.width=Math.round(a.w*a.dpr),o.height=Math.round(a.h*a.dpr);let s=o.getContext(`2d`);if(!s||(s.setTransform(a.dpr,0,0,a.dpr,0,0),s.clearRect(0,0,a.w,a.h),!(t>0)))return;s.fillStyle=Or(o,n);let c=Math.floor(a.w/nb),l=t*nb/a.w;for(let t=0;t<c;t++){let n=r+t*l,i=n+l,o=-1;for(let t of e){if(!(t.duration>0)||i<=t.offset||n>=t.offset+t.duration)continue;if(!t.peaks||t.peaks.length===0){o=Math.max(o,.04);continue}let e=t.peaks.length,r=Math.max(0,Math.floor((n-t.offset)/t.duration*e)),a=Math.min(e,Math.max(r+1,Math.ceil((i-t.offset)/t.duration*e)));for(let e=r;e<a;e++)o=Math.max(o,t.peaks[e])}if(o<0)continue;let c=Math.max(1.5,Math.min(1,o)*a.h*.92);s.globalAlpha=.9,s.fillRect(t*nb,(a.h-c)/2,rb,c)}},l),Q(`canvas`,{ref:i,class:`wave`,"aria-hidden":`true`})}var ab=2e3,ob=8e3,sb={kind:`none`},cb={kind:`pending`},lb={kind:`none`,silent:!0};async function ub(e,t,n){let r;try{r=await t.fetch(e.peaksUrl,{signal:n})}catch(e){if(n.aborted)throw e;return cb}if(r.status===202)return cb;if(r.status===501)return db(e,t,n);if(r.status===204)return lb;if(r.status!==200)return sb;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))?sb:{kind:`wave`,wave:{peaks:Float32Array.from(t),duration:e.duration}}}catch(e){if(n.aborted)throw e;return sb}}async function db(e,t,n){if(e.size===null||!(e.size<1e8))return sb;try{let r=await e.duration();if(n.aborted)throw new DOMException(`aborted`,`AbortError`);if(r===null||!(r>0)||r>900)return sb;let i=await t.fetch(e.mediaUrl,{signal:n});if(!i.ok)return sb;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)?sb:{kind:`wave`,wave:{peaks:fb(Ty(a,Math.min(ab,s))),duration:o}}}catch(e){if(n.aborted)throw e;return sb}}function fb(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 pb=40,mb=new Map,hb=new Set;function gb(e,t,n,r){return`${e}/${t}/${n}#${r??``}`}function _b(e){return mb.has(e)}function vb(e){return mb.get(e)??null}function yb(e){return hb.has(e)}function bb(e,t,n=!1){for(mb.delete(e),mb.set(e,t),n&&t===null?hb.add(e):hb.delete(e);mb.size>pb;){let e=mb.keys().next().value;mb.delete(e),hb.delete(e)}}function xb(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 Sb=1500,Cb=15e3,wb=15e3,Tb={fetch(e,t){let n=ni();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,ob).decodeAudioData(e),n=[];for(let e=0;e<t.numberOfChannels;e++)n.push(t.getChannelData(e));return{channels:n,duration:t.duration}}};function Eb(e,t,n,r,i){let a=e&&t?gb(e,t.id,t.file,r):``,o=G(i),s=G([]);U(()=>{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),wb)}),[l,u]=H(()=>a&&_b(a)?{key:a,wave:vb(a),silent:yb(a)}:null),d=G(null);return U(()=>{if(!e||!t)return;if(_b(a)){u({key:a,wave:vb(a),silent:yb(a)});return}let r=new AbortController,i,o=Sb,s={peaksUrl:`/api/videos/${encodeURIComponent(e)}/versions/${encodeURIComponent(t.id)}/peaks`,mediaUrl:si(t.file),size:n,duration:c},l=async()=>{d.current=null,clearTimeout(i);let e;try{e=await ub(s,Tb,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,Cb);return}let t=e.kind===`wave`?e.wave:null,n=e.kind===`none`&&e.silent===!0;bb(a,t,n),u({key:a,wave:t,silent:n})};return l(),()=>{r.abort(),clearTimeout(i),d.current=null}},[a]),U(()=>{d.current?.()},[t]),l&&l.key===a?{wave:l.wave,known:!0,silent:l.silent}:{wave:null,known:!1,silent:!1}}var Db=0;typeof location<`u`&&Gt(location.search).test&&(window.__rushesPicture={waveDraws:()=>Db});var Ob=3,kb=2;function Ab({wave:e,length:t,from:n=0}){let r=G(null),[i,a]=H({w:0,h:0,dpr:1});return U(()=>{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);n.observe(e);let i=xb(window,t);return()=>{n.disconnect(),i()}},[]),U(()=>{let a=r.current;if(!a||i.w<=0||i.h<=0)return;Db++,a.width=Math.round(i.w*i.dpr),a.height=Math.round(i.h*i.dpr);let o=a.getContext(`2d`);if(!o)return;o.setTransform(i.dpr,0,0,i.dpr,0,0),o.clearRect(0,0,i.w,i.h);let s=t>0?t:e.duration,c=e.peaks.length;if(!(s>0)||!(e.duration>0)||c===0)return;o.fillStyle=getComputedStyle(a).color;let l=e.duration/c;for(let t=0;t<i.w;t+=Ob){let r=n+t/i.w*s;if(r>=e.duration)break;let a=n+(t+Ob)/i.w*s,u=Math.min(c-1,Math.floor(r/l)),d=Math.min(c,Math.max(u+1,Math.ceil(a/l))),f=0;for(let t=u;t<d;t++)e.peaks[t]>f&&(f=e.peaks[t]);let p=Math.max(1,Math.min(1,f)*i.h);o.fillRect(t,(i.h-p)/2,kb,p)}},[i,e,t,n]),Q(`canvas`,{ref:r,class:`pwave`,"aria-hidden":`true`})}var jb=.03,Mb=.004,Nb=15e3;function Pb(e){return e.buffer?e.buffer.length*e.buffer.numberOfChannels*4:0}var Fb=0;function Ib(){return Fb}var Lb=new Map;function Rb(e){let t=Lb.get(e);return t&&(Lb.delete(e),Lb.set(e,t)),t}function zb(e,t){for(Lb.delete(e),Lb.set(e,t);Lb.size>200;)Lb.delete(Lb.keys().next().value)}function Bb(){let e=Error(`The load was cancelled`);return e.name=`AbortError`,e}function Vb(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),Nb)})}var Hb=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??si,fetch:t.fetch??((e,t)=>fetch(e,t)),probe:t.probe??Vb(n),createMedia:n,raf:t.raf??(e=>requestAnimationFrame(e)),caf:t.caf??(e=>cancelAnimationFrame(e))},e&&(this.ctx=e,Fb++)}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 Py(this.videoDuration,this.resolved())}inspect(){return{playing:this._playing,time:this.time,length:this.length,sources:this.voices.size,gains:xy(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=my({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)my(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=>(Dy(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(Ay(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 Bb();let d;if(u&&!Dy(u.duration,!0)){let e=Rb(t);if(!e){let n=[];for(let e=0;e<u.numberOfChannels;e++)n.push(u.getChannelData(e));e=Ty(n,Ey(u.duration)),zb(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 Bb();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)my(t)===e&&this.holding.delete(t.id);if(this._playing){for(let t of this.resolved())my(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(my)),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+=Pb(e.media);for(;this.idle.size>12||o>268435456;){let[e,t]=this.idle.entries().next().value;o-=Pb(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=xy(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(()=>{}),xh(this,()=>this.pause()),this._playing=!0,this.restart(r),this.startLoop(),this.emitChange()}resume(){if(this.disposed)return;let e=this.ensureContext();e.state===`suspended`&&e.resume().catch(()=>{})}pause(){this._playing&&(this.startOffset=this.time,this._playing=!1,this.stopVoices(),this.pauseStreams(),this.stopLoop(),Sh(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(),Sh(this),this.tickListeners.clear(),this.endedListeners.clear(),this.changeListeners.clear(),this.disposed=!0,this.ctx&&(this.ctx.close().catch(()=>{}),this.ctx=null,Fb--)}}ensureContext(){if(this.disposed)throw Error(`The audio engine was disposed`);return this.ctx||(this.ctx=this.opts.createContext(),Fb++),this.ctx}resolved(){let e={};for(let[t,n]of this.media)e[t]=n.duration;let t=Ny(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+jb;let n=this.resolved(),r=new Map(n.map(e=>[e.id,e]));for(let t of Sy(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+jb),r=this.startOffset+(n-this.startedAt);for(let t of Sy([e],r))this.startVoice(e,n+t.when,t.offset)}startVoice(e,t,n){let r=this.media.get(my(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(my(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=jy(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=xy([e],this.selection)[e.id],r.connect(this.laneNode(e.lane)),t={gain:r,seekedAt:-1/0},this.media.get(my(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+Mb)}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(my(e))&&!this.media.has(my(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)Ub(()=>e(t));if(t>=e){this.pause();for(let e of this.endedListeners)Ub(e);return}this._playing&&this.frame===null&&(this.frame=this.opts.raf(this.tick))};emitChange(){for(let e of this.changeListeners)Ub(e)}};function Ub(e){try{e()}catch(e){console.error(e)}}var Wb=e=>e.map(e=>[e.id,e.lane,e.path,e.rev??``,e.offset,e.duration].join(`\0`)).join(``);function Gb(e,t=null){let n=G(null);n.current||=new Hb;let r=n.current,i=G(!0),[a,o]=H(!1),[s,c]=H(0),[l,u]=H({});return U(()=>{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]),U(()=>{r.setClips(e);let t=new Map(e.map(e=>[my(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,Wb(e)]),U(()=>{r.setVideoDuration(t)},[r,t]),{engine:r,playing:a,length:s,media:l}}var Kb=[`play`,`playing`,`pause`,`seeking`,`seeked`,`waiting`,`canplay`,`ratechange`,`timeupdate`,`ended`,`loadedmetadata`,`durationchange`,`emptied`],qb=3;function Jb(e,t,n){let{engine:r,length:i,media:a}=Gb(t),o=G(t.length>0);o.current=t.length>0;let s=G({});W(()=>{for(let[e,t]of Object.entries(n))s.current[e]!==t&&(s.current[e]=t,r.setLaneGain(e,t))},[r,JSON.stringify(n)]);let[c,l]=H(null);W(()=>{e.current!==c&&l(e.current)});let u=G(-1/0);return U(()=>{let e=c;if(!e)return;let t=t=>{let n=e.duration;r.setVideoDuration(Number.isFinite(n)&&n>0?n:null);let i=!e.paused&&!e.ended&&!e.seeking&&e.readyState>=qb,a=e.currentTime,s=My(a,r.time,i,r.playing);if(s===`play`){if(!o.current||r.length>0&&a>=r.length)return;r.play(a),u.current=performance.now()/1e3}else if(s===`pause`)r.pause(),r.seek(a);else if(s===`seek`){let e=performance.now()/1e3;if(t?.type===`timeupdate`&&i&&e-u.current<.25)return;r.seek(a),u.current=e}};for(let n of Kb)e.addEventListener(n,t);return t(),()=>{for(let n of Kb)e.removeEventListener(n,t)}},[r,c]),U(()=>{let e=()=>{o.current&&r.resume()};return window.addEventListener(`pointerdown`,e,!0),window.addEventListener(`keydown`,e,!0),()=>{window.removeEventListener(`pointerdown`,e,!0),window.removeEventListener(`keydown`,e,!0)}},[r]),{media:a,length:i,engine:r}}var Yb=`rushes:preview`,Xb=.12,Zb=.75;function Qb(e,t,n){try{let r=localStorage.getItem(e),i=Number(r);return r!==null&&r.trim()!==``&&Number.isFinite(i)?Math.min(n,Math.max(t,i)):null}catch{return null}}function $b(e,t,n){let r=G(n);r.current=n,W(()=>e?.attach(t,()=>r.current()),[e,t])}var ex=`rushes:volume`,tx=`rushes:split`,nx=.75,rx=.08;function ix(){try{let e=JSON.parse(localStorage.getItem(ex)??`null`);return{level:typeof e?.level==`number`&&Number.isFinite(e.level)?Math.min(1,Math.max(0,e.level)):1,muted:e?.muted===!0}}catch{return{level:1,muted:!1}}}var ax=()=>Qb(tx,rx,nx);function ox(e,t){try{t===null?localStorage.removeItem(e):localStorage.setItem(e,t)}catch{}}function sx(){let[e,t]=H(ix);return U(()=>ox(ex,JSON.stringify(e)),[e]),[e,t]}function cx(){let[e,t]=H(ax);return{split:e,set:t,keep:e=>{t(e),ox(tx,e===null?null:String(Math.round(e*1e3)/1e3))}}}function lx(){let[e,t]=H(()=>Qb(Yb,Xb,Zb));return{size:e,set:t,keep:e=>{t(e),ox(Yb,e===null?null:String(Math.round(e*1e3)/1e3))}}}function ux({column:e,preview:t,size:n}){let r=G(null),i=()=>{let t=e.current?.getBoundingClientRect().height??0;return t>0?Math.max(Xb,Math.min(Zb,(t-448)/t)):Zb},a=e=>Math.min(i(),Math.max(Xb,e)),o=e=>{let t=r.current;if(!t||t.height<=0)return null;let i=a((e-4-t.top)/t.height);return n.set(i),i},s=()=>{r.current&&(r.current=null,n.size!==null&&n.keep(n.size))},c=()=>{let n=e.current?.getBoundingClientRect(),r=t.current?.getBoundingClientRect();return n&&r&&n.height>0?r.height/n.height:Xb};return Q(`div`,{class:`pvsplit`,role:`separator`,"aria-orientation":`horizontal`,"aria-label":`Resize the preview`,"aria-valuemin":Math.round(Xb*100),"aria-valuemax":Math.round(i()*100),"aria-valuenow":Math.round(Math.min(i(),n.size??c())*100),tabIndex:0,onPointerDown:t=>{let n=e.current;if(!n||t.button!==0)return;let i=n.getBoundingClientRect();r.current={top:i.top,height:i.height},t.currentTarget.setPointerCapture(t.pointerId)},onPointerMove:e=>o(e.clientY),onPointerUp:e=>{let t=o(e.clientY);r.current=null,t!==null&&n.keep(t)},onPointerCancel:()=>s(),onLostPointerCapture:()=>s(),onDblClick:()=>n.keep(null),onKeyDown:e=>{(e.key===`ArrowUp`||e.key===`ArrowDown`)&&(e.preventDefault(),e.stopPropagation(),n.keep(a((n.size??c())+(e.key===`ArrowDown`?.03:-.03))))}})}function dx(e,t=`tlpanel`){return{class:`${t}${e===null?``:` sized`}`,style:e===null?void 0:{height:`${e*100}%`}}}function fx({column:e,split:t}){let n=G(null),r=e=>{let r=n.current;if(!r||r.height<=0)return null;let i=Math.min(nx,Math.max(rx,(r.top+r.height-e)/r.height));return t.set(i),i},i=()=>{n.current&&(n.current=null,t.split!==null&&t.keep(t.split))};return Q(`div`,{class:`tlsplit`,role:`separator`,"aria-orientation":`horizontal`,"aria-label":`Resize the timeline`,"aria-valuemin":Math.round(rx*100),"aria-valuemax":Math.round(nx*100),"aria-valuenow":t.split===null?void 0:Math.round(t.split*100),tabIndex:0,onPointerDown:t=>{let r=e.current;if(!r||t.button!==0)return;let i=r.getBoundingClientRect();n.current={top:i.top,height:i.height},t.currentTarget.setPointerCapture(t.pointerId)},onPointerMove:e=>r(e.clientY),onPointerUp:e=>{let i=r(e.clientY);n.current=null,i!==null&&t.keep(i)},onPointerCancel:()=>i(),onLostPointerCapture:()=>i(),onDblClick:()=>t.keep(null),onKeyDown:n=>{if(n.key!==`ArrowUp`&&n.key!==`ArrowDown`)return;n.preventDefault();let r=e.current,i=r?.querySelector(`.tlpanel`),a=t.split??(r&&i?i.getBoundingClientRect().height/r.getBoundingClientRect().height:rx);t.keep(Math.min(nx,Math.max(rx,a+(n.key===`ArrowUp`?.03:-.03))))}})}function px({t:e,duration:t,playing:n,onToggle:r,onStep:i,rangeLabel:a,onClearRange:o,volume:s,muted:c,onVolume:l,onMute:u,onFullScreen:d,loudness:f}){let p=c||s===0;return Q(`div`,{class:`transport`,role:`group`,"aria-label":`Transport`,children:[Q(`div`,{class:`tleft`,children:[Q(`span`,{class:`tc`,"aria-label":`Timecode`,children:[Ce(e),Q(`small`,{children:[`/ `,Q(`span`,{class:`dur`,children:Ce(t)})]})]}),a&&Q(`span`,{class:`chipx`,children:[Q(`span`,{class:`mono`,children:a}),Q(`button`,{"aria-label":`Clear range`,"data-tip":`Clear range`,onClick:o,children:Q($,{name:`x`})})]})]}),Q(`div`,{class:`tmid`,children:[Q(`button`,{class:`btn ghost ib`,"data-tip":`Back one frame · ←`,"aria-label":`Back one frame · ←`,onClick:()=>i(-1),children:Q($,{name:`prev`})}),Q(`button`,{class:`btn ib tplay`,"data-tip":n?`Pause · Space`:`Play · Space`,"aria-label":n?`Pause · Space`:`Play · Space`,onClick:r,children:Q($,{name:n?`pause`:`play`})}),Q(`button`,{class:`btn ghost ib`,"data-tip":`Forward one frame · →`,"aria-label":`Forward one frame · →`,onClick:()=>i(1),children:Q($,{name:`next`})})]}),Q(`div`,{class:`tright`,children:[f,Q(`button`,{class:`btn ghost ib`,"data-tip":c?`Unmute`:`Mute`,"aria-label":c?`Unmute`:`Mute`,"aria-pressed":c,onClick:e=>{e.detail>0&&e.currentTarget.blur(),u()},children:Q($,{name:p?`mute`:`volume`})}),Q(`input`,{type:`range`,class:`vol`,"aria-label":`Volume`,min:0,max:1,step:.05,value:s,onInput:e=>l(Number(e.currentTarget.value)),onPointerUp:e=>e.currentTarget.blur()}),d&&Q(`button`,{class:`btn ghost ib`,"data-tip":`Full screen · F`,"aria-label":`Full screen · F`,onClick:e=>{e.detail>0&&e.currentTarget.blur(),d()},children:Q($,{name:`expand`})})]})]})}var mx={current:null},hx=e=>e instanceof HTMLElement&&(e.isContentEditable||/^(INPUT|TEXTAREA|SELECT)$/.test(e.tagName));function gx({state:e,assets:t,video:n,notes:r,prompt:i,readOnly:a=!1,toast:o,onChanged:s,onPendingChange:c,clock:l,mixView:u}){let[d,f]=H({level:1,muted:!1}),p=e.project.fps||30,m=G(null);$b(l,n?.id??``,()=>Te(m.current?.time??0,p));let h=$x({state:e,assets:t,video:n,version:null,player:mx,duration:0,monitor:d,toast:o,onChanged:s,keep:u}),{engine:g,length:_}=h;m.current=g,W(()=>{let e=l?.at(n?.id??``)??0;e>0&&g.seek(e)},[]);let[v,y]=H(()=>l?.at(n?.id??``)??0),[b,x]=H(!1);U(()=>g.subscribe(e=>y(e)),[g]),U(()=>g.onChange(()=>x(g.playing)),[g]);let S=G(null),[C,w]=H(!1),T=ay(h,e.notes.notes,n),E=qv(S),D=e=>Km({kind:`mix`,t:e},null,p),O=D(Te(v,p));W(()=>c?.(C),[C]),U(()=>()=>c?.(!1),[]);let k=()=>g.playing?g.pause():g.play(),A=e=>{g.pause(),g.seek(Ee(g.time,p,e,_))},j=G(()=>void 0);j.current=e=>{if(!(hx(e.target)||e.metaKey||e.ctrlKey||e.altKey)){if(e.key===` `){if(Wt(e.target))return;e.preventDefault(),k()}else e.key===`ArrowLeft`?(e.preventDefault(),A(e.shiftKey?-10:-1)):e.key===`ArrowRight`?(e.preventDefault(),A(e.shiftKey?10:1)):e.key.toLowerCase()===`n`&&!a&&(e.preventDefault(),E())}},W(()=>{let e=e=>j.current(e);return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[]);let ee=async e=>{let t=D(Te(g.time,p));await K.post(`/api/notes`,{stage:t.stage,video:n?.id??null,version:null,on:t.on,scope:t.scope,t:t.t,tOut:t.tOut,text:e,marks:[]}),s()};return Q(`div`,{class:`split deskcols`,children:[Q(`div`,{class:`tl`,children:[Q(`div`,{class:`monitor`,children:Q(_x,{prompt:i,toast:o,then:`Until then the takes in use play here together.`})}),Q(px,{t:v,duration:_,playing:b,onToggle:k,onStep:A,rangeLabel:null,onClearRange:()=>void 0,volume:d.level,muted:d.muted,onVolume:e=>f({level:e,muted:e===0&&d.muted}),onMute:()=>f({...d,muted:!d.muted}),loudness:h.inUse?Q(nS,{loudness:h.loudness,balance:h.balance}):null}),Q(`div`,{class:`tlpanel`,children:[Q(`div`,{class:`trow rrow`,children:[Q(`div`,{class:`thead`}),Q(py,{duration:_,t:v,marks:[],live:null,onSeek:e=>g.seek(e),onMark:()=>void 0})]}),Q(tS,{mix:h,duration:_,t:v,onSeek:e=>g.seek(e),notes:[...r,...T]})]})]}),Q(iy,{readOnly:a,notes:[...r,...T],version:null,placeholder:`Note on ${O.label}`,inputRef:S,toast:o,onAdd:ee,onChanged:s,onTextChange:w,onLabel:h.noteLabel,fixedTimes:!0,onSeek:e=>g.seek(e),target:{label:O.label,when:O.when,name:O.name}})]})}function _x({prompt:e,toast:t,then:n}){let r=async()=>{try{await navigator.clipboard.writeText(e),t(`Prompt copied`)}catch{t(`Couldn't reach the clipboard: press ${Sn(navigator.platform)} in the prompt instead`)}};return Q(`div`,{class:`noslate`,role:`region`,"aria-label":`No cut yet`,children:[Q($,{name:`film`}),Q(`h3`,{children:`No cut yet`}),Q(`p`,{children:[Le.picture.unlocks,` `,n]}),Q(`button`,{type:`button`,class:`btn sm`,onClick:()=>void r(),children:[Q($,{name:`copy`}),`Copy prompt for your agent`]})]})}var vx=`rushes:track-heights`;function yx(){try{let e=JSON.parse(localStorage.getItem(vx)??`null`);if(!e||typeof e!=`object`)return null;let t={};for(let[n,r]of Object.entries(e))typeof r==`number`&&Number.isFinite(r)&&(t[n]=Math.min(480,Math.max(24,Math.round(r))));return Object.keys(t).length>0?t:null}catch{return null}}function bx(e){try{e===null?localStorage.removeItem(vx):localStorage.setItem(vx,JSON.stringify(e))}catch{}}function xx(){let[e,t]=H(yx),n=G(null);return{heights:e,box:n,measure:()=>{let e={};return n.current?.querySelectorAll(`[data-row]`).forEach(t=>{e[t.dataset.row]=Math.round(t.getBoundingClientRect().height)}),e},style:t=>e&&e[t]?{height:`${e[t]}px`}:void 0,fit:()=>{t(null),bx(null)},set:(e,n)=>{t(e),n&&bx(e)}}}function Sx(e,t,n){let[r,i]=H(null);U(()=>i(null),[e,n]);let a=r&&e>0?ah(r,e):th(e),o=t=>i(t===null||nh(t,e)?null:ah(t,e)),s=t=>{if(!r)return;let n=ch(a,e,t);n!==a&&i(n)},c=G(t);return U(()=>{t!==null&&c.current!==t&&(c.current=t,s(t))},[t]),{view:a,zoomed:r!==null,set:o,follow:s}}function Cx({view:e,duration:t,t:n,onView:r}){let i=G(null),a=G(null),o=e=>t>0?e/t*100:0,s=n=>r=>{r.button===0&&i.current&&t>0&&(r.stopPropagation(),r.preventDefault(),a.current={grip:n,x:r.clientX,v:e,w:i.current.getBoundingClientRect().width},i.current.setPointerCapture(r.pointerId))},c=e=>{let n=a.current;if(!n||n.w<=0)return;let i=(e.clientX-n.x)/n.w*t,o=eh(t);n.grip===`pan`?r(sh(n.v,t,i)):n.grip===`start`?r(ah({start:Math.min(n.v.start+i,n.v.end-o),end:n.v.end},t)):r(ah({start:n.v.start,end:Math.max(n.v.end+i,n.v.start+o)},t))},l=e.end-e.start;return Q(`div`,{class:`zbar`,children:Q(`div`,{class:`ztrack`,ref:i,onPointerDown:e=>{if(e.button!==0||!i.current||!(t>0))return;let n=i.current.getBoundingClientRect(),a=(e.clientX-n.left)/n.width*t;r(ah({start:a-l/2,end:a+l/2},t))},onPointerMove:c,onPointerUp:()=>a.current=null,onPointerCancel:()=>a.current=null,onLostPointerCapture:()=>a.current=null,children:[Q(`span`,{class:`zplay`,style:{left:`${o(n)}%`},"aria-hidden":`true`}),Q(`div`,{class:`zthumb`,role:`scrollbar`,"aria-label":`Zoom and scroll the timeline. Drag the ends to zoom; double-click to show the whole cut`,"aria-orientation":`horizontal`,"aria-controls":`tltracks`,"aria-valuemin":0,"aria-valuemax":Math.round(t*10)/10,"aria-valuenow":Math.round(e.start*10)/10,tabIndex:0,"data-tip":`Drag to scroll · drag the ends to zoom · double-click for the whole cut`,style:{left:`${o(e.start)}%`,width:`${o(e.end)-o(e.start)}%`},onPointerDown:s(`pan`),onDblClick:()=>r(null),onKeyDown:n=>{(n.key===`ArrowLeft`||n.key===`ArrowRight`)&&(n.preventDefault(),n.stopPropagation(),r(sh(e,t,(n.key===`ArrowLeft`?-1:1)*l*.25)))},children:[Q(`span`,{class:`zgrip start`,onPointerDown:s(`start`),onDblClick:e=>{e.stopPropagation(),r(null)}}),Q(`span`,{class:`zgrip end`,onPointerDown:s(`end`),onDblClick:e=>{e.stopPropagation(),r(null)}})]})]})})}function wx({row:e,name:t,tracks:n}){let r=G(null),i=(t,n)=>({...t,[e]:Math.min(480,Math.max(24,Math.round(n)))});return Q(`div`,{class:`trsz`,role:`separator`,"aria-orientation":`horizontal`,"aria-label":`${t} track height`,"aria-valuemin":24,"aria-valuemax":480,"aria-valuenow":n.heights?.[e],tabIndex:-1,onPointerDown:e=>{e.button===0&&(e.preventDefault(),e.stopPropagation(),r.current={y:e.clientY,base:n.heights??n.measure()},e.currentTarget.setPointerCapture(e.pointerId))},onPointerMove:t=>{let a=r.current;a&&n.set(i(a.base,(a.base[e]??24)+t.clientY-a.y),!1)},onPointerUp:t=>{let a=r.current;r.current=null,a&&n.set(i(a.base,(a.base[e]??24)+t.clientY-a.y),!0)},onPointerCancel:()=>r.current=null,onClick:e=>e.stopPropagation(),onDblClick:e=>{e.stopPropagation(),n.fit()}})}function Tx({tv:e,duration:t,t:n}){let r=r=>i=>{i.detail>0&&i.currentTarget.blur(),e.set(oh(e.view,t,r,n))};return Q(`div`,{class:`trow zrow`,children:[Q(`div`,{class:`thead`,children:[Q(`button`,{type:`button`,class:`tbtn`,"data-tip":`Zoom out · -`,"aria-label":`Zoom out · -`,disabled:!e.zoomed,onClick:r(2),children:Q($,{name:`zoomout`})}),Q(`button`,{type:`button`,class:`tbtn`,"data-tip":`Zoom in · =`,"aria-label":`Zoom in · =`,disabled:t<=0||e.view.end-e.view.start<=Math.min(t,2)+1e-6,onClick:r(.5),children:Q($,{name:`zoomin`})})]}),Q(Cx,{view:e.view,duration:t,t:n,onView:e.set})]})}function Ex(e,t,n){let r=e.currentTarget.querySelector(`.ruler`)?.getBoundingClientRect();if(!r||r.width<=0||!(n>0))return;let i=(e.clientX-r.left)/r.width;if(e.ctrlKey||e.metaKey||e.altKey){e.preventDefault(),t.set(oh(t.view,n,Math.exp(Math.max(-1,Math.min(1,e.deltaY*.01))),ih(i,t.view)));return}let a=e.shiftKey?e.deltaY||e.deltaX:Math.abs(e.deltaX)>Math.abs(e.deltaY)?e.deltaX:0;if(a&&t.zoomed){e.preventDefault();let n=t.view.end-t.view.start;t.set({start:t.view.start+a/r.width*n,end:t.view.end+a/r.width*n})}}function Dx({name:e,control:t}){let[n,r]=H(!1),i=G(null),a=G(null),o=G(null);ev(n,i,e=>{r(!1),e&&a.current?.focus()}),W(()=>{n&&o.current?.focus()},[n]);let{on:s,films:c}=t,l=c.filter(e=>s.includes(e.id)).map(e=>e.name),u=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`}),`Films`]}),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:()=>u(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 Ox(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 K.put(`/api/variants/${encodeURIComponent(e.lane)}/${encodeURIComponent(e.variant)}/films`,{videos:t})}catch(e){r(`Couldn't change its films: ${e.message}`)}i()}}}function kx(e){let t=e.films;if(!t||t.readOnly)return!1;let n=t.films.find(e=>e.here)?.id;return n!==void 0&&t.on.includes(n)&&t.on.length>1}function Ax(e){let t={},n=e=>e!==null&&e.scrollWidth>e.clientWidth;for(let r of e.querySelectorAll(`.take[data-take]`)){let e=r.querySelector(`[data-name]`);(n(e)||e!==null&&jx(r,e))&&(t[r.dataset.take]=`n`)}for(let r of e.querySelectorAll(`.take[data-loose]`)){let e=(n(r.querySelector(`[data-name]`))?`n`:``)+(n(r.querySelector(`[data-meta-text]`))?`m`:``);e&&(t[`l:${r.dataset.loose}`]=e)}for(let r of e.querySelectorAll(`.khd[data-h]`))n(r)&&(t[`h:${r.dataset.h}`]=`h`);return t}function jx(e,t){let n=e.querySelector(`.khead`),r=e.querySelector(`.kslot`),i=e.querySelector(`.khead > .sp`);if(!n||!r||!i||getComputedStyle(r).position!==`absolute`)return!1;let a=parseFloat(getComputedStyle(n).columnGap)||0;return t.scrollWidth>t.clientWidth+i.offsetWidth-r.offsetWidth-a}var Mx=(e,t)=>Object.keys(e).length===Object.keys(t).length&&Object.keys(e).every(n=>e[n]===t[n]);function Nx(e){let{label:t,color:n,sections:r,away:i,loose:a,none:o,length:s,view:c,media:l,selected:u,marks:d,range:f,layers:p,onSelect:m,onPick:h,onUnpick:g,onPutAway:_,toast:v}=e,y=e=>c?rh(e,c):Qm(e,s),b=c&&c.end>c.start&&s>0?s/(c.end-c.start):1,x=G(null),[S,C]=H({}),T=()=>{if(!x.current)return;let e=Ax(x.current);C(t=>Mx(t,e)?t:e)},E=[...r.flatMap(e=>e.items),...i.open?i.items:[]],D=e=>{let t=e.clip?l[my(e.clip)]:void 0;return(t!==void 0&&t!==`error`?`${t.duration}${t.streamed?`s`:``}`:``)+(t===`error`?`b`:``)};W(T,[JSON.stringify([s,r.map(e=>e.heading),E.map(e=>[e.key,e.name,e.details.length>0,e.missing,D(e),e.take.madeFor??``]),i.items.length,a.items.length,a.open?a.items.map(e=>[e.key,e.name,e.meta??``]):null])]),U(()=>{let e=new ResizeObserver(T);return x.current&&e.observe(x.current),document.fonts?.ready.then(T),()=>e.disconnect()},[]);let{shown:O,api:k}=qy(),[A,j]=H({}),[ee,M]=H(new Set),N=e=>M(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),P=r.flatMap(e=>e.items),F=P.find(e=>e.take.inUse)?.key??P[0]?.key??null,te=e=>{if(![`ArrowUp`,`ArrowDown`,`ArrowLeft`,`ArrowRight`,`Home`,`End`].includes(e.key)||e.metaKey||e.ctrlKey||e.altKey)return;e.preventDefault(),e.stopPropagation();let t=[...x.current?.querySelectorAll(`[role="radio"]`)??[]],n=t.indexOf(e.currentTarget);t[e.key===`Home`?0:e.key===`End`?t.length-1:e.key===`ArrowUp`||e.key===`ArrowLeft`?Math.max(0,n-1):Math.min(t.length-1,n+1)]?.focus()},I=e=>Q(`h3`,{class:`khd tip-wrap`,"data-h":e,"data-tip":S[`h:${e}`]?e:void 0,children:e}),ne=(e,t)=>{let r=e.take,i=e.key===u,a=kx(e),o=S[e.key]??``,x=e.clip?l[my(e.clip)]:void 0,C=x!==void 0&&x!==`error`?x:null,T=x===`error`,E=!!C?.streamed,D=C?Math.min(s||C.duration,C.duration):s,O=Fy(e.cues),M=Wy(O),P=Nt(O,s),I=Math.min(A[e.key]??0,Math.max(0,O.length-1)),ne=(t,r)=>({key:`m:${e.key}:${M[r]}`,name:Iy(t),t:t.t,n:r+1,of:O.length,file:t.file??null,color:n}),re=d[e.key]??[],L=!!p?.open(e.key),ie=e=>{let t=e.currentTarget.getBoundingClientRect();if(!(t.width>0))return 0;let n=(e.clientX-t.left)/t.width;return Math.min(s,Math.max(0,c?ih(n,c):n*s))},ae=r.inUse?`In use`:`Use this one`,oe=e.missing?`File not found`:T?`This file won't play in a browser`:null,se=e.details.join(` · `),ce=se!==``&&ee.has(e.key),le=`kd-${e.key}`,ue=[o.includes(`n`)?e.name:null,se||null].filter(Boolean).join(`
|
|
64
|
+
`);return Q(w,{children:[Q(`div`,{class:`trow take${i?` picked`:``}`,role:`group`,"aria-label":e.name,"data-take":e.key,"aria-current":i?`true`:void 0,children:[Q(`div`,{class:`thead khead`,children:[p&&Q(`button`,{type:`button`,class:`chev tip-start`,"aria-expanded":L,"aria-controls":L&&O.length>0?`cl-${e.key}`:void 0,"aria-label":`Layers for ${e.name}`,"aria-description":O.length===0?`No cues in this pass`:void 0,"data-tip":O.length===0?`No cues in this pass`:L?`Hide the layers`:`Show the layers`,disabled:O.length===0,onClick:()=>p.toggle(e.key),children:Q($,{name:`chev`})}),t!==`back`&&Q(`button`,{type:`button`,role:`radio`,class:`kpick tip-start`,"aria-checked":r.inUse,"aria-label":`${ae}: ${e.name}`,"data-tip":ae,tabIndex:e.key===F?0:-1,onKeyDown:te,onClick:t=>{t.stopPropagation(),r.inUse||h(e)}}),Q(`button`,{type:`button`,class:`knm`,"data-player":!0,"aria-label":e.name,"aria-pressed":i,"aria-description":[e.missing?`Missing`:null,se||null].filter(Boolean).join(`. `)||void 0,"data-tip":ue||void 0,onClick:()=>m(e,null),children:[Q(`span`,{"data-name":!0,children:e.name}),e.missing&&Q(Kh,{})]}),Q(`span`,{class:`sp`}),Q(`span`,{class:`kslot`,children:t===null?Q(`button`,{type:`button`,class:`btn ghost sm kput`,onClick:()=>g(e),children:`Unpick`}):Q(`button`,{type:`button`,class:`btn ghost sm kput tip-end`,"aria-label":t===`away`?`Archive`:`Restore`,"data-tip":t===`away`&&a?`Takes it off this film; it stays on its other films`:void 0,onClick:()=>_(e,t===`away`),children:t===`away`?`Archive`:`Restore`})}),E&&Q(`span`,{class:`smk`,"data-tip":`Long file: switching isn't sample-exact`,children:Q($,{name:`stream`})}),se!==``&&Q(`button`,{type:`button`,class:`kinfo`,"aria-label":`Details for ${e.name}`,"aria-expanded":ce,"aria-controls":ce?le:void 0,"data-tip":ce?`Hide the details`:`Details`,onClick:()=>N(e.key),children:Q($,{name:`info`})}),r.madeFor&&Q(`span`,{class:`ktag mono${r.stale?` stale`:``}`,"data-tip":r.stale?`Made for ${r.madeFor}, an older cut`:`Made for ${r.madeFor}`,children:r.madeFor})]}),Q(`div`,{class:`tlane`,onClick:t=>m(e,ie(t)),children:[Q(`div`,{class:`sblock${r.stale?` stale`:``}${oe?` none gone`:``}`,style:oe?{left:`0%`,width:`100%`}:{left:`${y(0)}%`,width:`${y(D)-y(0)}%`},children:oe&&Q(`span`,{class:`slbl`,children:oe})}),e.clip&&Q(ib,{segments:[{offset:0,duration:C?.duration??0,peaks:C?C.peaks:null}],length:c?c.end-c.start:s,from:c?.start,color:n}),O.map((t,r)=>Q(`i`,{class:`cue-tick${k.shown===`m:${e.key}:${M[r]}`?` hot`:``}`,"aria-hidden":`true`,style:{left:`${y(t.t)}%`,color:n},...Jy(k,ne(t,r)),onClick:n=>{n.stopPropagation(),m(e,t.t,t.id)}},`t${M[r]}:${t.t}:${t.name}`)),O.map((t,r)=>{let i=ne(t,r),a=k.shown===i.key;return Q(`button`,{type:`button`,class:`cue${a?` hot`:``}`,"data-cue":t.id,tabIndex:r===I?0:-1,"aria-label":Ly(t),"aria-describedby":a?Ky:void 0,style:{left:`${y(t.t)}%`,color:n,maxWidth:`calc(${(P[r]*b*100).toFixed(3)}% - 8px)`},...Jy(k,i),onFocus:t=>{j(t=>t[e.key]===r?t:{...t,[e.key]:r}),k.show(t.currentTarget,i)},onBlur:()=>k.hide(),onKeyDown:e=>Zy(e,`button.cue`,k),onClick:n=>{n.stopPropagation(),m(e,t.t,t.id)},children:Q(`span`,{children:Iy(t)})},`c${M[r]}:${t.t}:${t.name}`)}),re.map(e=>e.tOut!==null&&Q(`span`,{class:`span ${e.status}`,"data-note":e.id,title:Zm(e.status,e.text),style:{left:`${y(e.t)}%`,width:`${y(e.tOut)-y(e.t)}%`}},`s${e.id}`)),re.map(e=>Q(`span`,{class:`mk ${e.status}`,"data-note":e.id,title:Zm(e.status,e.text),style:{left:`${y(e.t)}%`}},e.id)),f.in!==null&&Q(`span`,{class:`span live`,style:{left:`${y(f.in)}%`,width:`${y(f.out??f.in+Math.max(.2,s/200))-y(f.in)}%`}}),Q(`span`,{class:`playhead`})]})]}),ce&&Q(`p`,{class:`kdetail`,id:le,"data-details-of":e.key,children:se}),L&&O.length>0&&Q($y,{id:`cl-${e.key}`,name:e.name,cues:O,length:s,color:n,card:k,onSeek:(t,n)=>m(e,t,n),toast:v})]},e.key)},re=r.length===0&&i.items.length===0,L=a.items.length,ie=a.items.filter(e=>e.none).length;return Q(`div`,{class:`takes`,ref:x,role:`radiogroup`,"aria-label":t,style:{"--c":n},children:[re&&Q(`p`,{class:`knone`,children:o}),r.map((e,t)=>Q(w,{children:[I(e.heading),e.items.map(e=>ne(e,e.take.inUse?null:`away`))]},`${e.kind}:${t}`)),i.items.length>0&&Q(w,{children:[Q(`div`,{class:`kfold`,"data-fold":`away`,children:[I(`Archived · ${i.items.length}`),i.dot&&Q(`span`,{class:`fdot`,"data-dot":!0,"data-tip":`Open notes`,"aria-label":`Open notes`,role:`img`}),Q(`button`,{type:`button`,class:`btn ghost sm`,"aria-expanded":i.open,onClick:i.onToggle,children:i.open?`Hide`:`Show`})]}),i.open&&i.items.map(e=>ne(e,`back`))]}),L>0&&Q(w,{children:[Q(`div`,{class:`kfold`,"data-fold":`loose`,children:[I(`Not on this film · ${L} ${a.what}${ie?` · ${ie} on no film`:``}`),Q(`span`,{class:`khint`,children:`Use Films to put one on it`}),Q(`button`,{type:`button`,class:`btn ghost sm`,"aria-expanded":a.open,onClick:a.onToggle,children:a.open?`Hide`:`Show`})]}),a.open&&a.items.map(e=>Q(`div`,{class:`trow take loose`,role:`group`,"aria-label":e.name,"data-loose":e.key,children:[Q(`div`,{class:`thead khead`,children:[Q(`span`,{class:`knm tip-wrap`,"data-tip":S[`l:${e.key}`]?.includes(`n`)?e.name:void 0,children:Q(`span`,{"data-name":!0,children:e.name})}),Q(`span`,{class:`sp`}),e.films&&Q(Dx,{name:e.name,control:e.films})]}),Q(`div`,{class:`tlane`,children:Q(`div`,{class:`sblock none`,style:{left:`0%`,width:`100%`},children:Q(`span`,{class:`slbl tip-wrap`,"data-tip":e.meta&&S[`l:${e.key}`]?.includes(`m`)?e.meta:void 0,children:Q(`span`,{"data-meta-text":!0,children:e.meta??``})})})})]},e.key))]}),Q(Yy,{shown:O,onHide:k.hide})]})}var Px=[{tool:`select`,icon:`pointer`,tip:`Select · V`,marks:!1},{tool:`note`,icon:`note`,tip:`Note at the playhead · N`,marks:!0},{tool:`range`,icon:`range`,tip:`Mark a range · I and O`,marks:!0},{tool:`box`,icon:`box`,tip:`Box on the picture · B`,marks:!0},{tool:`grab`,icon:`camera`,tip:`Grab this frame · G`,marks:!0}];function Fx({active:e,readOnly:t,grabbing:n,onSelect:r,onNote:i,onRange:a,onBox:o,onGrab:s,tools:c}){let l={select:r,note:i,range:a,box:o,grab:s};return Q(`div`,{class:`tools`,role:`toolbar`,"aria-label":`Tools`,"aria-orientation":`vertical`,children:Px.filter(({tool:e})=>!c||c.includes(e)).map(({tool:r,icon:i,tip:a,marks:o})=>Q(`button`,{type:`button`,class:`tool`,"data-tip":a,"aria-label":a,"aria-pressed":e===r,"aria-busy":r===`grab`?n:void 0,disabled:t&&o,onClick:e=>{r!==`note`&&e.detail>0&&e.currentTarget.blur(),l[r]()},children:Q($,{name:i})},r))})}var Ix=typeof location>`u`?{test:!1,streamOver:!1}:Gt(location.search);Ix.streamOver&&ky(1);var Lx=Ix.test?{engine:null,inspect(){return this.engine?this.engine.inspect():null},renders:0,panelRenders:0,draws:tb,liveContexts:Ib,sample:()=>Xy.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;Lx&&(window.__rushesAudio=Lx);var Rx=Lx;function zx(e){let{stage:t,groups:n,assets:r,blind:i}=e,a=e=>i?V(e.map(Rm),i.seed).map(t=>e.find(e=>Rm(e)===t)):e,o=Vm(n,a),s=a(n.away),c=new Map,l=0;for(let e of[...o.flatMap(e=>e.takes),...s])c.set(Rm(e),i?`${i.word} ${++l}`:e.variant.name);let u=n=>{let a=Rm(n),o=r.find(e=>e.path===n.variant.file),s=o?.missing===!0;return{take:n,key:a,name:c.get(a),details:i?[]:kt(n.variant.meta,t===`sfx`?n.variant.cues.length:0),missing:s,clip:s?null:{id:a,lane:t,path:n.variant.file,offset:0,duration:0,rev:o?hy(o):void 0},cues:t===`sfx`?n.variant.cues:[],films:e.films(n)}},d=zm(n);return{sections:o.map(e=>({kind:e.kind,heading:e.heading,items:e.takes.map(u)})),away:s.map(u),nameOf:e=>c.get(e)??null,defaultKey:d?Rm(d):null}}var Bx=e=>({lane:e.lane,variant:e.variant.id,films:pr(e.variant)}),Vx=e=>e instanceof HTMLElement&&(e.isContentEditable||/^(INPUT|TEXTAREA|SELECT)$/.test(e.tagName)),Hx={in:null,out:null},Ux={voice:`var(--vo)`,music:`var(--music)`,sfx:`var(--sfx)`},Wx=new Set,Gx=new Set;function Kx({engine:e,children:t}){let[n,r]=H(e.time);return U(()=>(r(e.time),e.subscribe(r)),[e]),Q(w,{children:t(n)})}function qx({engine:e,by:t,children:n}){let[,r]=H(0),i=G(t);return i.current=t,U(()=>{let t=i.current(e.time);return r(e=>e+1),e.subscribe(e=>{let n=i.current(e);n!==t&&(t=n,r(e=>e+1))})},[e]),Q(w,{children:n(e.time)})}function Jx(e){let{stage:t,title:n,list:r,preview:i,fps:a,notes:o,noteRow:s,onLabel:c,targetName:l,rangeMarks:u,toast:d,onChanged:f,onPendingChange:p,onPlayingChange:m,readOnly:h=!1}=e;Lx&&Lx.renders++;let[,g]=H(0),_=e=>{e.has(t)?e.delete(t):e.add(t),g(e=>e+1)},v=Wx.has(t),y=[...r.sections.flatMap(e=>e.items),...v?r.away:[]],b=y.flatMap(e=>e.clip?[e.clip]:[]),[x,S]=H(null),[C,T]=H(16/9),E=i?.version.file;U(()=>{S(null),T(16/9)},[E]);let D=i?i.version.duration??x:null,O=G(null);$b(e.clock,e.film??``,()=>Te(O.current?.time??0,a));let{engine:k,playing:A,length:j,media:ee}=Gb(b,D);O.current=k,W(()=>{let t=e.clock?.at(e.film??``)??0;t>0&&k.seek(t)},[]);let[M,N]=H(null),[P,F]=H(null),te=M?y.find(e=>e.key===M.key)??null:null;W(()=>{M!==null&&te===null&&(N(null),F(null))},[te===null]);let I=te?.key??r.defaultKey??``;W(()=>k.selectVariant(t,I),[k,I]);let[ne,re]=sx();W(()=>k.setLaneGain(t,ne.muted?0:ne.level),[k,ne.muted,ne.level]);let[L,ie]=H(Hx),[ae,oe]=H([]),[se,ce]=H(!1),[le,ue]=H(!1),de=G(null),fe=qv(de),pe=G(null),me=lx(),he=G(null);U(()=>{let e=e=>ue(!!de.current&&e.target===de.current),t=e=>{e.target===de.current&&ue(!1)};return document.addEventListener(`focusin`,e),document.addEventListener(`focusout`,t),()=>{document.removeEventListener(`focusin`,e),document.removeEventListener(`focusout`,t)}},[]);let R=G(e.film);W(()=>{R.current!==e.film&&(R.current=e.film,N(null),F(null),k.pause(),k.seek(e.clock?.at(e.film??``)??0))},[e.film]);let ge=!h&&yt({range:L,marks:ae,hasText:se});W(()=>{p?.(ge)},[ge]),U(()=>()=>p?.(!1),[]),W(()=>m?.(A),[A]),U(()=>()=>m?.(!1),[]);let _e=te??y.find(e=>e.key===r.defaultKey)??null,z=te&&M?.cue&&te.cues.some(e=>e.id===M.cue)?M.cue:null,ve=L.in!==null&&L.out!==null?{t:L.in,tOut:L.out}:null,ye=e=>P===null?z!==null||!!(te&&M?.clicked)||Te(e,a)>0:!P,be=e=>{if(!_e){let r=ve?Oe(ve.t,ve.tOut):Wm(Te(e,a),a);return{stage:t,on:null,scope:ve?`range`:`point`,t:ve?.t??Te(e,a),tOut:ve?.tOut??null,label:`${r} · ${n}`,when:r,name:n}}let r=ve!==null||ye(e),i=r?z:null,o=i?`${_e.key}:${i}`:_e.key,s=l(_e,i);if(ve)return Km({kind:`take`,stage:t,on:o,name:s,t:ve.t,tOut:ve.tOut},null,a);let c=r?i?_e.cues.find(e=>e.id===i).t:Te(e,a):null;return Km({kind:`take`,stage:t,on:o,name:s,t:c},null,a)},xe=t=>{if(L.in!==null&&L.out===null)return`Set an Out point`;let n=be(t);return n.scope===`whole`?`Note on ${e.wholeLabel.toLowerCase()}`:n.scope===`range`?`Note on ${Oe(n.t,n.tOut)}`:`Note at ${Ce(n.t??Te(t,a))}`},Se=()=>{N(null),F(null)},De=Sx(j,null,`${e.film??``}:${i?.version.id??``}`),ke=G(De);ke.current=De;let Ae=G(null),je=G([]),Me=G(null),Ne=G(!1),Pe=G(0),Fe=e=>{let t=k.length,n=ke.current;n?.zoomed&&n.follow(e);let r=n?.zoomed?`${rh(Math.min(e,t),n.view)}%`:`${t>0?Math.min(e,t)/t*100:0}%`;for(let e of je.current)e.style.left=r;let i=Me.current;i&&i.readyState>=1&&!i.seeking&&Cy(i.currentTime,e,a)&&(i.currentTime=Math.min(e,Number.isFinite(i.duration)?i.duration:e)),i&&k.playing&&!Ne.current&&e>Pe.current&&(Ne.current=!0,i.play().catch(()=>void 0)),Pe.current=e},Ie=G(Fe);Ie.current=Fe,W(()=>{je.current=Ae.current?[...Ae.current.querySelectorAll(`.playhead`)]:[],Fe(k.time)}),U(()=>k.subscribe(e=>Ie.current(e)),[k]),U(()=>{let e=Me.current;e&&(Ne.current=!1,A||(e.pause(),Ie.current(k.time)))},[A,E]);let Le=()=>k.playing?k.pause():k.play(),Re=e=>{k.pause(),k.seek(Ee(k.time,a,e,k.length))},ze=e=>k.seek(e),Be=()=>{h||ie({in:Te(k.time,a),out:null})},Ve=()=>{if(h)return;let e=Te(k.time,a),t=L.in??0;if(e<=t)return d(`Out has to come after In`);ie({in:t,out:e})},He=()=>{ie(Hx),oe([])},Ue=L.in!==null&&L.out===null,We=le?`note`:Ue?`range`:`select`,Ge=()=>{Se(),Ue&&He(),de.current&&document.activeElement===de.current&&de.current.blur()},Ke=()=>{let e=pe.current;e&&(document.fullscreenElement?document.exitFullscreen().catch(()=>void 0):e.requestFullscreen?.().catch(()=>d(`Couldn't go full screen`)))},qe=(e,n,r)=>{N({key:e.key,cue:r??null,clicked:n!==null}),F(null),k.selectVariant(t,e.key),n!==null&&k.seek(n)},Je=async(t,n)=>{try{await ii(e.film??void 0,t.take.lane,n)}catch(e){d(`Couldn't ${n===null?`clear`:`set`} the pick: ${e.message}`)}f()},Ye=async(e,t)=>{if(t&&e.films&&kx(e)){let t=e.films,n=t.films.find(e=>e.here).id,r=t.films.filter(e=>e.id!==n&&t.on.includes(e.id)).map(e=>e.name);t.onChange(t.on.filter(e=>e!==n)),d(`Taken off this film. Still on ${r.join(`, `)}.`);return}try{await ai(e.take.lane,e.take.variant.id,t)}catch(e){d(`Couldn't ${t?`archive it`:`restore it`}: ${e.message}`)}f()},Xe=G(()=>void 0);Xe.current=e=>{if(Vx(e.target)||e.metaKey||e.ctrlKey||e.altKey)return;let t=e.key.toLowerCase();if(e.key===` `){if(Wt(e.target))return;e.preventDefault(),Le()}else e.key===`ArrowLeft`?(e.preventDefault(),Re(e.shiftKey?-10:-1)):e.key===`ArrowRight`?(e.preventDefault(),Re(e.shiftKey?10:1)):t===`v`?Ge():Yv(e)?Se():t===`f`&&i?(e.preventDefault(),e.repeat||Ke()):t===`i`?Be():t===`o`?Ve():t===`n`&&!h?(e.preventDefault(),fe()):e.key===`=`||e.key===`+`?(e.preventDefault(),De.set(oh(De.view,j,.5,k.time))):(e.key===`-`||e.key===`_`)&&(e.preventDefault(),De.set(oh(De.view,j,2,k.time)))},W(()=>{let e=e=>Xe.current(e);return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[]),W(()=>{Lx&&(Lx.clips=b)}),U(()=>{if(Lx)return Lx.engine=k,()=>{Lx.engine===k&&(Lx.engine=null)}},[k]);let Ze=async n=>{if(L.in!==null&&L.out===null)throw Error(`set an Out point for the range`);let r=be(k.time);await K.post(`/api/notes`,{stage:t,video:e.film,version:i?.version.id??null,on:r.on,scope:r.scope,t:r.t,tOut:r.tOut,text:n,marks:u&&r.scope===`range`?ae:[]}),ie(Hx),oe([]),f()},B={},Qe=[];for(let e of o){if(e.scope===`whole`||e.t===null)continue;let t=s(e);if(t===null)continue;let n=e.scope===`range`?e.tOut:null;(B[t]??=[]).push({id:e.id,t:e.t,tOut:n,status:Tm(e),text:e.text}),Qe.push({...e,tOut:n})}let $e=new Map(Qe.map(e=>[e.id,e.text])),et=$m(Qe,j,De.view).map(e=>({...e,ring:!1,title:$e.get(e.id)??``})),it=e=>De.zoomed?rh(Math.min(j,Math.max(0,e)),De.view):Qm(e,j),at=L.in===null?null:{left:it(L.in),width:it(L.out??L.in+.2)-it(L.in)},ot=L.in===null?null:L.out===null?`${Ce(L.in)} →`:Oe(L.in,L.out),st=i?i.version.shots.filter(e=>!j||e.start<j):[],ct=[{value:`point`,label:z?`This cue`:`This moment`},{value:`whole`,label:e.wholeLabel}],lt=Q(`div`,{class:`monitor spreview${i?``:` noslot`}`,ref:pe,style:i?{"--ar":String(C)}:void 0,children:i?Q(w,{children:[Q(`div`,{class:`framebox`,children:Q(`div`,{class:`fitbox`,children:Q(`div`,{class:`frame`,style:{aspectRatio:String(C),"--ar":String(C)},children:[Q(`video`,{ref:Me,src:si(i.version.file),muted:!0,playsInline:!0,preload:`auto`,"aria-label":`Picture preview`,onLoadedMetadata:e=>{let t=e.target;Number.isFinite(t.duration)&&S(t.duration),t.videoWidth&&t.videoHeight&&T(t.videoWidth/t.videoHeight),Ie.current(k.time)},onSeeked:()=>Ie.current(k.time),onClick:Le}),Q(Kx,{engine:k,children:e=>{let t=tt(st,Te(e,a));return Q(`div`,{class:`tcover`,children:[`f`,we(e,a),t&&` · shot ${nt(t.n)}`]})}})]})})}),Q(`button`,{type:`button`,class:`spfull`,"data-tip":`Full screen · F`,"aria-label":`Full screen · F`,onClick:e=>{e.detail>0&&e.currentTarget.blur(),Ke()},children:Q($,{name:`expand`})})]}):Q(_x,{prompt:e.prompt,toast:d,then:`Until then the takes play here on their own.`})});return Q(`div`,{class:`split deskcols soundcols${i&&me.size!==null?` pvsized`:``}`,style:i&&me.size!==null?{"--pv":String(me.size),"--ar":String(C)}:void 0,children:[Q(`div`,{class:`tl soundtab`,children:[Q(Kx,{engine:k,children:e=>Q(px,{t:e,duration:j,playing:A,onToggle:Le,onStep:Re,rangeLabel:ot,onClearRange:He,volume:ne.level,muted:ne.muted,onVolume:e=>re({level:e,muted:e===0&&ne.muted}),onMute:()=>re({...ne,muted:!ne.muted})})}),Q(`div`,{class:`kbody`,children:[Q(Fx,{active:We,readOnly:h,grabbing:!1,tools:[`select`,`note`,`range`],onSelect:Ge,onNote:fe,onRange:()=>Ue?Ve():Be(),onBox:()=>void 0,onGrab:()=>void 0}),Q(`div`,{class:`tlpanel takespanel${De.zoomed?` zoomed`:``}`,onWheel:e=>Ex(e,De,j),children:[Q(`div`,{class:`kstick`,children:Q(`div`,{class:`trow rrow`,children:[Q(`div`,{class:`thead`,children:[Q(`span`,{class:`kttl`,children:n}),Q(`span`,{class:`sp`}),e.headerExtra]}),Q(Kx,{engine:k,children:e=>Q(py,{duration:j,t:e,marks:et,live:at,view:De.view,onSeek:ze,onMark:e=>{let t=Qe.find(t=>t.id===e);t?.t!=null&&(k.pause(),ze(t.t))}})})]})}),Q(`div`,{ref:Ae,children:Q(Nx,{label:`${n} takes`,color:Ux[t],sections:r.sections,away:{items:r.away,open:v,dot:o.some(e=>e.status===`todo`&&r.away.some(t=>t.key===s(e))),onToggle:()=>_(Wx)},loose:{...e.loose,open:Gx.has(t),onToggle:()=>_(Gx)},none:e.none,length:j,view:De.zoomed?De.view:void 0,media:ee,selected:te?.key??null,marks:B,range:L,layers:e.layers,onSelect:qe,onPick:e=>void Je(e,e.take.variant.id),onUnpick:e=>void Je(e,null),onPutAway:(e,t)=>void Ye(e,t),toast:d})}),Q(`div`,{class:`kfoot`,children:[i&&Q(Kx,{engine:k,children:e=>Q(uy,{shots:st,duration:j,view:De.view,t:e,current:tt(st,Te(e,a))?.n??null,cutLabel:xp(i.version)||i.version.id,locked:i.locked,onSeek:e=>{k.pause(),ze(rt(e,a))}})}),Q(Kx,{engine:k,children:e=>Q(Tx,{tv:De,duration:j,t:e})})]})]})]})]}),Q(`div`,{class:`soundside`,ref:he,children:[lt,i&&Q(ux,{column:he,preview:pe,size:me}),Q(qx,{engine:k,by:e=>`${be(e).label}\n${xe(e)}`,children:e=>{let t=be(e);return Lx&&Lx.panelRenders++,Q(iy,{notes:o,version:i?.version.id??null,placeholder:xe(e),inputRef:de,toast:d,onAdd:Ze,onChanged:f,onTextChange:ce,fixedTimes:!0,onSeek:e=>k.seek(e),target:{label:t.label,when:t.when,name:t.name,menu:_e&&!ve?{value:t.scope===`whole`?`whole`:`point`,options:ct,onChange:e=>F(e===`whole`)}:void 0,onClear:te||P!==null?Se:void 0},marks:!u||t.scope!==`range`?void 0:{value:ae,onChange:oe},onLabel:c,readOnly:h})}})]})]})}var Yx={vo:`Voice`,music:`Music`,sfx:`Effects`},Xx={vo:{muted:!1,solo:!1},music:{muted:!1,solo:!1},sfx:{muted:!1,solo:!1}},Zx=e=>`${e.lane}/${e.variant.id}`;function Qx(e,t,n){let r=e=>t.find(t=>t.path===e),i=ir(e.picks,n?.id).use,a=mr(e.project.lanes,n?.id,e.project.videos);return $t.map(e=>{let t=Lm(a,en[e],i?.[en[e]],n??void 0),o=t.inUse;if(!o)return{lane:e,groups:t,take:o,clip:null,block:Hm(t).all>0?`waiting`:`none`};let s=o.variant.file,c=r(s);return c?.missing?{lane:e,groups:t,take:o,clip:null,block:`missing`}:{lane:e,groups:t,take:o,clip:{id:`${o.lane}/${o.variant.id}`,lane:e,path:s,offset:0,duration:0,rev:c?hy(c):void 0},block:`take`}})}function $x({state:e,assets:t,video:n,version:r,player:i,duration:a,monitor:o,toast:s,onChanged:c,keep:l}){let u=e=>t.find(t=>t.path===e),d=n?.id,f=Wr(()=>ir(e.picks,d),[e.picks,d]),p=f.use,m=Wr(()=>mr(e.project.lanes,d,e.project.videos),[e.project.lanes,d,e.project.videos]),h=Wr(()=>Qx(e,t,n),[e.picks,e.project,t,n]),g=Wr(()=>h.flatMap(e=>e.clip?[e.clip]:[]),[h]),_=h.some(e=>e.take!==null),[v,y]=H(()=>l?.current??Xx);W(()=>{l&&(l.current=v)},[v]);let b=(e,t)=>y(n=>({...n,[e]:{...n[e],[t]:!n[e][t]}})),x={vo:!1,music:!1,sfx:!1};for(let e of h)x[e.lane]=e.take!==null;W(()=>{y(e=>{let t=$t.filter(t=>!x[t]&&(e[t].muted||e[t].solo));return t.length===0?e:{...e,...Object.fromEntries(t.map(e=>[e,{muted:!1,solo:!1}]))}})},[$t.map(e=>x[e]?`1`:`0`).join(``)]);let[S,C]=H(null),w=S??_,T=f.levels,E=e=>T[en[e]]??0,[D,O]=H(()=>({vo:E(`vo`),music:E(`music`),sfx:E(`sfx`)})),k=G({});U(()=>{O(e=>{let t=!1,n={...e};for(let e of $t){if(k.current[e]!==void 0)continue;let r=E(e);n[e]!==r&&(n[e]=r,t=!0)}return t?n:e})},[Wr(()=>`${d}:${JSON.stringify(T)}`,[d,T])]);let A=e=>{let t=k.current;for(let n of $t){let r=t[n];r&&(window.clearTimeout(r.id),delete t[n],r.send(e))}};U(()=>{let e=()=>A(!0),t=()=>{document.visibilityState===`hidden`&&A(!0)};return window.addEventListener(`pagehide`,e),document.addEventListener(`visibilitychange`,t),()=>{window.removeEventListener(`pagehide`,e),document.removeEventListener(`visibilitychange`,t),A(!1)}},[]);let j=(e,t)=>{let n=cn(t);O(t=>t[e]===n?t:{...t,[e]:n});let r=k.current;r[e]!==void 0&&window.clearTimeout(r[e].id);let i=(t=!1)=>void K.put(`/api/picks`,{video:d,levels:{[en[e]]:n===0?null:n}},{keepalive:t}).then(c,e=>{s(e instanceof ti?e.message:`Couldn't save the level`)});r[e]={id:window.setTimeout(()=>{delete r[e],i()},300),send:i}},[ee,M]=H(!1),N=()=>{if(!ee){for(let e of $t){let t=k.current[e];t&&window.clearTimeout(t.id),delete k.current[e]}M(!0),K.post(`/api/mix/balance`,{video:d}).then(e=>{s(e.summary),c()},e=>s(e instanceof ti?e.message:`Couldn't balance the mix`)).finally(()=>M(!1))}},P=yy($t.map(e=>x[e]?{id:e,...v[e],level:D[e]}:{id:e,level:D[e]})),F=o.muted?0:o.level,{media:te,engine:I,length:ne}=Jb(i,g,Object.fromEntries(Object.entries(P).map(([e,t])=>[e,t*F]))),re=h.map(e=>e.clip&&te[my(e.clip)]===`error`?{...e,block:`broken`}:e),L=$t.some(e=>x[e]&&v[e].solo);W(()=>{Rx&&(Rx.clips=g)}),U(()=>{let e=Rx;if(e)return e.engine=I,()=>{e.engine===I&&(e.engine=null)}},[I]);let ie=r?u(r.file):void 0,ae=Eb(n?.id??null,r,ie?.size??null,ie?hy(ie):void 0,r?.duration??a),oe=r!==null&&!ae.silent&&(ae.known||_);W(()=>{oe||C(null)},[oe]),W(()=>C(null),[r?.id]);let se={vo:!1,music:!1,sfx:!1};for(let e of h)se[e.lane]=e.clip!==null;let ce=_?tn(se,P):[],le=Wr(()=>JSON.stringify({want:ce,film:d,levels:T,clips:g.map(e=>[e.path,e.rev??``])}),[ce.join(`
|
|
65
|
+
`),d,T,g]),[ue,de]=H({kind:`waiting`}),[fe,pe]=H(!1),[me,he]=H(0),R=G(0);U(()=>{let e=++R.current;if(ce.length===0){de({kind:`empty`}),pe(!1);return}de(e=>e.kind===`empty`||e.kind===`timeout`||e.kind===`error`?{kind:`waiting`}:e),pe(!0);let t=window.setTimeout(()=>{K.post(`/api/mix/loudness`,{lanes:ce,video:d}).then(t=>{e===R.current&&de({kind:`result`,result:t})},t=>{e===R.current&&de({kind:t instanceof ti&&t.status===504?`timeout`:`error`})}).finally(()=>{e===R.current&&pe(!1)})},500);return()=>window.clearTimeout(t)},[le,me]),U(()=>()=>void++R.current,[]);let ge=Wr(()=>({music:At(m,`music`),sfx:At(m,`sfx`)}),[m]),_e=e=>ge[e].filter(t=>Jt(p,e,t)&&!u(t.file)?.missing),z={variants:ge,heard:{vo:se.vo,music:_e(`music`),sfx:_e(`sfx`)}},ve=e=>{if(e.on===null||e.stage!==`voice`&&e.stage!==`music`&&e.stage!==`sfx`)return null;let t=e.on;return re.find(n=>n.take&&en[n.lane]===e.stage&&(t===Zx(n.take)||t.startsWith(`${Zx(n.take)}:`)))??null};return{rows:re,media:te,view:v,toggle:b,levels:D,setLevel:j,inUse:_,cut:{shown:oe,wave:ae.wave,known:ae.known},cutMuted:w,toggleCut:()=>C(!w),videoMuted:w||L,loudness:{state:ue,measuring:fe,retry:()=>he(e=>e+1)},balance:{run:N,busy:ee,owned:ar(f),balanced:f.balanced!==void 0},noteLabel:e=>{if(e.stage===`mix`)return on(z,e.on);let t=ve(e);return t?`${Yx[t.lane]} · ${t.take.variant.name}`:null},noteRow:e=>{if(e.stage===`mix`){let t=rn(z,e.on);return t===null||t===`mix`?null:t}return ve(e)?.lane??null},engine:I,length:ne}}var eS={vo:`var(--vo)`,music:`var(--music)`,sfx:`var(--sfx)`};function tS({mix:e,duration:t,t:n,onSeek:r,notes:i=[],view:a,rowStyle:o,sizer:s}){let c=a??th(t),l=e=>rh(e,c),u=e=>{let n=e.currentTarget.getBoundingClientRect();return n.width>0?Math.min(t,Math.max(0,ih((e.clientX-n.left)/n.width,c))):null},d=e=>{let t=u(e);t!==null&&r(t)},{shown:f,api:p}=qy(),[m,h]=H(0);return Q(w,{children:[e.rows.map(a=>{let u=Yx[a.lane],f=a.take,g=a.clip?e.media[my(a.clip)]:void 0,_=g!==void 0&&g!==`error`?g:null,v=_?Math.min(t||_.duration,_.duration):t,y=a.block===`take`?f.variant.name:a.block===`missing`?`File not found`:a.block===`broken`?`This file won't play in a browser`:a.block===`waiting`?`Nothing chosen yet`:`Not started`,b=a.lane===`sfx`&&a.block===`take`?Fy(f.variant.cues):[],x=Wy(b),S=i.filter(t=>t.t!==null&&e.noteRow(t)===a.lane);return Q(`div`,{class:`trow strack${f?``:` idle`}`,role:`group`,"aria-label":`${u} track`,"data-sound":a.lane,"data-row":a.lane,style:{"--c":eS[a.lane],...o?.(a.lane)},children:[Q(`div`,{class:`thead shead`,children:[Q(`i`,{class:`sw`,"aria-hidden":`true`}),Q(`span`,{class:`snm`,children:u}),Q(`span`,{class:`sp`}),f&&Q(w,{children:[Q(`button`,{type:`button`,class:`ms`,"aria-pressed":e.view[a.lane].muted,"aria-label":`Mute ${u}`,"data-tip":`Mute ${u}`,onClick:()=>e.toggle(a.lane,`muted`),children:`M`}),Q(`button`,{type:`button`,class:`ms`,"aria-pressed":e.view[a.lane].solo,"aria-label":`Solo ${u}`,"data-tip":`Solo ${u}`,onClick:()=>e.toggle(a.lane,`solo`),children:`S`}),Q(`label`,{class:`slvl`,"data-tip":`Level for ${u}. Double-click to reset.`,children:[Q(`input`,{type:`range`,min:-24,max:12,step:.5,value:e.levels[a.lane],"aria-label":`${u} level`,"aria-valuetext":`${ln(e.levels[a.lane])} dB`,onInput:t=>e.setLevel(a.lane,Number(t.target.value)),onDblClick:()=>e.setLevel(a.lane,0),onPointerUp:e=>e.currentTarget.blur()}),Q(`span`,{class:`db mono`,children:[ln(e.levels[a.lane]),` dB`]})]})]})]}),Q(`div`,{class:`tlane`,onClick:d,children:[a.block===`take`?Q(w,{children:[Q(`div`,{class:`sblock${f.stale?` stale`:``}`,role:`img`,"aria-label":f.stale?`${f.round} · ${y} · made for an older cut`:`${f.round} · ${y}`,style:{left:`${l(0)}%`,width:`${l(v)-l(0)}%`}}),Q(ib,{segments:[{offset:0,duration:_?.duration??0,peaks:_?_.peaks:null}],length:c.end-c.start,from:c.start,color:eS[a.lane]})]}):Q(`div`,{class:`sblock none${a.block===`missing`||a.block===`broken`?` gone`:``}`,style:{left:`0%`,width:`100%`},children:Q(`span`,{class:`slbl`,children:y})}),b.map((e,t)=>{let n={key:`t:${x[t]}`,name:Iy(e),t:e.t,n:t+1,of:b.length,file:e.file??null,color:eS.sfx},i=p.shown===n.key;return Q(`button`,{type:`button`,class:`cue${i?` hot`:``}`,"data-cue":e.id,tabIndex:t===Math.min(m,b.length-1)?0:-1,"aria-label":Ly(e),"aria-describedby":i?Ky:void 0,style:{left:`${l(e.t)}%`,color:eS.sfx},...Jy(p,n),onFocus:e=>{h(t),p.show(e.currentTarget,n)},onBlur:()=>p.hide(),onKeyDown:e=>Zy(e,`button.cue`,p),onClick:t=>{t.stopPropagation(),r(e.t)},children:Q(`span`,{children:Iy(e)})},`c${x[t]}:${e.t}:${e.name}`)}),S.map(e=>e.tOut===null?Q(`span`,{class:`mk ${Tm(e)}`,"data-note":e.id,title:Zm(Tm(e),e.text),style:{left:`${l(e.t)}%`}},e.id):Q(`span`,{class:`span ${Tm(e)}`,"data-note":e.id,title:Zm(Tm(e),e.text),style:{left:`${l(e.t)}%`,width:`${l(e.tOut)-l(e.t)}%`}},e.id)),Q(`span`,{class:`playhead`,style:{left:`${l(n)}%`}})]}),s?.(a.lane)]},a.lane)}),e.cut.shown&&Q(`div`,{class:`trow strack csound`,role:`group`,"aria-label":`Cut sound track`,"data-row":`cut`,style:{"--c":`var(--pic)`,...o?.(`cut`)},children:[Q(`div`,{class:`thead shead`,children:[Q(`i`,{class:`sw`,"aria-hidden":`true`}),Q(`span`,{class:`snm`,children:`Cut sound`}),Q(`span`,{class:`sp`}),Q(`button`,{type:`button`,class:`ms`,"aria-pressed":e.cutMuted,"aria-label":`Mute Cut sound`,"data-tip":`Mute Cut sound`,onClick:e.toggleCut,children:`M`})]}),Q(`div`,{class:`tlane`,onClick:d,children:[e.cut.wave?Q(w,{children:[Q(`div`,{class:`sblock cut`,style:{left:`0%`,width:`100%`}}),Q(Ab,{wave:e.cut.wave,length:c.end-c.start,from:c.start})]}):Q(`div`,{class:`sblock none`,style:{left:`0%`,width:`100%`},children:Q(`span`,{class:`slbl`,children:e.cut.known?`No waveform`:``})}),Q(`span`,{class:`playhead`,style:{left:`${l(n)}%`}})]}),s?.(`cut`)]}),Q(Yy,{shown:f,onHide:p.hide})]})}function nS({loudness:e,balance:t}){let n=e.state.kind===`timeout`||e.state.kind===`error`;return Q(`div`,{class:`tloud${n?` retry`:``}`,role:`group`,"aria-label":`Loudness`,"aria-busy":e.measuring,onClick:n?e.retry:void 0,children:[fn(e.state).map(e=>Q(`span`,{class:`lcell`,"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:rS[e.id]??e.label})]})),e.measuring&&Q(`span`,{class:`measuring`,"data-measuring":!0,"data-tip":`Measuring`,"aria-label":`Measuring`,children:Q($,{name:`gauge`})}),n&&!e.measuring&&Q(`button`,{type:`button`,class:`btn ghost ib sm`,"data-tip":`Measure again`,"aria-label":`Measure again`,children:Q($,{name:`gauge`})}),t&&Q(`button`,{type:`button`,class:`tbal`,"aria-pressed":t.balanced&&t.owned,"aria-busy":t.busy,disabled:t.busy,"data-tip":t.balanced&&t.owned?`Balanced: new takes are balanced too, until you move a fader`:`Set music and effects against the voice`,onClick:e=>{e.stopPropagation(),t.run()},children:t.busy?`Balancing`:`Balance`})]})}var rS={integrated:`LUFS`,truePeak:`dBTP`,musicUnderVo:`under VO`},iS=[{value:`frame`,label:`This frame`},{value:`mix`,label:`The whole mix`}],aS=e=>e instanceof HTMLElement&&(e.isContentEditable||/^(INPUT|TEXTAREA|SELECT)$/.test(e.tagName));function oS({video:e,version:t,fps:n,notes:r,toast:i,onChanged:a,onPendingChange:o,onMarksPendingChange:s,clock:c,mixView:l,grab:u,onGrabChange:d,playerRef:f,ffmpeg:p=!1,proxyJob:m,noteProxyJob:h,source:g=`proxy`,onSourceChange:_,formats:v=[],format:y=null,formatMissing:b=!1,onPrimarySize:x,onBoxPendingChange:S,onFormatChange:C,readOnly:T=!1,formatSwitch:E,state:D,assets:O}){let k=G(null),A=G(0);W(()=>{A.current=c?.at(e.id)??0},[]),$b(c,e.id,()=>k.current&&Ye.current?Te(k.current.currentTime,n):A.current);let j=G(null),ee=G(null),M=G(null),[N,P]=H(0),[F,te]=H(t.duration??0),I=y?v.find(e=>e.id===y)??null:null,ne=!I||I.primary,re=I??v.find(e=>e.primary)??null,L=re?re.width/re.height:null,ie=y!==null&&v.length>=2,ae=v.find(e=>e.primary)?.id??null,oe=Zn(r,y),se=Qn(r,y),[ce,le]=H(`this`),[ue,de]=H(L??16/9),[fe,pe]=H(!1),[me,he]=H(null),[R,ge]=H({in:null,out:null}),[_e,z]=H(!1),[ve,ye]=H(null),[xe,Se]=H({w:0,h:0}),[ke,Ae]=H(null),[je,Me]=H(null),[Ne,Pe]=H(!1),[Fe,Ie]=H(!1),[Le,Re]=H(`frame`),ze=()=>Re(`frame`),Be=qv(M),[Ve,He]=sx(),Ue=cx(),We=xx(),Ge=Sx(F,N,t.id),Ke=G(null),qe=G(null),Je=G(!1),Ye=G(!1),Xe=G(!0);U(()=>()=>{Xe.current=!1},[]);let Ze=G(t.id);U(()=>{Ze.current=t.id},[t.id]),U(()=>{let e=!T&&(R.in!==null||ke!==null||Ne);return o?.(e),()=>o?.(!1)},[R.in,ke,Ne,T]),W(()=>(s?.(!T&&(R.in!==null||ke!==null)),()=>s?.(!1)),[R.in,ke,T]),U(()=>(ke!==null&&le(`this`),S?.(ke!==null),()=>S?.(!1)),[ke]);let B=G(void 0);U(()=>{he(null),P(0),de(L??16/9),ge({in:null,out:null}),Ae(null),B.current!==void 0&&d(e.id,null),B.current=t.file,Me(null),le(`this`)},[t.file]);let Qe=ke?`this`:ce,$e=n=>be(e.versions.find(e=>e.id===n.version)??t),[et,it]=H({}),at=e=>e.id in et?et[e.id]:e.format,ot=e=>it(t=>{if(!(e in t))return t;let{[e]:n,...r}=t;return r});U(()=>{it(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 st=async(e,t)=>{if(at(e)!==t){it(n=>({...n,[e.id]:t}));try{await K.patch(`/api/notes/${e.id}`,{format:t})}catch(t){ot(e.id),ct.current?.id===e.id&&(ct.current=null),i(`Couldn't change that note: ${t.message}`)}a()}};U(()=>{je&&!oe.some(e=>e.id===je)&&Me(null)},[y,r]);let ct=G(null),lt=G(y);if(lt.current!==y){lt.current=y;let e=document.activeElement,t=e instanceof HTMLElement&&e.closest(`.nfmt`)?e.closest(`.list > .note[data-note]`):null;t&&!ct.current&&(ct.current={id:t.dataset.note,fallback:!0})}W(()=>{let e=ct.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?(ct.current=null,n&&r.focus()):e.fallback&&(ct.current=null,n&&document.querySelector(`.otherrow`)?.focus())},[y,r]);let ut=ne&&!!t.proxy&&g!==`original`,dt=si(ut?t.proxy.file:ne?t.file:I.file),ft=me===dt,pt=G(null),mt=G(null);if(mt.current&&mt.current.src!==dt){let e=k.current;mt.current.cut===t.file?!pt.current&&e&&(pt.current={t:e.error?N:e.currentTime,play:!e.paused&&!e.error}):pt.current=null}mt.current={cut:t.file,src:dt};let ht=G(null),gt=G(null),yt=I?.id??`primary`,bt=G(!0);W(()=>{if(bt.current){bt.current=!1;return}let e=j.current;if(!re||!e)return;let t=re.width/re.height;if(t===ue)return;let n=e.getBoundingClientRect();ht.current={width:n.width,height:n.height},de(t)},[yt]),W(()=>{let e=ht.current,t=j.current;if(ht.current=null,!e||!t)return;gt.current?.cancel(),gt.current=null;let n=t.getBoundingClientRect(),r=typeof matchMedia==`function`&&matchMedia(`(prefers-reduced-motion: reduce)`).matches,i=Xn(e,{width:n.width,height:n.height},r);Gt(location.search).test&&(window.__rushesLastReshape={animated:i!==null,ms:i?160:0}),i&&(gt.current=t.animate(i,{duration:160,easing:`ease-out`}))},[ue]),U(()=>{let e=k.current;if(!e)return;let t=()=>he(dt);return e.error&&t(),e.addEventListener(`error`,t),()=>e.removeEventListener(`error`,t)},[dt]);let xt=G(null);xt.current=!ne&&F>0?F:null;let St=e=>{let t=xt.current;t===null||e.paused||e.currentTime<t||(e.pause(),e.currentTime=t)};U(()=>{if(!fe)return;let e=0,t=()=>{k.current&&(St(k.current),P(k.current.currentTime)),e=requestAnimationFrame(t)};return e=requestAnimationFrame(t),()=>cancelAnimationFrame(e)},[fe]);let Ct=()=>pt.current?.t??k.current?.currentTime??N,wt=()=>Te(Ct(),n),Tt=e=>{let t=k.current;if(!t)return;let n=Math.min(Math.max(0,e),F||t.duration||e);if(pt.current){pt.current.t=n,P(n);return}t.currentTime=n,P(t.currentTime)},Et=()=>{let e=k.current;e&&(e.paused?(xt.current!==null&&e.currentTime>=xt.current-.001&&(e.currentTime=0),e.play().catch(()=>i(`Couldn't play this file`))):e.pause())},Dt=e=>{k.current?.pause(),Tt(Ee(Ct(),n,e,F))},Ot=()=>ge({in:wt(),out:null}),kt=()=>{let e=wt(),t=R.in??0;if(e<=t)return i(`Out has to come after In`);ge({in:t,out:e})},At=()=>ge({in:null,out:null}),jt=R.in!==null&&R.out===null,Mt=Fe?`note`:_e?`box`:jt?`range`:`select`,Nt=()=>{z(!1),ze(),jt&&At(),M.current&&document.activeElement===M.current&&M.current.blur()},Pt=()=>jt?kt():Ot();U(()=>{let e=e=>Ie(!!M.current&&e.target===M.current),t=e=>{e.target===M.current&&Ie(!1)};return document.addEventListener(`focusin`,e),document.addEventListener(`focusout`,t),()=>{document.removeEventListener(`focusin`,e),document.removeEventListener(`focusout`,t)}},[]);let Ft=()=>{let e=Ke.current;e&&(document.fullscreenElement?document.exitFullscreen().catch(()=>void 0):e.requestFullscreen?.().catch(()=>i(`Couldn't go full screen`)))},It=$x({state:D,assets:O,video:e,version:t,player:k,duration:F,monitor:Ve,toast:i,onChanged:a,keep:l}),Lt=ay(It,D.notes.notes,e);U(()=>{let e=k.current;e&&(e.volume=Ve.level,e.muted=Ve.muted||It.videoMuted)},[Ve,It.videoMuted]);let Rt=G(0),[zt,V]=H(0),Bt=async()=>{let r=k.current,o=wt(),s=e.id,c=t.id,l=ne?null:y,u=++Rt.current,f=!1;try{let e=we(o,n),t;if(p){f=!0,V(e=>e+1);let n=await oi(s,c,o,l);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 K.post(`/api/grabs`,{video:s,version:c,frame:e,png:t,...l?{format:l}:{}});if(u!==Rt.current){a();return}i(`Saved to ${m.grab}`),a(),Xe.current&&c===Ze.current&&d(s,m.grab)}catch(e){u===Rt.current&&i(e.message)}finally{f&&Xe.current&&V(e=>e-1)}},Vt=e=>{let t=R.in!==null&&R.out!==null?{t:R.in,tOut:R.out}:null;return Le===`mix`?t?{kind:`mix`,...t}:{kind:`mix`}:t?{kind:`range`,...t}:{kind:`frame`,t:e}},Ht=e=>{let t=Vt(e);return Km(t,tt(tn,t.kind===`frame`||t.kind===`range`?t.t:e),n)},Ut=async r=>{let i=Ht(wt());if(i.stage!==`picture`){await K.post(`/api/notes`,{stage:i.stage,video:e.id,version:t.id,on:i.on,scope:i.scope,t:i.t,tOut:i.tOut,text:r}),At(),Re(`frame`),le(`this`),Ae(null),d(e.id,null),a();return}await K.post(`/api/notes`,{stage:`picture`,video:e.id,version:t.id,scope:i.scope,t:i.t,tOut:i.tOut,frame:we(i.t,n),text:r,box:ke,grab:u,...ie?{format:Qe===`this`?y:null}:{}}),At(),le(`this`),Ae(null),d(e.id,null),a()},Kt=G(()=>void 0);Kt.current=e=>{if(aS(e.target)||e.metaKey||e.ctrlKey||e.altKey)return;let t=e.key.toLowerCase();if(e.key===` `){if(Wt(e.target))return;e.preventDefault(),Et()}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(t===`v`)Nt();else if(Yv(e))ze();else if(t===`f`)e.preventDefault(),e.repeat||Ft();else if(e.key===`=`||e.key===`+`)e.preventDefault(),Ge.set(oh(Ge.view,F,.5,N));else if(e.key===`-`||e.key===`_`)e.preventDefault(),Ge.set(oh(Ge.view,F,2,N));else if(T&&/^[iogbn]$/.test(t))return;else t===`i`?Ot():t===`o`?kt():t===`g`&&!e.repeat?Bt():t===`b`?z(e=>!e):t===`n`&&(e.preventDefault(),Be())},U(()=>{let e=e=>Kt.current(e);return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[]);let qt=(e,t)=>{let n=k.current;return _t(n?.videoWidth??0,n?.videoHeight??0,e,t)},Jt=e=>{let t=ee.current.getBoundingClientRect(),n=qt(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}};U(()=>{let e=ee.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 Yt=e=>{if(!_e)return;let t=Jt(e);e.target.setPointerCapture(e.pointerId),ye({x0:t.x,y0:t.y,x1:t.x,y1:t.y,w:t.w,h:t.h})},Xt=e=>{if(!ve)return;let t=Jt(e);ye({...ve,x1:t.x,y1:t.y})},Zt=e=>{if(!ve)return;let t=Jt(e),n=vt(ve.x0,ve.y0,t.x,t.y,ve.w,ve.h);ye(null),z(!1),Je.current=!0,n.w>.01&&n.h>.01&&Ae(n)},Qt=ve?vt(ve.x0,ve.y0,ve.x1,ve.y1,ve.w,ve.h):null,$t=qt(xe.w,xe.h),en=e=>({left:`${e.x*100}%`,top:`${e.y*100}%`,width:`${e.w*100}%`,height:`${e.h*100}%`}),tn=F?t.shots.filter(e=>e.start<F):t.shots,nn=tt(tn,Te(N,n)),rn=[...oe,...Lt].map(e=>({n:e,at:De(e,t.id)})).filter(({at:e})=>e.t!==null),an=new Map(rn.map(({n:e})=>[e.id,e])),on=$m(rn.map(({n:e,at:t})=>({...e,t:t.t,tOut:t.tOut})),F,Ge.view).map(e=>{let t=an.get(e.id),n=nr(t,ie);return{...e,ring:ie&&t.format===null,title:n?`${n} · ${t.text}`:t.text}}),sn=e=>rh(Math.min(F,Math.max(0,e)),Ge.view),cn=R.in===null?null:{left:sn(R.in),width:sn(R.out??R.in+.2)-sn(R.in)},ln=(e,t)=>{k.current?.pause(),Tt(t),Me(e.id)},un=oe.find(e=>e.id===je)??null,dn=un?.box&&(!un.version||un.version===t.id)&&$n(un,y,ae)?un.box:null,fn=R.in===null?null:R.out===null?`${Ce(R.in)} →`:Oe(R.in,R.out),pn=Ht(Te(N,n)),mn=R.in!==null&&R.out===null?`Set an Out point`:pn.stage===`picture`?`Note at ${fn&&R.out!==null?fn:Ce(N)}`:`Note on ${pn.label}`,hn=e=>{te(ne?e.duration||t.duration||0:t.duration??I?.duration??(e.duration||0)),ne&&t.width===null&&e.videoWidth&&e.videoHeight&&x?.(t.file,e.videoWidth,e.videoHeight),he(e=>e===dt?null:e),e.videoWidth&&e.videoHeight&&de(e.videoWidth/e.videoHeight),Ye.current||(Ye.current=!0,A.current&&(e.currentTime=Math.min(A.current,e.duration||A.current),P(e.currentTime)));let n=pt.current;n&&(pt.current=null,e.currentTime=Math.min(n.t,e.duration||n.t),P(n.t),n.play&&e.play().catch(()=>void 0))},gn=e=>Ex(e,Ge,F),_n=(e,t)=>({...e,class:`${e.class} ${t}`}),vn=t=>{t!==g&&_?.(e.id,t)};return Q(`div`,{class:`split deskcols`,children:[Q(`div`,{class:`tl`,ref:qe,children:[Q(`div`,{class:`monitor`,ref:Ke,children:[Q(Fx,{active:Mt,readOnly:T,grabbing:zt>0,onSelect:Nt,onNote:Be,onRange:Pt,onBox:()=>z(e=>!e),onGrab:()=>void Bt()}),Q(`div`,{class:`framebox`,children:[Q(`div`,{class:`fitbox`,children:Q(`div`,{class:`frame`,ref:j,style:{aspectRatio:String(ue),"--ar":String(ue)},children:[b&&!ne&&Q(`div`,{class:`msg`,children:`File not found`}),ft&&!ne&&!b&&Q(`div`,{class:`msg`,children:`This file won't play in a browser. Ask your agent for an H.264 MP4 of this format.`}),ft&&ne&&!p&&Q(`div`,{class:`msg`,children:`This file won't play in a browser. Ask your agent for an H.264 MP4 of this cut.`}),ft&&ne&&p&&t.proxy&&!ut&&Q(`div`,{class:`msg`,children:`This file won't play in a browser.`}),Q(`video`,{hidden:ft||b&&!ne,ref:e=>{k.current=e,f&&(f.current=e),e&&e.readyState>=1&&hn(e)},src:dt,preload:`auto`,playsInline:!0,onLoadedMetadata:e=>hn(e.target),onTimeUpdate:e=>{let t=e.target;St(t),!fe&&!pt.current&&P(t.currentTime)},onSeeked:e=>!pt.current&&P(e.target.currentTime),onPlay:()=>pe(!0),onPause:()=>pe(!1),onEnded:()=>pe(!1)}),Q(`div`,{ref:ee,class:`overlay${_e?` drawing`:``}`,onPointerDown:Yt,onPointerMove:Xt,onPointerUp:Zt,onClick:()=>{Je.current?Je.current=!1:_e||Et()},children:Q(`div`,{class:`pic`,style:{left:`${$t.x}px`,top:`${$t.y}px`,width:`${$t.w}px`,height:`${$t.h}px`},children:[dn&&Q(`div`,{class:`bx saved`,style:en(dn)}),ke&&Q(`div`,{class:`bx`,style:en(ke)}),Qt&&Q(`div`,{class:`bx`,style:en(Qt)})]})}),Q(`div`,{class:`tcover`,children:[`f`,we(N,n),nn&&` · shot ${nt(nn.n)}`]}),t.proxy&&ne&&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":ut,"aria-label":`Proxy`,"data-tip":`Playing the lightweight copy. Notes and timings are the same.`,onClick:e=>{e.currentTarget.blur(),vn(`proxy`)},children:`Proxy`}),Q(`button`,{type:`button`,class:`tip-below tip-start tip-wrap`,"aria-pressed":!ut,"aria-label":`Original`,"data-tip":`Play the full-quality file. It may stutter.`,onClick:e=>{e.currentTarget.blur(),vn(`original`)},children:`Original`})]})]})}),E&&Q(`div`,{class:`monfmt`,children:E}),h&&Q(ly,{hidden:!ne,video:e,version:t,ffmpeg:p,job:m,broken:ft&&!ut,duration:F,toast:i,onChanged:a,noteProxyJob:h},t.id)]})]}),Q(px,{t:N,duration:F,playing:fe,onToggle:Et,onStep:Dt,rangeLabel:fn,onClearRange:At,volume:Ve.level,muted:Ve.muted,onVolume:e=>He({level:e,muted:e===0&&Ve.muted}),onMute:()=>He({...Ve,muted:!Ve.muted}),onFullScreen:Ft,loudness:It.inUse?Q(nS,{loudness:It.loudness,balance:It.balance}):null}),Q(fx,{column:qe,split:Ue}),Q(`div`,{..._n(dx(Ue.split??.4),`deskpanel${Ge.zoomed?` zoomed`:``}`),onWheel:gn,children:[Q(`div`,{class:`trow rrow`,children:[Q(`div`,{class:`thead`,children:Q(`button`,{type:`button`,class:`tbtn`,"data-tip":`Fit the tracks to the panel`,"aria-label":`Fit the tracks to the panel`,"aria-pressed":We.heights===null,onClick:e=>{e.detail>0&&e.currentTarget.blur(),We.fit()},children:Q($,{name:`fitrows`})})}),Q(py,{duration:F,t:N,marks:on,live:cn,view:Ge.view,onSeek:Tt,onMark:e=>{let t=rn.find(({n:t})=>t.id===e);t&&ln(t.n,t.at.t)}})]}),Q(`div`,{id:`tltracks`,class:`tracks${We.heights===null?` fitted`:``}`,ref:We.box,children:[Q(tS,{mix:It,duration:F,t:N,onSeek:Tt,notes:[...oe,...Lt],view:Ge.view,rowStyle:We.style,sizer:e=>Q(wx,{row:e,name:e===`vo`?`Voice`:e===`music`?`Music`:e===`sfx`?`Effects`:`Cut sound`,tracks:We})}),Q(uy,{shots:tn,duration:F,t:N,current:nn?.n??null,cutLabel:xp(t)||t.id,locked:e.lockedVersion===t.id,onSeek:e=>{k.current?.pause(),Tt(rt(e,n))},view:Ge.view,style:We.style(`picture`),sizer:Q(wx,{row:`picture`,name:`Picture`,tracks:We})})]}),Q(Tx,{tv:Ge,duration:F,t:N})]})]}),Q(iy,{readOnly:T,notes:[...oe,...Lt],version:t.id,selectedId:je,placeholder:mn,inputRef:M,toast:i,onAdd:Ut,onChanged:a,onTextChange:Pe,onLabel:It.noteLabel,target:{label:pn.label,when:pn.when,name:pn.name,menu:{value:Le,options:iS,onChange:e=>Re(e===`mix`?`mix`:`frame`)},onClear:Le===`mix`?ze:void 0},formatTag:e=>nr(e,ie),cardExtra:ie&&I?e=>Q(Gg,{name:`Note applies to`,label:I.label,width:I.width,height:I.height,value:at(e)===null?`all`:`this`,lockedReason:e.box?er:null,onChange:t=>void st(e,t===`all`?null:I.id)}):void 0,formatScope:ie&&I?{label:I.label,width:I.width,height:I.height,value:Qe,onChange:le,lockedReason:ke?er:null,hint:tr(I.label,Qe,ke!==null)}:void 0,listFooter:e=>{let n=se.filter(t=>e===`all`||t.status===e);return n.length>0?Q(oy,{notes:n,version:t.id,viewsHere:v,ownViews:$e,onShow:(e,t)=>{ke||(ct.current={id:t.id,fallback:!1}),C?.(e)},onRestore:e=>{ct.current={id:e.id,fallback:!1},st(e,null)}}):null},onSeek:(e,t)=>ln(t,e),attachments:(ke||u)&&Q(w,{children:[ke&&Q(`span`,{class:`chipx`,children:[Q($,{name:`box`}),`Box`,Q(`button`,{"aria-label":`Remove box`,onClick:()=>Ae(null),children:Q($,{name:`x`})})]}),u&&Q(`span`,{class:`chipx`,children:[Q($,{name:`image`}),`Frame `,u.match(/_f(\d+)\.png$/)?.[1],Q(`button`,{"aria-label":`Remove frame`,onClick:()=>d(e.id,null),children:Q($,{name:`x`})})]})]})})]})}var sS=500,cS=(e,t)=>e.slice(0,t).filter(n=>n.heading===e[t].heading).length,lS=e=>String(e).padStart(2,`0`);function uS({shot:e,large:t}){let[n,r]=H(null);return!e.still||n===e.still?Q(`span`,{class:`nostill`,children:t?`No still for this shot yet`:`No still`}):Q(`img`,{src:si(e.still),alt:`Still for shot ${e.n}, ${e.name}`,onError:()=>r(e.still)})}function dS({shot:e,save:t,onZoom:n}){let[r,i]=H(e.description),[a,o]=H(e.direction),s=G(!1);U(()=>{s.current||i(e.description)},[e.description]),U(()=>{s.current||o(e.direction)},[e.direction]);let c=()=>{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)},l=Og(()=>{s.current=!1,c()},sS),u=Og(()=>{s.current=!1,c()},sS),d=[];r.trim()!==e.current.trim()&&d.push({text:e.current}),a.trim()!==e.directionCurrent.trim()&&d.push({label:`Direction`,text:e.directionCurrent});let f=d.length>0,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 the still for shot ${e.n}`,onClick:n,children:Q(uS,{shot:e})}),Q(`div`,{class:`sbmeta`,children:[Q(`b`,{children:lS(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:`pbody`,children:[Q(`b`,{class:`sbname`,children:e.name}),Q(Ng,{label:`Your version of shot ${e.n}`,value:r,onInput:e=>{s.current=!0,i(e),l.schedule()},onBlur:()=>l.flush()}),f&&Q(Pg,{baseline:d,revertLabel:`Revert shot ${e.n}`,onRevert:()=>{s.current=!1,i(e.current),o(e.directionCurrent),t.shot(e,{description:e.current,direction:e.directionCurrent})}})]}),Q(`div`,{class:`sblow`,children:[Q(`input`,{class:`dirin sbdir`,placeholder:`Direction`,"aria-label":`Direction for shot ${e.n}`,value:a,onInput:e=>{s.current=!0,o(e.target.value),u.schedule()},onBlur:()=>u.flush()}),Q(`button`,{class:`btn ib okd${p?` on`:``}`,"data-tip":`Approve shot ${e.n}`,"aria-label":`Approve shot ${e.n}`,"aria-pressed":p,onClick:()=>t.shot(e,{status:p?`draft`:`approved`}),children:Q($,{name:`check`})})]})]})}function fS({shot:e,onClose:t}){let n=G(null);return W(()=>{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(uS,{shot:e,large:!0})}),Q(`div`,{class:`sblcap`,children:[Q(`b`,{children:[lS(e.n),` · `,e.name]}),` `,e.tag&&Q(`span`,{class:`sbtag`,children:e.tag}),Q(`p`,{children:e.description})]})]})})}function pS({board:e,brief:t,video:n=null,toast:r,onChanged:i,settle:a}){let{latest:o,enqueue:s}=Dg(`storyboard`,e,{toast:r,onChanged:i,settle:a,video:n}),[c,l]=H(null),u=G(null),d={shot:(e,t)=>{let n=o.current.shots.findIndex(t=>t.index===e.index),r=n<0?0:cS(o.current.shots,n),i=t.status===`approved`&&t.description===void 0&&t.direction===void 0;s(`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})}},f=B(t),p=e.shots.find(e=>e.heading===c);return Q(`div`,{class:`col ppage`,children:[Q(`div`,{class:`shead`,children:Q(`h2`,{children:`Storyboard`})}),Q(`div`,{class:`sbtotal mono`,"aria-label":`Planned length`,children:[Q(`span`,{children:f?`${e.plannedLength.toFixed(1)} / ${f} s planned`:`${e.plannedLength.toFixed(1)} s planned`}),f&&Q(`span`,{class:`bar`,children:Q(`i`,{style:{width:`${Math.min(100,e.plannedLength/f*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:`prows`,children:e.shots.map((t,n)=>Q(dS,{shot:t,save:d,onZoom:()=>{u.current=document.activeElement,l(t.heading)}},`${t.heading}#${cS(e.shots,n)}`))}),Q(Fg,{counts:e.total>0?{approved:Ig(e.approved,e.total,`shot`),edited:e.changed}:null}),p&&Q(fS,{shot:p,onClose:()=>{l(null),u.current?.focus()}})]})}var mS={approved:{color:`var(--done)`,label:`Approved`},flagged:{color:`var(--todo)`,label:`Flagged`},draft:{color:`var(--text-3)`,label:`Draft`}},hS=500,gS=Dm;function _S({section:e,wps:t,video:n,toast:r,onChanged:i,onPick:a}){let[o,s]=H(e.proposed??e.current),[c,l]=H(e.direction),u=G(!1);U(()=>{u.current||s(e.proposed??e.current)},[e.proposed,e.current]),U(()=>{u.current||l(e.direction)},[e.direction]);let d=async t=>{try{await K.patch(`/api/script/${encodeURIComponent(e.id)}`,n?{...t,video:n}:t)}catch(t){r(`Couldn't save ${e.id.toUpperCase()}: ${t.message}`)}i()},f=Og(()=>{u.current=!1,d({proposed:o.trim()===e.current.trim()?null:o})},hS),p=Og(()=>{u.current=!1,d({direction:c})},hS),m=e.end-e.start,h=ke(o,m,t),g=o.trim()!==e.current.trim(),_=mS[e.status];return Q(`div`,{class:`srow${g?` changed`:``}`,"data-section":e.id,onFocusIn:()=>a?.({id:e.id,label:gS(e)}),onClick:()=>a?.({id:e.id,label:gS(e)}),children:[Q(`div`,{class:`sgrid`,children:[Q(`div`,{class:`when`,children:[Q(`b`,{children:e.id.toUpperCase()}),Q(`span`,{children:[Ce(e.start).replace(/\.\d+$/,``),`–`,Ce(e.end).replace(/\.\d+$/,``)]}),Q(`span`,{class:`stat`,"aria-label":_.label,"data-tip":_.label,title:_.label,children:Q(`i`,{style:{background:_.color}})})]}),Q(`div`,{class:`pbody`,children:[Q(Ng,{label:`Your version of ${e.id}`,value:o,onInput:e=>{u.current=!0,s(e),f.schedule()},onBlur:()=>f.flush()}),g&&Q(Pg,{baseline:[{text:e.current}],revertLabel:`Revert`,onRevert:()=>{u.current=!1,s(e.current),d({proposed:null})}})]})]}),Q(`div`,{class:`sfoot`,children:[Q(`div`,{class:`fit${h.state===`ok`?``:` ${h.state}`}`,title:`${h.words} words · ${h.seconds.toFixed(1)} s of ${m.toFixed(1)} s`,children:Q(`i`,{style:{width:`${Math.min(100,h.ratio*100)}%`}})}),Q(`input`,{class:`dirin`,placeholder:`Direction`,"aria-label":`Direction for ${e.id}`,value:c,onInput:e=>{u.current=!0,l(e.target.value),p.schedule()},onBlur:()=>p.flush()}),Q(`div`,{class:`sact`,children:[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 d({status:e.status===`flagged`?`draft`:`flagged`}),children:Q($,{name:`flag`})}),Q(`button`,{class:`btn ib okd`,"data-tip":`Approve`,"aria-label":`Approve`,"aria-pressed":e.status===`approved`,onClick:()=>void d({status:e.status===`approved`?`draft`:`approved`}),children:Q($,{name:`check`})})]})]})]})}function vS({script:e,video:t=null,toast:n,onChanged:r,onPickLine:i}){let a=e.sections.filter(Ae).length,o=e.sections.filter(e=>e.status===`approved`).length;return Q(`div`,{class:`col ppage`,children:[Q(`div`,{class:`shead`,children:Q(`h2`,{children:`Script`})}),Q(`div`,{class:`prows`,children:e.sections.map(a=>Q(_S,{section:a,wps:e.wordsPerSecond,video:t,toast:n,onChanged:r,onPick:i},a.id))}),Q(Fg,{counts:e.sections.length>0?{approved:Ig(o,e.sections.length,`line`),edited:a}:null})]})}var yS=Math.floor(Math.random()*2**31),bS=!1,xS=new Set,SS={music:{title:`Music`,one:`bed`,many:`beds`,none:`No music beds for this film yet.`},sfx:{title:`Effects`,one:`pass`,many:`passes`,none:`No sound effects passes for this film yet.`}};function CS({on:e,onToggle:t}){return Q(`button`,{type:`button`,class:`btn ghost sm kblind`,"aria-label":`Blind`,"aria-pressed":e,"data-tip":e?`Show the names`:`Hide the names while you listen`,onClick:t,children:[Q($,{name:`eyeoff`}),`Blind`]})}function wS({stage:e,state:t,assets:n,video:r,toast:i,onChanged:a,onPendingChange:o,onPlayingChange:s,clock:c,version:l}){let[u,d]=H(e===`music`&&bS),f=e=>{bS=e,d(e)},[,p]=H(0),m=SS[e],h=t.project.videos.length,g=mr(t.project.lanes,r?.id,t.project.videos),_=ir(t.picks,r?.id),v=e=>h>1?Ox(e,t.project.videos,r,i,a):void 0,y=zx({stage:e,groups:Lm(g,e,_.use?.[e],r??void 0),assets:n,blind:u?{seed:yS,word:`Bed`}:null,films:e=>v(Bx(e))}),b=r?At(hr(t.project.lanes,r.id,t.project.videos),e):[],x=At(g,e),S=Pt(x,e=>y.nameOf(e.key)??e.name,e===`sfx`),C=l??Me(r??void 0),w=r&&C?{video:r.id,version:C,locked:r.lockedVersion===C.id}:null;return Q(Jx,{stage:e,title:m.title,film:r?.id??null,readOnly:!!r?.shelved,list:y,loose:{items:b.map(e=>({key:e.key,name:e.name,meta:e.meta,films:v(e),none:e.films.length===0})),what:b.length===1?m.one:m.many},headerExtra:e===`music`?Q(CS,{on:u,onToggle:()=>f(!u)}):void 0,preview:w,prompt:Be(`picture`,t.project.name,r?.name??null),fps:C?.fps??(t.project.fps||30),notes:gr(t.notes.notes,e,r?.id,t.project.videos),noteRow:e=>Rt(x,e.on),onLabel:e=>zt(x,S,e.on),targetName:(e,t)=>t===null?e.name:S.find(n=>n.value===`c:${e.key}:${t}`)?.label??e.name,rangeMarks:!0,wholeLabel:`The whole ${m.one}`,none:m.none,layers:e===`sfx`?{open:e=>xS.has(e),toggle:e=>{xS.has(e)?xS.delete(e):xS.add(e),p(e=>e+1)}}:void 0,toast:i,onChanged:a,onPendingChange:o,onPlayingChange:s,clock:c})}var TS=Math.floor(Math.random()*2**31),ES=!1;function DS({state:e,assets:t,video:n,toast:r,onChanged:i,onPendingChange:a,onPlayingChange:o,clock:s,version:c}){let[l,u]=H(ES),d=e=>{ES=e,u(e)},f=e.project.videos.length,p=mr(e.project.lanes,n?.id,e.project.videos),m=ir(e.picks,n?.id),h=t=>f>1?Ox(t,e.project.videos,n,r,i):void 0,g=zx({stage:`voice`,groups:Lm(p,`voice`,m.use?.voice,n??void 0),assets:t,blind:l?{seed:TS,word:`Read`}:null,films:e=>h(Bx(e))}),_=e=>g.nameOf(e.key)??e.name,v=n?At(hr(e.project.lanes,n.id,e.project.videos),`voice`):[],y={rounds:qt(p,m.lanes),sections:e.script.sections},b=c??Me(n??void 0),x=n&&b?{video:n.id,version:b,locked:n.lockedVersion===b.id}:null;return Q(Jx,{stage:`voice`,title:`Voice`,film:n?.id??null,readOnly:!!n?.shelved,list:g,loose:{items:v.map(e=>({key:e.key,name:`${e.laneName} · ${e.name}`,meta:e.meta,films:h(e),none:e.films.length===0})),what:v.length===1?`read`:`reads`},headerExtra:Q(CS,{on:l,onToggle:()=>d(!l)}),preview:x,prompt:Be(`picture`,e.project.name,n?.name??null),fps:b?.fps??(e.project.fps||30),notes:gr(e.notes.notes,`voice`,n?.id,e.project.videos),noteRow:e=>Zt(y,e),onLabel:e=>Qt(y,e.on,_),targetName:e=>`${e.take.round} · ${e.name}`,rangeMarks:!1,wholeLabel:`The whole read`,none:`No voice reads for this film yet.`,toast:r,onChanged:i,onPendingChange:a,onPlayingChange:o,clock:s})}function OS(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 kS=e=>e.map(e=>e?`1`:`0`).join(``),AS={100:`left third`,"010":`centre`,"001":`right third`,110:`left two thirds`,"011":`right two thirds`,111:`full width`,101:`full width`},jS={100:`top third`,"010":`middle`,"001":`bottom third`,110:`top two thirds`,"011":`bottom two thirds`,111:`full height`,101:`full height`};function MS(e){let t=kS(OS(e.x,e.w)),n=kS(OS(e.y,e.h));return t===`111`&&n===`111`?`the whole picture`:t===`010`&&n===`010`?`the centre`:`${AS[t]}, ${jS[n]}`}function NS(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 PS(e,t,n=8){return Math.min(Math.max(0,e-1),Math.max(0,t-n))}var FS=e=>Math.round(e*1e4)/1e4,IS=e=>FS(Math.max(0,Math.min(1,e))),LS=.02;function RS(e,t,n){if(!n)return{pin:{x:IS(e.x),y:IS(e.y)}};let[r,i,a,o]=[IS(e.x),IS(e.y),IS(t.x),IS(t.y)],s={x:Math.min(r,a),y:Math.min(i,o),w:FS(Math.abs(a-r)),h:FS(Math.abs(o-i))};return s.w<LS||s.h<LS?null:{box:s}}var zS=e=>e.versions[e.versions.length-1];function BS(e){let t=zS(e);return{page:1,ratio:t.pages[0]?.images[0]?.ratio??``,ver:t.id}}function VS(e,t){let{ver:n,...r}=t;return n===zS(e).id?r:{...r,ver:n,since:zS(e).id}}function HS(e,t){let{ver:n,since:r,...i}=t??{},a=n!==void 0&&r===zS(e).id;return{...BS(e),...i,...a?{ver:n}:{}}}var US=(e,t)=>t.ver===zS(e).id;function WS(e,t){return[e.name,e.kind===`carousel`?`page ${t.page}`:null,ve(t.ratio),t.ver].filter(Boolean).join(` · `)}var GS=e=>(e.on??``).slice(0,(e.on??``).lastIndexOf(`/`)),KS=e=>Number((e.on??``).slice((e.on??``).lastIndexOf(`/`)+1))||0;function qS(e,t){return e.filter(e=>e.stage===`visuals`&&GS(e)===GS(t)).findIndex(e=>e.id===t.id)+1}function JS(e,t){let n=t.filter(e=>e.stage===`visuals`),r=[...e.map(e=>e.id),...new Set(n.map(GS).filter(t=>!e.some(e=>e.id===t)))],i=[];for(let t of r){let r=n.filter(e=>GS(e)===t);if(r.length===0)continue;let a=e.find(e=>e.id===t),o=[...new Set(r.map(KS))].sort((e,t)=>e-t).map(e=>({page:e,notes:r.filter(t=>KS(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 YS(e,t,n){return e.filter(e=>e.stage===`visuals`&&GS(e)===t&&KS(e)===n.page&&e.format===n.ratio&&e.version===n.ver&&(e.box!==null||e.pin!==null))}function XS(e,t){let n={};for(let r of e)r.stage===`visuals`&&r.status===`todo`&&GS(r)===t&&(n[KS(r)]=(n[KS(r)]??0)+1);return n}function ZS(e,t,n){return{page:KS(t),ratio:t.format??n.ratio,ver:t.version??n.ver}}function QS(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 $S=e=>e instanceof HTMLElement&&(e.isContentEditable||/^(INPUT|TEXTAREA|SELECT)$/.test(e.tagName));function eC(e){let t=G(null),[n,r]=H(null);return W(()=>{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 tC({notes:e,all:t,selected:n,draft:r}){return Q(w,{children:[e.map(e=>{let r=qS(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`&&GS(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`&&GS(e)===r.vis).length+1})})]})}function nC({file:e,alt:t,onBad:n}){return Q(`img`,{src:si(e),alt:t,draggable:!1,onError:n})}function rC({visual:e,view:t,badges:n,onPage:r}){let i=e.versions.find(e=>e.id===t.ver)??zS(e),a=G(null);W(()=>{let e=a.current;if(!e||e.children.length===0)return;let n=e.children[PS(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:si(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 iC({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)??zS(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:_}=eC({w:m.width,h:m.height}),[v,y]=H(null),b=YS(r,e.id,t),x=a&&a.vis===e.id&&a.page===t.page&&a.ratio===t.ratio&&a.ver===t.ver?a:null,S=!US(e,t),C=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===zS(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:ve(e.ratio)},e.ratio)):Q(`span`,{class:`vzchip static`,children:[m.width,`×`,m.height]}),S&&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":`${WS(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(nC,{file:m.file,alt:`${e.name}, page ${t.page}`,onBad:()=>y(m.file)},m.file),Q(tC,{notes:b,all:r,selected:i,draft:x})]})}),Q(`div`,{class:`vzfoot`,children:e.kind===`carousel`?Q(w,{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:[C,` / `,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(rC,{visual:e,view:t,badges:XS(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 aC({visual:e,view:t,notes:n,onPage:r,onClose:i}){let a=e.versions.find(e=>e.id===t.ver)??zS(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}=eC({w:s.width,h:s.height}),u=G(null);return U(()=>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(nC,{file:s.file,alt:`${e.name}, page ${t.page}`,onBad:()=>void 0},s.file),Q(tC,{notes:YS(n,e.id,t),all:n,selected:null,draft:null})]})}),Q(`div`,{class:`bar`,children:[e.kind===`carousel`&&Q(w,{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 oC({state:e,toast:t,onChanged:n,onPendingChange:r}){let i=e.visuals.visuals,a=e.notes.notes,[o,s]=H(i[0]?.id??``),[c,l]=H({}),[u,d]=H(null),[f,p]=H(null),[m,h]=H(null),[g,_]=H(null),v=G(null),y=G(null),b=e=>HS(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)??zS(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]:VS(e,{page:a,ratio:o,ver:i.id})}})},C=G(0);U(()=>{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)};U(()=>(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(!US(r,a))return t(`You're looking at ${a.ver}. Switch to the newest version to add notes.`);let s=QS(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:RS(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=RS(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(!US(x,e))return t(`You're looking at ${e.ver}. Switch to the newest version to add notes.`);let n=QS(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=G(!1),[ee,M]=H(!1),N=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(!US(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,M(!0);try{let t=await K.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 ti,e.message))}finally{j.current=!1,M(!1)}},P=async e=>{try{await K.patch(`/api/notes/${e.id}`,{status:e.status===`done`?`todo`:`done`}),n()}catch(e){t(e.message)}},F=e=>{let t=i.find(t=>t.id===GS(e));t&&(p(e.id),S(t,ZS(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))},te=G(()=>void 0);if(U(()=>{let e=e=>te.current(e);return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[]),te.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($S(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=sC(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)},U(()=>{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 I=JS(i,a),ne=a.filter(e=>e.stage===`visuals`&&e.status===`todo`).length,re=new Set(a.filter(e=>e.stage===`visuals`&&e.status===`todo`).map(GS)).size,L=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(iC,{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:[ne,` open across `,re,` visual`,re===1?``:`s`]}),e.project.videos.length>1&&Q(`span`,{class:`asub ashared`,"data-tip":`Visuals belong to the project: they show on every film`,children:`Shared`})]}),Q(`div`,{class:`vznlist`,children:[I.length===0&&Q(`div`,{class:`vzempty`,children:`No notes yet.`}),I.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!==zS(n).id;return Q(`div`,{class:`vznote${t.status===`done`?` done`:``}${f===t.id?` sel`:``}`,"data-note":t.id,role:`button`,tabIndex:0,onClick:()=>F(t),onKeyDown:e=>e.key===`Enter`&&F(t),children:[Q(`span`,{class:`no2`,children:qS(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?ve(t.format):`all ratios`}),Q(`span`,{class:`tag${r?` old`:``}`,children:r?`from ${t.version}`:t.version}),Q(`span`,{class:`tag`,title:t.box?MS(t.box):t.pin?NS(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,{...ZS(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(),P(t)},children:Q($,{name:t.status===`done`?`check`:`circle`})})]},t.id)})]},t.page))})]},e.visual.id))]}),Q(`div`,{class:`vzcomposer`,children:[Q(`div`,{class:`vztarget${O?` away`:``}`,children:[Q(`span`,{class:`lbl`,children:O?`Draft for`:`Adding to`}),Q(`b`,{children:O&&E?WS(E,u):WS(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()&&N()),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 `,ve(u.ratio)]}),Q(`div`,{class:`vzcrow`,children:[Q(`button`,{class:`btn primary`,disabled:ee,onClick:()=>void N(),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`})]})]})]}),L&&Q(aC,{visual:L,view:b(L),notes:a,onPage:e=>S(L,{page:e}),onClose:()=>h(null)})]})}function sC(e,t){return(e.versions.find(e=>e.id===t.ver)??zS(e)).pages[0]?.images.map(e=>e.ratio)??[]}var cC=()=>{try{return window.sessionStorage}catch{return}},lC=()=>{try{return window.localStorage}catch{return}};function uC(e,t,n,r=null){let i=r?`${wv(e,`log-seen`)}:${r}`:wv(e,`log-seen`),[a,o]=H(()=>Tv(cC(),wv(e,`log-open`))===`1`),[s,c]=H(!1),[l,u]=H({}),d=i in l?l[i]:Tv(lC(),i),f=e=>u(t=>({...t,[i]:e})),p=t?.mark??null,m=G(d);m.current=d;let h=e=>{f(e),Ev(lC(),i,e)},g=n(a);return U(()=>{g&&p&&Cv(p,d)&&h(p)},[g,p,i]),U(()=>{let e=e=>{e.key===i&&e.newValue&&f(e.newValue)};return window.addEventListener(`storage`,e),()=>window.removeEventListener(`storage`,e)},[i]),{open:a,focusOnOpen:s,dot:!g&&Cv(p,d),setOpen:(t,n=t)=>{o(t),c(t&&n),Ev(cC(),wv(e,`log-open`),t?`1`:`0`)},saw:e=>{Cv(e,m.current)&&h(e)},focused:()=>c(!1)}}function dC(e){let t=0,n=()=>{let r=document.querySelector(`.take[data-take="${CSS.escape(e)}"] .knm`);if(r){r.scrollIntoView({block:`nearest`}),r.focus({preventScroll:!0});return}++t<60&&requestAnimationFrame(n)};requestAnimationFrame(n)}var fC=700,pC=16,mC=()=>typeof matchMedia==`function`&&matchMedia(`(hover: none)`).matches;function hC({versions:e,shown:t,lockedVersion:n,onPick:r,name:i=`Version`,newer:a=null,footer:o,openFooter:s=0}){let c=[...e].reverse(),[l,u]=H(!1),[d,f]=H(t.id),[p,m]=H(null),[h,g]=H(!1),[_,v]=H(null),[y,b]=H(0),x=G(null),S=G(null),C=G(null),w=G({}),T=G(null),E=G({text:``,at:-1/0}),D=qr(),O=new Date,k=xp(t),A=e=>{f(e),m(null),v(null),g(mC()),u(!0)},j=e=>{u(!1),v(null),e&&S.current?.focus()},ee=e=>{j(!0),e!==t.id&&r(e)},M=l&&!e.some(e=>e.id===d),N=G(!1);W(()=>{M?j(!0):l&&N.current?(N.current=!1,T.current?.querySelector(`button:not(:disabled)`)?.focus()):l&&w.current[d]?.focus()},[l,d,M]),W(()=>{s<=0||!o||(N.current=!0,A(t.id))},[s]);let P=()=>{let e=x.current?.getBoundingClientRect(),t=C.current?.getBoundingClientRect();if(!e||!t)return;let n=document.documentElement.clientWidth-pC;b(Math.max(0,Math.min(e.left+t.width-n,e.left-pC)))};W(()=>{l&&P()}),W(()=>{if(l)return window.addEventListener(`resize`,P),()=>window.removeEventListener(`resize`,P)},[l]),U(()=>{if(!l)return;let e=e=>{x.current?.contains(e.target)||j(!1)};return document.addEventListener(`pointerdown`,e,!0),document.addEventListener(`focusin`,e,!0),()=>{document.removeEventListener(`pointerdown`,e,!0),document.removeEventListener(`focusin`,e,!0)}},[l]);let F=e=>{if(e.key===`Tab`){let t=e.shiftKey?null:T.current?.querySelector(`button:not(:disabled)`);if(t){e.preventDefault(),e.stopPropagation(),t.focus();return}j(!1);return}if(e.metaKey||e.ctrlKey||e.altKey)return;let t=c.findIndex(e=>e.id===d),n=Fh(e.key,t,c.length);if(n!==null){e.preventDefault(),e.stopPropagation(),m(null),f(c[n].id);return}if(e.key===`Escape`){e.preventDefault(),e.stopPropagation(),j(!0);return}if(e.key===`Enter`||e.key===` `){e.preventDefault(),e.stopPropagation(),ee(d);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-E.current.at<fC?E.current.text+e.key:e.key;E.current={text:t,at:e.timeStamp};let n=Ph(c.map(e=>e.id),t);n&&(m(null),f(n));return}e.key.length===1&&e.stopPropagation()},te=e=>{if(h&&_!==e){v(e),f(e);return}ee(e)},I=c.find(e=>e.id===(p??d))??t;return Q(`div`,{class:`vwrap`,ref:x,children:[Q(`button`,{ref:S,type:`button`,class:`vbtn`,"data-version":t.id,"aria-haspopup":`listbox`,"aria-expanded":l,"aria-controls":l?`vlist`:void 0,"aria-label":`${i}: ${t.id} · ${k}`,"aria-describedby":a?D:void 0,onClick:()=>l?j(!1):A(t.id),onKeyDown:e=>{!l&&(e.key===`ArrowDown`||e.key===`ArrowUp`)&&(e.preventDefault(),e.stopPropagation(),A(t.id))},children:[i!==`Version`&&Q(`small`,{children:i}),Q(`span`,{class:`vid`,children:t.id}),Q(`span`,{class:`vlbl`,dir:`auto`,children:k}),a&&Q(`span`,{class:`vnewer`,id:D,children:Q(`span`,{class:`vh`,children:[a,` is ready`]})}),Q($,{name:`chev`})]}),l&&Q(`div`,{ref:C,class:`vmenu${h?` touch`:``}`,style:y?{left:`${-y}px`}:void 0,children:[Q(`div`,{class:`vlist`,id:`vlist`,role:`listbox`,"aria-label":`Versions`,onKeyDown:F,onMouseLeave:()=>m(null),children:c.map(e=>Q(`button`,{type:`button`,role:`option`,class:`vrow`,"data-version":e.id,"data-on":e.id===(p??d)?`true`:`false`,"aria-selected":e.id===t.id,"aria-label":gC(e,n,O),"aria-describedby":!h&&e.id===I.id?`vdetail`:void 0,tabIndex:e.id===d?0:-1,ref:t=>{w.current[e.id]=t},onMouseEnter:()=>m(e.id),onClick:()=>te(e.id),children:[Q(`span`,{class:`vid`,children:e.id}),Q(`span`,{class:`vlbl`,dir:`auto`,children:xp(e)}),Q(`span`,{class:`vwhen`,children:[e.id===n&&Q($,{name:`lock`}),Mh(e.addedAt,O)]}),h&&_===e.id&&Q(`span`,{class:`vinline`,dir:`auto`,children:[cp(e.note)||`No note.`,Q(`span`,{class:`vmeta`,children:Ih(e,O)})]})]}))}),o&&Q(`div`,{ref:T,class:`vfoot`,onKeyDown:e=>{e.metaKey||e.ctrlKey||e.altKey||(e.key===`Escape`?(e.preventDefault(),e.stopPropagation(),j(!0)):e.key===`Tab`?(e.preventDefault(),e.stopPropagation(),e.shiftKey?w.current[d]?.focus():j(!1)):(e.key.length===1||e.key===`Enter`||e.key.startsWith(`Arrow`))&&e.stopPropagation())},children:o(j)}),!h&&Q(`div`,{class:`vdetail`,id:`vdetail`,children:[Q(`h4`,{children:I.id}),Q(_C,{note:I.note}),Q(`span`,{class:`vmeta`,children:Ih(I,O)})]})]})]})}function gC(e,t,n){return[e.id,xp(e),e.id===t?`locked`:``,Nh(e.addedAt,n)].filter(Boolean).join(`, `)}function _C({note:e}){if(!cp(e))return Q(`p`,{dir:`auto`,children:`No note.`});let{lead:t,points:n}=Lh(e);return Q(`div`,{class:`vnote`,dir:`auto`,children:[t&&Q(`p`,{class:`vlead`,children:t}),n.length>0&&Q(`ul`,{children:n.map((e,t)=>Q(`li`,{children:[e.head&&Q(`b`,{children:[e.head,`: `]}),e.text]},t))})]})}function vC({video:e,shown:t,newer:n,onPick:r,onToggleLock:i}){let a=!!e.lockedVersion;return Q(hC,{name:`Cut`,versions:e.versions,shown:t,lockedVersion:e.lockedVersion,newer:n,onPick:r,footer:n=>Q(`button`,{type:`button`,class:`mi`,disabled:!!e.shelved,onClick:()=>{n(!0),i()},children:[Q(`span`,{class:`nm`,children:a?`Unlock picture`:`Lock picture at ${t.id}`}),a&&Q(`span`,{class:`c`,children:[`locked at `,e.lockedVersion]})]})})}function yC({films:e,currentId:t,openNotes:n,onSwitch:r,onRestore:i,shelvedRequest:a}){let o=e.filter(Ne),s=e.filter(e=>!Ne(e)),c=e.find(e=>e.id===t),l=nv(o.length+s.length*2,e=>{if(/^\d+$/.test(e)){let t=Ph(o.map((e,t)=>String(t+1)),e);return t===null?null:Number(t)-1}let t=o.findIndex(t=>t.name.toLowerCase().startsWith(e));if(t>=0)return t;let n=s.findIndex(t=>t.name.toLowerCase().startsWith(e));return n>=0?o.length+n*2:null});if(U(()=>{a>0&&s.length>0&&l.show(o.length)},[a]),o.length<=1&&s.length===0)return Q(`span`,{class:`filmsel plain`,"data-tip":c?.name,children:[Q(`small`,{children:`Film`}),Q(`span`,{class:`filmname`,dir:`auto`,children:c?.name??`No film yet`})]});let u=e=>{l.close(!0),r(e.id)},d=e=>{if(e.versions.length===0)return`no cut yet`;let t=n(e.id);return t>0?`${t} open`:`done`};return Q(`span`,{class:`filmsel mwrap`,ref:l.wrap,children:[Q(`button`,{ref:l.button,type:`button`,class:`pick`,"aria-label":`Film: ${c?.name??`none open`}`,"aria-haspopup":`menu`,"aria-expanded":l.open,onClick:()=>l.toggle(Math.max(0,o.findIndex(e=>e.id===t))),onKeyDown:e=>{!l.open&&(e.key===`ArrowDown`||e.key===`ArrowUp`)&&(e.preventDefault(),e.stopPropagation(),l.show(Math.max(0,o.findIndex(e=>e.id===t))))},children:[Q(`small`,{children:`Film`}),Q(`span`,{class:`filmname`,dir:`auto`,children:c?.name??`None open`}),c?.shelved&&Q(`span`,{class:`fshelved`,children:`shelved`}),Q($,{name:`chev`})]}),l.open&&Q(`div`,{class:`dmenu films`,role:`menu`,"aria-label":`Films`,onKeyDown:l.onKeyDown,children:[o.map((e,r)=>Q(`button`,{ref:l.row(r),type:`button`,role:`menuitem`,class:`mi`,tabIndex:-1,"aria-current":e.id===t?`true`:void 0,onClick:()=>u(e),children:[Q(`span`,{class:`k`,children:r+1}),Q(`span`,{class:`nm`,dir:`auto`,children:e.name}),Q(`span`,{class:`c${n(e.id)>0?` todo`:``}`,children:d(e)})]},e.id)),s.length>0&&Q(w,{children:[Q(`hr`,{}),Q(`div`,{class:`hd`,children:[`Shelved (`,s.length,`)`]}),s.map((e,n)=>Q(`div`,{class:`mrow`,children:[Q(`button`,{ref:l.row(o.length+n*2),type:`button`,role:`menuitem`,class:`mi`,tabIndex:-1,"aria-label":`Open ${e.name}`,"aria-current":e.id===t?`true`:void 0,onClick:()=>u(e),children:[Q(`span`,{class:`k`}),Q(`span`,{class:`nm`,dir:`auto`,children:e.name}),Q(`span`,{class:`c`,children:[e.versions.length,` `,e.versions.length===1?`cut`:`cuts`,` · `,Im(e.shelved)]})]}),Q(`button`,{ref:l.row(o.length+n*2+1),type:`button`,role:`menuitem`,class:`ibtn`,tabIndex:-1,"aria-label":`Restore ${e.name}`,"data-tip":`Restore ${e.name}`,onClick:()=>{l.close(!0),i(e.id)},children:Q($,{name:`undo`})})]},e.id))]})]})]})}function bC({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 `,Im(e.shelved),`. View only.`]}),Q(`span`,{class:`sp`}),Q(`button`,{type:`button`,class:`btn`,onClick:t,children:[Q($,{name:`undo`}),`Restore film`]})]})}function xC({onOpen:e}){return Q(`div`,{class:`emptypage 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`})]})}function SC({found:e,onBringIn:t,video:n,onToggleShelved:r,autoProxy:i,onKeys:a,toast:o,onChanged:s}){let c=nv(6),l=!!n?.shelved,[u,d]=H(()=>br(wr())),f=()=>{let e=Sr(u);Tr(e),Dr(e),d(e)},p=async()=>{try{let{path:e}=await K.post(`/api/exports/notes`);o(`Saved to ${e}`),s()}catch(e){o(e.message)}},m=async e=>{try{await K.put(`/api/project/settings`,{autoProxy:e}),s()}catch(e){o(e.message)}},h=e=>()=>{c.close(!0),e()};return Q(`span`,{class:`mwrap more`,ref:c.wrap,children:[Q(`button`,{ref:c.button,type:`button`,class:`ibtn`,"aria-label":`More`,"data-tip":`More`,"aria-haspopup":`menu`,"aria-expanded":c.open,onClick:()=>c.toggle(0),children:Q($,{name:`more`})}),c.open&&Q(`div`,{class:`dmenu`,role:`menu`,"aria-label":`More`,onKeyDown:c.onKeyDown,children:[Q(`button`,{ref:c.row(0),type:`button`,role:`menuitem`,class:`mi`,tabIndex:-1,onClick:h(t),children:[Q($,{name:`download`}),Q(`span`,{class:`nm`,children:`Bring in new files`}),e&&Q(`span`,{class:`c`,children:e})]}),Q(`button`,{ref:c.row(1),type:`button`,role:`menuitem`,class:`mi`,tabIndex:-1,onClick:h(()=>void p()),children:[Q($,{name:`save`}),Q(`span`,{class:`nm`,children:`Export notes`})]}),Q(`hr`,{}),Q(`button`,{ref:c.row(2),type:`button`,role:`menuitem`,class:`mi`,tabIndex:-1,disabled:!n,onClick:h(r),children:[Q($,{name:l?`undo`:`shelve`}),Q(`span`,{class:`nm`,children:l?`Restore film`:`Shelve film`}),n&&Q(`span`,{class:`c fn`,dir:`auto`,children:n.name}),Q(`kbd`,{children:`Shift+S`})]}),Q(`button`,{ref:c.row(3),type:`button`,role:`menuitemcheckbox`,class:`mi`,tabIndex:-1,"aria-checked":i,onClick:()=>void m(!i),children:[Q(`span`,{class:`mtick`,"aria-hidden":`true`,children:i&&Q($,{name:`check`})}),Q(`span`,{class:`nm`,children:`Make lighter copies of new cuts automatically`})]}),Q(`hr`,{}),Q(`button`,{ref:c.row(4),type:`button`,role:`menuitem`,class:`mi`,tabIndex:-1,onClick:h(a),children:[Q($,{name:`kbd`}),Q(`span`,{class:`nm`,children:`Keyboard shortcuts`}),Q(`kbd`,{children:`?`})]}),Q(`button`,{ref:c.row(5),type:`button`,role:`menuitem`,class:`mi`,tabIndex:-1,onClick:f,children:[Q($,{name:`circle`}),Q(`span`,{class:`nm`,children:[`Appearance: `,Cr[u]]})]})]})]})}function CC({rows:e,selected:t,onPick:n}){return Q(`nav`,{class:`rtabs`,role:`tablist`,"aria-label":`Review`,children:e.map(e=>Q(`button`,{type:`button`,class:`tab`,role:`tab`,"aria-selected":t===e.view,"data-locked":e.locked?`true`:void 0,"data-tip":e.locked?`Locked: ask your agent for ${e.ask}`:e.todo>0?`${e.todo} open`:void 0,onClick:()=>n(e.view),children:[Q($,{name:e.icon}),e.label,e.locked?Q(w,{children:[Q($,{name:`lock`,class:`lk`}),Q(`span`,{class:`vh`,children:` Locked`})]}):Q(w,{children:[e.takes&&e.takes.all>0&&Q(w,{children:[` `,Q(`span`,{class:`tcount mono${e.takes.fresh>0?` new`:``}`,children:e.takes.fresh>0?`${e.takes.fresh} new`:e.takes.all})]}),e.todo>0&&Q(`span`,{class:`dot`,"aria-hidden":`true`})]})]},e.view))})}function wC({label:e,prompt:t,toast:n}){let[r,i]=H(!1),a=G(null),o=G(null),s=G(null),c=e=>{i(!1),e&&o.current?.focus()};ev(r,a,c),W(()=>{r&&s.current?.focus()},[r]);let l=`${e} · other shapes`;return Q(`span`,{class:`sshape`,ref:a,children:[Q(`button`,{ref:o,type:`button`,class:`sfmt`,"aria-haspopup":`dialog`,"aria-expanded":r,"aria-label":l,"data-tip":l,onClick:()=>i(e=>!e),children:e}),r&&Q(`div`,{class:`fmtpop open spop`,role:`dialog`,"aria-label":`Other shapes`,onKeyDown:e=>{e.key!==`Escape`&&e.key!==`Tab`&&e.stopPropagation()},children:Q(Ug,{prompt:t,toast:n,copyRef:s,onClick:()=>c(!0)})})]})}function TC({send:e=null,cut:t,shapes:n=null}){return Q(`footer`,{class:`status`,children:[e&&Q(`button`,{type:`button`,class:`ssend`,onClick:e.onGo,children:[Q($,{name:`send`}),e.text]}),Q(`span`,{class:`sp`}),t&&Q(`span`,{class:`smeta mono`,children:[t.format&&(n?Q(wC,{label:t.format,prompt:n.prompt,toast:n.toast}):Q(`span`,{children:t.format})),Q(`span`,{children:[t.fps,` fps`]}),Q(`span`,{children:t.lockedAt===t.id?`${t.id} locked`:t.lockedAt?`${t.id} · ${t.lockedAt} locked`:t.id})]})]})}var EC=96,DC=e=>e?Math.max(0,e.scrollWidth-e.clientWidth):0;function OC(e,t){let n=()=>{let t=e.current,n=t?.querySelector(`.vwrap`);if(!t||!t.lastElementChild)return;let r=t.getBoundingClientRect(),i=t.lastElementChild.getBoundingClientRect().right-r.left-(n?n.getBoundingClientRect().width-EC:0)+DC(t.querySelector(`.pname`))+DC(t.querySelector(`.filmname`));t.classList.toggle(`tight`,i>t.clientWidth+.5)};W(n),U(()=>{let e=new ResizeObserver(()=>n());return t.current&&e.observe(t.current),document.fonts?.ready.then(n),()=>e.disconnect()},[])}function kC({barRef:e,project:t,projectId:n,film:r,cut:i,workspaces:a,agent:o,notesToggle:s,more:c}){let l=G(null);return OC(l,e),Q(`header`,{class:`top`,ref:e,children:[Q(`div`,{class:`tleft`,ref:l,children:[Q(`span`,{class:`logo`,"aria-hidden":`true`,children:Q(`svg`,{viewBox:`0 0 24 24`,children:Q(`path`,{d:`M8 5v14l11-7z`})})}),Q(`span`,{class:`proj`,"data-tip":n?`${t} · ${n}`:t,children:[Q(`span`,{class:`pname`,children:t}),n&&Q(`span`,{class:`pid vh`,children:[` `,n]})]}),r,i]}),a,Q(`div`,{class:`tright`,children:[o,s,c]})]})}function AC({status:e,notes:t,onOpen:n,onStop:r}){let[,i]=H(0);if(U(()=>{let e=setInterval(()=>i(e=>e+1),6e4);return()=>clearInterval(e)},[]),!e||!e_(e,Date.now()))return null;let a=Qg(e,t);if(a===null)return null;let o=t_(e.phase),s=`Stop ${Yg(e.agent)}`,c=e.phase===`failed`&&e.error?e.error:null;return Q(`div`,{class:`agentchip ${o}`,children:[Q(`button`,{type:`button`,class:`achip`,"aria-label":a,"aria-description":c??void 0,"data-tip":c??a,onClick:n,children:[o===`busy`?Q($,{name:`spin`,class:`aspin`}):Q(`span`,{class:`adot`,"aria-hidden":`true`}),Q(`span`,{class:`atext`,children:a})]}),n_(e.phase)&&Q(`button`,{type:`button`,class:`ibtn astop`,"aria-label":s,"data-tip":s,onClick:r,children:Q($,{name:`stop`})})]})}var jC=8e3;function MC({film:e,versions:t,shown:n,busy:r,select:i,toast:a}){let o=G(null),[s,c]=H(null),l=G({shown:n,busy:r,select:i,toast:a});return l.current={shown:n,busy:r,select:i,toast:a},U(()=>{let n=Z_(o.current,e,t);o.current=n.memory;let r=l.current,i=Q_(n.arrived,r.shown,r.busy);if(!i||n.arrived===null)return;let a=n.arrived;i.show&&r.select(a),i.dot&&c({film:e,id:a}),r.toast(i.text,i.offer?jC:void 0,i.offer?{label:`Show`,run:()=>l.current.select(a)}:null)},[`${e}\n${t.join(`
|
|
66
|
+
`)}`]),$_(s,e,n,t)}function NC(e){let[t,n]=H(!1),[r,i]=H(!1);U(()=>{let t=t=>{let n=e.current;(t.target===n||t.target instanceof HTMLVideoElement)&&i(!!n&&!n.paused&&!n.ended)},n=[`play`,`playing`,`pause`,`ended`,`emptied`];for(let e of n)document.addEventListener(e,t,!0);return()=>n.forEach(e=>document.removeEventListener(e,t,!0))},[]);let a=e.current;return[t||r&&!!a&&a.isConnected&&!a.paused&&!a.ended,n]}var PC=!1;function FC(){if(!PC){PC=!0;try{if(typeof Notification>`u`||Notification.permission!=="default")return;Promise.resolve(Notification.requestPermission()).catch(()=>void 0)}catch{}}}function IC(e,t,n){let r=A_(e,t);return r.toast&&n(r.toast.text,r.toast.ms),r}var LC=e=>e instanceof ti&&e.status===409&&(e.code===`agent_not_signed_in`||e.code===`agent_not_installed`),RC=e=>K.get(`/api/agent/detect${e?`?fresh=1`:``}`).then(e=>e.agents,()=>[]);function zC({status:e,waiting:t,batch:n,onStatus:r,toast:i,onClose:a,onSend:o}){let[s,c]=H(null),[l,u]=H(null),[d,f]=H(null),p=G(!1),[m,h]=H(!1),g=G(!1),_=G(null),v=G(document.activeElement),y=T_(s),b=(e,t)=>{if(g.current)return;g.current=!0,a(e,t);let n=v.current;n instanceof HTMLElement&&n.isConnected&&n.focus()},x=G(b);x.current=b,W(()=>{RC(!1).then(t=>{c(t),u({step:`who`,pick:E_(T_(t),e.agent)})});let t=e=>{e.key===`Escape`&&(e.preventDefault(),e.stopPropagation(),p.current||x.current(!1))};return window.addEventListener(`keydown`,t,!0),()=>window.removeEventListener(`keydown`,t,!0)},[]);let S=l?.step;W(()=>{_.current?.querySelector(`input[type=radio]:checked`)?.focus()},[S]);let C=async e=>{try{let t=await K.post(`/api/agent/setup`,e);return r(t.status),t}catch(t){return LC(t)&&e.agent?(u({step:`who`,pick:e.agent}),f({agent:e.agent,message:t.message})):i(t.message),null}},T=e=>{e&&!g.current&&(b(!0,e),t&&o(e.status))},E=t=>({step:`may`,agent:t,permissions:e.asked&&e.permissions!==`bypass`?e.permissions:`project-edits`}),D=async()=>{if(l&&!p.current){l.step===`may`&&FC(),p.current=!0,h(!0);try{if(l.step===`may`)return T(await C({on:!0,agent:l.agent,permissions:l.permissions,...n?{batch:n}:{}}));f(null);let e=D_(l.pick,y);if(e===`copy`)return T(await C({on:!1,prompt:!0}));if(e===`missing`)return;let t=l.pick;if(e===`may`)return u(E(t));let r=await RC(!0);if(c(r),D_(t,T_(r))===`may`)return u(E(t));f({agent:t,message:O_(t)})}finally{p.current=!1,h(!1)}}},O=e=>{f(null),u({step:`who`,pick:e})},k=e=>void K.post(`/api/agent/sign-in`,{agent:e}).catch(e=>i(e.message));return Q(`div`,{class:`pop firstsend`,role:`dialog`,"aria-labelledby":`fs-title`,ref:_,onKeyDown:e=>{e.key===`Enter`&&e.target instanceof HTMLInputElement&&e.target.type===`radio`&&(e.preventDefault(),D())},children:[Q(`h3`,{id:`fs-title`,children:l?.step===`may`?S_(l.agent):x_.who}),l?.step===`who`&&Q(`div`,{class:`fsopts`,role:`radiogroup`,"aria-labelledby":`fs-title`,children:y.map(e=>Q(`div`,{class:`fsrow`,children:[Q(`label`,{class:`fsopt${l.pick===e.pick?` on`:``}${e.state===`missing`?` off`:``}${e.state===`signedOut`?` signin`:``}`,children:[Q(`input`,{type:`radio`,name:`fs-who`,value:e.pick,checked:l.pick===e.pick,disabled:e.state===`missing`,onChange:()=>O(e.pick)}),Q(`span`,{class:`fstext`,children:[Q(`b`,{children:e.name}),e.note&&Q(`small`,{class:e.state===`signedOut`?`todo`:void 0,children:e.note})]})]}),e.state===`signedOut`&&Q(`button`,{type:`button`,class:`btn ghost fssign`,onClick:()=>k(e.pick),children:m_.signIn}),d?.agent===e.pick&&Q(`p`,{class:`fserr`,role:`alert`,children:d.message})]},e.pick))}),l?.step===`may`&&Q(w,{children:[Q(`div`,{class:`fsopts`,role:`radiogroup`,"aria-labelledby":`fs-title`,children:h_.map(e=>Q(`div`,{class:`fsrow`,children:Q(`label`,{class:`fsopt${l.permissions===e.value?` on`:``}`,children:[Q(`input`,{type:`radio`,name:`fs-may`,value:e.value,"aria-label":e.label,"aria-describedby":`fs-may-${e.value}`,checked:l.permissions===e.value,onChange:()=>u({...l,permissions:e.value})}),Q(`span`,{class:`fstext`,children:[Q(`b`,{children:e.label}),Q(`small`,{id:`fs-may-${e.value}`,children:e.hint})]})]})},e.value))}),l.permissions===`bypass`&&Q(`p`,{class:`fswarn`,role:`note`,children:`Bypass: the agent runs every command and edits any file with nothing asked or checked, .rushes and .git included.`}),Q(`p`,{class:`fsline`,children:x_.noKey})]}),l&&Q(`div`,{class:`fsacts`,children:[l.step===`may`&&Q(`button`,{type:`button`,class:`btn ghost`,disabled:m,onClick:()=>u({step:`who`,pick:l.agent}),children:x_.back}),Q(`span`,{class:`sp`}),Q(`button`,{type:`button`,class:`btn ghost`,disabled:m,onClick:()=>b(!1),children:x_.cancel}),Q(`button`,{type:`button`,class:`btn primary`,disabled:m,onClick:()=>void D(),children:k_(l,t||n!==null)})]})]})}function BC({why:e,onSetUp:t}){return Q(`p`,{class:`swhy`,children:[Q(`span`,{children:e}),Q(`button`,{type:`button`,class:`btn`,onClick:t,children:x_.setUp})]})}function VC(e,t,n,r){let[i,a]=H(null);return{shown:i!==null,open:e=>a({batch:typeof e==`string`?e:null}),sheet:(o,s)=>i&&e?Q(zC,{status:e,waiting:o,batch:i.batch,onStatus:t,toast:n,onClose:(e,t)=>{a(null),e&&r(t?.agent?IC(t.agent,t.status,n):null)},onSend:s}):null}}var HC={asks:new Set,phase:null};function UC(e,t,n){if(!t)return{heard:e,notes:[]};let r={asks:new Set(t.asks.map(e=>e.id)),phase:t.phase};if(!n)return{heard:r,notes:[]};let i=[],a=t.asks.find(t=>!e.asks.has(t.id));return a&&i.push({body:`${Yg(t.agent)} is waiting for you`,tag:a.id}),t.phase===`question`&&e.phase!==`question`&&i.push({body:`${Yg(t.agent)} has a question`,tag:`question`}),{heard:r,notes:i}}var WC=(e=document)=>e.hidden||!e.hasFocus();function GC(e){try{if(typeof Notification>`u`||Notification.permission!==`granted`)return;let t=new Notification(`Rushes`,{body:e.body,tag:`rushes:${location.pathname}:${e.tag}`});t.onclick=()=>{window.focus(),t.close()}}catch{}}function KC(e){let t=G(HC);U(()=>{let n=UC(t.current,e,WC());t.current=n.heard;for(let e of n.notes)GC(e)},[e])}function qC({current:e,plan:t,hasVisuals:n,assetsUnlocked:r,found:i,onPick:a}){let o=(t,n,r,i,o=!1)=>Q(`button`,{type:`button`,class:`tab`,role:`tab`,"aria-selected":e===t,"data-locked":o?`true`:void 0,"data-tip":o&&t===`assets`?`Locked: ask your agent for ${Le.assets.ask}`:void 0,onClick:()=>a(t),children:[Q($,{name:n}),r,i]});return Q(`nav`,{class:`ws`,role:`tablist`,"aria-label":`Workspaces`,children:[o(`plan`,`list`,`Plan`,t.locked?Q(w,{children:[Q($,{name:`lock`,class:`lk`}),Q(`span`,{class:`vh`,children:` Locked`})]}):Q(w,{children:[t.approved&&Q(w,{children:[Q($,{name:`check`,class:`pready`}),Q(`span`,{class:`vh`,children:` Approved`})]}),t.open>0&&Q(`span`,{class:`dot`,title:`${t.open} not sent`})]}),t.locked),o(`review`,`film`,`Review`),n&&o(`visuals`,`image`,`Visuals`),o(`assets`,`grid`,`Assets`,r?i&&Q(w,{children:[` `,Q(`span`,{class:`wcount`,title:i.text,children:i.count})]}):Q(w,{children:[Q($,{name:`lock`,class:`lk`}),Q(`span`,{class:`vh`,children:` Locked`})]}),!r)]})}var JC=new Set([`picture`,`voice`,`music`,`sfx`,`mix`]),YC=[{view:`picture`,label:`Timeline`},{view:`voice`,label:`Voice`},{view:`music`,label:`Music`},{view:`sfx`,label:`Effects`}],XC=e=>e instanceof HTMLElement&&(e.isContentEditable||/^(INPUT|TEXTAREA|SELECT)$/.test(e.tagName));function ZC({tab:e,projectName:t,filmName:n,found:r,onReview:i,toast:a,paths:o=Ke}){let s=e===`brief`||e===`storyboard`,{what:c,unlocks:l}=e===`brief`?We:e===`storyboard`?Ge:Le[e],u=e===`assets`?`Assets`:e===`brief`?`Brief`:e===`storyboard`?`Storyboard`:Ie[e],d=e===`assets`?`grid`:e===`brief`?`brief`:e===`storyboard`?`story`:Vh[e],f=e===`brief`?qe(t,n,o):e===`storyboard`?Je(t,n,o):Be(e,t,n),p=s?null:Dn(e,r),m=G(null),h=async()=>{try{await navigator.clipboard.writeText(f),a(`Prompt copied`)}catch{m.current?.select(),a(`Prompt selected: press ${Sn(navigator.platform)}`)}};return Q(`div`,{class:`emptypage locked`,children:[Q($,{name:d}),Q(`h2`,{children:u}),Q(`p`,{children:c}),Q(`p`,{children:l}),Q(`textarea`,{class:`promptbox mono`,readOnly:!0,rows:4,ref:m,value:f,"aria-label":`Prompt for your agent`}),Q(`button`,{class:`btn primary`,onClick:()=>void h(),children:[Q($,{name:`copy`}),`Copy prompt for your agent`]}),p&&Q(`p`,{class:`foundline`,children:[Q(`span`,{children:p.text}),Q(`button`,{type:`button`,class:`btn`,"aria-label":p.review,onClick:()=>i(p.kind),children:`Review`})]})]})}function QC({onPendingChange:e,...t}){return U(()=>()=>e(!1),[]),Q(iy,{...t,onTextChange:e})}function $C(){let{state:e,assets:t,problem:n,wrongProject:r,refresh:i,proxyJobs:a,noteProxyJob:o,agent:s,noteAgent:c}=yh(),l=G(null),[u,d]=H(null),[f,p]=H(()=>dr(location.search)),[m,h]=H(null),[g,_]=H(null),[v,y]=H(null),[b,x]=H(null),[S,C]=H(`script`),[w,T]=H(`picture`),E=G(null),[D,O]=H(!1),[k,A]=H(!1),[j,ee]=H(!1),[M,N]=H(!1),P=G(new Map),F=G(null),te=G({at:e=>P.current.get(e)??0,attach:(e,t)=>{let n={film:e,read:t};return F.current=n,()=>{P.current.set(e,t()),F.current===n&&(F.current=null)}}}).current,I=G(null),[ne,re]=H({}),L=G(void 0),ie=G(new Map),ae=G(null),oe=(e,t)=>re(n=>({...n,[e]:t})),[se,ce]=H({}),le=(e,t)=>ce(n=>({...n,[e]:t})),[ue,de]=H({}),[fe,pe]=H({}),[me,he]=H(!1),[R,ge]=H(!1),_e=G(new Set),z=(e,t=2400,n=null)=>{_(e),y(n),clearTimeout(L.current),L.current=window.setTimeout(()=>{_(null),y(null)},t)},ye=VC(s,c,z,e=>x(t=>t&&(e&&!e.dialog?null:{...t,why:e?.why??null})));KC(s);let[xe,Se]=H({n:0,pending:!1}),[Ce,we]=H(null),Te=ty(),Ee=!!u&&(Mm(u).workspace===`review`||Mm(u).workspace===`plan`),De=e?.project.videos.find(e=>e.id===f)??e?.project.videos.find(Ne),Oe=De&&e?.films?.[De.id]?e.films[De.id].log:e?.log,ke=uC(ni()??``,Oe,e=>e&&Ee&&Te.shown,(e?.project.videos.length??0)>1?De?.id??null:null),[Ae,Ie]=H(!1),Re=G(null),ze=G(null);W(()=>{let e=ze.current;e&&(ze.current=null,e())});let[Ve,qe]=H(null);U(()=>{for(let e of Object.values(a))e.state!==`failed`||_e.current.has(e.job)||(_e.current.add(e.job),z(e.reason??`Couldn't make the proxy`))},[a]),U(()=>{if(!e)return;if(u===null){let t=Fm(Qe(e.tabs,e.brief));d(t),He(t)&&C(t)}let t=e.project.videos.find(Ne);f===null&&t&&p(t.id)},[e]);let Je=e?.project.videos.find(e=>e.id===f)??e?.project.videos.find(Ne);U(()=>{if(!e||!Je)return;let t=dr(location.search);if(e.project.videos.length<2&&t===null)return;let n=fr(location.search,Je.id);n!==location.search&&history.replaceState(history.state,``,`${location.pathname}${n}${location.hash}`)},[Je?.id,e?.project.videos.length]),U(()=>{e?.project.name&&(document.title=`${e.project.name} · Rushes`)},[e?.project.name]);let B=e?.project.videos.find(e=>e.id===f)??e?.project.videos.find(Ne),et=je(B),tt=Me(B),nt=B?.versions.find(e=>e.id===m)??tt,rt=!!B?.lockedVersion,it=nt?.fps??e?.project.fps??30,at=e?.notes.notes.filter(t=>t.stage===`picture`&&lr(t,B?.id,e.project.videos))??[],ot=nt?be(nt,fe[nt.file]):[],st=B&&nt?Hn(B,nt.id):void 0,ct=Un(ot,B?ue[B.id]:void 0),lt=new Set(t.filter(e=>e.kind===`cut`&&e.missing).map(e=>e.path)),ut=nt?Wn({views:ot,previous:st?be(st):[],current:ct,versionDuration:nt.duration,notes:at,missing:lt}):[],dt=e=>!B||e===ct?!1:me?(z(`Add or clear your box on ${ct?ve(ct):`this format`} first`),!1):(de(t=>({...t,[B.id]:e})),!0),[ft,pt]=NC(ae);U(()=>{(j||ft)&&m===null&&tt?(h(tt.id),N(!0)):!j&&!ft&&M&&m===tt?.id&&(h(null),N(!1))},[j,ft,m,tt?.id]),U(()=>{!M&&m!==null&&m===tt?.id&&h(null)},[tt?.id,M,m]);let mt=et&&nt&&et.id!==nt.id&&(rt||M)?et.id:null,ht=e=>R?z(`Add or clear your note first`):(h(e===tt?.id?null:e),N(!1)),gt=MC({film:B?.id??null,versions:B?.versions.map(e=>e.id)??[],shown:nt?.id,busy:ft||j||R||rt,select:ht,toast:z}),_t=e=>{if(e===B?.id)return;if(B&&j)return z(`Add or clear your note on ${B.name} first`);if(B){ae.current?.pause();let e=F.current;e&&e.film===B.id&&P.current.set(B.id,e.read()),ie.current.set(B.id,{versionId:m,held:M})}let t=ie.current.get(e);I.current=null,p(e),h(t?.versionId??null),N(t?.held??!1)},vt=async()=>{if(B&&nt)try{await K.put(`/api/videos/${B.id}/lock`,{version:B.lockedVersion?null:nt.id}),i()}catch(e){z(e.message)}},[yt,bt]=H(0),xt=G(_t);xt.current=_t;let St=async(t,n)=>{if(!e)return!1;if(n&&t.id===B?.id&&j)return z(`Add or clear your note on ${t.name} first`),!1;try{if(await K.put(`/api/videos/${t.id}/shelve`,{shelved:n}),n&&t.id===B?.id){let n=Fe(e.project.videos,t.id);n?_t(n):p(null)}return i(),n?z(`“${t.name}” shelved`,6e3,{label:`Undo`,run:()=>void St(t,!1).then(e=>e&&xt.current(t.id))}):z(`“${t.name}” restored`),!0}catch(e){return z(e.message),!1}},Ct=()=>{B&&St(B,!B.shelved)},wt=t=>{if(j)return z(`Add or clear your note first`);if(t.tab===`assets`)return Mt();if(t.video&&t.video!==B?.id&&_t(t.video),t.version){let n=e?.project.videos.find(e=>e.id===(t.video??B?.id));h(t.version===Me(n)?.id?null:t.version),N(!1)}let n=Fm(t.tab);d(n),Mm(n).workspace===`review`&&T(n),x(null),t.row&&dC(t.row)},Tt=B&&e?.films?.[B.id]?.tabs||e?.tabs||[],Et=B?e?.films?.[B.id]:void 0,Dt=e=>Tt.find(t=>t.stage===e),Ot=On(e?.found),kt=t.length>0||Ot!==null,At=e=>{let t=Fm(e);if(j&&t!==u)return z(`Add or clear your note first`);d(t),x(null),He(t)&&C(t),Mm(t).workspace===`review`&&T(t)},jt=()=>{let t={brief:!!(Et??e)?.brief.exists,script:!!Dt(`script`)?.unlocked,storyboard:!!(Et??e)?.storyboard.exists};At($e(S,t))},Mt=()=>{if(j&&u!==`assets`)return z(`Add or clear your note first`);d(`assets`),x(null)},Nt=e=>{if(j&&u!==`assets`)return z(`Add or clear your note first`);Se(t=>({n:t.n+1,kind:e,pending:!0})),d(`assets`),x(null)},Pt=G(Nt);Pt.current=Nt,U(()=>{Gt(location.search).test&&(window.__rushesOpenFound=e=>Pt.current(e))},[]),W(()=>{let t=t=>{if(t.altKey&&!t.metaKey&&!t.ctrlKey&&!t.shiftKey&&(t.key===`ArrowLeft`||t.key===`ArrowRight`)){if(u!==`picture`||XC(t.target))return;t.preventDefault();let e=Gn(ut,ct,t.key===`ArrowRight`?1:-1);e&&dt(e);return}if(XC(t.target)||t.metaKey||t.ctrlKey||t.altKey)return;let n=Pm(t.key,S);if(t.key===`1`?jt():n===`assets`?Mt():n&&At(n),t.key===`S`&&t.shiftKey&&!t.repeat&&Ct(),(t.key===`[`||t.key===`]`)&&e){let n=Pe(e.project.videos,f,t.key===`]`?1:-1);n&&_t(n)}t.key===`?`&&O(e=>!e),t.key===`\\`&&Ee&&!t.repeat&&(t.preventDefault(),Te.toggle()),t.key===`Escape`&&(O(!1),x(null))};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)});let Ft=G(null),It=G(null);W(()=>{let e=It.current;if(!e)return;let t=()=>{let t=getComputedStyle(e),n=`${Math.max(0,Math.round(e.clientHeight-parseFloat(t.paddingTop)-parseFloat(t.paddingBottom)))}px`;e.style.getPropertyValue(`--work-h`)!==n&&e.style.setProperty(`--work-h`,n)};t();let n=new ResizeObserver(t);return n.observe(e),()=>n.disconnect()},[!!e&&!!u]);let Lt=async({asked:t=s?.asked!==!1,status:n=s}={})=>{if(!e||!u)return;if(O(!1),!t&&un>0)return ye.open();n?.on&&FC();let r=u===`brief`||u===`storyboard`?await E.current?.():void 0,a=Et??e,o=(u===`brief`?r:void 0)??a.brief,c=(u===`storyboard`?r:void 0)??a.storyboard,l=Et?.paths??Ke,d=[o.exists&&(u===`brief`||o.changed>0)?Xe(e.project.name,B?.name??null,o,l):null,c.exists&&(u===`storyboard`||c.changed>0)?Ze(e.project.name,B?.name??null,c,l):null].filter(e=>e!==null),f=null,p;try{({batch:f,agent:p}=await K.post(`/api/batches`,B?{video:B.id}:{}))}catch(e){if(!(e instanceof ti&&e.code===`empty_batch`))return z(e.message)}let m=f?IC(p,n,z):null;if(m&&!m.dialog){if(i(),d.length===0)return;f=null}if(!f&&d.length===0)return u===`brief`&&!o.exists?z(`There's no brief yet: copy the prompt on this page for your agent`):u===`storyboard`&&!c.exists?z(`There's no storyboard yet: copy the prompt on this page for your agent`):z(B&&e.project.videos.length>1?`Nothing open to send on ${B.name}`:`Nothing open to send on any tab`);x(f?{id:f.id,prompt:[f.prompt,...d].join(`
|
|
67
|
+
|
|
68
|
+
`),why:m?.why}:{id:`plan`,title:`Message for your agent`,prompt:d.join(`
|
|
69
|
+
|
|
70
|
+
`),lead:j_(m,n)}),A(!1),f&&i()},Rt=async(e,t=s)=>{O(!1);for(let n of e){let e;try{({agent:e}=await K.post(`/api/batches/${encodeURIComponent(n.id)}/resend`,{}))}catch(e){if(e instanceof ti&&(e.code===`batch_delivered`||e.code===`batch_not_waiting`))continue;return i(),z(e.message)}let r=IC(e,t,z);if(r.dialog){x({id:n.id,prompt:n.prompt,why:r.why}),A(!1),i();return}}i()},zt=async()=>{if(b)try{await navigator.clipboard.writeText(b.prompt),A(!0)}catch{z(`Couldn't reach the clipboard. Select the text and copy it.`)}};if(!e||!u)return Q(`div`,{class:`shell`,children:n?Q(`div`,{class:`banner`,children:[Q($,{name:`alert`}),n]}):Q(`div`,{class:`emptypage`,children:Q(`p`,{children:`Loading…`})})});let V=ur(e,B?.id),Bt=B&&e.films?.[B.id]?.paths||Ke,Vt=V.notes.notes.filter(e=>e.stage===`picture`||e.stage===`mix`),Ht=t=>e.notes.notes.filter(n=>n.status===`todo`&&JC.has(n.stage)&&lr(n,t,e.project.videos)).length,Ut=ir(e.picks,B?.id).use,Wt=V.notes.notes.filter(e=>e.stage===`mix`),Kt=!nt&&(!!(Ut?.voice||Ut?.music||Ut?.sfx)||Wt.length>0)&&(!!B||e.project.videos.length===0),qt=!!Dt(`picture`)?.unlocked||Kt,Jt=u===`assets`?kt:u===`brief`?V.brief.exists:u===`storyboard`?V.storyboard.exists:u===`picture`?qt:Dt(u)?.unlocked??!1,Yt=!!Dt(`picture`)?.unlocked,Xt=Ue(V.brief,V.script.sections,V.storyboard),Zt=Xt.brief===`ok`&&Xt.script===`ok`&&Xt.storyboard===`ok`,Qt=V.build.started&&!Yt,$t=Dt(`script`)?.todo??0,en=[{page:`brief`,name:`Brief`,icon:`brief`,unlocked:V.brief.exists,ask:We.ask,approved:Xt.brief===`ok`,open:V.brief.changed},{page:`script`,name:`Script`,icon:Vh.script,unlocked:!!Dt(`script`)?.unlocked,ask:Le.script.ask,approved:Xt.script===`ok`,open:$t},{page:`storyboard`,name:`Storyboard`,icon:`story`,unlocked:V.storyboard.exists,ask:Ge.ask,approved:Xt.storyboard===`ok`,open:V.storyboard.changed}],tn=V.brief.changed+V.storyboard.changed+$t,nn=async()=>{try{await navigator.clipboard.writeText(Ye(e.project.name,B?.name??null,Bt)),z(`Prompt copied`)}catch{z(`Couldn't reach the clipboard. Ask your agent to build the film from the approved plan.`)}},rn=Mm(u),an=mr(e.project.lanes,B?.id,e.project.videos),on=Ut,sn={voice:Lm(an,`voice`,on?.voice,B),music:Lm(an,`music`,on?.music,B),sfx:Lm(an,`sfx`,on?.sfx,B)},cn=new Set(e.project.videos.filter(Ne).map(e=>e.id)),ln={notes:V.notes.notes,inPlay:cn,scriptTodo:Dt(`script`)?.todo??0,briefChanged:V.brief.changed,storyboardChanged:V.storyboard.changed},un=Ym(ln),dn=Xm(e.batches.batches,e.notes.notes),fn=dn.length===0?null:{count:dn.reduce((e,t)=>e+t.notes,0),why:dn[dn.length-1].batch.undelivered?.why??``,onSendAgain:()=>void Rt(dn.map(e=>e.batch))},pn=V.notes.notes.every(e=>e.stage===`script`||e.status!==`todo`||e.batch!==null||!!e.video&&!cn.has(e.video))&&un>0&&V.brief.changed+V.storyboard.changed+(Dt(`script`)?.todo??0)>0?He(u)?u:S:w,mn=un>0&&!Ee?{text:`Send ${un} ${Jm(ln)>0?un===1?`change`:`changes`:un===1?`note`:`notes`}`}:null,gn=()=>{if(j)return z(`Add or clear your note first`);At(pn),Te.setShown(!0),ke.setOpen(!1),Ie(!0)},_n=YC.map(({view:e,label:t})=>({view:e,label:t,icon:Vh[e],locked:e===`picture`?!qt:!Dt(e)?.unlocked,ask:Le[e].ask,takes:e===`voice`||e===`music`||e===`sfx`?Hm(sn[e]):null,todo:(Dt(e)?.todo??0)+(e===`picture`?Dt(`mix`)?.todo??0:0)})),vn=rn.workspace===`review`&&_n.some(e=>!e.locked),yn=(ot.find(e=>e.id===ct)??ot.find(e=>e.primary)??ot[0])?.label??null,bn=Ot!==null&&kn(e.found)!==Ce&&Tn(e.found?.counts)>0,xn={log:ke,activity:{projectId:ni()??``,head:V.log,project:e.project,film:B?.id??null,notes:e.notes.notes,stage:u===`brief`||u===`storyboard`?`script`:u,toast:z,onJump:e=>{wt(e),Te.narrow&&(Te.setShown(!1),Re.current?.focus())}},send:{count:un,always:u===`brief`&&V.brief.exists||u===`storyboard`&&V.storyboard.exists,onSend:()=>void Lt(),again:fn},agent:s&&{status:s,onSetUp:ye.open,menu:l,onStatus:c,toast:z},shown:Te.shown,narrow:Te.narrow,setShown:Te.setShown,width:Te.width,setWidth:Te.setWidth,reveal:Ae,onRevealed:()=>Ie(!1),revealNotes:e=>{ze.current=e,Te.setShown(!0),ke.open?ke.setOpen(!1,!1):Te.shown&&(ze.current=null,e())}},Sn=(e,t=Q(iy,{notes:[],version:null,placeholder:``,readOnly:!0,toast:z,onAdd:async()=>void 0,onChanged:()=>void i()}))=>Q(`div`,{class:`split deskcols`,children:[Q(`div`,{class:`wsmain`,...He(u)?{role:`tabpanel`,id:kg,"aria-labelledby":Ag(u)}:{},children:e}),t]}),Cn=V.notes.notes.filter(e=>e.stage===`script`),wn=Ve&&u===`script`?Km({kind:`line`,...Ve},null):{stage:`script`,on:null,scope:`whole`,t:null,tOut:null,label:`The script`},En=u===`script`,Dn=Q(QC,{notes:Cn,version:null,placeholder:`Note on ${wn.label}`,fixedTimes:!0,toast:z,onLabel:t=>t.on===null?`The script`:Om(t,{project:e.project,script:V.script}),target:{label:wn.label,onClear:Ve&&u===`script`?()=>qe(null):void 0},onAdd:async e=>{await K.post(`/api/notes`,{stage:`script`,video:B?.id??null,version:null,on:wn.on,scope:`whole`,t:null,tOut:null,text:e}),i()},onChanged:()=>void i(),onPendingChange:ee,readOnly:!En,instead:En?void 0:`Notes on the plan are written on the Script page.`});return Q(Kv.Provider,{value:xn,children:Q(`div`,{class:`shell${Ee&&!Te.narrow&&!Te.shown?` nhidden`:``}`,style:{"--notes-w":`${Te.width}px`},children:[Q(kC,{barRef:Ft,project:e.project.name,projectId:e.project.id??null,film:e.project.videos.length>0?Q(yC,{films:e.project.videos,currentId:B?.id??null,openNotes:Ht,onSwitch:_t,onRestore:t=>{let n=e.project.videos.find(e=>e.id===t);n&&St(n,!1)},shelvedRequest:yt}):null,cut:B&&nt?Q(vC,{video:B,shown:nt,newer:mt??gt,onPick:ht,onToggleLock:()=>void vt()}):null,workspaces:Q(qC,{current:rn.workspace,plan:{approved:Zt,open:tn,locked:en.every(e=>!e.unlocked)},hasVisuals:!!Dt(`visuals`)?.unlocked,assetsUnlocked:kt,found:bn?{count:Tn(e.found?.counts),text:Ot}:null,onPick:e=>e===`plan`?jt():e===`assets`?Mt():At(e===`visuals`?`visuals`:w)}),agent:Q(AC,{status:s,notes:e.notes.notes,onOpen:()=>{Ee||At(w),Te.setShown(!0),ke.setOpen(!0,!1)},onStop:()=>void K.post(`/api/agent/stop`,{}).catch(e=>z(e.message))}),notesToggle:Ee?Q(ry,{shown:Te.shown,onToggle:Te.toggle,buttonRef:Re}):null,more:Q(SC,{found:Ot,onBringIn:()=>Nt(),video:B,onToggleShelved:Ct,autoProxy:e.project.autoProxy,onKeys:()=>{x(null),O(!0)},toast:z,onChanged:()=>void i()})}),ye.sheet(un>0,e=>void Lt({asked:!0,status:e})),b&&!ye.shown&&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:b.title??`Batch ${b.id} is ready`}),Q(`span`,{class:`sp`}),Q(`button`,{class:`btn ghost ib sm`,"aria-label":`Close`,"data-tip":`Close`,onClick:()=>x(null),children:Q($,{name:`x`})})]}),b.why&&Q(BC,{why:b.why,onSetUp:()=>ye.open(b.id)}),b.lead&&Q(`p`,{class:`slead`,children:b.lead}),Q(`pre`,{children:b.prompt}),Q(`div`,{style:{display:`flex`,justifyContent:`flex-end`},children:Q(`button`,{class:`btn primary`,onClick:()=>void zt(),children:[Q($,{name:`copy`}),k?`Copied`:`Copy prompt`]})})]}),D&&Q(`div`,{class:`pop`,role:`dialog`,"aria-label":`Keyboard shortcuts`,style:{width:`320px`},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`,"data-tip":`Close`,onClick:()=>O(!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:`V`})}),Q(`span`,{children:`Select`}),Q(`span`,{children:Q(`kbd`,{children:`F`})}),Q(`span`,{children:`Full screen`}),Q(`span`,{children:Q(`kbd`,{children:`1`})}),Q(`span`,{children:`Plan`}),Q(`span`,{children:[Q(`kbd`,{children:`2`}),`–`,Q(`kbd`,{children:`6`})]}),Q(`span`,{children:`Review: Timeline, Voice, Music, Effects, Timeline`}),Q(`span`,{children:[Q(`kbd`,{children:`7`}),` `,Q(`kbd`,{children:`8`})]}),Q(`span`,{children:`Visuals, Assets`}),Q(`span`,{children:[Q(`kbd`,{children:`[`}),` `,Q(`kbd`,{children:`]`})]}),Q(`span`,{children:`Previous or next film`}),Q(`span`,{children:[Q(`kbd`,{children:`Shift`}),` `,Q(`kbd`,{children:`S`})]}),Q(`span`,{children:`Shelve or restore the 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:`Hide or show the notes panel`}),Q(`span`,{children:Q(`kbd`,{children:`?`})}),Q(`span`,{children:`Shortcuts`}),Q(`span`,{children:Q(`kbd`,{children:`Esc`})}),Q(`span`,{children:`Close`})]})]}),g&&Q(`div`,{class:`toast`,role:`status`,children:[g,v&&Q(`button`,{type:`button`,class:`toastact`,onClick:()=>{_(null),y(null),v.run()},children:v.label})]}),Q(`div`,{class:`work`,children:[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.`]}),n&&!r&&Q(`div`,{class:`banner`,children:[Q($,{name:`alert`}),n]}),rn.workspace===`plan`&&Q(`div`,{class:`rtabrow planrow`,children:[Q(jg,{rows:en,selected:He(u)?u:null,onPick:e=>At(e)}),Qt&&V.build.ready&&Q(`div`,{class:`planready`,children:[Q(`span`,{class:`rd`,children:[Q($,{name:`check`}),`Ready to build`]}),Q(`button`,{type:`button`,class:`btn`,onClick:()=>void nn(),children:[Q($,{name:`copy`}),`Copy prompt for your agent`]})]})]}),vn&&Q(`div`,{class:`rtabrow`,children:Q(CC,{rows:_n,selected:u,onPick:e=>At(e)})}),B?.shelved&&JC.has(u)&&Q(bC,{video:B,onRestore:()=>void St(B,!1)}),Q(`main`,{class:`body${B?.shelved?` fshelved`:``}`,ref:It,children:u===`assets`?Jt?Q(Tg,{assets:t,videos:e.project.videos,state:V,film:B?.id??null,foundRequest:xe,onFoundRequestUsed:()=>Se(e=>e.pending?{n:e.n,pending:!1}:e),onFoundSeen:we,toast:z,onChanged:()=>void i()}):Q(ZC,{tab:`assets`,projectName:e.project.name,filmName:B?.name??null,found:e.found?.counts,onReview:Nt,toast:z}):Jt?u===`picture`&&Kt?Q(gx,{state:V,assets:t,video:B??null,notes:Wt,prompt:Be(`picture`,e.project.name,B?.name??null),readOnly:!!B?.shelved,toast:z,onChanged:()=>void i(),onPendingChange:ee,clock:te,mixView:I},B?.id??`project`):u===`picture`&&!B?Sn(Q(xC,{onOpen:()=>bt(e=>e+1)})):u===`picture`&&B&&nt?Q(oS,{readOnly:!!B.shelved,video:B,version:nt,fps:it,notes:Vt,toast:z,onChanged:()=>void i(),onPendingChange:ee,clock:te,mixView:I,grab:ne[B.id]??null,onGrabChange:oe,playerRef:ae,ffmpeg:e.proxies?.ffmpeg??!1,proxyJob:a[hn(B.id,nt.id)],noteProxyJob:o,source:se[B.id]??`proxy`,onSourceChange:le,formats:ot,format:ct,formatMissing:!!ct&<.has(ot.find(e=>e.id===ct)?.file??``),onPrimarySize:(e,t,n)=>pe(r=>r[e]?r:{...r,[e]:{width:t,height:n}}),onBoxPendingChange:he,onMarksPendingChange:ge,onFormatChange:dt,formatSwitch:ut.length>1?Q(Hg,{chips:ut,versionId:nt.id,prompt:Yn(e.project.name,B.name,nt.id),onSelect:dt,toast:z}):null,state:V,assets:t},B.id):u===`brief`?Sn(Q(Bg,{brief:V.brief,video:B?.id??null,toast:z,onChanged:()=>void i(),settle:E},B?.id??``),Dn):u===`storyboard`?Sn(Q(pS,{board:V.storyboard,brief:V.brief,video:B?.id??null,toast:z,onChanged:()=>void i(),settle:E},B?.id??``),Dn):u===`visuals`?Q(oC,{state:V,toast:z,onChanged:()=>void i(),onPendingChange:ee}):u===`script`?Sn(Q(vS,{script:V.script,video:B?.id??null,toast:z,onChanged:()=>void i(),onPickLine:qe},B?.id??``),Dn):u===`voice`?Q(DS,{state:V,assets:t,video:B??null,toast:z,onChanged:()=>void i(),onPendingChange:ee,onPlayingChange:pt,clock:te,version:nt??null},`voice`):u===`music`||u===`sfx`?Q(wS,{stage:u,state:V,assets:t,video:B??null,toast:z,onChanged:()=>void i(),onPendingChange:ee,onPlayingChange:pt,clock:te,version:nt??null},u):null:Sn(Q(ZC,{tab:u,projectName:e.project.name,filmName:B?.name??null,found:e.found?.counts,onReview:Nt,toast:z,paths:Bt}))})]}),Q(TC,{send:mn?{text:mn.text,onGo:gn}:null,cut:B&&nt?{format:yn,fps:it,id:nt.id,lockedAt:B.lockedVersion}:null,shapes:u===`picture`&&B&&nt&&ut.length===1?{prompt:Yn(e.project.name,B.name,nt.id),toast:z}:null}),e.version&&Q(`span`,{class:`ver`,"aria-label":`Rushes version ${e.version}`,children:[`v`,e.version]})]})})}Ht(document),Dr(br(wr())),ce(Q($C,{}),document.getElementById(`app`));
|