clipoox-render 0.2.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/server-text/titleRaster.js +1413 -0
- package/package.json +5 -3
- package/scripts/render-local.mjs +1514 -1379
- package/shared/transitionStarterPack.json +616 -0
- package/web/assets/{FxEmbed-BymBArNa.js → FxEmbed-CGqGi2Lw.js} +1 -1
- package/web/assets/{GLTFLoader-Dy6SrZg8.js → GLTFLoader-BHWu1lKg.js} +1 -1
- package/web/assets/{MotionEmbed-PmXWSWe5.js → MotionEmbed-C3CZ3_y_.js} +1 -1
- package/web/assets/PluginStore-DKXZ-jBj.js +3 -0
- package/web/assets/{ShotComposer-Dprx-Yi7.js → ShotComposer-DFfaYLoV.js} +4 -4
- package/web/assets/TemplateEmbed-C8pXcPsc.js +2 -0
- package/web/assets/TimelinePlugins-DYarX9RK.css +1 -0
- package/web/assets/TimelinePlugins-DnkV3i4G.js +5 -0
- package/web/assets/TimelineShotFx-foiuuogg.js +2 -0
- package/web/assets/TransitionEmbed-BueDilY0.js +1 -0
- package/web/assets/{Whiteboard-DybaKCdo.js → Whiteboard-zBsNHh5h.js} +3 -3
- package/web/assets/aerial-z34Nww_T.js +2 -0
- package/web/assets/{agentTools-CxZqRLeR.js → agentTools-ALxghYpf.js} +2 -2
- package/web/assets/analyzerRun-DNwryAlU.js +1 -0
- package/web/assets/{analyzerSandbox-DO5ZTv5q.js → analyzerSandbox-A1oFsCrO.js} +2 -2
- package/web/assets/{api-BsKbf3l3.js → api-DUp403BK.js} +158 -158
- package/web/assets/auraTrack-BKVZCwNt.js +1 -0
- package/web/assets/breakthrough-Cwt8gEwK.js +2 -0
- package/web/assets/{cameraPresets-B234aNzE.js → cameraPresets-DSOPj4oy.js} +1 -1
- package/web/assets/{captionLayout-CNgb471H.js → captionLayout-EuB59pN_.js} +1 -1
- package/web/assets/clientExport-BL1XMTF0.js +1 -0
- package/web/assets/depthEstimate-DOvsY8mn.js +1 -0
- package/web/assets/{directorTools-BqFcShgT.js → directorTools-BkbNYbSq.js} +1 -1
- package/web/assets/{distortFrames-D3TQNcJA.js → distortFrames-Drch0LhT.js} +2 -2
- package/web/assets/{distortGL-BklPDXPq.js → distortGL-BlmBZKRU.js} +2 -2
- package/web/assets/{editTools-BQlG5WB_.js → editTools-BcGinqHC.js} +1 -1
- package/web/assets/{exportEncode-CaKEPgsy.js → exportEncode-MUwVTI52.js} +1 -1
- package/web/assets/{exportGlb-DstxwzH5.js → exportGlb-SIXFRRJM.js} +1 -1
- package/web/assets/faceTracker-DCbZbLMc.js +1 -0
- package/web/assets/fightDirector-hlF1JS_z.js +1 -0
- package/web/assets/fightDrama-fHN5EXk3.js +2 -0
- package/web/assets/{frameSink-Dj71jCRb.js → frameSink-BvOXjLuw.js} +3 -3
- package/web/assets/{gpuCompose-DIxBHlTa.js → gpuCompose-CNkLwpbZ.js} +1 -1
- package/web/assets/gpuExport-DQB6x4eh.js +194 -0
- package/web/assets/handMatte-BD7OE3Zc.js +1 -0
- package/web/assets/handTracker-BumGtRCW.js +2 -0
- package/web/assets/{index-CZn97Ygs.js → index-CuaB7Y0L.js} +1 -1
- package/web/assets/layer-worker-DxPMMKIZ.js +5 -0
- package/web/assets/library-CyjJ8nGG.js +1 -0
- package/web/assets/{lottieLayer-CfUPParC.js → lottieLayer-1ET89OUr.js} +5 -5
- package/web/assets/{lottie_light_canvas-7iv3btPX.js → lottie_light_canvas-DD9pkFL8.js} +1 -1
- package/web/assets/main-BKjBWQik.js +309 -0
- package/web/assets/{main-BPmr0TOL.css → main-Ca_CVxMz.css} +1 -1
- package/web/assets/mapBake-DLoBt_k5.js +1 -0
- package/web/assets/maskTrack-C2SJbDGO.js +1 -0
- package/web/assets/matteFixRun-BdHKC3m5.js +1 -0
- package/web/assets/{objectLocate-BDqfSo9J.js → objectLocate-bZtc5AJo.js} +1 -1
- package/web/assets/{objectTrack.worker-ENzKeSiV.js → objectTrack.worker-BlZkgpOX.js} +483 -352
- package/web/assets/pendingMatte-mlyLLZCT.js +2 -0
- package/web/assets/personAi-CUNQeseG.js +2 -0
- package/web/assets/plateCamera-_jP1xXnj.js +1 -0
- package/web/assets/{plateCameraMatch-D41LQrsm.js → plateCameraMatch-rr0oUwQ2.js} +2 -2
- package/web/assets/{plateFollow-CNfi4xuP.js → plateFollow-BjvtcT8q.js} +2 -2
- package/web/assets/plateMatte-BqyL8cQZ.js +2 -0
- package/web/assets/{pluginAutomation-BtQ_w2TB.js → pluginAutomation-Dp188qm7.js} +1 -1
- package/web/assets/poseTracker-DDGDhhMF.js +1 -0
- package/web/assets/{productTools-r2RgILaA.js → productTools-CRgI88-O.js} +2 -2
- package/web/assets/remote-Dva2qg58.js +1241 -0
- package/web/assets/{rigTrack-Bx9QHlFv.js → rigTrack-UYZU4P-e.js} +1 -1
- package/web/assets/{rotoMaskStore-pxpRt5Cj.js → rotoMaskStore-BxyxB2bD.js} +1 -1
- package/web/assets/{rotoMatte-DyXlW4jK.js → rotoMatte-BdYa8FSB.js} +1 -1
- package/web/assets/{rotoscope-GORCSVBr.js → rotoscope-DDixNQCt.js} +1 -1
- package/web/assets/{sceneTrack.worker-CEvCN5OB.js → sceneTrack.worker-CT4uoTKn.js} +475 -344
- package/web/assets/{shot-worker-B8JWkmBz.js → shot-worker-D9sZS6bn.js} +1 -1
- package/web/assets/{shotFxAgent-CzHfe75S.js → shotFxAgent-7RQNtEe4.js} +2 -2
- package/web/assets/{skin-BkaT2QuX.js → skin-CVwmK130.js} +1 -1
- package/web/assets/{spark.module-BRT8yMS4.js → spark.module-B34aiScb.js} +1 -1
- package/web/assets/{spellDuel-BUy289OT.js → spellDuel-BkweL6pI.js} +2 -2
- package/web/assets/{store-BSSbvpzr.js → store-75tQUvPT.js} +1 -1
- package/web/assets/{surfaceLight-CMaBhZ_d.js → surfaceLight-DhU-zgNL.js} +1 -1
- package/web/assets/surfacePin-ObK6QgDm.js +2 -0
- package/web/assets/textAnimators-nVSz_sZo.js +1 -0
- package/web/assets/{thumb-Cs636sYt.js → thumb-r6dlZprA.js} +1 -1
- package/web/assets/timeline3d-246tBEJl.js +2 -0
- package/web/assets/timeline3dExport-T57qnWi9.js +1 -0
- package/web/assets/{timelineComp-CRRzLazc.js → timelineComp-BcewYGR2.js} +1 -1
- package/web/assets/{timelineProps-tN2YsMYN.js → timelineProps-CJzzAWWO.js} +1 -1
- package/web/assets/{timelineText-CkoUgWcY.js → timelineText-BzUhNWPB.js} +1 -1
- package/web/assets/titleArt-B8DVR58F.js +5 -0
- package/web/assets/{titleFrameBudget-3MFHWIT6.js → titleFrameBudget-BYRZAQPs.js} +970 -839
- package/web/assets/titleFrames-BVgm601q.js +1 -0
- package/web/assets/{tool-BhIsq238.js → tool-CAGU3dUa.js} +1 -1
- package/web/assets/{tools-DMUnabc_.js → tools-DVaOkokV.js} +1 -1
- package/web/assets/{toonTools-CICrV3QB.js → toonTools-CfGTR_H1.js} +2 -2
- package/web/assets/trackAnchor-DzUt1r5Q.js +1 -0
- package/web/assets/{userFonts-BZ4QL-zq.js → userFonts-DzY0A4bD.js} +1 -1
- package/web/assets/{vfxAlpha-D3Dk1tfF.js → vfxAlpha-DQJOaZ9v.js} +2 -2
- package/web/assets/vfxBackground-DiktQFOD.js +2 -0
- package/web/assets/{videoExport-l5MGvMn_.js → videoExport-Ce0ElSQR.js} +1 -1
- package/web/assets/{views-BdWnG2xK.js → views-V3si1lOz.js} +1 -1
- package/web/assets/{weaponDuel-B2wTffPC.js → weaponDuel-D6sLVGmG.js} +1 -1
- package/web/assets/{windowFrames-CoIyWqxr.js → windowFrames-D_2QJCJJ.js} +1 -1
- package/web/layer-worker.html +3 -3
- package/web/assets/PluginStore-BVsm6n6N.js +0 -3
- package/web/assets/TemplateEmbed-CrZXoUk_.js +0 -2
- package/web/assets/TimelinePlugins-B1KGtbmb.js +0 -5
- package/web/assets/TimelinePlugins-B5WmAawO.css +0 -1
- package/web/assets/TimelineShotFx-DoLx312Y.js +0 -2
- package/web/assets/TransitionEmbed-C5SUosv2.js +0 -1
- package/web/assets/aerial-DSt_mJNA.js +0 -2
- package/web/assets/analyzerRun-DCJwb_-Z.js +0 -1
- package/web/assets/auraTrack-QR0WqBHp.js +0 -1
- package/web/assets/breakthrough-Dv1bndQb.js +0 -2
- package/web/assets/clientExport-NtJmxOYP.js +0 -1
- package/web/assets/depthEstimate-wVYSJtW8.js +0 -1
- package/web/assets/desktop-BWhFnYwd.js +0 -1
- package/web/assets/faceTracker-DWxxieVC.js +0 -1
- package/web/assets/fightDirector-OMlPZgjv.js +0 -1
- package/web/assets/fightDrama-G7bXfpQu.js +0 -2
- package/web/assets/gpuExport-CPSw_dmq.js +0 -189
- package/web/assets/handMatte-DHsHHz4m.js +0 -1
- package/web/assets/handTracker-D_O-C4Dw.js +0 -2
- package/web/assets/layer-worker-Bar7WgOA.js +0 -5
- package/web/assets/library-BtBrCaFk.js +0 -1
- package/web/assets/main-M1vRa-gd.js +0 -309
- package/web/assets/mapBake-lPNhNZgv.js +0 -1
- package/web/assets/maskTrack-D2jUh7aw.js +0 -1
- package/web/assets/matteFixRun-B7tWV9Y1.js +0 -1
- package/web/assets/pendingMatte-q35zVaiB.js +0 -2
- package/web/assets/personAi-ZjQVo-80.js +0 -2
- package/web/assets/plateCamera-A2E_WO_x.js +0 -1
- package/web/assets/plateMatte-BdIxGhw5.js +0 -2
- package/web/assets/poseTracker-DVX__OK7.js +0 -1
- package/web/assets/remote-sTZauTqM.js +0 -1220
- package/web/assets/surfacePin-DM9b9ubh.js +0 -2
- package/web/assets/textAnimators-Cihw35O8.js +0 -1
- package/web/assets/timeline3d-BEuZZOxM.js +0 -2
- package/web/assets/timeline3dExport-CmSI_pjv.js +0 -1
- package/web/assets/titleArt-CcTdJuOC.js +0 -5
- package/web/assets/titleFrames-w-iWje9N.js +0 -1
- package/web/assets/trackAnchor-D2bB5mZE.js +0 -1
- package/web/assets/vfxBackground-CHlCg8lb.js +0 -2
- package/web/assets/vfxTrack-CqiQDEYm.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{_ as Vo,f_ as Ct,eb as no,ec as vt,cb as Gt,kb as ko,ea as wt,d5 as yt,fu as it,fl as Bo,f$ as yo,fN as Uo,iI as Go,au as Et,F as ut,b_ as Jo,jk as go,mD as bo,mE as Qo,ig as so,ie as ro,ji as Zo,fp as Ho,jm as xo,mF as wo,mG as Wo,mH as ao,mI as te,mJ as oe,jl as Jt,jn as ee,cA as vo,dB as Yt,kd as ne,mK as se}from"./titleFrameBudget-3MFHWIT6.js";import{bV as re,bW as ae}from"./api-BsKbf3l3.js";const qt=.1,Kt=t=>Math.abs(t)>180?(t%360+540)%360-180:t;function Eo(t,o,s,n,e,a,r,l,i){const c=l-r,f=t==null?s-o:(s-t)/Math.max(1e-9,l-a)*c,h=n==null?s-o:(n-o)/Math.max(1e-9,i-r)*c,p=e*e,u=p*e;return(2*u-3*p+1)*o+(u-2*p+e)*f+(-2*u+3*p)*s+(u-p)*h}function Ao(t,o,s,n,e,a,r,l,i){const c=o+Kt(s-o),f=t==null?null:o+Kt(t-o),h=n==null?null:c+Kt(n-c);return Eo(f,o,c,h,e,a,r,l,i)}function ie(t,o,s=n=>n.time){if(globalThis.__clipooxLinearKeys)return!1;const n=(e,a)=>s(t[a])-s(t[e]);return!(n(o,o+1)>qt||o>0&&n(o-1,o)>qt||o+2<t.length&&n(o+1,o+2)>qt)}function Qt(t,o,s,n){let e=o>0,a=o+2<t.length;if(n!=null){const l=e?s(t[o-1]):null,i=s(t[o]),c=s(t[o+1]),f=a?s(t[o+2]):null;if(i<n-1e-9&&c>=n-1e-9)return{before:!1,after:!1};a&&c<n-1e-9&&f>=n-1e-9&&(a=!1),e&&i>=n-1e-9&&l<n-1e-9&&(e=!1)}return{before:e,after:a}}function Be(t,o,s,n=r=>r.pose,e=r=>r.time,a=null){const r=Qt(t,o,e,a),l=n(t[o]),i=n(t[o+1]),c=r.before?n(t[o-1]):null,f=r.after?n(t[o+2]):null,h=e(t[o]),p=e(t[o+1]),u=c?e(t[o-1]):h-(p-h),m=f?e(t[o+2]):p+(p-h),y={};for(const M of new Set([...Object.keys(l),...Object.keys(i)])){const d=l[M]??0,x=i[M]??0;if(typeof d!="number"||typeof x!="number")continue;const g=c&&typeof c[M]=="number"?c[M]:null,w=f&&typeof f[M]=="number"?f[M]:null;y[M]=Ao(g,d,x,w,s,u,h,p,m)}return y}function le(t,o,s,n=r=>r.position,e=r=>r.time,a=null){const r=Qt(t,o,e,a),l=n(t[o]),i=n(t[o+1]),c=r.before?n(t[o-1]):null,f=r.after?n(t[o+2]):null,h=e(t[o]),p=e(t[o+1]),u=c?e(t[o-1]):h-(p-h),m=f?e(t[o+2]):p+(p-h);return l.map((y,M)=>Eo(c?c[M]:null,y,i[M],f?f[M]:null,s,u,h,p,m))}function ce(t,o,s,n,e=r=>r.time,a=null){const r=Qt(t,o,e,a),l=n(t[o]),i=n(t[o+1]),c=r.before?n(t[o-1]):null,f=r.after?n(t[o+2]):null,h=e(t[o]),p=e(t[o+1]),u=c!=null?e(t[o-1]):h-(p-h),m=f!=null?e(t[o+2]):p+(p-h);return Ao(c,l,i,f,s,u,h,p,m)}const At=30,io=4,bt=Object.freeze({min:.25,max:6,default:3}),It=40,Po=300,Co=Object.freeze({position:.01,rotation:2}),So=80,To=Object.freeze(["here","above","explode","throw"]),$t=Object.freeze({bouncy:Object.freeze({restitution:.6,friction:.45}),normal:Object.freeze({restitution:.25,friction:.6}),heavy:Object.freeze({restitution:.04,friction:.9})}),fe=9.81;let Nt=null,Io=null;const Ro=()=>Io;function _o(){return Nt??=(async()=>{const t=await Vo(()=>import("./rapier-DBjBuyhF.js"),[]),o=t.default??t,s=console.warn;console.warn=(...n)=>{String(n[0]).includes("deprecated parameters")||s(...n)};try{await o.init()}finally{console.warn=s}return Io=o,o})().catch(t=>{throw Nt=null,t}),Nt}const ot=t=>typeof t=="number"&&Number.isFinite(t),Y=(t,o)=>Array.isArray(t)&&t.length===3&&t.every(ot)?[t[0],t[1],t[2]]:o,Q=Math.PI/180,St=t=>(t%360+540)%360-180,Tt=t=>Math.round(t*1e4)/1e4,Vt=t=>Math.round(t*100)/100;function Pt(t){const o=Math.cos(t[0]*Q/2),s=Math.cos(t[1]*Q/2),n=Math.cos(t[2]*Q/2),e=Math.sin(t[0]*Q/2),a=Math.sin(t[1]*Q/2),r=Math.sin(t[2]*Q/2);return[e*s*n+o*a*r,o*a*n-e*s*r,o*s*r+e*a*n,o*s*n-e*a*r]}function jo(t){const[o,s,n,e]=t,a=1-2*(s*s+n*n),r=2*(o*s-n*e),l=2*(o*n+s*e),i=1-2*(o*o+n*n),c=2*(s*n-o*e),f=2*(s*n+o*e),h=1-2*(o*o+s*s),p=Math.asin(Math.max(-1,Math.min(1,l)));return Math.abs(l)<.9999999?[Math.atan2(-c,h)/Q,p/Q,Math.atan2(-r,a)/Q]:[Math.atan2(f,i)/Q,p/Q,0]}const lo=(t,o)=>{const[s,n,e,a]=t,r=a*o[0]+n*o[2]-e*o[1],l=a*o[1]+e*o[0]-s*o[2],i=a*o[2]+s*o[1]-n*o[0],c=-s*o[0]-n*o[1]-e*o[2];return[r*a+c*-s+l*-e-i*-n,l*a+c*-n+i*-s-r*-e,i*a+c*-e+r*-n-l*-s]},Do=(t,o)=>2*Math.acos(Math.min(1,Math.abs(t[0]*o[0]+t[1]*o[1]+t[2]*o[2]+t[3]*o[3])))/Q;function Fo(t){let o=2166136261;for(const n of String(t))o=Math.imul(o^n.codePointAt(0),16777619);let s=o>>>0;return()=>{s=s+1831565813|0;let n=Math.imul(s^s>>>15,1|s);return n=n+Math.imul(n^n>>>7,61|n)^n,((n^n>>>14)>>>0)/4294967296}}const co=new Set(["box","sphere","cylinder","wall","platform"]),he=new Set(["person","fx","splat","set","floor"]);function ue(t){return t?t.locked?"Đối tượng đang khoá":t.hold?"Đồ đang cầm đi theo tay người cầm":t.kind==="person"||t.kind==="model"&&(t.skeleton==="native"||t.rig?.kind==="humanoid")?"Nhân vật không rơi như vật thể — dùng chuyển động":he.has(t.kind)?"Loại đối tượng này không rơi được":null:"Chưa chọn đối tượng"}function pe(t){const o=Y(t.scale,[1,1,1]);return t.kind==="sphere"&&Math.abs(o[0]-o[1])<1e-6&&Math.abs(o[1]-o[2])<1e-6||t.kind==="prop"&&t.prop?.kind==="ball"?"ball":t.kind==="cylinder"&&Math.abs(o[0]-o[2])<1e-6?"cylinder":"box"}function me(t){const o=Y(t.scale,[1,1,1]).map(Math.abs),s=Y(t.mirror,[1,1,1]),n=Y(t.origin,[0,0,0]);let e=[1,1,1],a=[0,.5,0];if(t.kind==="proxy"&&t.proxy?.dims)e=Y(t.proxy.dims,e),a=[0,e[1]/2,0];else if(t.kind==="prop"){const i=t.prop?.kind==="ball"?.12:.15;e=[2*i,2*i,2*i],a=[0,t.prop?.kind==="ball"?0:i,0]}else if(t.kind==="model"){const i=t.model?.height??2;e=[i*.6,i,i*.6],a=[0,i/2,0]}else co.has(t.kind)||(e=[.5,.5,.5],a=[0,.25,0]);const r=co.has(t.kind)?[(a[0]-n[0])*s[0],(a[1]-n[1])*s[1],(a[2]-n[2])*s[2]]:a,l=i=>[i[0]*(t.scale?.[0]??1),i[1]*(t.scale?.[1]??1),i[2]*(t.scale?.[2]??1)];return{half:[e[0]*o[0]/2,e[1]*o[1]/2,e[2]*o[2]/2],offset:l(r)}}function de(t,o){let s=0,n=t.length-1;for(;n-s>1;){const e=s+n>>1;t[e].time<=o?s=e:n=e}return s}function zo(t,o,s=null,n=null){const e=t[0],a=t[t.length-1];if(o<=e.time)return{position:e.position,rotation:e.rotation};if(o>=a.time)return{position:a.position,rotation:a.rotation};const r=de(t,o),l=t[r],i=t[r+1],c=(o-l.time)/(i.time-l.time),f=h=>l.rotation[h]+St(i.rotation[h]-l.rotation[h])*c;return ie(t,r,n>0?h=>h.time*n:void 0)?{position:le(t,r,c,h=>h.position,h=>h.time,s),rotation:[f(0),ce(t,r,c,h=>h.rotation[1],h=>h.time,s),f(2)]}:{position:[0,1,2].map(h=>l.position[h]+(i.position[h]-l.position[h])*c),rotation:[f(0),f(1),f(2)]}}function qo(t,{tolerance:o=Co,maxKeys:s=So,before:n=null,seam:e=null,duration:a=null}={}){const r=t.length;if(r<=2)return{keys:t.map(({time:f,position:h,rotation:p})=>({time:f,position:h,rotation:p})),error:{position:0,rotation:0}};const l=new Set([0,r-1]),i=()=>[...l].sort((f,h)=>f-h).map(f=>t[f]);let c={position:0,rotation:0};for(;;){const f=i(),h=n?[n,...f]:f;let p=-1,u=1;c={position:0,rotation:0};for(let m=1;m<r-1;m++){if(l.has(m))continue;const y=t[m],M=zo(h,y.time,e,a),d=Math.hypot(M.position[0]-y.position[0],M.position[1]-y.position[1],M.position[2]-y.position[2]),x=Do(Pt(M.rotation),y.quat);c={position:Math.max(c.position,d),rotation:Math.max(c.rotation,x)};const g=Math.max(d/o.position,x/o.rotation);g>u&&(u=g,p=m)}if(p<0||l.size>=s)break;l.add(p)}return{keys:i().map(({time:f,position:h,rotation:p})=>({time:f,position:h,rotation:p})),error:{position:Tt(c.position),rotation:Vt(c.rotation)}}}const Me=t=>ot(t)?{restitution:Math.max(0,Math.min(.95,t)),friction:.6}:$t[t]??$t.normal;async function ye(t){const o=Zt(await _o(),t),{duration:s,mode:n}=o,e=ot(t.start)?Math.max(0,t.start):0,a=ot(t.shotDuration)&&t.shotDuration>0?t.shotDuration:e+s,r={},l=e/a;for(const i of o.bodies){let c=null;const f=i.samples.map(m=>{let y=jo(m.q);if(c){const M=[y[0]+180,180-y[1],y[2]+180],d=x=>x.reduce((g,w,b)=>g+Math.abs(St(w-c[b])),0);d(M)<d(y)&&(y=M)}return y=y.map(M=>Vt(St(M)===-180?180:St(M))),c=y,{time:l+m.sec/a,position:m.pivot.map(Tt),rotation:y,quat:Pt(y)}}),h=t.before?.[i.id],{keys:p,error:u}=qo(f,{before:h&&ot(h.time)&&h.time<l?h:null,seam:ot(t.seam)?t.seam:null,duration:a});r[i.id]={keys:p,error:u,settledAt:i.settledAt,from:{position:i.position.map(Tt),rotation:i.rotation.map(Vt)},rest:f[f.length-1].position,restCentre:i.samples[i.samples.length-1].centre.map(Tt),restQuat:i.samples[i.samples.length-1].q}}return{tracks:r,settled:o.settled,seconds:s,mode:n}}function Zt(t,o){const s=!!o.planar,n=To.includes(o.mode)?o.mode:"here",e=Math.max(bt.min,Math.min(bt.max,ot(o.duration)?o.duration:bt.default)),a=ot(o.floor)?o.floor:0,r=Me(o.bounciness),l=Fo(`${o.seed??"drop"}|${n}`),i=m=>(l()*2-1)*m,c=(o.bodies||[]).filter(m=>m&&m.id!=null).map(m=>({id:String(m.id),shape:["ball","cylinder"].includes(m.shape)?m.shape:"box",position:Y(m.position,[0,0,0]),rotation:Y(m.rotation,[0,0,0]),half:Y(m.half,[.25,.25,.25]).map(y=>Math.max(.01,Math.abs(y))),offset:Y(m.offset,[0,0,0])})).sort((m,y)=>m.id<y.id?-1:m.id>y.id?1:0).slice(0,It);if(!c.length)throw new Error("no objects to drop");const f=m=>Math.hypot(...m.half);for(const m of c){m.q=Pt(m.rotation);const y=lo(m.q,m.offset);m.c=[m.position[0]+y[0],m.position[1]+y[1],m.position[2]+y[2]],m.v=[0,0,0],m.w=[0,0,0]}if(n==="above"){const m=ot(o.height)?Math.max(.3,Math.min(20,o.height)):2,y=Math.max(...c.map(d=>d.c[1]+f(d))),M=[];for(const d of[...c].sort((x,g)=>x.c[1]-g.c[1]||(x.id<g.id?-1:1))){d.q=Pt(s?[d.rotation[0],d.rotation[1],d.rotation[2]+i(35)]:[d.rotation[0]+i(35),d.rotation[1]+i(180),d.rotation[2]+i(35)]);let x=y+m+f(d);for(const g of M)Math.hypot(g.c[0]-d.c[0],g.c[2]-d.c[2])<f(g)+f(d)&&(x=Math.max(x,g.c[1]+f(g)+f(d)+.05));d.c=s?[d.c[0],x,d.c[2]]:[d.c[0]+i(.05),x,d.c[2]+i(.05)],M.push(d)}}if(n==="here")for(const m of c)m.w=[i(1.2),i(1.2),i(1.2)];const h=m=>s?[0,0,m[2]]:m,p=m=>s?[m[0],m[1],0]:m;if(n==="explode"){const m=Y(o.center,[0,1,2].map(M=>c.reduce((d,x)=>d+x.c[M],0)/c.length)),y=ot(o.strength)?Math.max(.5,Math.min(20,o.strength)):4;for(const M of c){let d=M.c[0]-m[0],x=s?0:M.c[2]-m[2],g=Math.hypot(d,x);if(g<.001){const b=l()*Math.PI*2;d=Math.cos(b),x=s?0:Math.sin(b),g=Math.hypot(d,x)||1}const w=y*(.75+l()*.5);M.v=[d/g*w,w*(.6+l()*.4),x/g*w],M.w=[i(7),i(7),i(7)]}}if(n==="throw"){const m=Y(o.velocity,[0,2,3]);for(const y of c)y.v=m.map(M=>M*(1+i(.08))),y.w=[i(5),i(5),i(5)]}const u=new t.World({x:0,y:-(ot(o.gravity)?o.gravity:fe),z:0});try{u.timestep=1/(At*io);for(const g of c)g.v=p(g.v),g.w=h(g.w);const m=(g,w)=>{const b=u.createRigidBody(t.RigidBodyDesc.fixed().setTranslation(g[0],g[1],g[2]));u.createCollider(t.ColliderDesc.cuboid(w[0],w[1],w[2]).setRestitution(r.restitution).setFriction(r.friction),b)};m([0,a-1,0],[1e3,1,1e3]);let y=0;for(const g of o.statics||[]){const w=Y(g?.min,null),b=Y(g?.max,null);if(!w||!b||y>=Po)continue;const v=[0,1,2].map(I=>(b[I]-w[I])/2);v.some(I=>!(I>.002))||b[1]<=a+.001||(m([0,1,2].map(I=>(w[I]+b[I])/2),v),y++)}for(const g of c){g.rb=u.createRigidBody(t.RigidBodyDesc.dynamic().setTranslation(g.c[0],g.c[1],g.c[2]).setRotation({x:g.q[0],y:g.q[1],z:g.q[2],w:g.q[3]}).setLinvel(g.v[0],g.v[1],g.v[2]).setAngvel({x:g.w[0],y:g.w[1],z:g.w[2]}).setLinearDamping(.05).setAngularDamping(g.shape==="box"?.2:1.2).setCcdEnabled(!0)),s&&(g.rb.setEnabledTranslations(!0,!0,!1,!1),g.rb.setEnabledRotations(!1,!1,!0,!1));const w=g.shape==="ball"?t.ColliderDesc.ball(Math.max(...g.half)):g.shape==="cylinder"?t.ColliderDesc.cylinder(g.half[1],Math.max(g.half[0],g.half[2])):t.ColliderDesc.cuboid(g.half[0],g.half[1],g.half[2]);u.createCollider(w.setRestitution(r.restitution).setFriction(r.friction).setDensity(400),g.rb),g.samples=[]}const M=Math.round(e*At);for(let g=0;g<=M;g++){if(g)for(let w=0;w<io;w++)u.step();for(const w of c){const b=w.rb.translation(),v=w.rb.rotation(),I=[v.x,v.y,v.z,v.w],T=lo(I,w.offset),D=w.rb.linvel(),q=w.rb.angvel();w.samples.push({sec:g/At,centre:[b.x,b.y,b.z],pivot:[b.x-T[0],b.y-T[1],b.z-T[2]],q:I,speed:Math.hypot(D.x,D.y,D.z)+Math.hypot(q.x,q.y,q.z)*f(w)})}}let d=!0;return{bodies:c.map(g=>{let w=null;for(let b=g.samples.length-1;b>=0&&g.samples[b].speed<.05;b--)w=g.samples[b].sec;return w==null&&(d=!1),{id:g.id,position:g.position,rotation:g.rotation,half:g.half,offset:g.offset,samples:g.samples,settledAt:w}}),settled:d,duration:e,mode:n}}finally{u.free()}}function ge(t,o,s,{scale:n={},newId:e,lifted:a=!1}={}){const r=e??(()=>globalThis.crypto.randomUUID());return{...t,shots:t.shots.map(l=>{if(l.id!==o)return l;const i={...l.objectKeys};for(const[c,f]of Object.entries(s)){if(!f.keys.length)continue;const h=f.keys[0].time,p=t.items.find(M=>M.id===c),u=Y(n[c],Y(p?.scale,[1,1,1])),m=(i[c]||[]).filter(M=>M.time<h-1e-6),y=1/(At*Math.max(1e-6,l.duration||1));a&&f.from&&m.length&&h-y>m[m.length-1].time+1e-6&&m.push({id:r(),time:h-y,position:[...f.from.position],rotation:[...f.from.rotation],scale:[...u]}),i[c]=[...m,...f.keys.map(M=>({id:r(),time:M.time,position:[...M.position],rotation:[...M.rotation],scale:[...u]}))]}return{...l,objectKeys:i}})}}const Ue=Object.freeze(Object.defineProperty({__proto__:null,BOUNCE_PRESETS:$t,DROP_MODES:To,DROP_SECONDS:bt,KEY_TOLERANCE:Co,MAX_KEYS_PER_BODY:So,MAX_PHYSICS_BODIES:It,MAX_PHYSICS_STATICS:Po,PHYSICS_FPS:At,applyDropKeys:ge,bakeDrop:ye,dropUnavailable:ue,eulerFromQuat:jo,fallbackShape:me,loadRapier:_o,quatAngle:Do,quatFromEuler:Pt,rapierReady:Ro,sampleBakedKeys:zo,seededRandom:Fo,shapeKind:pe,simulateDrop:Zt,thinKeys:qo},Symbol.toStringTag,{value:"Module"})),Ko=["x","y","zoom","rot","opacity","depth"],X=t=>Math.round(t*1e4)/1e4,Dt=(t,o)=>Object.keys(it).filter(s=>(!o||o.includes(s))&&Bo(t,s));function Ge(t,{in:o=.33,out:s=.33}={},n){const e=ko([Math.max(0,Math.min(1,s)),0,Math.max(0,Math.min(1,1-o)),1]);let a={...t},r={};for(const l of Dt(t)){const i=wt(a,l),c=n?n.filter(h=>h.prop===l):i;if(!c.length)continue;const f=i.map((h,p)=>p<i.length-1&&c.some(u=>Math.abs(u.time-h.time)<1/120)?{...h,ease:e}:h);r={...r,...yt(a,l,f)},a={...a,...r}}return r}const Ht={tl:[0,0],t:[.5,0],tr:[1,0],l:[0,.5],c:[.5,.5],r:[1,.5],bl:[0,1],b:[.5,1],br:[1,1]},Je=Object.keys(Ht);function Qe(t,o,s,n,e,a){const[r,l]=Ht[s],i=o.angle*Math.PI/180,c=Math.abs(o.w*Math.cos(i))+Math.abs(o.h*Math.sin(i)),f=Math.abs(o.w*Math.sin(i))+Math.abs(o.h*Math.cos(i)),h=c/2+(e-c)*r,p=f/2+(a-f)*l,u=(h-o.cx)/e,m=(p-o.cy)/a,y=(d,x)=>Math.max(it[d].min,Math.min(it[d].max,x));let M=no(t,"x",X(y("x",vt(t,"x",n)+u)),n);return M={...M,...no({...t,...M},"y",X(y("y",vt(t,"y",n)+m)),n)},M}function Ze(t,o,s,n,e,a){const[r,l]=Ht[s],i=Gt(t,n,e,a).zoom||1;return Go(t,n,X((r-.5)*o.w/(e*i)),X((l-.5)*o.h/(a*i)),e,a)}function He(t,o,s,n="forward",e=1){let a=t.filter(i=>o.includes(i.id)).sort((i,c)=>c.track-i.track||i.start-c.start);if(a.length<2)return t;if(n==="reverse")a.reverse();else if(n==="center"){const i=(a.length-1)/2;a=[...a].sort((c,f)=>Math.abs(a.indexOf(c)-i)-Math.abs(a.indexOf(f)-i))}else if(n==="random"){let i=e>>>0||1;const c=()=>(i=Math.imul(i^i>>>15,2246822507)>>>0)/4294967295;a=a.map(f=>[c(),f]).sort((f,h)=>f[0]-h[0]).map(f=>f[1])}const r=Math.min(...a.map(i=>i.start)),l=new Map(a.map((i,c)=>[i.id,X(Math.max(0,r+c*s))]));return t.map(i=>l.has(i.id)?{...i,start:Math.min(l.get(i.id),600-i.duration)}:i)}function We(t,o){const s={};for(const e of Dt(t)){const a=wt(t,e).filter(r=>!o||o.some(l=>l.prop===e&&Math.abs(l.time-r.time)<.008333333333333333));a.length&&(s[e]=a)}const n=Math.min(...Object.values(s).flat().map(e=>e.time));return Object.keys(s).length?{props:Object.fromEntries(Object.entries(s).map(([e,a])=>[e,a.map(r=>({...r,time:X(r.time-n)}))]))}:null}function tn(t,o,s){let n={...t},e={};for(const[a,r]of Object.entries(o.props)){if(!it[a]||t.kind==="model"&&a==="rot"||t.kind!=="model"&&["rx","ry","rz"].includes(a))continue;const l=r.map(c=>({...c,time:X(s+c.time)})).filter(c=>c.time<=t.duration+1e-6),i=wt(n,a).filter(c=>!l.some(f=>Math.abs(f.time-c.time)<1/120));e={...e,...yt(n,a,[...i,...l].sort((c,f)=>c.time-f.time))},n={...n,...e}}return e}function on(t,o="elastic",{amount:s=.5,cycles:n=3,props:e}={}){let a={...t},r={};for(const l of Dt(t,e??Ko)){const i=wt(a,l);if(i.length<2)continue;const c=i.at(-2),f=i.at(-1),h=f.time-c.time,p=t.duration-f.time;if(h<=0||p<.1)continue;const u=f.value-c.value;if(Math.abs(u)<1e-6)continue;const m=Math.max(1,Math.min(6,Math.round(n))),y=Math.min(p/(m*2),Math.max(.06,h*.6)),M=[];for(let d=1;d<=m*2;d++){const x=s*Math.pow(.45,Math.ceil(d/2)-1),g=o==="bounce"?(d%2?-1:0)*Math.abs(u)*x*Math.sign(u):(d%2?1:-1)*u*x*.5,w=d===m*2?f.value:f.value+g,b=it[l].min,v=it[l].max;M.push({time:X(f.time+y*d),value:X(Math.max(b,Math.min(v,w))),ease:fo})}r={...r,...yt(a,l,[...i.map((d,x)=>x===i.length-1?{...d,ease:fo}:d),...M])},a={...a,...r}}return r}const fo=[.33,0,.67,1];function en(t,o="cycle",{props:s,maxKeys:n=60}={}){let e={...t},a={};for(const r of Dt(t,s)){const l=wt(e,r);if(l.length<2)continue;const i=l[0].time,c=l.at(-1).time,f=c-i;if(f<=1/30)continue;const h=[...l],p=l.at(-1).value-l[0].value;for(let u=1;h.length<n;u++){const m=o==="pingpong"&&u%2?[...l].reverse().map(M=>({...M,time:c-(M.time-i)})):l;let y=!1;for(const M of m.slice(1)){const d=X(M.time+f*u);if(d>t.duration+1e-6||h.length>=n)break;const x=o==="offset"?M.value+p*u:M.value,{min:g,max:w}=it[r];h.push({...M,time:d,value:X(Math.max(g,Math.min(w,x)))}),y=!0}if(!y)break}a={...a,...yt(e,r,h)},e={...e,...a}}return a}function nn(t,o){const s=Ct(t.shape)?t.shape:yo(t.shape);return s.items.map(n=>({...t,id:o(),label:`${t.label} · ${n.name}`.slice(0,60),shape:{...s,items:[{...n}]}}))}const be=["posX","posY","scale","rotation","anchorX","anchorY","parentId","opacity"];function sn(t){if(t.length<2)throw Error("Chọn ít nhất 2 layer Shape để gộp");const[o,...s]=t,n=a=>be.every(r=>(a[r]??null)===(o[r]??null))&&!a.motionKeys?.some(r=>Ko.some(l=>l in r));if(!t.every(n))throw Error("Chỉ gộp được các layer Shape cùng vị trí / tỉ lệ / góc xoay và không có key chuyển động");const e=[];for(const a of t){const r=Ct(a.shape)?a.shape:yo(a.shape);for(const l of r.items)e.push({...l,id:Uo(e)})}if(e.length>24)throw Error("Một layer Shape chứa tối đa 24 hình");return{...o,start:Math.min(...t.map(a=>a.start)),duration:Math.max(...t.map(a=>a.start+a.duration))-Math.min(...t.map(a=>a.start)),shape:{v:2,items:e}}}function rn(t,o,s,{fps:n=10,makeId:e,label:a}={}){const r=Math.min(o/1280,s/720),l=(y,M)=>[X(((y-o/2)/r+640-280)/.72),X(((M-s/2)/r+360)/.72)],i=Math.max(2,Math.min(255,Math.round(t.duration*n)+1)),c=[];for(let y=0;y<i;y++){const M=Gt(t,t.duration*y/(i-1),o,s);c.push(l(o/2+M.x*o,s/2+M.y*s))}const f=c.map(y=>y[0]),h=c.map(y=>y[1]),p=(Math.min(...f)+Math.max(...f))/2,u=(Math.min(...h)+Math.max(...h))/2,m={id:"s1",name:"Position Trace",type:"path",params:{pts:c.map(([y,M])=>[X(y-p),X(M-u)]),closed:!1},pos:[X(p),X(u)],rot:0,scale:[1,1],opacity:1,fill:{type:"none"},stroke:{color:"#c6f432",width:8,cap:"round",join:"round"}};return{id:e(),nodeId:"",kind:"image",url:"",label:a??`${t.label} · trace`.slice(0,60),track:t.track,start:t.start,duration:t.duration,volume:0,motionV:2,shape:{v:2,items:[m]}}}const Wt=/^#[0-9a-fA-F]{6}$/,xe=24,an=["#c6f432","#2bd4c9","#ffffff","#0d0f12","#ff5bd1"];function ln(t,o=16){const s=new Map,n=e=>{if(typeof e=="string"&&Wt.test(e)){const a=e.toLowerCase();s.set(a,(s.get(a)||0)+1)}};for(const e of t){e.title&&(n(e.title.color),n(e.title.accentColor));const a=e.shape;if(a)if(Ct(a))for(const r of a.items){n(r.fill.color);for(const l of r.fill.stops||[])n(l[0]);n(r.stroke?.color)}else for(const r of a.paths)n(r.stroke),n(r.fill)}return[...s.entries()].sort((e,a)=>a[1]-e[1]).slice(0,o).map(e=>e[0])}function cn(t,o,{stroke:s=!1,itemId:n}={}){if(!Wt.test(o))throw Error("Invalid colour");if(t.title)return{title:{...t.title,[s?"accentColor":"color"]:o}};if(!t.shape)throw Error("Chọn layer Shape hoặc chữ để áp màu");return Ct(t.shape)?{shape:{...t.shape,items:t.shape.items.map(e=>n&&e.id!==n?e:s?{...e,stroke:{...e.stroke??{width:8,cap:"round",join:"round"},color:o}}:{...e,fill:e.fill.type==="linear"||e.fill.type==="radial"?{...e.fill,stops:e.fill.stops.map((a,r)=>r===0?[o,a[1]]:a)}:{...e.fill,type:"color",color:o}})}}:{shape:{...t.shape,paths:t.shape.paths.map(e=>s||!e.fill?{...e,stroke:o}:{...e,fill:o})}}}function fn(t,o){if(!Array.isArray(o)||!o.length||o.length>xe||!o.every(e=>Wt.test(e)))throw Error("Invalid palette");const s=e=>o[e%o.length];if(t.title)return{title:{...t.title,color:s(0),...o.length>1?{accentColor:s(1)}:{}}};if(!t.shape)throw Error("Chọn layer Shape hoặc chữ để áp màu");if(!Ct(t.shape))return{shape:{...t.shape,paths:t.shape.paths.map((e,a)=>({...e,...e.fill?{fill:s(a)}:{},...e.stroke?{stroke:e.fill?e.stroke:s(a)}:{}}))}};let n=0;return{shape:{...t.shape,items:t.shape.items.map(e=>{const a=e.fill;return a.type==="linear"||a.type==="radial"?{...e,fill:{...a,stops:a.stops.map(r=>[s(n++),r[1]])}}:a.type==="color"?{...e,fill:{...a,color:s(n++)}}:e.stroke?{...e,stroke:{...e.stroke,color:s(n++)}}:e})}}}function we(t,o,s,n){const e=Gt(t,o,s,n),a=t.card?t.card.width/t.card.height:t.lottie?t.lottie.w/t.lottie.h:null,[r,l]=a&&Number.isFinite(a)&&a>0?a>s/n?[s,s/a]:[n*a,n]:[s,n];return{cx:s/2+e.x*s,cy:n/2+e.y*n,w:r*e.zoom,h:l*e.zoom,angle:e.rot}}const ve=3,kt=30,Ot=Object.freeze({xy:.002,rot:1.5}),Ee=.2,ho=t=>typeof t=="number"&&Number.isFinite(t),uo=t=>Math.round(t*1e4)/1e4;function Ae(t){return t?t.kind==="audio"?"Âm thanh không rơi được":t.adjust===!0?"Lớp điều chỉnh không có hình để rơi":t.parentId?"Lớp đang gắn vào lớp cha — bỏ gắn rồi thử lại":null:"Không tìm thấy lớp"}function to(t,o,s,n=kt){const e=t.length;if(e<=2)return[...Array(e).keys()];const a=[0,e-1];for(;;){a.sort((i,c)=>i-c);let r=-1,l=s;for(let i=0;i+1<a.length;i++){const c=a[i],f=a[i+1];for(let h=c+1;h<f;h++){const p=o[c]+(o[f]-o[c])*(t[h]-t[c])/(t[f]-t[c]),u=Math.abs(p-o[h]);u>l&&(l=u,r=h)}}if(r<0||a.length>=n)return a;a.push(r)}}function Pe(t,o,s){let n=0;for(let e=0;e+1<s.length;e++)for(let a=s[e]+1;a<s[e+1];a++){const r=s[e],l=s[e+1];n=Math.max(n,Math.abs(o[r]+(o[l]-o[r])*(t[a]-t[r])/(t[l]-t[r])-o[a]))}return n}function Ce(t,o,s){const n=[],e=r=>Math.floor((r+180)/360),a=(r,l)=>r-360*l;for(let r=0;r<s.length;r++){const l=s[r],i=o[l],c=e(i);if(r){const f=s[r-1],h=e(o[f]);if(h!==c){const p=c>h,u=(p?h+1:h)*360-180,m=(u-o[f])/(i-o[f]),y=Et(t[f]+(t[l]-t[f])*m),M=Math.max(n.at(-1).time+1/ut,Math.min(y,Et(t[l]-2/ut))),d=M+1/ut;d<t[l]-1e-6?n.push({time:M,value:p?180:-180,ease:"hold"},{time:d,value:p?-180:180}):n[n.length-1]={...n[n.length-1],ease:"hold"}}}n.push({time:t[l],value:Math.max(-180,Math.min(180,a(i,c)))})}return n}function hn(t,o,s={}){const n=s.R??Ro();if(!n)throw Error("Physics engine not loaded yet — try again");const e=s.W??1280,a=s.H??720,r=ve/a,l=ho(s.at)?s.at:0,i=Math.max(1,Math.min(bt.max,ho(s.duration)?s.duration:bt.default)),c=s.mode==="above"?"above":"here",f=[...new Set(o)].map(b=>t.find(v=>v.id===b));if(!f.length)throw Error("physicsDrop needs clipIds");if(f.length>It)throw Error(`At most ${It} layers per drop`);for(const[b,v]of f.entries()){const I=Ae(v);if(I)throw Error(`${v?.label??o[b]}: ${I}`)}const h=f.map(b=>{const v=Et(l-b.start);if(v<0||v>b.duration-2/ut)throw Error(`${b.label??b.id}: the playhead is outside the layer`);const I=vt(b,"x",v),T=vt(b,"y",v),D=vt(b,"rot",v),q=s.rectOf?.(b)??we(b,v,e,a),O=[I*e*r,-T*a*r],N=[(q.cx-e/2)*r,-(q.cy-a/2)*r],P=D*Math.PI/180,E=[N[0]-O[0],N[1]-O[1]],R=[E[0]*Math.cos(P)-E[1]*Math.sin(P),E[0]*Math.sin(P)+E[1]*Math.cos(P)];return{id:b.id,position:[O[0],O[1],0],rotation:[0,0,-D],half:[Math.max(4,q.w)*r/2,Math.max(4,q.h)*r/2,Ee],offset:[R[0],R[1],0],local:v,x:I,y:T,rot:D}}),p=-a*r/2,u=a*r/2,m=e*r/2,y=s.walls?[{min:[-m-2,p,-2],max:[-m,u+20,2]},{min:[m,p,-2],max:[m+2,u+20,2]}]:[],M=b=>Math.hypot(b.half[0],b.half[1],b.half[2]),d=Math.max(...h.map(b=>b.position[1]+M(b))),x=Zt(n,{bodies:h,statics:y,floor:p,mode:c,bounciness:s.bounciness,duration:i,height:Math.max(.3,u-d+.05),seed:s.seed??[...o].sort().join(","),planar:!0}),g={},w=t.map(b=>({...b}));for(const b of h){const v=x.bodies.find(F=>F.id===b.id),I=w.findIndex(F=>F.id===b.id);let T=w[I];const D=[],q=[],O=[],N=[];let P=b.rot;for(const F of v.samples){const G=Et(b.local+F.sec);if(G>T.duration+1e-6)break;let H=-2*Math.atan2(F.q[2],F.q[3])*180/Math.PI;H+=360*Math.round((P-H)/360),P=H,D.push(G),q.push(F.pivot[0]/r/e),O.push(-F.pivot[1]/r/a),N.push(H)}const E=c==="above"&&b.local>=1/ut,R={},V={},K=Math.min(...N),k=Math.max(...N),B=k-K<360?Math.ceil((k-180)/360)*360:0,mt=B&&K-B>=-180?N.map(F=>F-B):N,dt=mt!==N&&b.local>=1/ut;for(const[F,G,H]of[["x",q,Ot.xy],["y",O,Ot.xy],["rot",mt,Ot.rot]]){const Mt=E||F==="rot"&&dt,W=wt(T,F).filter(L=>L.time<b.local-(Mt?1.5:.5)/ut),tt=Mt?[{time:Et(b.local-1/ut),value:F==="x"?b.x:F==="y"?b.y:b.rot,...F==="rot"&&dt?{ease:"hold"}:{}}]:[],ft=F==="rot"?G.reduce((L,J,at)=>L+(at&&Math.floor((J+180)/360)!==Math.floor((G[at-1]+180)/360)?1:0),0):0,rt=kt-W.length-tt.length-2*ft;if(rt<2)throw Error(`${T.label??T.id}: too many ${F} keys before the playhead (or too many turns) to add the drop`);const ht=to(D,G,H,rt),gt=it[F].min,j=it[F].max,z=F==="rot"?Ce(D,G,ht):ht.map(L=>({time:D[L],value:Math.max(gt,Math.min(j,G[L]))})),nt=[...W,...tt,...z].map(L=>({time:L.time,value:uo(L.value),...L.ease?{ease:L.ease}:{}}));T={...T,...yt(T,F,nt.slice(0,kt))},R[F]=z.length,V[F]=uo(Pe(D,G,ht))}w[I]=T,g[b.id]={keys:R,error:V,settledAt:v.settledAt==null?null:Math.round((l+v.settledAt)*1e3)/1e3}}return{clips:w,report:g,settled:x.settled}}const $=Object.freeze({work:480,focals:[.45,.55,.7,.85,1,1.25],maxFrames:900,keyTolPx:.05,points:400,smooth:.3,smoothFrames:4,smoothTolPx:.25,dense:{cols:40,rows:22,keep:700,minFrames:8,max:1500},slide:.01}),C=t=>Math.round(t*1e6)/1e6,A=(t,o)=>[t[0]-o[0],t[1]-o[1],t[2]-o[2]],U=(t,o)=>[t[0]+o[0],t[1]+o[1],t[2]+o[2]],_=(t,o)=>[t[0]*o,t[1]*o,t[2]*o],S=(t,o)=>t[0]*o[0]+t[1]*o[1]+t[2]*o[2],st=(t,o)=>[t[1]*o[2]-t[2]*o[1],t[2]*o[0]-t[0]*o[2],t[0]*o[1]-t[1]*o[0]],et=t=>{const o=Math.hypot(...t)||1;return _(t,1/o)},Z=(t,o)=>[S(t[0],o),S(t[1],o),S(t[2],o)],pt=t=>[0,1,2].map(o=>[t[0][o],t[1][o],t[2][o]]),po=(t,o)=>t.map(s=>[0,1,2].map(n=>s[0]*o[0][n]+s[1]*o[1][n]+s[2]*o[2][n]));function Se(t,o,s,n=bo(29)){const e=t;if(e.length<20)return null;const a=e.map(r=>Math.hypot(...A(r,s))).sort((r,l)=>r-l)[e.length>>1];for(const r of[.015,.03,.05]){const l=a*r;let i=null;for(let u=0;u<2e3;u++){const m=e[Math.floor(n()*e.length)],y=e[Math.floor(n()*e.length)],M=e[Math.floor(n()*e.length)];let d=st(A(y,m),A(M,m));const x=Math.hypot(...d);if(x<1e-9||(d=_(d,1/x),S(d,o)<0&&(d=_(d,-1)),S(d,o)<Math.cos(35*Math.PI/180)))continue;const g=-S(d,m);if(S(d,s)+g<=l)continue;let w=0;for(const b of e)Math.abs(S(d,b)+g)<l&&w++;(!i||w>i.k)&&(i={n:d,d:g,k:w})}if(!i||i.k<e.length*.2)continue;const c=e.filter(u=>Math.abs(S(i.n,u)+i.d)<l),f=_(c.reduce((u,m)=>U(u,m),[0,0,0]),1/c.length),h=[[0,0,0],[0,0,0],[0,0,0]];for(const u of c){const m=A(u,f);for(let y=0;y<3;y++)for(let M=0;M<3;M++)h[y][M]+=m[y]*m[M]}let p=Ft(h);return S(p,o)<0&&(p=_(p,-1)),{n:p,d:-S(p,f),count:c.length}}return null}function Ft(t){const o=t.map(e=>[...e]),s=[[1,0,0],[0,1,0],[0,0,1]];for(let e=0;e<30;e++){let a=0;for(let r=0;r<3;r++)for(let l=r+1;l<3;l++)a+=o[r][l]**2;if(a<1e-24)break;for(let r=0;r<3;r++)for(let l=r+1;l<3;l++){if(Math.abs(o[r][l])<1e-30)continue;const i=(o[l][l]-o[r][r])/(2*o[r][l]),c=Math.sign(i||1)/(Math.abs(i)+Math.sqrt(i*i+1)),f=1/Math.sqrt(c*c+1),h=c*f;for(let p=0;p<3;p++){const u=o[p][r],m=o[p][l];o[p][r]=f*u-h*m,o[p][l]=h*u+f*m}for(let p=0;p<3;p++){const u=o[r][p],m=o[l][p];o[r][p]=f*u-h*m,o[l][p]=h*u+f*m}for(let p=0;p<3;p++){const u=s[p][r],m=s[p][l];s[p][r]=f*u-h*m,s[p][l]=h*u+f*m}}}const n=[0,1,2].reduce((e,a)=>o[a][a]<o[e][e]?a:e,0);return et([s[0][n],s[1][n],s[2][n]])}function Rt(t,o,s,n){const e=new Map;t.poses.forEach((a,r)=>{if(!(!a||a.lost))for(const[l,i]of t.obs[r]){const c=t.points.get(l);if(!c)continue;const f=Z(a.R,A(c,a.C)),h=f[2]>-1e-6?50:Math.hypot(s+o*f[0]/-f[2]-i[0],n-o*f[1]/-f[2]-i[1]),p=e.get(l)??[0,0,0];p[0]+=h,p[1]++,p[2]=Math.max(p[2],h),e.set(l,p)}});for(const a of e.values())a[0]/=a[1];return e}function _t(t,o,s,n){const e=[...Rt(t,o,s,n).values()].map(r=>r[0]).sort((r,l)=>r-l),a=Math.floor(e.length*.8);return a>30?e.slice(0,a).reduce((r,l)=>r+l,0)/a:1/0}function mo(t,o,s,n){const{solved:e,keyframes:a}=No(t);for(let r=0;r<3;r++){const l=Rt(t,o,s,n),i=[...l.values()].map(h=>h[2]).sort((h,p)=>h-p),c=Math.max(1.2,2*(i[i.length>>1]??1));let f=0;for(const[h,p]of l)p[2]>c&&(t.points.delete(h),f++);if(!f)break;Jt(t.poses,t.points,t.obs,a,o,s,n,8),Oo(t,a,e,o,s,n)}}function No(t){const o=t.poses.map((n,e)=>n&&!n.lost?e:-1).filter(n=>n>=0),s=Math.max(1,Math.ceil(o.length/60));return{solved:o,keyframes:[t.pair[0],...o.filter((n,e)=>n!==t.pair[0]&&(e%s===0||e===o.length-1))]}}function Oo(t,o,s,n,e,a){const r=Math.hypot(...A(t.poses[t.pair[1]].C,t.poses[t.pair[0]].C))||1,l=new Set(o);for(const i of s){if(l.has(i))continue;const c=[];for(const[f,h]of t.obs[i])t.points.has(f)&&c.push({X:t.points.get(f),px:h});c.length>=10&&(t.poses[i]=ee(c,t.poses[i],n,e,a,r).pose)}}function Te(t,o,s,n){const{solved:e,keyframes:a}=No(t),r={poses:t.poses.map(c=>c&&{...c,R:c.R.map(f=>[...f]),C:[...c.C]}),points:new Map([...t.points].map(([c,f])=>[c,[...f]]))},l=_t(t,o,s,n),i=Jt(t.poses,t.points,t.obs,a,o,s,n,12,{focal:!0});return Math.abs(i/o-1)<1e-4?o:(Oo(t,a,e,i,s,n),Math.abs(i/o-1)<.15&&_t(t,i,s,n)<l?i:(t.poses=r.poses,t.points=r.points,o))}function Ie(t,o,{w:s,h:n,mw:e,mh:a,focals:r=$.focals,focal:l=null,onProgress:i=null}={}){const c=s/2,f=n/2;let h=l,p=0;const u=l?1:r.length+9;if(!h){const P=new Map,E=Math.max(s,n)/s;let R=t;const V=j=>{if(j=Math.round(j*1e3)/1e3,!(j>.2&&j<3)||P.has(j))return;const z=ao(null,j*s,{obs:R,w:s,h:n});z.mode==="free"&&mo(z,j*s,c,f),P.set(j,{s:z,e:z.mode==="free"?_t(z,j*s,c,f):1/0}),i?.(++p/u)};let K=[];for(let j=Math.max(1,Math.round(t.length/25));;j=Math.max(1,j>>1)){R=t.filter((z,nt)=>nt%j===0),P.clear(),p=0;for(const z of r)V(z*E);if(K=[...P.entries()].filter(([,z])=>Number.isFinite(z.e)).sort((z,nt)=>z[0]-nt[0]),K.length||j===1)break}if(!K.length)return i?.(1),null;const k=K.reduce((j,z,nt)=>z[1].e<K[j][1].e?nt:j,0),B=K[k][1].s,mt=k>0?K[k-1][0]:K[k][0]*.8,dt=k<K.length-1?K[k+1][0]:K[k][0]*1.25,F=B.poses.map((j,z)=>j&&!j.lost?z:-1).filter(j=>j>=0),G=B.pair[0],H=j=>{const z={...B,poses:B.poses.map(J=>J&&{...J,R:J.R.map(at=>[...at]),C:[...J.C]}),points:new Map([...B.points].map(([J,at])=>[J,[...at]]))};Jt(z.poses,z.points,z.obs,[G,...F.filter(J=>J!==G)],j*s,c,f,8),i?.(++p/u);let nt=0,L=0;for(const[J,at]of Rt(z,j*s,c,f).values())nt+=J*at,L+=at;return L?nt/L:1/0},Mt=(Math.sqrt(5)-1)/2;let W=mt,tt=dt,ft=tt-Mt*(tt-W),rt=W+Mt*(tt-W),ht=H(ft),gt=H(rt);for(let j=0;j<7;j++)ht<gt?(tt=rt,rt=ft,gt=ht,ft=tt-Mt*(tt-W),ht=H(ft)):(W=ft,ft=rt,ht=gt,rt=W+Mt*(tt-W),gt=H(rt));h=(W+tt)/2}const m=ao(null,h*s,{obs:t,w:s,h:n});if(i?.(1),m.mode!=="free")return null;let y=h*s;const M=m.poses[m.pair[0]].C,d=m.poses[m.pair[0]].R;if(mo(m,y,c,f),!l)for(let P=0;P<3;P++){const E=Te(m,y,c,f),R=Math.abs(E/y-1)<5e-4;if(y=E,R)break}const x=Rt(m,y,c,f),g=[...x.values()].map(P=>P[0]).sort((P,E)=>P-E),w=Math.max(1.5,3*(g[g.length>>1]??1)),b=[...x.entries()].filter(([P,E])=>m.points.has(P)&&E[0]<=w&&E[1]>=2),v=P=>t.flatMap((E,R)=>E.has(P)?[o[R]]:[]);let I=0,T=0;for(const[,P]of b)I+=P[0]*P[1],T+=P[1];const D=Z(pt(d),[0,1,0]),q=Se([...m.points.values()],D,M)??te(m.points,D,M)??oe(m.points,D,M),O={v:1,w:s,h:n,mw:e||s,mh:a||n,mode:"free",f:C(y),err:C(T?I/T:_t(m,y,c,f)),frames:m.poses.map((P,E)=>[C(o[E]),...xo(P.R).map(C),...P.C.map(C)]),floor:q?[...q.n.map(C),C(q.d)]:null},N=[];for(const[P]of b.sort((E,R)=>R[1][1]-E[1][1])){if(N.length>=$.points)break;const E=m.points.get(P),R=v(P);Xo(O,E,R)<=$.slide*s&&N.push([E.map(C),[C(R[0]),C(R.at(-1))]])}return{...O,points:N.map(P=>P[0]),seen:N.map(P=>P[1])}}function Xo(t,o,s){if(!s.length)return 1/0;const e=(s.length>24?s.filter((p,u)=>u%Math.ceil(s.length/24)===0||u===s.length-1):s).map(p=>et(A(o,lt(t,p).C)));let a=0;for(const p of[e[0],e.at(-1)])for(const u of e)a=Math.max(a,Math.acos(Math.min(1,S(p,u))));const r=lt(t,s[s.length>>1]).C,l=Math.hypot(...A(o,r)),i=U(o,_(et(A(o,r)),l*(.5/t.f)/Math.max(.001,Math.sin(a)))),c=t.frames,f=Math.max(1,Math.floor(c.length/40));let h=0;for(let p=0;p<c.length;p+=f){const u=ct(t,o,c[p][0]),m=ct(t,i,c[p][0]);u&&m&&(h=Math.max(h,Math.hypot(u[0]-m[0],u[1]-m[1])))}return h}function un(t,o,{mw:s,mh:n,focals:e=$.focals,focal:a=null,onProgress:r=null,dense:l=!0}={}){if(t.length<3)throw Error("FLAT");const i=t[0].w,c=t[0].h,f=wo(t,{anchor:!0,onProgress:r&&(u=>r(u*.35))}),h=Ie(f,o,{w:i,h:c,mw:s,mh:n,focals:e,focal:a,onProgress:r&&(u=>r(.35+u*.57))});if(h){const u=l?Re(h,t,o,r&&(m=>r(.92+m*.08))):h;return r?.(1),u}const p=Wo(t,(a??.7)*i);if(p.filter(u=>!u.lost).length<t.length*.5)throw Error("FLAT");return{v:1,w:i,h:c,mw:s||i,mh:n||c,mode:"tripod",frames:p.map((u,m)=>[C(o[m]),...u.q.map(C),C(u.f)])}}function Re(t,o,s,n=null,e=$.dense){const a=wo(o,{anchor:!0,keep:e.keep,cols:e.cols,rows:e.rows,onProgress:n&&(u=>n(u*.8))}),r=new Map;a.forEach((u,m)=>{for(const[y,M]of u){let d=r.get(y);d||r.set(y,d=[]),d.push([s[m],M[0],M[1]])}});const l=[...r.values()].filter(u=>u.length>=e.minFrames),i=t.points??[],c=u=>i.some(m=>Math.abs(m[0]-u[0])+Math.abs(m[1]-u[1])+Math.abs(m[2]-u[2])<1e-6),f=t.seen??i.map(()=>[t.frames[0][0],t.frames.at(-1)[0]]),h=[...i],p=[...f];for(const u of l){if(h.length>=e.max)break;const m=Lo(t,u);!m||c(m)||Xo(t,m,u.map(y=>y[0]))>$.slide*t.w||(h.push(m.map(C)),p.push([C(u[0][0]),C(u.at(-1)[0])]))}return n?.(1),{...t,points:h,seen:p}}const jt=t=>!!t&&typeof t.ref=="string"&&!Array.isArray(t.frames);function _e(t){if(!t||t.v!==1||!["free","tripod"].includes(t.mode))throw Error("Invalid scene track");for(const n of["w","h","mw","mh"])if(!(Number.isFinite(t[n])&&t[n]>0&&t[n]<=2e4))throw Error("Invalid scene track");if(t.smooth!==void 0&&!(Number.isFinite(t.smooth)&&t.smooth>=0&&t.smooth<=1))throw Error("Invalid scene track");if(jt(t)){if(!/^[0-9a-f]{64}$/.test(t.ref))throw Error("Invalid scene track");return t}const o=t.mode==="free"?8:6;if(!Array.isArray(t.frames)||t.frames.length<2)throw Error("Invalid scene track");let s=-1/0;for(const n of t.frames){if(!Array.isArray(n)||n.length!==o||!n.every(Number.isFinite)||n[0]<s)throw Error("Invalid scene track");s=n[0]}if(t.mode==="free"&&(!(Number.isFinite(t.f)&&t.f>0)||t.floor!=null&&!(Array.isArray(t.floor)&&t.floor.length===4&&t.floor.every(Number.isFinite))||!Array.isArray(t.points)||t.points.length>5e3||!t.points.every(n=>Array.isArray(n)&&n.length===3&&n.every(Number.isFinite))||t.seen!=null&&!(Array.isArray(t.seen)&&t.seen.length===t.points.length&&t.seen.every(n=>Array.isArray(n)&&n.length===2&&n.every(Number.isFinite)&&n[0]<=n[1]))))throw Error("Invalid scene track");return t}function lt(t,o){const s=t.frames,n=s.length;let e=0,a=Math.max(0,n-2);for(;e<a;){const u=e+a+1>>1;s[u][0]<=o?e=u:a=u-1}const r=s[e],l=s[Math.min(n-1,e+1)],i=l[0]>r[0]?Math.max(0,Math.min(1,(o-r[0])/(l[0]-r[0]))):0;let c=r.slice(1,5),f=l.slice(1,5);oo(c,f)<0&&(f=f.map(u=>-u));const h=je(c,f,i),p=go(h);return t.mode==="tripod"?{R:p,C:[0,0,0],f:r[5]+(l[5]-r[5])*i}:{R:p,C:[0,1,2].map(u=>r[5+u]+(l[5+u]-r[5+u])*i),f:t.f}}const oo=(t,o)=>t[0]*o[0]+t[1]*o[1]+t[2]*o[2]+t[3]*o[3];function je(t,o,s){const n=Math.min(1,Math.max(-1,oo(t,o)));if(n>.9995){const i=t.map((f,h)=>f+(o[h]-f)*s),c=Math.hypot(...i);return i.map(f=>f/c)}const e=Math.acos(n),a=Math.sin(e),r=Math.sin((1-s)*e)/a,l=Math.sin(s*e)/a;return t.map((i,c)=>i*r+o[c]*l)}function De(t,o,s){const n=t.seen?.[o];if(!n)return!0;const e=t.frames.length>1?(t.frames.at(-1)[0]-t.frames[0][0])/(t.frames.length-1):0;return s>=n[0]-e-1e-4&&s<=n[1]+e+1e-4}const eo=(t,o)=>(t.points??[]).map((s,n)=>[s,n]).filter(([,s])=>De(t,s,o));function ct(t,o,s){const n=lt(t,s),e=Z(n.R,t.mode==="tripod"?o:A(o,n.C));return e[2]>-1e-6?null:[t.w/2+n.f*e[0]/-e[2],t.h/2-n.f*e[1]/-e[2]]}function zt(t,o,s,n){const e=lt(t,n),a=et([(o-t.w/2)/e.f,-(s-t.h/2)/e.f,-1]);return{o:e.C,d:Z(pt(e.R),a),pose:e}}function Fe(t,o,s,n,{radius:e=null}={}){const{o:a,d:r}=zt(t,o,s,n);if(t.mode==="tripod")return r.map(C);const l=e??Math.max(10,t.w*.04),i=[];for(const[h]of eo(t,n)){const p=ct(t,h,n);if(!p)continue;const u=Math.hypot(p[0]-o,p[1]-s),m=S(A(h,a),r);m>0&&u<=t.w*.15&&i.push({X:h,depth:m,dist:u,w:1/(1+u)})}i.sort((h,p)=>h.dist-p.dist);const c=i.filter((h,p)=>h.dist<=l||p<6);let f=null;if(c.length>=3&&(f=ze(c,a,r)),f===null&&c.length>=2){c.sort((u,m)=>u.depth-m.depth);const h=c.reduce((u,m)=>u+m.w,0);let p=0;for(const u of c)if(p+=u.w,p>=h/2){f=u.depth;break}}else if(f===null&&t.floor){const h=t.floor.slice(0,3),p=S(h,r);if(Math.abs(p)>1e-6){const u=-(S(h,a)+t.floor[3])/p;u>0&&(f=u)}}if(f===null){const h=(t.points??[]).map(p=>S(A(p,a),r)).filter(p=>p>0).sort((p,u)=>p-u);f=h.length?h[h.length>>1]:1}return U(a,_(r,f)).map(C)}function ze(t,o,s){const n=t.slice(0,20),e=n.map(d=>d.depth).sort((d,x)=>d-x),a=e[e.length>>1]*.015,r=n.reduce((d,x)=>d+x.w,0);let l=null,i=0;for(let d=0;d<n.length;d++)for(let x=d+1;x<n.length;x++)for(let g=x+1;g<n.length;g++){let w=st(A(n[x].X,n[d].X),A(n[g].X,n[d].X));const b=Math.hypot(...w);if(b<1e-12)continue;w=_(w,1/b);const v=n.filter(T=>Math.abs(S(w,A(T.X,n[d].X)))<a),I=v.reduce((T,D)=>T+D.w,0);I>i&&(l=v,i=I)}if(!l||l.length<3||i<r*.5)return null;const c=_(l.reduce((d,x)=>U(d,x.X),[0,0,0]),1/l.length),f=[[0,0,0],[0,0,0],[0,0,0]];for(const{X:d}of l){const x=A(d,c);for(let g=0;g<3;g++)for(let w=0;w<3;w++)f[g][w]+=x[g]*x[w]}if(!(f[0][0]+f[1][1]+f[2][2]>0))return null;const p=Ft(f),u=S(p,s);if(Math.abs(u)<.05)return null;const m=Math.min(...l.map(d=>d.depth)),y=Math.max(...l.map(d=>d.depth)),M=S(p,A(c,o))/u;return M>=m*.7&&M<=y*1.4?M:null}function qe(t,o,s,n){if(t.mode!=="free"||!t.floor)return null;const{o:e,d:a}=zt(t,o,s,n),r=t.floor.slice(0,3),l=S(r,a);if(Math.abs(l)<1e-6)return null;const i=-(S(r,e)+t.floor[3])/l;return i>0?U(e,_(a,i)):null}function pn(t,o){return t.mode!=="free"?[]:o.map(s=>Lo(t,s)).filter(Boolean)}function Lo(t,o){if(t.mode!=="free"||o.length<4)return null;const s=o.map(([l,i,c])=>zt(t,i,c,l));let n=0;for(const l of s)n=Math.max(n,Math.acos(Math.min(1,S(l.d,s[0].d))));if(n<.5*Math.PI/180)return null;const e=[[0,0,0],[0,0,0],[0,0,0]],a=[0,0,0];for(const{o:l,d:i}of s)for(let c=0;c<3;c++)for(let f=0;f<3;f++){const h=(c===f?1:0)-i[c]*i[f];e[c][f]+=h,a[c]+=h*l[f]}const r=Ke(e,a);return r&&o.every(([l,i,c])=>{const f=ct(t,r,l);return f&&Math.hypot(f[0]-i,f[1]-c)<1.5})?r:null}function Ke(t,o){const s=e=>e[0][0]*(e[1][1]*e[2][2]-e[1][2]*e[2][1])-e[0][1]*(e[1][0]*e[2][2]-e[1][2]*e[2][0])+e[0][2]*(e[1][0]*e[2][1]-e[1][1]*e[2][0]),n=s(t);return Math.abs(n)<1e-12?null:[0,1,2].map(e=>s(t.map((a,r)=>a.map((l,i)=>i===e?o[r]:l)))/n)}function mn(t,o,s,{extra:n=[]}={}){if(t.mode!=="free")return null;const e=(p,u)=>{let m=0;for(let y=0;y<4;y++){const[M,d]=o[y],[x,g]=o[(y+1)%4],w=(x-M)*(u-d)-(g-d)*(p-M);if(w){if(m&&Math.sign(w)!==m)return!1;m=Math.sign(w)}}return!0},a=lt(t,s),r=[...n,...eo(t,s).map(([p])=>p)].filter(p=>{const u=ct(t,p,s);return u&&e(u[0],u[1])}),l=o.map(([p,u])=>zt(t,p,u,s)),i=(p,u)=>{const m=[];for(const{o:y,d:M}of l){const d=S(p,M);if(Math.abs(d)<1e-9)return null;const x=-(S(p,y)+u)/d;if(!(x>0))return null;m.push(U(y,_(M,x)))}return m};let c=null,f="points";if(r.length>=4){const p=r.map(y=>Math.hypot(...A(y,a.C))).sort((y,M)=>y-M)[r.length>>1],u=p*.015;let m=null;for(let y=0;y<r.length;y++)for(let M=y+1;M<r.length;M++)for(let d=M+1;d<r.length&&d<M+12;d++){let x=st(A(r[M],r[y]),A(r[d],r[y]));const g=Math.hypot(...x);if(g<1e-12)continue;x=_(x,1/g);const w=-S(x,r[y]);let b=0;for(const v of r)Math.abs(S(x,v)+w)<u&&b++;(!m||b>m.c)&&(m={n:x,d:w,c:b})}if(m&&m.c>=4){const y=r.filter(g=>Math.abs(S(m.n,g)+m.d)<u),M=_(y.reduce((g,w)=>U(g,w),[0,0,0]),1/y.length),d=[[0,0,0],[0,0,0],[0,0,0]];for(const g of y){const w=A(g,M);for(let b=0;b<3;b++)for(let v=0;v<3;v++)d[b][v]+=w[b]*w[v]}let x=Ft(d);S(x,A(a.C,M))<0&&(x=_(x,-1)),c={n:x,d:-S(x,M),count:y.length}}}if(!c){const p=o.reduce((d,x)=>d+x[0],0)/4,u=o.reduce((d,x)=>d+x[1],0)/4,m=Fe(t,p,u,s),y=t.floor?qe(t,p,u,s):null,M=Math.hypot(...A(m,a.C));if(y&&Math.abs(Math.hypot(...A(y,a.C))-M)<M*.12)c={n:t.floor.slice(0,3),d:t.floor[3],count:0},f="ground";else{const d=t.floor?t.floor.slice(0,3):Z(pt(a.R),[0,1,0]),x=A(a.C,m);let g=A(x,_(d,S(x,d)));Math.hypot(...g)<1e-9&&(g=x),g=et(g),c={n:g,d:-S(g,m),count:0},f="upright"}}const h=i(c.n,c.d);return h?{corners:h.map(p=>p.map(C)),n:c.n.map(C),d:C(c.d),count:c.count,by:f}:null}function dn(t,o,s,n=null){const e=o.crop||{left:0,right:0,top:0,bottom:0},a=1-e.left-e.right,r=1-e.top-e.bottom,l=[];for(const i of n??t.frames.map(c=>c[0])){const c=s.map(f=>ct(t,f,i));c.some(f=>!f)||l.push([+i.toFixed(4),...c.flatMap(([f,h])=>[C((f/t.w-e.left)/a),C((h/t.h-e.top)/r)]),1])}return l}function Mn(t,o,s,n){const e=o.crop||{left:0,right:0,top:0,bottom:0};return[(e.left+s*(1-e.left-e.right))*t.w,(e.top+n*(1-e.top-e.bottom))*t.h]}function Bt(t,o,s,n,e,a,r){const l=o.crop||{left:0,right:0,top:0,bottom:0},i=(s/t.w-l.left)/(1-l.left-l.right),c=(n/t.h-l.top)/(1-l.top-l.bottom),f=Jo(o,i,c,e,a,r,t.mw,t.mh);return[f.px,f.py]}function yn(t,o,s,n,e,a){const r=Math.max(t.start,o.start),l=Math.min(t.start+t.duration,o.start+o.duration);if(!(l>r))return{};const i=[],c=[],f=[r,...s.frames.map(p=>o.start+p[0]).filter(p=>p>r+1e-4&&p<l-1e-4),l];for(const p of f){const u=ct(s,n,p-o.start);if(!u)continue;const[m,y]=Bt(s,o,u[0],u[1],p-o.start,e,a),M=+(p-t.start).toFixed(4);i.push({time:M,value:C((m-e/2)/e)}),c.push({time:M,value:C((y-a/2)/a)})}if(!i.length)return{};let h={...t,motionV:2};return delete h.posX,delete h.posY,h={...h,...yt(h,"x",Mo(i,$.keyTolPx/e))},h={...h,...yt(h,"y",Mo(c,$.keyTolPx/a))},{motionV:2,motionKeys:h.motionKeys,posX:void 0,posY:void 0}}const Mo=(t,o)=>to(t.map(s=>s.time),t.map(s=>s.value),o,1/0).map(s=>t[s]);function Ne(t,o,s){if(!(s>0)||o.length<3)return o;const n=s*$.smoothFrames,e=Math.ceil(n*2.5),a=t.mode==="free",r=$.smoothTolPx,l=a?(t.points??[]).filter((h,p)=>p%Math.max(1,Math.floor((t.points?.length??0)/80))===0):[-.4,0,.4].flatMap(h=>[-.25,0,.25].map(p=>[h,p,-1])),i=(h,p)=>{const u=Z(h.R,a?A(p,h.C):Z(pt(o[0].R),p));return u[2]>-1e-6?null:[h.f*u[0]/-u[2],-h.f*u[1]/-u[2]]},c=(h,p)=>{let u=0,m=0;for(const y of l){const M=i(h,y),d=i(p,y);M&&d&&(u=Math.max(u,Math.hypot(M[0]-d[0],M[1]-d[1])),m++)}return m?u:0},f=o.map(h=>xo(h.R));return o.map((h,p)=>{let u=0,m=[0,0,0],y=[0,0,0,0],M=0;for(let b=Math.max(0,p-e);b<=Math.min(o.length-1,p+e);b++){const v=Math.exp(-((b-p)**2)/(2*n*n)),I=oo(f[b],f[p])<0?f[b].map(T=>-T):f[b];u+=v,m=U(m,_(o[b].C,v)),y=y.map((T,D)=>T+I[D]*v),M+=o[b].f*v}const d=b=>{const v=f[p].map((T,D)=>T+(y[D]/u-T)*b),I=Math.hypot(...v);return{R:go(v.map(T=>T/I)),C:U(h.C,_(A(_(m,1/u),h.C),b)),f:h.f+(M/u-h.f)*b}};let x=1,g=d(1),w=c(h,g);for(let b=0;b<6&&w>r;b++)x*=Math.max(.3,r/w*.95),g=d(x),w=c(h,g);return w>r?h:g})}function Yo(t,o,s,n){const e=Ho(s,n),a=lt(t,t.frames[0][0]),r=t.mode==="free",l=r&&t.floor?t.floor.slice(0,3):Z(pt(a.R),[0,1,0]),i=Z(pt(a.R),[0,0,-1]),c=[0,1,2].map(E=>{const R=(t.points??[]).map(V=>V[E]).sort((V,K)=>V-K);return R.length?R[R.length>>1]:a.C[E]+(r?0:i[E])}),f=r&&t.floor?A(c,_(t.floor.slice(0,3),S(t.floor.slice(0,3),c)+t.floor[3])):c,h=et(A(i,_(l,S(i,l)))),u=[st(_(l,-1),h),_(l,-1),h],m=8*e/Math.max(1e-9,Math.hypot(...A(a.C,f))),y=E=>_(Z(u,A(E,f)),m),M=Bt(t,o,t.w/2,t.h/2,0,s,n),d=Bt(t,o,t.w/2+10,t.h/2,0,s,n),x=Math.hypot(d[0]-M[0],d[1]-M[1])/10,g=[[1,0,0],[0,-1,0],[0,0,-1]],w=t.frames.filter(E=>E[0]>=-1e-6&&E[0]<=o.duration+1e-6),b=[],v={},I=(E,R)=>{if(E===void 0)return R;for(;R-E>180;)R-=360;for(;R-E<-180;)R+=360;return R},T=Ne(t,w.map(E=>lt(t,E[0])),t.smooth??0);for(const[E,R]of w.entries()){const V=T[E],K=po(po(u,pt(V.R)),g),k=y(V.C),B=Qo(K),mt=I(v.pan,B.pan),dt=I(v.roll,B.roll);v.pan=mt,v.roll=dt,b.push({time:+(o.start+R[0]).toFixed(4),cx:C(k[0]/s),cy:C(k[1]/n),cz:C(k[2]/e),pan:C(mt),tilt:C(B.tilt),roll:C(dt),zoom:C(V.f*x/(5*e))})}const D=5*e*(b[0]?.zoom??1),q=$.keyTolPx/D*180/Math.PI,O={cx:$.keyTolPx/s,cy:$.keyTolPx/n,cz:$.keyTolPx/e,pan:q,tilt:q,roll:q,zoom:$.keyTolPx/D},N=new Set;for(const[E,R]of Object.entries(O))for(const V of to(b.map(K=>K.time),b.map(K=>K[E]),R,1/0))N.add(V);return{camera:{enabled:!0,motionV:2,motionKeys:b.filter((E,R)=>N.has(R))},toTimeline:y,fromTimeline:E=>U(Z(pt(u),_(E,1/m)),f),M:u,k:m,U:e,first:a}}function Oe(t,o,s,n,e,{size:a=null,fill:r=1}={}){if(t.mode!=="free")throw Error("TRIPOD");const{camera:l,toTimeline:i,k:c,U:f,first:h}=Yo(t,o,n,e),p=(a??Math.hypot(...A(h.C,s))*.2)*c*r,u=i(s),m=A(i(h.C),u),y=Math.atan2(m[0],-m[2])*180/Math.PI;return{camera:l,place:{is3D:!0,posX:C(u[0]/n),posY:C(u[1]/e),spatialDepth:C(-u[2]/f),modelDepth:C(-u[2]/f),modelGround:!0,modelRotation:{x:0,y:C(y),z:0},scale:C(Math.max(1e-6,p/(1.8*f)))},toTimeline:i}}function Xe(t,o,s,n,e){const a=[];for(const[r,l]of eo(t,n)){const i=ct(t,r,n);if(i){const c=Math.hypot(i[0]-o,i[1]-s);c<=e&&a.push([l,c])}}return a.sort((r,l)=>r[1]-l[1]).map(r=>r[0])}function gn(t,o,s){if(!o.length)return null;const n=lt(t,s),e=t.mode==="free"?n.C:[0,0,0],a=h=>_(h.reduce((p,u)=>U(p,u),[0,0,0]),1/h.length);let r=o.map(h=>t.mode==="free"?h:et(h)),l=a(r),i=r,c="points";if(t.mode==="free"&&r.length<3){const h=ct(t,l,s),p=Math.hypot(...A(l,e));if(h){const u=Xe(t,h[0],h[1],s,t.w*.12).map(d=>t.points[d]).filter(d=>Math.abs(Math.hypot(...A(d,e))/p-1)<.25).slice(0,14),m=p*.02,y=r[0];let M=null;for(let d=0;d<u.length;d++)for(let x=d+1;x<u.length;x++){let g=st(A(u[d],y),A(u[x],y));const w=Math.hypot(...g);if(w<1e-12)continue;g=_(g,1/w);const b=u.filter(v=>Math.abs(S(g,A(v,y)))<m);r.every(v=>Math.abs(S(g,A(v,y)))<m)&&(!M||b.length>M.length)&&(M=b)}M&&M.length>=3&&(i=[...r,...M],c="around")}}let f=null;if(t.mode==="free"&&i.length>=3){if(c==="points"&&i.length>=6){const u=Math.hypot(...A(l,e)),m=u*.01,y=bo(31);let M=null;for(let d=0;d<300;d++){const x=i[Math.floor(y()*i.length)],g=i[Math.floor(y()*i.length)],w=i[Math.floor(y()*i.length)];let b=st(A(g,x),A(w,x));const v=Math.hypot(...b);if(v<1e-12)continue;b=_(b,1/v);const I=i.filter(T=>Math.abs(S(b,A(T,x)))<m);(!M||I.length>M.length)&&(M=I)}M&&M.length>=Math.max(3,i.length*.5)&&(i=M)}const h=a(i),p=[[0,0,0],[0,0,0],[0,0,0]];for(const u of i){const m=A(u,h);for(let y=0;y<3;y++)for(let M=0;M<3;M++)p[y][M]+=m[y]*m[M]}f=Ft(p),c!=="around"&&(l=h)}return f||(f=et(A(e,l)),c="facing"),S(f,A(e,l))<0&&(f=_(f,-1)),{center:l.map(C),n:f.map(C),radius:C(Math.hypot(...A(l,e))*.08),by:c}}function bn(t,o=t.radius,s=36){const n=t.n,e=et(Math.abs(n[1])<.9?st(n,[0,1,0]):st(n,[1,0,0])),a=st(n,e);return Array.from({length:s},(r,l)=>{const i=l/s*2*Math.PI;return U(t.center,U(_(e,o*Math.cos(i)),_(a,o*Math.sin(i))))})}const Le=["x","y","depth","zoom","rot","tiltX","tiltY"];function xn(t,o,s,n,e,a,{width:r=null}={}){if(t.kind==="model"){const{camera:P,place:E}=Oe(o,s,n.center,e,a,{size:n.radius*2});if(!(E.spatialDepth>=so&&E.spatialDepth<=ro))throw Error("FAR");return{camera:P,patch:E}}const{camera:l,toTimeline:i,M:c,k:f,U:h,first:p}=Yo(o,s,e,a),u=i(n.center),m=et(Z(c,n.n)),y=i(o.mode==="free"?lt(o,o.frames[0][0]).C:p.C),M=-u[2]/h;if(!(M>=so&&M<=ro))throw Error("FAR");const d=P=>A(P,_(m,S(P,m)));let x=Math.abs(m[1])<.85?d([0,1,0]):d(A(y,u));Math.hypot(...x)<1e-6&&(x=d([0,1,0])),x=et(x);const g=_(m,-1),w=st(x,g),b=Math.asin(Math.max(-1,Math.min(1,g[1]))),v=Math.atan2(-g[0],g[2]),I=[Math.cos(v),0,Math.sin(v)],T=[Math.sin(b)*Math.sin(v),Math.cos(b),-Math.sin(b)*Math.cos(v)],D=Math.atan2(S(w,T),S(w,I)),q=P=>C(P*180/Math.PI);let O={...t,motionV:2};for(const P of Le)(O.motionKeys??[]).some(E=>E[P]!==void 0)&&(O={...O,motionKeys:Zo(O,P,[])});const N=(r??n.radius*6)*f;return{camera:l,patch:{is3D:!0,motionV:2,motionKeys:O.motionKeys??[],posX:C(u[0]/e),posY:C(u[1]/a),spatialDepth:C(M),scale:C(Math.max(1e-4,N/e)),rotation:q(D),tiltX:q(b),tiltY:q(v)}}}const $o=24e3,xt=new WeakMap,Ut=new Map;function Xt(t){let o=xt.get(t);if(!o){const s=JSON.stringify(t);o=s.length<=$o?Promise.resolve(null):re(s).then(n=>(Ut.set(n,t),n)),o.catch(()=>xt.delete(t)),xt.set(t,o)}return o}async function Ye(t){return Promise.all(t.map(async o=>{let s=o;const n=o.mask;if(n&&n.v===2&&!vo(n)){const r=await Xt(n);r&&(s={...s,mask:{v:2,mw:n.mw,mh:n.mh,ref:r}})}const e=o.planar;if(e&&!Yt(e)){const r=await Xt(e);r&&(s={...s,planar:{v:1,mw:e.mw,mh:e.mh,ref:r}})}const a=o.sceneTrack;if(a&&!jt(a)){const r=await Xt(a);r&&(s={...s,sceneTrack:{v:1,mode:a.mode,w:a.w,h:a.h,mw:a.mw,mh:a.mh,ref:r,...a.key?{key:a.key}:{}}})}return s}))}async function Lt(t){const o=Ut.get(t);if(o)return o;const s=JSON.parse(await ae(t));return Ut.set(t,s),s}async function $e(t){let o=0;return{clips:await Promise.all(t.map(async n=>{let e=n;const a=n.mask;if(vo(a))try{const i=ne(await Lt(a.ref),n.duration);if(i.v!==2||!("masks"in i))throw Error("Invalid mask");xt.set(i,Promise.resolve(a.ref)),e={...e,mask:i}}catch{o++}const r=n.planar;if(Yt(r))try{const i=se(await Lt(r.ref),n.duration);if(Yt(i))throw Error("Invalid planar track");xt.set(i,Promise.resolve(r.ref)),e={...e,planar:i}}catch{o++}const l=n.sceneTrack;if(jt(l))try{const i=_e(await Lt(l.ref));if(jt(i))throw Error("Invalid scene track");xt.set(i,Promise.resolve(l.ref)),e={...e,sceneTrack:{...i,...l.key?{key:l.key}:{}}}}catch{o++}return e})),missing:o}}const wn=Object.freeze(Object.defineProperty({__proto__:null,MASK_INLINE_MAX:$o,packMasks:Ye,unpackMasks:$e},Symbol.toStringTag,{value:"Module"}));export{Ae as A,to as B,lt as C,an as D,De as E,Mn as F,Je as G,Xe as H,Fe as I,qe as J,fn as K,hn as L,we as M,ue as N,ie as O,xe as P,ce as Q,le as R,$ as S,Be as T,Oe as U,yn as V,Ue as W,wn as X,dn as a,un as b,gn as c,Yo as d,xn as e,Bt as f,ct as g,bn as h,ln as i,rn as j,nn as k,We as l,sn as m,He as n,cn as o,Ye as p,en as q,on as r,mn as s,pn as t,$e as u,tn as v,Ze as w,Qe as x,Ge as y,_o as z};
|
|
1
|
+
import{_ as Vo,g0 as Ct,ed as no,ee as vt,cd as Gt,kh as ko,ec as wt,d7 as yt,fw as it,fn as Bo,g1 as yo,fP as Uo,iM as Go,au as Et,F as ut,c0 as Jo,jf as go,mS as bo,mT as Qo,ij as so,ii as ro,jh as Zo,fr as Ho,jj as xo,mU as wo,mV as Wo,mW as ao,mX as te,mY as oe,ji as Jt,jk as ee,cC as vo,dD as Yt,kj as ne,mZ as se}from"./titleFrameBudget-BYRZAQPs.js";import{bW as re,bX as ae}from"./api-DUp403BK.js";const qt=.1,Kt=t=>Math.abs(t)>180?(t%360+540)%360-180:t;function Eo(t,o,s,n,e,a,r,l,i){const c=l-r,f=t==null?s-o:(s-t)/Math.max(1e-9,l-a)*c,h=n==null?s-o:(n-o)/Math.max(1e-9,i-r)*c,p=e*e,u=p*e;return(2*u-3*p+1)*o+(u-2*p+e)*f+(-2*u+3*p)*s+(u-p)*h}function Ao(t,o,s,n,e,a,r,l,i){const c=o+Kt(s-o),f=t==null?null:o+Kt(t-o),h=n==null?null:c+Kt(n-c);return Eo(f,o,c,h,e,a,r,l,i)}function ie(t,o,s=n=>n.time){if(globalThis.__clipooxLinearKeys)return!1;const n=(e,a)=>s(t[a])-s(t[e]);return!(n(o,o+1)>qt||o>0&&n(o-1,o)>qt||o+2<t.length&&n(o+1,o+2)>qt)}function Qt(t,o,s,n){let e=o>0,a=o+2<t.length;if(n!=null){const l=e?s(t[o-1]):null,i=s(t[o]),c=s(t[o+1]),f=a?s(t[o+2]):null;if(i<n-1e-9&&c>=n-1e-9)return{before:!1,after:!1};a&&c<n-1e-9&&f>=n-1e-9&&(a=!1),e&&i>=n-1e-9&&l<n-1e-9&&(e=!1)}return{before:e,after:a}}function Be(t,o,s,n=r=>r.pose,e=r=>r.time,a=null){const r=Qt(t,o,e,a),l=n(t[o]),i=n(t[o+1]),c=r.before?n(t[o-1]):null,f=r.after?n(t[o+2]):null,h=e(t[o]),p=e(t[o+1]),u=c?e(t[o-1]):h-(p-h),m=f?e(t[o+2]):p+(p-h),y={};for(const M of new Set([...Object.keys(l),...Object.keys(i)])){const d=l[M]??0,x=i[M]??0;if(typeof d!="number"||typeof x!="number")continue;const g=c&&typeof c[M]=="number"?c[M]:null,w=f&&typeof f[M]=="number"?f[M]:null;y[M]=Ao(g,d,x,w,s,u,h,p,m)}return y}function le(t,o,s,n=r=>r.position,e=r=>r.time,a=null){const r=Qt(t,o,e,a),l=n(t[o]),i=n(t[o+1]),c=r.before?n(t[o-1]):null,f=r.after?n(t[o+2]):null,h=e(t[o]),p=e(t[o+1]),u=c?e(t[o-1]):h-(p-h),m=f?e(t[o+2]):p+(p-h);return l.map((y,M)=>Eo(c?c[M]:null,y,i[M],f?f[M]:null,s,u,h,p,m))}function ce(t,o,s,n,e=r=>r.time,a=null){const r=Qt(t,o,e,a),l=n(t[o]),i=n(t[o+1]),c=r.before?n(t[o-1]):null,f=r.after?n(t[o+2]):null,h=e(t[o]),p=e(t[o+1]),u=c!=null?e(t[o-1]):h-(p-h),m=f!=null?e(t[o+2]):p+(p-h);return Ao(c,l,i,f,s,u,h,p,m)}const At=30,io=4,bt=Object.freeze({min:.25,max:6,default:3}),Rt=40,Po=300,Co=Object.freeze({position:.01,rotation:2}),So=80,To=Object.freeze(["here","above","explode","throw"]),$t=Object.freeze({bouncy:Object.freeze({restitution:.6,friction:.45}),normal:Object.freeze({restitution:.25,friction:.6}),heavy:Object.freeze({restitution:.04,friction:.9})}),fe=9.81;let Xt=null,Ro=null;const Io=()=>Ro;function jo(){return Xt??=(async()=>{const t=await Vo(()=>import("./rapier-DBjBuyhF.js"),[]),o=t.default??t,s=console.warn;console.warn=(...n)=>{String(n[0]).includes("deprecated parameters")||s(...n)};try{await o.init()}finally{console.warn=s}return Ro=o,o})().catch(t=>{throw Xt=null,t}),Xt}const ot=t=>typeof t=="number"&&Number.isFinite(t),Y=(t,o)=>Array.isArray(t)&&t.length===3&&t.every(ot)?[t[0],t[1],t[2]]:o,Q=Math.PI/180,St=t=>(t%360+540)%360-180,Tt=t=>Math.round(t*1e4)/1e4,Vt=t=>Math.round(t*100)/100;function Pt(t){const o=Math.cos(t[0]*Q/2),s=Math.cos(t[1]*Q/2),n=Math.cos(t[2]*Q/2),e=Math.sin(t[0]*Q/2),a=Math.sin(t[1]*Q/2),r=Math.sin(t[2]*Q/2);return[e*s*n+o*a*r,o*a*n-e*s*r,o*s*r+e*a*n,o*s*n-e*a*r]}function _o(t){const[o,s,n,e]=t,a=1-2*(s*s+n*n),r=2*(o*s-n*e),l=2*(o*n+s*e),i=1-2*(o*o+n*n),c=2*(s*n-o*e),f=2*(s*n+o*e),h=1-2*(o*o+s*s),p=Math.asin(Math.max(-1,Math.min(1,l)));return Math.abs(l)<.9999999?[Math.atan2(-c,h)/Q,p/Q,Math.atan2(-r,a)/Q]:[Math.atan2(f,i)/Q,p/Q,0]}const lo=(t,o)=>{const[s,n,e,a]=t,r=a*o[0]+n*o[2]-e*o[1],l=a*o[1]+e*o[0]-s*o[2],i=a*o[2]+s*o[1]-n*o[0],c=-s*o[0]-n*o[1]-e*o[2];return[r*a+c*-s+l*-e-i*-n,l*a+c*-n+i*-s-r*-e,i*a+c*-e+r*-n-l*-s]},Do=(t,o)=>2*Math.acos(Math.min(1,Math.abs(t[0]*o[0]+t[1]*o[1]+t[2]*o[2]+t[3]*o[3])))/Q;function Fo(t){let o=2166136261;for(const n of String(t))o=Math.imul(o^n.codePointAt(0),16777619);let s=o>>>0;return()=>{s=s+1831565813|0;let n=Math.imul(s^s>>>15,1|s);return n=n+Math.imul(n^n>>>7,61|n)^n,((n^n>>>14)>>>0)/4294967296}}const co=new Set(["box","sphere","cylinder","wall","platform"]),he=new Set(["person","fx","splat","set","floor"]);function ue(t){return t?t.locked?"Đối tượng đang khoá":t.hold?"Đồ đang cầm đi theo tay người cầm":t.kind==="person"||t.kind==="model"&&(t.skeleton==="native"||t.rig?.kind==="humanoid")?"Nhân vật không rơi như vật thể — dùng chuyển động":he.has(t.kind)?"Loại đối tượng này không rơi được":null:"Chưa chọn đối tượng"}function pe(t){const o=Y(t.scale,[1,1,1]);return t.kind==="sphere"&&Math.abs(o[0]-o[1])<1e-6&&Math.abs(o[1]-o[2])<1e-6||t.kind==="prop"&&t.prop?.kind==="ball"?"ball":t.kind==="cylinder"&&Math.abs(o[0]-o[2])<1e-6?"cylinder":"box"}function me(t){const o=Y(t.scale,[1,1,1]).map(Math.abs),s=Y(t.mirror,[1,1,1]),n=Y(t.origin,[0,0,0]);let e=[1,1,1],a=[0,.5,0];if(t.kind==="proxy"&&t.proxy?.dims)e=Y(t.proxy.dims,e),a=[0,e[1]/2,0];else if(t.kind==="prop"){const i=t.prop?.kind==="ball"?.12:.15;e=[2*i,2*i,2*i],a=[0,t.prop?.kind==="ball"?0:i,0]}else if(t.kind==="model"){const i=t.model?.height??2;e=[i*.6,i,i*.6],a=[0,i/2,0]}else co.has(t.kind)||(e=[.5,.5,.5],a=[0,.25,0]);const r=co.has(t.kind)?[(a[0]-n[0])*s[0],(a[1]-n[1])*s[1],(a[2]-n[2])*s[2]]:a,l=i=>[i[0]*(t.scale?.[0]??1),i[1]*(t.scale?.[1]??1),i[2]*(t.scale?.[2]??1)];return{half:[e[0]*o[0]/2,e[1]*o[1]/2,e[2]*o[2]/2],offset:l(r)}}function de(t,o){let s=0,n=t.length-1;for(;n-s>1;){const e=s+n>>1;t[e].time<=o?s=e:n=e}return s}function zo(t,o,s=null,n=null){const e=t[0],a=t[t.length-1];if(o<=e.time)return{position:e.position,rotation:e.rotation};if(o>=a.time)return{position:a.position,rotation:a.rotation};const r=de(t,o),l=t[r],i=t[r+1],c=(o-l.time)/(i.time-l.time),f=h=>l.rotation[h]+St(i.rotation[h]-l.rotation[h])*c;return ie(t,r,n>0?h=>h.time*n:void 0)?{position:le(t,r,c,h=>h.position,h=>h.time,s),rotation:[f(0),ce(t,r,c,h=>h.rotation[1],h=>h.time,s),f(2)]}:{position:[0,1,2].map(h=>l.position[h]+(i.position[h]-l.position[h])*c),rotation:[f(0),f(1),f(2)]}}function qo(t,{tolerance:o=Co,maxKeys:s=So,before:n=null,seam:e=null,duration:a=null}={}){const r=t.length;if(r<=2)return{keys:t.map(({time:f,position:h,rotation:p})=>({time:f,position:h,rotation:p})),error:{position:0,rotation:0}};const l=new Set([0,r-1]),i=()=>[...l].sort((f,h)=>f-h).map(f=>t[f]);let c={position:0,rotation:0};for(;;){const f=i(),h=n?[n,...f]:f;let p=-1,u=1;c={position:0,rotation:0};for(let m=1;m<r-1;m++){if(l.has(m))continue;const y=t[m],M=zo(h,y.time,e,a),d=Math.hypot(M.position[0]-y.position[0],M.position[1]-y.position[1],M.position[2]-y.position[2]),x=Do(Pt(M.rotation),y.quat);c={position:Math.max(c.position,d),rotation:Math.max(c.rotation,x)};const g=Math.max(d/o.position,x/o.rotation);g>u&&(u=g,p=m)}if(p<0||l.size>=s)break;l.add(p)}return{keys:i().map(({time:f,position:h,rotation:p})=>({time:f,position:h,rotation:p})),error:{position:Tt(c.position),rotation:Vt(c.rotation)}}}const Me=t=>ot(t)?{restitution:Math.max(0,Math.min(.95,t)),friction:.6}:$t[t]??$t.normal;async function ye(t){const o=Zt(await jo(),t),{duration:s,mode:n}=o,e=ot(t.start)?Math.max(0,t.start):0,a=ot(t.shotDuration)&&t.shotDuration>0?t.shotDuration:e+s,r={},l=e/a;for(const i of o.bodies){let c=null;const f=i.samples.map(m=>{let y=_o(m.q);if(c){const M=[y[0]+180,180-y[1],y[2]+180],d=x=>x.reduce((g,w,b)=>g+Math.abs(St(w-c[b])),0);d(M)<d(y)&&(y=M)}return y=y.map(M=>Vt(St(M)===-180?180:St(M))),c=y,{time:l+m.sec/a,position:m.pivot.map(Tt),rotation:y,quat:Pt(y)}}),h=t.before?.[i.id],{keys:p,error:u}=qo(f,{before:h&&ot(h.time)&&h.time<l?h:null,seam:ot(t.seam)?t.seam:null,duration:a});r[i.id]={keys:p,error:u,settledAt:i.settledAt,from:{position:i.position.map(Tt),rotation:i.rotation.map(Vt)},rest:f[f.length-1].position,restCentre:i.samples[i.samples.length-1].centre.map(Tt),restQuat:i.samples[i.samples.length-1].q}}return{tracks:r,settled:o.settled,seconds:s,mode:n}}function Zt(t,o){const s=!!o.planar,n=To.includes(o.mode)?o.mode:"here",e=Math.max(bt.min,Math.min(bt.max,ot(o.duration)?o.duration:bt.default)),a=ot(o.floor)?o.floor:0,r=Me(o.bounciness),l=Fo(`${o.seed??"drop"}|${n}`),i=m=>(l()*2-1)*m,c=(o.bodies||[]).filter(m=>m&&m.id!=null).map(m=>({id:String(m.id),shape:["ball","cylinder"].includes(m.shape)?m.shape:"box",position:Y(m.position,[0,0,0]),rotation:Y(m.rotation,[0,0,0]),half:Y(m.half,[.25,.25,.25]).map(y=>Math.max(.01,Math.abs(y))),offset:Y(m.offset,[0,0,0])})).sort((m,y)=>m.id<y.id?-1:m.id>y.id?1:0).slice(0,Rt);if(!c.length)throw new Error("no objects to drop");const f=m=>Math.hypot(...m.half);for(const m of c){m.q=Pt(m.rotation);const y=lo(m.q,m.offset);m.c=[m.position[0]+y[0],m.position[1]+y[1],m.position[2]+y[2]],m.v=[0,0,0],m.w=[0,0,0]}if(n==="above"){const m=ot(o.height)?Math.max(.3,Math.min(20,o.height)):2,y=Math.max(...c.map(d=>d.c[1]+f(d))),M=[];for(const d of[...c].sort((x,g)=>x.c[1]-g.c[1]||(x.id<g.id?-1:1))){d.q=Pt(s?[d.rotation[0],d.rotation[1],d.rotation[2]+i(35)]:[d.rotation[0]+i(35),d.rotation[1]+i(180),d.rotation[2]+i(35)]);let x=y+m+f(d);for(const g of M)Math.hypot(g.c[0]-d.c[0],g.c[2]-d.c[2])<f(g)+f(d)&&(x=Math.max(x,g.c[1]+f(g)+f(d)+.05));d.c=s?[d.c[0],x,d.c[2]]:[d.c[0]+i(.05),x,d.c[2]+i(.05)],M.push(d)}}if(n==="here")for(const m of c)m.w=[i(1.2),i(1.2),i(1.2)];const h=m=>s?[0,0,m[2]]:m,p=m=>s?[m[0],m[1],0]:m;if(n==="explode"){const m=Y(o.center,[0,1,2].map(M=>c.reduce((d,x)=>d+x.c[M],0)/c.length)),y=ot(o.strength)?Math.max(.5,Math.min(20,o.strength)):4;for(const M of c){let d=M.c[0]-m[0],x=s?0:M.c[2]-m[2],g=Math.hypot(d,x);if(g<.001){const b=l()*Math.PI*2;d=Math.cos(b),x=s?0:Math.sin(b),g=Math.hypot(d,x)||1}const w=y*(.75+l()*.5);M.v=[d/g*w,w*(.6+l()*.4),x/g*w],M.w=[i(7),i(7),i(7)]}}if(n==="throw"){const m=Y(o.velocity,[0,2,3]);for(const y of c)y.v=m.map(M=>M*(1+i(.08))),y.w=[i(5),i(5),i(5)]}const u=new t.World({x:0,y:-(ot(o.gravity)?o.gravity:fe),z:0});try{u.timestep=1/(At*io);for(const g of c)g.v=p(g.v),g.w=h(g.w);const m=(g,w)=>{const b=u.createRigidBody(t.RigidBodyDesc.fixed().setTranslation(g[0],g[1],g[2]));u.createCollider(t.ColliderDesc.cuboid(w[0],w[1],w[2]).setRestitution(r.restitution).setFriction(r.friction),b)};m([0,a-1,0],[1e3,1,1e3]);let y=0;for(const g of o.statics||[]){const w=Y(g?.min,null),b=Y(g?.max,null);if(!w||!b||y>=Po)continue;const v=[0,1,2].map(R=>(b[R]-w[R])/2);v.some(R=>!(R>.002))||b[1]<=a+.001||(m([0,1,2].map(R=>(w[R]+b[R])/2),v),y++)}for(const g of c){g.rb=u.createRigidBody(t.RigidBodyDesc.dynamic().setTranslation(g.c[0],g.c[1],g.c[2]).setRotation({x:g.q[0],y:g.q[1],z:g.q[2],w:g.q[3]}).setLinvel(g.v[0],g.v[1],g.v[2]).setAngvel({x:g.w[0],y:g.w[1],z:g.w[2]}).setLinearDamping(.05).setAngularDamping(g.shape==="box"?.2:1.2).setCcdEnabled(!0)),s&&(g.rb.setEnabledTranslations(!0,!0,!1,!1),g.rb.setEnabledRotations(!1,!1,!0,!1));const w=g.shape==="ball"?t.ColliderDesc.ball(Math.max(...g.half)):g.shape==="cylinder"?t.ColliderDesc.cylinder(g.half[1],Math.max(g.half[0],g.half[2])):t.ColliderDesc.cuboid(g.half[0],g.half[1],g.half[2]);u.createCollider(w.setRestitution(r.restitution).setFriction(r.friction).setDensity(400),g.rb),g.samples=[]}const M=Math.round(e*At);for(let g=0;g<=M;g++){if(g)for(let w=0;w<io;w++)u.step();for(const w of c){const b=w.rb.translation(),v=w.rb.rotation(),R=[v.x,v.y,v.z,v.w],T=lo(R,w.offset),D=w.rb.linvel(),q=w.rb.angvel();w.samples.push({sec:g/At,centre:[b.x,b.y,b.z],pivot:[b.x-T[0],b.y-T[1],b.z-T[2]],q:R,speed:Math.hypot(D.x,D.y,D.z)+Math.hypot(q.x,q.y,q.z)*f(w)})}}let d=!0;return{bodies:c.map(g=>{let w=null;for(let b=g.samples.length-1;b>=0&&g.samples[b].speed<.05;b--)w=g.samples[b].sec;return w==null&&(d=!1),{id:g.id,position:g.position,rotation:g.rotation,half:g.half,offset:g.offset,samples:g.samples,settledAt:w}}),settled:d,duration:e,mode:n}}finally{u.free()}}function ge(t,o,s,{scale:n={},newId:e,lifted:a=!1}={}){const r=e??(()=>globalThis.crypto.randomUUID());return{...t,shots:t.shots.map(l=>{if(l.id!==o)return l;const i={...l.objectKeys};for(const[c,f]of Object.entries(s)){if(!f.keys.length)continue;const h=f.keys[0].time,p=t.items.find(M=>M.id===c),u=Y(n[c],Y(p?.scale,[1,1,1])),m=(i[c]||[]).filter(M=>M.time<h-1e-6),y=1/(At*Math.max(1e-6,l.duration||1));a&&f.from&&m.length&&h-y>m[m.length-1].time+1e-6&&m.push({id:r(),time:h-y,position:[...f.from.position],rotation:[...f.from.rotation],scale:[...u]}),i[c]=[...m,...f.keys.map(M=>({id:r(),time:M.time,position:[...M.position],rotation:[...M.rotation],scale:[...u]}))]}return{...l,objectKeys:i}})}}const Ue=Object.freeze(Object.defineProperty({__proto__:null,BOUNCE_PRESETS:$t,DROP_MODES:To,DROP_SECONDS:bt,KEY_TOLERANCE:Co,MAX_KEYS_PER_BODY:So,MAX_PHYSICS_BODIES:Rt,MAX_PHYSICS_STATICS:Po,PHYSICS_FPS:At,applyDropKeys:ge,bakeDrop:ye,dropUnavailable:ue,eulerFromQuat:_o,fallbackShape:me,loadRapier:jo,quatAngle:Do,quatFromEuler:Pt,rapierReady:Io,sampleBakedKeys:zo,seededRandom:Fo,shapeKind:pe,simulateDrop:Zt,thinKeys:qo},Symbol.toStringTag,{value:"Module"})),Ko=["x","y","zoom","rot","opacity","depth"],N=t=>Math.round(t*1e4)/1e4,Dt=(t,o)=>Object.keys(it).filter(s=>(!o||o.includes(s))&&Bo(t,s));function Ge(t,{in:o=.33,out:s=.33}={},n){const e=ko([Math.max(0,Math.min(1,s)),0,Math.max(0,Math.min(1,1-o)),1]);let a={...t},r={};for(const l of Dt(t)){const i=wt(a,l),c=n?n.filter(h=>h.prop===l):i;if(!c.length)continue;const f=i.map((h,p)=>p<i.length-1&&c.some(u=>Math.abs(u.time-h.time)<1/120)?{...h,ease:e}:h);r={...r,...yt(a,l,f)},a={...a,...r}}return r}const Ht={tl:[0,0],t:[.5,0],tr:[1,0],l:[0,.5],c:[.5,.5],r:[1,.5],bl:[0,1],b:[.5,1],br:[1,1]},Je=Object.keys(Ht);function Qe(t,o,s,n,e,a){const[r,l]=Ht[s],i=o.angle*Math.PI/180,c=Math.abs(o.w*Math.cos(i))+Math.abs(o.h*Math.sin(i)),f=Math.abs(o.w*Math.sin(i))+Math.abs(o.h*Math.cos(i)),h=c/2+(e-c)*r,p=f/2+(a-f)*l,u=(h-o.cx)/e,m=(p-o.cy)/a,y=(d,x)=>Math.max(it[d].min,Math.min(it[d].max,x));let M=no(t,"x",N(y("x",vt(t,"x",n)+u)),n);return M={...M,...no({...t,...M},"y",N(y("y",vt(t,"y",n)+m)),n)},M}function Ze(t,o,s,n,e,a){const[r,l]=Ht[s],i=Gt(t,n,e,a).zoom||1;return Go(t,n,N((r-.5)*o.w/(e*i)),N((l-.5)*o.h/(a*i)),e,a)}function He(t,o,s,n="forward",e=1){let a=t.filter(i=>o.includes(i.id)).sort((i,c)=>c.track-i.track||i.start-c.start);if(a.length<2)return t;if(n==="reverse")a.reverse();else if(n==="center"){const i=(a.length-1)/2;a=[...a].sort((c,f)=>Math.abs(a.indexOf(c)-i)-Math.abs(a.indexOf(f)-i))}else if(n==="random"){let i=e>>>0||1;const c=()=>(i=Math.imul(i^i>>>15,2246822507)>>>0)/4294967295;a=a.map(f=>[c(),f]).sort((f,h)=>f[0]-h[0]).map(f=>f[1])}const r=Math.min(...a.map(i=>i.start)),l=new Map(a.map((i,c)=>[i.id,N(Math.max(0,r+c*s))]));return t.map(i=>l.has(i.id)?{...i,start:Math.min(l.get(i.id),600-i.duration)}:i)}function We(t,o){const s={};for(const e of Dt(t)){const a=wt(t,e).filter(r=>!o||o.some(l=>l.prop===e&&Math.abs(l.time-r.time)<.008333333333333333));a.length&&(s[e]=a)}const n=Math.min(...Object.values(s).flat().map(e=>e.time));return Object.keys(s).length?{props:Object.fromEntries(Object.entries(s).map(([e,a])=>[e,a.map(r=>({...r,time:N(r.time-n)}))]))}:null}function tn(t,o,s){let n={...t},e={};for(const[a,r]of Object.entries(o.props)){if(!it[a]||t.kind==="model"&&a==="rot"||t.kind!=="model"&&["rx","ry","rz"].includes(a))continue;const l=r.map(c=>({...c,time:N(s+c.time)})).filter(c=>c.time<=t.duration+1e-6),i=wt(n,a).filter(c=>!l.some(f=>Math.abs(f.time-c.time)<1/120));e={...e,...yt(n,a,[...i,...l].sort((c,f)=>c.time-f.time))},n={...n,...e}}return e}function on(t,o="elastic",{amount:s=.5,cycles:n=3,props:e}={}){let a={...t},r={};for(const l of Dt(t,e??Ko)){const i=wt(a,l);if(i.length<2)continue;const c=i.at(-2),f=i.at(-1),h=f.time-c.time,p=t.duration-f.time;if(h<=0||p<.1)continue;const u=f.value-c.value;if(Math.abs(u)<1e-6)continue;const m=Math.max(1,Math.min(6,Math.round(n))),y=Math.min(p/(m*2),Math.max(.06,h*.6)),M=[];for(let d=1;d<=m*2;d++){const x=s*Math.pow(.45,Math.ceil(d/2)-1),g=o==="bounce"?(d%2?-1:0)*Math.abs(u)*x*Math.sign(u):(d%2?1:-1)*u*x*.5,w=d===m*2?f.value:f.value+g,b=it[l].min,v=it[l].max;M.push({time:N(f.time+y*d),value:N(Math.max(b,Math.min(v,w))),ease:fo})}r={...r,...yt(a,l,[...i.map((d,x)=>x===i.length-1?{...d,ease:fo}:d),...M])},a={...a,...r}}return r}const fo=[.33,0,.67,1];function en(t,o="cycle",{props:s,maxKeys:n=60}={}){let e={...t},a={};for(const r of Dt(t,s)){const l=wt(e,r);if(l.length<2)continue;const i=l[0].time,c=l.at(-1).time,f=c-i;if(f<=1/30)continue;const h=[...l],p=l.at(-1).value-l[0].value;for(let u=1;h.length<n;u++){const m=o==="pingpong"&&u%2?[...l].reverse().map(M=>({...M,time:c-(M.time-i)})):l;let y=!1;for(const M of m.slice(1)){const d=N(M.time+f*u);if(d>t.duration+1e-6||h.length>=n)break;const x=o==="offset"?M.value+p*u:M.value,{min:g,max:w}=it[r];h.push({...M,time:d,value:N(Math.max(g,Math.min(w,x)))}),y=!0}if(!y)break}a={...a,...yt(e,r,h)},e={...e,...a}}return a}function nn(t,o){const s=Ct(t.shape)?t.shape:yo(t.shape);return s.items.map(n=>({...t,id:o(),label:`${t.label} · ${n.name}`.slice(0,60),shape:{...s,items:[{...n}]}}))}const be=["posX","posY","scale","rotation","anchorX","anchorY","parentId","opacity"];function sn(t){if(t.length<2)throw Error("Chọn ít nhất 2 layer Shape để gộp");const[o,...s]=t,n=a=>be.every(r=>(a[r]??null)===(o[r]??null))&&!a.motionKeys?.some(r=>Ko.some(l=>l in r));if(!t.every(n))throw Error("Chỉ gộp được các layer Shape cùng vị trí / tỉ lệ / góc xoay và không có key chuyển động");const e=[];for(const a of t){const r=Ct(a.shape)?a.shape:yo(a.shape);for(const l of r.items)e.push({...l,id:Uo(e)})}if(e.length>24)throw Error("Một layer Shape chứa tối đa 24 hình");return{...o,start:Math.min(...t.map(a=>a.start)),duration:Math.max(...t.map(a=>a.start+a.duration))-Math.min(...t.map(a=>a.start)),shape:{v:2,items:e}}}function rn(t,o,s,{fps:n=10,makeId:e,label:a}={}){const r=Math.min(o/1280,s/720),l=(y,M)=>[N(((y-o/2)/r+640-280)/.72),N(((M-s/2)/r+360)/.72)],i=Math.max(2,Math.min(255,Math.round(t.duration*n)+1)),c=[];for(let y=0;y<i;y++){const M=Gt(t,t.duration*y/(i-1),o,s);c.push(l(o/2+M.x*o,s/2+M.y*s))}const f=c.map(y=>y[0]),h=c.map(y=>y[1]),p=(Math.min(...f)+Math.max(...f))/2,u=(Math.min(...h)+Math.max(...h))/2,m={id:"s1",name:"Position Trace",type:"path",params:{pts:c.map(([y,M])=>[N(y-p),N(M-u)]),closed:!1},pos:[N(p),N(u)],rot:0,scale:[1,1],opacity:1,fill:{type:"none"},stroke:{color:"#c6f432",width:8,cap:"round",join:"round"}};return{id:e(),nodeId:"",kind:"image",url:"",label:a??`${t.label} · trace`.slice(0,60),track:t.track,start:t.start,duration:t.duration,volume:0,motionV:2,shape:{v:2,items:[m]}}}const Wt=/^#[0-9a-fA-F]{6}$/,xe=24,an=["#c6f432","#2bd4c9","#ffffff","#0d0f12","#ff5bd1"];function ln(t,o=16){const s=new Map,n=e=>{if(typeof e=="string"&&Wt.test(e)){const a=e.toLowerCase();s.set(a,(s.get(a)||0)+1)}};for(const e of t){e.title&&(n(e.title.color),n(e.title.accentColor));const a=e.shape;if(a)if(Ct(a))for(const r of a.items){n(r.fill.color);for(const l of r.fill.stops||[])n(l[0]);n(r.stroke?.color)}else for(const r of a.paths)n(r.stroke),n(r.fill)}return[...s.entries()].sort((e,a)=>a[1]-e[1]).slice(0,o).map(e=>e[0])}function cn(t,o,{stroke:s=!1,itemId:n}={}){if(!Wt.test(o))throw Error("Invalid colour");if(t.title)return{title:{...t.title,[s?"accentColor":"color"]:o}};if(!t.shape)throw Error("Chọn layer Shape hoặc chữ để áp màu");return Ct(t.shape)?{shape:{...t.shape,items:t.shape.items.map(e=>n&&e.id!==n?e:s?{...e,stroke:{...e.stroke??{width:8,cap:"round",join:"round"},color:o}}:{...e,fill:e.fill.type==="linear"||e.fill.type==="radial"?{...e.fill,stops:e.fill.stops.map((a,r)=>r===0?[o,a[1]]:a)}:{...e.fill,type:"color",color:o}})}}:{shape:{...t.shape,paths:t.shape.paths.map(e=>s||!e.fill?{...e,stroke:o}:{...e,fill:o})}}}function fn(t,o){if(!Array.isArray(o)||!o.length||o.length>xe||!o.every(e=>Wt.test(e)))throw Error("Invalid palette");const s=e=>o[e%o.length];if(t.title)return{title:{...t.title,color:s(0),...o.length>1?{accentColor:s(1)}:{}}};if(!t.shape)throw Error("Chọn layer Shape hoặc chữ để áp màu");if(!Ct(t.shape))return{shape:{...t.shape,paths:t.shape.paths.map((e,a)=>({...e,...e.fill?{fill:s(a)}:{},...e.stroke?{stroke:e.fill?e.stroke:s(a)}:{}}))}};let n=0;return{shape:{...t.shape,items:t.shape.items.map(e=>{const a=e.fill;return a.type==="linear"||a.type==="radial"?{...e,fill:{...a,stops:a.stops.map(r=>[s(n++),r[1]])}}:a.type==="color"?{...e,fill:{...a,color:s(n++)}}:e.stroke?{...e,stroke:{...e.stroke,color:s(n++)}}:e})}}}function we(t,o,s,n){const e=Gt(t,o,s,n),a=t.card?t.card.width/t.card.height:t.lottie?t.lottie.w/t.lottie.h:null,[r,l]=a&&Number.isFinite(a)&&a>0?a>s/n?[s,s/a]:[n*a,n]:[s,n];return{cx:s/2+e.x*s,cy:n/2+e.y*n,w:r*e.zoom,h:l*e.zoom,angle:e.rot}}const ve=3,kt=30,Ot=Object.freeze({xy:.002,rot:1.5}),Ee=.2,ho=t=>typeof t=="number"&&Number.isFinite(t),uo=t=>Math.round(t*1e4)/1e4;function Ae(t){return t?t.kind==="audio"?"Âm thanh không rơi được":t.adjust===!0?"Lớp điều chỉnh không có hình để rơi":t.parentId?"Lớp đang gắn vào lớp cha — bỏ gắn rồi thử lại":null:"Không tìm thấy lớp"}function to(t,o,s,n=kt){const e=t.length;if(e<=2)return[...Array(e).keys()];const a=[0,e-1];for(;;){a.sort((i,c)=>i-c);let r=-1,l=s;for(let i=0;i+1<a.length;i++){const c=a[i],f=a[i+1];for(let h=c+1;h<f;h++){const p=o[c]+(o[f]-o[c])*(t[h]-t[c])/(t[f]-t[c]),u=Math.abs(p-o[h]);u>l&&(l=u,r=h)}}if(r<0||a.length>=n)return a;a.push(r)}}function Pe(t,o,s){let n=0;for(let e=0;e+1<s.length;e++)for(let a=s[e]+1;a<s[e+1];a++){const r=s[e],l=s[e+1];n=Math.max(n,Math.abs(o[r]+(o[l]-o[r])*(t[a]-t[r])/(t[l]-t[r])-o[a]))}return n}function Ce(t,o,s){const n=[],e=r=>Math.floor((r+180)/360),a=(r,l)=>r-360*l;for(let r=0;r<s.length;r++){const l=s[r],i=o[l],c=e(i);if(r){const f=s[r-1],h=e(o[f]);if(h!==c){const p=c>h,u=(p?h+1:h)*360-180,m=(u-o[f])/(i-o[f]),y=Et(t[f]+(t[l]-t[f])*m),M=Math.max(n.at(-1).time+1/ut,Math.min(y,Et(t[l]-2/ut))),d=M+1/ut;d<t[l]-1e-6?n.push({time:M,value:p?180:-180,ease:"hold"},{time:d,value:p?-180:180}):n[n.length-1]={...n[n.length-1],ease:"hold"}}}n.push({time:t[l],value:Math.max(-180,Math.min(180,a(i,c)))})}return n}function hn(t,o,s={}){const n=s.R??Io();if(!n)throw Error("Physics engine not loaded yet — try again");const e=s.W??1280,a=s.H??720,r=ve/a,l=ho(s.at)?s.at:0,i=Math.max(1,Math.min(bt.max,ho(s.duration)?s.duration:bt.default)),c=s.mode==="above"?"above":"here",f=[...new Set(o)].map(b=>t.find(v=>v.id===b));if(!f.length)throw Error("physicsDrop needs clipIds");if(f.length>Rt)throw Error(`At most ${Rt} layers per drop`);for(const[b,v]of f.entries()){const R=Ae(v);if(R)throw Error(`${v?.label??o[b]}: ${R}`)}const h=f.map(b=>{const v=Et(l-b.start);if(v<0||v>b.duration-2/ut)throw Error(`${b.label??b.id}: the playhead is outside the layer`);const R=vt(b,"x",v),T=vt(b,"y",v),D=vt(b,"rot",v),q=s.rectOf?.(b)??we(b,v,e,a),O=[R*e*r,-T*a*r],X=[(q.cx-e/2)*r,-(q.cy-a/2)*r],P=D*Math.PI/180,E=[X[0]-O[0],X[1]-O[1]],I=[E[0]*Math.cos(P)-E[1]*Math.sin(P),E[0]*Math.sin(P)+E[1]*Math.cos(P)];return{id:b.id,position:[O[0],O[1],0],rotation:[0,0,-D],half:[Math.max(4,q.w)*r/2,Math.max(4,q.h)*r/2,Ee],offset:[I[0],I[1],0],local:v,x:R,y:T,rot:D}}),p=-a*r/2,u=a*r/2,m=e*r/2,y=s.walls?[{min:[-m-2,p,-2],max:[-m,u+20,2]},{min:[m,p,-2],max:[m+2,u+20,2]}]:[],M=b=>Math.hypot(b.half[0],b.half[1],b.half[2]),d=Math.max(...h.map(b=>b.position[1]+M(b))),x=Zt(n,{bodies:h,statics:y,floor:p,mode:c,bounciness:s.bounciness,duration:i,height:Math.max(.3,u-d+.05),seed:s.seed??[...o].sort().join(","),planar:!0}),g={},w=t.map(b=>({...b}));for(const b of h){const v=x.bodies.find(F=>F.id===b.id),R=w.findIndex(F=>F.id===b.id);let T=w[R];const D=[],q=[],O=[],X=[];let P=b.rot;for(const F of v.samples){const G=Et(b.local+F.sec);if(G>T.duration+1e-6)break;let H=-2*Math.atan2(F.q[2],F.q[3])*180/Math.PI;H+=360*Math.round((P-H)/360),P=H,D.push(G),q.push(F.pivot[0]/r/e),O.push(-F.pivot[1]/r/a),X.push(H)}const E=c==="above"&&b.local>=1/ut,I={},V={},K=Math.min(...X),k=Math.max(...X),B=k-K<360?Math.ceil((k-180)/360)*360:0,mt=B&&K-B>=-180?X.map(F=>F-B):X,dt=mt!==X&&b.local>=1/ut;for(const[F,G,H]of[["x",q,Ot.xy],["y",O,Ot.xy],["rot",mt,Ot.rot]]){const Mt=E||F==="rot"&&dt,W=wt(T,F).filter(L=>L.time<b.local-(Mt?1.5:.5)/ut),tt=Mt?[{time:Et(b.local-1/ut),value:F==="x"?b.x:F==="y"?b.y:b.rot,...F==="rot"&&dt?{ease:"hold"}:{}}]:[],ft=F==="rot"?G.reduce((L,J,at)=>L+(at&&Math.floor((J+180)/360)!==Math.floor((G[at-1]+180)/360)?1:0),0):0,rt=kt-W.length-tt.length-2*ft;if(rt<2)throw Error(`${T.label??T.id}: too many ${F} keys before the playhead (or too many turns) to add the drop`);const ht=to(D,G,H,rt),gt=it[F].min,_=it[F].max,z=F==="rot"?Ce(D,G,ht):ht.map(L=>({time:D[L],value:Math.max(gt,Math.min(_,G[L]))})),nt=[...W,...tt,...z].map(L=>({time:L.time,value:uo(L.value),...L.ease?{ease:L.ease}:{}}));T={...T,...yt(T,F,nt.slice(0,kt))},I[F]=z.length,V[F]=uo(Pe(D,G,ht))}w[R]=T,g[b.id]={keys:I,error:V,settledAt:v.settledAt==null?null:Math.round((l+v.settledAt)*1e3)/1e3}}return{clips:w,report:g,settled:x.settled}}const $=Object.freeze({work:480,focals:[.45,.55,.7,.85,1,1.25],maxFrames:900,keyTolPx:.05,points:400,smooth:.3,smoothFrames:4,smoothTolPx:.25,dense:{cols:40,rows:22,keep:700,minFrames:8,max:1500},slide:.01}),C=t=>Math.round(t*1e6)/1e6,A=(t,o)=>[t[0]-o[0],t[1]-o[1],t[2]-o[2]],U=(t,o)=>[t[0]+o[0],t[1]+o[1],t[2]+o[2]],j=(t,o)=>[t[0]*o,t[1]*o,t[2]*o],S=(t,o)=>t[0]*o[0]+t[1]*o[1]+t[2]*o[2],st=(t,o)=>[t[1]*o[2]-t[2]*o[1],t[2]*o[0]-t[0]*o[2],t[0]*o[1]-t[1]*o[0]],et=t=>{const o=Math.hypot(...t)||1;return j(t,1/o)},Z=(t,o)=>[S(t[0],o),S(t[1],o),S(t[2],o)],pt=t=>[0,1,2].map(o=>[t[0][o],t[1][o],t[2][o]]),po=(t,o)=>t.map(s=>[0,1,2].map(n=>s[0]*o[0][n]+s[1]*o[1][n]+s[2]*o[2][n]));function Se(t,o,s,n=bo(29)){const e=t;if(e.length<20)return null;const a=e.map(r=>Math.hypot(...A(r,s))).sort((r,l)=>r-l)[e.length>>1];for(const r of[.015,.03,.05]){const l=a*r;let i=null;for(let u=0;u<2e3;u++){const m=e[Math.floor(n()*e.length)],y=e[Math.floor(n()*e.length)],M=e[Math.floor(n()*e.length)];let d=st(A(y,m),A(M,m));const x=Math.hypot(...d);if(x<1e-9||(d=j(d,1/x),S(d,o)<0&&(d=j(d,-1)),S(d,o)<Math.cos(35*Math.PI/180)))continue;const g=-S(d,m);if(S(d,s)+g<=l)continue;let w=0;for(const b of e)Math.abs(S(d,b)+g)<l&&w++;(!i||w>i.k)&&(i={n:d,d:g,k:w})}if(!i||i.k<e.length*.2)continue;const c=e.filter(u=>Math.abs(S(i.n,u)+i.d)<l),f=j(c.reduce((u,m)=>U(u,m),[0,0,0]),1/c.length),h=[[0,0,0],[0,0,0],[0,0,0]];for(const u of c){const m=A(u,f);for(let y=0;y<3;y++)for(let M=0;M<3;M++)h[y][M]+=m[y]*m[M]}let p=Ft(h);return S(p,o)<0&&(p=j(p,-1)),{n:p,d:-S(p,f),count:c.length}}return null}function Ft(t){const o=t.map(e=>[...e]),s=[[1,0,0],[0,1,0],[0,0,1]];for(let e=0;e<30;e++){let a=0;for(let r=0;r<3;r++)for(let l=r+1;l<3;l++)a+=o[r][l]**2;if(a<1e-24)break;for(let r=0;r<3;r++)for(let l=r+1;l<3;l++){if(Math.abs(o[r][l])<1e-30)continue;const i=(o[l][l]-o[r][r])/(2*o[r][l]),c=Math.sign(i||1)/(Math.abs(i)+Math.sqrt(i*i+1)),f=1/Math.sqrt(c*c+1),h=c*f;for(let p=0;p<3;p++){const u=o[p][r],m=o[p][l];o[p][r]=f*u-h*m,o[p][l]=h*u+f*m}for(let p=0;p<3;p++){const u=o[r][p],m=o[l][p];o[r][p]=f*u-h*m,o[l][p]=h*u+f*m}for(let p=0;p<3;p++){const u=s[p][r],m=s[p][l];s[p][r]=f*u-h*m,s[p][l]=h*u+f*m}}}const n=[0,1,2].reduce((e,a)=>o[a][a]<o[e][e]?a:e,0);return et([s[0][n],s[1][n],s[2][n]])}function It(t,o,s,n){const e=new Map;t.poses.forEach((a,r)=>{if(!(!a||a.lost))for(const[l,i]of t.obs[r]){const c=t.points.get(l);if(!c)continue;const f=Z(a.R,A(c,a.C)),h=f[2]>-1e-6?50:Math.hypot(s+o*f[0]/-f[2]-i[0],n-o*f[1]/-f[2]-i[1]),p=e.get(l)??[0,0,0];p[0]+=h,p[1]++,p[2]=Math.max(p[2],h),e.set(l,p)}});for(const a of e.values())a[0]/=a[1];return e}function jt(t,o,s,n){const e=[...It(t,o,s,n).values()].map(r=>r[0]).sort((r,l)=>r-l),a=Math.floor(e.length*.8);return a>30?e.slice(0,a).reduce((r,l)=>r+l,0)/a:1/0}function mo(t,o,s,n){const{solved:e,keyframes:a}=Xo(t);for(let r=0;r<3;r++){const l=It(t,o,s,n),i=[...l.values()].map(h=>h[2]).sort((h,p)=>h-p),c=Math.max(1.2,2*(i[i.length>>1]??1));let f=0;for(const[h,p]of l)p[2]>c&&(t.points.delete(h),f++);if(!f)break;Jt(t.poses,t.points,t.obs,a,o,s,n,8),Oo(t,a,e,o,s,n)}}function Xo(t){const o=t.poses.map((n,e)=>n&&!n.lost?e:-1).filter(n=>n>=0),s=Math.max(1,Math.ceil(o.length/60));return{solved:o,keyframes:[t.pair[0],...o.filter((n,e)=>n!==t.pair[0]&&(e%s===0||e===o.length-1))]}}function Oo(t,o,s,n,e,a){const r=Math.hypot(...A(t.poses[t.pair[1]].C,t.poses[t.pair[0]].C))||1,l=new Set(o);for(const i of s){if(l.has(i))continue;const c=[];for(const[f,h]of t.obs[i])t.points.has(f)&&c.push({X:t.points.get(f),px:h});c.length>=10&&(t.poses[i]=ee(c,t.poses[i],n,e,a,r).pose)}}function Te(t,o,s,n){const{solved:e,keyframes:a}=Xo(t),r={poses:t.poses.map(c=>c&&{...c,R:c.R.map(f=>[...f]),C:[...c.C]}),points:new Map([...t.points].map(([c,f])=>[c,[...f]]))},l=jt(t,o,s,n),i=Jt(t.poses,t.points,t.obs,a,o,s,n,12,{focal:!0});return Math.abs(i/o-1)<1e-4?o:(Oo(t,a,e,i,s,n),Math.abs(i/o-1)<.15&&jt(t,i,s,n)<l?i:(t.poses=r.poses,t.points=r.points,o))}function Re(t,o,{w:s,h:n,mw:e,mh:a,focals:r=$.focals,focal:l=null,onProgress:i=null}={}){const c=s/2,f=n/2;let h=l,p=0;const u=l?1:r.length+9;if(!h){const P=new Map,E=Math.max(s,n)/s;let I=t;const V=_=>{if(_=Math.round(_*1e3)/1e3,!(_>.2&&_<3)||P.has(_))return;const z=ao(null,_*s,{obs:I,w:s,h:n});z.mode==="free"&&mo(z,_*s,c,f),P.set(_,{s:z,e:z.mode==="free"?jt(z,_*s,c,f):1/0}),i?.(++p/u)};let K=[];for(let _=Math.max(1,Math.round(t.length/25));;_=Math.max(1,_>>1)){I=t.filter((z,nt)=>nt%_===0),P.clear(),p=0;for(const z of r)V(z*E);if(K=[...P.entries()].filter(([,z])=>Number.isFinite(z.e)).sort((z,nt)=>z[0]-nt[0]),K.length||_===1)break}if(!K.length)return i?.(1),null;const k=K.reduce((_,z,nt)=>z[1].e<K[_][1].e?nt:_,0),B=K[k][1].s,mt=k>0?K[k-1][0]:K[k][0]*.8,dt=k<K.length-1?K[k+1][0]:K[k][0]*1.25,F=B.poses.map((_,z)=>_&&!_.lost?z:-1).filter(_=>_>=0),G=B.pair[0],H=_=>{const z={...B,poses:B.poses.map(J=>J&&{...J,R:J.R.map(at=>[...at]),C:[...J.C]}),points:new Map([...B.points].map(([J,at])=>[J,[...at]]))};Jt(z.poses,z.points,z.obs,[G,...F.filter(J=>J!==G)],_*s,c,f,8),i?.(++p/u);let nt=0,L=0;for(const[J,at]of It(z,_*s,c,f).values())nt+=J*at,L+=at;return L?nt/L:1/0},Mt=(Math.sqrt(5)-1)/2;let W=mt,tt=dt,ft=tt-Mt*(tt-W),rt=W+Mt*(tt-W),ht=H(ft),gt=H(rt);for(let _=0;_<7;_++)ht<gt?(tt=rt,rt=ft,gt=ht,ft=tt-Mt*(tt-W),ht=H(ft)):(W=ft,ft=rt,ht=gt,rt=W+Mt*(tt-W),gt=H(rt));h=(W+tt)/2}const m=ao(null,h*s,{obs:t,w:s,h:n});if(i?.(1),m.mode!=="free")return null;let y=h*s;const M=m.poses[m.pair[0]].C,d=m.poses[m.pair[0]].R;if(mo(m,y,c,f),!l)for(let P=0;P<3;P++){const E=Te(m,y,c,f),I=Math.abs(E/y-1)<5e-4;if(y=E,I)break}const x=It(m,y,c,f),g=[...x.values()].map(P=>P[0]).sort((P,E)=>P-E),w=Math.max(1.5,3*(g[g.length>>1]??1)),b=[...x.entries()].filter(([P,E])=>m.points.has(P)&&E[0]<=w&&E[1]>=2),v=P=>t.flatMap((E,I)=>E.has(P)?[o[I]]:[]);let R=0,T=0;for(const[,P]of b)R+=P[0]*P[1],T+=P[1];const D=Z(pt(d),[0,1,0]),q=Se([...m.points.values()],D,M)??te(m.points,D,M)??oe(m.points,D,M),O={v:1,w:s,h:n,mw:e||s,mh:a||n,mode:"free",f:C(y),err:C(T?R/T:jt(m,y,c,f)),frames:m.poses.map((P,E)=>[C(o[E]),...xo(P.R).map(C),...P.C.map(C)]),floor:q?[...q.n.map(C),C(q.d)]:null},X=[];for(const[P]of b.sort((E,I)=>I[1][1]-E[1][1])){if(X.length>=$.points)break;const E=m.points.get(P),I=v(P);No(O,E,I)<=$.slide*s&&X.push([E.map(C),[C(I[0]),C(I.at(-1))]])}return{...O,points:X.map(P=>P[0]),seen:X.map(P=>P[1])}}function No(t,o,s){if(!s.length)return 1/0;const e=(s.length>24?s.filter((p,u)=>u%Math.ceil(s.length/24)===0||u===s.length-1):s).map(p=>et(A(o,lt(t,p).C)));let a=0;for(const p of[e[0],e.at(-1)])for(const u of e)a=Math.max(a,Math.acos(Math.min(1,S(p,u))));const r=lt(t,s[s.length>>1]).C,l=Math.hypot(...A(o,r)),i=U(o,j(et(A(o,r)),l*(.5/t.f)/Math.max(.001,Math.sin(a)))),c=t.frames,f=Math.max(1,Math.floor(c.length/40));let h=0;for(let p=0;p<c.length;p+=f){const u=ct(t,o,c[p][0]),m=ct(t,i,c[p][0]);u&&m&&(h=Math.max(h,Math.hypot(u[0]-m[0],u[1]-m[1])))}return h}function un(t,o,{mw:s,mh:n,focals:e=$.focals,focal:a=null,onProgress:r=null,dense:l=!0}={}){if(t.length<3)throw Error("FLAT");const i=t[0].w,c=t[0].h,f=wo(t,{anchor:!0,onProgress:r&&(u=>r(u*.35))}),h=Re(f,o,{w:i,h:c,mw:s,mh:n,focals:e,focal:a,onProgress:r&&(u=>r(.35+u*.57))});if(h){const u=l?Ie(h,t,o,r&&(m=>r(.92+m*.08))):h;return r?.(1),u}const p=Wo(t,(a??.7)*i);if(p.filter(u=>!u.lost).length<t.length*.5)throw Error("FLAT");return{v:1,w:i,h:c,mw:s||i,mh:n||c,mode:"tripod",frames:p.map((u,m)=>[C(o[m]),...u.q.map(C),C(u.f)])}}function Ie(t,o,s,n=null,e=$.dense){const a=wo(o,{anchor:!0,keep:e.keep,cols:e.cols,rows:e.rows,onProgress:n&&(u=>n(u*.8))}),r=new Map;a.forEach((u,m)=>{for(const[y,M]of u){let d=r.get(y);d||r.set(y,d=[]),d.push([s[m],M[0],M[1]])}});const l=[...r.values()].filter(u=>u.length>=e.minFrames),i=t.points??[],c=u=>i.some(m=>Math.abs(m[0]-u[0])+Math.abs(m[1]-u[1])+Math.abs(m[2]-u[2])<1e-6),f=t.seen??i.map(()=>[t.frames[0][0],t.frames.at(-1)[0]]),h=[...i],p=[...f];for(const u of l){if(h.length>=e.max)break;const m=Lo(t,u);!m||c(m)||No(t,m,u.map(y=>y[0]))>$.slide*t.w||(h.push(m.map(C)),p.push([C(u[0][0]),C(u.at(-1)[0])]))}return n?.(1),{...t,points:h,seen:p}}const _t=t=>!!t&&typeof t.ref=="string"&&!Array.isArray(t.frames);function je(t){if(!t||t.v!==1||!["free","tripod"].includes(t.mode))throw Error("Invalid scene track");for(const n of["w","h","mw","mh"])if(!(Number.isFinite(t[n])&&t[n]>0&&t[n]<=2e4))throw Error("Invalid scene track");if(t.smooth!==void 0&&!(Number.isFinite(t.smooth)&&t.smooth>=0&&t.smooth<=1))throw Error("Invalid scene track");if(_t(t)){if(!/^[0-9a-f]{64}$/.test(t.ref))throw Error("Invalid scene track");return t}const o=t.mode==="free"?8:6;if(!Array.isArray(t.frames)||t.frames.length<2)throw Error("Invalid scene track");let s=-1/0;for(const n of t.frames){if(!Array.isArray(n)||n.length!==o||!n.every(Number.isFinite)||n[0]<s)throw Error("Invalid scene track");s=n[0]}if(t.mode==="free"&&(!(Number.isFinite(t.f)&&t.f>0)||t.floor!=null&&!(Array.isArray(t.floor)&&t.floor.length===4&&t.floor.every(Number.isFinite))||!Array.isArray(t.points)||t.points.length>5e3||!t.points.every(n=>Array.isArray(n)&&n.length===3&&n.every(Number.isFinite))||t.seen!=null&&!(Array.isArray(t.seen)&&t.seen.length===t.points.length&&t.seen.every(n=>Array.isArray(n)&&n.length===2&&n.every(Number.isFinite)&&n[0]<=n[1]))))throw Error("Invalid scene track");return t}function lt(t,o){const s=t.frames,n=s.length;let e=0,a=Math.max(0,n-2);for(;e<a;){const u=e+a+1>>1;s[u][0]<=o?e=u:a=u-1}const r=s[e],l=s[Math.min(n-1,e+1)],i=l[0]>r[0]?Math.max(0,Math.min(1,(o-r[0])/(l[0]-r[0]))):0;let c=r.slice(1,5),f=l.slice(1,5);oo(c,f)<0&&(f=f.map(u=>-u));const h=_e(c,f,i),p=go(h);return t.mode==="tripod"?{R:p,C:[0,0,0],f:r[5]+(l[5]-r[5])*i}:{R:p,C:[0,1,2].map(u=>r[5+u]+(l[5+u]-r[5+u])*i),f:t.f}}const oo=(t,o)=>t[0]*o[0]+t[1]*o[1]+t[2]*o[2]+t[3]*o[3];function _e(t,o,s){const n=Math.min(1,Math.max(-1,oo(t,o)));if(n>.9995){const i=t.map((f,h)=>f+(o[h]-f)*s),c=Math.hypot(...i);return i.map(f=>f/c)}const e=Math.acos(n),a=Math.sin(e),r=Math.sin((1-s)*e)/a,l=Math.sin(s*e)/a;return t.map((i,c)=>i*r+o[c]*l)}function De(t,o,s){const n=t.seen?.[o];if(!n)return!0;const e=t.frames.length>1?(t.frames.at(-1)[0]-t.frames[0][0])/(t.frames.length-1):0;return s>=n[0]-e-1e-4&&s<=n[1]+e+1e-4}const eo=(t,o)=>(t.points??[]).map((s,n)=>[s,n]).filter(([,s])=>De(t,s,o));function ct(t,o,s){const n=lt(t,s),e=Z(n.R,t.mode==="tripod"?o:A(o,n.C));return e[2]>-1e-6?null:[t.w/2+n.f*e[0]/-e[2],t.h/2-n.f*e[1]/-e[2]]}function zt(t,o,s,n){const e=lt(t,n),a=et([(o-t.w/2)/e.f,-(s-t.h/2)/e.f,-1]);return{o:e.C,d:Z(pt(e.R),a),pose:e}}function Fe(t,o,s,n,{radius:e=null}={}){const{o:a,d:r}=zt(t,o,s,n);if(t.mode==="tripod")return r.map(C);const l=e??Math.max(10,t.w*.04),i=[];for(const[h]of eo(t,n)){const p=ct(t,h,n);if(!p)continue;const u=Math.hypot(p[0]-o,p[1]-s),m=S(A(h,a),r);m>0&&u<=t.w*.15&&i.push({X:h,depth:m,dist:u,w:1/(1+u)})}i.sort((h,p)=>h.dist-p.dist);const c=i.filter((h,p)=>h.dist<=l||p<6);let f=null;if(c.length>=3&&(f=ze(c,a,r)),f===null&&c.length>=2){c.sort((u,m)=>u.depth-m.depth);const h=c.reduce((u,m)=>u+m.w,0);let p=0;for(const u of c)if(p+=u.w,p>=h/2){f=u.depth;break}}else if(f===null&&t.floor){const h=t.floor.slice(0,3),p=S(h,r);if(Math.abs(p)>1e-6){const u=-(S(h,a)+t.floor[3])/p;u>0&&(f=u)}}if(f===null){const h=(t.points??[]).map(p=>S(A(p,a),r)).filter(p=>p>0).sort((p,u)=>p-u);f=h.length?h[h.length>>1]:1}return U(a,j(r,f)).map(C)}function ze(t,o,s){const n=t.slice(0,20),e=n.map(d=>d.depth).sort((d,x)=>d-x),a=e[e.length>>1]*.015,r=n.reduce((d,x)=>d+x.w,0);let l=null,i=0;for(let d=0;d<n.length;d++)for(let x=d+1;x<n.length;x++)for(let g=x+1;g<n.length;g++){let w=st(A(n[x].X,n[d].X),A(n[g].X,n[d].X));const b=Math.hypot(...w);if(b<1e-12)continue;w=j(w,1/b);const v=n.filter(T=>Math.abs(S(w,A(T.X,n[d].X)))<a),R=v.reduce((T,D)=>T+D.w,0);R>i&&(l=v,i=R)}if(!l||l.length<3||i<r*.5)return null;const c=j(l.reduce((d,x)=>U(d,x.X),[0,0,0]),1/l.length),f=[[0,0,0],[0,0,0],[0,0,0]];for(const{X:d}of l){const x=A(d,c);for(let g=0;g<3;g++)for(let w=0;w<3;w++)f[g][w]+=x[g]*x[w]}if(!(f[0][0]+f[1][1]+f[2][2]>0))return null;const p=Ft(f),u=S(p,s);if(Math.abs(u)<.05)return null;const m=Math.min(...l.map(d=>d.depth)),y=Math.max(...l.map(d=>d.depth)),M=S(p,A(c,o))/u;return M>=m*.7&&M<=y*1.4?M:null}function qe(t,o,s,n){if(t.mode!=="free"||!t.floor)return null;const{o:e,d:a}=zt(t,o,s,n),r=t.floor.slice(0,3),l=S(r,a);if(Math.abs(l)<1e-6)return null;const i=-(S(r,e)+t.floor[3])/l;return i>0?U(e,j(a,i)):null}function pn(t,o){return t.mode!=="free"?[]:o.map(s=>Lo(t,s)).filter(Boolean)}function Lo(t,o){if(t.mode!=="free"||o.length<4)return null;const s=o.map(([l,i,c])=>zt(t,i,c,l));let n=0;for(const l of s)n=Math.max(n,Math.acos(Math.min(1,S(l.d,s[0].d))));if(n<.5*Math.PI/180)return null;const e=[[0,0,0],[0,0,0],[0,0,0]],a=[0,0,0];for(const{o:l,d:i}of s)for(let c=0;c<3;c++)for(let f=0;f<3;f++){const h=(c===f?1:0)-i[c]*i[f];e[c][f]+=h,a[c]+=h*l[f]}const r=Ke(e,a);return r&&o.every(([l,i,c])=>{const f=ct(t,r,l);return f&&Math.hypot(f[0]-i,f[1]-c)<1.5})?r:null}function Ke(t,o){const s=e=>e[0][0]*(e[1][1]*e[2][2]-e[1][2]*e[2][1])-e[0][1]*(e[1][0]*e[2][2]-e[1][2]*e[2][0])+e[0][2]*(e[1][0]*e[2][1]-e[1][1]*e[2][0]),n=s(t);return Math.abs(n)<1e-12?null:[0,1,2].map(e=>s(t.map((a,r)=>a.map((l,i)=>i===e?o[r]:l)))/n)}function mn(t,o,s,{extra:n=[]}={}){if(t.mode!=="free")return null;const e=(p,u)=>{let m=0;for(let y=0;y<4;y++){const[M,d]=o[y],[x,g]=o[(y+1)%4],w=(x-M)*(u-d)-(g-d)*(p-M);if(w){if(m&&Math.sign(w)!==m)return!1;m=Math.sign(w)}}return!0},a=lt(t,s),r=[...n,...eo(t,s).map(([p])=>p)].filter(p=>{const u=ct(t,p,s);return u&&e(u[0],u[1])}),l=o.map(([p,u])=>zt(t,p,u,s)),i=(p,u)=>{const m=[];for(const{o:y,d:M}of l){const d=S(p,M);if(Math.abs(d)<1e-9)return null;const x=-(S(p,y)+u)/d;if(!(x>0))return null;m.push(U(y,j(M,x)))}return m};let c=null,f="points";if(r.length>=4){const p=r.map(y=>Math.hypot(...A(y,a.C))).sort((y,M)=>y-M)[r.length>>1],u=p*.015;let m=null;for(let y=0;y<r.length;y++)for(let M=y+1;M<r.length;M++)for(let d=M+1;d<r.length&&d<M+12;d++){let x=st(A(r[M],r[y]),A(r[d],r[y]));const g=Math.hypot(...x);if(g<1e-12)continue;x=j(x,1/g);const w=-S(x,r[y]);let b=0;for(const v of r)Math.abs(S(x,v)+w)<u&&b++;(!m||b>m.c)&&(m={n:x,d:w,c:b})}if(m&&m.c>=4){const y=r.filter(g=>Math.abs(S(m.n,g)+m.d)<u),M=j(y.reduce((g,w)=>U(g,w),[0,0,0]),1/y.length),d=[[0,0,0],[0,0,0],[0,0,0]];for(const g of y){const w=A(g,M);for(let b=0;b<3;b++)for(let v=0;v<3;v++)d[b][v]+=w[b]*w[v]}let x=Ft(d);S(x,A(a.C,M))<0&&(x=j(x,-1)),c={n:x,d:-S(x,M),count:y.length}}}if(!c){const p=o.reduce((d,x)=>d+x[0],0)/4,u=o.reduce((d,x)=>d+x[1],0)/4,m=Fe(t,p,u,s),y=t.floor?qe(t,p,u,s):null,M=Math.hypot(...A(m,a.C));if(y&&Math.abs(Math.hypot(...A(y,a.C))-M)<M*.12)c={n:t.floor.slice(0,3),d:t.floor[3],count:0},f="ground";else{const d=t.floor?t.floor.slice(0,3):Z(pt(a.R),[0,1,0]),x=A(a.C,m);let g=A(x,j(d,S(x,d)));Math.hypot(...g)<1e-9&&(g=x),g=et(g),c={n:g,d:-S(g,m),count:0},f="upright"}}const h=i(c.n,c.d);return h?{corners:h.map(p=>p.map(C)),n:c.n.map(C),d:C(c.d),count:c.count,by:f}:null}function dn(t,o,s,n=null){const e=o.crop||{left:0,right:0,top:0,bottom:0},a=1-e.left-e.right,r=1-e.top-e.bottom,l=[];for(const i of n??t.frames.map(c=>c[0])){const c=s.map(f=>ct(t,f,i));c.some(f=>!f)||l.push([+i.toFixed(4),...c.flatMap(([f,h])=>[C((f/t.w-e.left)/a),C((h/t.h-e.top)/r)]),1])}return l}function Mn(t,o,s,n){const e=o.crop||{left:0,right:0,top:0,bottom:0};return[(e.left+s*(1-e.left-e.right))*t.w,(e.top+n*(1-e.top-e.bottom))*t.h]}function Bt(t,o,s,n,e,a,r){const l=o.crop||{left:0,right:0,top:0,bottom:0},i=(s/t.w-l.left)/(1-l.left-l.right),c=(n/t.h-l.top)/(1-l.top-l.bottom),f=Jo(o,i,c,e,a,r,t.mw,t.mh);return[f.px,f.py]}function yn(t,o,s,n,e,a){const r=Math.max(t.start,o.start),l=Math.min(t.start+t.duration,o.start+o.duration);if(!(l>r))return{};const i=[],c=[],f=[r,...s.frames.map(p=>o.start+p[0]).filter(p=>p>r+1e-4&&p<l-1e-4),l];for(const p of f){const u=ct(s,n,p-o.start);if(!u)continue;const[m,y]=Bt(s,o,u[0],u[1],p-o.start,e,a),M=+(p-t.start).toFixed(4);i.push({time:M,value:C((m-e/2)/e)}),c.push({time:M,value:C((y-a/2)/a)})}if(!i.length)return{};let h={...t,motionV:2};return delete h.posX,delete h.posY,h={...h,...yt(h,"x",Mo(i,$.keyTolPx/e))},h={...h,...yt(h,"y",Mo(c,$.keyTolPx/a))},{motionV:2,motionKeys:h.motionKeys,posX:void 0,posY:void 0}}const Mo=(t,o)=>to(t.map(s=>s.time),t.map(s=>s.value),o,1/0).map(s=>t[s]);function Xe(t,o,s){if(!(s>0)||o.length<3)return o;const n=s*$.smoothFrames,e=Math.ceil(n*2.5),a=t.mode==="free",r=$.smoothTolPx,l=a?(t.points??[]).filter((h,p)=>p%Math.max(1,Math.floor((t.points?.length??0)/80))===0):[-.4,0,.4].flatMap(h=>[-.25,0,.25].map(p=>[h,p,-1])),i=(h,p)=>{const u=Z(h.R,a?A(p,h.C):Z(pt(o[0].R),p));return u[2]>-1e-6?null:[h.f*u[0]/-u[2],-h.f*u[1]/-u[2]]},c=(h,p)=>{let u=0,m=0;for(const y of l){const M=i(h,y),d=i(p,y);M&&d&&(u=Math.max(u,Math.hypot(M[0]-d[0],M[1]-d[1])),m++)}return m?u:0},f=o.map(h=>xo(h.R));return o.map((h,p)=>{let u=0,m=[0,0,0],y=[0,0,0,0],M=0;for(let b=Math.max(0,p-e);b<=Math.min(o.length-1,p+e);b++){const v=Math.exp(-((b-p)**2)/(2*n*n)),R=oo(f[b],f[p])<0?f[b].map(T=>-T):f[b];u+=v,m=U(m,j(o[b].C,v)),y=y.map((T,D)=>T+R[D]*v),M+=o[b].f*v}const d=b=>{const v=f[p].map((T,D)=>T+(y[D]/u-T)*b),R=Math.hypot(...v);return{R:go(v.map(T=>T/R)),C:U(h.C,j(A(j(m,1/u),h.C),b)),f:h.f+(M/u-h.f)*b}};let x=1,g=d(1),w=c(h,g);for(let b=0;b<6&&w>r;b++)x*=Math.max(.3,r/w*.95),g=d(x),w=c(h,g);return w>r?h:g})}function Yo(t,o,s,n){const e=Ho(s,n),a=lt(t,t.frames[0][0]),r=t.mode==="free",l=r&&t.floor?t.floor.slice(0,3):Z(pt(a.R),[0,1,0]),i=Z(pt(a.R),[0,0,-1]),c=[0,1,2].map(E=>{const I=(t.points??[]).map(V=>V[E]).sort((V,K)=>V-K);return I.length?I[I.length>>1]:a.C[E]+(r?0:i[E])}),f=r&&t.floor?A(c,j(t.floor.slice(0,3),S(t.floor.slice(0,3),c)+t.floor[3])):c,h=et(A(i,j(l,S(i,l)))),u=[st(j(l,-1),h),j(l,-1),h],m=8*e/Math.max(1e-9,Math.hypot(...A(a.C,f))),y=E=>j(Z(u,A(E,f)),m),M=Bt(t,o,t.w/2,t.h/2,0,s,n),d=Bt(t,o,t.w/2+10,t.h/2,0,s,n),x=Math.hypot(d[0]-M[0],d[1]-M[1])/10,g=[[1,0,0],[0,-1,0],[0,0,-1]],w=t.frames.filter(E=>E[0]>=-1e-6&&E[0]<=o.duration+1e-6),b=[],v={},R=(E,I)=>{if(E===void 0)return I;for(;I-E>180;)I-=360;for(;I-E<-180;)I+=360;return I},T=Xe(t,w.map(E=>lt(t,E[0])),t.smooth??0);for(const[E,I]of w.entries()){const V=T[E],K=po(po(u,pt(V.R)),g),k=y(V.C),B=Qo(K),mt=R(v.pan,B.pan),dt=R(v.roll,B.roll);v.pan=mt,v.roll=dt,b.push({time:+(o.start+I[0]).toFixed(4),cx:C(k[0]/s),cy:C(k[1]/n),cz:C(k[2]/e),pan:C(mt),tilt:C(B.tilt),roll:C(dt),zoom:C(V.f*x/(5*e))})}const D=5*e*(b[0]?.zoom??1),q=$.keyTolPx/D*180/Math.PI,O={cx:$.keyTolPx/s,cy:$.keyTolPx/n,cz:$.keyTolPx/e,pan:q,tilt:q,roll:q,zoom:$.keyTolPx/D},X=new Set;for(const[E,I]of Object.entries(O))for(const V of to(b.map(K=>K.time),b.map(K=>K[E]),I,1/0))X.add(V);return{camera:{enabled:!0,motionV:2,motionKeys:b.filter((E,I)=>X.has(I))},toTimeline:y,fromTimeline:E=>U(Z(pt(u),j(E,1/m)),f),M:u,k:m,U:e,first:a}}function Oe(t,o,s,n,e,{size:a=null,fill:r=1}={}){if(t.mode!=="free")throw Error("TRIPOD");const{camera:l,toTimeline:i,k:c,U:f,first:h}=Yo(t,o,n,e),p=(a??Math.hypot(...A(h.C,s))*.2)*c*r,u=i(s),m=A(i(h.C),u),y=Math.atan2(m[0],-m[2])*180/Math.PI;return{camera:l,place:{is3D:!0,posX:C(u[0]/n),posY:C(u[1]/e),spatialDepth:C(-u[2]/f),modelDepth:C(-u[2]/f),modelGround:!0,modelRotation:{x:0,y:C(y),z:0},scale:C(Math.max(1e-6,p/(1.8*f)))},toTimeline:i}}function Ne(t,o,s,n,e){const a=[];for(const[r,l]of eo(t,n)){const i=ct(t,r,n);if(i){const c=Math.hypot(i[0]-o,i[1]-s);c<=e&&a.push([l,c])}}return a.sort((r,l)=>r[1]-l[1]).map(r=>r[0])}function gn(t,o,s){if(!o.length)return null;const n=lt(t,s),e=t.mode==="free"?n.C:[0,0,0],a=h=>j(h.reduce((p,u)=>U(p,u),[0,0,0]),1/h.length);let r=o.map(h=>t.mode==="free"?h:et(h)),l=a(r),i=r,c="points";if(t.mode==="free"&&r.length<3){const h=ct(t,l,s),p=Math.hypot(...A(l,e));if(h){const u=Ne(t,h[0],h[1],s,t.w*.12).map(d=>t.points[d]).filter(d=>Math.abs(Math.hypot(...A(d,e))/p-1)<.25).slice(0,14),m=p*.02,y=r[0];let M=null;for(let d=0;d<u.length;d++)for(let x=d+1;x<u.length;x++){let g=st(A(u[d],y),A(u[x],y));const w=Math.hypot(...g);if(w<1e-12)continue;g=j(g,1/w);const b=u.filter(v=>Math.abs(S(g,A(v,y)))<m);r.every(v=>Math.abs(S(g,A(v,y)))<m)&&(!M||b.length>M.length)&&(M=b)}M&&M.length>=3&&(i=[...r,...M],c="around")}}let f=null;if(t.mode==="free"&&i.length>=3){if(c==="points"&&i.length>=6){const u=Math.hypot(...A(l,e)),m=u*.01,y=bo(31);let M=null;for(let d=0;d<300;d++){const x=i[Math.floor(y()*i.length)],g=i[Math.floor(y()*i.length)],w=i[Math.floor(y()*i.length)];let b=st(A(g,x),A(w,x));const v=Math.hypot(...b);if(v<1e-12)continue;b=j(b,1/v);const R=i.filter(T=>Math.abs(S(b,A(T,x)))<m);(!M||R.length>M.length)&&(M=R)}M&&M.length>=Math.max(3,i.length*.5)&&(i=M)}const h=a(i),p=[[0,0,0],[0,0,0],[0,0,0]];for(const u of i){const m=A(u,h);for(let y=0;y<3;y++)for(let M=0;M<3;M++)p[y][M]+=m[y]*m[M]}f=Ft(p),c!=="around"&&(l=h)}return f||(f=et(A(e,l)),c="facing"),S(f,A(e,l))<0&&(f=j(f,-1)),{center:l.map(C),n:f.map(C),radius:C(Math.hypot(...A(l,e))*.08),by:c}}function bn(t,o=t.radius,s=36){const n=t.n,e=et(Math.abs(n[1])<.9?st(n,[0,1,0]):st(n,[1,0,0])),a=st(n,e);return Array.from({length:s},(r,l)=>{const i=l/s*2*Math.PI;return U(t.center,U(j(e,o*Math.cos(i)),j(a,o*Math.sin(i))))})}const Le=["x","y","depth","zoom","rot","tiltX","tiltY"];function xn(t,o,s,n,e,a,{width:r=null}={}){if(t.kind==="model"){const{camera:P,place:E}=Oe(o,s,n.center,e,a,{size:n.radius*2});if(!(E.spatialDepth>=so&&E.spatialDepth<=ro))throw Error("FAR");return{camera:P,patch:E}}const{camera:l,toTimeline:i,M:c,k:f,U:h,first:p}=Yo(o,s,e,a),u=i(n.center),m=et(Z(c,n.n)),y=i(o.mode==="free"?lt(o,o.frames[0][0]).C:p.C),M=-u[2]/h;if(!(M>=so&&M<=ro))throw Error("FAR");const d=P=>A(P,j(m,S(P,m)));let x=Math.abs(m[1])<.85?d([0,1,0]):d(A(y,u));Math.hypot(...x)<1e-6&&(x=d([0,1,0])),x=et(x);const g=j(m,-1),w=st(x,g),b=Math.asin(Math.max(-1,Math.min(1,g[1]))),v=Math.atan2(-g[0],g[2]),R=[Math.cos(v),0,Math.sin(v)],T=[Math.sin(b)*Math.sin(v),Math.cos(b),-Math.sin(b)*Math.cos(v)],D=Math.atan2(S(w,T),S(w,R)),q=P=>C(P*180/Math.PI);let O={...t,motionV:2};for(const P of Le)(O.motionKeys??[]).some(E=>E[P]!==void 0)&&(O={...O,motionKeys:Zo(O,P,[])});const X=(r??n.radius*6)*f;return{camera:l,patch:{is3D:!0,motionV:2,motionKeys:O.motionKeys??[],posX:C(u[0]/e),posY:C(u[1]/a),spatialDepth:C(M),scale:C(Math.max(1e-4,X/e)),rotation:q(D),tiltX:q(b),tiltY:q(v)}}}const $o=24e3,xt=new WeakMap,Ut=new Map;function Nt(t){let o=xt.get(t);if(!o){const s=JSON.stringify(t);o=s.length<=$o?Promise.resolve(null):re(s).then(n=>(Ut.set(n,t),n)),o.catch(()=>xt.delete(t)),xt.set(t,o)}return o}async function Ye(t){return Promise.all(t.map(async o=>{let s=o;const n=o.mask;if(n&&n.v===2&&!vo(n)){const r=await Nt(n);r&&(s={...s,mask:{v:2,mw:n.mw,mh:n.mh,ref:r}})}const e=o.planar;if(e&&!Yt(e)){const r=await Nt(e);r&&(s={...s,planar:{v:1,mw:e.mw,mh:e.mh,ref:r}})}const a=o.sceneTrack;if(a&&!_t(a)){const r=await Nt(a);r&&(s={...s,sceneTrack:{v:1,mode:a.mode,w:a.w,h:a.h,mw:a.mw,mh:a.mh,ref:r,...a.key?{key:a.key}:{}}})}return s}))}async function Lt(t){const o=Ut.get(t);if(o)return o;const s=JSON.parse(await ae(t));return Ut.set(t,s),s}async function $e(t){let o=0;return{clips:await Promise.all(t.map(async n=>{let e=n;const a=n.mask;if(vo(a))try{const i=ne(await Lt(a.ref),n.duration);if(i.v!==2||!("masks"in i))throw Error("Invalid mask");xt.set(i,Promise.resolve(a.ref)),e={...e,mask:i}}catch{o++}const r=n.planar;if(Yt(r))try{const i=se(await Lt(r.ref),n.duration);if(Yt(i))throw Error("Invalid planar track");xt.set(i,Promise.resolve(r.ref)),e={...e,planar:i}}catch{o++}const l=n.sceneTrack;if(_t(l))try{const i=je(await Lt(l.ref));if(_t(i))throw Error("Invalid scene track");xt.set(i,Promise.resolve(l.ref)),e={...e,sceneTrack:{...i,...l.key?{key:l.key}:{}}}}catch{o++}return e})),missing:o}}const wn=Object.freeze(Object.defineProperty({__proto__:null,MASK_INLINE_MAX:$o,packMasks:Ye,unpackMasks:$e},Symbol.toStringTag,{value:"Module"}));export{Ae as A,Mn as B,to as C,an as D,lt as E,qe as F,Je as G,Fe as H,De as I,Ne as J,fn as K,hn as L,we as M,ue as N,ie as O,xe as P,ce as Q,le as R,$ as S,Be as T,Oe as U,yn as V,Ue as W,wn as X,dn as a,un as b,gn as c,Yo as d,xn as e,Bt as f,ct as g,bn as h,ln as i,rn as j,nn as k,We as l,sn as m,He as n,cn as o,Ye as p,en as q,on as r,mn as s,pn as t,$e as u,tn as v,Ze as w,Qe as x,Ge as y,jo as z};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{cM as T,fp as N,c0 as g,eQ as z,eR as A,nk as j,c1 as U,nl as $,Z as I,cz as D,a7 as M,cX as v,nm as q,nn as B,no as J,np as K,_ as Q,nq as V}from"./titleFrameBudget-BYRZAQPs.js";import{c0 as X}from"./api-DUp403BK.js";import{u as b}from"./store-75tQUvPT.js";const Z=/^null:[^\s]{1,80}$/,E=t=>typeof t=="string"&&Z.test(t),G=t=>E(t)?t.slice(5):null,k=(t,e)=>[t[0]*e[0]+t[2]*e[1],t[1]*e[0]+t[3]*e[1],t[0]*e[2]+t[2]*e[3],t[1]*e[2]+t[3]*e[3],t[0]*e[4]+t[2]*e[5]+t[4],t[1]*e[4]+t[3]*e[5]+t[5]],x=t=>{const e=t[0]*t[3]-t[1]*t[2]||1e-12;return[t[3]/e,-t[1]/e,-t[2]/e,t[0]/e,(t[2]*t[5]-t[3]*t[4])/e,(t[1]*t[4]-t[0]*t[5])/e]};function S(t,e,a,o){const s=N(t,Math.max(0,Math.min(t.duration,e)),a,o),n=s.rot*Math.PI/180,r=Math.cos(n)*s.zoom,l=Math.sin(n)*s.zoom;return[r,l,-l,r,a/2+s.x*a,o/2+s.y*o]}function Y(t,e,a,o,s,n){const r=g(t,0,0,e,a,o,s,n),l=g(t,1,0,e,a,o,s,n),i=g(t,0,1,e,a,o,s,n);return[l.px-r.px,l.py-r.py,i.px-r.px,i.py-r.py,r.px,r.py]}function W(t,e){return e.map(a=>{const o=t[0]*a[0]+t[2]*a[1]+t[4],s=t[1]*a[0]+t[3]*a[1]+t[5];return a.length!==6?[o,s]:[o,s,t[0]*a[2]+t[2]*a[3],t[1]*a[2]+t[3]*a[3],t[0]*a[4]+t[2]*a[5],t[1]*a[4]+t[3]*a[5]]})}function H(t,e,a,o,s,n=1280,r=720,{inverse:l=!1}={}){const i=e.find(p=>p.id===a&&T(p));if(!i)return null;const f=t.mask?.mw??1920,u=t.mask?.mh??1080,c=p=>t.start+p-i.start,m=k(S(i,c(s),n,r),x(S(i,c(o),n,r))),d=Y(t,s,n,r,f,u),P=k(x(d),k(m,d));return l?x(P):P}function tt(t,e,a=1280,o=720){return(t.mask?.v===1?[t.mask]:t.mask?.masks||[]).some(n=>E(n.follow))?{...t.roto||{},followNull:(n,r,l,i,f=!1)=>{const u=H(t,e,G(n),r,l,a,o,{inverse:f});return u?W(u,i):i}}:t.roto}J(X);K(async t=>{const[e,a]=await Promise.all([Q(()=>import("./opentype.module-DcKU8U04.js"),[]),fetch(V[t]).then(o=>{if(!o.ok)throw Error(`Font ${o.status}`);return o.arrayBuffer()})]);return e.default.parse(a)});const F=t=>[...new Set(D(t.mask).flatMap(e=>e.shape?.kind==="text"?[e.shape.weight??800]:[]))],w=new Map;function R(t){const e=F(t).filter(a=>!q(a));for(const a of e){const o=w.get(a);o!==void 0&&(o===1/0||Date.now()<o)||(w.set(a,1/0),v(a).then(()=>{w.delete(a),b.setState(s=>({clips:s.clips.slice()}))},()=>w.set(a,Date.now()+1e4)))}return!e.length}let C=null,h=null,L=null;const y=(t,e,a)=>{const o=t??document.createElement("canvas");return(o.width!==e||o.height!==a)&&Object.assign(o,{width:e,height:a}),o},_=t=>!!(t.mask||t.person);function et(t,e){return t.mask&&!R(t)?-1:t.person?I(t.person)?e:-1:t.key||D(t.mask).some(a=>a.keys.length>1||a.follow||a.mblur||a.in!==void 0||a.out!==void 0)?e:0}function at(t){const e=t.person,a=I(e);return a||M(e).then(()=>b.setState(o=>({clips:o.clips.slice()}))).catch(()=>{}),a}function ot(t,e,a,o,s,n,r){const l=at(e);if(!l){r||(t.save(),t.globalCompositeOperation="source-over",t.fillStyle="#fff",t.fillRect(0,0,o,s),t.restore());return}const i=B(l,e.person,e,a,o,s),f=L=y(L,o,s),u=f.getContext("2d"),c=u.createImageData(o,s);for(let m=0,d=0;m<i.length;m++,d+=4)n?(c.data[d]=c.data[d+1]=c.data[d+2]=255,c.data[d+3]=i[m]):(c.data[d]=c.data[d+1]=c.data[d+2]=i[m],c.data[d+3]=255);u.putImageData(c,0,0),t.save(),t.setTransform(1,0,0,1,0,0),t.globalAlpha=1,t.filter="none",t.globalCompositeOperation=r?n?"destination-in":"multiply":"copy",t.drawImage(f,0,0),t.restore()}function O(t,e,a,o=!1,s){const{w:n,h:r}=j(t),l=a?y(a,n,r):C=y(C,n,r),i=l.getContext("2d");if(t.mask){R(t);const f=b.getState(),{width:u,height:c}=U(f.timelineFormat);$(i,t.mask,e,n,r,tt(t,s??f.clips,u,c),o)}return t.person&&ot(i,t,e,n,r,o,!!t.mask),l}function nt(t,e,a,o,s,n,r){const l=O(t,r,void 0,!0),i=l.width,f=l.height;h=y(h,i*2,f*2);const u=h.getContext("2d");return u.globalCompositeOperation="copy",u.drawImage(e,a,o,s,n,0,0,i*2,f*2),u.globalCompositeOperation="destination-in",u.imageSmoothingEnabled=!0,u.drawImage(l,0,0,i*2,f*2),u.globalCompositeOperation="source-over",h}const st=t=>z(A(t.filter(e=>!e.disabled))).filter(e=>e._virtual&&(e.mask||e.person));async function rt(t){for(const e of t.filter(_))e.person&&await M(e.person),await Promise.all(F(e).map(v))}async function it(t,e,a,o){const s=document.createElement("canvas");for(const n of t.filter(_)){if(a.wants&&!a.wants("matteFrames",n.id))continue;n.person&&await M(n.person),await Promise.all(F(n).map(v));const r=Math.ceil(n.duration*e);let l="";for(let i=0;i<r;i++){if(o?.aborted)throw new DOMException("Export cancelled","AbortError");if(a.wants&&!a.wants("matteFrames",n.id,i)){await a.push("matteFrames",n.id,"");continue}O(n,i/e,s,!1,t);const f=s.toDataURL("image/webp",.9),u=f.slice(f.indexOf(",")+1);if(u===l){await a.push("matteFrames",n.id,"=");continue}l=u,await a.push("matteFrames",n.id,u),i%10===0&&await new Promise(c=>setTimeout(c,0))}}}const ct=Object.freeze(Object.defineProperty({__proto__:null,maskedCopies:st,maskedSource:nt,matteActive:_,matteCanvas:O,matteStamp:et,prepareMattes:rt,renderMatteFrames:it},Symbol.toStringTag,{value:"Module"}));export{_ as a,nt as b,et as c,tt as m,ct as r};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{t as e,b as u,h}from"./api-
|
|
1
|
+
import{t as e,b as u,h}from"./api-DUp403BK.js";import{i7 as p}from"./remote-Dva2qg58.js";import"./titleFrameBudget-BYRZAQPs.js";import"./three.module-Bx43vjkH.js";import"./GLTFLoader-BHWu1lKg.js";import"./store-75tQUvPT.js";import"./rotoMaskStore-BxyxB2bD.js";import"./textAnimators-nVSz_sZo.js";import"./timelineComp-BcewYGR2.js";import"./rigTrack-UYZU4P-e.js";const a=new Map,s=n=>new Promise(r=>setTimeout(r,n));async function m(n){for(let r=0;r<100;r++){const o=await u(n,!0).catch(t=>{if(r<20)return null;throw t});if(!o){await s(3e3);continue}if(o.status==="failed")throw Error(e("Vẽ Animation không thành công (credit đã được hoàn)"));if(o.status==="succeeded"&&o.output?.url){const t=await fetch(o.output.url);if(!t.ok)throw Error(e("Không tải được hình vẽ"));return t.json()}await s(3e3)}throw Error(e("Vẽ Animation quá lâu — thử lại sau"))}async function V(n,r){const o=r.params??{},t=o.job;if(!t)throw Error(e("Thiếu job Vẽ Animation"));let i=a.get(t);i||(i=m(t),a.set(t,i),i.catch(()=>a.delete(t)));const c=await i;return p(c,o,{en:h()==="en"})}export{V as runRotoscope};
|