ossclip 0.1.1 → 0.1.3

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.
@@ -156,4 +156,4 @@ Check that all your Remotion packages are on the same version. If your dependenc
156
156
  if (${x}.issues.length) payload.issues = payload.issues.concat(${x}.issues.map(iss => ({
157
157
  ...iss,
158
158
  path: iss.path ? [${ci(y)}, ...iss.path] : [${ci(y)}]
159
- })));`),m.write(`newResult[${ci(y)}] = ${x}.value`)}m.write("payload.value = newResult;"),m.write("return payload;");const g=m.compile();return(y,x)=>g(p,y,x)};let o;const i=cd,s=!sw.jitless,l=s&&QI.value,u=t.catchall;let d;e._zod.parse=(p,m)=>{d??(d=n.value);const h=p.value;if(!i(h))return p.issues.push({expected:"object",code:"invalid_type",input:h,inst:e}),p;const w=[];if(s&&l&&(m==null?void 0:m.async)===!1&&m.jitless!==!0)o||(o=r(t.shape)),p=o(p,m);else{p.value={};const x=d.shape;for(const b of d.keys){const k=x[b],S=k._zod.run({value:h[b],issues:[]},m),C=k._zod.optin==="optional"&&k._zod.optout==="optional";S instanceof Promise?w.push(S.then(I=>C?oh(I,p,b,h):Ks(I,p,b))):C?oh(S,p,b,h):Ks(S,p,b)}}if(!u)return w.length?Promise.all(w).then(()=>p):p;const v=[],E=d.keySet,g=u._zod,y=g.def.type;for(const x of Object.keys(h)){if(E.has(x))continue;if(y==="never"){v.push(x);continue}const b=g.run({value:h[x],issues:[]},m);b instanceof Promise?w.push(b.then(k=>Ks(k,p,x))):Ks(b,p,x)}return v.length&&p.issues.push({code:"unrecognized_keys",keys:v,input:h,inst:e}),w.length?Promise.all(w).then(()=>p):p}});function ih(e,t,n,r){for(const o of e)if(o.issues.length===0)return t.value=o.value,t;return t.issues.push({code:"invalid_union",input:t.value,inst:n,errors:e.map(o=>o.issues.map(i=>sr(i,r,ir())))}),t}const M_=U("$ZodUnion",(e,t)=>{Ne.init(e,t),Re(e._zod,"optin",()=>t.options.some(n=>n._zod.optin==="optional")?"optional":void 0),Re(e._zod,"optout",()=>t.options.some(n=>n._zod.optout==="optional")?"optional":void 0),Re(e._zod,"values",()=>{if(t.options.every(n=>n._zod.values))return new Set(t.options.flatMap(n=>Array.from(n._zod.values)))}),Re(e._zod,"pattern",()=>{if(t.options.every(n=>n._zod.pattern)){const n=t.options.map(r=>r._zod.pattern);return new RegExp(`^(${n.map(r=>Wf(r.source)).join("|")})$`)}}),e._zod.parse=(n,r)=>{let o=!1;const i=[];for(const s of t.options){const a=s._zod.run({value:n.value,issues:[]},r);if(a instanceof Promise)i.push(a),o=!0;else{if(a.issues.length===0)return a;i.push(a)}}return o?Promise.all(i).then(s=>ih(s,n,e,r)):ih(i,n,e,r)}}),j_=U("$ZodIntersection",(e,t)=>{Ne.init(e,t),e._zod.parse=(n,r)=>{const o=n.value,i=t.left._zod.run({value:o,issues:[]},r),s=t.right._zod.run({value:o,issues:[]},r);return i instanceof Promise||s instanceof Promise?Promise.all([i,s]).then(([l,u])=>sh(n,l,u)):sh(n,i,s)}});function dd(e,t){if(e===t)return{valid:!0,data:e};if(e instanceof Date&&t instanceof Date&&+e==+t)return{valid:!0,data:e};if(Ga(e)&&Ga(t)){const n=Object.keys(t),r=Object.keys(e).filter(i=>n.indexOf(i)!==-1),o={...e,...t};for(const i of r){const s=dd(e[i],t[i]);if(!s.valid)return{valid:!1,mergeErrorPath:[i,...s.mergeErrorPath]};o[i]=s.data}return{valid:!0,data:o}}if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return{valid:!1,mergeErrorPath:[]};const n=[];for(let r=0;r<e.length;r++){const o=e[r],i=t[r],s=dd(o,i);if(!s.valid)return{valid:!1,mergeErrorPath:[r,...s.mergeErrorPath]};n.push(s.data)}return{valid:!0,data:n}}return{valid:!1,mergeErrorPath:[]}}function sh(e,t,n){if(t.issues.length&&e.issues.push(...t.issues),n.issues.length&&e.issues.push(...n.issues),Ti(e))return e;const r=dd(t.value,n.value);if(!r.valid)throw new Error(`Unmergable intersection. Error path: ${JSON.stringify(r.mergeErrorPath)}`);return e.value=r.data,e}const $_=U("$ZodRecord",(e,t)=>{Ne.init(e,t),e._zod.parse=(n,r)=>{const o=n.value;if(!Ga(o))return n.issues.push({expected:"record",code:"invalid_type",input:o,inst:e}),n;const i=[];if(t.keyType._zod.values){const s=t.keyType._zod.values;n.value={};for(const l of s)if(typeof l=="string"||typeof l=="number"||typeof l=="symbol"){const u=t.valueType._zod.run({value:o[l],issues:[]},r);u instanceof Promise?i.push(u.then(d=>{d.issues.length&&n.issues.push(...Er(l,d.issues)),n.value[l]=d.value})):(u.issues.length&&n.issues.push(...Er(l,u.issues)),n.value[l]=u.value)}let a;for(const l in o)s.has(l)||(a=a??[],a.push(l));a&&a.length>0&&n.issues.push({code:"unrecognized_keys",input:o,inst:e,keys:a})}else{n.value={};for(const s of Reflect.ownKeys(o)){if(s==="__proto__")continue;const a=t.keyType._zod.run({value:s,issues:[]},r);if(a instanceof Promise)throw new Error("Async schemas not supported in object keys currently");if(a.issues.length){n.issues.push({origin:"record",code:"invalid_key",issues:a.issues.map(u=>sr(u,r,ir())),input:s,path:[s],inst:e}),n.value[a.value]=a.value;continue}const l=t.valueType._zod.run({value:o[s],issues:[]},r);l instanceof Promise?i.push(l.then(u=>{u.issues.length&&n.issues.push(...Er(s,u.issues)),n.value[a.value]=u.value})):(l.issues.length&&n.issues.push(...Er(s,l.issues)),n.value[a.value]=l.value)}}return i.length?Promise.all(i).then(()=>n):n}}),A_=U("$ZodEnum",(e,t)=>{Ne.init(e,t);const n=XI(t.entries);e._zod.values=new Set(n),e._zod.pattern=new RegExp(`^(${n.filter(r=>JI.has(typeof r)).map(r=>typeof r=="string"?Ul(r):r.toString()).join("|")})$`),e._zod.parse=(r,o)=>{const i=r.value;return e._zod.values.has(i)||r.issues.push({code:"invalid_value",values:n,input:i,inst:e}),r}}),N_=U("$ZodTransform",(e,t)=>{Ne.init(e,t),e._zod.parse=(n,r)=>{const o=t.transform(n.value,n);if(r.async)return(o instanceof Promise?o:Promise.resolve(o)).then(s=>(n.value=s,n));if(o instanceof Promise)throw new Gi;return n.value=o,n}}),L_=U("$ZodOptional",(e,t)=>{Ne.init(e,t),e._zod.optin="optional",e._zod.optout="optional",Re(e._zod,"values",()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,void 0]):void 0),Re(e._zod,"pattern",()=>{const n=t.innerType._zod.pattern;return n?new RegExp(`^(${Wf(n.source)})?$`):void 0}),e._zod.parse=(n,r)=>t.innerType._zod.optin==="optional"?t.innerType._zod.run(n,r):n.value===void 0?n:t.innerType._zod.run(n,r)}),z_=U("$ZodNullable",(e,t)=>{Ne.init(e,t),Re(e._zod,"optin",()=>t.innerType._zod.optin),Re(e._zod,"optout",()=>t.innerType._zod.optout),Re(e._zod,"pattern",()=>{const n=t.innerType._zod.pattern;return n?new RegExp(`^(${Wf(n.source)}|null)$`):void 0}),Re(e._zod,"values",()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,null]):void 0),e._zod.parse=(n,r)=>n.value===null?n:t.innerType._zod.run(n,r)}),D_=U("$ZodDefault",(e,t)=>{Ne.init(e,t),e._zod.optin="optional",Re(e._zod,"values",()=>t.innerType._zod.values),e._zod.parse=(n,r)=>{if(n.value===void 0)return n.value=t.defaultValue,n;const o=t.innerType._zod.run(n,r);return o instanceof Promise?o.then(i=>ah(i,t)):ah(o,t)}});function ah(e,t){return e.value===void 0&&(e.value=t.defaultValue),e}const O_=U("$ZodPrefault",(e,t)=>{Ne.init(e,t),e._zod.optin="optional",Re(e._zod,"values",()=>t.innerType._zod.values),e._zod.parse=(n,r)=>(n.value===void 0&&(n.value=t.defaultValue),t.innerType._zod.run(n,r))}),V_=U("$ZodNonOptional",(e,t)=>{Ne.init(e,t),Re(e._zod,"values",()=>{const n=t.innerType._zod.values;return n?new Set([...n].filter(r=>r!==void 0)):void 0}),e._zod.parse=(n,r)=>{const o=t.innerType._zod.run(n,r);return o instanceof Promise?o.then(i=>lh(i,e)):lh(o,e)}});function lh(e,t){return!e.issues.length&&e.value===void 0&&e.issues.push({code:"invalid_type",expected:"nonoptional",input:e.value,inst:t}),e}const B_=U("$ZodCatch",(e,t)=>{Ne.init(e,t),e._zod.optin="optional",Re(e._zod,"optout",()=>t.innerType._zod.optout),Re(e._zod,"values",()=>t.innerType._zod.values),e._zod.parse=(n,r)=>{const o=t.innerType._zod.run(n,r);return o instanceof Promise?o.then(i=>(n.value=i.value,i.issues.length&&(n.value=t.catchValue({...n,error:{issues:i.issues.map(s=>sr(s,r,ir()))},input:n.value}),n.issues=[]),n)):(n.value=o.value,o.issues.length&&(n.value=t.catchValue({...n,error:{issues:o.issues.map(i=>sr(i,r,ir()))},input:n.value}),n.issues=[]),n)}}),W_=U("$ZodPipe",(e,t)=>{Ne.init(e,t),Re(e._zod,"values",()=>t.in._zod.values),Re(e._zod,"optin",()=>t.in._zod.optin),Re(e._zod,"optout",()=>t.out._zod.optout),e._zod.parse=(n,r)=>{const o=t.in._zod.run(n,r);return o instanceof Promise?o.then(i=>uh(i,t,r)):uh(o,t,r)}});function uh(e,t,n){return Ti(e)?e:t.out._zod.run({value:e.value,issues:e.issues},n)}const U_=U("$ZodReadonly",(e,t)=>{Ne.init(e,t),Re(e._zod,"propValues",()=>t.innerType._zod.propValues),Re(e._zod,"values",()=>t.innerType._zod.values),Re(e._zod,"optin",()=>t.innerType._zod.optin),Re(e._zod,"optout",()=>t.innerType._zod.optout),e._zod.parse=(n,r)=>{const o=t.innerType._zod.run(n,r);return o instanceof Promise?o.then(ch):ch(o)}});function ch(e){return e.value=Object.freeze(e.value),e}const H_=U("$ZodCustom",(e,t)=>{Rt.init(e,t),Ne.init(e,t),e._zod.parse=(n,r)=>n,e._zod.check=n=>{const r=n.value,o=t.fn(r);if(o instanceof Promise)return o.then(i=>dh(i,n,r,e));dh(o,n,r,e)}});function dh(e,t,n,r){if(!e){const o={code:"custom",input:n,inst:r,path:[...r._zod.def.path??[]],continue:!r._zod.def.abort};r._zod.def.params&&(o.params=r._zod.def.params),t.issues.push(qi(o))}}class Z_{constructor(){this._map=new Map,this._idmap=new Map}add(t,...n){const r=n[0];if(this._map.set(t,r),r&&typeof r=="object"&&"id"in r){if(this._idmap.has(r.id))throw new Error(`ID ${r.id} already exists in the registry`);this._idmap.set(r.id,t)}return this}clear(){return this._map=new Map,this._idmap=new Map,this}remove(t){const n=this._map.get(t);return n&&typeof n=="object"&&"id"in n&&this._idmap.delete(n.id),this._map.delete(t),this}get(t){const n=t._zod.parent;if(n){const r={...this.get(n)??{}};return delete r.id,{...r,...this._map.get(t)}}return this._map.get(t)}has(t){return this._map.has(t)}}function Y_(){return new Z_}const Xs=Y_();function K_(e,t){return new e({type:"string",...ie(t)})}function X_(e,t){return new e({type:"string",format:"email",check:"string_format",abort:!1,...ie(t)})}function fh(e,t){return new e({type:"string",format:"guid",check:"string_format",abort:!1,...ie(t)})}function G_(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,...ie(t)})}function q_(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v4",...ie(t)})}function Q_(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v6",...ie(t)})}function J_(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v7",...ie(t)})}function eR(e,t){return new e({type:"string",format:"url",check:"string_format",abort:!1,...ie(t)})}function tR(e,t){return new e({type:"string",format:"emoji",check:"string_format",abort:!1,...ie(t)})}function nR(e,t){return new e({type:"string",format:"nanoid",check:"string_format",abort:!1,...ie(t)})}function rR(e,t){return new e({type:"string",format:"cuid",check:"string_format",abort:!1,...ie(t)})}function oR(e,t){return new e({type:"string",format:"cuid2",check:"string_format",abort:!1,...ie(t)})}function iR(e,t){return new e({type:"string",format:"ulid",check:"string_format",abort:!1,...ie(t)})}function sR(e,t){return new e({type:"string",format:"xid",check:"string_format",abort:!1,...ie(t)})}function aR(e,t){return new e({type:"string",format:"ksuid",check:"string_format",abort:!1,...ie(t)})}function lR(e,t){return new e({type:"string",format:"ipv4",check:"string_format",abort:!1,...ie(t)})}function uR(e,t){return new e({type:"string",format:"ipv6",check:"string_format",abort:!1,...ie(t)})}function cR(e,t){return new e({type:"string",format:"cidrv4",check:"string_format",abort:!1,...ie(t)})}function dR(e,t){return new e({type:"string",format:"cidrv6",check:"string_format",abort:!1,...ie(t)})}function fR(e,t){return new e({type:"string",format:"base64",check:"string_format",abort:!1,...ie(t)})}function pR(e,t){return new e({type:"string",format:"base64url",check:"string_format",abort:!1,...ie(t)})}function mR(e,t){return new e({type:"string",format:"e164",check:"string_format",abort:!1,...ie(t)})}function hR(e,t){return new e({type:"string",format:"jwt",check:"string_format",abort:!1,...ie(t)})}function gR(e,t){return new e({type:"string",format:"datetime",check:"string_format",offset:!1,local:!1,precision:null,...ie(t)})}function vR(e,t){return new e({type:"string",format:"date",check:"string_format",...ie(t)})}function yR(e,t){return new e({type:"string",format:"time",check:"string_format",precision:null,...ie(t)})}function wR(e,t){return new e({type:"string",format:"duration",check:"string_format",...ie(t)})}function xR(e,t){return new e({type:"number",checks:[],...ie(t)})}function bR(e,t){return new e({type:"number",check:"number_format",abort:!1,format:"safeint",...ie(t)})}function SR(e,t){return new e({type:"boolean",...ie(t)})}function ER(e){return new e({type:"unknown"})}function kR(e,t){return new e({type:"never",...ie(t)})}function ph(e,t){return new yw({check:"less_than",...ie(t),value:e,inclusive:!1})}function zu(e,t){return new yw({check:"less_than",...ie(t),value:e,inclusive:!0})}function mh(e,t){return new ww({check:"greater_than",...ie(t),value:e,inclusive:!1})}function Du(e,t){return new ww({check:"greater_than",...ie(t),value:e,inclusive:!0})}function hh(e,t){return new VT({check:"multiple_of",...ie(t),value:e})}function Sw(e,t){return new WT({check:"max_length",...ie(t),maximum:e})}function qa(e,t){return new UT({check:"min_length",...ie(t),minimum:e})}function Ew(e,t){return new HT({check:"length_equals",...ie(t),length:e})}function CR(e,t){return new ZT({check:"string_format",format:"regex",...ie(t),pattern:e})}function IR(e){return new YT({check:"string_format",format:"lowercase",...ie(e)})}function TR(e){return new KT({check:"string_format",format:"uppercase",...ie(e)})}function _R(e,t){return new XT({check:"string_format",format:"includes",...ie(t),includes:e})}function RR(e,t){return new GT({check:"string_format",format:"starts_with",...ie(t),prefix:e})}function PR(e,t){return new qT({check:"string_format",format:"ends_with",...ie(t),suffix:e})}function hs(e){return new QT({check:"overwrite",tx:e})}function FR(e){return hs(t=>t.normalize(e))}function MR(){return hs(e=>e.trim())}function jR(){return hs(e=>e.toLowerCase())}function $R(){return hs(e=>e.toUpperCase())}function AR(e,t,n){return new e({type:"array",element:t,...ie(n)})}function NR(e,t,n){return new e({type:"custom",check:"custom",fn:t,...ie(n)})}const LR=U("ZodISODateTime",(e,t)=>{f_.init(e,t),Le.init(e,t)});function zR(e){return gR(LR,e)}const DR=U("ZodISODate",(e,t)=>{p_.init(e,t),Le.init(e,t)});function OR(e){return vR(DR,e)}const VR=U("ZodISOTime",(e,t)=>{m_.init(e,t),Le.init(e,t)});function BR(e){return yR(VR,e)}const WR=U("ZodISODuration",(e,t)=>{h_.init(e,t),Le.init(e,t)});function UR(e){return wR(WR,e)}const HR=(e,t)=>{cw.init(e,t),e.name="ZodError",Object.defineProperties(e,{format:{value:n=>uT(e,n)},flatten:{value:n=>lT(e,n)},addIssue:{value:n=>e.issues.push(n)},addIssues:{value:n=>e.issues.push(...n)},isEmpty:{get(){return e.issues.length===0}}})},Zl=U("ZodError",HR,{Parent:Error}),ZR=cT(Zl),YR=dT(Zl),KR=fw(Zl),XR=pw(Zl),Be=U("ZodType",(e,t)=>(Ne.init(e,t),e.def=t,Object.defineProperty(e,"_def",{value:t}),e.check=(...n)=>e.clone({...t,checks:[...t.checks??[],...n.map(r=>typeof r=="function"?{_zod:{check:r,def:{check:"custom"},onattach:[]}}:r)]}),e.clone=(n,r)=>Wr(e,n,r),e.brand=()=>e,e.register=(n,r)=>(n.add(e,r),e),e.parse=(n,r)=>ZR(e,n,r,{callee:e.parse}),e.safeParse=(n,r)=>KR(e,n,r),e.parseAsync=async(n,r)=>YR(e,n,r,{callee:e.parseAsync}),e.safeParseAsync=async(n,r)=>XR(e,n,r),e.spa=e.safeParseAsync,e.refine=(n,r)=>e.check(VP(n,r)),e.superRefine=n=>e.check(BP(n)),e.overwrite=n=>e.check(hs(n)),e.optional=()=>yh(e),e.nullable=()=>wh(e),e.nullish=()=>yh(wh(e)),e.nonoptional=n=>jP(e,n),e.array=()=>lr(e),e.or=n=>SP([e,n]),e.and=n=>kP(e,n),e.transform=n=>xh(e,TP(n)),e.default=n=>PP(e,n),e.prefault=n=>MP(e,n),e.catch=n=>AP(e,n),e.pipe=n=>xh(e,n),e.readonly=()=>zP(e),e.describe=n=>{const r=e.clone();return Xs.add(r,{description:n}),r},Object.defineProperty(e,"description",{get(){var n;return(n=Xs.get(e))==null?void 0:n.description},configurable:!0}),e.meta=(...n)=>{if(n.length===0)return Xs.get(e);const r=e.clone();return Xs.add(r,n[0]),r},e.isOptional=()=>e.safeParse(void 0).success,e.isNullable=()=>e.safeParse(null).success,e)),kw=U("_ZodString",(e,t)=>{Zf.init(e,t),Be.init(e,t);const n=e._zod.bag;e.format=n.format??null,e.minLength=n.minimum??null,e.maxLength=n.maximum??null,e.regex=(...r)=>e.check(CR(...r)),e.includes=(...r)=>e.check(_R(...r)),e.startsWith=(...r)=>e.check(RR(...r)),e.endsWith=(...r)=>e.check(PR(...r)),e.min=(...r)=>e.check(qa(...r)),e.max=(...r)=>e.check(Sw(...r)),e.length=(...r)=>e.check(Ew(...r)),e.nonempty=(...r)=>e.check(qa(1,...r)),e.lowercase=r=>e.check(IR(r)),e.uppercase=r=>e.check(TR(r)),e.trim=()=>e.check(MR()),e.normalize=(...r)=>e.check(FR(...r)),e.toLowerCase=()=>e.check(jR()),e.toUpperCase=()=>e.check($R())}),GR=U("ZodString",(e,t)=>{Zf.init(e,t),kw.init(e,t),e.email=n=>e.check(X_(qR,n)),e.url=n=>e.check(eR(QR,n)),e.jwt=n=>e.check(hR(pP,n)),e.emoji=n=>e.check(tR(JR,n)),e.guid=n=>e.check(fh(gh,n)),e.uuid=n=>e.check(G_(Gs,n)),e.uuidv4=n=>e.check(q_(Gs,n)),e.uuidv6=n=>e.check(Q_(Gs,n)),e.uuidv7=n=>e.check(J_(Gs,n)),e.nanoid=n=>e.check(nR(eP,n)),e.guid=n=>e.check(fh(gh,n)),e.cuid=n=>e.check(rR(tP,n)),e.cuid2=n=>e.check(oR(nP,n)),e.ulid=n=>e.check(iR(rP,n)),e.base64=n=>e.check(fR(cP,n)),e.base64url=n=>e.check(pR(dP,n)),e.xid=n=>e.check(sR(oP,n)),e.ksuid=n=>e.check(aR(iP,n)),e.ipv4=n=>e.check(lR(sP,n)),e.ipv6=n=>e.check(uR(aP,n)),e.cidrv4=n=>e.check(cR(lP,n)),e.cidrv6=n=>e.check(dR(uP,n)),e.e164=n=>e.check(mR(fP,n)),e.datetime=n=>e.check(zR(n)),e.date=n=>e.check(OR(n)),e.time=n=>e.check(BR(n)),e.duration=n=>e.check(UR(n))});function ue(e){return K_(GR,e)}const Le=U("ZodStringFormat",(e,t)=>{Pe.init(e,t),kw.init(e,t)}),qR=U("ZodEmail",(e,t)=>{r_.init(e,t),Le.init(e,t)}),gh=U("ZodGUID",(e,t)=>{t_.init(e,t),Le.init(e,t)}),Gs=U("ZodUUID",(e,t)=>{n_.init(e,t),Le.init(e,t)}),QR=U("ZodURL",(e,t)=>{o_.init(e,t),Le.init(e,t)}),JR=U("ZodEmoji",(e,t)=>{i_.init(e,t),Le.init(e,t)}),eP=U("ZodNanoID",(e,t)=>{s_.init(e,t),Le.init(e,t)}),tP=U("ZodCUID",(e,t)=>{a_.init(e,t),Le.init(e,t)}),nP=U("ZodCUID2",(e,t)=>{l_.init(e,t),Le.init(e,t)}),rP=U("ZodULID",(e,t)=>{u_.init(e,t),Le.init(e,t)}),oP=U("ZodXID",(e,t)=>{c_.init(e,t),Le.init(e,t)}),iP=U("ZodKSUID",(e,t)=>{d_.init(e,t),Le.init(e,t)}),sP=U("ZodIPv4",(e,t)=>{g_.init(e,t),Le.init(e,t)}),aP=U("ZodIPv6",(e,t)=>{v_.init(e,t),Le.init(e,t)}),lP=U("ZodCIDRv4",(e,t)=>{y_.init(e,t),Le.init(e,t)}),uP=U("ZodCIDRv6",(e,t)=>{w_.init(e,t),Le.init(e,t)}),cP=U("ZodBase64",(e,t)=>{x_.init(e,t),Le.init(e,t)}),dP=U("ZodBase64URL",(e,t)=>{S_.init(e,t),Le.init(e,t)}),fP=U("ZodE164",(e,t)=>{E_.init(e,t),Le.init(e,t)}),pP=U("ZodJWT",(e,t)=>{C_.init(e,t),Le.init(e,t)}),Cw=U("ZodNumber",(e,t)=>{bw.init(e,t),Be.init(e,t),e.gt=(r,o)=>e.check(mh(r,o)),e.gte=(r,o)=>e.check(Du(r,o)),e.min=(r,o)=>e.check(Du(r,o)),e.lt=(r,o)=>e.check(ph(r,o)),e.lte=(r,o)=>e.check(zu(r,o)),e.max=(r,o)=>e.check(zu(r,o)),e.int=r=>e.check(vh(r)),e.safe=r=>e.check(vh(r)),e.positive=r=>e.check(mh(0,r)),e.nonnegative=r=>e.check(Du(0,r)),e.negative=r=>e.check(ph(0,r)),e.nonpositive=r=>e.check(zu(0,r)),e.multipleOf=(r,o)=>e.check(hh(r,o)),e.step=(r,o)=>e.check(hh(r,o)),e.finite=()=>e;const n=e._zod.bag;e.minValue=Math.max(n.minimum??Number.NEGATIVE_INFINITY,n.exclusiveMinimum??Number.NEGATIVE_INFINITY)??null,e.maxValue=Math.min(n.maximum??Number.POSITIVE_INFINITY,n.exclusiveMaximum??Number.POSITIVE_INFINITY)??null,e.isInt=(n.format??"").includes("int")||Number.isSafeInteger(n.multipleOf??.5),e.isFinite=!0,e.format=n.format??null});function ce(e){return xR(Cw,e)}const mP=U("ZodNumberFormat",(e,t)=>{I_.init(e,t),Cw.init(e,t)});function vh(e){return bR(mP,e)}const hP=U("ZodBoolean",(e,t)=>{T_.init(e,t),Be.init(e,t)});function ar(e){return SR(hP,e)}const gP=U("ZodUnknown",(e,t)=>{__.init(e,t),Be.init(e,t)});function Mo(){return ER(gP)}const vP=U("ZodNever",(e,t)=>{R_.init(e,t),Be.init(e,t)});function yP(e){return kR(vP,e)}const wP=U("ZodArray",(e,t)=>{P_.init(e,t),Be.init(e,t),e.element=t.element,e.min=(n,r)=>e.check(qa(n,r)),e.nonempty=n=>e.check(qa(1,n)),e.max=(n,r)=>e.check(Sw(n,r)),e.length=(n,r)=>e.check(Ew(n,r)),e.unwrap=()=>e.element});function lr(e,t){return AR(wP,e,t)}const xP=U("ZodObject",(e,t)=>{F_.init(e,t),Be.init(e,t),Re(e,"shape",()=>t.shape),e.keyof=()=>Yo(Object.keys(e._zod.def.shape)),e.catchall=n=>e.clone({...e._zod.def,catchall:n}),e.passthrough=()=>e.clone({...e._zod.def,catchall:Mo()}),e.loose=()=>e.clone({...e._zod.def,catchall:Mo()}),e.strict=()=>e.clone({...e._zod.def,catchall:yP()}),e.strip=()=>e.clone({...e._zod.def,catchall:void 0}),e.extend=n=>oT(e,n),e.merge=n=>iT(e,n),e.pick=n=>nT(e,n),e.omit=n=>rT(e,n),e.partial=(...n)=>sT(Iw,e,n[0]),e.required=(...n)=>aT(Tw,e,n[0])});function xe(e,t){const n={type:"object",get shape(){return Uf(this,"shape",{...e}),this.shape},...ie(t)};return new xP(n)}const bP=U("ZodUnion",(e,t)=>{M_.init(e,t),Be.init(e,t),e.options=t.options});function SP(e,t){return new bP({type:"union",options:e,...ie(t)})}const EP=U("ZodIntersection",(e,t)=>{j_.init(e,t),Be.init(e,t)});function kP(e,t){return new EP({type:"intersection",left:e,right:t})}const CP=U("ZodRecord",(e,t)=>{$_.init(e,t),Be.init(e,t),e.keyType=t.keyType,e.valueType=t.valueType});function ur(e,t,n){return new CP({type:"record",keyType:e,valueType:t,...ie(n)})}const fd=U("ZodEnum",(e,t)=>{A_.init(e,t),Be.init(e,t),e.enum=t.entries,e.options=Object.values(t.entries);const n=new Set(Object.keys(t.entries));e.extract=(r,o)=>{const i={};for(const s of r)if(n.has(s))i[s]=t.entries[s];else throw new Error(`Key ${s} not found in enum`);return new fd({...t,checks:[],...ie(o),entries:i})},e.exclude=(r,o)=>{const i={...t.entries};for(const s of r)if(n.has(s))delete i[s];else throw new Error(`Key ${s} not found in enum`);return new fd({...t,checks:[],...ie(o),entries:i})}});function Yo(e,t){const n=Array.isArray(e)?Object.fromEntries(e.map(r=>[r,r])):e;return new fd({type:"enum",entries:n,...ie(t)})}const IP=U("ZodTransform",(e,t)=>{N_.init(e,t),Be.init(e,t),e._zod.parse=(n,r)=>{n.addIssue=i=>{if(typeof i=="string")n.issues.push(qi(i,n.value,t));else{const s=i;s.fatal&&(s.continue=!1),s.code??(s.code="custom"),s.input??(s.input=n.value),s.inst??(s.inst=e),s.continue??(s.continue=!0),n.issues.push(qi(s))}};const o=t.transform(n.value,n);return o instanceof Promise?o.then(i=>(n.value=i,n)):(n.value=o,n)}});function TP(e){return new IP({type:"transform",transform:e})}const Iw=U("ZodOptional",(e,t)=>{L_.init(e,t),Be.init(e,t),e.unwrap=()=>e._zod.def.innerType});function yh(e){return new Iw({type:"optional",innerType:e})}const _P=U("ZodNullable",(e,t)=>{z_.init(e,t),Be.init(e,t),e.unwrap=()=>e._zod.def.innerType});function wh(e){return new _P({type:"nullable",innerType:e})}const RP=U("ZodDefault",(e,t)=>{D_.init(e,t),Be.init(e,t),e.unwrap=()=>e._zod.def.innerType,e.removeDefault=e.unwrap});function PP(e,t){return new RP({type:"default",innerType:e,get defaultValue(){return typeof t=="function"?t():t}})}const FP=U("ZodPrefault",(e,t)=>{O_.init(e,t),Be.init(e,t),e.unwrap=()=>e._zod.def.innerType});function MP(e,t){return new FP({type:"prefault",innerType:e,get defaultValue(){return typeof t=="function"?t():t}})}const Tw=U("ZodNonOptional",(e,t)=>{V_.init(e,t),Be.init(e,t),e.unwrap=()=>e._zod.def.innerType});function jP(e,t){return new Tw({type:"nonoptional",innerType:e,...ie(t)})}const $P=U("ZodCatch",(e,t)=>{B_.init(e,t),Be.init(e,t),e.unwrap=()=>e._zod.def.innerType,e.removeCatch=e.unwrap});function AP(e,t){return new $P({type:"catch",innerType:e,catchValue:typeof t=="function"?t:()=>t})}const NP=U("ZodPipe",(e,t)=>{W_.init(e,t),Be.init(e,t),e.in=t.in,e.out=t.out});function xh(e,t){return new NP({type:"pipe",in:e,out:t})}const LP=U("ZodReadonly",(e,t)=>{U_.init(e,t),Be.init(e,t)});function zP(e){return new LP({type:"readonly",innerType:e})}const DP=U("ZodCustom",(e,t)=>{H_.init(e,t),Be.init(e,t)});function OP(e){const t=new Rt({check:"custom"});return t._zod.check=e,t}function VP(e,t={}){return NR(DP,e,t)}function BP(e){const t=OP(n=>(n.addIssue=r=>{if(typeof r=="string")n.issues.push(qi(r,n.value,t._zod.def));else{const o=r;o.fatal&&(o.continue=!1),o.code??(o.code="custom"),o.input??(o.input=n.value),o.inst??(o.inst=t),o.continue??(o.continue=!t._zod.def.abort),n.issues.push(qi(o))}},e(n.value,n)));return t}const Yl=Yo(["full-bleed","video-top","pip-bubble","graphic-only","blurred-behind","lower-third","split-left","split-right"]),Kl=Yo(["TitleCard","StatCard","RuleCard","StrikethroughReveal","FlowDiagram","TerminalMock","ChatMock","ScreenshotFrame","BulletList"]),WP=xe({startWord:ce().int().nonnegative(),endWord:ce().int().nonnegative()});xe({id:ue(),anchor:WP,layout:Yl,component:Kl,props:ur(ue(),Mo()),overrides:ur(ue(),Mo()).default({}),rationale:ue().optional()});xe({id:ue(),kind:Yo(["graphic","plain"]).optional(),layout:Yl,component:Kl.optional(),props:ur(ue(),Mo()).optional(),startSec:ce().nonnegative(),endSec:ce().nonnegative(),graphicRect:xe({x:ce(),y:ce(),w:ce(),h:ce()}).optional(),elements:ur(ue(),xe({dx:ce().optional(),dy:ce().optional(),scale:ce().positive().optional()})).optional(),video:xe({scale:ce().positive().max(4).optional(),dy:ce().optional(),dx:ce().optional(),autoZoom:ar().optional()}).optional(),pip:xe({cornerRadius:ce().min(0).max(1).optional(),x:ce().min(0).max(1).optional(),y:ce().min(0).max(1).optional()}).optional(),captionY:ce().min(0).max(1).optional(),captionScale:ce().min(.2).max(3).optional(),pinned:ar().optional()}).superRefine((e,t)=>{e.kind!=="plain"&&(e.component===void 0||e.props===void 0)&&t.addIssue({code:"custom",message:'a graphic cue requires component and props; only kind: "plain" may omit them'})});xe({centerYFrac:ce().min(0).max(1),sizeFrac:ce().min(0).max(1).optional(),centerXFrac:ce().min(0).max(1).optional(),sourceAspect:ce().positive().optional()});const Yf=xe({bg:ue().default("#0B0B0E"),fg:ue().default("#FFFFFF"),accent:ue().default("#FFE14D"),muted:ue().default("#9A9AA3"),success:ue().default("#5FBF77"),cardBg:ue().default("#15151B"),cardBorder:ue().default("#2A2A33"),danger:ue().default("#FF5C5C"),radiusPx:ce().default(24),fontDisplay:ue().default("'Inter', 'Helvetica Neue', 'Arial Black', Arial, sans-serif"),fontMono:ue().default("'SF Mono', 'Cascadia Code', Consolas, monospace")}),UP=Yf.parse({}),HP=xe({eyebrow:ue().max(28).optional(),title:ue().min(1).max(48).describe("the claim WITHOUT the emphasis token — never repeat the emphasis here"),emphasis:ue().max(16).optional().describe("the number/punch token pulled OUT of the title (e.g. '861%') — not a duplicate of it"),sub:ue().max(64).optional()}),ZP=xe({label:ue().min(1).max(28),value:ue().min(1).max(12),caption:ue().max(40).optional(),inverted:ar().default(!1)}),YP=xe({kicker:ue().min(1).max(24),text:ue().min(1).max(40),struck:ue().max(40).optional()}),KP=xe({lines:lr(xe({text:ue().min(1).max(32),struck:ar().default(!1),mark:Yo(["none","cross","check"]).default("none")})).min(1).max(4)}),XP=xe({title:ue().max(28).optional(),items:lr(ue().min(1).max(36)).min(2).max(5)}),GP=xe({nodes:lr(ue().min(1).max(16)).min(2).max(5),emphasizeLast:ar().default(!0)}),qP=xe({windows:lr(xe({title:ue().max(24),lines:lr(ue().max(40)).min(1).max(6)})).min(1).max(5),fanOut:ue().max(20).optional()}),QP=xe({messages:lr(xe({from:Yo(["user","agent"]),text:ue().min(1).max(60)})).min(1).max(4),keyword:ue().max(16).optional().describe("ONLY for a 'comment <word>' ask: the single distinctive word the viewer types, plain and unformatted. Leave unset for any other CTA — especially 'reply with a number/which one', where there is no word to type. Never a referential filler like 'number', 'answer', 'comment' or 'below'.")}),JP=xe({src:ue().optional(),label:ue().max(32).optional(),kenBurns:ar().default(!0)}),eF={TitleCard:{propsSchema:HP,defaultProps:{title:"TITLE"},defaultLayout:"pip-bubble",altLayouts:[],whenToUse:"The core claim or hook as big typography; use `emphasis` for a huge number or punch word."},StatCard:{propsSchema:ZP,defaultProps:{label:"METRIC",value:"+0%"},defaultLayout:"video-top",altLayouts:["blurred-behind"],whenToUse:"One striking metric (value like '+242%', '×3', '5s'); punchline in `caption`."},RuleCard:{propsSchema:YP,defaultProps:{kicker:"RULE",text:"DO THE THING"},defaultLayout:"video-top",altLayouts:["blurred-behind"],whenToUse:"A prescriptive takeaway ('CAPACITY RULE / CAP ACTIVE AGENTS'); `struck` shows the rejected alternative."},StrikethroughReveal:{propsSchema:KP,defaultProps:{lines:[{text:"NOT THIS",struck:!0}]},defaultLayout:"blurred-behind",altLayouts:["graphic-only"],whenToUse:'Negation/contrast beat — big words over the blurred speaker. Strike EVERY line of the phrase the speaker negates, not just its tail — a half-struck claim reads as a typo. For wrong-vs-right lists, set mark: "cross"/"check" (✗/✓) per line instead.'},FlowDiagram:{propsSchema:GP,defaultProps:{nodes:["A","B"]},defaultLayout:"graphic-only",altLayouts:[],whenToUse:"A causal chain or pipeline as chips with arrows (TEAM → AI AGENTS → CHURN)."},TerminalMock:{propsSchema:qP,defaultProps:{windows:[{title:"terminal-01",lines:["$ run"]}]},defaultLayout:"graphic-only",altLayouts:[],whenToUse:"Anything about running code/processes/agents — stylized terminal windows."},ChatMock:{propsSchema:QP,defaultProps:{messages:[{from:"user",text:"hello"}]},defaultLayout:"blurred-behind",altLayouts:["graphic-only"],whenToUse:"A quoted phrase or exchange as chat bubbles over the blurred speaker; for a comment-CTA beat, set `keyword` to the word viewers should type."},ScreenshotFrame:{propsSchema:JP,defaultProps:{},defaultLayout:"video-top",altLayouts:["blurred-behind"],whenToUse:"Reference to a document/PR/review — a framed screenshot look with a label chip."},BulletList:{propsSchema:XP,defaultProps:{items:["FIRST","SECOND"]},defaultLayout:"blurred-behind",altLayouts:["graphic-only"],whenToUse:"An ENUMERATION — the speaker lists two or more parallel things ('what you need is X, Y, Z'). One bullet per item, optional kicker title. Use this for lists instead of bending TitleCard or StrikethroughReveal around them."}};function bh(e,t,n={}){const r=eF[e],o={...r.defaultProps,...t,...n},i=r.propsSchema.safeParse(o);return i.success?i.data:null}const tF=xe({dx:ce().optional(),dy:ce().optional(),scale:ce().positive().optional()}),_w=xe({props:ur(ue(),Mo()).default({}),elements:ur(ue(),tF).default({}),timing:xe({startSec:ce().nonnegative(),endSec:ce().nonnegative()}).optional(),component:Kl.optional(),layout:Yl.optional(),video:xe({scale:ce().positive().max(4).optional(),dy:ce().optional(),dx:ce().optional(),autoZoom:ar().optional()}).optional(),pip:xe({cornerRadius:ce().min(0).max(1).optional(),x:ce().min(0).max(1).optional(),y:ce().min(0).max(1).optional()}).optional(),captionY:ce().min(0).max(1).optional(),captionScale:ce().min(.2).max(3).optional(),graphicRect:xe({x:ce().min(0).max(1),y:ce().min(0).max(1),w:ce().min(.08).max(1),h:ce().min(.05).max(1)}).optional(),hidden:ar().optional()}),nF=xe({text:ue().min(1).max(80),was:ue()});function rF(e,t,n){var r;return((r=e[String(t)])==null?void 0:r.was)??n}const oF=xe({theme:Yf.partial().default({}),scenes:ur(ue(),_w).default({}),captions:ur(ue(),nF).default({}),splits:lr(ce().nonnegative()).default([])}),iF=()=>oF.parse({});function sF(e,t){return bh(e,{},t)??bh(e,{},{})}function aF(e,t){const n=e[t],r=t.indexOf("@");if(r===-1)return n;const o=e[t.slice(0,r)];if(!o)return n;const{timing:i,hidden:s,...a}=o;return n?{...a,...n,props:{...a.props,...n.props},elements:{...a.elements,...n.elements},...a.video||n.video?{video:{...a.video,...n.video}}:{},...a.pip||n.pip?{pip:{...a.pip,...n.pip}}:{}}:{...a,props:{...a.props},elements:{...a.elements}}}function Ou(e,t){const n=new Set(e.map(i=>i.id)),r=Object.keys(t.scenes).filter(i=>!n.has(i));return{cues:e.map(i=>{const s=aF(t.scenes,i.id);if(!s)return i;const a=s.component!==void 0&&s.component!==i.component,l=s.component??i.component,u=s.component!==void 0&&a?sF(s.component,s.props):{...i.props,...s.props},d=s.layout!==void 0&&s.layout!==i.layout,{graphicRect:p,...m}=i;return{...d?m:i,component:l,layout:s.layout??i.layout,props:u,...Object.keys(s.elements).length>0?{elements:s.elements}:{},...s.video?{video:s.video}:{},...s.pip?{pip:s.pip}:{},...s.captionY!==void 0?{captionY:s.captionY}:{},...s.captionScale!==void 0?{captionScale:s.captionScale}:{},...s.graphicRect?{graphicRect:s.graphicRect}:{},...s.timing&&!i.pinned?{startSec:s.timing.startSec,endSec:s.timing.endSec,pinned:!0}:{}}}),orphans:r}}const Qa=.3;function lF(e,t){const n=[...e];for(const r of[...t].sort((o,i)=>o-i)){const o=n.findIndex(s=>r>=s.startSec+Qa&&r<=s.endSec-Qa);if(o===-1)continue;const i=n[o];n.splice(o,1,{...i,endSec:r},{...i,id:`${i.id.split("@")[0]}@${Math.round(r*1e3)}`,startSec:r})}return n}function Sh(e,t){const n=[];return{cues:e.filter(o=>{var i;return((i=t.scenes[o.id])==null?void 0:i.hidden)!==!0?!0:(n.push(o.id),!1)}),hidden:n}}function uF(e,t){const n=[];if(Object.keys(t).length===0)return{lines:[...e],dropped:n};let r=0;return{lines:e.map(i=>({...i,words:i.words.map(s=>{const a=t[String(r++)];return a?s.text!==a.was?(n.push({index:r-1,expected:a.was,found:s.text}),s):{...s,text:a.text}:s})})),dropped:n}}function cF(e,t){return Yf.parse({...e,...t.theme})}function dF(e,t,n,r){const o=e.scenes[t]??_w.parse({});return{...e,scenes:{...e.scenes,[t]:{...o,elements:{...o.elements,[n]:{...o.elements[n],...r}}}}}}function fF(e,t,n){const r=e.scenes[t];if(!r)return e;const{[n]:o,...i}=r.elements;return{...e,scenes:{...e.scenes,[t]:{...r,elements:i}}}}function pF(e,t){const n=e.scenes[t];if(!n||!n.timing)return e;const{timing:r,...o}=n;return{...e,scenes:{...e.scenes,[t]:o}}}function mF(e,t){const n=e.scenes[t];if(!n||!n.graphicRect)return e;const{graphicRect:r,...o}=n;return{...e,scenes:{...e.scenes,[t]:o}}}const hF=.6;function gF(e,t){const n=new Set([0]);for(const r of e??[])Number.isFinite(r)&&r>0&&r<t&&n.add(r);return[...n].sort((r,o)=>r-o)}function vF(e,t){const n=t.outputDurationSec,r=[...e].sort((d,p)=>d.startSec-p.startSec);if(n<=0)return r;const o=gF(t.clipStarts,n),i=[];let s=0;for(const d of r)d.startSec-s>1e-9&&i.push({start:s,end:d.startSec}),s=Math.max(s,d.endSec);n-s>1e-9&&i.push({start:s,end:n});const a=[];for(const d of i){const p=o.filter(h=>h>d.start+1e-9&&h<d.end-1e-9),m=[d.start,...p,d.end];for(let h=0;h<m.length-1;h++){const w=m[h],v=m[h+1];if(v-w<hF)continue;let E=0;for(let g=0;g<o.length;g++)o[g]<=w+1e-9&&(E=g);a.push({start:w,end:v,clip:E})}}const l=new Map,u=a.map(d=>{const p=l.get(d.clip)??0;return l.set(d.clip,p+1),{id:p===0?`take-${d.clip}`:`take-${d.clip}-${p}`,kind:"plain",layout:"full-bleed",startSec:d.start,endSec:d.end}});return[...r,...u].sort((d,p)=>d.startSec-p.startSec)}const yF=1.05;function wF(e,t){for(const r of e)if(t>=r.startSec&&t<r.endSec){const o=r.endSec-r.startSec,i=o>0?(t-r.startSec)/o:1,s=.5-.5*Math.cos(Math.PI*i);return r.from+(r.to-r.from)*s}const n=e[e.length-1];return n&&t===n.endSec?n.to:1}function xF(e,t,n){if(e.length===0)return{x:0,y:0,w:(n==null?void 0:n.width)??0,h:(n==null?void 0:n.height)??0,full:!0};if(t<e[0].startSec)return e[0].rect;for(const r of e)if(t>=r.startSec&&t<r.endSec)return r.rect;return e[e.length-1].rect}const Lt={width:1080,height:1920};Lt.width;Lt.height;const gs={centerYFrac:.38,sizeFrac:.22},bF=.35,SF=.45,Rw=1-1/yF,EF=.4*Rw,kF=.6*Rw;function Pw(e,t,n=Lt){const r=e.w*n.width,o=e.h*n.height;return Math.max(o,r/(t.sourceAspect??n.width/n.height))}function CF(e,t,n=Lt){const r=e.h*n.height,o=Pw(e,t,n),i=o-r;if(i<=1)return .5;const s=t.sizeFrac??gs.sizeFrac,a=(t.centerYFrac-s/2-bF*s)*o,l=(t.centerYFrac+s/2)*o,u=(a+l)/2-SF*r,d=a-EF*r,p=l+kF*r-r,m=p<=d?Math.min(Math.max(u,p),d):p;return Math.min(1,Math.max(0,m/i))}function IF(e,t,n,r,o=Lt){if(r.length===0)return e;const i=t.h*o.height,s=Pw(t,n,o);if(s-i<=1)return e;const l=i/s,u=1-l;if(u<=0)return e;let d=e*u;for(let p=0;p<r.length+1;p++){const m=r.find(x=>{const b=x.y,k=x.y+x.h,S=d+l,C=b<d&&d<k,I=b<S&&S<k;return C||I});if(!m)break;const h=[],w=m.y+m.h;w<=u&&h.push(w);const v=m.y-l;if(v>=0&&h.push(v),m.h<=l){const x=Math.max(0,m.y+m.h-l),b=Math.min(u,m.y);x<=b&&h.push(Math.min(Math.max(d,x),b))}const E=n.sizeFrac??gs.sizeFrac,g=n.centerYFrac+E/2,y=h.filter(x=>x+l>=g);if(y.length===0)return e;d=y.reduce((x,b)=>Math.abs(b-d)<Math.abs(x-d)?b:x)}return Math.min(1,Math.max(0,d/u))}function TF(e,t,n=Lt){const r=e.w*n.width,o=e.h*n.height,i=Math.max(r,o*(t.sourceAspect??n.width/n.height)),s=i-r;if(s<=1||t.centerXFrac===void 0)return .5;const a=t.centerXFrac*i-r/2;return Math.min(1,Math.max(0,a/s))}const _F={top:.12,bottom:.22,right:.16,left:.04},RF={top:.06,bottom:.12,right:.05,left:.05};function kr(e=Lt){return e.width>e.height?RF:_F}function PF(e=Lt){const t=kr(e);return{x:t.left,y:t.top,w:1-t.left-t.right,h:1-t.top-t.bottom}}const FF=.08,MF=.05;function Ja(e,t=Lt){const n=PF(t),r=1e-9,o=(u,d,p)=>u<d-r?d:u>p+r?p:u,i=o(e.w,FF,n.w),s=o(e.h,MF,n.h),a=o(e.x,n.x,n.x+n.w-i),l=o(e.y,n.y,n.y+n.h-s);return{x:a,y:l,w:i,h:s}}const Eh=.045,bn={x:0,y:0,w:1,h:1},Vu=.3,Gr={x:.5-Vu/2,y:.66,w:Vu,h:Vu*1080/1920};function jr(e,t=gs,n=[],r=Lt){const o=a=>IF(CF(a,t,r),a,t,n,r),i=a=>TF(a,t,r),s=r.width>r.height;switch(e){case"full-bleed":return{video:{rect:bn,cornerRadius:0,blurPx:0,dim:0,opacity:1,objectPosY:o(bn),objectPosX:i(bn)},graphic:null,captionAnchor:.7};case"lower-third":{const a=s?{x:.05,y:.7,w:.62,h:.18}:{x:.04,y:.56,w:.8,h:.22};return{video:{rect:bn,cornerRadius:0,blurPx:0,dim:0,opacity:1,objectPosY:o(bn),objectPosX:i(bn)},graphic:a,captionAnchor:s?.62:.49}}case"split-left":case"split-right":{if(s){const l=e==="split-left",u={x:l?0:.5,y:0,w:.5,h:1};return{video:{rect:u,cornerRadius:0,blurPx:0,dim:0,opacity:1,objectPosY:o(u),objectPosX:i(u)},graphic:l?{x:.55,y:.2,w:.4,h:.56}:{x:.05,y:.2,w:.4,h:.56},captionAnchor:.82}}const a={x:0,y:0,w:1,h:.5};return{video:{rect:a,cornerRadius:0,blurPx:0,dim:0,opacity:1,objectPosY:o(a),objectPosX:i(a)},graphic:{x:.04,y:.58,w:.8,h:.2},captionAnchor:.53}}case"video-top":{const a={x:0,y:0,w:1,h:.42};return{video:{rect:a,cornerRadius:0,blurPx:0,dim:0,opacity:1,objectPosY:o(a),objectPosX:i(a)},graphic:{x:.04,y:.54,w:.8,h:.24},captionAnchor:.48}}case"pip-bubble":return{video:{rect:Gr,cornerRadius:1,blurPx:0,dim:0,opacity:1,objectPosY:o(Gr),objectPosX:i(Gr)},graphic:{x:.06,y:.14,w:.78,h:.42},captionAnchor:.61};case"graphic-only":return{video:{rect:Gr,cornerRadius:1,blurPx:0,dim:0,opacity:0,objectPosY:o(Gr),objectPosX:i(Gr)},graphic:{x:.04,y:.14,w:.8,h:.54},captionAnchor:.73};case"blurred-behind":return{video:{rect:bn,cornerRadius:0,blurPx:22,dim:.55,opacity:1,objectPosY:o(bn),objectPosX:i(bn)},graphic:{x:.07,y:.24,w:.77,h:.36},captionAnchor:.69}}}const jF={x:.07,y:.24,w:.77,h:.36};function Fw(e,t=Lt){return e.graphicRect?Ja(e.graphicRect,t):jr(e.layout,gs,[],t).graphic??jF}const Mw=.35;function nr(e,t){for(const n of e)if(t>=n.startSec&&t<n.endSec)return n;return null}function Ut(e,t,n){return e+(t-e)*n}function $F(e,t,n){return{x:Ut(e.x,t.x,n),y:Ut(e.y,t.y,n),w:Ut(e.w,t.w,n),h:Ut(e.h,t.h,n)}}function kh(e,t,n){return{rect:$F(e.rect,t.rect,n),cornerRadius:Ut(e.cornerRadius,t.cornerRadius,n),blurPx:Ut(e.blurPx,t.blurPx,n),dim:Ut(e.dim,t.dim,n),opacity:Ut(e.opacity,t.opacity,n),objectPosY:Ut(e.objectPosY,t.objectPosY,n),objectPosX:Ut(e.objectPosX,t.objectPosX,n)}}function el(e){return e*e*(3-2*e)}function jw(e){return e.filter(t=>!(t.kind==="plain"&&t.layout==="full-bleed"))}function Bu(e,t,n,r){const o=jr(e.layout,t,n,r).video,i=e.layout==="pip-bubble"?e.pip:void 0;if(!i)return o;const s={...o.rect,x:Math.min(Math.max(i.x??o.rect.x,0),1-o.rect.w),y:Math.min(Math.max(i.y??o.rect.y,0),1-o.rect.h)};return{...o,rect:s,cornerRadius:i.cornerRadius??o.cornerRadius}}function AF(e,t,n=gs,r=[],o=Lt){const i=jw(e),s=r.filter(g=>t>=g.startSec&&t<g.endSec),a=jr("full-bleed",n,s,o).video,l=nr(i,t);if(!l)return a;const u=Bu(l,n,s,o),d=Math.min(Mw,(l.endSec-l.startSec)/2),p=t-l.startSec,m=l.endSec-t,h=nr(i,l.startSec-.001),w=nr(i,l.endSec+.001),v=h?Bu(h,n,s,o):a,E=w?Bu(w,n,s,o):a;return p<d?kh(v,u,el(p/d)):m<d?kh(u,E,el(1-m/d)):u}function Wu(e){return e==="pip-bubble"||e==="graphic-only"?1:0}function NF(e,t){const n=jw(e),r=nr(n,t);if(!r)return 0;const o=Wu(r.layout),i=Math.min(Mw,(r.endSec-r.startSec)/2),s=nr(n,r.startSec-.001),a=nr(n,r.endSec+.001),l=s?Wu(s.layout):0,u=a?Wu(a.layout):0,d=t-r.startSec,p=r.endSec-t;return d<i?Ut(l,o,el(d/i)):p<i?Ut(o,u,el(1-p/i)):o}function LF(e,t,n){return e.filter(r=>(r.startSec??Number.NEGATIVE_INFINITY)<n&&(r.endSec??Number.POSITIVE_INFINITY)>t)}function zF(e,t){let n=0;for(const r of t){const o=Math.max(e.y,r.y),i=Math.min(e.y+e.h,r.y+r.h);i>o&&(n+=i-o)}return Math.min(1,n/e.h)}function DF(e,t,n,r=Lt){const o=jr(e,void 0,[],r),i=kr(r),s=o.captionAnchor,a=l=>{const u={y:l-Eh,h:Eh*2};if(u.y<i.top||u.y+u.h>1-i.bottom||zF(u,t)>0)return!1;const d=n??o.graphic;return!(d&&Math.min(u.y+u.h,d.y+d.h)-Math.max(u.y,d.y)>0)};if(a(s))return s;for(let l=.02;l<=.6;l+=.02)for(const u of[s-l,s+l])if(a(u))return u;return s}const Ch=.4;function OF(e,t){if(!t)return e;const n=e.replace(/^[^A-Za-z0-9]+|[^A-Za-z0-9]+$/g,"");return n.toLowerCase()!==t.toLowerCase()?e:e.replace(n,`"${n.toUpperCase()}"`)}function VF(e,t){return t?e>=t.startSec-Ch&&e<=t.endSec+Ch:!1}const BF=({line:e,wordOffset:t,verticalAnchor:n,fontSizePx:r,activeColor:o,ctaKeyword:i,ctaWindow:s})=>{const a=ht(),{fps:l,width:u,height:d}=Xe(),p=kr({width:u,height:d}),m=e.start+a/l;return f.jsx(an,{style:{pointerEvents:"none"},children:f.jsx("div",{style:{position:"absolute",top:`${n*100}%`,left:0,right:0,transform:"translateY(-50%)",display:"flex",justifyContent:"center",gap:"0.28em",flexWrap:"wrap",paddingLeft:`${p.left*100}%`,paddingRight:`${p.right*100}%`,fontFamily:"'Inter', 'Helvetica Neue', 'Arial Black', Arial, sans-serif",fontWeight:900,fontSize:r,lineHeight:1.15,textAlign:"center",color:"white",WebkitTextStroke:"10px rgba(0,0,0,0.85)",paintOrder:"stroke fill",textShadow:"0 4px 24px rgba(0,0,0,0.55)"},children:e.words.map((h,w)=>{const v=m>=h.start&&m<=Math.max(h.end,h.start+.12);return f.jsx("span",{"data-caption-word":t+w,"data-caption-text":h.text,style:{display:"inline-block",pointerEvents:"auto",transform:v?"scale(1.08)":"scale(1)",color:v?o:"white",transition:"transform 60ms linear"},children:OF(h.text,VF(h.start,s)?i:void 0)},w)})})})},WF=({lines:e,cues:t=[],verticalAnchor:n=.76,fontSizePx:r=64,activeColor:o="#FFE14D",ctaKeyword:i,ctaWindow:s,sourceTextRegions:a=[]})=>{const{fps:l,width:u,height:d}=Xe(),p={width:u,height:d},m=[];let h=0;for(const w of e)m.push(h),h+=w.words.length;return f.jsx(an,{children:e.map((w,v)=>{const E=t.length>0?nr(t,w.start):null,g=(E==null?void 0:E.captionY)!==void 0?E.captionY:t.length>0||a.length>0?DF((E==null?void 0:E.layout)??"full-bleed",LF(a,w.start,w.end),E==null?void 0:E.graphicRect,p):n,y=Math.round(w.start*l),x=Math.max(1,Math.round((w.end-w.start)*l));return f.jsx(at,{from:y,durationInFrames:x,children:f.jsx(BF,{line:w,wordOffset:m[v],verticalAnchor:g,fontSizePx:r*((E==null?void 0:E.captionScale)??1),activeColor:o,ctaKeyword:i,ctaWindow:s})},v)})})};function UF(e,t,n,r=.5,o=.5){const i=Math.max(1,e.width),s=Math.max(1,e.height),a=Math.max(1,t.w),l=Math.max(1,t.h),u=Math.max(n.width/a,n.height/l),d=-t.x*u+(n.width-a*u)*Ih(r),p=-t.y*u+(n.height-l*u)*Ih(o);return{width:i*u,height:s*u,left:d,top:p}}function Ih(e){return Number.isFinite(e)?Math.min(1,Math.max(0,e)):.5}function $w(e,t,n){const r=Math.max(1,e.width),o=Math.max(1,e.height),i=Math.max(1,t.w),s=Math.max(1,t.h),a=Math.min(n.width/i,n.height/s),l=-t.x*a+(n.width-i*a)/2,u=-t.y*a+(n.height-s*a)/2;return{width:r*a,height:o*a,left:l,top:u}}function HF(e,t){return $w(e,{x:0,y:0,w:e.width,h:e.height},t)}function ZF(e,t){if(e.length===0)return t;for(const o of e)if(t>=o.outIn&&t<o.outOut)return o.srcIn+(t-o.outIn);const n=e[0];return t<n.outIn?n.srcIn:e[e.length-1].srcOut}function YF(e,t,n,r,o,i){return e==="fit"?$w(t,n,r):UF(t,n,r,o,i)}function KF(e,t,n,r){return e.length===0?{x:0,y:0,w:r.width,h:r.height,full:!0}:xF(e,ZF(t,n),r)}const XF=({cues:e,theme:t,face:n,zoomPlan:r,sourceTextRegions:o,contentTimeline:i,spans:s,sourceSize:a,contentCropMode:l="cover",sourceFit:u="cover",children:d})=>{const p=ht(),{fps:m,width:h,height:w}=Xe(),v=p/m,g=AF(e,v,n??void 0,o??[],{width:h,height:w}),y=NF(e,v),x=g.rect.w*h,b=g.rect.h*w,k=g.cornerRadius*Math.min(x,b)/2,S=nr(e,v),C=S==null?void 0:S.video,I=r&&r.length>0?wF(r,v):1,F=Math.max(0,g.opacity*(1-.6*g.cornerRadius)),j=(C==null?void 0:C.autoZoom)!==!1,P=u==="contain"&&a!==void 0,A=j&&!P?1+(I-1)*F:1,V=(C==null?void 0:C.scale)??1,_=(C==null?void 0:C.dx)??0,L=(C==null?void 0:C.dy)??0,O=[_!==0||L!==0?`translate(${_}px, ${L}px)`:"",A*V!==1?`scale(${A*V})`:""].filter(Boolean).join(" ")||void 0;return f.jsxs(an,{children:[f.jsx(an,{style:{background:t.bg,opacity:y}}),f.jsxs("div",{"data-edit-video":S==null?void 0:S.id,style:{position:"absolute",left:`${g.rect.x*100}%`,top:`${g.rect.y*100}%`,width:x,height:b,borderRadius:k,overflow:"hidden",opacity:g.opacity,backgroundColor:P?t.bg:void 0,boxShadow:g.cornerRadius>.5?"0 18px 60px rgba(0,0,0,0.55)":void 0},children:[f.jsx("div",{style:{position:"absolute",inset:0,filter:g.blurPx>.5?`blur(${g.blurPx}px)`:void 0,transform:O,transformOrigin:"50% 40%","--ossclip-obj-y":`${g.objectPosY*100}%`,"--ossclip-obj-x":`${g.objectPosX*100}%`},children:P?f.jsx(GF,{source:a,slot:{width:x,height:b},children:d}):f.jsx(qF,{timeline:i,spans:s,sourceSize:a,mode:l,tSec:v,slot:{width:x,height:b},posX:g.objectPosX,posY:g.objectPosY,children:d})}),f.jsx("div",{style:{position:"absolute",inset:0,background:"black",opacity:g.dim}})]})]})},GF=({source:e,slot:t,children:n})=>{const r=HF(e,t);return f.jsx("div",{style:{position:"absolute",width:r.width,height:r.height,left:r.left,top:r.top},children:n})},qF=({timeline:e,spans:t,sourceSize:n,mode:r,tSec:o,slot:i,posX:s,posY:a,children:l})=>{const u=f.jsx("div",{style:{position:"absolute",inset:0},children:l});if(!e||e.length<2||!n)return u;const d=KF(e,t??[],o,n);if(d.full)return u;const p=YF(r,n,d,i,s,a);return f.jsx("div",{style:{position:"absolute",width:p.width,height:p.height,left:p.left,top:p.top},children:l})},Kf=.94,QF=new Set(["FlowDiagram","StrikethroughReveal","ChatMock","BulletList"]),Th=2.4,qs=.45,Xl=.58,vt=.72,JF=.62;function Qr(e,t,n,r,o){const i=Math.max(1,Math.floor(n/Math.max(1,o*t)));return Math.max(1,Math.ceil(e/i))*t*r}const Me=e=>typeof e=="string"?e:"",Hn=e=>Array.isArray(e)?e:[];function e4(e,t,n,r=1/0){switch(e){case"TitleCard":{const o=n-80,i=Me(t.emphasis),s=28;let a=0,l=0;Me(t.eyebrow)&&(a+=34*1.2,l++),i&&(a+=210*.95,l++);const u=i?64:96;return a+=Qr(Me(t.title).length,u,o,1.05,vt),l++,Me(t.sub)&&(a+=Qr(Me(t.sub).length,40,o,1.2,Xl),l++),a+s*Math.max(0,l-1)}case"StatCard":{const o=Qr(Me(t.label).length,42,n*.55,1.15,vt);let i=88+Math.max(o,110*1.15)+4;return Me(t.caption)&&(i+=30+(38*1.2+32+4)),i}case"RuleCard":{const o=n-60-96;let i=80;return i+=30*1.2+14,i+=Qr(Me(t.text).length,72,o,1.02,vt),Me(t.struck)&&(i+=26+Qr(Me(t.struck).length,44,o,1.2,vt)),i}case"StrikethroughReveal":{const o=Hn(t.lines).map(a=>Me(a==null?void 0:a.text)),i=Dw(o,n,r),s=o.reduce((a,l)=>a+zw(l,i,n).length,0);return s*i*1.08+i*.2*Math.max(0,s-1)}case"FlowDiagram":{const o=Hn(t.nodes).map(l=>Me(l)),i=Math.max(1,o.length),{mode:s,fontSize:a}=Zw(o,n,r);return s==="row"?a*_i+4:a*(_i*i+Hw*(i-1))}case"TerminalMock":{const o=Hn(t.windows);let i=0;for(const s of o){const a=Hn(s==null?void 0:s.lines);i+=56.8+2,i+=Math.max(1,a.length)*27*1.2+8*Math.max(0,a.length-1)+36,i+=4}return i+=22*Math.max(0,o.length-1),Me(t.fanOut)&&(i+=22+40*1.2),i}case"ChatMock":{const o=Ww(t).map(s=>s.text),i=Uw(o,{widthPx:n,heightPx:r});return Bw(o,i,n)}case"ScreenshotFrame":{const o=n*.94;return(Me(t.src)?o*9/16:480)+4}case"BulletList":{const o=Hn(t.items).map(s=>Me(s)),i=Lw(o,n,r,!!Me(t.title));return o4(o.length,i,!!Me(t.title))}}}const Dn=e=>Me(e).split(/\s+/).reduce((t,n)=>Math.max(t,n.length),0);function t4(e,t){switch(e){case"RuleCard":{const n=Dn(t.kicker)*30*(vt+.28),r=Dn(t.text)*72*vt,o=Dn(t.struck)*44*(vt+.04),i=Math.max(n,r,o);return i>0?156+i:0}case"TitleCard":{const n=Me(t.emphasis)?64:96,r=Dn(t.eyebrow)*34*(vt+.35),o=Dn(t.emphasis)*210*vt,i=Dn(t.title)*n*(vt+.02),s=Dn(t.sub)*40*Xl,a=Math.max(r,o,i,s);return a>0?80+a:0}case"TerminalMock":{let n=0;for(const r of Hn(t.windows))for(const o of Hn(r==null?void 0:r.lines))n=Math.max(n,Me(o).length);return n>0?108+n*27*JF:0}case"StatCard":{const n=Me(t.value).length*110*vt;return n===0?0:164+Dn(t.label)*42*vt+40+n}default:return 0}}const _h=36,n4=120,Aw=1.6,Nw=1.1,r4=1.1;function o4(e,t,n){return(Math.max(1,e)*Aw+(n?Nw:0))*t}function Lw(e,t=831,n=1/0,r=!1){const o=e.reduce((a,l)=>Math.max(a,l.length),0);if(o===0)return _h;const i=t/(o*vt+r4),s=n*Kf/(Math.max(1,e.length)*Aw+(r?Nw:0));return Math.max(_h,Math.min(n4,Math.floor(Math.min(i,s))))}const i4=92,s4=44,a4=150,l4=[" → "," -> "," → "," > "];function zw(e,t,n){const r=o=>o.length*t*vt<=n;if(r(e))return[e];for(const o of l4){if(!e.includes(o))continue;const s=e.split(o).map((a,l)=>l===0?a:`${o.trim()} ${a}`.trim());if(s.every(r))return s}return[e]}function Dw(e,t=831,n=1/0){const r=e.reduce((s,a)=>Math.max(s,a.length),0);if(r===0)return i4;const o=t/(r*vt),i=n/(Math.max(1,e.length)*1.28);return Math.max(s4,Math.min(a4,Math.floor(Math.min(o,i))))}const Rh=22,Ph=44,u4=96,Fh=22,Ow=.85,Vw=.82;function Bw(e,t,n){const o=(n-80)*Vw-2*t*Ow;let i=0;for(const s of e)i+=Qr(s.length,t,o,1.2,Xl)+t*1.2+4;return i+t*.5*Math.max(0,e.length-1)}function Ww(e){const t=Me(e.keyword);return t?[{from:"user",text:`"${t.toUpperCase()}"`}]:Hn(e.messages).map(n=>{const r=n??{};return{from:r.from==="agent"?"agent":"user",text:Me(r.text)}})}function Uw(e,t={}){const n=t.widthPx??831,r=t.heightPx??1/0,o=n-80,i=e.reduce((p,m)=>Math.max(p,m.length),0);if(i===0)return Ph;const s=e.flatMap(p=>p.split(/\s+/)).reduce((p,m)=>Math.max(p,m.length),0),a=p=>o*Vw/(p*Xl+2*Ow),l=Math.min(i,Fh),u=i>Fh?Ph:u4;let d=Math.floor(Math.min(a(l),a(s),u));for(;d>Rh&&Bw(e,d,n)>r*Kf;)d-=1;return Math.max(Rh,d)}const Mh=26,c4=22,d4=76,_i=2.1,Hw=2.05;function Zw(e,t,n=1/0){const r=e.reduce((v,E)=>v+E.length,0),o=Math.max(1,e.length),i=.78,s=1.6,a=1.8,l=t-20,u=Math.floor(Math.min(l/(i*r+s*o+a*(o-1)),n/_i)),d=Math.max(...e.map(v=>v.length),1),p=_i*o+Hw*(o-1),m=Math.floor(Math.min(l/(i*d+s),n/p,d4)),h=u>=Mh;return m>=c4?h?u*_i>=m*p?{mode:"row",fontSize:u}:{mode:"stack",fontSize:m}:{mode:"stack",fontSize:m}:{mode:"row",fontSize:Math.max(Mh,u)}}function f4(e,t,n){if(QF.has(e))return 1;const r=n.heightPx*Kf,o=u=>e4(e,t,n.widthPx/u)*u<=r;if(!o(qs))return qs;const i=t4(e,t),s=i>0?n.widthPx/i:Th;let a=qs,l=Math.max(qs,Math.min(Th,s));if(l<=a)return a;for(let u=0;u<24;u++){const d=(a+l)/2;o(d)?a=d:l=d}return a}function tt(e=0){const t=ht(),{fps:n}=Xe();return Qc({frame:t-e,fps:n,config:{damping:200,stiffness:130},durationInFrames:Math.round(n*.5)})}function hn(e,t=26){return{opacity:e,transform:`translateY(${(1-e)*t}px)`}}function $r(e){return{opacity:e,transform:`scale(${.9+.1*e})`}}function p4(e,t){return!e||t===1?e:Object.fromEntries(Object.entries(e).map(([n,r])=>[n,{...r,...r.dx!==void 0?{dx:r.dx/t}:{},...r.dy!==void 0?{dy:r.dy/t}:{}}]))}function Ye(e,t){const n=e==null?void 0:e[t];if(!n)return{};const r=[`translate(${n.dx??0}px, ${n.dy??0}px)`];return n.scale!==void 0&&n.scale!==1&&r.push(`scale(${n.scale})`),{transform:r.join(" ")}}const m4=({props:e,theme:t,edits:n})=>{var l;const r=tt(0),o=tt(5),i=tt(10),s=(l=e.emphasis)==null?void 0:l.trim(),a=!!s&&s.toLowerCase().includes(e.title.trim().toLowerCase());return f.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:28,textAlign:"center",fontFamily:t.fontDisplay,color:t.fg,padding:"0 40px"},children:[e.eyebrow?f.jsx("div",{"data-edit-id":"eyebrow",style:{...hn(r),fontSize:34,fontWeight:700,letterSpacing:"0.35em",color:t.muted,textTransform:"uppercase",...Ye(n,"eyebrow")},children:e.eyebrow}):null,s?f.jsx("div",{"data-edit-id":"emphasis",style:{...hn(o,40),fontSize:210,fontWeight:900,lineHeight:.95,...Ye(n,"emphasis")},children:s}):null,a?null:f.jsx("div",{"data-edit-id":"title",style:{...hn(s?i:o,34),fontSize:s?64:96,fontWeight:900,lineHeight:1.05,textTransform:"uppercase",letterSpacing:"0.02em",...Ye(n,"title")},children:e.title}),e.sub?f.jsx("div",{"data-edit-id":"sub",style:{...hn(i),fontSize:40,fontWeight:600,color:t.muted,...Ye(n,"sub")},children:e.sub}):null]})},h4=({props:e,theme:t,edits:n})=>{const r=tt(0),o=tt(6),i=e.inverted;return f.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:30,fontFamily:t.fontDisplay,width:"100%",padding:"0 30px"},children:[f.jsxs("div",{style:{...$r(r),display:"flex",alignItems:"center",justifyContent:"space-between",gap:40,width:"100%",background:i?t.fg:t.cardBg,color:i?t.bg:t.fg,border:`2px solid ${i?t.fg:t.cardBorder}`,borderRadius:t.radiusPx,padding:"44px 52px"},children:[f.jsx("div",{"data-edit-id":"label",style:{fontSize:42,fontWeight:800,textTransform:"uppercase",letterSpacing:"0.06em",lineHeight:1.15,maxWidth:"55%",...Ye(n,"label")},children:e.label}),f.jsx("div",{"data-edit-id":"value",style:{fontSize:110,fontWeight:900,whiteSpace:"nowrap",...Ye(n,"value")},children:e.value})]}),e.caption?f.jsx("div",{"data-edit-id":"caption",style:{...hn(o),fontSize:38,fontWeight:800,color:t.fg,background:t.cardBg,border:`2px solid ${t.cardBorder}`,borderRadius:t.radiusPx/2,padding:"16px 30px",textTransform:"uppercase",letterSpacing:"0.08em",...Ye(n,"caption")},children:e.caption}):null]})},g4=({props:e,theme:t,edits:n})=>{const r=tt(0),o=tt(8);return f.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:26,fontFamily:t.fontDisplay,width:"100%",padding:"0 30px"},children:[f.jsxs("div",{style:{...$r(r),width:"100%",background:t.fg,color:t.bg,borderRadius:t.radiusPx,padding:"40px 48px",textAlign:"left"},children:[f.jsx("div",{"data-edit-id":"kicker",style:{fontSize:30,fontWeight:800,letterSpacing:"0.28em",textTransform:"uppercase",color:"#55555E",marginBottom:14,fontFamily:t.fontMono,...Ye(n,"kicker")},children:e.kicker}),f.jsx("div",{"data-edit-id":"text",style:{fontSize:72,fontWeight:900,lineHeight:1.02,textTransform:"uppercase",...Ye(n,"text")},children:e.text})]}),e.struck?f.jsx("div",{"data-edit-id":"struck",style:{...hn(o),fontSize:44,fontWeight:800,color:t.muted,textDecoration:"line-through",textDecorationThickness:6,textDecorationColor:t.danger,textTransform:"uppercase",letterSpacing:"0.04em",...Ye(n,"struck")},children:e.struck}):null]})},v4=({text:e,struck:t,mark:n,delay:r,fontSize:o,theme:i,editId:s,edits:a})=>{const l=tt(r),u=tt(r+8);return f.jsxs("div",{"data-edit-id":s,style:{...hn(l,30),position:"relative",display:"inline-block",...Ye(a,s)},children:[f.jsxs("span",{style:{fontSize:o,fontWeight:900,textTransform:"uppercase",lineHeight:1.08,whiteSpace:"nowrap",color:t?i.muted:i.fg},children:[n!=="none"?f.jsx("span",{style:{color:n==="cross"?i.danger:i.success,marginRight:"0.3em"},children:n==="cross"?"✗":"✓"}):null,e]}),t?f.jsx("div",{style:{position:"absolute",left:"-2%",top:"50%",height:o*.11,width:`${u*104}%`,background:i.danger,borderRadius:o*.055,transform:"translateY(-50%) rotate(-2deg)"}}):null]})},y4=({props:e,theme:t,widthPx:n,heightPx:r,edits:o})=>{const i=e.lines.map(l=>(l.mark??"none")!=="none"?`✗ ${l.text}`:l.text),s=Dw(i,n,r),a=e.lines.flatMap((l,u)=>zw(l.text,s,n??831).map((d,p)=>({text:d,struck:l.struck,mark:p===0?l.mark??"none":"none",lineIndex:u})));return f.jsx("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:s*.2,textAlign:"center",fontFamily:t.fontDisplay},children:a.map((l,u)=>f.jsx(v4,{text:l.text,struck:l.struck,mark:l.mark,delay:u*6,fontSize:s,theme:t,editId:`line-${l.lineIndex}`,edits:o},u))})},w4=({text:e,emphasized:t,delay:n,fontSize:r,theme:o,editId:i,edits:s})=>{const a=tt(n);return f.jsx("div",{"data-edit-id":i,style:{...$r(a),background:t?o.fg:o.cardBg,color:t?o.bg:o.fg,border:`2px solid ${t?o.fg:o.cardBorder}`,borderRadius:o.radiusPx/2,padding:`${r*.55}px ${r*.8}px`,fontSize:r,fontWeight:900,textTransform:"uppercase",letterSpacing:"0.04em",whiteSpace:"nowrap",fontFamily:o.fontDisplay,...Ye(s,i)},children:e})},x4=({delay:e,fontSize:t,theme:n,down:r=!1})=>{const o=tt(e);return f.jsx("div",{style:{opacity:o,color:n.muted,fontSize:t*1.15,fontWeight:700,lineHeight:1,paddingLeft:r?0:t*.55},children:r?"↓":"→"})};function b4(e,t=S4,n){return Zw(e,t,n)}const S4=864,E4=({props:e,theme:t,widthPx:n,heightPx:r,edits:o})=>{const{mode:i,fontSize:s}=b4(e.nodes,n,r),a=i==="row";return f.jsx("div",{style:{display:"flex",flexDirection:a?"row":"column",flexWrap:"nowrap",alignItems:"center",justifyContent:"center",gap:a?0:s*.45,padding:"0 10px"},children:e.nodes.map((l,u)=>f.jsxs("div",{style:{display:"flex",flexDirection:a?"row":"column",alignItems:"center",gap:a?s*.55:s*.45},children:[u>0?f.jsx(x4,{delay:u*6+3,fontSize:s,theme:t,down:!a}):null,f.jsx(w4,{text:l,emphasized:e.emphasizeLast&&u===e.nodes.length-1,delay:u*6,fontSize:s,theme:t,editId:`node-${u}`,edits:o})]},u))})},k4=({title:e,lines:t,delay:n,theme:r,editId:o,edits:i})=>{const s=tt(n);return f.jsxs("div",{"data-edit-id":o,style:{...$r(s),background:r.cardBg,border:`2px solid ${r.cardBorder}`,borderRadius:r.radiusPx/2,overflow:"hidden",width:"100%",fontFamily:r.fontMono,...Ye(i,o)},children:[f.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,padding:"14px 20px",borderBottom:`2px solid ${r.cardBorder}`},children:[["#FF5F57","#FEBC2E","#28C840"].map(a=>f.jsx("div",{style:{width:16,height:16,borderRadius:8,background:a}},a)),f.jsx("div",{style:{marginLeft:10,fontSize:24,color:r.muted},children:e})]}),f.jsx("div",{style:{padding:"18px 22px",display:"flex",flexDirection:"column",gap:8},children:t.map((a,l)=>f.jsx("div",{style:{fontSize:27,color:r.fg,whiteSpace:"pre"},children:a},l))})]})},C4=({props:e,theme:t,edits:n})=>{const r=tt(e.windows.length*6+4);return f.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:22,width:"100%",padding:"0 30px"},children:[e.windows.map((o,i)=>f.jsx(k4,{title:o.title,lines:o.lines,delay:i*6,theme:t,editId:`window-${i}`,edits:n},i)),e.fanOut?f.jsxs("div",{"data-edit-id":"fanOut",style:{...hn(r),fontFamily:t.fontDisplay,fontSize:40,fontWeight:900,letterSpacing:"0.2em",color:t.fg,textTransform:"uppercase",...Ye(n,"fanOut")},children:["⌄ ",e.fanOut]}):null]})},I4=({from:e,text:t,delay:n,fontSize:r,theme:o,editId:i,edits:s})=>{const a=tt(n),l=e==="user";return f.jsx("div",{"data-edit-id":i,style:{...$r(a),alignSelf:l?"flex-end":"flex-start",background:l?o.fg:o.cardBg,color:l?o.bg:o.fg,border:`2px solid ${l?o.fg:o.cardBorder}`,borderRadius:28,[l?"borderBottomRightRadius":"borderBottomLeftRadius"]:8,padding:`${r*.6}px ${r*.85}px`,fontSize:r,fontWeight:700,maxWidth:"82%",fontFamily:o.fontDisplay,...Ye(s,i)},children:t})},T4=({props:e,theme:t,widthPx:n,heightPx:r,edits:o})=>{const i=Ww(e),s=Uw(i.map(a=>a.text),{widthPx:n,heightPx:r});return f.jsx("div",{style:{display:"flex",flexDirection:"column",gap:s*.5,width:"100%",padding:"0 40px"},children:i.map((a,l)=>f.jsx(I4,{from:a.from,text:a.text,delay:l*8,fontSize:s,theme:t,editId:`message-${l}`,edits:o},l))})},_4=({props:e,theme:t,edits:n})=>{const r=tt(0),o=tt(8),i=ht(),{fps:s}=Xe(),a=e.kenBurns?Bo(i,[0,s*8],[1,1.08],{extrapolateRight:"clamp"}):1,l=e.src?/^https?:\/\//.test(e.src)?e.src:K0(e.src):null;return f.jsxs("div",{"data-edit-id":"image",style:{...$r(r),position:"relative",width:"94%",...Ye(n,"image")},children:[f.jsx("div",{style:{overflow:"hidden",borderRadius:t.radiusPx/2,border:`2px solid ${t.cardBorder}`,background:t.cardBg,boxShadow:"0 24px 80px rgba(0,0,0,0.5)"},children:l?f.jsx(jf,{src:l,style:{width:"100%",display:"block",transform:`scale(${a})`}}):f.jsx("div",{style:{height:420,display:"flex",flexDirection:"column",gap:14,padding:30,transform:`scale(${a})`},children:[.9,.75,.85,.6,.8,.5].map((u,d)=>f.jsx("div",{style:{height:22,width:`${u*100}%`,borderRadius:6,background:d%3===0?t.cardBorder:"#22222B"}},d))})}),e.label?f.jsx("div",{"data-edit-id":"label",style:{...$r(o),position:"absolute",right:-8,bottom:-20,background:t.fg,color:t.bg,fontFamily:t.fontMono,fontSize:28,fontWeight:800,letterSpacing:"0.08em",padding:"12px 22px",borderRadius:10,textTransform:"uppercase",...Ye(n,"label")},children:e.label}):null]})},R4=({text:e,index:t,fontSize:n,theme:r,edits:o})=>{const i=`item-${t}`,s=tt(t*7);return f.jsxs("div",{"data-edit-id":i,style:{...hn(s,26),display:"flex",alignItems:"baseline",gap:n*.35,...Ye(o,i)},children:[f.jsx("span",{style:{fontSize:n*.75,color:r.accent,fontWeight:900},children:"▸"}),f.jsx("span",{style:{fontSize:n,fontWeight:900,textTransform:"uppercase",lineHeight:1.15,whiteSpace:"nowrap",color:r.fg},children:e})]})},P4=({props:e,theme:t,widthPx:n,heightPx:r,edits:o})=>{const i=Lw(e.items,n,r,!!e.title),s=tt(0);return f.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"flex-start",gap:i*.45,fontFamily:t.fontDisplay},children:[e.title?f.jsx("div",{"data-edit-id":"title",style:{...hn(s,20),fontSize:i*.36,fontWeight:700,letterSpacing:"0.28em",textTransform:"uppercase",color:t.muted,...Ye(o,"title")},children:e.title}):null,e.items.map((a,l)=>f.jsx(R4,{text:a,index:l,fontSize:i,theme:t,edits:o},l))]})},F4={TitleCard:m4,StatCard:h4,RuleCard:g4,StrikethroughReveal:y4,FlowDiagram:E4,TerminalMock:C4,ChatMock:T4,ScreenshotFrame:_4,BulletList:P4},M4=.3,j4=new Set(["lower-third","full-bleed"]),$4=.55,A4=e=>{const t=/^#([0-9a-fA-F]{6})$/.exec(e.trim()),[n,r,o]=t?[0,2,4].map(i=>Number.parseInt(t[1].slice(i,i+2),16)):[0,0,0];return`rgba(${n}, ${r}, ${o}, ${$4})`},N4=({durationInFrames:e,children:t})=>{const n=ht(),{fps:r}=Xe(),o=(e-n)/r,i=Math.min(1,Math.max(0,o/M4)),s=i*(2-i);return f.jsx("div",{style:{width:"100%",height:"100%",display:"flex",alignItems:"center",justifyContent:"center",opacity:s,transform:s<1?`translateY(${(1-s)*18}px)`:void 0},children:t})},L4=({cues:e,theme:t})=>{const{fps:n,width:r,height:o}=Xe();return f.jsx(an,{style:{pointerEvents:"none"},children:e.map(i=>{if(i.kind==="plain"||!i.component||!i.props)return null;const s=Fw(i,{width:r,height:o}),a=F4[i.component],l=Math.round(i.startSec*n),u=Math.max(1,Math.round((i.endSec-i.startSec)*n)),d=s.w*r,p=s.h*o,m=j4.has(i.layout),h=m?Math.min(24,Math.round(p*.12)):0,w=d-h*2,v=p-h*2,E=f4(i.component,i.props,{widthPx:w,heightPx:v});return f.jsx(at,{from:l,durationInFrames:u,children:f.jsx("div",{"data-edit-scene":i.id,style:{position:"absolute",left:`${s.x*100}%`,top:`${s.y*100}%`,width:`${s.w*100}%`,height:`${s.h*100}%`,display:"flex",alignItems:"center",justifyContent:"center",pointerEvents:"auto",overflow:"hidden"},children:f.jsxs(N4,{durationInFrames:u,children:[m?f.jsx("div",{style:{position:"absolute",inset:0,background:A4(t.bg),backdropFilter:"blur(14px)",WebkitBackdropFilter:"blur(14px)",borderRadius:t.radiusPx}}):null,f.jsx("div",{style:{width:w/E,transform:`scale(${E})`,position:"relative"},children:f.jsx(a,{props:i.props,theme:t,widthPx:w/E,heightPx:v/E,edits:p4(i.elements,E)})})]})})},i.id)})})},z4=({videoFileName:e,spans:t,captionLines:n,sceneCues:r,theme:o,face:i,zoomPlan:s,ctaKeyword:a,ctaWindow:l,sourceTextRegions:u,contentTimeline:d,sourceSize:p,contentCropMode:m,sourceFit:h})=>{if(!e)return f.jsx(an,{style:{backgroundColor:"#111",color:"#888",alignItems:"center",justifyContent:"center",fontFamily:"monospace",fontSize:40},children:"no production loaded"});const w=/^https?:\/\//.test(e)?e:K0(e);return f.jsxs(an,{style:{backgroundColor:"black"},children:[f.jsx(XF,{cues:r,theme:o,face:i,zoomPlan:s,sourceTextRegions:u,contentTimeline:d,spans:t,sourceSize:p,contentCropMode:m,sourceFit:h,children:f.jsx(KI,{src:w,spans:t,...h==="contain"?{punchInScale:1,background:"transparent"}:{}})}),f.jsx(L4,{cues:r,theme:o}),f.jsx(WF,{lines:n,cues:r,activeColor:o.accent,ctaKeyword:a,ctaWindow:l,sourceTextRegions:u})]})},D4=600,O4=()=>({doc:iF(),past:[],future:[],dirty:!1,savedAt:0,lastCoalesce:null}),cn=(e,t)=>e.scenes[t]??{props:{},elements:{}};function V4(e,t){const n=(r,o)=>{const i=Date.now(),s=o!==void 0&&e.lastCoalesce!==null&&e.lastCoalesce.key===o&&i-e.lastCoalesce.at<D4;return{doc:r,past:s?e.past:[...e.past,e.doc],future:[],dirty:!0,savedAt:e.savedAt,lastCoalesce:o!==void 0?{key:o,at:i}:null}};switch(t.type){case"load":return{doc:t.doc,past:[],future:[],dirty:!1,savedAt:0,lastCoalesce:null};case"patchProps":{const r=cn(e.doc,t.sceneId);return n({...e.doc,scenes:{...e.doc.scenes,[t.sceneId]:{...r,props:{...r.props,...t.patch}}}},t.coalesce)}case"patchElement":return n(dF(e.doc,t.sceneId,t.elementId,t.patch),t.coalesce);case"clearElement":return n(fF(e.doc,t.sceneId,t.elementId));case"patchTiming":{const r=cn(e.doc,t.sceneId);return n({...e.doc,scenes:{...e.doc.scenes,[t.sceneId]:{...r,timing:{startSec:t.startSec,endSec:t.endSec}}}})}case"clearTiming":return n(pF(e.doc,t.sceneId));case"patchVideo":{const r=cn(e.doc,t.sceneId);return n({...e.doc,scenes:{...e.doc.scenes,[t.sceneId]:{...r,video:{...r.video,...t.patch}}}},t.coalesce)}case"clearVideo":{const r=e.doc.scenes[t.sceneId];if(!(r!=null&&r.video))return e;const{video:o,...i}=r;return n({...e.doc,scenes:{...e.doc.scenes,[t.sceneId]:i}})}case"patchPip":{const r=cn(e.doc,t.sceneId);return n({...e.doc,scenes:{...e.doc.scenes,[t.sceneId]:{...r,pip:{...r.pip,...t.patch}}}},t.coalesce)}case"clearPip":{const r=e.doc.scenes[t.sceneId];if(!(r!=null&&r.pip))return e;const{pip:o,...i}=r;return n({...e.doc,scenes:{...e.doc.scenes,[t.sceneId]:i}})}case"patchCaptionY":{const r=cn(e.doc,t.sceneId);return n({...e.doc,scenes:{...e.doc.scenes,[t.sceneId]:{...r,captionY:t.y}}},t.coalesce)}case"patchCaptionScale":{const r=cn(e.doc,t.sceneId);return n({...e.doc,scenes:{...e.doc.scenes,[t.sceneId]:{...r,captionScale:t.scale}}},t.coalesce)}case"clearCaptionStyle":{const r=e.doc.scenes[t.sceneId];if((r==null?void 0:r.captionY)===void 0&&(r==null?void 0:r.captionScale)===void 0)return e;const{captionY:o,captionScale:i,...s}=r;return n({...e.doc,scenes:{...e.doc.scenes,[t.sceneId]:s}})}case"patchCaptionStyleAll":{const r={...e.doc.scenes};for(const o of t.sceneIds){const i=r[o]??{props:{},elements:{}};r[o]={...i,...t.y!==void 0?{captionY:t.y}:{},...t.scale!==void 0?{captionScale:t.scale}:{}}}return n({...e.doc,scenes:r})}case"addSplit":return e.doc.splits.some(r=>Math.abs(r-t.t)<.001)?e:n({...e.doc,splits:[...e.doc.splits,t.t].sort((r,o)=>r-o)});case"hideScene":{const r=cn(e.doc,t.sceneId);return n({...e.doc,scenes:{...e.doc.scenes,[t.sceneId]:{...r,hidden:!0}}})}case"restoreScene":{const r=e.doc.scenes[t.sceneId];if(!(r!=null&&r.hidden))return e;const{hidden:o,...i}=r;return n({...e.doc,scenes:{...e.doc.scenes,[t.sceneId]:i}})}case"patchComponent":{const r=cn(e.doc,t.sceneId);return n({...e.doc,scenes:{...e.doc.scenes,[t.sceneId]:{...r,component:t.component}}})}case"patchLayout":{const{graphicRect:r,...o}=cn(e.doc,t.sceneId);return n({...e.doc,scenes:{...e.doc.scenes,[t.sceneId]:{...o,layout:t.layout}}})}case"patchGraphicRect":{const r=cn(e.doc,t.sceneId);return n({...e.doc,scenes:{...e.doc.scenes,[t.sceneId]:{...r,graphicRect:t.rect}}},t.coalesce)}case"clearGraphicRect":return n(mF(e.doc,t.sceneId));case"patchCaption":{const r=String(t.index),o=rF(e.doc.captions,t.index,t.was);if(t.text===o){const{[r]:i,...s}=e.doc.captions;return n({...e.doc,captions:s})}return n({...e.doc,captions:{...e.doc.captions,[r]:{text:t.text,was:o}}})}case"patchTheme":return n({...e.doc,theme:{...e.doc.theme,...t.patch}});case"undo":{if(e.past.length===0)return e;const r=e.past[e.past.length-1],o=e.past.slice(0,-1);return{doc:r,past:o,future:[...e.future,e.doc],savedAt:e.savedAt,dirty:o.length!==e.savedAt,lastCoalesce:null}}case"redo":{if(e.future.length===0)return e;const r=e.future[e.future.length-1],o=[...e.past,e.doc];return{doc:r,past:o,future:e.future.slice(0,-1),savedAt:e.savedAt,dirty:o.length!==e.savedAt,lastCoalesce:null}}case"saved":return{...e,dirty:!1,savedAt:e.past.length}}}function B4(){const[e,t]=c.useReducer(V4,void 0,O4),n=async()=>{const r=await fetch("/api/overrides",{method:"PUT",headers:{"content-type":"application/json"},body:JSON.stringify(e.doc)});if(!r.ok){const o=await r.json().catch(()=>({}));throw new Error(o.error??"save failed")}t({type:"saved"})};return{doc:e.doc,dirty:e.dirty,canUndo:e.past.length>0,canRedo:e.future.length>0,load:r=>t({type:"load",doc:r}),undo:()=>t({type:"undo"}),redo:()=>t({type:"redo"}),save:n,patchProps:(r,o,i)=>t({type:"patchProps",sceneId:r,patch:o,coalesce:i}),patchElement:(r,o,i,s)=>t({type:"patchElement",sceneId:r,elementId:o,patch:i,coalesce:s}),clearElement:(r,o)=>t({type:"clearElement",sceneId:r,elementId:o}),patchTiming:(r,o,i)=>t({type:"patchTiming",sceneId:r,startSec:o,endSec:i}),clearTiming:r=>t({type:"clearTiming",sceneId:r}),patchVideo:(r,o,i)=>t({type:"patchVideo",sceneId:r,patch:o,coalesce:i}),clearVideo:r=>t({type:"clearVideo",sceneId:r}),patchPip:(r,o,i)=>t({type:"patchPip",sceneId:r,patch:o,coalesce:i}),clearPip:r=>t({type:"clearPip",sceneId:r}),patchCaptionY:(r,o,i)=>t({type:"patchCaptionY",sceneId:r,y:o,coalesce:i}),patchCaptionScale:(r,o,i)=>t({type:"patchCaptionScale",sceneId:r,scale:o,coalesce:i}),clearCaptionStyle:r=>t({type:"clearCaptionStyle",sceneId:r}),patchCaptionStyleAll:(r,o)=>t({type:"patchCaptionStyleAll",sceneIds:r,...o}),addSplit:r=>t({type:"addSplit",t:r}),hideScene:r=>t({type:"hideScene",sceneId:r}),restoreScene:r=>t({type:"restoreScene",sceneId:r}),patchGraphicRect:(r,o,i)=>t({type:"patchGraphicRect",sceneId:r,rect:o,coalesce:i}),clearGraphicRect:r=>t({type:"clearGraphicRect",sceneId:r}),patchComponent:(r,o)=>t({type:"patchComponent",sceneId:r,component:o}),patchLayout:(r,o)=>t({type:"patchLayout",sceneId:r,layout:o}),patchCaption:(r,o,i)=>t({type:"patchCaption",index:r,text:o,was:i}),patchTheme:r=>t({type:"patchTheme",patch:r})}}function jh(e){const t=e==null?void 0:e.closest("[data-edit-id]");if(!t)return null;const n=t.closest("[data-edit-scene]");return n?{sceneId:n.dataset.editScene,elementId:t.dataset.editId}:null}function $h(e){const t=e==null?void 0:e.closest("[data-edit-video]");return(t==null?void 0:t.dataset.editVideo)||null}function Ah(e,t,n){const r=e.querySelectorAll(`[data-edit-scene="${t}"] [data-edit-id="${n}"]`);if(r.length===0)return null;let o=1/0,i=1/0,s=-1/0,a=-1/0;return r.forEach(l=>{const u=l.getBoundingClientRect();o=Math.min(o,u.left),i=Math.min(i,u.top),s=Math.max(s,u.right),a=Math.max(a,u.bottom)}),new DOMRect(o,i,s-o,a-i)}function Nh(e,t,n,r){const o={...e};return t==="move"?(o.x+=n,o.y+=r,o):(t.includes("w")&&(o.x+=n,o.w-=n),t.includes("e")&&(o.w+=n),t.includes("n")&&(o.y+=r,o.h-=r),t.includes("s")&&(o.h+=r),o)}const Lh=64,Qs=9,Js=e=>Math.round(e*10)/10,qr=e=>Math.round(e*1e4)/1e4,Yw={position:"absolute",width:10,height:10,background:"#5b8cff",border:"1px solid #0B0B0E",borderRadius:2,pointerEvents:"auto",zIndex:6},zh={nw:{left:0,top:0,transform:"translate(-50%,-50%)",cursor:"nwse-resize"},n:{left:"50%",top:0,transform:"translate(-50%,-50%)",cursor:"ns-resize"},ne:{right:0,top:0,transform:"translate(50%,-50%)",cursor:"nesw-resize"},e:{right:0,top:"50%",transform:"translate(50%,-50%)",cursor:"ew-resize"},se:{right:0,bottom:0,transform:"translate(50%,50%)",cursor:"nwse-resize"},s:{left:"50%",bottom:0,transform:"translate(-50%,50%)",cursor:"ns-resize"},sw:{left:0,bottom:0,transform:"translate(-50%,50%)",cursor:"nesw-resize"},w:{left:0,top:"50%",transform:"translate(-50%,-50%)",cursor:"ew-resize"}},W4={...Yw,background:"#ffe14d"},U4={top:{top:0,left:14,right:14,height:10},bottom:{bottom:0,left:14,right:14,height:10},left:{left:0,top:14,bottom:14,width:10},right:{right:0,top:14,bottom:14,width:10}},H4={position:"absolute",cursor:"move",pointerEvents:"auto",zIndex:5},Kw=/^(line|node|message|window|item)-(\d+)$/;function Z4(e,t,n){const r=Kw.exec(e);if(!r||r[1]==="window")return null;const o=r[1],i=Number(r[2]);if(o==="message"&&i===0&&typeof t.keyword=="string"&&t.keyword){const d=n.trim().replace(/^"(.*)"$/,"$1").toLowerCase();return d?{keyword:d}:null}const s=o==="line"?"lines":o==="node"?"nodes":o==="item"?"items":"messages",a=t[s];if(!Array.isArray(a)||i<0||i>=a.length)return null;const l=a.slice(),u=l[i];if(o==="node"||o==="item")l[i]=n;else{if(typeof u!="object"||u===null)return null;l[i]={...u,text:n}}return{[s]:l}}function Y4(e,t){const n=Kw.exec(e);if(!n){const u=t[e];return typeof u=="string"?u:null}if(n[1]==="window")return null;const r=n[1],o=Number(n[2]);if(r==="message"&&o===0&&typeof t.keyword=="string"&&t.keyword)return t.keyword;const s=t[r==="line"?"lines":r==="node"?"nodes":r==="item"?"items":"messages"];if(!Array.isArray(s)||o<0||o>=s.length)return null;const a=s[o];if(r==="node"||r==="item")return typeof a=="string"?a:null;const l=a==null?void 0:a.text;return typeof l=="string"?l:null}const K4=({stageRef:e,selection:t,onSelect:n,edits:r,onSave:o,settings:i,playerRef:s,onTransport:a,onVideoPreview:l,onGraphicPreview:u,cue:d,cues:p,onToggleHelp:m})=>{const[h,w]=c.useState(null),v=c.useRef(null),E=c.useRef(0),g=c.useRef(null),y=c.useRef(0),x=c.useRef(null),b=c.useRef(0),[k,S]=c.useState(!1),C=c.useRef(null),[I,F]=c.useState(null),[j,P]=c.useState(null),A=c.useRef(null),[V,_]=c.useState({dx:0,dy:0}),L=c.useRef(null),O=c.useRef(t),N=c.useCallback(R=>{O.current=R,n(R)},[n]);c.useEffect(()=>{O.current=t},[t]);const T=(R,$)=>{const B=[];let W=null;for(let M=0;M<25;M++){const D=document.elementFromPoint(R,$);if(!D||D===document.documentElement||D===document.body){W=D;break}if(W=D,D.hasAttribute("data-edit-id")||D.hasAttribute("data-edit-scene")||D.hasAttribute("data-caption-word")||D.closest("[data-edit-video]")!==null||["BUTTON","INPUT","SELECT","TEXTAREA"].includes(D.tagName)||!(D instanceof HTMLElement))break;B.push({el:D,prev:D.style.pointerEvents}),D.style.pointerEvents="none"}return B.forEach(({el:M,prev:D})=>{M.style.pointerEvents=D}),W},z=c.useCallback(()=>{var D,K;const R=e.current,$=(D=s.current)==null?void 0:D.getScale(),B=((K=R==null?void 0:R.querySelector(".__remotion-player"))==null?void 0:K.getBoundingClientRect())??(R==null?void 0:R.getBoundingClientRect());if(!B||!$||$<=0)return null;const W=i.width*$,M=i.height*$;return{left:B.left+(B.width-W)/2,top:B.top+(B.height-M)/2,w:W,h:M}},[e,s,i]);return c.useEffect(()=>{if(!t){w(null);return}let R;const $=()=>{var W;const B=e.current;if(B){const M=t.elementId?Ah(B,t.sceneId,t.elementId):((W=B.querySelector(`[data-edit-scene="${t.sceneId}"]`))==null?void 0:W.getBoundingClientRect())??null;w(M)}R=requestAnimationFrame($)};return R=requestAnimationFrame($),()=>cancelAnimationFrame(R)},[e,t]),c.useEffect(()=>{const R=$=>{var M,D;const B=e.current;if(!B||!B.contains($.target)||$.altKey||$.button!==0)return;(((M=O.current)==null?void 0:M.elementId)&&((D=L.current)==null?void 0:D.contains($.target))||jh(T($.clientX,$.clientY))!==null)&&$.stopPropagation()};return window.addEventListener("pointerdown",R,!0),()=>window.removeEventListener("pointerdown",R,!0)},[e]),c.useEffect(()=>{const R=$=>{var ne,Z,ee,ae,me,ge,le;const B=e.current;if(!B||!B.contains($.target)||$.altKey||$.button!==0)return;const W=$.target instanceof Element?$.target.closest("[data-el-handle]"):null,M=O.current;if(W&&(M!=null&&M.elementId)){const q=Ah(B,M.sceneId,M.elementId);if(q){const de=q.left+q.width/2,ye=q.top+q.height/2,Fe=Math.hypot($.clientX-de,$.clientY-ye);if(Fe>2){const se=((Z=(ne=r.doc.scenes[M.sceneId])==null?void 0:ne.elements[M.elementId])==null?void 0:Z.scale)??1;C.current={sceneId:M.sceneId,elementId:M.elementId,cx:de,cy:ye,startDist:Fe,prior:se,factor:1},F(1)}}return}if((ee=O.current)!=null&&ee.elementId&&((ae=L.current)!=null&&ae.contains($.target))){A.current={x:$.clientX,y:$.clientY,dx:0,dy:0},_({dx:0,dy:0});return}const D=$.target instanceof Element?$.target.closest("[data-box-handle]"):null,K=O.current;if(D&&K&&!K.elementId){const q=B.querySelector(`[data-edit-scene="${K.sceneId}"]`),de=z();if(q&&de){const ye=q.getBoundingClientRect();x.current={sceneId:K.sceneId,handle:D.dataset.boxHandle,x:$.clientX,y:$.clientY,dx:0,dy:0,start:{x:(ye.left-de.left)/de.w,y:(ye.top-de.top)/de.h,w:ye.width/de.w,h:ye.height/de.h}},S(!0)}return}const G=T($.clientX,$.clientY),oe=jh(G);if(!oe){const q=G==null?void 0:G.closest("[data-edit-scene]");if(q){N({sceneId:q.dataset.editScene,elementId:null});return}const de=$h(G),ye=B.getBoundingClientRect().bottom;if(de&&$.clientY<ye-Lh){N({sceneId:de,elementId:null});const Fe=p.find(We=>We.id===de);if((Fe==null?void 0:Fe.layout)==="pip-bubble"&&!$.altKey){const We=jr("pip-bubble",void 0,[],i).video.rect;g.current={sceneId:de,x:$.clientX,y:$.clientY,base:{x:((me=Fe.pip)==null?void 0:me.x)??We.x,y:((ge=Fe.pip)==null?void 0:ge.y)??We.y},slot:{w:We.w,h:We.h}};return}const se=(le=r.doc.scenes[de])==null?void 0:le.video;v.current={sceneId:de,x:$.clientX,y:$.clientY,dx:0,dy:0,baseDx:(se==null?void 0:se.dx)??0,baseDy:(se==null?void 0:se.dy)??0};return}N(null);return}N({sceneId:oe.sceneId,elementId:oe.elementId}),A.current={x:$.clientX,y:$.clientY,dx:0,dy:0},_({dx:0,dy:0})};return window.addEventListener("mousedown",R),()=>window.removeEventListener("mousedown",R)},[e,N,r,z,p,i]),c.useEffect(()=>{const R=()=>{var D,K;const W=(D=s.current)==null?void 0:D.getScale(),M=(K=e.current)==null?void 0:K.getBoundingClientRect();return W&&W>0?1/W:M&&M.width>0?i.width/M.width:1},$=W=>{const M=e.current;if(M&&!(x.current||C.current))if(g.current)M.style.cursor="move";else if(v.current)M.style.cursor="grabbing";else{const Z=W.target instanceof Element?W.target:null,ee=Z!==null&&M.contains(Z)&&!Z.closest("button, input, select, textarea, [data-edit-id], [data-edit-scene], [data-caption-word]")&&W.clientY<M.getBoundingClientRect().bottom-Lh,ae=ee&&(()=>{var ge;const me=$h(Z);return me!==null&&((ge=p.find(le=>le.id===me))==null?void 0:ge.layout)==="pip-bubble"})();M.style.cursor=ee?ae?"move":"grab":""}const D=C.current;if(D){const ee=Math.hypot(W.clientX-D.cx,W.clientY-D.cy)/D.startDist;D.factor=Math.min(4/D.prior,Math.max(.05/D.prior,ee)),F(D.factor);return}const K=x.current;if(K){K.dx=W.clientX-K.x,K.dy=W.clientY-K.y,b.current||(b.current=requestAnimationFrame(()=>{b.current=0;const Z=x.current,ee=z();if(!Z||!ee)return;const ae=Ja(Nh(Z.start,Z.handle,Z.dx/ee.w,Z.dy/ee.h),i);u({sceneId:Z.sceneId,rect:ae})}));return}if(g.current){y.current||(y.current=requestAnimationFrame(()=>{y.current=0;const Z=g.current,ee=z();if(!Z||!ee)return;const ae=(W.clientX-Z.x)/ee.w,me=(W.clientY-Z.y)/ee.h;r.patchPip(Z.sceneId,{x:qr(Math.min(Math.max(Z.base.x+ae,0),1-Z.slot.w)),y:qr(Math.min(Math.max(Z.base.y+me,0),1-Z.slot.h))},`pip:${Z.sceneId}:drag`)}));return}const oe=v.current;if(oe){oe.dx=W.clientX-oe.x,oe.dy=W.clientY-oe.y,E.current||(E.current=requestAnimationFrame(()=>{E.current=0;const Z=v.current;if(!Z)return;const ee=R();l({sceneId:Z.sceneId,patch:{dx:Z.baseDx+Z.dx*ee,dy:Z.baseDy+Z.dy*ee}})}));return}const ne=A.current;ne&&(ne.dx=W.clientX-ne.x,ne.dy=W.clientY-ne.y,_({dx:ne.dx,dy:ne.dy}))},B=()=>{const W=C.current;if(W){C.current=null,F(null),Math.abs(W.factor-1)>.001&&r.patchElement(W.sceneId,W.elementId,{scale:Math.round(W.prior*W.factor*1e3)/1e3});return}const M=x.current;if(M){if(x.current=null,S(!1),b.current&&(cancelAnimationFrame(b.current),b.current=0),M.dx!==0||M.dy!==0){const ne=z();if(ne){const Z=Ja(Nh(M.start,M.handle,M.dx/ne.w,M.dy/ne.h),i);r.patchGraphicRect(M.sceneId,{x:qr(Z.x),y:qr(Z.y),w:qr(Z.w),h:qr(Z.h)})}}u(null);return}if(g.current){g.current=null,y.current&&(cancelAnimationFrame(y.current),y.current=0);return}const K=v.current;if(K){if(v.current=null,E.current&&(cancelAnimationFrame(E.current),E.current=0),K.dx!==0||K.dy!==0){const ne=R();r.patchVideo(K.sceneId,{dx:Js(K.baseDx+K.dx*ne),dy:Js(K.baseDy+K.dy*ne)})}l(null);return}const G=A.current,oe=O.current;if(!G||!(oe!=null&&oe.elementId)){A.current=null;return}if(G.dx!==0||G.dy!==0){const ne=R(),Z=r.doc.scenes[oe.sceneId],ee=Z==null?void 0:Z.elements[oe.elementId];r.patchElement(oe.sceneId,oe.elementId,{dx:Js(((ee==null?void 0:ee.dx)??0)+G.dx*ne),dy:Js(((ee==null?void 0:ee.dy)??0)+G.dy*ne)})}A.current=null,_({dx:0,dy:0})};return window.addEventListener("mousemove",$),window.addEventListener("mouseup",B),()=>{window.removeEventListener("mousemove",$),window.removeEventListener("mouseup",B)}},[r,e,i,s,l,u,z,p]),c.useEffect(()=>{const R=$=>{var K;const B=e.current;if(!B||!B.contains($.target))return;const W=(K=T($.clientX,$.clientY))==null?void 0:K.closest("[data-caption-word]");if(!W)return;$.preventDefault();const M=Number(W.dataset.captionWord),D=W.dataset.captionText??"";!Number.isFinite(M)||!D||P({index:M,was:D,draft:D,rect:W.getBoundingClientRect()})};return window.addEventListener("dblclick",R),()=>window.removeEventListener("dblclick",R)},[e]),c.useEffect(()=>{const R=()=>{const M=document.activeElement;return M instanceof HTMLInputElement||M instanceof HTMLTextAreaElement||M instanceof HTMLSelectElement||M instanceof HTMLElement&&M.isContentEditable},$=()=>{const M=document.activeElement;return M instanceof HTMLTextAreaElement||M instanceof HTMLElement&&M.isContentEditable?!0:M instanceof HTMLInputElement&&!["range","checkbox","radio","button"].includes(M.type)},B=()=>{const M=document.activeElement;M instanceof HTMLElement&&!$()&&M.blur()},W=M=>{var K,G,oe,ne;if(j!==null)return;const D=M.metaKey||M.ctrlKey;if(M.key==="Escape"){if(R()){(K=document.activeElement)==null||K.blur();return}N(null)}else if(D&&M.key.toLowerCase()==="z")M.preventDefault(),M.shiftKey?r.redo():r.undo();else if(D&&M.key.toLowerCase()==="y")M.preventDefault(),r.redo();else if(D&&M.key.toLowerCase()==="s")M.preventDefault(),o();else if(M.key===" "&&!D){if($())return;const Z=document.activeElement;if(Z instanceof HTMLElement&&Z.tagName==="BUTTON"&&((G=e.current)!=null&&G.contains(Z)))return;B(),M.preventDefault(),(oe=s.current)==null||oe.toggle()}else if(!D&&["j","k","l"].includes(M.key.toLowerCase())){if($())return;B(),M.preventDefault(),a(M.key.toUpperCase())}else if(!D&&!M.altKey&&(M.key==="ArrowLeft"||M.key==="ArrowRight")){if(R())return;M.preventDefault();const Z=s.current;if(!Z)return;Z.seekTo(Math.max(0,Z.getCurrentFrame()+(M.key==="ArrowRight"?1:-1)))}else if(D&&M.key.toLowerCase()==="b"){if($())return;M.preventDefault();const Z=s.current;if(!Z)return;const ee=Z.getCurrentFrame()/i.fps;if(!p.find(me=>ee>=me.startSec+Qa&&ee<=me.endSec-Qa))return;r.addSplit(Math.round(ee*1e3)/1e3)}else if(!D&&M.altKey&&(M.key==="ArrowLeft"||M.key==="ArrowRight")){if($())return;const Z=O.current,ee=Z?(()=>{const ae=p.findIndex(me=>me.id===Z.sceneId);return ae===-1?void 0:p[ae+(M.key==="ArrowRight"?1:-1)]})():p[M.key==="ArrowRight"?0:p.length-1];if(!ee)return;M.preventDefault(),N({sceneId:ee.id,elementId:null})}else if(D&&(M.key==="ArrowLeft"||M.key==="ArrowRight")){if($())return;M.preventDefault();const Z=s.current;if(!Z)return;const ee=Z.getCurrentFrame()/i.fps,ae=p.findIndex(ge=>ee>=ge.startSec&&ee<ge.endSec),me=p[(ae===-1?0:ae)+(M.key==="ArrowRight"?1:-1)];if(!me)return;Z.seekTo(Math.round(me.startSec*i.fps)),N({sceneId:me.id,elementId:null})}else if(!D&&!M.altKey&&M.key==="?"){if(R())return;M.preventDefault(),m()}else if(!D&&(M.key==="Delete"||M.key==="Backspace")){if(R())return;const Z=O.current;if(!Z||Z.elementId!==null||!d||d.kind==="plain"||d.id!==Z.sceneId||((ne=r.doc.scenes[Z.sceneId])==null?void 0:ne.hidden)===!0)return;M.preventDefault(),r.hideScene(Z.sceneId)}};return window.addEventListener("keydown",W),()=>window.removeEventListener("keydown",W)},[N,r,j,o,s,e,a,d,p,i,m]),f.jsxs("div",{style:{position:"absolute",inset:0,pointerEvents:"none"},children:[V.dx!==0||V.dy!==0||k?f.jsx("div",{"data-testid":"safe-area-guide",style:{position:"absolute",left:`${kr(i).left*100}%`,top:`${kr(i).top*100}%`,right:`${kr(i).right*100}%`,bottom:`${kr(i).bottom*100}%`,border:"1px dashed rgba(255, 225, 77, 0.45)",boxShadow:"0 0 0 9999px rgba(0, 0, 0, 0.18)",pointerEvents:"none"}}):null,h&&t?f.jsxs("div",{ref:L,"data-testid":"overlay-box",style:{position:"fixed",pointerEvents:"auto",left:h.left+V.dx-Qs/2+h.width*(1-(I??1))/2,top:h.top+V.dy-Qs/2+h.height*(1-(I??1))/2,width:h.width*(I??1)+Qs,height:h.height*(I??1)+Qs,border:t.elementId?"2px dashed #ffe14d":"2px dashed #5b8cff",borderRadius:4,boxShadow:"0 0 0 1px rgba(0,0,0,0.35)",cursor:t.elementId?"grab":"default"},children:[t.elementId?f.jsx("div",{style:{position:"absolute",bottom:"100%",left:0,marginBottom:4,fontSize:10,fontFamily:"ui-monospace, 'SF Mono', monospace",letterSpacing:"0.04em",textTransform:"uppercase",color:"#0B0B0E",background:"#ffe14d",padding:"2px 6px",borderRadius:3,whiteSpace:"nowrap"},children:t.elementId}):null,t.elementId?["nw","ne","se","sw"].map(R=>f.jsx("div",{"data-el-handle":R,"data-testid":`el-handle-${R}`,style:{...W4,...zh[R]}},R)):null,!t.elementId&&d&&d.kind!=="plain"?f.jsxs(f.Fragment,{children:[["top","bottom","left","right"].map(R=>f.jsx("div",{"data-box-handle":"move","data-testid":R==="top"?"box-handle-move":`box-handle-move-${R}`,style:{...H4,...U4[R]}},R)),["nw","n","ne","e","se","s","sw","w"].map(R=>f.jsx("div",{"data-box-handle":R,"data-testid":`box-handle-${R}`,style:{...Yw,...zh[R]}},R))]}):null]}):null,j?f.jsx("input",{autoFocus:!0,"data-testid":"caption-edit",value:j.draft,onChange:R=>P({...j,draft:R.target.value}),onBlur:()=>{const R=j.draft.trim();R&&r.patchCaption(j.index,R,j.was),P(null)},onKeyDown:R=>{R.key==="Enter"&&R.target.blur(),R.key==="Escape"&&P(null)},style:{position:"fixed",pointerEvents:"auto",left:j.rect.left-4,top:j.rect.top-4,width:Math.max(j.rect.width+40,90),height:j.rect.height+8,fontSize:Math.max(13,Math.min(j.rect.height*.7,28)),fontFamily:"'Inter', system-ui, sans-serif",fontWeight:800,border:"2px solid #FFE14D",borderRadius:4,padding:"0 4px",background:"#0B0B0E",color:"#fff",outline:"none",zIndex:11}}):null]})},Jt={display:"flex",flexDirection:"column",gap:6},di={display:"grid",gridTemplateColumns:"1fr 1fr",gap:8},De={fontSize:11,fontWeight:600,letterSpacing:"0.06em",textTransform:"uppercase",color:"#9A9AA3"},Ri={fontFamily:"ui-monospace, 'SF Mono', Consolas, monospace",fontSize:13,background:"#0F0F14",border:"1px solid #2A2A33",borderRadius:6,color:"#fff",padding:"6px 8px",width:"100%"},Xw={...Ri,fontFamily:"'Inter', system-ui, sans-serif"},qe={display:"flex",flexDirection:"column",gap:14,padding:"16px 18px",borderBottom:"1px solid #22222a"},Sn={fontSize:12,fontWeight:600,color:"#FF5C5C",background:"transparent",border:"1px solid #452626",borderRadius:6,padding:"7px 10px",cursor:"pointer"},X4=e=>String(Math.round(e*1e3)/1e3),Et=({id:e,value:t,onCommit:n,min:r,max:o,dragStep:i})=>{const[s,a]=J.useState(null),[l,u]=J.useState(!1),d=J.useRef(null),p=J.useRef(null),m=r??-1/0,h=o??1/0,w=i??(r!==void 0&&o!==void 0?(o-r)/240:.5),v=s!==null;return f.jsxs("div",{style:Jt,children:[f.jsx("span",{style:De,children:e}),f.jsx("input",{type:"text",inputMode:"decimal",ref:d,"data-testid":`field-${e}`,style:{...Ri,...v?{}:{cursor:"ew-resize",touchAction:"none"},...l?{borderColor:"#FFE14D",color:"#FFE14D"}:{}},value:s??(Number.isFinite(t)?X4(t):"0"),onFocus:E=>a(E.target.value),onBlur:()=>a(null),onPointerDown:E=>{v||(E.preventDefault(),p.current={x:E.clientX,v:Number.isFinite(t)?t:0,moved:!1},E.currentTarget.setPointerCapture(E.pointerId),u(!0))},onPointerMove:E=>{const g=p.current;if(!g)return;const y=E.clientX-g.x;if(!g.moved&&Math.abs(y)<=2)return;g.moved=!0;const x=Math.round(Math.min(h,Math.max(m,g.v+y*w))*1e3)/1e3;n(x)},onPointerUp:()=>{var g,y,x;const E=((g=p.current)==null?void 0:g.moved)===!0;p.current=null,u(!1),E||((y=d.current)==null||y.focus(),(x=d.current)==null||x.select())},onPointerCancel:()=>{p.current=null,u(!1)},onChange:E=>{a(E.target.value);const g=E.target.value.trim();if(g==="")return;const y=Number(g.replace(",","."));Number.isFinite(y)&&n(Math.min(h,Math.max(m,y)))}})]})},ea=({id:e,value:t,isColor:n,onCommit:r})=>f.jsxs("div",{style:Jt,children:[f.jsx("span",{style:De,children:e}),f.jsxs("div",{style:{display:"flex",gap:8,alignItems:"center"},children:[n?f.jsx("input",{type:"color",value:t,onChange:o=>r(o.target.value),style:{width:28,height:28,border:"1px solid #2A2A33",borderRadius:6,padding:0,background:"none"}}):null,f.jsx("input",{style:{...Xw,flex:1},value:t,onChange:o=>r(o.target.value)})]})]}),G4=({selection:e,cue:t,frame:n,allSceneIds:r,edits:o,resolvedTheme:i,anchorText:s,onVideoPreview:a,runInfo:l})=>{var v,E,g,y,x,b,k,S,C,I,F,j;if(e!=null&&e.elementId&&t){const P=e.elementId,A=((v=t.elements)==null?void 0:v[P])??{},V=t.props?Y4(P,t.props):null;return f.jsxs("div",{children:[f.jsxs("div",{style:qe,children:[f.jsx("span",{style:De,children:"Selected"}),f.jsx("div",{style:{fontSize:15,fontWeight:700,fontFamily:"ui-monospace, monospace"},children:P})]}),(()=>{var z;const _=/^line-(\d+)$/.exec(P),L=(z=t.props)==null?void 0:z.lines;if(t.component!=="StrikethroughReveal"||!_||!Array.isArray(L))return null;const O=Number(_[1]),N=L[O];if(!N)return null;const T=N.struck?"struck":(N.mark??"none")!=="none"?N.mark:"plain";return f.jsx("div",{style:qe,children:f.jsxs("div",{style:Jt,children:[f.jsx("span",{style:De,children:"Line style"}),f.jsxs("select",{"data-testid":"line-style",style:Ri,value:T,onChange:R=>{const $=R.target.value,B=L.slice();B[O]={...B[O],struck:$==="struck",mark:$==="cross"||$==="check"?$:"none"},o.patchProps(e.sceneId,{lines:B})},children:[f.jsx("option",{value:"plain",children:"plain"}),f.jsx("option",{value:"struck",children:"struck through"}),f.jsx("option",{value:"cross",children:"✗ wrong"}),f.jsx("option",{value:"check",children:"✓ right"})]})]})})})(),V!==null?f.jsx("div",{style:qe,children:f.jsxs("div",{style:Jt,children:[f.jsx("span",{style:De,children:"Text"}),f.jsx("input",{style:Xw,"data-testid":"element-text",value:V,onChange:_=>{const L=t.props??{},O=/^(line|node|message|window|item)-\d+$/.test(P)?Z4(P,L,_.target.value):{[P]:_.target.value};O&&o.patchProps(e.sceneId,O,`text:${e.sceneId}:${P}`)}})]})}):null,f.jsxs("div",{style:qe,children:[f.jsxs("div",{style:Jt,children:[f.jsxs("span",{style:De,children:["scale"," ",f.jsxs("span",{style:{color:"#EDEDF2"},children:[(A.scale??1).toFixed(2),"×"]})]}),f.jsx("input",{type:"range","data-testid":"el-scale-slider",min:.1,max:3,step:.01,value:A.scale??1,onChange:_=>o.patchElement(e.sceneId,P,{scale:Number(_.target.value)},`element:${e.sceneId}:${P}:scale`)})]}),f.jsxs("div",{style:di,children:[f.jsx(Et,{id:"x",value:A.dx??0,dragStep:1,onCommit:_=>o.patchElement(e.sceneId,P,{dx:_},`element:${e.sceneId}:${P}:dx`)}),f.jsx(Et,{id:"y",value:A.dy??0,dragStep:1,onCommit:_=>o.patchElement(e.sceneId,P,{dy:_},`element:${e.sceneId}:${P}:dy`)})]}),f.jsx(Et,{id:"scale",value:A.scale??1,min:.05,max:4,dragStep:.01,onCommit:_=>o.patchElement(e.sceneId,P,{scale:_},`element:${e.sceneId}:${P}:scale`)})]}),f.jsx("div",{style:qe,children:f.jsx("button",{style:Sn,onClick:()=>o.clearElement(e.sceneId,P),children:"Reset element"})})]})}if(e&&t){const P=t.kind==="plain";return((E=o.doc.scenes[e.sceneId])==null?void 0:E.hidden)===!0?f.jsx("div",{children:f.jsxs("div",{style:qe,children:[f.jsx("span",{style:De,children:"Scene"}),f.jsxs("div",{style:{fontSize:15,fontWeight:700,fontFamily:"ui-monospace, monospace"},children:[e.sceneId," ",f.jsx("span",{style:{color:"#9A9AA3",fontWeight:400},children:"(deleted)"})]}),f.jsx("div",{style:{fontSize:12,color:"#9A9AA3"},children:"Its window plays as a plain take. Restore brings the graphic back."}),f.jsx("button",{"data-testid":"restore-scene",style:{...Sn,color:"#5FBF77",border:"1px solid #24402c"},onClick:()=>o.restoreScene(e.sceneId),children:"Restore scene"})]})}):f.jsxs("div",{children:[f.jsxs("div",{style:qe,children:[f.jsx("span",{style:De,children:P?"Take":"Scene"}),f.jsx("div",{style:{fontSize:15,fontWeight:700,fontFamily:"ui-monospace, monospace"},children:e.sceneId}),P?f.jsx("div",{style:{fontSize:12,color:"#9A9AA3"},children:"A continuous stretch of the talking head — no graphic. Frame it below; its window follows the cut."}):null]}),f.jsxs("div",{style:qe,children:[!P&&t.component?f.jsxs("div",{style:Jt,children:[f.jsx("span",{style:De,children:"Component"}),f.jsx("select",{style:Ri,value:t.component,onChange:A=>o.patchComponent(e.sceneId,A.target.value),children:Kl.options.map(A=>f.jsx("option",{value:A,children:A},A))})]}):null,f.jsxs("div",{style:Jt,children:[f.jsx("span",{style:De,children:"Layout"}),f.jsx("select",{style:Ri,"data-testid":"layout-select",value:t.layout,onChange:A=>o.patchLayout(e.sceneId,A.target.value),children:Yl.options.map(A=>f.jsx("option",{value:A,children:A},A))})]})]}),f.jsxs("div",{style:qe,children:[f.jsx("span",{style:De,children:"Video framing"}),f.jsxs("div",{style:Jt,children:[f.jsxs("span",{style:De,children:["zoom"," ",f.jsxs("span",{style:{color:"#EDEDF2"},children:[(((g=t.video)==null?void 0:g.scale)??1).toFixed(2),"×"]})]}),f.jsx("input",{type:"range","data-testid":"zoom-slider",min:.5,max:3,step:.01,value:((y=t.video)==null?void 0:y.scale)??1,onChange:A=>a({sceneId:e.sceneId,patch:{scale:Number(A.target.value)}}),onPointerUp:A=>{const V=Number(A.target.value);o.patchVideo(e.sceneId,{scale:V},`video:${e.sceneId}:scale`),a(null)},onKeyUp:A=>{if(!["ArrowLeft","ArrowRight","ArrowUp","ArrowDown","Home","End","PageUp","PageDown"].includes(A.key))return;const _=Number(A.target.value);o.patchVideo(e.sceneId,{scale:_},`video:${e.sceneId}:scale`),a(null)}})]}),f.jsxs("label",{style:{display:"flex",gap:8,alignItems:"center",fontSize:12,color:"#9A9AA3",cursor:"pointer"},children:[f.jsx("input",{type:"checkbox","data-testid":"auto-zoom",checked:((x=t.video)==null?void 0:x.autoZoom)!==!1,onChange:A=>o.patchVideo(e.sceneId,{autoZoom:A.target.checked})}),"auto zoom (the slow push composes on top of your zoom)"]}),f.jsx("div",{style:{fontSize:12,color:"#9A9AA3"},children:"Pan: drag the picture on the stage."}),f.jsx(Et,{id:"scale",value:((b=t.video)==null?void 0:b.scale)??1,min:.05,max:4,dragStep:.01,onCommit:A=>o.patchVideo(e.sceneId,{scale:A},`video:${e.sceneId}:scale`)}),f.jsxs("div",{style:di,children:[f.jsx(Et,{id:"dx",value:((k=t.video)==null?void 0:k.dx)??0,dragStep:1,onCommit:A=>o.patchVideo(e.sceneId,{dx:A},`video:${e.sceneId}:dx`)}),f.jsx(Et,{id:"dy",value:((S=t.video)==null?void 0:S.dy)??0,dragStep:1,onCommit:A=>o.patchVideo(e.sceneId,{dy:A},`video:${e.sceneId}:dy`)})]}),t.video?f.jsx("button",{style:Sn,onClick:()=>o.clearVideo(e.sceneId),children:"Reset framing"}):null]}),t.layout==="pip-bubble"?(()=>{const A=jr("pip-bubble",void 0,[],n).video,V=t.pip??{},_=V.cornerRadius??A.cornerRadius;return f.jsxs("div",{style:qe,children:[f.jsx("span",{style:De,children:"PiP bubble"}),f.jsxs("div",{style:Jt,children:[f.jsxs("span",{style:De,children:["roundness"," ",f.jsx("span",{style:{color:"#EDEDF2"},children:_.toFixed(2)})]}),f.jsx("input",{type:"range","data-testid":"pip-roundness",min:0,max:1,step:.01,value:_,onChange:L=>o.patchPip(e.sceneId,{cornerRadius:Number(L.target.value)},`pip:${e.sceneId}:cornerRadius`)})]}),f.jsxs("div",{style:di,children:[f.jsx(Et,{id:"pip-x",value:V.x??A.rect.x,min:0,max:1-A.rect.w,dragStep:.002,onCommit:L=>o.patchPip(e.sceneId,{x:L},`pip:${e.sceneId}:x`)}),f.jsx(Et,{id:"pip-y",value:V.y??A.rect.y,min:0,max:1-A.rect.h,dragStep:.002,onCommit:L=>o.patchPip(e.sceneId,{y:L},`pip:${e.sceneId}:y`)})]}),t.pip?f.jsx("button",{"data-testid":"reset-pip",style:Sn,onClick:()=>o.clearPip(e.sceneId),children:"Reset bubble"}):null]})})():null,(()=>{var _;if(P)return null;const A=Fw(t,n),V=L=>O=>o.patchGraphicRect(e.sceneId,Ja({...A,[L]:O},n),`box:${e.sceneId}:${L}`);return f.jsxs("div",{style:qe,children:[f.jsx("span",{style:De,children:"Graphic box"}),f.jsx("div",{style:{fontSize:12,color:"#9A9AA3"},children:"Frame fractions — or drag the handles on the stage."}),f.jsxs("div",{style:di,children:[f.jsx(Et,{id:"box-x",value:A.x,min:0,max:1,dragStep:.002,onCommit:V("x")}),f.jsx(Et,{id:"box-y",value:A.y,min:0,max:1,dragStep:.002,onCommit:V("y")})]}),f.jsxs("div",{style:di,children:[f.jsx(Et,{id:"box-w",value:A.w,min:.08,max:1,dragStep:.002,onCommit:V("w")}),f.jsx(Et,{id:"box-h",value:A.h,min:.05,max:1,dragStep:.002,onCommit:V("h")})]}),(_=o.doc.scenes[e.sceneId])!=null&&_.graphicRect?f.jsx("button",{"data-testid":"reset-box",style:Sn,onClick:()=>o.clearGraphicRect(e.sceneId),children:"Reset box"}):null]})})(),(()=>{const A=jr(t.layout,void 0,[],n).captionAnchor,V=t.captionY??A,_=t.captionScale??1,L=o.doc.scenes[e.sceneId];return f.jsxs("div",{style:qe,children:[f.jsx("span",{style:De,children:"Captions"}),f.jsxs("div",{style:Jt,children:[f.jsxs("span",{style:De,children:["position"," ",f.jsx("span",{style:{color:"#EDEDF2"},children:V.toFixed(2)})]}),f.jsx("input",{type:"range","data-testid":"caption-y-slider",min:.05,max:.95,step:.01,value:V,onChange:O=>o.patchCaptionY(e.sceneId,Number(O.target.value),`captionY:${e.sceneId}`)})]}),f.jsxs("div",{style:Jt,children:[f.jsxs("span",{style:De,children:["scale"," ",f.jsxs("span",{style:{color:"#EDEDF2"},children:[_.toFixed(2),"×"]})]}),f.jsx("input",{type:"range","data-testid":"caption-scale-slider",min:.2,max:3,step:.01,value:_,onChange:O=>o.patchCaptionScale(e.sceneId,Number(O.target.value),`captionScale:${e.sceneId}`)})]}),f.jsx(Et,{id:"caption-scale",value:_,min:.2,max:3,dragStep:.01,onCommit:O=>o.patchCaptionScale(e.sceneId,O,`captionScale:${e.sceneId}`)}),f.jsx("button",{"data-testid":"caption-y-all",style:{...Sn,color:"#EDEDF2",border:"1px solid #2A2A33"},title:"Write this scene's caption position and scale to every scene — one undo step",onClick:()=>o.patchCaptionStyleAll(r,{y:V,scale:_}),children:"Apply to all scenes"}),(L==null?void 0:L.captionY)!==void 0||(L==null?void 0:L.captionScale)!==void 0?f.jsx("button",{"data-testid":"reset-caption-y",style:Sn,onClick:()=>o.clearCaptionStyle(e.sceneId),children:"Reset captions"}):null]})})(),f.jsxs("div",{style:qe,children:[f.jsx("span",{style:De,children:"Timing"}),f.jsxs("div",{"data-testid":"timing-range",style:{fontSize:13,fontFamily:"ui-monospace, 'SF Mono', monospace"},children:[t.startSec.toFixed(2),"s – ",t.endSec.toFixed(2),"s",f.jsxs("span",{style:{color:"#9A9AA3"},children:[" ","(",(t.endSec-t.startSec).toFixed(2),"s)"]})]}),f.jsx("div",{style:{fontSize:12,color:t.pinned?"#FFE14D":"#9A9AA3"},children:P?"Derived from the cut — not movable":t.pinned?"Pinned to these times":"Tracking transcript"}),!t.pinned&&s?f.jsxs("div",{style:{fontSize:12,color:"#9A9AA3",fontStyle:"italic"},children:["“",s,"”"]}):null,t.pinned?f.jsx("button",{style:Sn,onClick:()=>o.clearTiming(e.sceneId),children:"Un-pin (re-anchor to words)"}):null]}),P?null:f.jsx("div",{style:qe,children:f.jsx("button",{"data-testid":"delete-scene",style:Sn,onClick:()=>o.hideScene(e.sceneId),children:"Delete scene"})})]})}const u=o.doc.theme,d=(P,A)=>o.patchTheme({[P]:A}),p=P=>`${Math.floor(P/60)}:${String(Math.floor(P%60)).padStart(2,"0")}`,m=((C=l==null?void 0:l.usage)==null?void 0:C.totals)??null,h=((I=l==null?void 0:l.production)==null?void 0:I.producer)??null,w=((F=l==null?void 0:l.production)==null?void 0:F.clip)??null;return f.jsxs("div",{children:[f.jsxs("div",{style:qe,children:[f.jsx("span",{style:De,children:"Theme"}),f.jsx("div",{style:{fontSize:12,color:"#9A9AA3"},children:"Nothing selected — global tokens."})]}),f.jsxs("div",{style:qe,children:[f.jsx(ea,{id:"accent",value:u.accent??i.accent,isColor:!0,onCommit:P=>d("accent",P)}),f.jsx(ea,{id:"bg",value:u.bg??i.bg,isColor:!0,onCommit:P=>d("bg",P)}),f.jsx(ea,{id:"fg",value:u.fg??i.fg,isColor:!0,onCommit:P=>d("fg",P)}),f.jsx(Et,{id:"radiusPx",value:u.radiusPx??i.radiusPx,min:0,dragStep:.5,onCommit:P=>d("radiusPx",P)}),f.jsx(ea,{id:"fontDisplay",value:u.fontDisplay??i.fontDisplay,isColor:!1,onCommit:P=>d("fontDisplay",P)})]}),h||m?f.jsxs("div",{style:qe,"data-testid":"run-info",children:[f.jsx("span",{style:De,children:"This video"}),h?f.jsxs("div",{style:{fontSize:12,color:"#C9C9D4"},children:["planned by ",f.jsx("span",{style:{color:"#EDEDF2"},children:h.provider}),h.models.length>0?` (${h.models.join(", ")})`:"",h.cached?" · reused from cache":"",h.at?` · ${new Date(h.at).toLocaleString()}`:""]}):null,m?f.jsxs("div",{style:{fontSize:12,color:"#C9C9D4"},children:[m.calls," LLM call",m.calls===1?"":"s"," ·"," ",m.inputTokens.toLocaleString()," in / ",m.outputTokens.toLocaleString()," out tokens",m.anyEstimated?" (partly estimated)":""]}):null,m&&m.equivalentUsd!==null?f.jsx("div",{style:{fontSize:12,color:"#C9C9D4"},children:m.allUnbilled?`~$${m.equivalentUsd.toFixed(2)} of API-rate work, covered by the subscription`:m.billedUsd!==null?`~$${m.billedUsd.toFixed(2)} charged at API rates`:`~$${m.equivalentUsd.toFixed(2)} at API rates`}):null,w?f.jsxs("div",{style:{fontSize:12,color:"#C9C9D4"},children:["clip: ",p(w.startSec),"–",p(w.endSec),(j=l==null?void 0:l.production)!=null&&j.sourceDuration?` of ${p(l.production.sourceDuration)}`:""," ","(--clip ",w.targetSec,")"]}):null]}):null,f.jsx("div",{style:qe,children:f.jsx("div",{"data-testid":"ai-disclaimer",style:{fontSize:12,color:"#9A9AA3"},children:"AI can make mistakes. The cut, captions and graphics are generated — review them before publishing."})})]})},Uu=1.2,tl=.05;function q4(e,t,n,r){return n<=0||r<=0?0:Math.min(1,Math.max(0,(e-t)/n))*r}const Q4=16,J4=e=>Math.min(Q4,Math.max(1,e));function eM(e,t,n,r,o){if(e<=0||n<=0)return 0;const s=(r+o)*(t/e),a=Math.max(0,t*n-n);return Math.min(a,Math.max(0,s-o))}const Gw=e=>e.filter(t=>t.kind!=="plain");function tM(e,t,n,r){const o=Gw(e),i=o.findIndex(h=>h.id===t),s=o[i];if(!s)return null;const a=s.endSec-s.startSec,l=i>0?o[i-1]:void 0,u=i<o.length-1?o[i+1]:void 0,d=l?l.endSec+tl:0,p=u?u.startSec-tl:r,m=Math.min(Math.max(s.startSec+n,d),Math.max(d,p-a));return{startSec:m,endSec:m+a}}function nM(e,t,n,r,o){const i=Gw(e),s=i.findIndex(h=>h.id===t),a=s>0?i[s-1]:void 0,l=s>=0&&s<i.length-1?i[s+1]:void 0,u=a?a.endSec+tl:0,d=l?l.startSec-tl:o;let p=Math.min(Math.max(n,u),Math.max(u,d-Uu)),m=Math.max(Math.min(r,d),p+Uu);return m>d&&(m=d,p=Math.max(u,m-Uu)),{startSec:p,endSec:m}}const rM=10,oM=4,Dh=8,iM=300,sM=e=>{const t=Math.max(0,e),n=Math.floor(t/60),r=(t%60).toFixed(1).padStart(4,"0");return`${n}:${r}`},aM=e=>{const t=Math.max(0,Math.round(e));return`${Math.floor(t/60)}:${String(t%60).padStart(2,"0")}`},lM=(e,t)=>{const[n,r]=J.useState({}),o=J.useRef({}),i=t.map(s=>s.toFixed(1)).join(",");return J.useEffect(()=>{if(!e||t.length===0)return;const s=[...new Set(t.map(p=>p.toFixed(1)))].filter(p=>o.current[p]===void 0);if(s.length===0)return;let a=!1;const l=document.createElement("video");l.src=e,l.muted=!0,l.preload="auto";const u=document.createElement("canvas");return(async()=>{await new Promise((m,h)=>{l.onloadedmetadata=()=>m(),l.onerror=()=>h(new Error("no video for thumbnails"))}),u.width=168,u.height=Math.max(1,Math.round(168*l.videoHeight/Math.max(1,l.videoWidth)));const p=u.getContext("2d");if(p){for(const m of s){if(a)return;await new Promise(h=>{l.onseeked=()=>h(),l.currentTime=Math.max(0,Number(m))}),p.drawImage(l,0,0,u.width,u.height),o.current[m]=u.toDataURL("image/jpeg",.6)}a||r({...o.current})}})().catch(()=>{}),()=>{a=!0,l.removeAttribute("src"),l.load()}},[e,i]),n},uM=({cues:e,ghosts:t,durationSec:n,fps:r,playerRef:o,selection:i,onSelect:s,edits:a,videoSrc:l,toSourceSec:u})=>{const d=c.useRef(null),p=c.useRef(null),m=c.useRef(!1),h=c.useRef(null),[w,v]=c.useState(0),[E,g]=c.useState(null),[y,x]=c.useState(1),b=J.useMemo(()=>u?e.filter(_=>_.kind==="plain").map(_=>u((_.startSec+_.endSec)/2)):[],[e,u]),k=lM(l,b),S=c.useRef(null),C=c.useRef(null),I=c.useCallback((_,L)=>{const O=S.current;x(N=>{const T=J4(_);if(T===N||!O)return T;const z=O.getBoundingClientRect();return C.current={prevZoom:N,anchorX:L!==void 0?L-z.left:z.width/2},T})},[]);c.useLayoutEffect(()=>{const _=S.current,L=C.current;!_||!L||(C.current=null,_.scrollLeft=eM(L.prevZoom,y,_.clientWidth,_.scrollLeft,L.anchorX))},[y]);const F=c.useRef(y);F.current=y,c.useEffect(()=>{const _=S.current;if(!_)return;const L=O=>{O.ctrlKey||O.metaKey?(O.preventDefault(),I(F.current*Math.exp(-O.deltaY*.01),O.clientX)):_.scrollWidth>_.clientWidth&&(O.preventDefault(),_.scrollLeft+=O.deltaY+O.deltaX)};return _.addEventListener("wheel",L,{passive:!1}),()=>_.removeEventListener("wheel",L)},[I]),c.useEffect(()=>{const _=o.current;if(!_)return;v(_.getCurrentFrame());const L=O=>v(O.detail.frame);return _.addEventListener("frameupdate",L),()=>_.removeEventListener("frameupdate",L)},[o]),c.useEffect(()=>{const _=S.current;if(!_||n<=0||_.scrollWidth<=_.clientWidth)return;const L=w/r/n*_.scrollWidth,{scrollLeft:O,clientWidth:N}=_;(L<O||L>O+N)&&(_.scrollLeft=Math.max(0,Math.min(_.scrollWidth-N,L-N*.1)))},[w,r,n]),c.useEffect(()=>{var L,O;if(!i)return;const _=(L=S.current)==null?void 0:L.querySelector(`[data-testid="timeline-block-${i.sceneId}"]`);(O=_==null?void 0:_.scrollIntoView)==null||O.call(_,{inline:"nearest",block:"nearest"})},[i]);const j=c.useCallback(_=>{var N;const L=d.current;if(!L||n<=0)return;const O=L.getBoundingClientRect();(N=o.current)==null||N.seekTo(Math.round(q4(_,O.left,O.width,n)*r))},[o,n,r]),P=c.useCallback((_,L)=>O=>{O.stopPropagation(),O.preventDefault();const N=d.current;N&&(p.current={sceneId:_.id,edge:L,startContentX:O.clientX-N.getBoundingClientRect().left,origStart:_.startSec,origEnd:_.endSec},g({sceneId:_.id,startSec:_.startSec,endSec:_.endSec}))},[]),A=c.useRef(0);c.useEffect(()=>{const _=N=>{const T=S.current;if(!T||T.scrollWidth<=T.clientWidth)return;const z=Date.now();if(z-A.current<iM)return;const R=T.getBoundingClientRect(),$=T.scrollWidth-T.clientWidth;N>=R.right-Dh&&T.scrollLeft<$?(T.scrollLeft=Math.min($,T.scrollLeft+T.clientWidth),A.current=z):N<=R.left+Dh&&T.scrollLeft>0&&(T.scrollLeft=Math.max(0,T.scrollLeft-T.clientWidth),A.current=z)},L=N=>{var G;if((m.current||((G=h.current)==null?void 0:G.moved)===!0||p.current!==null)&&_(N.clientX),m.current){j(N.clientX);return}const z=h.current;if(z&&n>0){if(!z.moved&&Math.abs(N.clientX-z.startX)<oM)return;z.moved=!0;const oe=d.current,ne=oe==null?void 0:oe.getBoundingClientRect(),Z=ne?(N.clientX-ne.left-z.startContentX)/ne.width*n:0,ee=tM(e,z.sceneId,Z,n);ee&&g({sceneId:z.sceneId,...ee});return}const R=p.current;if(!R||n<=0)return;const $=d.current;if(!$)return;const B=$.getBoundingClientRect(),W=(N.clientX-B.left-R.startContentX)/B.width*n,M=R.edge==="start"?R.origStart+W:R.origStart,D=R.edge==="end"?R.origEnd+W:R.origEnd,K=nM(e,R.sceneId,M,D,n);g({sceneId:R.sceneId,...K})},O=N=>{m.current=!1;const T=h.current;if(T){h.current=null,T.moved?g(R=>(R&&R.sceneId===T.sceneId&&a.patchTiming(T.sceneId,R.startSec,R.endSec),null)):j(N.clientX);return}const z=p.current;z&&(g(R=>(R&&R.sceneId===z.sceneId&&(R.startSec!==z.origStart||R.endSec!==z.origEnd)&&a.patchTiming(z.sceneId,R.startSec,R.endSec),null)),p.current=null)};return window.addEventListener("mousemove",L),window.addEventListener("mouseup",O),()=>{window.removeEventListener("mousemove",L),window.removeEventListener("mouseup",O)}},[e,n,a,j]);const V=n>0?Math.min(1,w/r/n)*100:0;return f.jsxs("div",{style:cM,children:[f.jsxs("div",{style:dM,children:[f.jsx("span",{style:pM,children:"ctrl+scroll to zoom"}),f.jsx("button",{"data-testid":"zoom-out",style:Hu,onClick:()=>I(y/2),disabled:y<=1,title:"Zoom out (ctrl/cmd + scroll on the timeline)",children:"−"}),f.jsxs("span",{"data-testid":"zoom-level",style:fM,children:[Math.round(y*10)/10,"×"]}),f.jsx("button",{"data-testid":"zoom-in",style:Hu,onClick:()=>I(y*2),disabled:y>=16,title:"Zoom in (ctrl/cmd + scroll on the timeline)",children:"+"}),f.jsx("button",{"data-testid":"zoom-fit",style:{...Hu,width:"auto",padding:"0 8px"},onClick:()=>I(1),disabled:y<=1,title:"Fit the whole clip in view",children:"fit"})]}),f.jsx("div",{ref:S,"data-testid":"timeline-scroller",style:mM,children:f.jsxs("div",{style:{width:`${y*100}%`,minWidth:"100%",paddingBottom:6},children:[f.jsx("div",{"data-testid":"ruler",style:hM,onMouseDown:_=>{_.preventDefault(),j(_.clientX),m.current=!0},children:(()=>{var R;if(n<=0)return f.jsx("span",{style:Zu,children:"0:00"});const L=(((R=S.current)==null?void 0:R.clientWidth)??1200)*y/n;let N=[.5,1,2,5,10,15,30,60,120,300,600].find($=>$*L>=70)??600;for(;n/(N/5)>600;)N*=2;const T=N/5,z=[];for(let $=0;$<=n+1e-6;$+=T){const B=Math.round($/T)%5===0,W=`${$/n*100}%`;z.push(f.jsx("div",{style:{position:"absolute",left:W,bottom:0,width:1,height:B?8:4,background:B?"#3A3A44":"#26262e",pointerEvents:"none"}},$.toFixed(3))),B&&$+T<=n&&z.push(f.jsx("span",{style:{...Zu,position:"absolute",left:W,top:0,transform:$===0?void 0:"translateX(-50%)",pointerEvents:"none"},children:aM($)},`l${$.toFixed(3)}`))}return f.jsxs(f.Fragment,{children:[z,f.jsx("span",{style:{...Zu,position:"absolute",right:2,top:0,pointerEvents:"none"},children:sM(n)})]})})()}),f.jsxs("div",{ref:d,style:gM,onMouseDown:_=>{_.preventDefault(),j(_.clientX),m.current=!0},children:[e.map(_=>{const L=_.kind==="plain",O=(E==null?void 0:E.sceneId)===_.id,N=O?E.startSec:_.startSec,T=O?E.endSec:_.endSec,z=n>0?N/n*100:0,R=n>0?Math.max(0,(T-N)/n*100):0,$=(i==null?void 0:i.sceneId)===_.id,B=L&&u?k[u((_.startSec+_.endSec)/2).toFixed(1)]:void 0;return f.jsxs("div",{"data-testid":`timeline-block-${_.id}`,onMouseDown:W=>{var M;if(W.stopPropagation(),W.preventDefault(),s({sceneId:_.id,elementId:null}),L){j(W.clientX),m.current=!0;return}h.current={sceneId:_.id,startX:W.clientX,startContentX:W.clientX-(((M=d.current)==null?void 0:M.getBoundingClientRect().left)??0),moved:!1}},style:{...Oh,left:`${z}%`,width:`${R}%`,zIndex:O?4:$?3:1,border:$?"2px solid #5b8cff":L?"1px solid #22222a":"1px solid #2A2A33",backgroundColor:$?"#1c2333":L?"#131318":"#1A1A21",...B?{backgroundImage:`linear-gradient(rgba(10,10,14,0.35), rgba(10,10,14,0.6)), url(${B})`,backgroundSize:"auto 100%, auto 100%",backgroundRepeat:"repeat-x"}:{}},children:[f.jsx("span",{style:L?B?{...ta,color:"#D8D8DE",textShadow:"0 1px 2px rgba(0,0,0,0.9)"}:{...ta,color:"#55555f"}:ta,children:_.id}),!L&&_.pinned?f.jsx("span",{style:vM,children:"PIN"}):null,L?null:f.jsxs(f.Fragment,{children:[f.jsx("div",{onMouseDown:P(_,"start"),style:{...Vh,left:0,cursor:"ew-resize"}}),f.jsx("div",{onMouseDown:P(_,"end"),style:{...Vh,right:0,cursor:"ew-resize"}})]})]},_.id)}),t.map(_=>{const L=n>0?_.startSec/n*100:0,O=n>0?Math.max(0,(_.endSec-_.startSec)/n*100):0,N=(i==null?void 0:i.sceneId)===_.id;return f.jsx("div",{"data-testid":`timeline-block-${_.id}`,onMouseDown:T=>{T.stopPropagation(),T.preventDefault(),s({sceneId:_.id,elementId:null})},style:{...Oh,left:`${L}%`,width:`${O}%`,zIndex:N?3:2,border:N?"2px dashed #5b8cff":"1px dashed #6a6a75",background:"transparent"},children:f.jsx("span",{style:{...ta,color:"#6a6a75",textDecoration:"line-through"},children:_.id})},`ghost-${_.id}`)}),f.jsx("div",{"data-testid":"playhead",style:{...yM,left:`${V}%`},children:f.jsx("div",{"data-testid":"playhead-grab",onMouseDown:_=>{_.stopPropagation(),_.preventDefault(),m.current=!0},style:wM})})]})]})})]})},cM={flexShrink:0,borderTop:"1px solid #1E1E24",background:"#111116",padding:"6px 20px 8px"},dM={display:"flex",justifyContent:"flex-end",alignItems:"center",gap:6,marginBottom:4},Hu={width:22,height:18,fontSize:12,lineHeight:1,color:"#EDEDF2",background:"#1A1A21",border:"1px solid #2A2A33",borderRadius:4,cursor:"pointer",padding:0},fM={fontSize:10,fontFamily:"ui-monospace, 'SF Mono', monospace",color:"#9A9AA3",minWidth:26,textAlign:"center"},pM={fontSize:10,color:"#55555f",marginRight:4,userSelect:"none"},mM={overflowX:"auto",overflowY:"hidden"},hM={position:"relative",height:18,padding:"0 2px",marginBottom:4,borderBottom:"1px solid #1E1E24",cursor:"ew-resize",userSelect:"none"},Zu={fontSize:10,fontFamily:"ui-monospace, 'SF Mono', monospace",color:"#9A9AA3"},gM={position:"relative",height:44,background:"#0F0F14",border:"1px solid #2A2A33",borderRadius:6,overflow:"visible",userSelect:"none"},Oh={position:"absolute",top:3,bottom:3,borderRadius:4,boxSizing:"border-box",cursor:"pointer",display:"flex",alignItems:"center",overflow:"hidden"},ta={fontSize:10,fontFamily:"ui-monospace, 'SF Mono', monospace",textTransform:"uppercase",letterSpacing:"0.04em",color:"#9A9AA3",padding:"0 8px",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",pointerEvents:"none"},vM={position:"absolute",top:3,right:3,fontSize:9,fontFamily:"ui-monospace, 'SF Mono', monospace",letterSpacing:"0.04em",textTransform:"uppercase",color:"#0B0B0E",background:"#ffe14d",padding:"1px 5px",borderRadius:3,pointerEvents:"none"},Vh={position:"absolute",top:0,bottom:0,width:rM},yM={position:"absolute",top:-26,bottom:-4,width:2,zIndex:5,background:"#FFE14D",pointerEvents:"none"},wM={position:"absolute",top:0,bottom:0,left:-4,width:10,pointerEvents:"auto",cursor:"ew-resize"},xM=({baseLines:e,liveLines:t,fps:n,playerRef:r,edits:o,width:i})=>{const[s,a]=c.useState(""),[l,u]=c.useState(null),[d,p]=c.useState(null),m=c.useRef(null),h=c.useMemo(()=>{var I;const S=[];let C=0;for(let F=0;F<t.length;F++){const j=t[F],P=e[F];for(let A=0;A<j.words.length;A++){const V=j.words[A];S.push({index:C,base:((I=P==null?void 0:P.words[A])==null?void 0:I.text)??V.text,live:V.text,start:V.start,end:V.end,lineStart:j.start}),C++}}return S},[e,t]);c.useEffect(()=>{const S=r.current;if(!S)return;const C=I=>{const F=I.detail.frame/n,j=h.find(P=>F>=P.start&&F<P.end);p(P=>j?j.index===P?P:j.index:P)};return S.addEventListener("frameupdate",C),()=>S.removeEventListener("frameupdate",C)},[r,n,h]),c.useEffect(()=>{var S,C,I;d!==null&&((I=(C=(S=m.current)==null?void 0:S.querySelector(`[data-testid="transcript-word-${d}"]`))==null?void 0:C.scrollIntoView)==null||I.call(C,{block:"nearest"}))},[d]);const w=s.trim().toLowerCase(),v=c.useMemo(()=>w?h.filter(S=>S.live.toLowerCase().includes(w)).map(S=>S.index):[],[w,h]),E=c.useMemo(()=>w?new Set(v):null,[w,v]),[g,y]=c.useState(0),x=S=>{var C,I,F;(F=(I=(C=m.current)==null?void 0:C.querySelector(`[data-testid="transcript-word-${S}"]`))==null?void 0:I.scrollIntoView)==null||F.call(I,{block:"center"})};c.useEffect(()=>{y(0),v.length>0&&x(v[0])},[v]);const b=S=>{if(v.length===0)return;const C=(g+S+v.length)%v.length;y(C),x(v[C])},k=(S,C,I)=>{const F=I.trim();F&&o.patchCaption(S,F,C),u(null)};return f.jsxs("div",{"data-testid":"transcript-panel",style:{...bM,width:i},children:[f.jsxs("div",{style:SM,children:[f.jsx("span",{style:EM,children:"Transcript"}),f.jsx("div",{style:kM,children:"Click a word to jump the preview there; double-click to retype it. 1:1 retype only — word count and timing stay fixed, so scene anchors and the caption highlight keep working."}),f.jsxs("div",{style:{display:"flex",gap:6,alignItems:"center"},children:[f.jsx("input",{"data-testid":"transcript-search",style:{...CM,flex:1},placeholder:"Find a word…",value:s,onChange:S=>a(S.target.value),onKeyDown:S=>{S.key==="Enter"&&(S.preventDefault(),b(S.shiftKey?-1:1))}}),f.jsx("button",{"data-testid":"transcript-prev",style:Bh,onClick:()=>b(-1),disabled:v.length===0,title:"Previous match (⇧Enter)","aria-label":"Previous match",children:"‹"}),f.jsx("button",{"data-testid":"transcript-next",style:Bh,onClick:()=>b(1),disabled:v.length===0,title:"Next match (Enter)","aria-label":"Next match",children:"›"})]}),E?f.jsx("div",{"data-testid":"transcript-match-count",style:{fontSize:11,color:"#9A9AA3"},children:v.length===0?"0 matches":`${g+1}/${v.length} match${v.length===1?"":"es"}`}):null]}),f.jsx("div",{style:IM,"data-testid":"transcript-body",ref:m,children:h.map((S,C)=>f.jsxs(J.Fragment,{children:[C>0?" ":null,(l==null?void 0:l.index)===S.index?f.jsx("input",{autoFocus:!0,"data-testid":"transcript-edit",style:MM,value:l.draft,onChange:I=>u({index:S.index,draft:I.target.value}),onBlur:()=>k(S.index,S.base,l.draft),onKeyDown:I=>{I.key==="Enter"&&I.target.blur(),I.key==="Escape"&&u(null)}}):f.jsx("span",{"data-testid":`transcript-word-${S.index}`,onClick:()=>{var I;return(I=r.current)==null?void 0:I.seekTo(Math.round(S.start*n))},onDoubleClick:()=>u({index:S.index,draft:S.live}),title:S.live!==S.base?`edited (was “${S.base}”) — double-click to retype`:"click to jump · double-click to retype",style:{...TM,...E!=null&&E.has(S.index)?_M:{},...v[g]===S.index?RM:{},...S.live!==S.base?PM:{},...d===S.index?FM:{}},children:S.live})]},S.index))})]})},bM={flexShrink:0,display:"flex",flexDirection:"column",background:"#111116",minHeight:0},SM={display:"flex",flexDirection:"column",gap:8,padding:"14px 14px 10px",borderBottom:"1px solid #1E1E24"},EM={fontSize:11,fontWeight:600,letterSpacing:"0.06em",textTransform:"uppercase",color:"#9A9AA3"},kM={fontSize:11,lineHeight:1.45,color:"#6a6a75"},CM={fontFamily:"'Inter', system-ui, sans-serif",fontSize:13,background:"#0F0F14",border:"1px solid #2A2A33",borderRadius:6,color:"#fff",padding:"6px 8px"},IM={flex:1,overflowY:"auto",overflowX:"hidden",overflowWrap:"break-word",padding:"10px 14px 16px",fontSize:13,lineHeight:2,color:"#C9C9D4"},TM={cursor:"pointer",borderRadius:3,padding:"1px 2px"},_M={background:"#2b2b1a",outline:"1px solid #6b6432"},RM={background:"#3d3a17",outline:"2px solid #FFE14D",color:"#fff"},Bh={width:26,height:30,fontSize:16,lineHeight:1,color:"#EDEDF2",background:"#1A1A21",border:"1px solid #2A2A33",borderRadius:6,cursor:"pointer",padding:0},PM={color:"#FFE14D"},FM={background:"#1c2333",outline:"1px solid #5b8cff"},MM={fontFamily:"'Inter', system-ui, sans-serif",fontSize:13,width:110,background:"#0F0F14",border:"1px solid #FFE14D",borderRadius:4,color:"#fff",padding:"1px 4px"},jM=[{title:"transport",rows:[["space","play / pause"],["J / K / L","reverse · pause · forward (tap again to speed up)"],["← / →","step one frame back / forward"],["⌘/ctrl + ← / →","jump to and select the previous / next scene"]]},{title:"selection",rows:[["click","select scene or element"],["⌥ + ← / →","select previous / next scene"],["esc","clear selection · close dialogs"]]},{title:"editing",rows:[["⌘/ctrl + B","split the scene at the playhead"],["delete / backspace","delete the selected scene (restorable)"],["⌘/ctrl + Z","undo"],["⌘/ctrl + ⇧ + Z","redo (⌘Y works too)"],["⌘/ctrl + S","save"],["double-click caption word","retype it in place"],["drag element / corner handles","move · resize"],["drag picture","pan the video framing"]]},{title:"view",rows:[["⌘/ctrl + scroll on preview","zoom the view (never edits)"],["⌥-drag / middle-drag","pan the zoomed view"],["⌘/ctrl + scroll on timeline","zoom the timeline"],["?","this reference"]]}],$M=({onClose:e})=>(c.useEffect(()=>{const t=n=>{n.key==="Escape"&&(n.stopPropagation(),e())};return window.addEventListener("keydown",t,!0),()=>window.removeEventListener("keydown",t,!0)},[e]),f.jsx("div",{style:AM,onMouseDown:e,children:f.jsxs("div",{"data-testid":"shortcuts-modal",style:NM,onMouseDown:t=>t.stopPropagation(),children:[f.jsxs("div",{style:LM,children:[f.jsx("span",{style:zM,children:"keybinds"}),f.jsx("span",{style:DM,children:"esc close"})]}),f.jsx("div",{style:OM,children:"available commands and configured shortcuts"}),jM.map(t=>f.jsxs("div",{style:{marginTop:18},children:[f.jsx("div",{style:VM,children:t.title}),t.rows.map(([n,r])=>f.jsxs("div",{style:BM,children:[f.jsx("span",{style:WM,children:n}),f.jsx("span",{style:UM,children:r})]},n))]},t.title))]})})),AM={position:"fixed",inset:0,zIndex:30,background:"rgba(5,5,8,0.6)",display:"flex",alignItems:"center",justifyContent:"center"},NM={width:620,maxWidth:"90vw",maxHeight:"82vh",overflowY:"auto",background:"#12121A",border:"1px solid #3A3A48",borderRadius:8,padding:"20px 26px 26px",fontFamily:"ui-monospace, 'SF Mono', Consolas, monospace"},LM={display:"flex",justifyContent:"space-between",alignItems:"center"},zM={fontSize:18,fontWeight:700,color:"#EDEDF2"},DM={fontSize:13,fontWeight:700,color:"#0B0B0E",background:"#a8c7fa",borderRadius:4,padding:"3px 10px"},OM={fontSize:13,color:"#6a6a75",marginTop:4},VM={fontSize:14,fontWeight:700,color:"#8ab4f8",marginBottom:6},BM={display:"flex",gap:16,padding:"3px 0"},WM={width:290,flexShrink:0,color:"#c5a3ff",fontWeight:600,fontSize:13},UM={color:"#C9C9D4",fontSize:13},Wh=({recent:e,required:t,onOpen:n,onClose:r})=>{const[o,i]=c.useState(null),[s,a]=c.useState(null),[l,u]=c.useState(!1),d=async m=>{try{const h=await fetch(`/api/fs${m?`?dir=${encodeURIComponent(m)}`:""}`),w=await h.json();if(!h.ok)throw new Error(w.error??`listing failed: ${h.status}`);i(w)}catch(h){a(h instanceof Error?h.message:String(h))}};c.useEffect(()=>{d()},[]),c.useEffect(()=>{if(t)return;const m=h=>{h.key==="Escape"&&(h.stopPropagation(),r())};return window.addEventListener("keydown",m,!0),()=>window.removeEventListener("keydown",m,!0)},[t,r]);const p=m=>{u(!0),a(null),n(m).then(h=>{u(!1),h&&a(h)})};return f.jsx("div",{style:HM,onMouseDown:t?void 0:r,children:f.jsxs("div",{"data-testid":"project-picker",style:ZM,onMouseDown:m=>m.stopPropagation(),children:[f.jsxs("div",{style:YM,children:[f.jsx("span",{style:KM,children:t?"open a project":"switch project"}),t?null:f.jsx("button",{"data-testid":"project-picker-close",style:XM,onClick:r,children:"esc close"})]}),f.jsx("div",{style:GM,children:"A project is a work directory a `ossclip produce` run wrote — the folder holding render-props.json."}),s?f.jsx("div",{"data-testid":"project-picker-error",style:qM,children:s}):null,e.length>0?f.jsxs("div",{style:{marginTop:16},children:[f.jsx("div",{style:Uh,children:"recent"}),e.map(m=>f.jsxs("button",{"data-testid":"project-recent",style:Yu,disabled:l,onClick:()=>p(m),title:m,children:[f.jsx("span",{style:{color:"#FFE14D",marginRight:8},children:"▸"}),m]},m))]}):null,f.jsxs("div",{style:{marginTop:16},children:[f.jsx("div",{style:Uh,children:"browse"}),f.jsxs("div",{style:{color:"#6a6a75",fontSize:12,marginBottom:6},children:["Folders only — hidden ones are omitted, and any projects produced inside a folder show up directly as ",f.jsx("span",{style:{color:"#FFE14D"},children:"▸ .ossclip/…"})," entries."]}),o?f.jsxs(f.Fragment,{children:[f.jsxs("div",{style:QM,children:[f.jsx("span",{style:JM,title:o.dir,children:o.dir}),o.isWorkdir?f.jsx("button",{"data-testid":"project-open-current",style:ej,disabled:l,onClick:()=>p(o.dir),children:"open this project"}):null]}),f.jsxs("div",{style:tj,"data-testid":"project-fs-list",children:[o.parent?f.jsx("button",{"data-testid":"project-fs-up",style:Yu,disabled:l,onClick:()=>void d(o.parent),children:".."}):null,o.entries.map(m=>f.jsxs("button",{"data-testid":m.isWorkdir?"project-fs-workdir":"project-fs-dir",style:{...Yu,...m.isWorkdir?nj:{}},disabled:l,onClick:()=>m.isWorkdir?p(m.path):void d(m.path),title:m.path,children:[f.jsx("span",{style:{marginRight:8,color:m.isWorkdir?"#FFE14D":"#6a6a75"},children:m.isWorkdir?"▸":"▪"}),m.name,m.isWorkdir?f.jsx("span",{style:rj,children:"project"}):f.jsx("span",{style:{color:"#55555f"},children:"/"})]},m.path)),o.entries.length===0?f.jsx("div",{style:{color:"#6a6a75",fontSize:12,padding:"6px 8px"},children:"no folders here"}):null]})]}):f.jsx("div",{style:{color:"#6a6a75",fontSize:13},children:"loading…"})]})]})})},HM={position:"fixed",inset:0,zIndex:30,background:"rgba(5,5,8,0.6)",display:"flex",alignItems:"center",justifyContent:"center"},ZM={width:620,maxWidth:"90vw",maxHeight:"82vh",overflowY:"auto",background:"#12121A",border:"1px solid #3A3A48",borderRadius:8,padding:"20px 26px 26px",fontFamily:"ui-monospace, 'SF Mono', Consolas, monospace"},YM={display:"flex",justifyContent:"space-between",alignItems:"center"},KM={fontSize:18,fontWeight:700,color:"#EDEDF2"},XM={fontSize:13,fontWeight:700,color:"#0B0B0E",background:"#a8c7fa",border:"none",borderRadius:4,padding:"3px 10px",cursor:"pointer"},GM={fontSize:13,color:"#6a6a75",marginTop:4},qM={marginTop:12,fontSize:13,color:"#FF5C5C"},Uh={fontSize:14,fontWeight:700,color:"#8ab4f8",marginBottom:6},QM={display:"flex",alignItems:"center",gap:10,marginBottom:6},JM={fontSize:12,color:"#9A9AA3",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},ej={flexShrink:0,fontSize:12,fontWeight:700,color:"#0B0B0E",background:"#FFE14D",border:"1px solid #FFE14D",borderRadius:6,padding:"4px 10px",cursor:"pointer"},tj={maxHeight:"34vh",overflowY:"auto",display:"flex",flexDirection:"column",gap:2},Yu={display:"block",width:"100%",textAlign:"left",fontFamily:"inherit",fontSize:13,color:"#C9C9D4",background:"transparent",border:"1px solid transparent",borderRadius:6,padding:"5px 8px",cursor:"pointer",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},nj={color:"#EDEDF2",background:"#1A1A21",border:"1px solid #2A2A33"},rj={marginLeft:10,fontSize:11,fontWeight:700,color:"#FFE14D"};function na(e){for(let t=e.length-1;t>=0;t--){const n=/^\s*(\d{1,3})%\s*$/.exec(e[t]);if(n)return Math.min(100,Number(n[1]))}return null}function oj(e){const t=n=>{for(let r=e.length-1;r>=0;r--)if(n.test(e[r]))return e[r]};return[t(/^▸ producing scenes/),t(/^▸ llm:/)].filter(n=>n!==void 0)}function ij(e,t){const n=Math.max(0,Math.floor((t-e)/1e3));return`${Math.floor(n/60)}:${String(n%60).padStart(2,"0")}`}const sj=()=>{const e=B4(),[t,n]=c.useState(null),[r,o]=c.useState(null),[i,s]=c.useState(null),[a,l]=c.useState(null),[u,d]=c.useState(!1),[p,m]=c.useState(1),[h,w]=c.useState(null),[v,E]=c.useState(!1),[g,y]=c.useState([]),[x,b]=c.useState(null),[k,S]=c.useState(!1),[C,I]=c.useState(null),F=c.useRef(null);c.useEffect(()=>()=>{F.current!==null&&window.clearInterval(F.current)},[]);const[j,P]=c.useState(null),A=c.useRef(null),V=c.useRef(null),_=c.useRef(null),L=c.useRef(null),[O,N]=c.useState(null),[T,z]=c.useState(null),R=c.useCallback(H=>{var pe;if(_.current=H,z(H),(pe=L.current)==null||pe.disconnect(),L.current=null,!H)return;const X=()=>N({w:Math.max(0,H.clientWidth-Xu*2),h:Math.max(0,H.clientHeight-Xu*2)});X();const Q=new ResizeObserver(X);Q.observe(H),L.current=Q},[]),[$,B]=c.useState(1),W=c.useRef($);W.current=$;const M=c.useRef(null),D=c.useCallback((H,X)=>{const Q=_.current,pe=Math.min(8,Math.max(.25,H)),Ce=W.current;if(Q&&pe!==Ce){const Ot=Q.getBoundingClientRect();M.current={prev:Ce,ax:((X==null?void 0:X.x)??Ot.left+Ot.width/2)-Ot.left,ay:((X==null?void 0:X.y)??Ot.top+Ot.height/2)-Ot.top,sl:Q.scrollLeft,st:Q.scrollTop}}B(pe)},[]);c.useLayoutEffect(()=>{const H=_.current,X=M.current;if(!H||!X)return;M.current=null;const Q=$/X.prev;H.scrollLeft=(X.sl+X.ax)*Q-X.ax,H.scrollTop=(X.st+X.ay)*Q-X.ay},[$]),c.useEffect(()=>{const H=T;if(!H)return;const X=Q=>{(Q.ctrlKey||Q.metaKey)&&(Q.preventDefault(),D(W.current*Math.exp(-Q.deltaY*.01),{x:Q.clientX,y:Q.clientY}))};return H.addEventListener("wheel",X,{passive:!1}),()=>H.removeEventListener("wheel",X)},[T,D]);const K=c.useRef(null);c.useEffect(()=>{const H=Q=>{const pe=K.current,Ce=_.current;!pe||!Ce||(Ce.scrollLeft=pe.sl-(Q.clientX-pe.x),Ce.scrollTop=pe.st-(Q.clientY-pe.y))},X=()=>{K.current=null};return window.addEventListener("mousemove",H),window.addEventListener("mouseup",X),()=>{window.removeEventListener("mousemove",H),window.removeEventListener("mouseup",X)}},[]);const[G,oe]=c.useState(!1),[ne,Z]=c.useState(()=>{const H=Number(window.localStorage.getItem(Hh));return Number.isFinite(H)&&H>0?Zh(H):300}),ee=c.useRef(null);c.useEffect(()=>{const H=Q=>{const pe=ee.current;pe&&Z(Zh(pe.startW+(Q.clientX-pe.startX)))},X=()=>{ee.current&&(ee.current=null,Z(Q=>(window.localStorage.setItem(Hh,String(Q)),Q)))};return window.addEventListener("mousemove",H),window.addEventListener("mouseup",X),()=>{window.removeEventListener("mousemove",H),window.removeEventListener("mouseup",X)}},[]);const[ae,me]=c.useState(!1),[ge,le]=c.useState(!0),q=c.useCallback(H=>{const X=YI({rate:p,playing:u},H);m(X.rate);const Q=V.current;Q&&(X.playing&&!u&&Q.play(),!X.playing&&u&&Q.pause())},[p,u]);c.useEffect(()=>{const H=V.current;if(!H)return;const X=()=>d(!0),Q=()=>d(!1);return H.addEventListener("play",X),H.addEventListener("pause",Q),()=>{H.removeEventListener("play",X),H.removeEventListener("pause",Q)}});const de=c.useCallback(()=>{if(F.current!==null)return;const H=window.setInterval(()=>{(async()=>{try{const Q=await(await fetch("/api/render/status")).json();if(Q.running||Q.exitCode===null){I(pe=>({running:Q.running,lines:Q.lines??[],startedAt:Q.startedAt??(pe==null?void 0:pe.startedAt)}));return}if(F.current!==null&&(window.clearInterval(F.current),F.current=null),Q.exitCode===0){const Ce=await(await fetch("/api/production")).json();n(Ce.renderProps),S(!!Ce.canRender),I(null)}else I({running:!1,lines:Q.lines??[],failed:Q.exitCode,cancelled:Q.cancelled})}catch{}})()},1e3);F.current=H},[]),ye=c.useCallback(async()=>{const H=await fetch("/api/production");if(!H.ok)throw new Error(`GET /api/production failed: ${H.status}`);const X=await H.json();if(y(X.recent??[]),X.noWorkdir){E(!0);return}n(X.renderProps),b(X.workdir??null),S(!!X.canRender),e.load(X.overrides),fetch("/api/usage").then(async Ce=>o(Ce.ok?await Ce.json():null)).catch(()=>o(null));const pe=await(await fetch("/api/render/status")).json();pe.running&&(I({running:!0,lines:pe.lines??[],startedAt:pe.startedAt}),de())},[de]);c.useEffect(()=>{ye().catch(H=>s(H instanceof Error?H.message:String(H)))},[]);const Fe=c.useCallback(async H=>{if(e.dirty&&!window.confirm("Unsaved edits will be lost — switch projects anyway?"))return null;try{const X=await fetch("/api/workdir",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({path:H})}),Q=await X.json().catch(()=>({}));return X.ok?(l(null),w(null),P(null),I(null),B(1),n(null),E(!1),await ye(),null):Q.error??`open failed: ${X.status}`}catch(X){return X instanceof Error?X.message:String(X)}},[e.dirty,ye]),se=c.useMemo(()=>{if(!t)return null;const H=(t.baseSceneCues??t.sceneCues??[]).filter(St=>St.kind!=="plain"),X=t.baseTheme??t.theme??UP,{cues:Q}=Ou(H,e.doc),{cues:pe}=Sh(Q,e.doc),Ce=vF(pe,{outputDurationSec:t.outputDurationSec,clipStarts:(t.spans??[]).map(St=>St.outIn)}),Ot=lF(Ce,e.doc.splits),{cues:Gl}=Ou(Ot,e.doc),{cues:Ko}=Sh(Gl,e.doc);let Ur=h?Ko.map(St=>St.id===h.sceneId?{...St,video:{...St.video,...h.patch}}:St):Ko;j&&(Ur=Ur.map(St=>St.id===j.sceneId?{...St,graphicRect:j.rect}:St));const ql=t.baseCaptionLines??t.captionLines??[];return{...t,sceneCues:Ur,captionLines:uF(ql,e.doc.captions).lines,theme:cF(X,e.doc),videoFileName:`/media/${t.videoFileName}`}},[t,e.doc,h,j]),We=()=>{e.save().catch(H=>s(H instanceof Error?H.message:String(H)))},zt=c.useCallback(async()=>{try{e.dirty&&await e.save();const H=await fetch("/api/render",{method:"POST"});if(!H.ok){const X=await H.json().catch(()=>({}));throw new Error(X.error??`render failed to start: ${H.status}`)}I({running:!0,lines:[],startedAt:Date.now()}),de()}catch(H){s(H instanceof Error?H.message:String(H))}},[e,de]),nt=c.useMemo(()=>{if(!t)return[];const H=(t.baseSceneCues??t.sceneCues??[]).filter(Q=>Q.kind!=="plain"),{cues:X}=Ou(H,e.doc);return X.filter(Q=>{var pe;return((pe=e.doc.scenes[Q.id])==null?void 0:pe.hidden)===!0})},[t,e.doc]),Ge=c.useMemo(()=>a?(se==null?void 0:se.sceneCues.find(H=>H.id===a.sceneId))??nt.find(H=>H.id===a.sceneId)??null:null,[se,a,nt]),lt=c.useMemo(()=>{if(!Ge||!se)return;const H=se.captionLines.filter(Q=>Q.start<Ge.endSec&&Q.end>Ge.startSec).flatMap(Q=>Q.words).filter(Q=>Q.start<Ge.endSec&&Q.end>Ge.startSec).map(Q=>Q.text);if(H.length===0)return;const X=H.join(" ");return X.length>90?`${X.slice(0,90)}…`:X},[Ge,se]);if(i)return f.jsx("div",{style:Ku,children:f.jsxs("div",{style:{padding:24,color:"#FF5C5C",fontFamily:"ui-monospace, monospace"},children:["Couldn't load the production: ",i]})});if(!se)return f.jsx("div",{style:Ku,children:v?f.jsx(Wh,{recent:g,required:!0,onOpen:Fe,onClose:()=>{}}):f.jsx("div",{style:{padding:24,color:"#9A9AA3"},children:"Loading production…"})});const ut=se.settings.width/se.settings.height,Dt=O?Math.max(220,Math.min(O.w,O.h*ut)):380,Xt=Math.round(Dt*$);return f.jsxs("div",{style:Ku,children:[f.jsxs("div",{style:cj,children:[f.jsx("span",{style:dj,children:"ossclip"}),x?f.jsx("span",{"data-testid":"workdir-label",style:fj,title:x,children:x.split("/").filter(Boolean).slice(-2).join("/")}):null,f.jsxs("div",{style:{display:"flex",gap:8},children:[f.jsx("button",{"data-testid":"open-button",style:dn,onClick:()=>E(!0),title:x?`Open another project — currently ${x}`:"Open another project",children:"Open"}),f.jsx("button",{"data-testid":"undo-button",style:dn,onClick:()=>e.undo(),disabled:!e.canUndo,title:"Undo (⌘Z)","aria-label":"Undo",children:f.jsx(lj,{})}),f.jsx("button",{"data-testid":"redo-button",style:dn,onClick:()=>e.redo(),disabled:!e.canRedo,title:"Redo (⌘⇧Z)","aria-label":"Redo",children:f.jsx(uj,{})}),f.jsx("button",{"data-testid":"transcript-toggle",style:{...dn,...G?{borderColor:"#5b8cff"}:{}},onClick:()=>oe(H=>!H),title:"Find and retype caption words across the whole transcript",children:"Transcript"}),f.jsx("button",{style:{...dn,...e.dirty?mj:{}},onClick:We,disabled:!e.dirty,children:"Save"}),f.jsx("button",{"data-testid":"render-button",style:dn,onClick:()=>void zt(),disabled:!k||(C==null?void 0:C.running)===!0,title:k?"Saves if needed, then replays the last completed produce command — pipeline flags come from that run; your saved edits apply on top":"No command.json in this workdir — run `ossclip produce` once in a terminal; it records the invocation and Render replays it",children:C!=null&&C.running?"Rendering…":"Render"})]}),f.jsx("span",{style:{...pj,color:e.dirty?"#FFE14D":"#5FBF77"},...e.dirty?{"data-testid":"dirty"}:{},children:e.dirty?"● Unsaved changes":"✓ Saved"}),f.jsx("button",{"data-testid":"shortcuts-button",style:{...dn,padding:"7px 10px"},onClick:()=>me(H=>!H),title:"Keyboard shortcuts (?)",children:"?"})]}),ae?f.jsx($M,{onClose:()=>me(!1)}):null,v?f.jsx(Wh,{recent:g,required:!1,onOpen:Fe,onClose:()=>E(!1)}):null,C?f.jsxs("div",{"data-testid":"render-log",style:{...Ej,borderColor:C.failed!==void 0?"#FF5C5C":"#2A2A33"},children:[C.failed!==void 0?f.jsxs("div",{style:{color:C.cancelled?"#9A9AA3":"#FF5C5C",marginBottom:4},"data-testid":C.cancelled?"render-cancelled":"render-failed",children:[C.cancelled?"render cancelled":`render failed (exit ${C.failed})`,f.jsx("button",{style:{...dn,marginLeft:10,padding:"2px 8px"},onClick:()=>I(null),children:"Dismiss"})]}):null,C.running?f.jsxs("div",{"data-testid":"render-status",style:kj,children:[f.jsx("style",{children:"@keyframes ossclip-spin { to { transform: rotate(360deg) } }"}),f.jsx("span",{style:Cj,"aria-hidden":!0}),f.jsxs("span",{style:{color:"#EDEDF2"},children:["rendering",C.startedAt!=null?` · ${ij(C.startedAt,Date.now())}`:"",na(C.lines)!==null?` · ${na(C.lines)}%`:""]}),na(C.lines)!==null?f.jsx("div",{style:Ij,children:f.jsx("div",{"data-testid":"render-progress-bar",style:{...Tj,width:`${na(C.lines)}%`}})}):null,f.jsx("button",{"data-testid":"render-cancel",style:{...dn,padding:"2px 8px"},onClick:()=>void fetch("/api/render/cancel",{method:"POST"}),children:"Cancel"}),f.jsx("button",{"data-testid":"render-logs-toggle",style:{...dn,padding:"2px 8px"},onClick:()=>le(H=>!H),title:ge?"Collapse the log":"Expand the log",children:ge?"▾ logs":"▸ logs"})]}):null,ge?f.jsxs(f.Fragment,{children:[oj(C.lines).map(H=>f.jsx("div",{"data-testid":"render-pinned",style:{color:"#C9C9D4"},children:H},H)),f.jsx(aj,{lines:C.lines})]}):null]}):null,f.jsxs("div",{style:hj,children:[G?f.jsxs(f.Fragment,{children:[f.jsx(xM,{baseLines:(t==null?void 0:t.baseCaptionLines)??(t==null?void 0:t.captionLines)??[],liveLines:se.captionLines,fps:se.settings.fps,playerRef:V,edits:e,width:ne}),f.jsx("div",{"data-testid":"transcript-divider",style:gj,title:"Drag to resize the transcript pane",onMouseDown:H=>{H.preventDefault(),ee.current={startX:H.clientX,startW:ne}}})]}):null,f.jsxs("div",{style:vj,children:[f.jsx("div",{ref:R,style:yj,onMouseDown:H=>{if(H.altKey||H.button===1){H.preventDefault();const X=_.current;X&&(K.current={x:H.clientX,y:H.clientY,sl:X.scrollLeft,st:X.scrollTop})}},children:f.jsx("div",{style:{margin:"auto",padding:Xu},children:f.jsxs("div",{ref:A,"data-testid":"stage","data-playing":u?"true":"false","data-rate":p,style:{position:"relative",display:"inline-block"},children:[f.jsx(OI,{ref:V,component:z4,inputProps:se,durationInFrames:Math.max(1,Math.round(se.outputDurationSec*se.settings.fps)),fps:se.settings.fps,compositionWidth:se.settings.width,compositionHeight:se.settings.height,style:{width:Xt},controls:!0,clickToPlay:!1,playbackRate:p}),f.jsx(K4,{stageRef:A,selection:a,onSelect:l,edits:e,onSave:We,settings:se.settings,cues:se.sceneCues,playerRef:V,cue:Ge,onTransport:q,onVideoPreview:w,onGraphicPreview:P,onToggleHelp:()=>me(H=>!H)}),f.jsx("button",{"data-testid":"rate-chip",onClick:()=>q("L"),title:"Playback rate — click to speed up (J/K/L on the keyboard)",style:_j,children:p<0?`◂◂ ${Math.abs(p)}×`:`${p}×`})]})})}),f.jsxs("div",{style:wj,children:[f.jsx("button",{"data-testid":"view-zoom-out",style:Gu,onClick:()=>D($/2),disabled:$<=.25,title:"Zoom the preview out — below 100% shrinks under the fitted size",children:"−"}),f.jsxs("span",{"data-testid":"view-zoom-level",style:xj,children:[Math.round($*100),"%"]}),f.jsx("button",{"data-testid":"view-zoom-in",style:Gu,onClick:()=>D($*2),disabled:$>=8,title:"Zoom the preview in — a viewing magnifier, it never edits the video",children:"+"}),f.jsx("button",{"data-testid":"view-zoom-fit",style:{...Gu,width:"auto",padding:"0 8px"},onClick:()=>D(1),disabled:Math.abs($-1)<.001,title:"Fit the preview to the window",children:"fit"}),f.jsx("span",{style:bj,children:"⌥-drag pans"})]})]}),f.jsx("div",{style:Sj,children:f.jsx(G4,{selection:a,cue:Ge,frame:{width:se.settings.width,height:se.settings.height},allSceneIds:se.sceneCues.map(H=>H.id),edits:e,resolvedTheme:se.theme,anchorText:lt,onVideoPreview:w,runInfo:r})})]}),f.jsx(uM,{cues:se.sceneCues,ghosts:nt,durationSec:se.outputDurationSec,fps:se.settings.fps,playerRef:V,selection:a,onSelect:l,edits:e,videoSrc:se.videoFileName,toSourceSec:H=>{var X;for(const Q of se.spans??[])if(H>=Q.outIn&&H<Q.outOut)return Q.srcIn+(H-Q.outIn);return((X=(se.spans??[])[0])==null?void 0:X.srcIn)??H}})]})},aj=({lines:e})=>{const t=c.useRef(null),n=c.useRef(!0);return c.useEffect(()=>{const r=t.current;r&&n.current&&(r.scrollTop=r.scrollHeight)},[e]),f.jsx("div",{ref:t,"data-testid":"render-tail",onScroll:r=>{const o=r.currentTarget;n.current=o.scrollTop+o.clientHeight>=o.scrollHeight-8},style:{maxHeight:220,overflowY:"auto"},children:e.map((r,o)=>f.jsx("div",{children:r},o))})},lj=()=>f.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.4",strokeLinecap:"round",strokeLinejoin:"round",style:{display:"block"},children:[f.jsx("path",{d:"M9 14 4 9l5-5"}),f.jsx("path",{d:"M4 9h10.5a5.5 5.5 0 0 1 0 11H11"})]}),uj=()=>f.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.4",strokeLinecap:"round",strokeLinejoin:"round",style:{display:"block"},children:[f.jsx("path",{d:"m15 14 5-5-5-5"}),f.jsx("path",{d:"M20 9H9.5a5.5 5.5 0 0 0 0 11H13"})]}),Ku={fontFamily:"'Inter', system-ui, sans-serif",background:"#0B0B0E",color:"#EDEDF2",height:"100vh",overflow:"hidden",display:"flex",flexDirection:"column"},cj={display:"flex",alignItems:"center",gap:14,padding:"10px 20px",borderBottom:"1px solid #1E1E24",background:"#111116"},dj={fontWeight:800,fontSize:14,letterSpacing:"0.02em",color:"#FFE14D",marginRight:8},fj={fontSize:12,fontFamily:"ui-monospace, 'SF Mono', monospace",color:"#6a6a75",maxWidth:260,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},pj={fontSize:12,fontFamily:"ui-monospace, 'SF Mono', monospace",marginLeft:"auto"},dn={fontSize:12,fontWeight:600,color:"#EDEDF2",background:"#1A1A21",border:"1px solid #2A2A33",borderRadius:6,padding:"7px 12px",cursor:"pointer"},mj={background:"#FFE14D",color:"#0B0B0E",border:"1px solid #FFE14D"},hj={display:"flex",flex:1,minHeight:0},Xu=32,Hh="ossclip.transcriptWidth",Zh=e=>Math.min(640,Math.max(220,e)),gj={width:5,flexShrink:0,cursor:"col-resize",background:"#1E1E24",borderLeft:"1px solid #2A2A33"},vj={position:"relative",flex:1,minWidth:0},yj={position:"absolute",inset:0,display:"flex",overflow:"auto"},wj={position:"absolute",top:10,left:10,zIndex:6,display:"flex",alignItems:"center",gap:6,padding:"4px 6px",background:"rgba(17,17,22,0.85)",border:"1px solid #2A2A33",borderRadius:6},Gu={width:22,height:18,fontSize:12,lineHeight:1,color:"#EDEDF2",background:"#1A1A21",border:"1px solid #2A2A33",borderRadius:4,cursor:"pointer",padding:0},xj={fontSize:10,fontFamily:"ui-monospace, 'SF Mono', monospace",color:"#9A9AA3",minWidth:34,textAlign:"center"},bj={fontSize:10,color:"#55555f",userSelect:"none"},Sj={width:260,flexShrink:0,borderLeft:"1px solid #1E1E24",background:"#111116",overflowY:"auto"},Ej={fontSize:11,fontFamily:"ui-monospace, 'SF Mono', monospace",color:"#9A9AA3",background:"#0F0F14",borderBottom:"1px solid #2A2A33",padding:"6px 20px",whiteSpace:"pre-wrap",flexShrink:0},kj={display:"flex",alignItems:"center",gap:10,marginBottom:4},Cj={width:12,height:12,flexShrink:0,border:"2px solid #2A2A33",borderTopColor:"#FFE14D",borderRadius:"50%",animation:"ossclip-spin 0.8s linear infinite"},Ij={flex:1,maxWidth:260,height:4,background:"#1E1E24",borderRadius:2,overflow:"hidden"},Tj={height:"100%",background:"#FFE14D",borderRadius:2,transition:"width 0.6s ease"},_j={position:"absolute",top:8,right:8,zIndex:5,fontSize:11,fontWeight:700,fontFamily:"ui-monospace, 'SF Mono', monospace",color:"#FFE14D",background:"rgba(11,11,14,0.75)",border:"1px solid #2A2A33",borderRadius:6,padding:"3px 8px",cursor:"pointer"};qu.createRoot(document.getElementById("root")).render(f.jsx(J.StrictMode,{children:f.jsx(sj,{})}));
159
+ })));`),m.write(`newResult[${ci(y)}] = ${x}.value`)}m.write("payload.value = newResult;"),m.write("return payload;");const g=m.compile();return(y,x)=>g(p,y,x)};let o;const i=cd,s=!sw.jitless,l=s&&QI.value,u=t.catchall;let d;e._zod.parse=(p,m)=>{d??(d=n.value);const h=p.value;if(!i(h))return p.issues.push({expected:"object",code:"invalid_type",input:h,inst:e}),p;const w=[];if(s&&l&&(m==null?void 0:m.async)===!1&&m.jitless!==!0)o||(o=r(t.shape)),p=o(p,m);else{p.value={};const x=d.shape;for(const b of d.keys){const k=x[b],S=k._zod.run({value:h[b],issues:[]},m),C=k._zod.optin==="optional"&&k._zod.optout==="optional";S instanceof Promise?w.push(S.then(I=>C?oh(I,p,b,h):Ks(I,p,b))):C?oh(S,p,b,h):Ks(S,p,b)}}if(!u)return w.length?Promise.all(w).then(()=>p):p;const v=[],E=d.keySet,g=u._zod,y=g.def.type;for(const x of Object.keys(h)){if(E.has(x))continue;if(y==="never"){v.push(x);continue}const b=g.run({value:h[x],issues:[]},m);b instanceof Promise?w.push(b.then(k=>Ks(k,p,x))):Ks(b,p,x)}return v.length&&p.issues.push({code:"unrecognized_keys",keys:v,input:h,inst:e}),w.length?Promise.all(w).then(()=>p):p}});function ih(e,t,n,r){for(const o of e)if(o.issues.length===0)return t.value=o.value,t;return t.issues.push({code:"invalid_union",input:t.value,inst:n,errors:e.map(o=>o.issues.map(i=>sr(i,r,ir())))}),t}const M_=U("$ZodUnion",(e,t)=>{Ne.init(e,t),Re(e._zod,"optin",()=>t.options.some(n=>n._zod.optin==="optional")?"optional":void 0),Re(e._zod,"optout",()=>t.options.some(n=>n._zod.optout==="optional")?"optional":void 0),Re(e._zod,"values",()=>{if(t.options.every(n=>n._zod.values))return new Set(t.options.flatMap(n=>Array.from(n._zod.values)))}),Re(e._zod,"pattern",()=>{if(t.options.every(n=>n._zod.pattern)){const n=t.options.map(r=>r._zod.pattern);return new RegExp(`^(${n.map(r=>Wf(r.source)).join("|")})$`)}}),e._zod.parse=(n,r)=>{let o=!1;const i=[];for(const s of t.options){const a=s._zod.run({value:n.value,issues:[]},r);if(a instanceof Promise)i.push(a),o=!0;else{if(a.issues.length===0)return a;i.push(a)}}return o?Promise.all(i).then(s=>ih(s,n,e,r)):ih(i,n,e,r)}}),j_=U("$ZodIntersection",(e,t)=>{Ne.init(e,t),e._zod.parse=(n,r)=>{const o=n.value,i=t.left._zod.run({value:o,issues:[]},r),s=t.right._zod.run({value:o,issues:[]},r);return i instanceof Promise||s instanceof Promise?Promise.all([i,s]).then(([l,u])=>sh(n,l,u)):sh(n,i,s)}});function dd(e,t){if(e===t)return{valid:!0,data:e};if(e instanceof Date&&t instanceof Date&&+e==+t)return{valid:!0,data:e};if(Ga(e)&&Ga(t)){const n=Object.keys(t),r=Object.keys(e).filter(i=>n.indexOf(i)!==-1),o={...e,...t};for(const i of r){const s=dd(e[i],t[i]);if(!s.valid)return{valid:!1,mergeErrorPath:[i,...s.mergeErrorPath]};o[i]=s.data}return{valid:!0,data:o}}if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return{valid:!1,mergeErrorPath:[]};const n=[];for(let r=0;r<e.length;r++){const o=e[r],i=t[r],s=dd(o,i);if(!s.valid)return{valid:!1,mergeErrorPath:[r,...s.mergeErrorPath]};n.push(s.data)}return{valid:!0,data:n}}return{valid:!1,mergeErrorPath:[]}}function sh(e,t,n){if(t.issues.length&&e.issues.push(...t.issues),n.issues.length&&e.issues.push(...n.issues),Ti(e))return e;const r=dd(t.value,n.value);if(!r.valid)throw new Error(`Unmergable intersection. Error path: ${JSON.stringify(r.mergeErrorPath)}`);return e.value=r.data,e}const $_=U("$ZodRecord",(e,t)=>{Ne.init(e,t),e._zod.parse=(n,r)=>{const o=n.value;if(!Ga(o))return n.issues.push({expected:"record",code:"invalid_type",input:o,inst:e}),n;const i=[];if(t.keyType._zod.values){const s=t.keyType._zod.values;n.value={};for(const l of s)if(typeof l=="string"||typeof l=="number"||typeof l=="symbol"){const u=t.valueType._zod.run({value:o[l],issues:[]},r);u instanceof Promise?i.push(u.then(d=>{d.issues.length&&n.issues.push(...Er(l,d.issues)),n.value[l]=d.value})):(u.issues.length&&n.issues.push(...Er(l,u.issues)),n.value[l]=u.value)}let a;for(const l in o)s.has(l)||(a=a??[],a.push(l));a&&a.length>0&&n.issues.push({code:"unrecognized_keys",input:o,inst:e,keys:a})}else{n.value={};for(const s of Reflect.ownKeys(o)){if(s==="__proto__")continue;const a=t.keyType._zod.run({value:s,issues:[]},r);if(a instanceof Promise)throw new Error("Async schemas not supported in object keys currently");if(a.issues.length){n.issues.push({origin:"record",code:"invalid_key",issues:a.issues.map(u=>sr(u,r,ir())),input:s,path:[s],inst:e}),n.value[a.value]=a.value;continue}const l=t.valueType._zod.run({value:o[s],issues:[]},r);l instanceof Promise?i.push(l.then(u=>{u.issues.length&&n.issues.push(...Er(s,u.issues)),n.value[a.value]=u.value})):(l.issues.length&&n.issues.push(...Er(s,l.issues)),n.value[a.value]=l.value)}}return i.length?Promise.all(i).then(()=>n):n}}),A_=U("$ZodEnum",(e,t)=>{Ne.init(e,t);const n=XI(t.entries);e._zod.values=new Set(n),e._zod.pattern=new RegExp(`^(${n.filter(r=>JI.has(typeof r)).map(r=>typeof r=="string"?Ul(r):r.toString()).join("|")})$`),e._zod.parse=(r,o)=>{const i=r.value;return e._zod.values.has(i)||r.issues.push({code:"invalid_value",values:n,input:i,inst:e}),r}}),N_=U("$ZodTransform",(e,t)=>{Ne.init(e,t),e._zod.parse=(n,r)=>{const o=t.transform(n.value,n);if(r.async)return(o instanceof Promise?o:Promise.resolve(o)).then(s=>(n.value=s,n));if(o instanceof Promise)throw new Gi;return n.value=o,n}}),L_=U("$ZodOptional",(e,t)=>{Ne.init(e,t),e._zod.optin="optional",e._zod.optout="optional",Re(e._zod,"values",()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,void 0]):void 0),Re(e._zod,"pattern",()=>{const n=t.innerType._zod.pattern;return n?new RegExp(`^(${Wf(n.source)})?$`):void 0}),e._zod.parse=(n,r)=>t.innerType._zod.optin==="optional"?t.innerType._zod.run(n,r):n.value===void 0?n:t.innerType._zod.run(n,r)}),z_=U("$ZodNullable",(e,t)=>{Ne.init(e,t),Re(e._zod,"optin",()=>t.innerType._zod.optin),Re(e._zod,"optout",()=>t.innerType._zod.optout),Re(e._zod,"pattern",()=>{const n=t.innerType._zod.pattern;return n?new RegExp(`^(${Wf(n.source)}|null)$`):void 0}),Re(e._zod,"values",()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,null]):void 0),e._zod.parse=(n,r)=>n.value===null?n:t.innerType._zod.run(n,r)}),D_=U("$ZodDefault",(e,t)=>{Ne.init(e,t),e._zod.optin="optional",Re(e._zod,"values",()=>t.innerType._zod.values),e._zod.parse=(n,r)=>{if(n.value===void 0)return n.value=t.defaultValue,n;const o=t.innerType._zod.run(n,r);return o instanceof Promise?o.then(i=>ah(i,t)):ah(o,t)}});function ah(e,t){return e.value===void 0&&(e.value=t.defaultValue),e}const O_=U("$ZodPrefault",(e,t)=>{Ne.init(e,t),e._zod.optin="optional",Re(e._zod,"values",()=>t.innerType._zod.values),e._zod.parse=(n,r)=>(n.value===void 0&&(n.value=t.defaultValue),t.innerType._zod.run(n,r))}),V_=U("$ZodNonOptional",(e,t)=>{Ne.init(e,t),Re(e._zod,"values",()=>{const n=t.innerType._zod.values;return n?new Set([...n].filter(r=>r!==void 0)):void 0}),e._zod.parse=(n,r)=>{const o=t.innerType._zod.run(n,r);return o instanceof Promise?o.then(i=>lh(i,e)):lh(o,e)}});function lh(e,t){return!e.issues.length&&e.value===void 0&&e.issues.push({code:"invalid_type",expected:"nonoptional",input:e.value,inst:t}),e}const B_=U("$ZodCatch",(e,t)=>{Ne.init(e,t),e._zod.optin="optional",Re(e._zod,"optout",()=>t.innerType._zod.optout),Re(e._zod,"values",()=>t.innerType._zod.values),e._zod.parse=(n,r)=>{const o=t.innerType._zod.run(n,r);return o instanceof Promise?o.then(i=>(n.value=i.value,i.issues.length&&(n.value=t.catchValue({...n,error:{issues:i.issues.map(s=>sr(s,r,ir()))},input:n.value}),n.issues=[]),n)):(n.value=o.value,o.issues.length&&(n.value=t.catchValue({...n,error:{issues:o.issues.map(i=>sr(i,r,ir()))},input:n.value}),n.issues=[]),n)}}),W_=U("$ZodPipe",(e,t)=>{Ne.init(e,t),Re(e._zod,"values",()=>t.in._zod.values),Re(e._zod,"optin",()=>t.in._zod.optin),Re(e._zod,"optout",()=>t.out._zod.optout),e._zod.parse=(n,r)=>{const o=t.in._zod.run(n,r);return o instanceof Promise?o.then(i=>uh(i,t,r)):uh(o,t,r)}});function uh(e,t,n){return Ti(e)?e:t.out._zod.run({value:e.value,issues:e.issues},n)}const U_=U("$ZodReadonly",(e,t)=>{Ne.init(e,t),Re(e._zod,"propValues",()=>t.innerType._zod.propValues),Re(e._zod,"values",()=>t.innerType._zod.values),Re(e._zod,"optin",()=>t.innerType._zod.optin),Re(e._zod,"optout",()=>t.innerType._zod.optout),e._zod.parse=(n,r)=>{const o=t.innerType._zod.run(n,r);return o instanceof Promise?o.then(ch):ch(o)}});function ch(e){return e.value=Object.freeze(e.value),e}const H_=U("$ZodCustom",(e,t)=>{Rt.init(e,t),Ne.init(e,t),e._zod.parse=(n,r)=>n,e._zod.check=n=>{const r=n.value,o=t.fn(r);if(o instanceof Promise)return o.then(i=>dh(i,n,r,e));dh(o,n,r,e)}});function dh(e,t,n,r){if(!e){const o={code:"custom",input:n,inst:r,path:[...r._zod.def.path??[]],continue:!r._zod.def.abort};r._zod.def.params&&(o.params=r._zod.def.params),t.issues.push(qi(o))}}class Z_{constructor(){this._map=new Map,this._idmap=new Map}add(t,...n){const r=n[0];if(this._map.set(t,r),r&&typeof r=="object"&&"id"in r){if(this._idmap.has(r.id))throw new Error(`ID ${r.id} already exists in the registry`);this._idmap.set(r.id,t)}return this}clear(){return this._map=new Map,this._idmap=new Map,this}remove(t){const n=this._map.get(t);return n&&typeof n=="object"&&"id"in n&&this._idmap.delete(n.id),this._map.delete(t),this}get(t){const n=t._zod.parent;if(n){const r={...this.get(n)??{}};return delete r.id,{...r,...this._map.get(t)}}return this._map.get(t)}has(t){return this._map.has(t)}}function Y_(){return new Z_}const Xs=Y_();function K_(e,t){return new e({type:"string",...ie(t)})}function X_(e,t){return new e({type:"string",format:"email",check:"string_format",abort:!1,...ie(t)})}function fh(e,t){return new e({type:"string",format:"guid",check:"string_format",abort:!1,...ie(t)})}function G_(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,...ie(t)})}function q_(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v4",...ie(t)})}function Q_(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v6",...ie(t)})}function J_(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v7",...ie(t)})}function eR(e,t){return new e({type:"string",format:"url",check:"string_format",abort:!1,...ie(t)})}function tR(e,t){return new e({type:"string",format:"emoji",check:"string_format",abort:!1,...ie(t)})}function nR(e,t){return new e({type:"string",format:"nanoid",check:"string_format",abort:!1,...ie(t)})}function rR(e,t){return new e({type:"string",format:"cuid",check:"string_format",abort:!1,...ie(t)})}function oR(e,t){return new e({type:"string",format:"cuid2",check:"string_format",abort:!1,...ie(t)})}function iR(e,t){return new e({type:"string",format:"ulid",check:"string_format",abort:!1,...ie(t)})}function sR(e,t){return new e({type:"string",format:"xid",check:"string_format",abort:!1,...ie(t)})}function aR(e,t){return new e({type:"string",format:"ksuid",check:"string_format",abort:!1,...ie(t)})}function lR(e,t){return new e({type:"string",format:"ipv4",check:"string_format",abort:!1,...ie(t)})}function uR(e,t){return new e({type:"string",format:"ipv6",check:"string_format",abort:!1,...ie(t)})}function cR(e,t){return new e({type:"string",format:"cidrv4",check:"string_format",abort:!1,...ie(t)})}function dR(e,t){return new e({type:"string",format:"cidrv6",check:"string_format",abort:!1,...ie(t)})}function fR(e,t){return new e({type:"string",format:"base64",check:"string_format",abort:!1,...ie(t)})}function pR(e,t){return new e({type:"string",format:"base64url",check:"string_format",abort:!1,...ie(t)})}function mR(e,t){return new e({type:"string",format:"e164",check:"string_format",abort:!1,...ie(t)})}function hR(e,t){return new e({type:"string",format:"jwt",check:"string_format",abort:!1,...ie(t)})}function gR(e,t){return new e({type:"string",format:"datetime",check:"string_format",offset:!1,local:!1,precision:null,...ie(t)})}function vR(e,t){return new e({type:"string",format:"date",check:"string_format",...ie(t)})}function yR(e,t){return new e({type:"string",format:"time",check:"string_format",precision:null,...ie(t)})}function wR(e,t){return new e({type:"string",format:"duration",check:"string_format",...ie(t)})}function xR(e,t){return new e({type:"number",checks:[],...ie(t)})}function bR(e,t){return new e({type:"number",check:"number_format",abort:!1,format:"safeint",...ie(t)})}function SR(e,t){return new e({type:"boolean",...ie(t)})}function ER(e){return new e({type:"unknown"})}function kR(e,t){return new e({type:"never",...ie(t)})}function ph(e,t){return new yw({check:"less_than",...ie(t),value:e,inclusive:!1})}function zu(e,t){return new yw({check:"less_than",...ie(t),value:e,inclusive:!0})}function mh(e,t){return new ww({check:"greater_than",...ie(t),value:e,inclusive:!1})}function Du(e,t){return new ww({check:"greater_than",...ie(t),value:e,inclusive:!0})}function hh(e,t){return new VT({check:"multiple_of",...ie(t),value:e})}function Sw(e,t){return new WT({check:"max_length",...ie(t),maximum:e})}function qa(e,t){return new UT({check:"min_length",...ie(t),minimum:e})}function Ew(e,t){return new HT({check:"length_equals",...ie(t),length:e})}function CR(e,t){return new ZT({check:"string_format",format:"regex",...ie(t),pattern:e})}function IR(e){return new YT({check:"string_format",format:"lowercase",...ie(e)})}function TR(e){return new KT({check:"string_format",format:"uppercase",...ie(e)})}function _R(e,t){return new XT({check:"string_format",format:"includes",...ie(t),includes:e})}function RR(e,t){return new GT({check:"string_format",format:"starts_with",...ie(t),prefix:e})}function PR(e,t){return new qT({check:"string_format",format:"ends_with",...ie(t),suffix:e})}function hs(e){return new QT({check:"overwrite",tx:e})}function FR(e){return hs(t=>t.normalize(e))}function MR(){return hs(e=>e.trim())}function jR(){return hs(e=>e.toLowerCase())}function $R(){return hs(e=>e.toUpperCase())}function AR(e,t,n){return new e({type:"array",element:t,...ie(n)})}function NR(e,t,n){return new e({type:"custom",check:"custom",fn:t,...ie(n)})}const LR=U("ZodISODateTime",(e,t)=>{f_.init(e,t),Le.init(e,t)});function zR(e){return gR(LR,e)}const DR=U("ZodISODate",(e,t)=>{p_.init(e,t),Le.init(e,t)});function OR(e){return vR(DR,e)}const VR=U("ZodISOTime",(e,t)=>{m_.init(e,t),Le.init(e,t)});function BR(e){return yR(VR,e)}const WR=U("ZodISODuration",(e,t)=>{h_.init(e,t),Le.init(e,t)});function UR(e){return wR(WR,e)}const HR=(e,t)=>{cw.init(e,t),e.name="ZodError",Object.defineProperties(e,{format:{value:n=>uT(e,n)},flatten:{value:n=>lT(e,n)},addIssue:{value:n=>e.issues.push(n)},addIssues:{value:n=>e.issues.push(...n)},isEmpty:{get(){return e.issues.length===0}}})},Zl=U("ZodError",HR,{Parent:Error}),ZR=cT(Zl),YR=dT(Zl),KR=fw(Zl),XR=pw(Zl),Be=U("ZodType",(e,t)=>(Ne.init(e,t),e.def=t,Object.defineProperty(e,"_def",{value:t}),e.check=(...n)=>e.clone({...t,checks:[...t.checks??[],...n.map(r=>typeof r=="function"?{_zod:{check:r,def:{check:"custom"},onattach:[]}}:r)]}),e.clone=(n,r)=>Wr(e,n,r),e.brand=()=>e,e.register=(n,r)=>(n.add(e,r),e),e.parse=(n,r)=>ZR(e,n,r,{callee:e.parse}),e.safeParse=(n,r)=>KR(e,n,r),e.parseAsync=async(n,r)=>YR(e,n,r,{callee:e.parseAsync}),e.safeParseAsync=async(n,r)=>XR(e,n,r),e.spa=e.safeParseAsync,e.refine=(n,r)=>e.check(VP(n,r)),e.superRefine=n=>e.check(BP(n)),e.overwrite=n=>e.check(hs(n)),e.optional=()=>yh(e),e.nullable=()=>wh(e),e.nullish=()=>yh(wh(e)),e.nonoptional=n=>jP(e,n),e.array=()=>lr(e),e.or=n=>SP([e,n]),e.and=n=>kP(e,n),e.transform=n=>xh(e,TP(n)),e.default=n=>PP(e,n),e.prefault=n=>MP(e,n),e.catch=n=>AP(e,n),e.pipe=n=>xh(e,n),e.readonly=()=>zP(e),e.describe=n=>{const r=e.clone();return Xs.add(r,{description:n}),r},Object.defineProperty(e,"description",{get(){var n;return(n=Xs.get(e))==null?void 0:n.description},configurable:!0}),e.meta=(...n)=>{if(n.length===0)return Xs.get(e);const r=e.clone();return Xs.add(r,n[0]),r},e.isOptional=()=>e.safeParse(void 0).success,e.isNullable=()=>e.safeParse(null).success,e)),kw=U("_ZodString",(e,t)=>{Zf.init(e,t),Be.init(e,t);const n=e._zod.bag;e.format=n.format??null,e.minLength=n.minimum??null,e.maxLength=n.maximum??null,e.regex=(...r)=>e.check(CR(...r)),e.includes=(...r)=>e.check(_R(...r)),e.startsWith=(...r)=>e.check(RR(...r)),e.endsWith=(...r)=>e.check(PR(...r)),e.min=(...r)=>e.check(qa(...r)),e.max=(...r)=>e.check(Sw(...r)),e.length=(...r)=>e.check(Ew(...r)),e.nonempty=(...r)=>e.check(qa(1,...r)),e.lowercase=r=>e.check(IR(r)),e.uppercase=r=>e.check(TR(r)),e.trim=()=>e.check(MR()),e.normalize=(...r)=>e.check(FR(...r)),e.toLowerCase=()=>e.check(jR()),e.toUpperCase=()=>e.check($R())}),GR=U("ZodString",(e,t)=>{Zf.init(e,t),kw.init(e,t),e.email=n=>e.check(X_(qR,n)),e.url=n=>e.check(eR(QR,n)),e.jwt=n=>e.check(hR(pP,n)),e.emoji=n=>e.check(tR(JR,n)),e.guid=n=>e.check(fh(gh,n)),e.uuid=n=>e.check(G_(Gs,n)),e.uuidv4=n=>e.check(q_(Gs,n)),e.uuidv6=n=>e.check(Q_(Gs,n)),e.uuidv7=n=>e.check(J_(Gs,n)),e.nanoid=n=>e.check(nR(eP,n)),e.guid=n=>e.check(fh(gh,n)),e.cuid=n=>e.check(rR(tP,n)),e.cuid2=n=>e.check(oR(nP,n)),e.ulid=n=>e.check(iR(rP,n)),e.base64=n=>e.check(fR(cP,n)),e.base64url=n=>e.check(pR(dP,n)),e.xid=n=>e.check(sR(oP,n)),e.ksuid=n=>e.check(aR(iP,n)),e.ipv4=n=>e.check(lR(sP,n)),e.ipv6=n=>e.check(uR(aP,n)),e.cidrv4=n=>e.check(cR(lP,n)),e.cidrv6=n=>e.check(dR(uP,n)),e.e164=n=>e.check(mR(fP,n)),e.datetime=n=>e.check(zR(n)),e.date=n=>e.check(OR(n)),e.time=n=>e.check(BR(n)),e.duration=n=>e.check(UR(n))});function ue(e){return K_(GR,e)}const Le=U("ZodStringFormat",(e,t)=>{Pe.init(e,t),kw.init(e,t)}),qR=U("ZodEmail",(e,t)=>{r_.init(e,t),Le.init(e,t)}),gh=U("ZodGUID",(e,t)=>{t_.init(e,t),Le.init(e,t)}),Gs=U("ZodUUID",(e,t)=>{n_.init(e,t),Le.init(e,t)}),QR=U("ZodURL",(e,t)=>{o_.init(e,t),Le.init(e,t)}),JR=U("ZodEmoji",(e,t)=>{i_.init(e,t),Le.init(e,t)}),eP=U("ZodNanoID",(e,t)=>{s_.init(e,t),Le.init(e,t)}),tP=U("ZodCUID",(e,t)=>{a_.init(e,t),Le.init(e,t)}),nP=U("ZodCUID2",(e,t)=>{l_.init(e,t),Le.init(e,t)}),rP=U("ZodULID",(e,t)=>{u_.init(e,t),Le.init(e,t)}),oP=U("ZodXID",(e,t)=>{c_.init(e,t),Le.init(e,t)}),iP=U("ZodKSUID",(e,t)=>{d_.init(e,t),Le.init(e,t)}),sP=U("ZodIPv4",(e,t)=>{g_.init(e,t),Le.init(e,t)}),aP=U("ZodIPv6",(e,t)=>{v_.init(e,t),Le.init(e,t)}),lP=U("ZodCIDRv4",(e,t)=>{y_.init(e,t),Le.init(e,t)}),uP=U("ZodCIDRv6",(e,t)=>{w_.init(e,t),Le.init(e,t)}),cP=U("ZodBase64",(e,t)=>{x_.init(e,t),Le.init(e,t)}),dP=U("ZodBase64URL",(e,t)=>{S_.init(e,t),Le.init(e,t)}),fP=U("ZodE164",(e,t)=>{E_.init(e,t),Le.init(e,t)}),pP=U("ZodJWT",(e,t)=>{C_.init(e,t),Le.init(e,t)}),Cw=U("ZodNumber",(e,t)=>{bw.init(e,t),Be.init(e,t),e.gt=(r,o)=>e.check(mh(r,o)),e.gte=(r,o)=>e.check(Du(r,o)),e.min=(r,o)=>e.check(Du(r,o)),e.lt=(r,o)=>e.check(ph(r,o)),e.lte=(r,o)=>e.check(zu(r,o)),e.max=(r,o)=>e.check(zu(r,o)),e.int=r=>e.check(vh(r)),e.safe=r=>e.check(vh(r)),e.positive=r=>e.check(mh(0,r)),e.nonnegative=r=>e.check(Du(0,r)),e.negative=r=>e.check(ph(0,r)),e.nonpositive=r=>e.check(zu(0,r)),e.multipleOf=(r,o)=>e.check(hh(r,o)),e.step=(r,o)=>e.check(hh(r,o)),e.finite=()=>e;const n=e._zod.bag;e.minValue=Math.max(n.minimum??Number.NEGATIVE_INFINITY,n.exclusiveMinimum??Number.NEGATIVE_INFINITY)??null,e.maxValue=Math.min(n.maximum??Number.POSITIVE_INFINITY,n.exclusiveMaximum??Number.POSITIVE_INFINITY)??null,e.isInt=(n.format??"").includes("int")||Number.isSafeInteger(n.multipleOf??.5),e.isFinite=!0,e.format=n.format??null});function ce(e){return xR(Cw,e)}const mP=U("ZodNumberFormat",(e,t)=>{I_.init(e,t),Cw.init(e,t)});function vh(e){return bR(mP,e)}const hP=U("ZodBoolean",(e,t)=>{T_.init(e,t),Be.init(e,t)});function ar(e){return SR(hP,e)}const gP=U("ZodUnknown",(e,t)=>{__.init(e,t),Be.init(e,t)});function Mo(){return ER(gP)}const vP=U("ZodNever",(e,t)=>{R_.init(e,t),Be.init(e,t)});function yP(e){return kR(vP,e)}const wP=U("ZodArray",(e,t)=>{P_.init(e,t),Be.init(e,t),e.element=t.element,e.min=(n,r)=>e.check(qa(n,r)),e.nonempty=n=>e.check(qa(1,n)),e.max=(n,r)=>e.check(Sw(n,r)),e.length=(n,r)=>e.check(Ew(n,r)),e.unwrap=()=>e.element});function lr(e,t){return AR(wP,e,t)}const xP=U("ZodObject",(e,t)=>{F_.init(e,t),Be.init(e,t),Re(e,"shape",()=>t.shape),e.keyof=()=>Yo(Object.keys(e._zod.def.shape)),e.catchall=n=>e.clone({...e._zod.def,catchall:n}),e.passthrough=()=>e.clone({...e._zod.def,catchall:Mo()}),e.loose=()=>e.clone({...e._zod.def,catchall:Mo()}),e.strict=()=>e.clone({...e._zod.def,catchall:yP()}),e.strip=()=>e.clone({...e._zod.def,catchall:void 0}),e.extend=n=>oT(e,n),e.merge=n=>iT(e,n),e.pick=n=>nT(e,n),e.omit=n=>rT(e,n),e.partial=(...n)=>sT(Iw,e,n[0]),e.required=(...n)=>aT(Tw,e,n[0])});function xe(e,t){const n={type:"object",get shape(){return Uf(this,"shape",{...e}),this.shape},...ie(t)};return new xP(n)}const bP=U("ZodUnion",(e,t)=>{M_.init(e,t),Be.init(e,t),e.options=t.options});function SP(e,t){return new bP({type:"union",options:e,...ie(t)})}const EP=U("ZodIntersection",(e,t)=>{j_.init(e,t),Be.init(e,t)});function kP(e,t){return new EP({type:"intersection",left:e,right:t})}const CP=U("ZodRecord",(e,t)=>{$_.init(e,t),Be.init(e,t),e.keyType=t.keyType,e.valueType=t.valueType});function ur(e,t,n){return new CP({type:"record",keyType:e,valueType:t,...ie(n)})}const fd=U("ZodEnum",(e,t)=>{A_.init(e,t),Be.init(e,t),e.enum=t.entries,e.options=Object.values(t.entries);const n=new Set(Object.keys(t.entries));e.extract=(r,o)=>{const i={};for(const s of r)if(n.has(s))i[s]=t.entries[s];else throw new Error(`Key ${s} not found in enum`);return new fd({...t,checks:[],...ie(o),entries:i})},e.exclude=(r,o)=>{const i={...t.entries};for(const s of r)if(n.has(s))delete i[s];else throw new Error(`Key ${s} not found in enum`);return new fd({...t,checks:[],...ie(o),entries:i})}});function Yo(e,t){const n=Array.isArray(e)?Object.fromEntries(e.map(r=>[r,r])):e;return new fd({type:"enum",entries:n,...ie(t)})}const IP=U("ZodTransform",(e,t)=>{N_.init(e,t),Be.init(e,t),e._zod.parse=(n,r)=>{n.addIssue=i=>{if(typeof i=="string")n.issues.push(qi(i,n.value,t));else{const s=i;s.fatal&&(s.continue=!1),s.code??(s.code="custom"),s.input??(s.input=n.value),s.inst??(s.inst=e),s.continue??(s.continue=!0),n.issues.push(qi(s))}};const o=t.transform(n.value,n);return o instanceof Promise?o.then(i=>(n.value=i,n)):(n.value=o,n)}});function TP(e){return new IP({type:"transform",transform:e})}const Iw=U("ZodOptional",(e,t)=>{L_.init(e,t),Be.init(e,t),e.unwrap=()=>e._zod.def.innerType});function yh(e){return new Iw({type:"optional",innerType:e})}const _P=U("ZodNullable",(e,t)=>{z_.init(e,t),Be.init(e,t),e.unwrap=()=>e._zod.def.innerType});function wh(e){return new _P({type:"nullable",innerType:e})}const RP=U("ZodDefault",(e,t)=>{D_.init(e,t),Be.init(e,t),e.unwrap=()=>e._zod.def.innerType,e.removeDefault=e.unwrap});function PP(e,t){return new RP({type:"default",innerType:e,get defaultValue(){return typeof t=="function"?t():t}})}const FP=U("ZodPrefault",(e,t)=>{O_.init(e,t),Be.init(e,t),e.unwrap=()=>e._zod.def.innerType});function MP(e,t){return new FP({type:"prefault",innerType:e,get defaultValue(){return typeof t=="function"?t():t}})}const Tw=U("ZodNonOptional",(e,t)=>{V_.init(e,t),Be.init(e,t),e.unwrap=()=>e._zod.def.innerType});function jP(e,t){return new Tw({type:"nonoptional",innerType:e,...ie(t)})}const $P=U("ZodCatch",(e,t)=>{B_.init(e,t),Be.init(e,t),e.unwrap=()=>e._zod.def.innerType,e.removeCatch=e.unwrap});function AP(e,t){return new $P({type:"catch",innerType:e,catchValue:typeof t=="function"?t:()=>t})}const NP=U("ZodPipe",(e,t)=>{W_.init(e,t),Be.init(e,t),e.in=t.in,e.out=t.out});function xh(e,t){return new NP({type:"pipe",in:e,out:t})}const LP=U("ZodReadonly",(e,t)=>{U_.init(e,t),Be.init(e,t)});function zP(e){return new LP({type:"readonly",innerType:e})}const DP=U("ZodCustom",(e,t)=>{H_.init(e,t),Be.init(e,t)});function OP(e){const t=new Rt({check:"custom"});return t._zod.check=e,t}function VP(e,t={}){return NR(DP,e,t)}function BP(e){const t=OP(n=>(n.addIssue=r=>{if(typeof r=="string")n.issues.push(qi(r,n.value,t._zod.def));else{const o=r;o.fatal&&(o.continue=!1),o.code??(o.code="custom"),o.input??(o.input=n.value),o.inst??(o.inst=t),o.continue??(o.continue=!t._zod.def.abort),n.issues.push(qi(o))}},e(n.value,n)));return t}const Yl=Yo(["full-bleed","video-top","pip-bubble","graphic-only","blurred-behind","lower-third","split-left","split-right"]),Kl=Yo(["TitleCard","StatCard","RuleCard","StrikethroughReveal","FlowDiagram","TerminalMock","ChatMock","ScreenshotFrame","BulletList"]),WP=xe({startWord:ce().int().nonnegative(),endWord:ce().int().nonnegative()});xe({id:ue(),anchor:WP,layout:Yl,component:Kl,props:ur(ue(),Mo()),overrides:ur(ue(),Mo()).default({}),rationale:ue().optional()});xe({id:ue(),kind:Yo(["graphic","plain"]).optional(),layout:Yl,component:Kl.optional(),props:ur(ue(),Mo()).optional(),startSec:ce().nonnegative(),endSec:ce().nonnegative(),graphicRect:xe({x:ce(),y:ce(),w:ce(),h:ce()}).optional(),elements:ur(ue(),xe({dx:ce().optional(),dy:ce().optional(),scale:ce().positive().optional()})).optional(),video:xe({scale:ce().positive().max(4).optional(),dy:ce().optional(),dx:ce().optional(),autoZoom:ar().optional()}).optional(),pip:xe({cornerRadius:ce().min(0).max(1).optional(),x:ce().min(0).max(1).optional(),y:ce().min(0).max(1).optional()}).optional(),captionY:ce().min(0).max(1).optional(),captionScale:ce().min(.2).max(3).optional(),pinned:ar().optional()}).superRefine((e,t)=>{e.kind!=="plain"&&(e.component===void 0||e.props===void 0)&&t.addIssue({code:"custom",message:'a graphic cue requires component and props; only kind: "plain" may omit them'})});xe({centerYFrac:ce().min(0).max(1),sizeFrac:ce().min(0).max(1).optional(),centerXFrac:ce().min(0).max(1).optional(),sourceAspect:ce().positive().optional()});const Yf=xe({bg:ue().default("#0B0B0E"),fg:ue().default("#FFFFFF"),accent:ue().default("#FFE14D"),muted:ue().default("#9A9AA3"),success:ue().default("#5FBF77"),cardBg:ue().default("#15151B"),cardBorder:ue().default("#2A2A33"),danger:ue().default("#FF5C5C"),radiusPx:ce().default(24),fontDisplay:ue().default("'Inter', 'Helvetica Neue', 'Arial Black', Arial, sans-serif"),fontMono:ue().default("'SF Mono', 'Cascadia Code', Consolas, monospace")}),UP=Yf.parse({}),HP=xe({eyebrow:ue().max(28).optional(),title:ue().min(1).max(48).describe("the claim WITHOUT the emphasis token — never repeat the emphasis here"),emphasis:ue().max(16).optional().describe("the number/punch token pulled OUT of the title (e.g. '861%') — not a duplicate of it"),sub:ue().max(64).optional()}),ZP=xe({label:ue().min(1).max(28),value:ue().min(1).max(12),caption:ue().max(40).optional(),inverted:ar().default(!1)}),YP=xe({kicker:ue().min(1).max(24),text:ue().min(1).max(40),struck:ue().max(40).optional()}),KP=xe({lines:lr(xe({text:ue().min(1).max(32),struck:ar().default(!1),mark:Yo(["none","cross","check"]).default("none")})).min(1).max(4)}),XP=xe({title:ue().max(28).optional(),items:lr(ue().min(1).max(36)).min(2).max(5)}),GP=xe({nodes:lr(ue().min(1).max(16)).min(2).max(5),emphasizeLast:ar().default(!0)}),qP=xe({windows:lr(xe({title:ue().max(24),lines:lr(ue().max(40)).min(1).max(6)})).min(1).max(5),fanOut:ue().max(20).optional()}),QP=xe({messages:lr(xe({from:Yo(["user","agent"]),text:ue().min(1).max(60)})).min(1).max(4),keyword:ue().max(16).optional().describe("ONLY for a 'comment <word>' ask: the single distinctive word the viewer types, plain and unformatted. Leave unset for any other CTA — especially 'reply with a number/which one', where there is no word to type. Never a referential filler like 'number', 'answer', 'comment' or 'below'.")}),JP=xe({src:ue().optional().describe("OMIT THIS unless the user supplied an actual image file beside the video — never invent a filename from the transcript; without it the frame renders as a styled placeholder, which is the intended look"),label:ue().max(32).optional(),kenBurns:ar().default(!0)}),eF={TitleCard:{propsSchema:HP,defaultProps:{title:"TITLE"},defaultLayout:"pip-bubble",altLayouts:[],whenToUse:"The core claim or hook as big typography; use `emphasis` for a huge number or punch word."},StatCard:{propsSchema:ZP,defaultProps:{label:"METRIC",value:"+0%"},defaultLayout:"video-top",altLayouts:["blurred-behind"],whenToUse:"One striking metric (value like '+242%', '×3', '5s'); punchline in `caption`."},RuleCard:{propsSchema:YP,defaultProps:{kicker:"RULE",text:"DO THE THING"},defaultLayout:"video-top",altLayouts:["blurred-behind"],whenToUse:"A prescriptive takeaway ('CAPACITY RULE / CAP ACTIVE AGENTS'); `struck` shows the rejected alternative."},StrikethroughReveal:{propsSchema:KP,defaultProps:{lines:[{text:"NOT THIS",struck:!0}]},defaultLayout:"blurred-behind",altLayouts:["graphic-only"],whenToUse:'Negation/contrast beat — big words over the blurred speaker. Strike EVERY line of the phrase the speaker negates, not just its tail — a half-struck claim reads as a typo. For wrong-vs-right lists, set mark: "cross"/"check" (✗/✓) per line instead.'},FlowDiagram:{propsSchema:GP,defaultProps:{nodes:["A","B"]},defaultLayout:"graphic-only",altLayouts:[],whenToUse:"A causal chain or pipeline as chips with arrows (TEAM → AI AGENTS → CHURN)."},TerminalMock:{propsSchema:qP,defaultProps:{windows:[{title:"terminal-01",lines:["$ run"]}]},defaultLayout:"graphic-only",altLayouts:[],whenToUse:"Anything about running code/processes/agents — stylized terminal windows."},ChatMock:{propsSchema:QP,defaultProps:{messages:[{from:"user",text:"hello"}]},defaultLayout:"blurred-behind",altLayouts:["graphic-only"],whenToUse:"A quoted phrase or exchange as chat bubbles over the blurred speaker; for a comment-CTA beat, set `keyword` to the word viewers should type."},ScreenshotFrame:{propsSchema:JP,defaultProps:{},defaultLayout:"video-top",altLayouts:["blurred-behind"],whenToUse:"Reference to a document/PR/review — a framed screenshot look with a label chip."},BulletList:{propsSchema:XP,defaultProps:{items:["FIRST","SECOND"]},defaultLayout:"blurred-behind",altLayouts:["graphic-only"],whenToUse:"An ENUMERATION — the speaker lists two or more parallel things ('what you need is X, Y, Z'). One bullet per item, optional kicker title. Use this for lists instead of bending TitleCard or StrikethroughReveal around them."}};function bh(e,t,n={}){const r=eF[e],o={...r.defaultProps,...t,...n},i=r.propsSchema.safeParse(o);return i.success?i.data:null}const tF=xe({dx:ce().optional(),dy:ce().optional(),scale:ce().positive().optional()}),_w=xe({props:ur(ue(),Mo()).default({}),elements:ur(ue(),tF).default({}),timing:xe({startSec:ce().nonnegative(),endSec:ce().nonnegative()}).optional(),component:Kl.optional(),layout:Yl.optional(),video:xe({scale:ce().positive().max(4).optional(),dy:ce().optional(),dx:ce().optional(),autoZoom:ar().optional()}).optional(),pip:xe({cornerRadius:ce().min(0).max(1).optional(),x:ce().min(0).max(1).optional(),y:ce().min(0).max(1).optional()}).optional(),captionY:ce().min(0).max(1).optional(),captionScale:ce().min(.2).max(3).optional(),graphicRect:xe({x:ce().min(0).max(1),y:ce().min(0).max(1),w:ce().min(.08).max(1),h:ce().min(.05).max(1)}).optional(),hidden:ar().optional()}),nF=xe({text:ue().min(1).max(80),was:ue()});function rF(e,t,n){var r;return((r=e[String(t)])==null?void 0:r.was)??n}const oF=xe({theme:Yf.partial().default({}),scenes:ur(ue(),_w).default({}),captions:ur(ue(),nF).default({}),splits:lr(ce().nonnegative()).default([])}),iF=()=>oF.parse({});function sF(e,t){return bh(e,{},t)??bh(e,{},{})}function aF(e,t){const n=e[t],r=t.indexOf("@");if(r===-1)return n;const o=e[t.slice(0,r)];if(!o)return n;const{timing:i,hidden:s,...a}=o;return n?{...a,...n,props:{...a.props,...n.props},elements:{...a.elements,...n.elements},...a.video||n.video?{video:{...a.video,...n.video}}:{},...a.pip||n.pip?{pip:{...a.pip,...n.pip}}:{}}:{...a,props:{...a.props},elements:{...a.elements}}}function Ou(e,t){const n=new Set(e.map(i=>i.id)),r=Object.keys(t.scenes).filter(i=>!n.has(i));return{cues:e.map(i=>{const s=aF(t.scenes,i.id);if(!s)return i;const a=s.component!==void 0&&s.component!==i.component,l=s.component??i.component,u=s.component!==void 0&&a?sF(s.component,s.props):{...i.props,...s.props},d=s.layout!==void 0&&s.layout!==i.layout,{graphicRect:p,...m}=i;return{...d?m:i,component:l,layout:s.layout??i.layout,props:u,...Object.keys(s.elements).length>0?{elements:s.elements}:{},...s.video?{video:s.video}:{},...s.pip?{pip:s.pip}:{},...s.captionY!==void 0?{captionY:s.captionY}:{},...s.captionScale!==void 0?{captionScale:s.captionScale}:{},...s.graphicRect?{graphicRect:s.graphicRect}:{},...s.timing&&!i.pinned?{startSec:s.timing.startSec,endSec:s.timing.endSec,pinned:!0}:{}}}),orphans:r}}const Qa=.3;function lF(e,t){const n=[...e];for(const r of[...t].sort((o,i)=>o-i)){const o=n.findIndex(s=>r>=s.startSec+Qa&&r<=s.endSec-Qa);if(o===-1)continue;const i=n[o];n.splice(o,1,{...i,endSec:r},{...i,id:`${i.id.split("@")[0]}@${Math.round(r*1e3)}`,startSec:r})}return n}function Sh(e,t){const n=[];return{cues:e.filter(o=>{var i;return((i=t.scenes[o.id])==null?void 0:i.hidden)!==!0?!0:(n.push(o.id),!1)}),hidden:n}}function uF(e,t){const n=[];if(Object.keys(t).length===0)return{lines:[...e],dropped:n};let r=0;return{lines:e.map(i=>({...i,words:i.words.map(s=>{const a=t[String(r++)];return a?s.text!==a.was?(n.push({index:r-1,expected:a.was,found:s.text}),s):{...s,text:a.text}:s})})),dropped:n}}function cF(e,t){return Yf.parse({...e,...t.theme})}function dF(e,t,n,r){const o=e.scenes[t]??_w.parse({});return{...e,scenes:{...e.scenes,[t]:{...o,elements:{...o.elements,[n]:{...o.elements[n],...r}}}}}}function fF(e,t,n){const r=e.scenes[t];if(!r)return e;const{[n]:o,...i}=r.elements;return{...e,scenes:{...e.scenes,[t]:{...r,elements:i}}}}function pF(e,t){const n=e.scenes[t];if(!n||!n.timing)return e;const{timing:r,...o}=n;return{...e,scenes:{...e.scenes,[t]:o}}}function mF(e,t){const n=e.scenes[t];if(!n||!n.graphicRect)return e;const{graphicRect:r,...o}=n;return{...e,scenes:{...e.scenes,[t]:o}}}const hF=.6;function gF(e,t){const n=new Set([0]);for(const r of e??[])Number.isFinite(r)&&r>0&&r<t&&n.add(r);return[...n].sort((r,o)=>r-o)}function vF(e,t){const n=t.outputDurationSec,r=[...e].sort((d,p)=>d.startSec-p.startSec);if(n<=0)return r;const o=gF(t.clipStarts,n),i=[];let s=0;for(const d of r)d.startSec-s>1e-9&&i.push({start:s,end:d.startSec}),s=Math.max(s,d.endSec);n-s>1e-9&&i.push({start:s,end:n});const a=[];for(const d of i){const p=o.filter(h=>h>d.start+1e-9&&h<d.end-1e-9),m=[d.start,...p,d.end];for(let h=0;h<m.length-1;h++){const w=m[h],v=m[h+1];if(v-w<hF)continue;let E=0;for(let g=0;g<o.length;g++)o[g]<=w+1e-9&&(E=g);a.push({start:w,end:v,clip:E})}}const l=new Map,u=a.map(d=>{const p=l.get(d.clip)??0;return l.set(d.clip,p+1),{id:p===0?`take-${d.clip}`:`take-${d.clip}-${p}`,kind:"plain",layout:"full-bleed",startSec:d.start,endSec:d.end}});return[...r,...u].sort((d,p)=>d.startSec-p.startSec)}const yF=1.05;function wF(e,t){for(const r of e)if(t>=r.startSec&&t<r.endSec){const o=r.endSec-r.startSec,i=o>0?(t-r.startSec)/o:1,s=.5-.5*Math.cos(Math.PI*i);return r.from+(r.to-r.from)*s}const n=e[e.length-1];return n&&t===n.endSec?n.to:1}function xF(e,t,n){if(e.length===0)return{x:0,y:0,w:(n==null?void 0:n.width)??0,h:(n==null?void 0:n.height)??0,full:!0};if(t<e[0].startSec)return e[0].rect;for(const r of e)if(t>=r.startSec&&t<r.endSec)return r.rect;return e[e.length-1].rect}const Lt={width:1080,height:1920};Lt.width;Lt.height;const gs={centerYFrac:.38,sizeFrac:.22},bF=.35,SF=.45,Rw=1-1/yF,EF=.4*Rw,kF=.6*Rw;function Pw(e,t,n=Lt){const r=e.w*n.width,o=e.h*n.height;return Math.max(o,r/(t.sourceAspect??n.width/n.height))}function CF(e,t,n=Lt){const r=e.h*n.height,o=Pw(e,t,n),i=o-r;if(i<=1)return .5;const s=t.sizeFrac??gs.sizeFrac,a=(t.centerYFrac-s/2-bF*s)*o,l=(t.centerYFrac+s/2)*o,u=(a+l)/2-SF*r,d=a-EF*r,p=l+kF*r-r,m=p<=d?Math.min(Math.max(u,p),d):p;return Math.min(1,Math.max(0,m/i))}function IF(e,t,n,r,o=Lt){if(r.length===0)return e;const i=t.h*o.height,s=Pw(t,n,o);if(s-i<=1)return e;const l=i/s,u=1-l;if(u<=0)return e;let d=e*u;for(let p=0;p<r.length+1;p++){const m=r.find(x=>{const b=x.y,k=x.y+x.h,S=d+l,C=b<d&&d<k,I=b<S&&S<k;return C||I});if(!m)break;const h=[],w=m.y+m.h;w<=u&&h.push(w);const v=m.y-l;if(v>=0&&h.push(v),m.h<=l){const x=Math.max(0,m.y+m.h-l),b=Math.min(u,m.y);x<=b&&h.push(Math.min(Math.max(d,x),b))}const E=n.sizeFrac??gs.sizeFrac,g=n.centerYFrac+E/2,y=h.filter(x=>x+l>=g);if(y.length===0)return e;d=y.reduce((x,b)=>Math.abs(b-d)<Math.abs(x-d)?b:x)}return Math.min(1,Math.max(0,d/u))}function TF(e,t,n=Lt){const r=e.w*n.width,o=e.h*n.height,i=Math.max(r,o*(t.sourceAspect??n.width/n.height)),s=i-r;if(s<=1||t.centerXFrac===void 0)return .5;const a=t.centerXFrac*i-r/2;return Math.min(1,Math.max(0,a/s))}const _F={top:.12,bottom:.22,right:.16,left:.04},RF={top:.06,bottom:.12,right:.05,left:.05};function kr(e=Lt){return e.width>e.height?RF:_F}function PF(e=Lt){const t=kr(e);return{x:t.left,y:t.top,w:1-t.left-t.right,h:1-t.top-t.bottom}}const FF=.08,MF=.05;function Ja(e,t=Lt){const n=PF(t),r=1e-9,o=(u,d,p)=>u<d-r?d:u>p+r?p:u,i=o(e.w,FF,n.w),s=o(e.h,MF,n.h),a=o(e.x,n.x,n.x+n.w-i),l=o(e.y,n.y,n.y+n.h-s);return{x:a,y:l,w:i,h:s}}const Eh=.045,bn={x:0,y:0,w:1,h:1},Vu=.3,Gr={x:.5-Vu/2,y:.66,w:Vu,h:Vu*1080/1920};function jr(e,t=gs,n=[],r=Lt){const o=a=>IF(CF(a,t,r),a,t,n,r),i=a=>TF(a,t,r),s=r.width>r.height;switch(e){case"full-bleed":return{video:{rect:bn,cornerRadius:0,blurPx:0,dim:0,opacity:1,objectPosY:o(bn),objectPosX:i(bn)},graphic:null,captionAnchor:.7};case"lower-third":{const a=s?{x:.05,y:.7,w:.62,h:.18}:{x:.04,y:.56,w:.8,h:.22};return{video:{rect:bn,cornerRadius:0,blurPx:0,dim:0,opacity:1,objectPosY:o(bn),objectPosX:i(bn)},graphic:a,captionAnchor:s?.62:.49}}case"split-left":case"split-right":{if(s){const l=e==="split-left",u={x:l?0:.5,y:0,w:.5,h:1};return{video:{rect:u,cornerRadius:0,blurPx:0,dim:0,opacity:1,objectPosY:o(u),objectPosX:i(u)},graphic:l?{x:.55,y:.2,w:.4,h:.56}:{x:.05,y:.2,w:.4,h:.56},captionAnchor:.82}}const a={x:0,y:0,w:1,h:.5};return{video:{rect:a,cornerRadius:0,blurPx:0,dim:0,opacity:1,objectPosY:o(a),objectPosX:i(a)},graphic:{x:.04,y:.58,w:.8,h:.2},captionAnchor:.53}}case"video-top":{const a={x:0,y:0,w:1,h:.42};return{video:{rect:a,cornerRadius:0,blurPx:0,dim:0,opacity:1,objectPosY:o(a),objectPosX:i(a)},graphic:{x:.04,y:.54,w:.8,h:.24},captionAnchor:.48}}case"pip-bubble":return{video:{rect:Gr,cornerRadius:1,blurPx:0,dim:0,opacity:1,objectPosY:o(Gr),objectPosX:i(Gr)},graphic:{x:.06,y:.14,w:.78,h:.42},captionAnchor:.61};case"graphic-only":return{video:{rect:Gr,cornerRadius:1,blurPx:0,dim:0,opacity:0,objectPosY:o(Gr),objectPosX:i(Gr)},graphic:{x:.04,y:.14,w:.8,h:.54},captionAnchor:.73};case"blurred-behind":return{video:{rect:bn,cornerRadius:0,blurPx:22,dim:.55,opacity:1,objectPosY:o(bn),objectPosX:i(bn)},graphic:{x:.07,y:.24,w:.77,h:.36},captionAnchor:.69}}}const jF={x:.07,y:.24,w:.77,h:.36};function Fw(e,t=Lt){return e.graphicRect?Ja(e.graphicRect,t):jr(e.layout,gs,[],t).graphic??jF}const Mw=.35;function nr(e,t){for(const n of e)if(t>=n.startSec&&t<n.endSec)return n;return null}function Ut(e,t,n){return e+(t-e)*n}function $F(e,t,n){return{x:Ut(e.x,t.x,n),y:Ut(e.y,t.y,n),w:Ut(e.w,t.w,n),h:Ut(e.h,t.h,n)}}function kh(e,t,n){return{rect:$F(e.rect,t.rect,n),cornerRadius:Ut(e.cornerRadius,t.cornerRadius,n),blurPx:Ut(e.blurPx,t.blurPx,n),dim:Ut(e.dim,t.dim,n),opacity:Ut(e.opacity,t.opacity,n),objectPosY:Ut(e.objectPosY,t.objectPosY,n),objectPosX:Ut(e.objectPosX,t.objectPosX,n)}}function el(e){return e*e*(3-2*e)}function jw(e){return e.filter(t=>!(t.kind==="plain"&&t.layout==="full-bleed"))}function Bu(e,t,n,r){const o=jr(e.layout,t,n,r).video,i=e.layout==="pip-bubble"?e.pip:void 0;if(!i)return o;const s={...o.rect,x:Math.min(Math.max(i.x??o.rect.x,0),1-o.rect.w),y:Math.min(Math.max(i.y??o.rect.y,0),1-o.rect.h)};return{...o,rect:s,cornerRadius:i.cornerRadius??o.cornerRadius}}function AF(e,t,n=gs,r=[],o=Lt){const i=jw(e),s=r.filter(g=>t>=g.startSec&&t<g.endSec),a=jr("full-bleed",n,s,o).video,l=nr(i,t);if(!l)return a;const u=Bu(l,n,s,o),d=Math.min(Mw,(l.endSec-l.startSec)/2),p=t-l.startSec,m=l.endSec-t,h=nr(i,l.startSec-.001),w=nr(i,l.endSec+.001),v=h?Bu(h,n,s,o):a,E=w?Bu(w,n,s,o):a;return p<d?kh(v,u,el(p/d)):m<d?kh(u,E,el(1-m/d)):u}function Wu(e){return e==="pip-bubble"||e==="graphic-only"?1:0}function NF(e,t){const n=jw(e),r=nr(n,t);if(!r)return 0;const o=Wu(r.layout),i=Math.min(Mw,(r.endSec-r.startSec)/2),s=nr(n,r.startSec-.001),a=nr(n,r.endSec+.001),l=s?Wu(s.layout):0,u=a?Wu(a.layout):0,d=t-r.startSec,p=r.endSec-t;return d<i?Ut(l,o,el(d/i)):p<i?Ut(o,u,el(1-p/i)):o}function LF(e,t,n){return e.filter(r=>(r.startSec??Number.NEGATIVE_INFINITY)<n&&(r.endSec??Number.POSITIVE_INFINITY)>t)}function zF(e,t){let n=0;for(const r of t){const o=Math.max(e.y,r.y),i=Math.min(e.y+e.h,r.y+r.h);i>o&&(n+=i-o)}return Math.min(1,n/e.h)}function DF(e,t,n,r=Lt){const o=jr(e,void 0,[],r),i=kr(r),s=o.captionAnchor,a=l=>{const u={y:l-Eh,h:Eh*2};if(u.y<i.top||u.y+u.h>1-i.bottom||zF(u,t)>0)return!1;const d=n??o.graphic;return!(d&&Math.min(u.y+u.h,d.y+d.h)-Math.max(u.y,d.y)>0)};if(a(s))return s;for(let l=.02;l<=.6;l+=.02)for(const u of[s-l,s+l])if(a(u))return u;return s}const Ch=.4;function OF(e,t){if(!t)return e;const n=e.replace(/^[^A-Za-z0-9]+|[^A-Za-z0-9]+$/g,"");return n.toLowerCase()!==t.toLowerCase()?e:e.replace(n,`"${n.toUpperCase()}"`)}function VF(e,t){return t?e>=t.startSec-Ch&&e<=t.endSec+Ch:!1}const BF=({line:e,wordOffset:t,verticalAnchor:n,fontSizePx:r,activeColor:o,ctaKeyword:i,ctaWindow:s})=>{const a=ht(),{fps:l,width:u,height:d}=Xe(),p=kr({width:u,height:d}),m=e.start+a/l;return f.jsx(an,{style:{pointerEvents:"none"},children:f.jsx("div",{style:{position:"absolute",top:`${n*100}%`,left:0,right:0,transform:"translateY(-50%)",display:"flex",justifyContent:"center",gap:"0.28em",flexWrap:"wrap",paddingLeft:`${p.left*100}%`,paddingRight:`${p.right*100}%`,fontFamily:"'Inter', 'Helvetica Neue', 'Arial Black', Arial, sans-serif",fontWeight:900,fontSize:r,lineHeight:1.15,textAlign:"center",color:"white",WebkitTextStroke:"10px rgba(0,0,0,0.85)",paintOrder:"stroke fill",textShadow:"0 4px 24px rgba(0,0,0,0.55)"},children:e.words.map((h,w)=>{const v=m>=h.start&&m<=Math.max(h.end,h.start+.12);return f.jsx("span",{"data-caption-word":t+w,"data-caption-text":h.text,style:{display:"inline-block",pointerEvents:"auto",transform:v?"scale(1.08)":"scale(1)",color:v?o:"white",transition:"transform 60ms linear"},children:OF(h.text,VF(h.start,s)?i:void 0)},w)})})})},WF=({lines:e,cues:t=[],verticalAnchor:n=.76,fontSizePx:r=64,activeColor:o="#FFE14D",ctaKeyword:i,ctaWindow:s,sourceTextRegions:a=[]})=>{const{fps:l,width:u,height:d}=Xe(),p={width:u,height:d},m=[];let h=0;for(const w of e)m.push(h),h+=w.words.length;return f.jsx(an,{children:e.map((w,v)=>{const E=t.length>0?nr(t,w.start):null,g=(E==null?void 0:E.captionY)!==void 0?E.captionY:t.length>0||a.length>0?DF((E==null?void 0:E.layout)??"full-bleed",LF(a,w.start,w.end),E==null?void 0:E.graphicRect,p):n,y=Math.round(w.start*l),x=Math.max(1,Math.round((w.end-w.start)*l));return f.jsx(at,{from:y,durationInFrames:x,children:f.jsx(BF,{line:w,wordOffset:m[v],verticalAnchor:g,fontSizePx:r*((E==null?void 0:E.captionScale)??1),activeColor:o,ctaKeyword:i,ctaWindow:s})},v)})})};function UF(e,t,n,r=.5,o=.5){const i=Math.max(1,e.width),s=Math.max(1,e.height),a=Math.max(1,t.w),l=Math.max(1,t.h),u=Math.max(n.width/a,n.height/l),d=-t.x*u+(n.width-a*u)*Ih(r),p=-t.y*u+(n.height-l*u)*Ih(o);return{width:i*u,height:s*u,left:d,top:p}}function Ih(e){return Number.isFinite(e)?Math.min(1,Math.max(0,e)):.5}function $w(e,t,n){const r=Math.max(1,e.width),o=Math.max(1,e.height),i=Math.max(1,t.w),s=Math.max(1,t.h),a=Math.min(n.width/i,n.height/s),l=-t.x*a+(n.width-i*a)/2,u=-t.y*a+(n.height-s*a)/2;return{width:r*a,height:o*a,left:l,top:u}}function HF(e,t){return $w(e,{x:0,y:0,w:e.width,h:e.height},t)}function ZF(e,t){if(e.length===0)return t;for(const o of e)if(t>=o.outIn&&t<o.outOut)return o.srcIn+(t-o.outIn);const n=e[0];return t<n.outIn?n.srcIn:e[e.length-1].srcOut}function YF(e,t,n,r,o,i){return e==="fit"?$w(t,n,r):UF(t,n,r,o,i)}function KF(e,t,n,r){return e.length===0?{x:0,y:0,w:r.width,h:r.height,full:!0}:xF(e,ZF(t,n),r)}const XF=({cues:e,theme:t,face:n,zoomPlan:r,sourceTextRegions:o,contentTimeline:i,spans:s,sourceSize:a,contentCropMode:l="cover",sourceFit:u="cover",children:d})=>{const p=ht(),{fps:m,width:h,height:w}=Xe(),v=p/m,g=AF(e,v,n??void 0,o??[],{width:h,height:w}),y=NF(e,v),x=g.rect.w*h,b=g.rect.h*w,k=g.cornerRadius*Math.min(x,b)/2,S=nr(e,v),C=S==null?void 0:S.video,I=r&&r.length>0?wF(r,v):1,F=Math.max(0,g.opacity*(1-.6*g.cornerRadius)),j=(C==null?void 0:C.autoZoom)!==!1,P=u==="contain"&&a!==void 0,A=j&&!P?1+(I-1)*F:1,V=(C==null?void 0:C.scale)??1,_=(C==null?void 0:C.dx)??0,L=(C==null?void 0:C.dy)??0,O=[_!==0||L!==0?`translate(${_}px, ${L}px)`:"",A*V!==1?`scale(${A*V})`:""].filter(Boolean).join(" ")||void 0;return f.jsxs(an,{children:[f.jsx(an,{style:{background:t.bg,opacity:y}}),f.jsxs("div",{"data-edit-video":S==null?void 0:S.id,style:{position:"absolute",left:`${g.rect.x*100}%`,top:`${g.rect.y*100}%`,width:x,height:b,borderRadius:k,overflow:"hidden",opacity:g.opacity,backgroundColor:P?t.bg:void 0,boxShadow:g.cornerRadius>.5?"0 18px 60px rgba(0,0,0,0.55)":void 0},children:[f.jsx("div",{style:{position:"absolute",inset:0,filter:g.blurPx>.5?`blur(${g.blurPx}px)`:void 0,transform:O,transformOrigin:"50% 40%","--ossclip-obj-y":`${g.objectPosY*100}%`,"--ossclip-obj-x":`${g.objectPosX*100}%`},children:P?f.jsx(GF,{source:a,slot:{width:x,height:b},children:d}):f.jsx(qF,{timeline:i,spans:s,sourceSize:a,mode:l,tSec:v,slot:{width:x,height:b},posX:g.objectPosX,posY:g.objectPosY,children:d})}),f.jsx("div",{style:{position:"absolute",inset:0,background:"black",opacity:g.dim}})]})]})},GF=({source:e,slot:t,children:n})=>{const r=HF(e,t);return f.jsx("div",{style:{position:"absolute",width:r.width,height:r.height,left:r.left,top:r.top},children:n})},qF=({timeline:e,spans:t,sourceSize:n,mode:r,tSec:o,slot:i,posX:s,posY:a,children:l})=>{const u=f.jsx("div",{style:{position:"absolute",inset:0},children:l});if(!e||e.length<2||!n)return u;const d=KF(e,t??[],o,n);if(d.full)return u;const p=YF(r,n,d,i,s,a);return f.jsx("div",{style:{position:"absolute",width:p.width,height:p.height,left:p.left,top:p.top},children:l})},Kf=.94,QF=new Set(["FlowDiagram","StrikethroughReveal","ChatMock","BulletList"]),Th=2.4,qs=.45,Xl=.58,vt=.72,JF=.62;function Qr(e,t,n,r,o){const i=Math.max(1,Math.floor(n/Math.max(1,o*t)));return Math.max(1,Math.ceil(e/i))*t*r}const Me=e=>typeof e=="string"?e:"",Hn=e=>Array.isArray(e)?e:[];function e4(e,t,n,r=1/0){switch(e){case"TitleCard":{const o=n-80,i=Me(t.emphasis),s=28;let a=0,l=0;Me(t.eyebrow)&&(a+=34*1.2,l++),i&&(a+=210*.95,l++);const u=i?64:96;return a+=Qr(Me(t.title).length,u,o,1.05,vt),l++,Me(t.sub)&&(a+=Qr(Me(t.sub).length,40,o,1.2,Xl),l++),a+s*Math.max(0,l-1)}case"StatCard":{const o=Qr(Me(t.label).length,42,n*.55,1.15,vt);let i=88+Math.max(o,110*1.15)+4;return Me(t.caption)&&(i+=30+(38*1.2+32+4)),i}case"RuleCard":{const o=n-60-96;let i=80;return i+=30*1.2+14,i+=Qr(Me(t.text).length,72,o,1.02,vt),Me(t.struck)&&(i+=26+Qr(Me(t.struck).length,44,o,1.2,vt)),i}case"StrikethroughReveal":{const o=Hn(t.lines).map(a=>Me(a==null?void 0:a.text)),i=Dw(o,n,r),s=o.reduce((a,l)=>a+zw(l,i,n).length,0);return s*i*1.08+i*.2*Math.max(0,s-1)}case"FlowDiagram":{const o=Hn(t.nodes).map(l=>Me(l)),i=Math.max(1,o.length),{mode:s,fontSize:a}=Zw(o,n,r);return s==="row"?a*_i+4:a*(_i*i+Hw*(i-1))}case"TerminalMock":{const o=Hn(t.windows);let i=0;for(const s of o){const a=Hn(s==null?void 0:s.lines);i+=56.8+2,i+=Math.max(1,a.length)*27*1.2+8*Math.max(0,a.length-1)+36,i+=4}return i+=22*Math.max(0,o.length-1),Me(t.fanOut)&&(i+=22+40*1.2),i}case"ChatMock":{const o=Ww(t).map(s=>s.text),i=Uw(o,{widthPx:n,heightPx:r});return Bw(o,i,n)}case"ScreenshotFrame":{const o=n*.94;return(Me(t.src)?o*9/16:480)+4}case"BulletList":{const o=Hn(t.items).map(s=>Me(s)),i=Lw(o,n,r,!!Me(t.title));return o4(o.length,i,!!Me(t.title))}}}const Dn=e=>Me(e).split(/\s+/).reduce((t,n)=>Math.max(t,n.length),0);function t4(e,t){switch(e){case"RuleCard":{const n=Dn(t.kicker)*30*(vt+.28),r=Dn(t.text)*72*vt,o=Dn(t.struck)*44*(vt+.04),i=Math.max(n,r,o);return i>0?156+i:0}case"TitleCard":{const n=Me(t.emphasis)?64:96,r=Dn(t.eyebrow)*34*(vt+.35),o=Dn(t.emphasis)*210*vt,i=Dn(t.title)*n*(vt+.02),s=Dn(t.sub)*40*Xl,a=Math.max(r,o,i,s);return a>0?80+a:0}case"TerminalMock":{let n=0;for(const r of Hn(t.windows))for(const o of Hn(r==null?void 0:r.lines))n=Math.max(n,Me(o).length);return n>0?108+n*27*JF:0}case"StatCard":{const n=Me(t.value).length*110*vt;return n===0?0:164+Dn(t.label)*42*vt+40+n}default:return 0}}const _h=36,n4=120,Aw=1.6,Nw=1.1,r4=1.1;function o4(e,t,n){return(Math.max(1,e)*Aw+(n?Nw:0))*t}function Lw(e,t=831,n=1/0,r=!1){const o=e.reduce((a,l)=>Math.max(a,l.length),0);if(o===0)return _h;const i=t/(o*vt+r4),s=n*Kf/(Math.max(1,e.length)*Aw+(r?Nw:0));return Math.max(_h,Math.min(n4,Math.floor(Math.min(i,s))))}const i4=92,s4=44,a4=150,l4=[" → "," -> "," → "," > "];function zw(e,t,n){const r=o=>o.length*t*vt<=n;if(r(e))return[e];for(const o of l4){if(!e.includes(o))continue;const s=e.split(o).map((a,l)=>l===0?a:`${o.trim()} ${a}`.trim());if(s.every(r))return s}return[e]}function Dw(e,t=831,n=1/0){const r=e.reduce((s,a)=>Math.max(s,a.length),0);if(r===0)return i4;const o=t/(r*vt),i=n/(Math.max(1,e.length)*1.28);return Math.max(s4,Math.min(a4,Math.floor(Math.min(o,i))))}const Rh=22,Ph=44,u4=96,Fh=22,Ow=.85,Vw=.82;function Bw(e,t,n){const o=(n-80)*Vw-2*t*Ow;let i=0;for(const s of e)i+=Qr(s.length,t,o,1.2,Xl)+t*1.2+4;return i+t*.5*Math.max(0,e.length-1)}function Ww(e){const t=Me(e.keyword);return t?[{from:"user",text:`"${t.toUpperCase()}"`}]:Hn(e.messages).map(n=>{const r=n??{};return{from:r.from==="agent"?"agent":"user",text:Me(r.text)}})}function Uw(e,t={}){const n=t.widthPx??831,r=t.heightPx??1/0,o=n-80,i=e.reduce((p,m)=>Math.max(p,m.length),0);if(i===0)return Ph;const s=e.flatMap(p=>p.split(/\s+/)).reduce((p,m)=>Math.max(p,m.length),0),a=p=>o*Vw/(p*Xl+2*Ow),l=Math.min(i,Fh),u=i>Fh?Ph:u4;let d=Math.floor(Math.min(a(l),a(s),u));for(;d>Rh&&Bw(e,d,n)>r*Kf;)d-=1;return Math.max(Rh,d)}const Mh=26,c4=22,d4=76,_i=2.1,Hw=2.05;function Zw(e,t,n=1/0){const r=e.reduce((v,E)=>v+E.length,0),o=Math.max(1,e.length),i=.78,s=1.6,a=1.8,l=t-20,u=Math.floor(Math.min(l/(i*r+s*o+a*(o-1)),n/_i)),d=Math.max(...e.map(v=>v.length),1),p=_i*o+Hw*(o-1),m=Math.floor(Math.min(l/(i*d+s),n/p,d4)),h=u>=Mh;return m>=c4?h?u*_i>=m*p?{mode:"row",fontSize:u}:{mode:"stack",fontSize:m}:{mode:"stack",fontSize:m}:{mode:"row",fontSize:Math.max(Mh,u)}}function f4(e,t,n){if(QF.has(e))return 1;const r=n.heightPx*Kf,o=u=>e4(e,t,n.widthPx/u)*u<=r;if(!o(qs))return qs;const i=t4(e,t),s=i>0?n.widthPx/i:Th;let a=qs,l=Math.max(qs,Math.min(Th,s));if(l<=a)return a;for(let u=0;u<24;u++){const d=(a+l)/2;o(d)?a=d:l=d}return a}function tt(e=0){const t=ht(),{fps:n}=Xe();return Qc({frame:t-e,fps:n,config:{damping:200,stiffness:130},durationInFrames:Math.round(n*.5)})}function hn(e,t=26){return{opacity:e,transform:`translateY(${(1-e)*t}px)`}}function $r(e){return{opacity:e,transform:`scale(${.9+.1*e})`}}function p4(e,t){return!e||t===1?e:Object.fromEntries(Object.entries(e).map(([n,r])=>[n,{...r,...r.dx!==void 0?{dx:r.dx/t}:{},...r.dy!==void 0?{dy:r.dy/t}:{}}]))}function Ye(e,t){const n=e==null?void 0:e[t];if(!n)return{};const r=[`translate(${n.dx??0}px, ${n.dy??0}px)`];return n.scale!==void 0&&n.scale!==1&&r.push(`scale(${n.scale})`),{transform:r.join(" ")}}const m4=({props:e,theme:t,edits:n})=>{var l;const r=tt(0),o=tt(5),i=tt(10),s=(l=e.emphasis)==null?void 0:l.trim(),a=!!s&&s.toLowerCase().includes(e.title.trim().toLowerCase());return f.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:28,textAlign:"center",fontFamily:t.fontDisplay,color:t.fg,padding:"0 40px"},children:[e.eyebrow?f.jsx("div",{"data-edit-id":"eyebrow",style:{...hn(r),fontSize:34,fontWeight:700,letterSpacing:"0.35em",color:t.muted,textTransform:"uppercase",...Ye(n,"eyebrow")},children:e.eyebrow}):null,s?f.jsx("div",{"data-edit-id":"emphasis",style:{...hn(o,40),fontSize:210,fontWeight:900,lineHeight:.95,...Ye(n,"emphasis")},children:s}):null,a?null:f.jsx("div",{"data-edit-id":"title",style:{...hn(s?i:o,34),fontSize:s?64:96,fontWeight:900,lineHeight:1.05,textTransform:"uppercase",letterSpacing:"0.02em",...Ye(n,"title")},children:e.title}),e.sub?f.jsx("div",{"data-edit-id":"sub",style:{...hn(i),fontSize:40,fontWeight:600,color:t.muted,...Ye(n,"sub")},children:e.sub}):null]})},h4=({props:e,theme:t,edits:n})=>{const r=tt(0),o=tt(6),i=e.inverted;return f.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:30,fontFamily:t.fontDisplay,width:"100%",padding:"0 30px"},children:[f.jsxs("div",{style:{...$r(r),display:"flex",alignItems:"center",justifyContent:"space-between",gap:40,width:"100%",background:i?t.fg:t.cardBg,color:i?t.bg:t.fg,border:`2px solid ${i?t.fg:t.cardBorder}`,borderRadius:t.radiusPx,padding:"44px 52px"},children:[f.jsx("div",{"data-edit-id":"label",style:{fontSize:42,fontWeight:800,textTransform:"uppercase",letterSpacing:"0.06em",lineHeight:1.15,maxWidth:"55%",...Ye(n,"label")},children:e.label}),f.jsx("div",{"data-edit-id":"value",style:{fontSize:110,fontWeight:900,whiteSpace:"nowrap",...Ye(n,"value")},children:e.value})]}),e.caption?f.jsx("div",{"data-edit-id":"caption",style:{...hn(o),fontSize:38,fontWeight:800,color:t.fg,background:t.cardBg,border:`2px solid ${t.cardBorder}`,borderRadius:t.radiusPx/2,padding:"16px 30px",textTransform:"uppercase",letterSpacing:"0.08em",...Ye(n,"caption")},children:e.caption}):null]})},g4=({props:e,theme:t,edits:n})=>{const r=tt(0),o=tt(8);return f.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:26,fontFamily:t.fontDisplay,width:"100%",padding:"0 30px"},children:[f.jsxs("div",{style:{...$r(r),width:"100%",background:t.fg,color:t.bg,borderRadius:t.radiusPx,padding:"40px 48px",textAlign:"left"},children:[f.jsx("div",{"data-edit-id":"kicker",style:{fontSize:30,fontWeight:800,letterSpacing:"0.28em",textTransform:"uppercase",color:"#55555E",marginBottom:14,fontFamily:t.fontMono,...Ye(n,"kicker")},children:e.kicker}),f.jsx("div",{"data-edit-id":"text",style:{fontSize:72,fontWeight:900,lineHeight:1.02,textTransform:"uppercase",...Ye(n,"text")},children:e.text})]}),e.struck?f.jsx("div",{"data-edit-id":"struck",style:{...hn(o),fontSize:44,fontWeight:800,color:t.muted,textDecoration:"line-through",textDecorationThickness:6,textDecorationColor:t.danger,textTransform:"uppercase",letterSpacing:"0.04em",...Ye(n,"struck")},children:e.struck}):null]})},v4=({text:e,struck:t,mark:n,delay:r,fontSize:o,theme:i,editId:s,edits:a})=>{const l=tt(r),u=tt(r+8);return f.jsxs("div",{"data-edit-id":s,style:{...hn(l,30),position:"relative",display:"inline-block",...Ye(a,s)},children:[f.jsxs("span",{style:{fontSize:o,fontWeight:900,textTransform:"uppercase",lineHeight:1.08,whiteSpace:"nowrap",color:t?i.muted:i.fg},children:[n!=="none"?f.jsx("span",{style:{color:n==="cross"?i.danger:i.success,marginRight:"0.3em"},children:n==="cross"?"✗":"✓"}):null,e]}),t?f.jsx("div",{style:{position:"absolute",left:"-2%",top:"50%",height:o*.11,width:`${u*104}%`,background:i.danger,borderRadius:o*.055,transform:"translateY(-50%) rotate(-2deg)"}}):null]})},y4=({props:e,theme:t,widthPx:n,heightPx:r,edits:o})=>{const i=e.lines.map(l=>(l.mark??"none")!=="none"?`✗ ${l.text}`:l.text),s=Dw(i,n,r),a=e.lines.flatMap((l,u)=>zw(l.text,s,n??831).map((d,p)=>({text:d,struck:l.struck,mark:p===0?l.mark??"none":"none",lineIndex:u})));return f.jsx("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:s*.2,textAlign:"center",fontFamily:t.fontDisplay},children:a.map((l,u)=>f.jsx(v4,{text:l.text,struck:l.struck,mark:l.mark,delay:u*6,fontSize:s,theme:t,editId:`line-${l.lineIndex}`,edits:o},u))})},w4=({text:e,emphasized:t,delay:n,fontSize:r,theme:o,editId:i,edits:s})=>{const a=tt(n);return f.jsx("div",{"data-edit-id":i,style:{...$r(a),background:t?o.fg:o.cardBg,color:t?o.bg:o.fg,border:`2px solid ${t?o.fg:o.cardBorder}`,borderRadius:o.radiusPx/2,padding:`${r*.55}px ${r*.8}px`,fontSize:r,fontWeight:900,textTransform:"uppercase",letterSpacing:"0.04em",whiteSpace:"nowrap",fontFamily:o.fontDisplay,...Ye(s,i)},children:e})},x4=({delay:e,fontSize:t,theme:n,down:r=!1})=>{const o=tt(e);return f.jsx("div",{style:{opacity:o,color:n.muted,fontSize:t*1.15,fontWeight:700,lineHeight:1,paddingLeft:r?0:t*.55},children:r?"↓":"→"})};function b4(e,t=S4,n){return Zw(e,t,n)}const S4=864,E4=({props:e,theme:t,widthPx:n,heightPx:r,edits:o})=>{const{mode:i,fontSize:s}=b4(e.nodes,n,r),a=i==="row";return f.jsx("div",{style:{display:"flex",flexDirection:a?"row":"column",flexWrap:"nowrap",alignItems:"center",justifyContent:"center",gap:a?0:s*.45,padding:"0 10px"},children:e.nodes.map((l,u)=>f.jsxs("div",{style:{display:"flex",flexDirection:a?"row":"column",alignItems:"center",gap:a?s*.55:s*.45},children:[u>0?f.jsx(x4,{delay:u*6+3,fontSize:s,theme:t,down:!a}):null,f.jsx(w4,{text:l,emphasized:e.emphasizeLast&&u===e.nodes.length-1,delay:u*6,fontSize:s,theme:t,editId:`node-${u}`,edits:o})]},u))})},k4=({title:e,lines:t,delay:n,theme:r,editId:o,edits:i})=>{const s=tt(n);return f.jsxs("div",{"data-edit-id":o,style:{...$r(s),background:r.cardBg,border:`2px solid ${r.cardBorder}`,borderRadius:r.radiusPx/2,overflow:"hidden",width:"100%",fontFamily:r.fontMono,...Ye(i,o)},children:[f.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,padding:"14px 20px",borderBottom:`2px solid ${r.cardBorder}`},children:[["#FF5F57","#FEBC2E","#28C840"].map(a=>f.jsx("div",{style:{width:16,height:16,borderRadius:8,background:a}},a)),f.jsx("div",{style:{marginLeft:10,fontSize:24,color:r.muted},children:e})]}),f.jsx("div",{style:{padding:"18px 22px",display:"flex",flexDirection:"column",gap:8},children:t.map((a,l)=>f.jsx("div",{style:{fontSize:27,color:r.fg,whiteSpace:"pre"},children:a},l))})]})},C4=({props:e,theme:t,edits:n})=>{const r=tt(e.windows.length*6+4);return f.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:22,width:"100%",padding:"0 30px"},children:[e.windows.map((o,i)=>f.jsx(k4,{title:o.title,lines:o.lines,delay:i*6,theme:t,editId:`window-${i}`,edits:n},i)),e.fanOut?f.jsxs("div",{"data-edit-id":"fanOut",style:{...hn(r),fontFamily:t.fontDisplay,fontSize:40,fontWeight:900,letterSpacing:"0.2em",color:t.fg,textTransform:"uppercase",...Ye(n,"fanOut")},children:["⌄ ",e.fanOut]}):null]})},I4=({from:e,text:t,delay:n,fontSize:r,theme:o,editId:i,edits:s})=>{const a=tt(n),l=e==="user";return f.jsx("div",{"data-edit-id":i,style:{...$r(a),alignSelf:l?"flex-end":"flex-start",background:l?o.fg:o.cardBg,color:l?o.bg:o.fg,border:`2px solid ${l?o.fg:o.cardBorder}`,borderRadius:28,[l?"borderBottomRightRadius":"borderBottomLeftRadius"]:8,padding:`${r*.6}px ${r*.85}px`,fontSize:r,fontWeight:700,maxWidth:"82%",fontFamily:o.fontDisplay,...Ye(s,i)},children:t})},T4=({props:e,theme:t,widthPx:n,heightPx:r,edits:o})=>{const i=Ww(e),s=Uw(i.map(a=>a.text),{widthPx:n,heightPx:r});return f.jsx("div",{style:{display:"flex",flexDirection:"column",gap:s*.5,width:"100%",padding:"0 40px"},children:i.map((a,l)=>f.jsx(I4,{from:a.from,text:a.text,delay:l*8,fontSize:s,theme:t,editId:`message-${l}`,edits:o},l))})},_4=({props:e,theme:t,edits:n})=>{const r=tt(0),o=tt(8),i=ht(),{fps:s}=Xe(),a=e.kenBurns?Bo(i,[0,s*8],[1,1.08],{extrapolateRight:"clamp"}):1,l=e.src?/^https?:\/\//.test(e.src)?e.src:K0(e.src):null;return f.jsxs("div",{"data-edit-id":"image",style:{...$r(r),position:"relative",width:"94%",...Ye(n,"image")},children:[f.jsx("div",{style:{overflow:"hidden",borderRadius:t.radiusPx/2,border:`2px solid ${t.cardBorder}`,background:t.cardBg,boxShadow:"0 24px 80px rgba(0,0,0,0.5)"},children:l?f.jsx(jf,{src:l,style:{width:"100%",display:"block",transform:`scale(${a})`}}):f.jsx("div",{style:{height:420,display:"flex",flexDirection:"column",gap:14,padding:30,transform:`scale(${a})`},children:[.9,.75,.85,.6,.8,.5].map((u,d)=>f.jsx("div",{style:{height:22,width:`${u*100}%`,borderRadius:6,background:d%3===0?t.cardBorder:"#22222B"}},d))})}),e.label?f.jsx("div",{"data-edit-id":"label",style:{...$r(o),position:"absolute",right:-8,bottom:-20,background:t.fg,color:t.bg,fontFamily:t.fontMono,fontSize:28,fontWeight:800,letterSpacing:"0.08em",padding:"12px 22px",borderRadius:10,textTransform:"uppercase",...Ye(n,"label")},children:e.label}):null]})},R4=({text:e,index:t,fontSize:n,theme:r,edits:o})=>{const i=`item-${t}`,s=tt(t*7);return f.jsxs("div",{"data-edit-id":i,style:{...hn(s,26),display:"flex",alignItems:"baseline",gap:n*.35,...Ye(o,i)},children:[f.jsx("span",{style:{fontSize:n*.75,color:r.accent,fontWeight:900},children:"▸"}),f.jsx("span",{style:{fontSize:n,fontWeight:900,textTransform:"uppercase",lineHeight:1.15,whiteSpace:"nowrap",color:r.fg},children:e})]})},P4=({props:e,theme:t,widthPx:n,heightPx:r,edits:o})=>{const i=Lw(e.items,n,r,!!e.title),s=tt(0);return f.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"flex-start",gap:i*.45,fontFamily:t.fontDisplay},children:[e.title?f.jsx("div",{"data-edit-id":"title",style:{...hn(s,20),fontSize:i*.36,fontWeight:700,letterSpacing:"0.28em",textTransform:"uppercase",color:t.muted,...Ye(o,"title")},children:e.title}):null,e.items.map((a,l)=>f.jsx(R4,{text:a,index:l,fontSize:i,theme:t,edits:o},l))]})},F4={TitleCard:m4,StatCard:h4,RuleCard:g4,StrikethroughReveal:y4,FlowDiagram:E4,TerminalMock:C4,ChatMock:T4,ScreenshotFrame:_4,BulletList:P4},M4=.3,j4=new Set(["lower-third","full-bleed"]),$4=.55,A4=e=>{const t=/^#([0-9a-fA-F]{6})$/.exec(e.trim()),[n,r,o]=t?[0,2,4].map(i=>Number.parseInt(t[1].slice(i,i+2),16)):[0,0,0];return`rgba(${n}, ${r}, ${o}, ${$4})`},N4=({durationInFrames:e,children:t})=>{const n=ht(),{fps:r}=Xe(),o=(e-n)/r,i=Math.min(1,Math.max(0,o/M4)),s=i*(2-i);return f.jsx("div",{style:{width:"100%",height:"100%",display:"flex",alignItems:"center",justifyContent:"center",opacity:s,transform:s<1?`translateY(${(1-s)*18}px)`:void 0},children:t})},L4=({cues:e,theme:t})=>{const{fps:n,width:r,height:o}=Xe();return f.jsx(an,{style:{pointerEvents:"none"},children:e.map(i=>{if(i.kind==="plain"||!i.component||!i.props)return null;const s=Fw(i,{width:r,height:o}),a=F4[i.component],l=Math.round(i.startSec*n),u=Math.max(1,Math.round((i.endSec-i.startSec)*n)),d=s.w*r,p=s.h*o,m=j4.has(i.layout),h=m?Math.min(24,Math.round(p*.12)):0,w=d-h*2,v=p-h*2,E=f4(i.component,i.props,{widthPx:w,heightPx:v});return f.jsx(at,{from:l,durationInFrames:u,children:f.jsx("div",{"data-edit-scene":i.id,style:{position:"absolute",left:`${s.x*100}%`,top:`${s.y*100}%`,width:`${s.w*100}%`,height:`${s.h*100}%`,display:"flex",alignItems:"center",justifyContent:"center",pointerEvents:"auto",overflow:"hidden"},children:f.jsxs(N4,{durationInFrames:u,children:[m?f.jsx("div",{style:{position:"absolute",inset:0,background:A4(t.bg),backdropFilter:"blur(14px)",WebkitBackdropFilter:"blur(14px)",borderRadius:t.radiusPx}}):null,f.jsx("div",{style:{width:w/E,transform:`scale(${E})`,position:"relative"},children:f.jsx(a,{props:i.props,theme:t,widthPx:w/E,heightPx:v/E,edits:p4(i.elements,E)})})]})})},i.id)})})},z4=({videoFileName:e,spans:t,captionLines:n,sceneCues:r,theme:o,face:i,zoomPlan:s,ctaKeyword:a,ctaWindow:l,sourceTextRegions:u,contentTimeline:d,sourceSize:p,contentCropMode:m,sourceFit:h})=>{if(!e)return f.jsx(an,{style:{backgroundColor:"#111",color:"#888",alignItems:"center",justifyContent:"center",fontFamily:"monospace",fontSize:40},children:"no production loaded"});const w=/^https?:\/\//.test(e)?e:K0(e);return f.jsxs(an,{style:{backgroundColor:"black"},children:[f.jsx(XF,{cues:r,theme:o,face:i,zoomPlan:s,sourceTextRegions:u,contentTimeline:d,spans:t,sourceSize:p,contentCropMode:m,sourceFit:h,children:f.jsx(KI,{src:w,spans:t,...h==="contain"?{punchInScale:1,background:"transparent"}:{}})}),f.jsx(L4,{cues:r,theme:o}),f.jsx(WF,{lines:n,cues:r,activeColor:o.accent,ctaKeyword:a,ctaWindow:l,sourceTextRegions:u})]})},D4=600,O4=()=>({doc:iF(),past:[],future:[],dirty:!1,savedAt:0,lastCoalesce:null}),cn=(e,t)=>e.scenes[t]??{props:{},elements:{}};function V4(e,t){const n=(r,o)=>{const i=Date.now(),s=o!==void 0&&e.lastCoalesce!==null&&e.lastCoalesce.key===o&&i-e.lastCoalesce.at<D4;return{doc:r,past:s?e.past:[...e.past,e.doc],future:[],dirty:!0,savedAt:e.savedAt,lastCoalesce:o!==void 0?{key:o,at:i}:null}};switch(t.type){case"load":return{doc:t.doc,past:[],future:[],dirty:!1,savedAt:0,lastCoalesce:null};case"patchProps":{const r=cn(e.doc,t.sceneId);return n({...e.doc,scenes:{...e.doc.scenes,[t.sceneId]:{...r,props:{...r.props,...t.patch}}}},t.coalesce)}case"patchElement":return n(dF(e.doc,t.sceneId,t.elementId,t.patch),t.coalesce);case"clearElement":return n(fF(e.doc,t.sceneId,t.elementId));case"patchTiming":{const r=cn(e.doc,t.sceneId);return n({...e.doc,scenes:{...e.doc.scenes,[t.sceneId]:{...r,timing:{startSec:t.startSec,endSec:t.endSec}}}})}case"clearTiming":return n(pF(e.doc,t.sceneId));case"patchVideo":{const r=cn(e.doc,t.sceneId);return n({...e.doc,scenes:{...e.doc.scenes,[t.sceneId]:{...r,video:{...r.video,...t.patch}}}},t.coalesce)}case"clearVideo":{const r=e.doc.scenes[t.sceneId];if(!(r!=null&&r.video))return e;const{video:o,...i}=r;return n({...e.doc,scenes:{...e.doc.scenes,[t.sceneId]:i}})}case"patchPip":{const r=cn(e.doc,t.sceneId);return n({...e.doc,scenes:{...e.doc.scenes,[t.sceneId]:{...r,pip:{...r.pip,...t.patch}}}},t.coalesce)}case"clearPip":{const r=e.doc.scenes[t.sceneId];if(!(r!=null&&r.pip))return e;const{pip:o,...i}=r;return n({...e.doc,scenes:{...e.doc.scenes,[t.sceneId]:i}})}case"patchCaptionY":{const r=cn(e.doc,t.sceneId);return n({...e.doc,scenes:{...e.doc.scenes,[t.sceneId]:{...r,captionY:t.y}}},t.coalesce)}case"patchCaptionScale":{const r=cn(e.doc,t.sceneId);return n({...e.doc,scenes:{...e.doc.scenes,[t.sceneId]:{...r,captionScale:t.scale}}},t.coalesce)}case"clearCaptionStyle":{const r=e.doc.scenes[t.sceneId];if((r==null?void 0:r.captionY)===void 0&&(r==null?void 0:r.captionScale)===void 0)return e;const{captionY:o,captionScale:i,...s}=r;return n({...e.doc,scenes:{...e.doc.scenes,[t.sceneId]:s}})}case"patchCaptionStyleAll":{const r={...e.doc.scenes};for(const o of t.sceneIds){const i=r[o]??{props:{},elements:{}};r[o]={...i,...t.y!==void 0?{captionY:t.y}:{},...t.scale!==void 0?{captionScale:t.scale}:{}}}return n({...e.doc,scenes:r})}case"addSplit":return e.doc.splits.some(r=>Math.abs(r-t.t)<.001)?e:n({...e.doc,splits:[...e.doc.splits,t.t].sort((r,o)=>r-o)});case"hideScene":{const r=cn(e.doc,t.sceneId);return n({...e.doc,scenes:{...e.doc.scenes,[t.sceneId]:{...r,hidden:!0}}})}case"restoreScene":{const r=e.doc.scenes[t.sceneId];if(!(r!=null&&r.hidden))return e;const{hidden:o,...i}=r;return n({...e.doc,scenes:{...e.doc.scenes,[t.sceneId]:i}})}case"patchComponent":{const r=cn(e.doc,t.sceneId);return n({...e.doc,scenes:{...e.doc.scenes,[t.sceneId]:{...r,component:t.component}}})}case"patchLayout":{const{graphicRect:r,...o}=cn(e.doc,t.sceneId);return n({...e.doc,scenes:{...e.doc.scenes,[t.sceneId]:{...o,layout:t.layout}}})}case"patchGraphicRect":{const r=cn(e.doc,t.sceneId);return n({...e.doc,scenes:{...e.doc.scenes,[t.sceneId]:{...r,graphicRect:t.rect}}},t.coalesce)}case"clearGraphicRect":return n(mF(e.doc,t.sceneId));case"patchCaption":{const r=String(t.index),o=rF(e.doc.captions,t.index,t.was);if(t.text===o){const{[r]:i,...s}=e.doc.captions;return n({...e.doc,captions:s})}return n({...e.doc,captions:{...e.doc.captions,[r]:{text:t.text,was:o}}})}case"patchTheme":return n({...e.doc,theme:{...e.doc.theme,...t.patch}});case"undo":{if(e.past.length===0)return e;const r=e.past[e.past.length-1],o=e.past.slice(0,-1);return{doc:r,past:o,future:[...e.future,e.doc],savedAt:e.savedAt,dirty:o.length!==e.savedAt,lastCoalesce:null}}case"redo":{if(e.future.length===0)return e;const r=e.future[e.future.length-1],o=[...e.past,e.doc];return{doc:r,past:o,future:e.future.slice(0,-1),savedAt:e.savedAt,dirty:o.length!==e.savedAt,lastCoalesce:null}}case"saved":return{...e,dirty:!1,savedAt:e.past.length}}}function B4(){const[e,t]=c.useReducer(V4,void 0,O4),n=async()=>{const r=await fetch("/api/overrides",{method:"PUT",headers:{"content-type":"application/json"},body:JSON.stringify(e.doc)});if(!r.ok){const o=await r.json().catch(()=>({}));throw new Error(o.error??"save failed")}t({type:"saved"})};return{doc:e.doc,dirty:e.dirty,canUndo:e.past.length>0,canRedo:e.future.length>0,load:r=>t({type:"load",doc:r}),undo:()=>t({type:"undo"}),redo:()=>t({type:"redo"}),save:n,patchProps:(r,o,i)=>t({type:"patchProps",sceneId:r,patch:o,coalesce:i}),patchElement:(r,o,i,s)=>t({type:"patchElement",sceneId:r,elementId:o,patch:i,coalesce:s}),clearElement:(r,o)=>t({type:"clearElement",sceneId:r,elementId:o}),patchTiming:(r,o,i)=>t({type:"patchTiming",sceneId:r,startSec:o,endSec:i}),clearTiming:r=>t({type:"clearTiming",sceneId:r}),patchVideo:(r,o,i)=>t({type:"patchVideo",sceneId:r,patch:o,coalesce:i}),clearVideo:r=>t({type:"clearVideo",sceneId:r}),patchPip:(r,o,i)=>t({type:"patchPip",sceneId:r,patch:o,coalesce:i}),clearPip:r=>t({type:"clearPip",sceneId:r}),patchCaptionY:(r,o,i)=>t({type:"patchCaptionY",sceneId:r,y:o,coalesce:i}),patchCaptionScale:(r,o,i)=>t({type:"patchCaptionScale",sceneId:r,scale:o,coalesce:i}),clearCaptionStyle:r=>t({type:"clearCaptionStyle",sceneId:r}),patchCaptionStyleAll:(r,o)=>t({type:"patchCaptionStyleAll",sceneIds:r,...o}),addSplit:r=>t({type:"addSplit",t:r}),hideScene:r=>t({type:"hideScene",sceneId:r}),restoreScene:r=>t({type:"restoreScene",sceneId:r}),patchGraphicRect:(r,o,i)=>t({type:"patchGraphicRect",sceneId:r,rect:o,coalesce:i}),clearGraphicRect:r=>t({type:"clearGraphicRect",sceneId:r}),patchComponent:(r,o)=>t({type:"patchComponent",sceneId:r,component:o}),patchLayout:(r,o)=>t({type:"patchLayout",sceneId:r,layout:o}),patchCaption:(r,o,i)=>t({type:"patchCaption",index:r,text:o,was:i}),patchTheme:r=>t({type:"patchTheme",patch:r})}}function jh(e){const t=e==null?void 0:e.closest("[data-edit-id]");if(!t)return null;const n=t.closest("[data-edit-scene]");return n?{sceneId:n.dataset.editScene,elementId:t.dataset.editId}:null}function $h(e){const t=e==null?void 0:e.closest("[data-edit-video]");return(t==null?void 0:t.dataset.editVideo)||null}function Ah(e,t,n){const r=e.querySelectorAll(`[data-edit-scene="${t}"] [data-edit-id="${n}"]`);if(r.length===0)return null;let o=1/0,i=1/0,s=-1/0,a=-1/0;return r.forEach(l=>{const u=l.getBoundingClientRect();o=Math.min(o,u.left),i=Math.min(i,u.top),s=Math.max(s,u.right),a=Math.max(a,u.bottom)}),new DOMRect(o,i,s-o,a-i)}function Nh(e,t,n,r){const o={...e};return t==="move"?(o.x+=n,o.y+=r,o):(t.includes("w")&&(o.x+=n,o.w-=n),t.includes("e")&&(o.w+=n),t.includes("n")&&(o.y+=r,o.h-=r),t.includes("s")&&(o.h+=r),o)}const Lh=64,Qs=9,Js=e=>Math.round(e*10)/10,qr=e=>Math.round(e*1e4)/1e4,Yw={position:"absolute",width:10,height:10,background:"#5b8cff",border:"1px solid #0B0B0E",borderRadius:2,pointerEvents:"auto",zIndex:6},zh={nw:{left:0,top:0,transform:"translate(-50%,-50%)",cursor:"nwse-resize"},n:{left:"50%",top:0,transform:"translate(-50%,-50%)",cursor:"ns-resize"},ne:{right:0,top:0,transform:"translate(50%,-50%)",cursor:"nesw-resize"},e:{right:0,top:"50%",transform:"translate(50%,-50%)",cursor:"ew-resize"},se:{right:0,bottom:0,transform:"translate(50%,50%)",cursor:"nwse-resize"},s:{left:"50%",bottom:0,transform:"translate(-50%,50%)",cursor:"ns-resize"},sw:{left:0,bottom:0,transform:"translate(-50%,50%)",cursor:"nesw-resize"},w:{left:0,top:"50%",transform:"translate(-50%,-50%)",cursor:"ew-resize"}},W4={...Yw,background:"#ffe14d"},U4={top:{top:0,left:14,right:14,height:10},bottom:{bottom:0,left:14,right:14,height:10},left:{left:0,top:14,bottom:14,width:10},right:{right:0,top:14,bottom:14,width:10}},H4={position:"absolute",cursor:"move",pointerEvents:"auto",zIndex:5},Kw=/^(line|node|message|window|item)-(\d+)$/;function Z4(e,t,n){const r=Kw.exec(e);if(!r||r[1]==="window")return null;const o=r[1],i=Number(r[2]);if(o==="message"&&i===0&&typeof t.keyword=="string"&&t.keyword){const d=n.trim().replace(/^"(.*)"$/,"$1").toLowerCase();return d?{keyword:d}:null}const s=o==="line"?"lines":o==="node"?"nodes":o==="item"?"items":"messages",a=t[s];if(!Array.isArray(a)||i<0||i>=a.length)return null;const l=a.slice(),u=l[i];if(o==="node"||o==="item")l[i]=n;else{if(typeof u!="object"||u===null)return null;l[i]={...u,text:n}}return{[s]:l}}function Y4(e,t){const n=Kw.exec(e);if(!n){const u=t[e];return typeof u=="string"?u:null}if(n[1]==="window")return null;const r=n[1],o=Number(n[2]);if(r==="message"&&o===0&&typeof t.keyword=="string"&&t.keyword)return t.keyword;const s=t[r==="line"?"lines":r==="node"?"nodes":r==="item"?"items":"messages"];if(!Array.isArray(s)||o<0||o>=s.length)return null;const a=s[o];if(r==="node"||r==="item")return typeof a=="string"?a:null;const l=a==null?void 0:a.text;return typeof l=="string"?l:null}const K4=({stageRef:e,selection:t,onSelect:n,edits:r,onSave:o,settings:i,playerRef:s,onTransport:a,onVideoPreview:l,onGraphicPreview:u,cue:d,cues:p,onToggleHelp:m})=>{const[h,w]=c.useState(null),v=c.useRef(null),E=c.useRef(0),g=c.useRef(null),y=c.useRef(0),x=c.useRef(null),b=c.useRef(0),[k,S]=c.useState(!1),C=c.useRef(null),[I,F]=c.useState(null),[j,P]=c.useState(null),A=c.useRef(null),[V,_]=c.useState({dx:0,dy:0}),L=c.useRef(null),O=c.useRef(t),N=c.useCallback(R=>{O.current=R,n(R)},[n]);c.useEffect(()=>{O.current=t},[t]);const T=(R,$)=>{const B=[];let W=null;for(let M=0;M<25;M++){const D=document.elementFromPoint(R,$);if(!D||D===document.documentElement||D===document.body){W=D;break}if(W=D,D.hasAttribute("data-edit-id")||D.hasAttribute("data-edit-scene")||D.hasAttribute("data-caption-word")||D.closest("[data-edit-video]")!==null||["BUTTON","INPUT","SELECT","TEXTAREA"].includes(D.tagName)||!(D instanceof HTMLElement))break;B.push({el:D,prev:D.style.pointerEvents}),D.style.pointerEvents="none"}return B.forEach(({el:M,prev:D})=>{M.style.pointerEvents=D}),W},z=c.useCallback(()=>{var D,K;const R=e.current,$=(D=s.current)==null?void 0:D.getScale(),B=((K=R==null?void 0:R.querySelector(".__remotion-player"))==null?void 0:K.getBoundingClientRect())??(R==null?void 0:R.getBoundingClientRect());if(!B||!$||$<=0)return null;const W=i.width*$,M=i.height*$;return{left:B.left+(B.width-W)/2,top:B.top+(B.height-M)/2,w:W,h:M}},[e,s,i]);return c.useEffect(()=>{if(!t){w(null);return}let R;const $=()=>{var W;const B=e.current;if(B){const M=t.elementId?Ah(B,t.sceneId,t.elementId):((W=B.querySelector(`[data-edit-scene="${t.sceneId}"]`))==null?void 0:W.getBoundingClientRect())??null;w(M)}R=requestAnimationFrame($)};return R=requestAnimationFrame($),()=>cancelAnimationFrame(R)},[e,t]),c.useEffect(()=>{const R=$=>{var M,D;const B=e.current;if(!B||!B.contains($.target)||$.altKey||$.button!==0)return;(((M=O.current)==null?void 0:M.elementId)&&((D=L.current)==null?void 0:D.contains($.target))||jh(T($.clientX,$.clientY))!==null)&&$.stopPropagation()};return window.addEventListener("pointerdown",R,!0),()=>window.removeEventListener("pointerdown",R,!0)},[e]),c.useEffect(()=>{const R=$=>{var ne,Z,ee,ae,me,ge,le;const B=e.current;if(!B||!B.contains($.target)||$.altKey||$.button!==0)return;const W=$.target instanceof Element?$.target.closest("[data-el-handle]"):null,M=O.current;if(W&&(M!=null&&M.elementId)){const q=Ah(B,M.sceneId,M.elementId);if(q){const de=q.left+q.width/2,ye=q.top+q.height/2,Fe=Math.hypot($.clientX-de,$.clientY-ye);if(Fe>2){const se=((Z=(ne=r.doc.scenes[M.sceneId])==null?void 0:ne.elements[M.elementId])==null?void 0:Z.scale)??1;C.current={sceneId:M.sceneId,elementId:M.elementId,cx:de,cy:ye,startDist:Fe,prior:se,factor:1},F(1)}}return}if((ee=O.current)!=null&&ee.elementId&&((ae=L.current)!=null&&ae.contains($.target))){A.current={x:$.clientX,y:$.clientY,dx:0,dy:0},_({dx:0,dy:0});return}const D=$.target instanceof Element?$.target.closest("[data-box-handle]"):null,K=O.current;if(D&&K&&!K.elementId){const q=B.querySelector(`[data-edit-scene="${K.sceneId}"]`),de=z();if(q&&de){const ye=q.getBoundingClientRect();x.current={sceneId:K.sceneId,handle:D.dataset.boxHandle,x:$.clientX,y:$.clientY,dx:0,dy:0,start:{x:(ye.left-de.left)/de.w,y:(ye.top-de.top)/de.h,w:ye.width/de.w,h:ye.height/de.h}},S(!0)}return}const G=T($.clientX,$.clientY),oe=jh(G);if(!oe){const q=G==null?void 0:G.closest("[data-edit-scene]");if(q){N({sceneId:q.dataset.editScene,elementId:null});return}const de=$h(G),ye=B.getBoundingClientRect().bottom;if(de&&$.clientY<ye-Lh){N({sceneId:de,elementId:null});const Fe=p.find(We=>We.id===de);if((Fe==null?void 0:Fe.layout)==="pip-bubble"&&!$.altKey){const We=jr("pip-bubble",void 0,[],i).video.rect;g.current={sceneId:de,x:$.clientX,y:$.clientY,base:{x:((me=Fe.pip)==null?void 0:me.x)??We.x,y:((ge=Fe.pip)==null?void 0:ge.y)??We.y},slot:{w:We.w,h:We.h}};return}const se=(le=r.doc.scenes[de])==null?void 0:le.video;v.current={sceneId:de,x:$.clientX,y:$.clientY,dx:0,dy:0,baseDx:(se==null?void 0:se.dx)??0,baseDy:(se==null?void 0:se.dy)??0};return}N(null);return}N({sceneId:oe.sceneId,elementId:oe.elementId}),A.current={x:$.clientX,y:$.clientY,dx:0,dy:0},_({dx:0,dy:0})};return window.addEventListener("mousedown",R),()=>window.removeEventListener("mousedown",R)},[e,N,r,z,p,i]),c.useEffect(()=>{const R=()=>{var D,K;const W=(D=s.current)==null?void 0:D.getScale(),M=(K=e.current)==null?void 0:K.getBoundingClientRect();return W&&W>0?1/W:M&&M.width>0?i.width/M.width:1},$=W=>{const M=e.current;if(M&&!(x.current||C.current))if(g.current)M.style.cursor="move";else if(v.current)M.style.cursor="grabbing";else{const Z=W.target instanceof Element?W.target:null,ee=Z!==null&&M.contains(Z)&&!Z.closest("button, input, select, textarea, [data-edit-id], [data-edit-scene], [data-caption-word]")&&W.clientY<M.getBoundingClientRect().bottom-Lh,ae=ee&&(()=>{var ge;const me=$h(Z);return me!==null&&((ge=p.find(le=>le.id===me))==null?void 0:ge.layout)==="pip-bubble"})();M.style.cursor=ee?ae?"move":"grab":""}const D=C.current;if(D){const ee=Math.hypot(W.clientX-D.cx,W.clientY-D.cy)/D.startDist;D.factor=Math.min(4/D.prior,Math.max(.05/D.prior,ee)),F(D.factor);return}const K=x.current;if(K){K.dx=W.clientX-K.x,K.dy=W.clientY-K.y,b.current||(b.current=requestAnimationFrame(()=>{b.current=0;const Z=x.current,ee=z();if(!Z||!ee)return;const ae=Ja(Nh(Z.start,Z.handle,Z.dx/ee.w,Z.dy/ee.h),i);u({sceneId:Z.sceneId,rect:ae})}));return}if(g.current){y.current||(y.current=requestAnimationFrame(()=>{y.current=0;const Z=g.current,ee=z();if(!Z||!ee)return;const ae=(W.clientX-Z.x)/ee.w,me=(W.clientY-Z.y)/ee.h;r.patchPip(Z.sceneId,{x:qr(Math.min(Math.max(Z.base.x+ae,0),1-Z.slot.w)),y:qr(Math.min(Math.max(Z.base.y+me,0),1-Z.slot.h))},`pip:${Z.sceneId}:drag`)}));return}const oe=v.current;if(oe){oe.dx=W.clientX-oe.x,oe.dy=W.clientY-oe.y,E.current||(E.current=requestAnimationFrame(()=>{E.current=0;const Z=v.current;if(!Z)return;const ee=R();l({sceneId:Z.sceneId,patch:{dx:Z.baseDx+Z.dx*ee,dy:Z.baseDy+Z.dy*ee}})}));return}const ne=A.current;ne&&(ne.dx=W.clientX-ne.x,ne.dy=W.clientY-ne.y,_({dx:ne.dx,dy:ne.dy}))},B=()=>{const W=C.current;if(W){C.current=null,F(null),Math.abs(W.factor-1)>.001&&r.patchElement(W.sceneId,W.elementId,{scale:Math.round(W.prior*W.factor*1e3)/1e3});return}const M=x.current;if(M){if(x.current=null,S(!1),b.current&&(cancelAnimationFrame(b.current),b.current=0),M.dx!==0||M.dy!==0){const ne=z();if(ne){const Z=Ja(Nh(M.start,M.handle,M.dx/ne.w,M.dy/ne.h),i);r.patchGraphicRect(M.sceneId,{x:qr(Z.x),y:qr(Z.y),w:qr(Z.w),h:qr(Z.h)})}}u(null);return}if(g.current){g.current=null,y.current&&(cancelAnimationFrame(y.current),y.current=0);return}const K=v.current;if(K){if(v.current=null,E.current&&(cancelAnimationFrame(E.current),E.current=0),K.dx!==0||K.dy!==0){const ne=R();r.patchVideo(K.sceneId,{dx:Js(K.baseDx+K.dx*ne),dy:Js(K.baseDy+K.dy*ne)})}l(null);return}const G=A.current,oe=O.current;if(!G||!(oe!=null&&oe.elementId)){A.current=null;return}if(G.dx!==0||G.dy!==0){const ne=R(),Z=r.doc.scenes[oe.sceneId],ee=Z==null?void 0:Z.elements[oe.elementId];r.patchElement(oe.sceneId,oe.elementId,{dx:Js(((ee==null?void 0:ee.dx)??0)+G.dx*ne),dy:Js(((ee==null?void 0:ee.dy)??0)+G.dy*ne)})}A.current=null,_({dx:0,dy:0})};return window.addEventListener("mousemove",$),window.addEventListener("mouseup",B),()=>{window.removeEventListener("mousemove",$),window.removeEventListener("mouseup",B)}},[r,e,i,s,l,u,z,p]),c.useEffect(()=>{const R=$=>{var K;const B=e.current;if(!B||!B.contains($.target))return;const W=(K=T($.clientX,$.clientY))==null?void 0:K.closest("[data-caption-word]");if(!W)return;$.preventDefault();const M=Number(W.dataset.captionWord),D=W.dataset.captionText??"";!Number.isFinite(M)||!D||P({index:M,was:D,draft:D,rect:W.getBoundingClientRect()})};return window.addEventListener("dblclick",R),()=>window.removeEventListener("dblclick",R)},[e]),c.useEffect(()=>{const R=()=>{const M=document.activeElement;return M instanceof HTMLInputElement||M instanceof HTMLTextAreaElement||M instanceof HTMLSelectElement||M instanceof HTMLElement&&M.isContentEditable},$=()=>{const M=document.activeElement;return M instanceof HTMLTextAreaElement||M instanceof HTMLElement&&M.isContentEditable?!0:M instanceof HTMLInputElement&&!["range","checkbox","radio","button"].includes(M.type)},B=()=>{const M=document.activeElement;M instanceof HTMLElement&&!$()&&M.blur()},W=M=>{var K,G,oe,ne;if(j!==null)return;const D=M.metaKey||M.ctrlKey;if(M.key==="Escape"){if(R()){(K=document.activeElement)==null||K.blur();return}N(null)}else if(D&&M.key.toLowerCase()==="z")M.preventDefault(),M.shiftKey?r.redo():r.undo();else if(D&&M.key.toLowerCase()==="y")M.preventDefault(),r.redo();else if(D&&M.key.toLowerCase()==="s")M.preventDefault(),o();else if(M.key===" "&&!D){if($())return;const Z=document.activeElement;if(Z instanceof HTMLElement&&Z.tagName==="BUTTON"&&((G=e.current)!=null&&G.contains(Z)))return;B(),M.preventDefault(),(oe=s.current)==null||oe.toggle()}else if(!D&&["j","k","l"].includes(M.key.toLowerCase())){if($())return;B(),M.preventDefault(),a(M.key.toUpperCase())}else if(!D&&!M.altKey&&(M.key==="ArrowLeft"||M.key==="ArrowRight")){if(R())return;M.preventDefault();const Z=s.current;if(!Z)return;Z.seekTo(Math.max(0,Z.getCurrentFrame()+(M.key==="ArrowRight"?1:-1)))}else if(D&&M.key.toLowerCase()==="b"){if($())return;M.preventDefault();const Z=s.current;if(!Z)return;const ee=Z.getCurrentFrame()/i.fps;if(!p.find(me=>ee>=me.startSec+Qa&&ee<=me.endSec-Qa))return;r.addSplit(Math.round(ee*1e3)/1e3)}else if(!D&&M.altKey&&(M.key==="ArrowLeft"||M.key==="ArrowRight")){if($())return;const Z=O.current,ee=Z?(()=>{const ae=p.findIndex(me=>me.id===Z.sceneId);return ae===-1?void 0:p[ae+(M.key==="ArrowRight"?1:-1)]})():p[M.key==="ArrowRight"?0:p.length-1];if(!ee)return;M.preventDefault(),N({sceneId:ee.id,elementId:null})}else if(D&&(M.key==="ArrowLeft"||M.key==="ArrowRight")){if($())return;M.preventDefault();const Z=s.current;if(!Z)return;const ee=Z.getCurrentFrame()/i.fps,ae=p.findIndex(ge=>ee>=ge.startSec&&ee<ge.endSec),me=p[(ae===-1?0:ae)+(M.key==="ArrowRight"?1:-1)];if(!me)return;Z.seekTo(Math.round(me.startSec*i.fps)),N({sceneId:me.id,elementId:null})}else if(!D&&!M.altKey&&M.key==="?"){if(R())return;M.preventDefault(),m()}else if(!D&&(M.key==="Delete"||M.key==="Backspace")){if(R())return;const Z=O.current;if(!Z||Z.elementId!==null||!d||d.kind==="plain"||d.id!==Z.sceneId||((ne=r.doc.scenes[Z.sceneId])==null?void 0:ne.hidden)===!0)return;M.preventDefault(),r.hideScene(Z.sceneId)}};return window.addEventListener("keydown",W),()=>window.removeEventListener("keydown",W)},[N,r,j,o,s,e,a,d,p,i,m]),f.jsxs("div",{style:{position:"absolute",inset:0,pointerEvents:"none"},children:[V.dx!==0||V.dy!==0||k?f.jsx("div",{"data-testid":"safe-area-guide",style:{position:"absolute",left:`${kr(i).left*100}%`,top:`${kr(i).top*100}%`,right:`${kr(i).right*100}%`,bottom:`${kr(i).bottom*100}%`,border:"1px dashed rgba(255, 225, 77, 0.45)",boxShadow:"0 0 0 9999px rgba(0, 0, 0, 0.18)",pointerEvents:"none"}}):null,h&&t?f.jsxs("div",{ref:L,"data-testid":"overlay-box",style:{position:"fixed",pointerEvents:"auto",left:h.left+V.dx-Qs/2+h.width*(1-(I??1))/2,top:h.top+V.dy-Qs/2+h.height*(1-(I??1))/2,width:h.width*(I??1)+Qs,height:h.height*(I??1)+Qs,border:t.elementId?"2px dashed #ffe14d":"2px dashed #5b8cff",borderRadius:4,boxShadow:"0 0 0 1px rgba(0,0,0,0.35)",cursor:t.elementId?"grab":"default"},children:[t.elementId?f.jsx("div",{style:{position:"absolute",bottom:"100%",left:0,marginBottom:4,fontSize:10,fontFamily:"ui-monospace, 'SF Mono', monospace",letterSpacing:"0.04em",textTransform:"uppercase",color:"#0B0B0E",background:"#ffe14d",padding:"2px 6px",borderRadius:3,whiteSpace:"nowrap"},children:t.elementId}):null,t.elementId?["nw","ne","se","sw"].map(R=>f.jsx("div",{"data-el-handle":R,"data-testid":`el-handle-${R}`,style:{...W4,...zh[R]}},R)):null,!t.elementId&&d&&d.kind!=="plain"?f.jsxs(f.Fragment,{children:[["top","bottom","left","right"].map(R=>f.jsx("div",{"data-box-handle":"move","data-testid":R==="top"?"box-handle-move":`box-handle-move-${R}`,style:{...H4,...U4[R]}},R)),["nw","n","ne","e","se","s","sw","w"].map(R=>f.jsx("div",{"data-box-handle":R,"data-testid":`box-handle-${R}`,style:{...Yw,...zh[R]}},R))]}):null]}):null,j?f.jsx("input",{autoFocus:!0,"data-testid":"caption-edit",value:j.draft,onChange:R=>P({...j,draft:R.target.value}),onBlur:()=>{const R=j.draft.trim();R&&r.patchCaption(j.index,R,j.was),P(null)},onKeyDown:R=>{R.key==="Enter"&&R.target.blur(),R.key==="Escape"&&P(null)},style:{position:"fixed",pointerEvents:"auto",left:j.rect.left-4,top:j.rect.top-4,width:Math.max(j.rect.width+40,90),height:j.rect.height+8,fontSize:Math.max(13,Math.min(j.rect.height*.7,28)),fontFamily:"'Inter', system-ui, sans-serif",fontWeight:800,border:"2px solid #FFE14D",borderRadius:4,padding:"0 4px",background:"#0B0B0E",color:"#fff",outline:"none",zIndex:11}}):null]})},Jt={display:"flex",flexDirection:"column",gap:6},di={display:"grid",gridTemplateColumns:"1fr 1fr",gap:8},De={fontSize:11,fontWeight:600,letterSpacing:"0.06em",textTransform:"uppercase",color:"#9A9AA3"},Ri={fontFamily:"ui-monospace, 'SF Mono', Consolas, monospace",fontSize:13,background:"#0F0F14",border:"1px solid #2A2A33",borderRadius:6,color:"#fff",padding:"6px 8px",width:"100%"},Xw={...Ri,fontFamily:"'Inter', system-ui, sans-serif"},qe={display:"flex",flexDirection:"column",gap:14,padding:"16px 18px",borderBottom:"1px solid #22222a"},Sn={fontSize:12,fontWeight:600,color:"#FF5C5C",background:"transparent",border:"1px solid #452626",borderRadius:6,padding:"7px 10px",cursor:"pointer"},X4=e=>String(Math.round(e*1e3)/1e3),Et=({id:e,value:t,onCommit:n,min:r,max:o,dragStep:i})=>{const[s,a]=J.useState(null),[l,u]=J.useState(!1),d=J.useRef(null),p=J.useRef(null),m=r??-1/0,h=o??1/0,w=i??(r!==void 0&&o!==void 0?(o-r)/240:.5),v=s!==null;return f.jsxs("div",{style:Jt,children:[f.jsx("span",{style:De,children:e}),f.jsx("input",{type:"text",inputMode:"decimal",ref:d,"data-testid":`field-${e}`,style:{...Ri,...v?{}:{cursor:"ew-resize",touchAction:"none"},...l?{borderColor:"#FFE14D",color:"#FFE14D"}:{}},value:s??(Number.isFinite(t)?X4(t):"0"),onFocus:E=>a(E.target.value),onBlur:()=>a(null),onPointerDown:E=>{v||(E.preventDefault(),p.current={x:E.clientX,v:Number.isFinite(t)?t:0,moved:!1},E.currentTarget.setPointerCapture(E.pointerId),u(!0))},onPointerMove:E=>{const g=p.current;if(!g)return;const y=E.clientX-g.x;if(!g.moved&&Math.abs(y)<=2)return;g.moved=!0;const x=Math.round(Math.min(h,Math.max(m,g.v+y*w))*1e3)/1e3;n(x)},onPointerUp:()=>{var g,y,x;const E=((g=p.current)==null?void 0:g.moved)===!0;p.current=null,u(!1),E||((y=d.current)==null||y.focus(),(x=d.current)==null||x.select())},onPointerCancel:()=>{p.current=null,u(!1)},onChange:E=>{a(E.target.value);const g=E.target.value.trim();if(g==="")return;const y=Number(g.replace(",","."));Number.isFinite(y)&&n(Math.min(h,Math.max(m,y)))}})]})},ea=({id:e,value:t,isColor:n,onCommit:r})=>f.jsxs("div",{style:Jt,children:[f.jsx("span",{style:De,children:e}),f.jsxs("div",{style:{display:"flex",gap:8,alignItems:"center"},children:[n?f.jsx("input",{type:"color",value:t,onChange:o=>r(o.target.value),style:{width:28,height:28,border:"1px solid #2A2A33",borderRadius:6,padding:0,background:"none"}}):null,f.jsx("input",{style:{...Xw,flex:1},value:t,onChange:o=>r(o.target.value)})]})]}),G4=({selection:e,cue:t,frame:n,allSceneIds:r,edits:o,resolvedTheme:i,anchorText:s,onVideoPreview:a,runInfo:l})=>{var v,E,g,y,x,b,k,S,C,I,F,j;if(e!=null&&e.elementId&&t){const P=e.elementId,A=((v=t.elements)==null?void 0:v[P])??{},V=t.props?Y4(P,t.props):null;return f.jsxs("div",{children:[f.jsxs("div",{style:qe,children:[f.jsx("span",{style:De,children:"Selected"}),f.jsx("div",{style:{fontSize:15,fontWeight:700,fontFamily:"ui-monospace, monospace"},children:P})]}),(()=>{var z;const _=/^line-(\d+)$/.exec(P),L=(z=t.props)==null?void 0:z.lines;if(t.component!=="StrikethroughReveal"||!_||!Array.isArray(L))return null;const O=Number(_[1]),N=L[O];if(!N)return null;const T=N.struck?"struck":(N.mark??"none")!=="none"?N.mark:"plain";return f.jsx("div",{style:qe,children:f.jsxs("div",{style:Jt,children:[f.jsx("span",{style:De,children:"Line style"}),f.jsxs("select",{"data-testid":"line-style",style:Ri,value:T,onChange:R=>{const $=R.target.value,B=L.slice();B[O]={...B[O],struck:$==="struck",mark:$==="cross"||$==="check"?$:"none"},o.patchProps(e.sceneId,{lines:B})},children:[f.jsx("option",{value:"plain",children:"plain"}),f.jsx("option",{value:"struck",children:"struck through"}),f.jsx("option",{value:"cross",children:"✗ wrong"}),f.jsx("option",{value:"check",children:"✓ right"})]})]})})})(),V!==null?f.jsx("div",{style:qe,children:f.jsxs("div",{style:Jt,children:[f.jsx("span",{style:De,children:"Text"}),f.jsx("input",{style:Xw,"data-testid":"element-text",value:V,onChange:_=>{const L=t.props??{},O=/^(line|node|message|window|item)-\d+$/.test(P)?Z4(P,L,_.target.value):{[P]:_.target.value};O&&o.patchProps(e.sceneId,O,`text:${e.sceneId}:${P}`)}})]})}):null,f.jsxs("div",{style:qe,children:[f.jsxs("div",{style:Jt,children:[f.jsxs("span",{style:De,children:["scale"," ",f.jsxs("span",{style:{color:"#EDEDF2"},children:[(A.scale??1).toFixed(2),"×"]})]}),f.jsx("input",{type:"range","data-testid":"el-scale-slider",min:.1,max:3,step:.01,value:A.scale??1,onChange:_=>o.patchElement(e.sceneId,P,{scale:Number(_.target.value)},`element:${e.sceneId}:${P}:scale`)})]}),f.jsxs("div",{style:di,children:[f.jsx(Et,{id:"x",value:A.dx??0,dragStep:1,onCommit:_=>o.patchElement(e.sceneId,P,{dx:_},`element:${e.sceneId}:${P}:dx`)}),f.jsx(Et,{id:"y",value:A.dy??0,dragStep:1,onCommit:_=>o.patchElement(e.sceneId,P,{dy:_},`element:${e.sceneId}:${P}:dy`)})]}),f.jsx(Et,{id:"scale",value:A.scale??1,min:.05,max:4,dragStep:.01,onCommit:_=>o.patchElement(e.sceneId,P,{scale:_},`element:${e.sceneId}:${P}:scale`)})]}),f.jsx("div",{style:qe,children:f.jsx("button",{style:Sn,onClick:()=>o.clearElement(e.sceneId,P),children:"Reset element"})})]})}if(e&&t){const P=t.kind==="plain";return((E=o.doc.scenes[e.sceneId])==null?void 0:E.hidden)===!0?f.jsx("div",{children:f.jsxs("div",{style:qe,children:[f.jsx("span",{style:De,children:"Scene"}),f.jsxs("div",{style:{fontSize:15,fontWeight:700,fontFamily:"ui-monospace, monospace"},children:[e.sceneId," ",f.jsx("span",{style:{color:"#9A9AA3",fontWeight:400},children:"(deleted)"})]}),f.jsx("div",{style:{fontSize:12,color:"#9A9AA3"},children:"Its window plays as a plain take. Restore brings the graphic back."}),f.jsx("button",{"data-testid":"restore-scene",style:{...Sn,color:"#5FBF77",border:"1px solid #24402c"},onClick:()=>o.restoreScene(e.sceneId),children:"Restore scene"})]})}):f.jsxs("div",{children:[f.jsxs("div",{style:qe,children:[f.jsx("span",{style:De,children:P?"Take":"Scene"}),f.jsx("div",{style:{fontSize:15,fontWeight:700,fontFamily:"ui-monospace, monospace"},children:e.sceneId}),P?f.jsx("div",{style:{fontSize:12,color:"#9A9AA3"},children:"A continuous stretch of the talking head — no graphic. Frame it below; its window follows the cut."}):null]}),f.jsxs("div",{style:qe,children:[!P&&t.component?f.jsxs("div",{style:Jt,children:[f.jsx("span",{style:De,children:"Component"}),f.jsx("select",{style:Ri,value:t.component,onChange:A=>o.patchComponent(e.sceneId,A.target.value),children:Kl.options.map(A=>f.jsx("option",{value:A,children:A},A))})]}):null,f.jsxs("div",{style:Jt,children:[f.jsx("span",{style:De,children:"Layout"}),f.jsx("select",{style:Ri,"data-testid":"layout-select",value:t.layout,onChange:A=>o.patchLayout(e.sceneId,A.target.value),children:Yl.options.map(A=>f.jsx("option",{value:A,children:A},A))})]})]}),f.jsxs("div",{style:qe,children:[f.jsx("span",{style:De,children:"Video framing"}),f.jsxs("div",{style:Jt,children:[f.jsxs("span",{style:De,children:["zoom"," ",f.jsxs("span",{style:{color:"#EDEDF2"},children:[(((g=t.video)==null?void 0:g.scale)??1).toFixed(2),"×"]})]}),f.jsx("input",{type:"range","data-testid":"zoom-slider",min:.5,max:3,step:.01,value:((y=t.video)==null?void 0:y.scale)??1,onChange:A=>a({sceneId:e.sceneId,patch:{scale:Number(A.target.value)}}),onPointerUp:A=>{const V=Number(A.target.value);o.patchVideo(e.sceneId,{scale:V},`video:${e.sceneId}:scale`),a(null)},onKeyUp:A=>{if(!["ArrowLeft","ArrowRight","ArrowUp","ArrowDown","Home","End","PageUp","PageDown"].includes(A.key))return;const _=Number(A.target.value);o.patchVideo(e.sceneId,{scale:_},`video:${e.sceneId}:scale`),a(null)}})]}),f.jsxs("label",{style:{display:"flex",gap:8,alignItems:"center",fontSize:12,color:"#9A9AA3",cursor:"pointer"},children:[f.jsx("input",{type:"checkbox","data-testid":"auto-zoom",checked:((x=t.video)==null?void 0:x.autoZoom)!==!1,onChange:A=>o.patchVideo(e.sceneId,{autoZoom:A.target.checked})}),"auto zoom (the slow push composes on top of your zoom)"]}),f.jsx("div",{style:{fontSize:12,color:"#9A9AA3"},children:"Pan: drag the picture on the stage."}),f.jsx(Et,{id:"scale",value:((b=t.video)==null?void 0:b.scale)??1,min:.05,max:4,dragStep:.01,onCommit:A=>o.patchVideo(e.sceneId,{scale:A},`video:${e.sceneId}:scale`)}),f.jsxs("div",{style:di,children:[f.jsx(Et,{id:"dx",value:((k=t.video)==null?void 0:k.dx)??0,dragStep:1,onCommit:A=>o.patchVideo(e.sceneId,{dx:A},`video:${e.sceneId}:dx`)}),f.jsx(Et,{id:"dy",value:((S=t.video)==null?void 0:S.dy)??0,dragStep:1,onCommit:A=>o.patchVideo(e.sceneId,{dy:A},`video:${e.sceneId}:dy`)})]}),t.video?f.jsx("button",{style:Sn,onClick:()=>o.clearVideo(e.sceneId),children:"Reset framing"}):null]}),t.layout==="pip-bubble"?(()=>{const A=jr("pip-bubble",void 0,[],n).video,V=t.pip??{},_=V.cornerRadius??A.cornerRadius;return f.jsxs("div",{style:qe,children:[f.jsx("span",{style:De,children:"PiP bubble"}),f.jsxs("div",{style:Jt,children:[f.jsxs("span",{style:De,children:["roundness"," ",f.jsx("span",{style:{color:"#EDEDF2"},children:_.toFixed(2)})]}),f.jsx("input",{type:"range","data-testid":"pip-roundness",min:0,max:1,step:.01,value:_,onChange:L=>o.patchPip(e.sceneId,{cornerRadius:Number(L.target.value)},`pip:${e.sceneId}:cornerRadius`)})]}),f.jsxs("div",{style:di,children:[f.jsx(Et,{id:"pip-x",value:V.x??A.rect.x,min:0,max:1-A.rect.w,dragStep:.002,onCommit:L=>o.patchPip(e.sceneId,{x:L},`pip:${e.sceneId}:x`)}),f.jsx(Et,{id:"pip-y",value:V.y??A.rect.y,min:0,max:1-A.rect.h,dragStep:.002,onCommit:L=>o.patchPip(e.sceneId,{y:L},`pip:${e.sceneId}:y`)})]}),t.pip?f.jsx("button",{"data-testid":"reset-pip",style:Sn,onClick:()=>o.clearPip(e.sceneId),children:"Reset bubble"}):null]})})():null,(()=>{var _;if(P)return null;const A=Fw(t,n),V=L=>O=>o.patchGraphicRect(e.sceneId,Ja({...A,[L]:O},n),`box:${e.sceneId}:${L}`);return f.jsxs("div",{style:qe,children:[f.jsx("span",{style:De,children:"Graphic box"}),f.jsx("div",{style:{fontSize:12,color:"#9A9AA3"},children:"Frame fractions — or drag the handles on the stage."}),f.jsxs("div",{style:di,children:[f.jsx(Et,{id:"box-x",value:A.x,min:0,max:1,dragStep:.002,onCommit:V("x")}),f.jsx(Et,{id:"box-y",value:A.y,min:0,max:1,dragStep:.002,onCommit:V("y")})]}),f.jsxs("div",{style:di,children:[f.jsx(Et,{id:"box-w",value:A.w,min:.08,max:1,dragStep:.002,onCommit:V("w")}),f.jsx(Et,{id:"box-h",value:A.h,min:.05,max:1,dragStep:.002,onCommit:V("h")})]}),(_=o.doc.scenes[e.sceneId])!=null&&_.graphicRect?f.jsx("button",{"data-testid":"reset-box",style:Sn,onClick:()=>o.clearGraphicRect(e.sceneId),children:"Reset box"}):null]})})(),(()=>{const A=jr(t.layout,void 0,[],n).captionAnchor,V=t.captionY??A,_=t.captionScale??1,L=o.doc.scenes[e.sceneId];return f.jsxs("div",{style:qe,children:[f.jsx("span",{style:De,children:"Captions"}),f.jsxs("div",{style:Jt,children:[f.jsxs("span",{style:De,children:["position"," ",f.jsx("span",{style:{color:"#EDEDF2"},children:V.toFixed(2)})]}),f.jsx("input",{type:"range","data-testid":"caption-y-slider",min:.05,max:.95,step:.01,value:V,onChange:O=>o.patchCaptionY(e.sceneId,Number(O.target.value),`captionY:${e.sceneId}`)})]}),f.jsxs("div",{style:Jt,children:[f.jsxs("span",{style:De,children:["scale"," ",f.jsxs("span",{style:{color:"#EDEDF2"},children:[_.toFixed(2),"×"]})]}),f.jsx("input",{type:"range","data-testid":"caption-scale-slider",min:.2,max:3,step:.01,value:_,onChange:O=>o.patchCaptionScale(e.sceneId,Number(O.target.value),`captionScale:${e.sceneId}`)})]}),f.jsx(Et,{id:"caption-scale",value:_,min:.2,max:3,dragStep:.01,onCommit:O=>o.patchCaptionScale(e.sceneId,O,`captionScale:${e.sceneId}`)}),f.jsx("button",{"data-testid":"caption-y-all",style:{...Sn,color:"#EDEDF2",border:"1px solid #2A2A33"},title:"Write this scene's caption position and scale to every scene — one undo step",onClick:()=>o.patchCaptionStyleAll(r,{y:V,scale:_}),children:"Apply to all scenes"}),(L==null?void 0:L.captionY)!==void 0||(L==null?void 0:L.captionScale)!==void 0?f.jsx("button",{"data-testid":"reset-caption-y",style:Sn,onClick:()=>o.clearCaptionStyle(e.sceneId),children:"Reset captions"}):null]})})(),f.jsxs("div",{style:qe,children:[f.jsx("span",{style:De,children:"Timing"}),f.jsxs("div",{"data-testid":"timing-range",style:{fontSize:13,fontFamily:"ui-monospace, 'SF Mono', monospace"},children:[t.startSec.toFixed(2),"s – ",t.endSec.toFixed(2),"s",f.jsxs("span",{style:{color:"#9A9AA3"},children:[" ","(",(t.endSec-t.startSec).toFixed(2),"s)"]})]}),f.jsx("div",{style:{fontSize:12,color:t.pinned?"#FFE14D":"#9A9AA3"},children:P?"Derived from the cut — not movable":t.pinned?"Pinned to these times":"Tracking transcript"}),!t.pinned&&s?f.jsxs("div",{style:{fontSize:12,color:"#9A9AA3",fontStyle:"italic"},children:["“",s,"”"]}):null,t.pinned?f.jsx("button",{style:Sn,onClick:()=>o.clearTiming(e.sceneId),children:"Un-pin (re-anchor to words)"}):null]}),P?null:f.jsx("div",{style:qe,children:f.jsx("button",{"data-testid":"delete-scene",style:Sn,onClick:()=>o.hideScene(e.sceneId),children:"Delete scene"})})]})}const u=o.doc.theme,d=(P,A)=>o.patchTheme({[P]:A}),p=P=>`${Math.floor(P/60)}:${String(Math.floor(P%60)).padStart(2,"0")}`,m=((C=l==null?void 0:l.usage)==null?void 0:C.totals)??null,h=((I=l==null?void 0:l.production)==null?void 0:I.producer)??null,w=((F=l==null?void 0:l.production)==null?void 0:F.clip)??null;return f.jsxs("div",{children:[f.jsxs("div",{style:qe,children:[f.jsx("span",{style:De,children:"Theme"}),f.jsx("div",{style:{fontSize:12,color:"#9A9AA3"},children:"Nothing selected — global tokens."})]}),f.jsxs("div",{style:qe,children:[f.jsx(ea,{id:"accent",value:u.accent??i.accent,isColor:!0,onCommit:P=>d("accent",P)}),f.jsx(ea,{id:"bg",value:u.bg??i.bg,isColor:!0,onCommit:P=>d("bg",P)}),f.jsx(ea,{id:"fg",value:u.fg??i.fg,isColor:!0,onCommit:P=>d("fg",P)}),f.jsx(Et,{id:"radiusPx",value:u.radiusPx??i.radiusPx,min:0,dragStep:.5,onCommit:P=>d("radiusPx",P)}),f.jsx(ea,{id:"fontDisplay",value:u.fontDisplay??i.fontDisplay,isColor:!1,onCommit:P=>d("fontDisplay",P)})]}),h||m?f.jsxs("div",{style:qe,"data-testid":"run-info",children:[f.jsx("span",{style:De,children:"This video"}),h?f.jsxs("div",{style:{fontSize:12,color:"#C9C9D4"},children:["planned by ",f.jsx("span",{style:{color:"#EDEDF2"},children:h.provider}),h.models.length>0?` (${h.models.join(", ")})`:"",h.cached?" · reused from cache":"",h.at?` · ${new Date(h.at).toLocaleString()}`:""]}):null,m?f.jsxs("div",{style:{fontSize:12,color:"#C9C9D4"},children:[m.calls," LLM call",m.calls===1?"":"s"," ·"," ",m.inputTokens.toLocaleString()," in / ",m.outputTokens.toLocaleString()," out tokens",m.anyEstimated?" (partly estimated)":""]}):null,m&&m.equivalentUsd!==null?f.jsx("div",{style:{fontSize:12,color:"#C9C9D4"},children:m.allUnbilled?`~$${m.equivalentUsd.toFixed(2)} of API-rate work, covered by the subscription`:m.billedUsd!==null?`~$${m.billedUsd.toFixed(2)} charged at API rates`:`~$${m.equivalentUsd.toFixed(2)} at API rates`}):null,w?f.jsxs("div",{style:{fontSize:12,color:"#C9C9D4"},children:["clip: ",p(w.startSec),"–",p(w.endSec),(j=l==null?void 0:l.production)!=null&&j.sourceDuration?` of ${p(l.production.sourceDuration)}`:""," ","(--clip ",w.targetSec,")"]}):null]}):null,f.jsx("div",{style:qe,children:f.jsx("div",{"data-testid":"ai-disclaimer",style:{fontSize:12,color:"#9A9AA3"},children:"AI can make mistakes. The cut, captions and graphics are generated — review them before publishing."})})]})},Uu=1.2,tl=.05;function q4(e,t,n,r){return n<=0||r<=0?0:Math.min(1,Math.max(0,(e-t)/n))*r}const Q4=16,J4=e=>Math.min(Q4,Math.max(1,e));function eM(e,t,n,r,o){if(e<=0||n<=0)return 0;const s=(r+o)*(t/e),a=Math.max(0,t*n-n);return Math.min(a,Math.max(0,s-o))}const Gw=e=>e.filter(t=>t.kind!=="plain");function tM(e,t,n,r){const o=Gw(e),i=o.findIndex(h=>h.id===t),s=o[i];if(!s)return null;const a=s.endSec-s.startSec,l=i>0?o[i-1]:void 0,u=i<o.length-1?o[i+1]:void 0,d=l?l.endSec+tl:0,p=u?u.startSec-tl:r,m=Math.min(Math.max(s.startSec+n,d),Math.max(d,p-a));return{startSec:m,endSec:m+a}}function nM(e,t,n,r,o){const i=Gw(e),s=i.findIndex(h=>h.id===t),a=s>0?i[s-1]:void 0,l=s>=0&&s<i.length-1?i[s+1]:void 0,u=a?a.endSec+tl:0,d=l?l.startSec-tl:o;let p=Math.min(Math.max(n,u),Math.max(u,d-Uu)),m=Math.max(Math.min(r,d),p+Uu);return m>d&&(m=d,p=Math.max(u,m-Uu)),{startSec:p,endSec:m}}const rM=10,oM=4,Dh=8,iM=300,sM=e=>{const t=Math.max(0,e),n=Math.floor(t/60),r=(t%60).toFixed(1).padStart(4,"0");return`${n}:${r}`},aM=e=>{const t=Math.max(0,Math.round(e));return`${Math.floor(t/60)}:${String(t%60).padStart(2,"0")}`},lM=(e,t)=>{const[n,r]=J.useState({}),o=J.useRef({}),i=t.map(s=>s.toFixed(1)).join(",");return J.useEffect(()=>{if(!e||t.length===0)return;const s=[...new Set(t.map(p=>p.toFixed(1)))].filter(p=>o.current[p]===void 0);if(s.length===0)return;let a=!1;const l=document.createElement("video");l.src=e,l.muted=!0,l.preload="auto";const u=document.createElement("canvas");return(async()=>{await new Promise((m,h)=>{l.onloadedmetadata=()=>m(),l.onerror=()=>h(new Error("no video for thumbnails"))}),u.width=168,u.height=Math.max(1,Math.round(168*l.videoHeight/Math.max(1,l.videoWidth)));const p=u.getContext("2d");if(p){for(const m of s){if(a)return;await new Promise(h=>{l.onseeked=()=>h(),l.currentTime=Math.max(0,Number(m))}),p.drawImage(l,0,0,u.width,u.height),o.current[m]=u.toDataURL("image/jpeg",.6)}a||r({...o.current})}})().catch(()=>{}),()=>{a=!0,l.removeAttribute("src"),l.load()}},[e,i]),n},uM=({cues:e,ghosts:t,durationSec:n,fps:r,playerRef:o,selection:i,onSelect:s,edits:a,videoSrc:l,toSourceSec:u})=>{const d=c.useRef(null),p=c.useRef(null),m=c.useRef(!1),h=c.useRef(null),[w,v]=c.useState(0),[E,g]=c.useState(null),[y,x]=c.useState(1),b=J.useMemo(()=>u?e.filter(_=>_.kind==="plain").map(_=>u((_.startSec+_.endSec)/2)):[],[e,u]),k=lM(l,b),S=c.useRef(null),C=c.useRef(null),I=c.useCallback((_,L)=>{const O=S.current;x(N=>{const T=J4(_);if(T===N||!O)return T;const z=O.getBoundingClientRect();return C.current={prevZoom:N,anchorX:L!==void 0?L-z.left:z.width/2},T})},[]);c.useLayoutEffect(()=>{const _=S.current,L=C.current;!_||!L||(C.current=null,_.scrollLeft=eM(L.prevZoom,y,_.clientWidth,_.scrollLeft,L.anchorX))},[y]);const F=c.useRef(y);F.current=y,c.useEffect(()=>{const _=S.current;if(!_)return;const L=O=>{O.ctrlKey||O.metaKey?(O.preventDefault(),I(F.current*Math.exp(-O.deltaY*.01),O.clientX)):_.scrollWidth>_.clientWidth&&(O.preventDefault(),_.scrollLeft+=O.deltaY+O.deltaX)};return _.addEventListener("wheel",L,{passive:!1}),()=>_.removeEventListener("wheel",L)},[I]),c.useEffect(()=>{const _=o.current;if(!_)return;v(_.getCurrentFrame());const L=O=>v(O.detail.frame);return _.addEventListener("frameupdate",L),()=>_.removeEventListener("frameupdate",L)},[o]),c.useEffect(()=>{const _=S.current;if(!_||n<=0||_.scrollWidth<=_.clientWidth)return;const L=w/r/n*_.scrollWidth,{scrollLeft:O,clientWidth:N}=_;(L<O||L>O+N)&&(_.scrollLeft=Math.max(0,Math.min(_.scrollWidth-N,L-N*.1)))},[w,r,n]),c.useEffect(()=>{var L,O;if(!i)return;const _=(L=S.current)==null?void 0:L.querySelector(`[data-testid="timeline-block-${i.sceneId}"]`);(O=_==null?void 0:_.scrollIntoView)==null||O.call(_,{inline:"nearest",block:"nearest"})},[i]);const j=c.useCallback(_=>{var N;const L=d.current;if(!L||n<=0)return;const O=L.getBoundingClientRect();(N=o.current)==null||N.seekTo(Math.round(q4(_,O.left,O.width,n)*r))},[o,n,r]),P=c.useCallback((_,L)=>O=>{O.stopPropagation(),O.preventDefault();const N=d.current;N&&(p.current={sceneId:_.id,edge:L,startContentX:O.clientX-N.getBoundingClientRect().left,origStart:_.startSec,origEnd:_.endSec},g({sceneId:_.id,startSec:_.startSec,endSec:_.endSec}))},[]),A=c.useRef(0);c.useEffect(()=>{const _=N=>{const T=S.current;if(!T||T.scrollWidth<=T.clientWidth)return;const z=Date.now();if(z-A.current<iM)return;const R=T.getBoundingClientRect(),$=T.scrollWidth-T.clientWidth;N>=R.right-Dh&&T.scrollLeft<$?(T.scrollLeft=Math.min($,T.scrollLeft+T.clientWidth),A.current=z):N<=R.left+Dh&&T.scrollLeft>0&&(T.scrollLeft=Math.max(0,T.scrollLeft-T.clientWidth),A.current=z)},L=N=>{var G;if((m.current||((G=h.current)==null?void 0:G.moved)===!0||p.current!==null)&&_(N.clientX),m.current){j(N.clientX);return}const z=h.current;if(z&&n>0){if(!z.moved&&Math.abs(N.clientX-z.startX)<oM)return;z.moved=!0;const oe=d.current,ne=oe==null?void 0:oe.getBoundingClientRect(),Z=ne?(N.clientX-ne.left-z.startContentX)/ne.width*n:0,ee=tM(e,z.sceneId,Z,n);ee&&g({sceneId:z.sceneId,...ee});return}const R=p.current;if(!R||n<=0)return;const $=d.current;if(!$)return;const B=$.getBoundingClientRect(),W=(N.clientX-B.left-R.startContentX)/B.width*n,M=R.edge==="start"?R.origStart+W:R.origStart,D=R.edge==="end"?R.origEnd+W:R.origEnd,K=nM(e,R.sceneId,M,D,n);g({sceneId:R.sceneId,...K})},O=N=>{m.current=!1;const T=h.current;if(T){h.current=null,T.moved?g(R=>(R&&R.sceneId===T.sceneId&&a.patchTiming(T.sceneId,R.startSec,R.endSec),null)):j(N.clientX);return}const z=p.current;z&&(g(R=>(R&&R.sceneId===z.sceneId&&(R.startSec!==z.origStart||R.endSec!==z.origEnd)&&a.patchTiming(z.sceneId,R.startSec,R.endSec),null)),p.current=null)};return window.addEventListener("mousemove",L),window.addEventListener("mouseup",O),()=>{window.removeEventListener("mousemove",L),window.removeEventListener("mouseup",O)}},[e,n,a,j]);const V=n>0?Math.min(1,w/r/n)*100:0;return f.jsxs("div",{style:cM,children:[f.jsxs("div",{style:dM,children:[f.jsx("span",{style:pM,children:"ctrl+scroll to zoom"}),f.jsx("button",{"data-testid":"zoom-out",style:Hu,onClick:()=>I(y/2),disabled:y<=1,title:"Zoom out (ctrl/cmd + scroll on the timeline)",children:"−"}),f.jsxs("span",{"data-testid":"zoom-level",style:fM,children:[Math.round(y*10)/10,"×"]}),f.jsx("button",{"data-testid":"zoom-in",style:Hu,onClick:()=>I(y*2),disabled:y>=16,title:"Zoom in (ctrl/cmd + scroll on the timeline)",children:"+"}),f.jsx("button",{"data-testid":"zoom-fit",style:{...Hu,width:"auto",padding:"0 8px"},onClick:()=>I(1),disabled:y<=1,title:"Fit the whole clip in view",children:"fit"})]}),f.jsx("div",{ref:S,"data-testid":"timeline-scroller",style:mM,children:f.jsxs("div",{style:{width:`${y*100}%`,minWidth:"100%",paddingBottom:6},children:[f.jsx("div",{"data-testid":"ruler",style:hM,onMouseDown:_=>{_.preventDefault(),j(_.clientX),m.current=!0},children:(()=>{var R;if(n<=0)return f.jsx("span",{style:Zu,children:"0:00"});const L=(((R=S.current)==null?void 0:R.clientWidth)??1200)*y/n;let N=[.5,1,2,5,10,15,30,60,120,300,600].find($=>$*L>=70)??600;for(;n/(N/5)>600;)N*=2;const T=N/5,z=[];for(let $=0;$<=n+1e-6;$+=T){const B=Math.round($/T)%5===0,W=`${$/n*100}%`;z.push(f.jsx("div",{style:{position:"absolute",left:W,bottom:0,width:1,height:B?8:4,background:B?"#3A3A44":"#26262e",pointerEvents:"none"}},$.toFixed(3))),B&&$+T<=n&&z.push(f.jsx("span",{style:{...Zu,position:"absolute",left:W,top:0,transform:$===0?void 0:"translateX(-50%)",pointerEvents:"none"},children:aM($)},`l${$.toFixed(3)}`))}return f.jsxs(f.Fragment,{children:[z,f.jsx("span",{style:{...Zu,position:"absolute",right:2,top:0,pointerEvents:"none"},children:sM(n)})]})})()}),f.jsxs("div",{ref:d,style:gM,onMouseDown:_=>{_.preventDefault(),j(_.clientX),m.current=!0},children:[e.map(_=>{const L=_.kind==="plain",O=(E==null?void 0:E.sceneId)===_.id,N=O?E.startSec:_.startSec,T=O?E.endSec:_.endSec,z=n>0?N/n*100:0,R=n>0?Math.max(0,(T-N)/n*100):0,$=(i==null?void 0:i.sceneId)===_.id,B=L&&u?k[u((_.startSec+_.endSec)/2).toFixed(1)]:void 0;return f.jsxs("div",{"data-testid":`timeline-block-${_.id}`,onMouseDown:W=>{var M;if(W.stopPropagation(),W.preventDefault(),s({sceneId:_.id,elementId:null}),L){j(W.clientX),m.current=!0;return}h.current={sceneId:_.id,startX:W.clientX,startContentX:W.clientX-(((M=d.current)==null?void 0:M.getBoundingClientRect().left)??0),moved:!1}},style:{...Oh,left:`${z}%`,width:`${R}%`,zIndex:O?4:$?3:1,border:$?"2px solid #5b8cff":L?"1px solid #22222a":"1px solid #2A2A33",backgroundColor:$?"#1c2333":L?"#131318":"#1A1A21",...B?{backgroundImage:`linear-gradient(rgba(10,10,14,0.35), rgba(10,10,14,0.6)), url(${B})`,backgroundSize:"auto 100%, auto 100%",backgroundRepeat:"repeat-x"}:{}},children:[f.jsx("span",{style:L?B?{...ta,color:"#D8D8DE",textShadow:"0 1px 2px rgba(0,0,0,0.9)"}:{...ta,color:"#55555f"}:ta,children:_.id}),!L&&_.pinned?f.jsx("span",{style:vM,children:"PIN"}):null,L?null:f.jsxs(f.Fragment,{children:[f.jsx("div",{onMouseDown:P(_,"start"),style:{...Vh,left:0,cursor:"ew-resize"}}),f.jsx("div",{onMouseDown:P(_,"end"),style:{...Vh,right:0,cursor:"ew-resize"}})]})]},_.id)}),t.map(_=>{const L=n>0?_.startSec/n*100:0,O=n>0?Math.max(0,(_.endSec-_.startSec)/n*100):0,N=(i==null?void 0:i.sceneId)===_.id;return f.jsx("div",{"data-testid":`timeline-block-${_.id}`,onMouseDown:T=>{T.stopPropagation(),T.preventDefault(),s({sceneId:_.id,elementId:null})},style:{...Oh,left:`${L}%`,width:`${O}%`,zIndex:N?3:2,border:N?"2px dashed #5b8cff":"1px dashed #6a6a75",background:"transparent"},children:f.jsx("span",{style:{...ta,color:"#6a6a75",textDecoration:"line-through"},children:_.id})},`ghost-${_.id}`)}),f.jsx("div",{"data-testid":"playhead",style:{...yM,left:`${V}%`},children:f.jsx("div",{"data-testid":"playhead-grab",onMouseDown:_=>{_.stopPropagation(),_.preventDefault(),m.current=!0},style:wM})})]})]})})]})},cM={flexShrink:0,borderTop:"1px solid #1E1E24",background:"#111116",padding:"6px 20px 8px"},dM={display:"flex",justifyContent:"flex-end",alignItems:"center",gap:6,marginBottom:4},Hu={width:22,height:18,fontSize:12,lineHeight:1,color:"#EDEDF2",background:"#1A1A21",border:"1px solid #2A2A33",borderRadius:4,cursor:"pointer",padding:0},fM={fontSize:10,fontFamily:"ui-monospace, 'SF Mono', monospace",color:"#9A9AA3",minWidth:26,textAlign:"center"},pM={fontSize:10,color:"#55555f",marginRight:4,userSelect:"none"},mM={overflowX:"auto",overflowY:"hidden"},hM={position:"relative",height:18,padding:"0 2px",marginBottom:4,borderBottom:"1px solid #1E1E24",cursor:"ew-resize",userSelect:"none"},Zu={fontSize:10,fontFamily:"ui-monospace, 'SF Mono', monospace",color:"#9A9AA3"},gM={position:"relative",height:44,background:"#0F0F14",border:"1px solid #2A2A33",borderRadius:6,overflow:"visible",userSelect:"none"},Oh={position:"absolute",top:3,bottom:3,borderRadius:4,boxSizing:"border-box",cursor:"pointer",display:"flex",alignItems:"center",overflow:"hidden"},ta={fontSize:10,fontFamily:"ui-monospace, 'SF Mono', monospace",textTransform:"uppercase",letterSpacing:"0.04em",color:"#9A9AA3",padding:"0 8px",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",pointerEvents:"none"},vM={position:"absolute",top:3,right:3,fontSize:9,fontFamily:"ui-monospace, 'SF Mono', monospace",letterSpacing:"0.04em",textTransform:"uppercase",color:"#0B0B0E",background:"#ffe14d",padding:"1px 5px",borderRadius:3,pointerEvents:"none"},Vh={position:"absolute",top:0,bottom:0,width:rM},yM={position:"absolute",top:-26,bottom:-4,width:2,zIndex:5,background:"#FFE14D",pointerEvents:"none"},wM={position:"absolute",top:0,bottom:0,left:-4,width:10,pointerEvents:"auto",cursor:"ew-resize"},xM=({baseLines:e,liveLines:t,fps:n,playerRef:r,edits:o,width:i})=>{const[s,a]=c.useState(""),[l,u]=c.useState(null),[d,p]=c.useState(null),m=c.useRef(null),h=c.useMemo(()=>{var I;const S=[];let C=0;for(let F=0;F<t.length;F++){const j=t[F],P=e[F];for(let A=0;A<j.words.length;A++){const V=j.words[A];S.push({index:C,base:((I=P==null?void 0:P.words[A])==null?void 0:I.text)??V.text,live:V.text,start:V.start,end:V.end,lineStart:j.start}),C++}}return S},[e,t]);c.useEffect(()=>{const S=r.current;if(!S)return;const C=I=>{const F=I.detail.frame/n,j=h.find(P=>F>=P.start&&F<P.end);p(P=>j?j.index===P?P:j.index:P)};return S.addEventListener("frameupdate",C),()=>S.removeEventListener("frameupdate",C)},[r,n,h]),c.useEffect(()=>{var S,C,I;d!==null&&((I=(C=(S=m.current)==null?void 0:S.querySelector(`[data-testid="transcript-word-${d}"]`))==null?void 0:C.scrollIntoView)==null||I.call(C,{block:"nearest"}))},[d]);const w=s.trim().toLowerCase(),v=c.useMemo(()=>w?h.filter(S=>S.live.toLowerCase().includes(w)).map(S=>S.index):[],[w,h]),E=c.useMemo(()=>w?new Set(v):null,[w,v]),[g,y]=c.useState(0),x=S=>{var C,I,F;(F=(I=(C=m.current)==null?void 0:C.querySelector(`[data-testid="transcript-word-${S}"]`))==null?void 0:I.scrollIntoView)==null||F.call(I,{block:"center"})};c.useEffect(()=>{y(0),v.length>0&&x(v[0])},[v]);const b=S=>{if(v.length===0)return;const C=(g+S+v.length)%v.length;y(C),x(v[C])},k=(S,C,I)=>{const F=I.trim();F&&o.patchCaption(S,F,C),u(null)};return f.jsxs("div",{"data-testid":"transcript-panel",style:{...bM,width:i},children:[f.jsxs("div",{style:SM,children:[f.jsx("span",{style:EM,children:"Transcript"}),f.jsx("div",{style:kM,children:"Click a word to jump the preview there; double-click to retype it. 1:1 retype only — word count and timing stay fixed, so scene anchors and the caption highlight keep working."}),f.jsxs("div",{style:{display:"flex",gap:6,alignItems:"center"},children:[f.jsx("input",{"data-testid":"transcript-search",style:{...CM,flex:1},placeholder:"Find a word…",value:s,onChange:S=>a(S.target.value),onKeyDown:S=>{S.key==="Enter"&&(S.preventDefault(),b(S.shiftKey?-1:1))}}),f.jsx("button",{"data-testid":"transcript-prev",style:Bh,onClick:()=>b(-1),disabled:v.length===0,title:"Previous match (⇧Enter)","aria-label":"Previous match",children:"‹"}),f.jsx("button",{"data-testid":"transcript-next",style:Bh,onClick:()=>b(1),disabled:v.length===0,title:"Next match (Enter)","aria-label":"Next match",children:"›"})]}),E?f.jsx("div",{"data-testid":"transcript-match-count",style:{fontSize:11,color:"#9A9AA3"},children:v.length===0?"0 matches":`${g+1}/${v.length} match${v.length===1?"":"es"}`}):null]}),f.jsx("div",{style:IM,"data-testid":"transcript-body",ref:m,children:h.map((S,C)=>f.jsxs(J.Fragment,{children:[C>0?" ":null,(l==null?void 0:l.index)===S.index?f.jsx("input",{autoFocus:!0,"data-testid":"transcript-edit",style:MM,value:l.draft,onChange:I=>u({index:S.index,draft:I.target.value}),onBlur:()=>k(S.index,S.base,l.draft),onKeyDown:I=>{I.key==="Enter"&&I.target.blur(),I.key==="Escape"&&u(null)}}):f.jsx("span",{"data-testid":`transcript-word-${S.index}`,onClick:()=>{var I;return(I=r.current)==null?void 0:I.seekTo(Math.round(S.start*n))},onDoubleClick:()=>u({index:S.index,draft:S.live}),title:S.live!==S.base?`edited (was “${S.base}”) — double-click to retype`:"click to jump · double-click to retype",style:{...TM,...E!=null&&E.has(S.index)?_M:{},...v[g]===S.index?RM:{},...S.live!==S.base?PM:{},...d===S.index?FM:{}},children:S.live})]},S.index))})]})},bM={flexShrink:0,display:"flex",flexDirection:"column",background:"#111116",minHeight:0},SM={display:"flex",flexDirection:"column",gap:8,padding:"14px 14px 10px",borderBottom:"1px solid #1E1E24"},EM={fontSize:11,fontWeight:600,letterSpacing:"0.06em",textTransform:"uppercase",color:"#9A9AA3"},kM={fontSize:11,lineHeight:1.45,color:"#6a6a75"},CM={fontFamily:"'Inter', system-ui, sans-serif",fontSize:13,background:"#0F0F14",border:"1px solid #2A2A33",borderRadius:6,color:"#fff",padding:"6px 8px"},IM={flex:1,overflowY:"auto",overflowX:"hidden",overflowWrap:"break-word",padding:"10px 14px 16px",fontSize:13,lineHeight:2,color:"#C9C9D4"},TM={cursor:"pointer",borderRadius:3,padding:"1px 2px"},_M={background:"#2b2b1a",outline:"1px solid #6b6432"},RM={background:"#3d3a17",outline:"2px solid #FFE14D",color:"#fff"},Bh={width:26,height:30,fontSize:16,lineHeight:1,color:"#EDEDF2",background:"#1A1A21",border:"1px solid #2A2A33",borderRadius:6,cursor:"pointer",padding:0},PM={color:"#FFE14D"},FM={background:"#1c2333",outline:"1px solid #5b8cff"},MM={fontFamily:"'Inter', system-ui, sans-serif",fontSize:13,width:110,background:"#0F0F14",border:"1px solid #FFE14D",borderRadius:4,color:"#fff",padding:"1px 4px"},jM=[{title:"transport",rows:[["space","play / pause"],["J / K / L","reverse · pause · forward (tap again to speed up)"],["← / →","step one frame back / forward"],["⌘/ctrl + ← / →","jump to and select the previous / next scene"]]},{title:"selection",rows:[["click","select scene or element"],["⌥ + ← / →","select previous / next scene"],["esc","clear selection · close dialogs"]]},{title:"editing",rows:[["⌘/ctrl + B","split the scene at the playhead"],["delete / backspace","delete the selected scene (restorable)"],["⌘/ctrl + Z","undo"],["⌘/ctrl + ⇧ + Z","redo (⌘Y works too)"],["⌘/ctrl + S","save"],["double-click caption word","retype it in place"],["drag element / corner handles","move · resize"],["drag picture","pan the video framing"]]},{title:"view",rows:[["⌘/ctrl + scroll on preview","zoom the view (never edits)"],["⌥-drag / middle-drag","pan the zoomed view"],["⌘/ctrl + scroll on timeline","zoom the timeline"],["?","this reference"]]}],$M=({onClose:e})=>(c.useEffect(()=>{const t=n=>{n.key==="Escape"&&(n.stopPropagation(),e())};return window.addEventListener("keydown",t,!0),()=>window.removeEventListener("keydown",t,!0)},[e]),f.jsx("div",{style:AM,onMouseDown:e,children:f.jsxs("div",{"data-testid":"shortcuts-modal",style:NM,onMouseDown:t=>t.stopPropagation(),children:[f.jsxs("div",{style:LM,children:[f.jsx("span",{style:zM,children:"keybinds"}),f.jsx("span",{style:DM,children:"esc close"})]}),f.jsx("div",{style:OM,children:"available commands and configured shortcuts"}),jM.map(t=>f.jsxs("div",{style:{marginTop:18},children:[f.jsx("div",{style:VM,children:t.title}),t.rows.map(([n,r])=>f.jsxs("div",{style:BM,children:[f.jsx("span",{style:WM,children:n}),f.jsx("span",{style:UM,children:r})]},n))]},t.title))]})})),AM={position:"fixed",inset:0,zIndex:30,background:"rgba(5,5,8,0.6)",display:"flex",alignItems:"center",justifyContent:"center"},NM={width:620,maxWidth:"90vw",maxHeight:"82vh",overflowY:"auto",background:"#12121A",border:"1px solid #3A3A48",borderRadius:8,padding:"20px 26px 26px",fontFamily:"ui-monospace, 'SF Mono', Consolas, monospace"},LM={display:"flex",justifyContent:"space-between",alignItems:"center"},zM={fontSize:18,fontWeight:700,color:"#EDEDF2"},DM={fontSize:13,fontWeight:700,color:"#0B0B0E",background:"#a8c7fa",borderRadius:4,padding:"3px 10px"},OM={fontSize:13,color:"#6a6a75",marginTop:4},VM={fontSize:14,fontWeight:700,color:"#8ab4f8",marginBottom:6},BM={display:"flex",gap:16,padding:"3px 0"},WM={width:290,flexShrink:0,color:"#c5a3ff",fontWeight:600,fontSize:13},UM={color:"#C9C9D4",fontSize:13},Wh=({recent:e,required:t,onOpen:n,onClose:r})=>{const[o,i]=c.useState(null),[s,a]=c.useState(null),[l,u]=c.useState(!1),d=async m=>{try{const h=await fetch(`/api/fs${m?`?dir=${encodeURIComponent(m)}`:""}`),w=await h.json();if(!h.ok)throw new Error(w.error??`listing failed: ${h.status}`);i(w)}catch(h){a(h instanceof Error?h.message:String(h))}};c.useEffect(()=>{d()},[]),c.useEffect(()=>{if(t)return;const m=h=>{h.key==="Escape"&&(h.stopPropagation(),r())};return window.addEventListener("keydown",m,!0),()=>window.removeEventListener("keydown",m,!0)},[t,r]);const p=m=>{u(!0),a(null),n(m).then(h=>{u(!1),h&&a(h)})};return f.jsx("div",{style:HM,onMouseDown:t?void 0:r,children:f.jsxs("div",{"data-testid":"project-picker",style:ZM,onMouseDown:m=>m.stopPropagation(),children:[f.jsxs("div",{style:YM,children:[f.jsx("span",{style:KM,children:t?"open a project":"switch project"}),t?null:f.jsx("button",{"data-testid":"project-picker-close",style:XM,onClick:r,children:"esc close"})]}),f.jsx("div",{style:GM,children:"A project is a work directory a `ossclip produce` run wrote — the folder holding render-props.json."}),s?f.jsx("div",{"data-testid":"project-picker-error",style:qM,children:s}):null,e.length>0?f.jsxs("div",{style:{marginTop:16},children:[f.jsx("div",{style:Uh,children:"recent"}),e.map(m=>f.jsxs("button",{"data-testid":"project-recent",style:Yu,disabled:l,onClick:()=>p(m),title:m,children:[f.jsx("span",{style:{color:"#FFE14D",marginRight:8},children:"▸"}),m]},m))]}):null,f.jsxs("div",{style:{marginTop:16},children:[f.jsx("div",{style:Uh,children:"browse"}),f.jsxs("div",{style:{color:"#6a6a75",fontSize:12,marginBottom:6},children:["Folders only — hidden ones are omitted, and any projects produced inside a folder show up directly as ",f.jsx("span",{style:{color:"#FFE14D"},children:"▸ .ossclip/…"})," entries."]}),o?f.jsxs(f.Fragment,{children:[f.jsxs("div",{style:QM,children:[f.jsx("span",{style:JM,title:o.dir,children:o.dir}),o.isWorkdir?f.jsx("button",{"data-testid":"project-open-current",style:ej,disabled:l,onClick:()=>p(o.dir),children:"open this project"}):null]}),f.jsxs("div",{style:tj,"data-testid":"project-fs-list",children:[o.parent?f.jsx("button",{"data-testid":"project-fs-up",style:Yu,disabled:l,onClick:()=>void d(o.parent),children:".."}):null,o.entries.map(m=>f.jsxs("button",{"data-testid":m.isWorkdir?"project-fs-workdir":"project-fs-dir",style:{...Yu,...m.isWorkdir?nj:{}},disabled:l,onClick:()=>m.isWorkdir?p(m.path):void d(m.path),title:m.path,children:[f.jsx("span",{style:{marginRight:8,color:m.isWorkdir?"#FFE14D":"#6a6a75"},children:m.isWorkdir?"▸":"▪"}),m.name,m.isWorkdir?f.jsx("span",{style:rj,children:"project"}):f.jsx("span",{style:{color:"#55555f"},children:"/"})]},m.path)),o.entries.length===0?f.jsx("div",{style:{color:"#6a6a75",fontSize:12,padding:"6px 8px"},children:"no folders here"}):null]})]}):f.jsx("div",{style:{color:"#6a6a75",fontSize:13},children:"loading…"})]})]})})},HM={position:"fixed",inset:0,zIndex:30,background:"rgba(5,5,8,0.6)",display:"flex",alignItems:"center",justifyContent:"center"},ZM={width:620,maxWidth:"90vw",maxHeight:"82vh",overflowY:"auto",background:"#12121A",border:"1px solid #3A3A48",borderRadius:8,padding:"20px 26px 26px",fontFamily:"ui-monospace, 'SF Mono', Consolas, monospace"},YM={display:"flex",justifyContent:"space-between",alignItems:"center"},KM={fontSize:18,fontWeight:700,color:"#EDEDF2"},XM={fontSize:13,fontWeight:700,color:"#0B0B0E",background:"#a8c7fa",border:"none",borderRadius:4,padding:"3px 10px",cursor:"pointer"},GM={fontSize:13,color:"#6a6a75",marginTop:4},qM={marginTop:12,fontSize:13,color:"#FF5C5C"},Uh={fontSize:14,fontWeight:700,color:"#8ab4f8",marginBottom:6},QM={display:"flex",alignItems:"center",gap:10,marginBottom:6},JM={fontSize:12,color:"#9A9AA3",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},ej={flexShrink:0,fontSize:12,fontWeight:700,color:"#0B0B0E",background:"#FFE14D",border:"1px solid #FFE14D",borderRadius:6,padding:"4px 10px",cursor:"pointer"},tj={maxHeight:"34vh",overflowY:"auto",display:"flex",flexDirection:"column",gap:2},Yu={display:"block",width:"100%",textAlign:"left",fontFamily:"inherit",fontSize:13,color:"#C9C9D4",background:"transparent",border:"1px solid transparent",borderRadius:6,padding:"5px 8px",cursor:"pointer",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},nj={color:"#EDEDF2",background:"#1A1A21",border:"1px solid #2A2A33"},rj={marginLeft:10,fontSize:11,fontWeight:700,color:"#FFE14D"};function na(e){for(let t=e.length-1;t>=0;t--){const n=/^\s*(\d{1,3})%\s*$/.exec(e[t]);if(n)return Math.min(100,Number(n[1]))}return null}function oj(e){const t=n=>{for(let r=e.length-1;r>=0;r--)if(n.test(e[r]))return e[r]};return[t(/^▸ producing scenes/),t(/^▸ llm:/)].filter(n=>n!==void 0)}function ij(e,t){const n=Math.max(0,Math.floor((t-e)/1e3));return`${Math.floor(n/60)}:${String(n%60).padStart(2,"0")}`}const sj=()=>{const e=B4(),[t,n]=c.useState(null),[r,o]=c.useState(null),[i,s]=c.useState(null),[a,l]=c.useState(null),[u,d]=c.useState(!1),[p,m]=c.useState(1),[h,w]=c.useState(null),[v,E]=c.useState(!1),[g,y]=c.useState([]),[x,b]=c.useState(null),[k,S]=c.useState(!1),[C,I]=c.useState(null),F=c.useRef(null);c.useEffect(()=>()=>{F.current!==null&&window.clearInterval(F.current)},[]);const[j,P]=c.useState(null),A=c.useRef(null),V=c.useRef(null),_=c.useRef(null),L=c.useRef(null),[O,N]=c.useState(null),[T,z]=c.useState(null),R=c.useCallback(H=>{var pe;if(_.current=H,z(H),(pe=L.current)==null||pe.disconnect(),L.current=null,!H)return;const X=()=>N({w:Math.max(0,H.clientWidth-Xu*2),h:Math.max(0,H.clientHeight-Xu*2)});X();const Q=new ResizeObserver(X);Q.observe(H),L.current=Q},[]),[$,B]=c.useState(1),W=c.useRef($);W.current=$;const M=c.useRef(null),D=c.useCallback((H,X)=>{const Q=_.current,pe=Math.min(8,Math.max(.25,H)),Ce=W.current;if(Q&&pe!==Ce){const Ot=Q.getBoundingClientRect();M.current={prev:Ce,ax:((X==null?void 0:X.x)??Ot.left+Ot.width/2)-Ot.left,ay:((X==null?void 0:X.y)??Ot.top+Ot.height/2)-Ot.top,sl:Q.scrollLeft,st:Q.scrollTop}}B(pe)},[]);c.useLayoutEffect(()=>{const H=_.current,X=M.current;if(!H||!X)return;M.current=null;const Q=$/X.prev;H.scrollLeft=(X.sl+X.ax)*Q-X.ax,H.scrollTop=(X.st+X.ay)*Q-X.ay},[$]),c.useEffect(()=>{const H=T;if(!H)return;const X=Q=>{(Q.ctrlKey||Q.metaKey)&&(Q.preventDefault(),D(W.current*Math.exp(-Q.deltaY*.01),{x:Q.clientX,y:Q.clientY}))};return H.addEventListener("wheel",X,{passive:!1}),()=>H.removeEventListener("wheel",X)},[T,D]);const K=c.useRef(null);c.useEffect(()=>{const H=Q=>{const pe=K.current,Ce=_.current;!pe||!Ce||(Ce.scrollLeft=pe.sl-(Q.clientX-pe.x),Ce.scrollTop=pe.st-(Q.clientY-pe.y))},X=()=>{K.current=null};return window.addEventListener("mousemove",H),window.addEventListener("mouseup",X),()=>{window.removeEventListener("mousemove",H),window.removeEventListener("mouseup",X)}},[]);const[G,oe]=c.useState(!1),[ne,Z]=c.useState(()=>{const H=Number(window.localStorage.getItem(Hh));return Number.isFinite(H)&&H>0?Zh(H):300}),ee=c.useRef(null);c.useEffect(()=>{const H=Q=>{const pe=ee.current;pe&&Z(Zh(pe.startW+(Q.clientX-pe.startX)))},X=()=>{ee.current&&(ee.current=null,Z(Q=>(window.localStorage.setItem(Hh,String(Q)),Q)))};return window.addEventListener("mousemove",H),window.addEventListener("mouseup",X),()=>{window.removeEventListener("mousemove",H),window.removeEventListener("mouseup",X)}},[]);const[ae,me]=c.useState(!1),[ge,le]=c.useState(!0),q=c.useCallback(H=>{const X=YI({rate:p,playing:u},H);m(X.rate);const Q=V.current;Q&&(X.playing&&!u&&Q.play(),!X.playing&&u&&Q.pause())},[p,u]);c.useEffect(()=>{const H=V.current;if(!H)return;const X=()=>d(!0),Q=()=>d(!1);return H.addEventListener("play",X),H.addEventListener("pause",Q),()=>{H.removeEventListener("play",X),H.removeEventListener("pause",Q)}});const de=c.useCallback(()=>{if(F.current!==null)return;const H=window.setInterval(()=>{(async()=>{try{const Q=await(await fetch("/api/render/status")).json();if(Q.running||Q.exitCode===null){I(pe=>({running:Q.running,lines:Q.lines??[],startedAt:Q.startedAt??(pe==null?void 0:pe.startedAt)}));return}if(F.current!==null&&(window.clearInterval(F.current),F.current=null),Q.exitCode===0){const Ce=await(await fetch("/api/production")).json();n(Ce.renderProps),S(!!Ce.canRender),I(null)}else I({running:!1,lines:Q.lines??[],failed:Q.exitCode,cancelled:Q.cancelled})}catch{}})()},1e3);F.current=H},[]),ye=c.useCallback(async()=>{const H=await fetch("/api/production");if(!H.ok)throw new Error(`GET /api/production failed: ${H.status}`);const X=await H.json();if(y(X.recent??[]),X.noWorkdir){E(!0);return}n(X.renderProps),b(X.workdir??null),S(!!X.canRender),e.load(X.overrides),fetch("/api/usage").then(async Ce=>o(Ce.ok?await Ce.json():null)).catch(()=>o(null));const pe=await(await fetch("/api/render/status")).json();pe.running&&(I({running:!0,lines:pe.lines??[],startedAt:pe.startedAt}),de())},[de]);c.useEffect(()=>{ye().catch(H=>s(H instanceof Error?H.message:String(H)))},[]);const Fe=c.useCallback(async H=>{if(e.dirty&&!window.confirm("Unsaved edits will be lost — switch projects anyway?"))return null;try{const X=await fetch("/api/workdir",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({path:H})}),Q=await X.json().catch(()=>({}));return X.ok?(l(null),w(null),P(null),I(null),B(1),n(null),E(!1),await ye(),null):Q.error??`open failed: ${X.status}`}catch(X){return X instanceof Error?X.message:String(X)}},[e.dirty,ye]),se=c.useMemo(()=>{if(!t)return null;const H=(t.baseSceneCues??t.sceneCues??[]).filter(St=>St.kind!=="plain"),X=t.baseTheme??t.theme??UP,{cues:Q}=Ou(H,e.doc),{cues:pe}=Sh(Q,e.doc),Ce=vF(pe,{outputDurationSec:t.outputDurationSec,clipStarts:(t.spans??[]).map(St=>St.outIn)}),Ot=lF(Ce,e.doc.splits),{cues:Gl}=Ou(Ot,e.doc),{cues:Ko}=Sh(Gl,e.doc);let Ur=h?Ko.map(St=>St.id===h.sceneId?{...St,video:{...St.video,...h.patch}}:St):Ko;j&&(Ur=Ur.map(St=>St.id===j.sceneId?{...St,graphicRect:j.rect}:St));const ql=t.baseCaptionLines??t.captionLines??[];return{...t,sceneCues:Ur,captionLines:uF(ql,e.doc.captions).lines,theme:cF(X,e.doc),videoFileName:`/media/${t.videoFileName}`}},[t,e.doc,h,j]),We=()=>{e.save().catch(H=>s(H instanceof Error?H.message:String(H)))},zt=c.useCallback(async()=>{try{e.dirty&&await e.save();const H=await fetch("/api/render",{method:"POST"});if(!H.ok){const X=await H.json().catch(()=>({}));throw new Error(X.error??`render failed to start: ${H.status}`)}I({running:!0,lines:[],startedAt:Date.now()}),de()}catch(H){s(H instanceof Error?H.message:String(H))}},[e,de]),nt=c.useMemo(()=>{if(!t)return[];const H=(t.baseSceneCues??t.sceneCues??[]).filter(Q=>Q.kind!=="plain"),{cues:X}=Ou(H,e.doc);return X.filter(Q=>{var pe;return((pe=e.doc.scenes[Q.id])==null?void 0:pe.hidden)===!0})},[t,e.doc]),Ge=c.useMemo(()=>a?(se==null?void 0:se.sceneCues.find(H=>H.id===a.sceneId))??nt.find(H=>H.id===a.sceneId)??null:null,[se,a,nt]),lt=c.useMemo(()=>{if(!Ge||!se)return;const H=se.captionLines.filter(Q=>Q.start<Ge.endSec&&Q.end>Ge.startSec).flatMap(Q=>Q.words).filter(Q=>Q.start<Ge.endSec&&Q.end>Ge.startSec).map(Q=>Q.text);if(H.length===0)return;const X=H.join(" ");return X.length>90?`${X.slice(0,90)}…`:X},[Ge,se]);if(i)return f.jsx("div",{style:Ku,children:f.jsxs("div",{style:{padding:24,color:"#FF5C5C",fontFamily:"ui-monospace, monospace"},children:["Couldn't load the production: ",i]})});if(!se)return f.jsx("div",{style:Ku,children:v?f.jsx(Wh,{recent:g,required:!0,onOpen:Fe,onClose:()=>{}}):f.jsx("div",{style:{padding:24,color:"#9A9AA3"},children:"Loading production…"})});const ut=se.settings.width/se.settings.height,Dt=O?Math.max(220,Math.min(O.w,O.h*ut)):380,Xt=Math.round(Dt*$);return f.jsxs("div",{style:Ku,children:[f.jsxs("div",{style:cj,children:[f.jsx("span",{style:dj,children:"ossclip"}),x?f.jsx("span",{"data-testid":"workdir-label",style:fj,title:x,children:x.split("/").filter(Boolean).slice(-2).join("/")}):null,f.jsxs("div",{style:{display:"flex",gap:8},children:[f.jsx("button",{"data-testid":"open-button",style:dn,onClick:()=>E(!0),title:x?`Open another project — currently ${x}`:"Open another project",children:"Open"}),f.jsx("button",{"data-testid":"undo-button",style:dn,onClick:()=>e.undo(),disabled:!e.canUndo,title:"Undo (⌘Z)","aria-label":"Undo",children:f.jsx(lj,{})}),f.jsx("button",{"data-testid":"redo-button",style:dn,onClick:()=>e.redo(),disabled:!e.canRedo,title:"Redo (⌘⇧Z)","aria-label":"Redo",children:f.jsx(uj,{})}),f.jsx("button",{"data-testid":"transcript-toggle",style:{...dn,...G?{borderColor:"#5b8cff"}:{}},onClick:()=>oe(H=>!H),title:"Find and retype caption words across the whole transcript",children:"Transcript"}),f.jsx("button",{style:{...dn,...e.dirty?mj:{}},onClick:We,disabled:!e.dirty,children:"Save"}),f.jsx("button",{"data-testid":"render-button",style:dn,onClick:()=>void zt(),disabled:!k||(C==null?void 0:C.running)===!0,title:k?"Saves if needed, then replays the last completed produce command — pipeline flags come from that run; your saved edits apply on top":"No command.json in this workdir — run `ossclip produce` once in a terminal; it records the invocation and Render replays it",children:C!=null&&C.running?"Rendering…":"Render"})]}),f.jsx("span",{style:{...pj,color:e.dirty?"#FFE14D":"#5FBF77"},...e.dirty?{"data-testid":"dirty"}:{},children:e.dirty?"● Unsaved changes":"✓ Saved"}),f.jsx("button",{"data-testid":"shortcuts-button",style:{...dn,padding:"7px 10px"},onClick:()=>me(H=>!H),title:"Keyboard shortcuts (?)",children:"?"})]}),ae?f.jsx($M,{onClose:()=>me(!1)}):null,v?f.jsx(Wh,{recent:g,required:!1,onOpen:Fe,onClose:()=>E(!1)}):null,C?f.jsxs("div",{"data-testid":"render-log",style:{...Ej,borderColor:C.failed!==void 0?"#FF5C5C":"#2A2A33"},children:[C.failed!==void 0?f.jsxs("div",{style:{color:C.cancelled?"#9A9AA3":"#FF5C5C",marginBottom:4},"data-testid":C.cancelled?"render-cancelled":"render-failed",children:[C.cancelled?"render cancelled":`render failed (exit ${C.failed})`,f.jsx("button",{style:{...dn,marginLeft:10,padding:"2px 8px"},onClick:()=>I(null),children:"Dismiss"})]}):null,C.running?f.jsxs("div",{"data-testid":"render-status",style:kj,children:[f.jsx("style",{children:"@keyframes ossclip-spin { to { transform: rotate(360deg) } }"}),f.jsx("span",{style:Cj,"aria-hidden":!0}),f.jsxs("span",{style:{color:"#EDEDF2"},children:["rendering",C.startedAt!=null?` · ${ij(C.startedAt,Date.now())}`:"",na(C.lines)!==null?` · ${na(C.lines)}%`:""]}),na(C.lines)!==null?f.jsx("div",{style:Ij,children:f.jsx("div",{"data-testid":"render-progress-bar",style:{...Tj,width:`${na(C.lines)}%`}})}):null,f.jsx("button",{"data-testid":"render-cancel",style:{...dn,padding:"2px 8px"},onClick:()=>void fetch("/api/render/cancel",{method:"POST"}),children:"Cancel"}),f.jsx("button",{"data-testid":"render-logs-toggle",style:{...dn,padding:"2px 8px"},onClick:()=>le(H=>!H),title:ge?"Collapse the log":"Expand the log",children:ge?"▾ logs":"▸ logs"})]}):null,ge?f.jsxs(f.Fragment,{children:[oj(C.lines).map(H=>f.jsx("div",{"data-testid":"render-pinned",style:{color:"#C9C9D4"},children:H},H)),f.jsx(aj,{lines:C.lines})]}):null]}):null,f.jsxs("div",{style:hj,children:[G?f.jsxs(f.Fragment,{children:[f.jsx(xM,{baseLines:(t==null?void 0:t.baseCaptionLines)??(t==null?void 0:t.captionLines)??[],liveLines:se.captionLines,fps:se.settings.fps,playerRef:V,edits:e,width:ne}),f.jsx("div",{"data-testid":"transcript-divider",style:gj,title:"Drag to resize the transcript pane",onMouseDown:H=>{H.preventDefault(),ee.current={startX:H.clientX,startW:ne}}})]}):null,f.jsxs("div",{style:vj,children:[f.jsx("div",{ref:R,style:yj,onMouseDown:H=>{if(H.altKey||H.button===1){H.preventDefault();const X=_.current;X&&(K.current={x:H.clientX,y:H.clientY,sl:X.scrollLeft,st:X.scrollTop})}},children:f.jsx("div",{style:{margin:"auto",padding:Xu},children:f.jsxs("div",{ref:A,"data-testid":"stage","data-playing":u?"true":"false","data-rate":p,style:{position:"relative",display:"inline-block"},children:[f.jsx(OI,{ref:V,component:z4,inputProps:se,durationInFrames:Math.max(1,Math.round(se.outputDurationSec*se.settings.fps)),fps:se.settings.fps,compositionWidth:se.settings.width,compositionHeight:se.settings.height,style:{width:Xt},controls:!0,clickToPlay:!1,playbackRate:p}),f.jsx(K4,{stageRef:A,selection:a,onSelect:l,edits:e,onSave:We,settings:se.settings,cues:se.sceneCues,playerRef:V,cue:Ge,onTransport:q,onVideoPreview:w,onGraphicPreview:P,onToggleHelp:()=>me(H=>!H)}),f.jsx("button",{"data-testid":"rate-chip",onClick:()=>q("L"),title:"Playback rate — click to speed up (J/K/L on the keyboard)",style:_j,children:p<0?`◂◂ ${Math.abs(p)}×`:`${p}×`})]})})}),f.jsxs("div",{style:wj,children:[f.jsx("button",{"data-testid":"view-zoom-out",style:Gu,onClick:()=>D($/2),disabled:$<=.25,title:"Zoom the preview out — below 100% shrinks under the fitted size",children:"−"}),f.jsxs("span",{"data-testid":"view-zoom-level",style:xj,children:[Math.round($*100),"%"]}),f.jsx("button",{"data-testid":"view-zoom-in",style:Gu,onClick:()=>D($*2),disabled:$>=8,title:"Zoom the preview in — a viewing magnifier, it never edits the video",children:"+"}),f.jsx("button",{"data-testid":"view-zoom-fit",style:{...Gu,width:"auto",padding:"0 8px"},onClick:()=>D(1),disabled:Math.abs($-1)<.001,title:"Fit the preview to the window",children:"fit"}),f.jsx("span",{style:bj,children:"⌥-drag pans"})]})]}),f.jsx("div",{style:Sj,children:f.jsx(G4,{selection:a,cue:Ge,frame:{width:se.settings.width,height:se.settings.height},allSceneIds:se.sceneCues.map(H=>H.id),edits:e,resolvedTheme:se.theme,anchorText:lt,onVideoPreview:w,runInfo:r})})]}),f.jsx(uM,{cues:se.sceneCues,ghosts:nt,durationSec:se.outputDurationSec,fps:se.settings.fps,playerRef:V,selection:a,onSelect:l,edits:e,videoSrc:se.videoFileName,toSourceSec:H=>{var X;for(const Q of se.spans??[])if(H>=Q.outIn&&H<Q.outOut)return Q.srcIn+(H-Q.outIn);return((X=(se.spans??[])[0])==null?void 0:X.srcIn)??H}})]})},aj=({lines:e})=>{const t=c.useRef(null),n=c.useRef(!0);return c.useEffect(()=>{const r=t.current;r&&n.current&&(r.scrollTop=r.scrollHeight)},[e]),f.jsx("div",{ref:t,"data-testid":"render-tail",onScroll:r=>{const o=r.currentTarget;n.current=o.scrollTop+o.clientHeight>=o.scrollHeight-8},style:{maxHeight:220,overflowY:"auto"},children:e.map((r,o)=>f.jsx("div",{children:r},o))})},lj=()=>f.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.4",strokeLinecap:"round",strokeLinejoin:"round",style:{display:"block"},children:[f.jsx("path",{d:"M9 14 4 9l5-5"}),f.jsx("path",{d:"M4 9h10.5a5.5 5.5 0 0 1 0 11H11"})]}),uj=()=>f.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.4",strokeLinecap:"round",strokeLinejoin:"round",style:{display:"block"},children:[f.jsx("path",{d:"m15 14 5-5-5-5"}),f.jsx("path",{d:"M20 9H9.5a5.5 5.5 0 0 0 0 11H13"})]}),Ku={fontFamily:"'Inter', system-ui, sans-serif",background:"#0B0B0E",color:"#EDEDF2",height:"100vh",overflow:"hidden",display:"flex",flexDirection:"column"},cj={display:"flex",alignItems:"center",gap:14,padding:"10px 20px",borderBottom:"1px solid #1E1E24",background:"#111116"},dj={fontWeight:800,fontSize:14,letterSpacing:"0.02em",color:"#FFE14D",marginRight:8},fj={fontSize:12,fontFamily:"ui-monospace, 'SF Mono', monospace",color:"#6a6a75",maxWidth:260,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},pj={fontSize:12,fontFamily:"ui-monospace, 'SF Mono', monospace",marginLeft:"auto"},dn={fontSize:12,fontWeight:600,color:"#EDEDF2",background:"#1A1A21",border:"1px solid #2A2A33",borderRadius:6,padding:"7px 12px",cursor:"pointer"},mj={background:"#FFE14D",color:"#0B0B0E",border:"1px solid #FFE14D"},hj={display:"flex",flex:1,minHeight:0},Xu=32,Hh="ossclip.transcriptWidth",Zh=e=>Math.min(640,Math.max(220,e)),gj={width:5,flexShrink:0,cursor:"col-resize",background:"#1E1E24",borderLeft:"1px solid #2A2A33"},vj={position:"relative",flex:1,minWidth:0},yj={position:"absolute",inset:0,display:"flex",overflow:"auto"},wj={position:"absolute",top:10,left:10,zIndex:6,display:"flex",alignItems:"center",gap:6,padding:"4px 6px",background:"rgba(17,17,22,0.85)",border:"1px solid #2A2A33",borderRadius:6},Gu={width:22,height:18,fontSize:12,lineHeight:1,color:"#EDEDF2",background:"#1A1A21",border:"1px solid #2A2A33",borderRadius:4,cursor:"pointer",padding:0},xj={fontSize:10,fontFamily:"ui-monospace, 'SF Mono', monospace",color:"#9A9AA3",minWidth:34,textAlign:"center"},bj={fontSize:10,color:"#55555f",userSelect:"none"},Sj={width:260,flexShrink:0,borderLeft:"1px solid #1E1E24",background:"#111116",overflowY:"auto"},Ej={fontSize:11,fontFamily:"ui-monospace, 'SF Mono', monospace",color:"#9A9AA3",background:"#0F0F14",borderBottom:"1px solid #2A2A33",padding:"6px 20px",whiteSpace:"pre-wrap",flexShrink:0},kj={display:"flex",alignItems:"center",gap:10,marginBottom:4},Cj={width:12,height:12,flexShrink:0,border:"2px solid #2A2A33",borderTopColor:"#FFE14D",borderRadius:"50%",animation:"ossclip-spin 0.8s linear infinite"},Ij={flex:1,maxWidth:260,height:4,background:"#1E1E24",borderRadius:2,overflow:"hidden"},Tj={height:"100%",background:"#FFE14D",borderRadius:2,transition:"width 0.6s ease"},_j={position:"absolute",top:8,right:8,zIndex:5,fontSize:11,fontWeight:700,fontFamily:"ui-monospace, 'SF Mono', monospace",color:"#FFE14D",background:"rgba(11,11,14,0.75)",border:"1px solid #2A2A33",borderRadius:6,padding:"3px 8px",cursor:"pointer"};qu.createRoot(document.getElementById("root")).render(f.jsx(J.StrictMode,{children:f.jsx(sj,{})}));
@@ -4,7 +4,7 @@
4
4
  <meta charset="UTF-8" />
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
6
  <title>ossclip editor</title>
7
- <script type="module" crossorigin src="/assets/index-CI9c6j62.js"></script>
7
+ <script type="module" crossorigin src="/assets/index-B5H_dKAW.js"></script>
8
8
  </head>
9
9
  <body>
10
10
  <div id="root"></div>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ossclip",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "description": "Local-first CLI video producer: cuts silence and fillers, word-timed captions, face-aware framing, and LLM-planned code-rendered graphics — transcription and rendering never leave your machine",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -35,9 +35,9 @@
35
35
  "commander": "^12.1.0",
36
36
  "tsx": "^4.19.0",
37
37
  "zod": "^3.25.76",
38
- "@ossclip/renderer": "0.1.1",
39
- "@ossclip/core": "0.1.1",
40
- "@ossclip/scenes": "0.1.1"
38
+ "@ossclip/scenes": "0.1.3",
39
+ "@ossclip/core": "0.1.3",
40
+ "@ossclip/renderer": "0.1.3"
41
41
  },
42
42
  "homepage": "https://github.com/AhsanAyaz/ossclip#readme",
43
43
  "bugs": {
package/src/index.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  #!/usr/bin/env tsx
2
2
  import { spawn } from "node:child_process";
3
+ import { readFileSync } from "node:fs";
3
4
  import { dirname, resolve } from "node:path";
4
5
  import { Command, InvalidArgumentError } from "commander";
5
6
  import { z } from "zod/v4";
@@ -20,7 +21,18 @@ program
20
21
  "local-first video producer: cuts silence and fillers, word-timed captions, " +
21
22
  "face-aware framing, LLM-planned code-rendered graphics",
22
23
  )
23
- .version("0.1.0");
24
+ // Read from the manifest, never hardcoded (R22 §113): a literal here said
25
+ // "0.1.0" for every release after it, so `--version` reported the number a
26
+ // developer typed rather than the one npm installed — the exact field a
27
+ // bug report is judged by. npm always packs package.json regardless of
28
+ // `files`, so this resolves in a published install too.
29
+ .version(
30
+ (
31
+ JSON.parse(
32
+ readFileSync(new URL("../package.json", import.meta.url), "utf8"),
33
+ ) as { version: string }
34
+ ).version,
35
+ );
24
36
 
25
37
  program
26
38
  .command("produce")
package/src/produce.ts CHANGED
@@ -990,6 +990,31 @@ export async function produce(inputArg: string, opts: ProduceOptions): Promise<v
990
990
  console.log(` ⚠ CTA keyword dropped — ${r.reason}`);
991
991
  }
992
992
 
993
+ // ScreenshotFrame `src` must name a file that EXISTS (R22 §112). The
994
+ // producer reads the transcript and will happily invent a plausible
995
+ // filename from it — a take that says "CLAUDE.md" produced
996
+ // `src: "claude.md"` — and Remotion treats an unloadable image as a fatal
997
+ // render error, so the whole run died at 40% after four minutes of work.
998
+ // The prop is optional and the component already draws a styled
999
+ // placeholder without it, so dropping the bad reference degrades exactly
1000
+ // the way the schema intended. Checked against the two directories that
1001
+ // can become the render's public dir: the workdir (mezzanine path) and
1002
+ // the source's own folder (--no-mezzanine).
1003
+ const srcRejections: Array<{ sceneId: string; src: string }> = [];
1004
+ for (const holder of [...scenes, ...graphicCues]) {
1005
+ const src = holder.props?.src;
1006
+ if (typeof src !== "string" || src.length === 0) continue;
1007
+ if (existsSync(join(work, src)) || existsSync(join(dirname(input), src))) continue;
1008
+ delete (holder.props as Record<string, unknown>).src;
1009
+ srcRejections.push({ sceneId: holder.id, src });
1010
+ }
1011
+ for (const r of [...new Map(srcRejections.map((r) => [r.src, r])).values()]) {
1012
+ console.log(
1013
+ ` ⚠ image "${r.src}" does not exist beside the video — ` +
1014
+ "rendering the frame as a placeholder instead",
1015
+ );
1016
+ }
1017
+
993
1018
  const production: Production = {
994
1019
  version: 1,
995
1020
  source: { path: input, probe: sourceProbe, audioPath, face: faceBox },