rushes 0.9.0 → 0.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/plugin.json +1 -1
- package/AGENTS.md +2 -2
- package/dist/mcp/tools.js +1 -1
- package/dist/server/app.js +1 -1
- package/package.json +1 -1
- package/skills/rushes/SKILL.md +2 -2
- package/web-dist/assets/{index-DebHxWrg.css → index-D8GLNrzy.css} +1 -1
- package/web-dist/assets/{index-D-520-nU.js → index-DdsawADA.js} +7 -7
- package/web-dist/index.html +2 -2
|
@@ -52,16 +52,16 @@ var e=(e,t)=>()=>(t||(e((t={exports:{}}).exports,t),e=null),t.exports);(function
|
|
|
52
52
|
|
|
53
53
|
`)}return o.write(`payload.value = newResult;`),o.write(`return payload;`),o.compile()},o,s=vi,c=!ma.jitless,l=c&&yi.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?Gs([],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 Js(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=>!Ri(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=>Ui(e,r,ha())))}),t)}var Ys=J(`$ZodUnion`,(e,t)=>{Go.init(e,t),ia(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),ia(e,`optout`,e=>e.def.options.some(e=>e._zod.optout===`optional`)?`optional`:void 0),ia(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)))}),ia(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=>ai(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=>Js(t,r,e,i)):Js(o,r,e,i)}}),Xs=J(`$ZodIntersection`,(e,t)=>{Go.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])=>Qs(e,t,n)):Qs(e,i,a)}});function Zs(e,t){if(e===t||e instanceof Date&&t instanceof Date&&+e==+t)return{valid:!0,data:e};if(bi(e)&&bi(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=Zs(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=Zs(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 Qs(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=Zs(t.value,n.value);if(!c.valid){if(Ri(e))return e;throw Error(`Unmergable intersection. Error path: ${JSON.stringify(c.mergeErrorPath)}`)}return e.value=c.data,e}var $s=J(`$ZodRecord`,(e,t)=>{Go.init(e,t);let n=ma.memoizer;n?.attach(e),e._zod.parse=(r,i)=>{let a=r.value;if(!bi(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=>Ui(e,i,ha())),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(...Bi(n,e.issues)),r.value[l]=e.value})):(u.issues.length&&r.issues.push(...Bi(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`&&xo.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=>Ui(e,i,ha())),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(...Bi(n,e.issues)),r.value[u]=e.value})):(d.issues.length&&r.issues.push(...Bi(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}}),ec=J(`$ZodEnum`,(e,t)=>{Go.init(e,t);let n=$r(t.entries),r=new Set(n);e._zod.values=r,ia(e,`pattern`,e=>{let t=$r(e.def.entries).filter(e=>Si.has(typeof e));return RegExp(t.length?`^(${t.map(e=>Ci(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}}),tc=J(`$ZodLiteral`,(e,t)=>{Go.init(e,t);let n=new Set(t.values);e._zod.values=n,ia(e,`pattern`,e=>{let t=e.def.values;return RegExp(t.length?`^(${t.map(e=>typeof e==`string`?Ci(e):e?Ci(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}}),nc=J(`$ZodTransform`,(e,t)=>{Go.init(e,t),e._zod.optin=`optional`,ma.memoizer?.guard(e),e._zod.parse=(n,r)=>{if(r.direction===`backward`)throw new pa(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 fa;return n.value=i,n}});function rc(e,t){return e.value=t.issues.length?void 0:t.value,e}var ic=J(`$ZodOptional`,(e,t)=>{Go.init(e,t),ia(e,`optin`,e=>e.def.innerType._zod.optin===`defaulted`?`defaulted`:`optional`),e._zod.optout=`optional`,ia(e,`values`,e=>{let t=e.def.innerType._zod.values;return t?new Set([...t,void 0]):void 0}),ia(e,`pattern`,e=>{let t=e.def.innerType._zod.pattern;return t?RegExp(`^(${ai(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=>rc(e,t)):rc(e,r)}return t.innerType._zod.run(e,n)}}),ac=J(`$ZodExactOptional`,(e,t)=>{ic.init(e,t),ia(e,`values`,e=>e.def.innerType._zod.values),ia(e,`pattern`,e=>e.def.innerType._zod.pattern),e._zod.parse=(e,n)=>t.innerType._zod.run(e,n)}),oc=J(`$ZodNullable`,(e,t)=>{Go.init(e,t),ia(e,`optin`,e=>e.def.innerType._zod.optin),ia(e,`optout`,e=>e.def.innerType._zod.optout),ia(e,`pattern`,e=>{let t=e.def.innerType._zod.pattern;return t?RegExp(`^(${ai(t.source)}|null)$`):void 0}),ia(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)}),sc=J(`$ZodDefault`,(e,t)=>{Go.init(e,t),e._zod.optin=`defaulted`,ia(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=>cc(e,t)):cc(r,t)}});function cc(e,t){return e.value===void 0&&(e.value=t.defaultValue),e}var lc=J(`$ZodPrefault`,(e,t)=>{Go.init(e,t),e._zod.optin=`defaulted`,ia(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))}),uc=J(`$ZodNonOptional`,(e,t)=>{Go.init(e,t),ia(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=>dc(t,e)):dc(i,e)}});function dc(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 fc(e,t,n,r){return t.issues.length?(e.value=n.catchValue({...t,value:e.value,error:{issues:t.issues.map(e=>Ui(e,r,ha()))},input:e.value}),e):(e.value=t.value,t.memo&&(e.memo=!0),e)}var pc=J(`$ZodCatch`,(e,t)=>{Go.init(e,t),ia(e,`optin`,e=>e.def.innerType._zod.optin===`defaulted`?`defaulted`:`optional`),ia(e,`optout`,e=>e.def.innerType._zod.optout),ia(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=>fc(e,r,t,n)):fc(e,r,t,n)}}),mc=J(`$ZodPipe`,(e,t)=>{Go.init(e,t),ia(e,`values`,e=>e.def.in._zod.values),ia(e,`optin`,e=>e.def.in._zod.optin),ia(e,`optout`,e=>e.def.out._zod.optout),ia(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=>hc(e,t.in,n)):hc(r,t.in,n)}let r=t.in._zod.run(e,n);return r instanceof Promise?r.then(e=>hc(e,t.out,n)):hc(r,t.out,n)}});function hc(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 gc=J(`$ZodPreprocess`,(e,t)=>{mc.init(e,t)}),_c=J(`$ZodReadonly`,(e,t)=>{Go.init(e,t),ia(e,`propValues`,e=>e.def.innerType._zod.propValues),ia(e,`values`,e=>e.def.innerType._zod.values),ia(e,`optin`,e=>e.def.innerType?._zod?.optin),ia(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(vc):vc(r)}});function vc(e){return e.memo||(e.value=Object.freeze(e.value)),e}var yc=J(`$ZodCustom`,(e,t)=>{To.init(e,t),Go.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=>bc(t,n,r,e));bc(i,n,r,e)}});function bc(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(Ji(e))}}var xc=class extends Error{constructor(){super(`Cannot parse a reference cycle that closes through a transform`),this.name=`ZodCyclicError`}},Sc=`~memo`,Cc=[];function wc(e){return typeof e==`object`&&!!e}function Tc(e){return e.map(e=>e.path?{...e,path:e.path.slice()}:{...e})}var Ec=new WeakMap,Dc=0,Oc=1,kc=2;function Ac(e,t,n){let r=Ec.get(e);if(r!==void 0)return r?kc:Dc;if(t.has(e))return kc;t.add(e);let i=Dc,a=e=>{if(i!==kc&&e?._zod){let r=Ac(e,t,n);r>i&&(i=r)}},o=(e,r)=>{let i=Dc;for(let a of Reflect.ownKeys(e)){let o=Object.getOwnPropertyDescriptor(e,a);if(r&&!o.enumerable)continue;let s=o.get?Oc:o.value?._zod?Ac(o.value,t,n):Dc;s>i&&(i=s)}return i},s=e=>{e>i&&(i=e)},c=e._zod.def;switch(c.type){case`object`:{let e=ci(c);s(e?o(e,!0):Oc),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?Ac(r,t,!1):Oc);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),jc(e,i)}function jc(e,t){return t!==Oc&&Ec.set(e,t===kc),t}function Mc(e,t){let n=e.buckets.get(t);return n||(n=new WeakMap,e.buckets.set(t,n)),n}var Nc,Pc=[],Fc={alloc(e,t,n){let r=Nc;if(!r)return n;Nc=void 0;let i={value:n,issues:null};return r.set(t.value,i),Pc.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`&&Lc(n,e.value))throw new xc;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=Ac(e,new Set,!1);if(i===Dc)return e._zod.parse=t,e._zod.run===o&&(e._zod.run=t),t(s,c);i===kc||r?n=!0:r=!0}let l=s.value;if(!wc(l))return t(s,c);let u=c[Sc];u||(u={buckets:new WeakMap,backEdges:void 0},c[Sc]=u);let d;i===c?d=a:(d=Mc(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(...Tc(f.issues)):(s.memo=!0,u.backEdges??(u.backEdges=new WeakSet),u.backEdges.add(f.value)),s;Nc=d;let p=Pc.length,m=t(s,c);Nc=void 0;let h=Pc.length>p?Pc.pop():void 0;return m instanceof Promise?m.then(e=>(h&&(h.issues=e.issues.length?Tc(e.issues):Cc),e)):(h&&(h.issues=m.issues.length?Tc(m.issues):Cc),m)};e._zod.parse=o,e._zod.run===t&&(e._zod.run=o)})}};function Ic(){return Fc}function Lc(e,t){let n=e[Sc]?.backEdges;return n!==void 0&&wc(t)&&n.has(t)}var Rc=()=>{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(qi(e.input),e.input)}`;case`invalid_value`:return e.values.length===1?`Invalid input: expected ${Ti(e.values[0])}`:`Invalid option: expected one of ${ei(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`:``}: ${ei(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:Rc()}}var Bc,Vc=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 Hc(){return new Vc}(Bc=globalThis).__zod_globalRegistry??(Bc.__zod_globalRegistry=Hc());var Uc=globalThis.__zod_globalRegistry;function Wc(e){return e.checks&&=[...e.checks],e}function Gc(e,t){return new e(Wc({type:`string`,...q(t)}))}function Kc(e,t){return new e({type:`string`,format:`email`,check:`string_format`,abort:!1,...q(t)})}function qc(e,t){return new e({type:`string`,format:`guid`,check:`string_format`,abort:!1,...q(t)})}function Jc(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,...q(t)})}function Yc(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v4`,...q(t)})}function Xc(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v6`,...q(t)})}function Zc(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v7`,...q(t)})}function Qc(e,t){return new e({type:`string`,format:`url`,check:`string_format`,abort:!1,...q(t)})}function $c(e,t){return new e({type:`string`,format:`emoji`,check:`string_format`,abort:!1,...q(t)})}function el(e,t){return new e({type:`string`,format:`nanoid`,check:`string_format`,abort:!1,...q(t)})}function tl(e,t){return new e({type:`string`,format:`cuid`,check:`string_format`,abort:!1,...q(t)})}function nl(e,t){return new e({type:`string`,format:`cuid2`,check:`string_format`,abort:!1,...q(t)})}function rl(e,t){return new e({type:`string`,format:`ulid`,check:`string_format`,abort:!1,...q(t)})}function il(e,t){return new e({type:`string`,format:`xid`,check:`string_format`,abort:!1,...q(t)})}function al(e,t){return new e({type:`string`,format:`ksuid`,check:`string_format`,abort:!1,...q(t)})}function ol(e,t){return new e({type:`string`,format:`ipv4`,check:`string_format`,abort:!1,...q(t)})}function sl(e,t){return new e({type:`string`,format:`ipv6`,check:`string_format`,abort:!1,...q(t)})}function cl(e,t){return new e({type:`string`,format:`cidrv4`,check:`string_format`,abort:!1,...q(t)})}function ll(e,t){return new e({type:`string`,format:`cidrv6`,check:`string_format`,abort:!1,...q(t)})}function ul(e,t){return new e({type:`string`,format:`base64`,check:`string_format`,abort:!1,...q(t)})}function dl(e,t){return new e({type:`string`,format:`base64url`,check:`string_format`,abort:!1,...q(t)})}function fl(e,t){return new e({type:`string`,format:`e164`,check:`string_format`,abort:!1,...q(t)})}function pl(e,t){return new e({type:`string`,format:`jwt`,check:`string_format`,abort:!1,...q(t)})}function ml(e,t){return new e({type:`string`,format:`datetime`,check:`string_format`,offset:!1,local:!1,precision:null,...q(t)})}function hl(e,t){return new e({type:`string`,format:`date`,check:`string_format`,...q(t)})}function gl(e,t){return new e({type:`string`,format:`time`,check:`string_format`,precision:null,...q(t)})}function _l(e,t){return new e({type:`string`,format:`duration`,check:`string_format`,...q(t)})}function vl(e,t){return new e(Wc({type:`number`,checks:[],...q(t)}))}function yl(e,t){return new e({type:`number`,check:`number_format`,abort:!1,format:`safeint`,...q(t)})}function bl(e,t){return new e({type:`boolean`,...q(t)})}function xl(e){return new e({type:`unknown`})}function Sl(e,t){return new e({type:`never`,...q(t)})}function Cl(e,t){return new Oo({check:`less_than`,...q(t),value:e,inclusive:!1})}function wl(e,t){return new Oo({check:`less_than`,...q(t),value:e,inclusive:!0})}function Tl(e,t){return new ko({check:`greater_than`,...q(t),value:e,inclusive:!1})}function El(e,t){return new ko({check:`greater_than`,...q(t),value:e,inclusive:!0})}function Dl(e,t){return new Ao({check:`multiple_of`,...q(t),value:e})}function Ol(e,t){return new Mo({check:`max_length`,...q(t),maximum:e})}function kl(e,t){return new No({check:`min_length`,...q(t),minimum:e})}function Al(e,t){return new Po({check:`length_equals`,...q(t),length:e})}function jl(e,t){return new Io({check:`string_format`,format:`regex`,...q(t),pattern:e})}function Ml(e){return new Lo({check:`string_format`,format:`lowercase`,...q(e)})}function Nl(e){return new Ro({check:`string_format`,format:`uppercase`,...q(e)})}function Pl(e,t){return new zo({check:`string_format`,format:`includes`,...q(t),includes:e})}function Fl(e,t){return new Bo({check:`string_format`,format:`starts_with`,...q(t),prefix:e})}function Il(e,t){return new Vo({check:`string_format`,format:`ends_with`,...q(t),suffix:e})}function Ll(e){return new Ho({check:`overwrite`,tx:e})}function Rl(e){return Ll(t=>t.normalize(e))}function zl(){return Ll(e=>e.trim())}function Bl(){return Ll(e=>e.toLowerCase())}function Vl(){return Ll(e=>e.toUpperCase())}function Hl(){return Ll(e=>gi(e))}function Ul(e,t,n){return new e({type:`array`,element:t,...q(n)})}function Wl(e,t,n){return new e({type:`custom`,check:`custom`,fn:t,...q(n)})}function Gl(e,t){let n=Kl(t=>(t.addIssue=e=>{if(typeof e==`string`)t.issues.push(Ji(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(Ji(r))}},e(t.value,t)),t);return n}function Kl(e,t){let n=new To({check:`custom`,...q(t)});return n._zod.check=e,n}function ql(e,...t){for(let n of t)for(let t of Reflect.ownKeys(n))Object.prototype.propertyIsEnumerable.call(n,t)&&si(e,t,n[t]);return e}function Jl(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??Uc,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 Yl(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 Xl(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,Xl(a,t,r),t.seen.get(a).isParent=!0)}let c=t.metadataRegistry.get(e);return c&&ql(o.schema,c),t.io===`input`&&ou(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 Zl(e){return e.replace(/~/g,`~0`).replace(/\//g,`~1`)}function Ql(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}/${Zl(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+Zl(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
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 $l(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;$l(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 eu=new Set([`type`,`properties`,`required`,`additionalProperties`]),tu=[`oneOf`,`anyOf`];function nu(e){let t=e.additionalProperties;return t===void 0||t===!1||typeof t!=`object`||!t?null:Object.keys(t).length?t:null}function ru(e){let t=[];for(let n of e){if(typeof n!=`object`||n.type!==`object`)return null;for(let e in n)if(!eu.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]??nu(n);t!=null&&(e.some(e=>JSON.stringify(e)===JSON.stringify(t))||e.push(t))}si(n,r,e.length===1?e[0]:ru(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=nu(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 iu(e){let t=e.allOf;if(!Array.isArray(t)||t.length<2)return;for(let t of eu)if(t in e)return;let n=t.filter(e=>tu.some(t=>Array.isArray(e[t]))),r=null;if(!n.length)r=ru(t);else{let e=n[0],i=tu.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=>ru([...a,e]));if(o.some(e=>!e))return;r={[i]:o}}r&&(delete e.allOf,ql(e,r))}function au(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)):ql(i,s),ql(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())$l(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)??[])iu(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)}ql(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,si(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:cu(t,`input`,e.processors),output:cu(t,`output`,e.processors)}},enumerable:!1,writable:!1}),n}catch{throw Error(`Error converting schema to JSON.`)}}function ou(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 ou(r.element,n);if(r.type===`set`)return ou(r.valueType,n);if(r.type===`lazy`)return ou(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 ou(r.innerType,n);if(r.type===`intersection`)return ou(r.left,n)||ou(r.right,n);if(r.type===`record`||r.type===`map`)return ou(r.keyType,n)||ou(r.valueType,n);if(r.type===`pipe`)return e._zod.traits.has(`$ZodCodec`)?!0:ou(r.in,n)||ou(r.out,n);if(r.type===`object`){for(let e in r.shape)if(ou(r.shape[e],n))return!0;return!1}if(r.type===`union`){for(let e of r.options)if(ou(e,n))return!0;return!1}if(r.type===`tuple`){for(let e of r.items)if(ou(e,n))return!0;return!!(r.rest&&ou(r.rest,n))}return!1}var su=(e,t={})=>n=>{let r=Jl({...n,processors:t});return Xl(e,r),Ql(r,e),au(r,e)},cu=(e,t,n={})=>r=>{let{libraryOptions:i,target:a}=r??{},o=Jl({...i??{},target:a,io:t,processors:n});return Xl(e,o),Ql(o,e),au(o,e)},lu=(e,t,n)=>{(e[t]===void 0||n>e[t])&&(e[t]=n)},uu=(e,t,n)=>{(e[t]===void 0||n<e[t])&&(e[t]=n)},du=(e,t)=>{lu(e,`minimum`,t),uu(e,`maximum`,t)},fu=(e,t)=>{e.multipleOf??=[],e.multipleOf.includes(t)||e.multipleOf.push(t)},pu=(e,t)=>{e.patterns??=new Set,e.patterns.add(t)},mu=(e,t)=>{e.mime=e.mime?e.mime.filter(e=>t.includes(e)):[...t]},hu=(e,t)=>{e.format=t,t.includes(`int`)&&(e.isInt=!0)},gu=(e,t)=>lu(e,`minimum`,t.minimum),_u=(e,t)=>uu(e,`maximum`,t.maximum),vu=e=>(t,n)=>{hu(t,n.format);let[r,i]=e[n.format];lu(t,`minimum`,r),uu(t,`maximum`,i)},yu={greater_than:(e,t)=>lu(e,t.inclusive?`minimum`:`exclusiveMinimum`,t.value),less_than:(e,t)=>uu(e,t.inclusive?`maximum`:`exclusiveMaximum`,t.value),multiple_of:(e,t)=>fu(e,t.value),number_format:vu(Di),bigint_format:vu(Oi),min_length:gu,max_length:_u,length_equals:(e,t)=>du(e,t.length),min_size:gu,max_size:_u,size_equals:(e,t)=>du(e,t.size),string_format:(e,t)=>{hu(e,t.format),t.pattern&&pu(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)=>mu(e,t.mime)};function bu(e){let t={},n=e._zod.def,r=e._zod.traits.has(`$ZodCheck`)?[e,...n.checks??[]]:n.checks??[];for(let e of r)yu[e._zod.def.check]?.(t,e._zod.def);let i=e._zod.bag;i.minimum!==void 0&&lu(t,`minimum`,i.minimum),i.exclusiveMinimum!==void 0&&lu(t,`exclusiveMinimum`,i.exclusiveMinimum),i.maximum!==void 0&&uu(t,`maximum`,i.maximum),i.exclusiveMaximum!==void 0&&uu(t,`exclusiveMaximum`,i.exclusiveMaximum),i.multipleOf!==void 0&&fu(t,i.multipleOf),i.format!==void 0&&(t.format??=i.format,i.format.includes(`int`)&&(t.isInt=!0)),i.mime&&mu(t,i.mime);for(let e of i.patterns??[])pu(t,e);return t}var xu={guid:`uuid`,url:`uri`,datetime:`date-time`,json_string:`json-string`,regex:``},Su=new Map([[Ds,co],[ks,lo]]),Cu=e=>Su.get(e)??e,wu=(e,t,n,r)=>{let i=n;i.type=`string`;let{minimum:a,maximum:o,format:s,patterns:c,contentEncoding:l,laxFormat:u}=bu(e);if(typeof a==`number`&&(i.minLength=a),typeof o==`number`&&(i.maxLength=o),s&&(i.format=xu[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(Cu);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}))])}},Tu=(e,t,n,r)=>{let i=n,{minimum:a,maximum:o,multipleOf:s,exclusiveMaximum:c,exclusiveMinimum:l,isInt:u}=bu(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)):Yl(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}))])}},Eu=(e,t,n,r)=>{n.type=`boolean`},Du=(e,t,n,r)=>{n.not={}},Ou=(e,t,n,r)=>{let i=e._zod.def,a=$r(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},ku=(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(Yl(e,t,n,r,"Literal `undefined` cannot be represented in JSON Schema"))return}else if(typeof o==`bigint`){if(Yl(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}},Au=(e,t,n,r)=>{Yl(e,t,n,r,`Custom types cannot be represented in JSON Schema`)},ju=(e,t,n,r)=>{Yl(e,t,n,r,`Transforms cannot be represented in JSON Schema`)},Mu=(e,t,n,r)=>{let i=n,a=e._zod.def,{minimum:o,maximum:s}=bu(e);typeof o==`number`&&(i.minItems=o),typeof s==`number`&&(i.maxItems=s),i.type=`array`,i.items=Xl(a.element,t,{...r,path:[...r.path,`items`]})};function Nu(e){let t=e._zod.def;return t.type===`pipe`&&t.in._zod.traits.has(`$ZodTransform`)?Nu(t.out):t.type===`catch`?Nu(t.innerType):e._zod.optin}var Pu=(e,t,n,r)=>{let i=n,a=e._zod.def,o=a.shape;if(Object.getOwnPropertySymbols(o).length&&Yl(e,t,i,r,`Symbol keys cannot be represented in JSON Schema`))return;i.type=`object`,i.properties={};for(let e in o)si(i.properties,e,Xl(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`?Nu(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=Xl(a.catchall,t,{...r,path:[...r.path,`additionalProperties`]})):t.io===`output`&&(i.additionalProperties=!1)},Fu=(e,t,n,r)=>{let i=e._zod.def,a=i.inclusive===!1,o=i.options.map((e,n)=>Xl(e,t,{...r,path:[...r.path,a?`oneOf`:`anyOf`,n]}));a?n.oneOf=o:n.anyOf=o},Iu=(e,t,n,r)=>{let i=e._zod.def,a=Xl(i.left,t,{...r,path:[...r.path,`allOf`,0]}),o=Xl(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 Lu(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=Lu(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=>Lu(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`)?xo:bo).source),p):p}var Ru=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 Ru.get(e)??[]){let i=e.seen.get(r),a=(i?.def??i?.schema)?.propertyNames;if(!a||a===!0||n.has(a))continue;let o=Lu(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 Bu=(e,t,n,r)=>{let i=n,a=e._zod.def;i.type=`object`;let o=a.keyType,s=bu(o).patterns;if(a.mode===`loose`&&s&&s.size>0){let e=Xl(a.valueType,t,{...r,path:[...r.path,`patternProperties`,`*`]});i.patternProperties={};for(let t of s)si(i.patternProperties,Cu(t).source,e)}else{if(t.target===`draft-07`||t.target===`draft-2020-12`){i.propertyNames=Xl(a.keyType,t,{...r,path:[...r.path,`propertyNames`]});let n=Ru.get(t);n||(n=[],Ru.set(t,n),t.deferred.push(()=>zu(t))),n.push(e)}i.additionalProperties=Xl(a.valueType,t,{...r,path:[...r.path,`additionalProperties`]})}let c=o._zod.values,l=t.io===`input`&&Nu(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))}},Vu=(e,t,n,r)=>{let i=e._zod.def,a=Xl(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`}]},Hu=(e,t,n,r)=>{let i=e._zod.def;Xl(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType},Uu=Symbol();function Wu(e,t,n,r,i){let a=!1,o=JSON.stringify(e,(e,t)=>typeof t==`bigint`?(a=!0,null):t);return a?(Yl(t,n,r,i,`BigInt defaults cannot be represented in JSON Schema`),Uu):JSON.parse(o)}var Gu=(e,t,n,r)=>{let i=e._zod.def;Xl(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType;let o=Wu(i.defaultValue,e,t,n,r);o!==Uu&&(n.default=o)},Ku=(e,t,n,r)=>{let i=e._zod.def;Xl(i.innerType,t,r);let a=t.seen.get(e);if(a.ref=i.innerType,t.io!==`input`)return;let o=Wu(i.defaultValue,e,t,n,r);o!==Uu&&(n._prefault=o)},qu=(e,t,n,r)=>{let i=e._zod.def;Xl(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType;let o;try{o=i.catchValue(void 0)}catch{Yl(e,t,n,r,`Dynamic catch values are not supported in JSON Schema`);return}n.default=o},Ju=(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;Xl(o,t,r);let s=t.seen.get(e);s.ref=o},Yu=(e,t,n,r)=>{let i=e._zod.def;Xl(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType,n.readOnly=!0},Xu=(e,t,n,r)=>{let i=e._zod.def;Xl(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType},Zu=new WeakSet([Object.prototype,Error.prototype]);function Qu(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 $u=J(`ZodError`,(e,t)=>{Sa.init(e,t),e.name=`ZodError`;let n=Object.getPrototypeOf(e);Zu.has(n)||(Zu.add(n),Qu(n,`format`,e=>t=>Ta(e,t)),Qu(n,`flatten`,e=>t=>wa(e,t)),Qu(n,`addIssue`,e=>t=>{e.issues.push(t),e.message=JSON.stringify(e.issues,ti,2)}),Qu(n,`addIssues`,e=>t=>{e.issues.push(...t),e.message=JSON.stringify(e.issues,ti,2)}),Object.defineProperty(n,"isEmpty",{configurable:!0,enumerable:!1,get(){return this.issues.length===0}}))},void 0,{Parent:Error}),ed=Da($u),td=Oa($u),nd=ka($u),rd=ja($u),id=La($u),ad=Ra($u),od=za($u),sd=Ba($u),cd=Va($u),ld=Ha($u),ud=Ua($u),dd=Wa($u);function fd(){ma.localeError||ha(zc())}function pd(){ma.memoizer||ha({memoizer:Ic()})}var md=J(`ZodType`,(e,t)=>(fd(),Go.init(e,t),e.def=t,e.type=t.type,e),{check(...e){let t=this.def;return this.clone(mi(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 wi(this,e,t)},brand(){return this},register(e,t){return e.add(this,t),this},refine(e,t){return this.check(Pf(e,t))},superRefine(e,t){return this.check(Ff(e,t))},overwrite(e){return this.check(Ll(e))},optional(){return hf(this)},exactOptional(){return _f(this)},nullable(){return yf(this)},nullish(){return hf(yf(this))},nonoptional(e){return Tf(this,e)},array(){return Zd(this)},or(e){return nf([this,e])},and(e){return af(this,e)},transform(e){return kf(this,pf(e))},default(e){return xf(this,e)},prefault(e){return Cf(this,e)},catch(e){return Df(this,e)},pipe(e){return kf(this,e)},readonly(){return Mf(this)},describe(e){let t=this.clone();return Uc.add(t,{description:e}),t},meta(...e){if(e.length===0)return Uc.get(this);let t=this.clone();return Uc.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 Zi(this,`~standard`,{...Jo(this),jsonSchema:{input:cu(this,`input`),output:cu(this,`output`)}})},set"~standard"(e){Xi(this,`~standard`,e)},parse:function e(t,n){return ed(this,t,n,{callee:e})},parseAsync:async function e(t,n){return await td(this,t,n,{callee:e})},safeParse(e,t){return nd(this,e,t)},async safeParseAsync(e,t){return rd(this,e,t)},get spa(){return this?.safeParseAsync},set spa(e){Xi(this,`spa`,e)},validate(e,t){return Pa(this,e,t)},validateAsync(e,t){return Ia(this,e,t)},encode:function e(t,n){return id(this,t,n,{callee:e})},decode:function e(t,n){return ad(this,t,n,{callee:e})},encodeAsync:async function e(t,n){return await od(this,t,n,{callee:e})},decodeAsync:async function e(t,n){return await sd(this,t,n,{callee:e})},safeEncode(e,t){return cd(this,e,t)},safeDecode(e,t){return ld(this,e,t)},async safeEncodeAsync(e,t){return ud(this,e,t)},async safeDecodeAsync(e,t){return dd(this,e,t)},toJSONSchema(e){return su(this,{})(e)},get description(){return Uc.get(this)?.description},get _def(){return this._zod.def}}),hd=J(`_ZodString`,(e,t)=>{Yo.init(e,t),md.init(e,t),e._zod.processJSONSchema=(t,n,r)=>wu(e,t,n,r)},Qi({format:e=>bu(e).format??null,minLength:e=>bu(e).minimum??null,maxLength:e=>bu(e).maximum??null},{regex(...e){return this.check(jl(...e))},includes(...e){return this.check(Pl(...e))},startsWith(...e){return this.check(Fl(...e))},endsWith(...e){return this.check(Il(...e))},min(...e){return this.check(kl(...e))},max(...e){return this.check(Ol(...e))},length(...e){return this.check(Al(...e))},nonempty(...e){return this.check(kl(1,...e))},lowercase(e){return this.check(Ml(e))},uppercase(e){return this.check(Nl(e))},trim(){return this.check(zl())},normalize(...e){return this.check(Rl(...e))},toLowerCase(){return this.check(Bl())},toUpperCase(){return this.check(Vl())},slugify(){return this.check(Hl())}})),gd=J(`ZodString`,(e,t)=>{Yo.init(e,t),hd.init(e,t)},{email(e){return this.check(Kc(Sd,e))},url(e){return this.check(Qc(Td,e))},jwt(e){return this.check(pl(Bd,e))},emoji(e){return this.check($c(Ed,e))},guid(e){return this.check(qc(Cd,e))},uuid(e){return this.check(Jc(wd,e))},uuidv4(e){return this.check(Yc(wd,e))},uuidv6(e){return this.check(Xc(wd,e))},uuidv7(e){return this.check(Zc(wd,e))},nanoid(e){return this.check(el(Dd,e))},cuid(e){return this.check(tl(Od,e))},cuid2(e){return this.check(nl(kd,e))},ulid(e){return this.check(rl(Ad,e))},base64(e){return this.check(ul(Ld,e))},base64url(e){return this.check(dl(Rd,e))},xid(e){return this.check(il(jd,e))},ksuid(e){return this.check(al(Md,e))},ipv4(e){return this.check(ol(Nd,e))},ipv6(e){return this.check(sl(Pd,e))},cidrv4(e){return this.check(cl(Fd,e))},cidrv6(e){return this.check(ll(Id,e))},e164(e){return this.check(fl(zd,e))},datetime(e){return this.check(ml(vd,e))},date(e){return this.check(hl(yd,e))},time(e){return this.check(gl(bd,e))},duration(e){return this.check(_l(xd,e))}});function Y(e){return Gc(gd,e)}var _d=J(`ZodStringFormat`,(e,t)=>{Xo.init(e,t),hd.init(e,t)}),vd=J(`ZodISODateTime`,(e,t)=>{hs.init(e,t),_d.init(e,t)}),yd=J(`ZodISODate`,(e,t)=>{gs.init(e,t),_d.init(e,t)}),bd=J(`ZodISOTime`,(e,t)=>{_s.init(e,t),_d.init(e,t)}),xd=J(`ZodISODuration`,(e,t)=>{vs.init(e,t),_d.init(e,t)}),Sd=J(`ZodEmail`,(e,t)=>{$o.init(e,t),_d.init(e,t)}),Cd=J(`ZodGUID`,(e,t)=>{Zo.init(e,t),_d.init(e,t)}),wd=J(`ZodUUID`,(e,t)=>{Qo.init(e,t),_d.init(e,t)}),Td=J(`ZodURL`,(e,t)=>{ss.init(e,t),_d.init(e,t)}),Ed=J(`ZodEmoji`,(e,t)=>{cs.init(e,t),_d.init(e,t)}),Dd=J(`ZodNanoID`,(e,t)=>{ls.init(e,t),_d.init(e,t)}),Od=J(`ZodCUID`,(e,t)=>{us.init(e,t),_d.init(e,t)}),kd=J(`ZodCUID2`,(e,t)=>{ds.init(e,t),_d.init(e,t)}),Ad=J(`ZodULID`,(e,t)=>{fs.init(e,t),_d.init(e,t)}),jd=J(`ZodXID`,(e,t)=>{ps.init(e,t),_d.init(e,t)}),Md=J(`ZodKSUID`,(e,t)=>{ms.init(e,t),_d.init(e,t)}),Nd=J(`ZodIPv4`,(e,t)=>{ys.init(e,t),_d.init(e,t)}),Pd=J(`ZodIPv6`,(e,t)=>{Ss.init(e,t),_d.init(e,t)}),Fd=J(`ZodCIDRv4`,(e,t)=>{Cs.init(e,t),_d.init(e,t)}),Id=J(`ZodCIDRv6`,(e,t)=>{Ts.init(e,t),_d.init(e,t)}),Ld=J(`ZodBase64`,(e,t)=>{Os.init(e,t),_d.init(e,t)}),Rd=J(`ZodBase64URL`,(e,t)=>{js.init(e,t),_d.init(e,t)}),zd=J(`ZodE164`,(e,t)=>{Ms.init(e,t),_d.init(e,t)}),Bd=J(`ZodJWT`,(e,t)=>{Ps.init(e,t),_d.init(e,t)}),Vd=J(`ZodNumber`,(e,t)=>{Fs.init(e,t),md.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Tu(e,t,n,r),e.isFinite=!0},Qi({minValue:e=>{let{minimum:t,exclusiveMinimum:n}=bu(e);return Math.max(t??-1/0,n??-1/0)},maxValue:e=>{let{maximum:t,exclusiveMaximum:n}=bu(e);return Math.min(t??1/0,n??1/0)},isInt:e=>{let{isInt:t,multipleOf:n}=bu(e);return!!t||!!n?.some(Number.isSafeInteger)},format:e=>bu(e).format??null},{gt(e,t){return this.check(Tl(e,t))},gte(e,t){return this.check(El(e,t))},min(e,t){return this.check(El(e,t))},lt(e,t){return this.check(Cl(e,t))},lte(e,t){return this.check(wl(e,t))},max(e,t){return this.check(wl(e,t))},int(e){return this.check(Ud(e))},safe(e){return this.check(Ud(e))},positive(e){return this.check(Tl(0,e))},nonnegative(e){return this.check(El(0,e))},negative(e){return this.check(Cl(0,e))},nonpositive(e){return this.check(wl(0,e))},multipleOf(e,t){return this.check(Dl(e,t))},step(e,t){return this.check(Dl(e,t))},finite(){return this}}));function X(e){return vl(Vd,e)}var Hd=J(`ZodNumberFormat`,(e,t)=>{Is.init(e,t),Vd.init(e,t)});function Ud(e){return yl(Hd,e)}var Wd=J(`ZodBoolean`,(e,t)=>{Ls.init(e,t),md.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Eu(e,t,n,r)});function Gd(e){return bl(Wd,e)}var Kd=J(`ZodUnknown`,(e,t)=>{Rs.init(e,t),md.init(e,t),e._zod.processJSONSchema=(e,t,n)=>void 0});function qd(){return xl(Kd)}var Jd=J(`ZodNever`,(e,t)=>{zs.init(e,t),md.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Du(e,t,n,r)});function Yd(e){return Sl(Jd,e)}var Xd=J(`ZodArray`,(e,t)=>{pd(),Vs.init(e,t),md.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Mu(e,t,n,r),e.element=t.element},{min(e,t){return this.check(kl(e,t))},nonempty(e){return this.check(kl(1,e))},max(e,t){return this.check(Ol(e,t))},length(e,t){return this.check(Al(e,t))},unwrap(){return this.element}});function Zd(e,t){return Ul(Xd,e,t)}var Qd=J(`ZodObject`,(e,t)=>{pd(),qs.init(e,t),md.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Pu(e,t,n,r),aa(e,`shape`,e=>e._zod.def.shape,!1)},{keyof(){return lf(Object.keys(this._zod.def.shape))},catchall(e){return this.clone(mi(this._zod.def,{catchall:e}))},passthrough(){return this.clone(mi(this._zod.def,{catchall:qd()}))},loose(){return this.clone(mi(this._zod.def,{catchall:qd()}))},strict(){return this.clone(mi(this._zod.def,{catchall:Yd()}))},strip(){return this.clone(mi(this._zod.def,{catchall:void 0}))},extend(e){return Mi(this,e)},safeExtend(e){return Pi(this,e)},merge(e){return Fi(this,e)},pick(e){return ki(this,e)},omit(e){return ji(this,e)},partial(...e){return Ii(mf,this,e[0])},exactPartial(...e){return Ii(gf,this,e[0],`exactPartial`)},required(...e){return Li(wf,this,e[0])}});function $d(e,t){return new Qd({type:`object`,shape:e??{},...q(t)})}function ef(e,t){return new Qd({type:`object`,shape:e,catchall:qd(),...q(t)})}var tf=J(`ZodUnion`,(e,t)=>{Ys.init(e,t),md.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Fu(e,t,n,r),e.options=t.options});function nf(e,t){return new tf({type:`union`,options:e,...q(t)})}var rf=J(`ZodIntersection`,(e,t)=>{Xs.init(e,t),md.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Iu(e,t,n,r)});function af(e,t){return new rf({type:`intersection`,left:e,right:t})}var of=J(`ZodRecord`,(e,t)=>{pd(),$s.init(e,t),md.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Bu(e,t,n,r),e.keyType=t.keyType,e.valueType=t.valueType});function sf(e,t,n){return!t||!t._zod?new of({type:`record`,keyType:Y(),valueType:e,...q(t)}):new of({type:`record`,keyType:e,valueType:t,...q(n)})}var cf=J(`ZodEnum`,(e,t)=>{ec.init(e,t),md.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Ou(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 cf({...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 cf({...t,checks:[],...q(r),entries:i})}});function lf(e,t){return new cf({type:`enum`,entries:Array.isArray(e)?Object.fromEntries(e.map(e=>[e,e])):e,...q(t)})}var uf=J(`ZodLiteral`,(e,t)=>{tc.init(e,t),md.init(e,t),e._zod.processJSONSchema=(t,n,r)=>ku(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 df(e,t){return new uf({type:`literal`,values:Array.isArray(e)?e:[e],...q(t)})}var ff=J(`ZodTransform`,(e,t)=>{pd(),nc.init(e,t),md.init(e,t),e._zod.processJSONSchema=(t,n,r)=>ju(e,t,n,r),e._zod.parse=(n,r)=>{if(r.direction===`backward`)throw new pa(e.constructor.name);n.addIssue=r=>{if(typeof r==`string`)n.issues.push(Ji(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(Ji(t))}};let i=t.transform(n.value,n);return i instanceof Promise?i.then(e=>(n.value=e,n)):(n.value=i,n)}});function pf(e){return new ff({type:`transform`,transform:e})}var mf=J(`ZodOptional`,(e,t)=>{ic.init(e,t),md.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Xu(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function hf(e){return new mf({type:`optional`,innerType:e})}var gf=J(`ZodExactOptional`,(e,t)=>{ac.init(e,t),md.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Xu(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function _f(e){return new gf({type:`optional`,innerType:e})}var vf=J(`ZodNullable`,(e,t)=>{oc.init(e,t),md.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Vu(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function yf(e){return new vf({type:`nullable`,innerType:e})}var bf=J(`ZodDefault`,(e,t)=>{sc.init(e,t),md.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Gu(e,t,n,r),e.unwrap=()=>e._zod.def.innerType,e.removeDefault=e.unwrap});function xf(e,t){return new bf({type:`default`,innerType:e,get defaultValue(){return typeof t==`function`?t():xi(t)}})}var Sf=J(`ZodPrefault`,(e,t)=>{lc.init(e,t),md.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Ku(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Cf(e,t){return new Sf({type:`prefault`,innerType:e,get defaultValue(){return typeof t==`function`?t():xi(t)}})}var wf=J(`ZodNonOptional`,(e,t)=>{uc.init(e,t),md.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Hu(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Tf(e,t){return new wf({type:`nonoptional`,innerType:e,...q(t)})}var Ef=J(`ZodCatch`,(e,t)=>{pc.init(e,t),md.init(e,t),e._zod.processJSONSchema=(t,n,r)=>qu(e,t,n,r),e.unwrap=()=>e._zod.def.innerType,e.removeCatch=e.unwrap});function Df(e,t){return new Ef({type:`catch`,innerType:e,catchValue:typeof t==`function`?t:sa(t)})}var Of=J(`ZodPipe`,(e,t)=>{mc.init(e,t),md.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Ju(e,t,n,r),e.in=t.in,e.out=t.out});function kf(e,t){return new Of({type:`pipe`,in:e,out:t})}var Af=J(`ZodPreprocess`,(e,t)=>{Of.init(e,t),gc.init(e,t)}),jf=J(`ZodReadonly`,(e,t)=>{_c.init(e,t),md.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Yu(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Mf(e){return new jf({type:`readonly`,innerType:e})}var Nf=J(`ZodCustom`,(e,t)=>{yc.init(e,t),md.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Au(e,t,n,r)});function Pf(e,t={}){return Wl(Nf,e,t)}function Ff(e,t){return Gl(e,t)}function If(e,t){return new Af({type:`pipe`,in:pf(e),out:t})}var Lf=/[\p{L}\p{N}]/u,Rf=/\s/,zf=/[_\-/]/,Bf=/[\s,;:.\-–—(_/]+$/u,Vf=/^[\p{M}\u200d\ufe0f\u{1F3FB}-\u{1F3FF}\u{E0020}-\u{E007F}]$/u,Hf=/^[\u{1F1E6}-\u{1F1FF}]$/u,Uf=/[\uD800-\uDFFF]/gu,Wf=/[\p{Cc}\p{Zl}\p{Zp}]+/gu,Gf=/(?![\u200c\u200d\u{E0000}-\u{E007F}])\p{Cf}/gu,Kf=/(\u{1F3F4})([\u{E0000}-\u{E007F}]*)|[\u{E0000}-\u{E007F}]+/gu,qf=/^[\p{Cf}\s\u034f\u115f\u1160\u17b4\u17b5\u2800\u3164\uffa0]*$/u;function Jf(e){let t=e.replace(Uf,`�`).replace(Wf,` `).replace(Gf,``).replace(Kf,(e,t,n)=>t?t+n:``).replace(/\s+/g,` `).trim();return qf.test(t)?``:t}function Yf(e){let t=[],n=!1,r=0;for(let i of e){let e=t.length-1;e>=0&&(n||Vf.test(i)||Hf.test(i)&&r===1)?(t[e]+=i,r=Hf.test(i)?r+1:r):(t.push(i),r=+!!Hf.test(i)),n=i===``}return t}function Xf(e,t){for(let n=e.length-1;n>0;n--)if(t.test(e[n]))return n;return-1}function Zf(e,t){if(e.length<=t)return e;let n=Array.from(e);if(n.length<=t)return e;let r=Yf(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&&!Vf.test(o))return o+`…`;let s=i.length,c=r[i.length];if(c!==void 0&&!Rf.test(c)){let e=Xf(i,Rf);e<=0&&(e=Xf(i,zf)),e>0&&(s=e)}return i.slice(0,s).join(``).replace(Bf,``)+`…`}var Qf=[`;`,`. `,` — `,` (`],$f=12;function ep(e,t){let n=0,r=0;for(let i of e){if(r++>=t)break;n+=i.length}return n}function tp(e,t){let n=ep(e,Math.max(0,$f-t)),r=e.length;for(let t of Qf){let i=e.indexOf(t,n);i>=0&&i<r&&(r=i)}return e.slice(0,r).trim()}function np(e){let t=e.split(/[\\/]/).pop()??``,n=t.lastIndexOf(`.`);return Jf(n>0?t.slice(0,n):t)}var rp=new Map;function ip(e){let t=e.replace(/^0+/,``)||`0`,n=rp.get(t);return n||(rp.size>=2e3&&rp.clear(),n=ap(t),rp.set(t,n)),n}function ap(e){return RegExp(`^v0*${e}(?![\\p{L}\\p{N}])(?:(?:\\s*[:,\\-–—]|\\.(?=\\s|$))[\\s:,.\\-–—]*|\\s*$|\\s+(?=\\(batch\\b))`,`iu`)}var op=e=>e!==``&&e!==`…`;function sp(e){let t=Zf(Jf(e.label??``),48);if(op(t))return t;let n=Jf(e.note??``),r=n,i=/^v(\d+)$/i.exec(e.id)?.[1];i!==void 0&&(r=r.replace(ip(i),``)),r=r.replace(/^\(batch\b[^)]*\)\s*:?\s*/i,``);let a=Array.from(n.slice(0,n.length-r.length)).length;if(r=tp(r,a),Lf.test(r)){let e=Zf(r,48);if(op(e))return e}let o=Zf(np(e.file),48);if(op(o))return o;let s=Zf(Jf(e.id),48);return op(s)?s:`Untitled`}var cp=[`script`,`picture`,`voice`,`music`,`sfx`,`mix`,`visuals`,`notes`,`assets`,`project`],lp=[`cut`,`variant`,`take`,`script`,`picks`,`notes-sent`,`replies`,`lock`,`files`,`entry`,`format`,`visual`,`film`],up=[`user`,`agent`,`rushes`],dp=5e3,fp={script:`Script`,picture:`Picture`,voice:`Voice`,music:`Music`,sfx:`Sound effects`,mix:`Mix`,visuals:`Visuals`,notes:`Notes`,assets:`Files`,project:`Project`},pp=[`Sunday`,`Monday`,`Tuesday`,`Wednesday`,`Thursday`,`Friday`,`Saturday`],mp=[`January`,`February`,`March`,`April`,`May`,`June`,`July`,`August`,`September`,`October`,`November`,`December`],hp=e=>String(e).padStart(2,`0`),gp=e=>Number.isFinite(e.getTime());function _p(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 vp(e){return gp(e)?`${hp(e.getHours())}:${hp(e.getMinutes())}`:`--:--`}function yp(e){return`${e.getFullYear()}-${hp(e.getMonth()+1)}-${hp(e.getDate())}`}function bp(e,t,n){if(!gp(e))return`Date unknown`;if(!n)return`${pp[e.getDay()]} ${e.getDate()} ${mp[e.getMonth()]} ${e.getFullYear()}`;let r=_p(e.toISOString(),t);if(r===0)return`Today`;if(r===1)return`Yesterday`;let i=e.getFullYear()===t.getFullYear()?``:` ${e.getFullYear()}`;return`${pp[e.getDay()].slice(0,3)} ${e.getDate()} ${mp[e.getMonth()].slice(0,3)}${i}`}function Z(e){return ef(e)}var xp=lf([`script`,`picture`,`voice`,`music`,`sfx`,`mix`,`visuals`]),Sp=lf([`voice`,`music`,`sfx`]),Cp=Y().min(1).max(64),wp=X().nonnegative(),Tp=Y().regex(/^[abcdefghjkmnpqrstuvwxyz23456789]{8}$/),Ep=Z({n:X().int().positive(),name:Y().trim().min(1).max(80),start:X().nonnegative(),tag:Y().trim().max(24).default(``)}),Dp=Z({file:Y().min(1),width:X().int().positive(),height:X().int().positive(),bytes:X().int().nonnegative(),createdAt:Y()}),Op=Z({id:Y().max(16).regex(ue),label:Y().min(3).max(16),file:Y().min(1),width:X().int().positive(),height:X().int().positive(),duration:wp.nullable().default(null),fps:X().positive().nullable().default(null),addedAt:Y()}),kp=$d({id:Cp,file:Y().min(1),duration:wp.nullable().default(null),fps:X().positive().nullable().default(null),addedAt:Y(),note:Y().default(``),label:Y().default(``),shots:Zd(Ep).max(200).default([]),proxy:Dp.nullable().default(null),width:X().int().positive().nullable().default(null),height:X().int().positive().nullable().default(null),formats:Zd(Op).max(8).default([])}).superRefine((e,t)=>{let n=e.width!==null&&e.height!==null&&fe(e.width,e.height)?_e(ge(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)})}),Ap=Z({id:Cp,name:Y().min(1),versions:Zd(kp).default([]),lockedVersion:Y().nullable().default(null),shelved:Y().max(40).nullable().optional()}),jp=Z({id:Cp,name:Y().min(1),t:wp,file:Y().min(1).max(1024).optional()}),Mp=Z({id:Cp,name:Y().min(1),file:Y().min(1),meta:sf(Y(),nf([Y(),X()])).default({}),cues:Zd(jp).default([]),videos:Zd(Cp).optional(),video:Cp.optional(),addedAt:Y().optional(),madeFor:sf(Y(),Y()).optional(),putAway:Y().optional()}),Np=Z({id:Cp,stage:Sp,name:Y().min(1),variants:Zd(Mp).default([])}),Pp=Z({id:Cp,kind:lf([`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:df(1),rev:X().int().nonnegative(),id:Tp.optional(),name:Y().min(1),fps:X().positive().default(30),videos:Zd(Ap).default([]),lanes:Zd(Np).default([]),files:Zd(Pp).default([]),autoProxy:Gd().default(!1)});var Fp=Z({id:Cp,file:Y().min(1),duration:wp.nullable().default(null),forText:Y()}),Ip=lf([`draft`,`approved`,`flagged`]),Lp=$d({id:Cp,start:wp,end:wp,current:Y(),proposed:Y().nullable().default(null),direction:Y().default(``),status:Ip.default(`draft`),takes:Zd(Fp).default([])}).refine(e=>e.end>e.start,{message:`end must be after start`,path:[`end`]});Z({schema:df(1),rev:X().int().nonnegative(),wordsPerSecond:X().positive().default(2.6),sections:Zd(Lp).default([]),sectionCounter:X().int().nonnegative().optional()});var Rp=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)}),zp=Z({x:X().min(0).max(1),y:X().min(0).max(1)}),Bp=Z({kind:lf([`rise`,`fall`,`louder`,`quieter`]),db:X().min(.5).max(24).optional()}),Vp=[`voice`,`music`,`sfx`,`mix`],Hp=$d({id:Cp,stage:xp,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:lf([`point`,`range`,`whole`]),t:wp.nullable().default(null),tOut:wp.nullable().default(null),frame:X().int().nonnegative().nullable().default(null),text:Y().trim().min(1).max(4e3),box:Rp.nullable().default(null),pin:zp.nullable().default(null),grab:Y().nullable().default(null),shot:Z({n:X().int().positive(),name:Y()}).nullable().default(null),marks:Zd(Bp).max(4).default([]),format:Y().max(16).regex(ue).nullable().default(null),status:lf([`todo`,`done`]).default(`todo`),reply:Y().default(``),fixT:wp.nullable().default(null),fixVersion:Y().nullable().default(null),batch:Y().nullable().default(null),createdAt:Y(),by:lf([`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&&!Vp.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:df(1),rev:X().int().nonnegative(),notes:Zd(Hp).default([])});var Up=Z({voice:X(),music:X(),sfx:X()}).partial().default({}),Wp=Z({lane:Cp,variant:Cp,at:Y(),seen:sf(Y(),Y()).default({})}),Gp=Z({voice:Wp,music:Wp,sfx:Wp}).partial(),Kp=Z({lanes:sf(Y(),Y()).default({}),levels:Up,use:Gp.optional()});Z({schema:df(1),rev:X().int().nonnegative(),lanes:sf(Y(),Y()).default({}),sections:sf(Y(),Y()).default({}),levels:Up,use:Gp.optional(),videos:sf(Y(),Kp).default({})});var qp=Z({id:Cp,stage:xp.nullable(),noteIds:Zd(Y()).default([]),sectionIds:Zd(Y()).default([]),sentAt:Y(),prompt:Y()});Z({schema:df(1),rev:X().int().nonnegative(),batches:Zd(qp).default([])}),Z({schema:df(1),rev:X().int().nonnegative(),dismissed:Zd(Y().max(1024)).max(1e4).default([]),settled:Zd(Z({video:Y().max(200),version:Y().max(200),kinds:Zd(lf([`voice`,`music`,`sfx`,`cut`,`other`])).max(5)})).max(200).default([])});var Jp=Z({id:Cp,at:Y(),area:lf(cp),kind:lf(lp),text:Y().min(1).max(160),video:Y().nullable().default(null),version:Y().nullable().default(null),ref:Y().max(300).nullable().default(null),by:lf(up),tab:xp.nullable().default(null),n:X().int().positive().default(1),subject:Y().max(200).default(``)}),Yp=Z({schema:df(1),rev:X().int().nonnegative(),backfilled:Gd().default(!1),began:Y().optional(),undated:Zd(Y().max(300)).max(dp).default([]),dropped:X().int().nonnegative().default(0),entries:Zd(Jp).max(dp).default([]),newer:df(!0).optional()}),Xp=e=>typeof e==`object`&&!!e&&!Array.isArray(e);function Zp(e){if(!Xp(e)||!Array.isArray(e.entries))return e;let t=[],n=new Set,r=0;for(let i of e.entries){let e=Jp.safeParse(Xp(i)?Qp(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-dp),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,dp):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 Qp(e){let t={...e};return typeof t.text==`string`&&(t.text=Jf(t.text)),typeof t.subject==`string`&&(t.subject=Jf(t.subject)),t}If(Zp,Yp),Z({schema:df(1),rev:X().int().nonnegative(),baseline:Y().max(1e6).default(``),seen:Y().max(64).default(``)});var $p=Z({ratio:Y().max(16).regex(ue),file:Y().min(1),width:X().int().positive(),height:X().int().positive()}),em=Z({n:X().int().positive(),images:Zd($p).min(1).max(8)}),tm=Z({id:Cp,addedAt:Y(),label:Y().default(``),pages:Zd(em).min(1).max(100)}),nm=Z({id:Cp,name:Y().trim().min(1).max(80),kind:lf([`still`,`carousel`]),addedAt:Y(),versions:Zd(tm).min(1)});Z({schema:df(1),rev:X().int().nonnegative(),visuals:Zd(nm).default([])}),e(((e,t)=>{t.exports={}}))();var rm={todo:`To do`,sent:`With your agent`,done:`Done`};function im(e){return e.status===`done`?`done`:e.batch===null?`todo`:`sent`}function am(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?am(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 sm(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 cm(e,t){return e.addedAt===void 0||e.putAway!==void 0?!1:t===void 0||e.addedAt>t.at}function lm(e,t,n){return n!==void 0&&n.lane===t&&n.variant===e.id?`in-use`:e.putAway===void 0?cm(e,n)?`new`:`earlier`:`put-away`}function um(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 dm={2:`picture`,3:`voice`,4:`music`,5:`sfx`,6:`picture`,7:`visuals`,8:`assets`};function fm(e,t){return e===`1`?t:dm[e]??null}function pm(e){return e===`mix`?`picture`:e}var mm=(e,t)=>new Date(e).toLocaleDateString(`en-GB`,{day:`numeric`,month:`short`,timeZone:t});function hm(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:mm(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=lm(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?sm(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 gm=e=>`${e.lane}/${e.variant.id}`;function _m(e){return e.inUse??e.fresh[0]??e.earlier[0]?.takes[0]??null}var vm={fresh:`New`,inUse:`In use`,earlier:`Earlier`};function ym(e,t=e=>e){let n=[],r=(e,r,i)=>n.push({kind:e,heading:`${vm[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 bm(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 xm=e=>String(e).padStart(2,`0`);function Sm(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`${xm(Math.floor(a/3600))}:${xm(Math.floor(a/60)%60)}:${xm(a%60)}:${xm(i)}`}var Cm={voice:`Voice`,music:`Music`,sfx:`Effects`};function wm(e,t,n=30){let r=e=>Sm(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?`${xm(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),`${Cm[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 Tm=e=>t=>t.status===`todo`&&(!t.video||e.inPlay.has(t.video));function Em(e){let t=Tm(e),n=e.scriptTodo-e.notes.filter(e=>e.stage===`script`&&t(e)).length;return Math.max(0,n)+e.briefChanged+e.storyboardChanged}function Dm(e){let t=Tm(e);return e.notes.filter(e=>t(e)&&e.batch===null).length+Em(e)}var Om=(e,t)=>e===`sent`?`${rm.sent} · ${t}`:t,km=(e,t)=>t>0?Math.min(100,Math.max(0,e/t*100)):0;function Am(e,t){return e.filter(e=>e.t!==null).map(e=>{let n=km(e.t,t);return{id:e.id,left:n,width:e.tOut===null?null:km(e.tOut,t)-n,status:im(e)}})}var jm=[`change`,`proxy`,`corrupt`],Mm=e=>`rushes-sse-v1-${e}`,Nm=e=>`rushes-v1-${e}`,Pm=4e4,Fm=5e3;function Im(){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 Lm(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`||jm.includes(n)&&typeof r==`string`:!1}function Rm(e,t){t.type===`open`?e.open():t.type===`error`?e.error():`data`in t&&e[t.type](t.data)}function zm(e,t,n,r){let i=new e.EventSource(t),a=e=>{Rm(n,e),r?.(e)};for(let e of jm)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 Bm(e,t,n,r=Im()){let{locks:i,BroadcastChannel:a}=r;if(!i||!a){let e=zm(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(Nm(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,Pm+o()*Fm))},b=e=>{p=e,s=`leader`,clearTimeout(h),u=zm(r,t,n,_)},x=(a=!1)=>{let o=++f;m?.abort();let h=new AbortController;m=h;let g=!1;i.request(Mm(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=zm(r,t,n))})},S=()=>{c||l||s!==`follower`||(x(!0),n.resync())};g.onmessage=e=>{s===`follower`&&!l&&Lm(e.data)&&(y(),Rm(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 Vm(){let[e,t]=H(null),[n,r]=H([]),[i,a]=H(null),[o,s]=H(!1),[c,l]=H({}),u=G(void 0),d=G(0),f=G(0),p=G(!1),m=G(void 0),h=G(750),g=async()=>{let e=++d.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<f.current)return;f.current=e;let c=!1;if(i.ok){let e=i.data;t(e);let r=(t,n)=>!!e.project.videos.find(e=>e.id===t)?.versions.find(e=>e.id===n)?.proxy;l(t=>gn(t,e.proxies?.jobs??[],n,r)),a(null),s(!1)}else i.error instanceof Gr&&i.error.code===`wrong_project`?(s(!0),c=!0):a(i.error.message);o.ok&&r(o.assets),clearTimeout(m.current),c||i.ok&&o.ok?h.current=750:(m.current=window.setTimeout(()=>void g(),h.current),h.current=Math.min(h.current*2,1e4))};return U(()=>{g();let e=Bm(Kr()??``,Qr(),{change(){clearTimeout(u.current),u.current=window.setTimeout(()=>void g(),40)},proxy(e){let t=JSON.parse(e);l(e=>hn(e,{...t,at:performance.now()}))},corrupt(e){let{file:t}=JSON.parse(e);a(`${t} has an error and wasn't loaded. Fix or restore it, and Rushes will pick it up.`)},error(){a(`Lost touch with the Rushes server. Retrying…`),!p.current&&(p.current=!0,g().finally(()=>{p.current=!1}))},open(){p.current=!1,g()},resync(){g()}});return Ut(location.search).test&&(window.__rushesLive={role:()=>e.role()}),()=>{e.close(),clearTimeout(u.current),clearTimeout(m.current)}},[]),{state:e,assets:n,problem:i,wrongProject:o,refresh:g,proxyJobs:c,noteProxyJob:e=>l(t=>hn(t,mn(e,performance.now())))}}var Hm=null;function Um(e,t){let n=Hm,r={owner:e,stop:t};if(Hm=r,n&&n.owner!==e)try{n.stop()}catch{}return()=>{Hm===r&&(Hm=null)}}function Wm(e){Hm&&Hm.owner===e&&(Hm=null)}function Gm(e){return e.replace(/&/g,`&`).replace(/</g,`<`).replace(/>/g,`>`).replace(/"/g,`"`).replace(/'/g,`'`)}function Km(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 qm(e){let t=/^( *)([-*]|\d+\.)[ \t]+(.*)$/.exec(e);return t?{indent:t[1].length,ordered:/\d/.test(t[2]),content:t[3]}:null}function Jm(e){let t=/^>\s?(.*)$/.exec(e);return t?t[1]:null}function Ym(e){let t=Gm(e).split(/\r\n|\r|\n|\u2028|\u2029/),n=[],r=[],i=null,a=()=>{r.length&&(n.push(`<p>${Km(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}>${
|
|
57
|
-
`)}function Xm(e){return!e||!((e.label??``).trim()||e.note.trim())?null:sp(e)}var Zm=[`January`,`February`,`March`,`April`,`May`,`June`,`July`,`August`,`September`,`October`,`November`,`December`];function Qm(e,t){let n=_p(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 $m(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?Zm[r.getMonth()].slice(0,3):Zm[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 eh(e,t){return $m(Qm(e,t),t,!0)}function th(e,t){return $m(Qm(e,t),t,!1)}function nh(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 rh(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=eh(e.addedAt,t);return r&&n.push(r),n.join(` · `)}var ah=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:--ah,__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 oh={circle:`<circle cx="12" cy="12" r="8"/>`,chev:`<path d="M6 9l6 6 6-6"/>`,story:`<rect x="3" y="4" width="11" height="8" rx="1.5"/><rect x="16" y="4" width="5" height="8" rx="1.5"/><rect x="3" y="14" width="5" height="6" rx="1.5"/><rect x="10" y="14" width="11" height="6" rx="1.5"/>`,brief:`<path d="M9 4h6v3H9z"/><path d="M7 5.5H6a1 1 0 0 0-1 1V20a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1V6.5a1 1 0 0 0-1-1h-1"/><path d="M9 12h6M9 16h4"/>`,kbd:`<rect x="2.5" y="6" width="19" height="12" rx="2.5"/><path d="M6.5 10h1M10.5 10h1M14.5 10h1M8 14h8"/>`,x:`<path d="M6 6l12 12M18 6L6 18"/>`,copy:`<rect x="9" y="9" width="11" height="11" rx="2"/><path d="M5 15V6a2 2 0 0 1 2-2h8"/>`,script:`<path d="M14 3H7a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V8z"/><path d="M14 3v5h5M9 13h6M9 17h4"/>`,film:`<rect x="3" y="4" width="18" height="16" rx="2.5"/><path d="M7 4v16M17 4v16M3 9h4M3 15h4M17 9h4M17 15h4"/>`,mic:`<rect x="9" y="3" width="6" height="11" rx="3"/><path d="M5 11a7 7 0 0 0 14 0M12 18v3"/>`,music:`<path d="M9 18V5l11-2v13"/><circle cx="6" cy="18" r="3"/><circle cx="17" cy="16" r="3"/>`,zap:`<path d="M13 3L5 13h6l-1 8 8-10h-6z"/>`,sliders:`<path d="M5 21v-7M5 10V3M12 21v-9M12 8V3M19 21v-5M19 12V3M2 14h6M9 8h6M16 16h6"/>`,lock:`<rect x="5" y="11" width="14" height="10" rx="2"/><path d="M8 11V8a4 4 0 0 1 8 0v3"/>`,unlock:`<rect x="5" y="11" width="14" height="10" rx="2"/><path d="M8 11V7a4 4 0 0 1 8 0v1"/>`,play:`<path d="M7 4.5v15l12-7.5z" fill="currentColor" stroke="none"/>`,pause:`<path d="M8 5v14M16 5v14"/>`,prev:`<path d="M15 6l-6 6 6 6"/>`,next:`<path d="M9 6l6 6-6 6"/>`,in:`<path d="M10 5H6v14h4"/><path d="M14 12h6M17 9l3 3-3 3"/>`,out:`<path d="M14 5h4v14h-4"/><path d="M4 12h6M7 9l3 3-3 3"/>`,box:`<path d="M4 8V5a1 1 0 0 1 1-1h3M16 4h3a1 1 0 0 1 1 1v3M20 16v3a1 1 0 0 1-1 1h-3M8 20H5a1 1 0 0 1-1-1v-3"/>`,camera:`<path d="M4 8h3l2-3h6l2 3h3a1 1 0 0 1 1 1v9a1 1 0 0 1-1 1H4a1 1 0 0 1-1-1V9a1 1 0 0 1 1-1z"/><circle cx="12" cy="13" r="3.5"/>`,check:`<path d="M5 12.5l4.5 4.5L19 7.5"/>`,flag:`<path d="M5 21V4M5 4h11l-2 4 2 4H5"/>`,undo:`<path d="M9 14L4 9l5-5"/><path d="M4 9h10a6 6 0 0 1 0 12h-3"/>`,send:`<path d="M5 12h14M13 6l6 6-6 6"/>`,reply:`<path d="M5 4v7a4 4 0 0 0 4 4h11"/><path d="M16 11l4 4-4 4"/>`,image:`<rect x="3" y="4" width="18" height="16" rx="2.5"/><circle cx="9" cy="10" r="2"/><path d="M21 16l-5-5-9 9"/>`,alert:`<path d="M12 3l9.5 17h-19z"/><path d="M12 10v4M12 17h.01"/>`,new:`<path d="M12 19V5M5 12l7-7 7 7"/>`,grid:`<rect x="3" y="3" width="8" height="8" rx="1.5"/><rect x="13" y="3" width="8" height="8" rx="1.5"/><rect x="3" y="13" width="8" height="8" rx="1.5"/><rect x="13" y="13" width="8" height="8" rx="1.5"/>`,download:`<path d="M12 4v11M7.5 11.5L12 16l4.5-4.5"/><path d="M5 19h14"/>`,save:`<path d="M5 4h11l3 3v13H5z"/><path d="M8 4v5h7V4"/><path d="M8 14h8v6H8z"/>`,folder:`<path d="M3 7a2 2 0 0 1 2-2h4l2 2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z"/>`,list:`<path d="M8 6h13M8 12h13M8 18h13"/><circle cx="3.5" cy="6" r="1.2" fill="currentColor" stroke="none"/><circle cx="3.5" cy="12" r="1.2" fill="currentColor" stroke="none"/><circle cx="3.5" cy="18" r="1.2" fill="currentColor" stroke="none"/>`,open:`<path d="M10 14L20 4"/><path d="M14 4h6v6"/><path d="M19 13v6a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"/>`,search:`<circle cx="10.5" cy="10.5" r="6.5"/><path d="M20 20l-5-5"/>`,eyeoff:`<path d="M3 3l18 18M10.6 6.1A10 10 0 0 1 12 6c5 0 9 6 9 6a17 17 0 0 1-3.2 3.7M6.6 6.6A17 17 0 0 0 3 12s4 6 9 6a9 9 0 0 0 4.4-1.1"/><path d="M9.9 9.9a3 3 0 0 0 4.2 4.2"/>`,gauge:`<path d="M4 17a8 8 0 1 1 16 0"/><path d="M12 17l3.5-5"/>`,trash:`<path d="M4 7h16M10 11v6M14 11v6"/><path d="M6 7l1 13h10l1-13M9 7V4h6v3"/>`,refresh:`<path d="M20 12a8 8 0 1 1-2.6-5.9"/><path d="M20 4v4h-4"/>`,stream:`<path d="M3 12h2l2-5 3 10 3-14 3 12 2-3h3"/>`,more:`<circle cx="5" cy="12" r="1.3"/><circle cx="12" cy="12" r="1.3"/><circle cx="19" cy="12" r="1.3"/>`,shelve:`<rect x="3" y="4" width="18" height="5" rx="1.5"/><path d="M5 9v9a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V9M10 13h4"/>`,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="M4 9V4h5M20 9V4h-5M4 15v5h5M20 15v5h-5"/>`,info:`<circle cx="12" cy="12" r="8.5"/><path d="M12 11v5.5M12 7.8h.01"/>`};function $({name:e,class:t}){return Q(`svg`,{class:`ic${t?` ${t}`:``}`,viewBox:`0 0 24 24`,"aria-hidden":`true`,dangerouslySetInnerHTML:{__html:oh[e]??``}})}var sh={script:`script`,picture:`film`,voice:`mic`,music:`music`,sfx:`zap`,mix:`sliders`,visuals:`image`},ch=typeof window<`u`&&`showSaveFilePicker`in window;function lh(){let e=navigator.userAgent;return/Mac/.test(e)?`Show in Finder`:/Windows/.test(e)?`Show in Explorer`:`Open folder`}function uh(e){return e?new Date(e).toLocaleDateString(void 0,{day:`numeric`,month:`short`,year:`numeric`}):``}function dh({asset:e,toast:t}){let[n,r]=H(!1),i=!e.missing&&it.has(ot(e.path)),a=async()=>{if(n)return;r(!0);let i;try{let t=await window.showSaveFilePicker({suggestedName:e.name}),n=await fetch(Zr(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:`${Zr(e.path)}&download=1`,download:e.name,onClick:t=>{e.missing&&t.preventDefault()},children:Q($,{name:`download`})}),ch&&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":lh(),"aria-label":lh(),"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 fh({tip:e=`Missing`}){return Q(`span`,{class:`amiss`,"data-tip":e,"aria-label":e,children:`●`})}function ph(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:mh(e)?null:Xm(r)}}function mh(e){return e.kind===`cut`&&e.format!==void 0}function hh({asset:e,videos:t,toast:n}){let r=e.kind===`cut`||e.kind===`delivery`?ph(e,t):null;return Q(`div`,{class:`arow${e.missing?` missing`:``}${mh(e)?` sub`:``}`,children:[Q(`div`,{class:`ainfo`,children:[Q(`div`,{class:`atitle`,children:[r?r.title:e.label??e.name,e.missing&&Q(fh,{})]}),r?.subtitle&&Q(`div`,{class:`asub`,children:r.subtitle}),Q(`div`,{class:`afolder mono`,children:e.path}),!e.missing&&Q(`div`,{class:`ameta`,children:[nt(e.size??0),` · `,uh(e.modified)]})]}),Q(dh,{asset:e,toast:n})]})}function gh({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(fh,{})]}),Q(`div`,{class:`afolder mono`,children:e.path}),!e.missing&&Q(`div`,{class:`ameta`,children:yn(e)})]}),Q(dh,{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 _h({asset:e,playing:t,paused:n,onToggle:r,videos:i,toast:a}){let o=t&&!n,s=e.label??e.name,c=rt(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(fh,{})]}),c&&Q(`div`,{class:`atrackmeta`,children:c}),Q(`div`,{class:`afolder mono`,children:e.path}),!e.missing&&Q(`div`,{class:`ameta`,children:[nt(e.size??0),` · `,uh(e.modified)]})]}),Q(dh,{asset:e,toast:a})]})}function vh({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(fh,{})]}),e.note&&Q(`div`,{class:`asub`,children:e.note}),Q(`div`,{class:`afolder mono`,children:e.path}),!e.missing&&Q(`div`,{class:`ameta`,children:[nt(e.size??0),` · `,uh(e.modified)]})]}),Q(dh,{asset:e,toast:i})]})}function yh({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:Zr(e.path),alt:e.name,loading:`lazy`})}),Q(`div`,{class:`shot-meta`,children:[Q(`div`,{class:`mono`,children:[a,e.missing&&Q(fh,{})]}),o&&Q(`div`,{class:`asub`,children:o})]}),Q(dh,{asset:e,toast:n})]})}function bh({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?`${Zr(e.path)}#t=0.5`:void 0,"aria-label":`${e.name} poster frame`})}function xh({asset:e,videos:t,toast:n}){let{title:r,subtitle:i}=ph(e,t),a=at.has(ot(e.path));return Q(`div`,{class:`shot-tile${e.missing?` missing`:``}${mh(e)?` sub`:``}`,children:[Q(`div`,{class:`shot-thumb poster`,children:!e.missing&&(a?Q(bh,{asset:e}):Q(`div`,{class:`file-tile`,children:Q(`span`,{class:`file-ext mono`,children:ot(e.path)||`file`})}))}),Q(`div`,{class:`shot-meta`,children:[Q(`div`,{class:`atitle`,children:[r,e.missing&&Q(fh,{})]}),i&&Q(`div`,{class:`asub`,children:i}),Q(`div`,{class:`afolder mono`,children:e.path})]}),Q(dh,{asset:e,toast:n})]})}function Sh(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 Ch({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=Sh(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:Zr(e.path),alt:e.name}),Q(`div`,{class:`lbactions`,children:[Q(dh,{asset:e,toast:n}),Q(`button`,{ref:i,class:`btn ghost ib`,"aria-label":`Close`,onClick:t,children:Q($,{name:`x`})})]})]})})}var wh=60,Th=`Up to 12 files of each kind at a time, so the tabs stay quick. Each voiceover folder becomes its own round.`,Eh=xn.filter(e=>e!==`cut`),Dh=e=>e.slice(e.lastIndexOf(`/`)+1),Oh=e=>`Couldn't be added: ${e.replace(/\.$/,``).replace(/^(\p{Lu})(?=\p{Ll})/u,e=>e.toLowerCase())}`,kh={voice:`var(--vo)`,music:`var(--music)`,sfx:`var(--sfx)`,other:`var(--text-3)`,cut:`var(--accent)`,doc:`var(--text-3)`};function Ah({kind:e}){return Q(`i`,{class:`kdot`,style:{background:e?kh[e]:`var(--text-3)`}})}function jh({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 Mh({row:e,playing:t,onPlay:n}){return Q(`div`,{class:`frow in`,children:[Q(`span`,{}),e.playable?Q(jh,{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(Ah,{kind:e.kind}),Q(`span`,{class:`klabel`,children:e.label})]}),Q(`span`,{}),Q(`span`,{})]})}var Nh=class extends T{shouldComponentUpdate(e){return zn(this.props,e)}render({item:e,kind:t,ticked:n,playing:r,failure:i,onTick:a,onKind:o,onPlay:s}){let c=Dh(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(jh,{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:Oh(i)})]}),l?Q(`span`,{class:`kind static`,children:[Q(Ah,{kind:`cut`}),Sn.cut]}):Q(`label`,{class:`kind`,children:[Q(Ah,{kind:t}),Q(`select`,{"aria-label":`Kind of ${c}`,value:t,onChange:t=>o(e.path,t.target.value),children:Eh.map(e=>Q(`option`,{value:e,children:Sn[e]}))}),Q($,{name:`chev`,class:`kchev`})]}),Q(`span`,{class:`fdur mono`,children:Fn(e.duration)}),Q(`span`,{class:`fsize mono`,children:nt(e.size)})]})}};function Ph(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 Fh({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),L=G({onPlay:r,onStop:i});L.current={onPlay:r,onStop:i};let R=Fr((e,t)=>L.current.onPlay(e,t),[]),ne=G(0),re=G(0),ie=async()=>{let e=++ne.current;try{let t=await K.get(`/api/found`);if(e<re.current)return;re.current=e,u(e=>{let n=kn(e?.files??[],t.files??[]),r=t.hidden??[];return e&&n===e.files&&JSON.stringify(e.hidden)===JSON.stringify(r)?e:{files:n,hidden:r}}),f(null)}catch(t){e>=re.current&&f(t.message)}};U(()=>{ie()},[e]);let ae=Dn(c);U(()=>s(ae),[ae]);let oe=l?.files??[],se=l?.hidden??[],ce=Pr(()=>oe.map(e=>({...e,kind:h[e.path]??e.kind,raw:e})),[oe,h]),le=Pr(()=>Nn(ce,x,y),[ce,x,y]),ue=Pr(()=>Mn(le),[le]),de=Pr(()=>Pn(ce),[ce]);U(()=>{x!==`all`&&l&&!c.scanning&&!de.some(([e])=>e===x)&&S(`all`)},[de,l,c.scanning]);let fe=Pr(()=>Rn(e.project,c.broughtIn),[e.project,c.broughtIn]),pe=Pr(()=>ue.filter(e=>!C.has(e.key)).flatMap(e=>e.files.map(e=>e.path)),[ue,C]),me=Pr(()=>new Set(pe),[pe]),z=oe.filter(e=>p.has(e.path)),he=z.length,ge=z.filter(e=>me.has(e.path)),_e=ge.length,ve=Pr(()=>new Set([...fe.map(e=>e.path),...M]),[fe,M]);U(()=>{l&&n.path&&!n.paused&&(me.has(n.path)||T&&ve.has(n.path)||L.current.onStop())},[l,n.path,n.paused,me,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=Fr((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=Fr((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=Ph(pe,t);I.current=n===null?`search`:{row:n},re.current=++ne.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||he===0)return;te.current=!0,A(!0);let e=z.slice(0,wh);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=z.length-e.length,r=Ln(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||_e===0)return;te.current=!0,A(!0);let e=ge.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(),ie()}catch(e){a(e.message)}finally{te.current=!1,A(!1)}},Ee=async e=>{let t=se.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},se.length<=1&&O(!1),o(),ie()}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=Cn(c.counts),B=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)})]}),de.length>0&&Q(`div`,{class:`seg`,role:`group`,"aria-label":`Kind`,children:[Q(`button`,{type:`button`,"aria-pressed":x===`all`,onClick:()=>S(`all`),children:[`All `,Q(`span`,{class:`n`,children:oe.length})]}),de.map(([e,t])=>Q(`button`,{type:`button`,"aria-pressed":x===e,onClick:()=>S(e),children:[Sn[e],` `,Q(`span`,{class:`n`,children:t})]},e))]}),Q(`button`,{type:`button`,class:`btn ib`,"aria-label":`Look again`,"aria-busy":B||j,"data-tip":`Look through the project folder again`,onClick:()=>void De(),children:Q($,{name:`refresh`})}),Q(`button`,{type:`button`,class:`btn`,disabled:_e===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:he===0||k,onClick:()=>void we(),children:he>0?`Bring in ${he}`:`Bring in`})]})]}),B&&Q(`p`,{class:`fscan`,"aria-live":`polite`,children:[Q(`span`,{class:`fspin`}),`Looking through the folder…`]}),d&&!l&&Q(`p`,{class:`aempty`,children:d}),fe.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:fe.length}),Q(`span`,{class:`fdone`,children:[Q($,{name:`check`}),`in the project`]})]}),T&&fe.map(e=>Q(Mh,{row:e,playing:Oe(e.path),onPlay:R},e.path))]}),l===null?!d&&Q(`p`,{class:`aempty`,children:`Loading…`}):oe.length===0?!B&&Q(`p`,{class:`aempty`,children:`Nothing else found in this folder.`}):le.length===0?Q(`p`,{class:`aempty`,children:`Nothing matches.`}):ue.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(Nh,{item:e.raw,kind:e.kind,ticked:p.has(e.path),playing:Oe(e.path),failure:_[e.path],onTick:ye,onKind:xe,onPlay:R},e.path))]},e.key)}),D&&se.length>0&&Q(`div`,{class:`fcard fhidden`,children:[Q(`p`,{class:`fhead`,children:[Q(`b`,{children:`Hidden`}),Q(`small`,{children:se.length})]}),se.map(e=>{let t=Dh(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:An(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:Th}),se.length>0&&Q(`button`,{type:`button`,class:`flink`,"aria-expanded":D,onClick:()=>O(e=>!e),children:[`Hidden (`,se.length,`)`]})]})]})}var Ih=new Set([`voiceover`,`music`,`sfx`]),Lh=new Set([`cut`,`delivery`]),Rh=1048576;function zh(e){return`rushes.assets.view.${e}`}function Bh(e){try{let t=localStorage.getItem(zh(e));return t===`grid`||t===`list`?t:null}catch{return null}}function Vh(e,t){try{localStorage.setItem(zh(e),t)}catch{}}function Hh(e){return e?e.gridToggle?Bh(e.id)??e.view:`list`:`grid`}async function Uh(e){let t=await fetch(Zr(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>Rh){let e=t.byteLength-(a-Rh);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 Wh({assets:e,videos:t,state:n,foundRequest:r,onFoundRequestUsed:i,onFoundSeen:a,toast:o,onChanged:s}){let c=Pr(()=>st.filter(t=>t.id===`export`||e.some(e=>t.kinds.includes(e.kind))),[e]),l=c.find(e=>e.id!==`export`)?.id,u=En(n.found)!==null,[d,f]=H(()=>r.pending?`found`:l??(u?`found`:c[0]?.id??`found`)),p=G(r.pending);U(()=>{if(d===`found`)return;let e=!!d&&c.some(e=>e.id===d);if(p.current&&e)return;let t=l??(e?d:c[0]?.id??`found`);t!==d&&f(t)},[c,d]);let[m,h]=H(()=>({key:0,kind:r.pending?r.kind:void 0})),g=e=>{p.current=!0,f(e)},_=G(r.pending?r.n:-1);U(()=>{r.pending&&(_.current!==r.n&&(_.current=r.n,g(`found`),h(e=>({key:e.key+1,kind:r.kind}))),i())},[r.n,r.pending]);let v=d===`found`,y=v?null:c.find(e=>e.id===d)??null,[b,x]=H(``),[S,C]=H(`newest`),[T,E]=H(null),[D,O]=H(()=>Hh(y)),k=G(y?.id??null);y&&y.id!==k.current&&(k.current=y.id,x(``),E(null),C(`newest`),O(Hh(y)));let A=Pr(()=>y?dt(e,y,{query:b,sort:S,film:T,videos:t}):[],[e,y,b,S,T,t]),j=e=>{y&&y.gridToggle&&(O(e),Vh(y.id,e))},[ee,M]=H(null),N=G(null),P=(e,t)=>{N.current=t,M(e)},F=()=>{M(null),N.current?.focus()},te=G(null),[I,L]=H({path:null,paused:!0}),R=G({}),ne=()=>{te.current?.pause(),Wm(R.current),L({path:null,paused:!0})},re=(e,t)=>{let n=te.current;if(n){if(I.path===e&&!I.paused){n.pause(),Wm(R.current),L({path:e,paused:!0});return}I.path!==e&&(n.src=Zr(e)),Um(R.current,()=>{te.current?.pause(),L(e=>({...e,paused:!0}))}),L({path:e,paused:!1}),n.play().catch(n=>{n instanceof Error&&n.name===`AbortError`||(Wm(R.current),L({path:e,paused:!0}),o(`Couldn't play ${t}`))})}},ie=e=>re(e.path,e.label??e.name);U(()=>ne,[d,T]),U(()=>ne,[]),U(()=>{s()},[d]),U(()=>{let e=()=>{document.visibilityState===`visible`&&s()};return document.addEventListener(`visibilitychange`,e),()=>document.removeEventListener(`visibilitychange`,e)},[]);let[ae,oe]=H(null),[se,ce]=H(null),le=!!y&&ct.has(y.id);U(()=>{if(!le){oe(null);return}ae&&A.some(e=>e.path===ae&&ut(e))||oe(A.find(ut)?.path??null)},[le,A]),U(()=>{if(!ae){ce(null);return}let e=!1;return ce({loading:!0,text:``,truncated:!1}),Uh(ae).then(t=>{e||ce({loading:!1,text:t.text,truncated:t.truncated})}).catch(t=>{e||ce({loading:!1,text:``,truncated:!1,error:t.message})}),()=>{e=!0}},[ae]);let ue=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())},de=async()=>{try{await K.post(`/api/reveal`,{project:!0})}catch(e){o(e.message)}},fe=async()=>{try{let{path:e}=await K.post(`/api/exports/notes`);o(`Saved to ${e}`),s()}catch(e){o(e.message)}},pe=t=>e.filter(e=>t.kinds.includes(e.kind)).length,me=()=>y?y.id===`screenshot`&&S!==`name`?pt(A,t).map((e,n)=>Q(`section`,{class:`afilm-group`,children:[e.heading&&Q(`h3`,{class:`afilm-heading`,children:e.heading}),Q(`div`,{class:`shots-grid`,children:e.items.map(e=>Q(yh,{asset:e,videos:t,toast:o,onOpen:t=>P(e,t)},e.path))})]},e.heading??`_${n}`)):Lh.has(y.id)?Q(`div`,{class:`shots-grid`,children:A.map(e=>Q(xh,{asset:e,videos:t,toast:o},e.path))}):Q(`div`,{class:`shots-grid`,children:A.map(e=>Q(yh,{asset:e,videos:t,toast:o,onOpen:t=>P(e,t)},e.path))}):null,z=()=>y?Ih.has(y.id)?Q(`div`,{class:`arows`,children:A.map(e=>Q(_h,{asset:e,playing:I.path===e.path,paused:I.paused,onToggle:ie,videos:t,toast:o},e.path))}):y.id===`proxy`?Q(`div`,{class:`arows`,children:A.map(e=>Q(gh,{asset:e,toast:o,onChanged:s},e.path))}):le?Q(`div`,{class:`arows`,children:A.map(e=>Q(vh,{asset:e,selected:ae===e.path,onSelect:()=>oe(e.path),videos:t,toast:o},e.path))}):Q(`div`,{class:`arows`,children:A.map(e=>Q(hh,{asset:e,videos:t,toast:o},e.path))}):null,he=ae?(ae.split(`.`).pop()??``).toLowerCase():``,ge=Pr(()=>Ym(se?.text??``),[se?.text]);return Q(`div`,{class:`assets-lib`,children:[Q(`nav`,{class:`asidebar`,"aria-label":`Folders`,onKeyDown:ue,children:[Q(`button`,{type:`button`,class:`afolder-btn afound`,"aria-current":v?`true`:void 0,onClick:()=>{v||h(e=>({key:e.key+1})),g(`found`)},children:[Q(`span`,{children:`Found`}),Q(`span`,{class:`count`,children:Cn(n.found?.counts)})]}),c.map(e=>Q(`button`,{type:`button`,class:`afolder-btn`,"aria-current":e.id===d?`true`:void 0,onClick:()=>g(e.id),children:[Q(`span`,{children:e.title}),Q(`span`,{class:`count`,children:pe(e)})]},e.id)),Q(`button`,{type:`button`,class:`afolder-root`,onClick:()=>void de(),children:[Q($,{name:`folder`}),`Project folder`]})]}),v?Q(Fh,{state:n,initialKind:m.kind,playing:I,onPlay:re,onStop:ne,toast:o,onChanged:s,onSeen:a},m.key):y?Q(`div`,{class:`amain`,children:[Q(`header`,{class:`aheader`,children:[Q(`h2`,{children:[y.title,` `,Q(`span`,{class:`count`,children:A.length})]}),Q(`div`,{class:`acontrols`,children:[Q(`label`,{class:`search-wrap`,children:[Q($,{name:`search`}),Q(`input`,{class:`search`,type:`search`,"aria-label":`Search`,placeholder:`Search`,value:b,onInput:e=>x(e.target.value)})]}),y.filmFilter&&Q(`select`,{class:`sel`,"aria-label":`Film`,value:T??``,onChange:e=>E(e.target.value||null),children:[Q(`option`,{value:``,children:`All films`}),t.map(e=>Q(`option`,{value:e.id,children:e.name},e.id))]}),Q(`select`,{class:`sel`,"aria-label":`Sort`,value:S,onChange:e=>C(e.target.value),children:[Q(`option`,{value:`newest`,children:`Newest`}),Q(`option`,{value:`oldest`,children:`Oldest`}),Q(`option`,{value:`name`,children:`Name`})]}),y.gridToggle&&Q(`div`,{class:`seg`,role:`group`,"aria-label":`View`,children:[Q(`button`,{type:`button`,"aria-pressed":D===`grid`,"aria-label":`Grid view`,"data-tip":`Grid`,onClick:()=>j(`grid`),children:Q($,{name:`grid`})}),Q(`button`,{type:`button`,"aria-pressed":D===`list`,"aria-label":`List view`,"data-tip":`List`,onClick:()=>j(`list`),children:Q($,{name:`list`})})]}),y.id===`export`&&Q(`button`,{type:`button`,class:`btn`,onClick:()=>void fe(),children:[Q($,{name:`script`}),`Export notes`]})]})]}),Q(`div`,{class:`abody${le?` split`:``}`,children:[Q(`div`,{class:`alist`,children:A.length===0?Q(`p`,{class:`aempty`,children:`Nothing here yet.`}):D===`grid`?me():z()}),le&&Q(`aside`,{class:`apreview`,children:!ae||!se?Q(`p`,{class:`aempty`,children:`Select a file to preview it here.`}):se.loading?Q(`p`,{class:`aempty`,children:`Loading…`}):se.error?Q(`p`,{class:`aempty`,children:se.error}):Q(w,{children:[he===`md`?Q(`div`,{class:`markdown`,dangerouslySetInnerHTML:{__html:ge}}):Q(`pre`,{class:`plain`,children:se.text}),se.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:te,onEnded:()=>{Wm(R.current),L(e=>({...e,paused:!0}))}}),ee&&Q(Ch,{asset:ee,toast:o,onClose:F})]})}var Gh=class extends Error{};function Kh(e,t,n){let r=G(t.hash),i=G(t);i.current=t;let a=G(Promise.resolve()),o=G(null),s=G(0);U(()=>{r.current=t.hash},[t.hash]),U(()=>(n.settle.current=async()=>(await a.current.catch(()=>void 0),(await K.get(`/api/state`))[e]),()=>{n.settle.current=null}),[]);let c=async(t,n)=>{let a=i.current;for(let i=0;;i++){let o=t(a,n||i>0);if(!o)throw Error(`that part is no longer in ${e}.md`);if(`refuse`in o)throw new Gh(o.refuse);try{let t=await K.put(o.path,{...o.body,hash:r.current});r.current=t[e].hash;return}catch(t){if(t instanceof Gr&&t.code===`${e}_changed`&&i===0){a=(await K.get(`/api/state`))[e],r.current=a.hash;continue}throw t}}},l=(t,r,i=!1)=>{let l=++s.current;o.current=null,a.current=a.current.catch(()=>void 0).then(()=>c(r,i)).catch(a=>{!i&&l===s.current&&a instanceof Gr&&a.code===`${e}_changed`&&(o.current={what:t,build:r}),n.toast(`Couldn't save ${t}: ${a.message}`)}).finally(n.onChanged)};return U(()=>{let e=o.current;e&&(o.current=null,l(e.what,e.build,!0))},[t.hash]),{latest:i,enqueue:l}}function qh(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 Jh=`plan-page`,Yh=e=>`ptab-${e}`;function Xh({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:Yh(e.page),"aria-controls":Jh,"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 Zh(e){e.style.height=`auto`,e.style.height=`${e.scrollHeight+2}px`}function Qh({value:e,label:t,onInput:n,onBlur:r}){let i=G(null);return W(()=>{i.current&&Zh(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,Zh(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 $h({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 eg({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 tg=(e,t,n)=>`${e} of ${t} ${n}${t===1?``:`s`} approved`,ng=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=qh(()=>{i.current=!1,n.trim()!==e.yours.trim()&&t.section(e,n)},ng),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(Qh,{label:`Your version of ${e.heading}`,value:n,onInput:e=>{i.current=!0,r(e),a.schedule()},onBlur:()=>a.flush()}),o&&Q($h,{baseline:[{text:e.current}],revertLabel:`Revert ${e.heading}`,onRevert:()=>{i.current=!1,r(e.current),t.section(e,e.current)}})]})]})}var ig=(e,t)=>e.slice(0,t).filter(n=>n.heading===e[t].heading).length;function ag({brief:e,toast:t,onChanged:n,settle:r}){let{latest:i,enqueue:a}=Kh(`brief`,e,{toast:t,onChanged:n,settle:r}),o={section:(e,t)=>{let n=ig(i.current.sections,e.index);a(e.heading,r=>{let i=r.sections.filter(t=>t.heading===e.heading)[n];return i?{path:`/api/brief/sections/${i.index}`,body:{heading:e.heading,text:t}}:null})},status:t=>{let n=e.sections.map(e=>`${e.heading}\n${e.yours}`).join(`
|
|
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 $l(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;$l(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 eu=new Set([`type`,`properties`,`required`,`additionalProperties`]),tu=[`oneOf`,`anyOf`];function nu(e){let t=e.additionalProperties;return t===void 0||t===!1||typeof t!=`object`||!t?null:Object.keys(t).length?t:null}function ru(e){let t=[];for(let n of e){if(typeof n!=`object`||n.type!==`object`)return null;for(let e in n)if(!eu.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]??nu(n);t!=null&&(e.some(e=>JSON.stringify(e)===JSON.stringify(t))||e.push(t))}si(n,r,e.length===1?e[0]:ru(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=nu(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 iu(e){let t=e.allOf;if(!Array.isArray(t)||t.length<2)return;for(let t of eu)if(t in e)return;let n=t.filter(e=>tu.some(t=>Array.isArray(e[t]))),r=null;if(!n.length)r=ru(t);else{let e=n[0],i=tu.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=>ru([...a,e]));if(o.some(e=>!e))return;r={[i]:o}}r&&(delete e.allOf,ql(e,r))}function au(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)):ql(i,s),ql(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())$l(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)??[])iu(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)}ql(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,si(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:cu(t,`input`,e.processors),output:cu(t,`output`,e.processors)}},enumerable:!1,writable:!1}),n}catch{throw Error(`Error converting schema to JSON.`)}}function ou(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 ou(r.element,n);if(r.type===`set`)return ou(r.valueType,n);if(r.type===`lazy`)return ou(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 ou(r.innerType,n);if(r.type===`intersection`)return ou(r.left,n)||ou(r.right,n);if(r.type===`record`||r.type===`map`)return ou(r.keyType,n)||ou(r.valueType,n);if(r.type===`pipe`)return e._zod.traits.has(`$ZodCodec`)?!0:ou(r.in,n)||ou(r.out,n);if(r.type===`object`){for(let e in r.shape)if(ou(r.shape[e],n))return!0;return!1}if(r.type===`union`){for(let e of r.options)if(ou(e,n))return!0;return!1}if(r.type===`tuple`){for(let e of r.items)if(ou(e,n))return!0;return!!(r.rest&&ou(r.rest,n))}return!1}var su=(e,t={})=>n=>{let r=Jl({...n,processors:t});return Xl(e,r),Ql(r,e),au(r,e)},cu=(e,t,n={})=>r=>{let{libraryOptions:i,target:a}=r??{},o=Jl({...i??{},target:a,io:t,processors:n});return Xl(e,o),Ql(o,e),au(o,e)},lu=(e,t,n)=>{(e[t]===void 0||n>e[t])&&(e[t]=n)},uu=(e,t,n)=>{(e[t]===void 0||n<e[t])&&(e[t]=n)},du=(e,t)=>{lu(e,`minimum`,t),uu(e,`maximum`,t)},fu=(e,t)=>{e.multipleOf??=[],e.multipleOf.includes(t)||e.multipleOf.push(t)},pu=(e,t)=>{e.patterns??=new Set,e.patterns.add(t)},mu=(e,t)=>{e.mime=e.mime?e.mime.filter(e=>t.includes(e)):[...t]},hu=(e,t)=>{e.format=t,t.includes(`int`)&&(e.isInt=!0)},gu=(e,t)=>lu(e,`minimum`,t.minimum),_u=(e,t)=>uu(e,`maximum`,t.maximum),vu=e=>(t,n)=>{hu(t,n.format);let[r,i]=e[n.format];lu(t,`minimum`,r),uu(t,`maximum`,i)},yu={greater_than:(e,t)=>lu(e,t.inclusive?`minimum`:`exclusiveMinimum`,t.value),less_than:(e,t)=>uu(e,t.inclusive?`maximum`:`exclusiveMaximum`,t.value),multiple_of:(e,t)=>fu(e,t.value),number_format:vu(Di),bigint_format:vu(Oi),min_length:gu,max_length:_u,length_equals:(e,t)=>du(e,t.length),min_size:gu,max_size:_u,size_equals:(e,t)=>du(e,t.size),string_format:(e,t)=>{hu(e,t.format),t.pattern&&pu(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)=>mu(e,t.mime)};function bu(e){let t={},n=e._zod.def,r=e._zod.traits.has(`$ZodCheck`)?[e,...n.checks??[]]:n.checks??[];for(let e of r)yu[e._zod.def.check]?.(t,e._zod.def);let i=e._zod.bag;i.minimum!==void 0&&lu(t,`minimum`,i.minimum),i.exclusiveMinimum!==void 0&&lu(t,`exclusiveMinimum`,i.exclusiveMinimum),i.maximum!==void 0&&uu(t,`maximum`,i.maximum),i.exclusiveMaximum!==void 0&&uu(t,`exclusiveMaximum`,i.exclusiveMaximum),i.multipleOf!==void 0&&fu(t,i.multipleOf),i.format!==void 0&&(t.format??=i.format,i.format.includes(`int`)&&(t.isInt=!0)),i.mime&&mu(t,i.mime);for(let e of i.patterns??[])pu(t,e);return t}var xu={guid:`uuid`,url:`uri`,datetime:`date-time`,json_string:`json-string`,regex:``},Su=new Map([[Ds,co],[ks,lo]]),Cu=e=>Su.get(e)??e,wu=(e,t,n,r)=>{let i=n;i.type=`string`;let{minimum:a,maximum:o,format:s,patterns:c,contentEncoding:l,laxFormat:u}=bu(e);if(typeof a==`number`&&(i.minLength=a),typeof o==`number`&&(i.maxLength=o),s&&(i.format=xu[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(Cu);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}))])}},Tu=(e,t,n,r)=>{let i=n,{minimum:a,maximum:o,multipleOf:s,exclusiveMaximum:c,exclusiveMinimum:l,isInt:u}=bu(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)):Yl(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}))])}},Eu=(e,t,n,r)=>{n.type=`boolean`},Du=(e,t,n,r)=>{n.not={}},Ou=(e,t,n,r)=>{let i=e._zod.def,a=$r(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},ku=(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(Yl(e,t,n,r,"Literal `undefined` cannot be represented in JSON Schema"))return}else if(typeof o==`bigint`){if(Yl(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}},Au=(e,t,n,r)=>{Yl(e,t,n,r,`Custom types cannot be represented in JSON Schema`)},ju=(e,t,n,r)=>{Yl(e,t,n,r,`Transforms cannot be represented in JSON Schema`)},Mu=(e,t,n,r)=>{let i=n,a=e._zod.def,{minimum:o,maximum:s}=bu(e);typeof o==`number`&&(i.minItems=o),typeof s==`number`&&(i.maxItems=s),i.type=`array`,i.items=Xl(a.element,t,{...r,path:[...r.path,`items`]})};function Nu(e){let t=e._zod.def;return t.type===`pipe`&&t.in._zod.traits.has(`$ZodTransform`)?Nu(t.out):t.type===`catch`?Nu(t.innerType):e._zod.optin}var Pu=(e,t,n,r)=>{let i=n,a=e._zod.def,o=a.shape;if(Object.getOwnPropertySymbols(o).length&&Yl(e,t,i,r,`Symbol keys cannot be represented in JSON Schema`))return;i.type=`object`,i.properties={};for(let e in o)si(i.properties,e,Xl(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`?Nu(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=Xl(a.catchall,t,{...r,path:[...r.path,`additionalProperties`]})):t.io===`output`&&(i.additionalProperties=!1)},Fu=(e,t,n,r)=>{let i=e._zod.def,a=i.inclusive===!1,o=i.options.map((e,n)=>Xl(e,t,{...r,path:[...r.path,a?`oneOf`:`anyOf`,n]}));a?n.oneOf=o:n.anyOf=o},Iu=(e,t,n,r)=>{let i=e._zod.def,a=Xl(i.left,t,{...r,path:[...r.path,`allOf`,0]}),o=Xl(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 Lu(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=Lu(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=>Lu(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`)?xo:bo).source),p):p}var Ru=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 Ru.get(e)??[]){let i=e.seen.get(r),a=(i?.def??i?.schema)?.propertyNames;if(!a||a===!0||n.has(a))continue;let o=Lu(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 Bu=(e,t,n,r)=>{let i=n,a=e._zod.def;i.type=`object`;let o=a.keyType,s=bu(o).patterns;if(a.mode===`loose`&&s&&s.size>0){let e=Xl(a.valueType,t,{...r,path:[...r.path,`patternProperties`,`*`]});i.patternProperties={};for(let t of s)si(i.patternProperties,Cu(t).source,e)}else{if(t.target===`draft-07`||t.target===`draft-2020-12`){i.propertyNames=Xl(a.keyType,t,{...r,path:[...r.path,`propertyNames`]});let n=Ru.get(t);n||(n=[],Ru.set(t,n),t.deferred.push(()=>zu(t))),n.push(e)}i.additionalProperties=Xl(a.valueType,t,{...r,path:[...r.path,`additionalProperties`]})}let c=o._zod.values,l=t.io===`input`&&Nu(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))}},Vu=(e,t,n,r)=>{let i=e._zod.def,a=Xl(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`}]},Hu=(e,t,n,r)=>{let i=e._zod.def;Xl(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType},Uu=Symbol();function Wu(e,t,n,r,i){let a=!1,o=JSON.stringify(e,(e,t)=>typeof t==`bigint`?(a=!0,null):t);return a?(Yl(t,n,r,i,`BigInt defaults cannot be represented in JSON Schema`),Uu):JSON.parse(o)}var Gu=(e,t,n,r)=>{let i=e._zod.def;Xl(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType;let o=Wu(i.defaultValue,e,t,n,r);o!==Uu&&(n.default=o)},Ku=(e,t,n,r)=>{let i=e._zod.def;Xl(i.innerType,t,r);let a=t.seen.get(e);if(a.ref=i.innerType,t.io!==`input`)return;let o=Wu(i.defaultValue,e,t,n,r);o!==Uu&&(n._prefault=o)},qu=(e,t,n,r)=>{let i=e._zod.def;Xl(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType;let o;try{o=i.catchValue(void 0)}catch{Yl(e,t,n,r,`Dynamic catch values are not supported in JSON Schema`);return}n.default=o},Ju=(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;Xl(o,t,r);let s=t.seen.get(e);s.ref=o},Yu=(e,t,n,r)=>{let i=e._zod.def;Xl(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType,n.readOnly=!0},Xu=(e,t,n,r)=>{let i=e._zod.def;Xl(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType},Zu=new WeakSet([Object.prototype,Error.prototype]);function Qu(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 $u=J(`ZodError`,(e,t)=>{Sa.init(e,t),e.name=`ZodError`;let n=Object.getPrototypeOf(e);Zu.has(n)||(Zu.add(n),Qu(n,`format`,e=>t=>Ta(e,t)),Qu(n,`flatten`,e=>t=>wa(e,t)),Qu(n,`addIssue`,e=>t=>{e.issues.push(t),e.message=JSON.stringify(e.issues,ti,2)}),Qu(n,`addIssues`,e=>t=>{e.issues.push(...t),e.message=JSON.stringify(e.issues,ti,2)}),Object.defineProperty(n,"isEmpty",{configurable:!0,enumerable:!1,get(){return this.issues.length===0}}))},void 0,{Parent:Error}),ed=Da($u),td=Oa($u),nd=ka($u),rd=ja($u),id=La($u),ad=Ra($u),od=za($u),sd=Ba($u),cd=Va($u),ld=Ha($u),ud=Ua($u),dd=Wa($u);function fd(){ma.localeError||ha(zc())}function pd(){ma.memoizer||ha({memoizer:Ic()})}var md=J(`ZodType`,(e,t)=>(fd(),Go.init(e,t),e.def=t,e.type=t.type,e),{check(...e){let t=this.def;return this.clone(mi(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 wi(this,e,t)},brand(){return this},register(e,t){return e.add(this,t),this},refine(e,t){return this.check(Pf(e,t))},superRefine(e,t){return this.check(Ff(e,t))},overwrite(e){return this.check(Ll(e))},optional(){return hf(this)},exactOptional(){return _f(this)},nullable(){return yf(this)},nullish(){return hf(yf(this))},nonoptional(e){return Tf(this,e)},array(){return Zd(this)},or(e){return nf([this,e])},and(e){return af(this,e)},transform(e){return kf(this,pf(e))},default(e){return xf(this,e)},prefault(e){return Cf(this,e)},catch(e){return Df(this,e)},pipe(e){return kf(this,e)},readonly(){return Mf(this)},describe(e){let t=this.clone();return Uc.add(t,{description:e}),t},meta(...e){if(e.length===0)return Uc.get(this);let t=this.clone();return Uc.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 Zi(this,`~standard`,{...Jo(this),jsonSchema:{input:cu(this,`input`),output:cu(this,`output`)}})},set"~standard"(e){Xi(this,`~standard`,e)},parse:function e(t,n){return ed(this,t,n,{callee:e})},parseAsync:async function e(t,n){return await td(this,t,n,{callee:e})},safeParse(e,t){return nd(this,e,t)},async safeParseAsync(e,t){return rd(this,e,t)},get spa(){return this?.safeParseAsync},set spa(e){Xi(this,`spa`,e)},validate(e,t){return Pa(this,e,t)},validateAsync(e,t){return Ia(this,e,t)},encode:function e(t,n){return id(this,t,n,{callee:e})},decode:function e(t,n){return ad(this,t,n,{callee:e})},encodeAsync:async function e(t,n){return await od(this,t,n,{callee:e})},decodeAsync:async function e(t,n){return await sd(this,t,n,{callee:e})},safeEncode(e,t){return cd(this,e,t)},safeDecode(e,t){return ld(this,e,t)},async safeEncodeAsync(e,t){return ud(this,e,t)},async safeDecodeAsync(e,t){return dd(this,e,t)},toJSONSchema(e){return su(this,{})(e)},get description(){return Uc.get(this)?.description},get _def(){return this._zod.def}}),hd=J(`_ZodString`,(e,t)=>{Yo.init(e,t),md.init(e,t),e._zod.processJSONSchema=(t,n,r)=>wu(e,t,n,r)},Qi({format:e=>bu(e).format??null,minLength:e=>bu(e).minimum??null,maxLength:e=>bu(e).maximum??null},{regex(...e){return this.check(jl(...e))},includes(...e){return this.check(Pl(...e))},startsWith(...e){return this.check(Fl(...e))},endsWith(...e){return this.check(Il(...e))},min(...e){return this.check(kl(...e))},max(...e){return this.check(Ol(...e))},length(...e){return this.check(Al(...e))},nonempty(...e){return this.check(kl(1,...e))},lowercase(e){return this.check(Ml(e))},uppercase(e){return this.check(Nl(e))},trim(){return this.check(zl())},normalize(...e){return this.check(Rl(...e))},toLowerCase(){return this.check(Bl())},toUpperCase(){return this.check(Vl())},slugify(){return this.check(Hl())}})),gd=J(`ZodString`,(e,t)=>{Yo.init(e,t),hd.init(e,t)},{email(e){return this.check(Kc(Sd,e))},url(e){return this.check(Qc(Td,e))},jwt(e){return this.check(pl(Bd,e))},emoji(e){return this.check($c(Ed,e))},guid(e){return this.check(qc(Cd,e))},uuid(e){return this.check(Jc(wd,e))},uuidv4(e){return this.check(Yc(wd,e))},uuidv6(e){return this.check(Xc(wd,e))},uuidv7(e){return this.check(Zc(wd,e))},nanoid(e){return this.check(el(Dd,e))},cuid(e){return this.check(tl(Od,e))},cuid2(e){return this.check(nl(kd,e))},ulid(e){return this.check(rl(Ad,e))},base64(e){return this.check(ul(Ld,e))},base64url(e){return this.check(dl(Rd,e))},xid(e){return this.check(il(jd,e))},ksuid(e){return this.check(al(Md,e))},ipv4(e){return this.check(ol(Nd,e))},ipv6(e){return this.check(sl(Pd,e))},cidrv4(e){return this.check(cl(Fd,e))},cidrv6(e){return this.check(ll(Id,e))},e164(e){return this.check(fl(zd,e))},datetime(e){return this.check(ml(vd,e))},date(e){return this.check(hl(yd,e))},time(e){return this.check(gl(bd,e))},duration(e){return this.check(_l(xd,e))}});function Y(e){return Gc(gd,e)}var _d=J(`ZodStringFormat`,(e,t)=>{Xo.init(e,t),hd.init(e,t)}),vd=J(`ZodISODateTime`,(e,t)=>{hs.init(e,t),_d.init(e,t)}),yd=J(`ZodISODate`,(e,t)=>{gs.init(e,t),_d.init(e,t)}),bd=J(`ZodISOTime`,(e,t)=>{_s.init(e,t),_d.init(e,t)}),xd=J(`ZodISODuration`,(e,t)=>{vs.init(e,t),_d.init(e,t)}),Sd=J(`ZodEmail`,(e,t)=>{$o.init(e,t),_d.init(e,t)}),Cd=J(`ZodGUID`,(e,t)=>{Zo.init(e,t),_d.init(e,t)}),wd=J(`ZodUUID`,(e,t)=>{Qo.init(e,t),_d.init(e,t)}),Td=J(`ZodURL`,(e,t)=>{ss.init(e,t),_d.init(e,t)}),Ed=J(`ZodEmoji`,(e,t)=>{cs.init(e,t),_d.init(e,t)}),Dd=J(`ZodNanoID`,(e,t)=>{ls.init(e,t),_d.init(e,t)}),Od=J(`ZodCUID`,(e,t)=>{us.init(e,t),_d.init(e,t)}),kd=J(`ZodCUID2`,(e,t)=>{ds.init(e,t),_d.init(e,t)}),Ad=J(`ZodULID`,(e,t)=>{fs.init(e,t),_d.init(e,t)}),jd=J(`ZodXID`,(e,t)=>{ps.init(e,t),_d.init(e,t)}),Md=J(`ZodKSUID`,(e,t)=>{ms.init(e,t),_d.init(e,t)}),Nd=J(`ZodIPv4`,(e,t)=>{ys.init(e,t),_d.init(e,t)}),Pd=J(`ZodIPv6`,(e,t)=>{Ss.init(e,t),_d.init(e,t)}),Fd=J(`ZodCIDRv4`,(e,t)=>{Cs.init(e,t),_d.init(e,t)}),Id=J(`ZodCIDRv6`,(e,t)=>{Ts.init(e,t),_d.init(e,t)}),Ld=J(`ZodBase64`,(e,t)=>{Os.init(e,t),_d.init(e,t)}),Rd=J(`ZodBase64URL`,(e,t)=>{js.init(e,t),_d.init(e,t)}),zd=J(`ZodE164`,(e,t)=>{Ms.init(e,t),_d.init(e,t)}),Bd=J(`ZodJWT`,(e,t)=>{Ps.init(e,t),_d.init(e,t)}),Vd=J(`ZodNumber`,(e,t)=>{Fs.init(e,t),md.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Tu(e,t,n,r),e.isFinite=!0},Qi({minValue:e=>{let{minimum:t,exclusiveMinimum:n}=bu(e);return Math.max(t??-1/0,n??-1/0)},maxValue:e=>{let{maximum:t,exclusiveMaximum:n}=bu(e);return Math.min(t??1/0,n??1/0)},isInt:e=>{let{isInt:t,multipleOf:n}=bu(e);return!!t||!!n?.some(Number.isSafeInteger)},format:e=>bu(e).format??null},{gt(e,t){return this.check(Tl(e,t))},gte(e,t){return this.check(El(e,t))},min(e,t){return this.check(El(e,t))},lt(e,t){return this.check(Cl(e,t))},lte(e,t){return this.check(wl(e,t))},max(e,t){return this.check(wl(e,t))},int(e){return this.check(Ud(e))},safe(e){return this.check(Ud(e))},positive(e){return this.check(Tl(0,e))},nonnegative(e){return this.check(El(0,e))},negative(e){return this.check(Cl(0,e))},nonpositive(e){return this.check(wl(0,e))},multipleOf(e,t){return this.check(Dl(e,t))},step(e,t){return this.check(Dl(e,t))},finite(){return this}}));function X(e){return vl(Vd,e)}var Hd=J(`ZodNumberFormat`,(e,t)=>{Is.init(e,t),Vd.init(e,t)});function Ud(e){return yl(Hd,e)}var Wd=J(`ZodBoolean`,(e,t)=>{Ls.init(e,t),md.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Eu(e,t,n,r)});function Gd(e){return bl(Wd,e)}var Kd=J(`ZodUnknown`,(e,t)=>{Rs.init(e,t),md.init(e,t),e._zod.processJSONSchema=(e,t,n)=>void 0});function qd(){return xl(Kd)}var Jd=J(`ZodNever`,(e,t)=>{zs.init(e,t),md.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Du(e,t,n,r)});function Yd(e){return Sl(Jd,e)}var Xd=J(`ZodArray`,(e,t)=>{pd(),Vs.init(e,t),md.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Mu(e,t,n,r),e.element=t.element},{min(e,t){return this.check(kl(e,t))},nonempty(e){return this.check(kl(1,e))},max(e,t){return this.check(Ol(e,t))},length(e,t){return this.check(Al(e,t))},unwrap(){return this.element}});function Zd(e,t){return Ul(Xd,e,t)}var Qd=J(`ZodObject`,(e,t)=>{pd(),qs.init(e,t),md.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Pu(e,t,n,r),aa(e,`shape`,e=>e._zod.def.shape,!1)},{keyof(){return lf(Object.keys(this._zod.def.shape))},catchall(e){return this.clone(mi(this._zod.def,{catchall:e}))},passthrough(){return this.clone(mi(this._zod.def,{catchall:qd()}))},loose(){return this.clone(mi(this._zod.def,{catchall:qd()}))},strict(){return this.clone(mi(this._zod.def,{catchall:Yd()}))},strip(){return this.clone(mi(this._zod.def,{catchall:void 0}))},extend(e){return Mi(this,e)},safeExtend(e){return Pi(this,e)},merge(e){return Fi(this,e)},pick(e){return ki(this,e)},omit(e){return ji(this,e)},partial(...e){return Ii(mf,this,e[0])},exactPartial(...e){return Ii(gf,this,e[0],`exactPartial`)},required(...e){return Li(wf,this,e[0])}});function $d(e,t){return new Qd({type:`object`,shape:e??{},...q(t)})}function ef(e,t){return new Qd({type:`object`,shape:e,catchall:qd(),...q(t)})}var tf=J(`ZodUnion`,(e,t)=>{Ys.init(e,t),md.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Fu(e,t,n,r),e.options=t.options});function nf(e,t){return new tf({type:`union`,options:e,...q(t)})}var rf=J(`ZodIntersection`,(e,t)=>{Xs.init(e,t),md.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Iu(e,t,n,r)});function af(e,t){return new rf({type:`intersection`,left:e,right:t})}var of=J(`ZodRecord`,(e,t)=>{pd(),$s.init(e,t),md.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Bu(e,t,n,r),e.keyType=t.keyType,e.valueType=t.valueType});function sf(e,t,n){return!t||!t._zod?new of({type:`record`,keyType:Y(),valueType:e,...q(t)}):new of({type:`record`,keyType:e,valueType:t,...q(n)})}var cf=J(`ZodEnum`,(e,t)=>{ec.init(e,t),md.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Ou(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 cf({...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 cf({...t,checks:[],...q(r),entries:i})}});function lf(e,t){return new cf({type:`enum`,entries:Array.isArray(e)?Object.fromEntries(e.map(e=>[e,e])):e,...q(t)})}var uf=J(`ZodLiteral`,(e,t)=>{tc.init(e,t),md.init(e,t),e._zod.processJSONSchema=(t,n,r)=>ku(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 df(e,t){return new uf({type:`literal`,values:Array.isArray(e)?e:[e],...q(t)})}var ff=J(`ZodTransform`,(e,t)=>{pd(),nc.init(e,t),md.init(e,t),e._zod.processJSONSchema=(t,n,r)=>ju(e,t,n,r),e._zod.parse=(n,r)=>{if(r.direction===`backward`)throw new pa(e.constructor.name);n.addIssue=r=>{if(typeof r==`string`)n.issues.push(Ji(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(Ji(t))}};let i=t.transform(n.value,n);return i instanceof Promise?i.then(e=>(n.value=e,n)):(n.value=i,n)}});function pf(e){return new ff({type:`transform`,transform:e})}var mf=J(`ZodOptional`,(e,t)=>{ic.init(e,t),md.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Xu(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function hf(e){return new mf({type:`optional`,innerType:e})}var gf=J(`ZodExactOptional`,(e,t)=>{ac.init(e,t),md.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Xu(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function _f(e){return new gf({type:`optional`,innerType:e})}var vf=J(`ZodNullable`,(e,t)=>{oc.init(e,t),md.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Vu(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function yf(e){return new vf({type:`nullable`,innerType:e})}var bf=J(`ZodDefault`,(e,t)=>{sc.init(e,t),md.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Gu(e,t,n,r),e.unwrap=()=>e._zod.def.innerType,e.removeDefault=e.unwrap});function xf(e,t){return new bf({type:`default`,innerType:e,get defaultValue(){return typeof t==`function`?t():xi(t)}})}var Sf=J(`ZodPrefault`,(e,t)=>{lc.init(e,t),md.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Ku(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Cf(e,t){return new Sf({type:`prefault`,innerType:e,get defaultValue(){return typeof t==`function`?t():xi(t)}})}var wf=J(`ZodNonOptional`,(e,t)=>{uc.init(e,t),md.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Hu(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Tf(e,t){return new wf({type:`nonoptional`,innerType:e,...q(t)})}var Ef=J(`ZodCatch`,(e,t)=>{pc.init(e,t),md.init(e,t),e._zod.processJSONSchema=(t,n,r)=>qu(e,t,n,r),e.unwrap=()=>e._zod.def.innerType,e.removeCatch=e.unwrap});function Df(e,t){return new Ef({type:`catch`,innerType:e,catchValue:typeof t==`function`?t:sa(t)})}var Of=J(`ZodPipe`,(e,t)=>{mc.init(e,t),md.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Ju(e,t,n,r),e.in=t.in,e.out=t.out});function kf(e,t){return new Of({type:`pipe`,in:e,out:t})}var Af=J(`ZodPreprocess`,(e,t)=>{Of.init(e,t),gc.init(e,t)}),jf=J(`ZodReadonly`,(e,t)=>{_c.init(e,t),md.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Yu(e,t,n,r),e.unwrap=()=>e._zod.def.innerType});function Mf(e){return new jf({type:`readonly`,innerType:e})}var Nf=J(`ZodCustom`,(e,t)=>{yc.init(e,t),md.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Au(e,t,n,r)});function Pf(e,t={}){return Wl(Nf,e,t)}function Ff(e,t){return Gl(e,t)}function If(e,t){return new Af({type:`pipe`,in:pf(e),out:t})}var Lf=/[\p{L}\p{N}]/u,Rf=/\s/,zf=/[_\-/]/,Bf=/[\s,;:.\-–—(_/]+$/u,Vf=/^[\p{M}\u200d\ufe0f\u{1F3FB}-\u{1F3FF}\u{E0020}-\u{E007F}]$/u,Hf=/^[\u{1F1E6}-\u{1F1FF}]$/u,Uf=/[\uD800-\uDFFF]/gu,Wf=/[\p{Cc}\p{Zl}\p{Zp}]+/gu,Gf=/(?![\u200c\u200d\u{E0000}-\u{E007F}])\p{Cf}/gu,Kf=/(\u{1F3F4})([\u{E0000}-\u{E007F}]*)|[\u{E0000}-\u{E007F}]+/gu,qf=/^[\p{Cf}\s\u034f\u115f\u1160\u17b4\u17b5\u2800\u3164\uffa0]*$/u;function Jf(e){let t=e.replace(Uf,`�`).replace(Wf,` `).replace(Gf,``).replace(Kf,(e,t,n)=>t?t+n:``).replace(/\s+/g,` `).trim();return qf.test(t)?``:t}function Yf(e){let t=[],n=!1,r=0;for(let i of e){let e=t.length-1;e>=0&&(n||Vf.test(i)||Hf.test(i)&&r===1)?(t[e]+=i,r=Hf.test(i)?r+1:r):(t.push(i),r=+!!Hf.test(i)),n=i===``}return t}function Xf(e,t){for(let n=e.length-1;n>0;n--)if(t.test(e[n]))return n;return-1}function Zf(e,t){if(e.length<=t)return e;let n=Array.from(e);if(n.length<=t)return e;let r=Yf(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&&!Vf.test(o))return o+`…`;let s=i.length,c=r[i.length];if(c!==void 0&&!Rf.test(c)){let e=Xf(i,Rf);e<=0&&(e=Xf(i,zf)),e>0&&(s=e)}return i.slice(0,s).join(``).replace(Bf,``)+`…`}var Qf=[`;`,`. `,` — `,` (`],$f=12;function ep(e,t){let n=0,r=0;for(let i of e){if(r++>=t)break;n+=i.length}return n}function tp(e,t){let n=ep(e,Math.max(0,$f-t)),r=e.length;for(let t of Qf){let i=e.indexOf(t,n);i>=0&&i<r&&(r=i)}return e.slice(0,r).trim()}function np(e){let t=e.split(/[\\/]/).pop()??``,n=t.lastIndexOf(`.`);return Jf(n>0?t.slice(0,n):t)}var rp=new Map;function ip(e){let t=e.replace(/^0+/,``)||`0`,n=rp.get(t);return n||(rp.size>=2e3&&rp.clear(),n=ap(t),rp.set(t,n)),n}function ap(e){return RegExp(`^v0*${e}(?![\\p{L}\\p{N}])(?:(?:\\s*[:,\\-–—]|\\.(?=\\s|$))[\\s:,.\\-–—]*|\\s*$|\\s+(?=\\(batch\\b))`,`iu`)}var op=e=>e!==``&&e!==`…`;function sp(e){let t=Zf(Jf(e.label??``),48);if(op(t))return t;let n=Jf(e.note??``),r=n,i=/^v(\d+)$/i.exec(e.id)?.[1];i!==void 0&&(r=r.replace(ip(i),``)),r=r.replace(/^\(batch\b[^)]*\)\s*:?\s*/i,``);let a=Array.from(n.slice(0,n.length-r.length)).length;if(r=tp(r,a),Lf.test(r)){let e=Zf(r,48);if(op(e))return e}let o=Zf(np(e.file),48);if(op(o))return o;let s=Zf(Jf(e.id),48);return op(s)?s:`Untitled`}var cp=[`script`,`picture`,`voice`,`music`,`sfx`,`mix`,`visuals`,`notes`,`assets`,`project`],lp=[`cut`,`variant`,`take`,`script`,`picks`,`notes-sent`,`replies`,`lock`,`files`,`entry`,`format`,`visual`,`film`],up=[`user`,`agent`,`rushes`],dp=5e3,fp={script:`Script`,picture:`Picture`,voice:`Voice`,music:`Music`,sfx:`Sound effects`,mix:`Mix`,visuals:`Visuals`,notes:`Notes`,assets:`Files`,project:`Project`},pp=[`Sunday`,`Monday`,`Tuesday`,`Wednesday`,`Thursday`,`Friday`,`Saturday`],mp=[`January`,`February`,`March`,`April`,`May`,`June`,`July`,`August`,`September`,`October`,`November`,`December`],hp=e=>String(e).padStart(2,`0`),gp=e=>Number.isFinite(e.getTime());function _p(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 vp(e){return gp(e)?`${hp(e.getHours())}:${hp(e.getMinutes())}`:`--:--`}function yp(e){return`${e.getFullYear()}-${hp(e.getMonth()+1)}-${hp(e.getDate())}`}function bp(e,t,n){if(!gp(e))return`Date unknown`;if(!n)return`${pp[e.getDay()]} ${e.getDate()} ${mp[e.getMonth()]} ${e.getFullYear()}`;let r=_p(e.toISOString(),t);if(r===0)return`Today`;if(r===1)return`Yesterday`;let i=e.getFullYear()===t.getFullYear()?``:` ${e.getFullYear()}`;return`${pp[e.getDay()].slice(0,3)} ${e.getDate()} ${mp[e.getMonth()].slice(0,3)}${i}`}function Z(e){return ef(e)}var xp=lf([`script`,`picture`,`voice`,`music`,`sfx`,`mix`,`visuals`]),Sp=lf([`voice`,`music`,`sfx`]),Cp=Y().min(1).max(64),wp=X().nonnegative(),Tp=Y().regex(/^[abcdefghjkmnpqrstuvwxyz23456789]{8}$/),Ep=Z({n:X().int().positive(),name:Y().trim().min(1).max(80),start:X().nonnegative(),tag:Y().trim().max(24).default(``)}),Dp=Z({file:Y().min(1),width:X().int().positive(),height:X().int().positive(),bytes:X().int().nonnegative(),createdAt:Y()}),Op=Z({id:Y().max(16).regex(ue),label:Y().min(3).max(16),file:Y().min(1),width:X().int().positive(),height:X().int().positive(),duration:wp.nullable().default(null),fps:X().positive().nullable().default(null),addedAt:Y()}),kp=$d({id:Cp,file:Y().min(1),duration:wp.nullable().default(null),fps:X().positive().nullable().default(null),addedAt:Y(),note:Y().default(``),label:Y().default(``),shots:Zd(Ep).max(200).default([]),proxy:Dp.nullable().default(null),width:X().int().positive().nullable().default(null),height:X().int().positive().nullable().default(null),formats:Zd(Op).max(8).default([])}).superRefine((e,t)=>{let n=e.width!==null&&e.height!==null&&fe(e.width,e.height)?_e(ge(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)})}),Ap=Z({id:Cp,name:Y().min(1),versions:Zd(kp).default([]),lockedVersion:Y().nullable().default(null),shelved:Y().max(40).nullable().optional()}),jp=Z({id:Cp,name:Y().min(1),t:wp,file:Y().min(1).max(1024).optional()}),Mp=Z({id:Cp,name:Y().min(1),file:Y().min(1),meta:sf(Y(),nf([Y(),X()])).default({}),cues:Zd(jp).default([]),videos:Zd(Cp).optional(),video:Cp.optional(),addedAt:Y().optional(),madeFor:sf(Y(),Y()).optional(),putAway:Y().optional()}),Np=Z({id:Cp,stage:Sp,name:Y().min(1),variants:Zd(Mp).default([])}),Pp=Z({id:Cp,kind:lf([`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:df(1),rev:X().int().nonnegative(),id:Tp.optional(),name:Y().min(1),fps:X().positive().default(30),videos:Zd(Ap).default([]),lanes:Zd(Np).default([]),files:Zd(Pp).default([]),autoProxy:Gd().default(!1)});var Fp=Z({id:Cp,file:Y().min(1),duration:wp.nullable().default(null),forText:Y()}),Ip=lf([`draft`,`approved`,`flagged`]),Lp=$d({id:Cp,start:wp,end:wp,current:Y(),proposed:Y().nullable().default(null),direction:Y().default(``),status:Ip.default(`draft`),takes:Zd(Fp).default([])}).refine(e=>e.end>e.start,{message:`end must be after start`,path:[`end`]});Z({schema:df(1),rev:X().int().nonnegative(),wordsPerSecond:X().positive().default(2.6),sections:Zd(Lp).default([]),sectionCounter:X().int().nonnegative().optional()});var Rp=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)}),zp=Z({x:X().min(0).max(1),y:X().min(0).max(1)}),Bp=Z({kind:lf([`rise`,`fall`,`louder`,`quieter`]),db:X().min(.5).max(24).optional()}),Vp=[`voice`,`music`,`sfx`,`mix`],Hp=$d({id:Cp,stage:xp,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:lf([`point`,`range`,`whole`]),t:wp.nullable().default(null),tOut:wp.nullable().default(null),frame:X().int().nonnegative().nullable().default(null),text:Y().trim().min(1).max(4e3),box:Rp.nullable().default(null),pin:zp.nullable().default(null),grab:Y().nullable().default(null),shot:Z({n:X().int().positive(),name:Y()}).nullable().default(null),marks:Zd(Bp).max(4).default([]),format:Y().max(16).regex(ue).nullable().default(null),status:lf([`todo`,`done`]).default(`todo`),reply:Y().default(``),fixT:wp.nullable().default(null),fixVersion:Y().nullable().default(null),batch:Y().nullable().default(null),createdAt:Y(),by:lf([`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&&!Vp.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:df(1),rev:X().int().nonnegative(),notes:Zd(Hp).default([])});var Up=Z({voice:X(),music:X(),sfx:X()}).partial().default({}),Wp=Z({lane:Cp,variant:Cp,at:Y(),seen:sf(Y(),Y()).default({})}),Gp=Z({voice:Wp,music:Wp,sfx:Wp}).partial(),Kp=Z({lanes:sf(Y(),Y()).default({}),levels:Up,use:Gp.optional()});Z({schema:df(1),rev:X().int().nonnegative(),lanes:sf(Y(),Y()).default({}),sections:sf(Y(),Y()).default({}),levels:Up,use:Gp.optional(),videos:sf(Y(),Kp).default({})});var qp=Z({id:Cp,stage:xp.nullable(),noteIds:Zd(Y()).default([]),sectionIds:Zd(Y()).default([]),sentAt:Y(),prompt:Y()});Z({schema:df(1),rev:X().int().nonnegative(),batches:Zd(qp).default([])}),Z({schema:df(1),rev:X().int().nonnegative(),dismissed:Zd(Y().max(1024)).max(1e4).default([]),settled:Zd(Z({video:Y().max(200),version:Y().max(200),kinds:Zd(lf([`voice`,`music`,`sfx`,`cut`,`other`])).max(5)})).max(200).default([])});var Jp=Z({id:Cp,at:Y(),area:lf(cp),kind:lf(lp),text:Y().min(1).max(160),video:Y().nullable().default(null),version:Y().nullable().default(null),ref:Y().max(300).nullable().default(null),by:lf(up),tab:xp.nullable().default(null),n:X().int().positive().default(1),subject:Y().max(200).default(``)}),Yp=Z({schema:df(1),rev:X().int().nonnegative(),backfilled:Gd().default(!1),began:Y().optional(),undated:Zd(Y().max(300)).max(dp).default([]),dropped:X().int().nonnegative().default(0),entries:Zd(Jp).max(dp).default([]),newer:df(!0).optional()}),Xp=e=>typeof e==`object`&&!!e&&!Array.isArray(e);function Zp(e){if(!Xp(e)||!Array.isArray(e.entries))return e;let t=[],n=new Set,r=0;for(let i of e.entries){let e=Jp.safeParse(Xp(i)?Qp(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-dp),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,dp):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 Qp(e){let t={...e};return typeof t.text==`string`&&(t.text=Jf(t.text)),typeof t.subject==`string`&&(t.subject=Jf(t.subject)),t}If(Zp,Yp),Z({schema:df(1),rev:X().int().nonnegative(),baseline:Y().max(1e6).default(``),seen:Y().max(64).default(``)});var $p=Z({ratio:Y().max(16).regex(ue),file:Y().min(1),width:X().int().positive(),height:X().int().positive()}),em=Z({n:X().int().positive(),images:Zd($p).min(1).max(8)}),tm=Z({id:Cp,addedAt:Y(),label:Y().default(``),pages:Zd(em).min(1).max(100)}),nm=Z({id:Cp,name:Y().trim().min(1).max(80),kind:lf([`still`,`carousel`]),addedAt:Y(),versions:Zd(tm).min(1)});Z({schema:df(1),rev:X().int().nonnegative(),visuals:Zd(nm).default([])}),e(((e,t)=>{t.exports={}}))();var rm={todo:`To do`,sent:`With your agent`,done:`Done`};function im(e){return e.status===`done`?`done`:e.batch===null?`todo`:`sent`}function am(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?am(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 sm(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 cm(e,t){return e.addedAt===void 0||e.putAway!==void 0?!1:t===void 0||e.addedAt>t.at}function lm(e,t,n){return n!==void 0&&n.lane===t&&n.variant===e.id?`in-use`:e.putAway===void 0?cm(e,n)?`new`:`earlier`:`put-away`}function um(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 dm={2:`picture`,3:`voice`,4:`music`,5:`sfx`,6:`picture`,7:`visuals`,8:`assets`};function fm(e,t){return e===`1`?t:dm[e]??null}function pm(e){return e===`mix`?`picture`:e}var mm=(e,t)=>new Date(e).toLocaleDateString(`en-GB`,{day:`numeric`,month:`short`,timeZone:t});function hm(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:mm(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=lm(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?sm(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 gm=e=>`${e.lane}/${e.variant.id}`;function _m(e){return e.inUse??e.fresh[0]??e.earlier[0]?.takes[0]??null}var vm={fresh:`New`,inUse:`In use`,earlier:`Earlier`};function ym(e,t=e=>e){let n=[],r=(e,r,i)=>n.push({kind:e,heading:`${vm[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 bm(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 xm=e=>String(e).padStart(2,`0`);function Sm(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`${xm(Math.floor(a/3600))}:${xm(Math.floor(a/60)%60)}:${xm(a%60)}:${xm(i)}`}var Cm={voice:`Voice`,music:`Music`,sfx:`Effects`};function wm(e,t,n=30){let r=e=>Sm(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?`${xm(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),`${Cm[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 Tm=e=>t=>t.status===`todo`&&(!t.video||e.inPlay.has(t.video));function Em(e){let t=Tm(e),n=e.scriptTodo-e.notes.filter(e=>e.stage===`script`&&t(e)).length;return Math.max(0,n)+e.briefChanged+e.storyboardChanged}function Dm(e){let t=Tm(e);return e.notes.filter(e=>t(e)&&e.batch===null).length+Em(e)}var Om=(e,t)=>e===`sent`?`${rm.sent} · ${t}`:t,km=(e,t)=>t>0?Math.min(100,Math.max(0,e/t*100)):0;function Am(e,t,n){let r=e=>n?Pm(Math.min(t,Math.max(0,e)),n):km(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:im(e)}})}var jm=e=>Math.min(e,2),Mm=e=>({start:0,end:Math.max(0,e)}),Nm=(e,t)=>e.start<=1e-6&&e.end>=t-1e-6;function Pm(e,t){let n=t.end-t.start;return n>0?Math.min(110,Math.max(-10,(e-t.start)/n*100)):0}var Fm=(e,t)=>t.start+Math.min(1,Math.max(0,e))*(t.end-t.start);function Im(e,t){if(!(t>0))return Mm(0);let n=Math.min(t,Math.max(jm(t),e.end-e.start)),r=Math.min(t-n,Math.max(0,e.start));return{start:r,end:r+n}}function Lm(e,t,n,r=(e.start+e.end)/2){let i=Math.min(t,Math.max(jm(t),(e.end-e.start)*n)),a=e.end>e.start?(r-e.start)/(e.end-e.start):.5;return Im({start:r-a*i,end:r-a*i+i},t)}var Rm=(e,t,n)=>Im({start:e.start+n,end:e.end+n},t);function zm(e,t,n){if(n>=e.start&&n<=e.end)return e;let r=e.end-e.start;return Im(n>e.end?{start:n,end:n+r}:{start:n-r*.1,end:n+r*.9},t)}var Bm=[`change`,`proxy`,`corrupt`],Vm=e=>`rushes-sse-v1-${e}`,Hm=e=>`rushes-v1-${e}`,Um=4e4,Wm=5e3;function Gm(){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 Km(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`||Bm.includes(n)&&typeof r==`string`:!1}function qm(e,t){t.type===`open`?e.open():t.type===`error`?e.error():`data`in t&&e[t.type](t.data)}function Jm(e,t,n,r){let i=new e.EventSource(t),a=e=>{qm(n,e),r?.(e)};for(let e of Bm)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 Ym(e,t,n,r=Gm()){let{locks:i,BroadcastChannel:a}=r;if(!i||!a){let e=Jm(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(Hm(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,Um+o()*Wm))},b=e=>{p=e,s=`leader`,clearTimeout(h),u=Jm(r,t,n,_)},x=(a=!1)=>{let o=++f;m?.abort();let h=new AbortController;m=h;let g=!1;i.request(Vm(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=Jm(r,t,n))})},S=()=>{c||l||s!==`follower`||(x(!0),n.resync())};g.onmessage=e=>{s===`follower`&&!l&&Km(e.data)&&(y(),qm(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 Xm(){let[e,t]=H(null),[n,r]=H([]),[i,a]=H(null),[o,s]=H(!1),[c,l]=H({}),u=G(void 0),d=G(0),f=G(0),p=G(!1),m=G(void 0),h=G(750),g=async()=>{let e=++d.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<f.current)return;f.current=e;let c=!1;if(i.ok){let e=i.data;t(e);let r=(t,n)=>!!e.project.videos.find(e=>e.id===t)?.versions.find(e=>e.id===n)?.proxy;l(t=>gn(t,e.proxies?.jobs??[],n,r)),a(null),s(!1)}else i.error instanceof Gr&&i.error.code===`wrong_project`?(s(!0),c=!0):a(i.error.message);o.ok&&r(o.assets),clearTimeout(m.current),c||i.ok&&o.ok?h.current=750:(m.current=window.setTimeout(()=>void g(),h.current),h.current=Math.min(h.current*2,1e4))};return U(()=>{g();let e=Ym(Kr()??``,Qr(),{change(){clearTimeout(u.current),u.current=window.setTimeout(()=>void g(),40)},proxy(e){let t=JSON.parse(e);l(e=>hn(e,{...t,at:performance.now()}))},corrupt(e){let{file:t}=JSON.parse(e);a(`${t} has an error and wasn't loaded. Fix or restore it, and Rushes will pick it up.`)},error(){a(`Lost touch with the Rushes server. Retrying…`),!p.current&&(p.current=!0,g().finally(()=>{p.current=!1}))},open(){p.current=!1,g()},resync(){g()}});return Ut(location.search).test&&(window.__rushesLive={role:()=>e.role()}),()=>{e.close(),clearTimeout(u.current),clearTimeout(m.current)}},[]),{state:e,assets:n,problem:i,wrongProject:o,refresh:g,proxyJobs:c,noteProxyJob:e=>l(t=>hn(t,mn(e,performance.now())))}}var Zm=null;function Qm(e,t){let n=Zm,r={owner:e,stop:t};if(Zm=r,n&&n.owner!==e)try{n.stop()}catch{}return()=>{Zm===r&&(Zm=null)}}function $m(e){Zm&&Zm.owner===e&&(Zm=null)}function eh(e){return e.replace(/&/g,`&`).replace(/</g,`<`).replace(/>/g,`>`).replace(/"/g,`"`).replace(/'/g,`'`)}function th(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 nh(e){let t=/^( *)([-*]|\d+\.)[ \t]+(.*)$/.exec(e);return t?{indent:t[1].length,ordered:/\d/.test(t[2]),content:t[3]}:null}function rh(e){let t=/^>\s?(.*)$/.exec(e);return t?t[1]:null}function ih(e){let t=eh(e).split(/\r\n|\r|\n|\u2028|\u2029/),n=[],r=[],i=null,a=()=>{r.length&&(n.push(`<p>${th(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}>${th(c[2])}</h${e}>`),s++;continue}let l=rh(e);if(l!==null){a(),o();let e=[l];s++;let r;for(;s<t.length&&(r=rh(t[s]))!==null;)e.push(r),s++;n.push(`<blockquote><p>${th(e.join(` `))}</p></blockquote>`);continue}let u=nh(e);if(u&&u.indent<2){a(),(!i||i.ordered!==u.ordered)&&(o(),i={ordered:u.ordered,items:[]});let e=th(u.content);s++;let n=[],r;for(;s<t.length&&(r=nh(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>${th(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 ah(e){return!e||!((e.label??``).trim()||e.note.trim())?null:sp(e)}var oh=[`January`,`February`,`March`,`April`,`May`,`June`,`July`,`August`,`September`,`October`,`November`,`December`];function sh(e,t){let n=_p(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 ch(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?oh[r.getMonth()].slice(0,3):oh[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 lh(e,t){return ch(sh(e,t),t,!0)}function uh(e,t){return ch(sh(e,t),t,!1)}function dh(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 ph(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=lh(e.addedAt,t);return r&&n.push(r),n.join(` · `)}function mh(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=hh(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 hh(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 gh=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:--gh,__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 _h={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"/>`};function $({name:e,class:t}){return Q(`svg`,{class:`ic${t?` ${t}`:``}`,viewBox:`0 0 24 24`,"aria-hidden":`true`,dangerouslySetInnerHTML:{__html:_h[e]??``}})}var vh={script:`script`,picture:`film`,voice:`mic`,music:`music`,sfx:`zap`,mix:`sliders`,visuals:`image`},yh=typeof window<`u`&&`showSaveFilePicker`in window;function bh(){let e=navigator.userAgent;return/Mac/.test(e)?`Show in Finder`:/Windows/.test(e)?`Show in Explorer`:`Open folder`}function xh(e){return e?new Date(e).toLocaleDateString(void 0,{day:`numeric`,month:`short`,year:`numeric`}):``}function Sh({asset:e,toast:t}){let[n,r]=H(!1),i=!e.missing&&it.has(ot(e.path)),a=async()=>{if(n)return;r(!0);let i;try{let t=await window.showSaveFilePicker({suggestedName:e.name}),n=await fetch(Zr(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:`${Zr(e.path)}&download=1`,download:e.name,onClick:t=>{e.missing&&t.preventDefault()},children:Q($,{name:`download`})}),yh&&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":bh(),"aria-label":bh(),"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 Ch({tip:e=`Missing`}){return Q(`span`,{class:`amiss`,"data-tip":e,"aria-label":e,children:`●`})}function wh(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:Th(e)?null:ah(r)}}function Th(e){return e.kind===`cut`&&e.format!==void 0}function Eh({asset:e,videos:t,toast:n}){let r=e.kind===`cut`||e.kind===`delivery`?wh(e,t):null;return Q(`div`,{class:`arow${e.missing?` missing`:``}${Th(e)?` sub`:``}`,children:[Q(`div`,{class:`ainfo`,children:[Q(`div`,{class:`atitle`,children:[r?r.title:e.label??e.name,e.missing&&Q(Ch,{})]}),r?.subtitle&&Q(`div`,{class:`asub`,children:r.subtitle}),Q(`div`,{class:`afolder mono`,children:e.path}),!e.missing&&Q(`div`,{class:`ameta`,children:[nt(e.size??0),` · `,xh(e.modified)]})]}),Q(Sh,{asset:e,toast:n})]})}function Dh({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(Ch,{})]}),Q(`div`,{class:`afolder mono`,children:e.path}),!e.missing&&Q(`div`,{class:`ameta`,children:yn(e)})]}),Q(Sh,{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 Oh({asset:e,playing:t,paused:n,onToggle:r,videos:i,toast:a}){let o=t&&!n,s=e.label??e.name,c=rt(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(Ch,{})]}),c&&Q(`div`,{class:`atrackmeta`,children:c}),Q(`div`,{class:`afolder mono`,children:e.path}),!e.missing&&Q(`div`,{class:`ameta`,children:[nt(e.size??0),` · `,xh(e.modified)]})]}),Q(Sh,{asset:e,toast:a})]})}function kh({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(Ch,{})]}),e.note&&Q(`div`,{class:`asub`,children:e.note}),Q(`div`,{class:`afolder mono`,children:e.path}),!e.missing&&Q(`div`,{class:`ameta`,children:[nt(e.size??0),` · `,xh(e.modified)]})]}),Q(Sh,{asset:e,toast:i})]})}function Ah({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:Zr(e.path),alt:e.name,loading:`lazy`})}),Q(`div`,{class:`shot-meta`,children:[Q(`div`,{class:`mono`,children:[a,e.missing&&Q(Ch,{})]}),o&&Q(`div`,{class:`asub`,children:o})]}),Q(Sh,{asset:e,toast:n})]})}function jh({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?`${Zr(e.path)}#t=0.5`:void 0,"aria-label":`${e.name} poster frame`})}function Mh({asset:e,videos:t,toast:n}){let{title:r,subtitle:i}=wh(e,t),a=at.has(ot(e.path));return Q(`div`,{class:`shot-tile${e.missing?` missing`:``}${Th(e)?` sub`:``}`,children:[Q(`div`,{class:`shot-thumb poster`,children:!e.missing&&(a?Q(jh,{asset:e}):Q(`div`,{class:`file-tile`,children:Q(`span`,{class:`file-ext mono`,children:ot(e.path)||`file`})}))}),Q(`div`,{class:`shot-meta`,children:[Q(`div`,{class:`atitle`,children:[r,e.missing&&Q(Ch,{})]}),i&&Q(`div`,{class:`asub`,children:i}),Q(`div`,{class:`afolder mono`,children:e.path})]}),Q(Sh,{asset:e,toast:n})]})}function Nh(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 Ph({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=Nh(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:Zr(e.path),alt:e.name}),Q(`div`,{class:`lbactions`,children:[Q(Sh,{asset:e,toast:n}),Q(`button`,{ref:i,class:`btn ghost ib`,"aria-label":`Close`,onClick:t,children:Q($,{name:`x`})})]})]})})}var Fh=60,Ih=`Up to 12 files of each kind at a time, so the tabs stay quick. Each voiceover folder becomes its own round.`,Lh=xn.filter(e=>e!==`cut`),Rh=e=>e.slice(e.lastIndexOf(`/`)+1),zh=e=>`Couldn't be added: ${e.replace(/\.$/,``).replace(/^(\p{Lu})(?=\p{Ll})/u,e=>e.toLowerCase())}`,Bh={voice:`var(--vo)`,music:`var(--music)`,sfx:`var(--sfx)`,other:`var(--text-3)`,cut:`var(--accent)`,doc:`var(--text-3)`};function Vh({kind:e}){return Q(`i`,{class:`kdot`,style:{background:e?Bh[e]:`var(--text-3)`}})}function Hh({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 Uh({row:e,playing:t,onPlay:n}){return Q(`div`,{class:`frow in`,children:[Q(`span`,{}),e.playable?Q(Hh,{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(Vh,{kind:e.kind}),Q(`span`,{class:`klabel`,children:e.label})]}),Q(`span`,{}),Q(`span`,{})]})}var Wh=class extends T{shouldComponentUpdate(e){return zn(this.props,e)}render({item:e,kind:t,ticked:n,playing:r,failure:i,onTick:a,onKind:o,onPlay:s}){let c=Rh(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(Hh,{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:zh(i)})]}),l?Q(`span`,{class:`kind static`,children:[Q(Vh,{kind:`cut`}),Sn.cut]}):Q(`label`,{class:`kind`,children:[Q(Vh,{kind:t}),Q(`select`,{"aria-label":`Kind of ${c}`,value:t,onChange:t=>o(e.path,t.target.value),children:Lh.map(e=>Q(`option`,{value:e,children:Sn[e]}))}),Q($,{name:`chev`,class:`kchev`})]}),Q(`span`,{class:`fdur mono`,children:Fn(e.duration)}),Q(`span`,{class:`fsize mono`,children:nt(e.size)})]})}};function Gh(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 Kh({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),L=G({onPlay:r,onStop:i});L.current={onPlay:r,onStop:i};let R=Fr((e,t)=>L.current.onPlay(e,t),[]),ne=G(0),re=G(0),ie=async()=>{let e=++ne.current;try{let t=await K.get(`/api/found`);if(e<re.current)return;re.current=e,u(e=>{let n=kn(e?.files??[],t.files??[]),r=t.hidden??[];return e&&n===e.files&&JSON.stringify(e.hidden)===JSON.stringify(r)?e:{files:n,hidden:r}}),f(null)}catch(t){e>=re.current&&f(t.message)}};U(()=>{ie()},[e]);let ae=Dn(c);U(()=>s(ae),[ae]);let oe=l?.files??[],se=l?.hidden??[],ce=Pr(()=>oe.map(e=>({...e,kind:h[e.path]??e.kind,raw:e})),[oe,h]),le=Pr(()=>Nn(ce,x,y),[ce,x,y]),ue=Pr(()=>Mn(le),[le]),de=Pr(()=>Pn(ce),[ce]);U(()=>{x!==`all`&&l&&!c.scanning&&!de.some(([e])=>e===x)&&S(`all`)},[de,l,c.scanning]);let fe=Pr(()=>Rn(e.project,c.broughtIn),[e.project,c.broughtIn]),pe=Pr(()=>ue.filter(e=>!C.has(e.key)).flatMap(e=>e.files.map(e=>e.path)),[ue,C]),me=Pr(()=>new Set(pe),[pe]),z=oe.filter(e=>p.has(e.path)),he=z.length,ge=z.filter(e=>me.has(e.path)),_e=ge.length,ve=Pr(()=>new Set([...fe.map(e=>e.path),...M]),[fe,M]);U(()=>{l&&n.path&&!n.paused&&(me.has(n.path)||T&&ve.has(n.path)||L.current.onStop())},[l,n.path,n.paused,me,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=Fr((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=Fr((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=Gh(pe,t);I.current=n===null?`search`:{row:n},re.current=++ne.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||he===0)return;te.current=!0,A(!0);let e=z.slice(0,Fh);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=z.length-e.length,r=Ln(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||_e===0)return;te.current=!0,A(!0);let e=ge.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(),ie()}catch(e){a(e.message)}finally{te.current=!1,A(!1)}},Ee=async e=>{let t=se.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},se.length<=1&&O(!1),o(),ie()}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=Cn(c.counts),B=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)})]}),de.length>0&&Q(`div`,{class:`seg`,role:`group`,"aria-label":`Kind`,children:[Q(`button`,{type:`button`,"aria-pressed":x===`all`,onClick:()=>S(`all`),children:[`All `,Q(`span`,{class:`n`,children:oe.length})]}),de.map(([e,t])=>Q(`button`,{type:`button`,"aria-pressed":x===e,onClick:()=>S(e),children:[Sn[e],` `,Q(`span`,{class:`n`,children:t})]},e))]}),Q(`button`,{type:`button`,class:`btn ib`,"aria-label":`Look again`,"aria-busy":B||j,"data-tip":`Look through the project folder again`,onClick:()=>void De(),children:Q($,{name:`refresh`})}),Q(`button`,{type:`button`,class:`btn`,disabled:_e===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:he===0||k,onClick:()=>void we(),children:he>0?`Bring in ${he}`:`Bring in`})]})]}),B&&Q(`p`,{class:`fscan`,"aria-live":`polite`,children:[Q(`span`,{class:`fspin`}),`Looking through the folder…`]}),d&&!l&&Q(`p`,{class:`aempty`,children:d}),fe.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:fe.length}),Q(`span`,{class:`fdone`,children:[Q($,{name:`check`}),`in the project`]})]}),T&&fe.map(e=>Q(Uh,{row:e,playing:Oe(e.path),onPlay:R},e.path))]}),l===null?!d&&Q(`p`,{class:`aempty`,children:`Loading…`}):oe.length===0?!B&&Q(`p`,{class:`aempty`,children:`Nothing else found in this folder.`}):le.length===0?Q(`p`,{class:`aempty`,children:`Nothing matches.`}):ue.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(Wh,{item:e.raw,kind:e.kind,ticked:p.has(e.path),playing:Oe(e.path),failure:_[e.path],onTick:ye,onKind:xe,onPlay:R},e.path))]},e.key)}),D&&se.length>0&&Q(`div`,{class:`fcard fhidden`,children:[Q(`p`,{class:`fhead`,children:[Q(`b`,{children:`Hidden`}),Q(`small`,{children:se.length})]}),se.map(e=>{let t=Rh(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:An(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:Ih}),se.length>0&&Q(`button`,{type:`button`,class:`flink`,"aria-expanded":D,onClick:()=>O(e=>!e),children:[`Hidden (`,se.length,`)`]})]})]})}var qh=new Set([`voiceover`,`music`,`sfx`]),Jh=new Set([`cut`,`delivery`]),Yh=1048576;function Xh(e){return`rushes.assets.view.${e}`}function Zh(e){try{let t=localStorage.getItem(Xh(e));return t===`grid`||t===`list`?t:null}catch{return null}}function Qh(e,t){try{localStorage.setItem(Xh(e),t)}catch{}}function $h(e){return e?e.gridToggle?Zh(e.id)??e.view:`list`:`grid`}async function eg(e){let t=await fetch(Zr(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>Yh){let e=t.byteLength-(a-Yh);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,foundRequest:r,onFoundRequestUsed:i,onFoundSeen:a,toast:o,onChanged:s}){let c=Pr(()=>st.filter(t=>t.id===`export`||e.some(e=>t.kinds.includes(e.kind))),[e]),l=c.find(e=>e.id!==`export`)?.id,u=En(n.found)!==null,[d,f]=H(()=>r.pending?`found`:l??(u?`found`:c[0]?.id??`found`)),p=G(r.pending);U(()=>{if(d===`found`)return;let e=!!d&&c.some(e=>e.id===d);if(p.current&&e)return;let t=l??(e?d:c[0]?.id??`found`);t!==d&&f(t)},[c,d]);let[m,h]=H(()=>({key:0,kind:r.pending?r.kind:void 0})),g=e=>{p.current=!0,f(e)},_=G(r.pending?r.n:-1);U(()=>{r.pending&&(_.current!==r.n&&(_.current=r.n,g(`found`),h(e=>({key:e.key+1,kind:r.kind}))),i())},[r.n,r.pending]);let v=d===`found`,y=v?null:c.find(e=>e.id===d)??null,[b,x]=H(``),[S,C]=H(`newest`),[T,E]=H(null),[D,O]=H(()=>$h(y)),k=G(y?.id??null);y&&y.id!==k.current&&(k.current=y.id,x(``),E(null),C(`newest`),O($h(y)));let A=Pr(()=>y?dt(e,y,{query:b,sort:S,film:T,videos:t}):[],[e,y,b,S,T,t]),j=e=>{y&&y.gridToggle&&(O(e),Qh(y.id,e))},[ee,M]=H(null),N=G(null),P=(e,t)=>{N.current=t,M(e)},F=()=>{M(null),N.current?.focus()},te=G(null),[I,L]=H({path:null,paused:!0}),R=G({}),ne=()=>{te.current?.pause(),$m(R.current),L({path:null,paused:!0})},re=(e,t)=>{let n=te.current;if(n){if(I.path===e&&!I.paused){n.pause(),$m(R.current),L({path:e,paused:!0});return}I.path!==e&&(n.src=Zr(e)),Qm(R.current,()=>{te.current?.pause(),L(e=>({...e,paused:!0}))}),L({path:e,paused:!1}),n.play().catch(n=>{n instanceof Error&&n.name===`AbortError`||($m(R.current),L({path:e,paused:!0}),o(`Couldn't play ${t}`))})}},ie=e=>re(e.path,e.label??e.name);U(()=>ne,[d,T]),U(()=>ne,[]),U(()=>{s()},[d]),U(()=>{let e=()=>{document.visibilityState===`visible`&&s()};return document.addEventListener(`visibilitychange`,e),()=>document.removeEventListener(`visibilitychange`,e)},[]);let[ae,oe]=H(null),[se,ce]=H(null),le=!!y&&ct.has(y.id);U(()=>{if(!le){oe(null);return}ae&&A.some(e=>e.path===ae&&ut(e))||oe(A.find(ut)?.path??null)},[le,A]),U(()=>{if(!ae){ce(null);return}let e=!1;return ce({loading:!0,text:``,truncated:!1}),eg(ae).then(t=>{e||ce({loading:!1,text:t.text,truncated:t.truncated})}).catch(t=>{e||ce({loading:!1,text:``,truncated:!1,error:t.message})}),()=>{e=!0}},[ae]);let ue=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())},de=async()=>{try{await K.post(`/api/reveal`,{project:!0})}catch(e){o(e.message)}},fe=async()=>{try{let{path:e}=await K.post(`/api/exports/notes`);o(`Saved to ${e}`),s()}catch(e){o(e.message)}},pe=t=>e.filter(e=>t.kinds.includes(e.kind)).length,me=()=>y?y.id===`screenshot`&&S!==`name`?pt(A,t).map((e,n)=>Q(`section`,{class:`afilm-group`,children:[e.heading&&Q(`h3`,{class:`afilm-heading`,children:e.heading}),Q(`div`,{class:`shots-grid`,children:e.items.map(e=>Q(Ah,{asset:e,videos:t,toast:o,onOpen:t=>P(e,t)},e.path))})]},e.heading??`_${n}`)):Jh.has(y.id)?Q(`div`,{class:`shots-grid`,children:A.map(e=>Q(Mh,{asset:e,videos:t,toast:o},e.path))}):Q(`div`,{class:`shots-grid`,children:A.map(e=>Q(Ah,{asset:e,videos:t,toast:o,onOpen:t=>P(e,t)},e.path))}):null,z=()=>y?qh.has(y.id)?Q(`div`,{class:`arows`,children:A.map(e=>Q(Oh,{asset:e,playing:I.path===e.path,paused:I.paused,onToggle:ie,videos:t,toast:o},e.path))}):y.id===`proxy`?Q(`div`,{class:`arows`,children:A.map(e=>Q(Dh,{asset:e,toast:o,onChanged:s},e.path))}):le?Q(`div`,{class:`arows`,children:A.map(e=>Q(kh,{asset:e,selected:ae===e.path,onSelect:()=>oe(e.path),videos:t,toast:o},e.path))}):Q(`div`,{class:`arows`,children:A.map(e=>Q(Eh,{asset:e,videos:t,toast:o},e.path))}):null,he=ae?(ae.split(`.`).pop()??``).toLowerCase():``,ge=Pr(()=>ih(se?.text??``),[se?.text]);return Q(`div`,{class:`assets-lib`,children:[Q(`nav`,{class:`asidebar`,"aria-label":`Folders`,onKeyDown:ue,children:[Q(`button`,{type:`button`,class:`afolder-btn afound`,"aria-current":v?`true`:void 0,onClick:()=>{v||h(e=>({key:e.key+1})),g(`found`)},children:[Q(`span`,{children:`Found`}),Q(`span`,{class:`count`,children:Cn(n.found?.counts)})]}),c.map(e=>Q(`button`,{type:`button`,class:`afolder-btn`,"aria-current":e.id===d?`true`:void 0,onClick:()=>g(e.id),children:[Q(`span`,{children:e.title}),Q(`span`,{class:`count`,children:pe(e)})]},e.id)),Q(`button`,{type:`button`,class:`afolder-root`,onClick:()=>void de(),children:[Q($,{name:`folder`}),`Project folder`]})]}),v?Q(Kh,{state:n,initialKind:m.kind,playing:I,onPlay:re,onStop:ne,toast:o,onChanged:s,onSeen:a},m.key):y?Q(`div`,{class:`amain`,children:[Q(`header`,{class:`aheader`,children:[Q(`h2`,{children:[y.title,` `,Q(`span`,{class:`count`,children:A.length})]}),Q(`div`,{class:`acontrols`,children:[Q(`label`,{class:`search-wrap`,children:[Q($,{name:`search`}),Q(`input`,{class:`search`,type:`search`,"aria-label":`Search`,placeholder:`Search`,value:b,onInput:e=>x(e.target.value)})]}),y.filmFilter&&Q(`select`,{class:`sel`,"aria-label":`Film`,value:T??``,onChange:e=>E(e.target.value||null),children:[Q(`option`,{value:``,children:`All films`}),t.map(e=>Q(`option`,{value:e.id,children:e.name},e.id))]}),Q(`select`,{class:`sel`,"aria-label":`Sort`,value:S,onChange:e=>C(e.target.value),children:[Q(`option`,{value:`newest`,children:`Newest`}),Q(`option`,{value:`oldest`,children:`Oldest`}),Q(`option`,{value:`name`,children:`Name`})]}),y.gridToggle&&Q(`div`,{class:`seg`,role:`group`,"aria-label":`View`,children:[Q(`button`,{type:`button`,"aria-pressed":D===`grid`,"aria-label":`Grid view`,"data-tip":`Grid`,onClick:()=>j(`grid`),children:Q($,{name:`grid`})}),Q(`button`,{type:`button`,"aria-pressed":D===`list`,"aria-label":`List view`,"data-tip":`List`,onClick:()=>j(`list`),children:Q($,{name:`list`})})]}),y.id===`export`&&Q(`button`,{type:`button`,class:`btn`,onClick:()=>void fe(),children:[Q($,{name:`script`}),`Export notes`]})]})]}),Q(`div`,{class:`abody${le?` split`:``}`,children:[Q(`div`,{class:`alist`,children:A.length===0?Q(`p`,{class:`aempty`,children:`Nothing here yet.`}):D===`grid`?me():z()}),le&&Q(`aside`,{class:`apreview`,children:!ae||!se?Q(`p`,{class:`aempty`,children:`Select a file to preview it here.`}):se.loading?Q(`p`,{class:`aempty`,children:`Loading…`}):se.error?Q(`p`,{class:`aempty`,children:se.error}):Q(w,{children:[he===`md`?Q(`div`,{class:`markdown`,dangerouslySetInnerHTML:{__html:ge}}):Q(`pre`,{class:`plain`,children:se.text}),se.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:te,onEnded:()=>{$m(R.current),L(e=>({...e,paused:!0}))}}),ee&&Q(Ph,{asset:ee,toast:o,onClose:F})]})}var ng=class extends Error{};function rg(e,t,n){let r=G(t.hash),i=G(t);i.current=t;let a=G(Promise.resolve()),o=G(null),s=G(0);U(()=>{r.current=t.hash},[t.hash]),U(()=>(n.settle.current=async()=>(await a.current.catch(()=>void 0),(await K.get(`/api/state`))[e]),()=>{n.settle.current=null}),[]);let c=async(t,n)=>{let a=i.current;for(let i=0;;i++){let o=t(a,n||i>0);if(!o)throw Error(`that part is no longer in ${e}.md`);if(`refuse`in o)throw new ng(o.refuse);try{let t=await K.put(o.path,{...o.body,hash:r.current});r.current=t[e].hash;return}catch(t){if(t instanceof Gr&&t.code===`${e}_changed`&&i===0){a=(await K.get(`/api/state`))[e],r.current=a.hash;continue}throw t}}},l=(t,r,i=!1)=>{let l=++s.current;o.current=null,a.current=a.current.catch(()=>void 0).then(()=>c(r,i)).catch(a=>{!i&&l===s.current&&a instanceof Gr&&a.code===`${e}_changed`&&(o.current={what:t,build:r}),n.toast(`Couldn't save ${t}: ${a.message}`)}).finally(n.onChanged)};return U(()=>{let e=o.current;e&&(o.current=null,l(e.what,e.build,!0))},[t.hash]),{latest:i,enqueue:l}}function ig(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 ag=`plan-page`,og=e=>`ptab-${e}`;function sg({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:og(e.page),"aria-controls":ag,"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 cg(e){e.style.height=`auto`,e.style.height=`${e.scrollHeight+2}px`}function lg({value:e,label:t,onInput:n,onBlur:r}){let i=G(null);return W(()=>{i.current&&cg(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,cg(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 ug({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 dg({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 fg=(e,t,n)=>`${e} of ${t} ${n}${t===1?``:`s`} approved`,pg=500;function mg({section:e,save:t}){let[n,r]=H(e.yours),i=G(!1);U(()=>{i.current||r(e.yours)},[e.yours]);let a=ig(()=>{i.current=!1,n.trim()!==e.yours.trim()&&t.section(e,n)},pg),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(lg,{label:`Your version of ${e.heading}`,value:n,onInput:e=>{i.current=!0,r(e),a.schedule()},onBlur:()=>a.flush()}),o&&Q(ug,{baseline:[{text:e.current}],revertLabel:`Revert ${e.heading}`,onRevert:()=>{i.current=!1,r(e.current),t.section(e,e.current)}})]})]})}var hg=(e,t)=>e.slice(0,t).filter(n=>n.heading===e[t].heading).length;function gg({brief:e,toast:t,onChanged:n,settle:r}){let{latest:i,enqueue:a}=rg(`brief`,e,{toast:t,onChanged:n,settle:r}),o={section:(e,t)=>{let n=hg(i.current.sections,e.index);a(e.heading,r=>{let i=r.sections.filter(t=>t.heading===e.heading)[n];return i?{path:`/api/brief/sections/${i.index}`,body:{heading:e.heading,text:t}}:null})},status:t=>{let n=e.sections.map(e=>`${e.heading}\n${e.yours}`).join(`
|
|
58
58
|
|
|
59
59
|
`);a(`the brief's status`,(e,r)=>r&&t===`approved`&&e.sections.map(e=>`${e.heading}\n${e.yours}`).join(`
|
|
60
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}})}},s=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:o},`${t.heading}#${ig(e.sections,t.index)}`))}),Q(eg,{counts:e.sections.length>0?{approved:s?`Brief approved`:`Brief not approved yet`,edited:e.changed}:null,children:Q(`button`,{class:`btn bapprove${s?` approved`:``}`,"aria-pressed":s,onClick:()=>o.status(s?`draft`:`approved`),children:[Q($,{name:`check`}),s?`Approved`:`Approve brief`]})})]})}var og=150;function sg({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),og)};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:Kn(e.length)},onKeyDown:e=>S(e),children:e.map(e=>{let n=Gn(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":Wn(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(cg,{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 cg({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 lg=[`ArrowLeft`,`ArrowRight`,`ArrowUp`,`ArrowDown`,`Home`,`End`];function ug({label:e,width:t,height:n,value:r,onChange:i,lockedReason:a,name:o}){let s=Gn(t,n),c=Lr();return Q(`div`,{class:`fscope`,role:`radiogroup`,"aria-label":o,onKeyDown:e=>{if(e.altKey||e.metaKey||e.ctrlKey||!lg.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})]})}function dg({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 fg({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 pg=e=>e.status===`done`?`Reopen`:Om(im(e),`Mark done`),mg=[{kind:`rise`,label:`Rise`},{kind:`fall`,label:`Fall`},{kind:`louder`,label:`Louder`},{kind:`quieter`,label:`Quieter`}];function hg({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}){let[S,C]=H(`all`),w=x??S,T=G(null),E=i??T,[D,O]=H(``),[k,A]=H(!1),j=e.filter(e=>e.status===`todo`).length,ee=v?.(w)??null,M=e.map(e=>({n:e,at:p?{t:e.t,tOut:e.tOut,from:null}:De(e,t)})).filter(({n:e})=>w===`all`||e.status===w).sort((e,t)=>(e.at.t??-1)-(t.at.t??-1)),N=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()},P=async()=>{let e=D.trim();if(e&&!k){A(!0);try{await o(e),O(``),l?.(!1)}catch(e){a(`Couldn't add the note: ${e.message}`)}finally{A(!1)}}};return Q(`div`,{class:`panel side notes`,role:`region`,"aria-label":`Notes`,children:[x===void 0&&Q(`div`,{class:`ph`,children:Q(fg,{filter:w,onChange:C,todo:j})}),Q(`div`,{class:`list`,children:[M.length===0&&Q(`div`,{class:`none`,children:w===`all`?ee?`None on this format.`:`No notes yet.`:`Nothing here.`}),M.map(({n:e,at:t})=>Q(`div`,{class:`note${im(e)===`todo`?``:` ${im(e)}`}`,"data-note":e.id,"aria-current":m===e.id?`true`:void 0,children:[Q(`button`,{class:`chk`,"aria-label":pg(e),"data-tip":pg(e),onClick:()=>void N(e),children:Q($,{name:`check`})}),Q(`div`,{class:`nt`,children:[Q(`button`,{class:`t`,onClick:()=>t.t!==null&&s?.(t.t,e),children:Oe(t.t,t.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})})(),t.from&&Q(`span`,{class:`from`,children:[`from `,t.from]})]}),St(e.marks)&&Q(`div`,{class:`nmarks`,children:St(e.marks)}),e.shot&&Q(`div`,{class:`shotref`,children:[`Shot `,et(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:Zr(e.grab),alt:`Frame grab`})}),e.reply&&Q(`div`,{class:`rp`,children:[Q($,{name:`reply`}),Q(`span`,{children:e.reply})]}),m===e.id&&g&&Q(`div`,{class:`nfmt`,children:g(e)})]},e.id)),ee]}),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:mg.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(Ct(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(wt(d.value,e,Number(n.value))),n.blur()},children:_t.map(e=>Q(`option`,{value:String(e),children:[e,` dB`]}))}),Q($,{name:`chev`})]})]})})}),_&&Q(`div`,{class:`row`,children:Q(ug,{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:E,class:`input`,rows:2,"aria-label":`New note`,placeholder:n,value:D,onInput:e=>{let t=e.target.value;O(t),l?.(t.trim()!==``)},onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),P()),e.key===`Escape`&&(D.trim()===``&&u?.onClear?.(),e.target.blur())}}),Q(`button`,{class:`btn primary ib sm send`,"data-tip":`Add note ↵`,"aria-label":`Add note`,onClick:()=>void P(),children:Q($,{name:`send`})})]}),_&&Q(`p`,{class:`fhint`,children:_.hint})]}),y&&b&&Q(`p`,{class:`ninstead`,children:b})]})}var gg=[[`all`,`All`],[`picture`,fp.picture],[`voice`,fp.voice],[`music`,fp.music],[`sfx`,`Effects`],[`mix`,fp.mix],[`visuals`,fp.visuals],[`notes`,fp.notes],[`assets`,fp.assets]];function _g(e){return gg.some(([t])=>t===e)}var vg={user:`added by you`,agent:`agent`,rushes:`Rushes`};function yg(e,t){let n=[];for(let r of e){let e=new Date(r.at),i=yp(e),a=n[n.length-1];a&&a.date===i?a.entries.push(r):n.push({key:i,date:i,heading:bp(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 bg(e,t){return e===`all`||e===t}var xg=new Set([` `,`ArrowLeft`,`ArrowRight`,`ArrowUp`,`ArrowDown`,`Home`,`End`,`PageUp`,`PageDown`]);function Sg(e){return xg.has(e.key)&&!e.altKey&&!e.ctrlKey&&!e.metaKey}var Cg=[`script`,`picture`,`voice`,`music`,`sfx`,`mix`];function wg(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&&Cg.includes(e.tab)?{tab:e.tab}:e.area===`assets`?{tab:`assets`}:Cg.includes(e.area)?{tab:e.area}:null}function Tg(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 Eg(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 Dg(e,t){let n=e.by===`user`?`added by you`:e.by===`agent`?`by the agent`:`by Rushes`;return`${e.text} (${fp[e.area]}, ${t}, ${n})`}function Og(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 kg(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 Ag(e,t){return`rushes:${e}:${t}`}function jg(e,t){try{return e?.getItem(t)??null}catch{return null}}function Mg(e,t,n){try{e?.setItem(t,n)}catch{}}var Ng=1e3,Pg=40,Fg=new Map,Ig=e=>`${e?.rev??``}:${e?.mark??``}`,Lg=()=>{try{return window.sessionStorage}catch{return}};function Rg({entry:e,to:t,onGo:n}){let r=vp(new Date(e.at)),i=Q(w,{children:[Q(`span`,{class:`ltime`,children:r}),Q(`span`,{class:`ltag ${e.area}`,children:fp[e.area]}),Q(`span`,{class:`ltext`,dir:`auto`,children:[e.text,Q(`span`,{class:`lby`,children:vg[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":Dg(e,r),onClick:()=>n(t),children:i}):Q(`div`,{class:`lrow`,"data-entry":e.id,children:i})}function zg({log:e,projectId:t,head:n,project:r,stage:i,toast:a,onJump:o,onEscape:s}){let[c,l]=H(()=>{let e=jg(Lg(),Ag(t,`log-filter`));return _g(e)?e:`all`}),u=e=>`${t}\n${e}`,[d,f]=H(()=>Fg.get(u(c))?.view??null),[p,m]=H(null),[h,g]=H(null),_=G(n);_.current=n;let[v,y]=H(``),b=G(null),x=G(null),S=G(null);S.current=d;let C=G(c);C.current=c;let w=G(0),T=()=>(b.current?.scrollTop??0)>Pg,E=t=>{f(t),m(null),C.current===`all`&&t.entries[0]&&e.saw(`${t.entries[0].id}@${t.entries[0].at}`)},D=async(e=!1)=>{let t=++w.current,n=new URLSearchParams({limit:String(Ng)}),r=C.current,i=Ig(_.current);r!==`all`&&n.set(`area`,r);try{let a=await K.get(`/api/log?${n}`);if(Fg.set(u(r),{head:i,view:a}),t!==w.current)return;g(null),!e&&S.current&&T()?m(a):E(a)}catch(e){if(t!==w.current)return;S.current?a(Og(`read`,e)):g(Og(`read`,e))}},O=G(!1);U(()=>{let e=!O.current;O.current=!0;let t=Fg.get(u(c));if(e&&t&&t.head===Ig(n)){E(t.view);return}b.current&&(b.current.scrollTop=0),m(null),D(!0)},[c]);let k=G(!0);U(()=>{if(k.current){k.current=!1;return}D()},[n?.rev,n?.mark]),W(()=>{e.focusOnOpen&&(x.current?.focus(),e.focused())},[]);let A=async()=>{let e=v.trim();if(e)try{if(await K.post(`/api/log`,{text:e,area:i}),y(``),!bg(c,i)){let e=fp[i];a(`Added under ${e}. Choose All${gg.some(([e])=>e===i)?` or ${e}`:``} to see it.`)}b.current&&(b.current.scrollTop=0),await D(!0)}catch(e){a(Og(`add`,e))}},j=e=>{l(e),Mg(Lg(),Ag(t,`log-filter`),e)},ee=()=>{p&&(E(p),b.current&&(b.current.scrollTop=0),requestAnimationFrame(()=>{let e=b.current?.querySelector(`.lrow`);(e instanceof HTMLButtonElement?e:b.current)?.focus({preventScroll:!0})}))},M=()=>{p&&!T()&&E(p)},N=G(o);N.current=o;let P=G(e=>N.current(e)).current,F=async()=>{try{a(`Saved to ${(await K.post(`/api/exports/change-log`,{})).path}`)}catch(e){a(Og(`export`,e))}},te=Pr(()=>d?yg(d.entries,new Date).map(e=>Q(`div`,{class:`dgroup`,children:[Q(`h3`,{class:`dday`,children:e.heading}),Q(`ul`,{children:e.entries.map(e=>Q(`li`,{children:Q(Rg,{entry:e,to:wg(e,r),onGo:P})},e.id))})]},e.key)):null,[d,r,yp(new Date)]),I=d&&p?Tg(d.entries,p.entries):0,L=d!==null&&d.total===0&&d.undated.length===0,R=d!==null&&!L&&d.entries.length===0&&d.undated.length===0;return Q(`div`,{id:`changelog`,class:`activity`,onKeyDown:e=>{if(e.key===`Escape`&&!e.defaultPrevented){e.preventDefault(),e.stopPropagation(),s();return}Sg(e)&&e.stopPropagation()},children:[Q(`form`,{class:`dadd`,onSubmit:e=>{e.preventDefault(),A()},children:[Q(`input`,{ref:x,value:v,maxLength:160,placeholder:`Add a line to the log`,"aria-label":`Add a line to the log`,onInput:e=>y(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:c,onChange:e=>{let t=e.target.value;_g(t)&&j(t)},children:gg.map(([e,t])=>Q(`option`,{value:e,children:t},e))}),Q($,{name:`chev`})]})}),Q(`div`,{class:`dwrap`,children:[I>0&&Q(`button`,{type:`button`,class:`dpill`,onClick:ee,children:[I,` new`]}),Q(`div`,{class:`dlist`,ref:b,tabIndex:0,role:`group`,"aria-label":`Entries`,onScroll:M,children:[d===null&&!h&&Q(`p`,{class:`dempty`,children:`Loading…`}),d===null&&h&&Q(`p`,{class:`dempty dproblem`,role:`alert`,children:h}),L&&Q(`p`,{class:`dempty`,children:`Nothing yet. Rushes writes a line here whenever a cut, a take or a variant is added.`}),R&&Q(`p`,{class:`dempty`,children:`Nothing for this filter.`}),te,d&&d.undated.length>0&&Q(`section`,{class:`dbefore`,"aria-label":`Before the log`,children:[Q(`h3`,{children:`Before the log`}),Q(`ul`,{children:d.undated.map((e,t)=>Q(`li`,{children:e.text},t))})]})]})]}),Q(`div`,{class:`dfoot`,children:[Q(`span`,{children:d?Eg(d):``}),Q(`button`,{type:`button`,class:`btn`,onClick:()=>void F(),children:`Export as Markdown`})]})]})}var Bg=ce(null);function Vg(e){let t=Ir(Bg);return()=>{t&&(!t.shown||t.log.open)?t.revealNotes(()=>e.current?.focus()):e.current?.focus()}}var Hg=`[role="dialog"], [role="menu"], [role="listbox"], .fmtpop.open`;function Ug(e){return e.key!==`Escape`||e.defaultPrevented||document.querySelector(Hg)!==null?!1:!(e.target instanceof Element?e.target:null)?.closest(`.npanel`)}var Wg=`rushes:notes-width`,Gg=`rushes:notes-hidden`;function Kg(e){try{return localStorage.getItem(e)}catch{return null}}function qg(e,t){try{t===null?localStorage.removeItem(e):localStorage.setItem(e,t)}catch{}}var Jg=()=>typeof matchMedia==`function`?matchMedia(`(max-width: 1099px)`):null;function Yg(){let[e,t]=H(()=>{let e=Number(Kg(Wg));return Kg(Wg)!==null&&Number.isFinite(e)?Math.min(560,Math.max(240,e)):300}),[n,r]=H(()=>Kg(Gg)===`1`),[i,a]=H(!1),[o,s]=H(()=>Jg()?.matches??!1);U(()=>{let e=Jg();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),qg(Gg,e?null:`1`))};return{width:e,setWidth:(e,n)=>{t(e),n&&qg(Wg,e===300?null:String(e))},narrow:o,shown:c,setShown:l,toggle:()=>l(!c)}}var Xg=`Hide the notes panel · \\`;function Zg({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 Qg(e){let t=Ir(Bg),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(hg,{...e});let{log:l,activity:u,send:d,shown:f,narrow:p}=t,m=l.open?`activity`:`notes`,h=e.notes.filter(e=>e.status===`todo`).length,g=(e,t=!0)=>{e===`activity`!==l.open&&l.setOpen(e===`activity`,t)},_=e=>{if(e.key!==`ArrowLeft`&&e.key!==`ArrowRight`)return;e.preventDefault(),e.stopPropagation();let t=m===`notes`?`activity`:`notes`;g(t,!1),(t===`notes`?n:r).current?.focus()},v=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=>v(e.clientX),onPointerUp:e=>{let n=v(e.clientX);o.current=null,n!==null&&t.setWidth(n,!0)},onDblClick:()=>t.setWidth(300,!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":m===`notes`,"aria-controls":`npanel-notes`,tabIndex:m===`notes`?0:-1,onClick:()=>g(`notes`),onKeyDown:_,children:[`Notes`,h>0&&Q(`span`,{class:`n`,children:h})]}),Q(`button`,{ref:r,type:`button`,role:`tab`,id:`ntab-activity`,class:`ntab`,"aria-selected":m===`activity`,"aria-controls":`npanel-activity`,"aria-label":l.dot?`Activity (new entries)`:`Activity`,tabIndex:m===`activity`?0:-1,onClick:()=>g(`activity`),onKeyDown:_,children:[`Activity`,l.dot&&Q(`span`,{class:`cdot`,"aria-hidden":`true`})]})]}),Q(`span`,{class:`sp`}),m===`notes`&&Q(dg,{filter:s,onChange:c}),p&&Q(`button`,{type:`button`,class:`ibtn`,"aria-label":Xg,"data-tip":Xg,onClick:()=>t.setShown(!1),children:Q($,{name:`x`})})]}),Q(`div`,{class:`ntabpanel`,role:`tabpanel`,id:`npanel-notes`,"aria-labelledby":`ntab-notes`,hidden:m!==`notes`,children:Q(hg,{...e,filter:s})}),m===`activity`&&Q(`div`,{class:`ntabpanel`,role:`tabpanel`,id:`npanel-activity`,"aria-label":`Activity`,children:Q(zg,{...u,log:l,onEscape:()=>r.current?.focus()})}),(d.count>0||d.always)&&Q(`div`,{class:`nfoot`,children:Q(`button`,{ref:i,type:`button`,class:`btn primary sendbtn`,"aria-label":d.count>0?`Send ${d.count}`:`Send`,"data-tip":`Notes and edits not sent yet, from every tab and film`,onClick:d.onSend,children:[`Send`,d.count>0&&Q(`span`,{class:`count`,children:d.count})]})})]})}function $g(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 e_({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=tr(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 t_=6e3,n_=e=>/[.!?]$/.test(e)?e:`${e}.`;function r_({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),_=_n({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),t_);return()=>clearTimeout(e)},[v]),!n)return null;let y=v&&h===v?`none`:_,b=vn(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 Gr&&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.`}),` `,n_(b)]}),Q(`button`,{class:`btn primary tip-wrap tip-end`,"aria-label":`Create proxy`,"data-tip":fn(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}),` (`,nt(t.proxy.bytes),`).`]}),Q(`button`,{class:`btn ghost ib`,"aria-label":`Dismiss`,"data-tip":`Dismiss`,onClick:()=>g(v),children:Q($,{name:`x`})})]})]})})}function i_({shots:e,duration:t,t:n,current:r,cutLabel:i,locked:a,onSeek:o}){let s=e=>km(e,t),c=e.length>0?e.map((n,i)=>({key:String(n.n),start:n.start,end:e[i+1]?.start??t,label:`${et(n.n)} ${n.name}`,tag:n.tag,current:r===n.n})):[{key:`cut`,start:0,end:t,label:i,tag:``,current:!0}];return Q(`div`,{class:`trow ptrack`,role:`group`,"aria-label":`Picture track`,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:[c.map(e=>Q(`button`,{type:`button`,class:`pblock`,"aria-current":e.current?`true`:void 0,"data-tip":e.tag?`${e.label} · ${e.tag}`:e.label,style:{left:`${s(e.start)}%`,width:`${Math.max(0,s(e.end)-s(e.start))}%`},onClick:t=>{t.detail>0&&t.currentTarget.blur(),o(e.start)},children:Q(`span`,{class:`plbl`,children:e.label})},e.key)),Q(`span`,{class:`playhead`,style:{left:`${s(n)}%`}})]})]})}var a_=[.5,1,2,5,10,15,30,60,120,300,600],o_=e=>`${Math.floor(e/60)}:${String(Math.floor(e%60)).padStart(2,`0`)}${e%1?`.${String(Math.round(e%1*10))}`:``}`;function s_({duration:e,t,marks:n,live:r,onSeek:i,onMark:a}){let o=t=>km(t,e),s=a_.find(t=>e/t<=8)??a_[a_.length-1],c=[];if(e>0)for(let t=0;t<e-1e-6;t+=s/2)c.push(t);let l=t=>{let n=t.currentTarget.getBoundingClientRect();return n.width?(t.clientX-n.left)/n.width*e:0};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(l(e)))},onPointerMove:e=>{e.currentTarget.hasPointerCapture(e.pointerId)&&i(l(e))},children:[c.map((e,t)=>Q(`span`,{class:`rtick${t%2?``:` major`}`,style:{left:`${o(e)}%`},children:t%2?null:Q(`span`,{class:`rlbl`,children:o_(e)})},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}%`}}),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":Om(e.status,e.title),"aria-label":Om(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:`${o(t)}%`}})]})}function c_(e){return e.rev?`${e.path}#${e.rev}`:e.path}function l_(e){return e.modified?e.modified:e.size===null?void 0:String(e.size)}var u_=.05,d_=6e4;function f_(e){return 10**(e/20)}function p_(e){let t=e.some(e=>e.solo),n={};for(let r of e){let e=t?+!!r.solo:+!r.muted;n[r.id]=f_(r.level??0)*e}return n}function m_(e,t){return+(e===t)}function h_(e,t){let n={};for(let r of e){let e=t[r.lane];n[r.id]=e===void 0?1:m_(e,r.id)}return n}function g_(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 __(e,t,n){return Math.abs(e-t)>1/n+1e-9}function v_(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 y_(e,t){let n=new Float32Array(Math.max(0,Math.floor(t)));for(let r of e){let e=v_(r,t);for(let t=0;t<n.length;t++)e[t]>n[t]&&(n[t]=e[t])}return n}function b_(e){return Math.min(d_,Math.max(1,Math.round(e*50)))}function x_(e,t){return!t||e!==null&&e>S_}var S_=900;function C_(e){S_=e??900}function w_(e){return e!==null&&e>3456e5}function T_(e,t,n,r=1/0,i=u_){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 E_(e,t,n,r){return n&&!r?`play`:!n&&r?`pause`:Math.abs(e-t)>.050000001?`seek`:null}function D_(e,t){return e.map(e=>e.duration>0?e:{...e,duration:t[c_(e)]??0})}function O_(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 k_(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 A_(e){return e.name.trim()||`Untitled cue`}function j_(e){return`${A_(e)} at ${Ce(e.t)}`}function M_(e,t){return`cue ${e} of ${t}`}function N_(e){let t=new Map;for(let n of k_(e)){let e=A_(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 P_(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 F_(e){return e.split(/[\\/]/).filter(Boolean).pop()??e}function I_(e,t){return`${((t>0?Math.min(1,Math.max(0,e/t)):0)*100).toFixed(3)}%`}function L_(e,t){return`clamp(5px, ${I_(e,t)}, calc(100% - 5px))`}function R_(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 z_(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 B_=`cue-card`;function V_(){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 H_(e,t){return{onPointerEnter:n=>e.show(n.currentTarget,t),onPointerLeave:()=>e.hide()}}function U_({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=z_({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:B_,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),` · `,M_(a.n,a.of)]}),a.file!==null&&Q(`span`,{class:`f`,style:{color:a.color},children:a.file})]})}var W_=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,Um(this,()=>this.stop()),this.set({path:e,playing:!0});try{await n.play()}catch(t){if(this.current.path===e&&this.current.playing)throw Wm(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(),Wm(this),this.current.playing&&this.set({...this.current,playing:!1})}element(){if(!this.el){let e=this.make();e.addEventListener(`ended`,()=>{Wm(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,Zr);function G_(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=P_(e.key,i.indexOf(r),i.length);a!==null&&(e.preventDefault(),e.stopPropagation(),i[a].focus())}function K_(){let[e,t]=H(W_.state());return U(()=>W_.subscribe(t),[]),e}function q_({id:e,name:t,cues:n,length:r,color:i,card:a,onSeek:o,toast:s}){let c=k_(n),l=new Map(c.map((e,t)=>[e,t+1])),u=N_(n),[d,f]=H({}),p=K_();U(()=>()=>W_.stopIf(e),[e]);let m=async t=>{try{await W_.toggle(t,e)}catch{s(`Couldn't play ${F_(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:L_(s.t,r)},"aria-label":j_(s),"aria-describedby":p?B_:void 0,...H_(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=>G_(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:F_(s)})]}),t.moreFiles>0&&Q(`small`,{children:[`+`,t.moreFiles]})]})]},t.name)})})}var J_=0;function Y_(){return J_}var X_=3,Z_=2;function Q_({segments:e,length:t,color:n}){let r=G(null),[i,a]=H({w:0,h:0,dpr:1});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);return n.observe(e),()=>n.disconnect()},[]);let[o,s]=H(0);U(()=>{let e=()=>s(e=>e+1);return window.addEventListener(cr,e),()=>window.removeEventListener(cr,e)},[]);let c=[i,t,n,o];for(let t of e)c.push(t.offset,t.duration,t.peaks);return U(()=>{let a=r.current;if(!a||i.w<=0||i.h<=0)return;J_++,a.width=Math.round(i.w*i.dpr),a.height=Math.round(i.h*i.dpr);let o=a.getContext(`2d`);if(!o||(o.setTransform(i.dpr,0,0,i.dpr,0,0),o.clearRect(0,0,i.w,i.h),!(t>0)))return;o.fillStyle=vr(a,n);let s=Math.floor(i.w/X_),c=t*X_/i.w;for(let t=0;t<s;t++){let n=t*c,r=n+c,a=-1;for(let t of e){if(!(t.duration>0)||r<=t.offset||n>=t.offset+t.duration)continue;if(!t.peaks||t.peaks.length===0){a=Math.max(a,.04);continue}let e=t.peaks.length,i=Math.max(0,Math.floor((n-t.offset)/t.duration*e)),o=Math.min(e,Math.max(i+1,Math.ceil((r-t.offset)/t.duration*e)));for(let e=i;e<o;e++)a=Math.max(a,t.peaks[e])}if(a<0)continue;let s=Math.max(1.5,Math.min(1,a)*i.h*.92);o.globalAlpha=.9,o.fillRect(t*X_,(i.h-s)/2,Z_,s)}},c),Q(`canvas`,{ref:r,class:`wave`,"aria-hidden":`true`})}var $_=2e3,ev=8e3,tv={kind:`none`},nv={kind:`pending`},rv={kind:`none`,silent:!0};async function iv(e,t,n){let r;try{r=await t.fetch(e.peaksUrl,{signal:n})}catch(e){if(n.aborted)throw e;return nv}if(r.status===202)return nv;if(r.status===501)return av(e,t,n);if(r.status===204)return rv;if(r.status!==200)return tv;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))?tv:{kind:`wave`,wave:{peaks:Float32Array.from(t),duration:e.duration}}}catch(e){if(n.aborted)throw e;return tv}}async function av(e,t,n){if(e.size===null||!(e.size<1e8))return tv;try{let r=await e.duration();if(n.aborted)throw new DOMException(`aborted`,`AbortError`);if(r===null||!(r>0)||r>900)return tv;let i=await t.fetch(e.mediaUrl,{signal:n});if(!i.ok)return tv;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)?tv:{kind:`wave`,wave:{peaks:ov(y_(a,Math.min($_,s))),duration:o}}}catch(e){if(n.aborted)throw e;return tv}}function ov(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 sv=40,cv=new Map,lv=new Set;function uv(e,t,n,r){return`${e}/${t}/${n}#${r??``}`}function dv(e){return cv.has(e)}function fv(e){return cv.get(e)??null}function pv(e){return lv.has(e)}function mv(e,t,n=!1){for(cv.delete(e),cv.set(e,t),n&&t===null?lv.add(e):lv.delete(e);cv.size>sv;){let e=cv.keys().next().value;cv.delete(e),lv.delete(e)}}function hv(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 gv=1500,_v=15e3,vv=15e3,yv={fetch(e,t){let n=Kr();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,ev).decodeAudioData(e),n=[];for(let e=0;e<t.numberOfChannels;e++)n.push(t.getChannelData(e));return{channels:n,duration:t.duration}}};function bv(e,t,n,r,i){let a=e&&t?uv(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),vv)}),[l,u]=H(()=>a&&dv(a)?{key:a,wave:fv(a),silent:pv(a)}:null),d=G(null);return U(()=>{if(!e||!t)return;if(dv(a)){u({key:a,wave:fv(a),silent:pv(a)});return}let r=new AbortController,i,o=gv,s={peaksUrl:`/api/videos/${encodeURIComponent(e)}/versions/${encodeURIComponent(t.id)}/peaks`,mediaUrl:Zr(t.file),size:n,duration:c},l=async()=>{d.current=null,clearTimeout(i);let e;try{e=await iv(s,yv,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,_v);return}let t=e.kind===`wave`?e.wave:null,n=e.kind===`none`&&e.silent===!0;mv(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 xv=0;typeof location<`u`&&Ut(location.search).test&&(window.__rushesPicture={waveDraws:()=>xv});var Sv=3,Cv=2;function wv({wave:e,length:t}){let n=G(null),[r,i]=H({w:0,h:0,dpr:1});return U(()=>{let e=n.current;if(!e)return;let t=()=>{let t=e.getBoundingClientRect(),n=window.devicePixelRatio||1;i(e=>e.w===t.width&&e.h===t.height&&e.dpr===n?e:{w:t.width,h:t.height,dpr:n})};t();let r=new ResizeObserver(t);r.observe(e);let a=hv(window,t);return()=>{r.disconnect(),a()}},[]),U(()=>{let i=n.current;if(!i||r.w<=0||r.h<=0)return;xv++,i.width=Math.round(r.w*r.dpr),i.height=Math.round(r.h*r.dpr);let a=i.getContext(`2d`);if(!a)return;a.setTransform(r.dpr,0,0,r.dpr,0,0),a.clearRect(0,0,r.w,r.h);let o=t>0?t:e.duration,s=e.peaks.length;if(!(o>0)||!(e.duration>0)||s===0)return;a.fillStyle=getComputedStyle(i).color;let c=e.duration/s;for(let t=0;t<r.w;t+=Sv){let n=t/r.w*o;if(n>=e.duration)break;let i=(t+Sv)/r.w*o,l=Math.min(s-1,Math.floor(n/c)),u=Math.min(s,Math.max(l+1,Math.ceil(i/c))),d=0;for(let t=l;t<u;t++)e.peaks[t]>d&&(d=e.peaks[t]);let f=Math.max(1,Math.min(1,d)*r.h);a.fillRect(t,(r.h-f)/2,Cv,f)}},[r,e,t]),Q(`canvas`,{ref:n,class:`pwave`,"aria-hidden":`true`})}var Tv=.03,Ev=.004,Dv=15e3;function Ov(e){return e.buffer?e.buffer.length*e.buffer.numberOfChannels*4:0}var kv=0;function Av(){return kv}var jv=new Map;function Mv(e){let t=jv.get(e);return t&&(jv.delete(e),jv.set(e,t)),t}function Nv(e,t){for(jv.delete(e),jv.set(e,t);jv.size>200;)jv.delete(jv.keys().next().value)}function Pv(){let e=Error(`The load was cancelled`);return e.name=`AbortError`,e}function Fv(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),Dv)})}var Iv=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??Zr,fetch:t.fetch??((e,t)=>fetch(e,t)),probe:t.probe??Fv(n),createMedia:n,raf:t.raf??(e=>requestAnimationFrame(e)),caf:t.caf??(e=>cancelAnimationFrame(e))},e&&(this.ctx=e,kv++)}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 O_(this.videoDuration,this.resolved())}inspect(){return{playing:this._playing,time:this.time,length:this.length,sources:this.voices.size,gains:h_(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=c_({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)c_(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=>(x_(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(w_(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 Pv();let d;if(u&&!x_(u.duration,!0)){let e=Mv(t);if(!e){let n=[];for(let e=0;e<u.numberOfChannels;e++)n.push(u.getChannelData(e));e=y_(n,b_(u.duration)),Nv(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 Pv();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)c_(t)===e&&this.holding.delete(t.id);if(this._playing){for(let t of this.resolved())c_(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(c_)),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+=Ov(e.media);for(;this.idle.size>12||o>268435456;){let[e,t]=this.idle.entries().next().value;o-=Ov(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=h_(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(()=>{}),Um(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(),Wm(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(),Wm(this),this.tickListeners.clear(),this.endedListeners.clear(),this.changeListeners.clear(),this.disposed=!0,this.ctx&&(this.ctx.close().catch(()=>{}),this.ctx=null,kv--)}}ensureContext(){if(this.disposed)throw Error(`The audio engine was disposed`);return this.ctx||(this.ctx=this.opts.createContext(),kv++),this.ctx}resolved(){let e={};for(let[t,n]of this.media)e[t]=n.duration;let t=D_(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+Tv;let n=this.resolved(),r=new Map(n.map(e=>[e.id,e]));for(let t of g_(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+Tv),r=this.startOffset+(n-this.startedAt);for(let t of g_([e],r))this.startVoice(e,n+t.when,t.offset)}startVoice(e,t,n){let r=this.media.get(c_(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(c_(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=T_(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=h_([e],this.selection)[e.id],r.connect(this.laneNode(e.lane)),t={gain:r,seekedAt:-1/0},this.media.get(c_(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+Ev)}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(c_(e))&&!this.media.has(c_(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)Lv(()=>e(t));if(t>=e){this.pause();for(let e of this.endedListeners)Lv(e);return}this._playing&&this.frame===null&&(this.frame=this.opts.raf(this.tick))};emitChange(){for(let e of this.changeListeners)Lv(e)}};function Lv(e){try{e()}catch(e){console.error(e)}}var Rv=e=>e.map(e=>[e.id,e.lane,e.path,e.rev??``,e.offset,e.duration].join(`\0`)).join(``);function zv(e,t=null){let n=G(null);n.current||=new Iv;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=>[c_(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,Rv(e)]),U(()=>{r.setVideoDuration(t)},[r,t]),{engine:r,playing:a,length:s,media:l}}var Bv=[`play`,`playing`,`pause`,`seeking`,`seeked`,`waiting`,`canplay`,`ratechange`,`timeupdate`,`ended`,`loadedmetadata`,`durationchange`,`emptied`],Vv=3;function Hv(e,t,n){let{engine:r,length:i,media:a}=zv(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>=Vv,a=e.currentTime,s=E_(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 Bv)e.addEventListener(n,t);return t(),()=>{for(let n of Bv)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 Uv=`rushes:preview`,Wv=.12,Gv=.75;function Kv(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 qv(e,t,n){let r=G(n);r.current=n,W(()=>e?.attach(t,()=>r.current()),[e,t])}var Jv=`rushes:volume`,Yv=`rushes:split`,Xv=.55,Zv=.08;function Qv(){try{let e=JSON.parse(localStorage.getItem(Jv)??`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 $v=()=>Kv(Yv,Zv,Xv);function ey(e,t){try{t===null?localStorage.removeItem(e):localStorage.setItem(e,t)}catch{}}function ty(){let[e,t]=H(Qv);return U(()=>ey(Jv,JSON.stringify(e)),[e]),[e,t]}function ny(){let[e,t]=H($v);return{split:e,set:t,keep:e=>{t(e),ey(Yv,e===null?null:String(Math.round(e*1e3)/1e3))}}}function ry(){let[e,t]=H(()=>Kv(Uv,Wv,Gv));return{size:e,set:t,keep:e=>{t(e),ey(Uv,e===null?null:String(Math.round(e*1e3)/1e3))}}}function iy({column:e,preview:t,size:n}){let r=G(null),i=()=>{let t=e.current?.getBoundingClientRect().height??0;return t>0?Math.max(Wv,Math.min(Gv,(t-448)/t)):Gv},a=e=>Math.min(i(),Math.max(Wv,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:Wv};return Q(`div`,{class:`pvsplit`,role:`separator`,"aria-orientation":`horizontal`,"aria-label":`Resize the preview`,"aria-valuemin":Math.round(Wv*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 ay(e,t=`tlpanel`){return{class:`${t}${e===null?``:` sized`}`,style:e===null?void 0:{height:`${e*100}%`}}}function oy({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(Xv,Math.max(Zv,(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(Zv*100),"aria-valuemax":Math.round(Xv*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:Zv);t.keep(Math.min(Xv,Math.max(Zv,a+(n.key===`ArrowUp`?.03:-.03))))}})}function sy({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 cy={current:null},ly=e=>e instanceof HTMLElement&&(e.isContentEditable||/^(INPUT|TEXTAREA|SELECT)$/.test(e.tagName));function uy({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);qv(l,n?.id??``,()=>Te(m.current?.time??0,p));let h=Ly({state:e,assets:t,video:n,version:null,player:cy,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=$g(h,e.notes.notes,n),E=Vg(S),D=e=>wm({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(!(ly(e.target)||e.metaKey||e.ctrlKey||e.altKey)){if(e.key===` `){if(Ht(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(dy,{prompt:i,toast:o,then:`Until then the takes in use play here together.`})}),Q(sy,{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(By,{loudness:h.loudness}):null}),Q(`div`,{class:`tlpanel`,children:[Q(`div`,{class:`trow rrow`,children:[Q(`div`,{class:`thead`}),Q(s_,{duration:_,t:v,marks:[],live:null,onSeek:e=>g.seek(e),onMark:()=>void 0})]}),Q(zy,{mix:h,duration:_,t:v,onSeek:e=>g.seek(e),notes:[...r,...T]})]})]}),Q(Qg,{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 dy({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 ${bn(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:[Ie.picture.unlocks,` `,n]}),Q(`button`,{type:`button`,class:`btn sm`,onClick:()=>void r(),children:[Q($,{name:`copy`}),`Copy prompt for your agent`]})]})}function fy(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])}function py({name:e,control:t}){let[n,r]=H(!1),i=G(null),a=G(null),o=G(null);fy(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=s.length===0?`No film`:s.length===1?`1 film`:`${s.length} films`,d=e=>t.onChange(s.includes(e)?s.filter(t=>t!==e):c.filter(t=>t.id===e||s.includes(t.id)).map(e=>e.id));return Q(`span`,{class:`fmwrap films`,ref:i,onClick:e=>e.stopPropagation(),children:[Q(`button`,{ref:a,type:`button`,class:`btn ghost sm filmsbtn${s.length===0?` none`:``}`,"data-tip":l.length?`On ${l.join(`, `)}`:`On no film`,"aria-label":`Films for ${e}: ${l.length?l.join(`, `):`none`}`,"aria-haspopup":`true`,"aria-expanded":n,disabled:t.readOnly,onClick:()=>r(!n),children:[Q($,{name:`film`}),u]}),n&&Q(`div`,{class:`fmenu filmsmenu`,role:`group`,"aria-label":`Films for ${e}`,children:[Q(`div`,{class:`fmtitle`,children:[`Films it is on`,Q(`b`,{dir:`auto`,children:e})]}),c.map((e,t)=>Q(`label`,{class:`fmitem`,children:[Q(`input`,{ref:t===0?o:void 0,type:`checkbox`,checked:s.includes(e.id),onChange:()=>d(e.id)}),Q(`span`,{dir:`auto`,children:e.name}),e.here?Q(`kbd`,{children:`this film`}):e.shelved?Q(`kbd`,{children:`shelved`}):null]},e.id))]})]})}function my(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 hy(e){let t={},n=e=>e!==null&&e.scrollWidth>e.clientWidth;for(let r of e.querySelectorAll(`.take[data-take]`))n(r.querySelector(`[data-name]`))&&(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}var gy=(e,t)=>Object.keys(e).length===Object.keys(t).length&&Object.keys(e).every(n=>e[n]===t[n]);function _y(e){let{label:t,color:n,sections:r,away:i,loose:a,none:o,length:s,media:c,selected:l,marks:u,range:d,layers:f,onSelect:p,onPick:m,onUnpick:h,onPutAway:g,toast:_}=e,v=e=>km(e,s),y=G(null),[b,x]=H({}),S=()=>{if(!y.current)return;let e=hy(y.current);x(t=>gy(t,e)?t:e)},C=[...r.flatMap(e=>e.items),...i.open?i.items:[]],T=e=>{let t=e.clip?c[c_(e.clip)]:void 0;return(t!==void 0&&t!==`error`?`${t.duration}${t.streamed?`s`:``}`:``)+(t===`error`?`b`:``)};W(S,[JSON.stringify([s,r.map(e=>e.heading),C.map(e=>[e.key,e.name,e.details.length>0,e.missing,T(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(S);return y.current&&e.observe(y.current),document.fonts?.ready.then(S),()=>e.disconnect()},[]);let{shown:E,api:D}=V_(),[O,k]=H({}),[A,j]=H(new Set),ee=e=>j(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),M=r.flatMap(e=>e.items),N=M.find(e=>e.take.inUse)?.key??M[0]?.key??null,P=e=>{if(![`ArrowUp`,`ArrowDown`,`ArrowLeft`,`ArrowRight`,`Home`,`End`].includes(e.key)||e.metaKey||e.ctrlKey||e.altKey)return;e.preventDefault(),e.stopPropagation();let t=[...y.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()},F=e=>Q(`h3`,{class:`khd tip-wrap`,"data-h":e,"data-tip":b[`h:${e}`]?e:void 0,children:e}),te=(e,t)=>{let r=e.take,i=e.key===l,a=b[e.key]??``,o=e.clip?c[c_(e.clip)]:void 0,y=o!==void 0&&o!==`error`?o:null,x=o===`error`,S=!!y?.streamed,C=y?Math.min(s||y.duration,y.duration):s,T=k_(e.cues),E=R_(T),j=At(T,s),M=Math.min(O[e.key]??0,Math.max(0,T.length-1)),F=(t,r)=>({key:`m:${e.key}:${E[r]}`,name:A_(t),t:t.t,n:r+1,of:T.length,file:t.file??null,color:n}),te=u[e.key]??[],I=!!f?.open(e.key),L=e=>{let t=e.currentTarget.getBoundingClientRect();return t.width>0?Math.min(s,Math.max(0,(e.clientX-t.left)/t.width*s)):0},R=r.inUse?`In use`:`Use this one`,ne=e.missing?`File not found`:x?`This file won't play in a browser`:null,re=e.details.join(` · `),ie=re!==``&&A.has(e.key),ae=`kd-${e.key}`,oe=[a.includes(`n`)?e.name:null,re||null].filter(Boolean).join(`
|
|
62
|
-
`);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:[f&&Q(`button`,{type:`button`,class:`chev tip-start`,"aria-expanded":I,"aria-controls":I&&T.length>0?`cl-${e.key}`:void 0,"aria-label":`Layers for ${e.name}`,"aria-description":T.length===0?`No cues in this pass`:void 0,"data-tip":T.length===0?`No cues in this pass`:I?`Hide the layers`:`Show the layers`,disabled:T.length===0,onClick:()=>f.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":`${R}: ${e.name}`,"data-tip":R,tabIndex:e.key===N?0:-1,onKeyDown:P,onClick:t=>{t.stopPropagation(),r.inUse||m(e)}}),Q(`button`,{type:`button`,class:`knm`,"data-player":!0,"aria-label":e.name,"aria-pressed":i,"aria-description":[e.missing?`Missing`:null,re||null].filter(Boolean).join(`. `)||void 0,"data-tip":oe||void 0,onClick:()=>p(e,null),children:[Q(`span`,{"data-name":!0,children:e.name}),e.missing&&Q(fh,{})]}),S&&Q(`span`,{class:`smk`,"data-tip":`Long file: switching isn't sample-exact`,children:Q($,{name:`stream`})}),re!==``&&Q(`button`,{type:`button`,class:`kinfo`,"aria-label":`Details for ${e.name}`,"aria-expanded":ie,"aria-controls":ie?ae:void 0,"data-tip":ie?`Hide the details`:`Details`,onClick:()=>ee(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(`span`,{class:`sp`}),e.films&&Q(py,{name:e.name,control:e.films}),Q(`span`,{class:`kslot`,children:t===null?Q(`button`,{type:`button`,class:`btn ghost sm kput`,onClick:()=>h(e),children:`Unpick`}):Q(`button`,{type:`button`,class:`btn ghost sm kput`,onClick:()=>g(e,t===`away`),children:t===`away`?`Put away`:`Bring back`})})]}),Q(`div`,{class:`tlane`,onClick:t=>p(e,L(t)),children:[Q(`div`,{class:`sblock${r.stale?` stale`:``}${ne?` none gone`:``}`,style:{left:`0%`,width:`${ne?100:v(C)}%`},children:ne&&Q(`span`,{class:`slbl`,children:ne})}),e.clip&&Q(Q_,{segments:[{offset:0,duration:y?.duration??0,peaks:y?y.peaks:null}],length:s,color:n}),T.map((t,r)=>Q(`i`,{class:`cue-tick${D.shown===`m:${e.key}:${E[r]}`?` hot`:``}`,"aria-hidden":`true`,style:{left:`${v(t.t)}%`,color:n},...H_(D,F(t,r)),onClick:n=>{n.stopPropagation(),p(e,t.t,t.id)}},`t${E[r]}:${t.t}:${t.name}`)),T.map((t,r)=>{let i=F(t,r),a=D.shown===i.key;return Q(`button`,{type:`button`,class:`cue${a?` hot`:``}`,"data-cue":t.id,tabIndex:r===M?0:-1,"aria-label":j_(t),"aria-describedby":a?B_:void 0,style:{left:`${v(t.t)}%`,color:n,maxWidth:`calc(${(j[r]*100).toFixed(3)}% - 8px)`},...H_(D,i),onFocus:t=>{k(t=>t[e.key]===r?t:{...t,[e.key]:r}),D.show(t.currentTarget,i)},onBlur:()=>D.hide(),onKeyDown:e=>G_(e,`button.cue`,D),onClick:n=>{n.stopPropagation(),p(e,t.t,t.id)},children:Q(`span`,{children:A_(t)})},`c${E[r]}:${t.t}:${t.name}`)}),te.map(e=>e.tOut!==null&&Q(`span`,{class:`span ${e.status}`,"data-note":e.id,title:Om(e.status,e.text),style:{left:`${v(e.t)}%`,width:`${v(e.tOut)-v(e.t)}%`}},`s${e.id}`)),te.map(e=>Q(`span`,{class:`mk ${e.status}`,"data-note":e.id,title:Om(e.status,e.text),style:{left:`${v(e.t)}%`}},e.id)),d.in!==null&&Q(`span`,{class:`span live`,style:{left:`${v(d.in)}%`,width:`${v(d.out??d.in+Math.max(.2,s/200))-v(d.in)}%`}}),Q(`span`,{class:`playhead`})]})]}),ie&&Q(`p`,{class:`kdetail`,id:ae,"data-details-of":e.key,children:re}),I&&T.length>0&&Q(q_,{id:`cl-${e.key}`,name:e.name,cues:T,length:s,color:n,card:D,onSeek:(t,n)=>p(e,t,n),toast:_})]},e.key)},I=r.length===0&&i.items.length===0,L=a.items.length,R=a.items.filter(e=>e.none).length;return Q(`div`,{class:`takes`,ref:y,role:`radiogroup`,"aria-label":t,style:{"--c":n},children:[I&&Q(`p`,{class:`knone`,children:o}),r.map((e,t)=>Q(w,{children:[F(e.heading),e.items.map(e=>te(e,e.take.inUse?null:`away`))]},`${e.kind}:${t}`)),i.items.length>0&&Q(w,{children:[Q(`div`,{class:`kfold`,"data-fold":`away`,children:[F(`Put away · ${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=>te(e,`back`))]}),L>0&&Q(w,{children:[Q(`div`,{class:`kfold`,"data-fold":`loose`,children:[F(`Not on this film · ${L} ${a.what}${R?` · ${R} 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":b[`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(py,{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&&b[`l:${e.key}`]?.includes(`m`)?e.meta:void 0,children:Q(`span`,{"data-meta-text":!0,children:e.meta??``})})})})]},e.key))]}),Q(U_,{shown:E,onHide:D.hide})]})}var vy=[{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 yy({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:vy.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 by=typeof location>`u`?{test:!1,streamOver:!1}:Ut(location.search);by.streamOver&&C_(1);var xy=by.test?{engine:null,inspect(){return this.engine?this.engine.inspect():null},renders:0,panelRenders:0,draws:Y_,liveContexts:Av,sample:()=>W_.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;xy&&(window.__rushesAudio=xy);var Sy=xy;function Cy(e){let{stage:t,groups:n,assets:r,blind:i}=e,a=e=>i?Lt(e.map(gm),i.seed).map(t=>e.find(e=>gm(e)===t)):e,o=ym(n,a),s=a(n.away),c=new Map,l=0;for(let e of[...o.flatMap(e=>e.takes),...s])c.set(gm(e),i?`${i.word} ${++l}`:e.variant.name);let u=n=>{let a=gm(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?[]:Et(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?l_(o):void 0},cues:t===`sfx`?n.variant.cues:[],films:e.films(n)}},d=_m(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?gm(d):null}}var wy=e=>({lane:e.lane,variant:e.variant.id,films:rr(e.variant)}),Ty=e=>e instanceof HTMLElement&&(e.isContentEditable||/^(INPUT|TEXTAREA|SELECT)$/.test(e.tagName)),Ey={in:null,out:null},Dy={voice:`var(--vo)`,music:`var(--music)`,sfx:`var(--sfx)`},Oy=new Set,ky=new Set;function Ay({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 jy({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 My(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,readOnly:m=!1}=e;xy&&xy.renders++;let[,h]=H(0),g=e=>{e.has(t)?e.delete(t):e.add(t),h(e=>e+1)},_=Oy.has(t),v=[...r.sections.flatMap(e=>e.items),..._?r.away:[]],y=v.flatMap(e=>e.clip?[e.clip]:[]),[b,x]=H(null),[S,C]=H(16/9),T=i?.version.file;U(()=>{x(null),C(16/9)},[T]);let E=i?i.version.duration??b:null,D=G(null);qv(e.clock,e.film??``,()=>Te(D.current?.time??0,a));let{engine:O,playing:k,length:A,media:j}=zv(y,E);D.current=O,W(()=>{let t=e.clock?.at(e.film??``)??0;t>0&&O.seek(t)},[]);let[ee,M]=H(null),[N,P]=H(null),F=ee?v.find(e=>e.key===ee.key)??null:null;W(()=>{ee!==null&&F===null&&(M(null),P(null))},[F===null]);let te=F?.key??r.defaultKey??``;W(()=>O.selectVariant(t,te),[O,te]);let[I,L]=ty();W(()=>O.setLaneGain(t,I.muted?0:I.level),[O,I.muted,I.level]);let[R,ne]=H(Ey),[re,ie]=H([]),[ae,oe]=H(!1),[se,ce]=H(!1),le=G(null),ue=Vg(le),de=G(null),fe=ry(),pe=G(null);U(()=>{let e=e=>ce(!!le.current&&e.target===le.current),t=e=>{e.target===le.current&&ce(!1)};return document.addEventListener(`focusin`,e),document.addEventListener(`focusout`,t),()=>{document.removeEventListener(`focusin`,e),document.removeEventListener(`focusout`,t)}},[]);let me=G(e.film);W(()=>{me.current!==e.film&&(me.current=e.film,M(null),P(null),O.pause(),O.seek(e.clock?.at(e.film??``)??0))},[e.film]);let z=!m&>({range:R,marks:re,hasText:ae});W(()=>{p?.(z)},[z]),U(()=>()=>p?.(!1),[]);let he=F??v.find(e=>e.key===r.defaultKey)??null,ge=F&&ee?.cue&&F.cues.some(e=>e.id===ee.cue)?ee.cue:null,_e=R.in!==null&&R.out!==null?{t:R.in,tOut:R.out}:null,ve=e=>N===null?ge!==null||!!(F&&ee?.clicked)||Te(e,a)>0:!N,ye=e=>{if(!he){let r=_e?Oe(_e.t,_e.tOut):Sm(Te(e,a),a);return{stage:t,on:null,scope:_e?`range`:`point`,t:_e?.t??Te(e,a),tOut:_e?.tOut??null,label:`${r} · ${n}`,when:r,name:n}}let r=_e!==null||ve(e),i=r?ge:null,o=i?`${he.key}:${i}`:he.key,s=l(he,i);if(_e)return wm({kind:`take`,stage:t,on:o,name:s,t:_e.t,tOut:_e.tOut},null,a);let c=r?i?he.cues.find(e=>e.id===i).t:Te(e,a):null;return wm({kind:`take`,stage:t,on:o,name:s,t:c},null,a)},be=t=>{if(R.in!==null&&R.out===null)return`Set an Out point`;let n=ye(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))}`},xe=()=>{M(null),P(null)},Se=G(null),De=G([]),ke=G(null),B=G(!1),Ae=G(0),je=e=>{let t=O.length,n=`${t>0?Math.min(e,t)/t*100:0}%`;for(let e of De.current)e.style.left=n;let r=ke.current;r&&r.readyState>=1&&!r.seeking&&__(r.currentTime,e,a)&&(r.currentTime=Math.min(e,Number.isFinite(r.duration)?r.duration:e)),r&&O.playing&&!B.current&&e>Ae.current&&(B.current=!0,r.play().catch(()=>void 0)),Ae.current=e},Me=G(je);Me.current=je,W(()=>{De.current=Se.current?[...Se.current.querySelectorAll(`.playhead`)]:[],je(O.time)}),U(()=>O.subscribe(e=>Me.current(e)),[O]),U(()=>{let e=ke.current;e&&(B.current=!1,k||(e.pause(),Me.current(O.time)))},[k,T]);let Ne=()=>O.playing?O.pause():O.play(),Pe=e=>{O.pause(),O.seek(Ee(O.time,a,e,O.length))},Fe=e=>O.seek(e),Ie=()=>{m||ne({in:Te(O.time,a),out:null})},Le=()=>{if(m)return;let e=Te(O.time,a),t=R.in??0;if(e<=t)return d(`Out has to come after In`);ne({in:t,out:e})},V=()=>{ne(Ey),ie([])},Re=R.in!==null&&R.out===null,ze=se?`note`:Re?`range`:`select`,Be=()=>{xe(),Re&&V(),le.current&&document.activeElement===le.current&&le.current.blur()},Ve=()=>{let e=de.current;e&&(document.fullscreenElement?document.exitFullscreen().catch(()=>void 0):e.requestFullscreen?.().catch(()=>d(`Couldn't go full screen`)))},He=(e,n,r)=>{M({key:e.key,cue:r??null,clicked:n!==null}),P(null),O.selectVariant(t,e.key),n!==null&&O.seek(n)},Ue=async(t,n)=>{try{await Jr(e.film??void 0,t.take.lane,n)}catch(e){d(`Couldn't ${n===null?`clear`:`set`} the pick: ${e.message}`)}f()},We=async(e,t)=>{try{await Yr(e.take.lane,e.take.variant.id,t)}catch(e){d(`Couldn't ${t?`put it away`:`bring it back`}: ${e.message}`)}f()},Ge=G(()=>void 0);Ge.current=e=>{if(Ty(e.target)||e.metaKey||e.ctrlKey||e.altKey)return;let t=e.key.toLowerCase();if(e.key===` `){if(Ht(e.target))return;e.preventDefault(),Ne()}else e.key===`ArrowLeft`?(e.preventDefault(),Pe(e.shiftKey?-10:-1)):e.key===`ArrowRight`?(e.preventDefault(),Pe(e.shiftKey?10:1)):t===`v`?Be():Ug(e)?xe():t===`f`&&i?(e.preventDefault(),e.repeat||Ve()):t===`i`?Ie():t===`o`?Le():t===`n`&&!m&&(e.preventDefault(),ue())},W(()=>{let e=e=>Ge.current(e);return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[]),W(()=>{xy&&(xy.clips=y)}),U(()=>{if(xy)return xy.engine=O,()=>{xy.engine===O&&(xy.engine=null)}},[O]);let Ke=async n=>{if(R.in!==null&&R.out===null)throw Error(`set an Out point for the range`);let r=ye(O.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`?re:[]}),ne(Ey),ie([]),f()},qe={},Je=[];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;(qe[t]??=[]).push({id:e.id,t:e.t,tOut:n,status:im(e),text:e.text}),Je.push({...e,tOut:n})}let Ye=new Map(Je.map(e=>[e.id,e.text])),Xe=Am(Je,A).map(e=>({...e,ring:!1,title:Ye.get(e.id)??``})),Ze=e=>km(e,A),Qe=R.in===null?null:{left:Ze(R.in),width:Ze(R.out??R.in+.2)-Ze(R.in)},nt=R.in===null?null:R.out===null?`${Ce(R.in)} →`:Oe(R.in,R.out),rt=i?i.version.shots.filter(e=>!A||e.start<A):[],it=[{value:`point`,label:ge?`This cue`:`This moment`},{value:`whole`,label:e.wholeLabel}],at=Q(`div`,{class:`monitor spreview${i?``:` noslot`}`,ref:de,style:i?{"--ar":String(S)}:void 0,children:i?Q(w,{children:[Q(`div`,{class:`framebox`,children:Q(`div`,{class:`fitbox`,children:Q(`div`,{class:`frame`,style:{aspectRatio:String(S),"--ar":String(S)},children:[Q(`video`,{ref:ke,src:Zr(i.version.file),muted:!0,playsInline:!0,preload:`auto`,"aria-label":`Picture preview`,onLoadedMetadata:e=>{let t=e.target;Number.isFinite(t.duration)&&x(t.duration),t.videoWidth&&t.videoHeight&&C(t.videoWidth/t.videoHeight),Me.current(O.time)},onSeeked:()=>Me.current(O.time),onClick:Ne}),Q(Ay,{engine:O,children:e=>{let t=$e(rt,Te(e,a));return Q(`div`,{class:`tcover`,children:[`f`,we(e,a),t&&` · shot ${et(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(),Ve()},children:Q($,{name:`expand`})})]}):Q(dy,{prompt:e.prompt,toast:d,then:`Until then the takes play here on their own.`})});return Q(`div`,{class:`split deskcols soundcols${i&&fe.size!==null?` pvsized`:``}`,style:i&&fe.size!==null?{"--pv":String(fe.size),"--ar":String(S)}:void 0,children:[Q(`div`,{class:`tl soundtab`,children:[Q(Ay,{engine:O,children:e=>Q(sy,{t:e,duration:A,playing:k,onToggle:Ne,onStep:Pe,rangeLabel:nt,onClearRange:V,volume:I.level,muted:I.muted,onVolume:e=>L({level:e,muted:e===0&&I.muted}),onMute:()=>L({...I,muted:!I.muted})})}),Q(`div`,{class:`kbody`,children:[Q(yy,{active:ze,readOnly:m,grabbing:!1,tools:[`select`,`note`,`range`],onSelect:Be,onNote:ue,onRange:()=>Re?Le():Ie(),onBox:()=>void 0,onGrab:()=>void 0}),Q(`div`,{class:`tlpanel takespanel`,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(Ay,{engine:O,children:e=>Q(s_,{duration:A,t:e,marks:Xe,live:Qe,onSeek:Fe,onMark:e=>{let t=Je.find(t=>t.id===e);t?.t!=null&&(O.pause(),Fe(t.t))}})})]}),i&&Q(Ay,{engine:O,children:e=>Q(i_,{shots:rt,duration:A,t:e,current:$e(rt,Te(e,a))?.n??null,cutLabel:sp(i.version)||i.version.id,locked:i.locked,onSeek:e=>{O.pause(),Fe(tt(e,a))}})})]}),Q(`div`,{ref:Se,children:Q(_y,{label:`${n} takes`,color:Dy[t],sections:r.sections,away:{items:r.away,open:_,dot:o.some(e=>e.status===`todo`&&r.away.some(t=>t.key===s(e))),onToggle:()=>g(Oy)},loose:{...e.loose,open:ky.has(t),onToggle:()=>g(ky)},none:e.none,length:A,media:j,selected:F?.key??null,marks:qe,range:R,layers:e.layers,onSelect:He,onPick:e=>void Ue(e,e.take.variant.id),onUnpick:e=>void Ue(e,null),onPutAway:(e,t)=>void We(e,t),toast:d})})]})]})]}),Q(`div`,{class:`soundside`,ref:pe,children:[at,i&&Q(iy,{column:pe,preview:de,size:fe}),Q(jy,{engine:O,by:e=>`${ye(e).label}\n${be(e)}`,children:e=>{let t=ye(e);return xy&&xy.panelRenders++,Q(Qg,{notes:o,version:i?.version.id??null,placeholder:be(e),inputRef:le,toast:d,onAdd:Ke,onChanged:f,onTextChange:oe,fixedTimes:!0,onSeek:e=>O.seek(e),target:{label:t.label,when:t.when,name:t.name,menu:he&&!_e?{value:t.scope===`whole`?`whole`:`point`,options:it,onChange:e=>P(e===`whole`)}:void 0,onClear:F||N!==null?xe:void 0},marks:!u||t.scope!==`range`?void 0:{value:re,onChange:ie},onLabel:c,readOnly:m})}})]})]})}var Ny={vo:`Voice`,music:`Music`,sfx:`Effects`},Py={vo:{muted:!1,solo:!1},music:{muted:!1,solo:!1},sfx:{muted:!1,solo:!1}},Fy=e=>`${e.lane}/${e.variant.id}`;function Iy(e,t,n){let r=e=>t.find(t=>t.path===e),i=nr(e.picks,n?.id).use,a=ir(e.project.lanes,n?.id,e.project.videos.length);return Zt.map(e=>{let t=hm(a,Qt[e],i?.[Qt[e]],n??void 0),o=t.inUse;if(!o)return{lane:e,groups:t,take:o,clip:null,block:bm(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?l_(c):void 0},block:`take`}})}function Ly({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=Pr(()=>nr(e.picks,d),[e.picks,d]),p=f.use,m=Pr(()=>ir(e.project.lanes,d,e.project.videos.length),[e.project.lanes,d,e.project.videos.length]),h=Pr(()=>Iy(e,t,n),[e.picks,e.project,t,n]),g=Pr(()=>h.flatMap(e=>e.clip?[e.clip]:[]),[h]),_=h.some(e=>e.take!==null),[v,y]=H(()=>l?.current??Py);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=Zt.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}]))}})},[Zt.map(e=>x[e]?`1`:`0`).join(``)]);let[S,C]=H(null),w=S??_,T=f.levels,E=e=>T[Qt[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 Zt){if(k.current[e]!==void 0)continue;let r=E(e);n[e]!==r&&(n[e]=r,t=!0)}return t?n:e})},[Pr(()=>`${d}:${JSON.stringify(T)}`,[d,T])]);let A=e=>{let t=k.current;for(let n of Zt){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=on(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:{[Qt[e]]:n===0?null:n}},{keepalive:t}).then(c,e=>{s(e instanceof Gr?e.message:`Couldn't save the level`)});r[e]={id:window.setTimeout(()=>{delete r[e],i()},300),send:i}},ee=p_(Zt.map(e=>x[e]?{id:e,...v[e],level:D[e]}:{id:e,level:D[e]})),M=o.muted?0:o.level,{media:N,engine:P,length:F}=Hv(i,g,Object.fromEntries(Object.entries(ee).map(([e,t])=>[e,t*M]))),te=h.map(e=>e.clip&&N[c_(e.clip)]===`error`?{...e,block:`broken`}:e),I=Zt.some(e=>x[e]&&v[e].solo);W(()=>{Sy&&(Sy.clips=g)}),U(()=>{let e=Sy;if(e)return e.engine=P,()=>{e.engine===P&&(e.engine=null)}},[P]);let L=r?u(r.file):void 0,R=bv(n?.id??null,r,L?.size??null,L?l_(L):void 0,r?.duration??a),ne=r!==null&&!R.silent&&(R.known||_);W(()=>{ne||C(null)},[ne]),W(()=>C(null),[r?.id]);let re={vo:!1,music:!1,sfx:!1};for(let e of h)re[e.lane]=e.clip!==null;let ie=_?$t(re,ee):[],ae=Pr(()=>JSON.stringify({want:ie,film:d,levels:T,clips:g.map(e=>[e.path,e.rev??``])}),[ie.join(`
|
|
63
|
-
`),d,T,g]),[oe,se]=H({kind:`waiting`}),[ce,le]=H(!1),[ue,de]=H(0),fe=G(0);U(()=>{let e=++fe.current;if(ie.length===0){se({kind:`empty`}),le(!1);return}se(e=>e.kind===`empty`||e.kind===`timeout`||e.kind===`error`?{kind:`waiting`}:e),le(!0);let t=window.setTimeout(()=>{K.post(`/api/mix/loudness`,{lanes:ie,video:d}).then(t=>{e===fe.current&&se({kind:`result`,result:t})},t=>{e===fe.current&&se({kind:t instanceof Gr&&t.status===504?`timeout`:`error`})}).finally(()=>{e===fe.current&&le(!1)})},500);return()=>window.clearTimeout(t)},[ae,ue]),U(()=>()=>void++fe.current,[]);let pe=Pr(()=>({music:Dt(m,`music`),sfx:Dt(m,`sfx`)}),[m]),me=e=>pe[e].filter(t=>Kt(p,e,t)&&!u(t.file)?.missing),z={variants:pe,heard:{vo:re.vo,music:me(`music`),sfx:me(`sfx`)}},he=e=>{if(e.on===null||e.stage!==`voice`&&e.stage!==`music`&&e.stage!==`sfx`)return null;let t=e.on;return te.find(n=>n.take&&Qt[n.lane]===e.stage&&(t===Fy(n.take)||t.startsWith(`${Fy(n.take)}:`)))??null};return{rows:te,media:N,view:v,toggle:b,levels:D,setLevel:j,inUse:_,cut:{shown:ne,wave:R.wave,known:R.known},cutMuted:w,toggleCut:()=>C(!w),videoMuted:w||I,loudness:{state:oe,measuring:ce,retry:()=>de(e=>e+1)},noteLabel:e=>{if(e.stage===`mix`)return rn(z,e.on);let t=he(e);return t?`${Ny[t.lane]} · ${t.take.variant.name}`:null},noteRow:e=>{if(e.stage===`mix`){let t=tn(z,e.on);return t===null||t===`mix`?null:t}return he(e)?.lane??null},engine:P,length:F}}var Ry={vo:`var(--vo)`,music:`var(--music)`,sfx:`var(--sfx)`};function zy({mix:e,duration:t,t:n,onSeek:r,notes:i=[]}){let a=e=>km(e,t),o=e=>{let n=e.currentTarget.getBoundingClientRect();return n.width>0?Math.min(t,Math.max(0,(e.clientX-n.left)/n.width*t)):null},s=e=>{let t=o(e);t!==null&&r(t)},{shown:c,api:l}=V_(),[u,d]=H(0);return Q(w,{children:[e.rows.map(o=>{let c=Ny[o.lane],f=o.take,p=o.clip?e.media[c_(o.clip)]:void 0,m=p!==void 0&&p!==`error`?p:null,h=m?Math.min(t||m.duration,m.duration):t,g=o.block===`take`?f.variant.name:o.block===`missing`?`File not found`:o.block===`broken`?`This file won't play in a browser`:o.block===`waiting`?`Nothing chosen yet`:`Not started`,_=o.lane===`sfx`&&o.block===`take`?k_(f.variant.cues):[],v=R_(_),y=i.filter(t=>t.t!==null&&e.noteRow(t)===o.lane);return Q(`div`,{class:`trow strack${f?``:` idle`}`,role:`group`,"aria-label":`${c} track`,"data-sound":o.lane,style:{"--c":Ry[o.lane]},children:[Q(`div`,{class:`thead shead`,children:[Q(`i`,{class:`sw`,"aria-hidden":`true`}),Q(`span`,{class:`snm`,children:c}),Q(`span`,{class:`sp`}),f&&Q(w,{children:[Q(`button`,{type:`button`,class:`ms`,"aria-pressed":e.view[o.lane].muted,"aria-label":`Mute ${c}`,"data-tip":`Mute ${c}`,onClick:()=>e.toggle(o.lane,`muted`),children:`M`}),Q(`button`,{type:`button`,class:`ms`,"aria-pressed":e.view[o.lane].solo,"aria-label":`Solo ${c}`,"data-tip":`Solo ${c}`,onClick:()=>e.toggle(o.lane,`solo`),children:`S`}),Q(`label`,{class:`slvl`,"data-tip":`Level for ${c}. Double-click to reset.`,children:[Q(`input`,{type:`range`,min:-24,max:6,step:.5,value:e.levels[o.lane],"aria-label":`${c} level`,"aria-valuetext":`${sn(e.levels[o.lane])} dB`,onInput:t=>e.setLevel(o.lane,Number(t.target.value)),onDblClick:()=>e.setLevel(o.lane,0),onPointerUp:e=>e.currentTarget.blur()}),Q(`span`,{class:`db mono`,children:[sn(e.levels[o.lane]),` dB`]})]})]})]}),Q(`div`,{class:`tlane`,onClick:s,children:[o.block===`take`?Q(w,{children:[Q(`div`,{class:`sblock${f.stale?` stale`:``}`,title:f.stale?`${f.round} · ${f.variant.name} · made for an older cut`:`${f.round} · ${f.variant.name}`,style:{left:`0%`,width:`${a(h)}%`},children:Q(`span`,{class:`slbl`,children:g})}),Q(Q_,{segments:[{offset:0,duration:m?.duration??0,peaks:m?m.peaks:null}],length:t,color:Ry[o.lane]})]}):Q(`div`,{class:`sblock none${o.block===`missing`||o.block===`broken`?` gone`:``}`,style:{left:`0%`,width:`100%`},children:Q(`span`,{class:`slbl`,children:g})}),_.map((e,t)=>{let n={key:`t:${v[t]}`,name:A_(e),t:e.t,n:t+1,of:_.length,file:e.file??null,color:Ry.sfx},i=l.shown===n.key;return Q(`button`,{type:`button`,class:`cue${i?` hot`:``}`,"data-cue":e.id,tabIndex:t===Math.min(u,_.length-1)?0:-1,"aria-label":j_(e),"aria-describedby":i?B_:void 0,style:{left:`${a(e.t)}%`,color:Ry.sfx},...H_(l,n),onFocus:e=>{d(t),l.show(e.currentTarget,n)},onBlur:()=>l.hide(),onKeyDown:e=>G_(e,`button.cue`,l),onClick:t=>{t.stopPropagation(),r(e.t)},children:Q(`span`,{children:A_(e)})},`c${v[t]}:${e.t}:${e.name}`)}),y.map(e=>e.tOut===null?Q(`span`,{class:`mk ${im(e)}`,"data-note":e.id,title:Om(im(e),e.text),style:{left:`${a(e.t)}%`}},e.id):Q(`span`,{class:`span ${im(e)}`,"data-note":e.id,title:Om(im(e),e.text),style:{left:`${a(e.t)}%`,width:`${a(e.tOut)-a(e.t)}%`}},e.id)),Q(`span`,{class:`playhead`,style:{left:`${a(n)}%`}})]})]},o.lane)}),e.cut.shown&&Q(`div`,{class:`trow strack csound`,role:`group`,"aria-label":`Cut sound track`,style:{"--c":`var(--pic)`},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:s,children:[e.cut.wave?Q(w,{children:[Q(`div`,{class:`sblock cut`,style:{left:`0%`,width:`100%`}}),Q(wv,{wave:e.cut.wave,length:t})]}):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:`${a(n)}%`}})]})]}),Q(U_,{shown:c,onHide:l.hide})]})}function By({loudness:e}){let t=e.state.kind===`timeout`||e.state.kind===`error`;return Q(`div`,{class:`tloud${t?` retry`:``}`,role:`group`,"aria-label":`Loudness`,"aria-busy":e.measuring,onClick:t?e.retry:void 0,children:[un(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:Vy[e.id]??e.label})]})),e.measuring&&Q(`span`,{class:`measuring`,"data-measuring":!0,"data-tip":`Measuring`,"aria-label":`Measuring`,children:Q($,{name:`gauge`})}),t&&!e.measuring&&Q(`button`,{type:`button`,class:`btn ghost ib sm`,"data-tip":`Measure again`,"aria-label":`Measure again`,children:Q($,{name:`gauge`})})]})}var Vy={integrated:`LUFS`,truePeak:`dBTP`,musicUnderVo:`under VO`},Hy=[{value:`frame`,label:`This frame`},{value:`mix`,label:`The whole mix`}],Uy=e=>e instanceof HTMLElement&&(e.isContentEditable||/^(INPUT|TEXTAREA|SELECT)$/.test(e.tagName));function Wy({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},[]),qv(c,e.id,()=>k.current&&Ge.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,L=!I||I.primary,R=I??v.find(e=>e.primary)??null,ne=R?R.width/R.height:null,re=y!==null&&v.length>=2,ie=v.find(e=>e.primary)?.id??null,ae=Yn(r,y),oe=Xn(r,y),[se,ce]=H(`this`),[le,ue]=H(ne??16/9),[de,fe]=H(!1),[pe,me]=H(null),[z,he]=H({in:null,out:null}),[ge,_e]=H(!1),[ve,ye]=H(null),[xe,Se]=H({w:0,h:0}),[ke,B]=H(null),[Ae,je]=H(null),[Me,Ne]=H(!1),[Pe,Fe]=H(!1),[Ie,Le]=H(`frame`),V=()=>Le(`frame`),Re=Vg(M),[ze,Be]=ty(),Ve=ny(),He=G(null),Ue=G(null),We=G(!1),Ge=G(!1),Ke=G(!0);U(()=>()=>{Ke.current=!1},[]);let qe=G(t.id);U(()=>{qe.current=t.id},[t.id]),U(()=>{let e=!T&&(z.in!==null||ke!==null||Me);return o?.(e),()=>o?.(!1)},[z.in,ke,Me,T]),W(()=>(s?.(!T&&(z.in!==null||ke!==null)),()=>s?.(!1)),[z.in,ke,T]),U(()=>(ke!==null&&ce(`this`),S?.(ke!==null),()=>S?.(!1)),[ke]);let Je=G(void 0);U(()=>{me(null),P(0),ue(ne??16/9),he({in:null,out:null}),B(null),Je.current!==void 0&&d(e.id,null),Je.current=t.file,je(null),ce(`this`)},[t.file]);let Ye=ke?`this`:se,Xe=n=>be(e.versions.find(e=>e.id===n.version)??t),[Ze,Qe]=H({}),nt=e=>e.id in Ze?Ze[e.id]:e.format,rt=e=>Qe(t=>{if(!(e in t))return t;let{[e]:n,...r}=t;return r});U(()=>{Qe(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 it=async(e,t)=>{if(nt(e)!==t){Qe(n=>({...n,[e.id]:t}));try{await K.patch(`/api/notes/${e.id}`,{format:t})}catch(t){rt(e.id),at.current?.id===e.id&&(at.current=null),i(`Couldn't change that note: ${t.message}`)}a()}};U(()=>{Ae&&!ae.some(e=>e.id===Ae)&&je(null)},[y,r]);let at=G(null),ot=G(y);if(ot.current!==y){ot.current=y;let e=document.activeElement,t=e instanceof HTMLElement&&e.closest(`.nfmt`)?e.closest(`.list > .note[data-note]`):null;t&&!at.current&&(at.current={id:t.dataset.note,fallback:!0})}W(()=>{let e=at.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?(at.current=null,n&&r.focus()):e.fallback&&(at.current=null,n&&document.querySelector(`.otherrow`)?.focus())},[y,r]);let st=L&&!!t.proxy&&g!==`original`,ct=Zr(st?t.proxy.file:L?t.file:I.file),lt=pe===ct,ut=G(null),dt=G(null);if(dt.current&&dt.current.src!==ct){let e=k.current;dt.current.cut===t.file?!ut.current&&e&&(ut.current={t:e.error?N:e.currentTime,play:!e.paused&&!e.error}):ut.current=null}dt.current={cut:t.file,src:ct};let ft=G(null),pt=G(null),gt=I?.id??`primary`,_t=G(!0);W(()=>{if(_t.current){_t.current=!1;return}let e=j.current;if(!R||!e)return;let t=R.width/R.height;if(t===le)return;let n=e.getBoundingClientRect();ft.current={width:n.width,height:n.height},ue(t)},[gt]),W(()=>{let e=ft.current,t=j.current;if(ft.current=null,!e||!t)return;pt.current?.cancel(),pt.current=null;let n=t.getBoundingClientRect(),r=typeof matchMedia==`function`&&matchMedia(`(prefers-reduced-motion: reduce)`).matches,i=Jn(e,{width:n.width,height:n.height},r);Ut(location.search).test&&(window.__rushesLastReshape={animated:i!==null,ms:i?160:0}),i&&(pt.current=t.animate(i,{duration:160,easing:`ease-out`}))},[le]),U(()=>{let e=k.current;if(!e)return;let t=()=>me(ct);return e.error&&t(),e.addEventListener(`error`,t),()=>e.removeEventListener(`error`,t)},[ct]);let vt=G(null);vt.current=!L&&F>0?F:null;let yt=e=>{let t=vt.current;t===null||e.paused||e.currentTime<t||(e.pause(),e.currentTime=t)};U(()=>{if(!de)return;let e=0,t=()=>{k.current&&(yt(k.current),P(k.current.currentTime)),e=requestAnimationFrame(t)};return e=requestAnimationFrame(t),()=>cancelAnimationFrame(e)},[de]);let bt=()=>ut.current?.t??k.current?.currentTime??N,xt=()=>Te(bt(),n),St=e=>{let t=k.current;if(!t)return;let n=Math.min(Math.max(0,e),F||t.duration||e);if(ut.current){ut.current.t=n,P(n);return}t.currentTime=n,P(t.currentTime)},Ct=()=>{let e=k.current;e&&(e.paused?(vt.current!==null&&e.currentTime>=vt.current-.001&&(e.currentTime=0),e.play().catch(()=>i(`Couldn't play this file`))):e.pause())},wt=e=>{k.current?.pause(),St(Ee(bt(),n,e,F))},Tt=()=>he({in:xt(),out:null}),Et=()=>{let e=xt(),t=z.in??0;if(e<=t)return i(`Out has to come after In`);he({in:t,out:e})},Dt=()=>he({in:null,out:null}),Ot=z.in!==null&&z.out===null,kt=Pe?`note`:ge?`box`:Ot?`range`:`select`,At=()=>{_e(!1),V(),Ot&&Dt(),M.current&&document.activeElement===M.current&&M.current.blur()},jt=()=>Ot?Et():Tt();U(()=>{let e=e=>Fe(!!M.current&&e.target===M.current),t=e=>{e.target===M.current&&Fe(!1)};return document.addEventListener(`focusin`,e),document.addEventListener(`focusout`,t),()=>{document.removeEventListener(`focusin`,e),document.removeEventListener(`focusout`,t)}},[]);let Mt=()=>{let e=He.current;e&&(document.fullscreenElement?document.exitFullscreen().catch(()=>void 0):e.requestFullscreen?.().catch(()=>i(`Couldn't go full screen`)))},Nt=Ly({state:D,assets:O,video:e,version:t,player:k,duration:F,monitor:ze,toast:i,onChanged:a,keep:l}),Pt=$g(Nt,D.notes.notes,e);U(()=>{let e=k.current;e&&(e.volume=ze.level,e.muted=ze.muted||Nt.videoMuted)},[ze,Nt.videoMuted]);let Ft=G(0),[It,Lt]=H(0),Rt=async()=>{let r=k.current,o=xt(),s=e.id,c=t.id,l=L?null:y,u=++Ft.current,f=!1;try{let e=we(o,n),t;if(p){f=!0,Lt(e=>e+1);let n=await Xr(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!==Ft.current){a();return}i(`Saved to ${m.grab}`),a(),Ke.current&&c===qe.current&&d(s,m.grab)}catch(e){u===Ft.current&&i(e.message)}finally{f&&Ke.current&&Lt(e=>e-1)}},zt=e=>{let t=z.in!==null&&z.out!==null?{t:z.in,tOut:z.out}:null;return Ie===`mix`?t?{kind:`mix`,...t}:{kind:`mix`}:t?{kind:`range`,...t}:{kind:`frame`,t:e}},Bt=e=>{let t=zt(e);return wm(t,$e($t,t.kind===`frame`||t.kind===`range`?t.t:e),n)},Vt=async r=>{let i=Bt(xt());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}),Dt(),Le(`frame`),ce(`this`),B(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,...re?{format:Ye===`this`?y:null}:{}}),Dt(),ce(`this`),B(null),d(e.id,null),a()},Wt=G(()=>void 0);Wt.current=e=>{if(Uy(e.target)||e.metaKey||e.ctrlKey||e.altKey)return;let t=e.key.toLowerCase();if(e.key===` `){if(Ht(e.target))return;e.preventDefault(),Ct()}else if(e.key===`ArrowLeft`)e.preventDefault(),wt(e.shiftKey?-10:-1);else if(e.key===`ArrowRight`)e.preventDefault(),wt(e.shiftKey?10:1);else if(t===`v`)At();else if(Ug(e))V();else if(t===`f`)e.preventDefault(),e.repeat||Mt();else if(T&&/^[iogbn]$/.test(t))return;else t===`i`?Tt():t===`o`?Et():t===`g`&&!e.repeat?Rt():t===`b`?_e(e=>!e):t===`n`&&(e.preventDefault(),Re())},U(()=>{let e=e=>Wt.current(e);return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[]);let Gt=(e,t)=>{let n=k.current;return mt(n?.videoWidth??0,n?.videoHeight??0,e,t)},Kt=e=>{let t=ee.current.getBoundingClientRect(),n=Gt(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 qt=e=>{if(!ge)return;let t=Kt(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})},Jt=e=>{if(!ve)return;let t=Kt(e);ye({...ve,x1:t.x,y1:t.y})},Yt=e=>{if(!ve)return;let t=Kt(e),n=ht(ve.x0,ve.y0,t.x,t.y,ve.w,ve.h);ye(null),_e(!1),We.current=!0,n.w>.01&&n.h>.01&&B(n)},Xt=ve?ht(ve.x0,ve.y0,ve.x1,ve.y1,ve.w,ve.h):null,Zt=Gt(xe.w,xe.h),Qt=e=>({left:`${e.x*100}%`,top:`${e.y*100}%`,width:`${e.w*100}%`,height:`${e.h*100}%`}),$t=F?t.shots.filter(e=>e.start<F):t.shots,en=$e($t,Te(N,n)),tn=[...ae,...Pt].map(e=>({n:e,at:De(e,t.id)})).filter(({at:e})=>e.t!==null),nn=new Map(tn.map(({n:e})=>[e.id,e])),rn=Am(tn.map(({n:e,at:t})=>({...e,t:t.t,tOut:t.tOut})),F).map(e=>{let t=nn.get(e.id),n=er(t,re);return{...e,ring:re&&t.format===null,title:n?`${n} · ${t.text}`:t.text}}),an=e=>km(e,F),on=z.in===null?null:{left:an(z.in),width:an(z.out??z.in+.2)-an(z.in)},sn=(e,t)=>{k.current?.pause(),St(t),je(e.id)},cn=ae.find(e=>e.id===Ae)??null,ln=cn?.box&&(!cn.version||cn.version===t.id)&&Zn(cn,y,ie)?cn.box:null,un=z.in===null?null:z.out===null?`${Ce(z.in)} →`:Oe(z.in,z.out),dn=Bt(Te(N,n)),fn=z.in!==null&&z.out===null?`Set an Out point`:dn.stage===`picture`?`Note at ${un&&z.out!==null?un:Ce(N)}`:`Note on ${dn.label}`,pn=e=>{te(L?e.duration||t.duration||0:t.duration??I?.duration??(e.duration||0)),L&&t.width===null&&e.videoWidth&&e.videoHeight&&x?.(t.file,e.videoWidth,e.videoHeight),me(e=>e===ct?null:e),e.videoWidth&&e.videoHeight&&ue(e.videoWidth/e.videoHeight),Ge.current||(Ge.current=!0,A.current&&(e.currentTime=Math.min(A.current,e.duration||A.current),P(e.currentTime)));let n=ut.current;n&&(ut.current=null,e.currentTime=Math.min(n.t,e.duration||n.t),P(n.t),n.play&&e.play().catch(()=>void 0))},mn=t=>{t!==g&&_?.(e.id,t)};return Q(`div`,{class:`split deskcols`,children:[Q(`div`,{class:`tl`,ref:Ue,children:[Q(`div`,{class:`monitor`,ref:He,children:[Q(yy,{active:kt,readOnly:T,grabbing:It>0,onSelect:At,onNote:Re,onRange:jt,onBox:()=>_e(e=>!e),onGrab:()=>void Rt()}),Q(`div`,{class:`framebox`,children:[Q(`div`,{class:`fitbox`,children:Q(`div`,{class:`frame`,ref:j,style:{aspectRatio:String(le),"--ar":String(le)},children:[b&&!L&&Q(`div`,{class:`msg`,children:`File not found`}),lt&&!L&&!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.`}),lt&&L&&!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.`}),lt&&L&&p&&t.proxy&&!st&&Q(`div`,{class:`msg`,children:`This file won't play in a browser.`}),Q(`video`,{hidden:lt||b&&!L,ref:e=>{k.current=e,f&&(f.current=e),e&&e.readyState>=1&&pn(e)},src:ct,preload:`auto`,playsInline:!0,onLoadedMetadata:e=>pn(e.target),onTimeUpdate:e=>{let t=e.target;yt(t),!de&&!ut.current&&P(t.currentTime)},onSeeked:e=>!ut.current&&P(e.target.currentTime),onPlay:()=>fe(!0),onPause:()=>fe(!1),onEnded:()=>fe(!1)}),Q(`div`,{ref:ee,class:`overlay${ge?` drawing`:``}`,onPointerDown:qt,onPointerMove:Jt,onPointerUp:Yt,onClick:()=>{We.current?We.current=!1:ge||Ct()},children:Q(`div`,{class:`pic`,style:{left:`${Zt.x}px`,top:`${Zt.y}px`,width:`${Zt.w}px`,height:`${Zt.h}px`},children:[ln&&Q(`div`,{class:`bx saved`,style:Qt(ln)}),ke&&Q(`div`,{class:`bx`,style:Qt(ke)}),Xt&&Q(`div`,{class:`bx`,style:Qt(Xt)})]})}),Q(`div`,{class:`tcover`,children:[`f`,we(N,n),en&&` · shot ${et(en.n)}`]}),t.proxy&&L&&Q(`div`,{class:`srcswitch`,role:`group`,"aria-label":`Which file plays`,children:[Q(`button`,{type:`button`,class:`tip-below tip-start tip-wrap`,"aria-pressed":st,"aria-label":`Proxy`,"data-tip":`Playing the lightweight copy. Notes and timings are the same.`,onClick:e=>{e.currentTarget.blur(),mn(`proxy`)},children:`Proxy`}),Q(`button`,{type:`button`,class:`tip-below tip-start tip-wrap`,"aria-pressed":!st,"aria-label":`Original`,"data-tip":`Play the full-quality file. It may stutter.`,onClick:e=>{e.currentTarget.blur(),mn(`original`)},children:`Original`})]})]})}),E&&Q(`div`,{class:`monfmt`,children:E}),h&&Q(r_,{hidden:!L,video:e,version:t,ffmpeg:p,job:m,broken:lt&&!st,duration:F,toast:i,onChanged:a,noteProxyJob:h},t.id)]})]}),Q(sy,{t:N,duration:F,playing:de,onToggle:Ct,onStep:wt,rangeLabel:un,onClearRange:Dt,volume:ze.level,muted:ze.muted,onVolume:e=>Be({level:e,muted:e===0&&ze.muted}),onMute:()=>Be({...ze,muted:!ze.muted}),onFullScreen:Mt,loudness:Nt.inUse?Q(By,{loudness:Nt.loudness}):null}),Q(oy,{column:Ue,split:Ve}),Q(`div`,{...ay(Ve.split),children:[Q(`div`,{class:`trow rrow`,children:[Q(`div`,{class:`thead`}),Q(s_,{duration:F,t:N,marks:rn,live:on,onSeek:St,onMark:e=>{let t=tn.find(({n:t})=>t.id===e);t&&sn(t.n,t.at.t)}})]}),Q(i_,{shots:$t,duration:F,t:N,current:en?.n??null,cutLabel:sp(t)||t.id,locked:e.lockedVersion===t.id,onSeek:e=>{k.current?.pause(),St(tt(e,n))}}),Q(zy,{mix:Nt,duration:F,t:N,onSeek:St,notes:[...ae,...Pt]})]})]}),Q(Qg,{readOnly:T,notes:[...ae,...Pt],version:t.id,selectedId:Ae,placeholder:fn,inputRef:M,toast:i,onAdd:Vt,onChanged:a,onTextChange:Ne,onLabel:Nt.noteLabel,target:{label:dn.label,when:dn.when,name:dn.name,menu:{value:Ie,options:Hy,onChange:e=>Le(e===`mix`?`mix`:`frame`)},onClear:Ie===`mix`?V:void 0},formatTag:e=>er(e,re),cardExtra:re&&I?e=>Q(ug,{name:`Note applies to`,label:I.label,width:I.width,height:I.height,value:nt(e)===null?`all`:`this`,lockedReason:e.box?Qn:null,onChange:t=>void it(e,t===`all`?null:I.id)}):void 0,formatScope:re&&I?{label:I.label,width:I.width,height:I.height,value:Ye,onChange:ce,lockedReason:ke?Qn:null,hint:$n(I.label,Ye,ke!==null)}:void 0,listFooter:e=>{let n=oe.filter(t=>e===`all`||t.status===e);return n.length>0?Q(e_,{notes:n,version:t.id,viewsHere:v,ownViews:Xe,onShow:(e,t)=>{ke||(at.current={id:t.id,fallback:!1}),C?.(e)},onRestore:e=>{at.current={id:e.id,fallback:!1},it(e,null)}}):null},onSeek:(e,t)=>sn(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:()=>B(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 Gy=500,Ky=(e,t)=>e.slice(0,t).filter(n=>n.heading===e[t].heading).length,qy=e=>String(e).padStart(2,`0`);function Jy({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:Zr(e.still),alt:`Still for shot ${e.n}, ${e.name}`,onError:()=>r(e.still)})}function Yy({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=qh(()=>{s.current=!1,c()},Gy),u=qh(()=>{s.current=!1,c()},Gy),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(Jy,{shot:e})}),Q(`div`,{class:`sbmeta`,children:[Q(`b`,{children:qy(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(Qh,{label:`Your version of shot ${e.n}`,value:r,onInput:e=>{s.current=!0,i(e),l.schedule()},onBlur:()=>l.flush()}),f&&Q($h,{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 Xy({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(Jy,{shot:e,large:!0})}),Q(`div`,{class:`sblcap`,children:[Q(`b`,{children:[qy(e.n),` · `,e.name]}),` `,e.tag&&Q(`span`,{class:`sbtag`,children:e.tag}),Q(`p`,{children:e.description})]})]})})}function Zy({board:e,brief:t,toast:n,onChanged:r,settle:i}){let{latest:a,enqueue:o}=Kh(`storyboard`,e,{toast:n,onChanged:r,settle:i}),[s,c]=H(null),l=G(null),u={shot:(e,t)=>{let n=a.current.shots.findIndex(t=>t.index===e.index),r=n<0?0:Ky(a.current.shots,n),i=t.status===`approved`&&t.description===void 0&&t.direction===void 0;o(`shot ${e.n}`,(n,a)=>{let o=n.shots.filter(t=>t.heading===e.heading)[r];if(!o){let t=n.shots.filter(t=>t.name===e.name);t.length===1&&(o=t[0])}return o&&a&&i&&(o.description!==e.description||o.direction!==e.direction)?{refuse:`the agent changed this shot while you were looking at it. Read it again, then approve.`}:o?{path:`/api/storyboard/shots/${o.index}`,body:{heading:o.heading,...t}}:null})}},d=Ye(t),f=e.shots.find(e=>e.heading===s);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:d?`${e.plannedLength.toFixed(1)} / ${d} s planned`:`${e.plannedLength.toFixed(1)} s planned`}),d&&Q(`span`,{class:`bar`,children:Q(`i`,{style:{width:`${Math.min(100,e.plannedLength/d*100)}%`}})})]}),e.total===0&&Q(`p`,{class:`sbnone`,children:"storyboard.md has no shots yet. Your agent adds them as `## Shot 01 · Name` sections."}),Q(`div`,{class:`prows`,children:e.shots.map((t,n)=>Q(Yy,{shot:t,save:u,onZoom:()=>{l.current=document.activeElement,c(t.heading)}},`${t.heading}#${Ky(e.shots,n)}`))}),Q(eg,{counts:e.total>0?{approved:tg(e.approved,e.total,`shot`),edited:e.changed}:null}),f&&Q(Xy,{shot:f,onClose:()=>{c(null),l.current?.focus()}})]})}var Qy={approved:{color:`var(--done)`,label:`Approved`},flagged:{color:`var(--todo)`,label:`Flagged`},draft:{color:`var(--text-3)`,label:`Draft`}},$y=500,eb=am;function tb({section:e,wps:t,toast:n,onChanged:r,onPick:i}){let[a,o]=H(e.proposed??e.current),[s,c]=H(e.direction),l=G(!1);U(()=>{l.current||o(e.proposed??e.current)},[e.proposed,e.current]),U(()=>{l.current||c(e.direction)},[e.direction]);let u=async t=>{try{await K.patch(`/api/script/${encodeURIComponent(e.id)}`,t)}catch(t){n(`Couldn't save ${e.id.toUpperCase()}: ${t.message}`)}r()},d=qh(()=>{l.current=!1,u({proposed:a.trim()===e.current.trim()?null:a})},$y),f=qh(()=>{l.current=!1,u({direction:s})},$y),p=e.end-e.start,m=ke(a,p,t),h=a.trim()!==e.current.trim(),g=Qy[e.status];return Q(`div`,{class:`srow${h?` changed`:``}`,"data-section":e.id,onFocusIn:()=>i?.({id:e.id,label:eb(e)}),onClick:()=>i?.({id:e.id,label:eb(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":g.label,"data-tip":g.label,title:g.label,children:Q(`i`,{style:{background:g.color}})})]}),Q(`div`,{class:`pbody`,children:[Q(Qh,{label:`Your version of ${e.id}`,value:a,onInput:e=>{l.current=!0,o(e),d.schedule()},onBlur:()=>d.flush()}),h&&Q($h,{baseline:[{text:e.current}],revertLabel:`Revert`,onRevert:()=>{l.current=!1,o(e.current),u({proposed:null})}})]})]}),Q(`div`,{class:`sfoot`,children:[Q(`div`,{class:`fit${m.state===`ok`?``:` ${m.state}`}`,title:`${m.words} words · ${m.seconds.toFixed(1)} s of ${p.toFixed(1)} s`,children:Q(`i`,{style:{width:`${Math.min(100,m.ratio*100)}%`}})}),Q(`input`,{class:`dirin`,placeholder:`Direction`,"aria-label":`Direction for ${e.id}`,value:s,onInput:e=>{l.current=!0,c(e.target.value),f.schedule()},onBlur:()=>f.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 u({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 u({status:e.status===`approved`?`draft`:`approved`}),children:Q($,{name:`check`})})]})]})]})}function nb({script:e,toast:t,onChanged:n,onPickLine:r}){let i=e.sections.filter(B).length,a=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(i=>Q(tb,{section:i,wps:e.wordsPerSecond,toast:t,onChanged:n,onPick:r},i.id))}),Q(eg,{counts:e.sections.length>0?{approved:tg(a,e.sections.length,`line`),edited:i}:null})]})}var rb=Math.floor(Math.random()*2**31),ib=!1,ab=new Set,ob={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 sb({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 cb({stage:e,state:t,assets:n,video:r,toast:i,onChanged:a,onPendingChange:o,clock:s,version:c}){let[l,u]=H(e===`music`&&ib),d=e=>{ib=e,u(e)},[,f]=H(0),p=ob[e],m=t.project.videos.length,h=ir(t.project.lanes,r?.id,m),g=nr(t.picks,r?.id),_=e=>m>1?my(e,t.project.videos,r,i,a):void 0,v=Cy({stage:e,groups:hm(h,e,g.use?.[e],r??void 0),assets:n,blind:l?{seed:rb,word:`Bed`}:null,films:e=>_(wy(e))}),y=r?Dt(ar(t.project.lanes,r.id,m),e):[],b=Dt(h,e),x=jt(b,e=>v.nameOf(e.key)??e.name,e===`sfx`),S=c??je(r??void 0),C=r&&S?{video:r.id,version:S,locked:r.lockedVersion===S.id}:null;return Q(My,{stage:e,title:p.title,film:r?.id??null,readOnly:!!r?.shelved,list:v,loose:{items:y.map(e=>({key:e.key,name:e.name,meta:e.meta,films:_(e),none:e.films.length===0})),what:y.length===1?p.one:p.many},headerExtra:e===`music`?Q(sb,{on:l,onToggle:()=>d(!l)}):void 0,preview:C,prompt:Re(`picture`,t.project.name,r?.name??null),fps:S?.fps??(t.project.fps||30),notes:or(t.notes.notes,e,r?.id),noteRow:e=>Ft(b,e.on),onLabel:e=>It(b,x,e.on),targetName:(e,t)=>t===null?e.name:x.find(n=>n.value===`c:${e.key}:${t}`)?.label??e.name,rangeMarks:!0,wholeLabel:`The whole ${p.one}`,none:p.none,layers:e===`sfx`?{open:e=>ab.has(e),toggle:e=>{ab.has(e)?ab.delete(e):ab.add(e),f(e=>e+1)}}:void 0,toast:i,onChanged:a,onPendingChange:o,clock:s})}var lb=Math.floor(Math.random()*2**31),ub=!1;function db({state:e,assets:t,video:n,toast:r,onChanged:i,onPendingChange:a,clock:o,version:s}){let[c,l]=H(ub),u=e=>{ub=e,l(e)},d=e.project.videos.length,f=ir(e.project.lanes,n?.id,d),p=nr(e.picks,n?.id),m=t=>d>1?my(t,e.project.videos,n,r,i):void 0,h=Cy({stage:`voice`,groups:hm(f,`voice`,p.use?.voice,n??void 0),assets:t,blind:c?{seed:lb,word:`Read`}:null,films:e=>m(wy(e))}),g=e=>h.nameOf(e.key)??e.name,_=n?Dt(ar(e.project.lanes,n.id,d),`voice`):[],v={rounds:Gt(f,p.lanes),sections:e.script.sections},y=s??je(n??void 0),b=n&&y?{video:n.id,version:y,locked:n.lockedVersion===y.id}:null;return Q(My,{stage:`voice`,title:`Voice`,film:n?.id??null,readOnly:!!n?.shelved,list:h,loose:{items:_.map(e=>({key:e.key,name:`${e.laneName} · ${e.name}`,meta:e.meta,films:m(e),none:e.films.length===0})),what:_.length===1?`read`:`reads`},headerExtra:Q(sb,{on:c,onToggle:()=>u(!c)}),preview:b,prompt:Re(`picture`,e.project.name,n?.name??null),fps:y?.fps??(e.project.fps||30),notes:or(e.notes.notes,`voice`,n?.id),noteRow:e=>Yt(v,e),onLabel:e=>Xt(v,e.on,g),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,clock:o})}function fb(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 pb=e=>e.map(e=>e?`1`:`0`).join(``),mb={100:`left third`,"010":`centre`,"001":`right third`,110:`left two thirds`,"011":`right two thirds`,111:`full width`,101:`full width`},hb={100:`top third`,"010":`middle`,"001":`bottom third`,110:`top two thirds`,"011":`bottom two thirds`,111:`full height`,101:`full height`};function gb(e){let t=pb(fb(e.x,e.w)),n=pb(fb(e.y,e.h));return t===`111`&&n===`111`?`the whole picture`:t===`010`&&n===`010`?`the centre`:`${mb[t]}, ${hb[n]}`}function _b(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 vb(e,t,n=8){return Math.min(Math.max(0,e-1),Math.max(0,t-n))}var yb=e=>Math.round(e*1e4)/1e4,bb=e=>yb(Math.max(0,Math.min(1,e))),xb=.02;function Sb(e,t,n){if(!n)return{pin:{x:bb(e.x),y:bb(e.y)}};let[r,i,a,o]=[bb(e.x),bb(e.y),bb(t.x),bb(t.y)],s={x:Math.min(r,a),y:Math.min(i,o),w:yb(Math.abs(a-r)),h:yb(Math.abs(o-i))};return s.w<xb||s.h<xb?null:{box:s}}var Cb=e=>e.versions[e.versions.length-1];function wb(e){let t=Cb(e);return{page:1,ratio:t.pages[0]?.images[0]?.ratio??``,ver:t.id}}function Tb(e,t){let{ver:n,...r}=t;return n===Cb(e).id?r:{...r,ver:n,since:Cb(e).id}}function Eb(e,t){let{ver:n,since:r,...i}=t??{},a=n!==void 0&&r===Cb(e).id;return{...wb(e),...i,...a?{ver:n}:{}}}var Db=(e,t)=>t.ver===Cb(e).id;function Ob(e,t){return[e.name,e.kind===`carousel`?`page ${t.page}`:null,ve(t.ratio),t.ver].filter(Boolean).join(` · `)}var kb=e=>(e.on??``).slice(0,(e.on??``).lastIndexOf(`/`)),Ab=e=>Number((e.on??``).slice((e.on??``).lastIndexOf(`/`)+1))||0;function jb(e,t){return e.filter(e=>e.stage===`visuals`&&kb(e)===kb(t)).findIndex(e=>e.id===t.id)+1}function Mb(e,t){let n=t.filter(e=>e.stage===`visuals`),r=[...e.map(e=>e.id),...new Set(n.map(kb).filter(t=>!e.some(e=>e.id===t)))],i=[];for(let t of r){let r=n.filter(e=>kb(e)===t);if(r.length===0)continue;let a=e.find(e=>e.id===t),o=[...new Set(r.map(Ab))].sort((e,t)=>e-t).map(e=>({page:e,notes:r.filter(t=>Ab(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 Nb(e,t,n){return e.filter(e=>e.stage===`visuals`&&kb(e)===t&&Ab(e)===n.page&&e.format===n.ratio&&e.version===n.ver&&(e.box!==null||e.pin!==null))}function Pb(e,t){let n={};for(let r of e)r.stage===`visuals`&&r.status===`todo`&&kb(r)===t&&(n[Ab(r)]=(n[Ab(r)]??0)+1);return n}function Fb(e,t,n){return{page:Ab(t),ratio:t.format??n.ratio,ver:t.version??n.ver}}function Ib(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 Lb=e=>e instanceof HTMLElement&&(e.isContentEditable||/^(INPUT|TEXTAREA|SELECT)$/.test(e.tagName));function Rb(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 zb({notes:e,all:t,selected:n,draft:r}){return Q(w,{children:[e.map(e=>{let r=jb(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`&&kb(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`&&kb(e)===r.vis).length+1})})]})}function Bb({file:e,alt:t,onBad:n}){return Q(`img`,{src:Zr(e),alt:t,draggable:!1,onError:n})}function Vb({visual:e,view:t,badges:n,onPage:r}){let i=e.versions.find(e=>e.id===t.ver)??Cb(e),a=G(null);W(()=>{let e=a.current;if(!e||e.children.length===0)return;let n=e.children[vb(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:Zr(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 Hb({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)??Cb(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:_}=Rb({w:m.width,h:m.height}),[v,y]=H(null),b=Nb(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=!Db(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===Cb(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":`${Ob(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(Bb,{file:m.file,alt:`${e.name}, page ${t.page}`,onBad:()=>y(m.file)},m.file),Q(zb,{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(Vb,{visual:e,view:t,badges:Pb(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 Ub({visual:e,view:t,notes:n,onPage:r,onClose:i}){let a=e.versions.find(e=>e.id===t.ver)??Cb(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}=Rb({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(Bb,{file:s.file,alt:`${e.name}, page ${t.page}`,onBad:()=>void 0},s.file),Q(zb,{notes:Nb(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 Wb({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=>Eb(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)??Cb(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]:Tb(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(!Db(r,a))return t(`You're looking at ${a.ver}. Switch to the newest version to add notes.`);let s=Ib(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:Sb(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=Sb(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(!Db(x,e))return t(`You're looking at ${e.ver}. Switch to the newest version to add notes.`);let n=Ib(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(!Db(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 Gr,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===kb(e));t&&(p(e.id),S(t,Fb(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(Lb(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=Gb(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=Mb(i,a),L=a.filter(e=>e.stage===`visuals`&&e.status===`todo`).length,R=new Set(a.filter(e=>e.stage===`visuals`&&e.status===`todo`).map(kb)).size,ne=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(Hb,{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:[L,` open across `,R,` visual`,R===1?``:`s`]})]}),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!==Cb(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:jb(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?gb(t.box):t.pin?_b(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,{...Fb(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?Ob(E,u):Ob(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`})]})]})]}),ne&&Q(Ub,{visual:ne,view:b(ne),notes:a,onPage:e=>S(ne,{page:e}),onClose:()=>h(null)})]})}function Gb(e,t){return(e.versions.find(e=>e.id===t.ver)??Cb(e)).pages[0]?.images.map(e=>e.ratio)??[]}var Kb=()=>{try{return window.sessionStorage}catch{return}},qb=()=>{try{return window.localStorage}catch{return}};function Jb(e,t,n){let[r,i]=H(()=>jg(Kb(),Ag(e,`log-open`))===`1`),[a,o]=H(!1),[s,c]=H(()=>jg(qb(),Ag(e,`log-seen`))),l=t?.mark??null,u=G(s);u.current=s;let d=t=>{c(t),Mg(qb(),Ag(e,`log-seen`),t)},f=n(r);return U(()=>{f&&l&&kg(l,s)&&d(l)},[f,l]),U(()=>{let t=Ag(e,`log-seen`),n=e=>{e.key===t&&e.newValue&&c(e.newValue)};return window.addEventListener(`storage`,n),()=>window.removeEventListener(`storage`,n)},[e]),{open:r,focusOnOpen:a,dot:!f&&kg(l,s),setOpen:(t,n=t)=>{i(t),o(t&&n),Mg(Kb(),Ag(e,`log-open`),t?`1`:`0`)},saw:e=>{kg(e,u.current)&&d(e)},focused:()=>o(!1)}}function Yb(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 Xb=700,Zb=16,Qb=()=>typeof matchMedia==`function`&&matchMedia(`(hover: none)`).matches;function $b({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=Lr(),O=new Date,k=sp(t),A=e=>{f(e),m(null),v(null),g(Qb()),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-Zb;b(Math.max(0,Math.min(e.left+t.width-n,e.left-Zb)))};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=rh(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<Xb?E.current.text+e.key:e.key;E.current={text:t,at:e.timeStamp};let n=nh(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":ex(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:sp(e)}),Q(`span`,{class:`vwhen`,children:[e.id===n&&Q($,{name:`lock`}),eh(e.addedAt,O)]}),h&&_===e.id&&Q(`span`,{class:`vinline`,dir:`auto`,children:[Jf(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(`p`,{dir:`auto`,children:Jf(I.note)||`No note.`}),Q(`span`,{class:`vmeta`,children:ih(I,O)})]})]})]})}function ex(e,t,n){return[e.id,sp(e),e.id===t?`locked`:``,th(e.addedAt,n)].filter(Boolean).join(`, `)}function tx({video:e,shown:t,newer:n,onPick:r,onToggleLock:i}){let a=!!e.lockedVersion;return Q($b,{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]})]})})}var nx=700;function rx(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=e=>{r(!1),e&&o.current?.focus()},d=(t=0)=>{a(Math.max(0,Math.min(e-1,t))),l.current={text:``,at:-1/0},r(!0)};return fy(n,s,u),W(()=>{n&&c.current[i]?.focus()},[n,i]),{open:n,show:d,close:u,toggle:e=>n?u(!1):d(e),row:e=>t=>{c.current[e]=t},onKeyDown:n=>{if(n.key===`Tab`)return u(!1);if(n.metaKey||n.ctrlKey||n.altKey)return;let r=c.current.findIndex(e=>e===document.activeElement),o=rh(n.key,r<0?i:r,e),s=e=>c.current[e]?.disabled===!0,d=n.key===`Home`?`ArrowDown`:n.key===`End`?`ArrowUp`:n.key;for(let t=0;o!==null&&t<e&&s(o);t++)o=rh(d,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<nx?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())}},button:o,wrap:s}}function ix({films:e,currentId:t,openNotes:n,onSwitch:r,onRestore:i,shelvedRequest:a}){let o=e.filter(Me),s=e.filter(e=>!Me(e)),c=e.find(e=>e.id===t),l=rx(o.length+s.length*2,e=>{if(/^\d+$/.test(e)){let t=nh(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`,` · `,mm(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 ax({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 `,mm(e.shelved),`. View only.`]}),Q(`span`,{class:`sp`}),Q(`button`,{type:`button`,class:`btn`,onClick:t,children:[Q($,{name:`undo`}),`Restore film`]})]})}function ox({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 sx({found:e,onBringIn:t,video:n,onToggleShelved:r,autoProxy:i,onKeys:a,toast:o,onChanged:s}){let c=rx(6),l=!!n?.shelved,[u,d]=H(()=>ur(mr())),f=()=>{let e=fr(u);hr(e),_r(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: `,pr[u]]})]})]})]})}function cx({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 lx({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()};fy(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(cg,{prompt:t,toast:n,copyRef:s,onClick:()=>c(!0)})})]})}function ux({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(lx,{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 dx=96,fx=e=>e?Math.max(0,e.scrollWidth-e.clientWidth):0;function px(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-dx:0)+fx(t.querySelector(`.pname`))+fx(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 mx({barRef:e,project:t,projectId:n,film:r,cut:i,workspaces:a,notesToggle:o,more:s}){let c=G(null);return px(c,e),Q(`header`,{class:`top`,ref:e,children:[Q(`div`,{class:`tleft`,ref:c,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]})]})}function hx({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 ${Ie.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 gx=new Set([`picture`,`voice`,`music`,`sfx`,`mix`]),_x=[{view:`picture`,label:`Timeline`},{view:`voice`,label:`Voice`},{view:`music`,label:`Music`},{view:`sfx`,label:`Effects`}],vx=e=>e instanceof HTMLElement&&(e.isContentEditable||/^(INPUT|TEXTAREA|SELECT)$/.test(e.tagName));function yx({tab:e,projectName:t,filmName:n,found:r,onReview:i,toast:a}){let o=e===`brief`||e===`storyboard`,{what:s,unlocks:c}=e===`brief`?He:e===`storyboard`?Ue:Ie[e],l=e===`assets`?`Assets`:e===`brief`?`Brief`:e===`storyboard`?`Storyboard`:Fe[e],u=e===`assets`?`grid`:e===`brief`?`brief`:e===`storyboard`?`story`:sh[e],d=e===`brief`?We(t,n):e===`storyboard`?Ge(t,n):Re(e,t,n),f=o?null:Tn(e,r),p=G(null),m=async()=>{try{await navigator.clipboard.writeText(d),a(`Prompt copied`)}catch{p.current?.select(),a(`Prompt selected: press ${bn(navigator.platform)}`)}};return Q(`div`,{class:`emptypage locked`,children:[Q($,{name:u}),Q(`h2`,{children:l}),Q(`p`,{children:s}),Q(`p`,{children:c}),Q(`textarea`,{class:`promptbox mono`,readOnly:!0,rows:4,ref:p,value:d,"aria-label":`Prompt for your agent`}),Q(`button`,{class:`btn primary`,onClick:()=>void m(),children:[Q($,{name:`copy`}),`Copy prompt for your agent`]}),f&&Q(`p`,{class:`foundline`,children:[Q(`span`,{children:f.text}),Q(`button`,{type:`button`,class:`btn`,"aria-label":f.review,onClick:()=>i(f.kind),children:`Review`})]})]})}function bx({onPendingChange:e,...t}){return U(()=>()=>e(!1),[]),Q(Qg,{...t,onTextChange:e})}function xx(){let{state:e,assets:t,problem:n,wrongProject:r,refresh:i,proxyJobs:a,noteProxyJob:o}=Vm(),[s,c]=H(null),[l,u]=H(null),[d,f]=H(null),[p,m]=H(null),[h,g]=H(null),[_,v]=H(null),[y,b]=H(`script`),[x,S]=H(`picture`),C=G(null),[w,T]=H(!1),[E,D]=H(!1),[O,k]=H(!1),[A,j]=H(!1),ee=G(new Map),M=G(null),N=G({at:e=>ee.current.get(e)??0,attach:(e,t)=>{let n={film:e,read:t};return M.current=n,()=>{ee.current.set(e,t()),M.current===n&&(M.current=null)}}}).current,P=G(null),[F,te]=H({}),I=G(void 0),L=G(new Map),R=G(null),ne=(e,t)=>te(n=>({...n,[e]:t})),[re,ie]=H({}),ae=(e,t)=>ie(n=>({...n,[e]:t})),[oe,se]=H({}),[ce,le]=H({}),[ue,de]=H(!1),[fe,pe]=H(!1),me=G(new Set),z=(e,t=2400,n=null)=>{m(e),g(n),clearTimeout(I.current),I.current=window.setTimeout(()=>{m(null),g(null)},t)},[he,ge]=H({n:0,pending:!1}),[_e,ye]=H(null),xe=Yg(),Se=!!s&&(um(s).workspace===`review`||um(s).workspace===`plan`),Ce=Jb(Kr()??``,e?.log,e=>e&&Se&&xe.shown),[we,Te]=H(!1),Ee=G(null),De=G(null);W(()=>{let e=De.current;e&&(De.current=null,e())});let[Oe,ke]=H(null);U(()=>{for(let e of Object.values(a))e.state!==`failed`||me.current.has(e.job)||(me.current.add(e.job),z(e.reason??`Couldn't make the proxy`))},[a]),U(()=>{if(!e)return;if(s===null){let t=pm(Xe(e.tabs,e.brief));c(t),Be(t)&&b(t)}let t=e.project.videos.find(Me);l===null&&t&&u(t.id)},[e]),U(()=>{e?.project.name&&(document.title=`${e.project.name} · Rushes`)},[e?.project.name]);let B=e?.project.videos.find(e=>e.id===l)??e?.project.videos.find(Me),Fe=Ae(B),Le=je(B),V=B?.versions.find(e=>e.id===d)??Le,ze=!!B?.lockedVersion,We=V?.fps??e?.project.fps??30,Ge=e?.notes.notes.filter(e=>e.stage===`picture`&&(!e.video||e.video===B?.id))??[],Ye=V?be(V,ce[V.file]):[],Qe=B&&V?Bn(B,V.id):void 0,$e=Vn(Ye,B?oe[B.id]:void 0),et=new Set(t.filter(e=>e.kind===`cut`&&e.missing).map(e=>e.path)),tt=V?Hn({views:Ye,previous:Qe?be(Qe):[],current:$e,versionDuration:V.duration,notes:Ge,missing:et}):[],nt=e=>!B||e===$e?!1:ue?(z(`Add or clear your box on ${$e?ve($e):`this format`} first`),!1):(se(t=>({...t,[B.id]:e})),!0);U(()=>{O&&d===null&&Le?(f(Le.id),j(!0)):!O&&A&&d===Le?.id&&(f(null),j(!1))},[O,d,Le?.id]),U(()=>{!A&&d!==null&&d===Le?.id&&f(null)},[Le?.id,A,d]);let rt=Fe&&V&&Fe.id!==V.id&&(ze||A)?Fe.id:null,it=e=>{if(e===B?.id)return;if(B&&O)return z(`Add or clear your note on ${B.name} first`);if(B){R.current?.pause();let e=M.current;e&&e.film===B.id&&ee.current.set(B.id,e.read()),L.current.set(B.id,{versionId:d,held:A})}let t=L.current.get(e);P.current=null,u(e),f(t?.versionId??null),j(t?.held??!1)},at=async()=>{if(B&&V)try{await K.put(`/api/videos/${B.id}/lock`,{version:B.lockedVersion?null:V.id}),i()}catch(e){z(e.message)}},[ot,st]=H(0),ct=G(it);ct.current=it;let lt=async(t,n)=>{if(!e)return!1;if(n&&t.id===B?.id&&O)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=Pe(e.project.videos,t.id);n?it(n):u(null)}return i(),n?z(`“${t.name}” shelved`,6e3,{label:`Undo`,run:()=>void lt(t,!1).then(e=>e&&ct.current(t.id))}):z(`“${t.name}” restored`),!0}catch(e){return z(e.message),!1}},ut=()=>{B&<(B,!B.shelved)},dt=t=>{if(O)return z(`Add or clear your note first`);if(t.tab===`assets`)return vt();if(t.video&&t.video!==B?.id&&it(t.video),t.version){let n=e?.project.videos.find(e=>e.id===(t.video??B?.id));f(t.version===je(n)?.id?null:t.version),j(!1)}let n=pm(t.tab);c(n),um(n).workspace===`review`&&S(n),v(null),t.row&&Yb(t.row)},ft=e?.tabs??[],pt=e=>ft.find(t=>t.stage===e),mt=En(e?.found),ht=t.length>0||mt!==null,gt=e=>{let t=pm(e);if(O&&t!==s)return z(`Add or clear your note first`);c(t),v(null),Be(t)&&b(t),um(t).workspace===`review`&&S(t)},_t=()=>{let t={brief:!!e?.brief.exists,script:!!pt(`script`)?.unlocked,storyboard:!!e?.storyboard.exists};gt(Ze(y,t))},vt=()=>{if(O&&s!==`assets`)return z(`Add or clear your note first`);c(`assets`),v(null)},yt=e=>{if(O&&s!==`assets`)return z(`Add or clear your note first`);ge(t=>({n:t.n+1,kind:e,pending:!0})),c(`assets`),v(null)},bt=G(yt);bt.current=yt,U(()=>{Ut(location.search).test&&(window.__rushesOpenFound=e=>bt.current(e))},[]),W(()=>{let t=t=>{if(t.altKey&&!t.metaKey&&!t.ctrlKey&&!t.shiftKey&&(t.key===`ArrowLeft`||t.key===`ArrowRight`)){if(s!==`picture`||vx(t.target))return;t.preventDefault();let e=Un(tt,$e,t.key===`ArrowRight`?1:-1);e&&nt(e);return}if(vx(t.target)||t.metaKey||t.ctrlKey||t.altKey)return;let n=fm(t.key,y);if(t.key===`1`?_t():n===`assets`?vt():n&>(n),t.key===`S`&&t.shiftKey&&!t.repeat&&ut(),(t.key===`[`||t.key===`]`)&&e){let n=Ne(e.project.videos,l,t.key===`]`?1:-1);n&&it(n)}t.key===`?`&&T(e=>!e),t.key===`\\`&&Se&&!t.repeat&&(t.preventDefault(),xe.toggle()),t.key===`Escape`&&(T(!1),v(null))};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)});let xt=G(null),St=G(null);W(()=>{let e=St.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&&!!s]);let Ct=async()=>{if(!e||!s)return;T(!1);let t=s===`brief`||s===`storyboard`?await C.current?.():void 0,n=(s===`brief`?t:void 0)??e.brief,r=(s===`storyboard`?t:void 0)??e.storyboard,a=[n.exists&&(s===`brief`||n.changed>0)?qe(e.project.name,B?.name??null,n):null,r.exists&&(s===`storyboard`||r.changed>0)?Je(e.project.name,B?.name??null,r):null].filter(e=>e!==null),o=null;try{o=(await K.post(`/api/batches`,{})).batch}catch(e){if(!(e instanceof Gr&&e.code===`empty_batch`))return z(e.message)}if(!o&&a.length===0)return s===`brief`&&!n.exists?z(`There's no brief yet: copy the prompt on this page for your agent`):s===`storyboard`&&!r.exists?z(`There's no storyboard yet: copy the prompt on this page for your agent`):z(`Nothing open to send on any tab`);v(o?{id:o.id,prompt:[o.prompt,...a].join(`
|
|
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}})}},s=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(mg,{section:t,save:o},`${t.heading}#${hg(e.sections,t.index)}`))}),Q(dg,{counts:e.sections.length>0?{approved:s?`Brief approved`:`Brief not approved yet`,edited:e.changed}:null,children:Q(`button`,{class:`btn bapprove${s?` approved`:``}`,"aria-pressed":s,onClick:()=>o.status(s?`draft`:`approved`),children:[Q($,{name:`check`}),s?`Approved`:`Approve brief`]})})]})}var _g=150;function vg({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),_g)};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:Kn(e.length)},onKeyDown:e=>S(e),children:e.map(e=>{let n=Gn(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":Wn(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(yg,{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 yg({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 bg=[`ArrowLeft`,`ArrowRight`,`ArrowUp`,`ArrowDown`,`Home`,`End`];function xg({label:e,width:t,height:n,value:r,onChange:i,lockedReason:a,name:o}){let s=Gn(t,n),c=Lr();return Q(`div`,{class:`fscope`,role:`radiogroup`,"aria-label":o,onKeyDown:e=>{if(e.altKey||e.metaKey||e.ctrlKey||!bg.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})]})}function Sg({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 Cg({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 wg=e=>e.status===`done`?`Reopen`:Om(im(e),`Mark done`),Tg=[{kind:`rise`,label:`Rise`},{kind:`fall`,label:`Fall`},{kind:`louder`,label:`Louder`},{kind:`quieter`,label:`Quieter`}];function Eg({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}){let[S,C]=H(`all`),w=x??S,T=G(null),E=i??T,[D,O]=H(``),[k,A]=H(!1),j=e.filter(e=>e.status===`todo`).length,ee=v?.(w)??null,M=e.map(e=>({n:e,at:p?{t:e.t,tOut:e.tOut,from:null}:De(e,t)})).filter(({n:e})=>w===`all`||e.status===w).sort((e,t)=>(e.at.t??-1)-(t.at.t??-1)),N=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()},P=async()=>{let e=D.trim();if(e&&!k){A(!0);try{await o(e),O(``),l?.(!1)}catch(e){a(`Couldn't add the note: ${e.message}`)}finally{A(!1)}}};return Q(`div`,{class:`panel side notes`,role:`region`,"aria-label":`Notes`,children:[x===void 0&&Q(`div`,{class:`ph`,children:Q(Cg,{filter:w,onChange:C,todo:j})}),Q(`div`,{class:`list`,children:[M.length===0&&Q(`div`,{class:`none`,children:w===`all`?ee?`None on this format.`:`No notes yet.`:`Nothing here.`}),M.map(({n:e,at:t})=>Q(`div`,{class:`note${im(e)===`todo`?``:` ${im(e)}`}`,"data-note":e.id,"aria-current":m===e.id?`true`:void 0,children:[Q(`button`,{class:`chk`,"aria-label":wg(e),"data-tip":wg(e),onClick:()=>void N(e),children:Q($,{name:`check`})}),Q(`div`,{class:`nt`,children:[Q(`button`,{class:`t`,onClick:()=>t.t!==null&&s?.(t.t,e),children:Oe(t.t,t.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})})(),t.from&&Q(`span`,{class:`from`,children:[`from `,t.from]})]}),St(e.marks)&&Q(`div`,{class:`nmarks`,children:St(e.marks)}),e.shot&&Q(`div`,{class:`shotref`,children:[`Shot `,et(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:Zr(e.grab),alt:`Frame grab`})}),e.reply&&Q(`div`,{class:`rp`,children:[Q($,{name:`reply`}),Q(`span`,{children:e.reply})]}),m===e.id&&g&&Q(`div`,{class:`nfmt`,children:g(e)})]},e.id)),ee]}),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:Tg.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(Ct(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(wt(d.value,e,Number(n.value))),n.blur()},children:_t.map(e=>Q(`option`,{value:String(e),children:[e,` dB`]}))}),Q($,{name:`chev`})]})]})})}),_&&Q(`div`,{class:`row`,children:Q(xg,{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:E,class:`input`,rows:2,"aria-label":`New note`,placeholder:n,value:D,onInput:e=>{let t=e.target.value;O(t),l?.(t.trim()!==``)},onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),P()),e.key===`Escape`&&(D.trim()===``&&u?.onClear?.(),e.target.blur())}}),Q(`button`,{class:`btn primary ib sm send`,"data-tip":`Add note ↵`,"aria-label":`Add note`,onClick:()=>void P(),children:Q($,{name:`send`})})]}),_&&Q(`p`,{class:`fhint`,children:_.hint})]}),y&&b&&Q(`p`,{class:`ninstead`,children:b})]})}var Dg=[[`all`,`All`],[`picture`,fp.picture],[`voice`,fp.voice],[`music`,fp.music],[`sfx`,`Effects`],[`mix`,fp.mix],[`visuals`,fp.visuals],[`notes`,fp.notes],[`assets`,fp.assets]];function Og(e){return Dg.some(([t])=>t===e)}var kg={user:`added by you`,agent:`agent`,rushes:`Rushes`};function Ag(e,t){let n=[];for(let r of e){let e=new Date(r.at),i=yp(e),a=n[n.length-1];a&&a.date===i?a.entries.push(r):n.push({key:i,date:i,heading:bp(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 jg(e,t){return e===`all`||e===t}var Mg=new Set([` `,`ArrowLeft`,`ArrowRight`,`ArrowUp`,`ArrowDown`,`Home`,`End`,`PageUp`,`PageDown`]);function Ng(e){return Mg.has(e.key)&&!e.altKey&&!e.ctrlKey&&!e.metaKey}var Pg=[`script`,`picture`,`voice`,`music`,`sfx`,`mix`];function Fg(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&&Pg.includes(e.tab)?{tab:e.tab}:e.area===`assets`?{tab:`assets`}:Pg.includes(e.area)?{tab:e.area}:null}function Ig(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 Lg(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 Rg(e,t){let n=e.by===`user`?`added by you`:e.by===`agent`?`by the agent`:`by Rushes`;return`${e.text} (${fp[e.area]}, ${t}, ${n})`}function zg(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 Bg(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 Vg(e,t){return`rushes:${e}:${t}`}function Hg(e,t){try{return e?.getItem(t)??null}catch{return null}}function Ug(e,t,n){try{e?.setItem(t,n)}catch{}}var Wg=1e3,Gg=40,Kg=new Map,qg=e=>`${e?.rev??``}:${e?.mark??``}`,Jg=()=>{try{return window.sessionStorage}catch{return}};function Yg({entry:e,to:t,onGo:n}){let r=vp(new Date(e.at)),i=Q(w,{children:[Q(`span`,{class:`ltime`,children:r}),Q(`span`,{class:`ltag ${e.area}`,children:fp[e.area]}),Q(`span`,{class:`ltext`,dir:`auto`,children:[e.text,Q(`span`,{class:`lby`,children:kg[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":Rg(e,r),onClick:()=>n(t),children:i}):Q(`div`,{class:`lrow`,"data-entry":e.id,children:i})}function Xg({log:e,projectId:t,head:n,project:r,stage:i,toast:a,onJump:o,onEscape:s}){let[c,l]=H(()=>{let e=Hg(Jg(),Vg(t,`log-filter`));return Og(e)?e:`all`}),u=e=>`${t}\n${e}`,[d,f]=H(()=>Kg.get(u(c))?.view??null),[p,m]=H(null),[h,g]=H(null),_=G(n);_.current=n;let[v,y]=H(``),b=G(null),x=G(null),S=G(null);S.current=d;let C=G(c);C.current=c;let w=G(0),T=()=>(b.current?.scrollTop??0)>Gg,E=t=>{f(t),m(null),C.current===`all`&&t.entries[0]&&e.saw(`${t.entries[0].id}@${t.entries[0].at}`)},D=async(e=!1)=>{let t=++w.current,n=new URLSearchParams({limit:String(Wg)}),r=C.current,i=qg(_.current);r!==`all`&&n.set(`area`,r);try{let a=await K.get(`/api/log?${n}`);if(Kg.set(u(r),{head:i,view:a}),t!==w.current)return;g(null),!e&&S.current&&T()?m(a):E(a)}catch(e){if(t!==w.current)return;S.current?a(zg(`read`,e)):g(zg(`read`,e))}},O=G(!1);U(()=>{let e=!O.current;O.current=!0;let t=Kg.get(u(c));if(e&&t&&t.head===qg(n)){E(t.view);return}b.current&&(b.current.scrollTop=0),m(null),D(!0)},[c]);let k=G(!0);U(()=>{if(k.current){k.current=!1;return}D()},[n?.rev,n?.mark]),W(()=>{e.focusOnOpen&&(x.current?.focus(),e.focused())},[]);let A=async()=>{let e=v.trim();if(e)try{if(await K.post(`/api/log`,{text:e,area:i}),y(``),!jg(c,i)){let e=fp[i];a(`Added under ${e}. Choose All${Dg.some(([e])=>e===i)?` or ${e}`:``} to see it.`)}b.current&&(b.current.scrollTop=0),await D(!0)}catch(e){a(zg(`add`,e))}},j=e=>{l(e),Ug(Jg(),Vg(t,`log-filter`),e)},ee=()=>{p&&(E(p),b.current&&(b.current.scrollTop=0),requestAnimationFrame(()=>{let e=b.current?.querySelector(`.lrow`);(e instanceof HTMLButtonElement?e:b.current)?.focus({preventScroll:!0})}))},M=()=>{p&&!T()&&E(p)},N=G(o);N.current=o;let P=G(e=>N.current(e)).current,F=async()=>{try{a(`Saved to ${(await K.post(`/api/exports/change-log`,{})).path}`)}catch(e){a(zg(`export`,e))}},te=Pr(()=>d?Ag(d.entries,new Date).map(e=>Q(`div`,{class:`dgroup`,children:[Q(`h3`,{class:`dday`,children:e.heading}),Q(`ul`,{children:e.entries.map(e=>Q(`li`,{children:Q(Yg,{entry:e,to:Fg(e,r),onGo:P})},e.id))})]},e.key)):null,[d,r,yp(new Date)]),I=d&&p?Ig(d.entries,p.entries):0,L=d!==null&&d.total===0&&d.undated.length===0,R=d!==null&&!L&&d.entries.length===0&&d.undated.length===0;return Q(`div`,{id:`changelog`,class:`activity`,onKeyDown:e=>{if(e.key===`Escape`&&!e.defaultPrevented){e.preventDefault(),e.stopPropagation(),s();return}Ng(e)&&e.stopPropagation()},children:[Q(`form`,{class:`dadd`,onSubmit:e=>{e.preventDefault(),A()},children:[Q(`input`,{ref:x,value:v,maxLength:160,placeholder:`Add a line to the log`,"aria-label":`Add a line to the log`,onInput:e=>y(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:c,onChange:e=>{let t=e.target.value;Og(t)&&j(t)},children:Dg.map(([e,t])=>Q(`option`,{value:e,children:t},e))}),Q($,{name:`chev`})]})}),Q(`div`,{class:`dwrap`,children:[I>0&&Q(`button`,{type:`button`,class:`dpill`,onClick:ee,children:[I,` new`]}),Q(`div`,{class:`dlist`,ref:b,tabIndex:0,role:`group`,"aria-label":`Entries`,onScroll:M,children:[d===null&&!h&&Q(`p`,{class:`dempty`,children:`Loading…`}),d===null&&h&&Q(`p`,{class:`dempty dproblem`,role:`alert`,children:h}),L&&Q(`p`,{class:`dempty`,children:`Nothing yet. Rushes writes a line here whenever a cut, a take or a variant is added.`}),R&&Q(`p`,{class:`dempty`,children:`Nothing for this filter.`}),te,d&&d.undated.length>0&&Q(`section`,{class:`dbefore`,"aria-label":`Before the log`,children:[Q(`h3`,{children:`Before the log`}),Q(`ul`,{children:d.undated.map((e,t)=>Q(`li`,{children:e.text},t))})]})]})]}),Q(`div`,{class:`dfoot`,children:[Q(`span`,{children:d?Lg(d):``}),Q(`button`,{type:`button`,class:`btn`,onClick:()=>void F(),children:`Export as Markdown`})]})]})}var Zg=ce(null);function Qg(e){let t=Ir(Zg);return()=>{t&&(!t.shown||t.log.open)?t.revealNotes(()=>e.current?.focus()):e.current?.focus()}}var $g=`[role="dialog"], [role="menu"], [role="listbox"], .fmtpop.open`;function e_(e){return e.key!==`Escape`||e.defaultPrevented||document.querySelector($g)!==null?!1:!(e.target instanceof Element?e.target:null)?.closest(`.npanel`)}var t_=`rushes:notes-width`,n_=`rushes:notes-hidden`;function r_(e){try{return localStorage.getItem(e)}catch{return null}}function i_(e,t){try{t===null?localStorage.removeItem(e):localStorage.setItem(e,t)}catch{}}var a_=()=>typeof matchMedia==`function`?matchMedia(`(max-width: 1099px)`):null;function o_(){let[e,t]=H(()=>{let e=Number(r_(t_));return r_(t_)!==null&&Number.isFinite(e)?Math.min(560,Math.max(240,e)):360}),[n,r]=H(()=>r_(n_)===`1`),[i,a]=H(!1),[o,s]=H(()=>a_()?.matches??!1);U(()=>{let e=a_();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),i_(n_,e?null:`1`))};return{width:e,setWidth:(e,n)=>{t(e),n&&i_(t_,e===360?null:String(e))},narrow:o,shown:c,setShown:l,toggle:()=>l(!c)}}var s_=`Hide the notes panel · \\`;function c_({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 l_(e){let t=Ir(Zg),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(Eg,{...e});let{log:l,activity:u,send:d,shown:f,narrow:p}=t,m=l.open?`activity`:`notes`,h=e.notes.filter(e=>e.status===`todo`).length,g=(e,t=!0)=>{e===`activity`!==l.open&&l.setOpen(e===`activity`,t)},_=e=>{if(e.key!==`ArrowLeft`&&e.key!==`ArrowRight`)return;e.preventDefault(),e.stopPropagation();let t=m===`notes`?`activity`:`notes`;g(t,!1),(t===`notes`?n:r).current?.focus()},v=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=>v(e.clientX),onPointerUp:e=>{let n=v(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":m===`notes`,"aria-controls":`npanel-notes`,tabIndex:m===`notes`?0:-1,onClick:()=>g(`notes`),onKeyDown:_,children:[`Notes`,h>0&&Q(`span`,{class:`n`,children:h})]}),Q(`button`,{ref:r,type:`button`,role:`tab`,id:`ntab-activity`,class:`ntab`,"aria-selected":m===`activity`,"aria-controls":`npanel-activity`,"aria-label":l.dot?`Activity (new entries)`:`Activity`,tabIndex:m===`activity`?0:-1,onClick:()=>g(`activity`),onKeyDown:_,children:[`Activity`,l.dot&&Q(`span`,{class:`cdot`,"aria-hidden":`true`})]})]}),Q(`span`,{class:`sp`}),m===`notes`&&Q(Sg,{filter:s,onChange:c}),p&&Q(`button`,{type:`button`,class:`ibtn`,"aria-label":s_,"data-tip":s_,onClick:()=>t.setShown(!1),children:Q($,{name:`x`})})]}),Q(`div`,{class:`ntabpanel`,role:`tabpanel`,id:`npanel-notes`,"aria-labelledby":`ntab-notes`,hidden:m!==`notes`,children:Q(Eg,{...e,filter:s})}),m===`activity`&&Q(`div`,{class:`ntabpanel`,role:`tabpanel`,id:`npanel-activity`,"aria-label":`Activity`,children:Q(Xg,{...u,log:l,onEscape:()=>r.current?.focus()})}),(d.count>0||d.always)&&Q(`div`,{class:`nfoot`,children:Q(`button`,{ref:i,type:`button`,class:`btn primary sendbtn`,"aria-label":d.count>0?`Send ${d.count}`:`Send`,"data-tip":`Notes and edits not sent yet, from every tab and film`,onClick:d.onSend,children:[`Send`,d.count>0&&Q(`span`,{class:`count`,children:d.count})]})})]})}function u_(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 d_({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=tr(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 f_=6e3,p_=e=>/[.!?]$/.test(e)?e:`${e}.`;function m_({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),_=_n({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),f_);return()=>clearTimeout(e)},[v]),!n)return null;let y=v&&h===v?`none`:_,b=vn(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 Gr&&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.`}),` `,p_(b)]}),Q(`button`,{class:`btn primary tip-wrap tip-end`,"aria-label":`Create proxy`,"data-tip":fn(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}),` (`,nt(t.proxy.bytes),`).`]}),Q(`button`,{class:`btn ghost ib`,"aria-label":`Dismiss`,"data-tip":`Dismiss`,onClick:()=>g(v),children:Q($,{name:`x`})})]})]})})}function h_({shots:e,duration:t,t:n,current:r,cutLabel:i,locked:a,onSeek:o,view:s,style:c,sizer:l}){let u=s??Mm(t),d=e=>Pm(e,u),f=e.length>0?e.map((n,i)=>({key:String(n.n),start:n.start,end:e[i+1]?.start??t,short:et(n.n),label:`${et(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 g_=[.5,1,2,5,10,15,30,60,120,300,600],__=e=>`${Math.floor(e/60)}:${String(Math.floor(e%60)).padStart(2,`0`)}${e%1?`.${String(Math.round(e%1*10))}`:``}`;function v_({duration:e,t,marks:n,live:r,onSeek:i,onMark:a,view:o}){let s=o??Mm(e),c=s.end-s.start,l=e=>Pm(e,s),u=g_.find(e=>c/e<=8)??g_[g_.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?Fm((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:__(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:__(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":Om(e.status,e.title),"aria-label":Om(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 y_(e){return e.rev?`${e.path}#${e.rev}`:e.path}function b_(e){return e.modified?e.modified:e.size===null?void 0:String(e.size)}var x_=.05,S_=6e4;function C_(e){return 10**(e/20)}function w_(e){let t=e.some(e=>e.solo),n={};for(let r of e){let e=t?+!!r.solo:+!r.muted;n[r.id]=C_(r.level??0)*e}return n}function T_(e,t){return+(e===t)}function E_(e,t){let n={};for(let r of e){let e=t[r.lane];n[r.id]=e===void 0?1:T_(e,r.id)}return n}function D_(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 O_(e,t,n){return Math.abs(e-t)>1/n+1e-9}function k_(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 A_(e,t){let n=new Float32Array(Math.max(0,Math.floor(t)));for(let r of e){let e=k_(r,t);for(let t=0;t<n.length;t++)e[t]>n[t]&&(n[t]=e[t])}return n}function j_(e){return Math.min(S_,Math.max(1,Math.round(e*50)))}function M_(e,t){return!t||e!==null&&e>N_}var N_=900;function P_(e){N_=e??900}function F_(e){return e!==null&&e>3456e5}function I_(e,t,n,r=1/0,i=x_){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 L_(e,t,n,r){return n&&!r?`play`:!n&&r?`pause`:Math.abs(e-t)>.050000001?`seek`:null}function R_(e,t){return e.map(e=>e.duration>0?e:{...e,duration:t[y_(e)]??0})}function z_(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 B_(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 V_(e){return e.name.trim()||`Untitled cue`}function H_(e){return`${V_(e)} at ${Ce(e.t)}`}function U_(e,t){return`cue ${e} of ${t}`}function W_(e){let t=new Map;for(let n of B_(e)){let e=V_(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 G_(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 K_(e){return e.split(/[\\/]/).filter(Boolean).pop()??e}function q_(e,t){return`${((t>0?Math.min(1,Math.max(0,e/t)):0)*100).toFixed(3)}%`}function J_(e,t){return`clamp(5px, ${q_(e,t)}, calc(100% - 5px))`}function Y_(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 X_(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 Z_=`cue-card`;function Q_(){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 $_(e,t){return{onPointerEnter:n=>e.show(n.currentTarget,t),onPointerLeave:()=>e.hide()}}function ev({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=X_({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:Z_,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),` · `,U_(a.n,a.of)]}),a.file!==null&&Q(`span`,{class:`f`,style:{color:a.color},children:a.file})]})}var tv=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,Qm(this,()=>this.stop()),this.set({path:e,playing:!0});try{await n.play()}catch(t){if(this.current.path===e&&this.current.playing)throw $m(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(),$m(this),this.current.playing&&this.set({...this.current,playing:!1})}element(){if(!this.el){let e=this.make();e.addEventListener(`ended`,()=>{$m(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,Zr);function nv(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=G_(e.key,i.indexOf(r),i.length);a!==null&&(e.preventDefault(),e.stopPropagation(),i[a].focus())}function rv(){let[e,t]=H(tv.state());return U(()=>tv.subscribe(t),[]),e}function iv({id:e,name:t,cues:n,length:r,color:i,card:a,onSeek:o,toast:s}){let c=B_(n),l=new Map(c.map((e,t)=>[e,t+1])),u=W_(n),[d,f]=H({}),p=rv();U(()=>()=>tv.stopIf(e),[e]);let m=async t=>{try{await tv.toggle(t,e)}catch{s(`Couldn't play ${K_(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:J_(s.t,r)},"aria-label":H_(s),"aria-describedby":p?Z_:void 0,...$_(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=>nv(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:K_(s)})]}),t.moreFiles>0&&Q(`small`,{children:[`+`,t.moreFiles]})]})]},t.name)})})}var av=0;function ov(){return av}var sv=3,cv=2;function lv({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(cr,e),()=>window.removeEventListener(cr,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;av++,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=vr(o,n);let c=Math.floor(a.w/sv),l=t*sv/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*sv,(a.h-c)/2,cv,c)}},l),Q(`canvas`,{ref:i,class:`wave`,"aria-hidden":`true`})}var uv=2e3,dv=8e3,fv={kind:`none`},pv={kind:`pending`},mv={kind:`none`,silent:!0};async function hv(e,t,n){let r;try{r=await t.fetch(e.peaksUrl,{signal:n})}catch(e){if(n.aborted)throw e;return pv}if(r.status===202)return pv;if(r.status===501)return gv(e,t,n);if(r.status===204)return mv;if(r.status!==200)return fv;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))?fv:{kind:`wave`,wave:{peaks:Float32Array.from(t),duration:e.duration}}}catch(e){if(n.aborted)throw e;return fv}}async function gv(e,t,n){if(e.size===null||!(e.size<1e8))return fv;try{let r=await e.duration();if(n.aborted)throw new DOMException(`aborted`,`AbortError`);if(r===null||!(r>0)||r>900)return fv;let i=await t.fetch(e.mediaUrl,{signal:n});if(!i.ok)return fv;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)?fv:{kind:`wave`,wave:{peaks:_v(A_(a,Math.min(uv,s))),duration:o}}}catch(e){if(n.aborted)throw e;return fv}}function _v(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 vv=40,yv=new Map,bv=new Set;function xv(e,t,n,r){return`${e}/${t}/${n}#${r??``}`}function Sv(e){return yv.has(e)}function Cv(e){return yv.get(e)??null}function wv(e){return bv.has(e)}function Tv(e,t,n=!1){for(yv.delete(e),yv.set(e,t),n&&t===null?bv.add(e):bv.delete(e);yv.size>vv;){let e=yv.keys().next().value;yv.delete(e),bv.delete(e)}}function Ev(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 Dv=1500,Ov=15e3,kv=15e3,Av={fetch(e,t){let n=Kr();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,dv).decodeAudioData(e),n=[];for(let e=0;e<t.numberOfChannels;e++)n.push(t.getChannelData(e));return{channels:n,duration:t.duration}}};function jv(e,t,n,r,i){let a=e&&t?xv(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),kv)}),[l,u]=H(()=>a&&Sv(a)?{key:a,wave:Cv(a),silent:wv(a)}:null),d=G(null);return U(()=>{if(!e||!t)return;if(Sv(a)){u({key:a,wave:Cv(a),silent:wv(a)});return}let r=new AbortController,i,o=Dv,s={peaksUrl:`/api/videos/${encodeURIComponent(e)}/versions/${encodeURIComponent(t.id)}/peaks`,mediaUrl:Zr(t.file),size:n,duration:c},l=async()=>{d.current=null,clearTimeout(i);let e;try{e=await hv(s,Av,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,Ov);return}let t=e.kind===`wave`?e.wave:null,n=e.kind===`none`&&e.silent===!0;Tv(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 Mv=0;typeof location<`u`&&Ut(location.search).test&&(window.__rushesPicture={waveDraws:()=>Mv});var Nv=3,Pv=2;function Fv({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=Ev(window,t);return()=>{n.disconnect(),i()}},[]),U(()=>{let a=r.current;if(!a||i.w<=0||i.h<=0)return;Mv++,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+=Nv){let r=n+t/i.w*s;if(r>=e.duration)break;let a=n+(t+Nv)/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,Pv,p)}},[i,e,t,n]),Q(`canvas`,{ref:r,class:`pwave`,"aria-hidden":`true`})}var Iv=.03,Lv=.004,Rv=15e3;function zv(e){return e.buffer?e.buffer.length*e.buffer.numberOfChannels*4:0}var Bv=0;function Vv(){return Bv}var Hv=new Map;function Uv(e){let t=Hv.get(e);return t&&(Hv.delete(e),Hv.set(e,t)),t}function Wv(e,t){for(Hv.delete(e),Hv.set(e,t);Hv.size>200;)Hv.delete(Hv.keys().next().value)}function Gv(){let e=Error(`The load was cancelled`);return e.name=`AbortError`,e}function Kv(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),Rv)})}var qv=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??Zr,fetch:t.fetch??((e,t)=>fetch(e,t)),probe:t.probe??Kv(n),createMedia:n,raf:t.raf??(e=>requestAnimationFrame(e)),caf:t.caf??(e=>cancelAnimationFrame(e))},e&&(this.ctx=e,Bv++)}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 z_(this.videoDuration,this.resolved())}inspect(){return{playing:this._playing,time:this.time,length:this.length,sources:this.voices.size,gains:E_(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=y_({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)y_(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=>(M_(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(F_(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 Gv();let d;if(u&&!M_(u.duration,!0)){let e=Uv(t);if(!e){let n=[];for(let e=0;e<u.numberOfChannels;e++)n.push(u.getChannelData(e));e=A_(n,j_(u.duration)),Wv(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 Gv();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)y_(t)===e&&this.holding.delete(t.id);if(this._playing){for(let t of this.resolved())y_(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(y_)),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+=zv(e.media);for(;this.idle.size>12||o>268435456;){let[e,t]=this.idle.entries().next().value;o-=zv(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=E_(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(()=>{}),Qm(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(),$m(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(),$m(this),this.tickListeners.clear(),this.endedListeners.clear(),this.changeListeners.clear(),this.disposed=!0,this.ctx&&(this.ctx.close().catch(()=>{}),this.ctx=null,Bv--)}}ensureContext(){if(this.disposed)throw Error(`The audio engine was disposed`);return this.ctx||(this.ctx=this.opts.createContext(),Bv++),this.ctx}resolved(){let e={};for(let[t,n]of this.media)e[t]=n.duration;let t=R_(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+Iv;let n=this.resolved(),r=new Map(n.map(e=>[e.id,e]));for(let t of D_(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+Iv),r=this.startOffset+(n-this.startedAt);for(let t of D_([e],r))this.startVoice(e,n+t.when,t.offset)}startVoice(e,t,n){let r=this.media.get(y_(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(y_(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=I_(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=E_([e],this.selection)[e.id],r.connect(this.laneNode(e.lane)),t={gain:r,seekedAt:-1/0},this.media.get(y_(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+Lv)}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(y_(e))&&!this.media.has(y_(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)Jv(()=>e(t));if(t>=e){this.pause();for(let e of this.endedListeners)Jv(e);return}this._playing&&this.frame===null&&(this.frame=this.opts.raf(this.tick))};emitChange(){for(let e of this.changeListeners)Jv(e)}};function Jv(e){try{e()}catch(e){console.error(e)}}var Yv=e=>e.map(e=>[e.id,e.lane,e.path,e.rev??``,e.offset,e.duration].join(`\0`)).join(``);function Xv(e,t=null){let n=G(null);n.current||=new qv;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=>[y_(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,Yv(e)]),U(()=>{r.setVideoDuration(t)},[r,t]),{engine:r,playing:a,length:s,media:l}}var Zv=[`play`,`playing`,`pause`,`seeking`,`seeked`,`waiting`,`canplay`,`ratechange`,`timeupdate`,`ended`,`loadedmetadata`,`durationchange`,`emptied`],Qv=3;function $v(e,t,n){let{engine:r,length:i,media:a}=Xv(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>=Qv,a=e.currentTime,s=L_(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 Zv)e.addEventListener(n,t);return t(),()=>{for(let n of Zv)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 ey=`rushes:preview`,ty=.12,ny=.75;function ry(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 iy(e,t,n){let r=G(n);r.current=n,W(()=>e?.attach(t,()=>r.current()),[e,t])}var ay=`rushes:volume`,oy=`rushes:split`,sy=.75,cy=.08;function ly(){try{let e=JSON.parse(localStorage.getItem(ay)??`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 uy=()=>ry(oy,cy,sy);function dy(e,t){try{t===null?localStorage.removeItem(e):localStorage.setItem(e,t)}catch{}}function fy(){let[e,t]=H(ly);return U(()=>dy(ay,JSON.stringify(e)),[e]),[e,t]}function py(){let[e,t]=H(uy);return{split:e,set:t,keep:e=>{t(e),dy(oy,e===null?null:String(Math.round(e*1e3)/1e3))}}}function my(){let[e,t]=H(()=>ry(ey,ty,ny));return{size:e,set:t,keep:e=>{t(e),dy(ey,e===null?null:String(Math.round(e*1e3)/1e3))}}}function hy({column:e,preview:t,size:n}){let r=G(null),i=()=>{let t=e.current?.getBoundingClientRect().height??0;return t>0?Math.max(ty,Math.min(ny,(t-448)/t)):ny},a=e=>Math.min(i(),Math.max(ty,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:ty};return Q(`div`,{class:`pvsplit`,role:`separator`,"aria-orientation":`horizontal`,"aria-label":`Resize the preview`,"aria-valuemin":Math.round(ty*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 gy(e,t=`tlpanel`){return{class:`${t}${e===null?``:` sized`}`,style:e===null?void 0:{height:`${e*100}%`}}}function _y({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(sy,Math.max(cy,(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(cy*100),"aria-valuemax":Math.round(sy*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:cy);t.keep(Math.min(sy,Math.max(cy,a+(n.key===`ArrowUp`?.03:-.03))))}})}function vy({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 yy={current:null},by=e=>e instanceof HTMLElement&&(e.isContentEditable||/^(INPUT|TEXTAREA|SELECT)$/.test(e.tagName));function xy({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);iy(l,n?.id??``,()=>Te(m.current?.time??0,p));let h=ib({state:e,assets:t,video:n,version:null,player:yy,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=u_(h,e.notes.notes,n),E=Qg(S),D=e=>wm({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(!(by(e.target)||e.metaKey||e.ctrlKey||e.altKey)){if(e.key===` `){if(Ht(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(Sy,{prompt:i,toast:o,then:`Until then the takes in use play here together.`})}),Q(vy,{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(sb,{loudness:h.loudness}):null}),Q(`div`,{class:`tlpanel`,children:[Q(`div`,{class:`trow rrow`,children:[Q(`div`,{class:`thead`}),Q(v_,{duration:_,t:v,marks:[],live:null,onSeek:e=>g.seek(e),onMark:()=>void 0})]}),Q(ob,{mix:h,duration:_,t:v,onSeek:e=>g.seek(e),notes:[...r,...T]})]})]}),Q(l_,{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 Sy({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 ${bn(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:[Ie.picture.unlocks,` `,n]}),Q(`button`,{type:`button`,class:`btn sm`,onClick:()=>void r(),children:[Q($,{name:`copy`}),`Copy prompt for your agent`]})]})}var Cy=`rushes:track-heights`;function wy(){try{let e=JSON.parse(localStorage.getItem(Cy)??`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 Ty(e){try{e===null?localStorage.removeItem(Cy):localStorage.setItem(Cy,JSON.stringify(e))}catch{}}function Ey(){let[e,t]=H(wy),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),Ty(null)},set:(e,n)=>{t(e),n&&Ty(e)}}}function Dy(e,t,n){let[r,i]=H(null);U(()=>i(null),[e,n]);let a=r&&e>0?Im(r,e):Mm(e),o=t=>i(t===null||Nm(t,e)?null:Im(t,e)),s=t=>{if(!r)return;let n=zm(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 Oy({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=jm(t);n.grip===`pan`?r(Rm(n.v,t,i)):n.grip===`start`?r(Im({start:Math.min(n.v.start+i,n.v.end-o),end:n.v.end},t)):r(Im({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(Im({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(Rm(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 ky({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 Ay({tv:e,duration:t,t:n}){let r=r=>i=>{i.detail>0&&i.currentTarget.blur(),e.set(Lm(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(Oy,{view:e.view,duration:t,t:n,onView:e.set})]})}function jy(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(Lm(t.view,n,Math.exp(Math.max(-1,Math.min(1,e.deltaY*.01))),Fm(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 My(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])}function Ny({name:e,control:t}){let[n,r]=H(!1),i=G(null),a=G(null),o=G(null);My(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=s.length===0?`No film`:s.length===1?`1 film`:`${s.length} films`,d=e=>t.onChange(s.includes(e)?s.filter(t=>t!==e):c.filter(t=>t.id===e||s.includes(t.id)).map(e=>e.id));return Q(`span`,{class:`fmwrap films`,ref:i,onClick:e=>e.stopPropagation(),children:[Q(`button`,{ref:a,type:`button`,class:`btn ghost sm filmsbtn${s.length===0?` none`:``}`,"data-tip":l.length?`On ${l.join(`, `)}`:`On no film`,"aria-label":`Films for ${e}: ${l.length?l.join(`, `):`none`}`,"aria-haspopup":`true`,"aria-expanded":n,disabled:t.readOnly,onClick:()=>r(!n),children:[Q($,{name:`film`}),u]}),n&&Q(`div`,{class:`fmenu filmsmenu`,role:`group`,"aria-label":`Films for ${e}`,children:[Q(`div`,{class:`fmtitle`,children:[`Films it is on`,Q(`b`,{dir:`auto`,children:e})]}),c.map((e,t)=>Q(`label`,{class:`fmitem`,children:[Q(`input`,{ref:t===0?o:void 0,type:`checkbox`,checked:s.includes(e.id),onChange:()=>d(e.id)}),Q(`span`,{dir:`auto`,children:e.name}),e.here?Q(`kbd`,{children:`this film`}):e.shelved?Q(`kbd`,{children:`shelved`}):null]},e.id))]})]})}function Py(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 Fy(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 Iy(e){let t={},n=e=>e!==null&&e.scrollWidth>e.clientWidth;for(let r of e.querySelectorAll(`.take[data-take]`))n(r.querySelector(`[data-name]`))&&(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}var Ly=(e,t)=>Object.keys(e).length===Object.keys(t).length&&Object.keys(e).every(n=>e[n]===t[n]);function Ry(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?Pm(e,c):km(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=Iy(x.current);C(t=>Ly(t,e)?t:e)},E=[...r.flatMap(e=>e.items),...i.open?i.items:[]],D=e=>{let t=e.clip?l[y_(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}=Q_(),[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}),L=(e,t)=>{let r=e.take,i=e.key===u,a=Fy(e),o=S[e.key]??``,x=e.clip?l[y_(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=B_(e.cues),M=Y_(O),P=At(O,s),I=Math.min(A[e.key]??0,Math.max(0,O.length-1)),L=(t,r)=>({key:`m:${e.key}:${M[r]}`,name:V_(t),t:t.t,n:r+1,of:O.length,file:t.file??null,color:n}),R=d[e.key]??[],ne=!!p?.open(e.key),re=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?Fm(n,c):n*s))},ie=r.inUse?`In use`:`Use this one`,ae=e.missing?`File not found`:T?`This file won't play in a browser`:null,oe=e.details.join(` · `),se=oe!==``&&ee.has(e.key),ce=`kd-${e.key}`,le=[o.includes(`n`)?e.name:null,oe||null].filter(Boolean).join(`
|
|
62
|
+
`);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":ne,"aria-controls":ne&&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`:ne?`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":`${ie}: ${e.name}`,"data-tip":ie,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,oe||null].filter(Boolean).join(`. `)||void 0,"data-tip":le||void 0,onClick:()=>m(e,null),children:[Q(`span`,{"data-name":!0,children:e.name}),e.missing&&Q(Ch,{})]}),E&&Q(`span`,{class:`smk`,"data-tip":`Long file: switching isn't sample-exact`,children:Q($,{name:`stream`})}),oe!==``&&Q(`button`,{type:`button`,class:`kinfo`,"aria-label":`Details for ${e.name}`,"aria-expanded":se,"aria-controls":se?ce:void 0,"data-tip":se?`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(`span`,{class:`sp`}),e.films&&Q(Ny,{name:e.name,control:e.films}),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`})})]}),Q(`div`,{class:`tlane`,onClick:t=>m(e,re(t)),children:[Q(`div`,{class:`sblock${r.stale?` stale`:``}${ae?` none gone`:``}`,style:ae?{left:`0%`,width:`100%`}:{left:`${y(0)}%`,width:`${y(D)-y(0)}%`},children:ae&&Q(`span`,{class:`slbl`,children:ae})}),e.clip&&Q(lv,{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},...$_(k,L(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=L(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":H_(t),"aria-describedby":a?Z_:void 0,style:{left:`${y(t.t)}%`,color:n,maxWidth:`calc(${(P[r]*b*100).toFixed(3)}% - 8px)`},...$_(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=>nv(e,`button.cue`,k),onClick:n=>{n.stopPropagation(),m(e,t.t,t.id)},children:Q(`span`,{children:V_(t)})},`c${M[r]}:${t.t}:${t.name}`)}),R.map(e=>e.tOut!==null&&Q(`span`,{class:`span ${e.status}`,"data-note":e.id,title:Om(e.status,e.text),style:{left:`${y(e.t)}%`,width:`${y(e.tOut)-y(e.t)}%`}},`s${e.id}`)),R.map(e=>Q(`span`,{class:`mk ${e.status}`,"data-note":e.id,title:Om(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`})]})]}),se&&Q(`p`,{class:`kdetail`,id:ce,"data-details-of":e.key,children:oe}),ne&&O.length>0&&Q(iv,{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)},R=r.length===0&&i.items.length===0,ne=a.items.length,re=a.items.filter(e=>e.none).length;return Q(`div`,{class:`takes`,ref:x,role:`radiogroup`,"aria-label":t,style:{"--c":n},children:[R&&Q(`p`,{class:`knone`,children:o}),r.map((e,t)=>Q(w,{children:[I(e.heading),e.items.map(e=>L(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=>L(e,`back`))]}),ne>0&&Q(w,{children:[Q(`div`,{class:`kfold`,"data-fold":`loose`,children:[I(`Not on this film · ${ne} ${a.what}${re?` · ${re} 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(Ny,{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(ev,{shown:O,onHide:k.hide})]})}var zy=[{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 By({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:zy.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 Vy=typeof location>`u`?{test:!1,streamOver:!1}:Ut(location.search);Vy.streamOver&&P_(1);var Hy=Vy.test?{engine:null,inspect(){return this.engine?this.engine.inspect():null},renders:0,panelRenders:0,draws:ov,liveContexts:Vv,sample:()=>tv.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;Hy&&(window.__rushesAudio=Hy);var Uy=Hy;function Wy(e){let{stage:t,groups:n,assets:r,blind:i}=e,a=e=>i?Lt(e.map(gm),i.seed).map(t=>e.find(e=>gm(e)===t)):e,o=ym(n,a),s=a(n.away),c=new Map,l=0;for(let e of[...o.flatMap(e=>e.takes),...s])c.set(gm(e),i?`${i.word} ${++l}`:e.variant.name);let u=n=>{let a=gm(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?[]:Et(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?b_(o):void 0},cues:t===`sfx`?n.variant.cues:[],films:e.films(n)}},d=_m(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?gm(d):null}}var Gy=e=>({lane:e.lane,variant:e.variant.id,films:rr(e.variant)}),Ky=e=>e instanceof HTMLElement&&(e.isContentEditable||/^(INPUT|TEXTAREA|SELECT)$/.test(e.tagName)),qy={in:null,out:null},Jy={voice:`var(--vo)`,music:`var(--music)`,sfx:`var(--sfx)`},Yy=new Set,Xy=new Set;function Zy({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 Qy({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 $y(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,readOnly:m=!1}=e;Hy&&Hy.renders++;let[,h]=H(0),g=e=>{e.has(t)?e.delete(t):e.add(t),h(e=>e+1)},_=Yy.has(t),v=[...r.sections.flatMap(e=>e.items),..._?r.away:[]],y=v.flatMap(e=>e.clip?[e.clip]:[]),[b,x]=H(null),[S,C]=H(16/9),T=i?.version.file;U(()=>{x(null),C(16/9)},[T]);let E=i?i.version.duration??b:null,D=G(null);iy(e.clock,e.film??``,()=>Te(D.current?.time??0,a));let{engine:O,playing:k,length:A,media:j}=Xv(y,E);D.current=O,W(()=>{let t=e.clock?.at(e.film??``)??0;t>0&&O.seek(t)},[]);let[ee,M]=H(null),[N,P]=H(null),F=ee?v.find(e=>e.key===ee.key)??null:null;W(()=>{ee!==null&&F===null&&(M(null),P(null))},[F===null]);let te=F?.key??r.defaultKey??``;W(()=>O.selectVariant(t,te),[O,te]);let[I,L]=fy();W(()=>O.setLaneGain(t,I.muted?0:I.level),[O,I.muted,I.level]);let[R,ne]=H(qy),[re,ie]=H([]),[ae,oe]=H(!1),[se,ce]=H(!1),le=G(null),ue=Qg(le),de=G(null),fe=my(),pe=G(null);U(()=>{let e=e=>ce(!!le.current&&e.target===le.current),t=e=>{e.target===le.current&&ce(!1)};return document.addEventListener(`focusin`,e),document.addEventListener(`focusout`,t),()=>{document.removeEventListener(`focusin`,e),document.removeEventListener(`focusout`,t)}},[]);let me=G(e.film);W(()=>{me.current!==e.film&&(me.current=e.film,M(null),P(null),O.pause(),O.seek(e.clock?.at(e.film??``)??0))},[e.film]);let z=!m&>({range:R,marks:re,hasText:ae});W(()=>{p?.(z)},[z]),U(()=>()=>p?.(!1),[]);let he=F??v.find(e=>e.key===r.defaultKey)??null,ge=F&&ee?.cue&&F.cues.some(e=>e.id===ee.cue)?ee.cue:null,_e=R.in!==null&&R.out!==null?{t:R.in,tOut:R.out}:null,ve=e=>N===null?ge!==null||!!(F&&ee?.clicked)||Te(e,a)>0:!N,ye=e=>{if(!he){let r=_e?Oe(_e.t,_e.tOut):Sm(Te(e,a),a);return{stage:t,on:null,scope:_e?`range`:`point`,t:_e?.t??Te(e,a),tOut:_e?.tOut??null,label:`${r} · ${n}`,when:r,name:n}}let r=_e!==null||ve(e),i=r?ge:null,o=i?`${he.key}:${i}`:he.key,s=l(he,i);if(_e)return wm({kind:`take`,stage:t,on:o,name:s,t:_e.t,tOut:_e.tOut},null,a);let c=r?i?he.cues.find(e=>e.id===i).t:Te(e,a):null;return wm({kind:`take`,stage:t,on:o,name:s,t:c},null,a)},be=t=>{if(R.in!==null&&R.out===null)return`Set an Out point`;let n=ye(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))}`},xe=()=>{M(null),P(null)},Se=Dy(A,null,`${e.film??``}:${i?.version.id??``}`),De=G(Se);De.current=Se;let ke=G(null),B=G([]),Ae=G(null),je=G(!1),Me=G(0),Ne=e=>{let t=O.length,n=De.current;n?.zoomed&&n.follow(e);let r=n?.zoomed?`${Pm(Math.min(e,t),n.view)}%`:`${t>0?Math.min(e,t)/t*100:0}%`;for(let e of B.current)e.style.left=r;let i=Ae.current;i&&i.readyState>=1&&!i.seeking&&O_(i.currentTime,e,a)&&(i.currentTime=Math.min(e,Number.isFinite(i.duration)?i.duration:e)),i&&O.playing&&!je.current&&e>Me.current&&(je.current=!0,i.play().catch(()=>void 0)),Me.current=e},Pe=G(Ne);Pe.current=Ne,W(()=>{B.current=ke.current?[...ke.current.querySelectorAll(`.playhead`)]:[],Ne(O.time)}),U(()=>O.subscribe(e=>Pe.current(e)),[O]),U(()=>{let e=Ae.current;e&&(je.current=!1,k||(e.pause(),Pe.current(O.time)))},[k,T]);let Fe=()=>O.playing?O.pause():O.play(),Ie=e=>{O.pause(),O.seek(Ee(O.time,a,e,O.length))},Le=e=>O.seek(e),V=()=>{m||ne({in:Te(O.time,a),out:null})},Re=()=>{if(m)return;let e=Te(O.time,a),t=R.in??0;if(e<=t)return d(`Out has to come after In`);ne({in:t,out:e})},ze=()=>{ne(qy),ie([])},Be=R.in!==null&&R.out===null,Ve=se?`note`:Be?`range`:`select`,He=()=>{xe(),Be&&ze(),le.current&&document.activeElement===le.current&&le.current.blur()},Ue=()=>{let e=de.current;e&&(document.fullscreenElement?document.exitFullscreen().catch(()=>void 0):e.requestFullscreen?.().catch(()=>d(`Couldn't go full screen`)))},We=(e,n,r)=>{M({key:e.key,cue:r??null,clicked:n!==null}),P(null),O.selectVariant(t,e.key),n!==null&&O.seek(n)},Ge=async(t,n)=>{try{await Jr(e.film??void 0,t.take.lane,n)}catch(e){d(`Couldn't ${n===null?`clear`:`set`} the pick: ${e.message}`)}f()},Ke=async(e,t)=>{if(t&&e.films&&Fy(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 Yr(e.take.lane,e.take.variant.id,t)}catch(e){d(`Couldn't ${t?`archive it`:`restore it`}: ${e.message}`)}f()},qe=G(()=>void 0);qe.current=e=>{if(Ky(e.target)||e.metaKey||e.ctrlKey||e.altKey)return;let t=e.key.toLowerCase();if(e.key===` `){if(Ht(e.target))return;e.preventDefault(),Fe()}else e.key===`ArrowLeft`?(e.preventDefault(),Ie(e.shiftKey?-10:-1)):e.key===`ArrowRight`?(e.preventDefault(),Ie(e.shiftKey?10:1)):t===`v`?He():e_(e)?xe():t===`f`&&i?(e.preventDefault(),e.repeat||Ue()):t===`i`?V():t===`o`?Re():t===`n`&&!m?(e.preventDefault(),ue()):e.key===`=`||e.key===`+`?(e.preventDefault(),Se.set(Lm(Se.view,A,.5,O.time))):(e.key===`-`||e.key===`_`)&&(e.preventDefault(),Se.set(Lm(Se.view,A,2,O.time)))},W(()=>{let e=e=>qe.current(e);return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[]),W(()=>{Hy&&(Hy.clips=y)}),U(()=>{if(Hy)return Hy.engine=O,()=>{Hy.engine===O&&(Hy.engine=null)}},[O]);let Je=async n=>{if(R.in!==null&&R.out===null)throw Error(`set an Out point for the range`);let r=ye(O.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`?re:[]}),ne(qy),ie([]),f()},Ye={},Xe=[];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;(Ye[t]??=[]).push({id:e.id,t:e.t,tOut:n,status:im(e),text:e.text}),Xe.push({...e,tOut:n})}let Ze=new Map(Xe.map(e=>[e.id,e.text])),Qe=Am(Xe,A,Se.view).map(e=>({...e,ring:!1,title:Ze.get(e.id)??``})),nt=e=>Se.zoomed?Pm(Math.min(A,Math.max(0,e)),Se.view):km(e,A),rt=R.in===null?null:{left:nt(R.in),width:nt(R.out??R.in+.2)-nt(R.in)},it=R.in===null?null:R.out===null?`${Ce(R.in)} →`:Oe(R.in,R.out),at=i?i.version.shots.filter(e=>!A||e.start<A):[],ot=[{value:`point`,label:ge?`This cue`:`This moment`},{value:`whole`,label:e.wholeLabel}],st=Q(`div`,{class:`monitor spreview${i?``:` noslot`}`,ref:de,style:i?{"--ar":String(S)}:void 0,children:i?Q(w,{children:[Q(`div`,{class:`framebox`,children:Q(`div`,{class:`fitbox`,children:Q(`div`,{class:`frame`,style:{aspectRatio:String(S),"--ar":String(S)},children:[Q(`video`,{ref:Ae,src:Zr(i.version.file),muted:!0,playsInline:!0,preload:`auto`,"aria-label":`Picture preview`,onLoadedMetadata:e=>{let t=e.target;Number.isFinite(t.duration)&&x(t.duration),t.videoWidth&&t.videoHeight&&C(t.videoWidth/t.videoHeight),Pe.current(O.time)},onSeeked:()=>Pe.current(O.time),onClick:Fe}),Q(Zy,{engine:O,children:e=>{let t=$e(at,Te(e,a));return Q(`div`,{class:`tcover`,children:[`f`,we(e,a),t&&` · shot ${et(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(),Ue()},children:Q($,{name:`expand`})})]}):Q(Sy,{prompt:e.prompt,toast:d,then:`Until then the takes play here on their own.`})});return Q(`div`,{class:`split deskcols soundcols${i&&fe.size!==null?` pvsized`:``}`,style:i&&fe.size!==null?{"--pv":String(fe.size),"--ar":String(S)}:void 0,children:[Q(`div`,{class:`tl soundtab`,children:[Q(Zy,{engine:O,children:e=>Q(vy,{t:e,duration:A,playing:k,onToggle:Fe,onStep:Ie,rangeLabel:it,onClearRange:ze,volume:I.level,muted:I.muted,onVolume:e=>L({level:e,muted:e===0&&I.muted}),onMute:()=>L({...I,muted:!I.muted})})}),Q(`div`,{class:`kbody`,children:[Q(By,{active:Ve,readOnly:m,grabbing:!1,tools:[`select`,`note`,`range`],onSelect:He,onNote:ue,onRange:()=>Be?Re():V(),onBox:()=>void 0,onGrab:()=>void 0}),Q(`div`,{class:`tlpanel takespanel${Se.zoomed?` zoomed`:``}`,onWheel:e=>jy(e,Se,A),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(Zy,{engine:O,children:e=>Q(v_,{duration:A,t:e,marks:Qe,live:rt,view:Se.view,onSeek:Le,onMark:e=>{let t=Xe.find(t=>t.id===e);t?.t!=null&&(O.pause(),Le(t.t))}})})]})}),Q(`div`,{ref:ke,children:Q(Ry,{label:`${n} takes`,color:Jy[t],sections:r.sections,away:{items:r.away,open:_,dot:o.some(e=>e.status===`todo`&&r.away.some(t=>t.key===s(e))),onToggle:()=>g(Yy)},loose:{...e.loose,open:Xy.has(t),onToggle:()=>g(Xy)},none:e.none,length:A,view:Se.zoomed?Se.view:void 0,media:j,selected:F?.key??null,marks:Ye,range:R,layers:e.layers,onSelect:We,onPick:e=>void Ge(e,e.take.variant.id),onUnpick:e=>void Ge(e,null),onPutAway:(e,t)=>void Ke(e,t),toast:d})}),Q(`div`,{class:`kfoot`,children:[i&&Q(Zy,{engine:O,children:e=>Q(h_,{shots:at,duration:A,view:Se.view,t:e,current:$e(at,Te(e,a))?.n??null,cutLabel:sp(i.version)||i.version.id,locked:i.locked,onSeek:e=>{O.pause(),Le(tt(e,a))}})}),Q(Zy,{engine:O,children:e=>Q(Ay,{tv:Se,duration:A,t:e})})]})]})]})]}),Q(`div`,{class:`soundside`,ref:pe,children:[st,i&&Q(hy,{column:pe,preview:de,size:fe}),Q(Qy,{engine:O,by:e=>`${ye(e).label}\n${be(e)}`,children:e=>{let t=ye(e);return Hy&&Hy.panelRenders++,Q(l_,{notes:o,version:i?.version.id??null,placeholder:be(e),inputRef:le,toast:d,onAdd:Je,onChanged:f,onTextChange:oe,fixedTimes:!0,onSeek:e=>O.seek(e),target:{label:t.label,when:t.when,name:t.name,menu:he&&!_e?{value:t.scope===`whole`?`whole`:`point`,options:ot,onChange:e=>P(e===`whole`)}:void 0,onClear:F||N!==null?xe:void 0},marks:!u||t.scope!==`range`?void 0:{value:re,onChange:ie},onLabel:c,readOnly:m})}})]})]})}var eb={vo:`Voice`,music:`Music`,sfx:`Effects`},tb={vo:{muted:!1,solo:!1},music:{muted:!1,solo:!1},sfx:{muted:!1,solo:!1}},nb=e=>`${e.lane}/${e.variant.id}`;function rb(e,t,n){let r=e=>t.find(t=>t.path===e),i=nr(e.picks,n?.id).use,a=ir(e.project.lanes,n?.id,e.project.videos.length);return Zt.map(e=>{let t=hm(a,Qt[e],i?.[Qt[e]],n??void 0),o=t.inUse;if(!o)return{lane:e,groups:t,take:o,clip:null,block:bm(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?b_(c):void 0},block:`take`}})}function ib({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=Pr(()=>nr(e.picks,d),[e.picks,d]),p=f.use,m=Pr(()=>ir(e.project.lanes,d,e.project.videos.length),[e.project.lanes,d,e.project.videos.length]),h=Pr(()=>rb(e,t,n),[e.picks,e.project,t,n]),g=Pr(()=>h.flatMap(e=>e.clip?[e.clip]:[]),[h]),_=h.some(e=>e.take!==null),[v,y]=H(()=>l?.current??tb);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=Zt.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}]))}})},[Zt.map(e=>x[e]?`1`:`0`).join(``)]);let[S,C]=H(null),w=S??_,T=f.levels,E=e=>T[Qt[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 Zt){if(k.current[e]!==void 0)continue;let r=E(e);n[e]!==r&&(n[e]=r,t=!0)}return t?n:e})},[Pr(()=>`${d}:${JSON.stringify(T)}`,[d,T])]);let A=e=>{let t=k.current;for(let n of Zt){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=on(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:{[Qt[e]]:n===0?null:n}},{keepalive:t}).then(c,e=>{s(e instanceof Gr?e.message:`Couldn't save the level`)});r[e]={id:window.setTimeout(()=>{delete r[e],i()},300),send:i}},ee=w_(Zt.map(e=>x[e]?{id:e,...v[e],level:D[e]}:{id:e,level:D[e]})),M=o.muted?0:o.level,{media:N,engine:P,length:F}=$v(i,g,Object.fromEntries(Object.entries(ee).map(([e,t])=>[e,t*M]))),te=h.map(e=>e.clip&&N[y_(e.clip)]===`error`?{...e,block:`broken`}:e),I=Zt.some(e=>x[e]&&v[e].solo);W(()=>{Uy&&(Uy.clips=g)}),U(()=>{let e=Uy;if(e)return e.engine=P,()=>{e.engine===P&&(e.engine=null)}},[P]);let L=r?u(r.file):void 0,R=jv(n?.id??null,r,L?.size??null,L?b_(L):void 0,r?.duration??a),ne=r!==null&&!R.silent&&(R.known||_);W(()=>{ne||C(null)},[ne]),W(()=>C(null),[r?.id]);let re={vo:!1,music:!1,sfx:!1};for(let e of h)re[e.lane]=e.clip!==null;let ie=_?$t(re,ee):[],ae=Pr(()=>JSON.stringify({want:ie,film:d,levels:T,clips:g.map(e=>[e.path,e.rev??``])}),[ie.join(`
|
|
63
|
+
`),d,T,g]),[oe,se]=H({kind:`waiting`}),[ce,le]=H(!1),[ue,de]=H(0),fe=G(0);U(()=>{let e=++fe.current;if(ie.length===0){se({kind:`empty`}),le(!1);return}se(e=>e.kind===`empty`||e.kind===`timeout`||e.kind===`error`?{kind:`waiting`}:e),le(!0);let t=window.setTimeout(()=>{K.post(`/api/mix/loudness`,{lanes:ie,video:d}).then(t=>{e===fe.current&&se({kind:`result`,result:t})},t=>{e===fe.current&&se({kind:t instanceof Gr&&t.status===504?`timeout`:`error`})}).finally(()=>{e===fe.current&&le(!1)})},500);return()=>window.clearTimeout(t)},[ae,ue]),U(()=>()=>void++fe.current,[]);let pe=Pr(()=>({music:Dt(m,`music`),sfx:Dt(m,`sfx`)}),[m]),me=e=>pe[e].filter(t=>Kt(p,e,t)&&!u(t.file)?.missing),z={variants:pe,heard:{vo:re.vo,music:me(`music`),sfx:me(`sfx`)}},he=e=>{if(e.on===null||e.stage!==`voice`&&e.stage!==`music`&&e.stage!==`sfx`)return null;let t=e.on;return te.find(n=>n.take&&Qt[n.lane]===e.stage&&(t===nb(n.take)||t.startsWith(`${nb(n.take)}:`)))??null};return{rows:te,media:N,view:v,toggle:b,levels:D,setLevel:j,inUse:_,cut:{shown:ne,wave:R.wave,known:R.known},cutMuted:w,toggleCut:()=>C(!w),videoMuted:w||I,loudness:{state:oe,measuring:ce,retry:()=>de(e=>e+1)},noteLabel:e=>{if(e.stage===`mix`)return rn(z,e.on);let t=he(e);return t?`${eb[t.lane]} · ${t.take.variant.name}`:null},noteRow:e=>{if(e.stage===`mix`){let t=tn(z,e.on);return t===null||t===`mix`?null:t}return he(e)?.lane??null},engine:P,length:F}}var ab={vo:`var(--vo)`,music:`var(--music)`,sfx:`var(--sfx)`};function ob({mix:e,duration:t,t:n,onSeek:r,notes:i=[],view:a,rowStyle:o,sizer:s}){let c=a??Mm(t),l=e=>Pm(e,c),u=e=>{let n=e.currentTarget.getBoundingClientRect();return n.width>0?Math.min(t,Math.max(0,Fm((e.clientX-n.left)/n.width,c))):null},d=e=>{let t=u(e);t!==null&&r(t)},{shown:f,api:p}=Q_(),[m,h]=H(0);return Q(w,{children:[e.rows.map(a=>{let u=eb[a.lane],f=a.take,g=a.clip?e.media[y_(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`?B_(f.variant.cues):[],x=Y_(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":ab[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:6,step:.5,value:e.levels[a.lane],"aria-label":`${u} level`,"aria-valuetext":`${sn(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:[sn(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(lv,{segments:[{offset:0,duration:_?.duration??0,peaks:_?_.peaks:null}],length:c.end-c.start,from:c.start,color:ab[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:V_(e),t:e.t,n:t+1,of:b.length,file:e.file??null,color:ab.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":H_(e),"aria-describedby":i?Z_:void 0,style:{left:`${l(e.t)}%`,color:ab.sfx},...$_(p,n),onFocus:e=>{h(t),p.show(e.currentTarget,n)},onBlur:()=>p.hide(),onKeyDown:e=>nv(e,`button.cue`,p),onClick:t=>{t.stopPropagation(),r(e.t)},children:Q(`span`,{children:V_(e)})},`c${x[t]}:${e.t}:${e.name}`)}),S.map(e=>e.tOut===null?Q(`span`,{class:`mk ${im(e)}`,"data-note":e.id,title:Om(im(e),e.text),style:{left:`${l(e.t)}%`}},e.id):Q(`span`,{class:`span ${im(e)}`,"data-note":e.id,title:Om(im(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(Fv,{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(ev,{shown:f,onHide:p.hide})]})}function sb({loudness:e}){let t=e.state.kind===`timeout`||e.state.kind===`error`;return Q(`div`,{class:`tloud${t?` retry`:``}`,role:`group`,"aria-label":`Loudness`,"aria-busy":e.measuring,onClick:t?e.retry:void 0,children:[un(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:cb[e.id]??e.label})]})),e.measuring&&Q(`span`,{class:`measuring`,"data-measuring":!0,"data-tip":`Measuring`,"aria-label":`Measuring`,children:Q($,{name:`gauge`})}),t&&!e.measuring&&Q(`button`,{type:`button`,class:`btn ghost ib sm`,"data-tip":`Measure again`,"aria-label":`Measure again`,children:Q($,{name:`gauge`})})]})}var cb={integrated:`LUFS`,truePeak:`dBTP`,musicUnderVo:`under VO`},lb=[{value:`frame`,label:`This frame`},{value:`mix`,label:`The whole mix`}],ub=e=>e instanceof HTMLElement&&(e.isContentEditable||/^(INPUT|TEXTAREA|SELECT)$/.test(e.tagName));function db({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},[]),iy(c,e.id,()=>k.current&&qe.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,L=!I||I.primary,R=I??v.find(e=>e.primary)??null,ne=R?R.width/R.height:null,re=y!==null&&v.length>=2,ie=v.find(e=>e.primary)?.id??null,ae=Yn(r,y),oe=Xn(r,y),[se,ce]=H(`this`),[le,ue]=H(ne??16/9),[de,fe]=H(!1),[pe,me]=H(null),[z,he]=H({in:null,out:null}),[ge,_e]=H(!1),[ve,ye]=H(null),[xe,Se]=H({w:0,h:0}),[ke,B]=H(null),[Ae,je]=H(null),[Me,Ne]=H(!1),[Pe,Fe]=H(!1),[Ie,Le]=H(`frame`),V=()=>Le(`frame`),Re=Qg(M),[ze,Be]=fy(),Ve=py(),He=Ey(),Ue=Dy(F,N,t.id),We=G(null),Ge=G(null),Ke=G(!1),qe=G(!1),Je=G(!0);U(()=>()=>{Je.current=!1},[]);let Ye=G(t.id);U(()=>{Ye.current=t.id},[t.id]),U(()=>{let e=!T&&(z.in!==null||ke!==null||Me);return o?.(e),()=>o?.(!1)},[z.in,ke,Me,T]),W(()=>(s?.(!T&&(z.in!==null||ke!==null)),()=>s?.(!1)),[z.in,ke,T]),U(()=>(ke!==null&&ce(`this`),S?.(ke!==null),()=>S?.(!1)),[ke]);let Xe=G(void 0);U(()=>{me(null),P(0),ue(ne??16/9),he({in:null,out:null}),B(null),Xe.current!==void 0&&d(e.id,null),Xe.current=t.file,je(null),ce(`this`)},[t.file]);let Ze=ke?`this`:se,Qe=n=>be(e.versions.find(e=>e.id===n.version)??t),[nt,rt]=H({}),it=e=>e.id in nt?nt[e.id]:e.format,at=e=>rt(t=>{if(!(e in t))return t;let{[e]:n,...r}=t;return r});U(()=>{rt(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 ot=async(e,t)=>{if(it(e)!==t){rt(n=>({...n,[e.id]:t}));try{await K.patch(`/api/notes/${e.id}`,{format:t})}catch(t){at(e.id),st.current?.id===e.id&&(st.current=null),i(`Couldn't change that note: ${t.message}`)}a()}};U(()=>{Ae&&!ae.some(e=>e.id===Ae)&&je(null)},[y,r]);let st=G(null),ct=G(y);if(ct.current!==y){ct.current=y;let e=document.activeElement,t=e instanceof HTMLElement&&e.closest(`.nfmt`)?e.closest(`.list > .note[data-note]`):null;t&&!st.current&&(st.current={id:t.dataset.note,fallback:!0})}W(()=>{let e=st.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?(st.current=null,n&&r.focus()):e.fallback&&(st.current=null,n&&document.querySelector(`.otherrow`)?.focus())},[y,r]);let lt=L&&!!t.proxy&&g!==`original`,ut=Zr(lt?t.proxy.file:L?t.file:I.file),dt=pe===ut,ft=G(null),pt=G(null);if(pt.current&&pt.current.src!==ut){let e=k.current;pt.current.cut===t.file?!ft.current&&e&&(ft.current={t:e.error?N:e.currentTime,play:!e.paused&&!e.error}):ft.current=null}pt.current={cut:t.file,src:ut};let gt=G(null),_t=G(null),vt=I?.id??`primary`,yt=G(!0);W(()=>{if(yt.current){yt.current=!1;return}let e=j.current;if(!R||!e)return;let t=R.width/R.height;if(t===le)return;let n=e.getBoundingClientRect();gt.current={width:n.width,height:n.height},ue(t)},[vt]),W(()=>{let e=gt.current,t=j.current;if(gt.current=null,!e||!t)return;_t.current?.cancel(),_t.current=null;let n=t.getBoundingClientRect(),r=typeof matchMedia==`function`&&matchMedia(`(prefers-reduced-motion: reduce)`).matches,i=Jn(e,{width:n.width,height:n.height},r);Ut(location.search).test&&(window.__rushesLastReshape={animated:i!==null,ms:i?160:0}),i&&(_t.current=t.animate(i,{duration:160,easing:`ease-out`}))},[le]),U(()=>{let e=k.current;if(!e)return;let t=()=>me(ut);return e.error&&t(),e.addEventListener(`error`,t),()=>e.removeEventListener(`error`,t)},[ut]);let bt=G(null);bt.current=!L&&F>0?F:null;let xt=e=>{let t=bt.current;t===null||e.paused||e.currentTime<t||(e.pause(),e.currentTime=t)};U(()=>{if(!de)return;let e=0,t=()=>{k.current&&(xt(k.current),P(k.current.currentTime)),e=requestAnimationFrame(t)};return e=requestAnimationFrame(t),()=>cancelAnimationFrame(e)},[de]);let St=()=>ft.current?.t??k.current?.currentTime??N,Ct=()=>Te(St(),n),wt=e=>{let t=k.current;if(!t)return;let n=Math.min(Math.max(0,e),F||t.duration||e);if(ft.current){ft.current.t=n,P(n);return}t.currentTime=n,P(t.currentTime)},Tt=()=>{let e=k.current;e&&(e.paused?(bt.current!==null&&e.currentTime>=bt.current-.001&&(e.currentTime=0),e.play().catch(()=>i(`Couldn't play this file`))):e.pause())},Et=e=>{k.current?.pause(),wt(Ee(St(),n,e,F))},Dt=()=>he({in:Ct(),out:null}),Ot=()=>{let e=Ct(),t=z.in??0;if(e<=t)return i(`Out has to come after In`);he({in:t,out:e})},kt=()=>he({in:null,out:null}),At=z.in!==null&&z.out===null,jt=Pe?`note`:ge?`box`:At?`range`:`select`,Mt=()=>{_e(!1),V(),At&&kt(),M.current&&document.activeElement===M.current&&M.current.blur()},Nt=()=>At?Ot():Dt();U(()=>{let e=e=>Fe(!!M.current&&e.target===M.current),t=e=>{e.target===M.current&&Fe(!1)};return document.addEventListener(`focusin`,e),document.addEventListener(`focusout`,t),()=>{document.removeEventListener(`focusin`,e),document.removeEventListener(`focusout`,t)}},[]);let Pt=()=>{let e=We.current;e&&(document.fullscreenElement?document.exitFullscreen().catch(()=>void 0):e.requestFullscreen?.().catch(()=>i(`Couldn't go full screen`)))},Ft=ib({state:D,assets:O,video:e,version:t,player:k,duration:F,monitor:ze,toast:i,onChanged:a,keep:l}),It=u_(Ft,D.notes.notes,e);U(()=>{let e=k.current;e&&(e.volume=ze.level,e.muted=ze.muted||Ft.videoMuted)},[ze,Ft.videoMuted]);let Lt=G(0),[Rt,zt]=H(0),Bt=async()=>{let r=k.current,o=Ct(),s=e.id,c=t.id,l=L?null:y,u=++Lt.current,f=!1;try{let e=we(o,n),t;if(p){f=!0,zt(e=>e+1);let n=await Xr(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!==Lt.current){a();return}i(`Saved to ${m.grab}`),a(),Je.current&&c===Ye.current&&d(s,m.grab)}catch(e){u===Lt.current&&i(e.message)}finally{f&&Je.current&&zt(e=>e-1)}},Vt=e=>{let t=z.in!==null&&z.out!==null?{t:z.in,tOut:z.out}:null;return Ie===`mix`?t?{kind:`mix`,...t}:{kind:`mix`}:t?{kind:`range`,...t}:{kind:`frame`,t:e}},Wt=e=>{let t=Vt(e);return wm(t,$e(tn,t.kind===`frame`||t.kind===`range`?t.t:e),n)},Gt=async r=>{let i=Wt(Ct());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}),kt(),Le(`frame`),ce(`this`),B(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,...re?{format:Ze===`this`?y:null}:{}}),kt(),ce(`this`),B(null),d(e.id,null),a()},Kt=G(()=>void 0);Kt.current=e=>{if(ub(e.target)||e.metaKey||e.ctrlKey||e.altKey)return;let t=e.key.toLowerCase();if(e.key===` `){if(Ht(e.target))return;e.preventDefault(),Tt()}else if(e.key===`ArrowLeft`)e.preventDefault(),Et(e.shiftKey?-10:-1);else if(e.key===`ArrowRight`)e.preventDefault(),Et(e.shiftKey?10:1);else if(t===`v`)Mt();else if(e_(e))V();else if(t===`f`)e.preventDefault(),e.repeat||Pt();else if(e.key===`=`||e.key===`+`)e.preventDefault(),Ue.set(Lm(Ue.view,F,.5,N));else if(e.key===`-`||e.key===`_`)e.preventDefault(),Ue.set(Lm(Ue.view,F,2,N));else if(T&&/^[iogbn]$/.test(t))return;else t===`i`?Dt():t===`o`?Ot():t===`g`&&!e.repeat?Bt():t===`b`?_e(e=>!e):t===`n`&&(e.preventDefault(),Re())},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 mt(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(!ge)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=ht(ve.x0,ve.y0,t.x,t.y,ve.w,ve.h);ye(null),_e(!1),Ke.current=!0,n.w>.01&&n.h>.01&&B(n)},Qt=ve?ht(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=$e(tn,Te(N,n)),rn=[...ae,...It].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=Am(rn.map(({n:e,at:t})=>({...e,t:t.t,tOut:t.tOut})),F,Ue.view).map(e=>{let t=an.get(e.id),n=er(t,re);return{...e,ring:re&&t.format===null,title:n?`${n} · ${t.text}`:t.text}}),sn=e=>Pm(Math.min(F,Math.max(0,e)),Ue.view),cn=z.in===null?null:{left:sn(z.in),width:sn(z.out??z.in+.2)-sn(z.in)},ln=(e,t)=>{k.current?.pause(),wt(t),je(e.id)},un=ae.find(e=>e.id===Ae)??null,dn=un?.box&&(!un.version||un.version===t.id)&&Zn(un,y,ie)?un.box:null,fn=z.in===null?null:z.out===null?`${Ce(z.in)} →`:Oe(z.in,z.out),pn=Wt(Te(N,n)),mn=z.in!==null&&z.out===null?`Set an Out point`:pn.stage===`picture`?`Note at ${fn&&z.out!==null?fn:Ce(N)}`:`Note on ${pn.label}`,hn=e=>{te(L?e.duration||t.duration||0:t.duration??I?.duration??(e.duration||0)),L&&t.width===null&&e.videoWidth&&e.videoHeight&&x?.(t.file,e.videoWidth,e.videoHeight),me(e=>e===ut?null:e),e.videoWidth&&e.videoHeight&&ue(e.videoWidth/e.videoHeight),qe.current||(qe.current=!0,A.current&&(e.currentTime=Math.min(A.current,e.duration||A.current),P(e.currentTime)));let n=ft.current;n&&(ft.current=null,e.currentTime=Math.min(n.t,e.duration||n.t),P(n.t),n.play&&e.play().catch(()=>void 0))},gn=e=>jy(e,Ue,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:Ge,children:[Q(`div`,{class:`monitor`,ref:We,children:[Q(By,{active:jt,readOnly:T,grabbing:Rt>0,onSelect:Mt,onNote:Re,onRange:Nt,onBox:()=>_e(e=>!e),onGrab:()=>void Bt()}),Q(`div`,{class:`framebox`,children:[Q(`div`,{class:`fitbox`,children:Q(`div`,{class:`frame`,ref:j,style:{aspectRatio:String(le),"--ar":String(le)},children:[b&&!L&&Q(`div`,{class:`msg`,children:`File not found`}),dt&&!L&&!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.`}),dt&&L&&!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.`}),dt&&L&&p&&t.proxy&&!lt&&Q(`div`,{class:`msg`,children:`This file won't play in a browser.`}),Q(`video`,{hidden:dt||b&&!L,ref:e=>{k.current=e,f&&(f.current=e),e&&e.readyState>=1&&hn(e)},src:ut,preload:`auto`,playsInline:!0,onLoadedMetadata:e=>hn(e.target),onTimeUpdate:e=>{let t=e.target;xt(t),!de&&!ft.current&&P(t.currentTime)},onSeeked:e=>!ft.current&&P(e.target.currentTime),onPlay:()=>fe(!0),onPause:()=>fe(!1),onEnded:()=>fe(!1)}),Q(`div`,{ref:ee,class:`overlay${ge?` drawing`:``}`,onPointerDown:Yt,onPointerMove:Xt,onPointerUp:Zt,onClick:()=>{Ke.current?Ke.current=!1:ge||Tt()},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 ${et(nn.n)}`]}),t.proxy&&L&&Q(`div`,{class:`srcswitch`,role:`group`,"aria-label":`Which file plays`,children:[Q(`button`,{type:`button`,class:`tip-below tip-start tip-wrap`,"aria-pressed":lt,"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":!lt,"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(m_,{hidden:!L,video:e,version:t,ffmpeg:p,job:m,broken:dt&&!lt,duration:F,toast:i,onChanged:a,noteProxyJob:h},t.id)]})]}),Q(vy,{t:N,duration:F,playing:de,onToggle:Tt,onStep:Et,rangeLabel:fn,onClearRange:kt,volume:ze.level,muted:ze.muted,onVolume:e=>Be({level:e,muted:e===0&&ze.muted}),onMute:()=>Be({...ze,muted:!ze.muted}),onFullScreen:Pt,loudness:Ft.inUse?Q(sb,{loudness:Ft.loudness}):null}),Q(_y,{column:Ge,split:Ve}),Q(`div`,{..._n(gy(Ve.split??.4),`deskpanel${Ue.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":He.heights===null,onClick:e=>{e.detail>0&&e.currentTarget.blur(),He.fit()},children:Q($,{name:`fitrows`})})}),Q(v_,{duration:F,t:N,marks:on,live:cn,view:Ue.view,onSeek:wt,onMark:e=>{let t=rn.find(({n:t})=>t.id===e);t&&ln(t.n,t.at.t)}})]}),Q(`div`,{id:`tltracks`,class:`tracks${He.heights===null?` fitted`:``}`,ref:He.box,children:[Q(ob,{mix:Ft,duration:F,t:N,onSeek:wt,notes:[...ae,...It],view:Ue.view,rowStyle:He.style,sizer:e=>Q(ky,{row:e,name:e===`vo`?`Voice`:e===`music`?`Music`:e===`sfx`?`Effects`:`Cut sound`,tracks:He})}),Q(h_,{shots:tn,duration:F,t:N,current:nn?.n??null,cutLabel:sp(t)||t.id,locked:e.lockedVersion===t.id,onSeek:e=>{k.current?.pause(),wt(tt(e,n))},view:Ue.view,style:He.style(`picture`),sizer:Q(ky,{row:`picture`,name:`Picture`,tracks:He})})]}),Q(Ay,{tv:Ue,duration:F,t:N})]})]}),Q(l_,{readOnly:T,notes:[...ae,...It],version:t.id,selectedId:Ae,placeholder:mn,inputRef:M,toast:i,onAdd:Gt,onChanged:a,onTextChange:Ne,onLabel:Ft.noteLabel,target:{label:pn.label,when:pn.when,name:pn.name,menu:{value:Ie,options:lb,onChange:e=>Le(e===`mix`?`mix`:`frame`)},onClear:Ie===`mix`?V:void 0},formatTag:e=>er(e,re),cardExtra:re&&I?e=>Q(xg,{name:`Note applies to`,label:I.label,width:I.width,height:I.height,value:it(e)===null?`all`:`this`,lockedReason:e.box?Qn:null,onChange:t=>void ot(e,t===`all`?null:I.id)}):void 0,formatScope:re&&I?{label:I.label,width:I.width,height:I.height,value:Ze,onChange:ce,lockedReason:ke?Qn:null,hint:$n(I.label,Ze,ke!==null)}:void 0,listFooter:e=>{let n=oe.filter(t=>e===`all`||t.status===e);return n.length>0?Q(d_,{notes:n,version:t.id,viewsHere:v,ownViews:Qe,onShow:(e,t)=>{ke||(st.current={id:t.id,fallback:!1}),C?.(e)},onRestore:e=>{st.current={id:e.id,fallback:!1},ot(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:()=>B(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 fb=500,pb=(e,t)=>e.slice(0,t).filter(n=>n.heading===e[t].heading).length,mb=e=>String(e).padStart(2,`0`);function hb({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:Zr(e.still),alt:`Still for shot ${e.n}, ${e.name}`,onError:()=>r(e.still)})}function gb({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=ig(()=>{s.current=!1,c()},fb),u=ig(()=>{s.current=!1,c()},fb),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(hb,{shot:e})}),Q(`div`,{class:`sbmeta`,children:[Q(`b`,{children:mb(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(lg,{label:`Your version of shot ${e.n}`,value:r,onInput:e=>{s.current=!0,i(e),l.schedule()},onBlur:()=>l.flush()}),f&&Q(ug,{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 _b({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(hb,{shot:e,large:!0})}),Q(`div`,{class:`sblcap`,children:[Q(`b`,{children:[mb(e.n),` · `,e.name]}),` `,e.tag&&Q(`span`,{class:`sbtag`,children:e.tag}),Q(`p`,{children:e.description})]})]})})}function vb({board:e,brief:t,toast:n,onChanged:r,settle:i}){let{latest:a,enqueue:o}=rg(`storyboard`,e,{toast:n,onChanged:r,settle:i}),[s,c]=H(null),l=G(null),u={shot:(e,t)=>{let n=a.current.shots.findIndex(t=>t.index===e.index),r=n<0?0:pb(a.current.shots,n),i=t.status===`approved`&&t.description===void 0&&t.direction===void 0;o(`shot ${e.n}`,(n,a)=>{let o=n.shots.filter(t=>t.heading===e.heading)[r];if(!o){let t=n.shots.filter(t=>t.name===e.name);t.length===1&&(o=t[0])}return o&&a&&i&&(o.description!==e.description||o.direction!==e.direction)?{refuse:`the agent changed this shot while you were looking at it. Read it again, then approve.`}:o?{path:`/api/storyboard/shots/${o.index}`,body:{heading:o.heading,...t}}:null})}},d=Ye(t),f=e.shots.find(e=>e.heading===s);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:d?`${e.plannedLength.toFixed(1)} / ${d} s planned`:`${e.plannedLength.toFixed(1)} s planned`}),d&&Q(`span`,{class:`bar`,children:Q(`i`,{style:{width:`${Math.min(100,e.plannedLength/d*100)}%`}})})]}),e.total===0&&Q(`p`,{class:`sbnone`,children:"storyboard.md has no shots yet. Your agent adds them as `## Shot 01 · Name` sections."}),Q(`div`,{class:`prows`,children:e.shots.map((t,n)=>Q(gb,{shot:t,save:u,onZoom:()=>{l.current=document.activeElement,c(t.heading)}},`${t.heading}#${pb(e.shots,n)}`))}),Q(dg,{counts:e.total>0?{approved:fg(e.approved,e.total,`shot`),edited:e.changed}:null}),f&&Q(_b,{shot:f,onClose:()=>{c(null),l.current?.focus()}})]})}var yb={approved:{color:`var(--done)`,label:`Approved`},flagged:{color:`var(--todo)`,label:`Flagged`},draft:{color:`var(--text-3)`,label:`Draft`}},bb=500,xb=am;function Sb({section:e,wps:t,toast:n,onChanged:r,onPick:i}){let[a,o]=H(e.proposed??e.current),[s,c]=H(e.direction),l=G(!1);U(()=>{l.current||o(e.proposed??e.current)},[e.proposed,e.current]),U(()=>{l.current||c(e.direction)},[e.direction]);let u=async t=>{try{await K.patch(`/api/script/${encodeURIComponent(e.id)}`,t)}catch(t){n(`Couldn't save ${e.id.toUpperCase()}: ${t.message}`)}r()},d=ig(()=>{l.current=!1,u({proposed:a.trim()===e.current.trim()?null:a})},bb),f=ig(()=>{l.current=!1,u({direction:s})},bb),p=e.end-e.start,m=ke(a,p,t),h=a.trim()!==e.current.trim(),g=yb[e.status];return Q(`div`,{class:`srow${h?` changed`:``}`,"data-section":e.id,onFocusIn:()=>i?.({id:e.id,label:xb(e)}),onClick:()=>i?.({id:e.id,label:xb(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":g.label,"data-tip":g.label,title:g.label,children:Q(`i`,{style:{background:g.color}})})]}),Q(`div`,{class:`pbody`,children:[Q(lg,{label:`Your version of ${e.id}`,value:a,onInput:e=>{l.current=!0,o(e),d.schedule()},onBlur:()=>d.flush()}),h&&Q(ug,{baseline:[{text:e.current}],revertLabel:`Revert`,onRevert:()=>{l.current=!1,o(e.current),u({proposed:null})}})]})]}),Q(`div`,{class:`sfoot`,children:[Q(`div`,{class:`fit${m.state===`ok`?``:` ${m.state}`}`,title:`${m.words} words · ${m.seconds.toFixed(1)} s of ${p.toFixed(1)} s`,children:Q(`i`,{style:{width:`${Math.min(100,m.ratio*100)}%`}})}),Q(`input`,{class:`dirin`,placeholder:`Direction`,"aria-label":`Direction for ${e.id}`,value:s,onInput:e=>{l.current=!0,c(e.target.value),f.schedule()},onBlur:()=>f.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 u({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 u({status:e.status===`approved`?`draft`:`approved`}),children:Q($,{name:`check`})})]})]})]})}function Cb({script:e,toast:t,onChanged:n,onPickLine:r}){let i=e.sections.filter(B).length,a=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(i=>Q(Sb,{section:i,wps:e.wordsPerSecond,toast:t,onChanged:n,onPick:r},i.id))}),Q(dg,{counts:e.sections.length>0?{approved:fg(a,e.sections.length,`line`),edited:i}:null})]})}var wb=Math.floor(Math.random()*2**31),Tb=!1,Eb=new Set,Db={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 Ob({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 kb({stage:e,state:t,assets:n,video:r,toast:i,onChanged:a,onPendingChange:o,clock:s,version:c}){let[l,u]=H(e===`music`&&Tb),d=e=>{Tb=e,u(e)},[,f]=H(0),p=Db[e],m=t.project.videos.length,h=ir(t.project.lanes,r?.id,m),g=nr(t.picks,r?.id),_=e=>m>1?Py(e,t.project.videos,r,i,a):void 0,v=Wy({stage:e,groups:hm(h,e,g.use?.[e],r??void 0),assets:n,blind:l?{seed:wb,word:`Bed`}:null,films:e=>_(Gy(e))}),y=r?Dt(ar(t.project.lanes,r.id,m),e):[],b=Dt(h,e),x=jt(b,e=>v.nameOf(e.key)??e.name,e===`sfx`),S=c??je(r??void 0),C=r&&S?{video:r.id,version:S,locked:r.lockedVersion===S.id}:null;return Q($y,{stage:e,title:p.title,film:r?.id??null,readOnly:!!r?.shelved,list:v,loose:{items:y.map(e=>({key:e.key,name:e.name,meta:e.meta,films:_(e),none:e.films.length===0})),what:y.length===1?p.one:p.many},headerExtra:e===`music`?Q(Ob,{on:l,onToggle:()=>d(!l)}):void 0,preview:C,prompt:Re(`picture`,t.project.name,r?.name??null),fps:S?.fps??(t.project.fps||30),notes:or(t.notes.notes,e,r?.id),noteRow:e=>Ft(b,e.on),onLabel:e=>It(b,x,e.on),targetName:(e,t)=>t===null?e.name:x.find(n=>n.value===`c:${e.key}:${t}`)?.label??e.name,rangeMarks:!0,wholeLabel:`The whole ${p.one}`,none:p.none,layers:e===`sfx`?{open:e=>Eb.has(e),toggle:e=>{Eb.has(e)?Eb.delete(e):Eb.add(e),f(e=>e+1)}}:void 0,toast:i,onChanged:a,onPendingChange:o,clock:s})}var Ab=Math.floor(Math.random()*2**31),jb=!1;function Mb({state:e,assets:t,video:n,toast:r,onChanged:i,onPendingChange:a,clock:o,version:s}){let[c,l]=H(jb),u=e=>{jb=e,l(e)},d=e.project.videos.length,f=ir(e.project.lanes,n?.id,d),p=nr(e.picks,n?.id),m=t=>d>1?Py(t,e.project.videos,n,r,i):void 0,h=Wy({stage:`voice`,groups:hm(f,`voice`,p.use?.voice,n??void 0),assets:t,blind:c?{seed:Ab,word:`Read`}:null,films:e=>m(Gy(e))}),g=e=>h.nameOf(e.key)??e.name,_=n?Dt(ar(e.project.lanes,n.id,d),`voice`):[],v={rounds:Gt(f,p.lanes),sections:e.script.sections},y=s??je(n??void 0),b=n&&y?{video:n.id,version:y,locked:n.lockedVersion===y.id}:null;return Q($y,{stage:`voice`,title:`Voice`,film:n?.id??null,readOnly:!!n?.shelved,list:h,loose:{items:_.map(e=>({key:e.key,name:`${e.laneName} · ${e.name}`,meta:e.meta,films:m(e),none:e.films.length===0})),what:_.length===1?`read`:`reads`},headerExtra:Q(Ob,{on:c,onToggle:()=>u(!c)}),preview:b,prompt:Re(`picture`,e.project.name,n?.name??null),fps:y?.fps??(e.project.fps||30),notes:or(e.notes.notes,`voice`,n?.id),noteRow:e=>Yt(v,e),onLabel:e=>Xt(v,e.on,g),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,clock:o})}function Nb(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 Pb=e=>e.map(e=>e?`1`:`0`).join(``),Fb={100:`left third`,"010":`centre`,"001":`right third`,110:`left two thirds`,"011":`right two thirds`,111:`full width`,101:`full width`},Ib={100:`top third`,"010":`middle`,"001":`bottom third`,110:`top two thirds`,"011":`bottom two thirds`,111:`full height`,101:`full height`};function Lb(e){let t=Pb(Nb(e.x,e.w)),n=Pb(Nb(e.y,e.h));return t===`111`&&n===`111`?`the whole picture`:t===`010`&&n===`010`?`the centre`:`${Fb[t]}, ${Ib[n]}`}function Rb(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 zb(e,t,n=8){return Math.min(Math.max(0,e-1),Math.max(0,t-n))}var Bb=e=>Math.round(e*1e4)/1e4,Vb=e=>Bb(Math.max(0,Math.min(1,e))),Hb=.02;function Ub(e,t,n){if(!n)return{pin:{x:Vb(e.x),y:Vb(e.y)}};let[r,i,a,o]=[Vb(e.x),Vb(e.y),Vb(t.x),Vb(t.y)],s={x:Math.min(r,a),y:Math.min(i,o),w:Bb(Math.abs(a-r)),h:Bb(Math.abs(o-i))};return s.w<Hb||s.h<Hb?null:{box:s}}var Wb=e=>e.versions[e.versions.length-1];function Gb(e){let t=Wb(e);return{page:1,ratio:t.pages[0]?.images[0]?.ratio??``,ver:t.id}}function Kb(e,t){let{ver:n,...r}=t;return n===Wb(e).id?r:{...r,ver:n,since:Wb(e).id}}function qb(e,t){let{ver:n,since:r,...i}=t??{},a=n!==void 0&&r===Wb(e).id;return{...Gb(e),...i,...a?{ver:n}:{}}}var Jb=(e,t)=>t.ver===Wb(e).id;function Yb(e,t){return[e.name,e.kind===`carousel`?`page ${t.page}`:null,ve(t.ratio),t.ver].filter(Boolean).join(` · `)}var Xb=e=>(e.on??``).slice(0,(e.on??``).lastIndexOf(`/`)),Zb=e=>Number((e.on??``).slice((e.on??``).lastIndexOf(`/`)+1))||0;function Qb(e,t){return e.filter(e=>e.stage===`visuals`&&Xb(e)===Xb(t)).findIndex(e=>e.id===t.id)+1}function $b(e,t){let n=t.filter(e=>e.stage===`visuals`),r=[...e.map(e=>e.id),...new Set(n.map(Xb).filter(t=>!e.some(e=>e.id===t)))],i=[];for(let t of r){let r=n.filter(e=>Xb(e)===t);if(r.length===0)continue;let a=e.find(e=>e.id===t),o=[...new Set(r.map(Zb))].sort((e,t)=>e-t).map(e=>({page:e,notes:r.filter(t=>Zb(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 ex(e,t,n){return e.filter(e=>e.stage===`visuals`&&Xb(e)===t&&Zb(e)===n.page&&e.format===n.ratio&&e.version===n.ver&&(e.box!==null||e.pin!==null))}function tx(e,t){let n={};for(let r of e)r.stage===`visuals`&&r.status===`todo`&&Xb(r)===t&&(n[Zb(r)]=(n[Zb(r)]??0)+1);return n}function nx(e,t,n){return{page:Zb(t),ratio:t.format??n.ratio,ver:t.version??n.ver}}function rx(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 ix=e=>e instanceof HTMLElement&&(e.isContentEditable||/^(INPUT|TEXTAREA|SELECT)$/.test(e.tagName));function ax(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 ox({notes:e,all:t,selected:n,draft:r}){return Q(w,{children:[e.map(e=>{let r=Qb(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`&&Xb(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`&&Xb(e)===r.vis).length+1})})]})}function sx({file:e,alt:t,onBad:n}){return Q(`img`,{src:Zr(e),alt:t,draggable:!1,onError:n})}function cx({visual:e,view:t,badges:n,onPage:r}){let i=e.versions.find(e=>e.id===t.ver)??Wb(e),a=G(null);W(()=>{let e=a.current;if(!e||e.children.length===0)return;let n=e.children[zb(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:Zr(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 lx({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)??Wb(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:_}=ax({w:m.width,h:m.height}),[v,y]=H(null),b=ex(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=!Jb(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===Wb(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":`${Yb(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(sx,{file:m.file,alt:`${e.name}, page ${t.page}`,onBad:()=>y(m.file)},m.file),Q(ox,{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(cx,{visual:e,view:t,badges:tx(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 ux({visual:e,view:t,notes:n,onPage:r,onClose:i}){let a=e.versions.find(e=>e.id===t.ver)??Wb(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}=ax({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(sx,{file:s.file,alt:`${e.name}, page ${t.page}`,onBad:()=>void 0},s.file),Q(ox,{notes:ex(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 dx({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=>qb(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)??Wb(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]:Kb(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(!Jb(r,a))return t(`You're looking at ${a.ver}. Switch to the newest version to add notes.`);let s=rx(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:Ub(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=Ub(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(!Jb(x,e))return t(`You're looking at ${e.ver}. Switch to the newest version to add notes.`);let n=rx(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(!Jb(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 Gr,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===Xb(e));t&&(p(e.id),S(t,nx(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(ix(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=fx(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=$b(i,a),L=a.filter(e=>e.stage===`visuals`&&e.status===`todo`).length,R=new Set(a.filter(e=>e.stage===`visuals`&&e.status===`todo`).map(Xb)).size,ne=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(lx,{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:[L,` open across `,R,` visual`,R===1?``:`s`]})]}),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!==Wb(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:Qb(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?Lb(t.box):t.pin?Rb(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,{...nx(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?Yb(E,u):Yb(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`})]})]})]}),ne&&Q(ux,{visual:ne,view:b(ne),notes:a,onPage:e=>S(ne,{page:e}),onClose:()=>h(null)})]})}function fx(e,t){return(e.versions.find(e=>e.id===t.ver)??Wb(e)).pages[0]?.images.map(e=>e.ratio)??[]}var px=()=>{try{return window.sessionStorage}catch{return}},mx=()=>{try{return window.localStorage}catch{return}};function hx(e,t,n){let[r,i]=H(()=>Hg(px(),Vg(e,`log-open`))===`1`),[a,o]=H(!1),[s,c]=H(()=>Hg(mx(),Vg(e,`log-seen`))),l=t?.mark??null,u=G(s);u.current=s;let d=t=>{c(t),Ug(mx(),Vg(e,`log-seen`),t)},f=n(r);return U(()=>{f&&l&&Bg(l,s)&&d(l)},[f,l]),U(()=>{let t=Vg(e,`log-seen`),n=e=>{e.key===t&&e.newValue&&c(e.newValue)};return window.addEventListener(`storage`,n),()=>window.removeEventListener(`storage`,n)},[e]),{open:r,focusOnOpen:a,dot:!f&&Bg(l,s),setOpen:(t,n=t)=>{i(t),o(t&&n),Ug(px(),Vg(e,`log-open`),t?`1`:`0`)},saw:e=>{Bg(e,u.current)&&d(e)},focused:()=>o(!1)}}function gx(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 _x=700,vx=16,yx=()=>typeof matchMedia==`function`&&matchMedia(`(hover: none)`).matches;function bx({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=Lr(),O=new Date,k=sp(t),A=e=>{f(e),m(null),v(null),g(yx()),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-vx;b(Math.max(0,Math.min(e.left+t.width-n,e.left-vx)))};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<_x?E.current.text+e.key:e.key;E.current={text:t,at:e.timeStamp};let n=dh(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":xx(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:sp(e)}),Q(`span`,{class:`vwhen`,children:[e.id===n&&Q($,{name:`lock`}),lh(e.addedAt,O)]}),h&&_===e.id&&Q(`span`,{class:`vinline`,dir:`auto`,children:[Jf(e.note)||`No note.`,Q(`span`,{class:`vmeta`,children:ph(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(Sx,{note:I.note}),Q(`span`,{class:`vmeta`,children:ph(I,O)})]})]})]})}function xx(e,t,n){return[e.id,sp(e),e.id===t?`locked`:``,uh(e.addedAt,n)].filter(Boolean).join(`, `)}function Sx({note:e}){if(!Jf(e))return Q(`p`,{dir:`auto`,children:`No note.`});let{lead:t,points:n}=mh(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 Cx({video:e,shown:t,newer:n,onPick:r,onToggleLock:i}){let a=!!e.lockedVersion;return Q(bx,{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]})]})})}var wx=700;function Tx(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=e=>{r(!1),e&&o.current?.focus()},d=(t=0)=>{a(Math.max(0,Math.min(e-1,t))),l.current={text:``,at:-1/0},r(!0)};return My(n,s,u),W(()=>{n&&c.current[i]?.focus()},[n,i]),{open:n,show:d,close:u,toggle:e=>n?u(!1):d(e),row:e=>t=>{c.current[e]=t},onKeyDown:n=>{if(n.key===`Tab`)return u(!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,d=n.key===`Home`?`ArrowDown`:n.key===`End`?`ArrowUp`:n.key;for(let t=0;o!==null&&t<e&&s(o);t++)o=fh(d,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<wx?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())}},button:o,wrap:s}}function Ex({films:e,currentId:t,openNotes:n,onSwitch:r,onRestore:i,shelvedRequest:a}){let o=e.filter(Me),s=e.filter(e=>!Me(e)),c=e.find(e=>e.id===t),l=Tx(o.length+s.length*2,e=>{if(/^\d+$/.test(e)){let t=dh(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`,` · `,mm(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 Dx({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 `,mm(e.shelved),`. View only.`]}),Q(`span`,{class:`sp`}),Q(`button`,{type:`button`,class:`btn`,onClick:t,children:[Q($,{name:`undo`}),`Restore film`]})]})}function Ox({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 kx({found:e,onBringIn:t,video:n,onToggleShelved:r,autoProxy:i,onKeys:a,toast:o,onChanged:s}){let c=Tx(6),l=!!n?.shelved,[u,d]=H(()=>ur(mr())),f=()=>{let e=fr(u);hr(e),_r(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: `,pr[u]]})]})]})]})}function Ax({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 jx({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()};My(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(yg,{prompt:t,toast:n,copyRef:s,onClick:()=>c(!0)})})]})}function Mx({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(jx,{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 Nx=96,Px=e=>e?Math.max(0,e.scrollWidth-e.clientWidth):0;function Fx(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-Nx:0)+Px(t.querySelector(`.pname`))+Px(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 Ix({barRef:e,project:t,projectId:n,film:r,cut:i,workspaces:a,notesToggle:o,more:s}){let c=G(null);return Fx(c,e),Q(`header`,{class:`top`,ref:e,children:[Q(`div`,{class:`tleft`,ref:c,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]})]})}function Lx({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 ${Ie.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 Rx=new Set([`picture`,`voice`,`music`,`sfx`,`mix`]),zx=[{view:`picture`,label:`Timeline`},{view:`voice`,label:`Voice`},{view:`music`,label:`Music`},{view:`sfx`,label:`Effects`}],Bx=e=>e instanceof HTMLElement&&(e.isContentEditable||/^(INPUT|TEXTAREA|SELECT)$/.test(e.tagName));function Vx({tab:e,projectName:t,filmName:n,found:r,onReview:i,toast:a}){let o=e===`brief`||e===`storyboard`,{what:s,unlocks:c}=e===`brief`?He:e===`storyboard`?Ue:Ie[e],l=e===`assets`?`Assets`:e===`brief`?`Brief`:e===`storyboard`?`Storyboard`:Fe[e],u=e===`assets`?`grid`:e===`brief`?`brief`:e===`storyboard`?`story`:vh[e],d=e===`brief`?We(t,n):e===`storyboard`?Ge(t,n):Re(e,t,n),f=o?null:Tn(e,r),p=G(null),m=async()=>{try{await navigator.clipboard.writeText(d),a(`Prompt copied`)}catch{p.current?.select(),a(`Prompt selected: press ${bn(navigator.platform)}`)}};return Q(`div`,{class:`emptypage locked`,children:[Q($,{name:u}),Q(`h2`,{children:l}),Q(`p`,{children:s}),Q(`p`,{children:c}),Q(`textarea`,{class:`promptbox mono`,readOnly:!0,rows:4,ref:p,value:d,"aria-label":`Prompt for your agent`}),Q(`button`,{class:`btn primary`,onClick:()=>void m(),children:[Q($,{name:`copy`}),`Copy prompt for your agent`]}),f&&Q(`p`,{class:`foundline`,children:[Q(`span`,{children:f.text}),Q(`button`,{type:`button`,class:`btn`,"aria-label":f.review,onClick:()=>i(f.kind),children:`Review`})]})]})}function Hx({onPendingChange:e,...t}){return U(()=>()=>e(!1),[]),Q(l_,{...t,onTextChange:e})}function Ux(){let{state:e,assets:t,problem:n,wrongProject:r,refresh:i,proxyJobs:a,noteProxyJob:o}=Xm(),[s,c]=H(null),[l,u]=H(null),[d,f]=H(null),[p,m]=H(null),[h,g]=H(null),[_,v]=H(null),[y,b]=H(`script`),[x,S]=H(`picture`),C=G(null),[w,T]=H(!1),[E,D]=H(!1),[O,k]=H(!1),[A,j]=H(!1),ee=G(new Map),M=G(null),N=G({at:e=>ee.current.get(e)??0,attach:(e,t)=>{let n={film:e,read:t};return M.current=n,()=>{ee.current.set(e,t()),M.current===n&&(M.current=null)}}}).current,P=G(null),[F,te]=H({}),I=G(void 0),L=G(new Map),R=G(null),ne=(e,t)=>te(n=>({...n,[e]:t})),[re,ie]=H({}),ae=(e,t)=>ie(n=>({...n,[e]:t})),[oe,se]=H({}),[ce,le]=H({}),[ue,de]=H(!1),[fe,pe]=H(!1),me=G(new Set),z=(e,t=2400,n=null)=>{m(e),g(n),clearTimeout(I.current),I.current=window.setTimeout(()=>{m(null),g(null)},t)},[he,ge]=H({n:0,pending:!1}),[_e,ye]=H(null),xe=o_(),Se=!!s&&(um(s).workspace===`review`||um(s).workspace===`plan`),Ce=hx(Kr()??``,e?.log,e=>e&&Se&&xe.shown),[we,Te]=H(!1),Ee=G(null),De=G(null);W(()=>{let e=De.current;e&&(De.current=null,e())});let[Oe,ke]=H(null);U(()=>{for(let e of Object.values(a))e.state!==`failed`||me.current.has(e.job)||(me.current.add(e.job),z(e.reason??`Couldn't make the proxy`))},[a]),U(()=>{if(!e)return;if(s===null){let t=pm(Xe(e.tabs,e.brief));c(t),Be(t)&&b(t)}let t=e.project.videos.find(Me);l===null&&t&&u(t.id)},[e]),U(()=>{e?.project.name&&(document.title=`${e.project.name} · Rushes`)},[e?.project.name]);let B=e?.project.videos.find(e=>e.id===l)??e?.project.videos.find(Me),Fe=Ae(B),Le=je(B),V=B?.versions.find(e=>e.id===d)??Le,ze=!!B?.lockedVersion,We=V?.fps??e?.project.fps??30,Ge=e?.notes.notes.filter(e=>e.stage===`picture`&&(!e.video||e.video===B?.id))??[],Ye=V?be(V,ce[V.file]):[],Qe=B&&V?Bn(B,V.id):void 0,$e=Vn(Ye,B?oe[B.id]:void 0),et=new Set(t.filter(e=>e.kind===`cut`&&e.missing).map(e=>e.path)),tt=V?Hn({views:Ye,previous:Qe?be(Qe):[],current:$e,versionDuration:V.duration,notes:Ge,missing:et}):[],nt=e=>!B||e===$e?!1:ue?(z(`Add or clear your box on ${$e?ve($e):`this format`} first`),!1):(se(t=>({...t,[B.id]:e})),!0);U(()=>{O&&d===null&&Le?(f(Le.id),j(!0)):!O&&A&&d===Le?.id&&(f(null),j(!1))},[O,d,Le?.id]),U(()=>{!A&&d!==null&&d===Le?.id&&f(null)},[Le?.id,A,d]);let rt=Fe&&V&&Fe.id!==V.id&&(ze||A)?Fe.id:null,it=e=>{if(e===B?.id)return;if(B&&O)return z(`Add or clear your note on ${B.name} first`);if(B){R.current?.pause();let e=M.current;e&&e.film===B.id&&ee.current.set(B.id,e.read()),L.current.set(B.id,{versionId:d,held:A})}let t=L.current.get(e);P.current=null,u(e),f(t?.versionId??null),j(t?.held??!1)},at=async()=>{if(B&&V)try{await K.put(`/api/videos/${B.id}/lock`,{version:B.lockedVersion?null:V.id}),i()}catch(e){z(e.message)}},[ot,st]=H(0),ct=G(it);ct.current=it;let lt=async(t,n)=>{if(!e)return!1;if(n&&t.id===B?.id&&O)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=Pe(e.project.videos,t.id);n?it(n):u(null)}return i(),n?z(`“${t.name}” shelved`,6e3,{label:`Undo`,run:()=>void lt(t,!1).then(e=>e&&ct.current(t.id))}):z(`“${t.name}” restored`),!0}catch(e){return z(e.message),!1}},ut=()=>{B&<(B,!B.shelved)},dt=t=>{if(O)return z(`Add or clear your note first`);if(t.tab===`assets`)return vt();if(t.video&&t.video!==B?.id&&it(t.video),t.version){let n=e?.project.videos.find(e=>e.id===(t.video??B?.id));f(t.version===je(n)?.id?null:t.version),j(!1)}let n=pm(t.tab);c(n),um(n).workspace===`review`&&S(n),v(null),t.row&&gx(t.row)},ft=e?.tabs??[],pt=e=>ft.find(t=>t.stage===e),mt=En(e?.found),ht=t.length>0||mt!==null,gt=e=>{let t=pm(e);if(O&&t!==s)return z(`Add or clear your note first`);c(t),v(null),Be(t)&&b(t),um(t).workspace===`review`&&S(t)},_t=()=>{let t={brief:!!e?.brief.exists,script:!!pt(`script`)?.unlocked,storyboard:!!e?.storyboard.exists};gt(Ze(y,t))},vt=()=>{if(O&&s!==`assets`)return z(`Add or clear your note first`);c(`assets`),v(null)},yt=e=>{if(O&&s!==`assets`)return z(`Add or clear your note first`);ge(t=>({n:t.n+1,kind:e,pending:!0})),c(`assets`),v(null)},bt=G(yt);bt.current=yt,U(()=>{Ut(location.search).test&&(window.__rushesOpenFound=e=>bt.current(e))},[]),W(()=>{let t=t=>{if(t.altKey&&!t.metaKey&&!t.ctrlKey&&!t.shiftKey&&(t.key===`ArrowLeft`||t.key===`ArrowRight`)){if(s!==`picture`||Bx(t.target))return;t.preventDefault();let e=Un(tt,$e,t.key===`ArrowRight`?1:-1);e&&nt(e);return}if(Bx(t.target)||t.metaKey||t.ctrlKey||t.altKey)return;let n=fm(t.key,y);if(t.key===`1`?_t():n===`assets`?vt():n&>(n),t.key===`S`&&t.shiftKey&&!t.repeat&&ut(),(t.key===`[`||t.key===`]`)&&e){let n=Ne(e.project.videos,l,t.key===`]`?1:-1);n&&it(n)}t.key===`?`&&T(e=>!e),t.key===`\\`&&Se&&!t.repeat&&(t.preventDefault(),xe.toggle()),t.key===`Escape`&&(T(!1),v(null))};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)});let xt=G(null),St=G(null);W(()=>{let e=St.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&&!!s]);let Ct=async()=>{if(!e||!s)return;T(!1);let t=s===`brief`||s===`storyboard`?await C.current?.():void 0,n=(s===`brief`?t:void 0)??e.brief,r=(s===`storyboard`?t:void 0)??e.storyboard,a=[n.exists&&(s===`brief`||n.changed>0)?qe(e.project.name,B?.name??null,n):null,r.exists&&(s===`storyboard`||r.changed>0)?Je(e.project.name,B?.name??null,r):null].filter(e=>e!==null),o=null;try{o=(await K.post(`/api/batches`,{})).batch}catch(e){if(!(e instanceof Gr&&e.code===`empty_batch`))return z(e.message)}if(!o&&a.length===0)return s===`brief`&&!n.exists?z(`There's no brief yet: copy the prompt on this page for your agent`):s===`storyboard`&&!r.exists?z(`There's no storyboard yet: copy the prompt on this page for your agent`):z(`Nothing open to send on any tab`);v(o?{id:o.id,prompt:[o.prompt,...a].join(`
|
|
64
64
|
|
|
65
65
|
`)}:{id:`plan`,title:`Message for your agent`,prompt:a.join(`
|
|
66
66
|
|
|
67
|
-
`)}),D(!1),o&&i()},wt=async()=>{if(_)try{await navigator.clipboard.writeText(_.prompt),D(!0)}catch{z(`Couldn't reach the clipboard. Select the text and copy it.`)}};if(!e||!s)return Q(`div`,{class:`shell`,children:n?Q(`div`,{class:`banner`,children:[Q($,{name:`alert`}),n]}):Q(`div`,{class:`emptypage`,children:Q(`p`,{children:`Loading…`})})});let Tt=e.notes.notes.filter(e=>(e.stage===`picture`||e.stage===`mix`)&&(!e.video||e.video===B?.id)),Et=t=>e.notes.notes.filter(e=>e.status===`todo`&&gx.has(e.stage)&&(!e.video||e.video===t)).length,Dt=nr(e.picks,B?.id).use,Ot=e.notes.notes.filter(e=>e.stage===`mix`&&(!e.video||e.video===B?.id)),kt=!V&&(!!(Dt?.voice||Dt?.music||Dt?.sfx)||Ot.length>0)&&(!!B||e.project.videos.length===0),At=!!pt(`picture`)?.unlocked||kt,jt=s===`assets`?ht:s===`brief`?e.brief.exists:s===`storyboard`?e.storyboard.exists:s===`picture`?At:pt(s)?.unlocked??!1,Mt=!!pt(`picture`)?.unlocked,Nt=Ve(e.brief,e.script.sections,e.storyboard),Pt=Nt.brief===`ok`&&Nt.script===`ok`&&Nt.storyboard===`ok`,Ft=e.build.started&&!Mt,It=pt(`script`)?.todo??0,Lt=[{page:`brief`,name:`Brief`,icon:`brief`,unlocked:e.brief.exists,ask:He.ask,approved:Nt.brief===`ok`,open:e.brief.changed},{page:`script`,name:`Script`,icon:sh.script,unlocked:!!pt(`script`)?.unlocked,ask:Ie.script.ask,approved:Nt.script===`ok`,open:It},{page:`storyboard`,name:`Storyboard`,icon:`story`,unlocked:e.storyboard.exists,ask:Ue.ask,approved:Nt.storyboard===`ok`,open:e.storyboard.changed}],Rt=e.brief.changed+e.storyboard.changed+It,zt=async()=>{try{await navigator.clipboard.writeText(Ke(e.project.name,B?.name??null)),z(`Prompt copied`)}catch{z(`Couldn't reach the clipboard. Ask your agent to build the film from the approved plan.`)}},Bt=um(s),Vt=ir(e.project.lanes,B?.id,e.project.videos.length),Ht=Dt,Wt={voice:hm(Vt,`voice`,Ht?.voice,B),music:hm(Vt,`music`,Ht?.music,B),sfx:hm(Vt,`sfx`,Ht?.sfx,B)},Gt=new Set(e.project.videos.filter(Me).map(e=>e.id)),Kt={notes:e.notes.notes,inPlay:Gt,scriptTodo:pt(`script`)?.todo??0,briefChanged:e.brief.changed,storyboardChanged:e.storyboard.changed},qt=Dm(Kt),Jt=e.notes.notes.every(e=>e.stage===`script`||e.status!==`todo`||e.batch!==null||!!e.video&&!Gt.has(e.video))&&qt>0&&e.brief.changed+e.storyboard.changed+(pt(`script`)?.todo??0)>0?Be(s)?s:y:x,Yt=qt>0&&!Se?{text:`Send ${qt} ${Em(Kt)>0?qt===1?`change`:`changes`:qt===1?`note`:`notes`}`}:null,Xt=()=>{if(O)return z(`Add or clear your note first`);gt(Jt),xe.setShown(!0),Ce.setOpen(!1),Te(!0)},Zt=_x.map(({view:e,label:t})=>({view:e,label:t,icon:sh[e],locked:e===`picture`?!At:!pt(e)?.unlocked,ask:Ie[e].ask,takes:e===`voice`||e===`music`||e===`sfx`?bm(Wt[e]):null,todo:(pt(e)?.todo??0)+(e===`picture`?pt(`mix`)?.todo??0:0)})),Qt=Bt.workspace===`review`&&Zt.some(e=>!e.locked),$t=(Ye.find(e=>e.id===$e)??Ye.find(e=>e.primary)??Ye[0])?.label??null,en=mt!==null&&Dn(e.found)!==_e&&Cn(e.found?.counts)>0,tn={log:Ce,activity:{projectId:Kr()??``,head:e.log,project:e.project,stage:s===`brief`||s===`storyboard`?`script`:s,toast:z,onJump:e=>{dt(e),xe.narrow&&(xe.setShown(!1),Ee.current?.focus())}},send:{count:qt,always:s===`brief`&&e.brief.exists||s===`storyboard`&&e.storyboard.exists,onSend:()=>void Ct()},shown:xe.shown,narrow:xe.narrow,setShown:xe.setShown,width:xe.width,setWidth:xe.setWidth,reveal:we,onRevealed:()=>Te(!1),revealNotes:e=>{De.current=e,xe.setShown(!0),Ce.open?Ce.setOpen(!1,!1):xe.shown&&(De.current=null,e())}},nn=(e,t=Q(Qg,{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`,...Be(s)?{role:`tabpanel`,id:Jh,"aria-labelledby":Yh(s)}:{},children:e}),t]}),rn=e.notes.notes.filter(e=>e.stage===`script`),an=Oe&&s===`script`?wm({kind:`line`,...Oe},null):{stage:`script`,on:null,scope:`whole`,t:null,tOut:null,label:`The script`},on=s===`script`,sn=Q(bx,{notes:rn,version:null,placeholder:`Note on ${an.label}`,fixedTimes:!0,toast:z,onLabel:t=>t.on===null?`The script`:om(t,{project:e.project,script:e.script}),target:{label:an.label,onClear:Oe&&s===`script`?()=>ke(null):void 0},onAdd:async e=>{await K.post(`/api/notes`,{stage:`script`,video:null,version:null,on:an.on,scope:`whole`,t:null,tOut:null,text:e}),i()},onChanged:()=>void i(),onPendingChange:k,readOnly:!on,instead:on?void 0:`Notes on the plan are written on the Script page.`});return Q(Bg.Provider,{value:tn,children:Q(`div`,{class:`shell${Se&&!xe.narrow&&!xe.shown?` nhidden`:``}`,style:{"--notes-w":`${xe.width}px`},children:[Q(mx,{barRef:xt,project:e.project.name,projectId:e.project.id??null,film:e.project.videos.length>0?Q(ix,{films:e.project.videos,currentId:B?.id??null,openNotes:Et,onSwitch:it,onRestore:t=>{let n=e.project.videos.find(e=>e.id===t);n&<(n,!1)},shelvedRequest:ot}):null,cut:B&&V?Q(tx,{video:B,shown:V,newer:rt,onPick:e=>{if(fe)return z(`Add or clear your note first`);f(e===Le?.id?null:e),j(!1)},onToggleLock:()=>void at()}):null,workspaces:Q(hx,{current:Bt.workspace,plan:{approved:Pt,open:Rt,locked:Lt.every(e=>!e.unlocked)},hasVisuals:!!pt(`visuals`)?.unlocked,assetsUnlocked:ht,found:en?{count:Cn(e.found?.counts),text:mt}:null,onPick:e=>e===`plan`?_t():e===`assets`?vt():gt(e===`visuals`?`visuals`:x)}),notesToggle:Se?Q(Zg,{shown:xe.shown,onToggle:xe.toggle,buttonRef:Ee}):null,more:Q(sx,{found:mt,onBringIn:()=>yt(),video:B,onToggleShelved:ut,autoProxy:e.project.autoProxy,onKeys:()=>{v(null),T(!0)},toast:z,onChanged:()=>void i()})}),_&&Q(`div`,{class:`pop`,role:`dialog`,"aria-label":`Sent to agent`,children:[Q(`div`,{style:{display:`flex`,alignItems:`center`,gap:`8px`},children:[Q(`h3`,{children:_.title??`Batch ${_.id} is ready`}),Q(`span`,{class:`sp`}),Q(`button`,{class:`btn ghost ib sm`,"aria-label":`Close`,"data-tip":`Close`,onClick:()=>v(null),children:Q($,{name:`x`})})]}),Q(`pre`,{children:_.prompt}),Q(`div`,{style:{display:`flex`,justifyContent:`flex-end`},children:Q(`button`,{class:`btn primary`,onClick:()=>void wt(),children:[Q($,{name:`copy`}),E?`Copied`:`Copy prompt`]})})]}),w&&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:()=>T(!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`})]})]}),p&&Q(`div`,{class:`toast`,role:`status`,children:[p,h&&Q(`button`,{type:`button`,class:`toastact`,onClick:()=>{m(null),g(null),h.run()},children:h.label})]}),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]}),Bt.workspace===`plan`&&Q(`div`,{class:`rtabrow planrow`,children:[Q(Xh,{rows:Lt,selected:Be(s)?s:null,onPick:e=>gt(e)}),Ft&&e.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 zt(),children:[Q($,{name:`copy`}),`Copy prompt for your agent`]})]})]}),Qt&&Q(`div`,{class:`rtabrow`,children:Q(cx,{rows:Zt,selected:s,onPick:e=>gt(e)})}),B?.shelved&&gx.has(s)&&Q(ax,{video:B,onRestore:()=>void lt(B,!1)}),Q(`main`,{class:`body${B?.shelved?` fshelved`:``}`,ref:St,children:s===`assets`?jt?Q(Wh,{assets:t,videos:e.project.videos,state:e,foundRequest:he,onFoundRequestUsed:()=>ge(e=>e.pending?{n:e.n,pending:!1}:e),onFoundSeen:ye,toast:z,onChanged:()=>void i()}):Q(yx,{tab:`assets`,projectName:e.project.name,filmName:B?.name??null,found:e.found?.counts,onReview:yt,toast:z}):jt?s===`picture`&&kt?Q(uy,{state:e,assets:t,video:B??null,notes:Ot,prompt:Re(`picture`,e.project.name,B?.name??null),readOnly:!!B?.shelved,toast:z,onChanged:()=>void i(),onPendingChange:k,clock:N,mixView:P},B?.id??`project`):s===`picture`&&!B?nn(Q(ox,{onOpen:()=>st(e=>e+1)})):s===`picture`&&B&&V?Q(Wy,{readOnly:!!B.shelved,video:B,version:V,fps:We,notes:Tt,toast:z,onChanged:()=>void i(),onPendingChange:k,clock:N,mixView:P,grab:F[B.id]??null,onGrabChange:ne,playerRef:R,ffmpeg:e.proxies?.ffmpeg??!1,proxyJob:a[pn(B.id,V.id)],noteProxyJob:o,source:re[B.id]??`proxy`,onSourceChange:ae,formats:Ye,format:$e,formatMissing:!!$e&&et.has(Ye.find(e=>e.id===$e)?.file??``),onPrimarySize:(e,t,n)=>le(r=>r[e]?r:{...r,[e]:{width:t,height:n}}),onBoxPendingChange:de,onMarksPendingChange:pe,onFormatChange:nt,formatSwitch:tt.length>1?Q(sg,{chips:tt,versionId:V.id,prompt:qn(e.project.name,B.name,V.id),onSelect:nt,toast:z}):null,state:e,assets:t},B.id):s===`brief`?nn(Q(ag,{brief:e.brief,toast:z,onChanged:()=>void i(),settle:C}),sn):s===`storyboard`?nn(Q(Zy,{board:e.storyboard,brief:e.brief,toast:z,onChanged:()=>void i(),settle:C}),sn):s===`visuals`?Q(Wb,{state:e,toast:z,onChanged:()=>void i(),onPendingChange:k}):s===`script`?nn(Q(nb,{script:e.script,toast:z,onChanged:()=>void i(),onPickLine:ke}),sn):s===`voice`?Q(db,{state:e,assets:t,video:B??null,toast:z,onChanged:()=>void i(),onPendingChange:k,clock:N,version:V??null},`voice`):s===`music`||s===`sfx`?Q(cb,{stage:s,state:e,assets:t,video:B??null,toast:z,onChanged:()=>void i(),onPendingChange:k,clock:N,version:V??null},s):null:nn(Q(yx,{tab:s,projectName:e.project.name,filmName:B?.name??null,found:e.found?.counts,onReview:yt,toast:z}))})]}),Q(ux,{send:Yt?{text:Yt.text,onGo:Xt}:null,cut:B&&V?{format:$t,fps:We,id:V.id,lockedAt:B.lockedVersion}:null,shapes:s===`picture`&&B&&V&&tt.length===1?{prompt:qn(e.project.name,B.name,V.id),toast:z}:null}),e.version&&Q(`span`,{class:`ver`,"aria-label":`Rushes version ${e.version}`,children:[`v`,e.version]})]})})}Bt(document),_r(ur(mr())),se(Q(xx,{}),document.getElementById(`app`));
|
|
67
|
+
`)}),D(!1),o&&i()},wt=async()=>{if(_)try{await navigator.clipboard.writeText(_.prompt),D(!0)}catch{z(`Couldn't reach the clipboard. Select the text and copy it.`)}};if(!e||!s)return Q(`div`,{class:`shell`,children:n?Q(`div`,{class:`banner`,children:[Q($,{name:`alert`}),n]}):Q(`div`,{class:`emptypage`,children:Q(`p`,{children:`Loading…`})})});let Tt=e.notes.notes.filter(e=>(e.stage===`picture`||e.stage===`mix`)&&(!e.video||e.video===B?.id)),Et=t=>e.notes.notes.filter(e=>e.status===`todo`&&Rx.has(e.stage)&&(!e.video||e.video===t)).length,Dt=nr(e.picks,B?.id).use,Ot=e.notes.notes.filter(e=>e.stage===`mix`&&(!e.video||e.video===B?.id)),kt=!V&&(!!(Dt?.voice||Dt?.music||Dt?.sfx)||Ot.length>0)&&(!!B||e.project.videos.length===0),At=!!pt(`picture`)?.unlocked||kt,jt=s===`assets`?ht:s===`brief`?e.brief.exists:s===`storyboard`?e.storyboard.exists:s===`picture`?At:pt(s)?.unlocked??!1,Mt=!!pt(`picture`)?.unlocked,Nt=Ve(e.brief,e.script.sections,e.storyboard),Pt=Nt.brief===`ok`&&Nt.script===`ok`&&Nt.storyboard===`ok`,Ft=e.build.started&&!Mt,It=pt(`script`)?.todo??0,Lt=[{page:`brief`,name:`Brief`,icon:`brief`,unlocked:e.brief.exists,ask:He.ask,approved:Nt.brief===`ok`,open:e.brief.changed},{page:`script`,name:`Script`,icon:vh.script,unlocked:!!pt(`script`)?.unlocked,ask:Ie.script.ask,approved:Nt.script===`ok`,open:It},{page:`storyboard`,name:`Storyboard`,icon:`story`,unlocked:e.storyboard.exists,ask:Ue.ask,approved:Nt.storyboard===`ok`,open:e.storyboard.changed}],Rt=e.brief.changed+e.storyboard.changed+It,zt=async()=>{try{await navigator.clipboard.writeText(Ke(e.project.name,B?.name??null)),z(`Prompt copied`)}catch{z(`Couldn't reach the clipboard. Ask your agent to build the film from the approved plan.`)}},Bt=um(s),Vt=ir(e.project.lanes,B?.id,e.project.videos.length),Ht=Dt,Wt={voice:hm(Vt,`voice`,Ht?.voice,B),music:hm(Vt,`music`,Ht?.music,B),sfx:hm(Vt,`sfx`,Ht?.sfx,B)},Gt=new Set(e.project.videos.filter(Me).map(e=>e.id)),Kt={notes:e.notes.notes,inPlay:Gt,scriptTodo:pt(`script`)?.todo??0,briefChanged:e.brief.changed,storyboardChanged:e.storyboard.changed},qt=Dm(Kt),Jt=e.notes.notes.every(e=>e.stage===`script`||e.status!==`todo`||e.batch!==null||!!e.video&&!Gt.has(e.video))&&qt>0&&e.brief.changed+e.storyboard.changed+(pt(`script`)?.todo??0)>0?Be(s)?s:y:x,Yt=qt>0&&!Se?{text:`Send ${qt} ${Em(Kt)>0?qt===1?`change`:`changes`:qt===1?`note`:`notes`}`}:null,Xt=()=>{if(O)return z(`Add or clear your note first`);gt(Jt),xe.setShown(!0),Ce.setOpen(!1),Te(!0)},Zt=zx.map(({view:e,label:t})=>({view:e,label:t,icon:vh[e],locked:e===`picture`?!At:!pt(e)?.unlocked,ask:Ie[e].ask,takes:e===`voice`||e===`music`||e===`sfx`?bm(Wt[e]):null,todo:(pt(e)?.todo??0)+(e===`picture`?pt(`mix`)?.todo??0:0)})),Qt=Bt.workspace===`review`&&Zt.some(e=>!e.locked),$t=(Ye.find(e=>e.id===$e)??Ye.find(e=>e.primary)??Ye[0])?.label??null,en=mt!==null&&Dn(e.found)!==_e&&Cn(e.found?.counts)>0,tn={log:Ce,activity:{projectId:Kr()??``,head:e.log,project:e.project,stage:s===`brief`||s===`storyboard`?`script`:s,toast:z,onJump:e=>{dt(e),xe.narrow&&(xe.setShown(!1),Ee.current?.focus())}},send:{count:qt,always:s===`brief`&&e.brief.exists||s===`storyboard`&&e.storyboard.exists,onSend:()=>void Ct()},shown:xe.shown,narrow:xe.narrow,setShown:xe.setShown,width:xe.width,setWidth:xe.setWidth,reveal:we,onRevealed:()=>Te(!1),revealNotes:e=>{De.current=e,xe.setShown(!0),Ce.open?Ce.setOpen(!1,!1):xe.shown&&(De.current=null,e())}},nn=(e,t=Q(l_,{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`,...Be(s)?{role:`tabpanel`,id:ag,"aria-labelledby":og(s)}:{},children:e}),t]}),rn=e.notes.notes.filter(e=>e.stage===`script`),an=Oe&&s===`script`?wm({kind:`line`,...Oe},null):{stage:`script`,on:null,scope:`whole`,t:null,tOut:null,label:`The script`},on=s===`script`,sn=Q(Hx,{notes:rn,version:null,placeholder:`Note on ${an.label}`,fixedTimes:!0,toast:z,onLabel:t=>t.on===null?`The script`:om(t,{project:e.project,script:e.script}),target:{label:an.label,onClear:Oe&&s===`script`?()=>ke(null):void 0},onAdd:async e=>{await K.post(`/api/notes`,{stage:`script`,video:null,version:null,on:an.on,scope:`whole`,t:null,tOut:null,text:e}),i()},onChanged:()=>void i(),onPendingChange:k,readOnly:!on,instead:on?void 0:`Notes on the plan are written on the Script page.`});return Q(Zg.Provider,{value:tn,children:Q(`div`,{class:`shell${Se&&!xe.narrow&&!xe.shown?` nhidden`:``}`,style:{"--notes-w":`${xe.width}px`},children:[Q(Ix,{barRef:xt,project:e.project.name,projectId:e.project.id??null,film:e.project.videos.length>0?Q(Ex,{films:e.project.videos,currentId:B?.id??null,openNotes:Et,onSwitch:it,onRestore:t=>{let n=e.project.videos.find(e=>e.id===t);n&<(n,!1)},shelvedRequest:ot}):null,cut:B&&V?Q(Cx,{video:B,shown:V,newer:rt,onPick:e=>{if(fe)return z(`Add or clear your note first`);f(e===Le?.id?null:e),j(!1)},onToggleLock:()=>void at()}):null,workspaces:Q(Lx,{current:Bt.workspace,plan:{approved:Pt,open:Rt,locked:Lt.every(e=>!e.unlocked)},hasVisuals:!!pt(`visuals`)?.unlocked,assetsUnlocked:ht,found:en?{count:Cn(e.found?.counts),text:mt}:null,onPick:e=>e===`plan`?_t():e===`assets`?vt():gt(e===`visuals`?`visuals`:x)}),notesToggle:Se?Q(c_,{shown:xe.shown,onToggle:xe.toggle,buttonRef:Ee}):null,more:Q(kx,{found:mt,onBringIn:()=>yt(),video:B,onToggleShelved:ut,autoProxy:e.project.autoProxy,onKeys:()=>{v(null),T(!0)},toast:z,onChanged:()=>void i()})}),_&&Q(`div`,{class:`pop`,role:`dialog`,"aria-label":`Sent to agent`,children:[Q(`div`,{style:{display:`flex`,alignItems:`center`,gap:`8px`},children:[Q(`h3`,{children:_.title??`Batch ${_.id} is ready`}),Q(`span`,{class:`sp`}),Q(`button`,{class:`btn ghost ib sm`,"aria-label":`Close`,"data-tip":`Close`,onClick:()=>v(null),children:Q($,{name:`x`})})]}),Q(`pre`,{children:_.prompt}),Q(`div`,{style:{display:`flex`,justifyContent:`flex-end`},children:Q(`button`,{class:`btn primary`,onClick:()=>void wt(),children:[Q($,{name:`copy`}),E?`Copied`:`Copy prompt`]})})]}),w&&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:()=>T(!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`})]})]}),p&&Q(`div`,{class:`toast`,role:`status`,children:[p,h&&Q(`button`,{type:`button`,class:`toastact`,onClick:()=>{m(null),g(null),h.run()},children:h.label})]}),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]}),Bt.workspace===`plan`&&Q(`div`,{class:`rtabrow planrow`,children:[Q(sg,{rows:Lt,selected:Be(s)?s:null,onPick:e=>gt(e)}),Ft&&e.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 zt(),children:[Q($,{name:`copy`}),`Copy prompt for your agent`]})]})]}),Qt&&Q(`div`,{class:`rtabrow`,children:Q(Ax,{rows:Zt,selected:s,onPick:e=>gt(e)})}),B?.shelved&&Rx.has(s)&&Q(Dx,{video:B,onRestore:()=>void lt(B,!1)}),Q(`main`,{class:`body${B?.shelved?` fshelved`:``}`,ref:St,children:s===`assets`?jt?Q(tg,{assets:t,videos:e.project.videos,state:e,foundRequest:he,onFoundRequestUsed:()=>ge(e=>e.pending?{n:e.n,pending:!1}:e),onFoundSeen:ye,toast:z,onChanged:()=>void i()}):Q(Vx,{tab:`assets`,projectName:e.project.name,filmName:B?.name??null,found:e.found?.counts,onReview:yt,toast:z}):jt?s===`picture`&&kt?Q(xy,{state:e,assets:t,video:B??null,notes:Ot,prompt:Re(`picture`,e.project.name,B?.name??null),readOnly:!!B?.shelved,toast:z,onChanged:()=>void i(),onPendingChange:k,clock:N,mixView:P},B?.id??`project`):s===`picture`&&!B?nn(Q(Ox,{onOpen:()=>st(e=>e+1)})):s===`picture`&&B&&V?Q(db,{readOnly:!!B.shelved,video:B,version:V,fps:We,notes:Tt,toast:z,onChanged:()=>void i(),onPendingChange:k,clock:N,mixView:P,grab:F[B.id]??null,onGrabChange:ne,playerRef:R,ffmpeg:e.proxies?.ffmpeg??!1,proxyJob:a[pn(B.id,V.id)],noteProxyJob:o,source:re[B.id]??`proxy`,onSourceChange:ae,formats:Ye,format:$e,formatMissing:!!$e&&et.has(Ye.find(e=>e.id===$e)?.file??``),onPrimarySize:(e,t,n)=>le(r=>r[e]?r:{...r,[e]:{width:t,height:n}}),onBoxPendingChange:de,onMarksPendingChange:pe,onFormatChange:nt,formatSwitch:tt.length>1?Q(vg,{chips:tt,versionId:V.id,prompt:qn(e.project.name,B.name,V.id),onSelect:nt,toast:z}):null,state:e,assets:t},B.id):s===`brief`?nn(Q(gg,{brief:e.brief,toast:z,onChanged:()=>void i(),settle:C}),sn):s===`storyboard`?nn(Q(vb,{board:e.storyboard,brief:e.brief,toast:z,onChanged:()=>void i(),settle:C}),sn):s===`visuals`?Q(dx,{state:e,toast:z,onChanged:()=>void i(),onPendingChange:k}):s===`script`?nn(Q(Cb,{script:e.script,toast:z,onChanged:()=>void i(),onPickLine:ke}),sn):s===`voice`?Q(Mb,{state:e,assets:t,video:B??null,toast:z,onChanged:()=>void i(),onPendingChange:k,clock:N,version:V??null},`voice`):s===`music`||s===`sfx`?Q(kb,{stage:s,state:e,assets:t,video:B??null,toast:z,onChanged:()=>void i(),onPendingChange:k,clock:N,version:V??null},s):null:nn(Q(Vx,{tab:s,projectName:e.project.name,filmName:B?.name??null,found:e.found?.counts,onReview:yt,toast:z}))})]}),Q(Mx,{send:Yt?{text:Yt.text,onGo:Xt}:null,cut:B&&V?{format:$t,fps:We,id:V.id,lockedAt:B.lockedVersion}:null,shapes:s===`picture`&&B&&V&&tt.length===1?{prompt:qn(e.project.name,B.name,V.id),toast:z}:null}),e.version&&Q(`span`,{class:`ver`,"aria-label":`Rushes version ${e.version}`,children:[`v`,e.version]})]})})}Bt(document),_r(ur(mr())),se(Q(Ux,{}),document.getElementById(`app`));
|