clipoox-render 0.4.3 → 0.4.5
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/package.json +4 -3
- package/scripts/render-local.mjs +5160 -1446
- package/web/assets/FxEmbed-DbfuM8Yo.js +1 -0
- package/web/assets/MotionEmbed-CBQ-8Tzh.js +1 -0
- package/web/assets/PluginStore-OOEx0lP5.js +3 -0
- package/web/assets/ShotComposer-Cng515xa.js +287 -0
- package/web/assets/{ShotComposer-VixLbeMe.css → ShotComposer-deLi4grZ.css} +1 -1
- package/web/assets/TemplateEmbed-hjwM2b0o.js +2 -0
- package/web/assets/{TimelinePlugins-BYZ9y4m3.js → TimelinePlugins-D-NakABP.js} +4 -4
- package/web/assets/TimelineShotFx-D3kGhHN3.js +2 -0
- package/web/assets/TransitionEmbed-DR26yI3a.js +1 -0
- package/web/assets/{Whiteboard-BP_DvIAV.js → Whiteboard-BhxY0D0Z.js} +3 -3
- package/web/assets/aerial-BisYSXzG.js +2 -0
- package/web/assets/agentTools-CPFQeiDP.js +2 -0
- package/web/assets/aiInbetween-AOOM1e6p.js +2 -0
- package/web/assets/analyzerRun-Dtp2o7gT.js +1 -0
- package/web/assets/analyzerSandbox-BG_3Cea1.js +33 -0
- package/web/assets/api-BFN7blbw.js +3158 -0
- package/web/assets/auraTrack-D_gxHNVe.js +1 -0
- package/web/assets/breakthrough-0qFpZW-V.js +2 -0
- package/web/assets/{cameraPresets-CYw0OdM3.js → cameraPresets-eK3mP7qb.js} +1 -1
- package/web/assets/cameraTracker-BAQHuTV-.js +72 -0
- package/web/assets/captionLayout-CWPcbid-.js +1 -0
- package/web/assets/clientExport-DvpTTndR.js +1 -0
- package/web/assets/clientJobs-CIrYTMpn.js +2 -0
- package/web/assets/clientJobs-CuuUyhEy.js +1 -0
- package/web/assets/cutoutClean-CLYYAuXg.js +1 -0
- package/web/assets/depthEstimate-B7D7cGCl.js +1 -0
- package/web/assets/directorTools-CJD4Huqk.js +1 -0
- package/web/assets/distortFrames-BLt1icUb.js +2 -0
- package/web/assets/{distortGL-QalhICvi.js → distortGL-BA5molk-.js} +3 -3
- package/web/assets/draco_decoder-C32yEggz.wasm +0 -0
- package/web/assets/draco_decoder-Z1_iN-Ht.wasm +0 -0
- package/web/assets/draco_decoder-fzg4nYZr.js +34 -0
- package/web/assets/draco_wasm_wrapper-DxJM36Ib.js +117 -0
- package/web/assets/draco_wasm_wrapper-fZCQGLGb.js +116 -0
- package/web/assets/editTools-NKLsWZD1.js +1 -0
- package/web/assets/{engine-BedcnK45.js → engine-DioUF2mX.js} +1 -1
- package/web/assets/exportGlb-BOdI9cVS.js +2 -0
- package/web/assets/faceTracker-D7CbF-qX.js +1 -0
- package/web/assets/fightDirector-CYP8jxo8.js +1 -0
- package/web/assets/fightDrama-DIPcRKnc.js +2 -0
- package/web/assets/focusTool-vfabPqQ5.js +1 -0
- package/web/assets/{frameSink-DeM8xC8_.js → frameSink-DYs2gTzq.js} +3 -3
- package/web/assets/glTransitionSources.generated-DM5sRMX2.js +3695 -0
- package/web/assets/gltfLoader-U0Eebg7v.js +2 -0
- package/web/assets/{gpuCompose-CA3UmOl4.js → gpuCompose-DbnZuelB.js} +1 -1
- package/web/assets/gpuExport-CQ7ZhpsX.js +198 -0
- package/web/assets/handMatte-DIbMuqCu.js +1 -0
- package/web/assets/handTracker-DY_g5Xmg.js +2 -0
- package/web/assets/i18n-BJppIrtF.js +3 -0
- package/web/assets/index-BfrDwjDI.js +4247 -0
- package/web/assets/index-CKtv7gGE.js +9 -0
- package/web/assets/{index-D5oyVCRl.js → index-DxdDhmLR.js} +2 -2
- package/web/assets/layer-worker-DK67WH1a.js +5 -0
- package/web/assets/library-B6KsZUKq.js +1 -0
- package/web/assets/lottieLayer-C2YbiXhK.js +161 -0
- package/web/assets/{lottie_light_canvas-B-d7-ATe.js → lottie_light_canvas-DX9Wf-DS.js} +1 -1
- package/web/assets/main-B27kf5aL.css +1 -0
- package/web/assets/main-BKatDoGw.js +309 -0
- package/web/assets/mapBake-C-G7WpFM.js +1 -0
- package/web/assets/maskTrack-LMrwm5ub.js +1 -0
- package/web/assets/matteFixRun-B38CbeEt.js +1 -0
- package/web/assets/matteQuality-9X-jgJrH.js +1 -0
- package/web/assets/objectLocate-CKi3OTnL.js +1 -0
- package/web/assets/objectSegmenter-CziPuM61.js +1 -0
- package/web/assets/{objectTrack.worker-BlZkgpOX.js → objectTrack.worker-b7DJ-ub6.js} +196 -196
- package/web/assets/pathTracer-bqau16sX.js +2 -0
- package/web/assets/pendingMatte-CQb7jPg1.js +2 -0
- package/web/assets/personAi-CQntGDqK.js +2 -0
- package/web/assets/personHq-B1c0QVJT.js +2 -0
- package/web/assets/plateCamera-D7iLiNBy.js +1 -0
- package/web/assets/plateCameraMatch-BM88dx-a.js +2 -0
- package/web/assets/plateFollow-4iGUDTu1.js +2 -0
- package/web/assets/plateMatte-zTyuHHqh.js +2 -0
- package/web/assets/plugin-guide.en-DO_fHbzT.js +1 -0
- package/web/assets/plugin-guide.vi-CMJDxOhi.js +1 -0
- package/web/assets/pluginAutomation-DSg-sYLF.js +1 -0
- package/web/assets/poseTracker-DZl8l2qS.js +1 -0
- package/web/assets/productTools-B-jh8ukh.js +2 -0
- package/web/assets/remote-DJd9xWjn.js +963 -0
- package/web/assets/{rigTrack-urT3nDK0.js → rigTrack-XaMj1yaH.js} +1 -1
- package/web/assets/rotoMaskStore-DdpmT9C3.js +1 -0
- package/web/assets/{rotoMatte-C-2o3vv0.js → rotoMatte-i-cJTYmK.js} +1 -1
- package/web/assets/rotoscope-DqRSWmHR.js +1 -0
- package/web/assets/sceneTrack-Bbov7zET.js +1 -0
- package/web/assets/sceneTrack-DIPzBmMK.js +1 -0
- package/web/assets/{sceneTrack.worker-CT4uoTKn.js → sceneTrack.worker-Bav9h0pv.js} +180 -180
- package/web/assets/shot-worker-m-q77W9f.js +1 -0
- package/web/assets/{shotFxAgent-BFLkqs8v.js → shotFxAgent-DIMS7BGA.js} +2 -2
- package/web/assets/{skin-DY4QLaBI.js → skin-DrUzJE1u.js} +1 -1
- package/web/assets/{spark.module-DzziUgOj.js → spark.module-Y1SEI8Xz.js} +10 -10
- package/web/assets/spellDuel-DNnyQDVr.js +2 -0
- package/web/assets/store-GFMJzaWS.js +1 -0
- package/web/assets/surfaceLight-C--moyc9.js +1 -0
- package/web/assets/surfacePin-B4-1UqXD.js +2 -0
- package/web/assets/{textAnimators-DUZjhVGO.js → textAnimators-BVXTl8bU.js} +1 -1
- package/web/assets/{thumb-CS0ZuiGS.js → thumb-CTfDJgLp.js} +1 -1
- package/web/assets/timeline3d-Dn7PqmEe.js +2 -0
- package/web/assets/timeline3dExport-DCOr6ARB.js +1 -0
- package/web/assets/timelineComp-Dx_kED5V.js +1 -0
- package/web/assets/timelineOps-afzSo188.js +525 -0
- package/web/assets/timelineProps-eYgO6gs5.js +1 -0
- package/web/assets/timelineText-RKyRP988.js +1 -0
- package/web/assets/{titleArt-Drsrtfiv.js → titleArt-CUtA0C3I.js} +4 -4
- package/web/assets/{titleFrameBudget-CLZWaFHO.js → titleFrameBudget-X7HLSDre.js} +721 -704
- package/web/assets/titleFrames-aMG7HdVe.js +1 -0
- package/web/assets/{tool-DktQYmS6.js → tool-DpFjybaq.js} +1 -1
- package/web/assets/{tools-Co9aRDiT.js → tools-CeOU0p13.js} +1 -1
- package/web/assets/toonTools-DLmo37Z_.js +2 -0
- package/web/assets/trackAnchor-hAOtEhKO.js +1 -0
- package/web/assets/userFonts-1kuRjWOo.js +1 -0
- package/web/assets/{vfxAlpha-71tSN86T.js → vfxAlpha-DxS5-QwY.js} +2 -2
- package/web/assets/vfxBackground-CYpaQaTa.js +2 -0
- package/web/assets/videoExport-Cg4B2Nyh.js +1 -0
- package/web/assets/views-CUXyRb9x.js +1 -0
- package/web/assets/weaponDuel-nFECu9nk.js +1 -0
- package/web/assets/windowFrames-1wAkkWnv.js +1 -0
- package/web/layer-worker.html +3 -3
- package/web/shot-worker.html +41 -0
- package/web/assets/FxEmbed-BCmj9Q5C.js +0 -1
- package/web/assets/GLTFLoader-BHWu1lKg.js +0 -1
- package/web/assets/MotionEmbed-CEmbcq8Z.js +0 -1
- package/web/assets/PluginStore-C5hyahvG.js +0 -3
- package/web/assets/ShotComposer-0DUtMTVI.js +0 -287
- package/web/assets/TemplateEmbed-ANxSs7H5.js +0 -2
- package/web/assets/TimelineShotFx-q5PQwq-V.js +0 -2
- package/web/assets/TransitionEmbed-O6LInGWq.js +0 -1
- package/web/assets/aerial-CGLDKKtP.js +0 -2
- package/web/assets/agentTools-2Ghb80VH.js +0 -2
- package/web/assets/analyzerRun-DRgxrcJA.js +0 -1
- package/web/assets/analyzerSandbox-DuIVFnsk.js +0 -33
- package/web/assets/api-CJ8PdbfZ.js +0 -3168
- package/web/assets/auraTrack-DQw9sVU6.js +0 -1
- package/web/assets/breakthrough-BNj_iTDr.js +0 -2
- package/web/assets/captionLayout-DvDPTwO9.js +0 -1
- package/web/assets/clientExport-xhoXY6Dh.js +0 -1
- package/web/assets/depthEstimate-DEpeCojm.js +0 -1
- package/web/assets/directorTools-C5CpTmci.js +0 -1
- package/web/assets/distortFrames-Dia8O1NM.js +0 -2
- package/web/assets/editTools-CY_JrQfw.js +0 -1
- package/web/assets/exportEncode-QYsT9JBO.js +0 -1
- package/web/assets/exportGlb-TSj09XoV.js +0 -2
- package/web/assets/faceTracker-CnCWOwnJ.js +0 -1
- package/web/assets/fightDirector-DCI_FWTh.js +0 -1
- package/web/assets/fightDrama-Bg7uP_2Q.js +0 -2
- package/web/assets/gpuExport-D31azOQA.js +0 -198
- package/web/assets/handMatte-Dl-xVXFR.js +0 -1
- package/web/assets/handTracker-CplBsAFg.js +0 -2
- package/web/assets/layer-worker-DFuo32bk.js +0 -5
- package/web/assets/library-BufgA-Pl.js +0 -1
- package/web/assets/lottieLayer-DzbA3bHV.js +0 -158
- package/web/assets/main-Ca_CVxMz.css +0 -1
- package/web/assets/main-VVYiW8XD.js +0 -309
- package/web/assets/mapBake-BKOcEd0w.js +0 -1
- package/web/assets/maskTrack-CHGXtBRy.js +0 -1
- package/web/assets/matteFixRun-vgYrINet.js +0 -1
- package/web/assets/objectLocate-BJltm8Ob.js +0 -1
- package/web/assets/pendingMatte-BPyzzx4y.js +0 -2
- package/web/assets/personAi-gJu03SjU.js +0 -2
- package/web/assets/plateCamera-B2JvhjJw.js +0 -1
- package/web/assets/plateCameraMatch-ByB9nVQT.js +0 -2
- package/web/assets/plateFollow-C9S-l7RH.js +0 -2
- package/web/assets/plateMatte-J4qlNHnY.js +0 -2
- package/web/assets/plugin-guide.en-CGYh_9Su.js +0 -1
- package/web/assets/plugin-guide.vi-DMphSELb.js +0 -1
- package/web/assets/pluginAutomation-CkP3tA9r.js +0 -1
- package/web/assets/poseTracker-DGLbouqt.js +0 -1
- package/web/assets/productTools-CkaWF1bM.js +0 -2
- package/web/assets/remote-C7J0Tqhb.js +0 -1433
- package/web/assets/rotoMaskStore-DPziPKAN.js +0 -1
- package/web/assets/rotoscope-GvPFRUBg.js +0 -1
- package/web/assets/shot-worker-6dYkHPoL.js +0 -1
- package/web/assets/spellDuel-BD3m2ebA.js +0 -2
- package/web/assets/store-DW4E9xnW.js +0 -1
- package/web/assets/surfaceLight-aDSYU8Jg.js +0 -1
- package/web/assets/surfacePin-m83hCgGP.js +0 -2
- package/web/assets/timeline3d-DOw-CpZI.js +0 -2
- package/web/assets/timeline3dExport-BtYLU1pw.js +0 -1
- package/web/assets/timelineComp-B4GtoH2f.js +0 -1
- package/web/assets/timelineProps-D7MVutxu.js +0 -1
- package/web/assets/timelineText-BH09jfSM.js +0 -1
- package/web/assets/titleFrames-BI1DnLBn.js +0 -1
- package/web/assets/toonTools-CD9clJvN.js +0 -2
- package/web/assets/trackAnchor-sOjTtd3I.js +0 -1
- package/web/assets/userFonts-CwlKh9NR.js +0 -1
- package/web/assets/vfxBackground-Bq7lJvmZ.js +0 -2
- package/web/assets/videoExport-D4KbireJ.js +0 -1
- package/web/assets/views-ozVF4ABO.js +0 -1
- package/web/assets/weaponDuel-ZhX-tjGZ.js +0 -1
- package/web/assets/windowFrames-CpqX3kOM.js +0 -1
|
@@ -0,0 +1,525 @@
|
|
|
1
|
+
import{G as Yi,I as tb,t as eb,hj as Qe,l as In,hI as Ii,au as ht,kI as Ai,cm as ob,F as be,gE as Ci,dH as rb,dG as ip,c_ as de,kJ as nb,kK as Yd,dW as Me,dE as J0,dY as Ut,aG as zn,kL as Zl,kM as ab,iw as Wc,kN as ib,s as Di,kO as sb,kP as Q0,kQ as lb,ax as qd,aw as Zd,h as Hr,f as Tn,kR as cb,ay as Jd,kS as ja,kT as pb,U as Md,ao as $d,v as si,bm as tg,kU as ub,kV as eg,kW as og,kX as rg,aB as Jt,kY as hn,dZ as qi,d4 as Zt,kZ as ng,aX as vd,b5 as Xc,dK as hu,k_ as db,k$ as Ed,l0 as hb,ib as Ne,b4 as Jl,l1 as fb,M as Cs,gQ as Ql,at as Qd,l2 as xs,dU as th,l3 as fu,l4 as mb,l5 as gb,l6 as ag,l7 as yb,fa as Cr,eU as js,fd as Gs,eW as bb,i7 as Sd,i6 as wb,l8 as qr,l9 as Xs,kp as kb,la as ig,kq as xb,lb as Mb,dk as sg,h7 as $b,dn as vb,dm as Eb,dN as Sb,lc as Zr,cw as Id,hi as Jo,B as tc,z as kn,ld as Ib,aN as Ab,bh as lg,fP as li,dX as Hc,le as cg,fW as ys,im as He,fy as Da,lf as mu,lg as pg,lh as Ol,jq as ug,li as eh,hh as ec,lj as Cb,lk as jb,ll as Tb,lm as Ob,ln as Pb,h$ as zb,iy as dg,gN as br,lo as Lb,lp as Nb,lq as Fb,lr as Rb,ls as Db,lt as Bb,fb as Ar,gI as un,gH as Ln,lu as jr,lv as gu,g2 as vn,cQ as Yn,cz as gr,lw as hg,lx as _b,hH as sp,ly as Gb,lz as Kb,lA as Vb,lB as Wb,cp as Ka,cT as yu,b$ as fg,eV as Xb,fh as Hb,lC as Ub,ff as Tr,gG as Bi,lD as mg,eX as Pl,gP as gg,aE as oh,lE as Uc,hf as yg,bg as lp,lF as bg,al as nn,h1 as bs,hb as zl,aj as oc,ac as Yb,hd as rh,lG as qb,h3 as Zb,lH as Jb,h8 as Qb,am as bu,ak as tw,aV as wg,eB as nr,ig as ew,ih as ow,iB as rw,iO as nw,cb as kg,cc as aw,ca as xg,lI as Vr,lJ as _i,lK as ir,fO as Xo,g9 as Jn,gc as rc,gb as Ms,lL as Ad,lM as Gi,fw as Mg,lN as Cd,fu as cp,lO as nh,fT as ah,lP as iw,lQ as sw,lR as $g,lS as ih,lT as lw,fD as sh,fL as jd,fv as lh,lU as cw,lV as Ts,lW as pw,lX as vg,lY as uw,ga as dw,lZ as ch,l_ as hw,l$ as fw,m0 as wu,ii as Td,aI as mw,av as gw,cB as Ma,cs as yw,cx as Hs,m1 as ph,cG as ku,cy as bw,dr as uh,ka as ww,dl as dh,m2 as kw,dt as xw,m as ci,aJ as Mw,m3 as hh,c0 as $w,c2 as fh,cd as vw,c5 as Ew,m4 as Sw,m5 as Us,bA as Eg,m6 as mh,m7 as Iw,m8 as Aw,m9 as Cw,gO as jw,i as Ys,aW as gh,ma as Tw,cj as ts,ix as yh,ik as bh,il as Ow,ij as Pw,bo as zw,bp as Lw,E as wh,mb as Nw,mc as Fw,md as Rw,me as Dw,mf as nc,q as kh,mg as Bw,D as _w,e as xh,c as Gw,R as Mh,n as Kw,a as Vw,d as Ww,fE as Qr,mh as $h,mi as Xw,mj as Hw,fF as Uw,mk as Yw,fI as qw,C as Zw,ml as xu,mm as Jw,mn as Qw,mo as vh,mp as t2,mq as e2,mr as o2,iv as _n,cY as qs,io as Eh,ms as Zs,ds as r2,g4 as Sh,d7 as Ih,dc as pp,dh as up,mt as n2,mu as Ah,ip as a2,df as i2,dg as s2,ir as l2,mv as c2,mw as p2,mx as u2,my as d2,fk as h2,hk as f2,mz as m2,mA as g2,mB as y2,mC as b2,hF as w2,iz as k2,mD as x2,mE as Ch,mF as M2,mG as $2,mH as v2,mI as E2,k7 as S2,gZ as I2,A as A2,gF as jh,mJ as C2,mK as j2,mL as T2,mM as O2,i9 as Th,aO as dp,aM as P2,i3 as Oh,mN as z2,mO as L2,mP as N2,go as F2,j as Ph,mQ as zh,b6 as R2,g as D2,mR as B2,dR as _2,dq as G2,co as K2,mS as Lh,mT as V2,mU as W2,gR as Nh,g0 as X2,mV as H2,fp as U2,mW as Y2,mX as q2,hT as Z2,bz as Sg,mY as J2,mZ as Fh,m_ as Rh,is as Q2,it as tk,iu as ek,m$ as Dh,n0 as ok,ky as rk}from"./titleFrameBudget-X7HLSDre.js";import{C as nk,N as ak,b as Bh,O as ik,E as sk,F as lk,s as ck,Q as pk,R as uk,G as dk,o as hk,T as fk,h as mk,U as gk,q as yk,l as bk,j as wk}from"./sceneTrack-Bbov7zET.js";import{B as Ig,m as Ll,s as kk,t as Nl,r as _h,h as xk,i as Mk,j as $k,D as vk,E as Ek,k as Js,n as Sk,o as Ik,f as Ak,q as Ck,u as jk}from"./cameraTracker-BAQHuTV-.js";import{A as Tk,H as Ok,h as Pk,j as zk,p as Lk,C as Nk,M as Gh}from"./textAnimators-BVXTl8bU.js";import{i as Kh,u as Fk,p as Rk,f as Dk,m as Bk}from"./timelineComp-Dx_kED5V.js";import{bP as Vh,aK as _k,aI as Gk}from"./api-BFN7blbw.js";import{L as Qs,f as Kk,s as Vk,r as Wk}from"./store-GFMJzaWS.js";import{n as Xk,P as Qn,o as Er,q as Wh,A as Mu,t as Ag,u as Xh,v as ji,x as Hk,y as Uk,B as hp,z as Yk,C as qk,D as Zk,E as Jk,F as Qk,G as tx,H as ex,I as fp,J as ox,K as Hh,L as rx,N as Uh,O as nx,Q as Cg,R as Yh,T as ax,U as ac,V as ic,W as $u,X as qh}from"./rigTrack-XaMj1yaH.js";import{addClientJob as Re}from"./clientJobs-CuuUyhEy.js";const ix={editorial3d:"scene",clipoox3d:"scene",bold:"overlay",clean:"overlay",neon:"overlay",podcast:"overlay",sale:"overlay",business:"overlay",launch:"overlay",glow:"scene",noir:"scene",pop:"scene",illus:"overlay",studio:"scene",creator:"overlay",mono:"overlay",ai:"overlay",fin:"overlay",explain:"overlay",info:"overlay",cyber:"overlay",kinetic:"overlay",bridge:"transition",tvc:"overlay",home:"overlay",health:"overlay",fit:"overlay",travel:"overlay",menu:"overlay",auto:"overlay",cine:"scene",pulse:"scene",story:"scene",lumen:"scene",rebound:"scene",join:"transition",fluid:"scene",promo:"scene",morph:"scene",glass:"overlay",clipooxmotion:"scene",prodreview:"overlay",course:"overlay",aiworkflow:"scene",techlaunch:"scene",framed:"scene",uibeats:"overlay",clipooxstudio:"scene",matrix:"overlay",lightfx:"overlay",sportcine:"overlay",faceholo:"overlay",history:"overlay"},Zh={"hist-window-light":"look","hist-film-look":"look","hist-year-wall":"scene","hist-stitch-card":"scene","hist-depth-words":"scene","sc-dot-screen":"look","lr-purple-flash":"transition","lr-light-ribbon":"overlay","lr-name-spark":"overlay","lr-flag-wave":"scene","mx-code-rain":"background","mx-data-tunnel":"background","mx-crt-screen":"look","mx-code-wipe":"transition","cs-callout":"overlay","cs-timer-ring":"overlay","cs-confetti-bg":"background","fr-backdrop":"background","fr-v-backdrop":"background","fr-definition":"overlay","fr-v-definition":"overlay","fr-lower-third":"overlay","fr-v-lower-third":"overlay","tl-4k-split":"overlay","tl-v-4k-split":"overlay","creator-chapter-bar":"scene","creator-quote-end":"scene","creator-thumb-wall":"scene","creator-phone-duo":"scene","course-compare-board":"scene","aiw-race-hud":"overlay","aiw-v-race-hud":"overlay","aiw-pause-menu":"overlay","aiw-v-pause-menu":"overlay","aiw-end-subtitle":"overlay","aiw-v-end-subtitle":"overlay","course-chapter-card":"scene","rv-packshot-title":"scene","clipoox-v-top-banner":"overlay","c3d-orbit-shapes":"background","clipoox-title-sparkle":"overlay","clipoox-publish-btn":"overlay","clipoox-status-log":"overlay","clipoox-zoom-burst":"transition","clipoox-slot-word":"overlay","clipoox-pill-lower":"overlay","clipoox-jelly-wipe":"transition","clipoox-star-flip":"transition","clipoox-skill-header":"overlay","clipoox-before-after":"overlay","clipoox-heat-flash":"transition","clipoox-bar-lower":"overlay","morph-caption":"overlay","promo-caption":"overlay","promo-glass-icon":"overlay","promo-star-flare":"overlay","fluid-caption":"overlay","fluid-blob-el":"overlay","fluid-drip-el":"overlay","rebound-caption":"overlay","rebound-ball":"overlay","rebound-bricks":"overlay","lumen-caption":"overlay","lumen-orb":"overlay","lumen-critter":"overlay","lumen-spark-trail":"overlay","story-caption":"overlay","cine-caption":"overlay","cine-spark":"overlay","pulse-word":"overlay","tvc-backdrop":"background","kin-beat":"scene","kin-orb":"overlay","kin-texture":"look","kin-el":"overlay","kin-el2":"overlay","kin-carry":"transition","bridge-portal":"overlay","aurora-bg":"background",vignette:"look","film-grain":"look","light-leak":"look",letterbox:"look",vhs:"look","launch-wipe":"transition","pop-circle-wipe":"transition","noir-chapter-wave":"transition","creator-flash":"transition","mono-ribbon-wipe":"transition","mono-grid-paper":"background","exp-backdrop":"background","info-backdrop":"background","info-ring-carousel":"scene","info-tilted-dashboard":"scene","cyber-backdrop":"background","cyber-plexus":"background","cyber-trace-lines":"background","cyber-slab-wipe":"transition","cyber-pixel-dissolve":"transition","cyber-orbit-cards":"scene","cyber-circuit-chip":"scene","cyber-logo-reveal":"scene","mono-blob-frame":"look","mono-spotlight-panels":"scene","noir-caption":"overlay","studio-click-callout":"overlay","launch-question":"scene","launch-logo":"scene","launch-prompt":"scene","biz-section-title":"scene","biz-logo-reveal":"scene","fxo-paper-bg":"background"};function sx(t,e){const o=typeof t=="string"?t:t?.id,r=typeof t=="string"?e:t?.pack;return/^fxo-/.test(o||"")?Zh[o]||"look":Zh[o]||ix[r]||"overlay"}const lx=Object.freeze(["general","creator","education","commerce","corporate","finance","tech","ai","saas","gaming","data","product","luxury","beauty","food","event","realestate","health","fitness","travel","auto"]),Jh=Object.freeze({bold:{industries:["general","creator","commerce"],tone:"any",energy:3},clean:{industries:["corporate","tech","beauty","luxury"],tone:"any",energy:1},neon:{industries:["gaming","event","creator"],tone:"dark",energy:3},podcast:{industries:["creator","education"],tone:"any",energy:2},sale:{industries:["commerce"],tone:"any",energy:3},business:{industries:["corporate","finance","saas","data"],tone:"any",energy:2},launch:{industries:["tech","product","saas"],tone:"light",energy:2},glow:{industries:["finance","creator","education"],tone:"dark",energy:2},noir:{industries:["luxury","finance","corporate"],tone:"dark",energy:2},pop:{industries:["creator","commerce","education"],tone:"light",energy:3},illus:{industries:["education","general"],tone:"light",energy:2},studio:{industries:["tech","saas","product"],tone:"dark",energy:2},creator:{industries:["creator","commerce"],tone:"dark",energy:3},mono:{industries:["product","luxury","corporate"],tone:"light",energy:1},ai:{industries:["ai","tech","saas"],tone:"dark",energy:2},fin:{industries:["finance"],tone:"dark",energy:2},explain:{industries:["education","creator","commerce"],tone:"dark",energy:2},info:{industries:["data","saas","corporate","education"],tone:"light",energy:1},cyber:{industries:["gaming","tech","event"],tone:"dark",energy:3},kinetic:{industries:["creator","commerce","education"],tone:"any",energy:3},bridge:{industries:["general"],tone:"any",energy:2},tvc:{industries:["corporate","commerce","product","beauty","food","luxury"],tone:"light",energy:2},home:{industries:["realestate","luxury","corporate"],tone:"any",energy:1},health:{industries:["health","education"],tone:"any",energy:1},fit:{industries:["fitness","event","creator"],tone:"dark",energy:3},travel:{industries:["travel","luxury","event"],tone:"any",energy:2},menu:{industries:["food","commerce"],tone:"any",energy:2},auto:{industries:["auto","luxury"],tone:"dark",energy:3},cine:{industries:["general","creator","event","luxury"],tone:"dark",energy:1},pulse:{industries:["general","tech","gaming","event","creator"],tone:"dark",energy:2},story:{industries:["general","creator","event","education"],tone:"dark",energy:2},lumen:{industries:["tech","ai","creator","gaming","beauty","event"],tone:"dark",energy:2},rebound:{industries:["tech","gaming","fitness","creator","product","event"],tone:"dark",energy:2},join:{industries:["general","creator","commerce","tech","event","education","product"],tone:"dark",energy:3},fluid:{industries:["beauty","creator","product","food","event","general"],tone:"dark",energy:2},promo:{industries:["tech","ai","saas","product","creator","data"],tone:"dark",energy:2},morph:{industries:["general","creator","product","tech","corporate","event"],tone:"dark",energy:2},glass:{industries:["finance","saas","tech","data"],tone:"dark",energy:2},clipooxmotion:{industries:["tech","ai","saas","product","creator","general"],tone:"any",energy:3},editorial3d:{industries:["general","creator","education","commerce","data"],tone:"light",energy:2},clipoox3d:{industries:["saas","tech","product","ai","data"],tone:"dark",energy:2},prodreview:{industries:["beauty","commerce","product","creator","health","food"],tone:"any",energy:1},course:{industries:["education","tech","ai","saas","creator"],tone:"dark",energy:1},aiworkflow:{industries:["ai","saas","tech","gaming"],tone:"any",energy:3},techlaunch:{industries:["ai","saas","tech","product"],tone:"light",energy:3},framed:{industries:["creator","education"],tone:"dark",energy:2},uibeats:{industries:["tech","saas","product","education"],tone:"dark",energy:2},clipooxstudio:{industries:["tech","ai","saas","product","education","creator"],tone:"any",energy:2},matrix:{industries:["tech","gaming","ai","data","event"],tone:"dark",energy:3},lightfx:{industries:["finance","corporate","event","auto","general"],tone:"dark",energy:3},sportcine:{industries:["fitness","creator","event","tech","education"],tone:"any",energy:3},faceholo:{industries:["tech","creator","ai","event","general"],tone:"dark",energy:2},history:{industries:["general","education","creator"],tone:"dark",energy:2},basic:{industries:["general"],tone:"any",energy:2}}),cx=[[/\bcta\b|subscribe|-follow|\bcontact\b|buy-|comment-cta|\bqr\b|kêu gọi|nút bấm/i,"cta"],[/lower[- ]third|name[- ]tag|lower/i,"lower"],[/hook|kicker|question|glitch-title|zoom-blur|hero/i,"hook"],[/title|headline|chapter|section|heading|tiêu đề/i,"title"],[/logo|reveal|intro|opener/i,"intro"],[/outro|end card|end-card|closing/i,"outro"],[/kpi|counter|odometer|number|percent|stat|gauge|meter|chart|bar|line|donut|pie|growth|candlestick|ticker|heatmap|bubble|radar|wave-area|balance|price|ring-progress|token/i,"number"],[/list|steps|process|checklist|timeline|agenda|funnel|loop|stack|gantt/i,"list"],[/compare|versus|vs|before|after|swap|strike/i,"compare"],[/testimonial|review|quote|rating|award|badge|stamp|verdict/i,"proof"],[/quote/i,"quote"],[/comment|profile|notification|chat|scan|explain|card|panel|browser|orbit|globe|network|chip/i,"explain"]],px=Object.freeze({"sc-scan-boxes":{beats:["decor","hook"]},"sc-named-cursor":{beats:["explain"]},"sc-card-label":{beats:["title","explain"]},"sc-comment-pill":{beats:["cta","outro"]},"lr-light-ribbon":{beats:["intro","decor"]},"lr-name-spark":{beats:["lower","title"]},"lr-flag-wave":{beats:["outro","title"]},"lr-chrome-logo":{beats:["hook","title","intro"]},"ub-liked":{beats:["cta","decor"]},"ub-check-chips":{beats:["list","proof"]},"ub-copy-link":{beats:["cta","explain"]},"ub-paste-chip":{beats:["explain"]},"ub-blur-words":{beats:["hook","title"]},"ub-draft-cards":{beats:["explain","compare"]},"creator-icon-row":{beats:["list","explain"]},"creator-phone-duo":{beats:["compare","explain"]},"creator-watch-chart":{beats:["number","explain"]},"creator-scrub-bar":{beats:["number","explain"]},"creator-dot-list":{beats:["list"]},"creator-offer-card":{beats:["number","cta"]},"creator-notify-stack":{beats:["proof","explain"]},"creator-message-chip":{beats:["proof","cta"]},"creator-thumb-wall":{beats:["proof","number"]},"creator-wave-mismatch":{beats:["compare","explain"]},"creator-layout-box":{beats:["compare","explain"]},"creator-glass-shatter":{beats:["explain","transition"]},"creator-reaction-pop":{beats:["decor","proof"]},"creator-pill-caption":{beats:["title","hook"]},"creator-chapter-bar":{beats:["title","transition"]},"creator-quote-end":{beats:["quote","outro"]},"kin-word-collage":{beats:["hook","explain"]},"kin-hero-lead":{beats:["hook","title"]},"kin-comment-cta":{beats:["cta"]},"exp-kicker-title":{beats:["hook","title"]},"exp-cta-button":{beats:["cta","outro"]},"cyber-logo-reveal":{beats:["intro","outro"]},"info-ring-carousel":{beats:["number","explain"]},"info-title":{beats:["title","intro"]},"mono-object-plate":{beats:["explain","decor"]},"3d-sparkle-star":{beats:["hook","decor"]},"3d-bounce-ball-title":{beats:["title","hook"]},"3d-shape-morph":{beats:["explain","decor"]},"3d-target-dart":{beats:["hook","proof"]},"3d-gradient-bars":{beats:["number"]},"3d-counter-orb":{beats:["number"]},"c3d-monitor-pedestal":{beats:["intro","explain"]},"c3d-phone-feed":{beats:["number","hook"]},"c3d-floating-chaos":{beats:["hook"]},"c3d-channel-hub":{beats:["explain","list"]},"c3d-dashboard-live":{beats:["number","proof"]},"c3d-window-assemble":{beats:["explain","intro"]},"c3d-plane-logo":{beats:["outro","intro"]},...Object.fromEntries(Object.entries({"clipoox-prompt-box":["hook","explain"],"clipoox-glitch-slam":["hook","title"],"clipoox-status-shimmer":["explain"],"clipoox-core-orbit":["explain"],"clipoox-card-cube":["title","hook"],"clipoox-ball-pit":["hook","explain"],"clipoox-end-credit":["outro"],"aiw-race-title":["intro","title","hook"],"aiw-gen-checklist":["list","explain"],"aiw-viewport":["explain"],"aiw-race-hud":["number","decor"],"aiw-pause-menu":["explain"],"aiw-select":["cta","explain"],"aiw-end-subtitle":["outro"]}).flatMap(([t,e])=>{const o={beats:e,.../end-|step-list/.test(t)?{energy:"calm"}:{}};return[[t,o],[t.replace(/^(clipoox|aiw)-/,"$1-v-"),o]]})),...Object.fromEntries(Object.entries({"fr-window":["intro","hook"],"fr-versus":["compare"],"fr-headline":["title","hook"],"fr-clock":["number","compare"],"fr-chips":["list"],"fr-paper":["hook","quote"],"fr-comment-cta":["cta","outro"],"fr-chapter":["title","intro"],"fr-definition":["explain"],"fr-recap":["list","outro"],"fr-lower-third":["lower"]}).flatMap(([t,e])=>[[t,{beats:e}],[t.replace(/^fr-/,"fr-v-"),{beats:e}]]))}),ux=t=>{const e=String(t||"").match(/\/\/ ([^\n]+)/);return e?e[1].trim():""},dx={text:"text",sub:"subText",items:"items",number:"numberValue",icon:"icon",glyph:"icon",posX:"posX"};function hx(t){const e=t.pack||"basic",o=Jh[e]||Jh.basic,r=sx(t),n=ux(t.code).slice(0,140),a=`${t.id} ${t.name} ${n}`;let i=r==="transition"?["transition"]:r==="background"?["background"]:r==="look"?["decor"]:[];if(!i.length)for(const[f,m]of cx)f.test(a)&&!i.includes(m)&&i.push(m);i.length||(i=[r==="scene"?"explain":"decor"]);const l=px[t.id];l?.beats&&(i=[...l.beats]);const p=t.params?.position,c=["scene","background","look","transition"].includes(r)?"full":["top","center","lower"].includes(p)?p:"center",s=[...new Set(Object.keys(t.params||{}).map(f=>dx[f]).filter(Boolean))],h=Array.isArray(t.formats)&&t.formats.includes("portrait")?"portrait":"any";return Object.freeze({id:t.id,pack:e,role:r,beats:i,zone:c,fields:s,energy:o.energy,tone:o.tone,industries:o.industries,dur:t.duration,about:n,fmt:h})}let mp=null;function Fl(){return mp||(mp=Object.freeze(Yi.filter(t=>tb.includes(t.id)).map(hx))),mp}const fx={finance:["tài chính","đầu tư","chứng khoán","cổ phiếu","ngân hàng","tiết kiệm","lãi","tiền","finance","invest","stock","bank","crypto","ví"],ai:[" ai ","trí tuệ nhân tạo","agent","chatbot","gpt","mô hình","model"],tech:["công nghệ","phần mềm","ứng dụng","app","tech","software","công cụ"],saas:["saas","dashboard","nền tảng","platform","tính năng","feature","timeline"],commerce:["bán hàng","sale","giảm giá","khuyến mãi","shop","livestream","đơn hàng","mua"],gaming:["game","gaming","esport","game thủ","stream"],education:["dạy","học","khoá học","khóa học","hướng dẫn","tutorial","giáo dục","bài học","giải thích"],corporate:["doanh nghiệp","công ty","b2b","báo cáo","corporate","tvc","thương hiệu","brand"],creator:["vlog","creator","talking head","reels","tiktok","youtube","người nói"],beauty:["mỹ phẩm","làm đẹp","spa","skincare","beauty"],food:["đồ ăn","món ăn","nhà hàng","f&b","cafe","cà phê","food","bánh","quán","thực đơn","menu","đồ uống","trà sữa","món ngon"],realestate:["bất động sản","căn hộ","chung cư","nhà phố","biệt thự","đất nền","dự án","phòng ngủ","real estate","apartment","property"],health:["sức khoẻ","sức khỏe","y tế","bác sĩ","phòng khám","bệnh viện","thuốc","khám","nha khoa","health","clinic","doctor","dental"],fitness:["gym","tập luyện","thể hình","thể thao","giảm cân","yoga","chạy bộ","huấn luyện viên","fitness","workout"," sport "],travel:["du lịch","tour","khách sạn","resort","vé máy bay","homestay","check-in","travel","hotel","trip"],auto:["ô tô","xe hơi","xe máy","xe điện","lái thử","showroom","car","vehicle","motorbike"],data:["số liệu","biểu đồ","thống kê","dashboard","data","chart","infographic"],luxury:["sang trọng","cao cấp","luxury","premium"],product:["sản phẩm","ra mắt","launch","3d","glb","product"],event:["sự kiện","event","hội nghị","lễ"]},mx={hook:["mở đầu","hook","gây chú ý"],title:["tiêu đề","title"],cta:["cta","kêu gọi","đăng ký","mua ngay","liên hệ","comment","bình luận"],number:["số liệu","tăng","%","doanh thu","kpi","con số"],list:["bước","quy trình","danh sách","steps"],compare:["so sánh","trước sau","before","after","vs"],proof:["đánh giá","review","khách hàng nói","chứng nhận"],transition:["chuyển cảnh","transition","nối"],lower:["tên người","lower third","chức danh"]},Qh=(t,e)=>t.includes(e);function jg(t){const e=` ${String(t||"").toLowerCase()} `,o=Object.entries(fx).filter(([,n])=>n.some(a=>Qh(e,a))).map(([n])=>n),r=Object.entries(mx).filter(([,n])=>n.some(a=>Qh(e,a))).map(([n])=>n);return{industries:o,beats:r}}const gx=Object.freeze(["minimal","luxury","friendly","bold","tech"]),yx=Object.freeze({minimal:["iris","slab"],luxury:["iris","ink"],friendly:["shapes","stripes"],bold:["slab","flash","whip"],tech:["glitch","tunnel","whip"]}),bx=/^#[0-9a-f]{6}$/i,Wa=(t,e)=>typeof t=="string"?t.trim().slice(0,e):"";function Tg(t){if(!t||typeof t!="object")return null;const e=new Set(eb.map(n=>n.id)),o={name:Wa(t.name,60),tagline:Wa(t.tagline,80),website:Wa(t.website,80),phone:Wa(t.phone,40),address:Wa(t.address,100),industry:lx.includes(t.industry)?t.industry:"general",tone:gx.includes(t.tone)?t.tone:"minimal",colors:(Array.isArray(t.colors)?t.colors:[]).filter(n=>bx.test(n)).map(n=>n.toLowerCase()).slice(0,3),pack:e.has(t.pack)?t.pack:null,banned:(Array.isArray(t.banned)?t.banned:[]).filter(n=>e.has(n)).slice(0,20),logoMaterialId:Wa(t.logoMaterialId,200)||null},r=Object.fromEntries(["heading","body"].filter(n=>Tk(t.fonts?.[n])).map(n=>[n,t.fonts[n]]));return Object.keys(r).length&&(o.fonts=r),o.name||o.colors.length||o.logoMaterialId?o:null}const wx=t=>[t?.website,t?.phone,t?.address].filter(Boolean);function BA(t){const e=Tg(t);return e?[e.name&&`Brand: ${e.name}`,e.tagline&&`tagline "${e.tagline}"`,e.industry!=="general"&&`industry ${e.industry}`,`tone ${e.tone}`,e.colors.length&&`colours ${e.colors.join(" ")}`,e.website&&`website ${e.website}`,e.phone&&`phone ${e.phone}`,e.address&&`address ${e.address}`].filter(Boolean).join(" · "):""}const ue=(t,e,...o)=>({name:t,dur:e,presets:o}),Og=Object.freeze({"tvc-15":{name:"TVC 15 giây",beats:[ue("open",2.5,"tvc-brand-open"),ue("problem",3,"tvc-problem"),ue("solution",3.5,"tvc-solution"),ue("offer",3,"tvc-offer","tvc-big-stat"),ue("cta",3,"tvc-cta-contact")]},"tvc-30":{name:"TVC 30 giây",beats:[ue("open",3,"tvc-brand-open"),ue("problem",4,"tvc-problem"),ue("solution",4,"tvc-solution"),ue("features",5,"tvc-feature-trio"),ue("proof",4,"tvc-testimonial","tvc-big-stat","tvc-trust-badges"),ue("offer",4,"tvc-offer","tvc-countdown-offer"),ue("cta",3,"tvc-cta-contact"),ue("logo",3,"tvc-logo-sting")]},"product-launch":{name:"Ra mắt sản phẩm",beats:[ue("open",3,"tvc-brand-open"),ue("solution",4,"tvc-solution"),ue("features",5,"tvc-feature-trio"),ue("compare",4,"tvc-before-after"),ue("cta",3,"tvc-cta-contact"),ue("logo",3,"tvc-logo-sting")]},"promo-sale":{name:"Khuyến mãi",beats:[ue("slogan",3,"tvc-slogan"),ue("offer",4,"tvc-offer"),ue("countdown",3,"tvc-countdown-offer"),ue("proof",2.5,"tvc-trust-badges"),ue("cta",3,"tvc-cta-contact")]},"brand-story":{name:"Câu chuyện thương hiệu",beats:[ue("logo",3,"tvc-logo-sting"),ue("slogan",4,"tvc-slogan"),ue("number",4,"tvc-big-stat"),ue("proof",5,"tvc-testimonial"),ue("partners",4,"tvc-partners"),ue("cta",3,"tvc-cta-contact")]},"store-visit":{name:"Mời ghé cửa hàng",beats:[ue("open",3,"tvc-brand-open"),ue("features",4,"tvc-feature-trio"),ue("offer",3.5,"tvc-offer"),ue("location",4,"tvc-location"),ue("logo",3,"tvc-logo-sting")]}}),kx=Object.freeze(Object.keys(Og)),xx={flash:.8,whip:.8,glitch:.8,slab:1,iris:1,stripes:1,ink:1.2,shapes:1.2,tunnel:1.2},da=t=>+(+t).toFixed(3),gp=t=>String(t??"").slice(0,60);function Mx(t,e,o){const r=e?.[t.name]||{},n={},a=r.text??(t.name==="open"||t.name==="logo"?o?.name:t.name==="slogan"?o?.tagline:void 0),i=r.sub??r.subText??(t.name==="open"||t.name==="logo"?o?.tagline:t.name==="location"?o?.address:void 0),l=Array.isArray(r.items)?r.items:t.name==="cta"?wx(o):void 0;return a&&(n.text=gp(a)),i&&(n.subText=gp(i)),l?.length&&(n.items=l.map(gp).slice(0,5)),Number.isFinite(+r.number)&&r.number!==null&&r.number!==""&&(n.numberValue=+r.number),n}function $x({recipe:t="tvc-15",copy:e={},brand:o=null,start:r=0,portrait:n=!1,dark:a=!1,base:i=0}={}){const l=Og[t];if(!l)throw Error(`TVC recipe must be ${kx.join("/")}`);const p=o?.colors?.[0],c=[],s=l.beats.reduce((y,$)=>y+$.dur,0),h=yx[o?.tone||"minimal"];for(let y=0;y<s-.001;y+=Qe.maxDuration)c.push({op:"addMotion",motionPreset:"tvc-backdrop",start:da(r+y),duration:da(Math.min(Qe.maxDuration,s-y)),numberValue:a?1:0,...p?{color:p}:{}});let f=r,m=null;if(l.beats.forEach((y,$)=>{const x=e?.[y.name]?.preset,E=y.presets.includes(x)?x:y.presets[0];if(c.push({op:"addMotion",motionPreset:E,start:da(f),duration:da(y.dur),placement:"center",...Mx(y,e,o),...p?{color:p}:{}}),E==="tvc-logo-sting"&&(m={start:f,dur:y.dur}),$>0){const v=h[($-1)%h.length],S=xx[v];c.push({op:"addMotion",motionPreset:`bridge-${v}`,start:da(Math.max(r,f-S/2)),duration:S,...p?{color:p}:{}})}f+=y.dur}),o?.logoMaterialId&&m){const y=i+c.filter($=>/^add/.test($.op)).length+1;c.push({op:"addClip",materialId:o.logoMaterialId,start:da(m.start+.25),duration:da(m.dur-.25),track:In(6)},{op:"setPropertyKeys",clipId:`new:${y}`,property:"zoom",propertyKeys:[{time:0,value:n?.2:.16}]},{op:"setPropertyKeys",clipId:`new:${y}`,property:n?"y":"x",propertyKeys:[{time:0,value:n?-.045:-.12}]})}return c}const vx=t=>{try{const e=JSON.parse(String(t||"{}"));return e&&typeof e=="object"?e:{}}catch{return{}}};function Ex(t,{brand:e=null,portrait:o=!1}={}){if(!t.some(p=>p?.op==="tvc"))return t;const r=[],n=[];let a=0,i=0;const l=p=>{const c=typeof p=="string"&&/^new:(\d+)$/.exec(p);if(!c)return p;const s=+c[1];let h=0;for(const f of n)s>f.after&&(h+=f.by);return`new:${s+h}`};for(const p of t){const c=p?.clipId||p?.fromClipId||p?.sourceClipId?{...p,...p.clipId?{clipId:l(p.clipId)}:{},...p.fromClipId?{fromClipId:l(p.fromClipId)}:{},...p.sourceClipId?{sourceClipId:l(p.sourceClipId)}:{}}:p;if(c?.op!=="tvc"){r.push(c),/^(add|lockup$)/.test(c?.op??"")&&(a++,i++);continue}const s=$x({recipe:c.preset,copy:vx(c.prompt),brand:e,start:+c.start||0,portrait:o,dark:c.booleanValue===!0,base:a}),h=s.filter(f=>/^add/.test(f.op)).length;r.push(...s),h&&n.push({after:i,by:h}),a+=h}return r}const Pg=15,Sx=7.5,yp=1e-6,es=t=>Math.round(t*30)/30;function _A(t){const e=Number(t);if(!Number.isFinite(e)||e<1-yp||e>Pg+yp)return null;const o=Math.max(1,Math.ceil(e/Sx-yp)),r=e/o;return Array.from({length:o},(n,a)=>({k:a+1,n:o,from:es(a*r),to:es((a+1)*r),duration:es(es((a+1)*r)-es(a*r))}))}const bp=t=>String(+t.toFixed(2));function GA(t,e,o,r=6e3){if(!e||e.n<=1)return String(t).slice(0,r);const n=`(Phần ${e.k}/${e.n}: chỉ dựng đoạn ${bp(e.from)}–${bp(e.to)} giây của cảnh ${bp(o)} giây${e.k>1?"; nối tiếp liền mạch từ phần trước":""}${e.k<e.n?"; kết thúc giữa chuyển động để phần sau nối tiếp":""})`;return`${String(t).trim().slice(0,r-n.length-1)}
|
|
2
|
+
${n}`}const Os="(\\d+(?:[.,]\\d+)?)",zg="(s|secs?|seconds?|giây|giay|phút|phut|min|mins|minutes?)(?![\\p{L}\\p{N}])",Ix=new RegExp(`${Os}\\s*(?:–|—|-|đến|tới|to)\\s*${Os}\\s*${zg}`,"giu"),Ax=new RegExp(`(?:từ\\s+)?(?:giây|giay|second)\\s*${Os}\\s*(?:–|—|-|đến|tới|to)\\s*(?:giây|giay|second)?\\s*${Os}(?![\\p{L}\\p{N}])`,"giu"),Cx=new RegExp(`${Os}\\s*${zg}`,"giu"),os=t=>Number(t.replace(",",".")),wp=t=>/^(phút|phut|min)/i.test(t)?60:1;function KA(t){let e=String(t||"").toLowerCase();const o=[];e=e.replace(Ix,(l,p,c,s)=>(o.push([os(p)*wp(s),os(c)*wp(s)])," ")),e=e.replace(Ax,(l,p,c)=>(o.push([os(p),os(c)])," "));const r=[...e.matchAll(Cx)].map(l=>os(l[1])*wp(l[2])).filter(l=>l>0),n=o.filter(([l,p])=>p>l),a=n.length?Math.max(...n.map(l=>l[1]))-Math.min(...n.map(l=>l[0])):0,i=Math.max(0,a,...r);return i>0?Math.round(i*100)/100:null}const jx=Object.freeze(["left","zoom","strips","up","glitch","right","zoom","down","strips","left","glitch","up"]),Tx={left:"whoosh-fast-swish",right:"whoosh-fast-swish",up:"whoosh-short-up",down:"whoosh-short-down",zoom:"zoom-whoosh",strips:"whoosh-double",glitch:"glitch"},Ox=Object.freeze(["bridge-ink","bridge-iris","bridge-slab","bridge-tunnel","pop-circle-wipe","bridge-stripes","bridge-shapes","mono-ribbon-wipe","bridge-flash","bridge-whip","launch-wipe","bridge-glitch","creator-flash"]),Px=["cyber-slab-wipe","cyber-pixel-dissolve"],Lg={punch:["join-cube-turn","join-split-screen","join-type-wall","join-zoom-object","join-panel-flip","join-mosaic-tiles"],motion:["join-cube-turn","join-shape-morph","join-split-screen","join-particle-reform","join-zoom-object","join-blinds-3d"],luxury:["join-light-leak","join-blinds-3d","join-page-curl"],neon:["join-mosaic-tiles","join-particle-reform","join-panel-flip","join-halftone"],paper:["join-paper-tear","join-paper-fold","join-page-curl","join-halftone"],minimal:["join-blinds-3d","join-split-screen","join-shape-morph"],cinematic:["join-light-leak","join-page-curl","join-zoom-object","join-blinds-3d"],pulse:["join-cube-turn","join-panel-flip","join-mosaic-tiles","join-halftone","join-shape-morph","join-split-screen"],lumen:["join-ripple-rings","join-light-leak","join-particle-reform","join-zoom-object"],fluid:["join-liquid-drip","join-ripple-rings","join-shape-morph"]},tf=["rect","circle","diamond","bars"],zx=Object.freeze(["letters","solid","outline","streak","echo","solid","reflect","chrome","glitch","outline"]),Lx=["chrome","echo","glitch"],Nx=["reflect","streak"],sc=t=>(t.match(/(?:^|\s)((?:[A-Z][\p{L}\d]+)(?:\s+[A-Z][\p{L}\d]+)*)/gu)||[]).map(e=>e.trim()).filter((e,o)=>o||!t.trim().startsWith(e))[0],Fx=Object.freeze([{el:"timeline",preset:"kin-el",re:/after effects|premiere|timeline|keyframe|dựng|chỉnh sửa|\bedit/i,label:(t,e)=>/after effects/i.test(t)?"After Effects":e?"Dự án · Timeline":"Project · Timeline"},{el:"nodes",preset:"kin-el2",re:/\bmcp\b|plugin|kết nối|tích hợp|\bapi\b|connect|integrat/i,label:t=>(t.match(/\bmcp\b|\bapi\b|plugin/i)?.[0]||"AI").toUpperCase()},{el:"render",preset:"kin-el2",re:/render|xuất|export|tải về|download/i,label:(t,e)=>e?"Đang xuất video…":"Rendering…"},{el:"cube",preset:"kin-el",re:/\b3d\b|khối|mô hình|model/i,label:()=>"3D"},{el:"chart",preset:"kin-el2",re:/tăng|doanh thu|tăng trưởng|%|\d|graph|chart|growth|revenue|số liệu/i,label:(t,e)=>e?"Kết quả":"Results"},{el:"player",preset:"kin-el",re:/video|clip|phim|reel|youtube|tiktok/i,label:()=>"Video"},{el:"chat",preset:"kin-el",re:/\b(ai|claude|chatgpt|gpt|prompt|chat)\b|gõ|hỏi/i,label:t=>t.replace(/[.!?…]+$/,"").slice(0,34)},{el:"logo",preset:"kin-el2",re:/./,label:t=>sc(t)||"",when:t=>(sc(t)||"").length>=5}]);function Rx(t,e=!0){const o=e?9:16,r=e?16:9,n=Math.min(o,r),a=o-2*o*(e?.075:.07),i=Math.min(a,n*(e?.86:.62)),l=i*.56,p=o/2-i/2,c=r*(e?.6:.56),s={icon:[o/2,c+l*.45],photo:[o/2,c+l*.42],player:[o/2,c+l*.45],chat:[p+i*.92,c+l*.48],cube:[o/2,c+l*.5],nodes:[p+i*.18,c+l*.35],timeline:[p+i*.6,c+l*.55],chart:[p+i*.82,c+l*.3],render:[p+i*.9,c+l*.6],logo:[o/2,c+l*.35]}[t]||[o/2,r/2];return[+(s[0]/o).toFixed(3),+(s[1]/r).toFixed(3)]}const Dx=[["cta",/mở tài khoản|tải app|xem ngay|gọi ngay|nhận ngay|ngay hôm nay|mua ngay|đăng ký|liên hệ|\bthử\b|đặt (ngay|hàng|lịch|bàn)|inbox|nhắn tin|theo dõi|follow|bình luận|comment|ghé|order|subscribe|sign up|\btry\b|\bbuy\b|shop now|book now/i],["proof",/đánh giá|khách hàng|review|feedback|tin dùng|tin tưởng|testimonial|trusted|★/i],["compare",/so với|\bvs\b|trước và sau|thay vì|hơn hẳn|before|after|instead/i],["list",/,.+,|\d+ (bước|cách|lý do|mẹo)|steps|tips|reasons/i],["number",/\d/]],Bx=[[/bánh|món|quán|ăn ngon|đồ uống|cà phê|trà sữa|nhà hàng|thực đơn|menu|food|coffee|restaurant/i,["food"]],[/căn hộ|nhà phố|biệt thự|đất nền|bất động sản|dự án|phòng ngủ|real estate|apartment/i,["realestate","luxury"]],[/sức khoẻ|sức khỏe|bác sĩ|phòng khám|bệnh viện|thuốc|nha khoa|khám|health|clinic|doctor/i,["health"]],[/gym|tập luyện|thể hình|giảm cân|yoga|chạy bộ|cơ bắp|workout|fitness/i,["fitness"]],[/ô tô|xe hơi|xe máy|xe điện|lái thử|showroom|\bcar\b|vehicle/i,["auto"]],[/da |làn da|serum|mỹ phẩm|làm đẹp|spa|son |kem dưỡng|skincare|beauty/i,["beauty","commerce"]],[/lãi|vay|tiết kiệm|đầu tư|ngân hàng|chứng khoán|bảo hiểm|loan|invest|bank/i,["finance","corporate"]],[/học|khoá|khóa|lớp|giáo viên|kỹ năng|course|lesson|learn/i,["education"]],[/du lịch|tour|vé máy bay|khách sạn|resort|homestay|travel|hotel/i,["travel","luxury"]],[/giảm giá|khuyến mãi|sale|freeship|mua 1|voucher|deal/i,["commerce"]]],Ng=t=>[...new Set(Bx.filter(([e])=>e.test(t)).flatMap(([,e])=>e))],_x=[[/giá|đồng|vnđ|vnd|\$|\d+k\b|tỷ|triệu|price/i,/\bprice|\bpricing|\boffer|receipt|\btag\b|wallet|odometer/],[/%/,/percent|ring|gauge|donut|progress|pie|burst/],[/khách|người|lượt|đơn|thành viên|users|customers|orders/i,/counter|odometer|kpi|stat|bubbles|ranking/],[/phút|giờ|ngày|tuần|countdown|minutes|hours|days/i,/countdown|calendar|timeline|clock|gantt/],[/sao|★|đánh giá|review/i,/testimonial|award|stamp|ranking|quote/],[/liên hệ|gọi|hotline|địa chỉ|contact|call/i,/contact|qr|cta/],[/mua|đặt|đăng ký|thử|buy|order|sign up|try/i,/cta|buy|offer|contact/]],Fg=t=>Dx.find(([,e])=>e.test(t))?.[0]??null,ef=t=>String(t).toLowerCase().normalize("NFC").split(/[^\p{L}\p{N}]+/u).filter(e=>e.length>=3),Rg=t=>{const e=String(t).match(/(\d[\d.,]*)/);if(!e)return null;const o=parseFloat(e[1].replace(/\.(?=\d{3}\b)/g,"").replace(",","."));return Number.isFinite(o)?o:null};function Gx(t,{industries:e=[],dark:o=!0,used:r=new Set,pack:n=null,accent:a="#e8141c"}={}){const i=Fg(t);if(!i)return null;const l=ef(t),p=i==="number"?"numberValue":i==="list"?"items":null,c=Fl().filter(S=>S.role==="overlay"&&!S.pack.startsWith("kinetic")&&!S.id.startsWith("kin-")&&S.beats.includes(i)&&S.zone!=="top"&&S.fields.includes("text")&&(!p||S.fields.includes(p))&&(S.tone==="any"||S.tone==="dark"===o)&&!r.has(S.id));if(!c.length)return null;const s=_x.filter(([S])=>S.test(t)).map(([,S])=>S),h=S=>`${S.id} ${S.about}`.toLowerCase(),f=S=>e.length&&!S.industries.some(k=>e.includes(k))&&!S.industries.includes("general"),m=S=>S.industries.filter(k=>e.includes(k)).length*3+(S.pack===n?2:0)+ef(h(S)).filter(k=>l.includes(k)).length+(S.industries.includes("general")?.5:0)+s.filter(k=>k.test(h(S))).length*4-(f(S)?4:0)-(/percent/.test(S.id)&&!/%/.test(t)?6:0)-(/^(ai|cyber)-/.test(S.id)&&!e.some(k=>["ai","tech","gaming","saas"].includes(k))?6:0),y=c.map(S=>({t:S,s:m(S)})).sort((S,k)=>k.s-S.s||S.t.id.localeCompare(k.t.id))[0].t,$=String(t).replace(/[.!?…]+$/,"").trim(),x=Rg($),E={color:a,placement:"lower",text:(i==="number"&&x!=null?$.replace(/\d[\d.,]*\s*%?/,"").replace(/\s+/g," ").trim():$).slice(0,28)||$.slice(0,28)};if(x!=null&&y.fields.includes("numberValue")&&(E.numberValue=x),y.fields.includes("items")){const S=$.split(/,| và | and /).map(k=>k.trim()).filter(Boolean);E.items=(S.length>=2?S:$.split(" ").reduce((k,b,A)=>{const I=Math.floor(A/2);return k[I]=k[I]?k[I]+" "+b:b,k},[])).slice(0,4)}const v=Ii($);v&&y.fields.includes("icon")&&(E.icon=v);try{const S=Ai(y.id,E);return{preset:y.id,pack:y.pack,params:S.params,library:!0}}catch{return null}}function Kx(t,e=!0){const o=Ii(t);if(!o)return null;const r=ob[o];return{el:"icon",preset:"kin-el2",label:(e?r.name:r.en||r.name)||"",glyph:o}}function Vx(t,{vi:e=!0,prev:o=null,last:r=!1}={}){if(r&&sc(t)&&o!=="logo")return{el:"logo",preset:"kin-el2",label:sc(t)};for(const n of Fx)if(n.re.test(t)&&(!n.when||n.when(t))&&n.el!==o){const a=n.label(t,e);if(a)return{el:n.el,preset:n.preset,label:a}}return null}const lc=/[.!?…:;,]$/,Dg=/[.!?…]$/,Wx=[[.91,.1],[.09,.9],[.91,.9],[.09,.1]],Ta=Object.freeze({words:300,beatMin:.28,lineChars:{portrait:14,landscape:22},maxBeatWords:3}),Xx=t=>String(t||"").split(/\s+/).filter(Boolean).length,Bg=t=>`Vượt giới hạn ${Ta.words} từ (đang có ${t} từ) — rút gọn kịch bản hoặc chọn một đoạn ngắn hơn.`;function Hx(t,e=0,{rate:o=2.6}={}){const r=[];let n=e;const a=Xx(t);if(a>Ta.words)throw Error(Bg(a));for(const i of String(t||"").split(/\s+/).filter(Boolean)){const l=Math.max(.24,Math.min(.7,(.18+i.length*.035)*2.6/o));r.push({word:i,start:+n.toFixed(3),end:+(n+l).toFixed(3)}),n+=l+(Dg.test(i)?.35:lc.test(i)?.15:0)}return r}const of=t=>/[!?]$/.test(t)||/\d/.test(t)||t.length>2&&t===t.toUpperCase()&&/[A-ZÀ-Ỹ]/.test(t);function Ux(t,{portrait:e=!0,dense:o=!1,wide:r=!1}={}){const n=(t||[]).filter(p=>p&&typeof p.word=="string"&&p.word.trim()&&Number.isFinite(p.start)).slice(0,Ta.words).map(p=>({word:p.word.trim(),start:p.start,end:Number.isFinite(p.end)?p.end:p.start+.3})),a=Ta.lineChars[e?"portrait":"landscape"]+(r?22:o?8:0),i=[];let l=null;return n.forEach((p,c)=>{const s=n[c-1],h=s?p.start-s.end:0,f=l?l.words.join(" ").length+1+p.word.length:0;(!l||lc.test(s?.word??"")||h>=.45||f>a+(lc.test(p.word)?10:0))&&(l={words:[],beats:[]},i.push(l));const m=l.beats.at(-1),y=l.words.length;l.words.push(p.word);const $=of(p.word)||m&&of(l.words[y-1]);m&&(p.start-m.start<Ta.beatMin||!$&&p.word.length<=3&&m.k<Ta.maxBeatWords)?(m.k++,m.n++,m.end=p.end):l.beats.push({n:y+1,k:1,start:p.start,end:p.end})}),i.map(p=>({text:p.words.join(" "),beats:p.beats}))}const La=Object.freeze({motion:{vi:"Motion (chữ động + cảnh motion)",en:"Motion (kinetic + motion scenes)",use:"kinetic words with motion-graphic scene interludes; general promos, explainers, mixed content",kind:"kinetic",interlude:!0},punch:{vi:"Bùng nổ",en:"Punch",use:"bold full-frame kinetic type, fast; sales, offers, hooks, ads, energetic social clips",kind:"kinetic"},luxury:{vi:"Sang trọng",en:"Luxury",use:"black + gold serif, slow and elegant; luxury brands, real estate, jewellery, premium services",kind:"kinetic",style:"cine",palette:{dark:"#0d0b08",light:"#f2ebdf",accent:"#c9a45c"},looks:["letters","reflect","streak","solid","letters","chrome"],joins:["zoom","up","zoom","left","up"],orb:!1},neon:{vi:"Neon",en:"Neon",use:"glitch neon type on dark; gaming, nightlife, cyber / tech hype, music drops",kind:"kinetic",style:"neon",palette:{dark:"#070512",light:"#16103a",accent:"#19e3ff"},looks:["glitch","echo","streak","outline","glitch","solid"],joins:["glitch","strips","zoom","left","glitch","up"]},paper:{vi:"Cắt dán",en:"Paper cut",use:"hand-made paper-cut collage, warm and friendly; food, kids, crafts, lifestyle, small shops",kind:"kinetic",style:"pop",palette:{dark:"#2b1d14",light:"#f3ead8",accent:"#e8492d"},looks:["outline","letters","solid","outline","echo"],joins:["up","left","right","down","strips"]},minimal:{vi:"Tối giản",en:"Minimal",use:"clean white, calm; corporate, education, finance, health, B2B, announcements",kind:"kinetic",style:"clean",palette:{dark:"#111214",light:"#f6f6f4",accent:"#2f6bff"},looks:["solid","letters","solid","outline"],joins:["up","left","zoom","right"],orb:!1},cinematic:{vi:"Điện ảnh",en:"Cinematic",use:"chain of glowing 2D symbol scenes (house, eye, sword, crown, heart, moon, rocket…) with serif captions; stories, inspiration, brand values, emotional messages",kind:"scenes",pack:"cine",caption:"cine-caption",min:2.4,colors:["#0a1030","#2a070e","#120c3a","#0b2018","#1d0a26","#062029","#2a1406"]},pulse:{vi:"Hình học",en:"Geometric",use:"chain of abstract geometric neon scenes (rings, bars, hexagons, a bouncing ball) cut on the beat; tech, AI, music, events, launches",kind:"scenes",pack:"pulse",caption:"pulse-word",min:1.6,colors:["#07060c","#8b7bff","#07060c","#ffb35c","#07060c","#ff2a3d","#07060c"]},story:{vi:"Câu chuyện",en:"Story",use:"duotone narrative where one hero object (paper plane, heart, message bubble) flies scene to scene with the camera following; personal stories, relationships, messages, journeys",kind:"scenes",pack:"story",caption:"story-caption",min:2.2,colors:["#1b1b1d","#ff3b5c","#0d0d0f","#ff3b5c","#1b1b1d","#efe9d6","#0d0d0f"]},morph:{vi:"Biến hình",en:"Shape shifter",use:"one glowing connector that changes form at every cut (dot, thread, arrow ring, diamond, star, pill, card, loading dots, sun, blobs, logo) in warm amber; brand stories, step-by-step explainers, product journeys, onboarding",kind:"scenes",pack:"morph",caption:"morph-caption",min:1.8,colors:["#120a06","#ff8a1f","#120a06","#fbf3e6","#120a06","#2a1408","#120a06"]},promo:{vi:"Ra mắt sản phẩm",en:"Product reveal",use:"app / AI / product launch: logo spark, glass card, neon prompt bar typing the words, glass app icons, call-to-action button; SaaS, apps, software features, product reveals",kind:"scenes",pack:"promo",caption:"promo-caption",min:1.8,colors:["#05050b","#07061a","#05050b","#0a0620","#05050b","#060a1c","#05050b"]},fluid:{vi:"Chất lỏng",en:"Liquid flow",use:"soft liquid scenes (morphing blobs, drops, waves, ink, bubbles) flooding into each other; beauty, cosmetics, drinks, wellness, fashion, calm premium products",kind:"scenes",pack:"fluid",caption:"fluid-caption",min:1.8,colors:["#14102a","#ff6fb5","#14102a","#b49cff","#0d0b1e","#ffb38a","#14102a"]},rebound:{vi:"Bóng nảy",en:"Rebound",use:"a glowing ball bouncing through thin neon line-art sets, the camera following it; sports, fitness, games, energetic tech, growth / momentum messages",kind:"scenes",pack:"rebound",caption:"rebound-caption",min:1.5,colors:["#07071a","#0a0b22","#07071a","#0c0a1e","#07071a","#0a0b22","#07071a"]},glass:{vi:"Kính Fintech",en:"Glass Fintech",use:"dark glass charts, counters, prices, big blue keyword; finance, trading, fintech, SaaS",kind:"scenes",plan:"glass",pack:"glass",caption:"glass-words",min:1.8,palette:{dark:"#04050d",light:"#04050d",accent:"#3a63ff"},colors:["#04050d"]},stack:{vi:"Chữ bậc thang",en:"Mixed-size Stack",use:"stairs of small + BIG accent words; explainers, persuasive talks, tips",kind:"kinetic",plan:"stack",caption:"glass-stack",palette:{dark:"#05060f",light:"#05060f",accent:"#3a63ff"}},lumen:{vi:"Ánh sáng sống",en:"Living glow",use:"living glow: neon rings, iridescent orbs, a glowing creature, holographic spheres, a ring tunnel, ending on a neon word; music, creative studios, dreamy / magical / AI-art moods",kind:"scenes",pack:"lumen",caption:"lumen-caption",min:1.3,colors:["#05041a","#0b0624","#05041a","#120a2c","#05041a","#0b0624","#05041a"]}}),VA=Object.keys(La),Yx=/ước mơ|hành trình|câu chuyện|cuộc đời|cuộc sống|hy vọng|tình yêu|yêu thương|nỗi|kỷ niệm|tuổi|bình yên|dream|journey|story|life|hope|love/i,qx={story:[/tin nhắn|nhắn|hành trình|chuyến đi|bạn bè|người yêu|kỷ niệm|nhớ|gặp lại|xa nhau|gia đình|message|journey|friend|memory|miss you/gi,3],cinematic:[/ước mơ|câu chuyện|cuộc đời|cuộc sống|hy vọng|yêu thương|bình yên|vượt qua|chiến thắng|giá trị|sứ mệnh|truyền cảm hứng|dream|story|life|hope|courage|mission|inspire/gi,2],morph:[/biến hình|thay đổi|chuyển mình|từng bước|bước \d|hành trình thương hiệu|quy trình|khởi đầu|transform|change|step by step|process|evolve/gi,3],promo:[/ra mắt|phiên bản|ứng dụng|tính năng|tải ngay|thử ngay|đăng ký|nền tảng|phần mềm|giao diện|tự động|trợ lý|launch|app|feature|download|sign up|platform|software|assistant/gi,3],fluid:[/mềm mại|dịu|mượt|tan chảy|chất lỏng|nước|tươi mát|làn da|dưỡng|mỹ phẩm|nước hoa|thức uống|smooth|liquid|flow|fresh|skin|serum|perfume|drink/gi,3],rebound:[/nhảy|nảy|bật|đà|tốc độ|vận động|thể thao|tập luyện|ghi bàn|cấp độ|thử thách|bounce|jump|speed|sport|workout|level up|challenge/gi,3],lumen:[/sống|thở|ánh sáng|phát sáng|năng lượng|kỳ diệu|phép màu|giấc mơ|âm nhạc|giai điệu|sáng tạo|alive|glow|energy|magic|music|creative|dreamy/gi,2],pulse:[/công nghệ|dữ liệu|thuật toán|tương lai|nhịp|đột phá|sự kiện|lễ hội|tech|data|future|beat|event|festival/gi,2],neon:[/game|chơi|đêm|bùng cháy|cyber|hacker|esport|night|club|neon|rave/gi,3],luxury:[/sang trọng|đẳng cấp|cao cấp|tinh tế|thượng lưu|biệt thự|trang sức|vàng|luxury|premium|elegant|exclusive|villa|jewel/gi,3],paper:[/món|ngon|bếp|nấu|bánh|trẻ em|thủ công|handmade|dễ thương|quán|food|kids|craft|cute|bakery/gi,3],minimal:[/doanh nghiệp|công ty|báo cáo|giáo dục|khoá học|khóa học|tài chính|sức khoẻ|sức khỏe|bệnh viện|đối tác|corporate|company|report|course|finance|health|clinic/gi,2],punch:[/giảm giá|khuyến mãi|sale|ưu đãi|mua ngay|chỉ còn|flash|deal|offer|buy now|%/gi,3],glass:[/giao dịch|đầu tư|chứng khoán|cổ phiếu|lợi nhuận|số dư|nguồn vốn|số vốn|quỹ|ví điện tử|thanh toán|tiền số|crypto|trading|trader|\btrade|fintech|invest|profit|balance|funds|stocks?\b|portfolio|dashboard/gi,3],stack:[/bí quyết|sự thật là|vấn đề là|hãy nhớ|lý do|tại sao|nếu bạn|bạn có biết|thay vì|đừng|the truth|here's why|if you|the reason|remember|instead of|secret|don't/gi,2]},Zx={luxury:["luxury","realestate"],promo:["saas","product","ai"],fluid:["beauty"],rebound:["fitness","gaming"],neon:["gaming"],pulse:["tech","data","event"],lumen:["creator","event"],glass:["finance","saas"],stack:["education"],paper:["food"],minimal:["corporate","education","finance","health"],punch:["commerce"],story:["general"],cinematic:["general"],motion:["general","creator"]};function Jx(t,{industries:e=[],tone:o=null}={}){const r={};for(const n of Object.keys(La))r[n]=0;for(const[n,[a,i]]of Object.entries(qx))r[n]+=Math.min(3,(String(t).match(a)||[]).length)*i;for(const[n,a]of Object.entries(Zx))a.some(i=>e.includes(i))&&(r[n]+=a[0]==="general"?.5:3);return o==="luxury"&&(r.luxury+=4),o==="friendly"&&(r.paper+=2),o==="minimal"&&(r.minimal+=3),o==="bold"&&(r.punch+=2),/\d/.test(t)&&(r.story-=3,r.cinematic-=3,r.punch+=1),r.motion+=1,r}function Qx(t,e={}){const o=Jx(t,e),r=Math.max(...Object.values(o)),n=Object.keys(o).filter(a=>o[a]>=r-.5&&o[a]>0);return n[(e.seed??1)%n.length]||"motion"}const cc=[[/nhà|gia đình|quê|home|house|family/i,"cine-night-house"],[/mắt|nhìn|thấy|tầm nhìn|eye|see|vision/i,"cine-eye"],[/chiến|đấu|mạnh|vượt qua|kiếm|fight|strong|battle/i,"cine-sword"],[/vua|đỉnh|thành công|chiến thắng|số 1|king|win|success|crown/i,"cine-crown-rain"],[/yêu|tim|thương|trái tim|love|heart/i,"cine-heart"],[/đêm|trăng|mơ|ngủ|night|moon|dream/i,"cine-moon"],[/chìa|bí mật|mở khoá|mở khóa|key|secret|unlock/i,"cine-key"],[/thời gian|giờ|phút|chờ|đợi|time|wait|hour/i,"cine-hourglass"],[/bay|vươn|tăng trưởng|khởi nghiệp|bứt phá|launch|rocket/i,"cine-rocket"],[/dẫn đường|hy vọng|ánh sáng|lối|hope|guide|light/i,"cine-lighthouse"],[/lửa|đam mê|nhiệt huyết|cháy|fire|passion|flame/i,"cine-flame"],[/phát triển|lớn lên|gieo|cây|rễ|grow|tree|root/i,"cine-tree"],[/vũ trụ|thế giới|hành tinh|toàn cầu|world|planet|universe|global/i,"cine-planet"],[/cơ hội|cánh cửa|bắt đầu|mở ra|door|chance|begin|start/i,"cine-door"]],rf=[[/điện thoại|tin nhắn|nhắn|gọi|phone|message|text/i,"story-phone-message"],[/thành phố|phố|đô thị|city|street/i,"story-city-flythrough"],[/mặt trời|tháp|biến mất|tan|sun|tower|vanish/i,"story-tower-dissolve"],[/vũ trụ|vệ tinh|kết nối|toàn cầu|space|satellite|connect/i,"story-satellite-orbit"],[/nhanh|tốc độ|lao|bứt tốc|fast|speed|rush/i,"story-warp-tunnel"],[/một mình|người|ánh sáng|alone|figure|light/i,"story-light-column"],[/vượt|thử thách|chướng ngại|obstacle|challenge|through/i,"story-pillar-pass"],[/nhà|quê|gia đình|home|village|family/i,"story-hill-houses"],[/tổn thương|giận|vò|crumple|hurt|angry/i,"story-paper-crumple"],[/buồn|khóc|cảm xúc|vui|sad|cry|feel/i,"story-face-reaction"],[/chú ý|nổi bật|sân khấu|spotlight|stage/i,"story-spotlight-v"],[/hành tinh|chân trời|xa|planet|horizon|far/i,"story-planet-horizon"],[/yêu|tim|thương|love|heart/i,"story-heart-burst"]],t3=t=>/yêu|tim|thương|love|heart/i.test(t)?"heart":/tin nhắn|nhắn|chat|message/i.test(t)?"bubble":/sao|ước|star|wish/i.test(t)?"star":"plane",e3={l:"r",r:"l",t:"b",b:"t",c:"c"},nf=["r","t","l","b","r"],vu=["pulse-horizon-open","pulse-dot-bloom","pulse-glossy-sphere","pulse-light-bars","pulse-color-cycle-bars","pulse-column-drop","pulse-target-rings","pulse-ring-cross","pulse-hex-spin","pulse-lens-arcs","pulse-equalizer","pulse-ui-bars","pulse-tri-orbit","pulse-ball-collide","pulse-perspective-lines","pulse-venn","pulse-ripple","pulse-ring-zoom","pulse-half-sweep","pulse-pit-bounce","pulse-split-fields","pulse-totem-stack","pulse-grid-wave","pulse-diamond-drop","pulse-orbit-dots"],_g=["lumen-dot-ring","lumen-beat-flash","lumen-jelly-bloom","lumen-horizon-flash","lumen-creature","lumen-orbit-ring","lumen-wedge-fan","lumen-holo-sphere","lumen-ring-tunnel","lumen-orb-split"],af="lumen-white-flash",o3=["rebound-dots-merge","rebound-brick-tower","rebound-ramp-shot","rebound-chevron-field","rebound-piston-launch","rebound-tube-slide","rebound-gradient-tile","rebound-skyline-hop","rebound-frame-in-frame","rebound-radial-web","rebound-atom-arches"],r3=[[/bắt đầu|hợp|gom|start|merge|together/i,"rebound-dots-merge"],[/xây|nền|gạch|build|brick|base/i,"rebound-brick-tower"],[/vươn|lên dốc|tăng|climb|rise|up/i,"rebound-ramp-shot"],[/nhịp|sóng|zigzag|rhythm|wave/i,"rebound-chevron-field"],[/bật|phóng|bứt|launch|boost|jump/i,"rebound-piston-launch"],[/trượt|ống|dòng chảy|flow|slide|pipe/i,"rebound-tube-slide"],[/thành phố|phố|biểu đồ|tăng trưởng|city|chart|growth/i,"rebound-skyline-hop"],[/màn hình|khung|app|screen|frame/i,"rebound-frame-in-frame"],[/kết nối|mạng|lan|network|connect|reach/i,"rebound-radial-web"],[/công nghệ|khoa học|nguyên tử|năng lượng|tech|science|atom|energy/i,"rebound-atom-arches"]],n3=["morph-light-thread","morph-arrow-ring","morph-diamond-frame","morph-sparkle-glow","morph-pill-band","morph-gradient-card","morph-loading-dots","morph-light-pole","morph-sun-flood","morph-path-tag","morph-blob-merge","morph-logo-wings"],a3=["dot","ring","line","star","pill","diamond","square","bar","cross","heart"],i3=["promo-logo-spark","promo-flare-card","promo-aurora-card","promo-card-pill","promo-prompt-bar","promo-icon-cloud","promo-icon-converge","promo-glass-orbit","promo-feature-cards","promo-arrow-launch","promo-dome-horizon"],s3=[[/gõ|hỏi|tìm|nhập|prompt|search|ask|type/i,"promo-prompt-bar"],[/mọi|tất cả|nhu cầu|ứng dụng|công cụ|any|every|tools|apps/i,"promo-icon-cloud"],[/tính năng|feature/i,"promo-feature-cards"],[/thử ngay|tải ngay|đăng ký|bắt đầu ngay|try|download|sign up|get started/i,"promo-cta-button"],[/phóng|bứt phá|tăng tốc|launch|boost|rise/i,"promo-arrow-launch"],[/tiến lên|tương lai|xa hơn|keep|future|forward/i,"promo-dome-horizon"]],l3=new Set(["promo-prompt-bar","promo-icon-cloud","promo-dome-horizon","promo-cta-button","promo-aurora-card","promo-flare-card"]),c3=["fluid-blob-morph","fluid-drop-splash","fluid-wave-flood","fluid-gradient-mesh","fluid-lava-lamp","fluid-ink-bloom","fluid-bubbles","fluid-pour","fluid-swirl","fluid-droplet-grid","fluid-glass-orb"],p3=[[/giọt|rơi|drop|fall/i,"fluid-drop-splash"],[/sóng|biển|tràn|wave|sea|flood/i,"fluid-wave-flood"],[/mực|lan toả|lan tỏa|ink|spread/i,"fluid-ink-bloom"],[/bong bóng|bọt|bubble|foam/i,"fluid-bubbles"],[/rót|đổ|pour|fill/i,"fluid-pour"],[/xoáy|khuấy|trộn|swirl|mix|blend/i,"fluid-swirl"],[/ấm|nóng|lava|warm|hot/i,"fluid-lava-lamp"],[/kính|trong suốt|cầu|glass|clear|orb/i,"fluid-glass-orb"],[/màu|gradient|sắc|colour|color/i,"fluid-gradient-mesh"]],u3=[[/vòng|nhẫn|bắt đầu|ring|start/i,"lumen-dot-ring"],[/nhịp|đập|tim|beat|pulse/i,"lumen-beat-flash"],[/lớn|nở|phát sáng|grow|bloom/i,"lumen-jelly-bloom"],[/chân trời|bình minh|thức|horizon|dawn|wake/i,"lumen-horizon-flash"],[/sinh vật|sống|sinh|creature|alive|life/i,"lumen-creature"],[/quanh|xoay|kết nối|orbit|around|connect/i,"lumen-orbit-ring"],[/quạt|mở ra|xoè|fan|open/i,"lumen-wedge-fan"],[/cầu|rực rỡ|hologram|sphere|shine/i,"lumen-holo-sphere"],[/đường hầm|lao|tốc độ|tunnel|rush|dive/i,"lumen-ring-tunnel"],[/chia|nhân|nhóm|split|team|together/i,"lumen-orb-split"]];function d3(t,e,{accent:o,seed:r,tail:n,known:a}){const i=[];let l=null;for(const A of t)(!l||l.end-l.start>=e.min)&&(l={lines:[],start:A.beats[0].start,end:0},i.push(l)),l.lines.push(A),l.end=A.beats.at(-1).end;if(i.length>1&&i.at(-1).end-i.at(-1).start<e.min*.6){const A=i.pop();i.at(-1).lines.push(...A.lines),i.at(-1).end=A.end}if(["lumen","rebound","fluid"].includes(e.pack)&&i.length>1&&i.at(-1).lines.length>1){const A=i.at(-1),I=A.lines.pop();A.end=A.lines.at(-1).beats.at(-1).end,i.push({lines:[I],start:I.beats[0].start,end:I.beats.at(-1).end})}const p=[],c=[],s=[],h=A=>!a||a(A),f=new Set,m=t.map(A=>A.text).join(" "),y=t3(m),$=t.find(A=>/\?$/.test(A.text)&&A.text.length<=40)?.text??"...";let x=null,E=r,v="l";const S=["dot"],k=(e.pack==="cine"?cc.map(A=>A[1]):e.pack==="story"?rf.map(A=>A[1]):e.pack==="lumen"?_g:e.pack==="rebound"?o3:e.pack==="fluid"?c3:e.pack==="promo"?i3:e.pack==="morph"?n3:vu).filter(h);if(!k.length)throw Error(`Poox 1.1: the ${e.pack} scenes are not installed`);i.forEach((A,I)=>{const P=A.lines.map(ut=>ut.text).join(" "),C=e.pack==="cine"?cc:e.pack==="story"?rf:e.pack==="lumen"?u3:e.pack==="rebound"?r3:e.pack==="fluid"?p3:e.pack==="promo"?s3:null;let z=C?C.find(([ut,gt])=>ut.test(P)&>!==x&&!f.has(gt)&&h(gt))?.[1]:null;!z&&["story","lumen","rebound","fluid","promo","morph"].includes(e.pack)&&(z=k.find(ut=>!f.has(ut)&&ut!==x));const N=e.pack==="fluid"?"fluid-melt-word":e.pack+"-neon-word",F=["lumen","rebound","fluid"].includes(e.pack)&&I===i.length-1&&I>0&&h(N);F&&(z=N),e.pack==="promo"&&I===0&&h("promo-flare-card")&&(z="promo-flare-card"),e.pack==="morph"&&I===i.length-1&&I>0&&h("morph-logo-wings")&&(z="morph-logo-wings");for(let ut=0;!z&&ut<k.length*2;ut++){const gt=k[E++%k.length];gt!==x&&(z=gt)}z=z??k[0],x=z,F||f.add(z),f.size>=k.length&&f.clear();const K=e.pack==="promo"&&l3.has(z)&&(z==="promo-cta-button"?A.lines.at(-1).text.length<=24:A.lines.every(ut=>ut.text.length<=40)),_=e.pack==="story"||e.pack==="rebound",q=_?.7:0,U=I?A.start-q:Math.max(0,A.start-.15),rt=I<i.length-1?i[I+1].start:A.end+n,ot=e.colors[I%e.colors.length],G=I<i.length-1?e.colors[(I+1)%e.colors.length]:e.colors[0],J=nf[I%nf.length],Z=(I?"i":"")+(I<i.length-1?"o":""),at=e.pack==="morph"?(()=>{const ut=S.at(-1),gt=a3.filter(u=>!S.slice(-2).includes(u)),xt=gt[(I*3+r)%gt.length];return S.push(xt),{formIn:ut,formOut:xt}})():{},D=e.pack==="story"?{hero:y,heroIn:v,heroOut:J,pan:Z}:e.pack==="rebound"?{ballIn:I?v:"c",ballOut:J,pan:Z}:e.pack==="pulse"?{ballIn:v}:{};v=e3[J],p.push({start:ht(U),duration:ht(Math.max(.6,rt-U)),line:I,preset:z,params:{bg:ot,next:G,fg:o,text:F?A.lines.at(-1).text.slice(0,60):K?z==="promo-cta-button"?A.lines.at(-1).text.slice(0,24):A.lines.map(ut=>ut.text).join(z==="promo-prompt-bar"?"|":" ").slice(0,80):"",...D,...at,...z==="story-phone-message"?{msg:$}:{}}});const H=_?[]:(Lg[e.pack==="cine"?"cinematic":e.pack]||[]).filter(h);I&&I%2===1&&H.length&&!(e.pack==="lumen"&&I%3===2)&&c.push({start:ht(Math.max(0,U-.45)),duration:ht(.9),preset:H[(I>>1)%H.length],params:{fg2:e.colors[I%e.colors.length]}}),e.pack==="rebound"&&I%4===3&&h("rebound-gradient-flash")&&c.push({start:ht(Math.max(0,U+q-.35)),duration:ht(.7),preset:"rebound-gradient-flash",params:{bg:ot,next:ot,fg:o}}),e.pack==="lumen"&&I%3===2&&h(af)&&c.push({start:ht(Math.max(0,U-.3)),duration:ht(.6),preset:af,params:{bg:ot,next:ot,fg:o}}),(!F&&!K?A.lines:K&&z==="promo-cta-button"?A.lines.slice(0,-1):[]).forEach((ut,gt)=>{const xt=Math.max(U+q+.25,ut.beats[0].start-.05),u=gt<A.lines.length-1?A.lines[gt+1].beats[0].start:rt-.35;u-xt>.3&&c.push({start:ht(xt),duration:ht(u-xt),preset:e.caption,params:{text:ut.text.slice(0,120),position:"lower"}})}),I&&s.push({at:ht(Math.max(0,U+q-.3)),id:e.pack==="pulse"||e.pack==="rebound"?"whoosh-short-up":"whoosh-airy"})});const b={lumen:[["lumen-orb",1,"top-right"],["lumen-critter",Math.floor(i.length/2)+1,"bottom-left"]],rebound:[["rebound-bricks",1,"top-left"],["rebound-ball",Math.floor(i.length/2)+1,"bottom-right"]],fluid:[["fluid-blob-el",1,"top-right"],["fluid-drip-el",Math.floor(i.length/2)+1,"top-left"]]}[e.pack];return b&&i.length>2&&b.forEach(([A,I,P])=>{const C=i[I];if(C&&h(A)&&I<i.length-1){const z=C.start+.4,N=i[I+1].start-.4;N-z>.8&&c.push({start:ht(z),duration:ht(N-z),preset:A,params:{position:P,fg:o}})}}),{beats:p,els:c,sfx:s}}const Gg=t=>t.beats.flatMap(e=>Array.from({length:e.k},(o,r)=>e.start+r*Math.min(.14,Math.max(0,(e.end??e.start+.3)-e.start)/e.k))),Kg=(t,e)=>t.map(o=>Math.max(0,o-e).toFixed(2)).join(",").slice(0,300),h3=/[ăâđêôơưàáạảãằắặẳẵầấậẩẫèéẹẻẽềếệểễìíịỉĩòóọỏõồốộổỗờớợởỡùúụủũừứựửữỳýỵỷỹ]/i,Rl=t=>t.replace(/[.,;:…]+$/,""),f3=["glass-orb-rise","glass-balance","glass-coin-bars","glass-step-chart","glass-line-target","glass-candles","glass-progress","glass-emblem"],m3=[[/%|phần trăm|percent/i,"glass-progress"],[/số dư|tài khoản|balance|account/i,"glass-balance"],[/giá|chỉ từ|chỉ còn|đ\b|₫|\$|price|from|only/i,"glass-emblem"],[/nến|giao dịch|thị trường|chứng khoán|trade|trading|market|stock/i,"glass-candles"],[/thử thách|rủi ro|mục tiêu|đích|vượt|challenge|risk|goal|target|pass/i,"glass-line-target"],[/vốn|quỹ|cấp|tài trợ|funds?|capital|fund/i,"glass-step-chart"],[/tăng|lợi nhuận|kỹ năng|thu nhập|growth|profit|skills?|earn|income/i,"glass-coin-bars"],[/bạn|trợ lý|\bai\b|you|assistant/i,"glass-orb-rise"]],sf=new Set(["glass-balance","glass-progress","glass-emblem"]);function g3(t,e,{accent:o,tail:r,known:n}){const a=E=>!n||n(E),i=[];let l=null;for(const E of t){const v=l?l.end-l.start:0;(!l||v>=e.min&&lc.test(l.lines.at(-1).text)||v>=e.min*2.5)&&(l={lines:[],start:E.beats[0].start,end:0},i.push(l)),l.lines.push(E),l.end=E.beats.at(-1).end}if(i.length>1&&i.at(-1).end-i.at(-1).start<1.2){const E=i.pop();i.at(-1).lines.push(...E.lines),i.at(-1).end=E.end}const p=f3.filter(a);if(!p.length)throw Error("Poox 1.1: the glass scenes are not installed");const c=[],s=[],h=[],f=new Set,m=e.colors[0],y=h3.test(t.map(E=>E.text).join(" "));let $=null,x=0;return i.forEach((E,v)=>{const S=E.lines.map(C=>C.text).join(" "),k=Rg(S);let b=m3.find(([C,z])=>C.test(S)&&z!==$&&!f.has(z)&&a(z)&&(!sf.has(z)||k!=null||z==="glass-balance"))?.[1];for(let C=0;!b&&C<p.length*2;C++){const z=p[x++%p.length];z!==$&&!f.has(z)&&(b=z)}b=b??p.find(C=>C!==$)??p[0],$=b,f.add(b),f.size>=p.length&&f.clear();const A=v?E.start-.1:Math.max(0,E.start-.15),I=v<i.length-1?i[v+1].start-.1:E.end+r,P=k!=null&&sf.has(b)?{number:b==="glass-progress"?Math.min(100,k):k,...b==="glass-balance"?{from:Math.round(k*.86)}:{}}:{};c.push({start:ht(A),duration:ht(Math.max(.3,ht(I)-ht(A))),line:v,preset:b,params:{bg:m,next:m,accent:o,text:"",sub:"",...P}}),E.lines.forEach((C,z)=>{const N=Math.max(A+.05,C.beats[0].start-.08),F=z<E.lines.length-1?E.lines[z+1].beats[0].start-.04:I-.02;if(F-N<=.3)return;const K=C.text.split(" ").filter(Boolean),_=K.length<2?K.length:K.length>=4&&(y||K.at(-1).length<=3)?2:1,q=Gg(C);s.push({start:ht(N),duration:ht(F-N),preset:e.caption,params:{text:K.slice(0,K.length-_).join(" ").slice(0,80),sub:Rl(K.slice(K.length-_).join(" ")).slice(0,40),marks:Kg(q,N),panel:(v+z)%3===2,position:"top",accent:o}})}),v&&h.push({at:ht(Math.max(0,A-.15)),id:"whoosh-airy"})}),{beats:c,els:s,sfx:h}}function y3(t,e,{accent:o,tail:r}){const n=[];let a=null;for(const c of t)(!a||a.lines.length>=3||Dg.test(a.lines.at(-1).text))&&(a={lines:[]},n.push(a)),a.lines.push(c);const i=[],l=[],p=e.palette.dark;return n.forEach((c,s)=>{const h=c.lines[0].beats[0].start,f=s?h-.08:Math.max(0,h-.12),m=n[s+1],y=m?m.lines[0].beats[0].start-.08:c.lines.at(-1).beats.at(-1).end+r,$=c.lines.map((E,v)=>{const S=E.text.split(" ").filter(Boolean),k=c.lines.length===1;let b=new Set(S.map((A,I)=>/\d/.test(A)?I:-1).filter(A=>A>=0));if(!b.size&&(v%2===1||k)){const A=k?S.length-1:S.reduce((I,P,C)=>Rl(P).length>Rl(S[I]).length?C:I,0);b.add(A),!k&&S.length>=3&&A+1<S.length&&Rl(S[A+1]).length>=4&&b.add(A+1)}return S.map((A,I)=>b.has(I)?`*${A}*`:A).join(" ").replace(/\* \*/g," ")}),x=c.lines.flatMap(Gg);i.push({start:ht(f),duration:ht(Math.max(.3,ht(y)-ht(f))),line:s,preset:e.caption,params:{text:$.join("|").slice(0,240),marks:Kg(x,f),bg:p,accent:o,position:"center"}}),s&&l.push({at:ht(Math.max(0,f-.1)),id:"whoosh-short-up"})}),{beats:i,els:[],sfx:l}}function b3(t,{palette:e={},io:o=.16,portrait:r=!0,seed:n=1,tail:a=.7,orb:i=!0,industry:l=null,genre:p="punch",known:c=null}={}){const s=La[p]||La.punch;if(s.palette&&(e={...s.palette,...e.accent&&!["luxury","neon","glass"].includes(p)?{accent:e.accent}:{}}),s.orb===!1&&(i=!1),(t||[]).length>Ta.words)throw Error(Bg(t.length));const h=(t||[]).length>120,f=Ux(t,{portrait:r,dense:h,wide:s.kind==="scenes"});if(!f.length)throw Error("Kinetic Edit cần lời thoại có mốc thời gian từng chữ hoặc một đoạn chữ");if(s.plan)return{...(s.plan==="glass"?g3:y3)(f,s,{accent:e.accent,tail:a,known:c}),orbs:[],texture:[],carriers:[],lines:f.length,genre:p};if(s.kind==="scenes")return{...d3(f,s,{accent:e.accent||s.colors[1],seed:n,tail:a,known:c}),orbs:[],texture:[],carriers:[],lines:f.length,genre:p};const m=e.dark||"#0b0b0d",y=e.light||"#f4f4f1",$=e.accent||"#e8141c",x=j=>{const O=parseInt(j.slice(1),16),L=O>>16&255,B=O>>8&255,X=O&255;return L*.299+B*.587+X*.114>150?"#111111":"#ffffff"};let E=null;const v=f.map((j,O)=>{let B=(/[!?]$/.test(j.text)||/\d/.test(j.text))&&E!==$?$:(O+n)%2?y:m;return B===E&&(B=B===m?y:m),E=B,B}),S=[],k=[],b=f.flatMap((j,O)=>j.beats.map((L,B)=>({...L,li:O,bi:B,line:j}))),A=/[ăâđêôơưàáạảãằắặẳẵầấậẩẫèéẹẻẽềếệểễìíịỉĩòóọỏõồốộổỗờớợởỡùúụủũừứựửữỳýỵỷỹ]/i.test(f.map(j=>j.text).join(" "));let I=null;const P=f.map(j=>j.text).join(" "),C=jg(P),z=[...new Set([...C.industries,...Ng(P),...l&&l!=="general"?[l]:[]])],N=new Set;let F=null;const K=[],_=f.map((j,O)=>{const L=(j.beats.at(-1).end??j.beats.at(-1).start)-j.beats[0].start;if(L<.8)return I=null,null;let B=Vx(j.text,{vi:A,prev:I,last:j===f.at(-1)});if(B?.el==="chart"&&(B=null),!B&&I!=="photo"){const X=Xk(j.text,{exclude:K});X&&(K.push(X.id),B={el:"photo",preset:"kin-el2",label:A?X.vi:X.en,photo:X.id,glyph:Ii(j.text)||"sparkle"})}if(!B&&L>=.8&&I!=="library"){const X=et=>Gx(j.text,{industries:z,dark:et,used:N,pack:F,accent:v[O]===$?"#ffffff":$});let Q=X(v[O]!==y);if(v[O]===y){const et=X(!0);et&&(!Q||z.some(lt=>Fl().find(Y=>Y.id===et.preset)?.industries.includes(lt))&&!z.some(lt=>Fl().find(Y=>Y.id===Q.preset)?.industries.includes(lt)))&&(Q=et,v[O]=m)}Q&&(N.add(Q.preset),F=F??Q.pack,B={el:"library",...Q})}if(!B&&Fg(j.text)==="number"&&I!=="chart"&&(B={el:"chart",preset:"kin-el2",label:A?"Kết quả":"Results"}),!B){const X=Kx(j.text,A);X&&X.glyph!==I&&(B=X)}return I=B?.el==="icon"?B.glyph:B?.el??null,B}),q=f.map(()=>null);if(s.interlude&&c){const j=Yx.test(P),O=z.some(B=>["ai","tech","gaming","saas","data"].includes(B));let L=0;f.forEach((B,X)=>{const Q=(B.beats.at(-1).end??B.beats.at(-1).start)-B.beats[0].start;if(!(X>0&&X<f.length-1&&X%3===2&&Q>=1&&!q[X-1]))return;const et=j?"cine":O?L%2?"lumen":"pulse":["pulse","cine","lumen"][L%3];let lt=(et==="pulse"?vu:et==="lumen"?_g:cc.map(bt=>bt[1])).filter(bt=>c(bt));if(lt.length||(lt=vu.filter(bt=>c(bt))),!lt.length)return;const Y=et==="cine"?cc.find(([bt,tt])=>bt.test(B.text)&&c(tt))?.[1]:null,dt=Y??lt[(L*5+n)%lt.length];q[X]={preset:dt,caption:dt.startsWith("cine-")?"cine-caption":dt.startsWith("lumen-")&&c("lumen-caption")?"lumen-caption":"pulse-word"},_[X]=null,L++})}let U=null;const rt=f.map((j,O)=>{const L=/[!?]$/.test(j.text)||/\d/.test(j.text);let B=(s.looks||zx).filter(Q=>Q!==U&&(v[O]!==y||!Nx.includes(Q)));L&&(B=B.filter(Q=>Lx.includes(Q)));const X=B[(O+n)%B.length];return U=X,X}),ot=s.joins||jx,G=j=>ot[(j-1+n)%ot.length],J=(j,O)=>`${O.n}|${O.k}|${_[j]?1:0}|${f[j].text}`;let Z=!1,at=0,D=0,H=0;const ut=z.some(j=>["ai","tech","gaming","saas","data"].includes(j)),gt=f.map((j,O)=>{if(!O)return null;if(q[O]||q[O-1])return Z=!0,{mode:"scene"};const L=f[O-1],B=J(O-1,L.beats.at(-1)),X=J(O,j.beats[0]),Q=/[!?]$/.test(L.text),et=(Lg[p]||[]).filter(tt=>!c||c(tt)),lt=[...Ox,...ut?Px:[],...et,...et],Y=()=>({mode:"lib",preset:lt[(at+++n)%lt.length]}),dt=_[O]&&!_[O].library?{mode:"cover",a:`word:${B}`,b:"panel"}:_[O-1]&&!_[O-1].library?{mode:"cover",a:`dot:${_[O-1].el}`,b:`word:${X}`}:Q?{mode:"cover",a:`letter:${B}`,b:`word:${X}`}:null;let bt=null;if(_[O]?.library||_[O-1]?.library)bt=H++%2?Y():{mode:"cover",a:`word:${B}`,b:_[O]?.library?"none":`word:${X}`};else{const tt=["carrier","push","lib","line"][D++%4];Z?bt=!h&&(tt==="line"||tt==="carrier")?{mode:"line",a:`word:${B}`,b:`word:${X}`}:null:tt==="carrier"?bt=dt??Y():tt==="lib"?bt=Y():tt==="line"&&!h&&(bt={mode:"line",a:`word:${B}`,b:`word:${X}`})}return Z=bt?.mode==="cover"||bt?.mode==="lib",bt}),xt=j=>["cover","lib","scene"].includes(gt[j]?.mode);b.forEach((j,O)=>{if(q[j.li])return;const L=b[O+1],B=j.bi===0,X=O===0?"zoom":B?xt(j.li)?"cut":G(j.li):"build",Q=L?L.bi===0?xt(L.li)?"cut":G(L.li):"cut":"zoom",et=O===0?Math.max(0,j.start-.12):B&&!xt(j.li)?j.start-o/2:j.start,lt=L?L.bi===0&&!xt(L.li)?L.start+o/2:L.start:j.end+a,Y=v[j.li],dt=rt[j.li];S.push({start:ht(et),duration:ht(Math.max(.1,lt-et)),line:j.li,params:{...s.style?{style:s.style}:{},text:j.line.text,n:j.n,k:j.k,bg:Y+":"+(Y===y?"dust":Y===$?"glow":j.li%2?"dots":"glow")+(_[j.li]?":top":""),look:dt,color:x(Y),accent:Y===$?x(Y)==="#ffffff"?"#111111":"#ffffff":$,in:X,out:Q,io:o,hit:B}}),B&&O>0&&(xt(j.li)||!h&&j.li%2===0)?k.push({at:ht(Math.max(0,j.start-(xt(j.li)?.3:o/2+.04))),id:xt(j.li)?"whoosh-cinematic":Tx[X]||"swoosh"}):B&&O===0&&k.push({at:ht(Math.max(0,et)),id:"impact"})});{const j=[];for(const O of S){const L=j.at(-1);L&&L.line===O.line&&O.params.in==="build"?(L.marks.push([+(O.start-L.start).toFixed(3),O.params.n,O.params.k]),L.duration=ht(O.start+O.duration-L.start),L.params.out=O.params.out):j.push({...O,params:{...O.params},marks:[[0,O.params.n,O.params.k]]})}S.length=0;for(const O of j){const{marks:L,...B}=O;S.push({...B,params:{...B.params,n:L.length>1?L.map(X=>X.join(":")).join("|").slice(0,300):L[0][1],k:L[0][2]}})}}const u=[];f.forEach((j,O)=>{const L=q[O];if(!L)return;const B=j.beats[0].start,X=f[O+1]?.beats[0].start??j.beats.at(-1).end+a;S.push({start:ht(B),duration:ht(X-B),line:O,preset:L.preset,params:{bg:v[O-1]??m,next:v[O+1]??m,fg:$,text:""}}),X-B>.8&&u.push({start:ht(B+.25),duration:ht(X-B-.55),preset:L.caption,params:{text:j.text.slice(0,120),position:"lower"}}),k.push({at:ht(Math.max(0,B-.05)),id:"whoosh-cinematic"})});const st=[];if(i&&S.length){const j=S[0].start,O=S.at(-1).start+S.at(-1).duration,L=(X,Q)=>_[X]&&!_[X].library?[...Rx(_[X].el,r),0]:[...Wx[Q%4],-1],B=f.map((X,Q)=>({li:Q,at:X.beats[0].start+(Q?.3:0)})).filter(X=>X.li);for(let X=j;X<O-.05;X+=19){const Q=Math.min(O,X+19),et=[...f.keys()].filter(Y=>f[Y].beats[0].start<=X+.2).at(-1)??0,lt=[[0,...L(et,st.length*3)]];B.filter(Y=>Y.at>X+.2&&Y.at<Q-.05).forEach((Y,dt)=>lt.push([+(Y.at-X).toFixed(2),...L(Y.li,st.length*3+dt+1)])),st.push({start:ht(X),duration:ht(Q-X),params:{pts:lt.slice(0,20).map(Y=>Y.map(dt=>+(+dt).toFixed(2)).join(",")).join("|"),accent:$}})}}const V=[...u];f.forEach((j,O)=>{const L=_[O];if(!L)return;const B=S.filter(et=>et.line===O),X=B[0],Q=B.at(-1);if(X){if(L.library){V.push({start:X.start,duration:ht(Q.start+Q.duration-X.start),preset:L.preset,params:L.params,library:!0});return}V.push({start:X.start,duration:ht(Q.start+Q.duration-X.start),preset:L.preset,params:{el:L.el,label:L.label,...L.glyph?{glyph:L.glyph}:{},...L.photo?{photo:L.photo}:{},in:X.params.in,out:Q.params.out,io:o,dark:X.params.color==="#ffffff",accent:X.params.accent}})}});const d=[];let w=0;gt.forEach((j,O)=>{if(!j||j.mode==="scene")return;const L=f[O].beats[0].start,B=S.filter(et=>et.line===O-1).at(-1)?.params.accent??$;if(j.mode==="lib"){const et=Math.min(.9,(Fl().find(Y=>Y.id===j.preset)?.dur??1)*.8);let lt={};try{lt=Ai(j.preset,{color:$}).params}catch{}d.push({start:ht(Math.max(0,L-et/2)),duration:ht(et),preset:j.preset,params:lt});return}const X=j.mode==="cover"?L-.24:L-o/2-.1,Q=j.mode==="cover"?.46:o+.45;d.push({start:ht(Math.max(0,X)),duration:ht(Q),preset:"kin-carry",params:{mode:j.mode,a:j.a.slice(0,290),b:j.b.slice(0,290),fill:B,...j.mode==="cover"?{shape:tf[w++%tf.length]}:{}}})});const T=[];if(S.length){const j=S[0].start,O=S.at(-1).start+S.at(-1).duration;for(let L=j;L<O-.05;L+=19)T.push({start:ht(L),duration:ht(Math.min(O,L+19)-L),params:{amount:.5}})}return{beats:S,orbs:st,sfx:k,texture:T,els:V,carriers:d,lines:f.length,genre:p}}const w3={motion:"Chuyển động",pop:"Nhấn & pop",alert:"Thông báo",impact:"Cao trào",fx:"Hiệu ứng",ui:"Giao diện & app",music:"Nhạc hiệu ngắn",fun:"Vui nhộn & game"},k3=[{id:"whoosh-up",name:"Whoosh lên",category:"motion",duration:.7,url:"/sfx/whoosh-up.mp3",tags:["chuyển cảnh","trượt vào"]},{id:"whoosh-down",name:"Whoosh xuống",category:"motion",duration:.7,url:"/sfx/whoosh-down.mp3",tags:["trượt ra","biến mất"]},{id:"swoosh",name:"Swoosh nhanh",category:"motion",duration:.32,url:"/sfx/swoosh.mp3",tags:["chuyển cảnh","nhanh"]},{id:"swipe",name:"Swipe",category:"motion",duration:.26,url:"/sfx/swipe.mp3",tags:["vuốt","chuyển slide"]},{id:"zoom-whoosh",name:"Whoosh zoom",category:"motion",duration:.5,url:"/sfx/zoom-whoosh.mp3",tags:["zoom","phóng to"]},{id:"pop",name:"Pop",category:"pop",duration:.14,url:"/sfx/pop.mp3",tags:["chữ hiện","nhấn"]},{id:"bubble-pop",name:"Bong bóng",category:"pop",duration:.18,url:"/sfx/bubble-pop.mp3",tags:["bong bóng","vui"]},{id:"click",name:"Click",category:"pop",duration:.05,url:"/sfx/click.mp3",tags:["bấm","nút"]},{id:"tick",name:"Tick",category:"pop",duration:.04,url:"/sfx/tick.mp3",tags:["đồng hồ","đếm"]},{id:"punch",name:"Punch thump",category:"pop",duration:.3,url:"/sfx/punch.mp3",tags:["zoom nhấn","đấm"]},{id:"ding",name:"Ding",category:"alert",duration:1.1,url:"/sfx/ding.mp3",tags:["chuông","đúng"]},{id:"chime",name:"Chime",category:"alert",duration:1.3,url:"/sfx/chime.mp3",tags:["chuông gió","nhẹ nhàng"]},{id:"notification",name:"Thông báo",category:"alert",duration:.43,url:"/sfx/notification.mp3",tags:["tin nhắn","app"]},{id:"success",name:"Thành công",category:"alert",duration:1.08,url:"/sfx/success.mp3",tags:["hoàn thành","đúng"]},{id:"ka-ching",name:"Ka-ching",category:"alert",duration:1.34,url:"/sfx/ka-ching.mp3",tags:["tiền","doanh thu","bán hàng"]},{id:"riser-1s",name:"Riser 1 giây",category:"impact",duration:1,url:"/sfx/riser-1s.mp3",tags:["dồn nhịp","build-up"]},{id:"riser-2s",name:"Riser 2 giây",category:"impact",duration:2,url:"/sfx/riser-2s.mp3",tags:["dồn nhịp","build-up","drop"]},{id:"impact",name:"Impact",category:"impact",duration:1,url:"/sfx/impact.mp3",tags:["cú đập","trailer"]},{id:"bass-drop",name:"Bass drop",category:"impact",duration:1.3,url:"/sfx/bass-drop.mp3",tags:["bass","drop"]},{id:"glitch",name:"Glitch",category:"fx",duration:.4,url:"/sfx/glitch.mp3",tags:["lỗi","digital","giật"]},{id:"shutter",name:"Chụp ảnh",category:"fx",duration:.2,url:"/sfx/shutter.mp3",tags:["camera","chụp"]},{id:"typing",name:"Gõ phím",category:"fx",duration:.63,url:"/sfx/typing.mp3",tags:["bàn phím","gõ chữ"]},{id:"sparkle",name:"Lấp lánh",category:"fx",duration:.92,url:"/sfx/sparkle.mp3",tags:["sáng","magic","nổi bật"]},{id:"pin-stick",name:"Ghim giấy",category:"pop",duration:.16,url:"/sfx/pin-stick.mp3",tags:["ghim","thẻ","bảng"]},{id:"marker-circle",name:"Bút dạ khoanh",category:"fx",duration:.6,url:"/sfx/marker-circle.mp3",tags:["khoanh tròn","bút","vẽ tay"]},{id:"paper-slide",name:"Giấy trượt",category:"motion",duration:.38,url:"/sfx/paper-slide.mp3",tags:["thẻ","giấy","trượt vào"]},{id:"coin-clink",name:"Xu leng keng",category:"alert",duration:.71,url:"/sfx/coin-clink.mp3",tags:["tiền xu","tiền","doanh thu"]},{id:"neon-buzz",name:"Đèn neon bật",category:"fx",duration:.9,url:"/sfx/neon-buzz.mp3",tags:["neon","đèn","bật sáng"]},{id:"counter-roll",name:"Số chạy",category:"pop",duration:1.35,url:"/sfx/counter-roll.mp3",tags:["đếm số","tăng","con số"]},{id:"wheel-spin",name:"Vòng quay",category:"fx",duration:2.34,url:"/sfx/wheel-spin.mp3",tags:["vòng quay","may mắn","bốc thăm"]},{id:"drill",name:"Máy khoan",category:"fx",duration:1.1,url:"/sfx/drill.mp3",tags:["khoan","máy","công cụ"]},{id:"ui-tap",name:"Chạm nút",category:"ui",duration:.04,url:"/sfx/ui-tap.mp3",tags:["chạm","nút","app"]},{id:"ui-tap-soft",name:"Chạm nhẹ",category:"ui",duration:.05,url:"/sfx/ui-tap-soft.mp3",tags:["chạm","nhẹ","app"]},{id:"ui-toggle-on",name:"Bật công tắc",category:"ui",duration:.14,url:"/sfx/ui-toggle-on.mp3",tags:["bật","công tắc","toggle"]},{id:"ui-toggle-off",name:"Tắt công tắc",category:"ui",duration:.14,url:"/sfx/ui-toggle-off.mp3",tags:["tắt","công tắc","toggle"]},{id:"ui-error",name:"Báo lỗi",category:"ui",duration:.3,url:"/sfx/ui-error.mp3",tags:["lỗi","sai","cảnh báo"]},{id:"ui-success-soft",name:"Hoàn tất nhẹ",category:"ui",duration:.68,url:"/sfx/ui-success-soft.mp3",tags:["xong","đúng","nhẹ nhàng"]},{id:"ui-message-in",name:"Tin nhắn đến",category:"ui",duration:.46,url:"/sfx/ui-message-in.mp3",tags:["tin nhắn","chat","nhận"]},{id:"ui-message-out",name:"Tin nhắn gửi",category:"ui",duration:.18,url:"/sfx/ui-message-out.mp3",tags:["tin nhắn","gửi","chat"]},{id:"ui-like",name:"Thả tim",category:"ui",duration:.38,url:"/sfx/ui-like.mp3",tags:["tim","thích","like"]},{id:"ui-unlock",name:"Mở khoá",category:"ui",duration:.49,url:"/sfx/ui-unlock.mp3",tags:["mở khoá","unlock","mật khẩu"]},{id:"ui-lock",name:"Khoá lại",category:"ui",duration:.09,url:"/sfx/ui-lock.mp3",tags:["khoá","bảo mật","đóng"]},{id:"ui-delete",name:"Xoá bỏ",category:"ui",duration:.3,url:"/sfx/ui-delete.mp3",tags:["xoá","thùng rác","huỷ"]},{id:"ui-focus",name:"Bíp lấy nét",category:"ui",duration:.09,url:"/sfx/ui-focus.mp3",tags:["camera","lấy nét","chụp"]},{id:"ui-scroll-tick",name:"Cuộn trang",category:"ui",duration:.17,url:"/sfx/ui-scroll-tick.mp3",tags:["cuộn","lướt","danh sách"]},{id:"ui-key-click",name:"Phím cơ",category:"ui",duration:.06,url:"/sfx/ui-key-click.mp3",tags:["bàn phím","phím","gõ"]},{id:"ui-hover",name:"Rê chuột",category:"ui",duration:.08,url:"/sfx/ui-hover.mp3",tags:["rê chuột","hover","nhẹ"]},{id:"ui-open",name:"Mở cửa sổ",category:"ui",duration:.25,url:"/sfx/ui-open.mp3",tags:["mở","menu","popup"]},{id:"ui-close",name:"Đóng cửa sổ",category:"ui",duration:.25,url:"/sfx/ui-close.mp3",tags:["đóng","menu","popup"]},{id:"ui-download-done",name:"Tải xong",category:"ui",duration:.49,url:"/sfx/ui-download-done.mp3",tags:["tải xuống","xong","hoàn thành"]},{id:"ui-notify-soft",name:"Báo nhẹ",category:"ui",duration:.82,url:"/sfx/ui-notify-soft.mp3",tags:["thông báo","nhẹ","app"]},{id:"pop-high",name:"Pop cao",category:"pop",duration:.1,url:"/sfx/pop-high.mp3",tags:["pop","cao","chữ hiện"]},{id:"pop-low",name:"Pop trầm",category:"pop",duration:.18,url:"/sfx/pop-low.mp3",tags:["pop","trầm","nhấn"]},{id:"pop-cork",name:"Bật nút chai",category:"pop",duration:.14,url:"/sfx/pop-cork.mp3",tags:["nút chai","ăn mừng","bật"]},{id:"pop-double",name:"Pop đôi",category:"pop",duration:.19,url:"/sfx/pop-double.mp3",tags:["pop","hai lần","vui"]},{id:"bubble-rise",name:"Bong bóng nổi",category:"pop",duration:.45,url:"/sfx/bubble-rise.mp3",tags:["bong bóng","nước","vui"]},{id:"pluck-soft",name:"Gảy dây nhẹ",category:"pop",duration:.6,url:"/sfx/pluck-soft.mp3",tags:["gảy","dây đàn","nhẹ"]},{id:"finger-snap",name:"Búng tay",category:"pop",duration:.05,url:"/sfx/finger-snap.mp3",tags:["búng tay","nhịp","nhấn"]},{id:"tap-wood",name:"Gõ gỗ",category:"pop",duration:.25,url:"/sfx/tap-wood.mp3",tags:["gỗ","gõ","nhịp"]},{id:"tap-glass",name:"Gõ thuỷ tinh",category:"pop",duration:.5,url:"/sfx/tap-glass.mp3",tags:["thuỷ tinh","ly","leng keng"]},{id:"tap-metal",name:"Gõ kim loại",category:"pop",duration:.6,url:"/sfx/tap-metal.mp3",tags:["kim loại","gõ","vang"]},{id:"knock-door",name:"Gõ cửa",category:"pop",duration:.52,url:"/sfx/knock-door.mp3",tags:["gõ cửa","cửa","ai đó"]},{id:"clap-single",name:"Vỗ tay một cái",category:"pop",duration:.15,url:"/sfx/clap-single.mp3",tags:["vỗ tay","nhịp","một"]},{id:"whoosh-short-up",name:"Vút lên ngắn",category:"motion",duration:.35,url:"/sfx/whoosh-short-up.mp3",tags:["whoosh","lên","nhanh"]},{id:"whoosh-short-down",name:"Vút xuống ngắn",category:"motion",duration:.35,url:"/sfx/whoosh-short-down.mp3",tags:["whoosh","xuống","nhanh"]},{id:"whoosh-heavy",name:"Whoosh nặng",category:"motion",duration:.9,url:"/sfx/whoosh-heavy.mp3",tags:["whoosh","nặng","điện ảnh"]},{id:"whoosh-airy",name:"Whoosh gió nhẹ",category:"motion",duration:.8,url:"/sfx/whoosh-airy.mp3",tags:["whoosh","gió","nhẹ nhàng"]},{id:"whoosh-double",name:"Whoosh đôi",category:"motion",duration:.47,url:"/sfx/whoosh-double.mp3",tags:["whoosh","hai lần","chuyển cảnh"]},{id:"sword-swish",name:"Vung kiếm",category:"motion",duration:.5,url:"/sfx/sword-swish.mp3",tags:["kiếm","chém","vung"]},{id:"spin-whoosh",name:"Xoáy tròn",category:"motion",duration:.9,url:"/sfx/spin-whoosh.mp3",tags:["xoay","xoáy","vòng"]},{id:"zip-up",name:"Kéo khoá lên",category:"motion",duration:.3,url:"/sfx/zip-up.mp3",tags:["khoá kéo","kéo","lên"]},{id:"zip-down",name:"Kéo khoá xuống",category:"motion",duration:.3,url:"/sfx/zip-down.mp3",tags:["khoá kéo","kéo","xuống"]},{id:"slide-in",name:"Trượt vào",category:"motion",duration:.4,url:"/sfx/slide-in.mp3",tags:["trượt","vào","thẻ"]},{id:"slide-out",name:"Trượt ra",category:"motion",duration:.4,url:"/sfx/slide-out.mp3",tags:["trượt","ra","thẻ"]},{id:"card-flip",name:"Lật thẻ",category:"motion",duration:.12,url:"/sfx/card-flip.mp3",tags:["lật","thẻ","bài"]},{id:"page-turn",name:"Lật trang",category:"motion",duration:.45,url:"/sfx/page-turn.mp3",tags:["giấy","lật trang","sách"]},{id:"fly-by",name:"Vụt qua",category:"motion",duration:1.2,url:"/sfx/fly-by.mp3",tags:["bay qua","vụt","tốc độ"]},{id:"hit-soft",name:"Đập nhẹ",category:"impact",duration:.4,url:"/sfx/hit-soft.mp3",tags:["đập","nhẹ","nhấn"]},{id:"hit-deep",name:"Đập sâu",category:"impact",duration:.9,url:"/sfx/hit-deep.mp3",tags:["đập","trầm","điện ảnh"]},{id:"hit-snare",name:"Trống snare",category:"impact",duration:.25,url:"/sfx/hit-snare.mp3",tags:["trống","snare","nhịp"]},{id:"hit-clap-stack",name:"Vỗ tay dày",category:"impact",duration:.33,url:"/sfx/hit-clap-stack.mp3",tags:["vỗ tay","nhịp","dày"]},{id:"boom-far",name:"Nổ xa",category:"impact",duration:1.5,url:"/sfx/boom-far.mp3",tags:["nổ","xa","pháo"]},{id:"thud-box",name:"Thùng rơi",category:"impact",duration:.35,url:"/sfx/thud-box.mp3",tags:["rơi","thùng","đồ vật"]},{id:"slam",name:"Đóng sầm",category:"impact",duration:.5,url:"/sfx/slam.mp3",tags:["sầm","đóng","mạnh"]},{id:"stomp",name:"Dậm chân",category:"impact",duration:.3,url:"/sfx/stomp.mp3",tags:["dậm","bước","nặng"]},{id:"metal-clang",name:"Kim loại va",category:"impact",duration:1.2,url:"/sfx/metal-clang.mp3",tags:["kim loại","va chạm","vang"]},{id:"rim-shot",name:"Gõ vành trống",category:"impact",duration:.12,url:"/sfx/rim-shot.mp3",tags:["trống","vành","nhịp"]},{id:"kick-808",name:"Kick 808",category:"impact",duration:1,url:"/sfx/kick-808.mp3",tags:["kick","808","bass"]},{id:"hit-cinematic",name:"Đập điện ảnh",category:"impact",duration:.8,url:"/sfx/hit-cinematic.mp3",tags:["trailer","đập","điện ảnh"]},{id:"riser-half",name:"Riser nửa giây",category:"impact",duration:.5,url:"/sfx/riser-half.mp3",tags:["dồn nhịp","ngắn","build-up"]},{id:"riser-tension",name:"Riser căng thẳng",category:"impact",duration:2.2,url:"/sfx/riser-tension.mp3",tags:["căng thẳng","dồn nhịp","hồi hộp"]},{id:"downlifter-1s",name:"Hạ nhịp 1 giây",category:"impact",duration:1,url:"/sfx/downlifter-1s.mp3",tags:["hạ nhịp","sau drop","chuyển cảnh"]},{id:"downlifter-2s",name:"Hạ nhịp 2 giây",category:"impact",duration:2,url:"/sfx/downlifter-2s.mp3",tags:["hạ nhịp","sau drop","dài"]},{id:"reverse-cymbal",name:"Cymbal ngược",category:"impact",duration:1.5,url:"/sfx/reverse-cymbal.mp3",tags:["cymbal","ngược","trước drop"]},{id:"sweep-up",name:"Âm quét lên",category:"impact",duration:1,url:"/sfx/sweep-up.mp3",tags:["quét","lên","chuyển cảnh"]},{id:"sweep-down",name:"Âm quét xuống",category:"impact",duration:1,url:"/sfx/sweep-down.mp3",tags:["quét","xuống","chuyển cảnh"]},{id:"swell-pad",name:"Pad dâng",category:"impact",duration:2,url:"/sfx/swell-pad.mp3",tags:["pad","dâng","cảm xúc"]},{id:"tape-stop",name:"Băng dừng",category:"impact",duration:1,url:"/sfx/tape-stop.mp3",tags:["dừng","tắt nhạc","tape stop"]},{id:"rewind",name:"Tua ngược",category:"impact",duration:.8,url:"/sfx/rewind.mp3",tags:["tua lại","ngược","quay lại"]},{id:"sting-win",name:"Nhạc chiến thắng",category:"music",duration:1.26,url:"/sfx/sting-win.mp3",tags:["chiến thắng","thành công","vui"]},{id:"sting-fail",name:"Nhạc thất bại",category:"music",duration:1.79,url:"/sfx/sting-fail.mp3",tags:["thất bại","buồn","hụt"]},{id:"sting-mystery",name:"Nhạc bí ẩn",category:"music",duration:1.6,url:"/sfx/sting-mystery.mp3",tags:["bí ẩn","tò mò","huyền bí"]},{id:"sting-reveal",name:"Nhạc hé lộ",category:"music",duration:1.66,url:"/sfx/sting-reveal.mp3",tags:["hé lộ","bất ngờ","ra mắt"]},{id:"sting-happy",name:"Nhạc vui tươi",category:"music",duration:.89,url:"/sfx/sting-happy.mp3",tags:["vui","tươi","nhẹ nhàng"]},{id:"sting-tense",name:"Nhạc căng thẳng",category:"music",duration:1.8,url:"/sfx/sting-tense.mp3",tags:["căng thẳng","nguy hiểm","hồi hộp"]},{id:"chord-major",name:"Hợp âm trưởng",category:"music",duration:1.26,url:"/sfx/chord-major.mp3",tags:["hợp âm","vui","sáng"]},{id:"chord-minor",name:"Hợp âm thứ",category:"music",duration:1.26,url:"/sfx/chord-minor.mp3",tags:["hợp âm","buồn","trầm"]},{id:"harp-gliss",name:"Đàn hạc lướt",category:"music",duration:.99,url:"/sfx/harp-gliss.mp3",tags:["đàn hạc","mơ","phép thuật"]},{id:"xylo-up",name:"Mộc cầm đi lên",category:"music",duration:.7,url:"/sfx/xylo-up.mp3",tags:["xylophone","đi lên","vui"]},{id:"xylo-down",name:"Mộc cầm đi xuống",category:"music",duration:.7,url:"/sfx/xylo-down.mp3",tags:["xylophone","đi xuống","hụt"]},{id:"music-box",name:"Hộp nhạc",category:"music",duration:1.32,url:"/sfx/music-box.mp3",tags:["hộp nhạc","ngọt ngào","kỷ niệm"]},{id:"game-coin",name:"Ăn xu game",category:"fun",duration:.32,url:"/sfx/game-coin.mp3",tags:["game","xu","điểm"]},{id:"power-up",name:"Tăng sức mạnh",category:"fun",duration:.6,url:"/sfx/power-up.mp3",tags:["game","sức mạnh","nâng cấp"]},{id:"level-up",name:"Lên cấp",category:"fun",duration:.95,url:"/sfx/level-up.mp3",tags:["game","lên cấp","thành tích"]},{id:"jump-boing",name:"Nhảy boing",category:"fun",duration:.45,url:"/sfx/jump-boing.mp3",tags:["nhảy","lò xo","hài"]},{id:"laser-zap",name:"Tia laser",category:"fun",duration:.3,url:"/sfx/laser-zap.mp3",tags:["laser","bắn","khoa học viễn tưởng"]},{id:"laser-pew",name:"Bắn pew",category:"fun",duration:.2,url:"/sfx/laser-pew.mp3",tags:["bắn","pew","game"]},{id:"alarm-beep",name:"Chuông báo động",category:"fun",duration:.52,url:"/sfx/alarm-beep.mp3",tags:["báo động","cảnh báo","gấp"]},{id:"buzzer-wrong",name:"Còi sai",category:"fun",duration:.6,url:"/sfx/buzzer-wrong.mp3",tags:["sai","quiz","trượt"]},{id:"quiz-correct",name:"Trả lời đúng",category:"fun",duration:.52,url:"/sfx/quiz-correct.mp3",tags:["đúng","quiz","chính xác"]},{id:"slot-reel",name:"Máy quay số",category:"fun",duration:1.95,url:"/sfx/slot-reel.mp3",tags:["quay số","may mắn","casino"]},{id:"slide-whistle-up",name:"Còi trượt lên",category:"fun",duration:.7,url:"/sfx/slide-whistle-up.mp3",tags:["còi","hài","lên"]},{id:"slide-whistle-down",name:"Còi trượt xuống",category:"fun",duration:.7,url:"/sfx/slide-whistle-down.mp3",tags:["còi","hài","xuống"]},{id:"data-blip",name:"Tín hiệu dữ liệu",category:"fx",duration:.19,url:"/sfx/data-blip.mp3",tags:["dữ liệu","công nghệ","blip"]},{id:"scan-sweep",name:"Quét dữ liệu",category:"fx",duration:1.2,url:"/sfx/scan-sweep.mp3",tags:["quét","máy quét","công nghệ"]},{id:"hologram",name:"Hologram",category:"fx",duration:1.5,url:"/sfx/hologram.mp3",tags:["hologram","tương lai","công nghệ"]},{id:"robot-beep",name:"Robot nói",category:"fx",duration:.41,url:"/sfx/robot-beep.mp3",tags:["robot","máy","beep"]},{id:"glitch-short",name:"Glitch ngắn",category:"fx",duration:.2,url:"/sfx/glitch-short.mp3",tags:["glitch","lỗi","digital"]},{id:"static-burst",name:"Nhiễu sóng",category:"fx",duration:.5,url:"/sfx/static-burst.mp3",tags:["nhiễu","radio","tivi"]},{id:"power-on",name:"Bật nguồn",category:"fx",duration:1,url:"/sfx/power-on.mp3",tags:["bật nguồn","khởi động","máy"]},{id:"power-down",name:"Tắt nguồn",category:"fx",duration:1.2,url:"/sfx/power-down.mp3",tags:["tắt nguồn","tắt máy","hết pin"]}],x3={logo:"Logo & stinger",whoosh:"Whoosh & chuyển cảnh",riser:"Riser & drop",water:"Nước & chất lỏng",ambience:"Không gian nền",machine:"Máy móc & đồ vật",human:"Con người",nature:"Thiên nhiên",food:"Ẩm thực & quán",care:"Sức khoẻ & làm đẹp",learn:"Giáo dục & công nghệ",place:"Nhà, du lịch & xe",commerce:"Bán hàng & mạng xã hội"},M3=[{id:"logo-royal-strings",name:"Logo dây hoàng gia",en:"Royal strings logo",category:"logo",duration:5.04,url:"/sfx/logo-royal-strings.mp3",tags:["royal strings logo"],ai:!0},{id:"logo-water-splash",name:"Logo tia nước",en:"Water splash logo",category:"logo",duration:4.06,url:"/sfx/logo-water-splash.mp3",tags:["water splash logo"],ai:!0},{id:"logo-digital-glitch",name:"Logo kỹ thuật số",en:"Digital glitch logo",category:"logo",duration:3.05,url:"/sfx/logo-digital-glitch.mp3",tags:["digital glitch logo"],ai:!0},{id:"logo-soft-chime",name:"Logo chuông nhẹ",en:"Soft chime logo",category:"logo",duration:3.05,url:"/sfx/logo-soft-chime.mp3",tags:["soft chime logo"],ai:!0},{id:"whoosh-windy",name:"Whoosh gió",en:"Windy whoosh",category:"whoosh",duration:3.05,url:"/sfx/whoosh-windy.mp3",tags:["windy whoosh"],ai:!0},{id:"whoosh-water-low",name:"Whoosh nước trầm",en:"Low water whoosh",category:"whoosh",duration:3.05,url:"/sfx/whoosh-water-low.mp3",tags:["low water whoosh"],ai:!0},{id:"whoosh-cinematic",name:"Whoosh điện ảnh",en:"Cinematic whoosh",category:"whoosh",duration:2.06,url:"/sfx/whoosh-cinematic.mp3",tags:["cinematic whoosh"],ai:!0},{id:"whoosh-fast-swish",name:"Swish nhanh",en:"Fast swish",category:"whoosh",duration:1.06,url:"/sfx/whoosh-fast-swish.mp3",tags:["fast swish"],ai:!0},{id:"whoosh-reverse",name:"Whoosh ngược",en:"Reverse whoosh",category:"whoosh",duration:2.06,url:"/sfx/whoosh-reverse.mp3",tags:["reverse whoosh"],ai:!0},{id:"whoosh-fire",name:"Whoosh lửa",en:"Fire whoosh",category:"whoosh",duration:2.06,url:"/sfx/whoosh-fire.mp3",tags:["fire whoosh"],ai:!0},{id:"riser-tense-trailer",name:"Riser căng thẳng",en:"Tense trailer riser",category:"riser",duration:6.02,url:"/sfx/riser-tense-trailer.mp3",tags:["tense trailer riser"],ai:!0},{id:"drop-slow-bass",name:"Chậm lại & bass drop",en:"Slow-down bass drop",category:"riser",duration:4.06,url:"/sfx/drop-slow-bass.mp3",tags:["slow-down bass drop"],ai:!0},{id:"braam-cinematic",name:"Braam điện ảnh",en:"Cinematic braam",category:"riser",duration:4.03,url:"/sfx/braam-cinematic.mp3",tags:["cinematic braam"],ai:!0},{id:"impact-sub-boom",name:"Sub boom",en:"Sub boom impact",category:"riser",duration:3.05,url:"/sfx/impact-sub-boom.mp3",tags:["sub boom impact"],ai:!0},{id:"impact-metal-hit",name:"Va chạm kim loại",en:"Metal hit",category:"riser",duration:1.99,url:"/sfx/impact-metal-hit.mp3",tags:["metal hit"],ai:!0},{id:"riser-electronic",name:"Riser điện tử",en:"Electronic riser",category:"riser",duration:5.04,url:"/sfx/riser-electronic.mp3",tags:["electronic riser"],ai:!0},{id:"water-splash",name:"Tạt nước",en:"Water splash",category:"water",duration:2.06,url:"/sfx/water-splash.mp3",tags:["water splash"],ai:!0},{id:"liquid-boiling",name:"Chất lỏng sôi",en:"Liquid boiling",category:"water",duration:6.05,url:"/sfx/liquid-boiling.mp3",tags:["liquid boiling"],ai:!0},{id:"hose-spray",name:"Vòi xịt nước",en:"Hose spray",category:"water",duration:3.05,url:"/sfx/hose-spray.mp3",tags:["hose spray"],ai:!0},{id:"water-bubbles",name:"Bong bóng nước",en:"Water bubbles",category:"water",duration:4.06,url:"/sfx/water-bubbles.mp3",tags:["water bubbles"],ai:!0},{id:"water-drip",name:"Giọt nước",en:"Water drips",category:"water",duration:4.06,url:"/sfx/water-drip.mp3",tags:["water drips"],ai:!0},{id:"pour-drink",name:"Rót nước uống",en:"Pouring a drink",category:"water",duration:4.03,url:"/sfx/pour-drink.mp3",tags:["pouring a drink"],ai:!0},{id:"ambience-cyber-room",name:"Phòng dữ liệu",en:"Cyber data room",category:"ambience",duration:10.03,url:"/sfx/ambience-cyber-room.mp3",tags:["cyber data room"],ai:!0},{id:"ambience-office",name:"Văn phòng",en:"Office room tone",category:"ambience",duration:10.03,url:"/sfx/ambience-office.mp3",tags:["office room tone"],ai:!0},{id:"ambience-cafe",name:"Quán cà phê",en:"Coffee shop",category:"ambience",duration:10.03,url:"/sfx/ambience-cafe.mp3",tags:["coffee shop"],ai:!0},{id:"ambience-city-street",name:"Phố đông",en:"City street",category:"ambience",duration:10.03,url:"/sfx/ambience-city-street.mp3",tags:["city street"],ai:!0},{id:"ambience-rain",name:"Mưa",en:"Rain",category:"nature",duration:10.03,url:"/sfx/ambience-rain.mp3",tags:["rain"],ai:!0},{id:"ambience-forest",name:"Rừng & chim",en:"Forest birds",category:"nature",duration:10.03,url:"/sfx/ambience-forest.mp3",tags:["forest birds"],ai:!0},{id:"ocean-waves",name:"Sóng biển",en:"Ocean waves",category:"nature",duration:10.03,url:"/sfx/ocean-waves.mp3",tags:["ocean waves"],ai:!0},{id:"thunder",name:"Sấm",en:"Thunder",category:"nature",duration:5.04,url:"/sfx/thunder.mp3",tags:["thunder"],ai:!0},{id:"vacuum-cleaner",name:"Máy hút bụi",en:"Vacuum cleaner",category:"machine",duration:5.04,url:"/sfx/vacuum-cleaner.mp3",tags:["vacuum cleaner"],ai:!0},{id:"planer-motor",name:"Máy bào gỗ",en:"Planer motor",category:"machine",duration:6.05,url:"/sfx/planer-motor.mp3",tags:["planer motor"],ai:!0},{id:"keyboard-typing",name:"Gõ bàn phím",en:"Keyboard typing",category:"machine",duration:5.04,url:"/sfx/keyboard-typing.mp3",tags:["keyboard typing"],ai:!0},{id:"camera-shutter",name:"Chụp ảnh",en:"Camera shutter",category:"machine",duration:1.03,url:"/sfx/camera-shutter.mp3",tags:["camera shutter"],ai:!0},{id:"door-open-close",name:"Mở & đóng cửa",en:"Door open and close",category:"machine",duration:3.05,url:"/sfx/door-open-close.mp3",tags:["door open and close"],ai:!0},{id:"car-pass-by",name:"Xe chạy qua",en:"Car pass-by",category:"machine",duration:4.06,url:"/sfx/car-pass-by.mp3",tags:["car pass-by"],ai:!0},{id:"phone-vibrate",name:"Điện thoại rung",en:"Phone vibration",category:"machine",duration:2.06,url:"/sfx/phone-vibrate.mp3",tags:["phone vibration"],ai:!0},{id:"crowd-cheer",name:"Đám đông reo hò",en:"Crowd cheer",category:"human",duration:5.04,url:"/sfx/crowd-cheer.mp3",tags:["crowd cheer"],ai:!0},{id:"applause",name:"Vỗ tay",en:"Applause",category:"human",duration:5.04,url:"/sfx/applause.mp3",tags:["applause"],ai:!0},{id:"crowd-laugh",name:"Cười",en:"Audience laugh",category:"human",duration:3.05,url:"/sfx/crowd-laugh.mp3",tags:["audience laugh"],ai:!0},{id:"crowd-gasp",name:"Ồ ngạc nhiên",en:"Surprised gasp",category:"human",duration:2.06,url:"/sfx/crowd-gasp.mp3",tags:["surprised gasp"],ai:!0},{id:"footsteps",name:"Tiếng bước chân",en:"Footsteps",category:"human",duration:4.06,url:"/sfx/footsteps.mp3",tags:["footsteps"],ai:!0},{id:"heartbeat",name:"Nhịp tim",en:"Heartbeat",category:"human",duration:4.06,url:"/sfx/heartbeat.mp3",tags:["heartbeat"],ai:!0},{id:"sizzle-pan",name:"Chảo xèo",en:"Sizzling pan",category:"food",duration:4.06,url:"/sfx/sizzle-pan.mp3",tags:["sizzling pan"],ai:!0},{id:"wok-stir-fry",name:"Xào chảo lửa lớn",en:"Wok stir fry",category:"food",duration:4.06,url:"/sfx/wok-stir-fry.mp3",tags:["wok stir fry"],ai:!0},{id:"knife-chopping",name:"Thái rau",en:"Knife chopping",category:"food",duration:3.05,url:"/sfx/knife-chopping.mp3",tags:["knife chopping"],ai:!0},{id:"coffee-machine",name:"Máy pha cà phê",en:"Espresso machine",category:"food",duration:5.04,url:"/sfx/coffee-machine.mp3",tags:["espresso machine"],ai:!0},{id:"milk-frother",name:"Đánh sữa",en:"Milk frother",category:"food",duration:3.05,url:"/sfx/milk-frother.mp3",tags:["milk frother"],ai:!0},{id:"ice-cubes-glass",name:"Đá vào ly",en:"Ice into a glass",category:"food",duration:2.06,url:"/sfx/ice-cubes-glass.mp3",tags:["ice into a glass"],ai:!0},{id:"soda-open-pour",name:"Mở lon nước ngọt",en:"Soda can open",category:"food",duration:3.05,url:"/sfx/soda-open-pour.mp3",tags:["soda can open"],ai:!0},{id:"cutlery-plate",name:"Dao nĩa",en:"Cutlery on a plate",category:"food",duration:2.98,url:"/sfx/cutlery-plate.mp3",tags:["cutlery on a plate"],ai:!0},{id:"crunchy-bite",name:"Cắn giòn",en:"Crunchy bite",category:"food",duration:2.06,url:"/sfx/crunchy-bite.mp3",tags:["crunchy bite"],ai:!0},{id:"noodle-slurp",name:"Húp mì",en:"Noodle slurp",category:"food",duration:2.06,url:"/sfx/noodle-slurp.mp3",tags:["noodle slurp"],ai:!0},{id:"service-bell",name:"Chuông quầy",en:"Service bell",category:"food",duration:2.06,url:"/sfx/service-bell.mp3",tags:["service bell"],ai:!0},{id:"shop-door-chime",name:"Chuông cửa tiệm",en:"Shop door chime",category:"food",duration:2.06,url:"/sfx/shop-door-chime.mp3",tags:["shop door chime"],ai:!0},{id:"microwave-ding",name:"Lò vi sóng",en:"Microwave ding",category:"food",duration:2.06,url:"/sfx/microwave-ding.mp3",tags:["microwave ding"],ai:!0},{id:"kettle-whistle",name:"Ấm reo",en:"Kettle whistle",category:"food",duration:3.05,url:"/sfx/kettle-whistle.mp3",tags:["kettle whistle"],ai:!0},{id:"spa-water",name:"Nước spa",en:"Spa water",category:"care",duration:6.05,url:"/sfx/spa-water.mp3",tags:["spa water"],ai:!0},{id:"singing-bowl",name:"Chuông xoay thiền",en:"Singing bowl",category:"care",duration:5.04,url:"/sfx/singing-bowl.mp3",tags:["singing bowl"],ai:!0},{id:"deep-breath",name:"Hít thở sâu",en:"Deep breath",category:"care",duration:4.06,url:"/sfx/deep-breath.mp3",tags:["deep breath"],ai:!0},{id:"spray-mist",name:"Xịt khoáng",en:"Spray mist",category:"care",duration:1.01,url:"/sfx/spray-mist.mp3",tags:["spray mist"],ai:!0},{id:"lotion-pump",name:"Bơm dưỡng thể",en:"Lotion pump",category:"care",duration:.5,url:"/sfx/lotion-pump.mp3",tags:["lotion pump"],ai:!0},{id:"hair-dryer",name:"Máy sấy tóc",en:"Hair dryer",category:"care",duration:4.01,url:"/sfx/hair-dryer.mp3",tags:["hair dryer"],ai:!0},{id:"scissors-snip",name:"Kéo cắt tóc",en:"Scissors snip",category:"care",duration:2.06,url:"/sfx/scissors-snip.mp3",tags:["scissors snip"],ai:!0},{id:"gym-weights",name:"Tạ gym",en:"Gym weights",category:"care",duration:2.04,url:"/sfx/gym-weights.mp3",tags:["gym weights"],ai:!0},{id:"treadmill-run",name:"Chạy máy",en:"Treadmill run",category:"care",duration:5.04,url:"/sfx/treadmill-run.mp3",tags:["treadmill run"],ai:!0},{id:"coach-whistle",name:"Còi huấn luyện",en:"Coach whistle",category:"care",duration:.58,url:"/sfx/coach-whistle.mp3",tags:["coach whistle"],ai:!0},{id:"heart-monitor",name:"Máy đo nhịp tim",en:"Heart monitor",category:"care",duration:4.06,url:"/sfx/heart-monitor.mp3",tags:["heart monitor"],ai:!0},{id:"pill-rattle",name:"Lọ thuốc",en:"Pill bottle",category:"care",duration:1.97,url:"/sfx/pill-rattle.mp3",tags:["pill bottle"],ai:!0},{id:"pencil-writing",name:"Viết bút chì",en:"Pencil writing",category:"learn",duration:3.05,url:"/sfx/pencil-writing.mp3",tags:["pencil writing"],ai:!0},{id:"chalk-board",name:"Viết phấn",en:"Chalk on board",category:"learn",duration:3.02,url:"/sfx/chalk-board.mp3",tags:["chalk on board"],ai:!0},{id:"book-page-turn",name:"Lật sách",en:"Page turn",category:"learn",duration:2.06,url:"/sfx/book-page-turn.mp3",tags:["page turn"],ai:!0},{id:"school-bell",name:"Chuông trường",en:"School bell",category:"learn",duration:3.05,url:"/sfx/school-bell.mp3",tags:["school bell"],ai:!0},{id:"robot-beeps",name:"Robot AI",en:"Robot beeps",category:"learn",duration:2.06,url:"/sfx/robot-beeps.mp3",tags:["robot beeps"],ai:!0},{id:"digital-scan",name:"Quét kỹ thuật số",en:"Digital scan",category:"learn",duration:2.06,url:"/sfx/digital-scan.mp3",tags:["digital scan"],ai:!0},{id:"data-processing",name:"Xử lý dữ liệu",en:"Data processing",category:"learn",duration:3.05,url:"/sfx/data-processing.mp3",tags:["data processing"],ai:!0},{id:"game-level-up",name:"Lên cấp",en:"Level up",category:"learn",duration:1.99,url:"/sfx/game-level-up.mp3",tags:["level up"],ai:!0},{id:"quiz-correct-chime",name:"Trả lời đúng",en:"Correct answer",category:"learn",duration:1.06,url:"/sfx/quiz-correct-chime.mp3",tags:["correct answer"],ai:!0},{id:"quiz-wrong",name:"Trả lời sai",en:"Wrong answer",category:"learn",duration:1.06,url:"/sfx/quiz-wrong.mp3",tags:["wrong answer"],ai:!0},{id:"printer",name:"Máy in",en:"Printer",category:"learn",duration:4.06,url:"/sfx/printer.mp3",tags:["printer"],ai:!0},{id:"airplane-takeoff",name:"Máy bay cất cánh",en:"Airplane takeoff",category:"place",duration:6.05,url:"/sfx/airplane-takeoff.mp3",tags:["airplane takeoff"],ai:!0},{id:"airport-chime",name:"Chuông sân bay",en:"Airport chime",category:"place",duration:3.05,url:"/sfx/airport-chime.mp3",tags:["airport chime"],ai:!0},{id:"suitcase-roll",name:"Kéo vali",en:"Rolling suitcase",category:"place",duration:3.05,url:"/sfx/suitcase-roll.mp3",tags:["rolling suitcase"],ai:!0},{id:"car-engine-start",name:"Đề máy xe",en:"Car engine start",category:"place",duration:4.06,url:"/sfx/car-engine-start.mp3",tags:["car engine start"],ai:!0},{id:"car-lock",name:"Khoá xe",en:"Car lock",category:"place",duration:2.06,url:"/sfx/car-lock.mp3",tags:["car lock"],ai:!0},{id:"ev-accelerate",name:"Xe điện tăng tốc",en:"EV acceleration",category:"place",duration:4.06,url:"/sfx/ev-accelerate.mp3",tags:["ev acceleration"],ai:!0},{id:"motorbike-pass",name:"Xe máy chạy qua",en:"Motorbike pass-by",category:"place",duration:3.05,url:"/sfx/motorbike-pass.mp3",tags:["motorbike pass-by"],ai:!0},{id:"train-pass",name:"Tàu chạy qua",en:"Train passing",category:"place",duration:5.04,url:"/sfx/train-pass.mp3",tags:["train passing"],ai:!0},{id:"keys-unlock",name:"Mở khoá cửa",en:"Keys and unlock",category:"place",duration:2.04,url:"/sfx/keys-unlock.mp3",tags:["keys and unlock"],ai:!0},{id:"construction",name:"Công trường",en:"Construction site",category:"place",duration:5.04,url:"/sfx/construction.mp3",tags:["construction site"],ai:!0},{id:"morning-birds",name:"Chim sáng",en:"Morning birds",category:"place",duration:6.05,url:"/sfx/morning-birds.mp3",tags:["morning birds"],ai:!0},{id:"beach-seagulls",name:"Biển và hải âu",en:"Beach & seagulls",category:"place",duration:6.05,url:"/sfx/beach-seagulls.mp3",tags:["beach & seagulls"],ai:!0},{id:"cash-counting",name:"Đếm tiền",en:"Counting cash",category:"commerce",duration:3.05,url:"/sfx/cash-counting.mp3",tags:["counting cash"],ai:!0},{id:"coins-drop",name:"Rơi đồng xu",en:"Coins drop",category:"commerce",duration:2.02,url:"/sfx/coins-drop.mp3",tags:["coins drop"],ai:!0},{id:"crowd-wow",name:"Khán giả wow",en:"Audience wow",category:"commerce",duration:2.06,url:"/sfx/crowd-wow.mp3",tags:["audience wow"],ai:!0},{id:"kids-yay",name:"Trẻ em reo",en:"Kids cheer",category:"commerce",duration:2.06,url:"/sfx/kids-yay.mp3",tags:["kids cheer"],ai:!0},{id:"like-pop",name:"Thông báo like",en:"Like notification",category:"commerce",duration:1.06,url:"/sfx/like-pop.mp3",tags:["like notification"],ai:!0},{id:"typing-chat",name:"Gõ tin nhắn",en:"Chat typing",category:"commerce",duration:2.06,url:"/sfx/typing-chat.mp3",tags:["chat typing"],ai:!0}],$3={whoosh:"Whoosh & lướt",transition:"Chuyển cảnh",impact:"Va chạm điện ảnh",riser:"Riser & drop",ui:"Giao diện & app",camera:"Máy ảnh",commerce:"Tiền & mua bán",foley:"Foley đồ vật",cartoon:"Hoạt hình & meme",glitch:"Glitch số",voice:"Giọng phản ứng",ambience:"Không gian nền",nature:"Thiên nhiên",human:"Con người",food:"Ẩm thực & bếp",vehicle:"Xe cộ & đường phố",scifi:"Khoa học viễn tưởng",input:"Chuột & bàn phím",fight:"Võ thuật & đánh nhau",magic:"Phép thuật & năng lượng",trailer:"Trailer điện ảnh",suspense:"Kịch tính & hồi hộp",sport:"Thể thao & khán giả",animal:"Động vật",weather:"Thời tiết"},v3=[{id:"pro-whoosh-air-fast",name:"Woosh gió nhanh",en:"Fast air whoosh",category:"whoosh",duration:2.04,url:"/sfx/pro-whoosh-air-fast.mp3",tags:["fast air whoosh"],pro:!0},{id:"pro-whoosh-air-slow",name:"Woosh gió chậm",en:"Slow air whoosh",category:"whoosh",duration:1.99,url:"/sfx/pro-whoosh-air-slow.mp3",tags:["slow air whoosh"],pro:!0},{id:"pro-whoosh-heavy-cinematic",name:"Woosh điện ảnh nặng",en:"Heavy cinematic whoosh",category:"whoosh",duration:3.05,url:"/sfx/pro-whoosh-heavy-cinematic.mp3",tags:["heavy cinematic whoosh"],pro:!0},{id:"pro-whoosh-short-swish",name:"Swish ngắn",en:"Short swish",category:"whoosh",duration:.82,url:"/sfx/pro-whoosh-short-swish.mp3",tags:["short swish"],pro:!0},{id:"pro-whoosh-bamboo-swing",name:"Vụt gậy tre",en:"Bamboo stick swing",category:"whoosh",duration:.96,url:"/sfx/pro-whoosh-bamboo-swing.mp3",tags:["bamboo stick swing"],pro:!0},{id:"pro-whoosh-cloth-swish",name:"Phất vải",en:"Cloth swish",category:"whoosh",duration:1.03,url:"/sfx/pro-whoosh-cloth-swish.mp3",tags:["cloth swish"],pro:!0},{id:"pro-whoosh-sword-swipe",name:"Chém kiếm gió",en:"Sword swipe",category:"whoosh",duration:1.03,url:"/sfx/pro-whoosh-sword-swipe.mp3",tags:["sword swipe"],pro:!0},{id:"pro-whoosh-fire-whoosh",name:"Woosh lửa",en:"Fire whoosh",category:"whoosh",duration:1.92,url:"/sfx/pro-whoosh-fire-whoosh.mp3",tags:["fire whoosh"],pro:!0},{id:"pro-whoosh-water-whoosh",name:"Woosh nước",en:"Water whoosh",category:"whoosh",duration:2.04,url:"/sfx/pro-whoosh-water-whoosh.mp3",tags:["water whoosh"],pro:!0},{id:"pro-whoosh-metal-whoosh",name:"Woosh kim loại",en:"Metallic whoosh",category:"whoosh",duration:2.04,url:"/sfx/pro-whoosh-metal-whoosh.mp3",tags:["metallic whoosh"],pro:!0},{id:"pro-whoosh-reverse",name:"Woosh ngược",en:"Reverse whoosh",category:"whoosh",duration:2.04,url:"/sfx/pro-whoosh-reverse.mp3",tags:["reverse whoosh"],pro:!0},{id:"pro-whoosh-car-pass",name:"Xe lướt qua",en:"Car pass-by",category:"whoosh",duration:3.05,url:"/sfx/pro-whoosh-car-pass.mp3",tags:["car pass-by"],pro:!0},{id:"pro-whoosh-arrow-fly",name:"Mũi tên bay",en:"Arrow fly-by",category:"whoosh",duration:1.03,url:"/sfx/pro-whoosh-arrow-fly.mp3",tags:["arrow fly-by"],pro:!0},{id:"pro-whoosh-punch-swing",name:"Vung đấm",en:"Punch swing",category:"whoosh",duration:1.03,url:"/sfx/pro-whoosh-punch-swing.mp3",tags:["punch swing"],pro:!0},{id:"pro-whoosh-wind-gust",name:"Gió giật",en:"Wind gust",category:"whoosh",duration:3.05,url:"/sfx/pro-whoosh-wind-gust.mp3",tags:["wind gust"],pro:!0},{id:"pro-whoosh-rocket-pass",name:"Tên lửa vụt qua",en:"Rocket pass",category:"whoosh",duration:3.05,url:"/sfx/pro-whoosh-rocket-pass.mp3",tags:["rocket pass"],pro:!0},{id:"pro-whoosh-magic-sparkle",name:"Woosh lấp lánh",en:"Magic sparkle whoosh",category:"whoosh",duration:1.94,url:"/sfx/pro-whoosh-magic-sparkle.mp3",tags:["magic sparkle whoosh"],pro:!0},{id:"pro-whoosh-low-boom-whoosh",name:"Woosh trầm kèm boom",en:"Low boom whoosh",category:"whoosh",duration:3.05,url:"/sfx/pro-whoosh-low-boom-whoosh.mp3",tags:["low boom whoosh"],pro:!0},{id:"pro-whoosh-double",name:"Woosh kép",en:"Double whoosh",category:"whoosh",duration:2.02,url:"/sfx/pro-whoosh-double.mp3",tags:["double whoosh"],pro:!0},{id:"pro-whoosh-spin",name:"Woosh xoáy",en:"Spinning whoosh",category:"whoosh",duration:2.04,url:"/sfx/pro-whoosh-spin.mp3",tags:["spinning whoosh"],pro:!0},{id:"pro-whoosh-paper-fly",name:"Giấy bay vụt",en:"Paper fly-by",category:"whoosh",duration:1.03,url:"/sfx/pro-whoosh-paper-fly.mp3",tags:["paper fly-by"],pro:!0},{id:"pro-whoosh-jet-flyover",name:"Máy bay phản lực",en:"Jet flyover",category:"whoosh",duration:4.03,url:"/sfx/pro-whoosh-jet-flyover.mp3",tags:["jet flyover"],pro:!0},{id:"pro-whoosh-ghost",name:"Woosh ma mị",en:"Ghostly whoosh",category:"whoosh",duration:3.05,url:"/sfx/pro-whoosh-ghost.mp3",tags:["ghostly whoosh"],pro:!0},{id:"pro-whoosh-laser-sweep",name:"Quét laser",en:"Laser sweep whoosh",category:"whoosh",duration:2.04,url:"/sfx/pro-whoosh-laser-sweep.mp3",tags:["laser sweep whoosh"],pro:!0},{id:"pro-whoosh-bird-wings",name:"Cánh chim vỗ",en:"Bird wings flap",category:"whoosh",duration:1.73,url:"/sfx/pro-whoosh-bird-wings.mp3",tags:["bird wings flap"],pro:!0},{id:"pro-transition-glitch-swipe",name:"Lướt glitch",en:"Glitch swipe",category:"transition",duration:2.04,url:"/sfx/pro-transition-glitch-swipe.mp3",tags:["glitch swipe"],pro:!0},{id:"pro-transition-digital-zap",name:"Zap số",en:"Digital zap",category:"transition",duration:.84,url:"/sfx/pro-transition-digital-zap.mp3",tags:["digital zap"],pro:!0},{id:"pro-transition-tape-stop",name:"Băng dừng",en:"Tape stop",category:"transition",duration:2.04,url:"/sfx/pro-transition-tape-stop.mp3",tags:["tape stop"],pro:!0},{id:"pro-transition-rewind",name:"Tua ngược",en:"Rewind",category:"transition",duration:2.04,url:"/sfx/pro-transition-rewind.mp3",tags:["rewind"],pro:!0},{id:"pro-transition-zoom-in",name:"Zoom vào",en:"Zoom-in transition",category:"transition",duration:1.03,url:"/sfx/pro-transition-zoom-in.mp3",tags:["zoom-in transition"],pro:!0},{id:"pro-transition-zoom-out",name:"Zoom ra",en:"Zoom-out transition",category:"transition",duration:1.03,url:"/sfx/pro-transition-zoom-out.mp3",tags:["zoom-out transition"],pro:!0},{id:"pro-transition-flash",name:"Loé sáng",en:"Light flash",category:"transition",duration:1.37,url:"/sfx/pro-transition-flash.mp3",tags:["light flash"],pro:!0},{id:"pro-transition-page-swipe",name:"Vuốt trang",en:"Page swipe",category:"transition",duration:1.03,url:"/sfx/pro-transition-page-swipe.mp3",tags:["page swipe"],pro:!0},{id:"pro-transition-film-reel",name:"Cuộn phim",en:"Film reel",category:"transition",duration:3.05,url:"/sfx/pro-transition-film-reel.mp3",tags:["film reel"],pro:!0},{id:"pro-transition-static-burst",name:"Nhiễu TV",en:"Static burst",category:"transition",duration:1.03,url:"/sfx/pro-transition-static-burst.mp3",tags:["static burst"],pro:!0},{id:"pro-transition-swoosh-pop",name:"Swoosh + pop",en:"Swoosh pop",category:"transition",duration:.86,url:"/sfx/pro-transition-swoosh-pop.mp3",tags:["swoosh pop"],pro:!0},{id:"pro-transition-slide",name:"Trượt",en:"Slide transition",category:"transition",duration:1.01,url:"/sfx/pro-transition-slide.mp3",tags:["slide transition"],pro:!0},{id:"pro-transition-camera-whip",name:"Lia máy nhanh",en:"Whip pan",category:"transition",duration:.5,url:"/sfx/pro-transition-camera-whip.mp3",tags:["whip pan"],pro:!0},{id:"pro-transition-shutter-transition",name:"Chuyển cảnh màn trập",en:"Shutter transition",category:"transition",duration:1.03,url:"/sfx/pro-transition-shutter-transition.mp3",tags:["shutter transition"],pro:!0},{id:"pro-transition-cinematic-hit-transition",name:"Chuyển cảnh kèm hit",en:"Hit transition",category:"transition",duration:2.04,url:"/sfx/pro-transition-cinematic-hit-transition.mp3",tags:["hit transition"],pro:!0},{id:"pro-transition-vhs-switch",name:"Chuyển kênh VHS",en:"VHS switch",category:"transition",duration:1.03,url:"/sfx/pro-transition-vhs-switch.mp3",tags:["vhs switch"],pro:!0},{id:"pro-transition-pixel-dissolve",name:"Tan pixel",en:"Pixel dissolve",category:"transition",duration:2.04,url:"/sfx/pro-transition-pixel-dissolve.mp3",tags:["pixel dissolve"],pro:!0},{id:"pro-transition-portal",name:"Cổng không gian",en:"Portal opening",category:"transition",duration:2.64,url:"/sfx/pro-transition-portal.mp3",tags:["portal opening"],pro:!0},{id:"pro-transition-door-swoosh",name:"Cửa trượt sci-fi",en:"Sci-fi door",category:"transition",duration:1.92,url:"/sfx/pro-transition-door-swoosh.mp3",tags:["sci-fi door"],pro:!0},{id:"pro-transition-ink-splash",name:"Mực loang",en:"Ink splash",category:"transition",duration:1.03,url:"/sfx/pro-transition-ink-splash.mp3",tags:["ink splash"],pro:!0},{id:"pro-impact-cinematic-boom",name:"Boom điện ảnh",en:"Cinematic boom",category:"impact",duration:3.34,url:"/sfx/pro-impact-cinematic-boom.mp3",tags:["cinematic boom"],pro:!0},{id:"pro-impact-metal-crack",name:"Hit kim loại",en:"Metal impact",category:"impact",duration:3.24,url:"/sfx/pro-impact-metal-crack.mp3",tags:["metal impact"],pro:!0},{id:"pro-impact-punch",name:"Cú đấm",en:"Punch hit",category:"impact",duration:1.34,url:"/sfx/pro-impact-punch.mp3",tags:["punch hit"],pro:!0},{id:"pro-impact-body-fall",name:"Ngã xuống đất",en:"Body fall",category:"impact",duration:2.18,url:"/sfx/pro-impact-body-fall.mp3",tags:["body fall"],pro:!0},{id:"pro-impact-metal-clang",name:"Va kim loại",en:"Metal clang",category:"impact",duration:2.3,url:"/sfx/pro-impact-metal-clang.mp3",tags:["metal clang"],pro:!0},{id:"pro-impact-wood-knock",name:"Gõ gỗ mạnh",en:"Wood hit",category:"impact",duration:1.34,url:"/sfx/pro-impact-wood-knock.mp3",tags:["wood hit"],pro:!0},{id:"pro-impact-glass-break",name:"Kính vỡ",en:"Glass break",category:"impact",duration:2.21,url:"/sfx/pro-impact-glass-break.mp3",tags:["glass break"],pro:!0},{id:"pro-impact-door-slam",name:"Đóng sập cửa",en:"Door slam",category:"impact",duration:2.14,url:"/sfx/pro-impact-door-slam.mp3",tags:["door slam"],pro:!0},{id:"pro-impact-thunder",name:"Sấm rền",en:"Thunder crack",category:"impact",duration:3.96,url:"/sfx/pro-impact-thunder.mp3",tags:["thunder crack"],pro:!0},{id:"pro-impact-explosion-short",name:"Nổ ngắn",en:"Short explosion",category:"impact",duration:3.24,url:"/sfx/pro-impact-explosion-short.mp3",tags:["short explosion"],pro:!0},{id:"pro-impact-braam",name:"Braam trailer",en:"Trailer braam",category:"impact",duration:4.03,url:"/sfx/pro-impact-braam.mp3",tags:["trailer braam"],pro:!0},{id:"pro-impact-kick",name:"Trống kick",en:"Kick drum hit",category:"impact",duration:1.34,url:"/sfx/pro-impact-kick.mp3",tags:["kick drum hit"],pro:!0},{id:"pro-impact-slap",name:"Cái tát",en:"Slap",category:"impact",duration:.53,url:"/sfx/pro-impact-slap.mp3",tags:["slap"],pro:!0},{id:"pro-impact-stomp",name:"Dậm chân",en:"Stomp",category:"impact",duration:1.34,url:"/sfx/pro-impact-stomp.mp3",tags:["stomp"],pro:!0},{id:"pro-impact-bass-drop",name:"Bass drop",en:"Bass drop hit",category:"impact",duration:3.31,url:"/sfx/pro-impact-bass-drop.mp3",tags:["bass drop hit"],pro:!0},{id:"pro-impact-sword-clash",name:"Kiếm chạm nhau",en:"Sword clash",category:"impact",duration:2.23,url:"/sfx/pro-impact-sword-clash.mp3",tags:["sword clash"],pro:!0},{id:"pro-impact-heartbeat-thump",name:"Tim đập dồn",en:"Heartbeat thump",category:"impact",duration:2.26,url:"/sfx/pro-impact-heartbeat-thump.mp3",tags:["heartbeat thump"],pro:!0},{id:"pro-impact-gong",name:"Cồng",en:"Gong hit",category:"impact",duration:5.02,url:"/sfx/pro-impact-gong.mp3",tags:["gong hit"],pro:!0},{id:"pro-impact-piano-hit",name:"Phím đàn đập mạnh",en:"Piano slam",category:"impact",duration:3.34,url:"/sfx/pro-impact-piano-hit.mp3",tags:["piano slam"],pro:!0},{id:"pro-impact-rock-crash",name:"Đá đổ",en:"Rock crash",category:"impact",duration:3.34,url:"/sfx/pro-impact-rock-crash.mp3",tags:["rock crash"],pro:!0},{id:"pro-impact-car-crash",name:"Xe đâm",en:"Car crash",category:"impact",duration:2.62,url:"/sfx/pro-impact-car-crash.mp3",tags:["car crash"],pro:!0},{id:"pro-impact-stone-drop",name:"Đá rơi",en:"Stone drop",category:"impact",duration:1.34,url:"/sfx/pro-impact-stone-drop.mp3",tags:["stone drop"],pro:!0},{id:"pro-impact-bell-ding-hit",name:"Chuông đánh mạnh",en:"Bell hit",category:"impact",duration:4.34,url:"/sfx/pro-impact-bell-ding-hit.mp3",tags:["bell hit"],pro:!0},{id:"pro-impact-whip-crack",name:"Roi quất",en:"Whip crack",category:"impact",duration:1.27,url:"/sfx/pro-impact-whip-crack.mp3",tags:["whip crack"],pro:!0},{id:"pro-impact-tribal-drum",name:"Trống trận",en:"War drum hit",category:"impact",duration:2.23,url:"/sfx/pro-impact-tribal-drum.mp3",tags:["war drum hit"],pro:!0},{id:"pro-riser-reverse-cymbal",name:"Cymbal ngược",en:"Reverse cymbal",category:"riser",duration:3.38,url:"/sfx/pro-riser-reverse-cymbal.mp3",tags:["reverse cymbal"],pro:!0},{id:"pro-riser-whoosh-riser",name:"Riser woosh",en:"Whoosh riser",category:"riser",duration:4.18,url:"/sfx/pro-riser-whoosh-riser.mp3",tags:["whoosh riser"],pro:!0},{id:"pro-riser-drone-swell",name:"Drone dâng",en:"Drone swell",category:"riser",duration:5.38,url:"/sfx/pro-riser-drone-swell.mp3",tags:["drone swell"],pro:!0},{id:"pro-riser-horror-riser",name:"Riser kinh dị",en:"Horror riser",category:"riser",duration:5.16,url:"/sfx/pro-riser-horror-riser.mp3",tags:["horror riser"],pro:!0},{id:"pro-riser-energy-charge",name:"Nạp năng lượng",en:"Energy charge-up",category:"riser",duration:3.38,url:"/sfx/pro-riser-energy-charge.mp3",tags:["energy charge-up"],pro:!0},{id:"pro-riser-crowd-build",name:"Đám đông hò dần",en:"Crowd build-up",category:"riser",duration:4.32,url:"/sfx/pro-riser-crowd-build.mp3",tags:["crowd build-up"],pro:!0},{id:"pro-riser-engine-rev",name:"Rồ ga",en:"Engine rev",category:"riser",duration:3.38,url:"/sfx/pro-riser-engine-rev.mp3",tags:["engine rev"],pro:!0},{id:"pro-riser-airplane-takeoff-swell",name:"Cất cánh dâng",en:"Takeoff swell",category:"riser",duration:5.38,url:"/sfx/pro-riser-airplane-takeoff-swell.mp3",tags:["takeoff swell"],pro:!0},{id:"pro-riser-synth-2s",name:"Riser tổng hợp 2s",en:"Synth riser 2s",category:"riser",duration:2.11,url:"/sfx/pro-riser-synth-2s.mp3",tags:["synth riser 2s"],pro:!0},{id:"pro-riser-synth-3s",name:"Riser tổng hợp 3s",en:"Synth riser 3s",category:"riser",duration:2.9,url:"/sfx/pro-riser-synth-3s.mp3",tags:["synth riser 3s"],pro:!0},{id:"pro-riser-synth-4s",name:"Riser tổng hợp 4s",en:"Synth riser 4s",category:"riser",duration:3.84,url:"/sfx/pro-riser-synth-4s.mp3",tags:["synth riser 4s"],pro:!0},{id:"pro-riser-synth-6s",name:"Riser tổng hợp 6s",en:"Synth riser 6s",category:"riser",duration:5.57,url:"/sfx/pro-riser-synth-6s.mp3",tags:["synth riser 6s"],pro:!0},{id:"pro-downlifter-2s",name:"Downlifter 2s",en:"Downlifter 2s",category:"riser",duration:2.3,url:"/sfx/pro-downlifter-2s.mp3",tags:["downlifter 2s"],pro:!0},{id:"pro-downlifter-3s",name:"Downlifter 3s",en:"Downlifter 3s",category:"riser",duration:3.26,url:"/sfx/pro-downlifter-3s.mp3",tags:["downlifter 3s"],pro:!0},{id:"pro-downlifter-5s",name:"Downlifter 5s",en:"Downlifter 5s",category:"riser",duration:5.18,url:"/sfx/pro-downlifter-5s.mp3",tags:["downlifter 5s"],pro:!0},{id:"pro-noise-sweep-up-1-5s",name:"Quét nhiễu lên 1,5s",en:"Noise sweep up 1.5s",category:"riser",duration:1.7,url:"/sfx/pro-noise-sweep-up-1-5s.mp3",tags:["noise sweep up 1.5s"],pro:!0},{id:"pro-noise-sweep-up-3s",name:"Quét nhiễu lên 3s",en:"Noise sweep up 3s",category:"riser",duration:3.05,url:"/sfx/pro-noise-sweep-up-3s.mp3",tags:["noise sweep up 3s"],pro:!0},{id:"pro-sub-drop-2s",name:"Sub drop 2s",en:"Sub drop 2s",category:"riser",duration:2.38,url:"/sfx/pro-sub-drop-2s.mp3",tags:["sub drop 2s"],pro:!0},{id:"pro-sub-drop-4s",name:"Sub drop 4s",en:"Sub drop 4s",category:"riser",duration:2.9,url:"/sfx/pro-sub-drop-4s.mp3",tags:["sub drop 4s"],pro:!0},{id:"pro-camera-shutter-dslr",name:"Màn trập DSLR",en:"DSLR shutter",category:"camera",duration:.36,url:"/sfx/pro-camera-shutter-dslr.mp3",tags:["dslr shutter"],pro:!0},{id:"pro-camera-shutter-burst",name:"Chụp liên tục",en:"Burst shutter",category:"camera",duration:1.94,url:"/sfx/pro-camera-shutter-burst.mp3",tags:["burst shutter"],pro:!0},{id:"pro-camera-film-advance",name:"Lên phim",en:"Film advance",category:"camera",duration:.24,url:"/sfx/pro-camera-film-advance.mp3",tags:["film advance"],pro:!0},{id:"pro-camera-polaroid",name:"Máy ảnh lấy liền",en:"Instant camera",category:"camera",duration:2.95,url:"/sfx/pro-camera-polaroid.mp3",tags:["instant camera"],pro:!0},{id:"pro-camera-flash-charge",name:"Sạc đèn flash",en:"Flash charge",category:"camera",duration:2.02,url:"/sfx/pro-camera-flash-charge.mp3",tags:["flash charge"],pro:!0},{id:"pro-camera-zoom-motor",name:"Mô tơ zoom",en:"Lens zoom motor",category:"camera",duration:1.34,url:"/sfx/pro-camera-zoom-motor.mp3",tags:["lens zoom motor"],pro:!0},{id:"pro-camera-phone-shutter",name:"Chụp điện thoại",en:"Phone camera",category:"camera",duration:.55,url:"/sfx/pro-camera-phone-shutter.mp3",tags:["phone camera"],pro:!0},{id:"pro-camera-lens-cap",name:"Nắp ống kính",en:"Lens cap",category:"camera",duration:.62,url:"/sfx/pro-camera-lens-cap.mp3",tags:["lens cap"],pro:!0},{id:"pro-money-cha-ching",name:"Cha-ching",en:"Cha-ching",category:"commerce",duration:.77,url:"/sfx/pro-money-cha-ching.mp3",tags:["cha-ching"],pro:!0},{id:"pro-money-coins-pour",name:"Đổ xu",en:"Coins pour",category:"commerce",duration:2.04,url:"/sfx/pro-money-coins-pour.mp3",tags:["coins pour"],pro:!0},{id:"pro-money-coin-drop",name:"Rơi đồng xu",en:"Coin drop",category:"commerce",duration:.96,url:"/sfx/pro-money-coin-drop.mp3",tags:["coin drop"],pro:!0},{id:"pro-money-card-tap",name:"Quẹt thẻ",en:"Card tap payment",category:"commerce",duration:1.01,url:"/sfx/pro-money-card-tap.mp3",tags:["card tap payment"],pro:!0},{id:"pro-money-receipt",name:"In hoá đơn",en:"Receipt print",category:"commerce",duration:2.04,url:"/sfx/pro-money-receipt.mp3",tags:["receipt print"],pro:!0},{id:"pro-money-bag-rustle",name:"Túi giấy sột soạt",en:"Shopping bag",category:"commerce",duration:1.99,url:"/sfx/pro-money-bag-rustle.mp3",tags:["shopping bag"],pro:!0},{id:"pro-money-cash-count",name:"Đếm tiền",en:"Cash count",category:"commerce",duration:2.02,url:"/sfx/pro-money-cash-count.mp3",tags:["cash count"],pro:!0},{id:"pro-money-money-counter",name:"Máy đếm tiền",en:"Money counter",category:"commerce",duration:1.68,url:"/sfx/pro-money-money-counter.mp3",tags:["money counter"],pro:!0},{id:"pro-money-scanner-beep",name:"Quét mã vạch",en:"Barcode beep",category:"commerce",duration:.86,url:"/sfx/pro-money-scanner-beep.mp3",tags:["barcode beep"],pro:!0},{id:"pro-money-gift-unwrap",name:"Mở quà",en:"Gift unwrap",category:"commerce",duration:2.16,url:"/sfx/pro-money-gift-unwrap.mp3",tags:["gift unwrap"],pro:!0},{id:"pro-money-box-open",name:"Mở hộp",en:"Box opening",category:"commerce",duration:.79,url:"/sfx/pro-money-box-open.mp3",tags:["box opening"],pro:!0},{id:"pro-money-doorbell-shop",name:"Chuông cửa tiệm",en:"Shop door bell",category:"commerce",duration:.86,url:"/sfx/pro-money-doorbell-shop.mp3",tags:["shop door bell"],pro:!0},{id:"pro-foley-paper-crumple",name:"Vò giấy",en:"Paper crumple",category:"foley",duration:2.35,url:"/sfx/pro-foley-paper-crumple.mp3",tags:["paper crumple"],pro:!0},{id:"pro-foley-page-turn",name:"Lật trang sách",en:"Page turn",category:"foley",duration:1.34,url:"/sfx/pro-foley-page-turn.mp3",tags:["page turn"],pro:!0},{id:"pro-foley-tape-rip",name:"Xé băng dính",en:"Tape rip",category:"foley",duration:.6,url:"/sfx/pro-foley-tape-rip.mp3",tags:["tape rip"],pro:!0},{id:"pro-foley-marker-scribble",name:"Viết bút dạ",en:"Marker scribble",category:"foley",duration:2.35,url:"/sfx/pro-foley-marker-scribble.mp3",tags:["marker scribble"],pro:!0},{id:"pro-foley-pencil-write",name:"Viết bút chì",en:"Pencil writing",category:"foley",duration:3.31,url:"/sfx/pro-foley-pencil-write.mp3",tags:["pencil writing"],pro:!0},{id:"pro-foley-zipper",name:"Kéo khoá",en:"Zipper",category:"foley",duration:1.18,url:"/sfx/pro-foley-zipper.mp3",tags:["zipper"],pro:!0},{id:"pro-foley-bottle-open",name:"Mở nắp chai",en:"Bottle open",category:"foley",duration:2.11,url:"/sfx/pro-foley-bottle-open.mp3",tags:["bottle open"],pro:!0},{id:"pro-foley-pour-drink",name:"Rót nước",en:"Pour drink",category:"foley",duration:2.78,url:"/sfx/pro-foley-pour-drink.mp3",tags:["pour drink"],pro:!0},{id:"pro-foley-ice-cubes",name:"Đá trong ly",en:"Ice cubes",category:"foley",duration:2.35,url:"/sfx/pro-foley-ice-cubes.mp3",tags:["ice cubes"],pro:!0},{id:"pro-foley-keys",name:"Chùm chìa khoá",en:"Keys jingle",category:"foley",duration:2.11,url:"/sfx/pro-foley-keys.mp3",tags:["keys jingle"],pro:!0},{id:"pro-foley-knock",name:"Gõ cửa",en:"Door knock",category:"foley",duration:1.56,url:"/sfx/pro-foley-knock.mp3",tags:["door knock"],pro:!0},{id:"pro-foley-footsteps",name:"Bước chân",en:"Footsteps",category:"foley",duration:2.88,url:"/sfx/pro-foley-footsteps.mp3",tags:["footsteps"],pro:!0},{id:"pro-foley-finger-snap",name:"Búng tay",en:"Finger snap",category:"foley",duration:.41,url:"/sfx/pro-foley-finger-snap.mp3",tags:["finger snap"],pro:!0},{id:"pro-foley-pen-click",name:"Bấm bút",en:"Pen click",category:"foley",duration:.41,url:"/sfx/pro-foley-pen-click.mp3",tags:["pen click"],pro:!0},{id:"pro-foley-scissors",name:"Cắt kéo",en:"Scissors cut",category:"foley",duration:1.44,url:"/sfx/pro-foley-scissors.mp3",tags:["scissors cut"],pro:!0},{id:"pro-foley-book-close",name:"Gập sách",en:"Book close",category:"foley",duration:1.34,url:"/sfx/pro-foley-book-close.mp3",tags:["book close"],pro:!0},{id:"pro-foley-stamp",name:"Đóng dấu",en:"Rubber stamp",category:"foley",duration:1.34,url:"/sfx/pro-foley-stamp.mp3",tags:["rubber stamp"],pro:!0},{id:"pro-foley-sticker-peel",name:"Bóc sticker",en:"Sticker peel",category:"foley",duration:1.34,url:"/sfx/pro-foley-sticker-peel.mp3",tags:["sticker peel"],pro:!0},{id:"pro-foley-typewriter",name:"Máy đánh chữ",en:"Typewriter",category:"foley",duration:2.57,url:"/sfx/pro-foley-typewriter.mp3",tags:["typewriter"],pro:!0},{id:"pro-foley-keyboard",name:"Gõ phím",en:"Keyboard typing",category:"foley",duration:3.19,url:"/sfx/pro-foley-keyboard.mp3",tags:["keyboard typing"],pro:!0},{id:"pro-foley-mouse-click",name:"Click chuột",en:"Mouse click",category:"foley",duration:.98,url:"/sfx/pro-foley-mouse-click.mp3",tags:["mouse click"],pro:!0},{id:"pro-foley-light-switch",name:"Công tắc đèn",en:"Light switch",category:"foley",duration:.41,url:"/sfx/pro-foley-light-switch.mp3",tags:["light switch"],pro:!0},{id:"pro-foley-cup-set-down",name:"Đặt cốc xuống",en:"Cup set down",category:"foley",duration:1.25,url:"/sfx/pro-foley-cup-set-down.mp3",tags:["cup set down"],pro:!0},{id:"pro-foley-chalk",name:"Phấn bảng",en:"Chalk writing",category:"foley",duration:2.62,url:"/sfx/pro-foley-chalk.mp3",tags:["chalk writing"],pro:!0},{id:"pro-foley-velcro",name:"Xé velcro",en:"Velcro rip",category:"foley",duration:1.13,url:"/sfx/pro-foley-velcro.mp3",tags:["velcro rip"],pro:!0},{id:"pro-fun-boing",name:"Boing",en:"Boing",category:"cartoon",duration:.82,url:"/sfx/pro-fun-boing.mp3",tags:["boing"],pro:!0},{id:"pro-fun-slide-whistle-up",name:"Còi trượt lên",en:"Slide whistle up",category:"cartoon",duration:.94,url:"/sfx/pro-fun-slide-whistle-up.mp3",tags:["slide whistle up"],pro:!0},{id:"pro-fun-slide-whistle-down",name:"Còi trượt xuống",en:"Slide whistle down",category:"cartoon",duration:.1,url:"/sfx/pro-fun-slide-whistle-down.mp3",tags:["slide whistle down"],pro:!0},{id:"pro-fun-bonk",name:"Bonk",en:"Bonk",category:"cartoon",duration:.5,url:"/sfx/pro-fun-bonk.mp3",tags:["bonk"],pro:!0},{id:"pro-fun-record-scratch",name:"Xước đĩa",en:"Record scratch",category:"cartoon",duration:.7,url:"/sfx/pro-fun-record-scratch.mp3",tags:["record scratch"],pro:!0},{id:"pro-fun-crickets",name:"Dế kêu im lặng",en:"Crickets",category:"cartoon",duration:3.05,url:"/sfx/pro-fun-crickets.mp3",tags:["crickets"],pro:!0},{id:"pro-fun-wrong-buzzer",name:"Còi sai",en:"Wrong buzzer",category:"cartoon",duration:1.03,url:"/sfx/pro-fun-wrong-buzzer.mp3",tags:["wrong buzzer"],pro:!0},{id:"pro-fun-correct-ding",name:"Ding đúng",en:"Correct ding",category:"cartoon",duration:.26,url:"/sfx/pro-fun-correct-ding.mp3",tags:["correct ding"],pro:!0},{id:"pro-fun-applause-short",name:"Vỗ tay ngắn",en:"Short applause",category:"cartoon",duration:3.05,url:"/sfx/pro-fun-applause-short.mp3",tags:["short applause"],pro:!0},{id:"pro-fun-laugh-track",name:"Tiếng cười khán giả",en:"Laugh track",category:"cartoon",duration:2.88,url:"/sfx/pro-fun-laugh-track.mp3",tags:["laugh track"],pro:!0},{id:"pro-fun-cartoon-run",name:"Chạy hoạt hình",en:"Cartoon run",category:"cartoon",duration:1.87,url:"/sfx/pro-fun-cartoon-run.mp3",tags:["cartoon run"],pro:!0},{id:"pro-fun-cartoon-pop",name:"Pop hoạt hình",en:"Cartoon pop",category:"cartoon",duration:.1,url:"/sfx/pro-fun-cartoon-pop.mp3",tags:["cartoon pop"],pro:!0},{id:"pro-fun-squeak-toy",name:"Đồ chơi chút chít",en:"Squeak toy",category:"cartoon",duration:1.03,url:"/sfx/pro-fun-squeak-toy.mp3",tags:["squeak toy"],pro:!0},{id:"pro-fun-tada",name:"Ta-da",en:"Ta-da",category:"cartoon",duration:1.68,url:"/sfx/pro-fun-tada.mp3",tags:["ta-da"],pro:!0},{id:"pro-fun-dramatic-sting",name:"Nhạc giật mình",en:"Dramatic sting",category:"cartoon",duration:3.05,url:"/sfx/pro-fun-dramatic-sting.mp3",tags:["dramatic sting"],pro:!0},{id:"pro-fun-fail-trombone",name:"Kèn thất bại",en:"Fail trombone",category:"cartoon",duration:2.23,url:"/sfx/pro-fun-fail-trombone.mp3",tags:["fail trombone"],pro:!0},{id:"pro-fun-drum-roll",name:"Trống dồn",en:"Drum roll",category:"cartoon",duration:3.02,url:"/sfx/pro-fun-drum-roll.mp3",tags:["drum roll"],pro:!0},{id:"pro-fun-rimshot",name:"Ba-dum-tss",en:"Rimshot",category:"cartoon",duration:1.03,url:"/sfx/pro-fun-rimshot.mp3",tags:["rimshot"],pro:!0},{id:"pro-fun-whistle-wolf",name:"Huýt sáo",en:"Wolf whistle",category:"cartoon",duration:.91,url:"/sfx/pro-fun-whistle-wolf.mp3",tags:["wolf whistle"],pro:!0},{id:"pro-fun-honk",name:"Bóp kèn",en:"Clown honk",category:"cartoon",duration:.82,url:"/sfx/pro-fun-honk.mp3",tags:["clown honk"],pro:!0},{id:"pro-fun-magic-wand",name:"Đũa thần",en:"Magic wand",category:"cartoon",duration:1.2,url:"/sfx/pro-fun-magic-wand.mp3",tags:["magic wand"],pro:!0},{id:"pro-fun-level-up",name:"Lên cấp",en:"Level up",category:"cartoon",duration:2.02,url:"/sfx/pro-fun-level-up.mp3",tags:["level up"],pro:!0},{id:"pro-fun-coin-game",name:"Ăn xu game",en:"Game coin",category:"cartoon",duration:.86,url:"/sfx/pro-fun-coin-game.mp3",tags:["game coin"],pro:!0},{id:"pro-fun-game-over",name:"Game over",en:"Game over",category:"cartoon",duration:2.04,url:"/sfx/pro-fun-game-over.mp3",tags:["game over"],pro:!0},{id:"pro-fun-baby-laugh",name:"Em bé cười",en:"Baby laugh",category:"cartoon",duration:2.04,url:"/sfx/pro-fun-baby-laugh.mp3",tags:["baby laugh"],pro:!0},{id:"pro-glitch-data-burst",name:"Bùng dữ liệu",en:"Data burst",category:"glitch",duration:1.03,url:"/sfx/pro-glitch-data-burst.mp3",tags:["data burst"],pro:!0},{id:"pro-glitch-error-crunch",name:"Lỗi số",en:"Digital error",category:"glitch",duration:1.03,url:"/sfx/pro-glitch-error-crunch.mp3",tags:["digital error"],pro:!0},{id:"pro-glitch-robot-beeps",name:"Robot bíp",en:"Robot beeps",category:"glitch",duration:2.04,url:"/sfx/pro-glitch-robot-beeps.mp3",tags:["robot beeps"],pro:!0},{id:"pro-glitch-hologram",name:"Hologram",en:"Hologram",category:"glitch",duration:2.04,url:"/sfx/pro-glitch-hologram.mp3",tags:["hologram"],pro:!0},{id:"pro-glitch-modem",name:"Modem quay số",en:"Dial-up modem",category:"glitch",duration:3.05,url:"/sfx/pro-glitch-modem.mp3",tags:["dial-up modem"],pro:!0},{id:"pro-glitch-synth-1",name:"Glitch tổng hợp 1",en:"Synth glitch 1",category:"glitch",duration:.43,url:"/sfx/pro-glitch-synth-1.mp3",tags:["synth glitch 1"],pro:!0},{id:"pro-glitch-synth-2",name:"Glitch tổng hợp 2",en:"Synth glitch 2",category:"glitch",duration:.43,url:"/sfx/pro-glitch-synth-2.mp3",tags:["synth glitch 2"],pro:!0},{id:"pro-glitch-synth-3",name:"Glitch tổng hợp 3",en:"Synth glitch 3",category:"glitch",duration:.43,url:"/sfx/pro-glitch-synth-3.mp3",tags:["synth glitch 3"],pro:!0},{id:"pro-glitch-synth-4",name:"Glitch tổng hợp 4",en:"Synth glitch 4",category:"glitch",duration:.43,url:"/sfx/pro-glitch-synth-4.mp3",tags:["synth glitch 4"],pro:!0},{id:"pro-glitch-synth-5",name:"Glitch tổng hợp 5",en:"Synth glitch 5",category:"glitch",duration:.43,url:"/sfx/pro-glitch-synth-5.mp3",tags:["synth glitch 5"],pro:!0},{id:"pro-glitch-synth-6",name:"Glitch tổng hợp 6",en:"Synth glitch 6",category:"glitch",duration:.43,url:"/sfx/pro-glitch-synth-6.mp3",tags:["synth glitch 6"],pro:!0},{id:"pro-stutter-1",name:"Lắp bắp số 1",en:"Digital stutter 1",category:"glitch",duration:.53,url:"/sfx/pro-stutter-1.mp3",tags:["digital stutter 1"],pro:!0},{id:"pro-stutter-2",name:"Lắp bắp số 2",en:"Digital stutter 2",category:"glitch",duration:.53,url:"/sfx/pro-stutter-2.mp3",tags:["digital stutter 2"],pro:!0},{id:"pro-stutter-3",name:"Lắp bắp số 3",en:"Digital stutter 3",category:"glitch",duration:.53,url:"/sfx/pro-stutter-3.mp3",tags:["digital stutter 3"],pro:!0},{id:"pro-ui-click",name:"Click mềm",en:"Soft click",category:"ui",duration:.12,url:"/sfx/pro-ui-click.mp3",tags:["soft click"],pro:!0},{id:"pro-ui-click-high",name:"Click cao",en:"High click",category:"ui",duration:.12,url:"/sfx/pro-ui-click-high.mp3",tags:["high click"],pro:!0},{id:"pro-ui-click-low",name:"Click trầm",en:"Low click",category:"ui",duration:.12,url:"/sfx/pro-ui-click-low.mp3",tags:["low click"],pro:!0},{id:"pro-ui-tick",name:"Tích",en:"Tick",category:"ui",duration:.07,url:"/sfx/pro-ui-tick.mp3",tags:["tick"],pro:!0},{id:"pro-ui-toggle-on",name:"Bật công tắc",en:"Toggle on",category:"ui",duration:.17,url:"/sfx/pro-ui-toggle-on.mp3",tags:["toggle on"],pro:!0},{id:"pro-ui-toggle-off",name:"Tắt công tắc",en:"Toggle off",category:"ui",duration:.17,url:"/sfx/pro-ui-toggle-off.mp3",tags:["toggle off"],pro:!0},{id:"pro-ui-notify",name:"Thông báo",en:"Notification",category:"ui",duration:.29,url:"/sfx/pro-ui-notify.mp3",tags:["notification"],pro:!0},{id:"pro-ui-notify-soft",name:"Thông báo nhẹ",en:"Soft notification",category:"ui",duration:.29,url:"/sfx/pro-ui-notify-soft.mp3",tags:["soft notification"],pro:!0},{id:"pro-ui-notify-triple",name:"Thông báo ba nốt",en:"Triple notification",category:"ui",duration:.55,url:"/sfx/pro-ui-notify-triple.mp3",tags:["triple notification"],pro:!0},{id:"pro-ui-success",name:"Thành công",en:"Success",category:"ui",duration:.55,url:"/sfx/pro-ui-success.mp3",tags:["success"],pro:!0},{id:"pro-ui-error",name:"Lỗi",en:"Error",category:"ui",duration:.34,url:"/sfx/pro-ui-error.mp3",tags:["error"],pro:!0},{id:"pro-ui-warning",name:"Cảnh báo",en:"Warning",category:"ui",duration:.34,url:"/sfx/pro-ui-warning.mp3",tags:["warning"],pro:!0},{id:"pro-ui-message-sent",name:"Gửi tin",en:"Message sent",category:"ui",duration:.22,url:"/sfx/pro-ui-message-sent.mp3",tags:["message sent"],pro:!0},{id:"pro-ui-message-in",name:"Tin đến",en:"Message received",category:"ui",duration:.55,url:"/sfx/pro-ui-message-in.mp3",tags:["message received"],pro:!0},{id:"pro-ui-pop-up",name:"Bật hộp thoại",en:"Pop-up",category:"ui",duration:.19,url:"/sfx/pro-ui-pop-up.mp3",tags:["pop-up"],pro:!0},{id:"pro-ui-swipe-tick",name:"Vuốt danh sách",en:"Scroll tick",category:"ui",duration:.38,url:"/sfx/pro-ui-swipe-tick.mp3",tags:["scroll tick"],pro:!0},{id:"pro-ui-countdown-beep",name:"Đếm ngược bíp",en:"Countdown beeps",category:"ui",duration:1.63,url:"/sfx/pro-ui-countdown-beep.mp3",tags:["countdown beeps"],pro:!0},{id:"pro-ui-timer-done",name:"Hết giờ",en:"Timer done",category:"ui",duration:.91,url:"/sfx/pro-ui-timer-done.mp3",tags:["timer done"],pro:!0},{id:"pro-ui-like",name:"Thả tim",en:"Like",category:"ui",duration:.19,url:"/sfx/pro-ui-like.mp3",tags:["like"],pro:!0},{id:"pro-ui-unlock",name:"Mở khoá",en:"Unlock",category:"ui",duration:.17,url:"/sfx/pro-ui-unlock.mp3",tags:["unlock"],pro:!0},{id:"pro-ui-lock",name:"Khoá",en:"Lock",category:"ui",duration:.17,url:"/sfx/pro-ui-lock.mp3",tags:["lock"],pro:!0},{id:"pro-ui-typing-bubble",name:"Đang gõ",en:"Typing bubble",category:"ui",duration:.38,url:"/sfx/pro-ui-typing-bubble.mp3",tags:["typing bubble"],pro:!0},{id:"pro-ui-focus-beep",name:"Lấy nét bíp",en:"Focus beep",category:"ui",duration:.29,url:"/sfx/pro-ui-focus-beep.mp3",tags:["focus beep"],pro:!0},{id:"pro-ui-hover",name:"Rê chuột",en:"Hover",category:"ui",duration:.12,url:"/sfx/pro-ui-hover.mp3",tags:["hover"],pro:!0},{id:"pro-ui-delete",name:"Xoá",en:"Delete",category:"ui",duration:.22,url:"/sfx/pro-ui-delete.mp3",tags:["delete"],pro:!0},{id:"pro-voice-wow",name:"Wow! (Anh)",en:"Wow!",category:"voice",duration:.62,url:"/sfx/pro-voice-wow.mp3",tags:["wow!"],pro:!0},{id:"pro-voice-wow-female",name:"Wow! (nữ, Anh)",en:"Wow! (female)",category:"voice",duration:.7,url:"/sfx/pro-voice-wow-female.mp3",tags:["wow! (female)"],pro:!0},{id:"pro-voice-oh-damn",name:"Oh damn! (nam)",en:"Oh damn!",category:"voice",duration:.94,url:"/sfx/pro-voice-oh-damn.mp3",tags:["oh damn!"],pro:!0},{id:"pro-voice-oh-no",name:"Oh no!",en:"Oh no!",category:"voice",duration:.72,url:"/sfx/pro-voice-oh-no.mp3",tags:["oh no!"],pro:!0},{id:"pro-voice-lets-go",name:"Let's go!",en:"Let's go!",category:"voice",duration:.67,url:"/sfx/pro-voice-lets-go.mp3",tags:["let's go!"],pro:!0},{id:"pro-voice-yes",name:"Yes!",en:"Yes!",category:"voice",duration:.48,url:"/sfx/pro-voice-yes.mp3",tags:["yes!"],pro:!0},{id:"pro-voice-what",name:"What?!",en:"What?!",category:"voice",duration:.48,url:"/sfx/pro-voice-what.mp3",tags:["what?!"],pro:!0},{id:"pro-voice-nice",name:"Nice!",en:"Nice!",category:"voice",duration:.67,url:"/sfx/pro-voice-nice.mp3",tags:["nice!"],pro:!0},{id:"pro-voice-level-up",name:"Level up!",en:"Level up!",category:"voice",duration:.72,url:"/sfx/pro-voice-level-up.mp3",tags:["level up!"],pro:!0},{id:"pro-voice-sale",name:"Sale!",en:"Sale!",category:"voice",duration:.41,url:"/sfx/pro-voice-sale.mp3",tags:["sale!"],pro:!0},{id:"pro-voice-oi-gioi-oi",name:"Ối giời ơi!",en:"Oi gioi oi!",category:"voice",duration:.72,url:"/sfx/pro-voice-oi-gioi-oi.mp3",tags:["oi gioi oi!"],pro:!0},{id:"pro-voice-tuyet-voi",name:"Tuyệt vời!",en:"Tuyet voi! (Awesome)",category:"voice",duration:.72,url:"/sfx/pro-voice-tuyet-voi.mp3",tags:["tuyet voi! (awesome)"],pro:!0},{id:"pro-voice-tron-oi",name:"Trời ơi!",en:"Troi oi! (Oh my)",category:"voice",duration:.86,url:"/sfx/pro-voice-tron-oi.mp3",tags:["troi oi! (oh my)"],pro:!0},{id:"pro-voice-dinh-qua",name:"Đỉnh quá!",en:"Dinh qua! (So good)",category:"voice",duration:.58,url:"/sfx/pro-voice-dinh-qua.mp3",tags:["dinh qua! (so good)"],pro:!0},{id:"pro-voice-chot-don",name:"Chốt đơn!",en:"Chot don! (Order placed)",category:"voice",duration:.7,url:"/sfx/pro-voice-chot-don.mp3",tags:["chot don! (order placed)"],pro:!0},{id:"pro-voice-sale-soc",name:"Sale sốc!",en:"Sale soc! (Crazy sale)",category:"voice",duration:.79,url:"/sfx/pro-voice-sale-soc.mp3",tags:["sale soc! (crazy sale)"],pro:!0},{id:"pro-voice-ba-hai-mot",name:"Ba, hai, một!",en:"Ba hai mot (3-2-1)",category:"voice",duration:2.09,url:"/sfx/pro-voice-ba-hai-mot.mp3",tags:["ba hai mot (3-2-1)"],pro:!0},{id:"pro-voice-ua-gi-vay",name:"Ủa, gì vậy?",en:"Ua gi vay? (Wait, what?)",category:"voice",duration:1.06,url:"/sfx/pro-voice-ua-gi-vay.mp3",tags:["ua gi vay? (wait, what?)"],pro:!0},{id:"pro-voice-hay-qua",name:"Hay quá!",en:"Hay qua! (So cool)",category:"voice",duration:.55,url:"/sfx/pro-voice-hay-qua.mp3",tags:["hay qua! (so cool)"],pro:!0},{id:"pro-voice-xin-chao",name:"Xin chào!",en:"Xin chao (Hello)",category:"voice",duration:.62,url:"/sfx/pro-voice-xin-chao.mp3",tags:["xin chao (hello)"],pro:!0},{id:"pro-amb-rain-window",name:"Mưa bên cửa sổ",en:"Rain on window",category:"ambience",duration:10.37,url:"/sfx/pro-amb-rain-window.mp3",tags:["rain on window"],pro:!0},{id:"pro-amb-night-city",name:"Phố đêm",en:"Night city",category:"ambience",duration:10.37,url:"/sfx/pro-amb-night-city.mp3",tags:["night city"],pro:!0},{id:"pro-amb-market",name:"Chợ đông",en:"Busy market",category:"ambience",duration:10.37,url:"/sfx/pro-amb-market.mp3",tags:["busy market"],pro:!0},{id:"pro-amb-office-busy",name:"Văn phòng bận",en:"Busy office",category:"ambience",duration:10.37,url:"/sfx/pro-amb-office-busy.mp3",tags:["busy office"],pro:!0},{id:"pro-amb-forest-morning",name:"Rừng buổi sáng",en:"Morning forest",category:"ambience",duration:10.37,url:"/sfx/pro-amb-forest-morning.mp3",tags:["morning forest"],pro:!0},{id:"pro-amb-beach-waves",name:"Sóng biển",en:"Beach waves",category:"ambience",duration:10.37,url:"/sfx/pro-amb-beach-waves.mp3",tags:["beach waves"],pro:!0},{id:"pro-amb-cafe-rain",name:"Quán cà phê mưa",en:"Rainy cafe",category:"ambience",duration:10.37,url:"/sfx/pro-amb-cafe-rain.mp3",tags:["rainy cafe"],pro:!0},{id:"pro-amb-classroom",name:"Lớp học",en:"Classroom",category:"ambience",duration:10.37,url:"/sfx/pro-amb-classroom.mp3",tags:["classroom"],pro:!0},{id:"pro-amb-stadium",name:"Sân vận động",en:"Stadium crowd",category:"ambience",duration:8.38,url:"/sfx/pro-amb-stadium.mp3",tags:["stadium crowd"],pro:!0},{id:"pro-amb-space-hum",name:"Phòng tàu vũ trụ",en:"Spaceship hum",category:"ambience",duration:10.37,url:"/sfx/pro-amb-space-hum.mp3",tags:["spaceship hum"],pro:!0},{id:"pro-amb-night-crickets",name:"Đêm quê",en:"Countryside night",category:"ambience",duration:10.37,url:"/sfx/pro-amb-night-crickets.mp3",tags:["countryside night"],pro:!0},{id:"pro-amb-wind-mountain",name:"Gió núi",en:"Mountain wind",category:"ambience",duration:10.37,url:"/sfx/pro-amb-wind-mountain.mp3",tags:["mountain wind"],pro:!0},{id:"pro-amb-underwater",name:"Dưới nước",en:"Underwater",category:"ambience",duration:8.38,url:"/sfx/pro-amb-underwater.mp3",tags:["underwater"],pro:!0},{id:"pro-amb-traffic-hcm",name:"Giờ cao điểm",en:"Rush hour traffic",category:"ambience",duration:10.37,url:"/sfx/pro-amb-traffic-hcm.mp3",tags:["rush hour traffic"],pro:!0},{id:"pro-amb-fireplace",name:"Lò sưởi",en:"Fireplace",category:"ambience",duration:10.37,url:"/sfx/pro-amb-fireplace.mp3",tags:["fireplace"],pro:!0},{id:"pro-nature-thunderstorm",name:"Giông bão",en:"Thunderstorm",category:"nature",duration:8.38,url:"/sfx/pro-nature-thunderstorm.mp3",tags:["thunderstorm"],pro:!0},{id:"pro-nature-birds",name:"Chim hót",en:"Birdsong",category:"nature",duration:5.5,url:"/sfx/pro-nature-birds.mp3",tags:["birdsong"],pro:!0},{id:"pro-nature-rooster",name:"Gà gáy",en:"Rooster",category:"nature",duration:2.18,url:"/sfx/pro-nature-rooster.mp3",tags:["rooster"],pro:!0},{id:"pro-nature-dog-bark",name:"Chó sủa",en:"Dog bark",category:"nature",duration:2.26,url:"/sfx/pro-nature-dog-bark.mp3",tags:["dog bark"],pro:!0},{id:"pro-nature-cat-meow",name:"Mèo kêu",en:"Cat meow",category:"nature",duration:2.38,url:"/sfx/pro-nature-cat-meow.mp3",tags:["cat meow"],pro:!0},{id:"pro-nature-stream",name:"Suối chảy",en:"Stream",category:"nature",duration:8.38,url:"/sfx/pro-nature-stream.mp3",tags:["stream"],pro:!0},{id:"pro-nature-waterfall",name:"Thác nước",en:"Waterfall",category:"nature",duration:8.38,url:"/sfx/pro-nature-waterfall.mp3",tags:["waterfall"],pro:!0},{id:"pro-nature-leaves",name:"Lá xào xạc",en:"Rustling leaves",category:"nature",duration:6.14,url:"/sfx/pro-nature-leaves.mp3",tags:["rustling leaves"],pro:!0},{id:"pro-nature-bees",name:"Ong bay",en:"Bees buzzing",category:"nature",duration:4.7,url:"/sfx/pro-nature-bees.mp3",tags:["bees buzzing"],pro:!0},{id:"pro-nature-frogs",name:"Ếch kêu",en:"Frogs",category:"nature",duration:6.26,url:"/sfx/pro-nature-frogs.mp3",tags:["frogs"],pro:!0},{id:"pro-nature-owl",name:"Cú kêu",en:"Owl",category:"nature",duration:3.38,url:"/sfx/pro-nature-owl.mp3",tags:["owl"],pro:!0},{id:"pro-nature-seagulls",name:"Hải âu",en:"Seagulls",category:"nature",duration:5.38,url:"/sfx/pro-nature-seagulls.mp3",tags:["seagulls"],pro:!0},{id:"pro-human-gasp",name:"Hít hà ngạc nhiên",en:"Gasp",category:"human",duration:1.34,url:"/sfx/pro-human-gasp.mp3",tags:["gasp"],pro:!0},{id:"pro-human-crowd-cheer",name:"Đám đông reo",en:"Crowd cheer",category:"human",duration:4.22,url:"/sfx/pro-human-crowd-cheer.mp3",tags:["crowd cheer"],pro:!0},{id:"pro-human-crowd-aww",name:"Đám đông ồ",en:"Crowd aww",category:"human",duration:2.35,url:"/sfx/pro-human-crowd-aww.mp3",tags:["crowd aww"],pro:!0},{id:"pro-human-crowd-gasp",name:"Đám đông ồ ngạc nhiên",en:"Crowd gasp",category:"human",duration:1.18,url:"/sfx/pro-human-crowd-gasp.mp3",tags:["crowd gasp"],pro:!0},{id:"pro-human-laugh-man",name:"Đàn ông cười",en:"Man laughing",category:"human",duration:2.76,url:"/sfx/pro-human-laugh-man.mp3",tags:["man laughing"],pro:!0},{id:"pro-human-laugh-woman",name:"Phụ nữ cười",en:"Woman laughing",category:"human",duration:3.36,url:"/sfx/pro-human-laugh-woman.mp3",tags:["woman laughing"],pro:!0},{id:"pro-human-kids-cheer",name:"Trẻ em reo",en:"Kids cheering",category:"human",duration:3.34,url:"/sfx/pro-human-kids-cheer.mp3",tags:["kids cheering"],pro:!0},{id:"pro-human-clap-single",name:"Vỗ tay một người",en:"Single clap",category:"human",duration:1.82,url:"/sfx/pro-human-clap-single.mp3",tags:["single clap"],pro:!0},{id:"pro-human-whistle-call",name:"Huýt sáo gọi",en:"Whistle call",category:"human",duration:1.3,url:"/sfx/pro-human-whistle-call.mp3",tags:["whistle call"],pro:!0},{id:"pro-human-sigh",name:"Thở dài",en:"Sigh",category:"human",duration:2.35,url:"/sfx/pro-human-sigh.mp3",tags:["sigh"],pro:!0},{id:"pro-human-yawn",name:"Ngáp",en:"Yawn",category:"human",duration:2.21,url:"/sfx/pro-human-yawn.mp3",tags:["yawn"],pro:!0},{id:"pro-human-heartbeat",name:"Nhịp tim",en:"Heartbeat",category:"human",duration:4.34,url:"/sfx/pro-human-heartbeat.mp3",tags:["heartbeat"],pro:!0},{id:"pro-human-breath-run",name:"Thở dốc",en:"Heavy breathing",category:"human",duration:3.36,url:"/sfx/pro-human-breath-run.mp3",tags:["heavy breathing"],pro:!0},{id:"pro-human-kiss",name:"Hôn gió",en:"Kiss",category:"human",duration:.98,url:"/sfx/pro-human-kiss.mp3",tags:["kiss"],pro:!0},{id:"pro-human-hmm",name:"Hmm suy nghĩ",en:"Thinking hmm",category:"human",duration:1.99,url:"/sfx/pro-human-hmm.mp3",tags:["thinking hmm"],pro:!0},{id:"pro-food-sizzle",name:"Xèo chảo",en:"Pan sizzle",category:"food",duration:4.34,url:"/sfx/pro-food-sizzle.mp3",tags:["pan sizzle"],pro:!0},{id:"pro-food-chop",name:"Thái rau",en:"Chopping",category:"food",duration:2.74,url:"/sfx/pro-food-chop.mp3",tags:["chopping"],pro:!0},{id:"pro-food-boil",name:"Nước sôi",en:"Boiling",category:"food",duration:4.34,url:"/sfx/pro-food-boil.mp3",tags:["boiling"],pro:!0},{id:"pro-food-crunch",name:"Cắn giòn",en:"Crunch bite",category:"food",duration:.62,url:"/sfx/pro-food-crunch.mp3",tags:["crunch bite"],pro:!0},{id:"pro-food-slurp",name:"Húp mì",en:"Noodle slurp",category:"food",duration:2.28,url:"/sfx/pro-food-slurp.mp3",tags:["noodle slurp"],pro:!0},{id:"pro-food-fizz",name:"Nước có ga",en:"Soda fizz",category:"food",duration:1.94,url:"/sfx/pro-food-fizz.mp3",tags:["soda fizz"],pro:!0},{id:"pro-food-coffee-machine",name:"Máy pha cà phê",en:"Espresso machine",category:"food",duration:5.3,url:"/sfx/pro-food-coffee-machine.mp3",tags:["espresso machine"],pro:!0},{id:"pro-food-microwave-ding",name:"Lò vi sóng",en:"Microwave ding",category:"food",duration:2.06,url:"/sfx/pro-food-microwave-ding.mp3",tags:["microwave ding"],pro:!0},{id:"pro-food-egg-crack",name:"Đập trứng",en:"Egg crack",category:"food",duration:.38,url:"/sfx/pro-food-egg-crack.mp3",tags:["egg crack"],pro:!0},{id:"pro-food-cheers",name:"Cụng ly",en:"Glasses cheers",category:"food",duration:.79,url:"/sfx/pro-food-cheers.mp3",tags:["glasses cheers"],pro:!0},{id:"pro-food-blender",name:"Máy xay",en:"Blender",category:"food",duration:4.2,url:"/sfx/pro-food-blender.mp3",tags:["blender"],pro:!0},{id:"pro-food-kettle",name:"Ấm reo",en:"Kettle whistle",category:"food",duration:4.34,url:"/sfx/pro-food-kettle.mp3",tags:["kettle whistle"],pro:!0},{id:"pro-street-motorbike-pass",name:"Xe máy chạy qua",en:"Motorbike pass",category:"vehicle",duration:3.05,url:"/sfx/pro-street-motorbike-pass.mp3",tags:["motorbike pass"],pro:!0},{id:"pro-street-horn",name:"Còi xe",en:"Car horn",category:"vehicle",duration:1.27,url:"/sfx/pro-street-horn.mp3",tags:["car horn"],pro:!0},{id:"pro-street-bike-bell",name:"Chuông xe đạp",en:"Bike bell",category:"vehicle",duration:1.34,url:"/sfx/pro-street-bike-bell.mp3",tags:["bike bell"],pro:!0},{id:"pro-street-train-pass",name:"Tàu chạy qua",en:"Train pass",category:"vehicle",duration:6.02,url:"/sfx/pro-street-train-pass.mp3",tags:["train pass"],pro:!0},{id:"pro-street-siren",name:"Còi cứu thương",en:"Siren",category:"vehicle",duration:5.35,url:"/sfx/pro-street-siren.mp3",tags:["siren"],pro:!0},{id:"pro-street-engine-start",name:"Nổ máy",en:"Engine start",category:"vehicle",duration:2.5,url:"/sfx/pro-street-engine-start.mp3",tags:["engine start"],pro:!0},{id:"pro-street-tires-screech",name:"Phanh gấp",en:"Tire screech",category:"vehicle",duration:2.14,url:"/sfx/pro-street-tires-screech.mp3",tags:["tire screech"],pro:!0},{id:"pro-street-helicopter",name:"Trực thăng",en:"Helicopter",category:"vehicle",duration:5.35,url:"/sfx/pro-street-helicopter.mp3",tags:["helicopter"],pro:!0},{id:"pro-street-bus-door",name:"Cửa xe buýt",en:"Bus door",category:"vehicle",duration:2.35,url:"/sfx/pro-street-bus-door.mp3",tags:["bus door"],pro:!0},{id:"pro-street-elevator-ding",name:"Thang máy",en:"Elevator ding",category:"vehicle",duration:2.28,url:"/sfx/pro-street-elevator-ding.mp3",tags:["elevator ding"],pro:!0},{id:"pro-scifi-laser-shot",name:"Bắn laser",en:"Laser shot",category:"scifi",duration:1.3,url:"/sfx/pro-scifi-laser-shot.mp3",tags:["laser shot"],pro:!0},{id:"pro-scifi-power-up",name:"Tăng sức mạnh",en:"Power up",category:"scifi",duration:1.75,url:"/sfx/pro-scifi-power-up.mp3",tags:["power up"],pro:!0},{id:"pro-scifi-power-down",name:"Tắt nguồn",en:"Power down",category:"scifi",duration:2.35,url:"/sfx/pro-scifi-power-down.mp3",tags:["power down"],pro:!0},{id:"pro-scifi-teleport",name:"Dịch chuyển",en:"Teleport",category:"scifi",duration:2.33,url:"/sfx/pro-scifi-teleport.mp3",tags:["teleport"],pro:!0},{id:"pro-scifi-scanner",name:"Quét tia",en:"Scanner",category:"scifi",duration:3.29,url:"/sfx/pro-scifi-scanner.mp3",tags:["scanner"],pro:!0},{id:"pro-scifi-alarm-ship",name:"Báo động tàu",en:"Ship alarm",category:"scifi",duration:3.31,url:"/sfx/pro-scifi-alarm-ship.mp3",tags:["ship alarm"],pro:!0},{id:"pro-scifi-force-field",name:"Khiên năng lượng",en:"Force field",category:"scifi",duration:3.36,url:"/sfx/pro-scifi-force-field.mp3",tags:["force field"],pro:!0},{id:"pro-scifi-ui-hud",name:"HUD hiện ra",en:"HUD boot",category:"scifi",duration:2.35,url:"/sfx/pro-scifi-ui-hud.mp3",tags:["hud boot"],pro:!0},{id:"pro-mouse-click-office",name:"Click chuột văn phòng",en:"Office mouse click",category:"input",duration:1.01,url:"/sfx/pro-mouse-click-office.mp3",tags:["office mouse click"],pro:!0},{id:"pro-mouse-click-gaming",name:"Click chuột gaming",en:"Gaming mouse click",category:"input",duration:1.01,url:"/sfx/pro-mouse-click-gaming.mp3",tags:["gaming mouse click"],pro:!0},{id:"pro-mouse-double",name:"Double click chuột",en:"Mouse double click",category:"input",duration:.24,url:"/sfx/pro-mouse-double.mp3",tags:["mouse double click"],pro:!0},{id:"pro-mouse-right",name:"Click chuột phải",en:"Right mouse click",category:"input",duration:1.03,url:"/sfx/pro-mouse-right.mp3",tags:["right mouse click"],pro:!0},{id:"pro-mouse-wheel",name:"Cuộn chuột",en:"Mouse wheel scroll",category:"input",duration:1.03,url:"/sfx/pro-mouse-wheel.mp3",tags:["mouse wheel scroll"],pro:!0},{id:"pro-mouse-wheel-fast",name:"Cuộn chuột nhanh",en:"Fast mouse scroll",category:"input",duration:1.03,url:"/sfx/pro-mouse-wheel-fast.mp3",tags:["fast mouse scroll"],pro:!0},{id:"pro-trackpad-tap",name:"Chạm trackpad",en:"Trackpad tap",category:"input",duration:1.03,url:"/sfx/pro-trackpad-tap.mp3",tags:["trackpad tap"],pro:!0},{id:"pro-trackpad-press",name:"Bấm trackpad",en:"Trackpad press",category:"input",duration:.17,url:"/sfx/pro-trackpad-press.mp3",tags:["trackpad press"],pro:!0},{id:"pro-mouse-drag",name:"Kéo thả chuột",en:"Mouse drag",category:"input",duration:.6,url:"/sfx/pro-mouse-drag.mp3",tags:["mouse drag"],pro:!0},{id:"pro-key-mechanical",name:"Phím cơ đơn",en:"Mechanical key",category:"input",duration:.17,url:"/sfx/pro-key-mechanical.mp3",tags:["mechanical key"],pro:!0},{id:"pro-key-laptop",name:"Phím laptop",en:"Laptop key",category:"input",duration:1.03,url:"/sfx/pro-key-laptop.mp3",tags:["laptop key"],pro:!0},{id:"pro-key-enter",name:"Phím Enter",en:"Enter key",category:"input",duration:1.01,url:"/sfx/pro-key-enter.mp3",tags:["enter key"],pro:!0},{id:"pro-key-space",name:"Phím cách",en:"Space bar",category:"input",duration:.38,url:"/sfx/pro-key-space.mp3",tags:["space bar"],pro:!0},{id:"pro-key-backspace",name:"Phím xoá",en:"Backspace key",category:"input",duration:.98,url:"/sfx/pro-key-backspace.mp3",tags:["backspace key"],pro:!0},{id:"pro-typing-short",name:"Gõ phím ngắn",en:"Short typing",category:"input",duration:1.99,url:"/sfx/pro-typing-short.mp3",tags:["short typing"],pro:!0},{id:"pro-typing-long",name:"Gõ phím dài",en:"Long typing",category:"input",duration:1.92,url:"/sfx/pro-typing-long.mp3",tags:["long typing"],pro:!0},{id:"pro-typing-laptop",name:"Gõ laptop",en:"Laptop typing",category:"input",duration:1.78,url:"/sfx/pro-typing-laptop.mp3",tags:["laptop typing"],pro:!0},{id:"pro-typing-thock",name:"Gõ phím thock",en:"Thocky typing",category:"input",duration:1.73,url:"/sfx/pro-typing-thock.mp3",tags:["thocky typing"],pro:!0},{id:"pro-phone-keyboard",name:"Bàn phím điện thoại",en:"Phone keyboard taps",category:"input",duration:.58,url:"/sfx/pro-phone-keyboard.mp3",tags:["phone keyboard taps"],pro:!0},{id:"pro-stylus-tap",name:"Gõ bút cảm ứng",en:"Stylus tap",category:"input",duration:.22,url:"/sfx/pro-stylus-tap.mp3",tags:["stylus tap"],pro:!0},{id:"pro-stylus-write",name:"Viết bút cảm ứng",en:"Stylus writing",category:"input",duration:.22,url:"/sfx/pro-stylus-write.mp3",tags:["stylus writing"],pro:!0},{id:"pro-phone-tap-glass",name:"Chạm màn hình",en:"Screen tap",category:"input",duration:.1,url:"/sfx/pro-phone-tap-glass.mp3",tags:["screen tap"],pro:!0},{id:"pro-phone-unlock",name:"Mở khoá điện thoại",en:"Phone unlock",category:"input",duration:1.01,url:"/sfx/pro-phone-unlock.mp3",tags:["phone unlock"],pro:!0},{id:"pro-camera-screenshot",name:"Chụp màn hình",en:"Screenshot",category:"input",duration:.91,url:"/sfx/pro-camera-screenshot.mp3",tags:["screenshot"],pro:!0},{id:"pro-usb-plug",name:"Cắm USB",en:"USB plug in",category:"input",duration:.12,url:"/sfx/pro-usb-plug.mp3",tags:["usb plug in"],pro:!0},{id:"pro-mouse-synth-1",name:"Click chuột sạch 1",en:"Clean mouse click 1",category:"input",duration:.12,url:"/sfx/pro-mouse-synth-1.mp3",tags:["clean mouse click 1"],pro:!0},{id:"pro-mouse-synth-2",name:"Click chuột sạch 2",en:"Clean mouse click 2",category:"input",duration:.12,url:"/sfx/pro-mouse-synth-2.mp3",tags:["clean mouse click 2"],pro:!0},{id:"pro-mouse-synth-3",name:"Click chuột sạch 3",en:"Clean mouse click 3",category:"input",duration:.12,url:"/sfx/pro-mouse-synth-3.mp3",tags:["clean mouse click 3"],pro:!0},{id:"pro-mouse-synth-4",name:"Click chuột sạch 4",en:"Clean mouse click 4",category:"input",duration:.12,url:"/sfx/pro-mouse-synth-4.mp3",tags:["clean mouse click 4"],pro:!0},{id:"pro-mouse-synth-5",name:"Click chuột sạch 5",en:"Clean mouse click 5",category:"input",duration:.12,url:"/sfx/pro-mouse-synth-5.mp3",tags:["clean mouse click 5"],pro:!0},{id:"pro-click-pitched-1",name:"Click cao độ 1",en:"Pitched click 1",category:"input",duration:.12,url:"/sfx/pro-click-pitched-1.mp3",tags:["pitched click 1"],pro:!0},{id:"pro-click-pitched-2",name:"Click cao độ 2",en:"Pitched click 2",category:"input",duration:.12,url:"/sfx/pro-click-pitched-2.mp3",tags:["pitched click 2"],pro:!0},{id:"pro-click-pitched-3",name:"Click cao độ 3",en:"Pitched click 3",category:"input",duration:.12,url:"/sfx/pro-click-pitched-3.mp3",tags:["pitched click 3"],pro:!0},{id:"pro-click-pitched-4",name:"Click cao độ 4",en:"Pitched click 4",category:"input",duration:.12,url:"/sfx/pro-click-pitched-4.mp3",tags:["pitched click 4"],pro:!0},{id:"pro-click-pitched-5",name:"Click cao độ 5",en:"Pitched click 5",category:"input",duration:.12,url:"/sfx/pro-click-pitched-5.mp3",tags:["pitched click 5"],pro:!0},{id:"pro-arp-1",name:"Arpeggio giao diện 1",en:"UI arpeggio 1",category:"ui",duration:.67,url:"/sfx/pro-arp-1.mp3",tags:["ui arpeggio 1"],pro:!0},{id:"pro-arp-2",name:"Arpeggio giao diện 2",en:"UI arpeggio 2",category:"ui",duration:.65,url:"/sfx/pro-arp-2.mp3",tags:["ui arpeggio 2"],pro:!0},{id:"pro-arp-3",name:"Arpeggio giao diện 3",en:"UI arpeggio 3",category:"ui",duration:.67,url:"/sfx/pro-arp-3.mp3",tags:["ui arpeggio 3"],pro:!0},{id:"pro-arp-4",name:"Arpeggio giao diện 4",en:"UI arpeggio 4",category:"ui",duration:.65,url:"/sfx/pro-arp-4.mp3",tags:["ui arpeggio 4"],pro:!0},{id:"pro-arp-5",name:"Arpeggio giao diện 5",en:"UI arpeggio 5",category:"ui",duration:.72,url:"/sfx/pro-arp-5.mp3",tags:["ui arpeggio 5"],pro:!0},{id:"pro-arp-6",name:"Arpeggio giao diện 6",en:"UI arpeggio 6",category:"ui",duration:.65,url:"/sfx/pro-arp-6.mp3",tags:["ui arpeggio 6"],pro:!0},{id:"pro-arp-7",name:"Arpeggio giao diện 7",en:"UI arpeggio 7",category:"ui",duration:.67,url:"/sfx/pro-arp-7.mp3",tags:["ui arpeggio 7"],pro:!0},{id:"pro-arp-8",name:"Arpeggio giao diện 8",en:"UI arpeggio 8",category:"ui",duration:.72,url:"/sfx/pro-arp-8.mp3",tags:["ui arpeggio 8"],pro:!0},{id:"pro-notify-1",name:"Thông báo 1",en:"Notification 1",category:"ui",duration:.29,url:"/sfx/pro-notify-1.mp3",tags:["notification 1"],pro:!0},{id:"pro-notify-2",name:"Thông báo 2",en:"Notification 2",category:"ui",duration:.29,url:"/sfx/pro-notify-2.mp3",tags:["notification 2"],pro:!0},{id:"pro-notify-3",name:"Thông báo 3",en:"Notification 3",category:"ui",duration:.29,url:"/sfx/pro-notify-3.mp3",tags:["notification 3"],pro:!0},{id:"pro-notify-4",name:"Thông báo 4",en:"Notification 4",category:"ui",duration:.29,url:"/sfx/pro-notify-4.mp3",tags:["notification 4"],pro:!0},{id:"pro-notify-5",name:"Thông báo 5",en:"Notification 5",category:"ui",duration:.29,url:"/sfx/pro-notify-5.mp3",tags:["notification 5"],pro:!0},{id:"pro-notify-6",name:"Thông báo 6",en:"Notification 6",category:"ui",duration:.29,url:"/sfx/pro-notify-6.mp3",tags:["notification 6"],pro:!0},{id:"pro-notify-7",name:"Thông báo 7",en:"Notification 7",category:"ui",duration:.29,url:"/sfx/pro-notify-7.mp3",tags:["notification 7"],pro:!0},{id:"pro-notify-8",name:"Thông báo 8",en:"Notification 8",category:"ui",duration:.29,url:"/sfx/pro-notify-8.mp3",tags:["notification 8"],pro:!0},{id:"pro-chime-1",name:"Chuông ba nốt 1",en:"Three-note chime 1",category:"ui",duration:.55,url:"/sfx/pro-chime-1.mp3",tags:["three-note chime 1"],pro:!0},{id:"pro-chime-2",name:"Chuông ba nốt 2",en:"Three-note chime 2",category:"ui",duration:.55,url:"/sfx/pro-chime-2.mp3",tags:["three-note chime 2"],pro:!0},{id:"pro-chime-3",name:"Chuông ba nốt 3",en:"Three-note chime 3",category:"ui",duration:.55,url:"/sfx/pro-chime-3.mp3",tags:["three-note chime 3"],pro:!0},{id:"pro-chime-4",name:"Chuông ba nốt 4",en:"Three-note chime 4",category:"ui",duration:.55,url:"/sfx/pro-chime-4.mp3",tags:["three-note chime 4"],pro:!0},{id:"pro-switch-1",name:"Công tắc bật 1",en:"Switch on 1",category:"ui",duration:.17,url:"/sfx/pro-switch-1.mp3",tags:["switch on 1"],pro:!0},{id:"pro-switch-2",name:"Công tắc bật 2",en:"Switch on 2",category:"ui",duration:.17,url:"/sfx/pro-switch-2.mp3",tags:["switch on 2"],pro:!0},{id:"pro-switch-3",name:"Công tắc tắt 3",en:"Switch off 3",category:"ui",duration:.17,url:"/sfx/pro-switch-3.mp3",tags:["switch off 3"],pro:!0},{id:"pro-switch-4",name:"Công tắc tắt 4",en:"Switch off 4",category:"ui",duration:.17,url:"/sfx/pro-switch-4.mp3",tags:["switch off 4"],pro:!0},{id:"pro-beep-1",name:"Beep 1",en:"Beep 1",category:"ui",duration:.14,url:"/sfx/pro-beep-1.mp3",tags:["beep 1"],pro:!0},{id:"pro-beep-2",name:"Beep 2",en:"Beep 2",category:"ui",duration:.22,url:"/sfx/pro-beep-2.mp3",tags:["beep 2"],pro:!0},{id:"pro-beep-3",name:"Beep 3",en:"Beep 3",category:"ui",duration:.34,url:"/sfx/pro-beep-3.mp3",tags:["beep 3"],pro:!0},{id:"pro-beep-4",name:"Beep 4",en:"Beep 4",category:"ui",duration:.1,url:"/sfx/pro-beep-4.mp3",tags:["beep 4"],pro:!0},{id:"pro-ui-glass-ping",name:"Ping thuỷ tinh",en:"Glass ping",category:"ui",duration:.29,url:"/sfx/pro-ui-glass-ping.mp3",tags:["glass ping"],pro:!0},{id:"pro-ui-water-drop-notify",name:"Giọt nước thông báo",en:"Water-drop notification",category:"ui",duration:.7,url:"/sfx/pro-ui-water-drop-notify.mp3",tags:["water-drop notification"],pro:!0},{id:"pro-ui-soft-confirm",name:"Xác nhận nhẹ",en:"Soft confirm",category:"ui",duration:.29,url:"/sfx/pro-ui-soft-confirm.mp3",tags:["soft confirm"],pro:!0},{id:"pro-ui-premium-tap",name:"Chạm cao cấp",en:"Premium tap",category:"ui",duration:.1,url:"/sfx/pro-ui-premium-tap.mp3",tags:["premium tap"],pro:!0},{id:"pro-ui-sparkle-success",name:"Thành công lấp lánh",en:"Sparkle success",category:"ui",duration:.7,url:"/sfx/pro-ui-sparkle-success.mp3",tags:["sparkle success"],pro:!0},{id:"pro-ui-whoop-open",name:"Mở bảng",en:"Panel open",category:"ui",duration:.22,url:"/sfx/pro-ui-whoop-open.mp3",tags:["panel open"],pro:!0},{id:"pro-ui-close-thud",name:"Đóng bảng",en:"Panel close",category:"ui",duration:.19,url:"/sfx/pro-ui-close-thud.mp3",tags:["panel close"],pro:!0},{id:"pro-ui-card-select",name:"Chọn thẻ",en:"Card select",category:"ui",duration:.53,url:"/sfx/pro-ui-card-select.mp3",tags:["card select"],pro:!0},{id:"pro-whoosh-ui-bright",name:"Lướt sáng",en:"Bright UI whoosh",category:"whoosh",duration:1.03,url:"/sfx/pro-whoosh-ui-bright.mp3",tags:["bright ui whoosh"],pro:!0},{id:"pro-whoosh-ui-soft",name:"Lướt mềm",en:"Soft UI whoosh",category:"whoosh",duration:1.03,url:"/sfx/pro-whoosh-ui-soft.mp3",tags:["soft ui whoosh"],pro:!0},{id:"pro-whoosh-flick",name:"Vuốt nhanh",en:"Quick flick",category:"whoosh",duration:.84,url:"/sfx/pro-whoosh-flick.mp3",tags:["quick flick"],pro:!0},{id:"pro-whoosh-card",name:"Thẻ lướt qua",en:"Card fly-by",category:"whoosh",duration:1.01,url:"/sfx/pro-whoosh-card.mp3",tags:["card fly-by"],pro:!0},{id:"pro-whoosh-zip",name:"Zip lướt",en:"Zip whoosh",category:"whoosh",duration:1.03,url:"/sfx/pro-whoosh-zip.mp3",tags:["zip whoosh"],pro:!0},{id:"pro-whoosh-swing-light",name:"Vung nhẹ",en:"Light swing",category:"whoosh",duration:.86,url:"/sfx/pro-whoosh-swing-light.mp3",tags:["light swing"],pro:!0},{id:"pro-whoosh-cinematic-short",name:"Woosh điện ảnh ngắn",en:"Short cinematic whoosh",category:"whoosh",duration:1.03,url:"/sfx/pro-whoosh-cinematic-short.mp3",tags:["short cinematic whoosh"],pro:!0},{id:"pro-whoosh-reverse-short",name:"Woosh ngược ngắn",en:"Short reverse whoosh",category:"whoosh",duration:.86,url:"/sfx/pro-whoosh-reverse-short.mp3",tags:["short reverse whoosh"],pro:!0},{id:"pro-whoosh-breathy",name:"Woosh hơi thở",en:"Breathy whoosh",category:"whoosh",duration:2.04,url:"/sfx/pro-whoosh-breathy.mp3",tags:["breathy whoosh"],pro:!0},{id:"pro-whoosh-electric",name:"Woosh điện",en:"Electric whoosh",category:"whoosh",duration:.82,url:"/sfx/pro-whoosh-electric.mp3",tags:["electric whoosh"],pro:!0},{id:"pro-whoosh-laser",name:"Woosh laser",en:"Laser whoosh",category:"whoosh",duration:.74,url:"/sfx/pro-whoosh-laser.mp3",tags:["laser whoosh"],pro:!0},{id:"pro-whoosh-wind-short",name:"Gió vụt ngắn",en:"Short wind swoosh",category:"whoosh",duration:1.03,url:"/sfx/pro-whoosh-wind-short.mp3",tags:["short wind swoosh"],pro:!0},{id:"pro-whoosh-pass-left",name:"Lướt qua trái",en:"Pass-by whoosh",category:"whoosh",duration:1.8,url:"/sfx/pro-whoosh-pass-left.mp3",tags:["pass-by whoosh"],pro:!0},{id:"pro-whoosh-pass-up",name:"Vút lên",en:"Upward whoosh",category:"whoosh",duration:1.03,url:"/sfx/pro-whoosh-pass-up.mp3",tags:["upward whoosh"],pro:!0},{id:"pro-whoosh-pass-down",name:"Vút xuống",en:"Downward whoosh",category:"whoosh",duration:.55,url:"/sfx/pro-whoosh-pass-down.mp3",tags:["downward whoosh"],pro:!0},{id:"pro-whoosh-heavy-short",name:"Woosh nặng ngắn",en:"Short heavy whoosh",category:"whoosh",duration:1.03,url:"/sfx/pro-whoosh-heavy-short.mp3",tags:["short heavy whoosh"],pro:!0},{id:"pro-whoosh-swoosh-pop",name:"Lướt kèm pop",en:"Swoosh + pop",category:"whoosh",duration:1.03,url:"/sfx/pro-whoosh-swoosh-pop.mp3",tags:["swoosh + pop"],pro:!0},{id:"pro-whoosh-glass",name:"Woosh thuỷ tinh",en:"Glassy whoosh",category:"whoosh",duration:1.87,url:"/sfx/pro-whoosh-glass.mp3",tags:["glassy whoosh"],pro:!0},{id:"pro-whoosh-metallic-short",name:"Woosh kim loại ngắn",en:"Short metallic whoosh",category:"whoosh",duration:1.03,url:"/sfx/pro-whoosh-metallic-short.mp3",tags:["short metallic whoosh"],pro:!0},{id:"pro-whoosh-fabric",name:"Vải phất",en:"Fabric flap",category:"whoosh",duration:1.03,url:"/sfx/pro-whoosh-fabric.mp3",tags:["fabric flap"],pro:!0},{id:"pro-swipe-synth-1",name:"Vuốt sạch 1",en:"Clean swipe 1",category:"whoosh",duration:.24,url:"/sfx/pro-swipe-synth-1.mp3",tags:["clean swipe 1"],pro:!0},{id:"pro-swipe-synth-2",name:"Vuốt sạch 2",en:"Clean swipe 2",category:"whoosh",duration:.19,url:"/sfx/pro-swipe-synth-2.mp3",tags:["clean swipe 2"],pro:!0},{id:"pro-swipe-synth-3",name:"Vuốt sạch 3",en:"Clean swipe 3",category:"whoosh",duration:.34,url:"/sfx/pro-swipe-synth-3.mp3",tags:["clean swipe 3"],pro:!0},{id:"pro-swipe-synth-4",name:"Vuốt sạch 4",en:"Clean swipe 4",category:"whoosh",duration:.26,url:"/sfx/pro-swipe-synth-4.mp3",tags:["clean swipe 4"],pro:!0},{id:"pro-swipe-synth-5",name:"Vuốt sạch 5",en:"Clean swipe 5",category:"whoosh",duration:.38,url:"/sfx/pro-swipe-synth-5.mp3",tags:["clean swipe 5"],pro:!0},{id:"pro-swipe-synth-6",name:"Vuốt sạch 6",en:"Clean swipe 6",category:"whoosh",duration:.17,url:"/sfx/pro-swipe-synth-6.mp3",tags:["clean swipe 6"],pro:!0},{id:"pro-swipe-synth-7",name:"Vuốt sạch 7",en:"Clean swipe 7",category:"whoosh",duration:.38,url:"/sfx/pro-swipe-synth-7.mp3",tags:["clean swipe 7"],pro:!0},{id:"pro-swipe-synth-8",name:"Vuốt sạch 8",en:"Clean swipe 8",category:"whoosh",duration:.29,url:"/sfx/pro-swipe-synth-8.mp3",tags:["clean swipe 8"],pro:!0},{id:"pro-swipe-synth-9",name:"Vuốt sạch 9",en:"Clean swipe 9",category:"whoosh",duration:.22,url:"/sfx/pro-swipe-synth-9.mp3",tags:["clean swipe 9"],pro:!0},{id:"pro-swipe-synth-10",name:"Vuốt sạch 10",en:"Clean swipe 10",category:"whoosh",duration:.48,url:"/sfx/pro-swipe-synth-10.mp3",tags:["clean swipe 10"],pro:!0},{id:"pro-trans-swoosh-hit",name:"Lướt + đập",en:"Swoosh + hit",category:"transition",duration:1.03,url:"/sfx/pro-trans-swoosh-hit.mp3",tags:["swoosh + hit"],pro:!0},{id:"pro-trans-whip-pan",name:"Lia máy nhanh",en:"Whip pan",category:"transition",duration:1.03,url:"/sfx/pro-trans-whip-pan.mp3",tags:["whip pan"],pro:!0},{id:"pro-trans-zoom-punch",name:"Zoom đấm",en:"Zoom punch",category:"transition",duration:.82,url:"/sfx/pro-trans-zoom-punch.mp3",tags:["zoom punch"],pro:!0},{id:"pro-trans-page-flip",name:"Lật trang nhanh",en:"Quick page flip",category:"transition",duration:.46,url:"/sfx/pro-trans-page-flip.mp3",tags:["quick page flip"],pro:!0},{id:"pro-trans-slide-panel",name:"Trượt tấm",en:"Panel slide",category:"transition",duration:1.03,url:"/sfx/pro-trans-slide-panel.mp3",tags:["panel slide"],pro:!0},{id:"pro-trans-rewind-short",name:"Tua ngược ngắn",en:"Short rewind",category:"transition",duration:1.03,url:"/sfx/pro-trans-rewind-short.mp3",tags:["short rewind"],pro:!0},{id:"pro-trans-tape-stop-short",name:"Dừng băng ngắn",en:"Short tape stop",category:"transition",duration:1.03,url:"/sfx/pro-trans-tape-stop-short.mp3",tags:["short tape stop"],pro:!0},{id:"pro-trans-glitch-cut",name:"Cắt glitch",en:"Glitch cut",category:"transition",duration:.98,url:"/sfx/pro-trans-glitch-cut.mp3",tags:["glitch cut"],pro:!0},{id:"pro-trans-light-flash",name:"Loé sáng",en:"Light flash",category:"transition",duration:1.03,url:"/sfx/pro-trans-light-flash.mp3",tags:["light flash"],pro:!0},{id:"pro-trans-film-burn",name:"Cháy phim",en:"Film burn",category:"transition",duration:2.02,url:"/sfx/pro-trans-film-burn.mp3",tags:["film burn"],pro:!0},{id:"pro-trans-shutter-click",name:"Màn trập chuyển cảnh",en:"Shutter transition",category:"transition",duration:.96,url:"/sfx/pro-trans-shutter-click.mp3",tags:["shutter transition"],pro:!0},{id:"pro-trans-cloth-wipe",name:"Lau vải chuyển cảnh",en:"Cloth wipe",category:"transition",duration:1.03,url:"/sfx/pro-trans-cloth-wipe.mp3",tags:["cloth wipe"],pro:!0},{id:"pro-trans-magic-poof",name:"Biến mất phép thuật",en:"Magic poof",category:"transition",duration:1.03,url:"/sfx/pro-trans-magic-poof.mp3",tags:["magic poof"],pro:!0},{id:"pro-trans-deep-impact",name:"Va chạm sâu",en:"Deep impact transition",category:"transition",duration:2.04,url:"/sfx/pro-trans-deep-impact.mp3",tags:["deep impact transition"],pro:!0},{id:"pro-trans-riser-hit",name:"Riser + đập",en:"Riser + hit",category:"transition",duration:2.02,url:"/sfx/pro-trans-riser-hit.mp3",tags:["riser + hit"],pro:!0},{id:"pro-chirp-sweep-1",name:"Quét số đi lên 1",en:"Digital chirp sweep 1",category:"transition",duration:.82,url:"/sfx/pro-chirp-sweep-1.mp3",tags:["digital chirp sweep 1"],pro:!0},{id:"pro-chirp-sweep-2",name:"Quét số đi lên 2",en:"Digital chirp sweep 2",category:"transition",duration:.62,url:"/sfx/pro-chirp-sweep-2.mp3",tags:["digital chirp sweep 2"],pro:!0},{id:"pro-chirp-sweep-3",name:"Quét số đi lên 3",en:"Digital chirp sweep 3",category:"transition",duration:1.03,url:"/sfx/pro-chirp-sweep-3.mp3",tags:["digital chirp sweep 3"],pro:!0},{id:"pro-chirp-sweep-4",name:"Quét số đi lên 4",en:"Digital chirp sweep 4",category:"transition",duration:.53,url:"/sfx/pro-chirp-sweep-4.mp3",tags:["digital chirp sweep 4"],pro:!0},{id:"pro-chirp-sweep-5",name:"Quét số đi lên 5",en:"Digital chirp sweep 5",category:"transition",duration:1.22,url:"/sfx/pro-chirp-sweep-5.mp3",tags:["digital chirp sweep 5"],pro:!0},{id:"pro-scan-1",name:"Máy quét 1",en:"Scanner 1",category:"transition",duration:.5,url:"/sfx/pro-scan-1.mp3",tags:["scanner 1"],pro:!0},{id:"pro-scan-2",name:"Máy quét 2",en:"Scanner 2",category:"transition",duration:.41,url:"/sfx/pro-scan-2.mp3",tags:["scanner 2"],pro:!0},{id:"pro-scan-3",name:"Máy quét 3",en:"Scanner 3",category:"transition",duration:.82,url:"/sfx/pro-scan-3.mp3",tags:["scanner 3"],pro:!0},{id:"pro-scan-4",name:"Máy quét 4",en:"Scanner 4",category:"transition",duration:.38,url:"/sfx/pro-scan-4.mp3",tags:["scanner 4"],pro:!0},{id:"pro-scan-5",name:"Máy quét 5",en:"Scanner 5",category:"transition",duration:.72,url:"/sfx/pro-scan-5.mp3",tags:["scanner 5"],pro:!0},{id:"pro-glitch-synth-7",name:"Glitch tổng hợp 7",en:"Synth glitch 7",category:"glitch",duration:.43,url:"/sfx/pro-glitch-synth-7.mp3",tags:["synth glitch 7"],pro:!0},{id:"pro-glitch-synth-8",name:"Glitch tổng hợp 8",en:"Synth glitch 8",category:"glitch",duration:.43,url:"/sfx/pro-glitch-synth-8.mp3",tags:["synth glitch 8"],pro:!0},{id:"pro-glitch-synth-9",name:"Glitch tổng hợp 9",en:"Synth glitch 9",category:"glitch",duration:.43,url:"/sfx/pro-glitch-synth-9.mp3",tags:["synth glitch 9"],pro:!0},{id:"pro-glitch-synth-10",name:"Glitch tổng hợp 10",en:"Synth glitch 10",category:"glitch",duration:.43,url:"/sfx/pro-glitch-synth-10.mp3",tags:["synth glitch 10"],pro:!0},{id:"pro-glitch-synth-11",name:"Glitch tổng hợp 11",en:"Synth glitch 11",category:"glitch",duration:.43,url:"/sfx/pro-glitch-synth-11.mp3",tags:["synth glitch 11"],pro:!0},{id:"pro-glitch-synth-12",name:"Glitch tổng hợp 12",en:"Synth glitch 12",category:"glitch",duration:.43,url:"/sfx/pro-glitch-synth-12.mp3",tags:["synth glitch 12"],pro:!0},{id:"pro-glitch-synth-13",name:"Glitch tổng hợp 13",en:"Synth glitch 13",category:"glitch",duration:.43,url:"/sfx/pro-glitch-synth-13.mp3",tags:["synth glitch 13"],pro:!0},{id:"pro-glitch-synth-14",name:"Glitch tổng hợp 14",en:"Synth glitch 14",category:"glitch",duration:.43,url:"/sfx/pro-glitch-synth-14.mp3",tags:["synth glitch 14"],pro:!0},{id:"pro-glitch-synth-15",name:"Glitch tổng hợp 15",en:"Synth glitch 15",category:"glitch",duration:.43,url:"/sfx/pro-glitch-synth-15.mp3",tags:["synth glitch 15"],pro:!0},{id:"pro-glitch-synth-16",name:"Glitch tổng hợp 16",en:"Synth glitch 16",category:"glitch",duration:.43,url:"/sfx/pro-glitch-synth-16.mp3",tags:["synth glitch 16"],pro:!0},{id:"pro-stutter-4",name:"Giật lặp 4",en:"Stutter 4",category:"glitch",duration:.53,url:"/sfx/pro-stutter-4.mp3",tags:["stutter 4"],pro:!0},{id:"pro-stutter-5",name:"Giật lặp 5",en:"Stutter 5",category:"glitch",duration:.53,url:"/sfx/pro-stutter-5.mp3",tags:["stutter 5"],pro:!0},{id:"pro-stutter-6",name:"Giật lặp 6",en:"Stutter 6",category:"glitch",duration:.53,url:"/sfx/pro-stutter-6.mp3",tags:["stutter 6"],pro:!0},{id:"pro-stutter-7",name:"Giật lặp 7",en:"Stutter 7",category:"glitch",duration:.53,url:"/sfx/pro-stutter-7.mp3",tags:["stutter 7"],pro:!0},{id:"pro-stutter-8",name:"Giật lặp 8",en:"Stutter 8",category:"glitch",duration:.53,url:"/sfx/pro-stutter-8.mp3",tags:["stutter 8"],pro:!0},{id:"pro-stutter-9",name:"Giật lặp 9",en:"Stutter 9",category:"glitch",duration:.53,url:"/sfx/pro-stutter-9.mp3",tags:["stutter 9"],pro:!0},{id:"pro-digital-data-short",name:"Dữ liệu ngắn",en:"Short data burst",category:"glitch",duration:1.03,url:"/sfx/pro-digital-data-short.mp3",tags:["short data burst"],pro:!0},{id:"pro-digital-processing",name:"Đang xử lý",en:"Processing",category:"glitch",duration:1.03,url:"/sfx/pro-digital-processing.mp3",tags:["processing"],pro:!0},{id:"pro-digital-error-glitch",name:"Lỗi glitch",en:"Glitch error",category:"glitch",duration:1.03,url:"/sfx/pro-digital-error-glitch.mp3",tags:["glitch error"],pro:!0},{id:"pro-digital-bitcrush",name:"Bitcrush",en:"Bitcrush hit",category:"glitch",duration:1.03,url:"/sfx/pro-digital-bitcrush.mp3",tags:["bitcrush hit"],pro:!0},{id:"pro-digital-signal-lost",name:"Mất tín hiệu",en:"Signal lost",category:"glitch",duration:.91,url:"/sfx/pro-digital-signal-lost.mp3",tags:["signal lost"],pro:!0},{id:"pro-digital-hologram-on",name:"Bật hologram",en:"Hologram on",category:"glitch",duration:1.03,url:"/sfx/pro-digital-hologram-on.mp3",tags:["hologram on"],pro:!0},{id:"pro-digital-ui-scan",name:"Quét giao diện",en:"UI scan",category:"glitch",duration:1.01,url:"/sfx/pro-digital-ui-scan.mp3",tags:["ui scan"],pro:!0},{id:"pro-digital-download",name:"Tải xuống",en:"Download",category:"glitch",duration:1.03,url:"/sfx/pro-digital-download.mp3",tags:["download"],pro:!0},{id:"pro-digital-zap",name:"Tia điện số",en:"Digital zap",category:"glitch",duration:1.03,url:"/sfx/pro-digital-zap.mp3",tags:["digital zap"],pro:!0},{id:"pro-riser-chirp-1",name:"Riser chirp 1",en:"Chirp riser 1",category:"riser",duration:1.87,url:"/sfx/pro-riser-chirp-1.mp3",tags:["chirp riser 1"],pro:!0},{id:"pro-riser-chirp-2",name:"Riser chirp 2",en:"Chirp riser 2",category:"riser",duration:2.38,url:"/sfx/pro-riser-chirp-2.mp3",tags:["chirp riser 2"],pro:!0},{id:"pro-riser-chirp-3",name:"Riser chirp 3",en:"Chirp riser 3",category:"riser",duration:1.37,url:"/sfx/pro-riser-chirp-3.mp3",tags:["chirp riser 3"],pro:!0},{id:"pro-noise-sweep-1s",name:"Quét nhiễu lên 1s",en:"Noise sweep up 1s",category:"riser",duration:1.25,url:"/sfx/pro-noise-sweep-1s.mp3",tags:["noise sweep up 1s"],pro:!0},{id:"pro-noise-sweep-1-5s",name:"Quét nhiễu lên 1.5s",en:"Noise sweep up 1.5s",category:"riser",duration:1.7,url:"/sfx/pro-noise-sweep-1-5s.mp3",tags:["noise sweep up 1.5s"],pro:!0},{id:"pro-noise-sweep-2-5s",name:"Quét nhiễu lên 2.5s",en:"Noise sweep up 2.5s",category:"riser",duration:2.59,url:"/sfx/pro-noise-sweep-2-5s.mp3",tags:["noise sweep up 2.5s"],pro:!0},{id:"pro-riser-short-tension",name:"Riser căng ngắn",en:"Short tension riser",category:"riser",duration:1.39,url:"/sfx/pro-riser-short-tension.mp3",tags:["short tension riser"],pro:!0},{id:"pro-riser-shimmer",name:"Riser lấp lánh",en:"Shimmer riser",category:"riser",duration:2.4,url:"/sfx/pro-riser-shimmer.mp3",tags:["shimmer riser"],pro:!0},{id:"pro-riser-synth-pluck",name:"Riser nốt synth",en:"Synth pluck riser",category:"riser",duration:2.4,url:"/sfx/pro-riser-synth-pluck.mp3",tags:["synth pluck riser"],pro:!0},{id:"pro-riser-whoosh-up",name:"Riser lướt lên",en:"Whoosh-up riser",category:"riser",duration:1.39,url:"/sfx/pro-riser-whoosh-up.mp3",tags:["whoosh-up riser"],pro:!0},{id:"pro-riser-vocal-swell",name:"Riser hợp xướng",en:"Choir swell",category:"riser",duration:2.4,url:"/sfx/pro-riser-vocal-swell.mp3",tags:["choir swell"],pro:!0},{id:"pro-riser-drum-roll",name:"Trống dồn ngắn",en:"Short drum roll",category:"riser",duration:1.73,url:"/sfx/pro-riser-drum-roll.mp3",tags:["short drum roll"],pro:!0},{id:"pro-riser-reverse-piano",name:"Piano ngược",en:"Reverse piano",category:"riser",duration:2.4,url:"/sfx/pro-riser-reverse-piano.mp3",tags:["reverse piano"],pro:!0},{id:"pro-riser-electric",name:"Riser điện",en:"Electric riser",category:"riser",duration:2.23,url:"/sfx/pro-riser-electric.mp3",tags:["electric riser"],pro:!0},{id:"pro-riser-heartbeat",name:"Tim đập nhanh dần",en:"Heartbeat build",category:"riser",duration:3.36,url:"/sfx/pro-riser-heartbeat.mp3",tags:["heartbeat build"],pro:!0},{id:"pro-bloop-1",name:"Bloop 1",en:"Bloop 1",category:"pop",duration:.17,url:"/sfx/pro-bloop-1.mp3",tags:["bloop 1"],pro:!0},{id:"pro-bloop-2",name:"Bloop 2",en:"Bloop 2",category:"pop",duration:.14,url:"/sfx/pro-bloop-2.mp3",tags:["bloop 2"],pro:!0},{id:"pro-bloop-3",name:"Bloop 3",en:"Bloop 3",category:"pop",duration:.22,url:"/sfx/pro-bloop-3.mp3",tags:["bloop 3"],pro:!0},{id:"pro-bloop-4",name:"Bloop 4",en:"Bloop 4",category:"pop",duration:.12,url:"/sfx/pro-bloop-4.mp3",tags:["bloop 4"],pro:!0},{id:"pro-bloop-5",name:"Bloop 5",en:"Bloop 5",category:"pop",duration:.14,url:"/sfx/pro-bloop-5.mp3",tags:["bloop 5"],pro:!0},{id:"pro-popup-1",name:"Pop hiện 1",en:"Pop-up 1",category:"pop",duration:.19,url:"/sfx/pro-popup-1.mp3",tags:["pop-up 1"],pro:!0},{id:"pro-popup-2",name:"Pop hiện 2",en:"Pop-up 2",category:"pop",duration:.19,url:"/sfx/pro-popup-2.mp3",tags:["pop-up 2"],pro:!0},{id:"pro-popup-3",name:"Pop hiện 3",en:"Pop-up 3",category:"pop",duration:.19,url:"/sfx/pro-popup-3.mp3",tags:["pop-up 3"],pro:!0},{id:"pro-pop-cork-small",name:"Bật nút nhỏ",en:"Small cork pop",category:"pop",duration:.96,url:"/sfx/pro-pop-cork-small.mp3",tags:["small cork pop"],pro:!0},{id:"pro-pop-bubble-cute",name:"Bong bóng dễ thương",en:"Cute bubble pop",category:"pop",duration:.31,url:"/sfx/pro-pop-bubble-cute.mp3",tags:["cute bubble pop"],pro:!0},{id:"pro-pop-finger-mouth",name:"Pop miệng",en:"Mouth pop",category:"pop",duration:.14,url:"/sfx/pro-pop-finger-mouth.mp3",tags:["mouth pop"],pro:!0},{id:"pro-pop-balloon-small",name:"Bóng bay nổ nhỏ",en:"Small balloon pop",category:"pop",duration:.86,url:"/sfx/pro-pop-balloon-small.mp3",tags:["small balloon pop"],pro:!0},{id:"pro-pop-plastic",name:"Pop nhựa",en:"Plastic pop",category:"pop",duration:1.03,url:"/sfx/pro-pop-plastic.mp3",tags:["plastic pop"],pro:!0},{id:"pro-pop-suction",name:"Hút bật",en:"Suction pop",category:"pop",duration:.14,url:"/sfx/pro-pop-suction.mp3",tags:["suction pop"],pro:!0},{id:"pro-pop-jelly",name:"Pop thạch",en:"Jelly pop",category:"pop",duration:.14,url:"/sfx/pro-pop-jelly.mp3",tags:["jelly pop"],pro:!0},{id:"pro-hit-snap-text",name:"Đập chữ",en:"Text snap",category:"impact",duration:1.34,url:"/sfx/pro-hit-snap-text.mp3",tags:["text snap"],pro:!0},{id:"pro-hit-thump-soft",name:"Thump mềm",en:"Soft thump",category:"impact",duration:1.34,url:"/sfx/pro-hit-thump-soft.mp3",tags:["soft thump"],pro:!0},{id:"pro-hit-tom",name:"Trống tom",en:"Tom hit",category:"impact",duration:1.34,url:"/sfx/pro-hit-tom.mp3",tags:["tom hit"],pro:!0},{id:"pro-hit-clap-snap",name:"Vỗ tay snap",en:"Clap snap",category:"impact",duration:1.34,url:"/sfx/pro-hit-clap-snap.mp3",tags:["clap snap"],pro:!0},{id:"pro-hit-kick-punch",name:"Kick đấm",en:"Punch kick",category:"impact",duration:1.34,url:"/sfx/pro-hit-kick-punch.mp3",tags:["punch kick"],pro:!0},{id:"pro-hit-wood-block",name:"Mõ gỗ",en:"Wood block",category:"impact",duration:1.22,url:"/sfx/pro-hit-wood-block.mp3",tags:["wood block"],pro:!0},{id:"pro-hit-metal-ping",name:"Ping kim loại",en:"Metal ping",category:"impact",duration:.62,url:"/sfx/pro-hit-metal-ping.mp3",tags:["metal ping"],pro:!0},{id:"pro-hit-sub-short",name:"Sub ngắn",en:"Short sub hit",category:"impact",duration:1.32,url:"/sfx/pro-hit-sub-short.mp3",tags:["short sub hit"],pro:!0},{id:"pro-hit-cinematic-short",name:"Đập điện ảnh ngắn",en:"Short cinematic hit",category:"impact",duration:1.34,url:"/sfx/pro-hit-cinematic-short.mp3",tags:["short cinematic hit"],pro:!0},{id:"pro-hit-glass-tap",name:"Gõ ly",en:"Glass tap hit",category:"impact",duration:1.13,url:"/sfx/pro-hit-glass-tap.mp3",tags:["glass tap hit"],pro:!0},{id:"pro-hit-cardboard",name:"Hộp giấy",en:"Cardboard thump",category:"impact",duration:1.34,url:"/sfx/pro-hit-cardboard.mp3",tags:["cardboard thump"],pro:!0},{id:"pro-hit-book-slam",name:"Đập sách",en:"Book slam",category:"impact",duration:1.32,url:"/sfx/pro-hit-book-slam.mp3",tags:["book slam"],pro:!0},{id:"pro-hit-stamp",name:"Đóng dấu",en:"Stamp hit",category:"impact",duration:1.34,url:"/sfx/pro-hit-stamp.mp3",tags:["stamp hit"],pro:!0},{id:"pro-hit-door-knock-one",name:"Gõ cửa một cái",en:"Single knock",category:"impact",duration:1.1,url:"/sfx/pro-hit-door-knock-one.mp3",tags:["single knock"],pro:!0},{id:"pro-hit-bass-drop-short",name:"Bass drop ngắn",en:"Short bass drop",category:"impact",duration:1.34,url:"/sfx/pro-hit-bass-drop-short.mp3",tags:["short bass drop"],pro:!0},{id:"pro-ui-coin-collect",name:"Nhận xu",en:"Coin collect",category:"ui",duration:1.03,url:"/sfx/pro-ui-coin-collect.mp3",tags:["coin collect"],pro:!0},{id:"pro-ui-level-complete",name:"Hoàn thành cấp",en:"Level complete",category:"ui",duration:.96,url:"/sfx/pro-ui-level-complete.mp3",tags:["level complete"],pro:!0},{id:"pro-ui-heart-like",name:"Thả tim",en:"Heart like",category:"ui",duration:.67,url:"/sfx/pro-ui-heart-like.mp3",tags:["heart like"],pro:!0},{id:"pro-ui-upload-done",name:"Tải lên xong",en:"Upload done",category:"ui",duration:.62,url:"/sfx/pro-ui-upload-done.mp3",tags:["upload done"],pro:!0},{id:"pro-glitch-crackle",name:"Lách tách glitch",en:"Glitch crackle",category:"glitch",duration:.31,url:"/sfx/pro-glitch-crackle.mp3",tags:["glitch crackle"],pro:!0},{id:"pro-impact-whoosh-sub",name:"Woosh + sub ngắn",en:"Whoosh + sub hit",category:"impact",duration:.72,url:"/sfx/pro-impact-whoosh-sub.mp3",tags:["whoosh + sub hit"],pro:!0},{id:"pro-shutter-tick-1",name:"Tick màn trập 1",en:"Shutter tick 1",category:"camera",duration:.12,url:"/sfx/pro-shutter-tick-1.mp3",tags:["shutter tick 1"],pro:!0},{id:"pro-shutter-tick-2",name:"Tick màn trập 2",en:"Shutter tick 2",category:"camera",duration:.12,url:"/sfx/pro-shutter-tick-2.mp3",tags:["shutter tick 2"],pro:!0},{id:"pro-shutter-tick-3",name:"Tick màn trập 3",en:"Shutter tick 3",category:"camera",duration:.12,url:"/sfx/pro-shutter-tick-3.mp3",tags:["shutter tick 3"],pro:!0},{id:"pro-swish-air-wide",name:"Lướt gió rộng",en:"Wide air swish",category:"whoosh",duration:.41,url:"/sfx/pro-swish-air-wide.mp3",tags:["wide air swish"],pro:!0},{id:"pro-riser-whistle-stop",name:"Riser huýt dừng gắt",en:"Whistle riser, hard stop",category:"riser",duration:.6,url:"/sfx/pro-riser-whistle-stop.mp3",tags:["whistle riser, hard stop"],pro:!0},{id:"pro-flash-burst",name:"Loé flash",en:"Flash burst",category:"transition",duration:.53,url:"/sfx/pro-flash-burst.mp3",tags:["flash burst"],pro:!0},{id:"pro-swell-impact",name:"Phồng lên + đập",en:"Swell into impact",category:"transition",duration:.62,url:"/sfx/pro-swell-impact.mp3",tags:["swell into impact"],pro:!0},{id:"pro-fight-punch-jab-quick",name:"Đấm nhanh",en:"Quick jab punch",category:"fight",duration:.82,url:"/sfx/pro-fight-punch-jab-quick.mp3",tags:["quick jab punch"],pro:!0},{id:"pro-fight-punch-heavy-hook",name:"Đấm móc mạnh",en:"Heavy hook punch",category:"fight",duration:1.34,url:"/sfx/pro-fight-punch-heavy-hook.mp3",tags:["heavy hook punch"],pro:!0},{id:"pro-fight-punch-combo-3",name:"Combo 3 cú đấm",en:"Three-punch combo",category:"fight",duration:2.09,url:"/sfx/pro-fight-punch-combo-3.mp3",tags:["three-punch combo"],pro:!0},{id:"pro-fight-punch-anime",name:"Đấm kiểu anime",en:"Anime punch impact",category:"fight",duration:1.34,url:"/sfx/pro-fight-punch-anime.mp3",tags:["anime punch impact"],pro:!0},{id:"pro-fight-punch-body-blow",name:"Đấm vào bụng",en:"Body blow",category:"fight",duration:1.06,url:"/sfx/pro-fight-punch-body-blow.mp3",tags:["body blow"],pro:!0},{id:"pro-fight-kick-roundhouse",name:"Đá vòng cầu",en:"Roundhouse kick",category:"fight",duration:1.34,url:"/sfx/pro-fight-kick-roundhouse.mp3",tags:["roundhouse kick"],pro:!0},{id:"pro-fight-kick-flying",name:"Phi cước",en:"Flying kick",category:"fight",duration:2.09,url:"/sfx/pro-fight-kick-flying.mp3",tags:["flying kick"],pro:!0},{id:"pro-fight-kick-heavy-bag",name:"Đá bao cát",en:"Heavy bag kick",category:"fight",duration:1.34,url:"/sfx/pro-fight-kick-heavy-bag.mp3",tags:["heavy bag kick"],pro:!0},{id:"pro-fight-block-forearm",name:"Đỡ đòn bằng tay",en:"Forearm block",category:"fight",duration:.89,url:"/sfx/pro-fight-block-forearm.mp3",tags:["forearm block"],pro:!0},{id:"pro-fight-block-parry",name:"Gạt đòn",en:"Palm parry",category:"fight",duration:.94,url:"/sfx/pro-fight-block-parry.mp3",tags:["palm parry"],pro:!0},{id:"pro-fight-body-slam",name:"Quật ngã",en:"Body slam",category:"fight",duration:1.68,url:"/sfx/pro-fight-body-slam.mp3",tags:["body slam"],pro:!0},{id:"pro-fight-fall-mat",name:"Ngã xuống thảm",en:"Fall on a mat",category:"fight",duration:1.06,url:"/sfx/pro-fight-fall-mat.mp3",tags:["fall on a mat"],pro:!0},{id:"pro-fight-joint-crack",name:"Rắc khớp",en:"Joint crack",category:"fight",duration:.14,url:"/sfx/pro-fight-joint-crack.mp3",tags:["joint crack"],pro:!0},{id:"pro-fight-knuckle-crack",name:"Bẻ khớp tay",en:"Knuckle crack",category:"fight",duration:.22,url:"/sfx/pro-fight-knuckle-crack.mp3",tags:["knuckle crack"],pro:!0},{id:"pro-fight-cloth-whip",name:"Vung áo",en:"Cloth whip",category:"fight",duration:1.03,url:"/sfx/pro-fight-cloth-whip.mp3",tags:["cloth whip"],pro:!0},{id:"pro-fight-stance-rustle",name:"Thủ thế",en:"Fighting stance rustle",category:"fight",duration:.55,url:"/sfx/pro-fight-stance-rustle.mp3",tags:["fighting stance rustle"],pro:!0},{id:"pro-fight-arm-swing-fast",name:"Vung tay nhanh",en:"Fast arm swing",category:"fight",duration:1.03,url:"/sfx/pro-fight-arm-swing-fast.mp3",tags:["fast arm swing"],pro:!0},{id:"pro-fight-katana-draw",name:"Rút kiếm katana",en:"Katana draw",category:"fight",duration:1.22,url:"/sfx/pro-fight-katana-draw.mp3",tags:["katana draw"],pro:!0},{id:"pro-fight-katana-sheathe",name:"Tra kiếm vào bao",en:"Katana sheathe",category:"fight",duration:.48,url:"/sfx/pro-fight-katana-sheathe.mp3",tags:["katana sheathe"],pro:!0},{id:"pro-fight-katana-slash",name:"Chém katana",en:"Katana slash",category:"fight",duration:.82,url:"/sfx/pro-fight-katana-slash.mp3",tags:["katana slash"],pro:!0},{id:"pro-fight-sword-clash-ring",name:"Kiếm chạm ngân dài",en:"Sword clash, long ring",category:"fight",duration:1.61,url:"/sfx/pro-fight-sword-clash-ring.mp3",tags:["sword clash, long ring"],pro:!0},{id:"pro-fight-blade-scrape",name:"Kiếm cọ kiếm",en:"Blade scrape",category:"fight",duration:2.35,url:"/sfx/pro-fight-blade-scrape.mp3",tags:["blade scrape"],pro:!0},{id:"pro-fight-sword-flurry",name:"Đấu kiếm liên hoàn",en:"Sword flurry",category:"fight",duration:3.07,url:"/sfx/pro-fight-sword-flurry.mp3",tags:["sword flurry"],pro:!0},{id:"pro-fight-staff-spin",name:"Xoay côn",en:"Staff spin",category:"fight",duration:1.06,url:"/sfx/pro-fight-staff-spin.mp3",tags:["staff spin"],pro:!0},{id:"pro-fight-staff-clack",name:"Côn gỗ va nhau",en:"Staff clack",category:"fight",duration:.29,url:"/sfx/pro-fight-staff-clack.mp3",tags:["staff clack"],pro:!0},{id:"pro-fight-shuriken-throw",name:"Phi tiêu ninja",en:"Shuriken throw",category:"fight",duration:.79,url:"/sfx/pro-fight-shuriken-throw.mp3",tags:["shuriken throw"],pro:!0},{id:"pro-fight-shuriken-hit",name:"Phi tiêu cắm gỗ",en:"Shuriken hits wood",category:"fight",duration:1.03,url:"/sfx/pro-fight-shuriken-hit.mp3",tags:["shuriken hits wood"],pro:!0},{id:"pro-fight-chain-swing",name:"Vung xích",en:"Chain swing",category:"fight",duration:2.33,url:"/sfx/pro-fight-chain-swing.mp3",tags:["chain swing"],pro:!0},{id:"pro-fight-nunchaku",name:"Côn nhị khúc",en:"Nunchaku twirl",category:"fight",duration:2.04,url:"/sfx/pro-fight-nunchaku.mp3",tags:["nunchaku twirl"],pro:!0},{id:"pro-fight-ground-pound",name:"Đấm xuống đất",en:"Ground pound",category:"fight",duration:2.14,url:"/sfx/pro-fight-ground-pound.mp3",tags:["ground pound"],pro:!0},{id:"pro-magic-powerup-charge",name:"Gồng năng lượng",en:"Power-up charge",category:"magic",duration:3.34,url:"/sfx/pro-magic-powerup-charge.mp3",tags:["power-up charge"],pro:!0},{id:"pro-magic-powerup-burst",name:"Bùng nổ sức mạnh",en:"Power-up burst",category:"magic",duration:2.33,url:"/sfx/pro-magic-powerup-burst.mp3",tags:["power-up burst"],pro:!0},{id:"pro-magic-aura-hum",name:"Hào quang ngân (lặp)",en:"Aura hum loop",category:"magic",duration:8.14,url:"/sfx/pro-magic-aura-hum.mp3",tags:["aura hum loop"],pro:!0},{id:"pro-magic-energy-blast",name:"Chưởng năng lượng",en:"Energy blast",category:"magic",duration:2.23,url:"/sfx/pro-magic-energy-blast.mp3",tags:["energy blast"],pro:!0},{id:"pro-magic-energy-ball",name:"Tụ cầu năng lượng",en:"Energy ball forming",category:"magic",duration:1.61,url:"/sfx/pro-magic-energy-ball.mp3",tags:["energy ball forming"],pro:!0},{id:"pro-magic-beam-long",name:"Tia năng lượng dài",en:"Long energy beam",category:"magic",duration:2.83,url:"/sfx/pro-magic-beam-long.mp3",tags:["long energy beam"],pro:!0},{id:"pro-magic-teleport-in",name:"Dịch chuyển xuất hiện",en:"Teleport in",category:"magic",duration:.91,url:"/sfx/pro-magic-teleport-in.mp3",tags:["teleport in"],pro:!0},{id:"pro-magic-teleport-out",name:"Dịch chuyển biến mất",en:"Teleport out",category:"magic",duration:.79,url:"/sfx/pro-magic-teleport-out.mp3",tags:["teleport out"],pro:!0},{id:"pro-magic-shield-up",name:"Bật khiên phép",en:"Shield up",category:"magic",duration:2.26,url:"/sfx/pro-magic-shield-up.mp3",tags:["shield up"],pro:!0},{id:"pro-magic-shield-hit",name:"Đòn đập vào khiên",en:"Shield hit",category:"magic",duration:1.3,url:"/sfx/pro-magic-shield-hit.mp3",tags:["shield hit"],pro:!0},{id:"pro-magic-spell-cast",name:"Niệm phép",en:"Spell cast",category:"magic",duration:2.35,url:"/sfx/pro-magic-spell-cast.mp3",tags:["spell cast"],pro:!0},{id:"pro-magic-spell-dark",name:"Phép hắc ám",en:"Dark spell",category:"magic",duration:2.35,url:"/sfx/pro-magic-spell-dark.mp3",tags:["dark spell"],pro:!0},{id:"pro-magic-sparkle-shimmer",name:"Lấp lánh",en:"Sparkle shimmer",category:"magic",duration:2.28,url:"/sfx/pro-magic-sparkle-shimmer.mp3",tags:["sparkle shimmer"],pro:!0},{id:"pro-magic-lightning-strike",name:"Sét phép thuật",en:"Magic lightning strike",category:"magic",duration:2.33,url:"/sfx/pro-magic-lightning-strike.mp3",tags:["magic lightning strike"],pro:!0},{id:"pro-magic-electric-arc",name:"Điện xẹt",en:"Electric arc crackle",category:"magic",duration:2.16,url:"/sfx/pro-magic-electric-arc.mp3",tags:["electric arc crackle"],pro:!0},{id:"pro-magic-ice-freeze",name:"Đóng băng",en:"Ice freeze",category:"magic",duration:2.3,url:"/sfx/pro-magic-ice-freeze.mp3",tags:["ice freeze"],pro:!0},{id:"pro-magic-ice-shatter",name:"Băng vỡ vụn",en:"Ice shatter",category:"magic",duration:1.06,url:"/sfx/pro-magic-ice-shatter.mp3",tags:["ice shatter"],pro:!0},{id:"pro-magic-fire-burst",name:"Bùng lửa",en:"Fire burst",category:"magic",duration:2.02,url:"/sfx/pro-magic-fire-burst.mp3",tags:["fire burst"],pro:!0},{id:"pro-magic-fire-breath",name:"Phun lửa",en:"Fire breath",category:"magic",duration:3.36,url:"/sfx/pro-magic-fire-breath.mp3",tags:["fire breath"],pro:!0},{id:"pro-magic-wind-spell",name:"Phép gió",en:"Wind spell",category:"magic",duration:2.04,url:"/sfx/pro-magic-wind-spell.mp3",tags:["wind spell"],pro:!0},{id:"pro-magic-heal",name:"Phép hồi phục",en:"Healing spell",category:"magic",duration:2.28,url:"/sfx/pro-magic-heal.mp3",tags:["healing spell"],pro:!0},{id:"pro-magic-portal-open",name:"Mở cổng không gian",en:"Portal open",category:"magic",duration:3.36,url:"/sfx/pro-magic-portal-open.mp3",tags:["portal open"],pro:!0},{id:"pro-magic-twinkle-up",name:"Chuỗi lấp lánh lên",en:"Twinkle run up",category:"magic",duration:1.03,url:"/sfx/pro-magic-twinkle-up.mp3",tags:["twinkle run up"],pro:!0},{id:"pro-magic-sparkle-fall",name:"Lấp lánh rơi xuống",en:"Sparkle fall",category:"magic",duration:1.03,url:"/sfx/pro-magic-sparkle-fall.mp3",tags:["sparkle fall"],pro:!0},{id:"pro-magic-mana-charge",name:"Tụ mana",en:"Mana charge",category:"magic",duration:2.88,url:"/sfx/pro-magic-mana-charge.mp3",tags:["mana charge"],pro:!0},{id:"pro-trailer-deep-hit",name:"Hit trầm trailer",en:"Deep trailer hit",category:"trailer",duration:3.34,url:"/sfx/pro-trailer-deep-hit.mp3",tags:["deep trailer hit"],pro:!0},{id:"pro-trailer-braam-short",name:"Braam ngắn",en:"Short braam",category:"trailer",duration:3.22,url:"/sfx/pro-trailer-braam-short.mp3",tags:["short braam"],pro:!0},{id:"pro-trailer-braam-rising",name:"Braam dâng",en:"Rising braam",category:"trailer",duration:3.02,url:"/sfx/pro-trailer-braam-rising.mp3",tags:["rising braam"],pro:!0},{id:"pro-trailer-metal-hit",name:"Hit kim loại",en:"Metallic trailer hit",category:"trailer",duration:2.74,url:"/sfx/pro-trailer-metal-hit.mp3",tags:["metallic trailer hit"],pro:!0},{id:"pro-trailer-metal-scrape-hit",name:"Cào kim loại + hit",en:"Metal scrape into hit",category:"trailer",duration:2.81,url:"/sfx/pro-trailer-metal-scrape-hit.mp3",tags:["metal scrape into hit"],pro:!0},{id:"pro-trailer-boom-distant",name:"Boom vọng xa",en:"Distant boom",category:"trailer",duration:3.34,url:"/sfx/pro-trailer-boom-distant.mp3",tags:["distant boom"],pro:!0},{id:"pro-trailer-taiko-hit",name:"Trống taiko",en:"Taiko hit",category:"trailer",duration:2.33,url:"/sfx/pro-trailer-taiko-hit.mp3",tags:["taiko hit"],pro:!0},{id:"pro-trailer-string-sting",name:"Sting dây căng",en:"String tension sting",category:"trailer",duration:3.38,url:"/sfx/pro-trailer-string-sting.mp3",tags:["string tension sting"],pro:!0},{id:"pro-trailer-reverse-swell",name:"Swell ngược",en:"Reverse swell",category:"trailer",duration:2.09,url:"/sfx/pro-trailer-reverse-swell.mp3",tags:["reverse swell"],pro:!0},{id:"pro-trailer-reverse-whoosh-stop",name:"Woosh ngược dừng gắt",en:"Reverse whoosh, hard stop",category:"trailer",duration:2.98,url:"/sfx/pro-trailer-reverse-whoosh-stop.mp3",tags:["reverse whoosh, hard stop"],pro:!0},{id:"pro-trailer-whoosh-hit",name:"Woosh + hit",en:"Whoosh into hit",category:"trailer",duration:2.09,url:"/sfx/pro-trailer-whoosh-hit.mp3",tags:["whoosh into hit"],pro:!0},{id:"pro-trailer-clock-tick",name:"Tích tắc trailer",en:"Trailer clock ticks",category:"trailer",duration:3.31,url:"/sfx/pro-trailer-clock-tick.mp3",tags:["trailer clock ticks"],pro:!0},{id:"pro-trailer-glass-hit",name:"Hit kính lạnh",en:"Glassy trailer hit",category:"trailer",duration:2.33,url:"/sfx/pro-trailer-glass-hit.mp3",tags:["glassy trailer hit"],pro:!0},{id:"pro-trailer-low-pulse",name:"Nhịp trầm (lặp)",en:"Low pulse loop",category:"trailer",duration:6.38,url:"/sfx/pro-trailer-low-pulse.mp3",tags:["low pulse loop"],pro:!0},{id:"pro-trailer-title-slam",name:"Cú chốt tiêu đề",en:"Title slam",category:"trailer",duration:3.31,url:"/sfx/pro-trailer-title-slam.mp3",tags:["title slam"],pro:!0},{id:"pro-trailer-vault-door",name:"Cửa thép khổng lồ",en:"Giant door boom",category:"trailer",duration:3.24,url:"/sfx/pro-trailer-vault-door.mp3",tags:["giant door boom"],pro:!0},{id:"pro-trailer-subdrop-3s",name:"Sub drop 3s",en:"Sub drop 3s",category:"trailer",duration:2.95,url:"/sfx/pro-trailer-subdrop-3s.mp3",tags:["sub drop 3s"],pro:!0},{id:"pro-trailer-subdrop-6s",name:"Sub drop dài 6s",en:"Long sub drop 6s",category:"trailer",duration:2.93,url:"/sfx/pro-trailer-subdrop-6s.mp3",tags:["long sub drop 6s"],pro:!0},{id:"pro-trailer-riser-8s",name:"Riser trailer 8s",en:"Trailer riser 8s",category:"trailer",duration:7.27,url:"/sfx/pro-trailer-riser-8s.mp3",tags:["trailer riser 8s"],pro:!0},{id:"pro-trailer-downlifter-6s",name:"Downlifter 6s",en:"Downlifter 6s",category:"trailer",duration:6.14,url:"/sfx/pro-trailer-downlifter-6s.mp3",tags:["downlifter 6s"],pro:!0},{id:"pro-suspense-heartbeat-slow",name:"Tim đập chậm (lặp)",en:"Slow heartbeat loop",category:"suspense",duration:6.34,url:"/sfx/pro-suspense-heartbeat-slow.mp3",tags:["slow heartbeat loop"],pro:!0},{id:"pro-suspense-heartbeat-fast",name:"Tim đập dồn dập (lặp)",en:"Racing heartbeat loop",category:"suspense",duration:6.26,url:"/sfx/pro-suspense-heartbeat-fast.mp3",tags:["racing heartbeat loop"],pro:!0},{id:"pro-suspense-drone-dark",name:"Drone u tối",en:"Dark tension drone",category:"suspense",duration:10.37,url:"/sfx/pro-suspense-drone-dark.mp3",tags:["dark tension drone"],pro:!0},{id:"pro-suspense-drone-metal",name:"Drone kim loại",en:"Metallic drone",category:"suspense",duration:8.38,url:"/sfx/pro-suspense-drone-metal.mp3",tags:["metallic drone"],pro:!0},{id:"pro-suspense-stinger-horror",name:"Stinger kinh dị",en:"Horror stinger",category:"suspense",duration:2.28,url:"/sfx/pro-suspense-stinger-horror.mp3",tags:["horror stinger"],pro:!0},{id:"pro-suspense-jump-scare",name:"Hù dọa",en:"Jump scare hit",category:"suspense",duration:1.34,url:"/sfx/pro-suspense-jump-scare.mp3",tags:["jump scare hit"],pro:!0},{id:"pro-suspense-door-creak",name:"Cửa kẽo kẹt",en:"Creaking door",category:"suspense",duration:3.36,url:"/sfx/pro-suspense-door-creak.mp3",tags:["creaking door"],pro:!0},{id:"pro-suspense-floor-creak",name:"Sàn gỗ kẽo kẹt",en:"Creaking floorboard",category:"suspense",duration:2.35,url:"/sfx/pro-suspense-floor-creak.mp3",tags:["creaking floorboard"],pro:!0},{id:"pro-suspense-wind-whisper",name:"Gió rít như thì thầm",en:"Whispering wind",category:"suspense",duration:8.38,url:"/sfx/pro-suspense-wind-whisper.mp3",tags:["whispering wind"],pro:!0},{id:"pro-suspense-wind-howl",name:"Gió hú rợn người",en:"Eerie wind howl",category:"suspense",duration:8.38,url:"/sfx/pro-suspense-wind-howl.mp3",tags:["eerie wind howl"],pro:!0},{id:"pro-suspense-clock-ticking",name:"Đồng hồ tích tắc",en:"Ticking clock",category:"suspense",duration:6.34,url:"/sfx/pro-suspense-clock-ticking.mp3",tags:["ticking clock"],pro:!0},{id:"pro-suspense-footsteps-approach",name:"Bước chân đến gần",en:"Approaching footsteps",category:"suspense",duration:2.98,url:"/sfx/pro-suspense-footsteps-approach.mp3",tags:["approaching footsteps"],pro:!0},{id:"pro-suspense-chains-rattle",name:"Xích lạch cạch",en:"Rattling chains",category:"suspense",duration:3,url:"/sfx/pro-suspense-chains-rattle.mp3",tags:["rattling chains"],pro:!0},{id:"pro-suspense-cellar-drips",name:"Nước nhỏ giọt hầm tối",en:"Dripping in the dark",category:"suspense",duration:8.38,url:"/sfx/pro-suspense-cellar-drips.mp3",tags:["dripping in the dark"],pro:!0},{id:"pro-suspense-metal-screech",name:"Rít kim loại",en:"Metal screech",category:"suspense",duration:2.4,url:"/sfx/pro-suspense-metal-screech.mp3",tags:["metal screech"],pro:!0},{id:"pro-suspense-thud-upstairs",name:"Tiếng động trên lầu",en:"Thud upstairs",category:"suspense",duration:2.35,url:"/sfx/pro-suspense-thud-upstairs.mp3",tags:["thud upstairs"],pro:!0},{id:"pro-suspense-radio-static",name:"Nhiễu radio (lặp)",en:"Radio static loop",category:"suspense",duration:6.38,url:"/sfx/pro-suspense-radio-static.mp3",tags:["radio static loop"],pro:!0},{id:"pro-suspense-low-hit",name:"Hit hồi hộp",en:"Low suspense hit",category:"suspense",duration:2.33,url:"/sfx/pro-suspense-low-hit.mp3",tags:["low suspense hit"],pro:!0},{id:"pro-suspense-tension-build-10s",name:"Căng thẳng dâng 10s",en:"Tension build 10s",category:"suspense",duration:9.19,url:"/sfx/pro-suspense-tension-build-10s.mp3",tags:["tension build 10s"],pro:!0},{id:"pro-suspense-noise-swell-4s",name:"Nhiễu dâng 4s",en:"Noise swell 4s",category:"suspense",duration:3.94,url:"/sfx/pro-suspense-noise-swell-4s.mp3",tags:["noise swell 4s"],pro:!0},{id:"pro-sport-ball-kick",name:"Sút bóng",en:"Football kick",category:"sport",duration:.24,url:"/sfx/pro-sport-ball-kick.mp3",tags:["football kick"],pro:!0},{id:"pro-sport-ball-net",name:"Bóng vào lưới",en:"Ball into the net",category:"sport",duration:.94,url:"/sfx/pro-sport-ball-net.mp3",tags:["ball into the net"],pro:!0},{id:"pro-sport-ball-post",name:"Bóng trúng cột",en:"Ball hits the post",category:"sport",duration:1.34,url:"/sfx/pro-sport-ball-post.mp3",tags:["ball hits the post"],pro:!0},{id:"pro-sport-basketball-dribble",name:"Bóng rổ nảy",en:"Basketball dribble",category:"sport",duration:3.34,url:"/sfx/pro-sport-basketball-dribble.mp3",tags:["basketball dribble"],pro:!0},{id:"pro-sport-net-swish",name:"Bóng lọt rổ",en:"Net swish",category:"sport",duration:.82,url:"/sfx/pro-sport-net-swish.mp3",tags:["net swish"],pro:!0},{id:"pro-sport-rim-clang",name:"Bóng chạm vành",en:"Rim clang",category:"sport",duration:.74,url:"/sfx/pro-sport-rim-clang.mp3",tags:["rim clang"],pro:!0},{id:"pro-sport-sneaker-squeak",name:"Giày rít sân",en:"Sneaker squeak",category:"sport",duration:1.34,url:"/sfx/pro-sport-sneaker-squeak.mp3",tags:["sneaker squeak"],pro:!0},{id:"pro-sport-referee-whistle",name:"Còi trọng tài",en:"Referee whistle",category:"sport",duration:.74,url:"/sfx/pro-sport-referee-whistle.mp3",tags:["referee whistle"],pro:!0},{id:"pro-sport-final-whistle",name:"Còi hết trận",en:"Final whistle",category:"sport",duration:2.45,url:"/sfx/pro-sport-final-whistle.mp3",tags:["final whistle"],pro:!0},{id:"pro-sport-crowd-goal",name:"Khán giả ăn mừng bàn thắng",en:"Goal celebration roar",category:"sport",duration:3.38,url:"/sfx/pro-sport-crowd-goal.mp3",tags:["goal celebration roar"],pro:!0},{id:"pro-sport-crowd-ooh",name:"Khán giả tiếc nuối",en:"Crowd near-miss groan",category:"sport",duration:2.3,url:"/sfx/pro-sport-crowd-ooh.mp3",tags:["crowd near-miss groan"],pro:!0},{id:"pro-sport-crowd-clap-rhythm",name:"Khán giả vỗ tay theo nhịp",en:"Rhythmic crowd clapping",category:"sport",duration:6.38,url:"/sfx/pro-sport-crowd-clap-rhythm.mp3",tags:["rhythmic crowd clapping"],pro:!0},{id:"pro-sport-arena-ambience",name:"Không khí nhà thi đấu",en:"Indoor arena ambience",category:"sport",duration:10.37,url:"/sfx/pro-sport-arena-ambience.mp3",tags:["indoor arena ambience"],pro:!0},{id:"pro-sport-bat-hit",name:"Gậy bóng chày",en:"Baseball bat hit",category:"sport",duration:.58,url:"/sfx/pro-sport-bat-hit.mp3",tags:["baseball bat hit"],pro:!0},{id:"pro-sport-tennis-hit",name:"Đánh tennis",en:"Tennis racket hit",category:"sport",duration:1.06,url:"/sfx/pro-sport-tennis-hit.mp3",tags:["tennis racket hit"],pro:!0},{id:"pro-sport-golf-swing",name:"Đánh golf",en:"Golf swing",category:"sport",duration:2.28,url:"/sfx/pro-sport-golf-swing.mp3",tags:["golf swing"],pro:!0},{id:"pro-sport-volleyball-spike",name:"Đập bóng chuyền",en:"Volleyball spike",category:"sport",duration:1.06,url:"/sfx/pro-sport-volleyball-spike.mp3",tags:["volleyball spike"],pro:!0},{id:"pro-sport-boxing-bell",name:"Chuông võ đài",en:"Boxing ring bell",category:"sport",duration:2.02,url:"/sfx/pro-sport-boxing-bell.mp3",tags:["boxing ring bell"],pro:!0},{id:"pro-sport-air-horn",name:"Còi hơi sân vận động",en:"Stadium air horn",category:"sport",duration:2.04,url:"/sfx/pro-sport-air-horn.mp3",tags:["stadium air horn"],pro:!0},{id:"pro-sport-skateboard-ollie",name:"Trượt ván ollie",en:"Skateboard ollie",category:"sport",duration:1.99,url:"/sfx/pro-sport-skateboard-ollie.mp3",tags:["skateboard ollie"],pro:!0},{id:"pro-animal-dog-small-yap",name:"Chó nhỏ sủa",en:"Small dog yapping",category:"animal",duration:2.16,url:"/sfx/pro-animal-dog-small-yap.mp3",tags:["small dog yapping"],pro:!0},{id:"pro-animal-dog-big-bark",name:"Chó to sủa",en:"Big dog bark",category:"animal",duration:1.54,url:"/sfx/pro-animal-dog-big-bark.mp3",tags:["big dog bark"],pro:!0},{id:"pro-animal-dog-growl",name:"Chó gầm gừ",en:"Dog growl",category:"animal",duration:2.06,url:"/sfx/pro-animal-dog-growl.mp3",tags:["dog growl"],pro:!0},{id:"pro-animal-puppy-whine",name:"Chó con rên",en:"Puppy whine",category:"animal",duration:2.33,url:"/sfx/pro-animal-puppy-whine.mp3",tags:["puppy whine"],pro:!0},{id:"pro-animal-kitten-mew",name:"Mèo con kêu",en:"Kitten mew",category:"animal",duration:2.35,url:"/sfx/pro-animal-kitten-mew.mp3",tags:["kitten mew"],pro:!0},{id:"pro-animal-cat-purr",name:"Mèo rừ rừ (lặp)",en:"Cat purr loop",category:"animal",duration:6.31,url:"/sfx/pro-animal-cat-purr.mp3",tags:["cat purr loop"],pro:!0},{id:"pro-animal-cat-hiss",name:"Mèo xù lông",en:"Cat hiss",category:"animal",duration:1.22,url:"/sfx/pro-animal-cat-hiss.mp3",tags:["cat hiss"],pro:!0},{id:"pro-animal-hen-cluck",name:"Gà mái cục tác",en:"Hen clucking",category:"animal",duration:3.31,url:"/sfx/pro-animal-hen-cluck.mp3",tags:["hen clucking"],pro:!0},{id:"pro-animal-chicks-peep",name:"Gà con chiêm chiếp",en:"Chicks peeping",category:"animal",duration:3.36,url:"/sfx/pro-animal-chicks-peep.mp3",tags:["chicks peeping"],pro:!0},{id:"pro-animal-duck-quack",name:"Vịt kêu",en:"Duck quack",category:"animal",duration:2.16,url:"/sfx/pro-animal-duck-quack.mp3",tags:["duck quack"],pro:!0},{id:"pro-animal-cow-moo",name:"Bò rống",en:"Cow moo",category:"animal",duration:3.36,url:"/sfx/pro-animal-cow-moo.mp3",tags:["cow moo"],pro:!0},{id:"pro-animal-horse-neigh",name:"Ngựa hí",en:"Horse neigh",category:"animal",duration:2.33,url:"/sfx/pro-animal-horse-neigh.mp3",tags:["horse neigh"],pro:!0},{id:"pro-animal-horse-gallop",name:"Ngựa phi",en:"Horse gallop",category:"animal",duration:3.17,url:"/sfx/pro-animal-horse-gallop.mp3",tags:["horse gallop"],pro:!0},{id:"pro-animal-goat-bleat",name:"Dê kêu",en:"Goat bleat",category:"animal",duration:2.35,url:"/sfx/pro-animal-goat-bleat.mp3",tags:["goat bleat"],pro:!0},{id:"pro-animal-pig-oink",name:"Heo kêu ụt ịt",en:"Pig oink",category:"animal",duration:1.66,url:"/sfx/pro-animal-pig-oink.mp3",tags:["pig oink"],pro:!0},{id:"pro-animal-lion-roar",name:"Sư tử gầm",en:"Lion roar",category:"animal",duration:3.36,url:"/sfx/pro-animal-lion-roar.mp3",tags:["lion roar"],pro:!0},{id:"pro-animal-elephant-trumpet",name:"Voi rống",en:"Elephant trumpet",category:"animal",duration:2.14,url:"/sfx/pro-animal-elephant-trumpet.mp3",tags:["elephant trumpet"],pro:!0},{id:"pro-animal-crow-caw",name:"Quạ kêu",en:"Crow caw",category:"animal",duration:2.35,url:"/sfx/pro-animal-crow-caw.mp3",tags:["crow caw"],pro:!0},{id:"pro-animal-cricket-close",name:"Dế gáy (lặp)",en:"Cricket chirping loop",category:"animal",duration:8.38,url:"/sfx/pro-animal-cricket-close.mp3",tags:["cricket chirping loop"],pro:!0},{id:"pro-animal-bullfrog",name:"Ếch ộp (lặp)",en:"Bullfrog croak loop",category:"animal",duration:.84,url:"/sfx/pro-animal-bullfrog.mp3",tags:["bullfrog croak loop"],pro:!0},{id:"pro-weather-rain-light",name:"Mưa nhẹ",en:"Light rain",category:"weather",duration:10.37,url:"/sfx/pro-weather-rain-light.mp3",tags:["light rain"],pro:!0},{id:"pro-weather-rain-heavy",name:"Mưa lớn",en:"Heavy rain",category:"weather",duration:10.37,url:"/sfx/pro-weather-rain-heavy.mp3",tags:["heavy rain"],pro:!0},{id:"pro-weather-rain-tin-roof",name:"Mưa mái tôn",en:"Rain on a tin roof",category:"weather",duration:10.37,url:"/sfx/pro-weather-rain-tin-roof.mp3",tags:["rain on a tin roof"],pro:!0},{id:"pro-weather-rain-umbrella",name:"Mưa trên ô",en:"Rain on an umbrella",category:"weather",duration:8.3,url:"/sfx/pro-weather-rain-umbrella.mp3",tags:["rain on an umbrella"],pro:!0},{id:"pro-weather-rain-car",name:"Mưa trong xe",en:"Rain inside a car",category:"weather",duration:10.37,url:"/sfx/pro-weather-rain-car.mp3",tags:["rain inside a car"],pro:!0},{id:"pro-weather-after-rain-drips",name:"Mưa tạnh nhỏ giọt",en:"After-rain drips",category:"weather",duration:8.38,url:"/sfx/pro-weather-after-rain-drips.mp3",tags:["after-rain drips"],pro:!0},{id:"pro-weather-thunder-far",name:"Sấm xa",en:"Distant thunder",category:"weather",duration:3.38,url:"/sfx/pro-weather-thunder-far.mp3",tags:["distant thunder"],pro:!0},{id:"pro-weather-thunder-near",name:"Sấm sét gần",en:"Thunder crack nearby",category:"weather",duration:3.14,url:"/sfx/pro-weather-thunder-near.mp3",tags:["thunder crack nearby"],pro:!0},{id:"pro-weather-wind-gust",name:"Gió giật",en:"Wind gust",category:"weather",duration:3.05,url:"/sfx/pro-weather-wind-gust.mp3",tags:["wind gust"],pro:!0},{id:"pro-weather-wind-steady",name:"Gió thổi đều",en:"Steady wind",category:"weather",duration:10.37,url:"/sfx/pro-weather-wind-steady.mp3",tags:["steady wind"],pro:!0},{id:"pro-weather-storm",name:"Bão",en:"Storm",category:"weather",duration:10.37,url:"/sfx/pro-weather-storm.mp3",tags:["storm"],pro:!0},{id:"pro-weather-hail",name:"Mưa đá",en:"Hail",category:"weather",duration:8.38,url:"/sfx/pro-weather-hail.mp3",tags:["hail"],pro:!0},{id:"pro-weather-tornado",name:"Lốc xoáy",en:"Tornado roar",category:"weather",duration:8.38,url:"/sfx/pro-weather-tornado.mp3",tags:["tornado roar"],pro:!0},{id:"pro-weather-blizzard",name:"Bão tuyết",en:"Blizzard",category:"weather",duration:10.37,url:"/sfx/pro-weather-blizzard.mp3",tags:["blizzard"],pro:!0},{id:"pro-weather-snow-footsteps",name:"Bước chân trên tuyết",en:"Footsteps in snow",category:"weather",duration:2.09,url:"/sfx/pro-weather-snow-footsteps.mp3",tags:["footsteps in snow"],pro:!0}],lf={"whoosh-up":.7,"whoosh-down":.67,swoosh:.36,swipe:.29,"zoom-whoosh":.43,pop:.17,"bubble-pop":.22,click:.1,tick:.07,punch:.34,ding:.7,chime:.89,notification:.46,success:.86,"ka-ching":.96,"riser-1s":1.1,"riser-2s":1.8,impact:1.32,"bass-drop":1.61,glitch:.72,shutter:.55,typing:.96,sparkle:1.2,"pin-stick":.19,"marker-circle":.91,"paper-slide":.38,"coin-clink":.62,"neon-buzz":1.22,"counter-roll":1.37,"wheel-spin":2.66,drill:1.42,"ui-tap":.07,"ui-tap-soft":.1,"ui-toggle-on":.17,"ui-toggle-off":.17,"ui-error":.34,"ui-success-soft":.58,"ui-message-in":.48,"ui-message-out":.22,"ui-like":.38,"ui-unlock":.46,"ui-lock":.12,"ui-delete":.34,"ui-focus":.12,"ui-scroll-tick":.19,"ui-key-click":.1,"ui-hover":.12,"ui-open":.29,"ui-close":.29,"ui-download-done":.5,"ui-notify-soft":.72,"pop-high":.14,"pop-low":.22,"pop-cork":.17,"pop-double":.22,"bubble-rise":.48,"pluck-soft":.58,"finger-snap":.07,"tap-wood":.17,"tap-glass":.43,"tap-metal":.6,"knock-door":.53,"clap-single":.1,"whoosh-short-up":.38,"whoosh-short-down":.38,"whoosh-heavy":.91,"whoosh-airy":.77,"whoosh-double":.48,"sword-swish":.41,"spin-whoosh":.91,"zip-up":.34,"zip-down":.34,"slide-in":.38,"slide-out":.41,"card-flip":.14,"page-turn":.46,"fly-by":1.15,"hit-soft":.72,"hit-deep":1.22,"hit-snare":.5,"hit-clap-stack":.53,"boom-far":1.78,"thud-box":.58,slam:.82,stomp:.62,"metal-clang":1.44,"rim-shot":.46,"kick-808":1.32,"hit-cinematic":1.13,"riser-half":.7,"riser-tension":2.02,"downlifter-1s":1.25,"downlifter-2s":2.11,"reverse-cymbal":1.34,"sweep-up":1.3,"sweep-down":1.3,"swell-pad":2.3,"tape-stop":1.32,rewind:1.1,"sting-win":1.56,"sting-fail":1.97,"sting-mystery":1.9,"sting-reveal":1.92,"sting-happy":1.2,"sting-tense":2.11,"chord-major":1.51,"chord-minor":1.51,"harp-gliss":1.32,"xylo-up":1.01,"xylo-down":1.01,"music-box":1.63,"game-coin":.36,"power-up":.62,"level-up":.96,"jump-boing":.48,"laser-zap":.34,"laser-pew":.24,"alarm-beep":.53,"buzzer-wrong":.62,"quiz-correct":.55,"slot-reel":1.97,"slide-whistle-up":.72,"slide-whistle-down":.72,"data-blip":.53,"scan-sweep":1.51,hologram:1.82,"robot-beep":.74,"glitch-short":.55,"static-burst":.82,"power-on":1.32,"power-down":1.54,"logo-royal-strings":5.33,"logo-water-splash":4.34,"logo-digital-glitch":3.34,"logo-soft-chime":3.34,"whoosh-windy":3.05,"whoosh-water-low":3.05,"whoosh-cinematic":2.04,"whoosh-fast-swish":1.03,"whoosh-reverse":2.04,"whoosh-fire":2.04,"riser-tense-trailer":6.34,"drop-slow-bass":4.39,"braam-cinematic":4.37,"impact-sub-boom":3.38,"impact-metal-hit":2.16,"riser-electronic":5.38,"water-splash":2.35,"liquid-boiling":6.34,"hose-spray":3.34,"water-bubbles":4.34,"water-drip":4.34,"pour-drink":4.34,"ambience-cyber-room":10.37,"ambience-office":10.37,"ambience-cafe":10.37,"ambience-city-street":10.37,"ambience-rain":10.37,"ambience-forest":10.37,"ocean-waves":10.37,thunder:5.38,"vacuum-cleaner":5.35,"planer-motor":6.34,"keyboard-typing":5.35,"camera-shutter":1.32,"door-open-close":3.34,"car-pass-by":4.03,"phone-vibrate":2.35,"crowd-cheer":5.35,applause:5.35,"crowd-laugh":3.34,"crowd-gasp":2.35,footsteps:4.34,heartbeat:4.34,"sizzle-pan":4.34,"wok-stir-fry":4.34,"knife-chopping":3.34,"coffee-machine":5.35,"milk-frother":3.34,"ice-cubes-glass":2.35,"soda-open-pour":3.34,"cutlery-plate":3.26,"crunchy-bite":2.35,"noodle-slurp":2.35,"service-bell":1.99,"shop-door-chime":2.35,"microwave-ding":2.35,"kettle-whistle":3.34,"spa-water":6.34,"singing-bowl":5.35,"deep-breath":4.34,"spray-mist":1.32,"lotion-pump":.79,"hair-dryer":4.3,"scissors-snip":2.35,"gym-weights":2.33,"treadmill-run":5.35,"coach-whistle":.86,"heart-monitor":4.34,"pill-rattle":2.26,"pencil-writing":3.34,"chalk-board":3.31,"book-page-turn":2.35,"school-bell":3.34,"robot-beeps":2.35,"digital-scan":2.35,"data-processing":3.31,"game-level-up":2.28,"quiz-correct-chime":1.34,"quiz-wrong":1.34,printer:4.34,"airplane-takeoff":6.38,"airport-chime":3.38,"suitcase-roll":3.38,"car-engine-start":4.39,"car-lock":2.38,"ev-accelerate":4.39,"motorbike-pass":3.05,"train-pass":5.04,"keys-unlock":2.38,construction:5.38,"morning-birds":6.38,"beach-seagulls":6.38,"cash-counting":3.05,"coins-drop":1.97,"crowd-wow":2.04,"kids-yay":2.04,"like-pop":1.03,"typing-chat":1.7},Ps={"alarm-beep":"pro-scifi-alarm-ship","bass-drop":"pro-impact-bass-drop","boom-far":"sp-sub-hit-3","chord-major":"sting-reveal","chord-minor":"sting-mystery","clap-single":"hit-clap-stack","downlifter-1s":"sp-downer-1","downlifter-2s":"sp-downer-2","finger-snap":"pro-foley-finger-snap","hit-cinematic":"sp-sub-hit-3","laser-pew":"pro-scifi-laser-shot","laser-zap":"sp-glitch-3","level-up":"game-level-up","metal-clang":"pro-impact-metal-clang","pop-cork":"pro-pop-cork-small","power-down":"sp-downer-1","pro-animal-dog-big-bark":"pro-animal-dog-small-yap","pro-animal-dog-growl":"pro-animal-dog-small-yap","pro-arp-1":"ui-tap","pro-arp-2":"ui-tap","pro-arp-3":"ui-tap","pro-arp-4":"ui-tap","pro-arp-5":"ui-tap","pro-arp-6":"ui-tap","pro-arp-7":"ui-tap","pro-arp-8":"ui-tap","pro-beep-1":"pro-ui-focus-beep","pro-beep-2":"pro-ui-focus-beep","pro-beep-3":"pro-ui-focus-beep","pro-beep-4":"pro-ui-focus-beep","pro-bloop-2":"pro-bloop-1","pro-bloop-3":"pro-bloop-1","pro-bloop-4":"pro-bloop-1","pro-bloop-5":"pro-bloop-1","pro-chime-1":"chime","pro-chime-2":"chime","pro-chime-3":"chime","pro-chime-4":"chime","pro-chirp-sweep-1":"sp-slice-4","pro-chirp-sweep-2":"sp-slice-4","pro-chirp-sweep-3":"sp-slice-4","pro-chirp-sweep-4":"sp-slice-4","pro-chirp-sweep-5":"sp-slice-4","pro-click-pitched-1":"pro-mouse-click-office","pro-click-pitched-2":"pro-mouse-click-office","pro-click-pitched-3":"pro-mouse-click-office","pro-click-pitched-4":"pro-mouse-click-office","pro-click-pitched-5":"pro-mouse-click-office","pro-digital-signal-lost":"pro-digital-ui-scan","pro-downlifter-2s":"sp-downer-1","pro-downlifter-3s":"sp-downer-1","pro-downlifter-5s":"sp-downer-2","pro-fight-arm-swing-fast":"pro-fight-chain-swing","pro-fight-blade-scrape":"pro-fight-punch-jab-quick","pro-fight-joint-crack":"pro-fight-punch-jab-quick","pro-fight-knuckle-crack":"pro-fight-punch-jab-quick","pro-fight-punch-anime":"pro-fight-punch-jab-quick","pro-foley-chalk":"pro-foley-paper-crumple","pro-foley-cup-set-down":"pro-foley-paper-crumple","pro-foley-light-switch":"pro-foley-paper-crumple","pro-foley-marker-scribble":"pro-foley-paper-crumple","pro-foley-page-turn":"page-turn","pro-foley-pencil-write":"pencil-writing","pro-foley-velcro":"pro-foley-tape-rip","pro-food-boil":"pro-food-sizzle","pro-food-chop":"knife-chopping","pro-food-egg-crack":"pro-food-sizzle","pro-fun-fail-trombone":"sp-fun-fail-1","pro-fun-game-over":"sp-fun-fail-1","pro-glitch-crackle":"sp-glitch-1","pro-glitch-hologram":"sp-glitch-1","pro-glitch-synth-1":"sp-glitch-1","pro-glitch-synth-10":"sp-glitch-1","pro-glitch-synth-11":"sp-glitch-1","pro-glitch-synth-12":"sp-glitch-1","pro-glitch-synth-13":"sp-glitch-1","pro-glitch-synth-14":"sp-glitch-1","pro-glitch-synth-15":"sp-glitch-1","pro-glitch-synth-16":"sp-glitch-1","pro-glitch-synth-2":"sp-glitch-1","pro-glitch-synth-3":"sp-glitch-1","pro-glitch-synth-4":"sp-glitch-1","pro-glitch-synth-5":"sp-glitch-1","pro-glitch-synth-6":"sp-glitch-1","pro-glitch-synth-7":"sp-glitch-1","pro-glitch-synth-8":"sp-glitch-1","pro-glitch-synth-9":"sp-glitch-1","pro-human-clap-single":"hit-clap-stack","pro-human-sigh":"pro-human-gasp","pro-key-backspace":"pro-key-mechanical","pro-key-enter":"pro-key-mechanical","pro-key-laptop":"pro-key-mechanical","pro-magic-beam-long":"pro-magic-energy-blast","pro-magic-electric-arc":"pro-magic-twinkle-up","pro-magic-lightning-strike":"pro-magic-twinkle-up","pro-magic-mana-charge":"pro-magic-powerup-charge","pro-magic-shield-hit":"pro-magic-shield-up","pro-magic-sparkle-fall":"sp-sparkle-1","pro-magic-spell-dark":"pro-magic-spell-cast","pro-mouse-drag":"pro-mouse-click-office","pro-mouse-synth-1":"pro-mouse-click-office","pro-mouse-synth-2":"pro-mouse-click-office","pro-mouse-synth-3":"pro-mouse-click-office","pro-mouse-synth-4":"pro-mouse-click-office","pro-mouse-synth-5":"pro-mouse-click-office","pro-noise-sweep-1-5s":"sweep-up","pro-noise-sweep-1s":"sweep-up","pro-noise-sweep-2-5s":"sweep-up","pro-noise-sweep-up-1-5s":"sweep-up","pro-noise-sweep-up-3s":"sweep-up","pro-notify-1":"pro-ui-notify-soft","pro-notify-2":"pro-ui-notify-soft","pro-notify-3":"pro-ui-notify-soft","pro-notify-4":"pro-ui-notify-soft","pro-notify-5":"pro-ui-notify-soft","pro-notify-6":"pro-ui-notify-soft","pro-notify-7":"pro-ui-notify-soft","pro-notify-8":"pro-ui-notify-soft","pro-pop-jelly":"pop","pro-pop-plastic":"pop","pro-pop-suction":"pop","pro-popup-3":"pro-popup-1","pro-riser-chirp-1":"sp-riser-1","pro-riser-chirp-2":"sp-riser-1","pro-riser-chirp-3":"sp-riser-1","pro-riser-synth-2s":"sp-riser-3","pro-riser-synth-3s":"sp-riser-3","pro-riser-synth-4s":"sp-riser-3","pro-riser-synth-6s":"sp-riser-3","pro-riser-whistle-stop":"pro-trailer-reverse-whoosh-stop","pro-scan-1":"pro-scan-2","pro-scan-3":"pro-scan-2","pro-scan-4":"pro-scan-2","pro-scan-5":"pro-scan-2","pro-scifi-teleport":"pro-scifi-laser-shot","pro-sport-air-horn":"sp-fun-horn-1","pro-sport-ball-net":"pro-sport-ball-kick","pro-sport-ball-post":"pro-sport-ball-kick","pro-sport-bat-hit":"pro-sport-tennis-hit","pro-sport-net-swish":"pro-sport-ball-kick","pro-sport-skateboard-ollie":"pro-sport-ball-kick","pro-stutter-1":"pro-digital-ui-scan","pro-stutter-2":"pro-digital-ui-scan","pro-stutter-3":"pro-digital-ui-scan","pro-stutter-4":"pro-digital-ui-scan","pro-stutter-5":"pro-digital-ui-scan","pro-stutter-6":"pro-digital-ui-scan","pro-stutter-7":"pro-digital-ui-scan","pro-stutter-8":"pro-digital-ui-scan","pro-stutter-9":"pro-digital-ui-scan","pro-sub-drop-2s":"sp-whoosh-transition-1","pro-sub-drop-4s":"sp-whoosh-transition-1","pro-suspense-noise-swell-4s":"pro-suspense-heartbeat-slow","pro-suspense-tension-build-10s":"pro-suspense-drone-dark","pro-swell-impact":"sp-whoosh-transition-3","pro-swipe-synth-1":"pro-whoosh-sword-swipe","pro-swipe-synth-10":"pro-whoosh-sword-swipe","pro-swipe-synth-2":"pro-whoosh-sword-swipe","pro-swipe-synth-3":"pro-whoosh-sword-swipe","pro-swipe-synth-4":"pro-whoosh-sword-swipe","pro-swipe-synth-5":"pro-whoosh-sword-swipe","pro-swipe-synth-6":"pro-whoosh-sword-swipe","pro-swipe-synth-7":"pro-whoosh-sword-swipe","pro-swipe-synth-8":"pro-whoosh-sword-swipe","pro-swipe-synth-9":"pro-whoosh-sword-swipe","pro-swish-air-wide":"sp-swish-1","pro-switch-1":"pro-transition-vhs-switch","pro-switch-2":"pro-transition-vhs-switch","pro-switch-3":"pro-transition-vhs-switch","pro-switch-4":"pro-transition-vhs-switch","pro-trackpad-press":"pro-trackpad-tap","pro-trailer-downlifter-6s":"pro-trailer-deep-hit","pro-trailer-riser-8s":"riser-tense-trailer","pro-trailer-subdrop-3s":"sp-whoosh-transition-1","pro-trailer-subdrop-6s":"sp-whoosh-transition-1","pro-trans-cloth-wipe":"pro-trans-whip-pan","pro-trans-film-burn":"pro-transition-film-reel","pro-trans-magic-poof":"pro-trans-whip-pan","pro-trans-page-flip":"pro-trans-whip-pan","pro-trans-riser-hit":"pro-transition-cinematic-hit-transition","pro-trans-swoosh-hit":"pro-transition-cinematic-hit-transition","pro-trans-zoom-punch":"punch","pro-transition-digital-zap":"pro-digital-zap","pro-transition-door-swoosh":"sp-whoosh-transition-1","pro-transition-ink-splash":"sp-whoosh-transition-1","pro-transition-page-swipe":"sp-transition-3","pro-transition-portal":"sp-whoosh-transition-1","pro-transition-swoosh-pop":"pro-whoosh-swoosh-pop","pro-transition-tape-stop":"pro-trans-tape-stop-short","pro-transition-zoom-out":"sp-transition-1","pro-ui-click-high":"ui-key-click","pro-ui-click-low":"ui-key-click","pro-ui-close-thud":"pro-ui-whoop-open","pro-ui-countdown-beep":"pro-ui-focus-beep","pro-ui-delete":"ui-error","pro-ui-error":"ui-error","pro-ui-hover":"ui-hover","pro-ui-like":"pro-ui-heart-like","pro-ui-lock":"ui-lock","pro-ui-notify":"pro-ui-notify-soft","pro-ui-notify-triple":"pro-ui-notify-soft","pro-ui-pop-up":"sp-chip-1","pro-ui-premium-tap":"ui-tap","pro-ui-tick":"ui-scroll-tick","pro-ui-timer-done":"ui-download-done","pro-ui-toggle-off":"sp-chip-2","pro-ui-toggle-on":"sp-chip-2","pro-ui-unlock":"pro-phone-unlock","pro-ui-upload-done":"ui-download-done","pro-ui-warning":"ui-error","pro-whoosh-electric":"sp-whoosh-transition-5","pro-whoosh-fabric":"pro-whoosh-bird-wings","pro-whoosh-laser":"pro-whoosh-laser-sweep","pro-whoosh-metal-whoosh":"pro-whoosh-metallic-short","pro-whoosh-pass-left":"pro-whoosh-car-pass","pro-whoosh-punch-swing":"pro-whoosh-bamboo-swing","pro-whoosh-swing-light":"pro-whoosh-bamboo-swing","quiz-correct":"quiz-correct-chime",rewind:"sp-glitch-4","rim-shot":"sp-fun-drum-1","riser-2s":"riser-1s","slide-out":"swipe","slide-whistle-up":"sp-fun-whistle-1","sting-fail":"sp-fun-fail-1","sting-happy":"sp-fun-tada-1","sting-tense":"sp-fun-suspense-1",stomp:"pro-impact-stomp","sweep-down":"sp-downer-1","tap-metal":"tap-wood","ui-close":"ui-open","ui-delete":"ui-error","ui-like":"pro-ui-heart-like","ui-toggle-off":"sp-chip-2","ui-toggle-on":"sp-chip-2","ui-unlock":"ui-lock","whoosh-down":"whoosh-short-down","whoosh-reverse":"pro-whoosh-reverse","xylo-down":"sp-downer-1","zip-down":"zip-up"},cf={"bubble-pop":.29,"bubble-rise":.6,"buzzer-wrong":.79,"card-flip":.24,"coin-clink":.91,"counter-roll":.84,"data-blip":.31,"fly-by":1.54,"game-coin":.43,"glitch-short":.31,"harp-gliss":1.27,"hit-clap-stack":.46,"hit-deep":1.15,"hit-snare":.36,"hit-soft":.53,"jump-boing":.6,"ka-ching":1.32,"kick-808":1.3,"marker-circle":.79,"music-box":1.68,"neon-buzz":1.15,"page-turn":.6,"paper-slide":.5,"pin-stick":.26,"pluck-soft":.79,"pop-double":.31,"pop-high":.22,"pop-low":.29,"power-on":1.3,"power-up":.79,"pro-flash-burst":.7,"pro-impact-whoosh-sub":.94,"pro-popup-1":.31,"pro-scan-2":.55,"pro-shutter-tick-1":.24,"pro-shutter-tick-2":.24,"pro-shutter-tick-3":.24,"pro-ui-card-select":.62,"pro-ui-click":.24,"pro-ui-focus-beep":.41,"pro-ui-message-in":.72,"pro-ui-notify-soft":.41,"pro-ui-soft-confirm":.41,"pro-ui-typing-bubble":.5,"reverse-cymbal":1.51,"riser-1s":1.3,"riser-half":.67,"riser-tension":2.78,"robot-beep":.55,"scan-sweep":1.54,"slide-in":.53,"slide-whistle-down":.91,"slot-reel":1.44,"spin-whoosh":1.15,"static-burst":.58,"sting-mystery":2.04,"sting-reveal":2.11,"sting-win":1.61,"sweep-up":1.3,"swell-pad":2.54,"sword-swish":.67,"tap-glass":.67,"tap-wood":.36,"thud-box":.48,"ui-download-done":.65,"ui-error":.41,"ui-focus":.22,"ui-key-click":.17,"ui-lock":.22,"ui-message-in":.6,"ui-message-out":.29,"ui-notify-soft":.84,"ui-open":.36,"ui-scroll-tick":.29,"ui-success-soft":.84,"ui-tap":.14,"ui-tap-soft":.17,"wheel-spin":2.54,"whoosh-airy":.6,"whoosh-double":.62,"whoosh-heavy":1.15,"whoosh-short-down":.43,"whoosh-short-up":.48,"whoosh-up":.91,"xylo-up":.91,"zip-up":.41,"zoom-whoosh":.67,"digital-scan":1.54,"logo-royal-strings":2.35,"logo-soft-chime":2.47,"pro-digital-ui-scan":1.3,"pro-stylus-tap":.34,"pro-whoosh-ui-bright":.77,chime:1.27,click:.17,ding:1.42,drill:1.42,glitch:.53,hologram:1.92,impact:1.3,"knock-door":.7,notification:.55,pop:.26,"pro-bloop-1":.29,"pro-magic-twinkle-up":1.32,"pro-pop-bubble-cute":.31,"pro-popup-2":.31,"pro-ui-message-sent":.34,"pro-ui-success":.72,"pro-ui-swipe-tick":.5,"pro-ui-whoop-open":.34,"pro-whoosh-ui-soft":1.32,punch:.41,shutter:.31,slam:.67,sparkle:1.18,success:1.39,swipe:.38,swoosh:.43,"tape-stop":1.3,tick:.14,typing:.82,"ui-hover":.19},E3=[{id:"sp-slice-1",name:"Slice sắc + sub",en:"Crisp slice + sub",category:"whoosh",duration:1.42,url:"/sfx/sp-slice-1.mp3",tags:["crisp slice + sub"],suno:!0},{id:"sp-slice-2",name:"Slice kim loại ngân",en:"Ringing metal slice",category:"whoosh",duration:1.82,url:"/sfx/sp-slice-2.mp3",tags:["ringing metal slice"],suno:!0},{id:"sp-slice-3",name:"Slice katana",en:"Katana slice",category:"whoosh",duration:1.7,url:"/sfx/sp-slice-3.mp3",tags:["katana slice"],suno:!0},{id:"sp-slice-4",name:"Slice kính số",en:"Glassy digital slice",category:"whoosh",duration:.58,url:"/sfx/sp-slice-4.mp3",tags:["glassy digital slice"],suno:!0},{id:"sp-slice-5",name:"Slice đôi nặng",en:"Heavy double slice",category:"whoosh",duration:1.82,url:"/sfx/sp-slice-5.mp3",tags:["heavy double slice"],suno:!0},{id:"sp-swish-1",name:"Swish chữ",en:"Text swish",category:"whoosh",duration:1.44,url:"/sfx/sp-swish-1.mp3",tags:["text swish"],suno:!0},{id:"sp-swish-2",name:"Swish vải mềm",en:"Soft fabric swish",category:"whoosh",duration:1.1,url:"/sfx/sp-swish-2.mp3",tags:["soft fabric swish"],suno:!0},{id:"sp-swish-3",name:"Swish roi",en:"Whip swish",category:"whoosh",duration:1.51,url:"/sfx/sp-swish-3.mp3",tags:["whip swish"],suno:!0},{id:"sp-swish-4",name:"Swish hút ngược",en:"Reverse suck swish",category:"whoosh",duration:.43,url:"/sfx/sp-swish-4.mp3",tags:["reverse suck swish"],suno:!0},{id:"sp-swish-5",name:"Swish điện ảnh",en:"Cinematic swish",category:"whoosh",duration:1.82,url:"/sfx/sp-swish-5.mp3",tags:["cinematic swish"],suno:!0},{id:"sp-whoosh-transition-1",name:"Whoosh chuyển cảnh + sub drop",en:"Transition whoosh + sub drop",category:"transition",duration:2.11,url:"/sfx/sp-whoosh-transition-1.mp3",tags:["transition whoosh + sub drop"],suno:!0},{id:"sp-whoosh-transition-2",name:"Whoosh bóng bẩy",en:"Glossy whoosh",category:"transition",duration:2.16,url:"/sfx/sp-whoosh-transition-2.mp3",tags:["glossy whoosh"],suno:!0},{id:"sp-whoosh-transition-3",name:"Whoosh vào cắt",en:"Whoosh into cut",category:"transition",duration:2.02,url:"/sfx/sp-whoosh-transition-3.mp3",tags:["whoosh into cut"],suno:!0},{id:"sp-whoosh-transition-4",name:"Whoosh xoáy lấp lánh",en:"Swirl shimmer whoosh",category:"transition",duration:2.23,url:"/sfx/sp-whoosh-transition-4.mp3",tags:["swirl shimmer whoosh"],suno:!0},{id:"sp-whoosh-transition-5",name:"Whoosh điện",en:"Electric whoosh",category:"transition",duration:2.23,url:"/sfx/sp-whoosh-transition-5.mp3",tags:["electric whoosh"],suno:!0},{id:"sp-sub-hit-1",name:"Sub hit sạch",en:"Clean sub hit",category:"impact",duration:2.64,url:"/sfx/sp-sub-hit-1.mp3",tags:["clean sub hit"],suno:!0},{id:"sp-sub-hit-2",name:"Sub thump + click",en:"Sub thump + click",category:"impact",duration:1.42,url:"/sfx/sp-sub-hit-2.mp3",tags:["sub thump + click"],suno:!0},{id:"sp-sub-hit-3",name:"Boom điện ảnh lớn",en:"Massive cinematic boom",category:"impact",duration:3.02,url:"/sfx/sp-sub-hit-3.mp3",tags:["massive cinematic boom"],suno:!0},{id:"sp-sub-hit-4",name:"808 trap",en:"Trap 808 hit",category:"impact",duration:2.28,url:"/sfx/sp-sub-hit-4.mp3",tags:["trap 808 hit"],suno:!0},{id:"sp-sub-hit-5",name:"Braam tối",en:"Dark braam",category:"impact",duration:3.02,url:"/sfx/sp-sub-hit-5.mp3",tags:["dark braam"],suno:!0},{id:"sp-impact-1",name:"Impact tiêu đề",en:"Title slam impact",category:"impact",duration:3.02,url:"/sfx/sp-impact-1.mp3",tags:["title slam impact"],suno:!0},{id:"sp-impact-2",name:"Impact kính vỡ",en:"Glass shatter impact",category:"impact",duration:2.11,url:"/sfx/sp-impact-2.mp3",tags:["glass shatter impact"],suno:!0},{id:"sp-impact-3",name:"Hit trailer",en:"Trailer hit",category:"impact",duration:3.02,url:"/sfx/sp-impact-3.mp3",tags:["trailer hit"],suno:!0},{id:"sp-impact-4",name:"Punch khô",en:"Dry punch",category:"impact",duration:1.82,url:"/sfx/sp-impact-4.mp3",tags:["dry punch"],suno:!0},{id:"sp-impact-5",name:"Impact sấm",en:"Thunder impact",category:"impact",duration:3.02,url:"/sfx/sp-impact-5.mp3",tags:["thunder impact"],suno:!0},{id:"sp-riser-1",name:"Riser vào drop",en:"Riser into drop",category:"riser",duration:1.97,url:"/sfx/sp-riser-1.mp3",tags:["riser into drop"],suno:!0},{id:"sp-riser-2",name:"Riser reverb ngược",en:"Reverse reverb riser",category:"riser",duration:2.81,url:"/sfx/sp-riser-2.mp3",tags:["reverse reverb riser"],suno:!0},{id:"sp-riser-3",name:"Riser synth sáng",en:"Bright synth riser",category:"riser",duration:3.53,url:"/sfx/sp-riser-3.mp3",tags:["bright synth riser"],suno:!0},{id:"sp-riser-4",name:"Riser nhịp tim",en:"Heartbeat riser",category:"riser",duration:3.53,url:"/sfx/sp-riser-4.mp3",tags:["heartbeat riser"],suno:!0},{id:"sp-downer-1",name:"Tụt năng lượng",en:"Downer",category:"riser",duration:3.53,url:"/sfx/sp-downer-1.mp3",tags:["downer"],suno:!0},{id:"sp-downer-2",name:"Tape stop",en:"Tape stop",category:"riser",duration:3.53,url:"/sfx/sp-downer-2.mp3",tags:["tape stop"],suno:!0},{id:"sp-pop-1",name:"Pop bong bóng UI",en:"Bubbly UI pop",category:"pop",duration:.84,url:"/sfx/sp-pop-1.mp3",tags:["bubbly ui pop"],suno:!0},{id:"sp-pop-2",name:"Pop cao su",en:"Rubbery pop",category:"pop",duration:.84,url:"/sfx/sp-pop-2.mp3",tags:["rubbery pop"],suno:!0},{id:"sp-pop-3",name:"Pop kính lấp lánh",en:"Glassy sparkle pop",category:"pop",duration:.84,url:"/sfx/sp-pop-3.mp3",tags:["glassy sparkle pop"],suno:!0},{id:"sp-pop-4",name:"Pop đôi",en:"Double pop",category:"pop",duration:.84,url:"/sfx/sp-pop-4.mp3",tags:["double pop"],suno:!0},{id:"sp-pop-5",name:"Pop gỗ ấm",en:"Warm wood pop",category:"pop",duration:.84,url:"/sfx/sp-pop-5.mp3",tags:["warm wood pop"],suno:!0},{id:"sp-chip-1",name:"Chip bật lên",en:"Chip pop-in",category:"ui",duration:.84,url:"/sfx/sp-chip-1.mp3",tags:["chip pop-in"],suno:!0},{id:"sp-chip-2",name:"Gạt công tắc",en:"Toggle flick",category:"ui",duration:.84,url:"/sfx/sp-chip-2.mp3",tags:["toggle flick"],suno:!0},{id:"sp-chip-3",name:"Thẻ hít nam châm",en:"Magnetic card snap",category:"ui",duration:.84,url:"/sfx/sp-chip-3.mp3",tags:["magnetic card snap"],suno:!0},{id:"sp-chip-4",name:"Dòng trượt vào",en:"List item slide",category:"ui",duration:.84,url:"/sfx/sp-chip-4.mp3",tags:["list item slide"],suno:!0},{id:"sp-chip-5",name:"Thanh tiến trình",en:"Progress bar fill",category:"ui",duration:.84,url:"/sfx/sp-chip-5.mp3",tags:["progress bar fill"],suno:!0},{id:"sp-click-1",name:"Click cao cấp",en:"Premium click",category:"ui",duration:.84,url:"/sfx/sp-click-1.mp3",tags:["premium click"],suno:!0},{id:"sp-click-2",name:"Click nút kính",en:"Glass button click",category:"ui",duration:.84,url:"/sfx/sp-click-2.mp3",tags:["glass button click"],suno:!0},{id:"sp-click-3",name:"Chạm màn hình rung",en:"Haptic tap",category:"ui",duration:.84,url:"/sfx/sp-click-3.mp3",tags:["haptic tap"],suno:!0},{id:"sp-type-1",name:"Gõ phím nhanh",en:"Fast typing",category:"ui",duration:.84,url:"/sfx/sp-type-1.mp3",tags:["fast typing"],suno:!0},{id:"sp-type-2",name:"Gõ một chữ",en:"Single letter tick",category:"ui",duration:.84,url:"/sfx/sp-type-2.mp3",tags:["single letter tick"],suno:!0},{id:"sp-text-1",name:"Chữ hiện + pop",en:"Text reveal pop",category:"ui",duration:.84,url:"/sfx/sp-text-1.mp3",tags:["text reveal pop"],suno:!0},{id:"sp-text-2",name:"Chữ đập vào",en:"Text slam",category:"ui",duration:.84,url:"/sfx/sp-text-2.mp3",tags:["text slam"],suno:!0},{id:"sp-text-3",name:"Chữ lấp lánh",en:"Text shimmer",category:"ui",duration:.84,url:"/sfx/sp-text-3.mp3",tags:["text shimmer"],suno:!0},{id:"sp-glitch-1",name:"Glitch chuyển cảnh",en:"Glitch transition",category:"glitch",duration:1.08,url:"/sfx/sp-glitch-1.mp3",tags:["glitch transition"],suno:!0},{id:"sp-glitch-2",name:"Dữ liệu hỏng",en:"Data corruption",category:"glitch",duration:1.54,url:"/sfx/sp-glitch-2.mp3",tags:["data corruption"],suno:!0},{id:"sp-glitch-3",name:"Glitch điện giật",en:"Electric zap glitch",category:"glitch",duration:1.44,url:"/sfx/sp-glitch-3.mp3",tags:["electric zap glitch"],suno:!0},{id:"sp-glitch-4",name:"Tua băng VHS",en:"VHS rewind",category:"glitch",duration:1.54,url:"/sfx/sp-glitch-4.mp3",tags:["vhs rewind"],suno:!0},{id:"sp-camera-1",name:"Chụp ảnh + sạc flash",en:"Shutter + flash charge",category:"camera",duration:1.22,url:"/sfx/sp-camera-1.mp3",tags:["shutter + flash charge"],suno:!0},{id:"sp-camera-2",name:"Ống kính zoom",en:"Lens zoom motor",category:"camera",duration:1.22,url:"/sfx/sp-camera-2.mp3",tags:["lens zoom motor"],suno:!0},{id:"sp-sparkle-1",name:"Lấp lánh phép thuật",en:"Magic sparkle",category:"magic",duration:2.4,url:"/sfx/sp-sparkle-1.mp3",tags:["magic sparkle"],suno:!0},{id:"sp-sparkle-2",name:"Bụi tiên",en:"Fairy dust",category:"magic",duration:1.94,url:"/sfx/sp-sparkle-2.mp3",tags:["fairy dust"],suno:!0},{id:"sp-shine-1",name:"Ánh sáng loé",en:"Shine ting",category:"magic",duration:1.75,url:"/sfx/sp-shine-1.mp3",tags:["shine ting"],suno:!0},{id:"sp-logo-1",name:"Logo cao cấp",en:"Premium logo sting",category:"logo",duration:1.8,url:"/sfx/sp-logo-1.mp3",tags:["premium logo sting"],suno:!0},{id:"sp-logo-2",name:"Logo công nghệ",en:"Tech logo reveal",category:"logo",duration:2.21,url:"/sfx/sp-logo-2.mp3",tags:["tech logo reveal"],suno:!0},{id:"sp-heartbeat-1",name:"Nhịp tim điện ảnh",en:"Cinematic heartbeat",category:"impact",duration:1.15,url:"/sfx/sp-heartbeat-1.mp3",tags:["cinematic heartbeat"],suno:!0},{id:"sp-tick-1",name:"Đồng hồ tích tắc",en:"Clock ticking",category:"ui",duration:.84,url:"/sfx/sp-tick-1.mp3",tags:["clock ticking"],suno:!0},{id:"sp-ding-1",name:"Ý tưởng loé",en:"Idea ding",category:"ui",duration:.84,url:"/sfx/sp-ding-1.mp3",tags:["idea ding"],suno:!0},{id:"sp-bell-1",name:"Chuông quầy",en:"Desk bell",category:"ui",duration:.84,url:"/sfx/sp-bell-1.mp3",tags:["desk bell"],suno:!0},{id:"sp-doorbell-1",name:"Chuông cửa",en:"Doorbell",category:"ui",duration:.84,url:"/sfx/sp-doorbell-1.mp3",tags:["doorbell"],suno:!0},{id:"sp-fun-wait-1",name:"Dế kêu im lặng",en:"Awkward crickets",category:"cartoon",duration:2.38,url:"/sfx/sp-fun-wait-1.mp3",tags:["awkward crickets"],suno:!0},{id:"sp-fun-fail-1",name:"Kèn thất bại",en:"Sad trombone",category:"cartoon",duration:3.53,url:"/sfx/sp-fun-fail-1.mp3",tags:["sad trombone"],suno:!0},{id:"sp-fun-fail-2",name:"Té hoạt hình",en:"Cartoon fall",category:"cartoon",duration:2.02,url:"/sfx/sp-fun-fail-2.mp3",tags:["cartoon fall"],suno:!0},{id:"sp-fun-bonk-1",name:"Cốc đầu",en:"Cartoon bonk",category:"cartoon",duration:1.73,url:"/sfx/sp-fun-bonk-1.mp3",tags:["cartoon bonk"],suno:!0},{id:"sp-fun-boing-2",name:"Boing lớn",en:"Big boing",category:"cartoon",duration:2.18,url:"/sfx/sp-fun-boing-2.mp3",tags:["big boing"],suno:!0},{id:"sp-fun-squeak-1",name:"Đồ chơi kêu chít",en:"Toy squeak",category:"cartoon",duration:1.51,url:"/sfx/sp-fun-squeak-1.mp3",tags:["toy squeak"],suno:!0},{id:"sp-fun-pop-1",name:"Bật nút chai",en:"Cork pop",category:"cartoon",duration:1.75,url:"/sfx/sp-fun-pop-1.mp3",tags:["cork pop"],suno:!0},{id:"sp-fun-whistle-1",name:"Còi trượt lên",en:"Slide whistle up",category:"cartoon",duration:.96,url:"/sfx/sp-fun-whistle-1.mp3",tags:["slide whistle up"],suno:!0},{id:"sp-fun-later-1",name:"Vài phút sau…",en:"A few moments later",category:"cartoon",duration:.89,url:"/sfx/sp-fun-later-1.mp3",tags:["a few moments later"],suno:!0},{id:"sp-fun-suspense-1",name:"Dun dun dunnn",en:"Dramatic sting",category:"cartoon",duration:1.44,url:"/sfx/sp-fun-suspense-1.mp3",tags:["dramatic sting"],suno:!0},{id:"sp-fun-shock-1",name:"Sóng sốc",en:"Shocking wave",category:"cartoon",duration:2.23,url:"/sfx/sp-fun-shock-1.mp3",tags:["shocking wave"],suno:!0},{id:"sp-fun-bong-1",name:"Bong meme",en:"Meme bong",category:"cartoon",duration:2.3,url:"/sfx/sp-fun-bong-1.mp3",tags:["meme bong"],suno:!0},{id:"sp-fun-vine-1",name:"Boom meme vang",en:"Meme boom",category:"cartoon",duration:1.58,url:"/sfx/sp-fun-vine-1.mp3",tags:["meme boom"],suno:!0},{id:"sp-fun-record-1",name:"Đĩa xước",en:"Record scratch",category:"cartoon",duration:3.53,url:"/sfx/sp-fun-record-1.mp3",tags:["record scratch"],suno:!0},{id:"sp-fun-laugh-1",name:"Khán giả cười",en:"Sitcom laugh",category:"cartoon",duration:3.17,url:"/sfx/sp-fun-laugh-1.mp3",tags:["sitcom laugh"],suno:!0},{id:"sp-fun-aww-1",name:"Khán giả aww",en:"Crowd aww",category:"cartoon",duration:3.53,url:"/sfx/sp-fun-aww-1.mp3",tags:["crowd aww"],suno:!0},{id:"sp-fun-wow-1",name:"Khán giả wow",en:"Crowd wow",category:"cartoon",duration:3.48,url:"/sfx/sp-fun-wow-1.mp3",tags:["crowd wow"],suno:!0},{id:"sp-fun-cheer-1",name:"Reo hò vỗ tay",en:"Cheer and applause",category:"cartoon",duration:2.76,url:"/sfx/sp-fun-cheer-1.mp3",tags:["cheer and applause"],suno:!0},{id:"sp-fun-buzz-1",name:"Ruồi vo ve",en:"Buzzing flies",category:"cartoon",duration:3.26,url:"/sfx/sp-fun-buzz-1.mp3",tags:["buzzing flies"],suno:!0},{id:"sp-fun-cash-1",name:"Mưa tiền",en:"Money rain",category:"cartoon",duration:2.26,url:"/sfx/sp-fun-cash-1.mp3",tags:["money rain"],suno:!0},{id:"sp-fun-tada-1",name:"Ta-da",en:"Ta-da",category:"cartoon",duration:2.71,url:"/sfx/sp-fun-tada-1.mp3",tags:["ta-da"],suno:!0},{id:"sp-fun-oops-1",name:"Úi trượt",en:"Oops slip",category:"cartoon",duration:1.61,url:"/sfx/sp-fun-oops-1.mp3",tags:["oops slip"],suno:!0},{id:"sp-fun-zoom-1",name:"Zoom kịch tính",en:"Dramatic zoom",category:"cartoon",duration:1.68,url:"/sfx/sp-fun-zoom-1.mp3",tags:["dramatic zoom"],suno:!0},{id:"sp-fun-bell-1",name:"Chuông võ đài",en:"Boxing bell",category:"cartoon",duration:.79,url:"/sfx/sp-fun-bell-1.mp3",tags:["boxing bell"],suno:!0},{id:"sp-fun-horn-1",name:"Còi hơi",en:"Air horn",category:"cartoon",duration:2.06,url:"/sfx/sp-fun-horn-1.mp3",tags:["air horn"],suno:!0},{id:"sp-fun-drum-1",name:"Ba-dum-tss",en:"Rimshot",category:"cartoon",duration:3.53,url:"/sfx/sp-fun-drum-1.mp3",tags:["rimshot"],suno:!0},{id:"sp-fun-sus-1",name:"Nghi ngờ",en:"Suspicious sting",category:"cartoon",duration:1.68,url:"/sfx/sp-fun-sus-1.mp3",tags:["suspicious sting"],suno:!0},{id:"sp-fun-bruh-1",name:"Hụt hẫng",en:"Bruh drop",category:"cartoon",duration:3.53,url:"/sfx/sp-fun-bruh-1.mp3",tags:["bruh drop"],suno:!0},{id:"sp-ambient-1",name:"Phòng công nghệ",en:"Tech room tone",category:"ambience",duration:2.98,url:"/sfx/sp-ambient-1.mp3",tags:["tech room tone"],suno:!0},{id:"sp-music-intro-1",name:"Intro điện tử",en:"Electronic intro",category:"music",duration:1.82,url:"/sfx/sp-music-intro-1.mp3",tags:["electronic intro"],suno:!0},{id:"sp-music-intro-2",name:"Intro lo-fi",en:"Lo-fi intro",category:"music",duration:1.94,url:"/sfx/sp-music-intro-2.mp3",tags:["lo-fi intro"],suno:!0},{id:"sp-music-outro-1",name:"Kết thúc dứt khoát",en:"Punchy outro",category:"music",duration:.98,url:"/sfx/sp-music-outro-1.mp3",tags:["punchy outro"],suno:!0},{id:"sp-transition-1",name:"Chuyển cảnh zoom",en:"Zoom transition",category:"transition",duration:2.23,url:"/sfx/sp-transition-1.mp3",tags:["zoom transition"],suno:!0},{id:"sp-transition-2",name:"Chuyển cảnh xoay",en:"Spin transition",category:"transition",duration:1.73,url:"/sfx/sp-transition-2.mp3",tags:["spin transition"],suno:!0},{id:"sp-transition-3",name:"Chuyển cảnh vuốt giấy",en:"Paper swipe transition",category:"transition",duration:1.99,url:"/sfx/sp-transition-3.mp3",tags:["paper swipe transition"],suno:!0},{id:"sp-transition-4",name:"Chuyển cảnh flash",en:"Flash transition",category:"transition",duration:2.23,url:"/sfx/sp-transition-4.mp3",tags:["flash transition"],suno:!0},{id:"sp-transition-5",name:"Chuyển cảnh light leak",en:"Light leak transition",category:"transition",duration:2.23,url:"/sfx/sp-transition-5.mp3",tags:["light leak transition"],suno:!0}],WA={...$3,...w3,...x3},S3=t=>t.id in lf?{...t,duration:lf[t.id],stereo:!0}:t,I3=t=>t.id in cf?{...t,duration:cf[t.id],stereo:!0,suno:!0}:t,Eu=[...k3,...M3].map(S3).concat(v3.map(t=>({...t,stereo:!0}))).map(I3).concat(E3.map(t=>({...t,stereo:!0}))).filter(t=>!(t.id in Ps)),Vg=.35,A3=.6,C3=1.5;Eu.map(t=>t.id);const Ba=t=>Eu.find(e=>e.id===t)??(typeof t=="string"&&Object.hasOwn(Ps,t)?Eu.find(e=>e.id===Ps[t]):void 0),j3=[7,6,2],T3=t=>typeof t=="string"&&Object.hasOwn(Ps,t)?Ps[t]:null,O3=t=>{const e=typeof t=="string"&&/^\/sfx\/([a-z0-9-]+)\.mp3$/.exec(t);if(!e)return null;const o=T3(e[1])||e[1];return Ba(o)?o:null};function P3(t){const e=t?.sound;return!e||typeof e!="object"||e.id!==t.sfxId||typeof t.sfxId!="string"||!/^plugin:[a-z0-9.-]{3,40}\/[a-z0-9-]{1,40}$/.test(t.sfxId)||typeof e.name!="string"||e.name.length>120||!Number.isFinite(e.duration)||e.duration<.04||e.duration>(e.music===!0?601:121)||typeof e.url!="string"||!/^https:\/\//.test(e.url)||e.url.length>4e3||typeof e.gcsUri!="string"||!/^gs:\/\//.test(e.gcsUri)||e.gcsUri.length>600?null:{id:e.id,name:e.name,duration:e.duration,url:e.url,gcsUri:e.gcsUri,category:"plugin",tags:[],...e.music===!0?{music:!0}:{}}}function z3(t,e,o,r,n=null){const a=l=>!e[l]?.locked&&!t.some(p=>p.track===l&&p.start<o+r-1e-6&&p.start+p.duration>o+1e-6);if(n!=null){if(!Ci.includes(n))throw Error("Sound effects go on an audio track");if(!a(n))throw Error("That audio track is locked or already has a clip there");return n}const i=j3.find(a);if(i===void 0)throw Error("No free audio track at that time — move or delete an overlapping clip");return i}function L3(t,e,o,r,n={}){const{sfx:a,...i}=zs(t,e,o,r,n);return{...i,nodeId:`music:${o.id}`,label:`Nhạc · ${o.name}`,volume:Number.isFinite(n.volume)?i.volume:A3}}function zs(t,e,o,r,{volume:n,track:a,id:i}={}){const l=ht(r),p=ht(Math.max(1/be,o.duration)),c=Number.isFinite(n)?Math.max(0,Math.min(1,n)):Vg;return{id:i,nodeId:`sfx:${o.id}`,track:z3(t,e,l,p,a),start:l,duration:p,inPoint:0,sourceDuration:o.duration,volume:c,url:o.url,kind:"audio",label:`SFX · ${o.name}`,sfx:o.id}}const N3={"lower-third":"swoosh","keyword-pop":"pop","gradient-keyword":"pop","kinetic-title":"whoosh-up","particle-burst":"sparkle","progress-ring":"tick","chat-typing":"typing","neon-swirl":"whoosh-up",scribble:"swipe","light-leak":"whoosh-up",letterbox:"swoosh",vhs:"glitch","ed-box-wipe":"whoosh-heavy","ed-arc-swoosh":"whoosh-fast-swish","ed-scroll-push":"whoosh-short-up","ed-morph-handoff":"pop-double","ed-star-flythrough":"sparkle","ed-blur-words":"whoosh-airy","ed-window-morph":"whoosh-short-up","ed-window-morph-v":"whoosh-short-down","ed-flicker-cut":"glitch-short","ed-color-flash":"whoosh-airy","ed-negative-blink":"static-burst","ed-silhouette-lead":"whoosh-airy","ed-flash-invert":"pro-flash-burst","ed-invert-cut":"pro-impact-whoosh-sub","ur-photocopy-scribble":"marker-circle","ur-magenta-flash":"hit-snare","ur-neon-edge":"neon-buzz","ur-torn-paper":"paper-slide","ur-cutout-blocks":"hit-clap-stack","ur-sticker-slap":"camera-shutter","tl-duotone-flash":"hit-snare","tl-pixel-dissolve":"glitch-short","tl-card-cascade":"whoosh-fast-swish","tl-chevron-push":"swoosh","tl-scramble":"data-processing","tl-blur-whip":"whoosh-double","tl-frame-zoom":"zoom-whoosh","glow-views-burst":"counter-roll","glow-coin-drop":"coin-clink","glow-balance-card":"counter-roll","glow-crowd-market":"crowd-cheer","glow-dual-curve":"riser-1s","glow-audience-wheel":"wheel-spin","glow-mindset":"chime","glow-versus-word":"impact","glow-perspective-line":"whoosh-fast-swish","glow-cta-arc":"sparkle","noir-thinker":"drop-slow-bass","noir-number-grid":"neon-buzz","noir-chapter-wave":"whoosh-cinematic","noir-silhouette-duo":"neon-buzz","noir-drill-target":"drill","noir-leaky-cup":"pour-drink","noir-idea-board":"pin-stick","noir-persona-box":"marker-circle","noir-phone-cta":"notification","noir-caption":"punch","pop-keyword":"pop","pop-glow-line":"whoosh-up","pop-icon-word":"bubble-pop","pop-emoji-react":"bubble-pop","pop-thought-head":"swoosh","pop-pinned-card":"pin-stick","pop-circle-wipe":"whoosh-cinematic","pop-circle-highlight":"marker-circle","pop-profile-card":"notification","pop-keyboard":"typing","studio-hero-tilt":"whoosh-cinematic","studio-drag-asset":"paper-slide","studio-asset-wall":"whoosh-airy","studio-timeline-build":"pop-double","studio-panels-explode":"whoosh-heavy","studio-monitor-play":"ui-tap","studio-ai-command":"ui-message-out","studio-before-after":"slide-in","studio-export":"ui-download-done","studio-multi-format":"whoosh-double","studio-sales-growth":"counter-roll","studio-time-saved":"ui-success-soft","studio-team-collab":"ui-message-in","studio-brand-kit":"pop-high","studio-template-flip":"card-flip","studio-feature-grid":"pop","studio-keyframe-curve":"sweep-up","studio-sfx-drop":"tap-wood","studio-click-callout":"ui-tap","studio-endcard":"sting-reveal","creator-behind-title":"impact-sub-boom","creator-coin-flip":"coin-clink","creator-money-rain":"ka-ching","creator-electric-arc":"static-burst","creator-3d-glyph":"pop-high","creator-question-card":"sting-mystery","creator-neon-script":"neon-buzz","creator-flash":"whoosh-short-up","creator-tick-caption":"ui-success-soft","creator-news-cards":"card-flip","creator-timeline-strip":"whoosh-airy","creator-icon-row":"ui-tap","creator-phone-duo":"swipe","creator-watch-chart":"whoosh-short-down","creator-scrub-bar":"ui-scroll-tick","creator-dot-list":"pop-low","creator-offer-card":"cash-counting","creator-notify-stack":"ui-notify-soft","creator-message-chip":"ui-message-out","creator-thumb-wall":"whoosh-airy","creator-wave-mismatch":"ui-error","creator-layout-box":"buzzer-wrong","creator-glass-shatter":"pro-impact-glass-break","creator-reaction-pop":"like-pop","creator-pill-caption":"ui-success-soft","creator-chapter-bar":"whoosh-cinematic","creator-quote-end":"logo-soft-chime","mono-grid-paper":"whoosh-airy","mono-blob-frame":"whoosh-heavy","mono-selection-text":"ui-tap","mono-two-tier":"pop-low","mono-ribbon-wipe":"whoosh-short-down","mono-orbit-ring":"sweep-up","mono-slide-line":"whoosh-fast-swish","mono-spotlight-panels":"slam","mono-object-plate":"tap-glass","mono-cta":"ui-success-soft","ai-neural-net":"data-processing","ai-chat-reply":"pop","ai-prompt-result":"whoosh-fast-swish","ai-chip-glow":"riser-electronic","ai-data-stream":"data-blip","ai-scan-frame":"robot-beeps","ai-agent-loop":"whoosh-fast-swish","ai-token-counter":"data-processing","ai-model-compare":"sweep-up","ai-network-globe":"logo-digital-glitch","fin-candlestick":"sweep-up","fin-ticker-tape":"data-blip","fin-portfolio-donut":"pop","fin-card-tap":"ui-success-soft","fin-compound-growth":"riser-1s","fin-wallet-balance":"cash-counting","fin-transfer":"whoosh-fast-swish","fin-savings-jar":"coins-drop","fin-risk-gauge":"tap-glass","fin-market-heatmap":"pop-double","exp-backdrop":"whoosh-airy","exp-kicker-title":"impact-sub-boom","exp-comment-thread":"pop","exp-profile-card":"ui-tap","exp-mood-gauge":"riser-tension","exp-notifications":"pop-double","exp-expert-stamp":"slam","exp-checklist-x":"ui-tap","exp-toggle-on":"ui-success-soft","exp-id-badge":"whoosh-short-down","exp-triple-meters":"riser-electronic","exp-price-up":"sweep-up","exp-cta-button":"ui-success-soft","exp-fame-meter":"pop-high","exp-question-banner":"whoosh-short-down","exp-room-panel":"whoosh-airy","info-backdrop":"whoosh-airy","info-ring-carousel":"whoosh-airy","info-title":"pop-low","info-ring-progress":"sweep-up","info-multi-rings":"data-blip","info-bar-columns":"pop-double","info-wave-area":"sweep-up","info-line-dashed":"data-processing","info-hbar-lines":"whoosh-fast-swish","info-donut-legend":"pop","info-kpi-card":"ui-success-soft","info-card-flip":"card-flip","info-card-fan":"card-flip","info-tilted-dashboard":"whoosh-heavy","info-gauge":"riser-1s","info-progress-steps":"ui-tap","info-bubbles":"bubble-pop","info-radar":"data-processing","info-pie-pop":"pop-high","info-stat-chips":"pop","info-arc-timeline":"whoosh-airy","cyber-backdrop":"whoosh-airy","cyber-orbit-cards":"whoosh-airy","cyber-circuit-chip":"data-processing","cyber-chip-morph":"riser-electronic","cyber-logo-reveal":"logo-digital-glitch","cyber-glitch-title":"glitch-short","cyber-particle-assemble":"data-processing","cyber-plexus":"whoosh-airy","cyber-trace-lines":"data-blip","cyber-neon-icons":"pop-high","cyber-hud-frame":"robot-beeps","cyber-data-panel":"glitch-short","cyber-loading-ring":"riser-electronic","cyber-slab-wipe":"whoosh-fast-swish","cyber-pixel-dissolve":"glitch","cyber-scan-reveal":"sweep-up","cyber-energy-core":"riser-tension","cyber-badge-unlock":"game-coin","cyber-countdown":"robot-beep","cyber-lower-third":"whoosh-short-down","kin-word-collage":"pop","kin-hero-lead":"impact-sub-boom","kin-arc-word":"whoosh-airy","kin-wave-word":"whoosh-airy","kin-circle-badge":"pop-low","kin-grow-toward":"whoosh-fast-swish","kin-blur-slide":"whoosh-fast-swish","kin-zoom-blur":"slam","kin-pixel-word":"glitch-short","kin-floor-word":"whoosh-heavy","kin-tilt-stack":"whoosh-short-down","kin-ribbon-nodes":"sweep-up","kin-word-swap":"ui-tap","kin-big-number":"impact-sub-boom","kin-strike-replace":"pop-high","kin-swoosh-underline":"whoosh-airy","kin-scatter-assemble":"whoosh-double","kin-letter-drop":"pop-double","kin-stretch-word":"slam","kin-echo-stack":"riser-1s","kin-quote":"pop-low","kin-comment-cta":"ui-success-soft","kin-flip-letters":"card-flip","kin-marker-swipe":"whoosh-fast-swish","kin-ribbon-sweep":"whoosh-airy","kin-split-line":"whoosh-fast-swish","bridge-portal":"riser-1s","bridge-slab":"whoosh-fast-swish","bridge-iris":"whoosh-heavy","bridge-flash":"slam","bridge-whip":"whoosh-fast-swish","bridge-ink":"whoosh-airy","bridge-stripes":"whoosh-double","bridge-shapes":"pop-double","bridge-glitch":"glitch-short","bridge-tunnel":"riser-electronic","tvc-backdrop":"whoosh-airy","tvc-brand-open":"sweep-up","tvc-problem":"slam","tvc-solution":"riser-1s","tvc-feature-trio":"pop-double","tvc-big-stat":"data-processing","tvc-trust-badges":"pop","tvc-testimonial":"ui-success-soft","tvc-offer":"ka-ching","tvc-countdown-offer":"ui-tap","tvc-cta-contact":"ui-success-soft","tvc-logo-sting":"logo-soft-chime","tvc-location":"pop-low","tvc-slogan":"whoosh-short-down","tvc-before-after":"whoosh-fast-swish","tvc-partners":"whoosh-airy","home-title":"whoosh-airy","health-title":"whoosh-airy","fit-title":"whoosh-airy","travel-title":"whoosh-airy","menu-title":"whoosh-airy","auto-title":"whoosh-airy","home-listing-card":"whoosh-airy","home-floor-plan":"pencil-writing","home-map-pin":"pin-stick","home-price-m2":"counter-roll","home-key-handover":"keys-unlock","home-amenities":"pop","home-mortgage":"cash-counting","home-before-after":"swipe","home-skyline":"riser-1s","home-open-house":"card-flip","home-room-tour":"slide-in","home-sold-stamp":"slam","health-heartbeat":"heart-monitor","health-pill-capsule":"pill-rattle","health-doctor-card":"card-flip","health-booking":"ui-success-soft","health-vitals":"data-blip","health-checklist":"tick","health-tooth":"sparkle","health-cross-reveal":"sting-reveal","health-water-intake":"pour-drink","health-body-map":"scan-sweep","health-pharmacy-shelf":"thud-box","health-hotline":"phone-vibrate","fit-rep-counter":"counter-roll","fit-round-timer":"coach-whistle","fit-macros-ring":"ui-success-soft","fit-pr-medal":"sting-win","fit-step-counter":"counter-roll","fit-workout-plan":"tick","fit-scoreboard":"crowd-cheer","fit-speed-lines":"slam","fit-heart-zone":"heartbeat","fit-before-after":"impact","fit-coach-card":"whoosh-heavy","fit-lower-third":"swoosh","travel-boarding-pass":"paper-slide","travel-flight-route":"airplane-takeoff","travel-itinerary":"pop","travel-room-card":"service-bell","travel-weather":"whoosh-airy","travel-passport-stamp":"slam","travel-postcard":"card-flip","travel-suitcase-pack":"suitcase-roll","travel-compass":"spin-whoosh","travel-countdown-trip":"counter-roll","travel-review-stars":"sparkle","travel-checkin":"keys-unlock","menu-board":"chalk-board","menu-steaming-dish":"liquid-boiling","menu-recipe-steps":"knife-chopping","menu-order-ticket":"printer","menu-spice-level":"sizzle-pan","menu-price-badge":"ka-ching","menu-delivery-route":"motorbike-pass","menu-combo-builder":"pop","menu-rating-plate":"cutlery-plate","menu-coffee-pour":"pour-drink","menu-open-hours":"shop-door-chime","menu-new-dish":"sting-reveal","auto-speedometer":"ev-accelerate","auto-spec-sheet":"slide-in","auto-ev-battery":"power-up","auto-test-drive":"car-engine-start","auto-car-reveal":"sting-reveal","auto-light-streaks":"car-pass-by","auto-price-tag":"ka-ching","auto-dashboard-hud":"digital-scan","auto-fuel-save":"counter-roll","auto-service-check":"drill","auto-finance":"coin-clink","auto-lower-third":"whoosh-fast-swish","travel-city-poster":"whoosh-airy","travel-city-montage":"swipe","travel-name-wall":"whoosh-windy","travel-landmark-rise":"riser-half","travel-sticker-burst":"pop-double","travel-collage-cta":"slam","pulse-dot-bloom":"swell-pad","pulse-light-bars":"riser-electronic","pulse-target-rings":"scan-sweep","pulse-hex-spin":"spin-whoosh","pulse-tri-orbit":"hologram","pulse-equalizer":"data-blip","pulse-perspective-lines":"whoosh-cinematic","pulse-half-sweep":"sweep-up","pulse-diamond-drop":"hit-deep","pulse-split-fields":"slide-in","pulse-ripple":"singing-bowl","pulse-grid-wave":"digital-scan","pulse-title-glow":"sting-reveal","pulse-orbit-dots":"sparkle","pulse-word":"whoosh-airy","cine-night-house":"sparkle","cine-eye":"sting-mystery","cine-sword":"sword-swish","cine-crown-rain":"logo-royal-strings","cine-heart":"heartbeat","cine-moon":"music-box","cine-key":"keys-unlock","cine-hourglass":"swell-pad","cine-rocket":"airplane-takeoff","cine-lighthouse":"ocean-waves","cine-flame":"singing-bowl","cine-tree":"harp-gliss","cine-planet":"hologram","cine-door":"door-open-close","cine-caption":"whoosh-airy","cine-spark":"sparkle","pulse-horizon-open":"whoosh-airy","pulse-glossy-sphere":"hologram","pulse-color-cycle-bars":"kick-808","pulse-column-drop":"thud-box","pulse-ring-cross":"sting-reveal","pulse-lens-arcs":"scan-sweep","pulse-ui-bars":"ui-scroll-tick","pulse-ball-collide":"hit-soft","pulse-venn":"chime","pulse-ring-zoom":"zoom-whoosh","pulse-pit-bounce":"jump-boing","pulse-totem-stack":"tap-wood","pulse-end-title":"logo-soft-chime","story-phone-message":"ui-message-out","story-city-flythrough":"fly-by","story-tower-dissolve":"sparkle","story-satellite-orbit":"hologram","story-warp-tunnel":"whoosh-cinematic","story-light-column":"swell-pad","story-pillar-pass":"whoosh-fast-swish","story-hill-houses":"whoosh-windy","story-paper-crumple":"paper-slide","story-face-reaction":"sting-mystery","story-spotlight-v":"sting-reveal","story-planet-horizon":"riser-tension","story-heart-burst":"heartbeat","story-caption":"whoosh-airy","lumen-dot-ring":"swell-pad","lumen-beat-flash":"kick-808","lumen-jelly-bloom":"bubble-rise","lumen-horizon-flash":"sweep-up","lumen-creature":"hologram","lumen-orbit-ring":"scan-sweep","lumen-wedge-fan":"whoosh-airy","lumen-holo-sphere":"hologram","lumen-white-flash":"whoosh-cinematic","lumen-ring-tunnel":"zoom-whoosh","lumen-neon-word":"neon-buzz","lumen-orb-split":"chime","lumen-caption":"whoosh-airy","lumen-orb":"sparkle","lumen-critter":"bubble-pop","lumen-spark-trail":"whoosh-short-up","rebound-dots-merge":"pop-high","rebound-brick-tower":"thud-box","rebound-ramp-shot":"whoosh-short-up","rebound-chevron-field":"tap-glass","rebound-piston-launch":"jump-boing","rebound-tube-slide":"slide-whistle-down","rebound-gradient-tile":"hit-soft","rebound-skyline-hop":"xylo-up","rebound-frame-in-frame":"zoom-whoosh","rebound-radial-web":"scan-sweep","rebound-atom-arches":"hologram","rebound-neon-word":"neon-buzz","rebound-gradient-flash":"impact","rebound-caption":"whoosh-airy","rebound-ball":"pop-low","rebound-bricks":"tap-wood","join-cube-turn":"whoosh-heavy","join-panel-flip":"card-flip","join-paper-fold":"paper-slide","join-page-curl":"page-turn","join-paper-tear":"zip-up","join-liquid-drip":"pour-drink","join-ripple-rings":"water-drip","join-particle-reform":"sparkle","join-split-screen":"whoosh-double","join-shape-morph":"swoosh","join-type-wall":"whoosh-fast-swish","join-zoom-object":"zoom-whoosh","join-blinds-3d":"slide-in","join-mosaic-tiles":"swipe","join-halftone":"scan-sweep","join-light-leak":"reverse-cymbal","fluid-blob-morph":"swell-pad","fluid-drop-splash":"water-splash","fluid-wave-flood":"ocean-waves","fluid-lava-lamp":"liquid-boiling","fluid-ink-bloom":"spa-water","fluid-bubbles":"water-bubbles","fluid-pour":"pour-drink","fluid-gradient-mesh":"whoosh-airy","fluid-melt-word":"water-drip","fluid-swirl":"whoosh-water-low","fluid-droplet-grid":"bubble-pop","fluid-glass-orb":"tap-glass","fluid-caption":"whoosh-airy","fluid-blob-el":"bubble-rise","fluid-drip-el":"water-drip","promo-logo-spark":"logo-soft-chime","promo-flare-card":"whoosh-airy","promo-aurora-card":"swell-pad","promo-card-pill":"whoosh-short-up","promo-prompt-bar":"keyboard-typing","promo-icon-cloud":"bubble-rise","promo-icon-converge":"ui-message-in","promo-arrow-launch":"riser-electronic","promo-dome-horizon":"sting-reveal","promo-feature-cards":"card-flip","promo-cta-button":"ui-tap","promo-glass-orbit":"hologram","promo-caption":"whoosh-airy","promo-glass-icon":"sparkle","promo-star-flare":"sparkle","morph-light-thread":"swell-pad","morph-arrow-ring":"spin-whoosh","morph-diamond-frame":"sparkle","morph-sparkle-glow":"chime","morph-pill-band":"slide-in","morph-gradient-card":"card-flip","morph-loading-dots":"typing-chat","morph-light-pole":"power-on","morph-sun-flood":"riser-electronic","morph-path-tag":"pin-stick","morph-blob-merge":"bubble-pop","morph-logo-wings":"logo-soft-chime","morph-caption":"whoosh-airy","glass-orb-rise":"hologram","glass-balance":"counter-roll","glass-coin-bars":"coins-drop","glass-step-chart":"data-blip","glass-line-target":"quiz-correct-chime","glass-candles":"scan-sweep","glass-progress":"power-up","glass-emblem":"sting-reveal","glass-words":"whoosh-airy","glass-stack":"whoosh-short-up","clipoox-logo-title":"logo-soft-chime","clipoox-whip-text":"whoosh-fast-swish","clipoox-card-row":"slide-in","clipoox-stat-dome":"sweep-up","clipoox-connect":"power-on","clipoox-ui-stack":"whoosh-airy","clipoox-discount":"ka-ching","clipoox-phone-build":"whoosh-short-down","clipoox-phone-wall":"whoosh-double","clipoox-price-dial":"counter-roll","clipoox-end-card":"sting-reveal","clipoox-title-sparkle":"sparkle","clipoox-search-ui":"ui-key-click","clipoox-icon-zoom":"zoom-whoosh","clipoox-url-analyze":"keyboard-typing","clipoox-zoom-burst":"whoosh-cinematic","clipoox-particle-sphere":"data-processing","clipoox-brand-kit":"ui-open","clipoox-giant-word":"whoosh-fast-swish","clipoox-product-pick":"ui-tap","clipoox-count-ruler":"ui-scroll-tick","clipoox-status-log":"typing","clipoox-gen-cards":"digital-scan","clipoox-publish-btn":"ui-tap","clipoox-slot-word":"slot-reel","clipoox-jelly-wipe":"whoosh-water-low","clipoox-counter-dots":"counter-roll","clipoox-pill-lower":"slide-in","clipoox-glass-thanks":"chime","clipoox-claim-block":"whoosh-fast-swish","clipoox-star-flip":"sting-reveal","clipoox-fine-print":"ui-notify-soft","clipoox-coin-rain":"coins-drop","clipoox-chip-circuit":"power-on","clipoox-glitch-headline":"glitch-short","clipoox-balance-card":"ka-ching","clipoox-model-wheel":"slot-reel","clipoox-countdown-hud":"counter-roll","clipoox-number-rush":"whoosh-fast-swish","clipoox-notch-frame":"sting-reveal","clipoox-dash-gauge":"data-blip","clipoox-growth-race":"riser-electronic","clipoox-big-percent":"counter-roll","clipoox-line-stat":"sweep-up","clipoox-dot-grid-stat":"digital-scan","clipoox-logo-end":"logo-soft-chime","clipoox-sticker-stack":"slam","clipoox-slash-list":"keyboard-typing","clipoox-skill-header":"slide-in","clipoox-before-after":"swipe","clipoox-heat-flash":"whoosh-fire","clipoox-url-live":"keyboard-typing","clipoox-model-scroll":"ui-scroll-tick","clipoox-holo-button":"power-on","clipoox-bar-lower":"slide-in","clipoox-bar-compare":"sweep-up","clipoox-lock-button":"ui-lock","clipoox-offer-table":"slam","clipoox-checklist":"quiz-correct-chime","clipoox-site-cards":"whoosh-cinematic","clipoox-trace-label":"digital-scan","clipoox-lock-cta":"keys-unlock","clipoox-v-hook":"whoosh-fast-swish","clipoox-v-stack":"slide-in","clipoox-v-steps":"pop","clipoox-v-split":"swipe","clipoox-v-stat":"counter-roll","clipoox-v-plans":"card-flip","clipoox-v-phone":"ui-tap","clipoox-v-cta":"sting-reveal","clipoox-v-top-banner":"ui-message-in","clipoox-v-chat":"ui-message-in","clipoox-v-marquee":"whoosh-airy","rv-logo-open":"logo-soft-chime","rv-packshot-title":"whoosh-airy","rv-product-callout":"ui-tap-soft","rv-benefit-list":"pop-low","rv-rating":"ui-success-soft","rv-cta-end":"ui-tap-soft","rv-step-caption":"pluck-soft","rv-instruction":"ui-tap-soft","rv-brand-watermark":"whoosh-airy","course-question-nav":"ui-open","course-step-tiles":"ui-tap-soft","course-tool-badge":"ui-message-in","course-chapter-card":"page-turn","course-key-takeaway":"ui-success-soft","course-progress-bar":"ui-scroll-tick","course-screen-frame":"ui-focus","course-callout":"marker-circle","clipoox-prompt-box":"keyboard-typing","clipoox-v-prompt-box":"keyboard-typing","clipoox-glitch-slam":"glitch-short","clipoox-v-glitch-slam":"glitch-short","clipoox-status-shimmer":"data-processing","clipoox-v-status-shimmer":"data-processing","clipoox-window-burst":"sparkle","clipoox-v-window-burst":"sparkle","clipoox-logo-type":"keyboard-typing","clipoox-v-logo-type":"keyboard-typing","clipoox-ball-pit":"bubble-pop","clipoox-v-ball-pit":"bubble-pop","clipoox-pixel-face":"robot-beep","clipoox-v-pixel-face":"robot-beep","clipoox-core-orbit":"hologram","clipoox-v-core-orbit":"hologram","clipoox-holo-mesh":"scan-sweep","clipoox-v-holo-mesh":"scan-sweep","clipoox-card-cube":"whoosh-airy","clipoox-v-card-cube":"whoosh-airy","clipoox-ray-logo":"sting-reveal","clipoox-v-ray-logo":"sting-reveal","clipoox-end-credit":"ui-notify-soft","clipoox-v-end-credit":"ui-notify-soft","aiw-race-title":"whoosh-fast-swish","aiw-v-race-title":"whoosh-fast-swish","aiw-prompt-attach":"keyboard-typing","aiw-v-prompt-attach":"keyboard-typing","aiw-scan":"digital-scan","aiw-v-scan":"digital-scan","aiw-gen-checklist":"data-processing","aiw-v-gen-checklist":"data-processing","aiw-style-pick":"ui-tap","aiw-v-style-pick":"ui-tap","aiw-step-list":"ui-success-soft","aiw-v-step-list":"ui-success-soft","aiw-viewport":"hologram","aiw-v-viewport":"hologram","aiw-race-hud":"game-coin","aiw-v-race-hud":"game-coin","aiw-pause-menu":"ui-open","aiw-v-pause-menu":"ui-open","aiw-select":"game-level-up","aiw-v-select":"game-level-up","aiw-end-subtitle":"ui-notify-soft","aiw-v-end-subtitle":"ui-notify-soft","course-pip-frame":"ui-focus","course-label-tag":"ui-message-in","course-journey-line":"sweep-up","course-photo-pop":"pop-high","course-cover-insert":"card-flip","course-framework-stack":"ui-tap-soft","course-split-cards":"ui-focus","course-brand-bug":"whoosh-airy","course-compare-board":"marker-circle","course-doc-highlight":"marker-circle","course-map-pins":"pop-low","tl-hook-stack":"whoosh-fast-swish","tl-v-hook-stack":"whoosh-fast-swish","tl-title-lockup":"keyboard-typing","tl-v-title-lockup":"keyboard-typing","tl-word-build":"ui-tap","tl-v-word-build":"ui-tap","tl-hero-swarm":"whoosh-airy","tl-v-hero-swarm":"whoosh-airy","tl-feature-panel":"ui-open","tl-v-feature-panel":"ui-open","tl-count-stairs":"data-processing","tl-v-count-stairs":"data-processing","tl-player":"ui-tap","tl-v-player":"ui-tap","tl-frames":"ui-success-soft","tl-v-frames":"ui-success-soft","tl-4k-split":"digital-scan","tl-v-4k-split":"digital-scan","tl-end-card":"ui-notify-soft","tl-v-end-card":"ui-notify-soft","fr-window":"ui-open","fr-v-window":"ui-open","fr-versus":"whoosh-double","fr-v-versus":"whoosh-double","fr-headline":"typing","fr-v-headline":"typing","fr-clock":"counter-roll","fr-v-clock":"counter-roll","fr-chips":"pop-high","fr-v-chips":"pop-high","fr-paper":"paper-slide","fr-v-paper":"paper-slide","fr-comment-cta":"ui-notify-soft","fr-v-comment-cta":"ui-notify-soft","fr-chapter":"slot-reel","fr-v-chapter":"slot-reel","fr-definition":"slide-in","fr-v-definition":"slide-in","fr-recap":"ui-success-soft","fr-v-recap":"ui-success-soft","fr-lower-third":"slide-in","fr-v-lower-third":"slide-in","ub-liked":"ui-tap","ub-copy-link":"ui-tap","ub-paste-chip":"typing-chat","cs-prompt":"keyboard-typing","cs-title-curve":"whoosh-airy","cs-cursor-click":"pro-mouse-click-office","cs-file-window":"ui-open","cs-timeline-fix":"ui-success-soft","cs-generating":"data-processing","cs-card-fan":"pro-whoosh-card","cs-graph-editor":"keyboard-typing","cs-render-card":"pro-digital-processing","cs-callout":"pro-impact-whoosh-sub","cs-timer-ring":"pro-trailer-clock-tick","cs-pen-logo":"pro-stylus-tap","cs-multi-cursor":"ui-tap","cs-phone-trio":"pro-whoosh-ui-bright","cs-cta-logo":"pro-ui-click","cs-doc-stamp":"pro-foley-stamp","cs-route-map":"pin-stick","cs-flip-board":"card-flip","cs-title-plates":"paper-slide","cs-glitch-type":"glitch-short","mx-code-rain":"data-processing","mx-data-tunnel":"whoosh-cinematic","mx-decode-text":"digital-scan","mx-crt-screen":"keyboard-typing","mx-code-wipe":"glitch-short","lr-light-ribbon":"whoosh-cinematic","lr-name-spark":"sparkle","lr-flag-wave":"whoosh-airy","lr-chrome-logo":"whoosh-cinematic","lr-purple-flash":"whoosh-airy","sc-dot-screen":"pro-flash-burst","sc-scan-boxes":"pro-digital-ui-scan","sc-named-cursor":"pro-mouse-click-office","sc-card-label":"pro-popup-1","sc-comment-pill":"pro-ui-heart-like","fh-call-panel":"pro-digital-hologram-on","fh-keypad":"pro-phone-tap-glass","fh-text-column":"pro-digital-data-short","fh-face-scan":"pro-scifi-scanner","fh-chat-bubble":"pro-ui-typing-bubble","fh-data-ring":"pro-scifi-ui-hud","fh-music-player":"pro-ui-soft-confirm","fh-heart-rate":"heart-monitor","fh-profile-card":"pro-ui-card-select","fh-notify-stack":"pro-ui-notify-soft","fh-radar-map":"pro-scan-2","fh-target-lock":"pro-ui-focus-beep","fh-translate":"pro-ui-message-in","fh-weather":"pro-ui-glass-ping","hist-year-wall":"whoosh-heavy","hist-serif-title":"whoosh-airy","hist-tape-label":"pro-foley-tape-rip","hist-stitch-card":"pop","hist-depth-words":"pro-riser-shimmer","hist-big-word":"impact","hist-search-cta":"pro-ui-click"},F3=t=>N3[t]??"pop";function XA({clips:t=[],punches:e=[],existing:o=[]}={},{gap:r=C3,volume:n=Vg}={}){const a=[...t.filter(p=>p&&(p.motion||p.title)&&Number.isFinite(p.start)).map(p=>({at:p.start,sfxId:p.motion?.preset?F3(p.motion.preset):"pop"})),...e.filter(p=>Number.isFinite(p?.at)).map(p=>({at:p.at,sfxId:p.sfxId??"punch"}))].sort((p,c)=>p.at-c.at),i=o.filter(p=>p.sfx||O3(p.url)).map(p=>p.start),l=[];for(const p of a)!Ba(p.sfxId)||i.some(c=>Math.abs(c-p.at)<r)||(i.push(p.at),l.push({op:"addSfx",sfxId:p.sfxId,at:+p.at.toFixed(3),volume:n}));return l}const Wg=Object.freeze({front:{s:2.2,x:0,y:.15,z:-1,ry:0,rx:0,f:1},left:{s:2.2,x:-1.9,y:-.1,z:-.4,ry:30,rx:0,f:1},right:{s:2.2,x:1.9,y:-.1,z:-.4,ry:-30,rx:0,f:1},above:{s:1.8,x:0,y:-1.45,z:-.4,ry:0,rx:-12,f:1},scan:{short:1.95,x:0,y:0,z:0,ry:0,rx:0,f:1},ring:{short:2.9,x:0,y:-.05,z:0,ry:0,rx:0,f:1}}),R3=2.6,Su=Object.freeze(Object.keys(Wg)),Xg=Object.freeze({call:{name:"Cuộc gọi hologram",en:"Hologram call",layers:[{preset:"fh-call-panel",place:"left"},{preset:"fh-keypad",place:"front"}]},keypad:{name:"Bàn phím trước mặt",en:"Dial pad in front",layers:[{preset:"fh-keypad",place:"front"}]},text:{name:"Cột chữ bay",en:"Floating text column",layers:[{preset:"fh-text-column",place:"right"}]},scan:{name:"Quét khuôn mặt",en:"Face scan",layers:[{preset:"fh-face-scan",place:"scan"}]},chat:{name:"Bong bóng chat",en:"Chat bubble",layers:[{preset:"fh-chat-bubble",place:"right"}]},ring:{name:"Vòng dữ liệu quanh đầu",en:"Data ring round the head",layers:[{preset:"fh-data-ring",place:"ring"}]},music:{name:"Trình phát nhạc",en:"Music player",layers:[{preset:"fh-music-player",place:"left"}]},health:{name:"Nhịp tim + vòng dữ liệu",en:"Heart rate + data ring",layers:[{preset:"fh-heart-rate",place:"right"},{preset:"fh-data-ring",place:"ring"}]},profile:{name:"Thẻ hồ sơ",en:"Profile card",layers:[{preset:"fh-profile-card",place:"right"}]},notify:{name:"Chồng thông báo",en:"Notification stack",layers:[{preset:"fh-notify-stack",place:"left"}]},radar:{name:"Radar bản đồ",en:"Radar map",layers:[{preset:"fh-radar-map",place:"above"}]},lock:{name:"Khoá mục tiêu",en:"Target lock",layers:[{preset:"fh-target-lock",place:"scan"}]},translate:{name:"Dịch song ngữ",en:"Live translate",layers:[{preset:"fh-translate",place:"above"}]},weather:{name:"Thời tiết",en:"Weather",layers:[{preset:"fh-weather",place:"right"}]},scanlock:{name:"Quét + khoá mục tiêu",en:"Scan + target lock",layers:[{preset:"fh-face-scan",place:"scan"},{preset:"fh-target-lock",place:"scan"}]},dashboard:{name:"Bảng điều khiển 2 bên",en:"Dashboard both sides",layers:[{preset:"fh-call-panel",place:"left"},{preset:"fh-text-column",place:"right"}]},social:{name:"Mạng xã hội",en:"Social",layers:[{preset:"fh-notify-stack",place:"left"},{preset:"fh-chat-bubble",place:"right"}]},cyber:{name:"Cyber HUD",en:"Cyber HUD",layers:[{preset:"fh-face-scan",place:"scan"},{preset:"fh-data-ring",place:"ring"},{preset:"fh-text-column",place:"right"}]},travel:{name:"Du lịch",en:"Travel",layers:[{preset:"fh-weather",place:"left"},{preset:"fh-radar-map",place:"right"}]},creator:{name:"Creator",en:"Creator",layers:[{preset:"fh-profile-card",place:"left"},{preset:"fh-music-player",place:"right"}]}}),D3=Object.freeze(Object.keys(Xg)),pf=t=>+t.toFixed(3),uf=(t,[e,o])=>Math.max(e,Math.min(o,t));function df(t="front",e=16/9,o={}){const r=Wg[t];if(!r)throw Error(`Face place must be one of ${Su.join(", ")}`);const n=uf(e,ip.a),{short:a,...i}=r,l={...rb,...i,s:a?a*Math.max(1,n):Math.min(r.s,R3*n),a:pf(n)},p=c=>typeof c=="number"&&Number.isFinite(c);for(const[c,s]of[["s","s"],["x","x"],["y","y"],["z","z"],["ry","ry"],["rx","rx"],["r","r"],["follow","f"]])p(o[c])&&(l[s]=o[c]);o.mirror!==void 0&&o.mirror!==null&&(l.m=o.mirror===!0||o.mirror===1?1:0);for(const c of Object.keys(l))c in ip&&c!=="m"&&(l[c]=pf(uf(l[c],ip[c])));return l.m||delete l.m,l}const rs=t=>t?.face?.v===2&&!!t.face.mesh,hf=.7,B3=1/30,_3=t=>t<.5?4*t*t*t:1-(-2*t+2)**3/2;function G3({at:t,dur:e}){const o=Math.max(Yd.dur[0]/(1-hf),Number(e)||1.2),r=+(o*hf).toFixed(3);return nb({at:+(Number(t)+r).toFixed(3),dur:+Math.max(Yd.dur[0],o-r).toFixed(3),lead:r})}function Iu(t,e,o,r){return Me(t,e).filter(n=>n.time+t.start<o-1e-6||n.time+t.start>r+1e-6)}function Hg(t,e,o,r){const n=t.find(N=>N.id===e),a=n?.pin?.dive;if(!a?.lead||n.pin.scene)return t;const i=t.find(N=>N.id===n.pin.clip);if(!i)return t;const l=a.at-a.lead,p=a.at,c=a.at+a.dur;let s=i;for(const N of["x","y","zoom"])s={...s,...de(s,N,Iu(s,N,l,c))};const h={...n,pin:{...n.pin,dive:void 0}},f=N=>J0(h,t.map(F=>F.id===i.id?s:F),N,o,r),m=f(p);if(!m||!m.every(N=>N.every(Number.isFinite)))return t;const y=N=>[(N[0][0]+N[1][0]+N[2][0]+N[3][0])/4,(N[0][1]+N[1][1]+N[2][1]+N[3][1])/4],[$,x]=y(m),E=Math.max(m[0][0],m[2][0]),v=Math.min(m[1][0],m[3][0]),S=Math.max(m[0][1],m[1][1]),k=Math.min(m[2][1],m[3][1]);if(!(v-$>1&&$-E>1&&k-x>1&&x-S>1))return t;const b=1.04*Math.max(o/2/($-E),o/2/(v-$),r/2/(x-S),r/2/(k-x)),A={x:[],y:[],zoom:[]},I=(N,F,K)=>{const _=N-i.start,[q,U]=y(K),rt=1+(b-1)*F,ot=Ut(s,"x",_),G=Ut(s,"y",_),J=Ut(s,"zoom",_),Z=[o/2+ot*o,r/2+G*r],at=[q+(o/2-q)*F,U+(r/2-U)*F],D=[at[0]-(q-Z[0])*rt,at[1]-(U-Z[1])*rt];A.x.push({time:+_.toFixed(4),value:+((D[0]-o/2)/o).toFixed(5)}),A.y.push({time:+_.toFixed(4),value:+((D[1]-r/2)/r).toFixed(5)}),A.zoom.push({time:+_.toFixed(4),value:+(J*rt).toFixed(5)})},P=Math.max(2,Math.round(a.lead/B3));for(let N=0;N<=P;N++){const F=l+a.lead*N/P,K=f(F);K&&I(F,_3(N/P),K)}const C=f(c);C&&I(Math.min(c,i.start+i.duration),1,C);let z=s;for(const N of["x","y","zoom"])z={...z,...de(z,N,[...Iu(s,N,l,c),...A[N]].sort((F,K)=>F.time-K.time))};return t.map(N=>N.id===i.id?{...N,motionKeys:z.motionKeys,motionV:2,...z.posX!==void 0?{posX:z.posX}:{},...z.posY!==void 0?{posY:z.posY}:{},...z.scale!==void 0?{scale:z.scale}:{}}:N.id===n.id?{...N,pin:{...N.pin,dive:{...a,keys:!0}}}:N)}function K3(t,e){const o=t.find(l=>l.id===e),r=o?.pin?.dive??o?.pendingPin?.dive;if(!r)return t;const n=o.pin?.clip??o.pendingPin?.source,a=r.lead?t.find(l=>l.id===n):null;let i=a;if(a)for(const l of["x","y","zoom"])i={...i,...de(i,l,Iu(i,l,r.at-r.lead,r.at+r.dur))};return t.map(l=>{if(a&&l.id===a.id)return{...l,motionKeys:i.motionKeys,motionV:2};if(l.id!==o.id)return l;if(l.pin?.dive){const{dive:s,...h}=l.pin;return{...l,pin:h}}const{dive:p,...c}=l.pendingPin;return{...l,pendingPin:c}})}function HA(t,e,o){let r=t;for(const n of t)n.pin?.dive?.lead&&!n.pin.dive.keys&&!n.pin.scene&&(r=Hg(r,n.id,e,o));return r}const Od=t=>Math.max(1/30,Math.floor(t*30+1e-6)/30),ff=t=>Math.round(t*1e3)/1e3;function $s(t,e){if(t.start+e.duration>Tn+1e-6)throw Error("Speed exceeds timeline duration limit");const o={...t,duration:e.duration};if(delete o.speedRamp,delete o.playbackRate,e.speedRamp?o.speedRamp=e.speedRamp:o.playbackRate=e.playbackRate,Q0(o),!Hr(t)&&!Hr(o))Object.assign(o,cb(t,o.duration));else{const r=n=>Math.max(0,Math.min(o.duration,ja(o,Di(t,n))));t.captions&&(o.captions=t.captions.map(n=>({...n,start:r(n.start),end:r(n.end)})).filter(n=>n.end>n.start)),t.captionWords&&(o.captionWords=t.captionWords.map(n=>({...n,start:ff(r(n.start)),end:ff(r(n.end))})).filter(n=>n.end-n.start>=.005))}return t.motionKeys?.length&&(o.motionKeys=t.motionKeys.map(r=>({...r,time:r.time*o.duration/t.duration}))),o}const V3=t=>{if(["image","model"].includes(t.kind)&&!t.comp)throw Error("Invalid playback speed");if(zn(t))throw Error("Time remap replaces speed, speed ramp, reverse and freeze frame")};function Au(t,e){if(V3(t),!Number.isFinite(e)||e<qd||e>Zd)throw Error(`Invalid playback speed (${qd}–${Zd}×)`);const o=Wc(t);return $s(t,{playbackRate:e,duration:Hr(t)?Od(o/e):ht(t.duration*(t.playbackRate||1)/e)})}function W3(t){if(!Array.isArray(t)||t.length<2||t.length>Jd)throw Error(`Speed ramp needs 2–${Jd} keys`);return t.map(e=>({t:Math.round(Number(e?.t)*1e3)/1e3,speed:Math.round(Number(e?.speed)*100)/100,...e?.ease==="linear"?{ease:"linear"}:{}})).sort((e,o)=>e.t-o.t)}function X3(t,{preset:e,keys:o,hitAt:r,peak:n}={}){if(t.kind!=="video")throw Error("Speed ramp requires a video clip");if(zn(t))throw Error("Time remap replaces speed, speed ramp, reverse and freeze frame");if(t.reverse||t.freeze)throw Error("Speed ramp cannot be combined with reverse or freeze frame");const a=Wc(t);if(e==="normal")return Au(t,1);if(e!=null&&!o?.length){if(!Zl.includes(e))throw Error(`Unknown speed ramp preset (${Zl.join(", ")})`);if(Number.isFinite(r)){const{duration:l,speedRamp:p}=ib(e,a,Di(t,r),n);return $s(t,{duration:l,speedRamp:p})}return $s(t,sb(e,a,n))}const i=W3(o);return i.every(l=>l.speed===i[0].speed)?Au(t,i[0].speed):(Q0({kind:"video",speedRamp:i}),$s(t,{speedRamp:i,duration:Od(lb(a,i))}))}function mf(t,e,o,{peak:r}={}){if(t.kind!=="video")throw Error("Speed ramp requires a video clip");if(zn(t))throw Error("Time remap replaces speed, speed ramp, reverse and freeze frame");if(t.reverse||t.freeze)throw Error("Speed ramp cannot be combined with reverse or freeze frame");if(!Zl.includes(e))throw Error(`Unknown speed ramp preset (${Zl.join(", ")})`);const n=Od(o),a=Number.isFinite(t.sourceDuration)?Math.max(.05,t.sourceDuration-(t.inPoint||0)):1/0,i=ab(e,n,a,r);return $s(t,{duration:n,speedRamp:i.speedRamp})}const H3=t=>+(+t).toFixed(4),ha=(t,e)=>H3(Math.max(0,Math.min(t,t-e)));function U3(t){const e=t.duration,o={...pb(t)},r=a=>({...a,keys:a.keys.map(i=>({...i,t:ha(e,i.t)})).reverse()});t.mask?.keys?o.mask=r(t.mask):Array.isArray(t.mask?.masks)&&(o.mask={...t.mask,masks:t.mask.masks.map(a=>{const i=r(a);return delete i.in,delete i.out,a.out!==void 0&&(i.in=ha(e,a.out)),a.in!==void 0&&(i.out=ha(e,a.in)),i})}),Array.isArray(t.planar?.frames)&&(o.planar={...t.planar,frames:t.planar.frames.map(a=>[ha(e,a[0]),...a.slice(1)]).reverse(),...t.planar.surface?{surface:{...t.planar.surface,t:ha(e,t.planar.surface.t)}}:{}}),t.roto?.points&&(o.roto={...t.roto,points:t.roto.points.map(a=>[ha(e,a[0]),a[1],a[2],a[3]]).reverse()});const n=Md(t.grade);return n.some(a=>a?.motion?.mode==="keys")&&(o.grade=$d(t.grade,n.map(a=>a?.motion?.mode==="keys"?{...a,motion:{...a.motion,keys:a.motion.keys.map(i=>[ha(e,i[0]),...i.slice(1)]).reverse()}}:a))),o}const Dl=t=>Math.round(t*30)/30;function gf(t,e,o,r={}){const n=t.find(p=>p.id===e);if(!n)throw Error("Clip not found");if(r[n.track]?.locked)throw Error("Track is locked");const a=Dl(n.start+n.duration);if(t.some(p=>p.id!==e&&p.track===n.track&&p.start<a-1/60&&p.start+p.duration>n.start+1/60))throw Error("Resolve overlapping clips before ripple editing");const i=Dl((o?.duration||0)-n.duration),l=t.flatMap(p=>p.id===e?o?[{...o,start:n.start}]:[]:[{...p,...p.track===n.track&&p.start>=a-1/60?{start:Dl(p.start+i)}:{}}]);if(l.some(p=>p.start<0||p.start+p.duration>600))throw Error("Ripple exceeds timeline bounds");return l}function Y3(t,e,o,r,n={}){const a=t.find(c=>c.id===e),i=a&&t.find(c=>c.id!==e&&c.track===a.track&&Math.abs(c.start-a.start-a.duration)<1/60);if(!a||a.kind==="audio"||!i||i.kind==="audio")throw Error("Select a visual clip with an adjacent next clip on the same track");if(n[a.track]?.locked)throw Error("Track is locked");if(!["none","fade-black","fade-white"].includes(o)||!Number.isFinite(r)||r<0||r>4)throw Error("Invalid transition");if(o!=="none"&&(r<2/30||r/2>Math.min(a.duration,i.duration)))throw Error("Transition is longer than adjacent clips");const l=o==="none"?0:Dl(r/2),p=o==="fade-white"?"white":"black";return t.map(c=>c.id===e?{...c,visualFadeOut:l,fadeOutColor:p}:c.id===i.id?{...c,visualFadeIn:l,fadeInColor:p}:c)}function UA(t,e){const o=Math.min(t.visualFadeIn||0,t.duration),r=Math.min(t.visualFadeOut||0,t.duration),n=o?Math.max(0,Math.min(1,e/o)):1,a=r?Math.max(0,Math.min(1,(t.duration-e)/r)):1;return n<a?{amount:1-n,color:t.fadeInColor||"black"}:{amount:1-a,color:t.fadeOutColor||"black"}}const q3=["font","color","emphasisColor","emphasisColor2","strokeColor","strokeWidth","shadow","glow","box","boxOpacity","boxShape","emphasisText","upper","trColor","hl"],ye=t=>({emphasisColor:t,emphasisColor2:t}),Ug=[{id:"classic",label:"Cổ điển",font:"Noto Sans",color:"#ffffff",...ye("#ffe14a")},{id:"pop-yellow",label:"Nổi vàng",font:"Anton",color:"#ffffff",emphasisColor:"#ffe14a",emphasisColor2:"#ff8a1f"},{id:"bold-white",label:"Trắng đậm",font:"Montserrat ExtraBold",color:"#ffffff",...ye("#ffffff"),strokeWidth:1.6,upper:!0},{id:"green-hi",label:"Xanh nổi",font:"Montserrat ExtraBold",color:"#ffffff",...ye("#3dff4f"),upper:!0,strokeWidth:1.3},{id:"red-hi",label:"Đỏ nổi",font:"Montserrat ExtraBold",color:"#ffffff",...ye("#ff3b30"),upper:!0,strokeWidth:1.3},{id:"challenge",label:"Thử thách",font:"Paytone One",color:"#ffffff",...ye("#ffe600"),strokeWidth:2.2,shadow:"#000000"},{id:"comic",label:"Truyện tranh",font:"Bangers",color:"#ffffff",...ye("#ff3b30"),strokeWidth:1.8,shadow:"#000000"},{id:"black-box",label:"Hộp đen",font:"Be Vietnam Pro ExtraBold",color:"#ffffff",...ye("#ffe14a"),strokeWidth:0,box:"#000000",boxOpacity:.72,boxShape:"line"},{id:"white-box",label:"Hộp trắng",font:"Be Vietnam Pro ExtraBold",color:"#111111",...ye("#e5232b"),strokeWidth:0,box:"#ffffff",boxOpacity:1,boxShape:"line"},{id:"news-red",label:"Tin nóng",font:"Oswald Bold",color:"#ffffff",...ye("#ffe14a"),strokeWidth:0,box:"#d7141a",boxOpacity:.95,boxShape:"block",upper:!0},{id:"yellow-word",label:"Ô vàng",font:"Paytone One",color:"#ffffff",...ye("#ffd60a"),strokeWidth:1.2,box:"#ffd60a",boxShape:"word",emphasisText:"#111111"},{id:"blue-word",label:"Ô xanh dương",font:"Lexend Bold",color:"#ffffff",...ye("#2f6bff"),strokeWidth:1,box:"#2f6bff",boxShape:"word",emphasisText:"#ffffff"},{id:"pink-word",label:"Ô hồng",font:"Baloo 2",color:"#ffffff",...ye("#ff3ea5"),strokeWidth:1,box:"#ff3ea5",boxShape:"word",emphasisText:"#ffffff"},{id:"neon-yellow",label:"Neon vàng",font:"Lexend Bold",color:"#f6ff8a",...ye("#ffffff"),strokeWidth:0,glow:"#d4ff00"},{id:"neon-cyan",label:"Neon xanh",font:"Chakra Petch",color:"#e9feff",...ye("#00e5ff"),strokeWidth:0,glow:"#00c8ff"},{id:"neon-pink",label:"Neon hồng",font:"Lobster",color:"#fff0fb",...ye("#ff7ad9"),strokeWidth:0,glow:"#ff2fb9"},{id:"fire",label:"Lửa",font:"Anton",color:"#ffffff",emphasisColor:"#ffde00",emphasisColor2:"#ff3b00",upper:!0,glow:"#ff5a00"},{id:"clipoox-lime",label:"Clipoox Lime",font:"Montserrat ExtraBold",color:"#ffffff",...ye("#c6f432"),strokeWidth:1.2,shadow:"#000000"},{id:"soft-shadow",label:"Bóng mềm",font:"Be Vietnam Pro ExtraBold",color:"#ffffff",...ye("#ffe14a"),strokeWidth:0,shadow:"#000000"},{id:"minimal",label:"Tối giản",font:"Be Vietnam Pro",color:"#ffffff",...ye("#ffffff"),strokeWidth:0,shadow:"#000000"},{id:"cinema",label:"Điện ảnh",font:"Playfair Display",color:"#f5f0e6",...ye("#f2c66d"),strokeWidth:0,shadow:"#000000"},{id:"gold",label:"Vàng sang",font:"Playfair Display",color:"#f7d774",emphasisColor:"#fff3b0",emphasisColor2:"#c99a2e",strokeColor:"#2a1c00",strokeWidth:.8},{id:"script",label:"Viết tay thanh lịch",font:"Dancing Script",color:"#ffffff",...ye("#ffd1e8"),strokeColor:"#1a1a1a",strokeWidth:.6,shadow:"#000000"},{id:"hand",label:"Viết tay",font:"Patrick Hand",color:"#fff8e7",...ye("#ffd23f"),strokeColor:"#3a2a1a",strokeWidth:1},{id:"retro",label:"Retro",font:"Lobster",color:"#ffe9a8",...ye("#ff9b54"),strokeColor:"#7a2e00",strokeWidth:1.2},{id:"candy",label:"Kẹo ngọt",font:"Baloo 2",color:"#ffffff",...ye("#ffe14a"),strokeColor:"#ff4fa3",strokeWidth:1.6},{id:"orange-pop",label:"Cam rực",font:"Paytone One",color:"#ff8a1f",...ye("#ffe14a"),strokeColor:"#ffffff",strokeWidth:1.4,shadow:"#5a1a00"},{id:"aqua",label:"Xanh ngọc",font:"Lexend Bold",color:"#5ef3ff",...ye("#ffffff"),strokeColor:"#062a33",strokeWidth:1.2},{id:"gaming",label:"Game",font:"Chakra Petch",color:"#ffffff",...ye("#a6ff00"),strokeWidth:1.3,upper:!0},{id:"pastel",label:"Pastel",font:"Baloo 2",color:"#4a1d3a",...ye("#c2185b"),strokeWidth:0,box:"#ffc4dc",boxOpacity:.92,boxShape:"line"},{id:"karaoke-green",label:"Karaoke xanh",font:"Bungee",color:"#ffffff",...ye("#39ff14"),strokeWidth:1.2},{id:"kinetic-red",label:"Chữ nhấn đỏ khổng lồ",font:"Montserrat ExtraBold",color:"#ffffff",...ye("#e8251a"),strokeWidth:0,shadow:"#000000",emphasisScale:1.9},{id:"surf",label:"Biển xanh",font:"Pacifico",color:"#ffffff",...ye("#7ee8fa"),strokeColor:"#0b4f6c",strokeWidth:1}],Z3=new Map(Ug.map(t=>[t.id,t])),Yg=t=>Z3.get(t)||null;function J3(t){const e=Yg(t);if(!e)throw Error(`Unknown caption look "${t}"`);const o={look:t};for(const r of q3)o[r]=e[r];return e.emphasisScale&&(o.emphasisScale=e.emphasisScale),o}function yf(t,e){const o={...t||{style:"classic"},...J3(e)};for(const r of Object.keys(o))o[r]===void 0&&delete o[r];return si(o)}const qg=[{id:"lime",label:"Lime Clipoox",emphasisColor:"#c6f432",emphasisColor2:"#8fdc1e"},{id:"lime-box",label:"Ô lime",emphasisColor:"#b7ff42",emphasisColor2:"#b7ff42",box:"#b7ff42",emphasisText:"#0d1300"},{id:"lime-dark",label:"Ô đen chữ lime",emphasisColor:"#0b0e08",emphasisColor2:"#0b0e08",box:"#0b0e08",emphasisText:"#c6f432"},{id:"gold",label:"Vàng cháy",emphasisColor:"#ffe14a",emphasisColor2:"#ff8a1f"},{id:"white",label:"Trắng sáng",emphasisColor:"#ffffff",emphasisColor2:"#ffffff"},{id:"red",label:"Đỏ",emphasisColor:"#ff3b30",emphasisColor2:"#ff3b30"},{id:"aqua",label:"Xanh ngọc",emphasisColor:"#5ef3ff",emphasisColor2:"#2f9bff"},{id:"violet",label:"Tím",emphasisColor:"#d3a4ff",emphasisColor2:"#7b4dff"},{id:"rainbow",label:"Cầu vồng",emphasisColor:"#ffe14a",emphasisColor2:"#ff3ea5"},{id:"pink-box",label:"Ô hồng",emphasisColor:"#ff3ea5",emphasisColor2:"#ff3ea5",box:"#ff3ea5",emphasisText:"#ffffff"},{id:"yellow-box",label:"Ô vàng",emphasisColor:"#ffd60a",emphasisColor2:"#ffd60a",box:"#ffd60a",emphasisText:"#111111"},{id:"blue-box",label:"Ô xanh dương",emphasisColor:"#2f6bff",emphasisColor2:"#2f6bff",box:"#2f6bff",emphasisText:"#ffffff"}],Q3=new Map(qg.map(t=>[t.id,t])),Zg=t=>Q3.get(t)||null;function t4(t,e){const o=Zg(t);if(!o)throw Error(`Unknown highlight look "${t}"`);const r={hl:t,emphasisColor:o.emphasisColor,emphasisColor2:o.emphasisColor2};return o.box?Object.assign(r,{box:o.box,boxShape:"word",emphasisText:o.emphasisText,boxOpacity:void 0}):e?.boxShape==="word"&&Object.assign(r,{box:void 0,boxShape:void 0,emphasisText:void 0}),r}const e4=[.3,1.9,.5,1],kp={fade:{type:"fade",duration:.3},pop:{type:"pop",duration:.35,amount:.5},slide:{type:"slide-up",duration:.45,amount:.25},bounce:{type:"pop",duration:.6,amount:1,ease:e4}},xp={fade:{type:"fade",duration:.3},pop:{type:"pop",duration:.3,amount:.5},slide:{type:"slide-down",duration:.4,amount:.25}},bf=.5,o4=.8,r4=.6,n4=28,tl=(t,e,o)=>Math.max(e,Math.min(o,t));function a4(t){const e=t?.element?.anim??{};return{in:eg.includes(e.in)?e.in:"none",out:og.includes(e.out)?e.out:"none",loop:rg.includes(e.loop)?e.loop:"none"}}const i4=(t,e)=>[...e.in==="spin"||e.loop==="wiggle"?["rot"]:[],...e.loop==="pulse"?["zoom"]:[],...e.loop==="float"?["y"]:[]].includes(t);function Mp(t,e,o,r,n,a){const i=[];for(let l=0,p=t;p<=e+1e-6&&i.length<n4;l++,p=t+l*n)i.push({time:ht(Math.min(p,e)),value:l%2?r:o,...l%2===0?{ease:a}:{}});return i.filter((l,p)=>!p||l.time>i[p-1].time+1/60)}function s4(t,e={}){const o=a4(t),r=!!t.element?.anim,n=tg(t.element?.id)?.anim??ub,a={in:e.in??(r?o.in:n.in),out:e.out??(r?o.out:n.out),loop:e.loop??(r?o.loop:n.loop)};if(!eg.includes(a.in)||!og.includes(a.out)||!rg.includes(a.loop))throw Error("Unknown element animation preset");let i={...t};for(const f of["rot","zoom","y"])i4(f,o)&&(i={...i,...de(i,f,[])});if(o.in==="wipe"||o.out==="wipe"){const{revealType:f,reveal:m,...y}=i;i={...y,...de(y,"reveal",[])}}o.in==="draw"&&(i={...i,...de(i,"trimEnd",[])}),delete i.enter,delete i.exit;const l=i.duration;kp[a.in]&&(i.enter={...kp[a.in],duration:Math.min(kp[a.in].duration,l/2)}),xp[a.out]&&(i.exit={...xp[a.out],duration:Math.min(xp[a.out].duration,l/2)});const p=tl(Ut(i,"rot",0),-180,180),c=ht(Math.min(r4,l)),s=a.in==="spin"?[{time:0,value:-180,ease:Jt["ease-out"]}]:[];let h=s;if(a.loop==="wiggle"?h=[...s,...Mp(s.length?c:0,l,p,tl(p+5,-180,180),.2,Jt["ease-in-out"])]:s.length&&(h=[...s,{time:c,value:p}]),h.length>1&&(i={...i,...de(i,"rot",h)}),a.loop==="pulse"){const f=Ut(i,"zoom",0);i={...i,...de(i,"zoom",Mp(0,l,f,tl(f*1.08,0,qi),.4,Jt["ease-in-out"]))}}if(a.loop==="float"){const f=Ut(i,"y",0);i={...i,...de(i,"y",Mp(0,l,f,tl(f-.03,-1,1),.8,Jt["ease-in-out"]))}}if(a.in==="wipe"||a.out==="wipe"){const f=[];a.in==="wipe"&&f.push({time:0,value:0,ease:Jt["ease-out"]},{time:ht(Math.min(bf,l/2)),value:1}),a.out==="wipe"&&f.push({time:ht(l-Math.min(bf,l/2)),value:1,ease:Jt["ease-in"]},{time:ht(l),value:0}),i={...i,revealType:"wipe-left",...de(i,"reveal",f.filter((m,y)=>!y||m.time>f[y-1].time+1/60))}}return a.in==="draw"&&i.shape&&(i={...i,...de(i,"trimEnd",[{time:0,value:0,ease:Jt["ease-out"]},{time:ht(Math.min(o4,l/2)),value:1}])}),i.element={...i.element??{},anim:a},hn(i),i}[...Object.keys(Ig)];const l4=4,c4=/^gs:\/\/[\w.-]+\/(uploads|assets|outputs)\/[^\s?#\\]+$/,pi=t=>typeof t=="string"&&t.length<=400&&!t.includes("..")&&c4.test(t),YA=t=>({id:t.id,start:+t.start.toFixed(2),end:+t.end.toFixed(2),duration:+(t.end-t.start).toFixed(2),request:t.text.slice(0,1e3),kinds:t.kinds,model:t.generator??"auto",...t.refs?.length?{referenceImages:t.refs.length}:{}});function p4(t,e,o){let r=null,n=0;for(const a of t||[]){if(!a?.refs?.length)continue;const i=Math.min(a.end,e+o)-Math.max(a.start,e);i>n+1e-9&&(n=i,r=a)}return r}const qA=(t,e)=>t.map(o=>{if(o?.op!=="generateBroll"||o.refs?.length||!Number.isFinite(o.start)||!Number.isFinite(o.duration))return o;const r=p4(e,o.start,o.duration);return r?{...o,refs:r.refs.map(n=>n.gcsUri)}:o}),u4=["dissolve","cut","whip"],d4=.12,h4=.08,f4=1.06,m4=.2,g4=.12,Jg=.35,y4=.7,Qg=/[.!?…。]["')\]]*$/,b4=/[,;:,]["')\]]*$/,$p=t=>Math.floor(t*be+1e-6)/be,ns=t=>Math.ceil(t*be-1e-6)/be,wf=t=>Math.round(t*1e3)/1e3;function w4(t,e=[]){const o=[];for(const n of t){if(n.kind!=="video"&&n.kind!=="audio"||n.gen)continue;let a=n.captionWords;if(!a?.length){const i=e.find(l=>l.id===n.nodeId);Array.isArray(i?.words)&&i.words.length?a=vd(n,i.words):n.captions?.length&&(a=Xc(n.captions))}for(const i of a??[])o.push({start:wf(n.start+i.start),end:wf(n.start+i.end),word:i.word})}o.sort((n,a)=>n.start-a.start||n.end-a.end);const r=[];for(const n of o)(!r.length||n.start>=r.at(-1).end-.02)&&r.push(n);return r}function kf(t,{gap:e=Jg,maxWords:o=14,soft:r=!0}={}){const n=[];let a=[];return t.forEach((i,l)=>{a.push(i);const p=t[l+1];(!p||p.start-i.end>=e||Qg.test(i.word)||r&&b4.test(i.word)&&a.length>=4||a.length>=o)&&(n.push(a),a=[])}),n.map(i=>({start:i[0].start,end:i.at(-1).end,text:i.map(l=>l.word).join(" "),words:i}))}function ZA(t,e){const o=kf(t);if(!o.length)return null;let r=o.findIndex(l=>e>=l.start-.05&&e<=l.end+.05);r<0&&(r=o.findIndex(l=>l.start>e)),r<0&&(r=o.length-1);const n=kf(t,{gap:y4,maxWords:60,soft:!1}),a=Math.max(0,n.findIndex(l=>o[r].start>=l.start-.001&&o[r].start<=l.end+.001)),i=n.slice(Math.max(0,a-1),a+2).map(l=>l.text).join(" ").slice(0,600);return{start:o[r].start,end:o[r].end,text:o[r].text,context:i}}function k4(t,e,o,{min:r=2,max:n=8,lead:a=d4,tail:i=h4}={}){const l=Math.min(e,o),p=Math.max(e,o),c=n-1/be,s=()=>{const P=$p(Math.max(0,l)),C=ht(Math.min(n,Math.max(r,p-l)));return{start:P,end:ht(P+C),duration:C,snapped:!1,words:[]}},h=t.filter(P=>P.end>P.start),f=h.findIndex(P=>P.end>l+.02);if(f<0||h[f].start>=p-.02)return s();let m=f;for(;m+1<h.length&&h[m+1].start<p-.02;)m++;const y=h[f-1],$=h[f];let x=y?Math.max($.start-a,Math.min($.start,(y.end+$.start)/2)):$.start-a;x=Math.max(0,x);let E=$p(x);y&&E<y.end-1e-6&&(E=Math.min($.start,ns(y.end)));const v=P=>P===h.length-1||h[P+1].start-h[P].end>=Jg||Qg.test(h[P].word),S=P=>h[P].end+i-E;let k=m;if(!v(m)){let P=m+1;for(;P<h.length&&S(P)<=c&&h[P].end-p<=1.5&&!v(P);)P++;if(P<h.length&&S(P)<=c&&h[P].end-p<=1.5&&v(P))k=P;else{let C=m-1;for(;C>f&&!v(C);)C--;C>=f&&v(C)&&h[C].end-E>=r*.6&&(k=C)}}const b=P=>{const C=h[P+1];let z=h[P].end+i;C&&C.start>=h[P].end&&(z=Math.min(z,(h[P].end+C.start)/2));let N=ns(z);return C&&N>C.start+1e-6&&C.start>=h[P].end&&ns(h[P].end)<=C.start&&(N=ns(h[P].end)),N};for(;k>f&&b(k)-E>c;)k--;let A=b(k);if(A-E<r-1e-6){const P=ns(E+r);for(;k+1<h.length&&h[k+1].start<P-1e-6&&b(k+1)-E<=c;)k++;A=Math.max(P,b(k))}let I=!1;return A-E>n+1e-6&&(A=$p(E+n),I=!0),h.some(P=>P.start<A-1e-6&&P.end>A+1e-6)&&(I=!0),{start:ht(E),end:ht(A),duration:ht(A-E),snapped:!0,clipped:I,words:h.slice(f,k+1)}}function Cu(t,e,o,r,n=null,{fallback:a=!1}={}){const{track:i,moved:l}=Zt(t,e,o,r,n,{fallback:a}),p=t.filter(s=>s.kind!=="audio"&&s.start<r-1e-9&&s.start+s.duration>o+1e-9),c=Math.max(0,...p.map(s=>s.zIndex??0));return{track:i,...c>0?{zIndex:Math.min(100,c)}:{},...l?{moved:l}:{}}}function JA(t,e,o){return t.filter(r=>r.id!==o&&(r.kind==="video"||r.kind==="image")&&r.url&&!r.gen&&!r.title&&!r.shape&&!r.card&&!r.motion&&r.layout===void 0&&!r.person&&!r.mask&&r.start<=e&&e<r.start+r.duration).sort((r,n)=>(r.kind===n.kind?0:r.kind==="video"?-1:1)||r.track-n.track)[0]??null}function x4(t,{transition:e="dissolve",pushIn:o=!0,layout:r="cutaway"}={}){const n={};if(o&&r==="cutaway"&&t>=1&&(n.motionKeys=[{time:0,zoom:1},{time:ht(t),zoom:f4}],n.motionV=2),e==="dissolve"){const a=Math.max(.05,Math.min(m4,t/4));n.enter={type:"fade",duration:a},n.exit={type:"fade",duration:a}}else if(e==="whip"){const a=Math.max(.05,Math.min(g4,t/4));n.enter={type:"slide-left",amount:1,duration:a},n.exit={type:"slide-left",amount:1,duration:a}}return n}function M4({clips:t,tracks:e={},materials:o=[],generator:r,prompt:n,start:a,duration:i,layout:l="cutaway",transition:p="dissolve",pushIn:c,colorMatch:s=!0,preset:h,track:f=null,trackFallback:m=!1,newId:y,refs:$}){const x=Ig[r];if(!x)throw Error("Unsupported B-roll generator");const E=typeof n=="string"?n.trim():"";if(E.length<12||E.length>1200)throw Error("B-roll prompt must be 12–1200 characters");if(!ng.includes(l))throw Error("Unsupported B-roll layout");if($!==void 0&&(!Array.isArray($)||$.length>l4||!$.every(pi)))throw Error("Invalid B-roll reference images");if(!u4.includes(p))throw Error("Unsupported B-roll transition");if(!Number.isFinite(a)||!Number.isFinite(i)||a<0||i<1/be||a+i>Tn)throw Error("Invalid creative clip timing");const v=w4(t,o),S=v.length?k4(v,a,a+i,{min:x.min,max:x.max}):null,k=S?.snapped?S.start:ht(a),b=S?.snapped?S.duration:ht(i);if(b<x.min-1e-6||b>x.max+1e-6)throw Error(`${x.label}: ${x.min}–${x.max}s`);if(k+b>Tn)throw Error("Invalid creative clip timing");const{moved:A,...I}=Cu(t,e,k,k+b,f,{fallback:m}),P=c??!0,C=x4(b,{transition:p,pushIn:P,layout:l});h&&h!=="none"?C.motionKeys=Ll(h,b):h==="none"&&(delete C.motionKeys,delete C.motionV);const z={nodeId:"",kind:"video",url:"",label:`AI B-roll · ${E.slice(0,40)}`,inPoint:0,sourceDuration:b,volume:0,fit:"cover",layout:l,...I,...C,id:y(),start:k,duration:b,gen:{status:"pending",generator:r,prompt:E,duration:b,finish:{transition:p,pushIn:P&&l==="cutaway",colorMatch:s},...$?.length?{refs:[...$]}:{}}};return{clip:z,snap:S,...A?{trackNote:`track ${f} → ${z.track} (${A})`}:{}}}const $4=["green","black","alpha"],v4=[{id:"explosion",name:"Nổ"},{id:"smoke",name:"Khói & bụi"},{id:"fire",name:"Lửa"},{id:"spark",name:"Tia lửa & điện"},{id:"energy",name:"Năng lượng & phép thuật"},{id:"debris",name:"Mảnh vỡ & va chạm"},{id:"muzzle",name:"Súng & đạn"},{id:"weather",name:"Thời tiết"},{id:"destruction",name:"Phá hủy & sụp đổ"},{id:"blood",name:"Máu & cơ thể"},{id:"cartoon",name:"Hiệu ứng 2D / Hoạt hình"},{id:"vehicle",name:"Phương tiện & thiên thạch"},{id:"object",name:"Kính, giấy & đồ vật"}];v4.map(t=>t.id);const ju=[.5,.85],xf=[.1,4],E4=/^#[0-9a-f]{6}$/i,S4=(t,e,o)=>Math.min(o,Math.max(e,t)),Oa=t=>Math.round(t*1e4)/1e4;function I4(t){if(!t||typeof t!="object")throw Error("Footage VFX: thiếu nền (green / black / alpha)");if(!$4.includes(t.bg))throw Error("Footage VFX: nền phải là green, black hoặc alpha");const e={bg:t.bg};if(t.bg==="green"){const n=t.keyColor??hu.color;if(typeof n!="string"||!E4.test(n))throw Error("Footage VFX: màu key không hợp lệ");e.keyColor=n.toLowerCase()}const o=Number(t.anchorU??ju[0]),r=Number(t.anchorV??ju[1]);if(!Number.isFinite(o)||!Number.isFinite(r)||o<0||o>1||r<0||r>1)throw Error("Footage VFX: điểm neo phải trong 0..1");return e.anchorU=Oa(o),e.anchorV=Oa(r),e}const A4=t=>({...hu,color:(t||hu.color).toLowerCase(),similarity:.14,blend:.1,spill:.7});function C4(t,e,o,r=1){const n=t.W/t.H,a=e.width&&e.height?e.width/e.height:n,i=a>=n?1:a/n,l=a>=n?n/a:1,p=S4(Number(r)||1,xf[0],xf[1]);if(!o)return{posX:0,posY:0,scale:Oa(p)};const[c,s]=o;return{posX:Oa(c-.5-(e.anchorU-.5)*i*p),posY:Oa(s-.5-(e.anchorV-.5)*l*p),scale:Oa(p)}}const j4=(t,e)=>t&&typeof t.url=="string"&&typeof t.gcsUri=="string"&&t.fps>0&&t.width>0&&t.height>0?{proxy:{url:t.url,gcsUri:t.gcsUri,fps:t.fps,width:t.width,height:t.height,...e==="alpha"?{alpha:!0}:{}}}:null;function Mf({id:t,track:e,start:o,duration:r,footage:n,frame:a,at:i,scale:l,sound:p=!1}){const c=I4(n),s=C4(a,{...n,...c},i,l);return{id:t,nodeId:n.id?`vfx:${n.id}`:t,track:e,start:o,duration:r,inPoint:0,sourceDuration:n.duration,kind:"video",url:n.url,...n.gcsUri?{gcsUri:n.gcsUri}:{},...j4(n.proxy,c.bg)??{},label:String(n.name||"VFX").slice(0,80),volume:p?1:0,motionV:2,...s,...c.bg==="green"?{key:A4(c.keyColor)}:c.bg==="black"?{blend:"screen"}:{},vfxFootage:{...n.id?{id:n.id}:{},bg:c.bg,anchor:[c.anchorU,c.anchorV],...n.width>0&&n.height>0?{aspect:Oa(n.width/n.height)}:{}}}}const T4="clipoox-canvas-assets",O4=t=>`gs://${T4}/library/models/${t}/model.glb`,P4=Object.freeze([{id:"sun-saphia-residence",name:"Sun Saphia Residence",developer:"Sun Group",city:"Đà Nẵng",district:"Ngũ Hành Sơn",at:[108.25778,16.02125],height:119.2,rotation:0,towers:1,floors:"30",note:"Mở bán 10/2026. 1 tháp 30 tầng trên khối đế, cạnh biển Võ Nguyên Giáp.",sha:"71fb509cc6b3eaf914b7431fc008c0c5a1fea76bebb347d2638a6acfc602d814"},{id:"astor-1-ciputra",name:"Astor 1 Ciputra",developer:"Pristie",city:"Hà Nội",district:"Tây Hồ",at:[105.78881,21.08381],height:168.8,rotation:-5,towers:1,floors:"40",note:"Mở bán 9/2026. 1 tháp 40 tầng phong cách Art Deco, lô IA25 KĐT Ciputra.",aka:["IA25"],sha:"5e2b34bbc17fadcadd9d5410e36504b8b9011c246703d8acbe1ebca2861ff05a"},{id:"the-prive",name:"The Privé",developer:"Đất Xanh",city:"TP.HCM",district:"Bình Trưng (Thủ Đức)",at:[106.76862,10.79233],height:119,rotation:0,zoom:15.8,towers:12,floors:"33–35",note:"12 tháp trên bán đảo Nam Rạch Chiếc, 3 mặt giáp sông; bố cục theo mặt bằng tổng thể.",aka:["Nam Rạch Chiếc","Quận 2"],sha:"aae093260e7e2a6afbdd7f5553e8fec385227a2de412a68ab30906a9397c134f"},{id:"imperia-sensa-park",name:"Imperia Sensa Park",developer:"MIK Group",city:"TP.HCM",district:"Phước Long (Thủ Đức)",at:[106.78944,10.81324],height:90.4,rotation:0,zoom:16,towers:2,floors:"25",note:"2 tháp 25 tầng + dãy nhà thấp tầng, mặt Võ Chí Công (Vành đai 2).",aka:["The Sensa","Quận 9"],sha:"4346fe4d4e053a773ae33c40a99824d126131510f02f70201768537354e9d3a9"},{id:"palm-river",name:"Palm River",developer:"Hướng Việt",city:"TP.HCM",district:"Bình Trưng (Thủ Đức)",at:[106.76213,10.79104],height:135.1,rotation:21.8,towers:4,floors:"36",note:"4 tháp 36 tầng dọc sông, phân khu của Palm City.",aka:["Palm City","Palm Garden","Quận 2"],sha:"e57bc09794d5cf07fdeebd457270e0f15d5c64deb2c3bf930d7128bb29fed6ae"},{id:"norton-park",name:"Norton Park",developer:"Gamuda Land",city:"TP.HCM",district:"Thuận Giao (Bình Dương cũ)",at:[106.71274,10.93134],height:70.5,rotation:0,zoom:15.8,towers:6,floors:"19",note:"6 tháp 19 tầng mặt QL13, cạnh ga metro; vị trí theo Google Maps.",aka:["Bình Dương","QL13"],sha:"474f3dac6e76d83ef80d93dbea29c01401a1e2aefea937ec0a689444352f9b99"},{id:"eaton-park",name:"Eaton Park",developer:"Gamuda Land",city:"TP.HCM",district:"Bình Trưng (Thủ Đức)",at:[106.755,10.7975],height:148,rotation:0,zoom:16,towers:6,floors:"29–39",note:"6 tháp 29–39 tầng quanh công viên, mặt Mai Chí Thọ. Vị trí ước lượng — chỉnh lại nếu lệch.",aka:["Mai Chí Thọ","Quận 2"],sha:"e64c202c40d0c804103c18e31220f7a36dd573691ee1ee1980bc8171189c49fa"},{id:"lumiere-midtown",name:"Lumière Midtown",developer:"Masterise Homes",city:"TP.HCM",district:"The Global City (Thủ Đức)",at:[106.77459,10.8034],height:102.3,rotation:0,towers:2,floors:"27",note:"2 tháp trên khối đế 4 tầng, lô CT7 The Global City.",aka:["Global City","CT7","Quận 2"],sha:"d9a8869bb2ef4adeb40eac0a1227bfec2c66127fd1be18dde999fd6de1def5ce"},{id:"noble-crystal-tay-ho",name:"Noble Crystal Tây Hồ",developer:"Sunshine Group",city:"Hà Nội",district:"Tây Hồ",at:[105.80305,21.08439],height:148.3,rotation:5.5,zoom:16,towers:5,floors:"40",note:"5 tháp 40 tầng thành một dải nhìn sông Hồng, cầu nối trên mái.",aka:["Ciputra"],sha:"eaf05d4ad91a97a6775738a42fcb7a0cd7fde4080236812a6df8cf53ce12324e"},{id:"lumiere-prime-hills",name:"Lumière Prime Hills",developer:"Masterise Homes",city:"Hà Nội",district:"Cổ Loa (Đông Anh)",at:[105.85463,21.10003],height:170.4,rotation:-38.8,towers:3,floors:"45",note:"3 tháp 45 tầng trên khối đế, đường Trường Sa, Vinhomes Global Gate.",aka:["Cổ Loa","Global Gate","Đông Anh"],sha:"7454b84846ddb8521895b098beab53086ab8fd9135c9094b2068678ecda4fff5"}].map(t=>Object.freeze({...t,model:O4(t.sha)})));function z4(t){return P4.find(e=>e.id===t)??null}function L4(t,{show:e=0,rise:o=!0,at:r,height:n,rotation:a}={}){return{gcsUri:t.model,label:t.name.slice(0,60),at:r??[...t.at],height:n??t.height,rotation:a??t.rotation,show:e,rise:o}}function QA(t){return{label:t.name.slice(0,60),center:[...t.at],zoom:t.zoom??16.4,pitch:55,bearing:t.bearing??0}}const Tu=1e3,Yc=["ờ","ơ","ừm","ưm","ừ","ờm","hừm","hmm","hm","ừa","um","umm","uh","uhm","erm","er","ah","eh","mm"],t1=t=>String(t||"").normalize("NFC").toLowerCase().replace(/[^\p{L}]/gu,""),Ks=t=>{const e=t1(t);return!!e&&Yc.includes(e)};function N4(t=[]){return t.flatMap(e=>Yc.includes(t1(e?.word))&&Number.isFinite(e.start)&&Number.isFinite(e.end)&&e.end>e.start&&e.end-e.start<2.5?[{start:e.start,end:e.end,text:String(e.word).trim()}]:[])}function F4(t,e){const o=[...t.map(a=>({start:+a.start.toFixed(3),end:+a.end.toFixed(3),kind:"silence"})),...e.map(a=>({start:+a.start.toFixed(3),end:+a.end.toFixed(3),kind:"filler",text:a.text.slice(0,20)}))],r=a=>a.kind==="filler"?1:a.end-a.start>=.6?0:2;return(o.length<=Tu?o:[...o].sort((a,i)=>r(a)-r(i)||i.end-i.start-(a.end-a.start)||a.start-i.start).slice(0,Tu)).sort((a,i)=>a.start-i.start)}function R4(t){if(!Array.isArray(t)||t.length>Tu||t.some(e=>!e||!Number.isFinite(e.start)||!Number.isFinite(e.end)||e.start<0||e.end<=e.start||!["silence","filler"].includes(e.kind)))throw Error("Invalid pause analysis");return t}const Bl=Object.freeze({min:.3,lead:.05,tail:.08,long:.6,minShare:.25,minWords:10}),e1=t=>(Array.isArray(t)?t:[]).filter(e=>e&&Number.isFinite(e.start)&&Number.isFinite(e.end)&&e.end>e.start).sort((e,o)=>e.start-o.start);function D4(t,e,{min:o,lead:r,tail:n}=Bl){const a=e1(t).filter(p=>!Ks(p.word)),i=[],l=(p,c)=>{c-p>=o-r-n&&c-p>.05&&i.push({start:Math.max(0,p),end:c})};if(!a.length)return i;a[0].start>=o&&l(0,a[0].start-n);for(let p=1;p<a.length;p++)a[p].start-a[p-1].end>=o&&l(a[p-1].end+r,a[p].start-n);return Number.isFinite(e)&&e-a.at(-1).end>=o&&l(a.at(-1).end+r,e),i}function o1(t){const e=Array.isArray(t?.pauses)?t.pauses:null,o=e1(t?.words).filter(l=>!Ks(l.word));if(o.length<Bl.minWords)return e;const r=[];for(let l=1;l<o.length;l++)o[l].start-o[l-1].end>=Bl.long&&r.push({start:o[l-1].end,end:o[l].start});if(!r.length)return e;const n=(e||[]).filter(l=>l?.kind==="silence"),a=r.filter(l=>n.some(p=>Math.min(p.end,l.end)-Math.max(p.start,l.start)>=.5*(l.end-l.start))).length;if(e&&a>=Bl.minShare*r.length)return e;const i=[...(e||[]).filter(l=>l?.kind==="filler").map(l=>({start:l.start,end:l.end,text:String(l.text||"")})),...N4(t.words)].filter((l,p,c)=>c.findIndex(s=>Math.abs(s.start-l.start)<.05)===p);return F4(D4(t.words,Number(t.duration)),i)}function B4(t,e,o,{minGap:r=.6,padding:n=.12,fillers:a=!1,maxClips:i=100,isBed:l=s=>s.kind==="audio"&&s.nodeId!==o?.id}={},p={},c=()=>Math.random().toString(36).slice(2,10)){const s=t.find(I=>I.id===e);if(!s||!["video","audio"].includes(s.kind))throw Error("Pause removal needs a video or audio clip");if(s.reverse)throw Error("Pause removal does not support reversed clips");if(p[s.track]?.locked)throw Error("Track is locked");const h=o1(o);if(!h)throw Error("Analyze speech first (pauses unknown)");if(!(r>=.2&&r<=5)||!(n>=0&&n<=.5))throw Error("Invalid pause settings");const f=s.playbackRate||1,m=s.inPoint||0,y=m+s.duration*f;let x=Ed(R4(h).flatMap(I=>I.kind==="filler"?a?[{start:I.start-.02,end:I.end+.02}]:[]:I.end-I.start>=r?[{start:I.start+n,end:I.end-n}]:[]).map(I=>({start:Math.max(I.start,m),end:Math.min(I.end,y)})).filter(I=>I.end-I.start>=2/30)).map(I=>({start:ht(s.start+(I.start-m)/f),end:ht(s.start+(I.end-m)/f)})).filter(I=>I.end-I.start>=2/30);const E=Math.max(0,i-t.length),v=Math.max(0,x.length-E);v&&(x=[...x].sort((I,P)=>P.end-P.start-(I.end-I.start)).slice(0,E)),x.sort((I,P)=>P.start-I.start);let S=t.map(I=>({...I})),k=0,b=v,A=0;for(const I of x){const P=S.find(U=>U.track===s.track&&U.nodeId===s.nodeId&&U.start<=I.start+1e-6&&U.start+U.duration>=I.end-1e-6),C=!P||S.some(U=>U.track!==s.track&&!l(U)&&U.start<I.end-1/60&&U.start+U.duration>I.start+1/60)||S.some(U=>p[U.track]?.locked&&U.start>=I.end-1/60),z=P&&I.start<=P.start+1/30,N=P&&I.end>=P.start+P.duration-1/30;if(C||z&&N){b++;continue}let F=null,K=null;if(z)K=Ne(P,I.end,c())[1];else if(N)F=Ne(P,I.start,c())[0];else{const[U,rt]=Ne(P,I.start,c());F=U,K=rt&&Ne(rt,I.end,c())[1]}if(!F&&!K){b++;continue}const _=ht(I.end-I.start),q=[...F?[F]:[],...K?[{...K,id:F?K.id:P.id,start:I.start}]:[]];S=S.flatMap(U=>U.id===P.id?q:[U.start>=I.end-1/60&&!(l(U)&&U.start<I.end+1/60&&U.start>I.start)?{...U,start:ht(U.start-_)}:U]),k++,A+=_}return{clips:S,removed:k,skipped:b,saved:ht(A)}}function _4(t,e,o={},r=new Set){const n=[];for(const a of t){if(r.has(a.id)||a.kind==="image"||a.kind==="model"||(a.volume??1)<=0||o[a.track]?.muted)continue;const i=e.find(l=>l.id===a.nodeId);for(const l of Jl(a,Array.isArray(i?.transcript)?i.transcript:[]))n.push({start:a.start+l.start,end:a.start+l.end})}return Ed(n,.4)}function G4(t,e,o,r,n={}){if(!(r>=.05&&r<=.8))throw Error("Duck level must be 0.05–0.8");const a=new Set(e);if(!a.size)throw Error("No music/audio clip to duck");const i=_4(t,o,n,a);if(!i.length)throw Error("No analysed speech to duck under — analyze the talking-head clip first");let l=0;return{clips:t.map(c=>{if(!a.has(c.id))return c;if(n[c.track]?.locked)throw Error("Track is locked");if(!["audio","video"].includes(c.kind))throw Error("Only audio/video clips can be ducked");const s=Ed(i.flatMap(h=>{const f=Math.max(0,h.start-c.start),m=Math.min(c.duration,h.end-c.start);return m>f?[{start:+f.toFixed(3),end:+m.toFixed(3)}]:[]}),2*fb).slice(0,hb);if(!s.length){const{duck:h,...f}=c;return f}return l++,{...c,duck:{level:+r.toFixed(3),ranges:s}}}),ducked:l}}function K4(t,e,o=.5,r=.5){const n=t,a=e;if(!(n>0)||!(a>0))throw Error("Unknown source dimensions");const i=Math.min(4,Math.max(n/a,a/n)),l=Number.isFinite(o)?Math.max(0,Math.min(1,o)):.5,p=Number.isFinite(r)?Math.max(0,Math.min(1,r)):.5,c=(i-1)/2,s=n>a?Math.max(-c,Math.min(c,i*(.5-l))):0,h=n<a?Math.max(-c,Math.min(c,i*(.5-p))):0;return{scale:+i.toFixed(4),posX:+Math.max(-1,Math.min(1,s)).toFixed(4),posY:+Math.max(-1,Math.min(1,h)).toFixed(4)}}function V4(t,e,o,{clipId:r}={},n={}){const a=db(o);let i=0;const l=[];return{clips:t.map(c=>{if(r?c.id!==r:c.kind!=="video"&&c.kind!=="image"||c.title)return c;const s=e.find(y=>y.id===c.nodeId),h=c.label||c.id;if(n[c.track]?.locked)return l.push(`${h}: locked`),c;if(!(s?.width>0&&s?.height>0))return l.push(`${h}: size unknown (analyze first)`),c;if(Me(c,"x").length||Me(c,"zoom").length||Me(c,"y").length)return l.push(`${h}: has position keyframes`),c;const f=(c.inPoint||0)+c.duration*(c.playbackRate||1)/2,m=(s.scenes||[]).find(y=>y.start<=f&&y.end>f)||(s.scenes||[]).find(y=>Number.isFinite(y.subjectX));return i++,{...c,...K4(s.width/s.height,a,m?.subjectX,m?.subjectY),motionV:2}}),reframed:i,skipped:l}}const Ti=Object.freeze({reach:.6,breath:.08,near:.04});function vp(t,e){if(!Array.isArray(t)||!t.length||!Number.isFinite(e))return e;const o=t.findIndex(c=>c.start<e&&e<c.end),r=c=>{const s=t[c-1],h=t[c];return s?[s.end,h.start]:[Math.max(0,h.start-.3),h.start]},n=c=>{const s=t[c],h=t[c+1];return h?[s.end,h.start]:[s.end,s.end+.3]},a=([c,s],h)=>{const f=Math.max(0,s-c),m=Math.min(Ti.breath,f/2);return h==="before"?s-m:c+m};if(o>=0){const c=t[o];return(c.start+c.end)/2>e?a(r(o),"before"):a(n(o),"after")}const i=t.findIndex(c=>c.start>=e),l=i>0?t[i-1]:i<0?t[t.length-1]:null,p=i>=0?t[i]:null;return p&&p.start-e<Ti.near?a([l?l.end:p.start-.3,p.start],"before"):l&&e-l.end<Ti.near?a([l.end,p?p.start:l.end+.3],"after"):e}const Eo=Object.freeze({window:90,minSimilarity:.6,pause:.45,restartGap:6,abandonGap:1.2,maxBetween:2,lookBack:12,breath:.08,closeGap:2.5,junkWords:3,junkSeconds:4,maxWords:60}),r1=Object.freeze(["best","last","first"]),W4=/[.?!…。]["'”’)\]]*$/u,n1=t=>String(t||"").normalize("NFC").toLowerCase().replace(/[^\p{L}\p{N}]/gu,""),Zi=t=>n1(t).normalize("NFD").replace(/\p{M}/gu,"").replace(/đ/g,"d"),X4=new Set(Yc),H4=new Set([...Yc,"à","like","kiểu"]),U4=new Set("là và của có cho các những một nhé nha ạ ha hả ở thì mà để với khi này đó đấy thế vậy rồi được cũng đã sẽ đang mình tôi tớ bạn chúng ta em anh chị nó họ về trong ra vào lên xuống không rất lại nào gì như nếu vì nên từ đến tới theo hay hoặc thôi luôn đây kia ấy cái chiếc thật quá lắm nhiều ai nhỉ ơi vâng dạ ok okay the a an and or but so to of in on at for with is are was were be been it its this that these those i im ive you youre we they he she my your our me us them just really very do does did dont not no yes yeah well now then here there what how if as by from up out about can will would gonna going get got lets let all some".split(" ")),$f=t=>(t.kind==="video"||t.kind==="audio")&&!t.reverse&&!t.title&&!t.motion&&!t.shape,vf=t=>!!(t&&(Array.isArray(t.words)&&t.words.length||Array.isArray(t.transcript)&&t.transcript.length));function Y4(t){return Array.isArray(t.words)&&t.words.length?t.words.filter(e=>e&&Number.isFinite(e.start)&&Number.isFinite(e.end)&&e.end>e.start&&typeof e.word=="string"):t.transcript.flatMap(e=>{const o=String(e?.text||"").split(/\s+/).filter(Boolean);if(!o.length||!(e.end>e.start))return[];const r=(e.end-e.start)/o.length;return o.map((n,a)=>({start:e.start+a*r,end:e.start+(a+1)*r,word:n,...a===o.length-1?{cueEnd:!0}:{}}))})}const a1=t=>(Array.isArray(t?.pauses)?t.pauses:[]).filter(e=>e?.kind==="filler"&&Number.isFinite(e.start)&&e.end>e.start),i1=(t,e,o,r)=>Math.max(0,Math.min(e,r)-Math.max(t,o));function Ou(t,e,o){const r=t.length,n=e.length,a=n+1,i=new Uint16Array((r+1)*a);for(let s=1;s<=r;s++)for(let h=1;h<=n;h++)i[s*a+h]=t[s-1]===e[h-1]?i[(s-1)*a+h-1]+1:Math.max(i[(s-1)*a+h],i[s*a+h-1]);let l=r,p=n,c=0;for(;l>0&&p>0;)t[l-1]===e[p-1]?(o[l-1]&&c++,l--,p--):i[(l-1)*a+p]>=i[l*a+p-1]?l--:p--;return{len:i[r*a+n],mc:c}}const Ep=t=>t.reduce((e,o)=>e+(o?1:0),0);function Ef(t,e,o=Eo.minSimilarity){const r=t.keys,n=e.keys;if(r.length<2||n.length<2)return null;let a=null;const[i,l]=r.length<=n.length?[t,e]:[e,t];if(i.keys.length<l.keys.length&&i.keys[0]===l.keys[0]){const p=Ou(i.keys,l.keys.slice(0,i.keys.length+1),i.content),c=i.keys.length-(i.keys.length>=4?1:0);p.len>=c&&p.mc>=1&&p.mc===Ep(i.content)&&(i.keys.length>=3||p.mc>=2)&&(a={kind:"prefix",sim:+(p.len/i.keys.length).toFixed(4),short:i===t?0:1})}if(r.length>=3&&n.length>=3){const p=Ep(t.content),c=Ep(e.content);if(p>=2&&c>=2){const s=Ou(r,n,t.content),h=+(2*s.len/(r.length+n.length)).toFixed(4);h>=o&&s.mc>=.8*Math.min(p,c)-1e-9&&s.mc>=.5*Math.max(p,c)-1e-9&&(!a||h>a.sim)&&(a={kind:"full",sim:h})}}return a}function s1(t,e){const o=[],r=t.length;for(let n=0;n<r-3;n++){let a=null;for(let i=Math.floor((r-n)/2);i>=(n>0?3:2)&&!a;i--)for(const l of[0,1]){const p=n+i+l;if(p+i>r)continue;let c=!0;for(let s=0;s<i&&c;s++)c=t[n+s]===t[p+s];if(c&&(i>=3||e.slice(n,n+i).some(Boolean))){a={i:n,j:p};break}}a&&(o.push(a),n=a.j-1)}return o}function q4(t,e,o,r){const n=s=>e.find(h=>h.id===s);let a;if(Array.isArray(o)&&o.length){a=o.map(h=>{const f=t.find(m=>m.id===h);if(!f)throw Error(`Clip not found: ${h}`);return f});const s=a.find(h=>!$f(h)||!vf(n(h.nodeId)));if(s)throw Error(`"${s.label||s.id}" has no analysed speech (video / audio with a transcript)`)}else a=t.filter(s=>$f(s)&&vf(n(s.nodeId)));if(!a.length)throw Error("Analyze speech first (no clip with transcript words)");const i=s=>(s.volume??1)>0&&!r[s.track]?.muted,l=[...a].sort((s,h)=>Number(i(h))-Number(i(s))||(s.kind==="audio")-(h.kind==="audio")||s.track-h.track||s.start-h.start),p=[],c=[];for(const s of l)(p.filter(f=>f.track!==s.track).reduce((f,m)=>f+i1(s.start,s.start+s.duration,m.start,m.start+m.duration),0)>=s.duration*.5?c:p).push(s);return{primary:p,companions:c}}function Z4(t,e){const o=new Map;for(const r of t){const n=e.find(s=>s.id===r.nodeId),a=r.playbackRate||1,i=r.inPoint||0,l=i+r.duration*a,p=r.start+r.duration,c=o.get(r.track)??[];o.set(r.track,c);for(const s of Y4(n)){const h=(s.start+s.end)/2;if(h<i-1e-6||h>=l-1e-6)continue;const f=n1(s.word),m=Zi(s.word),y=!m||H4.has(f);c.push({t:r.start+(Math.max(s.start,i)-i)/a,te:r.start+(Math.min(s.end,l)-i)/a,s:s.start,e:s.end,clipId:r.id,node:r.nodeId,track:r.track,cs:r.start,ce:p,rate:a,text:String(s.word).trim(),key:y?"":m,content:!y&&!U4.has(f),filler:X4.has(f),stop:W4.test(String(s.word).trim())||!!s.cueEnd})}}for(const r of o.values())r.sort((n,a)=>n.t-a.t||n.s-a.s);return o}function J4(t,e){const o=new Map,r=[];let n=null;const a=(i,l)=>{if(i.node!==l.node)return 0;let p=o.get(i.node);return p||(p=a1(e.find(c=>c.id===i.node)),o.set(i.node,p)),p.reduce((c,s)=>c+i1(i.e,l.s,s.start,s.end),0)/(i.rate||1)};t.forEach((i,l)=>{const p=t[l-1];(!n||p.stop||p.node!==i.node||i.s<p.s-.05||i.s-p.e>3||i.t-p.te-a(p,i)>=Eo.pause||n.keys.length>=Eo.maxWords)&&(n?.keys.length&&r.push(n),n={w0:l,w1:l,keys:[],content:[],keyWord:[]}),n.w1=l,i.key&&(n.keys.push(i.key),n.content.push(i.content),n.keyWord.push(l))}),n?.keys.length&&r.push(n);for(const i of r)i.t=t[i.w0].t,i.te=t[i.w1].te;return r}function Q4(t,{window:e,minSimilarity:o}){const r=new Array(t.length).fill(-1),n=[];for(let i=0;i<t.length;i++){let l=null;for(let c=i-1;c>=0&&i-c<=Eo.lookBack&&!(t[i].t-t[c].te>e);c--){const s=Ef(t[c],t[i],o);if(!s)continue;let h=0;for(let f=c+1;f<i;f++)t[f].keys.length>=4&&(r[c]<0||r[f]!==r[c])&&h++;(s.kind==="prefix"?h>0||t[i].t-t[c].te>Eo.restartGap:h>Eo.maxBetween)||(!l||s.sim>l.rel.sim+1e-9)&&(l={i:c,rel:s})}if(!l)continue;let p=r[l.i];p<0&&(p=n.length,n.push([l.i]),r[l.i]=p),n[p].push(i),r[i]=p}const a=[];for(let i=1;i<t.length;i++){const l=t[i-1],p=t[i];if(r[i-1]>=0||p.t-l.te>Eo.restartGap)continue;const c=l.keys.lastIndexOf(p.keys[0]);c<2||l.keys.length-c<3||Ef({keys:l.keys.slice(c),content:l.content.slice(c)},p,o)&&a.push({i:i-1,j:i,p:c})}return{groups:n,gid:r,tails:a}}function t5(t,e,o){const r=t.slice(e.w0,e.w1+1);let n=r.filter(f=>f.filler).length;for(const f of new Set(r.map(m=>m.node))){const m=r.filter(x=>x.node===f&&!x.filler);if(!m.length)continue;const y=m[0].s,$=m.at(-1).e;n+=a1(o.find(x=>x.id===f)).filter(x=>x.start>=y-1e-6&&x.end<=$+1e-6).length}const a=e.keys;let i=s1(a,e.content).length;for(let f=1;f<a.length;f++)a[f]===a[f-1]&&i++;const l=r.filter(f=>f.key);let p=0;for(let f=1;f<l.length;f++)p+=Math.max(0,l[f].t-l[f-1].te-.3);const c=l.slice(1).map((f,m)=>f.t-l[m].t),s=c.reduce((f,m)=>f+m,0)/(c.length||1),h=c.length>=2&&s>0?Math.sqrt(c.reduce((f,m)=>f+(m-s)**2,0)/c.length)/s:0;return{fillers:n,restarts:i,longPause:+p.toFixed(3),steady:+Math.max(0,1-Math.min(1,h)).toFixed(3)}}const l1=(t,e=5)=>{const o=t.split(/\s+/).filter(Boolean);return o.length>e?`${o.slice(0,e).join(" ")}…`:o.join(" ")};function e5(t,e){const o=t.map((n,a)=>({t:n,i:a})).filter(n=>n.t.full);if(e==="first")return o[0].i;if(e==="last")return o.at(-1).i;const r=Math.max(...o.map(n=>n.t.score));return o.filter(n=>n.t.score>=r-.03).at(-1).i}function o5(t,e,o,r){return e===o?null:t.kind==="restart"?"restart":t.takes[e].full?r==="last"?"earlier":r==="first"?"later":"weaker":"abandoned"}function r5(t,e=[],o={}){const r=o.keep??"best";if(!r1.includes(r))throw Error("keep must be best, last or first");const n=o.window??Eo.window,a=o.minSimilarity??Eo.minSimilarity;if(!(n>=5&&n<=600))throw Error("window must be 5–600 s");if(!(a>=0&&a<=1))throw Error("minSimilarity must be 0..1");const i=o.tracks??{},{primary:l,companions:p}=q4(t,e,o.clipIds,i),c=Z4(l,e),s=[];for(const[m,y]of[...c].sort(($,x)=>$[0]-x[0])){const $=J4(y,e),{groups:x,gid:E,tails:v}=Q4($,{window:n,minSimilarity:Math.max(.4,a)}),S=[];for(const k of x){const b=k.map(A=>({w0:$[A].w0,w1:$[A].w1,keys:$[A].keys,content:$[A].content}));S.push({kind:"repeat",track:m,takes:b,between:[],utt:k})}for(const{i:k,j:b,p:A}of v){const I=$[k],P={w0:I.keyWord[A],w1:I.w1,keys:I.keys.slice(A),content:I.content.slice(A)};E[b]>=0&&S[E[b]].utt[0]===b?(S[E[b]].takes.unshift(P),S[E[b]].utt.unshift(-1)):E[b]<0&&(E[b]=S.length,x.push([b]),S.push({kind:"repeat",track:m,takes:[P,{w0:$[b].w0,w1:$[b].w1,keys:$[b].keys,content:$[b].content}],between:[],utt:[-1,b]}))}$.forEach((k,b)=>{for(const A of s1(k.keys,k.content)){const I=E[b]>=0?S[E[b]]:null,P={w0:k.keyWord[A.i]===k.keyWord[0]?k.w0:k.keyWord[A.i],w1:k.keyWord[A.j]-1,keys:k.keys.slice(A.i,A.j),content:k.content.slice(A.i,A.j)},C={w0:k.keyWord[A.j],w1:k.w1,keys:k.keys.slice(A.j),content:k.content.slice(A.j)};S.push({kind:"restart",track:m,takes:[P,C],between:[],parentRef:I?{g:I,take:I.utt.indexOf(b)}:null})}});for(const k of S){const b=new Set(k.takes.flatMap(I=>I.keys));for(const I of k.takes)Object.assign(I,t5(y,I,e)),I.completeness=+(new Set(I.keys.filter(P=>b.has(P))).size/b.size).toFixed(3);const A=Math.max(...k.takes.map(I=>I.completeness));for(const I of k.takes)I.full=I.completeness>=Math.max(.6,A-.3)-1e-9,I.score=+(.6*I.completeness+.1*I.steady-.06*I.fillers-.08*I.restarts-.15*Math.min(1,I.longPause)).toFixed(4);if(k.kind==="repeat"){const I=k.takes.map((P,C)=>C<k.takes.length-1&&P.full&&!y[P.w1].stop&&y[k.takes[C+1].w0].t-y[P.w1].te<=Eo.abandonGap);k.takes.some((P,C)=>P.full&&!I[C])&&k.takes.forEach((P,C)=>{I[C]&&(P.full=!1)})}if(k.kind==="repeat")for(let I=1;I<k.takes.length;I++){const P=k.takes[I-1].w1+1,C=k.takes[I].w0-1;if(C<P)continue;const z=$.filter(F=>F.w0>=P&&F.w1<=C),N=F=>!y[F.w1].stop&&F.keys.length>=2&&Ou(F.keys,k.takes[I].keys,F.content).len>=.7*F.keys.length;z.every(F=>F.keys.length<=Eo.junkWords||N(F))&&y[C].te-y[P].t<=Eo.junkSeconds&&k.between.push({w0:P,w1:C})}}for(const k of S)s.push(k)}const h=s.map(m=>{const y=c.get(m.track),$=y[m.takes[0].w0];return{...m,id:`${m.kind==="restart"?"r":"g"}:${$.node}@${$.s.toFixed(2)}`}}).sort((m,y)=>c.get(m.track)[m.takes[0].w0].t-c.get(y.track)[y.takes[0].w0].t||m.track-y.track),f={groups:[],streams:Object.fromEntries(c),primary:l.map(Sf),companions:p.map(Sf),speechNodes:[...new Set([...l,...p].map(m=>m.nodeId))]};for(const m of h){const y=c.get(m.track),$=e5(m.takes,r),x=m.takes.map(v=>({w0:v.w0,w1:v.w1,text:y.slice(v.w0,v.w1+1).map(S=>S.text).join(" "),start:+y[v.w0].t.toFixed(3),end:+y[v.w1].te.toFixed(3),clipId:y[v.w0].clipId,score:v.score,completeness:v.completeness,fillers:v.fillers,restarts:v.restarts,longPause:v.longPause,steady:v.steady,full:v.full})),E=m.parentRef?{id:h.find(v=>v.takes===m.parentRef.g.takes)?.id??null,take:m.parentRef.take}:null;f.groups.push({id:m.id,kind:m.kind,track:m.track,label:l1(x[$].text),takes:x,kept:$,reasons:x.map((v,S)=>o5(m,S,$,r)),between:m.between,parent:E?.id?E:null,cuts:[]})}for(const m of f.groups)m.cuts=m.takes.flatMap((y,$)=>$===m.kept?[]:[{take:$,reason:m.reasons[$],ranges:n5(f,Pu(f.streams[m.track],m.takes[$].w0,m.takes[$].w1),m.track)}]);return f}const Sf=t=>({id:t.id,track:t.track,nodeId:t.nodeId,start:t.start,duration:t.duration,inPoint:t.inPoint||0,rate:t.playbackRate||1});function Pu(t,e,o){const r=t[e],n=t[o],a=t[e-1],i=t[o+1],p=a&&a.te<=r.t+1e-6&&a.te>=r.cs-1e-6?r.t-Math.min(Eo.breath,Math.max(0,r.t-a.te)/2):r.t-r.cs<=Eo.closeGap?r.cs:r.t-Eo.breath,c=i?i.t:n.ce,s=Math.max(0,c-n.te),h=s<=Eo.closeGap?i?i.t-Math.min(Eo.breath,s/2):c:n.te+.12;return{start:Math.max(0,p),end:Math.max(p,h)}}function zu(t,e,o){return t.primary.filter(r=>r.track===o).flatMap(r=>{const n=ht(r.start+r.duration);let a=ht(Math.max(e.start,r.start)),i=ht(Math.min(e.end,n));return a-r.start<=1/30+1e-9&&(a=r.start),n-i<=1/30+1e-9&&(i=n),i-a>=2/30?[{clipId:r.id,track:o,nodeId:r.nodeId,start:a,end:i,srcStart:+(r.inPoint+(a-r.start)*r.rate).toFixed(3),srcEnd:+(r.inPoint+(i-r.start)*r.rate).toFixed(3)}]:[]})}const n5=(t,e,o)=>zu(t,e,o).map(r=>({clipId:r.clipId,start:r.srcStart,end:r.srcEnd}));function a5(t,e,o,r){const n=t.start+t.duration,a=e<=t.start+1/30,i=o>=n-1/30;if(a&&i)return[];if(a){const s=Ne(t,o,r())[1];return s?[{...s,id:t.id,start:t.start}]:[t]}if(i)return[Ne(t,e,r())[0]];const[l,p]=Ne(t,e,r()),c=p&&Ne(p,o,r())[1];return c?[l,{...c,start:ht(e)}]:[l]}const i5=t=>t.label||t.id;function s5(t,e,o={}){const r=o.tracks??{},n=o.makeId??(()=>Math.random().toString(36).slice(2,10)),a=o.maxClips??Cs,i=o.isBed??(C=>C.kind==="audio"&&!e.speechNodes.includes(C.nodeId)),l=o.choose??{},p=new Set(o.skip??[]),c=new Map(e.groups.map(C=>[C.id,C])),s=C=>{const z=l[C.id];return Number.isInteger(z)&&z>=0&&z<C.takes.length?z:C.kept},h=(C,z)=>{const N=c.get(C);return!!N&&!p.has(C)&&s(N)!==z},f=[],m=[];for(const C of e.groups){if(p.has(C.id)||C.parent&&h(C.parent.id,C.parent.take))continue;const z=s(C),N=C.takes.map((_,q)=>q).filter(_=>_!==z),F=e.streams[C.track],K={id:C.id,label:C.kind==="restart"?C.label:l5(C,z),kind:C.kind,takes:C.takes.length,kept:z,cut:N,blocked:[]};f.push(K);for(const _ of N)m.push({...Pu(F,C.takes[_].w0,C.takes[_].w1),track:C.track,who:[[K,_]]});if(N.length)for(const _ of C.between)m.push({...Pu(F,_.w0,_.w1),track:C.track,who:[]})}const y=new Set(e.primary.map(C=>C.id)),$=new Set(e.companions.map(C=>`${C.track}|${C.nodeId}`)),x=(C,z,N)=>C.start<=z+1e-6&&C.start+C.duration>=N-1e-6,E=C=>{if(r[C.track]?.locked)return"locked";for(const z of zu(e,C,C.track)){const N=K=>K.start<z.end-.016666666666666666&&K.start+K.duration>z.start+.016666666666666666,F=t.find(K=>K.id!==z.clipId&&N(K)&&(K.track===C.track?!y.has(K.id):!i(K)&&!($.has(`${K.track}|${K.nodeId}`)&&x(K,z.start,z.end))));if(F)return`"${i5(F)}"`;if(t.some(K=>r[K.track]?.locked&&(K.start>=z.end-1/60||N(K)&&$.has(`${K.track}|${K.nodeId}`))))return"locked"}return null},v=[];for(const C of m.sort((z,N)=>z.track-N.track||z.start-N.start)){const z=E(C);if(z){for(const[F,K]of C.who)F.blocked.push({take:K,reason:z});continue}const N=v.at(-1);N&&N.track===C.track&&C.start<=N.end+1/60?(N.end=Math.max(N.end,C.end),N.who.push(...C.who)):v.push({...C,who:[...C.who]})}const S=[];let k=0;for(const C of v){const z=zu(e,C,C.track);let N=null;if(!z.length)continue;const F=z.reduce((K,_)=>{const q=t.find(rt=>rt.id===_.clipId),U=q&&_.start>q.start+1/30&&_.end<q.start+q.duration-1/30;return K+(U?1+t.filter(rt=>rt.track!==C.track&&$.has(`${rt.track}|${rt.nodeId}`)&&x(rt,_.start,_.end)).length:0)},0);if(!N&&t.length+k+F>a&&(N="limit"),N){for(const[K,_]of C.who)K.blocked.push({take:_,reason:N});continue}k+=F,S.push(...z)}let b=t.map(C=>({...C})),A=0,I=0;for(const C of S.sort((z,N)=>N.start-z.start)){const z=b.filter(K=>(K.track===C.track&&K.nodeId===C.nodeId||K.track!==C.track&&$.has(`${K.track}|${K.nodeId}`))&&x(K,C.start,C.end));if(!z.some(K=>K.track===C.track))continue;const N=ht(C.end-C.start),F=new Set(z.map(K=>K.id));b=b.flatMap(K=>F.has(K.id)?a5(K,C.start,C.end,n):[K.start>=C.end-1/60&&!(i(K)&&K.start<C.end+1/60&&K.start>C.start)?{...K,start:ht(K.start-N)}:K]),A++,I+=N}const P=f.filter(C=>C.cut.length).map(C=>c5(C,o.en));return{clips:b,groups:f,removed:A,saved:ht(I),lines:P}}const l5=(t,e)=>l1(t.takes[e].text);function c5(t,e){const o=t.cut.filter(a=>!t.blocked.some(i=>i.take===a)),r=[...new Set(t.blocked.map(a=>a.reason==="locked"?e?"a locked track":"track đã khoá":a.reason==="limit"?e?"the clip limit":"giới hạn clip":a.reason))].join(", "),n=t.blocked.length?e?` (${t.blocked.length} not cut: blocked by ${r})`:` (${t.blocked.length} lần không cắt được: vướng ${r})`:"";return t.kind==="restart"?e?`retakes: false start "${t.label}" → ${o.length?"cut":"kept"}${n}`:`retakes: nói vấp "${t.label}" → ${o.length?"bỏ đoạn vấp":"giữ nguyên"}${n}`:e?`retakes: ${t.takes} takes of "${t.label}" → kept take ${t.kept+1}${n}`:`retakes: ${t.takes} lần nói "${t.label}" → giữ lần ${t.kept+1}${n}`}function p5(t,e,o={}){const r=r5(t,e,o);return{...s5(t,r,o),found:r}}const fa=Object.freeze({lead:.3,iconLead:.2,minGap:.8,maxLead:2}),If=new Set("cau cho truong benh vien khu du an thanh pho tp quan huyen phuong xa tinh song ho bai bien cong san bay nha ga ben duong dai hoc trung tam thuong mai sieu thi toa chung cu can ho biet thu vinh dao nui deo lang quoc te the of and bridge river lake beach park market school hospital airport station street road city district mall center centre".split(" ")),Lu=t=>String(t??"").split(",")[0].split(/[\s\-–—/.]+/).map(Zi).filter(Boolean);function c1(t,e,o,r,n=null){const a=[];for(const i of Array.isArray(t)?t:[]){if((n?i.id!==n:!["audio","video"].includes(i.kind)||i.muted||i.volume===0)||!(i.start<r&&i.start+i.duration>o))continue;const l=(e??[]).find(p=>p.id===i.nodeId);for(const p of Ql(i,Array.isArray(l?.words)?l.words:null)){const c=i.start+p.start;c>=o-1e-6&&c<r&&a.push({start:c,end:i.start+p.end,word:p.word,key:Zi(p.word)})}}return a.sort((i,l)=>i.start-l.start)}function Nu(t,e,o=-1/0){const r=Lu(t);if(!r.length)return null;let n=null;for(let a=0;a<e.length;a++)if(!(e[a].start<o)){for(let i=0;i<r.length;i++){let l=0;for(;a+l<e.length&&i+l<r.length&&e[a+l].key===r[i+l];)l++;if(!l)continue;const p=r.filter(s=>!If.has(s)),c=r.slice(i,i+l).filter(s=>!If.has(s)).length;l<r.length&&!(c&&(c===p.length||c>=2))||(!n||l>n.n)&&(n={n:l,at:e[a].start,said:e.slice(a,a+l).map(s=>s.word).join(" ")})}if(n?.n===r.length)break}return n&&{at:n.at,said:n.said}}const el=t=>Math.round(t*100)/100,Sp=(t,e,o)=>Math.min(o,Math.max(e,t));function u5(t,e,{words:o=[],times:r=null,start:n=0,duration:a,lead:i=fa.lead}){const l=a,p=Sp(Number.isFinite(i)?i:fa.lead,0,fa.maxLead),c=[],s=Array.isArray(r)?r.filter(b=>b&&Number.isFinite(Number(b.at))):null,h=(b,A,I)=>{const P=I[A];if(Number.isInteger(P))return P>=1&&P<=b.length?P-1:-1;const C=Lu(P).join(" ");return C?b.findIndex(z=>Lu(z.label).join(" ")===C):-1},f=t.map(()=>null);let m=n-1e-6;t.forEach((b,A)=>{const I=s?.find(C=>C.place!=null&&h(t,"place",C)===A),P=I?{at:Number(I.at),said:null}:s?null:Nu(b.label,o,m);P&&(f[A]=P,m=P.at+.001),c.push({kind:"place",name:b.label||`#${A+1}`,at:P?el(P.at):null,...P?.said?{said:P.said}:{}})});const y=(e??[]).map((b,A)=>{const I=s?.find(C=>C.icon!=null&&h(e,"icon",C)===A),P=I?{at:Number(I.at),said:null}:s||!b.label?null:Nu(b.label,o,n-1e-6);return c.push({kind:"icon",name:b.label||b.icon,at:P?el(P.at):null,...P?.said?{said:P.said}:{}}),P});if(!f.some(Boolean)&&!y.some(Boolean))throw Error("None of the map's places or icons is said in the voice (check the Transcript, or give times)");const $=t.length,x=$>1?l*.85:0,E=f.map(b=>b?Sp(b.at-n-p,0,l-.3):null);for(let b=1;b<$;b++)if(E[b]!=null){const A=E.slice(0,b).reverse().find(I=>I!=null);A!=null&&E[b]<A+fa.minGap&&(E[b]=Math.min(l-.3,A+fa.minGap))}const v=E.map((b,A)=>b==null?null:A).filter(b=>b!=null);for(let b=0;b<$;b++){if(E[b]!=null)continue;const A=[...v].reverse().find(P=>P<b),I=v.find(P=>P>b);A!=null&&I!=null?E[b]=E[A]+(E[I]-E[A])*(b-A)/(I-A):I!=null?E[b]=E[I]*b/I:A!=null?E[b]=Math.min(l-.3,E[A]+Math.max(fa.minGap,(x-E[A])/($-1-A))*(b-A)):E[b]=$>1?x*b/($-1):0}const S=t.map((b,A)=>({...b,at:el(E[A])})),k=(e??[]).map((b,A)=>{const I=y[A],{show:P,...C}=b;return I?{...C,show:el(Sp(I.at-n-fa.iconLead,0,l-.5))}:C});return{places:S,icons:k,report:c}}function d5(t){return t.map(e=>e.at==null?`${e.name} not said`:`${e.name} ${e.at} s${e.said?` («${e.said}»)`:""}`).join("; ")}const tn=Object.freeze({maxReplace:60,maxCues:300,maxText:300,near:.35}),h5=t=>t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),f5=(t,e)=>new RegExp(`(?<![\\p{L}\\p{N}])${h5(t.normalize("NFC"))}(?![\\p{L}\\p{N}])`,e?"gu":"giu");function m5(t,e){if(e!=null){if(!Array.isArray(e)||!e.length)throw Error("clipIds must be a list of clip ids");return e.map(o=>{const r=t.find(n=>n.id===o);if(!r)throw Error(`Clip not found: ${String(o).slice(0,40)}`);if(!r.captions?.length)throw Error(`"${r.label||r.id}" has no subtitles (addSocialCaptions first)`);return r})}return t.filter(o=>o.captions?.length)}function g5(t,e){const o=e.replace==null?[]:e.replace,r=e.cues==null?[]:e.cues;if(!Array.isArray(o)||!Array.isArray(r))throw Error("replace and cues must be lists");if(!o.length&&!r.length)throw Error("needs replace [{from, to}] or cues [{at, text}]");if(o.length>tn.maxReplace)throw Error(`at most ${tn.maxReplace} replacements`);if(r.length>tn.maxCues)throw Error(`at most ${tn.maxCues} cues per edit`);const n=m5(t,e.clipIds);if(!n.length)throw Error("No subtitles on the timeline yet (addSocialCaptions first)");const a=[],i=o.map((c,s)=>{if(!c||typeof c.from!="string"||!c.from.trim()||typeof c.to!="string")throw Error(`replace[${s}] needs from and to (text)`);if(c.from.length>120||c.to.length>120)throw Error(`replace[${s}]: from / to ≤ 120 characters`);return{re:f5(c.from.trim(),c.matchCase===!0),to:c.to.normalize("NFC"),from:c.from.trim(),n:0}});if(i.length){for(const c of n)c.captions.forEach((s,h)=>{let f=s.text.normalize("NFC");for(const m of i)f=f.replace(m.re,()=>(m.n++,m.to));if(f=f.replace(/\s{2,}/g," ").trim(),f!==s.text){if(!f)throw Error(`replace would leave an empty subtitle ("${s.text.slice(0,40)}") — use cues [{at, text: null}] to delete it`);Object.assign(c,Qd(c,h,{text:f.slice(0,tn.maxText)}))}});a.push(...i.map(c=>`replace "${c.from.slice(0,40)}" → "${c.to.slice(0,40)}": ${c.n} time${c.n===1?"":"s"}`))}const l=r.map((c,s)=>{if(!c||!Number.isFinite(c.at))throw Error(`cues[${s}].at must be timeline seconds`);if(c.text!=null&&typeof c.text!="string")throw Error(`cues[${s}].text must be text (null = delete the cue)`);if(typeof c.text=="string"&&c.text.length>tn.maxText)throw Error(`cues[${s}].text ≤ ${tn.maxText} characters`);let h=null;for(const f of n){const m=c.at-f.start;m<-tn.near||m>f.duration+tn.near||f.captions.forEach((y,$)=>{const x=m<y.start?y.start-m:m>=y.end?m-y.end:0;x<=tn.near&&(!h||x<h.d||x===h.d&&(f.track??0)>(h.c.track??0))&&(h={c:f,k:$,d:x})})}if(!h)throw Error(`cues[${s}]: no subtitle shows at ${c.at} s`);return{...h,i:s,text:typeof c.text=="string"?c.text.normalize("NFC").trim():""}}),p=new Set;for(const c of l){const s=`${c.c.id}#${c.k}`;if(p.has(s))throw Error(`cues[${c.i}]: the same subtitle is edited twice`);p.add(s)}for(const c of[...l].sort((s,h)=>s.c.id<h.c.id?-1:s.c.id>h.c.id?1:h.k-s.k)){const s=c.c.captions[c.k].text,h=+(c.c.start+c.c.captions[c.k].start).toFixed(2);Object.assign(c.c,Qd(c.c,c.k,c.text?{text:c.text}:null)),a.push(c.text?`subtitle @${h}s: "${s.slice(0,40)}" → "${c.text.slice(0,40)}"`:`subtitle @${h}s deleted: "${s.slice(0,40)}"`)}return a}const Fu={rotation:[-xs,xs],brightness:[0,2],contrast:[0,2],exposure:[-3,3],saturation:[0,2],hue:[-180,180],audioFadeIn:[0,600],audioFadeOut:[0,600],volume:[0,1]},y5=["flipX","flipY","reverse","colorBypass","motionBlur","disabled"],vs=["analyzeFootage","exportVideo","setExportFormat","play","pause","seek","undo","redo"];function b5(t,e){const o=structuredClone(t),r=e.property;if(e.op==="setClipProperty"){if(r in Fu){const[n,a]=Fu[r],i=e.numberValue;if(!Number.isFinite(i)||i<n||i>a)throw Error("Invalid clip value");o[r]=i}else if(y5.includes(r)){if(typeof e.booleanValue!="boolean")throw Error("Invalid clip flag");o[r]=e.booleanValue}else if(r==="blend"){const n=e.blend??e.preset;if(!th.includes(n))throw Error(`blend must be ${th.join(" | ")}`);n==="normal"?delete o.blend:o.blend=n}else throw Error("Unsupported clip property");if(o.kind==="audio"&&!["volume","audioFadeIn","audioFadeOut","reverse"].includes(r))throw Error("Visual property requires image/video");if(o.kind==="image"&&["volume","audioFadeIn","audioFadeOut","reverse"].includes(r))throw Error("Image has no audio or reverse playback");if(["audioFadeIn","audioFadeOut"].includes(r)&&o[r]>o.duration)throw Error("Fade exceeds clip duration")}if(e.op==="setSpeed"){if(o.kind==="image"&&!o.comp)throw Error("Invalid playback speed");const n=Au(o,e.numberValue);for(const a of Object.keys(o))a in n||delete o[a];Object.assign(o,n)}if(e.op==="setCrop"){if(o.kind==="audio"||!e.crop)throw Error("Crop requires visual clip and crop values");o.crop={...e.crop}}if(e.op==="setKeyframes"){if(o.kind==="audio"||!Array.isArray(e.motionKeys))throw Error("Keyframes require a visual clip");if(o.motionKeys=fu(o,e.motionKeys),delete o.posX,delete o.posY,delete o.scale,o.motionV=2,o.motionKeys.some(n=>n.time>o.duration))throw Error("Key outside clip duration")}if(e.op==="setClipProperty"&&e.property==="reverse"&&o.reverse&&o.speedRamp)throw Error("Speed ramp cannot be combined with reverse — setSpeed first");return e.op==="setClipProperty"&&e.property==="reverse"&&!!t.reverse!=!!o.reverse&&Object.assign(o,U3(o)),hn(o),o}const qc=.35,w5=2e3;function k5(t,e,o=.25){const r=t?.beats;if(!Array.isArray(r)||!r.length||!((t.confidence??0)>=qc))return e;let n=0,a=r.length-1;for(;n<a;){const l=n+a>>1;r[l]<e?n=l+1:a=l}const i=[r[n],r[n-1]].filter(l=>l!==void 0).sort((l,p)=>Math.abs(l-e)-Math.abs(p-e))[0];return Math.abs(i-e)<=o?i:e}function x5(t){if(t==null)return null;const e=r=>Array.isArray(r)&&r.length<=w5&&r.every((n,a)=>Number.isFinite(n)&&n>=0&&n<=3600&&(a===0||n>r[a-1]));if(typeof t!="object"||!e(t.beats)||!e(t.downbeats??[])||!e(t.drops??[]))throw Error("Invalid beat grid");const o=t.bpm==null?null:Number(t.bpm);if(o!=null&&!(o>=30&&o<=300))throw Error("Invalid beat grid tempo");return{bpm:o,confidence:Math.max(0,Math.min(1,Number(t.confidence)||0)),beats:t.beats,downbeats:t.downbeats??[],drops:t.drops??[],duration:Number(t.duration)||0}}const M5=t=>Math.round(t*1e3)/1e3;function $5(t,e){const o=[];for(const r of t){const n=e.find(l=>l.id===r.nodeId)?.beats;if(!Array.isArray(n?.beats)||!((n.confidence??0)>=qc)||r.reverse)continue;const a=Number(r.playbackRate)||1,i=Number(r.inPoint)||0;for(const l of n.beats)l>=i-1e-6&&l<i+r.duration*a-1e-6&&o.push(M5(r.start+(l-i)/a))}return[...new Set(o)].sort((r,n)=>r-n)}const v5=Object.freeze([{id:"ease-in-fast",view:"value"},{id:"s-curve",view:"value"},{id:"ease-out-slow",view:"value"},{id:"ramp-in",view:"value"},{id:"ramp-out",view:"value"},{id:"v-dip",view:"speed"},{id:"peak-burst",view:"speed"},{id:"decelerate",view:"speed"},{id:"accelerate",view:"speed"},{id:"wave",view:"speed"},...["hero-slowmo","montage","rush-brake","freeze-hit","burst-out","rush-stop-rush","double-dip","late-burst","early-brake","stutter-ramp","glide","snap-freeze"].map(t=>({id:t,view:"speed"}))]);v5.map(t=>t.id);function tC(t,e="speed",o=30,r=20,n=24){const a=t==="montage"?[{u:0,speed:3},{u:1,speed:3}]:mb[t];if(!a)throw Error(`Unknown curve ${t}`);const i=a.map(s=>({t:s.u,speed:s.speed,...s.ease?{ease:s.ease}:{}})),l=Array.from({length:n+1},(s,h)=>gb(i,h/n));let p;if(e==="value"){let s=0;p=l.map((f,m)=>m?s+=(f+l[m-1])/2/n:0).map(f=>f/(s||1))}else{const s=Math.max(...l),h=Math.min(...l);p=l.map(f=>s-h<1e-6?.5:(f-h)/(s-h))}const c=2;return p.map((s,h)=>[+(c+(o-2*c)*h/n).toFixed(2),+(r-c-(r-2*c)*s).toFixed(2)])}const Af=Object.freeze([.5,1,2,4]);function E5(t,e,o,r=1){const n=(t||[]).filter(Number.isFinite);if(n.length<2||!(e>0))return[];const a=r===.5?n.flatMap((c,s)=>s<n.length-1?[c,(c+n[s+1])/2]:[c]):n,i=r===.5?1:r;let l=0;for(let c=1;c<a.length;c++)Math.abs(a[c]-o)<Math.abs(a[l]-o)&&(l=c);const p=[];for(let c=0;c<e;c++){const s=l+c*i,h=s+i;if(h>=a.length)break;p.push({start:+a[s].toFixed(3),duration:+(a[h]-a[s]).toFixed(3)})}return p}const p1=Object.freeze({vertical:{props:["y"],amp:{y:.03},freq:12},horizontal:{props:["x"],amp:{x:.03},freq:12},rotation:{props:["rot"],amp:{rot:3.2},freq:10},body:{props:["y","x"],amp:{y:.016,x:.006},freq:6},all:{props:["x","y","rot"],amp:{x:.018,y:.018,rot:1.6},freq:12},custom:{props:["x","y","rot"],amp:{x:.018,y:.018,rot:1.6},freq:12}}),Ru=Object.keys(p1);function S5(t="all",e=.5,o={}){const r=p1[t];if(!r)throw Error(`Shake axis must be one of ${Ru.join(", ")}`);const n=Math.max(.1,Math.min(1,Number.isFinite(e)?e:.5)),a=(i,l)=>Math.max(0,Math.min(1,Number.isFinite(i)?i:l));if(t==="custom"){const i={x:.03*a(o.amountX,.5),y:.03*a(o.amountY,.5),rot:3.2*a(o.amountRot,.3)},l=["x","y","rot"].filter(p=>i[p]>1e-6);if(!l.length)throw Error("Custom shake needs some amountX, amountY or amountRot");return{props:l,amp:Object.fromEntries(l.map(p=>[p,+(i[p]*n*2).toFixed(4)])),freq:Math.max(2,Math.min(30,Number.isFinite(o.freq)?o.freq:12))}}return{props:r.props,amp:Object.fromEntries(r.props.map(i=>[i,+(r.amp[i]*n*2).toFixed(4)])),freq:r.freq}}const u1=Object.freeze({tl:[-.5,-.5],t:[0,-.5],tr:[.5,-.5],l:[-.5,0],c:[0,0],r:[.5,0],bl:[-.5,.5],b:[0,.5],br:[.5,.5]}),Cf=Object.keys(u1),eC=Object.freeze([{id:"slide-right",transition:"kit-slide-right",label:"Trượt →"},{id:"slide-left",transition:"kit-slide-left",label:"Trượt ←"},{id:"slide-up",transition:"kit-slide-up",label:"Trượt ↑"},{id:"slide-down",transition:"kit-slide-down",label:"Trượt ↓"},{id:"zoom-in",transition:"zoom-punch",label:"Zoom vào"},{id:"chroma",transition:"pr-chroma-zoom",label:"Méo màu"},{id:"glitch",transition:"glitch",label:"Glitch"},{id:"gravity",transition:"kit-gravity",label:"Hút tâm"}]),pc=Object.freeze(["zoom-in-start","zoom-in-end","zoom-out-start","zoom-out-end"]);function I5(t,e,o=1,r=.25,n){if(!pc.includes(t))throw Error(`zoomMove preset must be one of ${pc.join(", ")}`);const a=Math.max(.05,Math.min(1,Number.isFinite(r)?r:.25)),i=Math.max(.2,Math.min(e,Number.isFinite(n)?n:Math.min(1.2,e/3))),l=t.startsWith("zoom-in"),p=t.endsWith("start"),c=+(o*(1+a)).toFixed(4),s=+o.toFixed(4),h=l?p?+(o/(1+a)).toFixed(4):c:p?c:+(o/(1+a)).toFixed(4);return p?[{time:0,value:h,ease:"expo-out"},{time:+i.toFixed(3),value:s}]:[{time:+(e-i).toFixed(3),value:s,ease:"expo-in"},{time:+e.toFixed(3),value:h}]}const oC=Object.freeze({min:.1,max:1}),Ip=1,jf=Object.freeze(["color","number","bool","choice"]),Tf=Object.freeze(["chieu.blend","generator.py"]),Mr=Object.freeze({params:16,seconds:10,fps:[24,25,30,60],width:3840,height:3840,tags:24,sfx:4}),rC=Object.freeze(["draft","standard","film"]),A5=t=>`/vfx-presets/${t}/preview.webm`,nC=t=>`/vfx-presets/${t}/poster.jpg`,C5=/^[a-z0-9][a-z0-9-]{1,63}$/,Of=/^[a-z][a-zA-Z0-9_]{0,31}$/,d1=/^#[0-9a-fA-F]{6}$/,xe=(t,e)=>{throw Error(`${t}: ${e}`)},Br=t=>typeof t=="number"&&Number.isFinite(t),ln=(t,e)=>typeof t=="string"&&t.trim()&&t.length<=e;function j5(t,e){const o=`params[${e}]`;(!t||typeof t!="object")&&xe(o,"object"),Of.test(t.key??"")||xe(`${o}.key`,"a-z start, letters / digits / _ (≤ 32)"),jf.includes(t.type)||xe(`${o}.type`,jf.join(" | ")),(!ln(t.label,40)||!ln(t.labelEn,40))&&xe(`${o}.label`,"label + labelEn (1–40 chars)");const r={key:t.key,type:t.type,label:t.label.trim(),labelEn:t.labelEn.trim()};if(t.type==="color"&&(d1.test(t.default??"")||xe(`${o}.default`,"#RRGGBB"),r.default=t.default.toLowerCase()),t.type==="bool"&&(typeof t.default!="boolean"&&xe(`${o}.default`,"true | false"),r.default=t.default),t.type==="number"&&((!Br(t.min)||!Br(t.max)||!(t.min<t.max))&&xe(`${o}.min`,"min < max"),(!Br(t.default)||t.default<t.min||t.default>t.max)&&xe(`${o}.default`,`${t.min}..${t.max}`),Object.assign(r,{min:t.min,max:t.max,default:t.default,step:Br(t.step)&&t.step>0?t.step:(t.max-t.min)/100}),t.unit!==void 0&&(ln(t.unit,8)||xe(`${o}.unit`,"≤ 8 chars"),r.unit=t.unit)),t.type==="choice"){const n=Array.isArray(t.options)?t.options:[];(n.length<2||n.length>12||n.some(a=>!a||!Of.test(a.value??"")||!ln(a.label,40)||!ln(a.labelEn,40)))&&xe(`${o}.options`,"2–12 {value, label, labelEn}"),n.some(a=>a.value===t.default)||xe(`${o}.default`,"one of the options"),Object.assign(r,{options:n.map(a=>({value:a.value,label:a.label.trim(),labelEn:a.labelEn.trim()})),default:t.default})}return r}function T5(t,{allowScript:e=!1}={}){(!t||typeof t!="object"||Array.isArray(t))&&xe("chieu.json","object"),C5.test(t.id??"")||xe("id","lowercase a-z0-9-, 2–64 chars"),(t.version??1)!==Ip&&xe("version",`must be ${Ip}`),(!ln(t.name,60)||!ln(t.nameEn,60))&&xe("name","name + nameEn (1–60 chars)"),Tf.includes(t.entry)||xe("entry",Tf.join(" | ")),t.entry==="generator.py"&&!e&&xe("entry","a Plug-in Store move is a .blend (no Python runs from a partner's file)"),(!Br(t.duration)||t.duration<.2||t.duration>Mr.seconds)&&xe("duration",`0.2..${Mr.seconds} s`);const o=t.fps??30;Mr.fps.includes(o)||xe("fps",Mr.fps.join(" | "));const r=t.width??1920,n=t.height??1080;(!Number.isInteger(r)||!Number.isInteger(n)||r<64||n<64||r>Mr.width||n>Mr.height||r%2||n%2)&&xe("width","even 64..3840");const a=t.impact??0;(!Br(a)||a<0||a>t.duration)&&xe("impact","0..duration");const i=t.emit??[.5,.5];(!Array.isArray(i)||i.length!==2||!i.every(f=>Br(f)&&f>=0&&f<=1))&&xe("emit","[u, v] 0..1");const l=t.tags??[];(!Array.isArray(l)||l.length>Mr.tags||l.some(f=>!ln(f,30)))&&xe("tags",`≤ ${Mr.tags} short strings`);const p=t.sfx??[];(!Array.isArray(p)||p.length>Mr.sfx||p.some(f=>!f||!/^[a-z0-9-]{2,64}$/.test(f.id??"")||!Br(f.at)||f.at<0||f.at>t.duration))&&xe("sfx",`≤ ${Mr.sfx} {id, at}`);let c=null;if(t.shake!=null){const f=t.shake;(!Br(f.at)||!Br(f.duration)||!Br(f.intensity)||f.at<0||f.duration<=0||f.duration>2||f.intensity<=0||f.intensity>1)&&xe("shake","{at, duration ≤ 2, intensity 0..1}"),c={at:f.at,duration:f.duration,intensity:f.intensity}}const s=Array.isArray(t.params)?t.params:xe("params","array");s.length>Mr.params&&xe("params",`≤ ${Mr.params}`);const h=s.map(j5);return new Set(h.map(f=>f.key)).size!==h.length&&xe("params","keys must be unique"),{id:t.id,version:Ip,name:t.name.trim(),nameEn:t.nameEn.trim(),...ln(t.desc,200)?{desc:t.desc.trim()}:{},...ln(t.descEn,200)?{descEn:t.descEn.trim()}:{},entry:t.entry,duration:t.duration,fps:o,width:r,height:n,impact:a,emit:[i[0],i[1]],tags:l.map(f=>f.trim().toLowerCase()),sfx:p.map(f=>({id:f.id,at:f.at})),...c?{shake:c}:{},params:h}}function O5(t,e={}){if(e&&typeof e!="object")throw Error("params: object");const o=new Set(t.params.map(n=>n.key));for(const n of Object.keys(e||{}))if(!o.has(n))throw Error(`params.${n}: unknown — ${[...o].join(", ")}`);const r={};for(const n of t.params){const a=e?.[n.key];if(a==null){r[n.key]=n.default;continue}if(n.type==="color"){if(!d1.test(String(a)))throw Error(`params.${n.key}: #RRGGBB`);r[n.key]=String(a).toLowerCase()}else if(n.type==="bool"){if(typeof a!="boolean")throw Error(`params.${n.key}: true | false`);r[n.key]=a}else if(n.type==="choice"){if(!n.options.some(i=>i.value===a))throw Error(`params.${n.key}: ${n.options.map(i=>i.value).join(" | ")}`);r[n.key]=a}else{const i=Number(a);if(!Number.isFinite(i))throw Error(`params.${n.key}: number ${n.min}..${n.max}`);r[n.key]=Math.round(Math.min(n.max,Math.max(n.min,i))*1e4)/1e4}}return r}const P5=[{id:"huyet-loi-xoan",version:1,name:"Huyết Lôi Xoắn 3D",nameEn:"Crimson-Cyan 3D Vortex",desc:"7 dải plasma xoắn 3D đỏ huyết viền xanh điện, hồ quang lôi xoay, sương thể tích và tàn lửa",descEn:"Seven layered crimson-cyan UV-scrolling 3D plasma ribbons, swirling lightning arcs, volumetric mist and embers",entry:"generator.py",duration:3,fps:30,width:1920,height:1080,impact:.3,emit:[.5,.5],tags:["huyet loi","huyết lôi","xoắn","vortex","plasma","đỏ","xanh điện","crimson","cyan","donghua","wuxia","võ hiệp"],sfx:[{id:"sp-whoosh-transition-1",at:.1},{id:"sp-sub-hit-1",at:.3}],shake:{at:.3,duration:.45,intensity:.55},params:[{key:"color",type:"color",default:"#f20538",label:"Màu chính",labelEn:"Main colour"},{key:"color2",type:"color",default:"#0a94ff",label:"Màu phụ",labelEn:"Second colour"},{key:"speed",type:"number",min:.5,max:2,step:.05,default:1,label:"Tốc độ",labelEn:"Speed"},{key:"thickness",type:"number",min:.3,max:2.5,step:.05,default:1,label:"Độ dày",labelEn:"Thickness"},{key:"size",type:"number",min:.5,max:2,step:.05,default:1,label:"Độ lớn",labelEn:"Size"},{key:"glow",type:"number",min:0,max:1,step:.05,default:.8,label:"Phát sáng",labelEn:"Glow"},{key:"tilt",type:"number",min:-45,max:45,step:1,default:0,unit:"°",label:"Góc nghiêng",labelEn:"Tilt"},{key:"mist",type:"bool",default:!0,label:"Sương thể tích",labelEn:"Volumetric mist"}]},{id:"kiem-khi-bang-lam",version:1,name:"Kiếm Khí Băng Lam Trảm",nameEn:"Ice-Blue Sword Slash",desc:"3 tầng kiếm khí bán nguyệt băng lam quét 3D, tia băng điện, sương lạnh thể tích và tàn lửa",descEn:"Three sweeping 3D crescent ice-blue plasma sword-slash ribbons, frost lightning arcs, volumetric mist and sparks",entry:"generator.py",duration:2.2,fps:30,width:1920,height:1080,impact:.2,emit:[.5,.5],tags:["kiem khi","kiếm khí","băng lam","trảm","sword","slash","ice","cyan","donghua","wuxia","võ hiệp"],sfx:[{id:"sp-slice-1",at:.15},{id:"sp-impact-2",at:.2}],shake:{at:.2,duration:.3,intensity:.65},params:[{key:"color",type:"color",default:"#2edbff",label:"Màu chính",labelEn:"Main colour"},{key:"color2",type:"color",default:"#f2fcff",label:"Màu phụ",labelEn:"Second colour"},{key:"speed",type:"number",min:.5,max:2,step:.05,default:1,label:"Tốc độ",labelEn:"Speed"},{key:"thickness",type:"number",min:.3,max:2.5,step:.05,default:1,label:"Độ dày",labelEn:"Thickness"},{key:"size",type:"number",min:.5,max:2,step:.05,default:1,label:"Độ lớn",labelEn:"Size"},{key:"glow",type:"number",min:0,max:1,step:.05,default:.8,label:"Phát sáng",labelEn:"Glow"},{key:"tilt",type:"number",min:-45,max:45,step:1,default:0,unit:"°",label:"Góc nghiêng",labelEn:"Tilt"},{key:"mist",type:"bool",default:!0,label:"Sương thể tích",labelEn:"Volumetric mist"}]},{id:"thien-loi-giang-the",version:1,name:"Thiên Lôi Giáng Thế",nameEn:"Heavenly Lightning Strike",desc:"3 đợt thiên lôi giáng xuống mặt đất kèm 22 nhánh sét, vòng xung điện plasma, sương bão và tia lửa",descEn:"Three pulsing heavenly lightning strikes with 22 branching bolts, swirling electric ground plasma ring, storm mist and sparks",entry:"generator.py",duration:2.5,fps:30,width:1920,height:1080,impact:.2,emit:[.5,.85],tags:["thien loi","thiên lôi","sấm sét","tia chớp","lôi điện","lightning","strike","storm","thunder","donghua","wuxia","võ hiệp"],sfx:[{id:"thunder",at:.15},{id:"sp-impact-1",at:.2},{id:"sp-sub-hit-3",at:.2}],shake:{at:.2,duration:.5,intensity:.85},params:[{key:"color",type:"color",default:"#4ddbff",label:"Màu chính",labelEn:"Main colour"},{key:"color2",type:"color",default:"#e8fcff",label:"Màu phụ",labelEn:"Second colour"},{key:"speed",type:"number",min:.5,max:2,step:.05,default:1,label:"Tốc độ",labelEn:"Speed"},{key:"thickness",type:"number",min:.3,max:2.5,step:.05,default:1,label:"Độ dày",labelEn:"Thickness"},{key:"size",type:"number",min:.5,max:2,step:.05,default:1,label:"Độ lớn",labelEn:"Size"},{key:"glow",type:"number",min:0,max:1,step:.05,default:.8,label:"Phát sáng",labelEn:"Glow"},{key:"tilt",type:"number",min:-30,max:30,step:1,default:0,unit:"°",label:"Góc nghiêng",labelEn:"Tilt"},{key:"mist",type:"bool",default:!0,label:"Sương thể tích",labelEn:"Volumetric mist"}]},{id:"kim-quang-shockwave",version:1,name:"Sóng Xung Kích Kim Quang",nameEn:"Golden Shockwave",desc:"Chớp lõi vàng, vòng sóng ánh kim bung rộng, tia lửa văng và bụi sáng",descEn:"A golden core flash, a ring of golden light bursting outward, flying sparks and glowing dust",entry:"generator.py",duration:1.4,fps:30,width:1920,height:1080,impact:.05,emit:[.5,.56],tags:["kim quang","shockwave","sóng xung kích","vàng","nổ","golden","impact","wuxia","võ hiệp"],sfx:[{id:"sp-impact-3",at:.05},{id:"sp-sub-hit-2",at:.05}],shake:{at:.05,duration:.35,intensity:.6},params:[{key:"color",type:"color",default:"#ffc83a",label:"Màu chính",labelEn:"Main colour"},{key:"color2",type:"color",default:"#fff4cf",label:"Màu phụ",labelEn:"Second colour"},{key:"speed",type:"number",min:.5,max:2,step:.05,default:1,label:"Tốc độ",labelEn:"Speed"},{key:"thickness",type:"number",min:.3,max:2.5,step:.05,default:1,label:"Độ dày",labelEn:"Thickness"},{key:"size",type:"number",min:.5,max:2,step:.05,default:1,label:"Độ lớn",labelEn:"Size"},{key:"glow",type:"number",min:0,max:1,step:.05,default:.8,label:"Phát sáng",labelEn:"Glow"},{key:"tilt",type:"number",min:10,max:85,step:1,default:62,unit:"°",label:"Góc nghiêng",labelEn:"Tilt"},{key:"mist",type:"bool",default:!0,label:"Sương thể tích",labelEn:"Volumetric mist"}]}],z5=Object.freeze(P5.map(t=>Object.freeze(T5(t,{allowScript:!0})))),L5=t=>z5.find(e=>e.id===t)??null,ze=Object.freeze({points:21,slots:2,maxSeconds:20,maxFrames:600,fps:[15,30]}),ol=Object.freeze({wrist:0,thumb:4,index:8,middle:12,ring:16,pinky:20,indexBase:5,middleBase:9}),uc=Object.freeze(["pinch","index","thumb","middle","ring","pinky","wrist","palm"]),Du=Object.freeze(["any","right","left"]),dc=1+ze.points*4,Bu=-.5,_u=2,uo=t=>Math.round(t*1e4)/1e4,ws="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",rl=Object.fromEntries([...ws].map((t,e)=>[t,e]));function Pf(t){let e="";for(let o=0;o<t.length;o+=3){const r=t[o],n=t[o+1]??0,a=t[o+2]??0,i=r<<16|n<<8|a;e+=ws[i>>18&63]+ws[i>>12&63]+(o+1<t.length?ws[i>>6&63]:"=")+(o+2<t.length?ws[i&63]:"=")}return e}function zf(t){const e=t.replace(/=+$/,""),o=new Uint8Array(Math.floor(e.length*3/4));let r=0;for(let n=0;n<e.length;n+=4){const a=rl[e[n]]<<18|rl[e[n+1]]<<12|(rl[e[n+2]]??0)<<6|(rl[e[n+3]]??0);r<o.length&&(o[r++]=a>>16&255),r<o.length&&(o[r++]=a>>8&255),r<o.length&&(o[r++]=a&255)}return o}function aC({mw:t,mh:e,fps:o,s0:r,frames:n}){const a=Math.min(ze.maxFrames,n.length),i=new Uint8Array(a*ze.slots*dc),l=new DataView(i.buffer);for(let c=0;c<a;c++)for(let s=0;s<ze.slots;s++){const h=n[c]?.[s],f=(c*ze.slots+s)*dc;if(!(!h?.lm||h.lm.length<ze.points)){i[f]=Math.max(1,Math.min(255,Math.round((Number.isFinite(h.score)?h.score:1)*255)));for(let m=0;m<ze.points;m++)for(let y=0;y<2;y++){const $=Math.max(0,Math.min(65535,Math.round((h.lm[m][y]-Bu)/_u*65535)));l.setUint16(f+1+(m*2+y)*2,$,!0)}}}let p=null;if(n.slice(0,a).some(c=>c?.some(s=>Array.isArray(s?.edge)))){const c=new Int8Array(a*ze.slots*Xr);for(let s=0;s<a;s++)for(let h=0;h<ze.slots;h++){const f=n[s]?.[h]?.edge;if(Array.isArray(f))for(let m=0;m<Xr;m++)c[(s*ze.slots+h)*Xr+m]=Math.max(-127,Math.min(127,Math.round((f[m]||0)*wi.unit)))}p=Pf(new Uint8Array(c.buffer))}return N5({v:1,mw:Math.round(t),mh:Math.round(e),fps:o,s0:uo(r),n:a,data:Pf(i),...p?{edge:p}:{}})}function N5(t){if(!t||typeof t!="object"||Array.isArray(t)||Object.keys(t).some(e=>!["v","mw","mh","fps","s0","n","data","edge"].includes(e))||t.v!==1||!Number.isInteger(t.mw)||!Number.isInteger(t.mh)||t.mw<2||t.mh<2||t.mw>8192||t.mh>8192||!ze.fps.includes(t.fps)||!Number.isFinite(t.s0)||t.s0<0||t.s0>36e3||!Number.isInteger(t.n)||t.n<1||t.n>ze.maxFrames||typeof t.data!="string"||!/^[A-Za-z0-9+/]*={0,2}$/.test(t.data)||Math.floor(t.data.replace(/=+$/,"").length*3/4)!==t.n*ze.slots*dc||t.edge!==void 0&&(typeof t.edge!="string"||!/^[A-Za-z0-9+/]*={0,2}$/.test(t.edge)||Math.floor(t.edge.replace(/=+$/,"").length*3/4)!==t.n*ze.slots*Xr))throw Error("Invalid hand track");return t}const as=new Map;function Vs(t){const e=`${t.s0}|${t.fps}|${t.data.length}|${t.data.slice(0,64)}|${t.data.slice(-64)}|${t.edge?.length??0}|${t.edge?.slice(-64)??""}`,o=as.get(e);if(o)return o;const r=zf(t.data),n=new DataView(r.buffer),a=[],i=t.edge?new Int8Array(zf(t.edge).buffer):null;for(let p=0;p<t.n;p++){const c=[];for(let s=0;s<ze.slots;s++){const h=(p*ze.slots+s)*dc;if(!r[h]){c.push(null);continue}const f=[];for(let y=0;y<ze.points;y++)f.push([Bu+n.getUint16(h+1+y*4,!0)/65535*_u,Bu+n.getUint16(h+3+y*4,!0)/65535*_u]);const m=i?Array.from(i.subarray((p*ze.slots+s)*Xr,(p*ze.slots+s+1)*Xr),y=>y/wi.unit):null;c.push({lm:f,score:r[h]/255,...m?{edge:m}:{}})}a.push(c)}const l={fps:t.fps,s0:t.s0,n:t.n,mw:t.mw,mh:t.mh,frames:a};return as.size>16&&as.delete(as.keys().next().value),as.set(e,l),l}const hc=(t,e)=>(t.inPoint||0)+e*(t.playbackRate||1),h1=(t,e)=>(e-(t.inPoint||0))/(t.playbackRate||1);function Ap(t,e,o){const r=t?.hands;if(!r)return!1;const n=hc(t,e),a=hc(t,e+o),i=r.s0+(r.n-1)/r.fps;return n>=r.s0-1.5/r.fps&&a<=i+1.5/r.fps}const f1=(t,e,o)=>[t[0]+(e[0]-t[0])*o,t[1]+(e[1]-t[1])*o];function fc(t,e,o){const r=(e-t.s0)*t.fps;if(r<-.5||r>t.n-.5)return null;const n=Math.max(0,Math.min(t.n-1,Math.floor(r))),a=Math.min(t.n-1,n+1),i=Math.max(0,Math.min(1,r-n)),l=t.frames[n][o],p=t.frames[a][o];if(l&&p)return l.lm.map((s,h)=>f1(s,p.lm[h],i));const c=i<.5?l:p;return c?c.lm:null}function F5(t,e,o="any"){return o==="right"?0:o==="left"?1:fc(t,e,0)?0:fc(t,e,1)?1:0}const m1=(t,e,o)=>Math.hypot((t[0][0]-t[9][0])*e,(t[0][1]-t[9][1])*o);function bi(t,e="index"){if(e==="pinch")return f1(t[ol.thumb],t[ol.index],.5);if(e==="palm"){const o=[0,5,9,13,17];return[o.reduce((r,n)=>r+t[n][0],0)/5,o.reduce((r,n)=>r+t[n][1],0)/5]}return t[ol[e]??ol.index]}const Gn=Object.freeze({on:.3,off:.46,hold:2,minHold:.2}),Xa=Object.freeze({fast:2.2,back:1,cos:-.25,gap:.35,window:3});function R5(t){const e=[];for(let o=0;o<ze.slots;o++){let r=!1,n=!1,a=0,i=0,l=-1/0;const p=[],c=[],s=[];for(let f=0;f<t.n;f++){const m=t.frames[f][o];if(!m){p.push(null),c.push(null),s.push(!1);continue}const y=m1(m.lm,t.mw,t.mh)||1;p.push(Math.hypot((m.lm[4][0]-m.lm[8][0])*t.mw,(m.lm[4][1]-m.lm[8][1])*t.mh)/y),c.push([m.lm[8][0]*t.mw/y,m.lm[8][1]*t.mh/y,Math.hypot((m.lm[8][0]-m.lm[5][0])*t.mw,(m.lm[8][1]-m.lm[5][1])*t.mh)/y]),s.push(!0)}const h=f=>t.s0+f/t.fps;for(let f=0;f<t.n;f++){const m=t.frames[f][o],y=p[f];if(!m){if(i++,r&&i>=3){const N=t.frames[f-i]?.[o],F=N?bi(N.lm,"pinch"):[.5,.5];e.push({type:"release",s:uo(h(f-i)),slot:o,u:uo(F[0]),v:uo(F[1])}),r=!1}a=0;continue}if(i=0,r){if(a=y>Gn.off?a+1:0,a>=Gn.hold){const N=f-Gn.hold+1,F=bi(t.frames[N][o].lm,"pinch");e.push({type:"release",s:uo(h(N)),slot:o,u:uo(F[0]),v:uo(F[1])}),r=!1,a=0}}else if(y>Gn.off&&(n=!0),a=n&&y<Gn.on?a+1:0,a>=Gn.hold){const N=f-Gn.hold+1,F=bi(t.frames[N][o].lm,"pinch");e.push({type:"pinch",s:uo(h(N)),slot:o,u:uo(F[0]),v:uo(F[1])}),r=!0,n=!1,a=0}const $=Math.max(1,Math.round(Xa.window*t.fps/30)),x=f-$,E=f+$;if(r||x<0||E>=t.n||!s[x]||!s[E]||!c[f]||p[f]<Gn.off||c[f][2]<.55||h(f)-l<Xa.gap)continue;const v=$/t.fps,S=[(c[f][0]-c[x][0])/v,(c[f][1]-c[x][1])/v],k=[(c[E][0]-c[f][0])/v,(c[E][1]-c[f][1])/v],b=Math.hypot(...S),A=Math.hypot(...k);if(b<Xa.fast||A<Xa.back||(S[0]*k[0]+S[1]*k[1])/(b*A)>Xa.cos)continue;let P=f,C=-1/0;for(let N=x;N<=E;N++)if(c[N]){const F=c[N][0]*S[0]+c[N][1]*S[1];F>C&&(C=F,P=N)}if(h(P)-l<Xa.gap)continue;const z=t.frames[P][o].lm[8];e.push({type:"tap",s:uo(h(P)),slot:o,u:uo(z[0]),v:uo(z[1])}),l=h(P)}if(r){const f=[...t.frames].reverse().find(y=>y[o])?.[o],m=f?bi(f.lm,"pinch"):[.5,.5];e.push({type:"release",s:uo(t.s0+(t.n-1)/t.fps),slot:o,u:uo(m[0]),v:uo(m[1])})}}return e.sort((o,r)=>o.s-r.s||(o.type==="release"?-1:1))}const ui=[[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16],[17,18,19,20]],Gu=[2.4,1.6,.8],Xr=ui.length*9+4+2*Gu.length,iC=Object.freeze([0,1,2,3,4,5,Xr-4,Xr-3,Xr-2,Xr-1]);function g1(t,e,o,{width:r=.17,arm:n=3.2}={}){const a=t.map(([z,N])=>[z*e,N*o]),i=Math.hypot(a[0][0]-a[9][0],a[0][1]-a[9][1])||1,l=(z,N)=>[z[0]-N[0],z[1]-N[1]],p=(z,N)=>[z[0]+N[0],z[1]+N[1]],c=(z,N)=>[z[0]*N,z[1]*N],s=z=>{const N=Math.hypot(z[0],z[1])||1;return[z[0]/N,z[1]/N]},h=z=>[-z[1],z[0]],f=(z,N)=>z[0]*N[0]+z[1]*N[1],m=[],y=(z,N,F,K=!0)=>m.push({anchor:z,dir:N,dist:F,snap:K}),$=s(l(a[0],a[9])),x=h($),E=.36*i,v=f(x,l(a[1],a[0]))>0?1:-1,S=c(x,v),k=c(x,-v),b=p(a[0],c($,n*i)),A=z=>p(a[0],c($,z*i)),I=z=>E*(1+.1*z);y(b,k,I(n),!1),y(b,S,I(n),!1);for(const z of Gu)y(A(z),S,I(z));y(a[0],S,E);const P=p(a[0],c(S,E)),C=p(a[0],c(k,E));for(let z=0;z<ui.length;z++){const N=ui[z],F=N.map(Z=>a[Z]),K=z?a[ui[z-1][0]]:P,_=z<ui.length-1?a[ui[z+1][0]]:C,q=s(l(F[3],F[0])),U=h(q),rt=f(U,l(K,F[0]))-f(U,l(_,F[0]))>=0?1:-1,ot=c(U,rt),G=c(ot,-1),J=Z=>r*(z===0?1.15:1)*(1-.18*Z/3)*i/2;for(let Z=0;Z<3;Z++)y(F[Z],ot,J(Z));y(F[3],ot,J(3)),y(F[3],s(l(F[3],F[2])),J(3)*1.2),y(F[3],G,J(3));for(let Z=2;Z>=0;Z--)y(F[Z],G,J(Z))}y(a[0],k,E);for(const z of[...Gu].reverse())y(A(z),k,I(z));return{pts:m,S:i}}function D5(t,e,o,{width:r=.17,arm:n=3.2,edge:a=null,scale:i=1,grow:l=0}={}){const{pts:p,S:c}=g1(t,e,o,{width:r,arm:n});return p.map((s,h)=>{const f=Math.max(0,s.dist*i+(a?.[h]??0)*c+l*c);return[uo((s.anchor[0]+s.dir[0]*f)/e),uo((s.anchor[1]+s.dir[1]*f)/o)]})}const wi=Object.freeze({in:.6,out:.1,unit:200});function sC(t,e,o,r,n={}){const{pts:a,S:i}=g1(t,e,o,n),l=t.map(([S,k])=>[S*e,k*o]),p=(S,k)=>{let b=0,A=0,I=0;for(let P=-1;P<=1;P++)for(let C=-1;C<=1;C++){const z=r(Math.round(S+C),Math.round(k+P));b+=z[0],A+=z[1],I+=z[2]}return[b/9,A/9,I/9]},c=(S,k)=>(S[0]-k[0])**2+(S[1]-k[1])**2+(S[2]-k[2])**2,s=(S,k)=>Math.min(...k.map(b=>c(S,b))),h=S=>[0,1,2].map(k=>S.map(b=>b[k]).sort((b,A)=>b-A)[S.length>>1]);let f=[[1,2],[2,3],[5,6],[6,7],[9,10],[10,11],[13,14],[14,15],[17,18],[18,19]].map(([S,k])=>p((l[S][0]+l[k][0])/2,(l[S][1]+l[k][1])/2));const m=[0,5,9,13,17].reduce((S,k)=>[S[0]+l[k][0]/5,S[1]+l[k][1]/5],[0,0]);f.push(p(m[0],m[1]));const y=h(f);if(f=f.filter(S=>c(S,y)<55**2),f.length<4)return null;let $=a.filter(S=>S.snap).map(S=>p(S.anchor[0]+S.dir[0]*(S.dist+.3*i),S.anchor[1]+S.dir[1]*(S.dist+.3*i)));const x=Math.sqrt(Math.max(...f.map(S=>c(S,y))))+12;if($=$.filter(S=>Math.sqrt(s(S,f))>x),$.length<4)return null;const E=S=>s(S,f)<s(S,$),v=Math.max(.5,i/60);return a.map(S=>{if(!S.snap)return 0;const k=P=>p(S.anchor[0]+S.dir[0]*P,S.anchor[1]+S.dir[1]*P);if(!E(k(S.dist*.3)))return 0;const b=S.dist*(1-wi.in),A=S.dist+wi.out*i;let I=Math.max(S.dist*.3,b);for(;I<A&&E(k(I+v));)I+=v;return Math.round((Math.max(b,I+v/2)-S.dist)/i*wi.unit)/wi.unit})}const Lo=Object.freeze({work:640,fps:30,longFps:15,long:20,maxFrames:600,seeds:240,minPoints:6,points:200,smooth:.3,smoothFrames:4,smoothTolPx:.35,keyTolPx:.05,max:6,regionPoints:[3,64],size:[.005,20],glue:{text:1.6,plane:1,null:.3,model:1}}),Ku=Object.freeze(["x","y","z","rx","ry","rz","s"]),y1={x:0,y:0,z:0,rx:0,ry:0,rz:0,s:1},zo=t=>Math.round(t*1e6)/1e6,Po=t=>Math.round(t*1e3)/1e3,No=(t,e)=>[t[0]-e[0],t[1]-e[1],t[2]-e[2]],wr=(t,e)=>[t[0]+e[0],t[1]+e[1],t[2]+e[2]],Le=(t,e)=>[t[0]*e,t[1]*e,t[2]*e],yr=(t,e)=>t[0]*e[0]+t[1]*e[1]+t[2]*e[2],Pd=(t,e)=>[t[1]*e[2]-t[2]*e[1],t[2]*e[0]-t[0]*e[2],t[0]*e[1]-t[1]*e[0]],_a=t=>{const e=Math.hypot(...t)||1;return Le(t,1/e)},lr=(t,e)=>[yr(t[0],e),yr(t[1],e),yr(t[2],e)],An=t=>[0,1,2].map(e=>[t[0][e],t[1][e],t[2][e]]),Ho=(t,e)=>t.map(o=>[0,1,2].map(r=>o[0]*e[0][r]+o[1]*e[1][r]+o[2]*e[2][r])),b1=()=>[[1,0,0],[0,1,0],[0,0,1]],nl=[[1,0,0],[0,-1,0],[0,0,-1]],Vu=t=>[t[0],-t[1],-t[2]],al=t=>{if(!t.length)return 0;const e=[...t].sort((o,r)=>o-r);return e[e.length>>1]},pn=Math.PI/180,B5=t=>[[1,0,0],[0,Math.cos(t),-Math.sin(t)],[0,Math.sin(t),Math.cos(t)]],_5=t=>[[Math.cos(t),0,Math.sin(t)],[0,1,0],[-Math.sin(t),0,Math.cos(t)]],G5=t=>[[Math.cos(t),-Math.sin(t),0],[Math.sin(t),Math.cos(t),0],[0,0,1]],w1=(t,e,o)=>Ho(Ho(B5(t*pn),_5(e*pn)),G5(o*pn));function k1(t,e,o){let r=!1;for(let n=0,a=t.length-1;n<t.length;a=n++){const[i,l]=t[n],[p,c]=t[a];l>o!=c>o&&e<(p-i)*(o-l)/(c-l)+i&&(r=!r)}return r}function K5(t){const e=[...t].sort((a,i)=>a[0]-i[0]||a[1]-i[1]);if(e.length<3)return e;const o=(a,i,l)=>(i[0]-a[0])*(l[1]-a[1])-(i[1]-a[1])*(l[0]-a[0]),r=[],n=[];for(const a of e){for(;r.length>=2&&o(r.at(-2),r.at(-1),a)<=0;)r.pop();r.push(a)}for(const a of[...e].reverse()){for(;n.length>=2&&o(n.at(-2),n.at(-1),a)<=0;)n.pop();n.push(a)}return[...r.slice(0,-1),...n.slice(0,-1)]}function V5(t,e,o,r){if(k1(t,e,o))return!0;for(let n=0,a=t.length-1;n<t.length;a=n++){const[i,l]=t[a],[p,c]=t[n],s=p-i,h=c-l,f=s*s+h*h,m=f?Math.max(0,Math.min(1,((e-i)*s+(o-l)*h)/f)):0;if(Math.hypot(i+m*s-e,l+m*h-o)<=r)return!0}return!1}function W5(t,e,o,{n:r=Lo.seeds,minScore:n=1e-4,taken:a=[]}={}){const{w:i,h:l,data:p}=t,c=4,s=Math.max(c,Math.floor(o[0])),h=Math.max(c,Math.floor(o[1])),f=Math.min(i-c-1,Math.ceil(o[2])),m=Math.min(l-c-1,Math.ceil(o[3]));if(!(f>s&&m>h))return[];let y=0;for(let v=h;v<=m;v+=2)for(let S=s;S<=f;S+=2)e(S,v)&&(y+=4);const $=Math.max(5,Math.sqrt(y/Math.max(1,r))),x=[],E=(v,S)=>a.some(k=>Math.abs(k[0]-v)<$*.7&&Math.abs(k[1]-S)<$*.7);for(let v=h;v<=m;v+=$)for(let S=s;S<=f;S+=$){let k=null;for(let b=Math.round(v);b<Math.min(m+1,v+$);b++)for(let A=Math.round(S);A<Math.min(f+1,S+$);A++){if(!e(A,b))continue;let I=0,P=0,C=0;for(let N=-2;N<=2;N++)for(let F=-2;F<=2;F++){const K=(b+N)*i+A+F,_=(p[K+1]-p[K-1])/2,q=(p[K+i]-p[K-i])/2;I+=_*_,P+=_*q,C+=q*q}const z=(I+C)/2-Math.sqrt(((I-C)/2)**2+P*P);z>n&&(!k||z>k[2])&&(k=[A,b,z])}k&&!E(k[0],k[1])&&x.push([k[0],k[1]])}return x}const X5=(t,e,o,r,n)=>{const a=lr(t.R,No(e,t.C));return a[2]>-1e-6?null:[r+o*a[0]/-a[2],n-o*a[1]/-a[2]]},$a=(t,e,o,r,n,a)=>{const i=X5(t,e,r,n,a);return i?Math.hypot(i[0]-o[0],i[1]-o[1]):1e3},Lf=(t,e,o,r,n,a)=>wr(t.C,lr(An(t.R),[(e[0]-n)/r*o,-(e[1]-a)/r*o,-o]));function H5(t,e){const o=Math.cos(e),r=Math.sin(e),n=1-o;return[[o+t[0]*t[0]*n,t[0]*t[1]*n-t[2]*r,t[0]*t[2]*n+t[1]*r],[t[1]*t[0]*n+t[2]*r,o+t[1]*t[1]*n,t[1]*t[2]*n-t[0]*r],[t[2]*t[0]*n-t[1]*r,t[2]*t[1]*n+t[0]*r,o+t[2]*t[2]*n]]}function U5(t,e){if(e.length<4)return null;const o=Le(e.reduce((y,$)=>wr(y,$),[0,0,0]),1/e.length),r=[[0,0,0],[0,0,0],[0,0,0]];for(const y of e){const $=No(y,o);for(let x=0;x<3;x++)for(let E=0;E<3;E++)r[x][E]+=$[x]*$[E]}const{values:n,vectors:a}=Ls(r),i=[0,1,2].reduce((y,$)=>n[$]<n[y]?$:y,0),l=lr(t.R,No(o,t.C)),p=_a(l),c=lr(t.R,a.map(y=>y[i])),s=No(Le(p,2*yr(c,p)),c),h=Pd(c,s),f=Math.hypot(...h);if(f<Math.sin(.5*pn))return null;const m=Ho(H5(Le(h,1/f),Math.atan2(f,yr(c,s))),t.R);return{R:m,C:No(o,lr(An(m),l))}}function Y5(t){const e=t.length,o=t.map(a=>[...a]),r=Array.from({length:e},(a,i)=>Array.from({length:e},(l,p)=>i===p?1:0));for(let a=0;a<60;a++){let i=0;for(let l=0;l<e;l++)for(let p=l+1;p<e;p++)i+=o[l][p]**2;if(i<1e-24)break;for(let l=0;l<e;l++)for(let p=l+1;p<e;p++){if(Math.abs(o[l][p])<1e-300)continue;const c=(o[p][p]-o[l][l])/(2*o[l][p]),s=Math.sign(c||1)/(Math.abs(c)+Math.sqrt(c*c+1)),h=1/Math.sqrt(s*s+1),f=s*h;for(let m=0;m<e;m++){const y=o[m][l],$=o[m][p];o[m][l]=h*y-f*$,o[m][p]=f*y+h*$}for(let m=0;m<e;m++){const y=o[l][m],$=o[p][m];o[l][m]=h*y-f*$,o[p][m]=f*y+h*$}for(let m=0;m<e;m++){const y=r[m][l],$=r[m][p];r[m][l]=h*y-f*$,r[m][p]=f*y+h*$}}}let n=0;for(let a=1;a<e;a++)o[a][a]<o[n][n]&&(n=a);return r.map(a=>a[n])}function q5(t,e){if(t.length<8)return[];const o=Array.from({length:9},()=>new Array(9).fill(0));for(let b=0;b<t.length;b++){const[A,I]=t[b],[P,C]=e[b];for(const z of[[A,I,1,0,0,0,-P*A,-P*I,-P],[0,0,0,A,I,1,-C*A,-C*I,-C]])for(let N=0;N<9;N++)for(let F=0;F<9;F++)o[N][F]+=z[N]*z[F]}const r=Y5(o),n=[[r[0],r[1],r[2]],[r[3],r[4],r[5]],[r[6],r[7],r[8]]],{values:a}=Ls(Ho(An(n),n)),i=Math.sqrt([...a].sort((b,A)=>b-A)[1]);let l=n.map(b=>b.map(A=>A/i)),p=0;for(let b=0;b<t.length;b++)p+=yr([e[b][0],e[b][1],1],lr(l,[t[b][0],t[b][1],1]))>0?1:-1;p<0&&(l=l.map(b=>b.map(A=>-A)));const{values:c,vectors:s}=Ls(Ho(An(l),l)),h=[0,1,2].sort((b,A)=>c[A]-c[b]),f=c[h[0]],m=c[h[2]],y=s.map(b=>b[h[0]]),$=s.map(b=>b[h[1]]),x=s.map(b=>b[h[2]]);if(!(f-m>1e-9))return[];const E=Math.sqrt(f-m),v=Math.sqrt(Math.max(0,1-m))/E,S=Math.sqrt(Math.max(0,f-1))/E,k=[];for(const b of[wr(Le(y,v),Le(x,S)),No(Le(y,v),Le(x,S))]){let A=_a(Pd($,b));A[2]>0&&(A=Le(A,-1)),k.push(A)}return k}function Z5(t,e,{iters:o=80,thr:r=1}={}){const n=t.length;if(n<8)return null;let a=5;const i=()=>(a=a*1664525+1013904223>>>0)/2**32,l=m=>{const y=[[0,0,0],[0,0,0],[0,0,0]],$=[0,0,0],x=[0,0,0];for(const S of m){const k=[t[S][0],t[S][1],1];for(let b=0;b<3;b++){$[b]+=k[b]*e[S][0],x[b]+=k[b]*e[S][1];for(let A=0;A<3;A++)y[b][A]+=k[b]*k[A]}}const E=Nf(y,$),v=Nf(y,x);return E&&v?[E,v]:null},p=m=>t.map((y,$)=>Math.hypot(m[0][0]*y[0]+m[0][1]*y[1]+m[0][2]-e[$][0],m[1][0]*y[0]+m[1][1]*y[1]+m[1][2]-e[$][1]));let c=null,s=-1;for(let m=0;m<o;m++){const y=[Math.floor(i()*n),Math.floor(i()*n),Math.floor(i()*n)];if(y[0]===y[1]||y[1]===y[2]||y[0]===y[2])continue;const $=l(y);if(!$)continue;const x=p($).filter(E=>E<r).length;x>s&&(s=x,c=$)}if(!c)return null;const h=p(c),f=l(h.map((m,y)=>m<r*1.5?y:-1).filter(m=>m>=0))??c;return p(f)}function J5(t){if(t.length<8)return null;const e=Le(t.reduce((i,l)=>wr(i,l),[0,0,0]),1/t.length),o=[[0,0,0],[0,0,0],[0,0,0]];for(const i of t){const l=No(i,e);for(let p=0;p<3;p++)for(let c=0;c<3;c++)o[p][c]+=l[p]*l[c]}const{values:r,vectors:n}=Ls(o),a=[0,1,2].sort((i,l)=>r[i]-r[l]);return r[a[0]]<.15**2*r[a[1]]?{O:e,n:_a(n.map(i=>i[a[0]]))}:null}function Q5(t,e,{w:o,h:r,f:n,region:a,follow:i,seed:l,onProgress:p=null,seeds:c=Lo.seeds}){const s=o/2,h=r/2,f=Lo.minPoints,m=Array.from({length:t},()=>new Map),y=new Map,$=new Map,x=new Map,E=new Map,v=new Array(t).fill(null);let S=0,k=0;const b=ot=>[Math.min(...ot.map(G=>G[0])),Math.min(...ot.map(G=>G[1])),Math.max(...ot.map(G=>G[0])),Math.max(...ot.map(G=>G[1]))];v[e]={R:b1(),C:[0,0,0]};for(const ot of l(e,(G,J)=>k1(a,G,J),[],b(a))){const G=S++;m[e].set(G,ot),y.set(G,Lf(v[e],ot,1,n,s,h)),$.set(G,e)}if(y.size<10)throw Error("FLAT");const A=(ot,G)=>y.has(ot)&&($.get(ot)===e||Math.abs(G-$.get(ot))>=3),I=ot=>{y.delete(ot);for(const G of m)G.delete(ot)},P=(ot,G)=>{const J=[...m[ot]].filter(([Z])=>A(Z,ot)).map(([Z,at])=>[Math.hypot(at[0]-G[0],at[1]-G[1]),-lr(v[ot].R,No(y.get(Z),v[ot].C))[2]]).sort((Z,at)=>Z[0]-at[0]).slice(0,6);return J.length?al(J.map(Z=>Z[1])):1},C=()=>{const ot=v.map((J,Z)=>J&&Z!==e?Z:-1).filter(J=>J>=0),G=Math.max(1,Math.ceil(ot.length/20));Xs(v,y,m,[e,...ot.filter((J,Z)=>Z%G===0||Z===ot.length-1)],n,s,h,4)},z=(ot,G,J=!0)=>{const Z=ut=>ut&&ut.R.flat().every(Number.isFinite)&&ut.C.every(Number.isFinite),at=ut=>{let gt;try{gt=Mb(ot,ut,n,s,h,1).pose}catch{return null}if(!Z(gt))return null;const xt=ot.map(u=>$a(gt,u.X,u.px,n,s,h));return{pose:gt,res:xt,e:xt.reduce((u,st)=>u+Math.min(st,3),0)/xt.length}};let D=at(G);const H=J&&U5(G,ot.map(ut=>ut.X));if(Z(H)){const ut=at(H);ut&&(!D||ut.e<D.e*.98)&&(D=ut)}return D??{pose:G,res:ot.map(ut=>$a(G,ut.X,ut.px,n,s,h)),e:1/0}},N=ot=>{let G=new Map([...m[e]].filter(([Z])=>y.has(Z))),J=0;for(let Z=e+ot;Z>=0&&Z<t;Z+=ot){const at=[...G.keys()],D=i(Z-ot,Z,at.map(st=>G.get(st))),H=new Map;at.forEach((st,V)=>{D[V]&&H.set(st,D[V])});{const st=[...H.keys()],V=st.map(T=>G.get(T)),d=st.map(T=>H.get(T)),w=Z5(V,d);if(w){const T=Math.max(1,3*al(w));st.forEach((j,O)=>{const L=w[O]>T?(E.get(j)??0)+1:0;E.set(j,L),L>=2&&(I(j),H.delete(j))})}}const ut=()=>{const st=[...H].filter(([d])=>A(d,Z));if(st.length<f)return null;const V=st.map(([d,w])=>({X:y.get(d),px:w}));return{...z(V,v[Z-ot],Z%3===0),use:st}};let gt=ut();if(!gt)break;const xt=Math.max(1.5,3*al(gt.res));let u=0;for(const[st,V]of H){const T=$a(gt.pose,y.get(st),V,n,s,h)>(A(st,Z)?xt:3*xt+4)?(x.get(st)??0)+1:0;x.set(st,T),T>=2&&(I(st),H.delete(st),u++)}if(u&&(gt=ut(),!gt))break;v[Z]=gt.pose;for(const[st,V]of H)m[Z].set(st,V);if(G=H,G.size<c*.7){const st=K5([...G].filter(([V])=>A(V,Z)).map(([,V])=>V));if(st.length>=3){const V=Math.max(3,o*.012);for(const d of l(Z,(w,T)=>V5(st,w,T,V),[...G.values()],b(st).map((w,T)=>w+(T<2?-V:V)))){const w=S++;y.set(w,Lf(v[Z],d,P(Z,d),n,s,h)),$.set(w,Z),G.set(w,d),m[Z].set(w,d)}}}++J>=15&&(J=0,C()),p?.(++k/t)}};N(1),N(-1);const F=v.map((ot,G)=>ot?G:-1).filter(ot=>ot>=0),K=Math.max(1,Math.ceil(F.length/36)),_=[e,...F.filter((ot,G)=>ot!==e&&(G%K===0||G===F.length-1))],q=(ot=!1,G=!1)=>{for(const J of F){if(!ot&&_.includes(J))continue;const Z=[];for(const[at,D]of m[J])y.has(at)&&Z.push({X:y.get(at),px:D});Z.length>=f&&J!==e&&(v[J]=z(Z,v[J],G).pose)}},U=()=>{let ot=0;for(const G of _)for(const[J,Z]of m[G])if(y.has(J)){const at=$a(v[G],y.get(J),Z,n,s,h);ot+=at<=2?at*at:4*at-4}return ot},rt=J5([...m[e].keys()].filter(ot=>y.has(ot)).map(ot=>y.get(ot)));if(rt){const ot=()=>({P:v.map(u=>u&&{R:u.R.map(st=>[...st]),C:[...u.C]}),X:new Map([...y].map(([u,st])=>[u,[...st]]))}),G=u=>{u.P.forEach((st,V)=>{v[V]=st&&{R:st.R.map(d=>[...d]),C:[...st.C]}}),y.clear();for(const[st,V]of u.X)y.set(st,[...V])},J=u=>{let st=0;for(const V of u)for(const[d,w]of m[V])if(y.has(d)){const T=$a(v[V],y.get(d),w,n,s,h);st+=T<=2?T*T:4*T-4}return st},Z=()=>{for(const u of[1,-1])for(let st=e+u;v[st];st+=u){const V=[];for(const[d,w]of m[st])y.has(d)&&V.push({X:y.get(d),px:w});v[st]=V.length>=f?z(V,v[st-u],!0).pose:{...v[st-u]}}},at=u=>[...m[e].keys()].filter(st=>m[u].has(st)&&y.has(st)),H=[F.find(u=>at(u).length>=12),[...F].reverse().find(u=>at(u).length>=12)].filter(u=>u!==void 0&&u!==e).map(u=>{const st=at(u),V=d=>[(d[0]-s)/n,(d[1]-h)/n];return q5(st.map(d=>V(m[e].get(d))),st.map(d=>V(m[u].get(d))))}).filter(u=>u.length),ut=[];if(H.length===2)for(const u of H[0]){const st=H[1].reduce((V,d)=>yr(d,u)>yr(V,u)?d:V);yr(u,st)>Math.cos(15*pn)&&ut.push(_a(wr(u,st)))}else H.length===1&&ut.push(...H[0]);const gt=ot();let xt={cost:J(F),st:gt};for(const u of ut){const st=[u[0],-u[1],-u[2]];G(gt);for(const d of m[e].keys()){const w=y.get(d);if(!w)continue;const T=_a(w),j=yr(st,T);if(Math.abs(j)>.05){const O=yr(st,rt.O)/j;O>0&&y.set(d,Le(T,O))}}Z(),Xs(v,y,m,_,n,s,h,8),q(!0,!0);const V=J(F);V<xt.cost&&(xt={cost:V,st:ot()})}G(xt.st)}for(let ot=0;ot<4;ot++){q(!0,ot===0);const G=new Map;for(const at of F)for(const[D,H]of m[at])y.has(D)&&G.set(D,Math.max(G.get(D)??0,$a(v[at],y.get(D),H,n,s,h)));const J=Math.max(1.5,2.5*al([...G.values()]));let Z=0;for(const[at,D]of G)D>J&&(I(at),Z++);if(Xs(v,y,m,_,n,s,h,8),q(),!Z&&ot)break}for(let ot=0,G=U();ot<8;ot++){Xs(v,y,m,_,n,s,h,5);const J=U();if(J>G*.998)break;G=J}return q(!0),p?.(1),{poses:v,points:y,obs:m,ref:e}}function tM(t,e,{w:o,h:r,mw:n,mh:a,f:i,region:l,smooth:p=Lo.smooth,id:c="o1",name:s=""}){const{poses:h,points:f,obs:m,ref:y}=t,$=o/2,x=r/2,E=[...f.values()];if(E.length<Lo.minPoints)throw Error("FLAT");const v=Le(E.reduce((H,ut)=>wr(H,ut),[0,0,0]),1/E.length),S=h[y].C,k=h[y].R,b=Math.hypot(...No(v,S))||1,A=[[0,0,0],[0,0,0],[0,0,0]];for(const H of E){const ut=No(H,v);for(let gt=0;gt<3;gt++)for(let xt=0;xt<3;xt++)A[gt][xt]+=ut[gt]*ut[xt]}const{values:I,vectors:P}=Ls(A),C=[0,1,2].sort((H,ut)=>I[H]-I[ut]),z=I[C[0]]<.08**2*I[C[1]];let N=An(k);if(z){let H=_a(P.map(u=>u[C[0]]));yr(H,No(S,v))<0&&(H=Le(H,-1));const ut=lr(An(k),[1,0,0]),gt=_a(No(ut,Le(H,yr(H,ut)))),xt=Pd(H,gt);N=An([gt,xt,H])}const F=H=>Le(lr(An(N),No(H,v)),1/b),K=h.map((H,ut)=>H?ut:-1).filter(H=>H>=0),_=Math.min(...K),q=Math.max(...K),U=[];for(let H=_;H<=q;H++){const ut=h[H]??h[U.length?H-1:y];h[H]=ut;const gt=Ho(ut.R,N),xt=Le(lr(ut.R,No(v,ut.C)),1/b);let u=0,st=0;for(const[V,d]of m[H]){const w=f.get(V);w&&(u+=$a(ut,w,d,i,$,x),st++)}U.push({t:e[H],R:gt,T:xt,err:st?u/st:0,n:st})}const rt=new Map;for(const H of m)for(const ut of H.keys())f.has(ut)&&rt.set(ut,(rt.get(ut)??0)+1);const ot=[...rt].sort((H,ut)=>ut[1]-H[1]).slice(0,Lo.points).map(([H])=>F(f.get(H))),G=ot.map(H=>H[0]).sort((H,ut)=>H-ut),J=Math.max(1e-4,G[Math.floor(G.length*.98)]-G[Math.floor(G.length*.02)]),Z=eM(U,ot,i,p);let at=0,D=0;for(const H of U)at+=H.err*H.n,D+=H.n;return{v:1,id:c,...s?{name:String(s).slice(0,40)}:{},w:o,h:r,mw:n||o,mh:a||r,f:zo(i),ref:zo(e[y]),region:l.map(H=>[Po(H[0]),Po(H[1])]),plane:z,width:zo(J),err:zo(D?at/D:0),smooth:p,frames:Z.map((H,ut)=>[zo(H.t),...ig(H.R).map(zo),...H.T.map(zo),Po(U[ut].err),U[ut].n]),points:ot.map(H=>H.map(zo))}}function eM(t,e,o,r){if(!(r>0)||t.length<3)return t;const n=r*Lo.smoothFrames,a=Math.ceil(n*2.5),i=Lo.smoothTolPx,l=e.filter((h,f)=>f%Math.max(1,Math.floor(e.length/40))===0),p=(h,f)=>{const m=wr(lr(h.R,f),h.T);return m[2]>-1e-6?null:[o*m[0]/-m[2],o*m[1]/-m[2]]},c=(h,f)=>{let m=0;for(const y of l){const $=p(h,y),x=p(f,y);$&&x&&(m=Math.max(m,Math.hypot($[0]-x[0],$[1]-x[1])))}return m},s=t.map(h=>ig(h.R));return t.map((h,f)=>{let m=0,y=[0,0,0],$=[0,0,0,0];for(let k=Math.max(0,f-a);k<=Math.min(t.length-1,f+a);k++){const b=Math.exp(-((k-f)**2)/(2*n*n)),A=Wu(s[k],s[f])<0?s[k].map(I=>-I):s[k];m+=b,y=wr(y,Le(t[k].T,b)),$=$.map((I,P)=>I+A[P]*b)}const x=k=>{const b=s[f].map((I,P)=>I+($[P]/m-I)*k),A=Math.hypot(...b);return{...h,R:ag(b.map(I=>I/A)),T:wr(h.T,Le(No(Le(y,1/m),h.T),k))}};let E=1,v=x(1),S=c(h,v);for(let k=0;k<6&&S>i;k++)E*=Math.max(.3,i/S*.95),v=x(E),S=c(h,v);return S>i?h:v})}const Wu=(t,e)=>t[0]*e[0]+t[1]*e[1]+t[2]*e[2]+t[3]*e[3];function Nf(t,e){const o=n=>n[0][0]*(n[1][1]*n[2][2]-n[1][2]*n[2][1])-n[0][1]*(n[1][0]*n[2][2]-n[1][2]*n[2][0])+n[0][2]*(n[1][0]*n[2][1]-n[1][1]*n[2][0]),r=o(t);return Math.abs(r)>1e-30?[0,1,2].map(n=>o(t.map((a,i)=>a.map((l,p)=>p===n?e[i]:l)))/r):null}function Ls(t){const e=t.map(r=>[...r]),o=b1();for(let r=0;r<40;r++){let n=0;for(let a=0;a<3;a++)for(let i=a+1;i<3;i++)n+=e[a][i]**2;if(n<1e-26)break;for(let a=0;a<3;a++)for(let i=a+1;i<3;i++){if(Math.abs(e[a][i])<1e-300)continue;const l=(e[i][i]-e[a][a])/(2*e[a][i]),p=Math.sign(l||1)/(Math.abs(l)+Math.sqrt(l*l+1)),c=1/Math.sqrt(p*p+1),s=p*c;for(let h=0;h<3;h++){const f=e[h][a],m=e[h][i];e[h][a]=c*f-s*m,e[h][i]=s*f+c*m}for(let h=0;h<3;h++){const f=e[a][h],m=e[i][h];e[a][h]=c*f-s*m,e[i][h]=s*f+c*m}for(let h=0;h<3;h++){const f=o[h][a],m=o[h][i];o[h][a]=c*f-s*m,o[h][i]=s*f+c*m}}}return{values:[e[0][0],e[1][1],e[2][2]],vectors:o}}const oM=t=>{const e=new Float32Array(t.data.length);for(let o=0;o<e.length;o++)e[o]=t.data[o]/255;return{w:t.w,h:t.h,data:e}};function lC(t,e,{ref:o,region:r,f:n,mw:a,mh:i,smooth:l,onProgress:p=null,id:c,name:s}={}){if(t.length<3)throw Error("FLAT");const h=t[0].w,f=t[0].h,m=new Map,y=x=>{let E=m.get(x);return E||(m.size>3&&m.delete(m.keys().next().value),E=xb(oM(t[x])),m.set(x,E)),E},$=Q5(t.length,o,{w:h,h:f,f:n,region:r,onProgress:p,follow:(x,E,v)=>kb(y(x),y(E),v),seed:(x,E,v,S)=>W5(y(x)[0],E,S,{taken:v})});if($.poses.filter(Boolean).length<Math.min(t.length,3))throw Error("LOST");return tM($,e,{w:h,h:f,mw:a,mh:i,f:n,region:r,smooth:l,id:c,name:s})}function rM(t,e){const o=t.frames,r=o.length;let n=0;for(;n<r-2&&o[n+1][0]<=e;)n++;const a=o[n],i=o[Math.min(r-1,n+1)],l=i[0]>a[0]?Math.max(0,Math.min(1,(e-a[0])/(i[0]-a[0]))):0;let p=a.slice(1,5),c=i.slice(1,5);Wu(p,c)<0&&(c=c.map(f=>-f));const s=Math.min(1,Math.max(-1,Wu(p,c)));let h;if(s>.9995){h=p.map((m,y)=>m+(c[y]-m)*l);const f=Math.hypot(...h);h=h.map(m=>m/f)}else{const f=Math.acos(s),m=Math.sin(f);h=p.map((y,$)=>y*Math.sin((1-l)*f)/m+c[$]*Math.sin(l*f)/m)}return{R:ag(h),T:[0,1,2].map(f=>a[5+f]+(i[5+f]-a[5+f])*l),err:a[8]+(i[8]-a[8])*l,n:Math.round(a[9]+(i[9]-a[9])*l)}}function nM(t,e,o){const r=(t.keys??[]).filter(l=>Number.isFinite(l[e])).sort((l,p)=>l.t-p.t);if(!r.length)return t.fix?.[e]??y1[e];if(o<=r[0].t)return r[0][e];if(o>=r.at(-1).t)return r.at(-1)[e];let n=0;for(;r[n+1].t<o;)n++;const a=r[n],i=r[n+1];return a[e]+(i[e]-a[e])*(o-a.t)/(i.t-a.t)}const aM=(t,e)=>Object.fromEntries(Ku.map(o=>[o,nM(t,o,e)]));function zd(t,e,{raw:o=!1}={}){const r=rM(t,e);if(o)return{...r,s:1};const n=aM(t,e);return{...r,R:Ho(r.R,w1(n.rx,n.ry,n.rz)),T:wr(r.T,Le(Vu([n.x,n.y,n.z]),t.width)),s:n.s}}function x1(t,e,o,r=zd(t,o)){const n=wr(lr(r.R,Le(e,r.s)),r.T);return n[2]>-1e-6?null:[t.w/2+t.f*n[0]/-n[2],t.h/2-t.f*n[1]/-n[2]]}function cC(t,e,o=.5){const r=zd(t,e),n=t.width*o,a=i=>x1(t,i,e,r);return{o:a([0,0,0]),x:a([n,0,0]),y:a([0,n,0]),z:a([0,0,n])}}function pC(t){const e=[];for(const o of t.keys??[])e.some(r=>Math.abs(r-o.t)<1/60)||e.push(o.t);return e.sort((o,r)=>o-r)}function uC(t,e,o,r=!1){let n=(t.keys??[]).map(i=>({...i})),a={...t.fix};o=Po(o);for(const i of Ku){const l=e[i];if(typeof l!="number"||!Number.isFinite(l))continue;if(n.some(c=>Number.isFinite(c[i]))||r){let c=n.find(s=>Math.abs(s.t-o)<.016666666666666666);c||(c={t:o},n.push(c)),c[i]=Po(l)}else a[i]=Po(l)}for(const i of Ku)a[i]===y1[i]&&delete a[i];return n=n.sort((i,l)=>i.t-l.t),{...t,keys:n.length?n:void 0,fix:Object.keys(a).length?a:void 0}}function dC(t,e){const o=(t.keys??[]).filter(r=>Math.abs(r.t-e)>=.016666666666666666);return{...t,keys:o.length?o:void 0}}function hC(t){const e=new Set((t?.objectTracks??[]).map(r=>r.id));let o=1;for(;e.has(`o${o}`);)o++;return`o${o}`}function M1(t,e,o,r,n){const a=Bh(t,e,t.w/2,t.h/2,o,r,n),i=Bh(t,e,t.w/2+10,t.h/2,o,r,n);return Math.hypot(i[0]-a[0],i[1]-a[1])/10}function iM(t,e,o,r,n,a,i=null){return i?yb(i,e.w,e.w/e.h):5*Cr(r,n)*(js(a)?Gs(a,"zoom",t.start+o):1)/M1(e,t,o,r,n)}function fC(t,e,o,r,n=t.f){return n*M1(t,e,t.ref,o,r)/(5*Cr(o,r))}function sM(t,e,o,r,n,a=null){if(t.size)return t.size*o/t.width;if(a?.mode==="free"&&Array.isArray(a.frames)){const i=a.w/t.w,l=t.region.map(y=>y[0]),p=t.region.map(y=>y[1]),c=[(Math.min(...l)+Math.max(...l))/2*i,Math.max(...p)*i],s=[l.reduce((y,$)=>y+$,0)/l.length*i,p.reduce((y,$)=>y+$,0)/p.length*i],h=ik(a,t.ref).C,f=sk(a,c[0],c[1],t.ref)??lk(a,s[0],s[1],t.ref),m=Math.hypot(...No(f,h));if(m>0)return m*ck(a,e,o,r).k}return 5*Cr(o,r)*(js(n)?Gs(n,"zoom",e.start+t.ref):1)}function lM(t,e){const o=Math.asin(Math.max(-1,Math.min(1,t[1][2]))),r=Math.atan2(-t[0][2],t[2][2]),n=[[o,r],[Math.PI-o,r+Math.PI]].map(([a,i])=>{const l=[[1,0,0],[0,Math.cos(a),Math.sin(a)],[0,-Math.sin(a),Math.cos(a)]],p=[[Math.cos(i),0,-Math.sin(i)],[0,1,0],[Math.sin(i),0,Math.cos(i)]],c=Ho(An(Ho(p,l)),t);return[a/pn,i/pn,Math.atan2(c[1][0],c[0][0])/pn]});return $1(n,e)}function cM(t,e){const o=Math.asin(Math.max(-1,Math.min(1,t[0][2]))),r=Math.atan2(-t[1][2],t[2][2]),n=Math.atan2(-t[0][1],t[0][0]);return $1([[r,o,n],[r+Math.PI,Math.PI-o,n+Math.PI]].map(a=>a.map(i=>i/pn)),e)}function $1(t,e){const o=(n,a)=>{if(a===void 0)return n;for(;n-a>180;)n-=360;for(;n-a<-180;)n+=360;return n},r=t.map(n=>n.map((a,i)=>o(a,e?.[i])));return e?r.reduce((n,a)=>a.reduce((i,l,p)=>i+Math.abs(l-e[p]),0)<n.reduce((i,l,p)=>i+Math.abs(l-e[p]),0)?a:n):r[0]}const pM=["x","y","depth","zoom","rot","tiltX","tiltY","rx","ry","rz"],uM=t=>t.kind==="model"?"model":t.nullLayer?"null":t.title?"text":"plane";function dM(t,e,o,r,n,a,i={},{scene:l=null}={}){const p=Math.max(t.start,e.start+o.frames[0][0]),c=Math.min(t.start+t.duration,e.start+o.frames.at(-1)[0]),s=Math.max(t.start,e.start),h=Math.min(t.start+t.duration,e.start+e.duration);if(!(h>s))throw Error("TIME");const f=js(a)?a:{enabled:!0,motionV:2,motionKeys:[]},m=iM(e,o,o.ref,r,n,f);if(Math.abs(m/o.f-1)>.03)throw Error("LENS");const y=Cr(r,n),$=sM(o,e,r,n,f,l),x=uM(t),E=Number.isFinite(i.size)&&i.size>0?i.size:Lo.glue[x],v=(i.offset??[0,0,0]).map(Z=>Z*o.width),S=i.turn??[0,0,0],k=w1(S[0],S[1],S[2]),b=[Math.max(s,Math.min(h,p)),...o.frames.map(Z=>e.start+Z[0]).filter(Z=>Z>p+1e-4&&Z<c-1e-4),Math.min(h,Math.max(s,c))],A=b.filter((Z,at)=>at===0||Z>b[at-1]+1e-4),I=[];let P,C;for(const Z of A){const at=Z-e.start,D=zd(o,at),H=bb(f,Z,r,n),ut=Ho(Ho(D.R,k),nl),gt=wr(lr(D.R,Le(Vu(v),D.s)),D.T),xt=Le(Vu(gt),$),u=wr(lr(H.R,xt),H.pos),st=Ho(H.R,Ho(nl,ut)),V=-u[2]/y;if(!(V>=Sd&&V<=wb)||!(xt[2]>1))throw Error("FAR");const d={time:+(Z-t.start).toFixed(4),x:u[0]/r,y:u[1]/n,depth:V,zoom:E*o.width*D.s*$/(x==="model"?1.8*y:r),d:xt[2],f:H.f};if(x==="model"){const w=cM(Ho(Ho(nl,st),nl),C);C=w,Object.assign(d,{rx:w[0],ry:w[1],rz:w[2]})}else{const w=lM(st,P);P=w,Object.assign(d,{tiltX:w[0],tiltY:w[1],rot:w[2]})}I.push(d)}const z=Lo.keyTolPx,N=Math.max(1,...I.map(Z=>Z.zoom*(x==="model"?1.8*y:r)*Z.f/Z.d)),F=Math.min(...I.map(Z=>Z.d)),K=2*z/N/pn,_={x:z/r,y:z/n,depth:z*F/N/y,zoom:z/N*I[0].zoom,rot:K,tiltX:K,tiltY:K,rx:K,ry:K,rz:K};let q={...t,motionV:2};for(const Z of pM)(q.motionKeys??[]).some(at=>at[Z]!==void 0)&&(q={...q,motionKeys:qr(q,Z,[])});const U=x==="model"?["x","y","depth","zoom","rx","ry","rz"]:["x","y","depth","zoom","rot","tiltX","tiltY"],rt={},ot=I.map(Z=>Z.time);for(const Z of U){const at=I.map(D=>D[Z]);if(Math.max(...at)-Math.min(...at)<=_[Z]){rt[Z]=zo(at[0]);continue}q={...q,motionKeys:qr(q,Z,ak(ot,at,_[Z],1/0).sort((D,H)=>D-H).map(D=>({time:ot[D],value:zo(at[D])})))}}const G=I[0],J={is3D:!0,motionV:2,motionKeys:q.motionKeys??[],posX:zo(G.x),posY:zo(G.y),spatialDepth:zo(G.depth),scale:zo(rt.zoom??G.zoom),objectGlue:{source:e.id,object:o.id,...Number.isFinite(i.size)?{size:Po(i.size)}:{},...i.offset?{offset:i.offset.map(Po)}:{},...i.turn?{turn:i.turn.map(Po)}:{}}};return x==="model"?Object.assign(J,{modelDepth:J.spatialDepth,modelGround:void 0,modelRotation:{x:Po(rt.rx??G.rx),y:Po(rt.ry??G.ry),z:Po(rt.rz??G.rz)}}):Object.assign(J,{rotation:Po(rt.rot??G.rot),tiltX:Po(rt.tiltX??G.tiltX),tiltY:Po(rt.tiltY??G.tiltY)}),{camera:js(a)?null:f,patch:J}}function mC(t,e,o,r,n,a,{scene:i=null}={}){const l=t.find(m=>m.id===e),p=l?.objectTracks?.find(m=>m.id===o);let c=a,s=null;const h=[];return p?{clips:t.map(m=>{if(m.objectGlue?.source!==e||m.objectGlue.object!==o)return m;try{const y=dM(m,l,p,r,n,c,m.objectGlue,{scene:i});return y.camera&&(c=s=y.camera),{...m,...y.patch}}catch{return h.push(m.id),m}}),camera:s,failed:h}:{clips:t,camera:null,failed:h}}const Dr=t=>typeof t=="number"&&Number.isFinite(t)?t:null,Ff=(t,e,o)=>{if(t!=null){if(!(Array.isArray(t)&&t.length===3&&t.every(r=>Dr(r)!==null&&Math.abs(r)<=o)))throw Error(`placeOnObject ${e}: [x, y, z] (each within ±${o})`);return t.map(Po)}};function hM(t,e){if(!e||e.kind!=="video")throw Error("trackObject3D needs a video clip (the footage the object moves in)");const o=t.region,r=o&&!Array.isArray(o)&&typeof o=="object"&&[o.x,o.y,o.w,o.h].every(y=>Dr(y)!==null)?[[o.x,o.y],[o.x+o.w,o.y],[o.x+o.w,o.y+o.h],[o.x,o.y+o.h]]:o,[n,a]=Lo.regionPoints;if(!(Array.isArray(r)&&r.length>=n&&r.length<=a&&r.every(y=>Array.isArray(y)&&y.length===2&&y.every($=>Dr($)!==null&&$>=0&&$<=1))))throw Error(`trackObject3D region: ${n}–${a} points [u, v] (0..1 of the footage picture) round the object`);let i=0;for(let y=0,$=r.length-1;y<r.length;$=y++)i+=(r[$][0]+r[y][0])*(r[$][1]-r[y][1]);if(!(Math.abs(i)/2>=4e-4))throw Error("trackObject3D region: draw round the object (the region is too small)");const l=Math.max(0,Math.min(e.duration,(Dr(t.at)??e.start)-e.start)),p=Math.max(0,Math.min(e.duration,(Dr(t.from)??Dr(t.start)??e.start)-e.start)),c=Math.min(e.duration-p,Dr(t.duration)??e.duration-p);if(!(c>=.3))throw Error("trackObject3D: at least 0.3 s of the footage");if(l<p-.001||l>p+c+.001)throw Error("trackObject3D: `at` (the frame the region is drawn on) must be inside from … from + duration");const s=Dr(t.size),h=Dr(t.lens),f=Dr(t.smooth);if(s!==null&&!(s>=Lo.size[0]&&s<=Lo.size[1]))throw Error(`trackObject3D size: ${Lo.size.join("–")} (the object's width as a share of the frame width)`);if(h!==null&&h!==0&&!(h>=8&&h<=300))throw Error("trackObject3D lens: 8–300 mm (35 mm equivalent), or leave it out (the timeline camera's)");if(f!==null&&!(f>=0&&f<=1))throw Error("trackObject3D smooth: 0 (the raw solve) … 1");if(t.name!==void 0&&t.name!==null&&typeof t.name!="string")throw Error("trackObject3D name: text");if((e.objectTracks?.length??0)>=Lo.max)throw Error(`trackObject3D: at most ${Lo.max} objects per clip (remove one first)`);const m=p<.001&&c>e.duration-.001;return{region:r.map(y=>[zo(y[0]),zo(y[1])]),at:+l.toFixed(4),...m?{}:{from:+p.toFixed(4),duration:+c.toFixed(4)},...s!==null?{size:s}:{},...h?{lens:h}:{},...f!==null?{smooth:f}:{},...t.name?{name:String(t.name).slice(0,40)}:{}}}function fM(t,e,o){if(!e||e.kind==="audio")throw Error("placeOnObject needs a visual layer (text, null, solid, picture, video, 3D model)");if(!o||o.kind!=="video"||o.id===e.id)throw Error("placeOnObject needs sourceClipId = the footage with the tracked object (a video clip, not the layer itself)");const r=Math.max(e.start,o.start);if(!(Math.min(e.start+e.duration,o.start+o.duration)>r))throw Error("placeOnObject: the layer and the footage must play at the same time");const a=t.objectId??t.object;if(a!=null&&!(typeof a=="string"&&/^[\w-]{1,24}$/.test(a)))throw Error("placeOnObject objectId: an object track id (o1, o2 … from get_timeline)");const i=o.clientJobs?.some(s=>s?.kind==="object-track"&&(s.state==="pending"||s.state==="running"));if(a&&!i&&!o.objectTracks?.some(s=>s.id===a))throw Error(`placeOnObject: ${o.label||o.id} has no object ${a} (trackObject3D first)`);if(!a&&!i&&!o.objectTracks?.length)throw Error(`placeOnObject: ${o.label||o.id} has no tracked object (trackObject3D first)`);const l=Dr(t.size);if(l!==null&&!(l>.01&&l<=100))throw Error("placeOnObject size: 0.01–100 (× the object's width)");const p=Ff(t.offset,"offset",50),c=Ff(t.turn,"turn",3600);return{source:o.id,...a?{object:a}:{},...l!==null?{size:l}:{},...p?{offset:p}:{},...c?{turn:c}:{}}}const gC=(t,e,o)=>o.map(([r,n])=>nk(t,e,r,n)),mc=Object.freeze(["hand","roto","planar","face","object"]),v1=15,Xu=900,mM=t=>t?.crop??{left:0,right:0,top:0,bottom:0},gM=(t,e,o)=>{const r=mM(t);return[r.left+e*(1-r.left-r.right),r.top+o*(1-r.top-r.bottom)]},il=t=>Math.round(t*1e4)/1e4;function yC(t){if(!t||t.kind!=="video")return[];const e=[];t.hands?.data&&e.push({source:"hand",label:"Tay (tracking tay)",points:uc,sides:["right","left"]}),t.roto?.points?.length&&e.push({source:"roto",label:"Điểm Roto"}),t.planar?.frames?.length&&!sg(t.planar)&&e.push({source:"planar",label:"Mặt phẳng (planar)"}),t.face?.f?.length&&e.push({source:"face",label:"Khuôn mặt"});for(const o of t.objectTracks??[])o?.frames?.length&&e.push({source:"object",object:o.id,label:`Vật thể 3D ${o.name||o.id}`});return e}function yM(t,e,{side:o="right",point:r="palm",object:n,from:a=0,to:i,fps:l=v1}={}){if(!t||t.kind!=="video")throw Error("VFX tracks come from a filmed video clip");if(!mc.includes(e))throw Error(`source must be ${mc.join(" / ")}`);const p=Math.min(t.duration,i??t.duration),c=1/Math.max(1,Math.min(30,l)),s=[];let h,f,m;if(e==="hand"){if(!t.hands?.data)throw Error("this clip has no hand track yet (Timeline: Track hands, or edit_timeline handAttach once)");const y=Vs(t.hands),$=o==="left"?1:0,x=uc.includes(r)?r:"palm";f=y.mw,m=y.mh,h=E=>{const v=fc(y,hc(t,E),$);return v?[...bi(v,x),m1(v,y.mw,y.mh)/(y.mh||1)]:null}}else if(e==="roto"){if(!t.roto?.points?.length)throw Error("this clip has no Roto point track");f=t.roto.mw,m=t.roto.mh,h=y=>$b(t,y)}else if(e==="planar"){if(!t.planar?.frames?.length)throw Error(sg(t.planar)?"this planar track is stored apart from the clip: open the Timeline in the editor and run it there":"this clip has no planar track");f=t.planar.mw,m=t.planar.mh;const y=f&&m?f/m:16/9;h=$=>{if(!vb(t.planar,$))return null;const x=Eb(t.planar,$).map(([E,v])=>gM(t,E,v));return[x.reduce((E,v)=>E+v[0],0)/x.length,x.reduce((E,v)=>E+v[1],0)/x.length,Math.hypot((x[0][0]-x[3][0])*y,x[0][1]-x[3][1])]}}else if(e==="face"){if(!t.face?.f?.length)throw Error("this clip has no face track");f=t.face.mw,m=t.face.mh,h=y=>{const $=Sb(t,y);return $&&$.score>0?[$.cx,$.cy,$.h]:null}}else{const y=(t.objectTracks??[]).find($=>$?.id===n)??(n==null?t.objectTracks?.[0]:null);if(!y?.frames?.length)throw Error(n==null?"this clip has no 3D-tracked object (edit_timeline trackObject3D)":`no 3D-tracked object ${n} on this clip`);f=y.mw,m=y.mh,h=$=>{if($<y.frames[0][0]-1e-6||$>y.frames.at(-1)[0]+1e-6)return null;const x=x1(y,[0,0,0],$);return x?[x[0]/y.w,x[1]/y.h]:null}}for(let y=0;s.length<Xu;y++){const $=Math.max(0,a)+y*c;if($>p+1e-6)break;const x=h(Math.min($,p));x&&Number.isFinite(x[0])&&Number.isFinite(x[1])&&x[0]>-.5&&x[0]<1.5&&x[1]>-.5&&x[1]<1.5&&s.push([il(Math.min($,p)),il(x[0]),il(x[1]),...Number.isFinite(x[2])&&x[2]>0?[il(x[2])]:[]])}if(s.length<2)throw Error(`the ${e} track does not see its target in this clip (fewer than 2 samples)`);return{fps:Math.round(1/c),points:s,...f>0&&m>0?{mw:f,mh:m}:{}}}function bC(t,e=600){if(!t||typeof t!="object"||!Array.isArray(t.points))throw Error("track must be {fps, points: [[t, u, v], …]}");if(t.points.length<2||t.points.length>Xu)throw Error(`track: 2 to ${Xu} points`);let o=-1/0;const r=t.points.map(n=>{if(!Array.isArray(n)||n.length<3||!n.slice(0,3).every(p=>Number.isFinite(Number(p))))throw Error("each track point is [t, u, v]");const[a,i,l]=n.map(Number);if(a<0||a>e+.001||a<=o)throw Error(`track times must rise within the shot (0–${e} s)`);if(i<-.5||i>1.5||l<-.5||l>1.5)throw Error("track u / v are fractions of the picture (−0.5..1.5)");return o=a,[a,i,l]});return{fps:Number.isFinite(Number(t.fps))?Number(t.fps):v1,points:r}}const bM=15,$n=t=>Math.round(t*1e4)/1e4,wM=new Set(["hand","face","planar"]);function kM(t,e,o){const r=t.vfxFootage||{},n=Array.isArray(r.anchor)&&r.anchor.length===2&&r.anchor.every(Number.isFinite)?r.anchor:ju,a=Number(r.aspect)>0?Number(r.aspect):Number(t.proxy?.width)>0&&Number(t.proxy?.height)>0?t.proxy.width/t.proxy.height:e/o;return{anchor:n,aspect:a}}function xM(t,e,{source:o,hand:r="right",point:n="palm",object:a,scale:i=!1,offset:l=null,W:p=1280,H:c=720}={}){if(!t?.vfxFootage)throw Error("vfxFootageFollow: clipId must be a Footage VFX layer (addVfxFootage)");if(!e||e.kind!=="video"||e.vfxFootage||e.vfx)throw Error("vfxFootageFollow: sourceClipId must be the filmed video clip with the track");if(!mc.includes(o))throw Error(`vfxFootageFollow: source must be ${mc.join(" / ")}`);if(i&&!wM.has(o))throw Error(`vfxFootageFollow: scale follows a hand, a face or a planar surface (not ${o})`);if(t.pin||t.pendingPin||t.parentId)throw Error("vfxFootageFollow: unpin / unparent the effect first");const s=Math.max(t.start,e.start),h=Math.min(t.start+t.duration,e.start+e.duration);if(!(h-s>=1/30))throw Error("vfxFootageFollow: the effect and the filmed clip do not play at the same time");const f=yM(e,o,{side:r==="left"?"left":"right",point:n,...a!=null?{object:String(a)}:{},from:s-e.start,to:h-e.start,fps:bM}),m=f.mw||Number(e.proxy?.width)||p,y=f.mh||Number(e.proxy?.height)||c,$=e.crop??{left:0,right:0,top:0,bottom:0},x=1-$.left-$.right||1,E=1-$.top-$.bottom||1,v=f.points.map(([rt,ot,G,J])=>{const Z=Id(e,(ot-$.left)/x,(G-$.top)/E,rt,p,c,m,y);return{T:e.start+rt,fx:Z.px/p,fy:Z.py/c,size:J}});if(i&&v.some(rt=>!(rt.size>0)))throw Error(`vfxFootageFollow: the ${o} track has no size to scale with`);const S={...t,...Zr(t)},k=v[0],b=rt=>$n(rt-t.start),{anchor:A,aspect:I}=kM(t,p,c),P=p/c,C=I>=P?1:I/P,z=I>=P?P/I:1,N=Array.isArray(l)&&Number.isFinite(Number(l[0]))?Number(l[0]):0,F=Array.isArray(l)&&Number.isFinite(Number(l[1]))?Number(l[1]):0,K=Ut(S,"zoom",k.T-t.start)||1,_=v.map(rt=>i?Math.max(.05,K*rt.size/k.size):Ut(S,"zoom",rt.T-t.start)||1);let q={...S,motionV:2};delete q.posX,delete q.posY,q={...q,...de(q,"x",v.map((rt,ot)=>({time:b(rt.T),value:$n(rt.fx+N-.5-(A[0]-.5)*C*_[ot])})))},q={...q,...de(q,"y",v.map((rt,ot)=>({time:b(rt.T),value:$n(rt.fy+F-.5-(A[1]-.5)*z*_[ot])})))},i&&(q={...q,...de(q,"zoom",v.map((rt,ot)=>({time:b(rt.T),value:$n(_[ot])})))});const U={clip:e.id,source:o,...o==="hand"?{hand:r==="left"?"left":"right",point:n}:{},...o==="object"&&a!=null?{object:String(a)}:{},...i?{scale:!0}:{}};return{patch:{motionV:2,motionKeys:q.motionKeys,posX:void 0,posY:void 0,vfxFootage:{...t.vfxFootage,follow:U}},keys:v.length,from:$n(v[0].T),to:$n(v.at(-1).T)}}function MM(t,e=0){const o=t?.vfxFootage?.follow;if(!o)throw Error("vfxFootageFollow: this effect follows nothing");const r={...t,...Zr(t)},n=Ut(r,"x",e),a=Ut(r,"y",e),i=Ut(r,"zoom",e),l=(r.motionKeys||[]).map(s=>{const{x:h,y:f,...m}=s;if(o.scale&&delete m.zoom,m.ease){const{x:y,y:$,...x}=m.ease;o.scale&&delete x.zoom,m.ease=x,Object.keys(x).length||delete m.ease}return m}).filter(s=>Object.keys(s).some(h=>h!=="time")),{follow:p,...c}=t.vfxFootage;return{motionV:2,motionKeys:l,posX:$n(n),posY:$n(a),...o.scale?{scale:$n(i)}:{},vfxFootage:c}}const ta=Object.freeze({echo:{copies:[1,16],gap:[.02,1],fade:[0,1],spread:[-.2,.2]},clone:{count:[1,24],spread:[.05,1],depth:[0,.9],delay:[0,2]},layouts:["row","wedge","crowd"]}),_r=(t,[e,o],r)=>{const n=Number(t);return Number.isFinite(n)?Math.min(o,Math.max(e,n)):r},Ae=t=>Math.round(t*1e4)/1e4,Rf=Object.freeze({grow:-.35,feather:.004});function Nn(t,e,o={}){const r={...t,id:e,volume:0,...o};return r.person&&(r.person={...r.person,grow:Math.min(r.person.grow??0,Rf.grow),feather:Math.max(r.person.feather??0,Rf.feather)}),delete r.roto,delete r.planar,delete r.personPending,delete r.sceneTrack,delete r.shocks,delete r.impacts,r}function $M(t,{copies:e=5,gap:o=.07,fade:r=.35,opacity:n=.85,spread:a=0,look:i=null,start:l=null,duration:p=null}={},c){const s=Math.round(_r(e,ta.echo.copies,5)),h=_r(o,ta.echo.gap,.07),f=_r(r,ta.echo.fade,.35),m=_r(a,ta.echo.spread,0);if(i!=null&&!Object.hasOwn(tc,i))throw Error(`personEcho: look must be a clip effect (${Object.keys(tc).join(", ")})`);const y=i?[...(t.effects??[]).slice(0,kn-1),{type:i,amount:.85}]:null,$=Math.max(t.start,Number.isFinite(l)?l:t.start),x=Math.min(t.start+t.duration,Number.isFinite(p)?$+p:t.start+t.duration);if(!(x-$>.1))throw Error("personEcho: the echo must lie inside the person clip");const E=[];for(let S=s;S>=1;S--){const k=S*h,b=$+k;if(b>=x-.05)continue;const A=(t.inPoint||0)+($-t.start)*(t.playbackRate||1);E.push(Nn(t,c(),{start:Ae(b),duration:Ae(x-b),inPoint:Ae(A),opacity:Ae(n*(1-f)**(S-1)*(1-.5*S/(s+1))),label:`${t.label||"Video"} · vệt ${S}`,...m?{motionV:2,posX:Ae((t.posX??0)+S*m)}:{},...y?{effects:y}:{}}))}const v=(t.inPoint||0)+($-t.start)*(t.playbackRate||1);return E.push(Nn(t,c(),{start:Ae($),duration:Ae(x-$),inPoint:Ae(v),label:`${t.label||"Video"} · người`})),E}function vM(t,e="wedge",o=.22,r=.25,n=7){const a=[];let i=n;const l=()=>(i=i*1664525+1013904223>>>0)/2**32;for(let p=1;p<=t;p++){const c=p%2?1:-1,s=Math.ceil(p/2);e==="row"?a.push([c*o*s,0]):e==="wedge"?a.push([c*o*s*.8,-r*s*.35]):a.push([(l()*2-1)*o*3,-r*(.15+l()*.85)])}return a}function EM(t,{count:e=6,layout:o="wedge",spread:r=.2,depth:n=.25,delay:a=.12,mirror:i=!0,feet:l=[.5,.9],horizon:p=.4,start:c=null,duration:s=null,smoke:h=!0,appear:f=.12}={},m){const y=Math.round(_r(e,ta.clone.count,6)),$=ta.layouts.includes(o)?o:"wedge",x=_r(r,ta.clone.spread,.2),E=_r(n,ta.clone.depth,.25),v=_r(a,[-2,2],.12),S=[_r(l?.[0],[0,1],.5),_r(l?.[1],[.05,1],.9)],k=_r(p,[-1,S[1]-.05],Math.min(.4,S[1]-.1)),b=Math.max(t.start,Number.isFinite(c)?c:t.start),A=Math.min(t.start+t.duration,Number.isFinite(s)?b+s:t.start+t.duration);if(!(A-b>.2))throw Error("clonePerson: the clones must lie inside the person clip");const I=vM(y,$,x,E).map(([N,F],K)=>({i:K,T:[S[0]+N,S[1]+F]})).filter(N=>N.T[1]>k+.02);I.sort((N,F)=>N.T[1]-F.T[1]);const P=[],C=[],z=(t.inPoint||0)+(b-t.start)*(t.playbackRate||1);for(const{i:N,T:F}of I){const K=N+1,_=(F[1]-k)/(S[1]-k),q=Ae(F[0]-.5-_*(S[0]-.5)),U=Ae(F[1]-.5-_*(S[1]-.5)),rt=Math.abs(v)*K,ot=v>=0?b+Math.min(rt,(A-b)*.6):b,G=v>=0?z:z+Math.min(rt,(A-b)*.6)*(t.playbackRate||1),J=Ae(ot+(f>0?f*(K-1)*.5:0));J>=A-.1||(P.push(Nn(t,m(),{start:J,duration:Ae(A-J),inPoint:Ae(G+(J-ot)*(t.playbackRate||1)),motionV:2,posX:q,posY:U,scale:Ae((t.scale??1)*_),...i&&K%2===0?{flipX:!t.flipX}:{},enter:{type:"fade",duration:.18},label:`${t.label||"Video"} · bản sao ${K}`})),h&&C.push({at:J,u:F[0],v:F[1]-.18*_,size:_}))}return P.push(Nn(t,m(),{start:Ae(b),duration:Ae(A-b),inPoint:Ae(z),label:`${t.label||"Video"} · người`})),{layers:P,poofs:C.map(N=>SM(N,m))}}const Cp="vfx-smoke-poof";function SM({at:t,u:e,v:o,size:r=1,duration:n=1.1},a){const i=Yi.find(l=>l.id===Cp);return{id:a(),nodeId:"",kind:"image",url:"",volume:0,start:Ae(Math.max(0,t-.12)),duration:n,label:"Khói bụp",motionV:2,posX:Ae(e-.5),posY:Ae(o-.5),scale:Ae(Math.max(.2,Math.min(3,r))),motion:Jo({code:`@preset:${Cp}`,params:{...i.params},preset:Cp})}}const jp="vfx-debris-burst";function IM({id:t,at:e,u:o,v:r,size:n=1,seed:a=7,duration:i=1.2}){const l=Yi.find(p=>p.id===jp);return{id:t,nodeId:"",kind:"image",url:"",volume:0,start:Ae(Math.max(0,e)),duration:i,label:"Mảnh vụn",motionV:2,posX:Ae(o-.5),posY:Ae(r-.5),scale:Ae(Math.max(.2,Math.min(3,n))),motion:Jo({code:`@preset:${jp}`,params:{...l.params,seed:a},preset:jp})}}function E1(t){if(t?.kind!=="video")return!1;const e=Ib(t);return e?e.some(o=>o.speed<.999):(t.playbackRate||1)<.999}function wC(t,e,o=30){if(Ab(t)==="none"&&(!t?.smoothSlow||!E1(t)))return null;const r=lg(t,e)*o,n=Math.floor(r+1e-6);return{frame:n,phase:Math.min(1,Math.max(0,r-n))}}const AM=Object.freeze(["flame","spirit","electric","smoke","burst"]),va=Object.freeze({fps:15,maxFrames:900,color:"#b44dff",hot:"#fff1ff",size:[.3,3],intensity:[.2,2.5],stretch:[.2,4],taper:.75}),CM=Object.freeze([0,11,12,13,14,15,16,23,24,25,26,27,28]),Un=t=>Math.round(t*1e3)/1e3,Hu=t=>Math.round(t*1e4)/1e4,Ha=(t,e,o,r)=>Number.isFinite(t)?Math.min(o,Math.max(e,t)):r,Df=/^#[0-9a-fA-F]{6}$/;function Ld(t={}){const e=AM.includes(t.look)?t.look:"flame",o=Array.isArray(t.wind)&&t.wind.length===2&&t.wind.every(Number.isFinite)?t.wind.map(r=>Un(Ha(r,-1,1,0))):[0,0];return{look:e,color:Df.test(t.color??"")?t.color.toLowerCase():va.color,hot:Df.test(t.hot??"")?t.hot.toLowerCase():va.hot,size:Un(Ha(t.size,...va.size,1)),intensity:Un(Ha(t.intensity,...va.intensity,1)),wind:o,speed:Un(Ha(t.speed,0,2,1)),stretch:Un(Ha(t.stretch,...va.stretch,1)),taper:Un(Ha(t.taper,0,1,va.taper))}}function kC(t,e=o=>o){const o=[];for(const r of t){if(!r?.lm)continue;const n=[Hu(r.t)];for(const a of CM){const i=r.lm[a];if(!i||(i[3]??1)<.35){n.push(-1,-1);continue}const[l,p]=e([i[0],i[1]]);n.push(Un(l),Un(p))}if(o.push(n),o.length>=va.maxFrames)break}return o}function jM(t,e,o="person"){const r=Ld(e),n="const SK="+JSON.stringify(t??[])+";const KIND="+JSON.stringify(o==="thing"?"thing":"person")+";"+TM;return Jo({code:n,params:{look:r.look,color:r.color,hot:r.hot,size:r.size,intensity:r.intensity,windX:r.wind[0],windY:r.wind[1],speed:r.speed,stretch:r.stretch,taper:r.taper}})}const TM=`const VOL=(ctx,W,H,blurPx,paint,draw)=>{if(typeof OffscreenCanvas==='undefined')return;const S=4,w=Math.max(2,Math.ceil(W/S)),h=Math.max(2,Math.ceil(H/S))
|
|
3
|
+
let A=globalThis.__VOLA,B=globalThis.__VOLB;if(!A||A.width!==w||A.height!==h){A=new OffscreenCanvas(w,h);B=new OffscreenCanvas(w,h);globalThis.__VOLA=A;globalThis.__VOLB=B}
|
|
4
|
+
const a=A.getContext('2d'),b=B.getContext('2d');a.setTransform(1,0,0,1,0,0);a.clearRect(0,0,w,h);a.setTransform(1/S,0,0,1/S,0,0);a.lineCap='round';a.lineJoin='round';draw(a)
|
|
5
|
+
const pass=(px)=>{b.setTransform(1,0,0,1,0,0);b.clearRect(0,0,w,h);b.filter='blur('+Math.max(.6,px/S)+'px)';b.drawImage(A,0,0);b.filter='none'}
|
|
6
|
+
ctx.save();pass(blurPx);if(paint>0){ctx.globalCompositeOperation='source-over';ctx.globalAlpha=paint;ctx.drawImage(B,0,0,W,H)}ctx.globalCompositeOperation='lighter';ctx.globalAlpha=1;ctx.drawImage(B,0,0,W,H)
|
|
7
|
+
pass(blurPx*.3);ctx.drawImage(B,0,0,W,H);ctx.restore()}
|
|
8
|
+
function render(ctx,t,env){
|
|
9
|
+
const {width:W,height:H,params:p}=env,look=p.look||'flame',col=p.color||'#b44dff',hot=p.hot||'#fff1ff',I=M.clamp(+p.intensity||1,.2,2.5),SZ=M.clamp(+p.size||1,.3,3),LEN=M.clamp(+p.stretch||1,.2,4),TP=M.clamp(p.taper===undefined?.75:+p.taper,0,1)
|
|
10
|
+
if(!SK.length||t<SK[0][0]-1e-6||t>SK[SK.length-1][0]+.2)return
|
|
11
|
+
const fade=Math.min(M.clamp((t-SK[0][0])/.25+.001),t>SK[SK.length-1][0]?Math.max(0,1-(t-SK[SK.length-1][0])/.2):1)
|
|
12
|
+
const frameAt=(s)=>{if(s<=SK[0][0])return SK[0];for(let i=1;i<SK.length;i++)if(SK[i][0]>=s){const a=SK[i-1],b=SK[i],u=(s-a[0])/((b[0]-a[0])||1);return a.map((v,k)=>k===0?s:(v<0||b[k]<0?(v<0?b[k]:v):v+(b[k]-v)*u))}return SK[SK.length-1]}
|
|
13
|
+
const F=frameAt(Math.min(t,SK[SK.length-1][0])),G=frameAt(Math.max(SK[0][0],Math.min(t,SK[SK.length-1][0])-.12))
|
|
14
|
+
// the body: points in px, its size, its centre and how fast it goes (px a second)
|
|
15
|
+
let pts=[],sc,cen,cenB
|
|
16
|
+
if(KIND==='thing'){pts=[[F[1]*W,F[2]*H]];sc=Math.max(4,(F[3]||.08)*H*2);cen=pts[0];cenB=[G[1]*W,G[2]*H]}
|
|
17
|
+
else{for(let i=0;i<13;i++)pts.push(F[1+i*2]<0?null:[F[1+i*2]*W,F[2+i*2]*H])
|
|
18
|
+
const seen=pts.filter(Boolean);if(seen.length<3)return
|
|
19
|
+
const sh=pts[1]&&pts[2]?Math.hypot(pts[1][0]-pts[2][0],pts[1][1]-pts[2][1]):0;sc=Math.max(H*.05,sh||H*.12)
|
|
20
|
+
cen=[seen.reduce((a,q)=>a+q[0],0)/seen.length,seen.reduce((a,q)=>a+q[1],0)/seen.length]
|
|
21
|
+
const gs=[];for(let i=0;i<13;i++)if(G[1+i*2]>=0)gs.push([G[1+i*2]*W,G[2+i*2]*H]);cenB=gs.length?[gs.reduce((a,q)=>a+q[0],0)/gs.length,gs.reduce((a,q)=>a+q[1],0)/gs.length]:cen}
|
|
22
|
+
sc*=SZ
|
|
23
|
+
const vx=(cen[0]-cenB[0])/.12,vy=(cen[1]-cenB[1])/.12,vs=Math.hypot(vx,vy),spd=M.clamp(vs/(sc*3),0,2)*(+p.speed||1)
|
|
24
|
+
// where the energy goes: up, bent by the wind, swept back against the body's motion
|
|
25
|
+
const wx=(+p.windX||0),wy=(+p.windY||0),bx=vs>1?-vx/vs:0,by=vs>1?-vy/vs:0
|
|
26
|
+
const dir=(nx,ny)=>{let x=nx*.35+wx*1.2+bx*spd*1.4,y=-1+ny*.35+wy*1.2+by*spd*1.4;const l=Math.hypot(x,y)||1;return [x/l,y/l]}
|
|
27
|
+
const BONES=KIND==='thing'?[]:[[1,2],[1,3],[3,5],[2,4],[4,6],[1,7],[2,8],[7,8],[7,9],[9,11],[8,10],[10,12]]
|
|
28
|
+
const bones=BONES.filter(b=>pts[b[0]]&&pts[b[1]])
|
|
29
|
+
// a point on the body's edge: along a bone (or round the head / the thing), pushed out by its half-width, with its outward normal
|
|
30
|
+
const edge=(rr)=>{if(KIND==='thing'||!bones.length){const a=rr()*Math.PI*2,c=pts[0]||cen,R=KIND==='thing'?sc*.5:sc*.45;return [c[0]+Math.cos(a)*R,c[1]+Math.sin(a)*R,Math.cos(a),Math.sin(a)]}
|
|
31
|
+
if(pts[0]&&rr()<.18){const a=-Math.PI*(.1+rr()*.8),R=sc*.42;return [pts[0][0]+Math.cos(a)*R,pts[0][1]+Math.sin(a)*R*1.15,Math.cos(a),Math.sin(a)]}
|
|
32
|
+
const b=bones[Math.floor(rr()*bones.length)],A=pts[b[0]],B=pts[b[1]],u=rr(),x=A[0]+(B[0]-A[0])*u,y=A[1]+(B[1]-A[1])*u,dx=B[0]-A[0],dy=B[1]-A[1],l=Math.hypot(dx,dy)||1,side=rr()<.5?-1:1
|
|
33
|
+
const nx=-dy/l*side,ny=dx/l*side,half=sc*(b[0]===1&&b[1]===2||b[0]===7&&b[1]===8?.3:.18);return [x+nx*half,y+ny*half,nx,ny]}
|
|
34
|
+
const halo=(k,al)=>{ctx.strokeStyle=M.rgba(col,al*fade);ctx.lineCap='round';ctx.lineJoin='round'
|
|
35
|
+
for(const b of bones){ctx.lineWidth=sc*k;ctx.beginPath();ctx.moveTo(pts[b[0]][0],pts[b[0]][1]);ctx.lineTo(pts[b[1]][0],pts[b[1]][1]);ctx.stroke()}
|
|
36
|
+
const c=KIND==='thing'?cen:pts[0];if(c){ctx.fillStyle=M.rgba(col,al*fade*.8);ctx.beginPath();ctx.arc(c[0],c[1],KIND==='thing'?sc*.5+sc*k*.5:sc*(.45+k*.5),0,Math.PI*2);ctx.fill()}}
|
|
37
|
+
const flick=(k)=>.75+.25*Math.sin(t*19+k*2.1)*Math.sin(t*7.7+k)
|
|
38
|
+
ctx.save()
|
|
39
|
+
if(look==='smoke'){
|
|
40
|
+
// a dark aura: soft wisps of smoke rising off the body, turning and spreading as they climb, a faint coloured rim
|
|
41
|
+
ctx.globalCompositeOperation='source-over'
|
|
42
|
+
for(let k=0;k<70;k++){const rr=M.rand(k*919+3),life=1.6,age=((t*(.6+rr()*.5)+rr()*life)%life),e=edge(M.rand(k*31+Math.floor((t*(.6+rr()*.5)+rr()*life)/life)*7)),d=dir(e[2],e[3])
|
|
43
|
+
const x=e[0]+d[0]*age*sc*1.4*I,y=e[1]+d[1]*age*sc*1.4*I,R=sc*(.12+age*.45),a=(1-age/life)*.22*fade
|
|
44
|
+
const g=ctx.createRadialGradient(x,y,0,x,y,R);g.addColorStop(0,'rgba(12,6,18,'+a+')');g.addColorStop(1,'rgba(12,6,18,0)');ctx.fillStyle=g;ctx.beginPath();ctx.arc(x,y,R,0,Math.PI*2);ctx.fill()}
|
|
45
|
+
ctx.globalCompositeOperation='lighter';halo(.5,.05);ctx.restore();return}
|
|
46
|
+
// the MASS (owner 2026-11-05: "aura dính liền và toả thành nguyên khối có xung nhiệt"): the body's shape smeared up / downwind /
|
|
47
|
+
// back along its motion, blurred into one connected glow, pulsing with heat; flames, arcs and motes ride on top of it
|
|
48
|
+
// stretch: how far it reaches; taper: each copy shrinks toward the body's leading point (the far end along the flow), so the
|
|
49
|
+
// mass narrows to a point away from the body
|
|
50
|
+
if(look!=='smoke'){const pulse=.82+.18*Math.sin(t*6.3)*Math.sin(t*2.1+1),d0=dir(0,0),steps=16
|
|
51
|
+
const seenP=(KIND==='thing'?[cen]:pts.filter(Boolean));let lead=seenP[0],best=-1e9;for(const q of seenP){const d=q[0]*d0[0]+q[1]*d0[1];if(d>best){best=d;lead=q}}
|
|
52
|
+
const ax=lead[0]+d0[0]*sc*.45,ay=lead[1]+d0[1]*sc*.45,reach=sc*1.6*LEN*I*(1+spd*.5)
|
|
53
|
+
VOL(ctx,W,H,sc*.22,.35,(c)=>{for(let k=0;k<=steps;k++){const u=k/steps,sh=1-TP*Math.pow(u,.8),wob=Math.sin(t*9-k*.9)*sc*.07*(1-u*.5),ox=d0[0]*u*reach-d0[1]*wob,oy=d0[1]*u*reach+d0[0]*wob
|
|
54
|
+
const al=Math.pow(1-u,1.6)*.9*pulse*fade*(.85+.15*Math.sin(t*14+k*1.7)),grow=(1+u*.6*(1-TP))*Math.max(.08,sh)
|
|
55
|
+
const P=(q)=>[ax+(q[0]-ax)*sh+ox,ay+(q[1]-ay)*sh+oy]
|
|
56
|
+
c.strokeStyle=M.rgba(k<2?hot:col,al);c.fillStyle=M.rgba(col,al*.9)
|
|
57
|
+
for(const b of bones){const A=P(pts[b[0]]),B=P(pts[b[1]]);c.lineWidth=sc*.5*grow;c.beginPath();c.moveTo(A[0],A[1]);c.lineTo(B[0],B[1]);c.stroke()}
|
|
58
|
+
const hc=KIND==='thing'?cen:pts[0];if(hc){const Q=P(hc);c.beginPath();c.arc(Q[0],Q[1],(KIND==='thing'?sc*.55:sc*.48)*grow,0,Math.PI*2);c.fill()}}})}
|
|
59
|
+
// the halo: the body's glow, wide and soft (the burst breathes bigger) — painted, so it reads on a bright street too, then a
|
|
60
|
+
// lighter inner glow added as light
|
|
61
|
+
const breathe=look==='burst'?1.15+.12*Math.sin(t*9):1+.05*Math.sin(t*5)
|
|
62
|
+
ctx.globalCompositeOperation='source-over';halo(1.7*breathe*I,.07);halo(1.15*breathe*I,.1);halo(.75*breathe,.14)
|
|
63
|
+
ctx.globalCompositeOperation='lighter';halo(.5*breathe,.18)
|
|
64
|
+
if(look==='flame'||look==='burst'){
|
|
65
|
+
// flame tongues licking up off the body's edge: tapered, wavering, white-hot at the root
|
|
66
|
+
const N=Math.round((look==='burst'?70:48)*I)
|
|
67
|
+
for(let k=0;k<N;k++){const rr=M.rand(k*733+17),cyc=.55+rr()*.4,ph=(t/cyc+rr())%1,gen=Math.floor(t/cyc+rr()),e=edge(M.rand(k*97+gen*13)),d=dir(e[2],e[3])
|
|
68
|
+
const L=sc*(.5+rr()*1.1)*LEN*I*(look==='burst'?1.35:1)*flick(k)*(1+spd*.6)*Math.sin(Math.PI*Math.min(1,ph*1.2)),wd=sc*(.1+rr()*.14)
|
|
69
|
+
if(L<1)continue
|
|
70
|
+
const wob=sc*.18*Math.sin(t*11+k),x1=e[0]+d[0]*L*.5-d[1]*wob,y1=e[1]+d[1]*L*.5+d[0]*wob,x2=e[0]+d[0]*L,y2=e[1]+d[1]*L
|
|
71
|
+
for(const [w,al,c] of [[2.6,.14,col],[1.1,.4,col],[.38,.85,hot]]){ctx.globalCompositeOperation=c===hot?'lighter':'source-over';const g=ctx.createLinearGradient(e[0],e[1],x2,y2);g.addColorStop(0,M.rgba(c,al*fade));g.addColorStop(.6,M.rgba(col,al*.5*fade));g.addColorStop(1,M.rgba(col,0))
|
|
72
|
+
ctx.strokeStyle=g;ctx.lineWidth=Math.max(1,wd*w);ctx.beginPath();ctx.moveTo(e[0],e[1]);ctx.quadraticCurveTo(x1,y1,x2,y2);ctx.stroke()}}
|
|
73
|
+
}
|
|
74
|
+
ctx.globalCompositeOperation='lighter'
|
|
75
|
+
if(look==='electric'||look==='burst'){
|
|
76
|
+
// electricity: jagged arcs leaping off the body and between its limbs, re-struck 15 times a second
|
|
77
|
+
const strike=Math.floor(t*15),N=Math.round((look==='burst'?6:12)*I)
|
|
78
|
+
for(let k=0;k<N;k++){const rr=M.rand(strike*131+k*17),a=edge(rr),far=rr()<.5,b=far?null:edge(M.rand(strike*71+k*5)),d=dir(a[2],a[3])
|
|
79
|
+
const ex=far?a[0]+(a[2]*.7+d[0]*.3)*sc*(.6+rr()*.8)*I:b[0],ey=far?a[1]+(a[3]*.7+d[1]*.3)*sc*(.6+rr()*.8)*I:b[1],seg=7,P=[[a[0],a[1]]]
|
|
80
|
+
for(let i=1;i<seg;i++){const u=i/seg,j=sc*.12*(rr()-.5);P.push([a[0]+(ex-a[0])*u+j*(a[3]||0),a[1]+(ey-a[1])*u-j*(a[2]||0)])}P.push([ex,ey])
|
|
81
|
+
for(const [w,al,c] of [[6,.12,col],[2.2,.4,col],[.8,.95,hot]]){ctx.strokeStyle=M.rgba(c,al*fade);ctx.lineWidth=Math.max(1,sc*.012*w);ctx.beginPath();ctx.moveTo(P[0][0],P[0][1]);for(const q of P.slice(1))ctx.lineTo(q[0],q[1]);ctx.stroke()}}
|
|
82
|
+
}
|
|
83
|
+
if(look==='spirit'||look==='burst'){
|
|
84
|
+
// motes of light drifting up off the body, twinkling
|
|
85
|
+
const N=Math.round(46*I)
|
|
86
|
+
for(let k=0;k<N;k++){const rr=M.rand(k*53+29),life=1.2+rr(),age=(t+rr()*life)%life,gen=Math.floor((t+rr()*life)/life),e=edge(M.rand(k*7+gen*41)),d=dir(e[2],e[3])
|
|
87
|
+
const x=e[0]+d[0]*age*sc*.9+Math.sin(t*3+k)*sc*.08,y=e[1]+d[1]*age*sc*.9,a=(1-age/life)*fade*(.5+.5*Math.sin(t*20+k)),R=Math.max(1,sc*.025*(.5+rr()))
|
|
88
|
+
ctx.fillStyle=M.rgba(rr()<.4?hot:col,a);ctx.beginPath();ctx.arc(x,y,R,0,Math.PI*2);ctx.fill()}
|
|
89
|
+
}
|
|
90
|
+
if(look==='burst'){
|
|
91
|
+
// the power-up: a shock ring racing out along the ground from the feet, every 1.4 s
|
|
92
|
+
const feet=KIND==='thing'?[cen[0],cen[1]+sc*.5]:pts[11]&&pts[12]?[(pts[11][0]+pts[12][0])/2,Math.max(pts[11][1],pts[12][1])]:[cen[0],cen[1]+sc*2]
|
|
93
|
+
const u=((t-SK[0][0])%1.4)/1.4,R=sc*(.4+u*3.2)
|
|
94
|
+
for(const [w,al,c] of [[.4,.12,col],[.14,.4,col],[.04,.9,hot]]){ctx.strokeStyle=M.rgba(c,al*(1-u)*fade);ctx.lineWidth=Math.max(1,sc*w);ctx.beginPath();ctx.ellipse(feet[0],feet[1],R,R*.22,0,0,Math.PI*2);ctx.stroke()}
|
|
95
|
+
}
|
|
96
|
+
ctx.restore()
|
|
97
|
+
}`;function OM({id:t,at:e,duration:o,settings:r,body:n=[],kind:a="person",label:i}){const l=Ld(r);return{id:t,nodeId:"",kind:"image",url:"",volume:0,start:Hu(e),duration:Hu(o),label:i||`Aura · ${l.look}`,motionV:2,posX:0,posY:0,scale:1,motion:jM(n,l,a)}}const is=Object.freeze({count:[3,8],size:[.05,.8],open:[.03,.6],items:24,head:.4}),sl=(t,[e,o],r)=>Number.isFinite(t)?Math.min(o,Math.max(e,t)):r,ma=t=>Math.round(t*1e4)/1e4;function PM({x:t,y:e,radius:o,squash:r=.38,count:n=8,seed:a=3}){let i=a>>>0||1;const l=()=>(i=i*1664525+1013904223>>>0)/2**32,p=[],c=(s,h,f,m,y,$)=>{const x=[[s,h]];let E=s,v=h,S=f;for(let k=1;k<=y;k++){S+=(l()-.5)*.9;const b=m/y*(.7+.6*l());E+=Math.cos(S)*b,v+=Math.sin(S)*b*r,x.push([E,v]),$<1&&k>1&&k<y&&l()<.28&&c(E,v,S+(l()<.5?-1:1)*(.5+.5*l()),m*(.35+.25*l()),Math.max(2,y-k),$+1)}p.push({pts:x,depth:$})};for(let s=0;s<n;s++)c(t,e,(s+l()*.7)/n*Math.PI*2,o*(.55+.45*l()),7,0);return p}function Bf(t,e){const o=t.slice(1).reduce((i,l,p)=>i+Math.hypot(l[0]-t[p][0],l[1]-t[p][1]),0),r=o*e,n=[t[0]];let a=0;for(let i=1;i<t.length;i++){const l=Math.hypot(t[i][0]-t[i-1][0],t[i][1]-t[i-1][1]);if(a+l>=r){const p=(r-a)/(l||1);return n.push([t[i-1][0]+(t[i][0]-t[i-1][0])*p,t[i-1][1]+(t[i][1]-t[i-1][1])*p]),n}a+=l,n.push(t[i])}return n}function zM({id:t,at:e,duration:o=1.6,u:r,v:n,size:a=.3,squash:i=.38,count:l=6,open:p=.12,color:c="#1a120c",seed:s=3,W:h=1280,H:f=720}){const m=kk(h,f),y=Math.round(sl(l,is.count,6)),$=sl(a,is.size,.3)*h,x=sl(p,is.open,.12),E=Math.max(x+.3,o),v=PM({x:r*h,y:n*f,radius:$,squash:sl(i,[.15,1],.38),count:y,seed:s}),S=Math.max(1.2,h/900),k=[],b=v.filter(C=>C.depth===0),A=v.filter(C=>C.depth>0).slice(0,Math.max(0,is.items-3*b.length)),I=(C,z,N,F,K,_,q=[0,0])=>k.push({id:C,name:z,type:"path",params:{pts:N.map(U=>m.pt(U)),closed:!1},pos:q,rot:0,scale:[1,1],opacity:1,fill:{type:"none"},stroke:{color:K,width:ma(m.len(F)),cap:"round",join:"round",opacity:_}});b.forEach(({pts:C},z)=>{I(`c${z}l`,`crack ${z+1} lip`,Bf(C,.7),S*1.6,"#ffffff",.18,[0,ma(m.len(S*1.4))]),I(`c${z}`,`crack ${z+1}`,C,S,c,.85),I(`c${z}w`,`crack ${z+1} wide`,Bf(C,is.head),S*3.2,c,.9)}),A.forEach(({pts:C},z)=>I(`f${z}`,`crack fork ${z+1}`,C,S*.8,c,.75));let P={id:t,nodeId:"",kind:"image",url:"",volume:0,start:ma(e),duration:ma(E),label:"Nứt nền",motionV:2,posX:0,posY:0,scale:1,opacity:1,shape:{v:2,size:m.size,items:k}};return P={...P,...de(P,"trimEnd",[{time:0,value:0},{time:ma(x),value:1}])},P={...P,...de(P,"opacity",[{time:0,value:1},{time:ma(E*.55),value:.85},{time:ma(E),value:0}])},P}const _f=Object.freeze(["float","turntable","drop-bounce","flip","fly-in","hero-spin","tilt-to-camera","exit-spin"]),LM=Object.freeze({float:4,turntable:6,"drop-bounce":1.2,flip:1,"fly-in":1.2,"hero-spin":1.6,"tilt-to-camera":1,"exit-spin":.9}),Gf=t=>+t.toFixed(3);function NM(t,e){switch(t){case"float":{const r={y:[],ry:[]};for(let n=0;n<=4;n++){const a=n/4;r.y.push({t:a,v:(n%2?-1:1)*.025*e*(n&&n<4?1:0),ease:"ease-in-out"}),r.ry.push({t:a,v:(n%2?1:-1)*8*e*(n&&n<4?1:0),ease:"ease-in-out"})}return r}case"turntable":return{ry:[{t:0,v:0,ease:"linear"},{t:1,v:360*e}]};case"drop-bounce":return{y:[{t:0,v:-.7*e,ease:"ease-in"},{t:.55,v:.025*e,ease:"ease-out"},{t:.78,v:-.02*e,ease:"ease-in-out"},{t:1,v:0}],rz:[{t:0,v:-12*e,ease:"back-out"},{t:.7,v:0}]};case"flip":return{rx:[{t:0,v:0,ease:"back-out"},{t:1,v:360*e}]};case"fly-in":return{depth:[{t:0,v:-25*e,ease:"expo-out",abs:!0},{t:1,v:0,abs:!0}],ry:[{t:0,v:-70*e,ease:"expo-out"},{t:1,v:0}]};case"hero-spin":return{ry:[{t:0,v:-40*e,ease:"expo-out"},{t:1,v:320*e}],zoom:[{t:0,v:.82,ease:"expo-out",abs:!0},{t:1,v:1,abs:!0}]};case"tilt-to-camera":return{rx:[{t:0,v:24*e,ease:"easy-ease"},{t:1,v:0}],ry:[{t:0,v:-28*e,ease:"easy-ease"},{t:1,v:0}]};case"exit-spin":return{ry:[{t:0,v:0,ease:"ease-in"},{t:1,v:540*e}],depth:[{t:0,v:0,ease:"ease-in",abs:!0},{t:1,v:-30*e,abs:!0}]};default:return null}}const FM={rx:"tiltX",ry:"tiltY",rz:"rot"},Kf=t=>t==null?void 0:typeof t=="string"?t:Object.entries(Jt).find(([,e])=>JSON.stringify(e)===JSON.stringify(t))?.[0];function RM(t,e,{at:o=0,duration:r,amount:n=1}={}){const a=NM(e,Math.max(.25,Math.min(3,Number.isFinite(+n)?+n:1)));if(!a)throw Error(`Unknown 3D move: ${e}`);const i=Math.max(.2,Number.isFinite(+r)&&+r>0?+r:LM[e]),l=Math.max(0,+o||0),p=Math.min(t.duration,l+i);if(!(p-l>=.2))throw Error("3D move outside the clip");let c=t;for(const[s,h]of Object.entries(a)){const f=t.kind==="model"?s:FM[s]||s,m=["rx","ry","rz","tiltX","tiltY","rot"].includes(f);let y=Ut(c,f,l);m&&(y=(y%360+540)%360-180);const $=Me(c,f).filter(E=>E.time<l-1/60||E.time>p+1/60).map(E=>({time:E.time,value:E.value,...Kf(E.ease)?{ease:Kf(E.ease)}:{}})),x=h.map(E=>({time:Gf(l+(p-l)*E.t),value:Gf(E.abs?E.v:y+E.v),...E.ease?{ease:E.ease}:{}}));c=li(c,f,[...$,...x].sort((E,v)=>E.time-v.time))}return c}const Zc=Object.freeze({x:"x",y:"y",lift:"depth",scale:"zoom",yaw:"ry",tilt:"rx",roll:"rz"}),DM=(t,e)=>t==="tilt"?90+e:e,BM=(t,e)=>t==="tilt"?e-90:e,_l=t=>Math.round(t*1e3)/1e3;function xC(t,e){const o={};for(const[r,n]of Object.entries(Zc))o[r]=_l(BM(r,Ut(t,n,e)));return o}function MC(t){const e=[];for(const o of Object.values(Zc))for(const r of Me(t,o))e.some(n=>Math.abs(n-r.time)<1/60)||e.push(r.time);return e.sort((o,r)=>o-r)}function _M(t,e,o,r=!1){let n={...t,...Zr(t)};for(const[i,l]of Object.entries(Zc)){const p=e[i];if(typeof p!="number"||!Number.isFinite(p))continue;const c=_l(DM(i,p)),s=r&&!Me(n,l).length?{motionKeys:qr(n,l,[{time:_l(o),value:c}])}:Hc(n,l,c,_l(o));n={...n,...s},l==="depth"&&!Me(n,l).length&&(n.modelDepth=c)}const a={};for(const i of["motionKeys","posX","posY","scale","spatialDepth","modelDepth","modelRotation"])n[i]!==t[i]&&(a[i]=n[i]);return a}function $C(t,e){let o={...t};for(const r of Object.values(Zc)){const n=Me(o,r);n.some(a=>Math.abs(a.time-e)<1/60)&&(o={...o,motionKeys:qr(o,r,n.filter(a=>Math.abs(a.time-e)>=1/60))})}return{motionKeys:o.motionKeys??[]}}const vC=["easy-ease","ease-out","ease-in-out","expo-out","back-out","linear"],EC=["none","elastic","bounce"],GM=Object.freeze({ease:"easy-ease",in:.5,out:.4,settle:"none"}),Nd=t=>({...GM,...t||{}}),SC=t=>{const e=Jt[Nd(t).ease];return Array.isArray(e)&&!(e[0]===0&&e[1]===0&&e[2]===1&&e[3]===1)?[...e]:void 0};function KM(t){const e=Jt[Nd(t).ease];return Array.isArray(e)?{in:+(1-e[2]).toFixed(2),out:+e[0].toFixed(2)}:{in:0,out:0}}const VM=Object.freeze(["hero","icon","broll","motion","text"]),IC=Object.freeze({hero:{name:"Từ nhấn",color:"#ffd23f"},icon:{name:"Icon",color:"#ff7ab6"},broll:{name:"B-roll",color:"#ff9f43"},motion:{name:"Motion",color:"#4fb3ff"},text:{name:"Chữ",color:"#3ddc84"}}),Vf=300,WM=300,XM=/^[A-Za-z0-9_-]{1,40}$/;function HM(t){if(!Array.isArray(t)||t.length>Vf)throw Error(`At most ${Vf} pins`);const e=new Set;for(const o of t){if(!o||typeof o!="object"||Array.isArray(o))throw Error("Invalid pin");if(Object.keys(o).some(r=>!["id","mediaId","from","to","kind","note","materialId","icon","status"].includes(r)))throw Error("Invalid pin field");if(!XM.test(o.id)||e.has(o.id))throw Error("Invalid pin id");if(e.add(o.id),typeof o.mediaId!="string"||!o.mediaId||o.mediaId.length>500)throw Error("Invalid pin media");if(!Number.isInteger(o.from)||!Number.isInteger(o.to)||o.from<0||o.to<o.from||o.to-o.from>80)throw Error("Invalid pin words");if(!VM.includes(o.kind))throw Error("Invalid pin kind");if(o.note!==void 0&&(typeof o.note!="string"||o.note.length>WM))throw Error("Invalid pin note");if(o.materialId!==void 0&&(typeof o.materialId!="string"||o.materialId.length>500))throw Error("Invalid pin material");if(o.icon!==void 0&&(typeof o.icon!="string"||!/^[a-z0-9-]{1,32}$/.test(o.icon)))throw Error("Invalid pin icon");if(o.status!==void 0&&!["idea","done"].includes(o.status))throw Error("Invalid pin status")}return t}function UM(t,e){const o=e?.[t.from],r=e?.[t.to];return o&&r?{start:o.start,end:r.end}:null}const S1=(t,e)=>!t.some(o=>o.nodeId===e&&o.kind!=="audio"&&!o.reverse),I1=(t,e,o)=>t.nodeId!==e||t.kind==="audio"!==o||t.reverse;function Wf(t,e,o){const r=S1(t,e);for(const n of t){if(I1(n,e,r))continue;const a=n.inPoint||0,i=a+Wc(n);if(o>=a-1e-6&&o<i-1e-6)return+(n.start+ja(n,o-a)).toFixed(3)}return null}function AC(t,e,o){const r=(o.start+o.end)/2,n=S1(t,e);for(const a of t){if(I1(a,e,n))continue;const i=a.inPoint||0,l=i+Wc(a);if(r>=i-1e-6&&r<l-1e-6)return+(a.start+ja(a,Math.max(o.start,i)-i)).toFixed(3)}return null}function CC(t,e,o){const r=UM(t,o);if(!r)return null;const n=Wf(e,t.mediaId,r.start),a=Wf(e,t.mediaId,Math.max(r.start,r.end-.02));return n===null&&a===null?null:{start:n??a,end:a!==null?+(a+.02).toFixed(3):n,cut:n===null||a===null}}function YM(t,e=.6){const o=[];let r=0;return(t||[]).forEach((n,a)=>{const i=t[a+1],l=/[.?!…]["'”)]?$/.test(String(n.word).trim()),p=i&&i.start-n.end>=e;(!i||l||p)&&(o.push({from:r,to:a}),r=a+1)}),o}const qM=/\d/,Xf=new Set("và là thì mà của có cho với những các một này đó được không rất cũng như để khi đã đang sẽ vì nên thế nào gì ai đâu bạn mình tôi chúng ta anh em họ nó the a an and or of to in on for with is are was be it this that you we i".split(" ")),ZM=new Set("xin chào cảm ơn hello hi".split(" "));function jC(t,e,{existing:o=[],newId:r}={}){const n=new Set(o.flatMap(l=>Array.from({length:l.to-l.from+1},(p,c)=>l.from+c))),a=r||(()=>{let l=0;return()=>`p${Date.now().toString(36)}${(l++).toString(36)}`})(),i=[];for(const l of YM(t)){const p=Array.from({length:l.to-l.from+1},(y,$)=>l.from+$).filter(y=>!n.has(y)),c=p.find(y=>qM.test(t[y].word));if(c!==void 0){const y=Math.min(l.to,c+(t[c+1]&&/^(%|triệu|tỷ|nghìn|k|đ|đồng|usd|\$)/i.test(t[c+1].word)?1:0));i.push({id:a(),mediaId:e,from:c,to:y,kind:"text",status:"idea"});continue}const s=y=>{const $=String(t[y].word).replace(/[^\p{L}\p{N}]/gu,""),x=$.toLowerCase();return!$||Xf.has(x)||ZM.has(x)?0:cg($)+(y>l.from&&/^\p{Lu}/u.test($)?3:0)+(y-l.from)/(l.to-l.from+1)},h=p.filter(y=>s(y)>=1.5).sort((y,$)=>s($)-s(y))[0],f=y=>String(t[y]?.word??"").replace(/[^\p{L}\p{N}]/gu,""),m=h!==void 0&&h>l.from&&p.includes(h-1)&&/^\p{Ll}/u.test(f(h))&&/^\p{Ll}/u.test(f(h-1))&&!Xf.has(f(h-1).toLowerCase())?h-1:h;h!==void 0&&l.to-l.from>=3&&i.push({id:a(),mediaId:e,from:m,to:h,kind:"hero",status:"idea"})}return i}const Hf=500,JM=60,gc=Object.freeze(["#ffd23f","#ff5d73","#4fb3ff","#3ddc84","#b18cff","#ff9f43"]),Uf=Object.freeze(["beats","bars","drops"]),A1=(t,e)=>t.t-e.t||t.id.localeCompare(e.id),C1=t=>typeof t=="string"?t.trim().slice(0,JM):void 0,j1=t=>{if(typeof t!="number"||!Number.isFinite(t)||t<0||t>Tn)throw Error(`Marker time must be 0–${Tn} s`);return ht(t)};let QM=0;const t$=()=>`m${Date.now().toString(36)}${(QM++).toString(36)}`;function e$(t,{t:e,label:o,color:r,id:n=t$()}={}){const a=j1(e),i=t.find(c=>Math.abs(c.t-a)<1e-6);if(i)return{markers:t,id:i.id,added:!1};if(t.length>=Hf)throw Error(`Tối đa ${Hf} marker`);if(r!==void 0&&!gc.includes(r))throw Error("Màu marker không hợp lệ");const l=C1(o),p={id:n,t:a,...l?{label:l}:{},...r?{color:r}:{}};return{markers:[...t,p].sort(A1),id:n,added:!0}}function o$(t,e,{t:o,label:r,color:n}={}){const a=t.find(l=>l.id===e);if(!a)throw Error(`Không thấy marker ${e}`);if(n!=null&&!gc.includes(n))throw Error("Màu marker không hợp lệ");const i={...a};if(o!==void 0&&(i.t=j1(o)),r!==void 0){const l=C1(r);l?i.label=l:delete i.label}return n!==void 0&&(n?i.color=n:delete i.color),t.map(l=>l.id===e?i:l).sort(A1)}function r$(t,e){if(!t.some(o=>o.id===e))throw Error(`Không thấy marker ${e}`);return t.filter(o=>o.id!==e)}function n$(t,e,{density:o="beats"}={}){const r={beat:0,bar:1,drop:2},n=new Map;for(const a of t??[]){if(a.disabled||a.reverse)continue;const i=e?.find(h=>h.id===a.nodeId)?.beats;if(!Array.isArray(i?.beats)||!((i.confidence??0)>=qc))continue;const l=Number(a.playbackRate)||1,p=Number(a.inPoint)||0,c=p+a.duration*l,s=[["drop",i.drops],...o==="drops"?[]:[["bar",i.downbeats]],...o==="beats"?[["beat",i.beats]]:[]];for(const[h,f]of s)for(const m of Array.isArray(f)?f:[]){if(m<p-1e-6||m>=c-1e-6)continue;const y=ht(a.start+(m-p)/l),$=y.toFixed(3),x=n.get($);(!x||r[h]>r[x.kind])&&n.set($,{t:y,kind:h})}}return[...n.values()].sort((a,i)=>a.t-i.t)}function TC(t,e=[]){return[...new Set([...(t??[]).map(o=>o.t),...e.map(o=>o.t)])].sort((o,r)=>o-r)}function OC(t,e,{pps:o,px:r=8}){let n=null;for(const a of t)(n===null||Math.abs(a-e)<Math.abs(n-e))&&(n=a);return n!==null&&Math.abs(n-e)*o<r?n:null}function a$(t,e){const o=t.start+.03333333333333333-1e-6,r=t.start+t.duration-1/30+1e-6;return e.filter(n=>n>o&&n<r).sort((n,a)=>n-a)}const Do=t=>Object.freeze(t),Oi=Object.freeze({white:Do({vi:"Chớp trắng",en:"White flash",fx:[["exposure",[[0,1,"hold"],[1,.75,"ease-out"],[5,0]]]]}),"white-double":Do({vi:"Chớp trắng 2 lần",en:"Double white flash",fx:[["exposure",[[0,1,"hold"],[1,0,"hold"],[2,1,"hold"],[3,.7,"ease-out"],[7,0]]]]}),pop:Do({vi:"Bật sáng",en:"Exposure pop",fx:[["exposure",[[0,.55,"ease-out"],[6,0]]]]}),negative:Do({vi:"Âm bản 2 khung",en:"Negative (2 frames)",fx:[["invert",[[0,1,"hold"],[2,0]]]]}),"negative-double":Do({vi:"Âm bản nháy đôi",en:"Double negative",fx:[["invert",[[0,1,"hold"],[2,0,"hold"],[5,1,"hold"],[7,0]]]]}),"negative-blink":Do({vi:"Âm bản 1 khung",en:"Negative blink (1 frame)",fx:[["invert",[[0,1,"hold"],[1,0]]]]}),"luma-negative":Do({vi:"Âm bản giữ màu",en:"Hue-keeping negative",fx:[["luma-invert",[[0,1,"hold"],[3,0]]]]}),"flash-negative":Do({vi:"Loé + âm bản",en:"Flash + negative",fx:[["exposure",[[0,.7,"hold"],[1,0,"hold"],[2,.5,"hold"],[3,0]]],["luma-invert",[[0,1,"hold"],[3,0]]]]}),strobe:Do({vi:"Nháy strobe",en:"Strobe",fx:[["exposure",[[0,1,"hold"],[2,0,"hold"],[4,1,"hold"],[6,0,"hold"],[8,1,"hold"],[10,0]]]]}),glow:Do({vi:"Bùng sáng toả",en:"Glow burst",fx:[["glow",[[0,1,"ease-out"],[9,0]]],["exposure",[[0,.45,"ease-out"],[4,0]]]]}),rgb:Do({vi:"Giật tách màu",en:"RGB hit",fx:[["rgb-split",[[0,1,"ease-out"],[6,0]]]]}),blur:Do({vi:"Nhoè giật",en:"Blur hit",fx:[["blur",[[0,.8,"ease-out"],[6,0]]]]}),threshold:Do({vi:"Đen trắng gắt 2 khung",en:"Hard black & white (2 frames)",fx:[["threshold",[[0,.5,"hold"],[2,0]]]]}),"threshold-blink":Do({vi:"Đen trắng gắt 1 khung",en:"Hard black & white blink (1 frame)",fx:[["threshold",[[0,.5,"hold"],[1,0]]]]}),"poster-bw":Do({vi:"Đen trắng 3 tông 3 khung",en:"Three-tone black & white (3 frames)",fx:[["mono",[[0,1,"hold"],[3,0]]],["posterize",[[0,1,"hold"],[3,0]]]]})}),i$=Object.freeze(Object.keys(Oi)),T1=30,Yf=32,s$=t=>(Math.max(...Oi[t].fx.map(([,e])=>e.at(-1)[0]))+1)/T1;function l$(t,e=1){const o=Oi[t];if(!o)throw Error(`addFlash style: ${i$.join("|")}`);if(!Number.isFinite(e)||e<.1||e>1)throw Error("addFlash strength: 0.1..1");return o.fx.map(([r,n])=>{if(!Object.hasOwn(tc,r))throw Error(`Unknown effect ${r}`);return{type:r,amount:1,keys:n.map(([a,i,l])=>({time:+(a/T1).toFixed(4),value:+Math.min(1,i*e).toFixed(3),...l?{ease:Jt[l]}:{}}))}})}const De=(t,e)=>({id:Da(t),rot:0,scale:[1,1],opacity:1,...e}),dr=t=>({type:"color",color:t}),Kn={type:"none"},Vn=(t,e,o={})=>({color:t,width:e,cap:"round",join:"round",...o});function $r(t){const e=[];for(const o of t)e.push({...o,id:Da(e)});return{v:2,items:e}}const Fd={callout:{vi:"Callout",en:"Callout",build:({color:t})=>$r([De([],{name:"Khung",type:"rect",params:{w:520,h:240,round:36},pos:[500,440],fill:dr(t),stroke:null}),De([],{name:"Đuôi",type:"path",params:{pts:[[-40,-30],[40,-30],[-30,60]],closed:!0},pos:[420,590],fill:dr(t),stroke:null})])},"chat-bubble":{vi:"Bong bóng chat",en:"Chat bubble",build:({color:t})=>$r([De([],{name:"Bóng",type:"rect",params:{w:560,h:260,round:130},pos:[500,450],fill:dr(t),stroke:null}),De([],{name:"Đuôi",type:"path",params:{pts:[[-20,-60],[60,-40,0,0,-20,40],[-70,60]],closed:!0},pos:[330,600],fill:dr(t),stroke:null})])},badge:{vi:"Huy hiệu",en:"Badge",build:({color:t,accent:e})=>$r([De([],{name:"Răng cưa",type:"star",params:{points:16,outer:260,inner:225,round:6},pos:[500,500],fill:dr(t),stroke:null}),De([],{name:"Lõi",type:"ellipse",params:{w:380,h:380},pos:[500,500],fill:Kn,stroke:Vn(e,10)})])},"lower-third":{vi:"Lower third",en:"Lower third",build:({color:t,accent:e})=>$r([De([],{name:"Vạch nhấn",type:"rect",params:{w:22,h:150,round:4},pos:[-60,790],fill:dr(e),stroke:null}),De([],{name:"Nền chữ",type:"rect",params:{w:780,h:150,round:8},pos:[350,790],fill:{type:"linear",stops:[[t,0],[t,.6],["#0d0f12",1]],angle:0,opacity:.92},stroke:null}),De([],{name:"Dòng phụ",type:"rect",params:{w:420,h:56,round:6},pos:[170,895],fill:dr("#0d0f12"),stroke:null})])},"progress-bar":{vi:"Thanh tiến trình",en:"Progress bar",build:({color:t,duration:e})=>{const o=$r([De([],{name:"Rãnh",type:"rect",params:{w:800,h:44,round:22},pos:[500,500],fill:dr("#1f2622"),stroke:null}),De([],{name:"Tiến trình",type:"rect",params:{w:800,h:44,round:22},pos:[500,500],fill:dr(t),stroke:null})]),r=+Math.max(.2,e).toFixed(3),n=o.items[1];return n.keys={"params.w":[{time:0,value:44,ease:[.33,0,.67,1]},{time:r,value:800}],"pos.0":[{time:0,value:122,ease:[.33,0,.67,1]},{time:r,value:500}]},o}},starburst:{vi:"Tia nổ",en:"Starburst",build:({color:t})=>$r([De([],{name:"Tia",type:"star",params:{points:18,outer:300,inner:170,round:0},pos:[500,500],fill:dr(t),stroke:null})])},"loading-ring":{vi:"Vòng loading",en:"Loading ring",build:({color:t,duration:e})=>{const o=$r([De([],{name:"Rãnh",type:"ellipse",params:{w:300,h:300},pos:[500,500],fill:Kn,stroke:Vn("#1f2622",26)}),De([],{name:"Vòng chạy",type:"ellipse",params:{w:300,h:300},pos:[500,500],fill:Kn,stroke:Vn(t,26,{dash:[260,700]})})]),r=+Math.max(.2,e).toFixed(3);return o.items[1].keys={rot:[{time:0,value:0},{time:r,value:Math.min(3600,Math.round(r)*360||360)}]},o}},"photo-frame":{vi:"Khung ảnh",en:"Photo frame",build:({color:t,accent:e})=>$r([De([],{name:"Viền ngoài",type:"rect",params:{w:760,h:520,round:12},pos:[500,500],fill:Kn,stroke:Vn(t,28,{join:"miter",cap:"butt"})}),De([],{name:"Viền trong",type:"rect",params:{w:690,h:450,round:6},pos:[500,500],fill:Kn,stroke:Vn(e,4,{join:"miter",cap:"butt"})})])},"arrow-curved":{vi:"Mũi tên cong",en:"Curved arrow",build:({color:t})=>$r([De([],{name:"Thân",type:"path",params:{pts:[[-280,160],[0,-120,-200,40,200,-40],[260,-40]],closed:!1},pos:[500,520],fill:Kn,stroke:Vn(t,22)}),De([],{name:"Đầu",type:"path",params:{pts:[[-60,-70],[0,0],[-80,40]],closed:!1},pos:[760,480],fill:Kn,stroke:Vn(t,22)})])},"arrow-bold":{vi:"Mũi tên đậm",en:"Bold arrow",build:({color:t})=>$r([De([],{name:"Mũi tên",type:"path",params:{pts:[[-320,-60],[80,-60],[80,-160],[320,0],[80,160],[80,60],[-320,60]],closed:!0},pos:[500,500],fill:dr(t),stroke:null})])},"hand-underline":{vi:"Gạch chân vẽ tay",en:"Hand-drawn underline",build:({color:t,duration:e})=>{const o=$r([De([],{name:"Nét",type:"path",params:{pts:[[-380,10],[0,-6,-150,10,150,-14],[380,4]],closed:!1},pos:[500,620],fill:Kn,stroke:Vn(t,18),ops:[{...ys("wiggle"),size:8,detail:24,speed:0,seed:3},{...ys("trim"),start:0,end:1,offset:0}]})]);return o.items[0].keys={"ops.1.end":[{time:0,value:0,ease:[0,0,.58,1]},{time:+Math.min(.6,Math.max(.1,e)).toFixed(3),value:1}]},o}},"price-tag":{vi:"Nhãn giá",en:"Price tag",build:({color:t})=>$r([De([],{name:"Nhãn",type:"path",params:{pts:[[-300,-120],[180,-120],[300,0],[180,120],[-300,120]],closed:!0},pos:[500,500],fill:dr(t),stroke:null,ops:[{...ys("round"),radius:24}]}),De([],{name:"Lỗ",type:"ellipse",params:{w:48,h:48},pos:[740,500],fill:dr("#000000"),stroke:null,ops:[{...ys("merge"),mode:"subtract"}]})])}},PC=Object.keys(Fd),c$={Khung:"Box",Đuôi:"Tail",Bóng:"Bubble","Răng cưa":"Burst",Lõi:"Ring","Vạch nhấn":"Accent bar","Nền chữ":"Title bar","Dòng phụ":"Subtitle bar",Rãnh:"Track","Tiến trình":"Progress",Tia:"Rays","Vòng chạy":"Spinner","Viền ngoài":"Outer frame","Viền trong":"Inner frame",Thân:"Shaft",Đầu:"Head","Mũi tên":"Arrow",Nét:"Stroke",Nhãn:"Tag",Lỗ:"Hole"};function p$(t,{color:e="#c6f432",accent:o="#2bd4c9",duration:r=5,en:n=!1}={}){const a=Fd[t];if(!a)throw Error(`Unknown library shape "${t}"`);const i=a.build({color:e,accent:o,duration:r});if(n)for(const l of i.items)l.name=c$[l.name]??l.name;return He(i)}const O1={smooth:["Mịn da","Smooth skin"],even:["Đều màu da","Even skin tone"],brighten:["Sáng da mặt","Brighter face"],eyes:["Mắt sáng","Bright eyes"]},ll=Object.freeze({smooth:.5,brighten:.4,even:.3,eyes:!0}),u$=new Set(Object.values(O1).flat().map(t=>`✨ ${t}`)),d$=t=>u$.has(t?.name),ga=t=>+t.toFixed(3),Tp=(t,e)=>{const o=Number(t);return Number.isFinite(o)?Math.max(0,Math.min(1,o)):e};function h$(t={}){return{smooth:Tp(t.smooth,ll.smooth),brighten:Tp(t.brighten,ll.brighten),even:Tp(t.even,ll.even),eyes:t.eyes==null?ll.eyes:t.eyes===!0||t.eyes==="true"||Number(t.eyes)>0}}function f$(t,e="vi"){const o=p=>`✨ ${O1[p][e==="en"?1:0]}`,{smooth:r,brighten:n,even:a,eyes:i}=t,l=[];return r>0&&l.push({name:o("smooth"),shape:"skin",fx:{type:"denoise",amount:ga(Math.min(1,.45+.6*r)),size:ga(Math.min(1,.45+.6*r))},blur:ga(.1*r),contrast:ga(1-.06*r)}),a>0&&l.push({name:o("even"),shape:"skin",saturation:ga(1-.2*a)}),n>0&&l.push({name:o("brighten"),shape:"face",exposure:ga(.05+.3*n),contrast:ga(1-.06*n)}),i&&(r>0||n>0)&&l.push({name:o("eyes"),shape:"eyes",exposure:.08,contrast:1.1,sharpen:30}),l}const Je=t=>Math.round(t*1e4)/1e4,Na=(t,e,o,r)=>Number.isFinite(t)?Math.min(o,Math.max(e,t)):r,m$=t=>t*t*(3-2*t),Jc=Object.freeze({flipKeys:16,auraColors:["#ffd23f","#7dff6a","#3ff2ff","#e85dff"],maxHits:8}),g$=(t,e=16,o=9)=>{const r=Math.abs(t%180)*Math.PI/180,n=Math.min(r,Math.PI-r);return Math.cos(n)+Math.max(e/o,o/e)*Math.sin(n)};function y$(t,{from:e=0,to:o=.6,turn:r=180,back:n=!1,W:a=1280,H:i=720}={}){const l=Zr(t),p={...t,...l};if(e=Math.max(0,Math.min(t.duration,e)),o=Math.max(e,Math.min(t.duration,o)),o-e<.15)throw Error("worldFlip needs at least 0.15 s");r=Na(r,-720,720,180);const c=Jc.flipKeys,s=Array.from({length:c+1},(v,S)=>Je(e+(o-e)*S/c)),h=v=>n?r*Math.sin(Math.PI*v):r*m$(v),f=v=>Ut(p,"rot",v),m=v=>Ut(p,"zoom",v),y=v=>Me(p,v).filter(S=>S.time<e-1e-6||S.time>o+1e-6),$=s.map((v,S)=>({time:v,value:Je(f(v)+h(S/c))})),x=s.map((v,S)=>{const k=g$(h(S/c),a,i);return{time:v,value:Je(m(v)*(k>1+1e-6?k*1.01:1))}});let E=qr(p,"rot",[...y("rot"),...$].sort((v,S)=>v.time-S.time));return E=qr({...p,motionKeys:E},"zoom",[...y("zoom"),...x].sort((v,S)=>v.time-S.time)),{...l,motionKeys:E,rotFit:"frame"}}function qf(t,e){const o=Math.min(pg,Math.max(2,Math.round(t*3)+1)),r=Array.from({length:o},(a,i)=>({time:Je(t*i/(o-1)),value:Je(.5-.5*Math.cos(2*Math.PI*i/(o-1)))}));return[{type:"glow",amount:1},...e?[{type:"invert",amount:1}]:[{type:"blur",amount:.25}],{type:"hue",amount:0,keys:r},{type:"light-burst",amount:.7}].slice(0,kn)}function b$(t,e,{start:o,duration:r,color:n=Jc.auraColors[0],silhouette:a=!1}={}){const i=Math.max(t.start,o??t.start),l=Math.min(t.start+t.duration,i+(r??t.start+t.duration-i));if(!(l-i>.2))throw Error("personAura must lie inside the person clip");const p=Je(l-i),c=Je((t.inPoint||0)+(i-t.start)*(t.playbackRate||1)),s=t.scale??1,h=P1(t,i,p),f=Math.min(30,Math.max(3,Math.round(p*4)+1)),m={...t,...h,motionKeys:h.motionKeys??[],scale:h.scale??s},y=Array.from({length:f},(v,S)=>Je(p*S/(f-1)));let $=qr(m,"zoom",y.map((v,S)=>({time:v,value:Je(Ut(m,"zoom",v)*(1.035+.025*Math.sin(S*1.7)))})));$=qr({...m,motionKeys:$},"opacity",y.map((v,S)=>({time:v,value:S===0||S===f-1?0:.92})));const x=Nn(t,e(),{start:Je(i),duration:p,inPoint:c,label:`${t.label||"Video"} · hào quang`,...h,motionV:2,motionKeys:$,edge:mu({color:n,width:.03,glow:2,amount:1}),effects:qf(p,!1)});delete x.impacts;const E=Nn(t,e(),{start:Je(i),duration:p,inPoint:c,label:`${t.label||"Video"} · ${a?"bóng màu":"người nét"}`,...h,...a?{effects:qf(p,!0).filter(v=>v.type!=="light-burst")}:{}});return a||delete E.effects,h.motionKeys||delete E.motionKeys,delete E.impacts,delete E.edge,[x,E]}function P1(t,e,o){if(!t.motionKeys?.length)return{motionKeys:void 0};const r=Ol(t,e-t.start,o),n={motionV:2,motionKeys:r.motionKeys};for(const a of["posX","posY","scale"])r[a]!==void 0&&(n[a]=r[a]);return n}const z1=(t,e,{at:o,u:r,v:n,size:a=1,duration:i,label:l,params:p={}})=>{const c=Yi.find(s=>s.id===e);return{id:t,nodeId:"",kind:"image",url:"",volume:0,start:Je(Math.max(0,o)),duration:Je(i??c.duration),label:l,motionV:2,posX:Je(r-.5),posY:Je(n-.5),scale:Je(Na(a,.2,3,1)),motion:Jo({code:`@preset:${e}`,params:{...c.params,...p},preset:e})}},w$=({id:t,at:e,u:o,v:r,angle:n=200,length:a=1,size:i=1,duration:l=1.6,color:p})=>z1(t,"vfx-breath-mist",{at:e,u:o,v:r,size:i,duration:l,label:"Hơi thở",params:{angle:Na(n,-360,360,200),length:Na(a,.2,3,1),seed:Math.round(e*1e3)%997+1,...p?{color:p}:{}}}),k$=({id:t,at:e,u:o,v:r,size:n=1,color:a})=>({...z1(t,"vfx-light-pillar",{at:e,u:.5,v:.5,size:1,label:"Cột sáng",params:{x:Je(Na(o,0,1,.5)),y:Je(Na(r,0,1,.5)),size:Je(Na(n,.2,3,1)),seed:Math.round(e*1e3)%997+1,...a?{color:a}:{}}})});function x$(t){const e=(Array.isArray(t.hits)?t.hits:Number.isFinite(t.at)?[t.at]:[]).filter(Number.isFinite).slice(0,Jc.maxHits),o=Array.isArray(t.hitPoint)?{point:t.hitPoint}:{},r=[{op:"setEffect",clipId:t.clipId,property:"fisheye",numberValue:.45},{op:"setEffect",clipId:t.clipId,property:"dispersion",numberValue:.6}];t.flip&&r.push({op:"worldFlip",clipId:t.clipId,...Number.isFinite(t.flipAt)?{at:t.flipAt}:{}});for(const n of e)r.push({op:"addImpact",clipId:t.clipId,at:n,pillars:!0,...o});return e.length&&r.push({op:"lightBurst",clipId:t.clipId,hits:e}),r.push({op:"personAura",clipId:t.clipId,...e.length?{start:Math.max(...e)}:{},...t.silhouette?{silhouette:!0}:{}}),r}function M$(t,e){const o=[];for(const r of[...e].sort((n,a)=>n-a)){const n=r-t.start;for(const[a,i]of[[-.06,0],[0,1],[.18,.55],[.5,0]]){const l=Je(n+a);l>=0&&l<=t.duration&&(!o.length||l-o.at(-1).time>=1/60)&&o.push({time:l,value:i})}}return o.slice(0,pg)}const ia=Object.freeze({maxLines:200,maxChars:2e4,minCoverage:.6,tieCoverage:.08,maxPause:.45,pause:.2,lead:.08,tail:.15,minRate:.85,maxRate:1.25,rateStep:.03,snap:1.2}),Uu="\\d+(?:[.,]\\d+)?",$$="(?:\\d{1,2}:)?\\d{1,2}:\\d{2}(?:[.,]\\d+)?",Zf=`(?:${$$}|${Uu})`,yc="\\s*(?:s|sec|secs|giây|seconds?)\\b",v$=new RegExp(`(${Zf})(?:${yc})?\\s*(?:-|–|—|→|->|~|đến|to)\\s*(${Zf})(?:${yc})?`,"iu"),E$=new RegExp(`[([]\\s*(${Uu})${yc}\\s*[)\\]]|^\\s*(${Uu})${yc}\\s*[:\\-–—]`,"iu"),Op=/^\s*(?:\*\*)?(?:cảnh|canh|scene|shot|câu|cau|line|đoạn|doan|vo|lời|loi|thoại|thoai|voice ?over|narration|mc|host)\s*\d*\s*(?:\*\*)?\s*[:.\-–—)]\s*/iu,cl=/lời|loi|thoại|thoai|voice|\bvo\b|nói|noi|script|kịch bản|kich ban|text|nội dung|noi dung|dialog|narration/iu,Pp=/giây|giay|thời gian|thoi gian|time|tc\b|timecode|\bs\b|duration|độ dài|do dai/iu;function Jf(t){const e=String(t).trim().replace(",",".");return e.includes(":")?e.split(":").reduce((o,r)=>o*60+Number(r),0):Number(e)}const pl=t=>String(t).replace(/\*\*|__|`/g,"").replace(/^[\s|"“”'‘’«»>*•\-–—]+|[\s"“”'‘’«»]+$/g,"").replace(/\s{2,}/g," ").trim();function zp(t){const e=v$.exec(t);if(e){const r=Jf(e[1]),n=Jf(e[2]);if(Number.isFinite(r)&&n>r)return{time:{start:r,end:n},rest:t.replace(e[0]," ")}}const o=E$.exec(t);if(o){const r=Number(String(o[1]??o[2]).replace(",","."));if(r>0)return{time:{duration:r},rest:t.replace(o[0]," ")}}return{time:null,rest:t}}const S$=t=>t.includes(" ")?t.split(" "):t.trim().startsWith("|")?t.trim().replace(/^\||\|$/g,"").split("|"):null,ul=t=>/\p{L}{2}/u.test(t);function Qf(t){const o=String(t??"").slice(0,ia.maxChars).replace(/\r\n?/g,`
|
|
98
|
+
`).split(`
|
|
99
|
+
`),r=o.map(S$);let n=-1,a=-1;const i=r.filter(c=>c&&c.length>1&&!c.every(s=>/^\s*:?-{2,}:?\s*$/.test(s)));if(i.length){const c=i[0],s=i.length>=2&&c.every(f=>!/\d/.test(f)||Pp.test(f))&&c.some(f=>cl.test(f)||Pp.test(f));s&&(n=c.findIndex(f=>cl.test(f)),a=c.findIndex(f=>Pp.test(f)&&!cl.test(f)));const h=s?i.slice(1):i;if(n<0){const f=Math.max(...h.map(y=>y.length)),m=y=>h.reduce(($,x)=>$+(ul(x[y]??"")?x[y].length:0),0);n=[...Array(f).keys()].filter(y=>y!==a).sort((y,$)=>m($)-m(y))[0]??0}}const l=[];let p=null;for(const[c,s]of o.entries()){const h=r[c];if(h&&h.length>1){if(h.every(b=>/^\s*:?-{2,}:?\s*$/.test(b)))continue;const x=pl(h[n]??"");if(!x||cl.test(x)&&x.split(/\s+/).length<=3&&i[0]===h)continue;let E=null;for(const[b,A]of h.entries()){if(b===n)continue;const I=zp(A).time;if(I){E=I;break}}!E&&a>=0&&/^\s*\d+(?:[.,]\d+)?\s*$/.test(h[a]??"")&&(E={duration:Number(h[a].replace(",","."))});const{time:v,rest:S}=zp(x),k=pl(S.replace(Op,""));ul(k)&&l.push({text:k,...v??E??{}});continue}if(!s.trim()||/^\s*(#{1,6}\s|={3,}|-{3,}\s*$)/.test(s)&&!ul(s.replace(/^#+/,"").trim())||/^\s*#{1,6}\s/.test(s))continue;const{time:f,rest:m}=zp(s);if(!f&&/\p{Lu}/u.test(s)&&s===s.toUpperCase()&&s.trim().split(/\s+/).length<=4)continue;let y=pl(m.replace(Op,"").replace(Op,""));const $=/(?:lời|loi|thoại|thoai|vo|voice ?over)\s*[::]\s*(.+)$/iu.exec(m);if($&&(y=pl($[1])),!ul(y)){f&&(p=f);continue}if(l.push({text:y,...f??p??{}}),p=null,l.length>=ia.maxLines)break}return l.slice(0,ia.maxLines).map(c=>{const s={text:c.text.slice(0,600)};return Number.isFinite(c.start)&&Number.isFinite(c.end)&&c.end>c.start?(s.start=+c.start.toFixed(3),s.end=+c.end.toFixed(3),s.duration=+(c.end-c.start).toFixed(3)):c.duration>0&&(s.duration=+c.duration.toFixed(3)),s})}const I$=t=>String(t).split(/\s+/).filter(e=>!Ks(e)).map(Zi).filter(Boolean);function A$(t,e){if(t===e)return 2;if(t.length<3||e.length<3)return 0;if(t.startsWith(e)||e.startsWith(t))return 1;if(Math.abs(t.length-e.length)>1)return 0;let o=0,r=0,n=0;for(;o<t.length&&r<e.length;){if(t[o]===e[r]){o++,r++;continue}if(++n>1)return 0;t.length>e.length?o++:(e.length>t.length||o++,r++)}return n+(t.length-o)+(e.length-r)<=1?1:0}const C$=2,j$=1,T$=-1,O$=-1,P$=-.5;function tm(t,e,o,r){const n=t.length,a=r-o;if(!n||a<=0)return null;let i=new Float64Array(a+1),l=new Float64Array(a+1);const p=new Uint8Array((n+1)*(a+1)),c=new Uint8Array((n+1)*(a+1));let s=0,h=0,f=0;for(let E=1;E<=n;E++){l[0]=0;for(let v=1;v<=a;v++){const S=A$(t[E-1],e[o+v-1]),k=i[v-1]+(S===2?C$:S===1?j$:T$),b=i[v]+O$,A=l[v-1]+P$;let I=0,P=0;k>I&&(I=k,P=1),b>I&&(I=b,P=2),A>I&&(I=A,P=3),l[v]=I,p[E*(a+1)+v]=P,c[E*(a+1)+v]=P===1?S:0,I>s&&(s=I,h=E,f=v)}[i,l]=[l,i]}if(s<=0)return null;let m=h,y=f,$=0,x=f;for(;m>0&&y>0;){const E=p[m*(a+1)+y];if(E===0)break;E===1?($+=c[m*(a+1)+y]/2,x=y,m--,y--):E===2?m--:y--}return{score:s,a:o+x-1,b:o+f-1,matched:$,coverage:$/n}}function z$(t,e,o=e.map(r=>Zi(r.word))){const r=I$(t.text??t);if(!r.length)return[];const n=r.length+Math.ceil(r.length*.3)+2,a=new Set(r.slice(0,3)),i=new Set(r.slice(-3)),l=[],p=s=>{if(!s||s.coverage<ia.minCoverage)return;const h=l.find(f=>s.a<=f.b&&s.b>=f.a);h?s.score>h.score&&Object.assign(h,s):l.push(s)},c=s=>l.some(h=>s>h.a&&s<=h.b);for(let s=0;s<o.length;s++)a.has(o[s])&&!c(s)&&p(tm(r,o,s,Math.min(o.length,s+n))),i.has(o[s])&&!c(s)&&p(tm(r,o,Math.max(0,s-n+1),s+1));return l.sort((s,h)=>s.a-h.a)}function L$(t,{maxPause:e=ia.maxPause}={}){const o=(Array.isArray(t)?t:[]).filter(l=>Number.isFinite(l?.start)&&Number.isFinite(l?.end)&&!Ks(l.word)).sort((l,p)=>l.start-p.start);if(o.length<12)return null;let r=0,n=o[0].start;const a=[];for(let l=1;l<=o.length;l++){const p=l<o.length?o[l].start-o[l-1].end:1/0;p>e&&(r+=o[l-1].end-n,l<o.length&&(p<3&&a.push(p),n=o[l].start))}if(!(r>0))return null;a.sort((l,p)=>l-p);const i=a.length?a[a.length>>1]:ia.pause;return{wordsPerSecond:+(o.length/r).toFixed(3),pause:+Math.min(.8,Math.max(.12,i)).toFixed(3)}}const dl=(t,e,o)=>Math.min(o,Math.max(e,t)),er=t=>+t.toFixed(3);function N$(t,e,o={}){const r={...ia,...o.maxPause?{maxPause:dl(o.maxPause,.2,3)}:{}},n=o.pace??null;n?.pause&&(r.pause=dl(n.pause,.12,.6),r.maxPause=o.maxPause?r.maxPause:Math.max(.3,r.pause*1.6));const a=o.cutPauses!==!1,i=o.speed!==!1,l=new Set(o.skip??[]),p=(Array.isArray(e)?e:[]).filter(E=>Number.isFinite(E?.start)&&Number.isFinite(E?.end)&&E.end>=E.start&&!Ks(E.word)).sort((E,v)=>E.start-v.start),c=p.map(E=>Zi(E.word)),s=(Array.isArray(o.silences)?o.silences:[]).filter(E=>E&&E.kind!=="filler"&&Number.isFinite(E.start)&&E.end>E.start).sort((E,v)=>E.start-v.start),h=E=>s.find(v=>v.start>=E-.05&&v.start<=E+r.snap),f=E=>[...s].reverse().find(v=>v.end<=E+.05&&v.end>=E-r.snap),m=(E,v)=>s.find(S=>S.start<v&&S.end>E),y=[],$=[];for(const[E,v]of t.entries()){const S={index:E,text:v.text,...v.duration?{target:v.duration}:{}};if(l.has(E)){$.push({...S,status:"skipped"});continue}const k=z$(v,p,c);if(!k.length){$.push({...S,status:"missing",takes:0});continue}const b=k.filter(D=>!y.some(H=>D.a<=H.b&&D.b>=H.a)),A=b.length?b:k,I=Math.max(...A.map(D=>D.coverage)),P=A.filter(D=>D.coverage>=I-r.tieCoverage).at(-1);y.push(P);const C=p.slice(P.a,P.b+1),z=p[P.a-1],N=p[P.b+1],F=(D,H)=>p.filter((ut,gt)=>(gt<P.a||gt>P.b)&&ut.end>D+.02&&ut.start<H-.02).length;let K=f(C[0].start),_=h(C.at(-1).end);K&&F(K.end,C[0].start)>0&&(K=null),_&&F(C.at(-1).end,_.start)>2&&(_=null);const q=K?Math.max(K.start,K.end-Math.min(r.lead,(K.end-K.start)/2)):Math.max(C[0].start-r.lead,z?z.end+.02:0,0),U=_?Math.min(_.end,_.start+Math.min(r.tail,(_.end-_.start)/2)):Math.min(C.at(-1).end+r.tail,N?N.start-.02:1/0),rt=[];let ot=q,G=0,J=0;for(let D=1;D<C.length;D++){const H=C[D].start-C[D-1].end;if(a&&H>r.maxPause){const ut=m(C[D-1].end,C[D].start),gt=ut?Math.max(ut.start,C[D-1].end):C[D-1].end,xt=ut?Math.min(ut.end,C[D].start):C[D].start;if(xt-gt<=r.pause)continue;const u=r.pause/2;rt.push({start:er(ot),end:er(gt+u)}),ot=xt-u,G++,J+=xt-gt-r.pause}}rt.push({start:er(ot),end:er(U)});const Z=rt.reduce((D,H)=>D+H.end-H.start,0);let at=1;if(i&&v.duration>0)at=dl(Z/v.duration,r.minRate,r.maxRate);else if(i&&n?.wordsPerSecond){const D=rt.reduce((H,ut)=>H+ut.end-ut.start,0)-(r.lead+r.tail);D>.5&&(at=dl(n.wordsPerSecond/(C.length/D),r.minRate,r.maxRate))}Math.abs(at-1)<r.rateStep&&(at=1),at=+at.toFixed(2),$.push({...S,status:"ok",takes:k.length,take:k.indexOf(P),coverage:+P.coverage.toFixed(2),source:{start:er(q),end:er(U)},heard:C.map(D=>D.word).join(" "),pieces:rt,pausesCut:G,pauseSaved:er(J),rate:at,natural:er(Z),final:er(Z/at)})}const x=$.filter(E=>E.status==="ok");for(const E of x)for(const v of x){if(E===v||!(v.source.start<E.source.end&&v.source.start>=E.source.start))continue;const S=v.pieces[0];E.source.end>=S.end-.05||(S.start=v.source.start=er(E.source.end),v.natural=er(v.pieces.reduce((k,b)=>k+b.end-b.start,0)),v.final=er(v.natural/v.rate))}return{lines:$,found:x.length,missing:$.filter(E=>E.status==="missing").length,length:er(x.reduce((E,v)=>E+v.final,0)),pause:r.pause,maxPause:r.maxPause,...n?{pace:n}:{}}}const F$=t=>t.label||t.id;function R$(t,e,o,r={}){const n=r.tracks??{},a=r.makeId??(()=>Math.random().toString(36).slice(2,10)),i=r.maxClips??Cs,l=r.isBed??(b=>b.kind==="audio"),p=t.find(b=>b.id===e);if(!p||!["video","audio"].includes(p.kind))throw Error("Script edit needs the talking video or audio clip");if(p.reverse)throw Error("Script edit does not support reversed clips");if(Hr(p)||p?.timeRemap)throw Error("Script edit does not support speed-ramped or time-remapped clips");if(Array.isArray(p.motionKeys)&&p.motionKeys.length)throw Error("The clip has keyframes — run the script edit on the raw clip, before animating it");if(n[p.track]?.locked)throw Error("Track is locked");const c=o.lines.filter(b=>b.status==="ok");if(!c.length)throw Error("No script line was found in the clip");const s=p.start+p.duration,h=t.filter(b=>b.id!==p.id&&b.nodeId===p.nodeId&&b.track!==p.track&&Math.abs(b.start-p.start)<1/30&&Math.abs(b.duration-p.duration)<1/30&&!b.reverse),f=new Set(h.map(b=>b.id)),m=t.filter(b=>b.id!==p.id&&!f.has(b.id)&&b.track!==p.track&&!l(b)&&b.start<s-1/60&&b.start+b.duration>p.start+1/60);if(m.length)throw Error(`Layers over the clip would lose their place: ${m.slice(0,3).map(F$).join(", ")} — run the script edit before adding titles / B-roll`);if(t.some(b=>n[b.track]?.locked&&b.start>=s-1/60))throw Error("A locked track has clips after the clip");const y=c.flatMap(b=>b.pieces.map(A=>({...A,rate:b.rate,line:b.index}))),$=(y.length-1)*(1+h.length);if(t.length+$>i)throw Error(`Too many clips: the script edit needs ${y.length} pieces (limit ${i})`);const x=(b,A)=>{let I=p.start;return y.map((P,C)=>{const z=ht((P.end-P.start)/P.rate),N={...b,id:C===0?A:a(),start:ht(I),inPoint:er(P.start),duration:z,playbackRate:P.rate};return N.playbackRate===1&&delete N.playbackRate,I+=z,N})},E=x(p,p.id),v=E.reduce((b,A)=>b+A.duration,0),S=ht(v-p.duration);return{clips:t.flatMap(b=>b.id===p.id?E:f.has(b.id)?x(b,b.id).map((A,I)=>({...A,track:b.track,start:E[I].start,duration:E[I].duration})):b.start>=s-1/60&&!(l(b)&&b.track!==p.track)?[{...b,start:ht(Math.max(0,b.start+S))}]:[b]),pieces:y.length,length:ht(v),delta:S}}function D$(t,e=!1){return t.lines.map(o=>{const r=`#${o.index+1}`,n=o.text.length>48?o.text.slice(0,47)+"…":o.text;if(o.status==="skipped")return e?`${r} "${n}": left out`:`${r} "${n}": bỏ qua`;if(o.status==="missing")return e?`${r} "${n}": not found in the clip`:`${r} "${n}": không thấy trong clip`;const a=[];return o.takes>1&&a.push(e?`take ${o.take+1} of ${o.takes}`:`lần ${o.take+1}/${o.takes}`),o.pausesCut&&a.push(e?`${o.pausesCut} pause${o.pausesCut>1?"s":""} −${o.pauseSaved}s`:`${o.pausesCut} chỗ ngừng −${o.pauseSaved}s`),o.rate!==1&&a.push(`${o.rate}×`),a.push(`${o.final.toFixed(1)}s${o.target?` / ${o.target}s`:""}`),`${r} "${n}": ${a.join(", ")}`})}const Yu=Object.freeze({overlap:Object.freeze([.2,.4]),enter:Object.freeze({type:"zoom-in",ease:"expo-out"}),exit:Object.freeze({type:"zoom-out",ease:"ease-in"}),camera:Object.freeze({push:.5,roll:1.5})}),B$=new Set(["ai-scan-frame","aiw-end-subtitle","aiw-gen-checklist","aiw-pause-menu","aiw-race-hud","aiw-race-title","aiw-scan","aiw-select","aiw-style-pick","aiw-v-end-subtitle","aiw-v-gen-checklist","aiw-v-pause-menu","aiw-v-race-hud","aiw-v-race-title","aiw-v-scan","aiw-v-select","aiw-v-style-pick","bridge-portal","cine-crown-rain","cine-door","cine-eye","cine-flame","cine-heart","cine-hourglass","cine-key","cine-lighthouse","cine-moon","cine-night-house","cine-planet","cine-rocket","cine-sword","cine-tree","clipoox-bar-lower","clipoox-card-cube","clipoox-card-row","clipoox-claim-block","clipoox-coin-rain","clipoox-connect","clipoox-core-orbit","clipoox-count-ruler","clipoox-counter-dots","clipoox-discount","clipoox-dot-grid-stat","clipoox-end-card","clipoox-end-credit","clipoox-fine-print","clipoox-gen-cards","clipoox-giant-word","clipoox-glass-thanks","clipoox-glitch-slam","clipoox-holo-button","clipoox-holo-mesh","clipoox-line-stat","clipoox-notch-frame","clipoox-number-rush","clipoox-phone-build","clipoox-pill-lower","clipoox-pixel-face","clipoox-price-dial","clipoox-product-pick","clipoox-prompt-box","clipoox-ray-logo","clipoox-skill-header","clipoox-stat-dome","clipoox-sticker-stack","clipoox-trace-label","clipoox-ui-stack","clipoox-url-analyze","clipoox-v-card-cube","clipoox-v-core-orbit","clipoox-v-cta","clipoox-v-end-credit","clipoox-v-glitch-slam","clipoox-v-holo-mesh","clipoox-v-hook","clipoox-v-marquee","clipoox-v-phone","clipoox-v-pixel-face","clipoox-v-plans","clipoox-v-prompt-box","clipoox-v-ray-logo","clipoox-v-split","clipoox-v-stack","clipoox-v-stat","clipoox-v-steps","clipoox-v-top-banner","clipoox-v-window-burst","clipoox-window-burst","course-brand-bug","course-callout","course-chapter-card","course-cover-insert","course-framework-stack","course-journey-line","course-map-pins","course-photo-pop","course-pip-frame","course-screen-frame","creator-3d-glyph","creator-behind-title","creator-chapter-bar","creator-coin-flip","creator-news-cards","creator-phone-duo","creator-quote-end","cs-card-fan","cs-doc-stamp","cs-file-window","cs-flip-board","cs-generating","cs-graph-editor","cs-pen-logo","cs-phone-trio","cs-prompt","cs-render-card","cs-route-map","cs-timeline-fix","cs-title-curve","exp-checklist-x","exp-comment-thread","exp-cta-button","exp-expert-stamp","exp-fame-meter","exp-id-badge","exp-kicker-title","exp-mood-gauge","exp-notifications","exp-price-up","exp-profile-card","exp-question-banner","exp-toggle-on","exp-triple-meters","fh-call-panel","fh-data-ring","fh-keypad","fh-music-player","fh-profile-card","fh-radar-map","fh-target-lock","fh-text-column","fh-translate","fh-weather","fluid-melt-word","fr-chapter","fr-comment-cta","fr-headline","fr-paper","fr-recap","fr-v-chapter","fr-v-comment-cta","fr-v-headline","fr-v-paper","fr-v-recap","fr-v-window","fr-window","glass-balance","glass-candles","glass-coin-bars","glass-line-target","glass-orb-rise","glass-step-chart","hist-depth-words","hist-year-wall","home-money-rain","home-news-stack","home-sticky-cta","illus-callout","illus-steps","illus-timeline","illus-versus","join-type-wall","kin-beat","kin-ribbon-nodes","lr-chrome-logo","lr-name-spark","lumen-neon-word","mono-ribbon-wipe","mono-spotlight-panels","morph-arrow-ring","morph-diamond-frame","morph-gradient-card","morph-light-pole","morph-light-thread","morph-loading-dots","morph-logo-wings","morph-path-tag","morph-pill-band","morph-sparkle-glow","morph-sun-flood","mx-crt-screen","mx-data-tunnel","pod-icon-burst","promo-aurora-card","promo-card-pill","promo-cta-button","promo-dome-horizon","promo-feature-cards","promo-flare-card","promo-glass-orbit","promo-icon-cloud","promo-logo-spark","promo-prompt-bar","pulse-end-title","rebound-atom-arches","rebound-brick-tower","rebound-chevron-field","rebound-dots-merge","rebound-frame-in-frame","rebound-gradient-flash","rebound-gradient-tile","rebound-neon-word","rebound-piston-launch","rebound-radial-web","rebound-ramp-shot","rebound-skyline-hop","rebound-tube-slide","rv-packshot-title","rv-product-callout","sc-card-label","sc-named-cursor","sc-scan-boxes","studio-ai-command","studio-asset-wall","studio-before-after","studio-brand-kit","studio-click-callout","studio-drag-asset","studio-endcard","studio-export","studio-feature-grid","studio-hero-tilt","studio-keyframe-curve","studio-monitor-play","studio-multi-format","studio-panels-explode","studio-sales-growth","studio-sfx-drop","studio-team-collab","studio-template-flip","studio-time-saved","studio-timeline-build","tl-4k-split","tl-end-card","tl-feature-panel","tl-player","tl-title-lockup","tl-v-4k-split","tl-v-end-card","tl-v-feature-panel","tl-v-player","tl-v-title-lockup","travel-city-poster","travel-name-wall"]);let _$=null;const G$=()=>_$??=new Function("return "+ug)(),Lp=new Map;function K$(t){if(Lp.has(t))return Lp.get(t);const e=Yi.find(r=>r.id===t&&!r.kind);let o=null;if(e)try{o=new Function("M",'"use strict";'+e.code+`
|
|
100
|
+
;return render`)(G$())}catch{o=null}return Lp.set(t,o),o}const qu=t=>Yi.find(e=>e.id===t&&!e.kind)??null,hl=(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]],Rr=(t,e,o)=>[t[0]*e+t[2]*o+t[4],t[1]*e+t[3]*o+t[5]],em=t=>{const e=/(\d+(?:\.\d+)?)px/.exec(String(t||""));return e?+e[1]:10},V$=t=>typeof t=="string"?t:t&&t.stops?.length?t.stops[Math.floor(t.stops.length/2)]:null;function W$(t,e){const o=[];let r={m:[1,0,0,1,0,0],fillStyle:"#000",strokeStyle:"#000",globalAlpha:1,lineWidth:1,shadowBlur:0,shadowColor:"transparent",font:"10px sans-serif",textAlign:"start",textBaseline:"alphabetic",globalCompositeOperation:"source-over",filter:"none"};const n=[];let a=[];const i=()=>Math.sqrt(Math.abs(r.m[0]*r.m[3]-r.m[1]*r.m[2])),l=(x,E)=>{const[v,S]=Rr(r.m,x,E);a.push({t:"pt",x:v,y:S})},p=()=>{const x={stops:[],addColorStop(E,v){x.stops.push(v)}};return x},c=x=>{let E=1/0,v=1/0,S=-1/0,k=-1/0;for(const[b,A]of x)E=Math.min(E,b),v=Math.min(v,A),S=Math.max(S,b),k=Math.max(k,A);return{x:E,y:v,w:S-E,h:k-v}},s=x=>{const E=v=>x.reduce((S,k)=>v(k)>v(S)?k:S);return[E(v=>-(v[0]+v[1])),E(v=>v[0]-v[1]),E(v=>v[0]+v[1]),E(v=>v[1]-v[0])]},h=()=>{const x=[],E=[],v=[];let S=0,k=[],b=0,A=!1,I=0,P=!1,C=null;for(const _ of a)_.t==="pt"?(x.push([_.x,_.y]),E.push([_.x,_.y])):_.t==="move"?(I++,x.push([_.x,_.y]),E.push([_.x,_.y])):_.t==="rect"?(b++,C=_.pts,x.push(..._.pts)):_.t==="arc"?(S++,A||=_.full,x.push([_.cx-_.r,_.cy-_.r],[_.cx+_.r,_.cy+_.r])):_.t==="arcTo"?(k.push(_.r),v.push([_.x,_.y]),x.push([_.x,_.y])):_.t==="close"&&(P=!0);if(!x.length)return null;const z=c(x);let N="path",F=0,K=null;if(b===1&&!S&&!k.length&&I<=1)N="rect",K=s(C);else if(k.length>=4&&I<=1&&!S)N="rrect",F=Math.min(...k),K=s(v.slice(0,4));else if(S===1&&A&&!k.length&&!b&&x.length<=4)N="circle",F=z.w/2;else if(!S&&!k.length&&!b&&I===1&&(P||E.length>=4)){const _=E.length;if(_===4)N="quad",K=s(E);else if(_>=8&&_%4===0){const q=_/4,U=[];let rt=0;for(let ot=0;ot<4;ot++){const G=E.slice(ot*q,ot*q+q),J=G[0],Z=G[q-1],at=[(J[0]+Z[0])/2,(J[1]+Z[1])/2];if(q>=4){const D=[G[1][0]+G[q-2][0],G[1][1]+G[q-2][1]],H=[(D[0]-J[0]-Z[0])/.366,(D[1]-J[1]-Z[1])/.366];U.push([at[0]+H[0]/2,at[1]+H[1]/2])}else U.push(at);rt+=Math.hypot(J[0]-Z[0],J[1]-Z[1])/Math.SQRT2}N="rrect",F=rt/4,K=s(U)}}return{...z,kind:N,r:F,...K?{quad:K}:{}}},f=(x,E,v={})=>{if(!E||!(E.w>0||E.h>0))return;const S=r.globalAlpha;if(S<=.02||r.globalCompositeOperation!=="source-over"&&r.globalCompositeOperation!=="source-atop")return;const k=x==="fill"?r.fillStyle:r.strokeStyle;o.push({...E,op:x,color:V$(k),gradient:typeof k!="string",alpha:S,lw:x==="stroke"?r.lineWidth*i():0,glow:r.shadowBlur>0&&r.shadowColor&&!/transparent|rgba\([^)]*,\s*0\)/.test(r.shadowColor)?r.shadowColor:null,z:o.length,...v})},m=(x,E,v,S)=>{if(E=String(E??""),!E.trim())return;const k=em(r.font),b=E.length*k*.56,A=r.textAlign,I=r.textBaseline,P=A==="center"?v-b/2:A==="right"||A==="end"?v-b:v,C=I==="top"||I==="hanging"?S:I==="middle"?S-k/2:I==="bottom"||I==="ideographic"?S-k:S-k*.8,z=[[P,C],[P+b,C],[P,C+k],[P+b,C+k]].map(([N,F])=>Rr(r.m,N,F));f(x,{...c(z),kind:"text",r:0},{text:E,size:k*i()})},y={save(){n.push({...r,m:[...r.m]})},restore(){n.length&&(r=n.pop())},translate(x,E){r.m=hl(r.m,[1,0,0,1,x,E])},scale(x,E){r.m=hl(r.m,[x,0,0,E,0,0])},rotate(x){const E=Math.cos(x),v=Math.sin(x);r.m=hl(r.m,[E,v,-v,E,0,0])},transform(x,E,v,S,k,b){r.m=hl(r.m,[x,E,v,S,k,b])},setTransform(x,E,v,S,k,b){x&&typeof x=="object"?r.m=[x.a,x.b,x.c,x.d,x.e,x.f]:r.m=x===void 0?[1,0,0,1,0,0]:[x,E,v,S,k,b]},resetTransform(){r.m=[1,0,0,1,0,0]},getTransform(){const x=r.m;return{a:x[0],b:x[1],c:x[2],d:x[3],e:x[4],f:x[5]}},beginPath(){a=[]},closePath(){a.push({t:"close"})},moveTo(x,E){const[v,S]=Rr(r.m,x,E);a.push({t:"move",x:v,y:S})},lineTo(x,E){l(x,E)},quadraticCurveTo(x,E,v,S){l(x,E),l(v,S)},bezierCurveTo(x,E,v,S,k,b){l(x,E),l(v,S),l(k,b)},arcTo(x,E,v,S,k){const[b,A]=Rr(r.m,x,E);a.push({t:"arcTo",x:b,y:A,r:k*i()}),l(v,S)},arc(x,E,v,S,k,b){const[A,I]=Rr(r.m,x,E);a.push({t:"arc",cx:A,cy:I,r:Math.abs(v)*i(),full:Math.abs((k??0)-(S??0))>=Math.PI*2-.001||!!b&&!1})},ellipse(x,E,v,S){const[k,b]=Rr(r.m,x,E);a.push({t:"arc",cx:k,cy:b,r:Math.max(v,S)*i(),full:!1})},rect(x,E,v,S){a.push({t:"rect",pts:[[x,E],[x+v,E],[x,E+S],[x+v,E+S]].map(([k,b])=>Rr(r.m,k,b))})},roundRect(x,E,v,S,k){const b=Array.isArray(k)?k[0]:k,A=typeof b=="object"?b.x:b||0,I=[[x,E],[x+v,E],[x,E+S],[x+v,E+S]].map(([P,C])=>Rr(r.m,P,C));if(a.push({t:"rect",pts:I}),A>0){a.pop(),a.push({t:"move",x:I[0][0],y:I[0][1]});for(const P of I)a.push({t:"arcTo",x:P[0],y:P[1],r:A*i()})}},fill(){f("fill",h())},stroke(){f("stroke",h())},clip(){},fillRect(x,E,v,S){const k=[[x,E],[x+v,E],[x,E+S],[x+v,E+S]].map(([b,A])=>Rr(r.m,b,A));f("fill",{...c(k),kind:"rect",r:0})},strokeRect(x,E,v,S){const k=[[x,E],[x+v,E],[x,E+S],[x+v,E+S]].map(([b,A])=>Rr(r.m,b,A));f("stroke",{...c(k),kind:"rect",r:0})},clearRect(){},fillText(x,E,v){m("fill",x,E,v)},strokeText(x,E,v){m("stroke",x,E,v)},measureText(x){const E=em(r.font);return{width:String(x).length*E*.56,actualBoundingBoxAscent:E*.8,actualBoundingBoxDescent:E*.2}},drawImage(x,...E){const[v,S,k,b]=E.length>=8?E.slice(4):E.length>=4?E:[E[0],E[1],x?.width||0,x?.height||0],A=[[v,S],[v+k,S],[v,S+b],[v+k,S+b]].map(([I,P])=>Rr(r.m,I,P));f("fill",{...c(A),kind:"image",r:0})},createLinearGradient:p,createRadialGradient:p,createConicGradient:p,createPattern:()=>({stops:[]}),getImageData:(x,E,v,S)=>({data:new Uint8ClampedArray(Math.max(4,(v|0)*(S|0)*4)),width:v,height:S}),putImageData(){},createImageData:(x,E)=>({data:new Uint8ClampedArray(Math.max(4,(x|0)*(E|0)*4)),width:x,height:E}),setLineDash(){},getLineDash:()=>[],isPointInPath:()=>!1};return new Proxy({},{get:(x,E)=>E==="canvas"?{width:t,height:e}:E==="draws"?o:E in y?y[E]:E in r?r[E]:void 0,set:(x,E,v)=>(E!=="m"&&(r[E]=v),!0)})}function X$(t,e,{W:o=1280,H:r=720,params:n={},duration:a}={}){const i=K$(t),l=qu(t);if(!i||!l)return[];const p=W$(o,r),c=a??l.duration;try{i(p,e,Object.freeze({width:o,height:r,duration:c,fps:30,progress:c?e/c:0,params:Object.freeze({...l.params,...n}),fonts:{}}))}catch{return p.draws.slice()}return p.draws.slice()}const ki=t=>{if(!t)return null;const e=/^#([0-9a-f]{6}|[0-9a-f]{3})(?![0-9a-f])|^#([0-9a-f]{6})[0-9a-f]{2}$/i.exec(t);if(e){e[1]=e[1]??e[2];const r=e[1].length===3?e[1].split("").map(n=>n+n).join(""):e[1];return[0,2,4].map(n=>parseInt(r.slice(n,n+2),16))}const o=/rgba?\(([^)]+)\)/.exec(t);if(o){const r=o[1].split(",").map(Number);return r.length>3&&r[3]<.05?null:r.slice(0,3)}return t==="white"?[255,255,255]:t==="black"?[0,0,0]:null},H$=t=>{if(!t)return null;const e=/^#([0-9a-f]{6})([0-9a-f]{2})$/i.exec(t);if(e)return[ki("#"+e[1]),parseInt(e[2],16)/255];const o=/rgba\(([^)]+)\)/.exec(t);if(o){const n=o[1].split(",").map(Number);return n[3]>=.05?[n.slice(0,3),n[3]]:null}const r=ki(t);return r?[r,1]:null},om=[14,16,19],rm=(t,e,o)=>t.map((r,n)=>r+(e[n]-r)*o),ss=t=>{if(!t)return 0;const e=Math.max(...t),o=Math.min(...t);return e?(e-o)/e:0},fl=t=>t?(.2126*t[0]+.7152*t[1]+.0722*t[2])/255:0,U$=(t,e)=>{const o=Math.max(t.x,e.x),r=Math.max(t.y,e.y),n=Math.min(t.x+t.w,e.x+e.w),a=Math.min(t.y+t.h,e.y+e.h),i=Math.max(0,n-o)*Math.max(0,a-r);return i/(t.w*t.h+e.w*e.h-i||1)},ls=t=>t?"#"+t.map(e=>Math.max(0,Math.min(255,Math.round(e))).toString(16).padStart(2,"0")).join(""):null;function Y$(t,{W:e=1280,H:o=720,accent:r}={}){const n=e*o,a=ki(r),i=[];for(const c of t){if(c.kind==="text"||c.kind==="image"||c.kind==="path")continue;const s=c.w*c.h;if(s>n*.85||c.w<6||c.h<6||s<n*8e-4||Math.max(0,Math.min(e,c.x+c.w)-Math.max(0,c.x))*Math.max(0,Math.min(o,c.y+c.h)-Math.max(0,c.y))/s<.7||c.w>e*.92&&c.op==="fill"&&!c.glow||c.alpha<.3||c.gradient&&c.kind==="circle"&&c.op==="fill"&&c.alpha<.8)continue;const f=i.find(x=>U$(x,c)>.88),m=H$(c.color),y=m?m[0]:null,$=m?m[1]*c.alpha:0;if(f){c.op==="fill"&&y&&(f.fillRgb=rm(f.fillRgb??om,y,$)),c.op==="stroke"&&y&&(f.borderRgb=y),c.glow&&(f.glow=c.glow),f.z=Math.max(f.z,c.z);continue}i.push({x:c.x,y:c.y,w:c.w,h:c.h,kind:c.kind,r:c.r,quad:c.quad,fillRgb:c.op==="fill"&&y?rm(om,y,$):null,borderRgb:c.op==="stroke"?y:null,glow:c.glow,z:c.z,alpha:c.alpha})}const l=[];for(const c of i){const s=c.w*c.h/n,h=Math.min(c.w,c.h),f=c.w/c.h;let m;if(c.kind==="circle"||c.kind==="rrect"&&c.r>=h*.45&&f>.8&&f<1.25?m="circle":c.kind==="rrect"&&c.r>=h*.38&&f>=1.6?m="pill":s<=.03&&f>=1.4&&f<=5&&(ss(c.fillRgb)>.3||fl(c.fillRgb)>.55)?m="button":s<.008?m="chip":s<.42?m="card":m="panel",m==="chip"&&!c.borderRgb&&!c.glow&&ss(c.fillRgb)<.25)continue;const y=c.borderRgb??c.fillRgb,$=a&&y?1-Math.min(1,Math.hypot(y[0]-a[0],y[1]-a[1],y[2]-a[2])/120):0,x=m==="panel"?.45:Math.min(1,Math.sqrt(s/.03));if(Math.max(fl(c.fillRgb)>.55?.7:ss(c.fillRgb)*fl(c.fillRgb)*1.6,c.borderRgb?.8:0,c.glow?1:0)<.12)continue;const v=x+.7*Math.max($,ss(y)*fl(y))+(c.glow?.45:0)+(c.borderRgb?.25:0)+(m==="pill"||m==="button"?.35:m==="card"?.2:m==="circle"?.15:0)+.15*(c.z/Math.max(1,t.length));l.push({role:m,x:c.x,y:c.y,w:c.w,h:c.h,r:Math.min(c.r||0,h/2),...c.quad?{quad:c.quad.map(S=>S.map(k=>+k.toFixed(1)))}:{},fill:ls(c.fillRgb),border:ls(c.borderRgb),glow:c.glow?ls(ki(c.glow))??null:null,score:+v.toFixed(3)})}const p=t.filter(c=>c.kind==="text"&&c.alpha>.5&&c.size>=o*.035);for(const c of p){const s=ki(c.color),h=l.find(f=>f.role==="headline"&&Math.abs(f.y-c.y)<c.size*.6&&Math.abs(f.size-c.size)<2);if(h){const f=Math.min(h.x,c.x),m=Math.max(h.x+h.w,c.x+c.w);h.x=f,h.w=m-f,h.text+=" "+c.text;continue}l.push({role:"headline",x:c.x,y:c.y,w:c.w,h:c.h,r:0,fill:ls(s),border:null,glow:c.glow?ls(ki(c.glow)):null,text:c.text,size:c.size,score:+(.5+c.size/o*4+(ss(s)>.4?.3:0)).toFixed(3)})}return l.sort((c,s)=>s.score-c.score).slice(0,8)}function q$(t,e,{W:o=1280,H:r=720,accent:n}={}){const a=t?.motion?.preset;if(!a||!qu(a))return[];const i=t.motion.duration??qu(a).duration,l=Math.max(0,Math.min(i-1/30,e+(t.inPoint||0)));return Y$(X$(a,l,{W:o,H:r,params:t.motion.params||{},duration:i}),{W:o,H:r,accent:n??t.motion.params?.accent})}const Z$={pill:{pill:1,button:1,chip:.8,card:.5,circle:.5},button:{button:1,pill:1,chip:.8,card:.55},chip:{chip:1,button:.8,pill:.8,circle:.7,card:.5},card:{card:1,panel:.85,button:.55,pill:.5,chip:.5},panel:{panel:1,card:.85},circle:{circle:1,chip:.7,pill:.5}},En={minScore:.32,ease:"easy-ease",maxZoom:4},J$=t=>t.w*t.h,nm=t=>t.quad?[t.quad.reduce((e,o)=>e+o[0],0)/4,t.quad.reduce((e,o)=>e+o[1],0)/4]:[t.x+t.w/2,t.y+t.h/2],L1=t=>t.quad??[[t.x,t.y],[t.x+t.w,t.y],[t.x+t.w,t.y+t.h],[t.x,t.y+t.h]],xi=t=>Math.sqrt(J$(t)),Q$=t=>t.filter(e=>e.kind!=="audio"&&e.motion?.preset&&!e.seam?.hero),Zu=(t,e)=>({x:Ut(t,"x",e),y:Ut(t,"y",e),zoom:Ut(t,"zoom",e)});function tv(t,e,o,r){const n=([p,c])=>[o/2+e.x*o+(p-o/2)*e.zoom,r/2+e.y*r+(c-r/2)*e.zoom],a=L1(t).map(n),i=a.map(p=>p[0]),l=a.map(p=>p[1]);return{...t,quad:a,x:Math.min(...i),y:Math.min(...l),w:Math.max(...i)-Math.min(...i),h:Math.max(...l)-Math.min(...l),r:t.r*e.zoom}}function am(t,e,{W:o=1280,H:r=720,accent:n}={}){const a=[];for(const i of Q$(t)){const l=e-i.start;if(l<-1e-6||l>i.duration+1e-6)continue;const p=Zu(i,l);for(const c of q$(i,l,{W:o,H:r,accent:n}))a.push({...tv(c,p,o,r),layer:i.id})}return a.sort((i,l)=>l.score-i.score)}function im(t,e,o,r,{W:n=1280,H:a=720,accent:i}={}){const l=am(t,o,{W:n,H:a,accent:i}).slice(0,5),p=am(e,r,{W:n,H:a,accent:i}).slice(0,5);if(!l.length||!p.length)return null;const c=m=>Math.max(...m.map(y=>y.score)),s=c(l),h=c(p);let f=null;for(const m of l)for(const y of p){const $=Z$[m.role]?.[y.role]??0;if(!$)continue;const x=b=>b.w/b.h,E=Math.min(x(m),x(y))/Math.max(x(m),x(y)),v=Math.min(xi(m),xi(y))/Math.max(xi(m),xi(y)),S=m.score/s*(y.score/h),k=$*(.7+.3*E)*(.65+.35*Math.sqrt(v))*S*(v<1/En.maxZoom?.6:1);(!f||k>f.score)&&(f={a:m,b:y,score:+k.toFixed(3)})}return f&&f.score>=En.minScore?f:null}const ea=t=>Math.round(t*1e4)/1e4;function ev(t,e,o,r,n,{W:a=1280,H:i=720,ease:l=En.ease}={}){const p=new Map,c=n-r,s=Object.hasOwn(Jt,l)?l:En.ease,[h,f]=nm(t.a),[m,y]=nm(t.b),$=Math.max(1/En.maxZoom,Math.min(En.maxZoom,xi(t.b)/xi(t.a))),x=(v,S,k,b)=>{b=Math.min(b,En.maxZoom/Math.max(.01,v.zoom));const A=v.zoom*b,I=a/2+v.x*a,P=i/2+v.y*i;return{x:ea((k[0]-a/2-(S[0]-I)*b)/a),y:ea((k[1]-i/2-(S[1]-P)*b)/i),zoom:ea(A)}},E=(v,S,k,b,A)=>{const I=v.duration,P=C=>Math.min(I,Math.max(0,ea(C-v.start)));for(const C of["x","y","zoom"])v=eh(v,C,[{time:P(S),value:k[C],ease:s},{time:P(S+c),value:b[C]}]);return eh(v,"opacity",A.map(([C,z])=>({time:P(S+C*c),value:z})))};for(const v of e){if(v.kind==="audio")continue;const S=ht(n-v.start);if(S<c+1/30)continue;let k={...v,duration:S};delete k.exit;const b=Zu(v,r-v.start);k=E(k,r,{...b},x(b,[h,f],[m,y],$),[[.22,1],[.5,0]]),p.set(k.id,{...k,seam:{...k.seam,out:!0,excl:!0}})}for(const v of o){if(v.kind==="audio")continue;const S=ht(v.start+v.duration-r);if(S<c+1/30)continue;let k={...v,start:ht(r),duration:S};delete k.enter;const b=Zu(v,n-v.start);k=E(k,r,x(b,[m,y],[h,f],1/$),{...b},[[.5,0],[.78,1]]),p.set(k.id,{...k,seam:{...k.seam,in:!0,excl:!0}})}return p}const ov=`function render(ctx,t,env){
|
|
101
|
+
// Element match cut carrier (shared/seamlessMatch.js): A's shape becomes B's.
|
|
102
|
+
const p=env.params,W=env.width,H=env.height,u=M.clamp(t/Math.max(.01,env.duration))
|
|
103
|
+
const EZ=x=>{x=M.clamp(x);const a=+p.e0,b=+p.e1,c=+p.e2,d=+p.e3;const bz=(q,r,s)=>3*q*(1-s)*(1-s)*s+3*r*(1-s)*s*s+s*s*s;let lo=0,hi=1,s=x;for(let i=0;i<40;i++){s=(lo+hi)/2;if(bz(a,c,s)<x)lo=s;else hi=s}return bz(b,d,s)}
|
|
104
|
+
const k=EZ(u),qa=String(p.qa).split(',').map(Number),qb=String(p.qb).split(',').map(Number)
|
|
105
|
+
const al=+p.peak*M.range(u,.1,.3)*(1-M.range(u,.7,.9));if(al<=.003)return
|
|
106
|
+
const q=[0,1,2,3].map(i=>[M.lerp(qa[2*i],qb[2*i],k)*W,M.lerp(qa[2*i+1],qb[2*i+1],k)*H])
|
|
107
|
+
const side=(i,j)=>Math.hypot(q[j][0]-q[i][0],q[j][1]-q[i][1]),mn=Math.min(side(0,1),side(1,2),side(2,3),side(3,0))
|
|
108
|
+
const r=Math.min(mn/2,M.lerp(+p.ra,+p.rb,k)*Math.min(W,H))
|
|
109
|
+
const mid=(i,j)=>[(q[i][0]+q[j][0])/2,(q[i][1]+q[j][1])/2]
|
|
110
|
+
const path=()=>{ctx.beginPath();const m0=mid(3,0);ctx.moveTo(m0[0],m0[1]);for(let i=0;i<4;i++){const n=(i+1)%4,m=mid(i,n);ctx.arcTo(q[i][0],q[i][1],m[0],m[1],r)}ctx.closePath()}
|
|
111
|
+
// The fill only veils the two scenes (aligned under it, their content cross-fading inside the shape); the border carries
|
|
112
|
+
// the shape and the glow — on the stroke only, so no colour bleeds into the fill.
|
|
113
|
+
const fill=M.mix(p.fa,p.fb,k),line=M.mix(p.ba,p.bb,k)
|
|
114
|
+
ctx.save();ctx.globalAlpha=al*(+p.veil);path();ctx.fillStyle=fill;ctx.fill();ctx.restore()
|
|
115
|
+
ctx.save();ctx.globalAlpha=al;ctx.shadowColor=p.glow;ctx.shadowBlur=Math.min(W,H)*.025*Math.sin(Math.PI*k);ctx.lineWidth=Math.max(1.5,Math.min(W,H)*.0045);ctx.strokeStyle=line;path();ctx.stroke();ctx.restore()
|
|
116
|
+
}`;function rv(t,e,o,r,{W:n=1280,H:a=720,accent:i="#c6f432",ease:l=En.ease,id:p}={}){const c=E=>L1(E).map(([v,S])=>`${ea(v/n)},${ea(S/a)}`).join(","),s=Jt[l]??Jt[En.ease],h=ht(r-o),f=E=>({fill:E.fill??E.border??i,line:E.border??E.fill??i}),m=f(t.a),y=f(t.b),$={qa:c(t.a),qb:c(t.b),ra:ea(t.a.r/Math.min(n,a)),rb:ea(t.b.r/Math.min(n,a)),fa:m.fill,fb:y.fill,ba:m.line,bb:y.line,glow:i,e0:s[0],e1:s[1],e2:s[2],e3:s[3],peak:1,veil:.5},x=Jo({code:ov,params:$,preset:"match-morph"});return{id:p??`seam-match-${e}`,nodeId:"",kind:"image",url:"",label:`Nối ${e} · ${t.a.role} → ${t.b.role}`,volume:0,start:ht(o),duration:h,track:0,motion:{...x,duration:h},motionKeys:[],is3D:!0,zIndex:Math.min(99,e),seam:{hero:!0,flight:e,style:"match-morph",match:{a:t.a.role,b:t.b.role,score:t.score,...t.a.text?{aText:t.a.text.slice(0,40)}:{},...t.b.text?{bText:t.b.text.slice(0,40)}:{}}}}}const bc={overlap:Yu.overlap[1],collide:1/30,world:.75,worldMin:6},sm="#c6f432",lm=["whoosh-short-up","swoosh"],cm=["top","center","lower"],Ns=t=>Math.round(t*1e3)/1e3,Ue=t=>t.start+t.duration,nv=t=>t.kind==="video"||t.kind==="model"||t.kind==="image"&&!t.title&&!t.shape&&!t.card&&!t.motion&&!t.geo&&!t.solid&&!t.adjust&&!t.nullLayer&&!t.element&&!t.gen;function di(t){if(t?.kind==="audio")return null;if(t?.title)return{band:cm.includes(t.title.placement)?t.title.placement:"lower",set:n=>({...t,title:{...t.title,placement:n},url:"",gcsUri:void 0})};const e=t?.motion?.preset;if(e==="kin-beat"||e==="kin-orb"||!e||!gu(e,"text")||B$.has(e))return null;const o=gu(e,"placement"),r=o?t.motion.params?.[o]:null;return!o||!cm.includes(r)?null:{band:r,set:n=>({...t,motion:{...t.motion,params:{...t.motion.params,[o]:n}}})}}const av=new Set(["rv-brand-watermark","home-sticky-cta","home-brand-plate","course-progress-bar","course-tool-badge","course-screen-frame","course-callout","course-pip-frame","course-label-tag","course-journey-line","course-photo-pop","course-cover-insert","course-framework-stack","course-brand-bug","course-doc-highlight","course-map-pins"]);function Np(t){if(av.has(t?.motion?.preset)||t?.mapAnno||t?.decor||t?.pin||t?.pendingPin||t?.motion?.preset==="course-chapter-card"&&!String(t.motion.params?.text??"").trim())return null;const e=di(t);return e?e.band:t?.kind!=="audio"&&(t?.title||t?.motion?.preset&&gu(t.motion.preset,"text"))?"full":null}const Qc=(t,e)=>Math.min(Ue(t),Ue(e))-Math.max(t.start,e.start);function pm(t,e){const o=t.exit,r=e.enter;if(!o||!r||o.type!==r.type||!o.type.startsWith("slide-")||o.fade!==!1||r.fade!==!1||(o.amount??0)<.99||(r.amount??0)<.99)return!1;const n=Math.min(o.duration,t.duration/(t.enter?2:1)),a=Math.min(r.duration,e.duration/(e.exit?2:1));return Math.abs(Ue(t)-n-e.start)<1/60&&Math.abs(n-a)<1/60&&Math.abs(Qc(t,e)-n)<1/60}const um=t=>t&&t.fade!==!1&&t.duration||0,iv=.15,dm=(t,e)=>{const o=Math.max(e.start>=t.start-1e-6?um(e.enter):0,Ue(t)<=Ue(e)+1e-6?um(t.exit):0);return o>0&&Qc(t,e)<=o+iv},hm=(t,e)=>!!(t.seam?.out&&e.seam?.in&&t.seam.excl&&e.seam.excl&&e.seam.scene===t.seam.scene+1),fm=t=>Math.max(...String(t.title.text).split(`
|
|
117
|
+
`).map(e=>e.length))*t.title.fontSize*.62+t.title.fontSize,sv=(t,e)=>!!(t.title&&e.title)&&[t.title.align,e.title.align].sort().join()==="left,right"&&fm(t)+fm(e)<=1040;function lv(t,e={}){const o=t.filter(n=>!e[n.track]?.hidden&&Np(n)).sort((n,a)=>n.start-a.start||n.track-a.track),r=[];return o.forEach((n,a)=>{for(const i of o.slice(0,a)){const l=Np(i),p=Np(n),c=i.seam?.scene!==void 0&&n.seam?.scene!==void 0&&i.seam.scene!==n.seam.scene;(l===p||(l==="full"||p==="full")&&c)&&(Qc(i,n)<=bc.collide||pm(i,n)||pm(n,i)||hm(i,n)||hm(n,i)||l===p&&sv(i,n)||(l==="full"||p==="full")&&(dm(i,n)||dm(n,i))||r.push({a:i,b:n,at:Ns(Math.max(i.start,n.start))}))}}),r}const cv={center:["lower","top"],lower:["top","center"],top:["lower","center"]},pv=.8;function Ju(t,{tracks:e={},movable:o=null}={}){let r=t.slice();const n=[],a=new Set,i=new Set,l=p=>!o||o.has(p.id);for(let p=0;p<80;p++){const c=lv(r,e),s=c.find($=>di($.b)&&!a.has($.b.id)&&l($.b));if(s){const $=r.filter(E=>E.id!==s.b.id&&di(E)&&Qc(E,s.b)>bc.collide).map(E=>di(E).band),x=cv[di(s.b).band].find(E=>!$.includes(E));if(!x){a.add(s.b.id);continue}r=r.map(E=>E.id===s.b.id?di(E).set(x):E),n.push(`"${s.b.label}" moved to ${x} (was over "${s.a.label}")`);continue}const h=c.find($=>!i.has($.a.id+"|"+$.b.id)&&(l($.a)||l($.b)));if(!h)break;const{a:f,b:m}=h,y=Ns(m.start-f.start);l(f)&&y>=pv?(r=r.map($=>$.id===f.id?{...$,duration:y}:$),n.push(`"${f.label}" now ends when "${m.label}" starts (their text cannot share the frame)`)):l(m)?(r=r.map($=>$.id===m.id?{...$,start:Ns(Ue(f))}:$),n.push(`"${m.label}" now starts after "${f.label}" (their text cannot share the frame)`)):(i.add(f.id+"|"+m.id),n.push(`"${m.label}" still overlaps "${f.label}"`))}return{clips:r,notes:n}}function uv(t){const e=Math.min(...t.map(s=>s.start)),o=Math.max(...t.map(Ue)),r=o-e,n=t.filter(s=>r>=bc.worldMin&&s.duration>=bc.world*r),a=t.filter(s=>!n.includes(s)),i=new Map;for(const s of a)Number.isInteger(s.seam?.scene)&&(i.has(s.seam.scene)||i.set(s.seam.scene,[]),i.get(s.seam.scene).push(s));const l=[...i.values()].map(s=>({s:Math.min(...s.map(h=>h.start)),e:Math.max(...s.map(Ue)),list:s})),p=[];for(const s of a.filter(h=>!Number.isInteger(h.seam?.scene)).sort((h,f)=>h.start-f.start)){const h=l.map(m=>({k:m,o:Math.min(Ue(s),m.e)-Math.max(s.start,m.s)})).filter(m=>m.o>.5*s.duration).sort((m,y)=>y.o-m.o)[0];if(h){h.k.list.push(s);continue}const f=p.at(-1);f&&s.start<f.e-1e-6?(f.list.push(s),f.e=Math.max(f.e,Ue(s))):p.push({s:s.start,e:Ue(s),list:[s]})}const c=[...l,...p].map(s=>s.list).sort((s,h)=>Math.min(...s.map(f=>f.start))-Math.min(...h.map(f=>f.start)));return{world:n,scenes:c}}function Rd(t,e={},o=null,{overlap:r,accent:n,newId:a,seed:i="clipoox",W:l=1280,H:p=720}={}){if(t.some(G=>nv(G)))throw Error("makeSeamless is for motion / text timelines (no footage or 3D models)");n=n??t.find(G=>G.seam?.hero&&G.shape)?.shape?.paths?.[0]?.stroke??t.find(G=>G.seam?.match)?.motion?.params?.glow??t.find(G=>Number.isInteger(G.seam?.deco))?.motion?.params?.accent??sm;const c=t.filter(G=>Number.isInteger(G.seam?.joinFx)),s=t.filter(G=>!G.seam?.hero&&!G.seam?.join&&!Number.isInteger(G.seam?.joinFx)).map(G=>G.seam?.raw?Cb(G):G),h=s.filter(G=>G.kind!=="audio");if(!h.length)throw Error("Nothing to link: add motion / text layers first");if(h.some(G=>e[G.track]?.locked))throw Error("Track đã khóa");const{world:f,scenes:m}=uv(h),y=new Set(f.map(G=>G.id)),$=[],x={};m.forEach((G,J)=>{const Z=G.find(at=>at.seam&&(at.seam.style||at.seam.dur||at.seam.ease||at.seam.shuffle||at.seam.not))?.seam;Z&&(x[J]={style:Z.style,dur:Z.dur,ease:Z.ease,shuffle:Z.shuffle,not:Z.not})});const E={};for(let G=1;G<m.length;G++){const J=x[G]??{};if(J.style&&J.style!=="match-morph")continue;const Z=m[G-1].filter(ut=>!y.has(ut.id)),at=m[G].filter(ut=>!y.has(ut.id)),D=Number.isFinite(J.dur)?J.dur:ec("match-morph").dur,H=Z.length&&at.length?im(Z,at,Math.max(...Z.map(Ue))-D,Math.min(...at.map(ut=>ut.start))+D,{accent:n,W:l,H:p}):null;H?E[G]=H:J.style==="match-morph"&&($.push(`join ${G}: no element pair to morph — kept a plain style`),x[G]={...J,style:void 0})}const v=jb(m.map(Tb),{seed:i,overrides:x}).map((G,J)=>ec(E[J+1]?"match-morph":G)),S=G=>{const J=v[G-1],Z=x[G]??{},at=Number.isFinite(Z.dur)?Z.dur:Number.isFinite(r)?r:J.dur;return Math.max(.2,Math.min(1.2,at))},k=s.filter(G=>G.kind==="audio"&&G.sfx),b=new Map(k.map(G=>[G.id,m.findIndex(J=>J.some(Z=>G.start>=Z.start-1e-6&&G.start<Ue(Z)))])),A=new Map;let I=null;m.forEach((G,J)=>{const Z=Math.min(...G.map(H=>H.start)),at=Math.max(...G.map(Ue)),D=J===0?0:Math.max(-Z,ht(I-S(J)-Z));A.set(J,D),I=at+D});const P=new Map(m.flatMap((G,J)=>G.map(Z=>[Z.id,J])));let C=s.map(G=>{if(G.kind==="audio"){const D=b.get(G.id);return D>=0&&A.get(D)?{...G,start:ht(Math.max(0,G.start+A.get(D)))}:G}const J=P.get(G.id);if(J===void 0)return G;const Z=x[J]??{},at={...G,start:ht(G.start+A.get(J))};return{...at,seam:{scene:J,...Object.fromEntries(Object.entries(Z).filter(([,D])=>D!==void 0)),raw:Ob(at)}}});const z=G=>C.filter(J=>J.seam?.scene===G&&J.kind!=="audio"&&!y.has(J.id)),N=G=>{const J=z(G);return[Math.min(...J.map(Z=>Z.start)),Math.max(...J.map(Ue))]},F=[];for(let G=1;G<m.length;G++){const J=v[G-1],Z=N(G-1)[1],at=ht(Z-S(G)),D=J.kind==="match"?im(z(G-1),z(G),at,Z,{accent:n,W:l,H:p})??E[G]:null;F.push({k:G,b0:at,b1:Z,style:J,pair:D});const H=D?ev(D,z(G-1),z(G),at,Z,{W:l,H:p,ease:x[G]?.ease??J.ease}):Pb(J,{out:z(G-1),inn:z(G),b0:at,b1:Z,ease:x[G]?.ease});if(C=C.map(ut=>H.get(ut.id)??ut),J.kind==="sequence"){const ut=ht(at+(Z-at)/2);C=C.map(gt=>gt.kind==="audio"&>.sfx&&b.get(gt.id)===G&>.start<ut-1e-6?{...gt,start:ht(ut+(gt.start-at))}:gt)}}const K=Math.min(...C.filter(G=>G.kind!=="audio").map(G=>G.start)),_=Math.max(...C.filter(G=>G.kind!=="audio"&&!y.has(G.id)).map(Ue),K+.5);C=C.map(G=>y.has(G.id)&&Ue(G)>_+1e-6?{...G,duration:ht(Math.max(1/30,_-G.start))}:G);const q=[...C.filter(G=>y.has(G.id)).sort((G,J)=>G.track-J.track),...m.flatMap((G,J)=>z(J).sort((Z,at)=>Z.track-at.track||Z.start-at.start))],U=C.filter(G=>G.kind==="audio");for(const G of q){const{track:J}=Zt(U,e,G.start,Ue(G),G.track);U.push({...G,track:J})}C=U,C=C.map(G=>{if(!G.transition)return G;const J=zb(C,G);if(J&&dg(J))return G;const{transition:Z,...at}=G;return $.push(`transition on "${G.label}" removed (layers re-timed)`),at});let rt=o;if(m.length>=2){C=C.map(D=>D.seam?.scene!==void 0&&D.kind!=="audio"&&D.zIndex===void 0?{...D,zIndex:Math.min(99,D.seam.scene)}:D);const G=[];for(const D of F){const H=D.pair?rv(D.pair,D.k,D.b0,D.b1,{W:l,H:p,accent:n,ease:x[D.k]?.ease??D.style.ease,...a?{id:a()}:{}}):{...br({id:a?a():`seam-flight-${D.k}`,track:0,start:ht(D.b0),duration:ht(Math.max(.03333333333333333,D.b1-D.b0)),label:`Nối ${D.k}`}),seam:{hero:!0,flight:D.k,style:D.style.id},zIndex:Math.min(99,D.k)};H.track=Zt([...C,...G],e,H.start,Ue(H)).track,G.push(H)}C.push(...G);for(const D of c){const H=F.find(xt=>xt.k===D.seam.joinFx);if(!H){$.push(`Claude Motion layer of join ${D.seam.joinFx} removed (that join is gone)`);continue}const ut=ht(Math.max(0,(H.b0+H.b1)/2-D.duration/2)),gt={...D,start:ut,zIndex:Math.min(99,H.k),is3D:!0};gt.track=Zt(C,e,gt.start,Ue(gt)).track,C.push(gt)}for(const D of F){const H=D.style.pack==="urban",ut=D.style.pack==="techlaunch",gt=ut?Lb(D.style.deco):H?Nb(D.style.deco):Fb(D.style.deco);if(!gt)continue;const xt=(D.b0+D.b1)/2,u=ht(Math.min(2*xt,Qe.maxDuration,Math.max(gt.min,(D.b1-D.b0)*gt.k+gt.add))),st=Jt[x[D.k]?.ease??D.style.ease],V=st==="hold"?[-1,0,0,0]:Array.isArray(st)?st:[0,0,1,1],d=Jo({code:gt.code,params:ut?{...Rb,...n&&n!==sm?{accent:n}:{},e0:V[0],e1:V[1],e2:V[2],e3:V[3]}:H?{accent:n,...Db,e0:V[0],e1:V[1],e2:V[2],e3:V[3]}:{accent:n,...Bb,e0:V[0],e1:V[1],e2:V[2],e3:V[3],w:D.b1-D.b0,flash:"#ffffff"},preset:D.style.id}),w={id:a?a():`seam-deco-${D.k}`,nodeId:"",kind:"image",url:"",label:`${ut?"Tech Launch":H?"Urban":"Editorial"} · nối ${D.k}`,volume:0,start:ht(xt-u/2),duration:u,track:0,motion:{...d,duration:u},motionKeys:[],seam:{join:!0,deco:D.k},zIndex:Math.min(99,D.k),is3D:!!gt.cam};w.track=Zt(C,e,w.start,Ue(w)).track,C.push(w)}C=C.map(D=>D.kind!=="audio"&&!D.nullLayer&&!y.has(D.id)&&D.is3D===void 0?{...D,is3D:!0}:D);const J={...o??{...Ar,motionKeys:[]},enabled:!0},Z=Ln.cz.base(J),at=Jt["sine-in-out"];rt=un(J,"cz",[{time:ht(K),value:Z,ease:at},{time:ht(_),value:Ns(Math.min(Ln.cz.max,Z+Yu.camera.push))}]),rt=un(rt,"roll",[{time:ht(K),value:0,ease:at},{time:ht(_),value:Yu.camera.roll}]),jr(rt),F.forEach((D,H)=>{const ut=Math.max(0,D.b0-.05);if(C.some(xt=>xt.kind==="audio"&&/whoosh|swoosh|glitch/.test(xt.sfx||"")&&Math.abs(xt.start-ut)<.35))return;const gt=Ba(D.style.sfx)??Ba(lm[H%lm.length]);gt&&C.push({...zs(C,e,gt,ut,{id:a?a():`seam-join-${H}`}),seam:{join:!0}})})}const ot=Ju(C,{tracks:e});return C=ot.clips,$.push(...ot.notes),$.unshift(m.length>=2?`${m.length} scenes linked: ${F.map(G=>`${G.k}: ${G.style.id}${G.pair?` (${G.pair.a.role} → ${G.pair.b.role})`:""} ${Ns(G.b1-G.b0)}s`).join(", ")} — camera + whoosh`:"one scene so far — it will link to the next one"),{clips:C,camera:rt,notes:$,scenes:m.length,joins:F.map(G=>({k:G.k,start:G.b0,end:G.b1,style:G.style.id,...G.pair?{match:{a:G.pair.a.role,b:G.pair.b.role,score:G.pair.score}}:{}}))}}function dv(t,e={},o=null,{join:r,style:n,duration:a=null,ease:i=null,newId:l,seed:p,W:c,H:s}={}){const h=t.filter(S=>S.seam?.scene===r&&!S.seam.hero&&S.kind!=="audio");if(!Number.isInteger(r)||r<1||!h.length)throw Error("No such join — link the scenes first (makeSeamless)");const f=t.find(S=>S.seam?.flight===r)?.seam?.style??null,m=h.find(S=>S.seam.style||S.seam.dur||S.seam.ease||S.seam.shuffle||S.seam.not)?.seam??{};let y={style:m.style,dur:m.dur,ease:m.ease,shuffle:m.shuffle,not:m.not};if(n==="auto")y={},t=t.filter(S=>S.seam?.joinFx!==r);else if(n==="shuffle")y={...y,style:void 0,shuffle:(y.shuffle??0)+1,not:f??void 0};else if(n!=null){if(!ec(n))throw Error(`Unknown join style "${n}"`);if(ec(n).only==="footage")throw Error(`"${n}" is for cuts between filmed clips (joinCut), not a motion piece`);y={...y,style:n,not:void 0}}if(a!=null){if(!(a>=.2&&a<=1.2))throw Error("Join duration must be 0.2–1.2 s");y.dur=a}if(i!=null){if(!Object.hasOwn(Jt,i))throw Error(`Unknown easing "${i}"`);y.ease=i}const $=Object.fromEntries(Object.entries(y).filter(([,S])=>S!==void 0)),x=t.map(S=>{if(S.seam?.scene!==r||S.seam.hero||S.kind==="audio")return S;const{style:k,dur:b,ease:A,shuffle:I,not:P,...C}=S.seam;return{...S,seam:{...C,...$}}}),E=Rd(x,e,o,{newId:l,seed:p,W:c,H:s}),v=E.joins.find(S=>S.k===r)?.style;return $.style&&v!==$.style&&E.notes.push(`"${$.style}" does not fit these scenes — kept ${v}`),{...E,style:v}}const hv=t=>/\b(fillText|strokeText)\b/.test(String(t));function fv(t,e={},o=null,{join:r,code:n,params:a={},prompt:i="",duration:l,newId:p,seed:c,W:s,H:h}={}){if(!t.some(x=>x.seam?.flight===r))throw Error("No such join — link the scenes first (makeSeamless)");if(hv(n))throw Error("Claude Motion join layers must not draw text (the scenes own the words) — kept the join style");const f=Math.max(1,Math.min(Qe.maxDuration,Number(l)||1.2)),m=Jo({code:n,params:a,preset:"claude",prompt:String(i).slice(0,2e3)}),y={id:p?p():`seam-fx-${r}`,nodeId:"",kind:"image",url:"",label:`Claude Motion · nối ${r}`,volume:0,start:0,duration:ht(f),track:0,motion:{...m,duration:ht(f)},motionKeys:[],seam:{joinFx:r}},$=Rd([...t.filter(x=>x.seam?.joinFx!==r),y],e,o,{newId:p,seed:c,W:s,H:h});return{...$,layer:$.clips.find(x=>x.seam?.joinFx===r)?.id}}const Wo={minDuration:.4,maxDuration:3,defaultDuration:1.2,minAmount:1.05,maxAmount:1.3,defaultAmount:1.12,ramp:.35,defaultStyle:"smooth",styles:["cut","smooth","push"]},Gr=1/30,Ua=.4,mv=.7,Mi=(t,e,o)=>Math.max(e,Math.min(o,t)),mm=t=>+t.toFixed(4);function wc(t,e){const o=Array.isArray(e?.scenes)?e.scenes:[],r=(t.inPoint||0)+t.duration*(t.playbackRate||1)/2,n=o.find(a=>a.start<=r&&a.end>r&&Number.isFinite(a.subjectX))||o.find(a=>Number.isFinite(a.subjectX));return n?{x:Mi(n.subjectX,0,1),y:Number.isFinite(n.subjectY)?Mi(n.subjectY,0,1):.5}:null}function gv(t,e,o,r,n){const a=[];if(r==="cut"){if(t>=Gr&&a.push({time:ht(t-Gr),f:0,ease:"hold"}),a.push({time:t,f:1}),n)for(let l=t+Ua;l<e-Gr-.05;l+=Ua)a.push({time:ht(l),f:1});e>=o-1e-6?a.push({time:o,f:1}):a.push({time:ht(e-Gr),f:1,ease:"hold"},{time:e,f:0})}else if(r==="push"){if(a.push({time:t,f:0,ease:"ease-in-out"}),n)for(let l=t+Ua;l<e-Gr-.05;l+=Ua)a.push({time:ht(l),f:(l-t)/(e-Gr-t)});e>=o-1e-6?a.push({time:o,f:1}):a.push({time:ht(e-Gr),f:1,ease:"hold"},{time:e,f:0})}else{const l=Math.min(Wo.ramp,(e-t)/3);if(a.push({time:t,f:0,ease:"easy-ease"},{time:ht(t+l),f:1}),n)for(let p=t+l+Ua;p<e-l-.05;p+=Ua)a.push({time:ht(p),f:1});e>=o-1e-6?a.push({time:o,f:1}):a.push({time:ht(e-l),f:1,ease:"easy-ease"},{time:e,f:0})}const i=[];for(const l of a)(!i.length||l.time>i.at(-1).time+1e-6)&&i.push(l);return i}function gm(t,{at:e,duration:o=Wo.defaultDuration,amount:r=Wo.defaultAmount,style:n=Wo.defaultStyle,anchor:a=null}={}){if(t.kind==="audio"||t.kind==="model"||t.title||t.shape||t.motion)throw Error("Punch-in needs a video or image clip");if(!Wo.styles.includes(n))throw Error(`Punch-in style must be ${Wo.styles.join("/")}`);if(!Number.isFinite(e)||e<0||e>=t.duration-Gr)throw Error("Punch-in must start inside the clip");const i=Mi(Number.isFinite(o)?o:Wo.defaultDuration,Wo.minDuration,Wo.maxDuration),l=Mi(Number.isFinite(r)?r:Wo.defaultAmount,Wo.minAmount,Wo.maxAmount),p=ht(e);let c=ht(Math.min(t.duration,p+i));if(t.duration-c<Gr&&(c=t.duration),c-p<Gr*3)throw Error("Punch-in is too short for the clip");const s=Me(t,"zoom").length>=2||!!a&&(Me(t,"x").length>=2||Me(t,"y").length>=2),h=gv(p,c,t.duration,n,s),f=h[0].time,m=h.at(-1).time,y=a?a.x-.5:0,$=a?a.y-.5:0,x=(v,S)=>{const k=Ut(t,v,S.time),b=Ut(t,"zoom",S.time),A=Math.min(qi,b*(1+(l-1)*S.f));if(v==="zoom")return mm(A);const I=Math.max(0,(A-1)/2),P=-(A-b)*(v==="x"?y:$)*mv;return mm(Mi(k+Mi(P,-I,I),-1,1))};let E={...t};for(const v of a?["zoom","x","y"]:["zoom"]){const S=Me(t,v).filter(I=>I.time<f-.001||I.time>m+.001),k=h.map(I=>({time:I.time,value:x(v,I),...I.ease?{ease:Jt[I.ease]}:{}})),b=[...S,...k].sort((I,P)=>I.time-P.time),A=de(E,v,b);E={...E,...A}}return hn(E),{motionV:E.motionV,motionKeys:E.motionKeys,...E.posX!==void 0?{posX:E.posX,posY:E.posY,scale:E.scale}:{}}}const yv=/[!?]$/;function N1(t,{every:e=[2.5,5],max:o=12,lead:r=.08,from:n=0}={}){const[a,i]=e;if(!Array.isArray(t)||!t.length||!(a>0)||!(i>=a))return[];const l=t.map((c,s)=>{const h=String(c.word??""),f=t[s-1];let m=0;return c.kw===!0?m+=6:c.kw!==!1&&(m+=Math.max(0,cg(h)-1)),(!f||/[.!?…]$/.test(f.word)||c.start-f.end>.6)&&(m+=2),c.end-c.start>=.45&&(m+=1),yv.test(h)&&(m+=1),{at:Math.max(n,+(c.start-r).toFixed(3)),word:h,score:m,start:c.start}}).filter(c=>c.at>=n),p=[];for(;!(p.length>=o);){const c=p.length?p.at(-1).at+a:n,s=p.length?p.at(-1).at+i:n+i,h=l.filter(m=>m.at>=c-1e-9&&m.at<=s+1e-9);if(!h.length){const m=l.find(y=>y.at>s);if(!m)break;p.push({at:m.at,word:m.word,score:m.score});continue}const f=h.reduce((m,y)=>y.score>m.score?y:m);p.push({at:f.at,word:f.word,score:f.score})}return p}function F1(t,e){try{if(Array.isArray(t.captionWords)&&t.captionWords.length)return t.captionWords;if(Array.isArray(e?.words)&&e.words.length)return vd(t,e.words);const o=t.captions?.length?t.captions:Array.isArray(e?.transcript)?Jl(t,e.transcript):[];return o.length?Xc(o):[]}catch{return[]}}function zC(t,e,o={}){const r=Me(t,"zoom");return N1(F1(t,e),{from:.5,...o}).filter(n=>!r.some(a=>Math.abs(a.time-n.at)<=2.5*Gr)).map(n=>({...n,at:+(t.start+n.at).toFixed(3)}))}const ce=Object.freeze({wide:[2,3],close:[2,3],closeAmount:1.28,pushAmount:1.06,pushEvery:3,logo:2.6,packshot:2.6,cta:3.2,caption:{min:1.5,max:3.2,gap:.04,lead:.08},benefits:4.5,rating:3.4,callout:3.4,pieceMin:.5}),me=t=>+(+t).toFixed(3),Bo=t=>String(t??"").trim().slice(0,40),Yo=t=>String(t??"").toLowerCase().normalize("NFC").replace(/[.,!?…:;"“”'‘’()[\]{}]+/gu,"").trim(),kc=t=>/[.!?…:;]$/u.test(String(t??"").trim()),bv={một:1,mot:1,hai:2,ba:3,bốn:4,tư:4,năm:5,sáu:6,bảy:7,tám:8,chín:9,mười:10,one:1,two:2,three:3,four:4,five:5,six:6,seven:7,eight:8,nine:9,ten:10},Fp={first:1,second:2,third:3,fourth:4,fifth:5,sixth:6,đầu:1},Rp=new Set(["cuối","cuối cùng","final","last"]),Qu=t=>{const e=Yo(t);return/^\d{1,2}$/.test(e)?+e:bv[e]??null},wv=new Set(["là","thì","nhé","nha","đó","này","mình","sẽ","dùng","tiếp","theo","chính","của","we","i","is","the","use","a","an","then","you","to","it","s","with","và","rồi","ta","các","bạn","em","chị","anh"]),kv=new Set(["rồi","và","sau","then","and","xong","nhé","nha"]),ym=new Set(["thoa","xịt","đợi","chờ","massage","mát-xa","lắc","rửa","xả","ủ","bôi","apply","wait","spray","rinse","shake","leave","pump","dab","pat","vỗ","vuốt","gội"]);function Dd(t,e,o){const r=t.find(i=>i.id===e);if(!r)return[];const n=t.filter(i=>i.id===e||r.nodeId&&i.nodeId===r.nodeId&&i.track===r.track&&i.kind===r.kind&&(!i.mask||i.speakerLayout)&&!i.bubble),a=o.find(i=>i.id===r.nodeId);return n.flatMap(i=>F1(i,a).map(l=>({start:me(i.start+l.start),end:me(i.start+l.end),word:String(l.word)}))).sort((i,l)=>i.start-l.start)}function R1(t){const e=[];return t.forEach((o,r)=>{const n=Yo(o.word),a=t[r+1],i=t[r-1];let l=null,p=r+2,c=o.start,s=n==="step"?"Step":"Bước";if((n==="bước"||n==="step")&&a&&(l=Qu(a.word),l===null)){const f=Yo(a.word),m=f+" "+Yo(t[r+2]?.word);Fp[f]===1&&n==="bước"?l=1:Rp.has(m)?(l=-1,p=r+3):Rp.has(f)&&(l=-1)}if(l===null&&n==="step"&&i){const f=Yo(i.word);Fp[f]?(l=Fp[f],c=i.start,p=r+1):Rp.has(f)&&(l=-1,c=i.start,p=r+1)}if(l===null||(l===-1&&(l=(e.at(-1)?.number??0)+1),e.some(f=>f.number===l)))return;const h=[];for(let f=p;f<t.length&&h.length<3;f++){const m=Yo(t[f].word);if(!h.length&&wv.has(m)){if(kc(t[f].word))break;continue}if(!(Qu(t[f].word)!==null&&!h.length)&&(["bước","step"].includes(m)||(h.push(String(t[f].word).replace(/[.,!?…:;"“”]+$/u,"")),kc(t[f].word)||t[f+1]&&t[f+1].start-t[f].end>.5)))break}e.push({i:r,at:c,number:l,label:s,auto:h.join(" ")})}),e}function xv(t,e=new Set){const o=[];for(let r=0;r<t.length;r++){if(e.has(r)||!ym.has(Yo(t[r].word)))continue;const n=[];let a=r;for(;a<t.length&&n.length<6;a++){n.push(String(t[a].word).replace(/[,!?…:;"“”]+$/u,"").replace(/\.$/u,""));const i=Yo(t[a+1]?.word);if(kc(t[a].word)||/,$/u.test(t[a].word)||t[a+1]&&t[a+1].start-t[a].end>.45||ym.has(i)||kv.has(i))break}["đợi","chờ","wait"].includes(Yo(t[r].word))&&!n.slice(1).some(i=>Qu(i)!==null||/phút|giây|minute|second|chút|lát/u.test(Yo(i)))||n.length<2||(o.push({i:r,at:t[r].start,text:n.join(" ")}),r=a)}return o}function Mv(t,e,o=0){const r=String(e||"").split(/\s+/u).map(Yo).filter(a=>a.length>1);if(!r.length)return null;const n=Math.min(2,r.length);for(let a=0;a<t.length;a++){if(t[a].start<o)continue;let i=0;for(;i<r.length&&a+i<t.length&&Yo(t[a+i].word)===r[i];)i++;if(i>=n)return t[a].start}return null}function bm(t,e,o,r){const n=[...t].sort((i,l)=>i[0]-l[0]);let a=e;for(const[i,l]of n){if(a+o<=i+1e-6)break;l>a&&(a=l+.05)}return a+o<=r+1e-6?me(a):null}const cs=(t,e,o,r)=>{let n=null;for(const a of t){if(a.start<o||a.start>r)continue;const i=t[t.indexOf(a)-1],l=Math.abs(a.start-e)-(i&&(kc(i.word)||a.start-i.end>.25)?.6:0);(!n||l<n.score)&&(n={at:a.start,score:l})}return n?n.at:e},$v=t=>{try{const e=typeof t=="string"?JSON.parse(t||"{}"):t;return e&&typeof e=="object"&&!Array.isArray(e)?e:{}}catch{return{}}},vv=/sản phẩm|san pham|product|packshot|chai|lọ|tuýp|hộp|bottle|serum|kem|dầu|son/iu;function Ev({clips:t=[],materials:e=[],clipId:o,copy:r={},brand:n=null,en:a=!1,portrait:i=!0}={}){const l=(()=>{const V=t.find(d=>d.id===o);return V?t.filter(d=>d.id===o||V.nodeId&&d.nodeId===V.nodeId&&d.track===V.track&&d.kind===V.kind&&!d.mask).sort((d,w)=>d.start-w.start):[]})();if(!l.length)throw Error("productReview: the speaker clip was not found");const p=Dd(t,o,e),c=l[0].start,s=l.at(-1).start+l.at(-1).duration,h=s-c;if(h<6)throw Error("productReview: the clip is too short for a review (≥ 6 s)");const f=V=>{const d=e.find(w=>w.id===V);return d&&d.kind==="image"&&d.url?d.id:null},m=Bo(r.brand??n?.name??""),y=Bo(r.tagline??n?.tagline??""),$=f(r.logoImage)||f(n?.logoMaterialId),x=Bo(r.product??""),E=Bo(r.stepLabel??""),v=e.filter(V=>V.kind==="image"&&V.url&&V.id!==$&&V.role!=="reference"&&vv.test(`${V.label||""} ${(V.labels||[]).join(" ")} ${V.description||""}`)).map(V=>V.id),S=f(r.productImage)||v[0]||null,k=[],b=[],A=[],I=V=>(k.push(V),V),P=R1(p),C=new Set(P.flatMap(V=>[V.i,V.i+1,V.i+2,V.i+3,V.i+4])),z=Array.isArray(r.steps)?r.steps:[];for(const V of P){const d=z[V.number-1],w=Bo(typeof d=="string"?d:d?.name??V.auto);A.push({kind:"step",at:me(Math.max(c,V.at-ce.caption.lead)),number:V.number,label:E||(V.label==="Step"||a?"Step":"Bước"),text:w,image:f(typeof d=="object"?d?.image:null)||(v.length>=Math.max(2,P.length)?v[V.number-1]??null:null)})}const N=Array.isArray(r.instructions)?r.instructions.map(Bo).filter(Boolean):null;if(N){let V=0;for(const d of N){const w=d.split(/\s+/u).slice(0,2).map(Yo),T=p.findIndex((j,O)=>j.start>=V&&Yo(j.word)===w[0]&&(!w[1]||Yo(p[O+1]?.word)===w[1]));T<0||(V=p[T].end,A.push({kind:"do",at:me(Math.max(c,p[T].start-ce.caption.lead)),text:d}))}}else for(const V of xv(p,C))A.push({kind:"do",at:me(Math.max(c,V.at-ce.caption.lead)),text:Bo(V.text)});A.sort((V,d)=>V.at-d.at||(V.kind==="step"?-1:1));const F=me(Math.max(c+ce.logo+2,s-ce.cta)),K=me(c+ce.logo),_=[];for(const V of A){if(V.at<K-.3||V.at>F-ce.caption.min)continue;const d=_.at(-1);if(d&&V.at-d.at<ce.caption.min)if(V.kind==="step"&&d.kind!=="step")_.pop();else continue;_.push(V)}_.forEach((V,d)=>{const w=_[d+1]?.at??F;V.dur=me(Math.max(ce.caption.min,Math.min(ce.caption.max,w-ce.caption.gap-V.at)))});const q=Number.isFinite(+r.rating)&&r.rating!==null&&r.rating!==""?Math.max(0,Math.min(5,+r.rating)):null;let U=null;if(q!==null||r.verdict){const V=[..._].reverse().find(T=>T.at+T.dur>F-ce.rating),d=me(Math.max(F-ce.rating-.05,V?V.at+ce.caption.min+ce.caption.gap:0,K)),w=me(F-.05-d);if(w>=2.4){U={at:d,dur:w};for(const T of _)T.at+T.dur>d-ce.caption.gap&&(T.dur=me(d-ce.caption.gap-T.at))}}for(const V of _)b.push([V.at,V.at+V.dur]);U&&b.push([U.at,U.at+U.dur]);const rt=Mv(p,x,c),ot=rt!==null&&rt>=K?rt:cs(p,c+h*.28,K,c+h*.5);let G=x||m?bm(b,Math.max(K+.2,ot-.1),ce.packshot,F-.5):null,J=ce.logo,Z=ce.packshot;if(G===null&&(x||m)){const V=_[0]?.at??F,d=me(Math.max(c+1.4,Math.min(rt??c+1.4,K)-.1)),w=V-d-.05>=2?d:me(c+1.4),T=me(Math.min(ce.packshot,V-w-.05));T>=2&&(G=w,Z=T,J=me(w-c))}G!==null&&b.push([G,G+Z]);{const V=G!==null?[[G,G+Z]]:[];for(const d of _)if(d.image){if(V.some(([w,T])=>d.at<T+2&&d.at+d.dur>w-2)){d.image=null;continue}V.push([d.at,d.at+d.dur])}}const at=[...G!==null?[[G,G+Z]]:[],..._.filter(V=>V.image).map(V=>[V.at,V.at+V.dur])],D=(V,d)=>at.some(([w,T])=>V<T-.05&&d>w+.05),H=V=>l.find(d=>V>=d.start-1e-6&&V<d.start+d.duration-1e-6);let ut=cs(p,c+2.4,c+ce.wide[0],c+ce.wide[1]),gt=0,xt=c;for(;ut<F-ce.close[0];){const V=Math.min(F-.1,cs(p,ut+2.5,ut+ce.close[0],ut+ce.close[1])),d=H(ut);let w=d?Math.min(V,d.start+d.duration):V;const T=at.find(([j,O])=>ut<O-.05&&w>j+.05);if(T&&T[0]-ut>=1.2)w=T[0];else if(T){ut=cs(p,T[1]+.15,T[1]+.05,T[1]+.6),xt=T[1];continue}if(d&&w-ut>=ce.pieceMin&&!D(ut,w)&&I({op:"punchIn",clipId:o,at:me(ut),duration:me(Math.min(3,w-ut)),numberValue:ce.closeAmount,punchStyle:"cut",accent:!1}),gt++,gt%ce.pushEvery===0){const j=H(xt+.05),O=me(xt+.05),L=Math.min(ut-.05,j?j.start+j.duration:ut,O+3);j&&L-O>=1&&!D(O,L)&&I({op:"punchIn",clipId:o,at:O,duration:me(L-O),numberValue:ce.pushAmount,punchStyle:"push",accent:!1})}xt=V,ut=cs(p,V+2.4,V+ce.wide[0],V+ce.wide[1])}if($)I({op:"addElement",materialId:$,start:K,duration:me(s-K),posX:0,posY:i?.3:.385,scale:i?.16:.1,anim:{in:"fade",out:"fade"}});else if(m){const V=s-K,d=Math.ceil(V/Qe.maxDuration-1e-9);for(let w=0;w<d;w++){const T=K+V*w/d,j=K+V*(w+1)/d;I({op:"addMotion",motionPreset:"rv-brand-watermark",start:me(T),duration:me(j-T),placement:"lower",text:m,...w>0?{numberValue:w<d-1?3:1}:d>1?{numberValue:2}:{}})}}(m||$)&&(I({op:"addMotion",motionPreset:"rv-logo-open",start:me(c),duration:J,placement:"center",text:m||x||" ",...y?{subText:y}:{},...$?{numberValue:1}:{}}),$&&I({op:"addElement",materialId:$,start:me(c+.15),duration:me(J-.3),posX:0,posY:i?-.02:-.06,scale:i?.3:.2,anim:{in:"pop",out:"fade"}})),G!==null&&(I({op:"addMotion",motionPreset:"rv-packshot-title",start:G,duration:Z,placement:"center",text:x||m,subText:r.tag===""?" ":Bo(r.tag??(a?"New":"Mới")),items:[m||" ",...y?[y]:[]]}),S&&I({op:"addElement",materialId:S,start:me(G+.2),duration:me(Z-.2),posX:i?0:.2,posY:i?.1:.08,scale:i?.62:.5,anim:{in:"pop",out:"none"}}));for(const V of _){if(V.image){const w=V.dur;I({op:"addMotion",motionPreset:"rv-packshot-title",start:V.at,duration:w,placement:"center",text:x||" ",numberValue:1}),I({op:"addElement",materialId:V.image,start:me(V.at+.05),duration:me(w-.05),posX:i?0:.2,posY:i?.1:.08,scale:i?.62:.5,anim:{in:"fade",out:"none"}})}const d=V.image?{params:{color:"#2b2230"}}:{};V.kind==="step"?I({op:"addMotion",motionPreset:"rv-step-caption",start:V.at,duration:V.dur,placement:V.image?"top":"center",text:V.text||" ",subText:V.label,numberValue:V.number,...d}):I({op:"addMotion",motionPreset:"rv-instruction",start:V.at,duration:V.dur,placement:"center",text:V.text,...d})}const u=(V,d)=>{const w=bm(b,Number.isFinite(+d)?Math.max(K,+d):K+.5,V,F-.2);return w!==null&&b.push([w,w+V]),w},st=(Array.isArray(r.benefits)?r.benefits:[]).map(Bo).filter(Boolean).slice(0,4);if(st.length){const V=u(ce.benefits,r.benefitsAt);V!==null&&I({op:"addMotion",motionPreset:"rv-benefit-list",start:V,duration:ce.benefits,placement:"center",text:Bo(r.benefitsTitle??(a?"Why it works":"Vì sao nên dùng")),items:st})}if(r.callout&&typeof r.callout=="object"&&r.callout.text){const V=u(ce.callout,r.callout.at);V!==null&&I({op:"addMotion",motionPreset:"rv-product-callout",start:V,duration:ce.callout,placement:"center",text:Bo(r.callout.text),...r.callout.sub?{subText:Bo(r.callout.sub)}:{},posX:Math.max(-1,Math.min(1,+r.callout.posX||-.2)),posY:Math.max(-1,Math.min(1,+r.callout.posY||.18))})}return U&&I({op:"addMotion",motionPreset:"rv-rating",start:U.at,duration:U.dur,placement:"center",text:Bo(r.verdict??(a?"Worth it":"Đáng mua")),numberValue:q??0,...r.ratingNote?{subText:Bo(r.ratingNote)}:{}}),I({op:"addMotion",motionPreset:"rv-cta-end",start:F,duration:me(s-F),placement:"lower",text:x||m||(a?"Shop now":"Mua ngay"),subText:Bo(r.cta??(a?"Shop now · Link in bio":"Mua ngay · Link ở bio"))}),k}function Sv(t,{clips:e=[],materials:o=[],brand:r=null,portrait:n=!0,en:a=!1,simulate:i=null}={}){if(!Array.isArray(t)||!t.some(h=>h?.op==="productReview"))return t;const l=[],p=[];let c=0;const s=h=>{const f=typeof h=="string"&&/^new:(\d+)$/.exec(h);if(!f)return h;const m=+f[1];let y=0;for(const $ of p)m>$.after&&(y+=$.by);return`new:${m+y}`};for(const h of t){const f=h&&(h.clipId||h.fromClipId||h.sourceClipId)?{...h,...h.clipId?{clipId:s(h.clipId)}:{},...h.fromClipId?{fromClipId:s(h.fromClipId)}:{},...h.sourceClipId?{sourceClipId:s(h.sourceClipId)}:{}}:h;if(f?.op!=="productReview"){l.push(f),/^(add|lockup$)/.test(f?.op??"")&&c++;continue}const m=f.fromClipId??f.clipId,y=e.find(k=>k.id===m),$=y&&o.find(k=>k.id===y.nodeId),x=[];y&&f.booleanValue!==!0&&Array.isArray($?.pauses)&&$.pauses.length&&!l.some(k=>k?.op==="cutPauses"&&k.clipId===m)&&x.push({op:"cutPauses",clipId:m,numberValue:.5,booleanValue:!0});let E=e;if(i&&(x.length||l.some(k=>["cutPauses","removeRetakes","split","trim","delete","move","compact","ripple"].includes(k?.op))))try{E=i([...l,...x])??e}catch{E=e}const v=[...x,...Ev({clips:E,materials:o,clipId:m,copy:$v(f.prompt),brand:r,en:a,portrait:n})],S=v.filter(k=>/^add/.test(k.op)).length;l.push(...v),S&&p.push({after:c,by:S})}return l}const oa=Object.freeze({beat:{min:2.5,max:6,base:2.8,perWord:.2},maxBeats:8,gap:0,photoScale:.5,photoScaleTall:.62}),Iv=Object.freeze({white:{color:"#ffffff",width:10},"white-red":{color:"#ffffff",width:10,accent:{color:"#e2382f",distance:5,angle:135}},paper:{color:"#fbf7ec",width:5},black:{color:"#1c1c22",width:5}}),Dp="#2a241c",Bp="#d62b25",wm="#f6efdd",Ke=t=>+(+t).toFixed(3),ps=(t,e)=>typeof t=="string"?t.trim().slice(0,e):"";function Av(t,e=[]){let o;try{o=typeof t=="string"?JSON.parse(t):t}catch{throw Error("voxCollage: the copy must be JSON")}const r=new Map(e.filter(a=>a.kind==="image"&&a.url).map(a=>[a.id,a])),n=(Array.isArray(o?.scenes)?o.scenes:[]).filter(a=>r.has(a?.materialId)).slice(0,oa.maxBeats).map(a=>({materialId:a.materialId,label:ps(a.label,40),year:ps(a.year,12),caption:ps(a.caption,140),keys:(Array.isArray(a.keys)?a.keys:[]).map(i=>ps(i,24)).filter(Boolean).slice(0,3),cutout:["person","object"].includes(a.cutout)?a.cutout:"none",old:a.old===!0}));if(!n.length)throw Error("voxCollage: no scene uses an image from Media");return{title:ps(o?.title,60),beats:n}}function km(t){const e=`${t.caption} ${t.keys.join(" ")}`.split(/\s+/).filter(Boolean).length;return Ke(Math.max(oa.beat.min,Math.min(oa.beat.max,oa.beat.base+e*oa.beat.perWord)))}function Cv({prompt:t,materials:e,start:o=0,portrait:r=!1}){const{beats:n}=Av(t,e),a=[],i={n:0},l=h=>(a.push(h),["addElement","addText","addMotion"].includes(h.op)&&i.n++,`new:${i.n}`),p=n.reduce((h,f)=>h+km(f),0),c=Ke(Math.max(0,o));for(let h=0;h<p-.001;h+=Qe.maxDuration){const f=l({op:"addMotion",motionPreset:"fxo-paper-bg",start:Ke(c+h),duration:Ke(Math.min(Qe.maxDuration,p-h)),label:"Motion · Nền giấy"});a.push({op:"collageStyle",clipId:f,back:!0})}let s=c;n.forEach((h,f)=>{const m=km(h),y=f%2===0,$=y?-1:1,x=h.cutout!=="none",E=r?0:$*.24,v=r?-.14:.04,S=r?oa.photoScaleTall:oa.photoScale,k=l({op:"addElement",materialId:h.materialId,start:Ke(s),duration:m,posX:E,posY:v,scale:S,anim:x?{in:"pop",out:"fade",loop:"none"}:{in:"none",out:"fade",loop:"none"}});a.push({op:"collageStyle",clipId:k,sticker:x?"white-red":"paper",...x?{cutout:h.cutout}:{torn:"all",watercolor:!0,seed:f+1}}),h.old&&a.push({op:"setEffect",clipId:k,property:"mono",numberValue:.95}),x&&l({op:"addElement",elementId:"doodle-circle",start:Ke(s+.6),duration:Ke(m-.6),posX:E,posY:v,scale:Ke(S*.95),primary:"#e2382f"}),h.label&&l({op:"addText",text:h.label,styleId:"tape-label",accentColor:"#e6d9b8",color:Dp,fontFamily:"Oswald",fontSize:40,placement:"top",align:y?"left":"right",start:Ke(s+.15),duration:Ke(m-.15),preset:"slide-left"}),h.year&&(l({op:"addText",text:h.year,styleId:"serif-year",accentColor:Bp,color:Bp,fontFamily:"Playfair Display",fontSize:96,placement:"top",align:y?"right":"left",start:Ke(s+.35),duration:Ke(m-.35),preset:"pop-in"}),l({op:"addElement",elementId:"doodle-underline",start:Ke(s+.7),duration:Ke(m-.7),posX:r?0:-$*.62,posY:-.46,scale:.22,primary:Bp})),h.keys.length&&l({op:"addText",text:h.keys.join(`
|
|
118
|
+
`),styleId:"accent-bar",accentColor:wm,color:Dp,fontFamily:"Oswald",fontSize:44,placement:"center",align:r?"center":y?"right":"left",start:Ke(s+.9),duration:Ke(m-.9),preset:"slide-left"}),h.caption&&l({op:"addText",text:h.caption,styleId:"accent-bar",accentColor:wm,color:Dp,fontFamily:"Noto Serif",fontSize:30,placement:"lower",align:"center",start:Ke(s+.5),duration:Ke(m-.5),preset:"slide-up"}),s=Ke(s+m+oa.gap)});for(let h=0;h<p-.001;h+=Qe.maxDuration)l({op:"addMotion",motionPreset:"fxo-paper-grain",start:Ke(c+h),duration:Ke(Math.min(Qe.maxDuration,p-h)),label:"Motion · Vân giấy"});return a}const xm=["addClip","addBroll","generateBroll","addText","addShape","addMotion","addElement","addCard","addSolid","addAdjustmentLayer","generateElement"];function jv(t,{materials:e=[],portrait:o=!1}={}){if(!Array.isArray(t)||!t.some(l=>l?.op==="voxCollage"))return t;const r=[],n=[];let a=0;const i=l=>{const p=typeof l=="string"&&/^new:(\d+)$/.exec(l);if(!p)return l;const c=Number(p[1]);return`new:${c+n.filter(([s])=>s<c).reduce((s,[,h])=>s+h,0)}`};for(const l of t){if(l?.op!=="voxCollage"){r.push(l&&(l.clipId||Array.isArray(l.clipIds))?{...l,...l.clipId?{clipId:i(l.clipId)}:{},...Array.isArray(l.clipIds)?{clipIds:l.clipIds.map(i)}:{}}:l),xm.includes(l?.op)&&a++;continue}const p=Cv({prompt:l.prompt,materials:e,start:Number.isFinite(l.start)?l.start:0,portrait:o}),c=a+n.reduce((h,[,f])=>h+f,0),s=h=>{const f=typeof h=="string"&&/^new:(\d+)$/.exec(h);return f?`new:${Number(f[1])+c}`:h};for(const h of p)r.push(h.clipId?{...h,clipId:s(h.clipId)}:h);n.push([a,p.filter(h=>xm.includes(h.op)).length])}return r}const ve=Object.freeze({bands:{portrait:{top:[.06,.4],center:[.33,.67],lower:[.58,.86]},landscape:{top:[.05,.33],center:[.3,.7],lower:[.64,.92]}},head:.14,halfWidth:{portrait:.3,landscape:.17},face:{portrait:{x:.5,y:.36},landscape:{x:.5,y:.38}},skip:new Set(["exp-room-panel","exp-question-banner","rv-brand-watermark","rv-product-callout","course-tool-badge","course-key-takeaway","course-progress-bar","course-screen-frame","course-callout","course-pip-frame","course-label-tag","course-journey-line","course-photo-pop","course-cover-insert","course-framework-stack","course-split-cards","course-compare-board","course-doc-highlight","course-map-pins","course-brand-bug"]),headOnly:new Set(["rv-step-caption","rv-instruction","rv-logo-open","rv-benefit-list","rv-rating","rv-cta-end","course-question-nav","course-step-tiles"]),chin:.1});function xc(t,e,o,{W:r,H:n}){if(!t||t.kind!=="video"||t.motion||t.title||t.shape)return null;const a=Array.isArray(e?.scenes)?e.scenes:[],i=(t.inPoint||0)+(o-t.start)*(t.playbackRate||1),l=a.find(E=>E.start<=i&&E.end>i&&Number.isFinite(E.subjectX))||a.find(E=>Number.isFinite(E.subjectX)),p=!!(t.captions?.length||t.captionWords?.length||e?.transcript?.length||e?.words?.length);if(!l&&!p)return null;const c=n>r*1.1,s=c?ve.face.portrait:ve.face.landscape;if(!l)return{...s,assumed:!0};const h=e?.width&&e?.height?e.width/e.height:r/n,f=r/n,m=t.scale??1,y=h>f?h/f:1,$=h<f?f/h:1,x=Number.isFinite(l.subjectY)?l.subjectY:.4;return{x:.5+(l.subjectX-.5)*y*m+(t.posX??0),y:.5+(x-.5)*$*m+(t.posY??0)}}function Mm(t,e,o,r=!1){const n=e.y-ve.head,a=o?ve.halfWidth.portrait:ve.halfWidth.landscape;return e.x+a<.08||e.x-a>.92?!1:t[1]>n&&(!r||t[0]<e.y+ve.chin)}const lo=Object.freeze({corners:["bottom-left","bottom-right","top-left","top-right"],size:.3,minSize:.18,maxSize:.45,margin:.045,minDuration:1,maxDuration:30,zIndex:60,points:24,ring:"#ffffff",minFace:.08,rim:Object.freeze({color:"#ffffff",width:.006,glow:.35})}),qo=(t,e,o)=>Math.max(e,Math.min(o,t)),Ee=t=>+t.toFixed(4);function D1(t,e,o,r,n,a=lo.points){const i=o*r/n;return Array.from({length:a},(l,p)=>{const c=p/a*2*Math.PI;return[Ee(t+Math.cos(c)*o),Ee(e+Math.sin(c)*i)]})}function td(t,{W:e,H:o,mw:r,mh:n,corner:a="bottom-left",size:i=lo.size,anchor:l=null,cx:p,cy:c,ru:s,posX:h=null,posY:f=null}){const m=r<=n,y=Math.min(.5,.5*n/r),$=qo(Number.isFinite(s)?s:Math.min(m?.34:.34*n/r,y),lo.minFace*Math.min(1,n/r),y),x=$*r/n,E=qo(Number.isFinite(p)?p:l?.x??.5,$,1-$),v=qo(Number.isFinite(c)?c:l?.y??(m?.36:.45),x,1-x),S=t.fit==="cover"?Math.max(e/r,o/n):Math.min(e/r,o/n),k=r*S,b=n*S,A=qo(i,lo.minSize,lo.maxSize),I=A/2*Math.min(e,o),P=I/($*k),C=a.endsWith("left"),z=a.startsWith("bottom"),N=lo.margin*Math.min(e,o),F=(q,U)=>qo(q*U,I,U-I)-U/2,K=Number.isFinite(h)?F(h,e):(C?-1:1)*(e/2-N-I),_=Number.isFinite(f)?F(f,o):(z?1:-1)*(o/2-N-I);return{mask:{v:1,mw:r,mh:n,keys:[{t:0,pts:D1(E,v,$,r,n)}],smooth:!0,feather:.004},posX:Ee((K-P*(E-.5)*k)/e),posY:Ee((_-P*(v-.5)*b)/o),scale:Ee(P),bubble:{cx:Ee(E),cy:Ee(v),ru:Ee($),size:Ee(A),corner:a}}}function Tv(t,e,{at:o,duration:r,corner:n="bottom-left",size:a,W:i=1080,H:l=1920,material:p=null,newId:c,posX:s=null,posY:h=null,color:f=null}){const m=t.find(I=>I.id===e);if(!m||m.kind!=="video"||m.title||m.shape||m.motion||m.gen)throw Error("Speaker bubble needs a video clip of the speaker");if(!lo.corners.includes(n))throw Error(`Bubble corner must be ${lo.corners.join("/")}`);const y=ht(Math.max(m.start,o)),$=ht(Math.min(m.start+m.duration,y+qo(Number.isFinite(r)?r:5,lo.minDuration,lo.maxDuration)));if($-y<lo.minDuration-1e-6)throw Error("Speaker bubble must start at least 1 s before the clip ends");const x=Math.round(p?.width)||(i<=l?1080:1920),E=Math.round(p?.height)||(i<=l?1920:1080);let v=t,S=m;const k=[c?.()??`${m.id}-b`,c?.()??`${m.id}-a`];if(y>m.start+1e-6){const[I,P]=Ne(S,y,k[0]);P&&(v=v.flatMap(C=>C.id===S.id?[I,P]:[C]),S=P)}if($<S.start+S.duration-1e-6){const[I,P]=Ne(S,$,k[1]);P&&(v=v.flatMap(C=>C.id===S.id?[I,P]:[C]),S=I)}const b=td(S,{W:i,H:l,mw:x,mh:E,corner:n,size:a,anchor:wc(S,p),posX:s,posY:h}),A={...S,motionV:2,motionKeys:[],posX:b.posX,posY:b.posY,scale:b.scale,mask:b.mask,bubble:b.bubble,zIndex:lo.zIndex,edge:{...lo.rim,...f?{color:f}:{}},shadow:{...vn,opacity:.55,blur:18,distance:8},enter:{type:"pop",duration:.3},exit:{type:"zoom-out",duration:.2}};for(const I of["glow","person","roto","planar","scaleX","scaleY","anchorX","anchorY","tiltX","tiltY","rotation","crop","pin","layout"])delete A[I];return{clips:v.map(I=>I.id===S.id?A:I),bubbleId:S.id}}const mr=Object.freeze({width:.28,minWidth:.16,maxWidth:.45,aspect:.86,x:.81,y:.45,radius:.07,margin:.04,portrait:Object.freeze({width:.44,x:.72,y:.76}),zIndex:60,minDuration:1,maxDuration:600,rim:Object.freeze({width:.005,glow:.7})});function ed({W:t,H:e,width:o,cx:r,cy:n,aspect:a=mr.aspect}={}){const i=e>t*1.1,l=i?mr.portrait:mr,p=mr.margin*Math.min(t,e),c=t*qo(Number.isFinite(o)?o:l.width,mr.minWidth,mr.maxWidth),s=Math.min(e*.86,c/qo(a,.4,2)),h=qo(t*(Number.isFinite(r)?r:l.x)-c/2,p,t-p-c),f=qo(e*(Number.isFinite(n)?n:l.y)-s/2,p,e-p-s);return{x:h,y:f,w:c,h:s,params:{posX:Ee((h+c/2)/t),posY:Ee((f+s/2)/e),pw:Ee(c/t),ph:Ee(s/e),radius:mr.radius}}}function Ov(t,{W:e,H:o,mw:r,mh:n,rect:a,anchor:i=null}){const l=a.w/a.h,p=r<=n;let c=n*(p?.42:.74),s=c*l;s>r&&(s=r,c=s/l),c>n&&(c=n,s=c*l);const h=i?.x??.5,f=i?.y??(p?.36:.4),m=qo(h,s/r/2,1-s/r/2),y=qo(f+c/n*.24,c/n/2,1-c/n/2),$=t.fit==="cover"?Math.max(e/r,o/n):Math.min(e/r,o/n),x=r*$,E=n*$,v=a.w/(s*$),S=qo(2*mr.radius*a.w/Math.min(a.w,a.h),0,1),k=Yn({kind:"rect",cx:Ee(m),cy:Ee(y),w:Ee(s/r),h:Ee(c/n),rot:0,round:Ee(S)},r,n);return{mask:gr({mw:r,mh:n},[k]),posX:Ee((a.x+a.w/2-e/2-v*(m-.5)*x)/e),posY:Ee((a.y+a.h/2-o/2-v*(y-.5)*E)/o),scale:Ee(v)}}function Pv(t,e,{at:o,duration:r,width:n,cx:a,cy:i,aspect:l,color:p="#ff2d3f",W:c=1280,H:s=720,material:h=null,newId:f}){const m=t.find(P=>P.id===e);if(!m||m.kind!=="video"||m.title||m.shape||m.motion||m.gen)throw Error("Speaker window needs a video clip of the speaker");if(!/^#[0-9a-f]{6}$/i.test(String(p)))throw Error("Speaker window color must be #RRGGBB");const y=ht(Math.max(m.start,o)),$=ht(Math.min(m.start+m.duration,y+qo(Number.isFinite(r)?r:5,mr.minDuration,mr.maxDuration)));if($-y<mr.minDuration-1e-6)throw Error("Speaker window must start at least 1 s before the clip ends");const x=Math.round(h?.width)||(c<=s?1080:1920),E=Math.round(h?.height)||(c<=s?1920:1080);let v=t,S=m;const k=[f?.()??`${m.id}-wb`,f?.()??`${m.id}-wa`];if(y>m.start+1e-6){const[P,C]=Ne(S,y,k[0]);C&&(v=v.flatMap(z=>z.id===S.id?[P,C]:[z]),S=C)}if($<S.start+S.duration-1e-6){const[P,C]=Ne(S,$,k[1]);C&&(v=v.flatMap(z=>z.id===S.id?[P,C]:[z]),S=P)}const b=ed({W:c,H:s,width:n,cx:a,cy:i,...Number.isFinite(l)?{aspect:l}:{}}),A=Ov(S,{W:c,H:s,mw:x,mh:E,rect:b,anchor:wc(S,h)}),I={...S,motionV:2,motionKeys:[],posX:A.posX,posY:A.posY,scale:A.scale,mask:A.mask,zIndex:mr.zIndex,edge:{color:p.toLowerCase(),...mr.rim},shadow:{...vn,opacity:.5,blur:22,distance:6},enter:{type:"fade",duration:.3},exit:{type:"fade",duration:.25}};for(const P of["glow","person","roto","planar","scaleX","scaleY","anchorX","anchorY","tiltX","tiltY","rotation","crop","pin","layout","bubble"])delete I[P];return{clips:v.map(P=>P.id===S.id?I:P),windowId:S.id}}function zv(t,{W:e,H:o}){if(t?.bubble)return t.bubble;const r=t?.mask?.v===1&&t.mask.keys?.[0]?.pts;if(!r||r.length!==lo.points||t.zIndex!==lo.zIndex)return null;const n=r.map(m=>m[0]),a=r.map(m=>m[1]),i=(Math.min(...n)+Math.max(...n))/2,l=(Math.min(...a)+Math.max(...a))/2,p=(Math.max(...n)-Math.min(...n))/2,{mw:c,mh:s}=t.mask,h=t.fit==="cover"?Math.max(e/c,o/s):Math.min(e/c,o/s),f=2*(t.scale??1)*p*c*h/Math.min(e,o);return{cx:Ee(i),cy:Ee(l),ru:Ee(p),size:Ee(qo(f,lo.minSize,lo.maxSize)),corner:`${(t.posY??0)<0?"top":"bottom"}-${(t.posX??0)>0?"right":"left"}`}}function LC(t,e,{W:o,H:r}){const n=zv(t,{W:o,H:r});if(!n)throw Error("Not a speaker bubble");const{mw:a,mh:i}=t.mask,l={...n,...e},p=td(t,{W:o,H:r,mw:a,mh:i,...n}),c=td(t,{W:o,H:r,mw:a,mh:i,...l}),s=e.corner===void 0||e.corner===n.corner,h=s?(t.posX??0)-p.posX:0,f=s?(t.posY??0)-p.posY:0;return{mask:c.mask,posX:Ee(c.posX+h),posY:Ee(c.posY+f),scale:c.scale,bubble:c.bubble}}const St=Object.freeze({nav:{dur:5,min:2.5,max:7},steps:{dur:4,min:1.5},tool:{dur:4,min:2,max:8,maxCount:12},takeaway:5,card:3.5,questionGap:20,questionPause:.6,stepGap:120,punch:{every:[8,15],amount:1.1,max:3,maxCount:60},lift:.1,maxItems:6,screen:{landscape:{w:.84,h:.8,cy:.535},portrait:{w:.92,h:.62,cy:.45}},fade:.4,overhead:{min:2,max:120,fade:.25,maxCount:12},label:{dur:4,w:.22,gap:30,maxAuto:2},journey:{dur:8,min:3,a:.6,b:.8,delay:.3,r:{landscape:.06,portrait:.07}},photo:{dur:4,min:2,group:2.5,size:[.34,.27,.22],minSize:.14,rot:[-6,5,-3],maxCount:12},cover:{dur:4.5,min:2,size:.52,rot:6},framework:{w:.26,minW:.17,min:2,max:6,hold:4,gap:30,step:1.2,lead:.3,within:180,maxCount:3},split:{dur:6,min:2,max:20,fade:.25,maxCount:12,landscape:{m:[.35,.5,.6,.78],p:[.815,.5,.27,.78]},portrait:{m:[.5,.27,.88,.36],p:[.5,.7,.44,.4]}},compare:{dur:9,min:4,max:20,within:90,side:30,lines:3,maxAuto:2},doc:{dur:5,min:2,max:20,zoom:.05,w:.8,h:.8,cy:.52,fade:.3,maxCount:8},map:{dur:7,min:3,max:20,pins:4,fade:.35},brand:{h:.06,maxW:.16,margin:[.045,.05]}}),$m=Object.freeze(Object.keys(hg)),vm=Object.freeze(["questions","chapters","steps","none"]),Lv=Object.freeze({style:"karaoke",position:"bottom",font:"Be Vietnam Pro",perGroup:3,emphasis:!0,emphasisColor:"#8fc4ff",emphasisColor2:"#3d7bff",size:.8}),Tt=t=>+(+t).toFixed(3),Ko=(t,e,o)=>Math.max(e,Math.min(o,t)),Ur=t=>String(t??"").toLowerCase().normalize("NFC").replace(/[.,!?…:;"“”'‘’()[\]{}]+/gu,"").trim(),Nv=t=>/[.!?…]$/u.test(String(t??"").trim()),Ki=t=>String(t??"").replace(/[.,!?…:;"“”]+$/u,""),Ga=t=>{const e=String(t??"").trim().replace(/[.,:;…"“”]+$/u,"");return e.charAt(0).toUpperCase()+e.slice(1)},ge=(t,e)=>String(t??"").replace(/\s+/gu," ").trim().slice(0,e),Cn=(t,e=24)=>{let o="";for(const r of Ki(String(t??"")).split(/[\s,;:]+/u).filter(Boolean)){const n=o?o+" "+r:r;if(n.length>e)break;o=n}return Ki(o)},Fv=/[ăâđêôơưạảấầẩẫậắằẳẵặẹẻẽếềểễệỉịọỏốồổỗộớờởỡợụủứừửữựỳỵỷỹ]/iu,Rv={một:1,mot:1,hai:2,ba:3,bốn:4,tư:4,năm:5,sáu:6,bảy:7,tám:8,chín:9,mười:10,one:1,two:2,three:3,four:4,five:5,six:6,seven:7,eight:8,nine:9,ten:10},Fs=t=>{const e=Ur(t);return/^\d{1,2}$/u.test(e)?+e:Rv[e]??null},tp=new Set(["là","thì","nhé","nha","đó","này","đây","của","chúng","ta","mình","sẽ","về","is","the","about","we","will","so","a","an","và","rồi"]),Mc={nhất:1,hai:2,ba:3,tư:4,năm:5,sáu:6},$c={first:1,firstly:1,second:2,secondly:2,third:3,thirdly:3,fourth:4,fourthly:4,fifth:5,finally:-1,lastly:-1},Dv=Object.freeze([{re:/trợ lý ai|chatbot|chat ?bot|(?<![\p{L}])assistant|ai chat|trợ lý ảo|công cụ ai/iu,vi:"Trợ lý AI",en:"AI assistant",icon:"robot"},{re:/tạo ảnh|vẽ ảnh|image generator|ảnh ai|ai image/iu,vi:"Tạo ảnh AI",en:"AI image maker",icon:"camera"},{re:/tạo video|dựng video|video editor|edit video|làm video/iu,vi:"Dựng video",en:"Video editor",icon:"video-cam"},{re:/trình duyệt|browser/iu,vi:"Trình duyệt",en:"Web browser",icon:"globe"},{re:/bảng tính|spreadsheet/iu,vi:"Bảng tính",en:"Spreadsheet",icon:"calculator"},{re:/trình chiếu|slide|presentation|thuyết trình/iu,vi:"Trình chiếu",en:"Slides",icon:"monitor"},{re:/soạn thảo|văn bản|word processor|text editor/iu,vi:"Soạn thảo văn bản",en:"Text editor",icon:"document"},{re:/lập trình|viết code|code editor|coding/iu,vi:"Viết code",en:"Code editor",icon:"code"},{re:/ghi chú|note app|notes app|note-taking/iu,vi:"Ghi chú",en:"Notes",icon:"pencil"},{re:/công cụ tìm kiếm|search engine|tìm kiếm google|tra cứu/iu,vi:"Tìm kiếm",en:"Search",icon:"search"},{re:/dịch thuật|translator|translate/iu,vi:"Dịch thuật",en:"Translator",icon:"translate"},{re:/email|thư điện tử/iu,vi:"Email",en:"Email",icon:"mail"}]),Bv=/màn hình|screen|record|quay màn|demo|browser|trình duyệt|capture|hướng dẫn thao tác|screencast/iu;function _v(t){const e=[];let o=null;return t.forEach((r,n)=>{const a=t[n-1],i=a?r.start-a.end:1/0;(!o||i>.8||Nv(a.word))&&(o={start:r.start,end:r.end,words:[],gap:i,i0:n},e.push(o)),o.words.push(r),o.end=r.end}),e.map(r=>({...r,text:r.words.map(n=>String(n.word)).join(" ")}))}const Vi=(t,e,o=12)=>{const r=t.words.slice(e).map(n=>String(n.word));for(;r.length&&tp.has(Ur(r[0]));)r.shift();return r.slice(0,o).join(" ").replace(/^[,:–-]+\s*/u,"")},Em={tiếp:null,đầu:1,cuối:null};function Gv(t){const e=t.words.map(o=>Ur(o.word));for(let o=0;o<Math.min(5,e.length);o++){if(e[o]==="câu"&&e[o+1]==="hỏi"){let r=o+2;["số","thứ"].includes(e[r])&&r++;const n=Fs(t.words[r]?.word);if(n!==null)return{j:r+1,number:n};if(e[r]in Em&&["theo","tiên","cùng"].includes(e[r+1]))return{j:r+2,number:Em[e[r]]};continue}if(e[o]==="question"){let r=o+1;["number","no"].includes(e[r])&&r++;const n=Fs(t.words[r]?.word);if(n!==null)return{j:r+1,number:n};if(["next","first","last","final"].includes(e[o-1]))return{j:r,number:e[o-1]==="first"?1:null}}}return null}function Kv(t){const e=[];if(t.forEach((r,n)=>{const a=Gv(r);if(!a)return;let i=Vi(r,a.j,14);i.split(" ").filter(Boolean).length<3&&t[n+1]&&(i=t[n+1].text),e.push({at:r.start,number:a.number,text:ge(Ga(i),90)})}),e.length>=2)return e;const o=[];for(const r of t)!/[??]$/u.test(String(r.words.at(-1)?.word??"").trim())||r.words.length<4||!(r.gap>=St.questionPause)&&r!==t[0]||o.length&&r.start-o.at(-1).at<St.questionGap||o.push({at:r.start,text:ge(Ga(r.text),90)});return o}function Vv(t){const e=[];for(const o of t){const r=o.words.map(n=>Ur(n.word));for(let n=0;n<Math.min(4,r.length-1);n++){if(!["chương","phần","chapter","part","module","bài"].includes(r[n]))continue;const a=Fs(o.words[n+1].word);if(a!==null){e.some(i=>i.number===a)||e.push({at:o.start,number:a,title:ge(Ki(Vi(o,n+2,8)),60)});break}}}return e}function Wv(t,e){const o=(i,l)=>{const p=e.find(c=>i>=c.i0&&i<c.i0+c.words.length);return p?Cn(Vi(p,l-p.i0,6)):""},r=R1(t).map(i=>({at:i.at,number:i.number,label:o(i.i,i.i+(Fs(t[i.i+1]?.word)!==null||Ur(t[i.i]?.word)==="bước"?2:1))||ge(i.auto,24)}));for(const i of e){const l=Ur(i.words[0]?.word),p=Ur(i.words[1]?.word);let c=null,s=1;l==="thứ"&&Mc[p]?(c=Mc[p],s=2):$c[l]&&(c=$c[l]),c!==null&&(c===-1&&(c=(r.filter(h=>h.at<i.start).at(-1)?.number??0)+1),!r.some(h=>Math.abs(h.at-i.start)<1.5)&&r.push({at:i.start,number:c,label:Cn(Vi(i,s,6))}))}r.sort((i,l)=>i.at-l.at);const n=[];for(const i of r){const l=n.at(-1),p=l?.at(-1);!l||i.number===1&&p.number!==1||i.number<=p.number||i.at-p.at>St.stepGap?n.push([i]):l.push(i)}const a=[];for(const i of n){if(i.length<2)continue;const l=Math.min(St.maxItems,Math.max(...i.map(c=>c.number))),p=Array.from({length:l},(c,s)=>i.find(h=>h.number===s+1)?.label||String(s+1));i.forEach((c,s)=>{if(c.number>l)return;const h=i[s+1]?.at;a.push({at:Tt(c.at),duration:Tt(Ko((h??c.at+St.steps.dur)-c.at-.1,St.steps.min,St.steps.dur)),labels:p,current:c.number})})}return a}const Xv=/(?<![\p{L}\p{N}])(\d|ba|bốn|năm|sáu)\s+(chữ\s+[a-zđ]|bước|nguyên tắc|yếu tố|trụ cột|giai đoạn|cấp độ|điều|cách|bí quyết|lý do|thành phần|chìa khoá|chìa khóa|tầng|kỹ năng|thói quen|sai lầm|chữ)(?![\p{L}\p{N}])/iu,Hv=/(?<![\p{L}\p{N}])(\d|three|four|five|six)\s+(steps|principles|pillars|stages|levels|things|ways|reasons|keys|rules|habits|mistakes|skills|layers|elements|factors|a'?s|p'?s|c'?s)(?![\p{L}\p{N}])/iu,Uv=/(?<![\p{L}\p{N}])(mô hình|khung|framework|model|the)?\s*([3-6])\s?([APCSM])(?:'?s)?(?![\p{L}\p{N}])/u,Sm=/(?:^|\s)(mô hình|khung|framework|model)\s*$/iu;function vc(t){const e=t.words.map(o=>Ur(o.word));for(let o=0;o<Math.min(6,e.length);o++){if(e[o]==="thứ"&&Mc[e[o+1]])return{num:Mc[e[o+1]],j:o+2};if(e[o]==="đầu"&&e[o+1]==="tiên"&&o<3)return{num:1,j:o+2};if(e[o]==="cuối"&&e[o+1]==="cùng"&&o<3)return{num:-1,j:o+2};if(o<4&&$c[e[o]])return{num:$c[e[o]],j:o+1}}return null}const Yv=/^(tức là|nghĩa là|có nghĩa là|là|which means|that is|meaning|means|is)\s+/iu,qv=new Set([...tp,"one","chữ","cái","yếu","tố","điều","step","bước","nguyên","tắc","letter","then"]);function Zv(t){const e=String(t??"").split(/\s+/u).filter(Boolean);for(;e.length&&qv.has(Ur(e[0]));)e.shift();const o=e.join(" ").replace(/^[,:;–—-]+\s*/u,""),r=/^([^,:;–—]+?)\s*(?:[,:;–—]\s*|\s+(?=(?:tức là|nghĩa là|có nghĩa là|which means|meaning)\s))(.*)$/iu.exec(o),n=r?r[1]:o,a=r?r[2].replace(Yv,""):"",i=n.split(/\s+/u).filter(Boolean),l=i.length<=3?Ki(n):Ki(i.slice(0,3).join(" ")),p=i.length<=3?Cn(a,30):Cn(i.slice(3).join(" ")+" "+a,30);return{title:Ga(Cn(l,20)),sub:Cn(p,30),short:!!r&&i.length<=3}}function Jv(t){const e=[],o=new Set,r=(n,a)=>{const i=[];for(let l=n;l<t.length;l++){const p=t[l];if(p.start>a)break;if(o.has(l))continue;const c=vc(p);if(!c)continue;const s=c.num===-1?i.length+1:c.num;if(s!==i.length+1){if(i.length>=2)break;if(s===1)i.length=0;else continue}if(i.push({k:l,at:Tt(p.start),...Zv(Vi(p,c.j,16))}),i.length>=St.framework.max)break}return i.filter(l=>l.title)};t.forEach((n,a)=>{if(e.length>=St.framework.maxCount||o.has(a))return;const i=n.text,l=Xv.exec(i),p=Hv.exec(i),c=Uv.exec(i),s=l||p||c;if(!s)return;const h=c&&!l&&!p?+c[2]:Fs(s[1]);if(!(h>=3&&h<=St.framework.max))return;const f=r(a,n.start+St.framework.within).slice(0,h);if(f.length<Math.min(3,h))return;const m=i.slice(0,s.index),y=c&&!l&&!p?`${c[1]&&c[1]!=="the"?c[1]+" ":""}${c[2]}${c[3]}`:(Sm.exec(m)?.[1]?Sm.exec(m)[1]+" ":"")+s[0].trim();f.forEach($=>o.add($.k)),o.add(a),e.push({at:Tt(n.start),title:ge(Ga(y),32),items:f.map(({k:$,short:x,...E})=>E)})});for(let n=0;n<t.length&&e.length<St.framework.maxCount;n++){if(o.has(n)||!vc(t[n]))continue;const a=r(n,t[n].start+St.framework.within);a.length<3||!a.every(i=>i.short)||(a.forEach(i=>o.add(i.k)),e.push({at:a[0].at,title:"",items:a.map(({k:i,short:l,...p})=>p)}))}return e.sort((n,a)=>n.at-a.at)}const Qv=/(?<![\p{L}])(video|tập|bài|số|clip)\s+(trước|lần trước|vừa rồi)(?![\p{L}])/iu,t6=/(?<![\p{L}])(previous|last|earlier)\s+(video|episode|lesson|part)(?![\p{L}])/iu,e6=new Set([...tp,"mình","chúng","ta","tôi","đã","có","nói","về","chia","sẻ","đề","cập","đến","tới","bàn","we","i","talked","covered","discussed","shared","looked","at","in","on","of","that","what","where","how"]);function o6(t){const e=[];for(const o of t){if(e.length>=St.label.maxAuto)break;const r=Qv.exec(o.text)||t6.exec(o.text);if(!r||e.length&&o.start-e.at(-1).at<St.label.gap)continue;const n=o.text.slice(r.index+r[0].length).split(/\s+/u).filter(Boolean);for(;n.length&&e6.has(Ur(n[0]));)n.shift();e.push({at:Tt(o.start),sub:Cn(n.join(" "),30)})}return e}const r6=/(?<![\p{L}\p{N}])(hai|2)\s+(cách|con đường|lựa chọn|hướng đi|kiểu|loại|mô hình|phương án)(?![\p{L}\p{N}])/iu,n6=/(?<![\p{L}\p{N}])(two|2)\s+(ways|paths|options|routes|kinds|types|models|approaches)(?![\p{L}\p{N}])/iu,a6=new Set([...tp,"cách","con","đường","lựa","chọn","hướng","đi","kiểu","loại","phương","án","way","path","option","route","approach","one","to","be","của","một","a"]),i6=/(?:từ\s+)?(\d+(?:[.,]\d+)?)\s*(?:(?:đến|tới|-|–)\s*(\d+(?:[.,]\d+)?)\s*)?(triệu|tr|nghìn|ngàn|tỷ|tỉ|usd|đô|đồng)(?![\p{L}])/iu,s6=/\$\s?(\d[\d,.]*)\s*(k|m|thousand|million)?(?:\s*(?:to|-|–)\s*\$?\s?(\d[\d,.]*)\s*(k|m|thousand|million)?)?|(\d[\d,.]*)\s*(k|thousand)?\s*(?:to|-|–)\s*(\d[\d,.]*)\s*(k|thousand)?\s*dollars/iu,Im=t=>t?/^(k|thousand)$/i.test(t)?"K":"M":"";function _p(t){const e=String(t??""),o=i6.exec(e);if(o)return`${o[1]}${o[2]?"–"+o[2]:""} ${o[3].toLowerCase()}`;const r=s6.exec(e);if(!r)return"";const n=r[1]??r[5],a=r[3]??r[7],i=r[4]??r[8]??r[2]??r[6],l=r[2]??r[6]??(r[5]?i:void 0);return`$${n}${Im(l)}${a?` – $${a}${Im(i)}`:""}`}function l6(t){const e=String(t??"").split(/\s+/u).filter(Boolean);for(;e.length&&a6.has(Ur(e[0]));)e.shift();const o=e.join(" "),r=/^([^,:;–—]+?)\s*[,:;–—]\s*(.*)$/u.exec(o),n=r?r[1]:o,a=n.split(/\s+/u);return{head:Ga(Ki(a.slice(0,5).join(" "))),rest:r?r[2]:a.slice(5).join(" ")}}function c6(t){const e=[];return t.forEach((o,r)=>{if(e.length>=St.compare.maxAuto||e.length&&o.start<e.at(-1).end)return;const n=r6.exec(o.text)||n6.exec(o.text);if(!n)return;const a=[];let i=r;for(;i<t.length&&t[i].start<=o.start+St.compare.within&&a.length<3;i++){const f=t[i],m=i===r?null:vc(f);if(!m)continue;if((m.num===-1?a.length+1:m.num)!==a.length+1)break;a.push({k:i,m})}if(a.length!==2)return;let l=1;const p=(f,m)=>{const y=t[f.k],{head:$,rest:x}=l6(Vi(y,f.m.j,24)),E=m===0?t[a[1].k].start:y.start+St.compare.side,v=t.slice(f.k+1).filter(I=>I.start<E&&!vc(I)).slice(0,m===0?St.compare.lines:Math.max(1,l)).map(I=>I.text),S=[x,...v].filter(Boolean);m===0&&(l=v.length);const k=S.map(_p).find(Boolean)||_p(y.text),b=[...new Set(S.filter(I=>!_p(I)).map(I=>Ga(Cn(I,40))).filter(I=>I.split(" ").length>=2))].slice(0,St.compare.lines),A=t[f.k+v.length];return{head:ge($,28),amount:k,lines:b,end:A?.end??y.end}},c=p(a[0],0),s=p(a[1],1);if(!c.head||!s.head)return;const h=ge(Ga(Cn(o.text.slice(n.index),48)).toUpperCase(),48);e.push({at:Tt(o.start),end:Tt(s.end),title:h,left:{head:c.head,amount:c.amount,lines:c.lines},right:{head:s.head,amount:s.amount,lines:s.lines}})}),e}function p6(t,e=!1){const o=[];for(const r of t)for(const n of Dv)o.some(a=>a.kind===n)||n.re.test(r.text)&&o.push({kind:n,at:Tt(r.start+.2),label:e?n.en:n.vi,icon:n.icon});return o.sort((r,n)=>r.at-n.at).map(({kind:r,...n})=>n).slice(0,St.tool.maxCount)}const u6=t=>{try{const e=typeof t=="string"?JSON.parse(t||"{}"):t;return e&&typeof e=="object"&&!Array.isArray(e)?e:{}}catch{throw Error("prompt must be the course options as JSON")}},_o=(t,e,o)=>t.some(([r,n])=>e<n-.05&&o>r+.05),ml=(t,e)=>{const o=Math.max(1,Math.ceil((e-t)/Qe.maxDuration-1e-9)),r=[];for(let n=0;n<o;n++){const a=t+(e-t)*n/o,i=t+(e-t)*(n+1)/o;r.push({start:Tt(a),duration:Tt(i-a),fade:o===1?"both":n===0?"in":n===o-1?"out":"none"})}return r},Gl=new Set(["addClip","addBroll","generateBroll","addText","addShape","addMotion","addElement","addCard","addSolid","addAdjustmentLayer","generateElement","lockup","placeBehindPerson"]),Am=/bảng trắng|whiteboard|white board|notepad|note ?pad|sổ tay|overhead|top ?down|từ trên xuống|vẽ tay|hand ?drawn|bảng viết|giấy nháp|sketch|phác thảo|vẽ sơ đồ/iu;function Cm(t,e){const o=Math.min(t,e)/Math.max(t,e),r=1-o;return t>=e?{left:Tt(r/2),right:Tt(r/2),top:0,bottom:0}:{left:0,right:0,top:Tt(r*.3),bottom:Tt(r*.7)}}function d6(t,e,o){const r=t/e;if(r>o){const a=Tt((1-o/r)/2);return{left:a,right:a,top:0,bottom:0}}const n=1-r/o;return{left:0,right:0,top:Tt(n*.4),bottom:Tt(n*.6)}}function Ya(t,e,o,r,n,a){const i=y=>Math.max(2,Math.floor(y/2)*2),l=i(t),p=i(e),c=Math.abs(r*Math.PI/180),s=Math.abs(Math.cos(c)),h=Math.abs(Math.sin(c)),f=c?Math.ceil((l*s+p*h)/2)*2:l,m=c?Math.ceil((l*h+p*s)/2)*2:p;return Tt(Ko(o/Math.min(n/f,a/m),.02,4))}function h6({clips:t=[],materials:e=[],op:o={},W:r=1280,H:n=720,en:a=null,maxOps:i=1/0,brand:l=null}={}){const p={...u6(o.prompt),...Object.fromEntries(Object.entries(o).filter(([W,ft])=>!["op","prompt"].includes(W)&&ft!==null&&ft!==void 0))},c=t.find(W=>W.id===p.clipId);if(!c||c.kind!=="video"||c.motion||c.title||c.shape)throw Error("clipId must be the main lesson video on the timeline");if(p.navigator!=null&&!vm.includes(p.navigator))throw Error(`navigator must be ${vm.join(" / ")}`);if(p.theme!=null&&!$m.includes(p.theme))throw Error(`theme must be ${$m.join(" / ")}`);for(const W of["chapters","steps","tools","screenClips","overhead","photos","labels","split","docs"])if(p[W]!=null&&!Array.isArray(p[W]))throw Error(`${W} must be a list`);for(const W of["framework","journey","cover","map"])if(p[W]!=null&&(typeof p[W]!="object"||Array.isArray(p[W])))throw Error(`${W} must be an object`);if(p.compare!=null&&p.compare!==!1&&(typeof p.compare!="object"||Array.isArray(p.compare)))throw Error("compare must be an object (or false)");const s=hg[p.theme??_b],h=t.filter(W=>W.id===c.id||c.nodeId&&W.nodeId===c.nodeId&&W.track===c.track&&W.kind===c.kind&&!W.mask).sort((W,ft)=>W.start-ft.start),f=h[0].start,m=h.at(-1).start+h.at(-1).duration,y=Math.max(.001,m-f),$=W=>W>=f-1e-6&&W<m-.5,x=Dd(t,c.id,e),E=_v(x),v=x.map(W=>W.word).join(" "),S=v?!Fv.test(v)&&a!==!1:!!a,k=n>r*1.1,b=W=>e.find(ft=>ft.id===W),A=Math.min(r,n),I=(W,ft)=>{if(!Number.isFinite(+W))throw Error(`${ft} needs at (timeline seconds)`);return Tt(Ko(+W,f,m-.5))},P=W=>`${b(W.nodeId)?.label||W.label||""} ${(b(W.nodeId)?.labels||[]).join(" ")}`,C=(W,ft)=>{const yt=b(W);if(!yt||yt.kind!=="image"||!yt.url)throw Error(`${ft} must be an image from Media`);return yt},z=(p.chapters??[]).slice(0,30).map((W,ft)=>({at:I(W?.at,`chapters[${ft}]`),title:ge(W?.title,80),sub:ge(W?.sub,80),takeaways:(Array.isArray(W?.takeaways)?W.takeaways:[]).map(yt=>ge(yt,48)).filter(Boolean).slice(0,3),number:ft+1})).sort((W,ft)=>W.at-ft.at),N=z.length?[]:Vv(E).filter(W=>$(W.at)),F=z.length?z:N.map((W,ft)=>({...W,number:W.number??ft+1,sub:"",takeaways:[]})),K=(W,ft,yt)=>{const Mt=W&&typeof W=="object",Pt=Mt?`${W.title??""}${W.sub?" — "+W.sub:""}`:String(W??""),Lt=Pt.split(/\s+[—–-]\s+|\s*:\s+/u),Ot=ge(Mt?W.title:Lt[0],20),Wt=ge(Mt?W.sub:Lt.slice(1).join(" "),30);if(!Ot)throw Error(`framework.items[${ft}] needs a title`);return{at:Mt&&Number.isFinite(+W.at)?I(W.at,`framework.items[${ft}]`):Tt(yt+St.framework.lead*2+ft*St.framework.step),title:Ot,sub:Wt,icon:Mt&&sp(W.icon)?W.icon:null}},_=p.framework?(()=>{const W=p.framework,ft=I(W.at,"framework"),yt=Array.isArray(W.items)?W.items.slice(0,St.framework.max):[];if(yt.length<St.framework.min)throw Error(`framework needs ${St.framework.min}–${St.framework.max} items`);return[{at:ft,title:ge(W.title,32),items:yt.map((Mt,Pt)=>K(Mt,Pt,ft)).sort((Mt,Pt)=>Mt.at-Pt.at)}]})():Jv(E).filter(W=>$(W.at)).map(W=>({...W,items:W.items.map(ft=>({...ft,icon:null}))})),q=W=>[W.at-1,W.items.at(-1).at+St.framework.hold],U=(W,ft)=>{if(!W||typeof W!="object"||!ge(W.head,28))throw Error(`compare.${ft} needs head`);return{head:ge(W.head,28),amount:ge(W.amount,24),lines:(Array.isArray(W.lines)?W.lines:[]).map(yt=>ge(yt,40).replace(/[|]+/gu," ")).filter(Boolean).slice(0,4)}},rt=p.compare===!1?[]:p.compare?[(()=>{const W=p.compare,ft=I(W.at,"compare");return{at:ft,end:ft+(Number.isFinite(+W.duration)?+W.duration:St.compare.dur),title:ge(W.title,48),left:U(W.left,"left"),right:U(W.right,"right"),given:!0}})()]:c6(E).filter(W=>$(W.at)),ot=W=>[W.at-.5,W.end+.5],G=(p.steps?p.steps.slice(0,40).map((W,ft)=>{const yt=(Array.isArray(W?.labels)?W.labels:[]).map(Mt=>ge(Mt,24)).filter(Boolean).slice(0,St.maxItems);if(!yt.length)throw Error(`steps[${ft}] needs labels`);return{at:I(W?.at,`steps[${ft}]`),duration:Tt(Ko(Number.isFinite(+W?.duration)?+W.duration:St.steps.dur,St.steps.min,8)),labels:yt,current:Ko(Math.round(+W?.current||1),1,yt.length)}}):Wv(x,E).filter(W=>$(W.at))).filter(W=>p.steps||!_.some(ft=>{const[yt,Mt]=q(ft);return W.at>=yt&&W.at<=Mt})&&!rt.some(ft=>{const[yt,Mt]=ot(ft);return W.at>=yt&&W.at<=Mt})),J=p.tools?p.tools.slice(0,St.tool.maxCount).map((W,ft)=>{const yt=ge(W?.label,32);if(!yt)throw Error(`tools[${ft}] needs label`);return{at:I(W?.at,`tools[${ft}]`),duration:Number.isFinite(+W?.duration)?Ko(+W.duration,St.tool.min,St.tool.max):St.tool.dur,label:yt,url:ge(W?.url,40),icon:sp(W?.icon)?W.icon:Ii(`${W?.label??""} ${W?.url??""}`)||"sparkle"}}):p6(E,S).filter(W=>$(W.at)).map(W=>({...W,duration:St.tool.dur,url:""})),Z=Kv(E).filter(W=>$(W.at)),at=p.navigator??(F.length?"chapters":Z.length>=2?"questions":G.length?"steps":"none");if(!x.length&&!F.length&&!G.length&&!J.length&&!(p.screenClips??[]).length&&!(p.overhead??[]).length&&!p.framework&&!(p.photos??[]).length&&!p.cover&&!p.journey&&!(p.labels??[]).length&&!(p.split??[]).length&&!(p.docs??[]).length&&!p.map&&!p.compare&&p.brand!==!0)throw Error("analyse the speech first (transcript) or give chapters / steps / tools");const D=p.overhead??t.filter(W=>["video","image"].includes(W.kind)&&!h.includes(W)&&!W.motion&&!W.title&&!W.shape&&Am.test(P(W))&&W.start<m-1&&W.start+W.duration>f+1).map(W=>({clipId:W.id})),H=[],ut=new Map;D.slice(0,St.overhead.maxCount).forEach((W,ft)=>{const yt=t.find(re=>re.id===W?.clipId),Mt=yt&&b(yt.nodeId);if(!yt||!["video","image"].includes(yt.kind)||yt.motion||yt.title||yt.shape||!Mt?.url)throw Error(`overhead[${ft}] clipId must be a whiteboard / B-roll video or image clip from Media`);if(h.includes(yt))throw Error("the lesson video cannot be its own overhead shot");const Pt=I(W.at??yt.start,`overhead[${ft}]`),Lt=(yt.inPoint||0)+(ut.get(yt.id)||0),Ot=yt.kind==="video"&&Number.isFinite(Mt.duration)?Mt.duration-Lt:1/0;let Wt=Math.min(Number.isFinite(+W.duration)?+W.duration:yt.duration,m-Pt,St.overhead.max);const Ht=Ot>=Math.min(Wt,St.overhead.min)?Lt:yt.inPoint||0;yt.kind==="video"&&Number.isFinite(Mt.duration)&&(Wt=Math.min(Wt,Mt.duration-Ht));const qt=H.at(-1);qt&&Pt<qt.a+qt.d&&(Wt=0),!(Wt<St.overhead.min)&&(ut.set(yt.id,(ut.get(yt.id)||0)+Wt),H.push({c:yt,m:Mt,a:Pt,d:Tt(Wt),inPoint:Tt(yt.kind==="video"?Ht:0)}))});const gt=H.map(W=>[W.a,W.a+W.d]),xt=ed({W:r,H:n}),u=new Set(H.map(W=>W.c.id)),V=(p.screenClips??t.filter(W=>W.kind==="video"&&!h.includes(W)&&!W.motion&&!u.has(W.id)&&!Am.test(P(W))&&Bv.test(P(W))).map(W=>W.id)).map(W=>{const ft=t.find(yt=>yt.id===W);if(!ft||!["video","image"].includes(ft.kind)||ft.motion||ft.title)throw Error(`screen clip ${String(W).slice(0,40)} not found`);if(h.includes(ft))throw Error("the lesson video cannot be its own screen recording");return ft}),d=V.map(W=>[W.start,W.start+W.duration]),w=W=>{if(_o(gt,W,W+.01))return{x:xt.params.posX,y:xt.params.posY-xt.params.ph*.2,window:!0};const ft=h.find(yt=>W>=yt.start&&W<yt.start+yt.duration)??h[0];return xc(ft,b(ft.nodeId),W,{W:r,H:n})??(k?ve.face.portrait:ve.face.landscape)},T=(W,ft,yt)=>{const Mt=w(W);return ft<Mt.y+ve.chin&&yt>Mt.y-ve.head},j=p.captions===!0?St.lift:0,O=(W,ft,yt)=>T(W,ft-j,yt-j)&&!T(W,k?.08:.06,k?.3:.24)?"top":"lower",L=[],B=[],X=[],Q=[],et=[...gt],lt=S?{q:"Q",ch:"Chapter",step:"Step",take:"Key takeaways",prev:"PREVIOUS EPISODE"}:{q:"Q",ch:"Chương",step:"Bước",take:"Ghi nhớ",prev:"TẬP TRƯỚC"};let Y=0;const dt=W=>(L.push(W),Gl.has(W.op)&&Y++,W),bt=()=>`new:${Y}`,tt=W=>{const ft=w(W),yt=ft.window?xt.params.pw/2:ve.halfWidth.landscape,Mt=ft.x-yt-.07-.03,Pt=.93-(ft.x+yt)-.03;return Pt>=Mt?{side:"right",x0:ft.x+yt+.03,w:Pt,f:ft}:{side:"left",x0:.07,w:Mt,f:ft}},nt=(W,ft)=>{X.push([W,W+ft]),dt({op:"addMotion",motionPreset:"course-chapter-card",start:W,duration:ft,placement:"center",params:{text:"",sub:"",number:0,label:"",...p.theme?{bg:s.bg}:{}}})};for(const W of u)dt({op:"delete",clipId:W});for(const W of H){dt({op:"addBroll",materialId:W.m.id,start:Tt(W.a),duration:W.d,inPoint:W.inPoint});const ft=bt();dt({op:"setAnimation",clipId:ft,property:"enter",preset:"fade",duration:St.overhead.fade}),dt({op:"setAnimation",clipId:ft,property:"exit",preset:"fade",duration:St.overhead.fade}),dt({op:"speakerWindow",clipId:c.id,at:Tt(W.a),duration:W.d,numberValue:xt.params.pw,posX:xt.params.posX,posY:xt.params.posY,color:s.accent});for(const yt of ml(W.a,W.a+W.d))dt({op:"addMotion",motionPreset:"course-pip-frame",start:yt.start,duration:yt.duration,placement:"center",params:{...xt.params,fade:yt.fade,text:""}})}(p.chapterCards===!0?F.map(W=>({at:W.at,end:Tt(Math.min(m,W.at+St.card))})):[]).forEach((W,ft)=>{const yt=F[ft];X.push([W.at,W.end]),dt({op:"addMotion",motionPreset:"course-chapter-card",start:W.at,duration:Tt(W.end-W.at),placement:"center",text:yt.title||`${lt.ch} ${yt.number}`,...yt.sub?{subText:yt.sub}:{},numberValue:yt.number,params:{label:lt.ch,...p.theme?{bg:s.bg}:{}}})});const It=[],Nt=W=>Math.floor(W*30+1e-6)/30,$t=W=>Math.floor(W*1e3)/1e3,zt=W=>+(+W).toFixed(4),Dt=(W,ft)=>!_o([...X,...gt,...d,...It],W,ft),ae=(W,ft,yt)=>Nt(Math.min(m-yt,Ko(Number.isFinite(+W)?+W:ft.dur,ft.min,ft.max))),we=(W,ft)=>{X.push([W,W+ft]),et.push([W,W+ft]),It.push([W,W+ft])},Oe=(W,ft)=>{dt({op:"setAnimation",clipId:W,property:"enter",preset:"fade",duration:ft}),dt({op:"setAnimation",clipId:W,property:"exit",preset:"fade",duration:ft})},Ce=k?St.split.portrait:St.split.landscape,Yt=new Set;(p.split??[]).slice(0,St.split.maxCount).forEach((W,ft)=>{const yt=W?.clipId!=null?t.find(Qy=>Qy.id===W.clipId):null;if(W?.clipId!=null&&(!yt||!["video","image"].includes(yt.kind)||yt.motion||yt.title||yt.shape))throw Error(`split[${ft}] clipId must be a B-roll video or image clip`);if(yt&&h.includes(yt))throw Error("the lesson video cannot be its own split card");const Mt=b(yt?yt.nodeId:W?.materialId);if(!Mt||!["video","image"].includes(Mt.kind)||!Mt.url)throw Error(`split[${ft}] needs clipId or materialId (a video / image from Media)`);const Pt=I(W.at??yt?.start,`split[${ft}]`),Lt=Mt.kind==="video"?Tt(yt?yt.inPoint||0:Ko(+W.inPoint||0,0,Math.max(0,(Mt.duration||0)-1))):0;let Ot=ae(W.duration??yt?.duration,St.split,Pt);if(Mt.kind==="video"&&Number.isFinite(Mt.duration)&&(Ot=Nt(Math.min(Ot,Mt.duration-Lt))),Ot<St.split.min||!Dt(Pt,Pt+Ot))return;yt&&!Yt.has(yt.id)&&(Yt.add(yt.id),dt({op:"delete",clipId:yt.id}));const[Wt,Ht,qt,re]=Ce.m,ie=Mt.width||1920,Xt=Mt.height||1080,te=d6(ie,Xt,qt*r/(re*n)),oe=ie*(1-te.left-te.right),pr=Ya(oe,Xt*(1-te.top-te.bottom),qt*r/oe,0,r,n);dt({op:"addBroll",materialId:Mt.id,start:Pt,duration:Ot,inPoint:Lt});const po=bt();dt({op:"courseStyle",clipId:po,crop:te,fit:"contain",mask:"rounded"}),dt({op:"setKeyframes",clipId:po,motionKeys:[{time:0,x:Tt(Wt-.5),y:Tt(Ht-.5),zoom:pr},{time:$t(Ot),x:Tt(Wt-.5),y:Tt(Ht-.5),zoom:pr}]}),Oe(po,St.split.fade);const[Jr,xr,ur,pa]=Ce.p,ua=zt(ur*r/(pa*n)),Bn=ed({W:r,H:n,width:ur,cx:Jr,cy:xr,aspect:ua});dt({op:"speakerWindow",clipId:c.id,at:Pt,duration:Ot,numberValue:ur,posX:Jr,posY:xr,aspect:ua,color:s.accent}),dt({op:"addMotion",motionPreset:"course-split-cards",start:Pt,duration:Ot,placement:"center",params:{mx:Wt,my:Ht,mw:qt,mh:re,px:Bn.params.posX,py:Bn.params.posY,pw:Bn.params.pw,ph:Bn.params.ph,bg:s.bg}}),we(Pt,Ot)});for(const W of rt){const ft=W.at,yt=ae(W.given?W.end-W.at:Math.max(St.compare.min,W.end-W.at+1.2),St.compare,ft);yt<St.compare.min||!Dt(ft,ft+yt)||(dt({op:"addMotion",motionPreset:"course-compare-board",start:ft,duration:yt,placement:"center",params:{title:W.title,leftHead:W.left.head,leftAmount:W.left.amount,leftLines:W.left.lines.join("|"),rightHead:W.right.head,rightAmount:W.right.amount,rightLines:W.right.lines.join("|"),vs:"VS",bg:s.bg}}),we(ft,yt))}if((p.docs??[]).slice(0,St.doc.maxCount).forEach((W,ft)=>{const yt=C(W?.materialId,`docs[${ft}].materialId`),Mt=I(W.at,`docs[${ft}]`),Pt=ae(W.duration,St.doc,Mt),Lt=W.highlight;if(Lt!=null&&!(["x","y","w","h"].every(oe=>Number.isFinite(+Lt[oe]))&&Lt.x>=0&&Lt.y>=0&&Lt.w>0&&Lt.h>0&&Lt.x+Lt.w<=1.001&&Lt.y+Lt.h<=1.001))throw Error(`docs[${ft}].highlight must be {x, y, w, h} (0..1 of the document)`);if(Pt<St.doc.min||!Dt(Mt,Mt+Pt))return;const Ot=yt.width||1200,Wt=yt.height||1600,Ht=Math.min(St.doc.w*r/Ot,St.doc.h*n/Wt),qt=zt(Ot*Ht/r),re=zt(Wt*Ht/n),ie=St.doc.cy,Xt=Ya(Ot,Wt,Ht,0,r,n);dt({op:"addBroll",materialId:yt.id,start:Mt,duration:Pt});const te=bt();dt({op:"courseStyle",clipId:te,fit:"contain"}),dt({op:"setKeyframes",clipId:te,motionKeys:[{time:0,x:0,y:Tt(ie-.5),zoom:Xt},{time:$t(Pt),x:0,y:Tt(ie-.5),zoom:zt(Xt*(1+St.doc.zoom*$t(Pt)/Pt))}]}),Oe(te,St.doc.fade),dt({op:"addMotion",motionPreset:"course-doc-highlight",start:Mt,duration:Pt,placement:"center",params:{cx:.5,cy:ie,cw:qt,ch:re,...Lt?{posX:zt(.5+(+Lt.x+Lt.w/2-.5)*qt),posY:zt(ie+(+Lt.y+Lt.h/2-.5)*re),bw:zt(Lt.w*qt),bh:zt(Lt.h*re)}:{bw:0,bh:0},text:ge(W.note,30)}}),we(Mt,Pt)}),p.map){const W=p.map,ft=I(W.at,"map"),yt=W.materialId!=null?C(W.materialId,"map.materialId"):null,Mt=Array.isArray(W.pins)?W.pins.slice(0,St.map.pins):[];if(!Mt.length)throw Error(`map needs 1–${St.map.pins} pins [{x, y, label}]`);const Pt=Mt.map((Ot,Wt)=>{let Ht=+Ot?.x,qt=+Ot?.y;if(!(Ot?.x!=null&&Ot?.y!=null)&&!yt&&Number.isFinite(+Ot?.lat)&&Number.isFinite(+Ot?.lon)&&(Ht=(+Ot.lon+180)/360,qt=(85-Ot.lat)/145),!(Ht>=0&&Ht<=1&&qt>=0&&qt<=1))throw Error(`map.pins[${Wt}] needs x, y (0..1 of the map)${yt?"":" or lat / lon"}`);if(yt){const re=yt.width||1920,ie=yt.height||1080,Xt=Math.max(r/re,n/ie);Ht=.5+(Ht-.5)*re*Xt/r,qt=.5+(qt-.5)*ie*Xt/n}return{x:Tt(Ht),y:Tt(qt),label:ge(Ot.label,24).replace(/[|@]+/gu," ")}}).filter(Ot=>Ot.x>=0&&Ot.x<=1&&Ot.y>=0&&Ot.y<=1),Lt=ae(W.duration,St.map,ft);Pt.length&&Lt>=St.map.min&&Dt(ft,ft+Lt)&&(yt&&(dt({op:"addBroll",materialId:yt.id,start:ft,duration:Lt}),Oe(bt(),St.map.fade)),dt({op:"addMotion",motionPreset:"course-map-pins",start:ft,duration:Lt,placement:"center",params:{items:Pt.map(Ot=>`${Ot.label}@${Ot.x},${Ot.y}`).join("|"),map:yt?0:1,text:ge(W.title,30),route:Pt.length>1?1:0,bg:s.bg}}),we(ft,Lt))}const Ft=p.journey,Bt=Ft?(()=>{const W=I(Ft.at,"journey"),ft=Tt(Math.min(Qe.maxDuration,m-W,Number.isFinite(+Ft.duration)?Ko(+Ft.duration,St.journey.min,Qe.maxDuration):St.journey.dur));return ft>=St.journey.min?{a:W,d:ft,avatar:Ft.avatarMaterialId!=null?C(Ft.avatarMaterialId,"journey.avatarMaterialId"):null,from:Ko(Number.isFinite(+Ft.from)?+Ft.from:0,0,1),to:Ko(Number.isFinite(+Ft.to)?+Ft.to:1,0,1),labels:(Array.isArray(Ft.labels)?Ft.labels:[]).map(yt=>ge(yt,22)).filter(Boolean).slice(0,6),text:ge(Ft.text,32)}:null})():null,_t=Bt?[Bt.a,Bt.a+Bt.d]:null,pe=at==="chapters"?F.map(W=>({at:W.at,text:W.title,badge:lt.ch,n:W.number})):at==="questions"?Z.map((W,ft)=>({at:W.at,text:W.text,badge:lt.q,n:W.number??ft+1})):at==="steps"?G.map(W=>({at:W.at,text:W.labels[W.current-1],badge:lt.step,n:W.current,total:W.labels.length})):[],ee=Math.max(1,...pe.map(W=>W.n)),fe=pe.slice(1).map(W=>Tt((W.at-f)/y)).filter(W=>W>0&&W<1).slice(0,40).join("|");if(pe.forEach((W,ft)=>{const yt=X.find(([Wt,Ht])=>W.at>=Wt-.05&&W.at<Ht),Mt=Tt(yt?yt[1]+.1:W.at),Pt=pe[ft+1]?.at??m,Lt=Tt(Math.min(St.nav.dur,Pt-.15-Mt,m-Mt));if(Lt<St.nav.min)return;B.push([Mt,Mt+Lt]);const Ot=_t&&_o([_t],Mt,Mt+Lt)?"top":O(Mt+Lt/2,k?.62:.68,k?.8:.9);dt({op:"addMotion",motionPreset:"course-question-nav",start:Mt,duration:Lt,text:ge(W.text,90),numberValue:W.n,placement:Ot,params:{sub:W.badge,total:W.total??ee,lift:j}}),p.progress!==!1&&at!=="steps"&&dt({op:"addMotion",motionPreset:"course-progress-bar",start:Mt,duration:Lt,params:{from:Tt(Ko((Mt-f)/y,0,1)),to:Tt(Ko((Mt+Lt-f)/y,0,1)),ticks:fe,text:"",position:Ot==="top"||w(Mt+Lt/2).y-ve.head<.16?"lower":"top"}})}),at!=="steps")for(const W of G)_o(B,W.at,W.at+W.duration)||_o(X,W.at,W.at+W.duration)||_t&&_o([_t],W.at,W.at+W.duration)||(B.push([W.at,W.at+W.duration]),dt({op:"addMotion",motionPreset:"course-step-tiles",start:W.at,duration:W.duration,items:W.labels,numberValue:W.current,placement:O(W.at+W.duration/2,k?.7:.78,k?.8:.92),params:{lift:j}}));if(Bt){const{a:W,d:ft}=Bt,yt=T(W+ft/2,.74,.86),Mt=Tt(yt?.2:.8-j*.6),Pt=A*(k?St.journey.r.portrait:St.journey.r.landscape),Lt=k?.075:.07,Ot=1-Lt,Wt=Ht=>Tt(Lt+(Ot-Lt)*Ht-.5);if(Bt.avatar){const Ht=Bt.avatar,qt=Ht.width||1e3,re=Ht.height||1e3,ie=St.journey.delay,Xt=Tt(2*Pt/A),te=Tt(ft-ie),oe=Tt(St.journey.a-ie),pr=Tt(Math.max(oe+.1,ft-St.journey.b-ie));dt({op:"addElement",materialId:Ht.id,start:Tt(W+ie),duration:te,posX:Wt(Bt.from),posY:Tt(Mt-.5),scale:.25,anim:{in:"pop",out:"fade",loop:"none"}});const po=bt();dt({op:"courseStyle",clipId:po,crop:Cm(qt,re),mask:"circle"}),dt({op:"setKeyframes",clipId:po,motionKeys:[{time:0,x:Wt(Bt.from),y:Tt(Mt-.5),zoom:Xt},{time:oe,x:Wt(Bt.from),y:Tt(Mt-.5),zoom:Xt},{time:pr,x:Wt(Bt.to),y:Tt(Mt-.5),zoom:Xt},{time:te,x:Wt(Bt.to),y:Tt(Mt-.5),zoom:Xt}]})}dt({op:"addMotion",motionPreset:"course-journey-line",start:W,duration:ft,placement:"lower",...Bt.text?{text:Bt.text}:{},...Bt.labels.length?{items:Bt.labels}:{},params:{from:Bt.from,to:Bt.to,posY:Mt,ring:Bt.avatar?1:0,glyph:"user",...Bt.labels.length?{}:{items:""}}}),B.push([W,W+ft]),et.push([W,W+ft])}for(const W of _){const ft=W.items.filter(Xt=>Xt.at<m-.5),yt=ft.length;if(yt<St.framework.min)continue;const Mt=ft.map(Xt=>Xt.icon||Ii(`${Xt.title} ${Xt.sub}`)),Pt=Mt.every(Boolean)?Mt:ft.map(Xt=>Xt.icon),Lt=Xt=>ft.map((te,oe)=>`${Pt[oe]?Pt[oe]+":":""}${te.title}${te.sub?" — "+te.sub.slice(0,Xt):""}`.replace(/[|]+/gu," ")).join("|");let Ot=30;for(;Lt(Ot).length>290&&Ot>0;)Ot-=4;const Wt=[];ft.forEach((Xt,te)=>{const oe=Wt.at(-1);oe&&Xt.at-ft[te-1].at<=St.framework.gap?oe.last=te:Wt.push({first:te,last:te})});const Ht=[...X,...Q],qt=tt((W.at+ft.at(-1).at)/2),re=Math.min(St.framework.w,qt.w/(1+.08*(yt-1))),ie=!k&&re<St.framework.minW;for(const Xt of Wt){const te=Tt(Xt.first===0?W.at:ft[Xt.first].at-St.framework.lead),oe=Tt(Math.min(m,ft[Xt.last].at+St.framework.hold,(ft[Xt.last+1]?.at??1/0)-St.framework.lead-.1));if(oe-te<St.framework.min||_o(Ht,te,oe))continue;ie&&nt(te,Tt(oe-te));const pr=_o(B,te,oe)?.44:.5;for(const po of ml(te,oe)){const Jr=ft.map((xr,ur)=>ur<Xt.first?-1:ur>Xt.last?999:Tt(xr.at-po.start)).join("|");dt({op:"addMotion",motionPreset:"course-framework-stack",start:po.start,duration:po.duration,placement:"center",...W.title?{text:W.title}:{},params:{items:Lt(Ot),at:Jr,fade:po.fade,...W.title?{}:{text:""},...ie?{position:"left",posX:.5,posY:.5,width:.3}:{position:k?"left":qt.side,...k?{}:{width:Tt(re),posY:pr}}}})}Q.push([te,oe]),et.push([te,oe])}}const Qo=(p.photos??[]).slice(0,St.photo.maxCount).map((W,ft)=>({at:I(W?.at,`photos[${ft}]`),m:C(W?.materialId,`photos[${ft}].materialId`),scribble:W?.scribble===!0})).sort((W,ft)=>W.at-ft.at),kr=[];for(const W of Qo){const ft=kr.at(-1);ft&&!W.scribble&&!ft[0].scribble&&ft.length<3&&W.at-ft[0].at<St.photo.group?ft.push(W):kr.push([W])}if(kr.forEach((W,ft)=>{const yt=W[0].at,Mt=Tt(Math.min(m,W.at(-1).at+St.photo.dur,(kr[ft+1]?.[0].at??1/0)-.15));if(Mt-yt<St.photo.min||_o([...X,...Q],yt,Mt))return;let Pt=tt((yt+Mt)/2),Lt=!1;const Ot=W.length,Wt=St.photo.size[Ot-1]*n,Ht=Math.min(Wt,Pt.w*r/Ot*.86);(Ht<St.photo.minSize*n||W[0].scribble&&Pt.w<.22)&&(Lt=!0,Pt={side:"right",x0:.15,w:.7}),Lt&&nt(yt,Tt(Mt-yt)),W.forEach((qt,re)=>{const ie=qt.m,Xt=ie.width||1e3,te=ie.height||1e3,oe=Pt.x0+Pt.w*(re+.5)/Ot,pr=(k?.36:.42)+(Ot>1?re%2?.05:-.03:0),po=St.photo.rot[re%3]*(Pt.side==="left"?-1:1),Jr=Tt(Mt-qt.at);if(!(Jr<1))if(qt.scribble){const xr=Math.min(n*(k?.36:.5),Pt.w*r*.9*te/Xt),ur=Ya(Xt,te,xr/te,po,r,n),pa=xr*Xt/te,ua=Tt(Math.max(pa/2/.74,xr/2/.68)*1.06/A);dt({op:"addElement",materialId:ie.id,start:qt.at,duration:Jr,posX:Tt(oe-.5),posY:Tt(pr-.5),scale:Math.max(.25,ur),anim:{in:"pop",out:"fade",loop:"none"}});const Bn=bt();ur<.25&&dt({op:"setKeyframes",clipId:Bn,motionKeys:[{time:0,x:Tt(oe-.5),y:Tt(pr-.5),zoom:ur}]}),dt({op:"collageStyle",clipId:Bn,sticker:"white",cutout:"person"}),dt({op:"courseStyle",clipId:Bn,rotation:po}),dt({op:"addMotion",motionPreset:"course-photo-pop",start:qt.at,duration:Jr,placement:"center",params:{tile:0,scribble:1,posX:Tt(oe),posY:Tt(pr),size:ua,rot:po,text:""}})}else{const xr=Math.min(Xt,te),ur=Lt?Wt:Ht,pa=Ya(xr,xr,ur/xr,po,r,n);dt({op:"addElement",materialId:ie.id,start:qt.at,duration:Jr,posX:Tt(oe-.5),posY:Tt(pr-.5),scale:Math.max(.25,pa),anim:{in:"pop",out:"fade",loop:"none"}});const ua=bt();pa<.25&&dt({op:"setKeyframes",clipId:ua,motionKeys:[{time:0,x:Tt(oe-.5),y:Tt(pr-.5),zoom:pa}]}),dt({op:"courseStyle",clipId:ua,crop:Cm(Xt,te),rotation:po,shadow:!0}),dt({op:"addMotion",motionPreset:"course-photo-pop",start:qt.at,duration:Jr,placement:"center",params:{tile:1,scribble:0,posX:Tt(oe),posY:Tt(pr),size:Tt(ur/A),rot:po,text:""}})}}),Q.push([yt,Mt]),et.push([yt,Mt])}),p.cover){const W=p.cover,ft=C(W.materialId,"cover.materialId"),yt=I(W.at,"cover"),Mt=Tt(Math.min(m-yt,Number.isFinite(+W.duration)?Ko(+W.duration,St.cover.min,Qe.maxDuration):St.cover.dur));if(Mt>=St.cover.min&&!_o([...X,...Q],yt,yt+Mt)){let Pt=tt(yt+Mt/2);const Lt=ft.width||800,Ot=ft.height||1200;let Wt=Math.min(n*(k?.4:St.cover.size),Pt.w*r*.85*Ot/Lt);Wt<n*.28&&(Pt={side:"right",x0:.2,w:.6},nt(yt,Mt),Wt=n*St.cover.size);const Ht=Pt.x0+Pt.w/2,qt=k?.36:.46,re=Pt.side==="right"?-St.cover.rot:St.cover.rot,ie=Ya(Lt,Ot,Wt/Ot,re,r,n);dt({op:"addElement",materialId:ft.id,start:yt,duration:Mt,posX:Tt(Ht-.5),posY:Tt(qt-.5),scale:Math.max(.25,ie),anim:{in:"pop",out:"fade",loop:"none"}});const Xt=bt();ie<.25&&dt({op:"setKeyframes",clipId:Xt,motionKeys:[{time:0,x:Tt(Ht-.5),y:Tt(qt-.5),zoom:ie}]}),dt({op:"courseStyle",clipId:Xt,rotation:re,shadow:!0}),dt({op:"addMotion",motionPreset:"course-cover-insert",start:yt,duration:Mt,placement:"center",params:{cover:1,text:"",sub:ge(W.title,28),posX:Tt(Ht),posY:qt,size:Tt(Wt/n),aspect:Tt(Lt/Ot),rot:re}}),Q.push([yt,yt+Mt]),et.push([yt,yt+Mt])}}const Fr=W=>w(W).x>=.5?"left":"right";for(const W of J){const ft=Tt(Math.min(W.duration,m-W.at));if(ft<St.tool.min||_o([...X,...Q],W.at,W.at+ft))continue;const yt=w(W.at+ft/2),Mt=Fr(W.at+ft/2),Pt=k?yt.y-ve.head>.19?`top-${Mt}`:`bottom-${Mt}`:Mt;dt({op:"addMotion",motionPreset:"course-tool-badge",start:W.at,duration:ft,text:W.label,...W.url?{subText:W.url}:{},icon:W.icon,params:{position:Pt,...k?{}:{posY:Tt(Ko(yt.y-.02,.2,.6))}}})}F.forEach((W,ft)=>{if(!W.takeaways.length)return;const yt=F[ft+1]?.at??m,Mt=Tt(Math.max(W.at+1,yt-St.takeaway-.2)),Pt=Tt(Math.min(St.takeaway,yt-.1-Mt));if(Pt<2||_o([...X,...Q],Mt,Mt+Pt))return;const Lt=w(Mt+Pt/2),Ot=ve.halfWidth.landscape,Wt=.93-(Lt.x+Ot)-.02,Ht=Lt.x-Ot-.07-.02,qt=Math.min(.34,Math.max(Wt,Ht)),re={op:"addMotion",motionPreset:"course-key-takeaway",start:Mt,duration:Pt,text:lt.take,items:W.takeaways};if(k){dt({...re,params:{position:"lower"}});return}if(qt>=.26){dt({...re,params:{position:Wt>=Ht?"right":"left",width:Tt(qt)}});return}nt(Mt,Pt),dt({...re,params:{position:"center",width:.5}})});const Co=p.labels?p.labels.slice(0,20).map((W,ft)=>{const yt=ge(W?.title,28);if(!yt)throw Error(`labels[${ft}] needs title`);return{at:I(W?.at,`labels[${ft}]`),title:yt,sub:ge(W?.sub,40),icon:sp(W?.icon)?W.icon:Ii(`${yt} ${W?.sub??""}`)||"flag"}}):o6(E).filter(W=>$(W.at)).map(W=>({at:W.at,title:lt.prev,sub:W.sub,icon:"play"}));for(const W of Co){const ft=Tt(Math.min(St.label.dur,m-W.at));if(ft<2||_o(X,W.at,W.at+ft))continue;const yt=w(W.at+ft/2),Mt=yt.window||yt.x>=.5?"left":"right",Pt=!_o([...B,...Q],W.at,W.at+ft)&&!T(W.at+ft/2,.76,.88),Lt=Math.max(A*.085,Math.min(A*.13,r*St.label.w*.27))/n;dt({op:"addMotion",motionPreset:"course-label-tag",start:W.at,duration:ft,text:W.title,...W.sub?{subText:W.sub}:{},icon:W.icon,params:{position:`${Pt?"lower":"top"}-${Mt}`,...Pt&&j?{posY:Tt((k?.8:.86)-j-Lt/2)}:{}}})}const qe=k?St.screen.portrait:St.screen.landscape;for(const W of V){const ft=b(W.nodeId),yt=ft?.width&&ft?.height?ft.width/ft.height:16/9,Mt=r/n,Pt=W.fit==="cover",Lt=yt>Mt!==Pt?r:n*yt,Ot=yt>Mt!==Pt?r/yt:n,Wt=Tt(Math.min(qe.w*r/Lt,qe.h*n/Ot)),Ht=Tt(Wt*Lt/r),qt=Tt(Wt*Ot/n),re=Tt(qe.cy-.5),ie=J.find(Xt=>Xt.url&&Xt.at>=W.start-3&&Xt.at<W.start+W.duration)?.url??"";dt({op:"setKeyframes",clipId:W.id,motionKeys:[{time:0,x:0,y:re,zoom:Wt},{time:Tt(W.duration),x:0,y:re,zoom:Wt}]}),dt({op:"setAnimation",clipId:W.id,property:"enter",preset:"fade",duration:St.fade}),dt({op:"setAnimation",clipId:W.id,property:"exit",preset:"fade",duration:St.fade});for(const Xt of ml(W.start,W.start+W.duration))dt({op:"addMotion",motionPreset:"course-screen-frame",start:Xt.start,duration:Xt.duration,placement:"center",params:{cw:Ht,ch:qt,cy:qe.cy,text:ie,fade:Xt.fade,...p.theme?{bg:s.screenBg}:{}}})}if(p.captions===!0&&(b(c.nodeId)?.transcript?.length||c.captions?.length)&&dt({op:"addSocialCaptions",clipId:c.id,captionStyle:"lesson",...p.theme&&p.theme!=="blue"?{color:s.accent}:{}}),p.punchIns!==!1&&E.length){const W=E.map(Mt=>({start:Mt.start,end:Mt.start+.3,word:String(Mt.words[0].word),kw:Mt.gap>=.4})),ft=Math.max(0,i-L.length),yt=N1(W,{every:St.punch.every,max:Math.min(St.punch.maxCount,ft),lead:.04,from:f+1});for(const Mt of yt){const Pt=E.find(Ot=>Math.abs(Ot.start-Mt.at)<.1)??E.find(Ot=>Ot.start>=Mt.at),Lt=Tt(Math.min(St.punch.max,Math.max(.8,(Pt?Pt.end:Mt.at+2)-Mt.at)));Mt.at+Lt>m-.1||_o([...X,...d,...et],Mt.at,Mt.at+Lt)||!h.some(Ot=>Mt.at>=Ot.start&&Mt.at+Lt<=Ot.start+Ot.duration)||dt({op:"punchIn",clipId:c.id,at:Tt(Mt.at),duration:Lt,numberValue:St.punch.amount,punchStyle:"cut",accent:!1})}}const xo=p.brand===!0?Tg(l):null;if(xo){const W=w(f+y/2),ft=ve.halfWidth[k?"portrait":"landscape"]??ve.halfWidth.landscape,[yt,Mt]=St.brand.margin,Pt=W.x+ft>1-yt-St.brand.maxW&&W.y-ve.head<Mt+St.brand.h+.02,Lt=xo.logoMaterialId?b(xo.logoMaterialId):null;if(Lt?.kind==="image"&&Lt.url){const Ot=Lt.width||600,Wt=Lt.height||600,Ht=Math.min(St.brand.h*n/Wt,St.brand.maxW*r/Ot),qt=Ya(Ot,Wt,Ht,0,r,n),re=Pt?yt+Ot*Ht/r/2:1-yt-Ot*Ht/r/2,ie=Mt+Wt*Ht/n/2;dt({op:"addElement",materialId:Lt.id,start:f,duration:Nt(m-f),posX:Tt(re-.5),posY:Tt(ie-.5),scale:Math.max(.25,qt),anim:{in:"fade",out:"fade",loop:"none"}});const Xt=bt();qt<.25&&dt({op:"setKeyframes",clipId:Xt,motionKeys:[{time:0,x:Tt(re-.5),y:Tt(ie-.5),zoom:qt}]})}else if(xo.name)for(const Ot of ml(f,m))dt({op:"addMotion",motionPreset:"course-brand-bug",start:Ot.start,duration:Ot.duration,placement:"top",text:ge(xo.name,40),params:{fade:Ot.fade,position:Pt?"top-left":"top-right"}})}for(const W of L)W.op==="addMotion"&&(W.color||(W.color=s.accent),s.look&&(W.params={...W.params,look:s.look}));return L.length>i?L.filter(W=>W.op!=="punchIn").slice(0,i):L}function f6(t,{clips:e=[],materials:o=[],W:r=1280,H:n=720,en:a=null,maxOps:i=1/0,simulate:l=null,brand:p=null}={}){if(!Array.isArray(t)||!t.some(m=>m?.op==="courseEdit"&&!m.error))return t;const c=[],s=[];let h=0;const f=m=>{const y=typeof m=="string"&&/^new:(\d+)$/.exec(m);if(!y)return m;const $=+y[1];let x=0;for(const E of s)$>E.after&&(x+=E.by);return`new:${$+x}`};for(const m of t){const y=m&&typeof m=="object"?{...m,...Object.fromEntries(["clipId","fromClipId","sourceClipId"].filter(x=>typeof m[x]=="string").map(x=>[x,f(m[x])])),...Array.isArray(m.clipIds)?{clipIds:m.clipIds.map(f)}:{}}:m;if(y?.op!=="courseEdit"||y.error){c.push(y),Gl.has(y?.op)&&h++;continue}let $=e;if(l&&c.some(x=>["cutPauses","removeRetakes","split","trim","delete","move","compact","rippleDelete","rippleTrim"].includes(x?.op)))try{$=l([...c])??e}catch{$=e}try{const x=h6({clips:$,materials:o,op:y,W:r,H:n,en:a,maxOps:Math.max(1,i-t.length),brand:p}),E=x.filter(k=>Gl.has(k.op)).length,v=c.filter(k=>Gl.has(k?.op)).length,S=k=>{const b=typeof k=="string"&&/^new:(\d+)$/.exec(k);return b?`new:${+b[1]+v}`:k};c.push(...x.map(k=>typeof k.clipId=="string"?{...k,clipId:S(k.clipId)}:k)),E&&s.push({after:h,by:E})}catch(x){c.push({op:"courseEdit",error:String(x?.message||x).slice(0,300)})}}return c}const jn=(t,e,o)=>Math.max(e,Math.min(o,t)),sr=t=>+(+t).toFixed(4),Ea=t=>+(+t).toFixed(3),m6=new Function("return "+ug)(),Bd=Object.freeze({"fr-window":["win",0],"fr-v-window":["win",1],"fr-versus":["vs",0],"fr-v-versus":["vs",1],"fr-headline":["head",0],"fr-v-headline":["head",1],"fr-chips":["chips",0],"fr-v-chips":["chips",1],"fr-paper":["paper",0],"fr-v-paper":["paper",1],"fr-comment-cta":["cta",0],"fr-v-comment-cta":["cta",1]}),g6=Object.fromEntries(Object.entries(Bd).map(([t,[e,o]])=>[t,new Function("M","env","const p={},W=env.width,H=env.height,S=M.safe(env,'center'),u=S.u,cx=W/2,cy=H/2,PT=S.port;"+Gb(o)+"const "+Kb[e]+",r="+Vb+";return {x:wx,y:wy,w:ww,h:wh,r:Math.min(r,ww/2,wh/2)}")]));function Ec(t,e,o){const r=g6[t];return r?r(m6,{width:e,height:o}):null}const jm=(t,e,o)=>({x:sr(t.x/e),y:sr(t.y/o),w:sr(t.w/e),h:sr(t.h/o),r:sr(t.r/Math.min(e,o))});Object.freeze(Object.fromEntries(Object.keys(Bd).map(t=>[t,Object.freeze({landscape:jm(Ec(t,1920,1080),1920,1080),portrait:jm(Ec(t,1080,1920),1080,1920)})])));const Tm=Object.freeze(["full","center","left","right","small","corner"]),so=Object.freeze({morph:.35,maxMorph:1.5,maxBeats:80,minBeat:.2,zoomMax:2.5,keysMax:200,maskFeather:.002,scenes:Object.freeze({center:["fr-window","fr-v-window"],left:["fr-chips","fr-v-chips"],right:["fr-headline","fr-v-headline"],small:["fr-versus","fr-v-versus"]}),corner:Object.freeze({landscape:{w:.3,margin:.04},portrait:{w:.42,aspect:.8,bottom:.8}})}),B1=(t,e)=>e>t*1.1;function _1(t,e,o){const r=B1(e,o),n=Math.min(e,o);if(t==="full")return{x:0,y:0,w:e,h:o,r:0};if(so.scenes[t])return Ec(so.scenes[t][r?1:0],e,o);if(t==="corner"){const a=n*.028;if(r){const s=so.corner.portrait,h=e*s.w,f=h/s.aspect;return{x:e-e*.06-h,y:o*s.bottom-f,w:h,h:f,r:a}}const i=so.corner.landscape,l=e*i.w,p=l*o/e,c=i.margin*n;return{x:e-c-l,y:o-c-p,w:l,h:p,r:a}}if(typeof t=="string"&&/^fr-/.test(t)){const a=Ec(t,e,o);if(a)return a;throw Error(`${t.slice(0,40)} has no speaker window — use ${Tm.join(" / ")} or a window scene (${Object.keys(Bd).filter(i=>!i.startsWith("fr-v-")).join(", ")})`)}throw Error(`layout must be ${Tm.join(" / ")} or a Framed Creator window scene id (fr-window, fr-versus, fr-headline, fr-chips, fr-paper, fr-comment-cta, or their fr-v- twins)`)}const y6=t=>t!=="full",b6=t=>1-Math.pow(1-t,3),qa=(t,e,o)=>t+(e-t)*o;function w6(t,e){const o=Array.isArray(t?.scenes)?t.scenes:[],r=o.find(n=>n.start<=e&&n.end>e&&Number.isFinite(n.subjectX))||o.find(n=>Number.isFinite(n.subjectX));return r?{x:jn(r.subjectX,0,1),y:Number.isFinite(r.subjectY)?jn(r.subjectY,0,1):.42}:null}function G1(t,{W:e,H:o,morph:r=so.morph}={}){if(!Array.isArray(t)||!t.length)throw Error("needs beats [{start, end, layout}]");if(t.length>so.maxBeats)throw Error(`at most ${so.maxBeats} beats`);const n=Number.isFinite(+r)?jn(+r,0,so.maxMorph):so.morph,a=t.map((i,l)=>{if(!i||typeof i!="object")throw Error(`beats[${l}] must be an object`);const p=+i.start,c=+i.end;if(!Number.isFinite(p)||!Number.isFinite(c)||p<0)throw Error(`beats[${l}] needs start and end (timeline s)`);if(c-p<so.minBeat)throw Error(`beats[${l}]: end must be at least ${so.minBeat} s after start`);if(i.zoom!=null&&!(Number.isFinite(+i.zoom)&&+i.zoom>=1&&+i.zoom<=so.zoomMax))throw Error(`beats[${l}].zoom must be 1–${so.zoomMax}`);if(i.morph!=null&&!(Number.isFinite(+i.morph)&&+i.morph>=0&&+i.morph<=so.maxMorph))throw Error(`beats[${l}].morph must be 0–${so.maxMorph} s`);let s;try{s=_1(i.layout??"full",e,o)}catch(h){throw Error(`beats[${l}]: ${h.message}`)}return{i:l,start:ht(p),end:ht(c),layout:i.layout??"full",rect:s,zoom:i.zoom!=null?+i.zoom:1,morph:i.morph!=null?+i.morph:n}}).sort((i,l)=>i.start-l.start);for(let i=1;i<a.length;i++)if(a[i].start<a[i-1].end-1e-6)throw Error(`beats[${a[i].i}] overlaps beats[${a[i-1].i}] — one layout at a time`);return a}function k6(t,e,o,r){const n={rect:{x:0,y:0,w:o,h:r,r:0},zoom:1};let a=-1;for(let f=0;f<t.length;f++)t[f].start<=e+1e-9&&(a=f);if(a<0)return n;const i=t[a],l=a>0?t[a-1]:n,p=Math.min(i.morph,(i.end-i.start)*.6);if(p<=1e-6||e>=i.start+p)return i;const c=b6(jn((e-i.start)/p,0,1)),s=l.rect,h=i.rect;return{rect:{x:qa(s.x,h.x,c),y:qa(s.y,h.y,c),w:qa(s.w,h.w,c),h:qa(s.h,h.h,c),r:qa(s.r,h.r,c)},zoom:qa(l.zoom,i.zoom,c)}}function x6(t,e,o){const r=[];let n={rect:{x:0,y:0,w:e,h:o},zoom:1};for(const a of t){const i=Math.min(a.morph,(a.end-a.start)*.6),l=n.rect,p=a.rect;(Math.abs(l.x-p.x)+Math.abs(l.y-p.y)+Math.abs(l.w-p.w)+Math.abs(l.h-p.h)>.5||Math.abs(n.zoom-a.zoom)>.001)&&r.push(i>1e-6?[a.start,a.start+i]:[a.start,a.start]),n=a}return r}function M6(t,{rect:e,zoom:o},{W:r,H:n,mw:a,mh:i,face:l}){const p=t.fit==="cover"?Math.max(r/a,n/i):Math.min(r/a,n/i),c=a*p,s=i*p,h=e.w/e.h;let f=h<=a/i?i:a/h,m=f*h;f/=o,m/=o;const y=l?.x??.5,$=l?.y??(a<=i?.36:.42),x=jn(y*a,m/2,a-m/2),E=jn($*i+f*.08,f/2,i-f/2),v=e.w/(m*p),S=t.flipX?-1:1,k=t.flipY?-1:1,b=(e.x+e.w/2-r/2-S*v*(x/a-.5)*c)/r,A=(e.y+e.h/2-n/2-k*v*(E/i-.5)*s)/n,I=1/(v*p),P=.02*Math.min(r,n)*I,C=e.x<=.5?P:0,z=e.y<=.5?P:0,N=e.x+e.w>=r-.5?P:0,F=e.y+e.h>=n-.5?P:0,K=(x-m/2-C)/a,_=(x+m/2+N)/a,q=(E-f/2-z)/i,U=(E+f/2+F)/i,rt=Math.min(e.r*I,m/2,f/2),ot=rt/a,G=rt/i,J=.5523*ot,Z=.5523*G,at=ut=>sr(jn(ut,-1,2)),D=ut=>sr(jn(ut,-1,1)),H=[[K+ot,q,-J,0,0,0],[_-ot,q,0,0,J,0],[_,q+G,0,-Z,0,0],[_,U-G,0,0,0,Z],[_-ot,U,J,0,0,0],[K+ot,U,0,0,-J,0],[K,U-G,0,Z,0,0],[K,q+G,0,0,0,-Z]].map(ut=>[at(ut[0]),at(ut[1]),D(ut[2]),D(ut[3]),D(ut[4]),D(ut[5])]);return{x:sr(b),y:sr(A),zoom:sr(v),pts:H}}function $6(t,e){const o=t.find(r=>r.id===e);if(!o||o.kind!=="video"||o.title||o.shape||o.motion||o.gen||o.card)throw Error("needs the speaker's video clip (clipId)");return t.filter(r=>r.id===o.id||o.nodeId&&r.nodeId===o.nodeId&&r.track===o.track&&r.kind===o.kind&&(!r.mask||r.speakerLayout)&&!r.bubble).sort((r,n)=>r.start-n.start)}function v6(t,e,{beats:o,morph:r,W:n=1280,H:a=720,material:i=null}={}){const l=$6(t,e),p=G1(o,{W:n,H:a,morph:r}),c=l[0].start,s=l.at(-1).start+l.at(-1).duration;if(p[0].start>=s-1e-6||p.at(-1).end<=c+1e-6)throw Error("beats must fall inside the speaker clip");const h=Math.round(i?.width)||(n<=a?1080:1920),f=Math.round(i?.height)||(n<=a?1920:1080),m=x6(p,n,a),y=new Map;for(const $ of l){const x=$.start,E=$.start+$.duration,v=m.filter(([z,N])=>N>x-1e-6&&z<E+1e-6);if(!(p.some(z=>z.start<E&&z.end>x)||v.length||p[0].start<E))continue;const S=jn(Math.floor((so.keysMax-2)/Math.max(1,v.length*2))-1,2,8),k=new Set([0,Ea($.duration)]);for(const[z,N]of v){if(z-x>1/30&&k.add(Ea(z-x)),N>z)for(let F=0;F<=S;F++){const K=z+(N-z)*F/S;K>x&&K<E&&k.add(Ea(K-x))}N-x<$.duration&&k.add(Ea(Math.max(0,N-x))),N<=z&&z-x>1/30&&k.add(Ea(Math.max(0,z-x-1/30)))}const b=$.playbackRate||1,A=z=>($.inPoint||0)+z*b,P=[...k].filter(z=>z>=0&&z<=$.duration+1e-6).sort((z,N)=>z-N).map(z=>{const N=k6(p,$.start+z,n,a);return{t:z,...M6($,N,{W:n,H:a,mw:h,mh:f,face:w6(i,A(z))})}});let C={...$,...Zr($)};for(const z of["sx","sy","ax","ay","rot"])Me(C,z).length&&(C={...C,motionKeys:qr(C,z,[])});for(const z of["x","y","zoom"])C={...C,motionKeys:qr(C,z,P.map(N=>({time:N.t,value:N[z]})))};if(C.motionKeys.length>Wb)throw Error("too many layout changes on one clip — fewer beats or a shorter morph");C.posX=P[0].x,C.posY=P[0].y,C.scale=P[0].zoom,C.mask={v:2,mw:h,mh:f,masks:[{id:"m1",name:"Khung người nói",mode:"add",feather:so.maskFeather,smooth:!1,keys:E6(P.map(z=>({t:Ea(Math.min(z.t,$.duration)),pts:z.pts})))}]},C.speakerLayout={beats:p.filter(z=>z.start<E&&z.end>x).length,v:1};for(const z of["crop","rotation","scaleX","scaleY","anchorX","anchorY","tiltX","tiltY","pin","layout","person","roto","planar","bubble"])delete C[z];y.set($.id,C)}if(!y.size)throw Error("beats must fall inside the speaker clip");return{clips:t.map($=>y.get($.id)??$),pieces:y.size}}function E6(t){const e=(o,r)=>o.pts.every((n,a)=>n.every((i,l)=>i===r.pts[a][l]));return t.filter((o,r)=>!(r>0&&r<t.length-1&&e(o,t[r-1])&&e(o,t[r+1])))}const S6=new Set(["addClip","addBroll","generateBroll","addText","addShape","addMotion","addElement","addCard","addSolid","addAdjustmentLayer","generateElement","lockup","placeBehindPerson"]),_d=(t,e)=>{let o={};if(typeof t?.prompt=="string"&&t.prompt.trim()){try{o=JSON.parse(t.prompt)}catch{throw Error("prompt must be the options as JSON")}if(!o||typeof o!="object"||Array.isArray(o))throw Error("prompt must be the options as JSON")}return{...o,...Object.fromEntries(Object.entries(t).filter(([r,n])=>!["op","prompt"].includes(r)&&n!==null&&n!==void 0))}},I6=/^#[0-9a-f]{6}$/i;function A6(t,e,{W:o,H:r}){const n=B1(o,r),a=[],i=I6.test(String(t.accent??""))?t.accent:null;if(t.frame!=null&&t.frame!=="brackets"&&t.frame!=="none")throw Error("frame must be brackets or none");for(const l of e){const p=t.beats[l.i],c=p.motion,s=Ea(Math.min(l.end-l.start,Qe.maxDuration));if(c!=null){if(typeof c!="object"||Array.isArray(c))throw Error(`beats[${l.i}].motion must be an object`);const h=c.preset??c.motionPreset??(typeof l.layout=="string"&&l.layout.startsWith("fr-")?l.layout:null);if(!h)throw Error(`beats[${l.i}].motion needs preset (a layout like "${l.layout}" names no scene)`);const{preset:f,motionPreset:m,...y}=c;a.push({op:"addMotion",motionPreset:h,start:l.start,duration:s,...y,...i&&!y.color?{color:i}:{}})}else if(t.frame==="brackets"&&y6(l.layout)){const h=l.rect;a.push({op:"addMotion",motionPreset:n?"fr-v-window":"fr-window",start:l.start,duration:s,...i?{color:i}:{},params:{bg:!1,text:typeof p.label=="string"?p.label.slice(0,40):"",sub:"",wx:sr(h.x/o),wy:sr(h.y/r),ww:sr(h.w/o),wh:sr(h.h/r)}})}}return a}function C6(t,{W:e=1280,H:o=720}={}){if(!Array.isArray(t)||!t.some(l=>l?.op==="speakerLayout"&&!l.error))return t;const r=[],n=[];let a=0;const i=l=>{const p=typeof l=="string"&&/^new:(\d+)$/.exec(l);if(!p)return l;const c=+p[1];let s=0;for(const h of n)c>h.after&&(s+=h.by);return`new:${c+s}`};for(const l of t){const p=l&&typeof l=="object"?{...l,...Object.fromEntries(["clipId","fromClipId","sourceClipId","parentClipId"].filter(c=>typeof l[c]=="string").map(c=>[c,i(l[c])])),...Array.isArray(l.clipIds)?{clipIds:l.clipIds.map(i)}:{}}:l;if(p?.op!=="speakerLayout"||p.error){r.push(p),S6.has(p?.op)&&a++;continue}try{const c=_d(p,"speakerLayout");if(c.frame!=null&&c.frame!=="brackets"&&c.frame!=="none")throw Error("frame must be brackets or none");if(!(c.frame==="brackets"||Array.isArray(c.beats)&&c.beats.some(E=>E&&E.motion!=null))){r.push(p);continue}const h=G1(c.beats,{W:e,H:o,morph:c.morph}),f=A6(c,h,{W:e,H:o}),{frame:m,accent:y,prompt:$,...x}=c;r.push({...x,op:"speakerLayout",beats:c.beats.map(E=>{const{motion:v,label:S,...k}=E;return k})},...f),f.length&&n.push({after:a,by:f.length})}catch(c){r.push({op:"speakerLayout",error:String(c?.message||c).slice(0,300)})}}return r}const ho=t=>+(+t).toFixed(3),Om=(t,e,o)=>Math.max(e,Math.min(o,t)),Sc=t=>String(t??"").toLowerCase().normalize("NFC").replace(/[.,!?…:;"“”'‘’()[\]{}*/]+/gu,"").trim(),an=(t,e)=>typeof t=="string"?t.replace(/\s+/gu," ").trim().slice(0,e):"",j6=/^#[0-9a-f]{6}$/i,Kl=Object.freeze({hook:{scene:"fr-window",sit:"window"},headline:{scene:"fr-headline",sit:"window"},versus:{scene:"fr-versus",sit:"window"},clock:{scene:"fr-clock",sit:"cover"},chips:{scene:"fr-chips",sit:"window"},question:{scene:"fr-paper",sit:"window"},cta:{scene:"fr-comment-cta",sit:"window"},chapter:{scene:"fr-chapter",sit:"cover"},definition:{scene:"fr-definition",sit:"over"},recap:{scene:"fr-recap",sit:"cover"},lowerThird:{scene:"fr-lower-third",sit:"over"},full:{scene:null,sit:"full"}}),T6=Object.freeze(Object.keys(Kl)),ro=Object.freeze({accent:"#ffc21a",snap:.6,closeGap:2,replyFrom:1,backdrop:["fr-backdrop","fr-v-backdrop"],maxBeats:40,minBeat:.6,lead:.08,tail:1.2,whipMorph:.22,whipSfx:"swoosh",whipVolume:.45,jump:.25,punch:{amount:1.12,max:1.2,min:1.2},lower:{dur:4,min:2}});function O6(t,e,o=0){const r=String(e??"").split(/\s+/u).map(Sc).filter(Boolean);if(!r.length)return null;const n=t.map(p=>Sc(p.word)),a=(p,c)=>p===c||c.length>2&&p.startsWith(c)||p.length>2&&c.startsWith(p),i=p=>{for(let c=p;c<=n.length-r.length;c++)if(r.every((s,h)=>a(n[c+h],s)))return[c,c+r.length-1];return null},l=i(o)??i(0);if(l)return l;for(const p of[o,0])for(let c=p;c<n.length;c++)if(a(n[c],r[0])){for(let s=c+1;s<Math.min(n.length,c+r.length+3);s++)if(a(n[s],r.at(-1)))return[c,s]}return null}function K1(t,e,o,r){const n=e.filter(c=>c.start>=o-.1&&c.start<r),a=t.map(c=>{const s=String(c),h=s.indexOf(":");return Sc((h>0&&!/\s/.test(s.slice(0,h))?s.slice(h+1):s).split(/\s+/u)[0])});let i=0;const l=a.map(c=>{for(let s=i;s<n.length;s++){const h=Sc(n[s].word);if(c&&(h===c||c.length>2&&h.startsWith(c)||h.length>2&&c.startsWith(h)))return i=s+1,ho(Math.max(0,n[s].start-o))}return null});if(l.every(c=>c===null))return null;for(let c=0;c<l.length;c++)if(l[c]===null){let s=c-1;for(;s>=0&&l[s]===null;)s--;let h=c+1;for(;h<l.length&&l[h]===null;)h++;const f=s>=0?l[s]:null,m=h<l.length?l[h]:null;l[c]=ho(f!==null&&m!==null?f+(m-f)*(c-s)/(h-s):f!==null?f+.4*(c-s):Math.max(0,m-.4*(h-c)))}let p=0;return l.map(c=>{const s=ho(Math.max(p,c));return p=s+.05,s})}const P6=t=>String(t??"").split("/").flatMap(e=>e.split(" ").filter(Boolean)).map(e=>e.replace(/[*]/g,"")).filter(Boolean);function Pm(t,e,o,r,n=0){const a=K1(P6(t),e,o,r);if(!a)return null;let i=0;return a.map(l=>{const p=ho(Math.max(n,i,l));return i=p+.05,p})}const z6=["label","caret","total","position","times"];function L6(t){if(t==null)return{};if(typeof t!="object"||Array.isArray(t))throw Error("fields must be an object");const e={};t.text!=null&&(e.text=an(String(t.text),120));const o=t.sub??t.subText;o!=null&&(e.subText=an(String(o),160)),Array.isArray(t.items)&&(e.items=t.items.filter(a=>typeof a=="string").map(a=>an(a,48)).filter(Boolean).slice(0,5));const r=t.number??t.numberValue;r!=null&&Number.isFinite(+r)&&(e.numberValue=+r),typeof t.icon=="string"&&(e.icon=t.icon);const n=Object.fromEntries(z6.filter(a=>t[a]!=null&&["string","number","boolean"].includes(typeof t[a])).map(a=>[a,typeof t[a]=="string"?t[a].slice(0,120):t[a]]));return Object.keys(n).length&&(e.params=n),e}function N6({clips:t=[],materials:e=[],op:o={},W:r=1280,H:n=720}={}){const a=_d(o),i=t.find(C=>C.id===a.clipId);if(!i||i.kind!=="video"||i.motion||i.title||i.shape)throw Error("clipId must be the speaker video on the timeline");if(a.aspect!=null&&!["16:9","9:16"].includes(a.aspect))throw Error("aspect must be 16:9 or 9:16");if(a.accent!=null&&!j6.test(String(a.accent)))throw Error("accent must be #RRGGBB");if(a.flavor!=null&&!["creator","course"].includes(a.flavor))throw Error("flavor must be creator or course");if(!Array.isArray(a.beats)||!a.beats.length)throw Error("needs beats [{kind, say | start, end?, fields?}]");if(a.beats.length>ro.maxBeats)throw Error(`at most ${ro.maxBeats} beats`);const l=a.aspect?a.aspect==="9:16":n>r*1.1,p=C=>C&&l?C.replace(/^fr-/,"fr-v-"):C,c=a.accent?String(a.accent).toLowerCase():ro.accent,s=t.filter(C=>C.id===i.id||i.nodeId&&C.nodeId===i.nodeId&&C.track===i.track&&C.kind===i.kind&&!C.bubble).sort((C,z)=>C.start-z.start),h=s[0].start,f=s.at(-1).start+s.at(-1).duration,m=Dd(t,i.id,e);let y=0;const $=a.beats.map((C,z)=>{if(!C||typeof C!="object")throw Error(`beats[${z}] must be an object`);if(!Kl[C.kind])throw Error(`beats[${z}].kind must be ${T6.join(" / ")}`);let N=C.start!=null?+C.start:null,F=null;if(C.start!=null&&!Number.isFinite(N))throw Error(`beats[${z}].start must be timeline seconds`);if(C.say!=null){if(!m.length)throw Error(`beats[${z}].say needs the speaker's transcript (transcribe the clip first) — or give start / end`);const _=O6(m,C.say,y);if(!_)throw Error(`beats[${z}].say "${an(String(C.say),60)}" is not in the transcript`);F={start:m[_[0]].start,end:m[_[1]].end,first:_[0]},y=_[1]+1,N===null&&(N=Math.max(h,F.start-ro.lead))}if(N===null)throw Error(`beats[${z}] needs say (a phrase of the transcript) or start`);if(C.end!=null&&!Number.isFinite(+C.end))throw Error(`beats[${z}].end must be timeline seconds`);let K;try{K=L6(C.fields)}catch(_){throw Error(`beats[${z}].${_.message}`)}return{i:z,kind:C.kind,start:ho(Om(N,h,f)),end:C.end!=null?+C.end:null,said:F,fields:K}}).sort((C,z)=>C.start-z.start);if($[0].start-h<ro.snap&&($[0].start=ho(h)),a.flavor==="course"&&a.instructor&&typeof a.instructor=="object"&&an(a.instructor.name,60)&&!$.some(C=>C.kind==="lowerThird")){const C=h+.3,z=Math.min(h+.3+ro.lower.dur,$[0].start);z-C>=ro.lower.min&&$.unshift({i:-1,kind:"lowerThird",start:ho(C),end:ho(z),said:null,fields:{text:an(a.instructor.name,60),...an(a.instructor.role,80)?{subText:an(a.instructor.role,80)}:{},...an(a.instructor.label,24)?{params:{label:an(a.instructor.label,24)}}:{}}})}const x=$.map((C,z)=>{const N=$[z+1],F=N?N.start:f;let K=C.end!==null?Math.min(C.end,F):N?N.start:Math.min(f,(C.said?.end??C.start+3)+ro.tail);if(K=ho(Math.min(K,f)),K-C.start<ro.minBeat-1e-6)throw Error(`beats[${C.i}] (${C.kind}) is too short (${ho(K-C.start)} s) — the next beat starts right after it`);return{...C,end:K}});$.at(-1).end===null&&f-x.at(-1).end<ro.closeGap&&(x.at(-1).end=ho(f));let E=null;const v=x.map(C=>{const z=Kl[C.kind],N=z.sit==="window"?p(z.scene):z.sit==="cover"?E??p("fr-window"):"full";return E=N,N}),S=v.map(C=>_1(C,r,n)),k=(C,z)=>{if(!C||!z)return!1;const N=F=>F.w>=r-1&&F.h>=n-1;return N(C)!==N(z)?!0:Math.hypot((C.x+C.w/2-z.x-z.w/2)/r,(C.y+C.h/2-z.y-z.h/2)/n)>ro.jump},b=a.whip!==!1,A=[],I=[],P=x.map((C,z)=>{const N=z>0&&k(S[z-1],S[z])&&v[z]!==v[z-1];return N&&b&&I.push(ho(Math.max(0,C.start-.05))),{start:C.start,end:C.end,layout:v[z],...N&&b?{morph:ro.whipMorph}:{}}});if(A.push({op:"speakerLayout",clipId:i.id,beats:P,morph:Number.isFinite(+a.morph)?Om(+a.morph,0,so.maxMorph):so.morph}),a.backdrop!==!1){const C=x[0].start,z=x.at(-1).end;let N=0;for(let F=C;F<z-.001;F+=Qe.maxDuration){const K=ho(Math.min(Qe.maxDuration,z-F));A.push({op:"addMotion",motionPreset:ro.backdrop[l?1:0],start:ho(F),duration:K,params:{offset:ho(F-C)}}),N++}for(let F=1;F<=N;F++)A.push({op:"setLayerOrder",clipId:`new:${F}`,numberValue:-1})}for(const C of x){const z=Kl[C.kind];if(!z.scene)continue;const N={...C.fields,params:{...C.fields.params??{}}};if(C.kind==="chips"&&N.items?.length&&N.params.times==null){const F=K1(N.items,m,C.start,C.end);F&&(N.params.times=F.join(","))}if(C.kind==="headline"&&N.text&&N.params.times==null){const F=Pm(N.text,m,C.start,C.end);F&&(N.params.times=F.join(","))}if(C.kind==="question"&&N.subText&&N.params.times==null){const F=Pm(N.subText,m,C.start,C.end,ro.replyFrom);F&&(N.params.times=F.join(","))}Object.keys(N.params).length||delete N.params,A.push({op:"addMotion",motionPreset:p(z.scene),start:C.start,duration:ho(Math.min(C.end-C.start,Qe.maxDuration)),color:c,...N})}if(a.punch!==!1){for(const C of x)if(C.kind==="full"&&C.end-C.start>=ro.punch.min){const z=ho(Math.max(C.start,C.said?C.said.start:C.start+.1)),N=ho(Math.min(ro.punch.max,C.end-z-.25));N>=.4&&A.push({op:"punchIn",clipId:i.id,at:z,duration:N,numberValue:ro.punch.amount,punchStyle:"smooth"})}}for(const C of I)A.push({op:"addSfx",sfxId:ro.whipSfx,at:C,volume:ro.whipVolume});return A}const Gp=new Set(["addClip","addBroll","generateBroll","addText","addShape","addMotion","addElement","addCard","addSolid","addAdjustmentLayer","generateElement","lockup","placeBehindPerson"]),F6=["cutPauses","removeRetakes","split","trim","delete","move","compact","rippleDelete","rippleTrim"];function R6(t,{clips:e=[],materials:o=[],W:r=1280,H:n=720,maxOps:a=1/0,simulate:i=null}={}){if(!Array.isArray(t)||!t.some(h=>h?.op==="framedEdit"&&!h.error))return t;const l=[],p=[];let c=0;const s=h=>{const f=typeof h=="string"&&/^new:(\d+)$/.exec(h);if(!f)return h;const m=+f[1];let y=0;for(const $ of p)m>$.after&&(y+=$.by);return`new:${m+y}`};for(const h of t){const f=h&&typeof h=="object"?{...h,...Object.fromEntries(["clipId","fromClipId","sourceClipId","parentClipId"].filter(y=>typeof h[y]=="string").map(y=>[y,s(h[y])])),...Array.isArray(h.clipIds)?{clipIds:h.clipIds.map(s)}:{}}:h;if(f?.op!=="framedEdit"||f.error){l.push(f),Gp.has(f?.op)&&c++;continue}let m=e;if(i&&l.some(y=>F6.includes(y?.op)))try{m=i([...l])??e}catch{m=e}try{const y=N6({clips:m,materials:o,op:f,W:r,H:n}),$=y.filter(v=>Gp.has(v.op)).length;if(l.length+y.length>a)throw Error(`makes ${y.length} ops — over the plan's ${a}; fewer beats`);const x=l.filter(v=>Gp.has(v?.op)).length,E=v=>{const S=typeof v=="string"&&/^new:(\d+)$/.exec(v);return S?`new:${+S[1]+x}`:v};l.push(...y.map(v=>typeof v.clipId=="string"?{...v,clipId:E(v.clipId)}:v)),$&&p.push({after:c,by:$})}catch(y){l.push({op:"framedEdit",error:String(y?.message||y).slice(0,300)})}}return l}const Wi="torn",Ic=["top","right","bottom","left"],zm=Object.freeze({depth:.03,seed:1}),D6=30;function B6(t){let e=t>>>0||1;return()=>{e=e+1831565813>>>0;let o=e;return o=Math.imul(o^o>>>15,o|1),o^=o+Math.imul(o^o>>>7,o|61),((o^o>>>14)>>>0)/4294967296}}const Za=t=>Math.round(t*1e4)/1e4;function _6({sides:t=Ic,depth:e=zm.depth,seed:o=zm.seed,aspect:r=16/9}={}){const n=new Set(t.filter($=>Ic.includes($)));if(!n.size)throw Error("Pick at least one side to tear");if(!Number.isFinite(e)||e<.005||e>.1)throw Error("Invalid tear depth");const a=B6(o),i=e/Math.max(1,r),l=e*Math.min(1,r),p=($,x,E,v)=>[Za(n.has(E)?$?1-i*(.4+a()*.6):i*(.4+a()*.6):$),Za(n.has(v)?x?1-l*(.4+a()*.6):l*(.4+a()*.6):x)],c=p(0,0,"left","top"),s=p(1,0,"right","top"),h=p(1,1,"right","bottom"),f=p(0,1,"left","bottom"),m=($,x,E)=>{if(!n.has(E))return[];const v=[],S=D6,k=E==="top"||E==="bottom";for(let b=1;b<S;b++){const A=b/S+(a()-.5)*.6/S,I=a()**1.6,P=$[0]+(x[0]-$[0])*A,C=$[1]+(x[1]-$[1])*A;k?v.push([Za(P),Za(E==="top"?I*l:1-I*l)]):v.push([Za(E==="left"?I*i:1-I*i),Za(C)])}return v},y=[c,...m(c,s,"top"),s,...m(s,h,"right"),h,...m(h,f,"bottom"),f,...m(f,c,"left")];if(y.length>yu)throw Error("Torn outline too long");return y}function G6(t,{mw:e,mh:o,crop:r,sides:n,depth:a,seed:i}){const l=Ka(t).filter(h=>h.id!==Wi),p=r||{left:0,right:0,top:0,bottom:0},c=e*(1-p.left-p.right)/Math.max(1,o*(1-p.top-p.bottom)),s={id:Wi,name:"Mép xé",mode:l.length?"intersect":"add",keys:[{t:0,pts:_6({sides:n,depth:a,seed:i,aspect:c})}],feather:.0015};return gr(t?{mw:t.mw,mh:t.mh}:{mw:e,mh:o},[...l,s])}function NC(t){const e=Ka(t).filter(o=>o.id!==Wi);return t&&e.length?gr(t,e.map((o,r)=>r===0&&o.mode==="intersect"?{...o,mode:"add"}:o)):void 0}const FC=t=>Ka(t).some(e=>e.id===Wi),V1="cut",Gd=t=>new RegExp(`^${V1}\\d+$`).test(t.id);function RC(t,{mw:e,mh:o},r){if(!r.length)throw Error("Nothing to cut out");const n=Ka(t).filter(c=>!Gd(c)),a=n.filter(c=>c.id===Wi),i=n.filter(c=>c.id!==Wi),l=r.slice(0,Math.max(1,8-n.length)).map((c,s)=>({id:`${V1}${s+1}`,name:"Tách nền",mode:"add",keys:[{t:0,pts:c}],smooth:!0,feather:.0012})),p=[...i,...l,...a.map(c=>({...c,mode:"intersect"}))].map((c,s)=>s===0&&c.mode!=="add"?{...c,mode:"add"}:c);return gr(t?{mw:t.mw,mh:t.mh}:{mw:e,mh:o},p)}const DC=t=>Ka(t).some(Gd);function BC(t){const e=Ka(t).filter(o=>!Gd(o));return t&&e.length?gr(t,e.map((o,r)=>r===0&&o.mode!=="add"?{...o,mode:"add"}:o)):void 0}const cn=Object.freeze({maxCards:24,cols:[1,8],rows:[1,6],curve:[0,1],maxSeconds:20,fly:[.25,2],color:"#5ee7ff"}),K6=Object.freeze(["glass","neon","mono"]),Kp=Object.freeze(["chart","play","photo","music","chat","map","cart","stats","calendar","mail","code","camera"]),W1=/^#[0-9a-fA-F]{6}$/,ne=t=>Math.round(t*1e4)/1e4,Vl=t=>Math.round(t*1e3)/1e3,Es=(t,e,o,r)=>Number.isFinite(t)?Math.min(o,Math.max(e,t)):r,V6={vi:[["Doanh thu","+24% tuần này"],["Video mới","4K · 02:15"],["Bộ sưu tập","128 ảnh"],["Đang phát","Lo-fi Focus"],["Tin nhắn","3 tin mới"],["Bản đồ","12 phút"],["Đơn hàng","56 đơn hôm nay"],["Người xem","18,4K"],["Lịch","Họp 15:00"],["Hộp thư","9 chưa đọc"],["Dự án","Build #42"],["Máy ảnh","Sẵn sàng"]],en:[["Revenue","+24% this week"],["New video","4K · 02:15"],["Gallery","128 photos"],["Now playing","Lo-fi Focus"],["Messages","3 new"],["Map","12 min"],["Orders","56 today"],["Viewers","18.4K"],["Calendar","Meeting 3 PM"],["Inbox","9 unread"],["Project","Build #42"],["Camera","Ready"]]},Lm=["#5ee7ff","#7c8cff","#ff6bd6","#ffd166","#6dffb3","#ff8f5e"];function Pi(t,e,o,r){var n=Math.max(1e-4,(t.curve||0)*1.75),a=1.55,i=(e-.5)*n,l=t.w/n,p=l*Math.sin(i),c=l*(1-Math.cos(i)),s=(o-.5)*t.h,h=a/(a-c);return[t.cx+p*h,t.cy+s*h*r,h]}function W6(t,e,o,r){let n=.5+(e-t.cx)/t.w,a=.5+(o-t.cy)/(t.h*r);for(let i=0;i<12;i++){const l=Pi(t,n,a,r),p=1e-4,c=Pi(t,n+p,a,r),s=Pi(t,n,a+p,r),h=(c[0]-l[0])/p,f=(s[0]-l[0])/p,m=(c[1]-l[1])/p,y=(s[1]-l[1])/p,$=h*y-f*m||1e-9,x=e-l[0],E=o-l[1];n+=(y*x-f*E)/$,a+=(-m*x+h*E)/$}return[n,a]}function X1(t,e){var o=Math.floor(e/t.cols),r=e%t.cols,n=.07,a=n*(t.w/t.cols)/(t.h/t.rows);return[(r+n)/t.cols,(o+a)/t.rows,(r+1-n)/t.cols,(o+1-a)/t.rows]}function Nm(t,e,o,r=0){if(e<-r/t.cols||e>1+r/t.cols||o<-r/t.rows||o>1+r/t.rows)return-1;const n=Math.max(0,Math.min(t.cols-1,Math.floor(e*t.cols))),a=Math.max(0,Math.min(t.rows-1,Math.floor(o*t.rows))),i=a*t.cols+n;return i<t.cards.length?i:-1}function X6(t,e=[],o="vi"){const r=Array.isArray(t?.cards)?t.cards.slice(0,cn.maxCards):null,n=r?r.length:Math.round(Es(Number(t?.count),1,cn.maxCards,12));if(!n)throw Error("hudWall needs at least one card");const a=V6[o==="en"?"en":"vi"],i={},l=[];for(let p=0;p<n;p++){const c=r?.[p]??{},s=a[p%a.length],h={title:String(c.title??s[0]).slice(0,40),sub:String(c.sub??(r?"":s[1])).slice(0,60),color:W1.test(c.color??"")?c.color.toLowerCase():Lm[p%Lm.length],icon:Kp.includes(c.icon)?c.icon:Kp[p%Kp.length]};if(c.materialId!=null){const f=e.find(y=>y.id===c.materialId);if(!f||f.kind!=="image"||typeof f.gcsUri!="string")throw Error(`hudWall card ${p+1}: "${String(c.materialId).slice(0,40)}" is not a picture in the Media bin`);const m=`card${p}.img`;i[m]=f.gcsUri,h.img=m}l.push(h)}return{cards:l,assets:i}}function H6({cards:t,cols:e,rows:o,curve:r,color:n,look:a,toolbar:i=!0,W:l=1280,H:p=720,fill:c=!1}){const s=t.length,h=l/p,f=i!==!1,m=Math.round(Es(e,...cn.cols,Math.min(s,h>=1?4:2))),y=Math.round(Es(o,...cn.rows,Math.ceil(s/m)));if(m*y<s)throw Error(`hudWall: ${s} cards do not fit ${m} × ${y}`);const $=1.45,x=c?f?.84:.92:h>=1?.64:.82,E=(c?.84:.58)/h*m/y*$,v=Math.min(x,E),S=v/m*y/$;return{cols:m,rows:y,curve:Vl(Es(r,...cn.curve,.45)),color:W1.test(n??"")?n.toLowerCase():cn.color,look:K6.includes(a)?a:"glass",toolbar:f,cx:.5+(f?c?.045:.02:0),cy:c?.5:.4,w:ne(v),h:ne(S),cards:t,...c?{asp:ne(h)}:{}}}function H1(t,e,o,r,n,a,i){var l=Math.min(o,r)*(i?.02:.09),p=Math.min(o,r*1.45),c=function(gt,xt,u,st,V){t.beginPath(),t.moveTo(gt+V,xt),t.arcTo(gt+u,xt,gt+u,xt+st,V),t.arcTo(gt+u,xt+st,gt,xt+st,V),t.arcTo(gt,xt+st,gt,xt,V),t.arcTo(gt,xt,gt+u,xt,V),t.closePath()},s=e.color||n,h=e.img&&typeof M<"u"&&M.asset?M.asset(e.img):null;t.save(),c(0,0,o,r,l),t.clip();var f=t.createLinearGradient(0,0,o,r),m=i?1:0;if(a==="mono"?(f.addColorStop(0,"rgba(235,240,248,"+(m||.97)+")"),f.addColorStop(1,"rgba(190,200,215,"+(m||.95)+")")):(f.addColorStop(0,"rgba(14,22,38,"+(m||.97)+")"),f.addColorStop(1,"rgba(8,12,24,"+(m||.95)+")")),t.fillStyle=f,t.fillRect(0,0,o,r),i){var y=t.createRadialGradient(o*.75,r*.2,0,o*.75,r*.2,o*.7);y.addColorStop(0,(e.color||n)+"33"),y.addColorStop(1,(e.color||n)+"00"),t.fillStyle=y,t.fillRect(0,0,o,r)}var $=a==="mono"?"#0d1424":"#eaf6ff",x=a==="mono"?"rgba(13,20,36,0.55)":"rgba(234,246,255,0.55)",E=o*.07,v=r*.36,S=o*.86,k=r*.56;if(h){var b=Math.max(o/h.width,r/h.height),A=h.width*b,I=h.height*b;t.drawImage(h,(o-A)/2,(r-I)/2,A,I);var P=t.createLinearGradient(0,r*.45,0,r);P.addColorStop(0,"rgba(0,0,0,0)"),P.addColorStop(1,"rgba(0,0,0,0.62)"),t.fillStyle=P,t.fillRect(0,0,o,r),$="#ffffff",x="rgba(255,255,255,0.75)"}else{t.strokeStyle=s,t.fillStyle=s,t.lineWidth=Math.max(1,p*.012),t.lineCap="round",t.lineJoin="round";var C=(e.title||"").length*7+(e.icon||"").length,z=function(gt){var xt=Math.sin(C*12.9898+gt*78.233)*43758.5453;return xt-Math.floor(xt)},N=e.icon;if(N==="chart"||N==="stats"){t.globalAlpha=.9,t.beginPath();for(var F=0;F<=8;F++){var K=E+S*F/8,_=v+k*(.85-.6*(.3+.7*z(F))*(.4+F/12));F?t.lineTo(K,_):t.moveTo(K,_)}t.stroke(),t.globalAlpha=.18,t.lineTo(E+S,v+k),t.lineTo(E,v+k),t.closePath(),t.fill(),t.globalAlpha=1}else if(N==="play"||N==="camera"){var q=t.createLinearGradient(E,v,E+S,v+k);q.addColorStop(0,s),q.addColorStop(1,"#101a30"),t.globalAlpha=.55,t.fillStyle=q,c(E,v,S,k,l*.5),t.fill(),t.globalAlpha=1,t.fillStyle=$,t.beginPath();var U=E+S/2,rt=v+k/2,ot=k*.22;N==="play"?(t.moveTo(U-ot*.6,rt-ot),t.lineTo(U+ot,rt),t.lineTo(U-ot*.6,rt+ot)):t.arc(U,rt,ot,0,Math.PI*2),t.closePath(),t.fill()}else if(N==="photo")t.globalAlpha=.5,t.fillStyle=s,c(E,v,S,k,l*.5),t.fill(),t.globalAlpha=1,t.fillStyle="rgba(255,255,255,0.85)",t.beginPath(),t.moveTo(E,v+k),t.lineTo(E+S*.35,v+k*.35),t.lineTo(E+S*.6,v+k*.7),t.lineTo(E+S*.75,v+k*.5),t.lineTo(E+S,v+k),t.closePath(),t.fill(),t.beginPath(),t.arc(E+S*.78,v+k*.25,k*.1,0,Math.PI*2),t.fill();else if(N==="music"){for(var F=0;F<18;F++){var G=k*(.15+.75*z(F));t.globalAlpha=.35+.65*z(F+30),t.fillRect(E+S*F/18,v+k/2-G/2,S/18*.55,G)}t.globalAlpha=1}else if(N==="chat"||N==="mail"){for(var F=0;F<3;F++){var J=v+k*(.05+F*.33),Z=S*(.45+.4*z(F));t.globalAlpha=F%2?.85:.35,c(F%2&&N==="chat"?E+S-Z:E,J,Z,k*.24,k*.1),t.fill()}t.globalAlpha=1}else if(N==="map"){t.globalAlpha=.25;for(var F=1;F<5;F++)t.beginPath(),t.moveTo(E,v+k*F/5),t.lineTo(E+S,v+k*(F/5+.08)),t.stroke();t.globalAlpha=1,t.beginPath(),t.moveTo(E+S*.1,v+k*.85),t.bezierCurveTo(E+S*.4,v+k*.2,E+S*.6,v+k*.9,E+S*.88,v+k*.2),t.stroke(),t.beginPath(),t.arc(E+S*.88,v+k*.2,k*.09,0,Math.PI*2),t.fill()}else if(N==="calendar"){for(var F=0;F<14;F++)t.globalAlpha=F===9?1:.28,c(E+S*(F%7)/7,v+k*Math.floor(F/7)*.5,S/7*.82,k*.4,k*.06),t.fill();t.globalAlpha=1}else if(N==="cart"){for(var F=0;F<7;F++){var G=k*.45*(.3+.7*(F+1)/7*(.7+.3*z(F)));t.globalAlpha=.35+.08*F,t.fillRect(E+S*(.55+F*.064),v+k*.5-G,S*.04,G)}t.globalAlpha=1}else{for(var F=0;F<4;F++)t.globalAlpha=.3+.5*z(F),t.fillRect(E+S*.06*(F%2),v+k*F/4,S*(.4+.5*z(F+9)),k*.12);t.globalAlpha=1}(N==="stats"||N==="cart")&&(t.fillStyle=$,t.font="700 "+Math.round(Math.min(p*.15,k*.42))+"px "+(typeof FONTS<"u"&&FONTS.mont?FONTS.mont:"sans-serif"),t.textBaseline="alphabetic",t.fillText(e.sub||"",E,v+k*.95,S))}t.fillStyle=s,t.beginPath(),t.arc(o*.1,r*.16,p*.042,0,Math.PI*2),t.fill();var at=typeof FONTS<"u"&&FONTS.mont?FONTS.mont:"sans-serif";t.fillStyle=$,t.textBaseline="middle",t.font="700 "+Math.round(p*(i?.05:.082))+"px "+at;var D=o*.17,H=o*.78;t.fillText(e.title||"",D,r*.16,H),(e.sub&&e.icon!=="stats"&&e.icon!=="cart"||h)&&(t.fillStyle=x,t.font="500 "+Math.round(p*(i?.032:.056))+"px "+at,t.fillText(e.sub||"",D,r*.26,H)),t.restore(),c(.5,.5,o-1,r-1,l),t.lineWidth=Math.max(1,p*.008),t.strokeStyle=a==="neon"?s:"rgba(255,255,255,0.28)",t.stroke();var ut=t.createLinearGradient(0,0,0,r*.2);ut.addColorStop(0,"rgba(255,255,255,0.16)"),ut.addColorStop(1,"rgba(255,255,255,0)"),t.fillStyle=ut,c(1,1,o-2,r*.2,l),t.fill()}function U6(t,e,o,r,n){for(var a=function(y,$,x,E,v,S){t.save(),t.beginPath();var k=(E[0]+v[0]+S[0])/3,b=(E[1]+v[1]+S[1])/3,A=function(rt){var ot=rt[0]-k,G=rt[1]-b,J=Math.hypot(ot,G)||1;return[rt[0]+ot/J*.7,rt[1]+G/J*.7]},I=A(E),P=A(v),C=A(S);t.moveTo(I[0],I[1]),t.lineTo(P[0],P[1]),t.lineTo(C[0],C[1]),t.closePath(),t.clip();var z=y[0]*($[1]-x[1])+$[0]*(x[1]-y[1])+x[0]*(y[1]-$[1]);if(Math.abs(z)<1e-9){t.restore();return}var N=(E[0]*($[1]-x[1])+v[0]*(x[1]-y[1])+S[0]*(y[1]-$[1]))/z,F=(E[1]*($[1]-x[1])+v[1]*(x[1]-y[1])+S[1]*(y[1]-$[1]))/z,K=(E[0]*(x[0]-$[0])+v[0]*(y[0]-x[0])+S[0]*($[0]-y[0]))/z,_=(E[1]*(x[0]-$[0])+v[1]*(y[0]-x[0])+S[1]*($[0]-y[0]))/z,q=(E[0]*($[0]*x[1]-x[0]*$[1])+v[0]*(x[0]*y[1]-y[0]*x[1])+S[0]*(y[0]*$[1]-$[0]*y[1]))/z,U=(E[1]*($[0]*x[1]-x[0]*$[1])+v[1]*(x[0]*y[1]-y[0]*x[1])+S[1]*(y[0]*$[1]-$[0]*y[1]))/z;t.transform(N,F,K,_,q,U),t.drawImage(e,0,0),t.restore()},i=2,l=function(y,$){return[n[0][0]*(1-y)*(1-$)+n[1][0]*y*(1-$)+n[2][0]*(1-y)*$+n[3][0]*y*$,n[0][1]*(1-y)*(1-$)+n[1][1]*y*(1-$)+n[2][1]*(1-y)*$+n[3][1]*y*$]},p=0;p<i;p++)for(var c=0;c<i;c++){var s=c/i,h=(c+1)/i,f=p/i,m=(p+1)/i;a([s*o,f*r],[h*o,f*r],[s*o,m*r],l(s,f),l(h,f),l(s,m)),a([h*o,f*r],[h*o,m*r],[s*o,m*r],l(h,f),l(h,m),l(s,m))}}const Y6=`const GEO=${Pi.toString()};const CARD=${H1.toString()};
|
|
119
|
+
const CW=360,CH=248,cache=globalThis.__hudCards||(globalThis.__hudCards=new Map())
|
|
120
|
+
function cardCanvas(k,col,look){const c=HUD.cards[k],key=JSON.stringify([c,col,look]);let cv=cache.get(key);if(!cv&&typeof OffscreenCanvas!=='undefined'){cv=new OffscreenCanvas(CW,CH);CARD(cv.getContext('2d'),c,CW,CH,col,look,false);if(!c.img||M.asset(c.img))cache.set(key,cv)}return cv}
|
|
121
|
+
const CELL=${X1.toString()},cell=k=>CELL(HUD,k)
|
|
122
|
+
function render(ctx,t,env){
|
|
123
|
+
const W=env.width,H=env.height,asp=HUD.asp||W/H,p=env.params||{},col=p.color||HUD.color,look=p.look||HUD.look,P=(a,b)=>{const q=GEO(HUD,a,b,asp);return [q[0]*W,q[1]*H,q[2]]}
|
|
124
|
+
const ease=x=>1-Math.pow(1-M.clamp(x,0,1),3),grow=ease((t-.05)/.6),fade=M.clamp((env.duration-t)/.35,0,1)
|
|
125
|
+
if(grow<=0||fade<=0)return
|
|
126
|
+
ctx.globalAlpha=fade
|
|
127
|
+
// the wall's glass back plate + grid lines
|
|
128
|
+
const ring=(a0,b0,a1,b1,n)=>{const pts=[];for(let i=0;i<=n;i++)pts.push(P(a0+(a1-a0)*i/n,b0));for(let i=0;i<=n;i++)pts.push(P(a1-(a1-a0)*i/n,b1));return pts}
|
|
129
|
+
const plate=ring(-.025,-.05,1.025,1.05,24),mid=.5
|
|
130
|
+
ctx.save();ctx.beginPath();plate.forEach((q,i)=>i?ctx.lineTo(q[0],q[1]):ctx.moveTo(q[0],q[1]));ctx.closePath()
|
|
131
|
+
ctx.globalAlpha=fade*grow*.16;ctx.fillStyle=col;ctx.fill();ctx.globalAlpha=fade*grow*.55;ctx.lineWidth=1.4;ctx.strokeStyle=col;ctx.shadowColor=col;ctx.shadowBlur=14;ctx.stroke();ctx.restore()
|
|
132
|
+
ctx.save();ctx.globalAlpha=fade*grow*.12;ctx.strokeStyle=col;ctx.lineWidth=1
|
|
133
|
+
for(let r=1;r<HUD.rows;r++){ctx.beginPath();for(let i=0;i<=20;i++){const q=P(-.02+1.04*i/20,r/HUD.rows);i?ctx.lineTo(q[0],q[1]):ctx.moveTo(q[0],q[1])}ctx.stroke()}
|
|
134
|
+
ctx.restore()
|
|
135
|
+
// the side toolbar
|
|
136
|
+
if(HUD.toolbar){const a0=-.085,a1=-.045,bar=ring(a0,.12,a1,.88,4);ctx.save();ctx.beginPath();bar.forEach((q,i)=>i?ctx.lineTo(q[0],q[1]):ctx.moveTo(q[0],q[1]));ctx.closePath();ctx.globalAlpha=fade*grow*.5;ctx.fillStyle='rgba(10,16,30,0.8)';ctx.fill();ctx.globalAlpha=fade*grow;ctx.strokeStyle=col;ctx.lineWidth=1.2;ctx.stroke()
|
|
137
|
+
for(let i=0;i<6;i++){const q=P((a0+a1)/2,.2+i*.12),r=Math.max(3,(P(a1,.5)[0]-P(a0,.5)[0])*.28);ctx.beginPath();ctx.arc(q[0],q[1],r,0,Math.PI*2);ctx.globalAlpha=fade*grow*(i===0?1:.55);ctx.fillStyle=i===0?col:'rgba(234,246,255,0.7)';ctx.fill()}
|
|
138
|
+
ctx.restore()}
|
|
139
|
+
// the finger's hover point on the wall
|
|
140
|
+
let hov=null,best=.07;for(let i=0;i<FP.length;i++){const d=Math.abs(FP[i][0]-t);if(d<best){best=d;hov=FP[i]}}
|
|
141
|
+
for(let k=0;k<HUD.cards.length;k++){
|
|
142
|
+
let [a0,b0,a1,b1]=cell(k)
|
|
143
|
+
const cv=cardCanvas(k,col,look);if(!cv)continue
|
|
144
|
+
const enter=ease((t-.12-.035*k)/.45);if(enter<=0)continue
|
|
145
|
+
const held=G&&G.k===k&&t>=G.t0
|
|
146
|
+
// press: the card dips in for 0.3 s at each tap / pinch on it; glow after
|
|
147
|
+
let press=0,glow=0
|
|
148
|
+
for(const e of EV){if(e.k!==k)continue;const d=t-e.t;if(d>=0&&d<.3)press=Math.max(press,Math.sin(Math.PI*d/.3));if(d>=-.15&&d<1.2)glow=Math.max(glow,d<0?1+d/.15:1-d/1.2)}
|
|
149
|
+
if(hov&&hov[1]>=a0&&hov[1]<=a1&&hov[2]>=b0&&hov[2]<=b1)glow=Math.max(glow,.6)
|
|
150
|
+
const sc=(.82+.18*enter)*(1-.07*press),ca=(a0+a1)/2,cb=(b0+b1)/2
|
|
151
|
+
a0=ca+(a0-ca)*sc;a1=ca+(a1-ca)*sc;b0=cb+(b0-cb)*sc;b1=cb+(b1-cb)*sc
|
|
152
|
+
if(held){ // the empty slot the card was pulled out of
|
|
153
|
+
const r=ring(a0,b0,a1,b1,6);ctx.save();ctx.beginPath();r.forEach((q,i)=>i?ctx.lineTo(q[0],q[1]):ctx.moveTo(q[0],q[1]));ctx.closePath();ctx.setLineDash([6,5]);ctx.globalAlpha=fade*.7;ctx.strokeStyle=col;ctx.lineWidth=1.5;ctx.stroke();ctx.globalAlpha=fade*.08;ctx.fillStyle=col;ctx.fill();ctx.restore();continue
|
|
154
|
+
}
|
|
155
|
+
ctx.save();ctx.globalAlpha=fade*enter*(.92+.08*glow)
|
|
156
|
+
const N=5;for(let s=0;s<N;s++){
|
|
157
|
+
const u0=s/N,u1=(s+1)/N,A0=a0+(a1-a0)*u0,A1=a0+(a1-a0)*u1,tl=P(A0,b0),tr=P(A1,b0),bl=P(A0,b1),sw=CW/N
|
|
158
|
+
ctx.save();ctx.setTransform((tr[0]-tl[0])/sw,(tr[1]-tl[1])/sw,(bl[0]-tl[0])/CH,(bl[1]-tl[1])/CH,tl[0],tl[1]);ctx.drawImage(cv,u0*CW,0,sw+.6,CH,0,0,sw+.6,CH);ctx.restore()
|
|
159
|
+
}
|
|
160
|
+
if(glow>0||press>0){const r=ring(a0,b0,a1,b1,6);ctx.beginPath();r.forEach((q,i)=>i?ctx.lineTo(q[0],q[1]):ctx.moveTo(q[0],q[1]));ctx.closePath();ctx.globalCompositeOperation='lighter';ctx.globalAlpha=fade*Math.max(glow,press);ctx.strokeStyle=col;ctx.lineWidth=2.4;ctx.shadowColor=col;ctx.shadowBlur=22;ctx.stroke();ctx.globalAlpha=fade*.18*Math.max(glow,press);ctx.fillStyle=col;ctx.fill()}
|
|
161
|
+
ctx.restore()
|
|
162
|
+
}
|
|
163
|
+
// ripples where the finger touched
|
|
164
|
+
for(const e of EV){const d=t-e.t;if(d<0||d>.75)continue;const q=P(e.a,e.b),u=d/.75,r=(.012+.11*ease(u))*W*q[2]*HUD.w
|
|
165
|
+
ctx.save();ctx.globalCompositeOperation='lighter';ctx.strokeStyle=col;ctx.shadowColor=col;ctx.shadowBlur=16
|
|
166
|
+
for(let i=0;i<2;i++){const rr=r*(1-i*.35);ctx.globalAlpha=fade*(1-u)*(i?0.5:0.9);ctx.lineWidth=2.5*(1-u)+.6;ctx.beginPath();ctx.ellipse(q[0],q[1],rr,rr*.62,0,0,Math.PI*2);ctx.stroke()}
|
|
167
|
+
ctx.globalAlpha=fade*(1-u);ctx.fillStyle='#ffffff';ctx.beginPath();ctx.arc(q[0],q[1],3.5*(1-u)+1,0,Math.PI*2);ctx.fill();ctx.restore()}
|
|
168
|
+
}`,q6=`const CARD=${H1.toString()};const QUAD=${U6.toString()};
|
|
169
|
+
const CW=720,CH=496,cache=globalThis.__hudGrab||(globalThis.__hudGrab=new Map())
|
|
170
|
+
function canvasOf(w,h,hero,col,look){const key=JSON.stringify([C,w,h,hero,col,look]);let cv=cache.get(key);if(!cv&&typeof OffscreenCanvas!=='undefined'){cv=new OffscreenCanvas(w,h);CARD(cv.getContext('2d'),C,w,h,col,look,hero);if(!C.img||M.asset(C.img))cache.set(key,cv)}return cv}
|
|
171
|
+
function at(T){const p=G.path;if(!p.length)return [0,0,1];if(T<=p[0][0])return p[0].slice(1);for(let i=1;i<p.length;i++)if(T<=p[i][0]){const a=p[i-1],b=p[i],k=(T-a[0])/((b[0]-a[0])||1);return [a[1]+(b[1]-a[1])*k,a[2]+(b[2]-a[2])*k,a[3]+(b[3]-a[3])*k]}return p[p.length-1].slice(1)}
|
|
172
|
+
// the card's corners while it is held: the slot's quad carried with the pinch, standing up and coming closer as it lifts
|
|
173
|
+
function held(T,W,H){
|
|
174
|
+
const q0=G.q.map(p=>[p[0]*W,p[1]*H]),a=at(G.t0),b=at(T),dx=(b[0]-a[0])*W,dy=(b[1]-a[1])*H,depth=M.clamp(b[2]/(a[2]||1),.6,1.9)
|
|
175
|
+
const lift=1-Math.pow(1-M.clamp((T-G.t0)/.32,0,1),3),cx=(q0[0][0]+q0[1][0]+q0[2][0]+q0[3][0])/4+dx,cy=(q0[0][1]+q0[1][1]+q0[2][1]+q0[3][1])/4+dy
|
|
176
|
+
const w=(Math.hypot(q0[1][0]-q0[0][0],q0[1][1]-q0[0][1])+Math.hypot(q0[3][0]-q0[2][0],q0[3][1]-q0[2][1]))/2*(1+.16*lift)*depth,h=w*CH/CW
|
|
177
|
+
// swing: the card leans with the hand's sideways speed (3D feel)
|
|
178
|
+
const c=at(T+.05),v=M.clamp((c[0]-b[0])/.05*.06,-.22,.22)*lift,rect=[[cx-w/2,cy-h/2+v*h],[cx+w/2,cy-h/2-v*h],[cx-w/2,cy+h/2-v*h*.4],[cx+w/2,cy+h/2+v*h*.4]]
|
|
179
|
+
return q0.map((p,i)=>[p[0]+dx+(rect[i][0]-p[0]-dx)*lift,p[1]+dy+(rect[i][1]-p[1]-dy)*lift])
|
|
180
|
+
}
|
|
181
|
+
function render(ctx,t,env){
|
|
182
|
+
if(!G||t<G.t0)return
|
|
183
|
+
const W=env.width,H=env.height,p=env.params||{},col=p.color||COL,look=p.look||LOOK
|
|
184
|
+
let q,fly=0
|
|
185
|
+
if(t<G.t1)q=held(t,W,H)
|
|
186
|
+
else{const r=held(G.t1,W,H),u=M.clamp((t-G.t1)/G.fly,0,1);fly=u<.5?4*u*u*u:1-Math.pow(-2*u+2,3)/2
|
|
187
|
+
const over=1+.04*Math.sin(Math.PI*M.clamp((t-G.t1)/G.fly*1.15,0,1)),full=[[0,0],[W,0],[0,H],[W,H]].map(p=>[W/2+(p[0]-W/2)*over,H/2+(p[1]-H/2)*over])
|
|
188
|
+
q=r.map((p,i)=>[p[0]+(full[i][0]-p[0])*fly,p[1]+(full[i][1]-p[1])*fly])}
|
|
189
|
+
const card=canvasOf(CW,CH,false,col,look);if(!card)return
|
|
190
|
+
// shadow under the held card
|
|
191
|
+
if(fly<1){ctx.save();ctx.globalAlpha=.42*(1-fly);ctx.fillStyle='#000';ctx.filter='blur('+Math.round(H*.025)+'px)';ctx.beginPath();const o=H*.035;ctx.moveTo(q[0][0],q[0][1]+o);ctx.lineTo(q[1][0],q[1][1]+o);ctx.lineTo(q[3][0],q[3][1]+o);ctx.lineTo(q[2][0],q[2][1]+o);ctx.closePath();ctx.fill();ctx.restore()}
|
|
192
|
+
if(fly<1)QUAD(ctx,card,CW,CH,q)
|
|
193
|
+
if(fly>0){const hero=canvasOf(W,H,true,col,look);if(hero){ctx.save();ctx.globalAlpha=M.clamp(fly*1.6-.25,0,1);QUAD(ctx,hero,W,H,q);ctx.restore()}}
|
|
194
|
+
// light: the card's edge glows while held, streaks while it flies
|
|
195
|
+
ctx.save();ctx.globalCompositeOperation='lighter';ctx.strokeStyle=col;ctx.shadowColor=col;ctx.shadowBlur=24;ctx.lineWidth=2.4;ctx.globalAlpha=(1-fly)*.95
|
|
196
|
+
ctx.beginPath();ctx.moveTo(q[0][0],q[0][1]);ctx.lineTo(q[1][0],q[1][1]);ctx.lineTo(q[3][0],q[3][1]);ctx.lineTo(q[2][0],q[2][1]);ctx.closePath();ctx.stroke()
|
|
197
|
+
if(fly>0&&fly<1){const cx=W/2,cy=H/2;ctx.shadowBlur=0;for(let i=0;i<14;i++){const a=i*2.399,r0=Math.min(W,H)*(.15+.5*fly),r1=r0+Math.min(W,H)*.25*(1-fly);ctx.globalAlpha=(1-fly)*.5;ctx.lineWidth=1.5;ctx.beginPath();ctx.moveTo(cx+Math.cos(a)*r0,cy+Math.sin(a)*r0*.6);ctx.lineTo(cx+Math.cos(a)*r1,cy+Math.sin(a)*r1*.6);ctx.stroke()}}
|
|
198
|
+
ctx.restore()
|
|
199
|
+
}`,ra=(t,e)=>`const ${t}=${JSON.stringify(e)};`;function U1({cfg:t,events:e=[],grab:o=null,hover:r=[],assets:n}){const a=[ra("HUD",t),ra("EV",e),ra("G",o),ra("FP",r),Y6].join(`
|
|
200
|
+
`);return Jo({code:a,params:{color:t.color,look:t.look},preset:"hud-wall",...n&&Object.keys(n).length?{assets:n}:{}})}function od({card:t=null,grab:e=null,color:o=cn.color,look:r="glass",assets:n}){const a=[ra("C",t),ra("G",e),ra("COL",o),ra("LOOK",r),q6].join(`
|
|
201
|
+
`);return Jo({code:a,params:{color:o,look:r},preset:"hud-grab",...n&&Object.keys(n).length?{assets:n}:{}})}function Kd(t){const e={};for(const o of String(t?.code??"").split(`
|
|
202
|
+
`,4)){const r=/^const ([A-Z]+)=(.*);$/.exec(o);if(r)try{e[r[1]]=JSON.parse(r[2])}catch{}}return e}const Y1=t=>t?.motion?.preset==="hud-wall";function Z6({id:t,at:e,duration:o,cfg:r,assets:n,label:a}){if(!(o>=.2))throw Error("hudWall needs at least 0.2 s");return{id:t,nodeId:"",kind:"image",url:"",volume:0,start:ne(e),duration:ne(Math.min(cn.maxSeconds,o)),label:a||"Tường HUD",motionV:2,posX:0,posY:0,scale:1,motion:U1({cfg:r,assets:n})}}function rd(t,e,o,r,n,a=null){if(t.pin&&!t.pin.scene){const l=J0(t,e,o,r,n,a);if(l)return l}const i=Math.max(0,Math.min(t.duration,o-t.start));if(js(a)&&Xb(t)){const l=Hb(t,i,a,o,r,n);if(l)return l.quad}return Ub(t,i,r,n)}function nd(t){const[e,o,r,n]=t,a=o[0]-n[0],i=r[0]-n[0],l=o[1]-n[1],p=r[1]-n[1],c=e[0]-o[0]+n[0]-r[0],s=e[1]-o[1]+n[1]-r[1];let h=0,f=0;const m=a*p-i*l||1e-12;(Math.abs(c)>1e-9||Math.abs(s)>1e-9)&&(h=(c*p-i*s)/m,f=(a*s-c*l)/m);const y=o[0]-e[0]+h*o[0],$=r[0]-e[0]+f*r[0],x=e[0],E=o[1]-e[1]+h*o[1],v=r[1]-e[1]+f*r[1],S=e[1],k=(q,U)=>{const rt=h*q+f*U+1;return[(y*q+$*U+x)/rt,(E*q+v*U+S)/rt]},b=v-S*f,A=x*f-$,I=$*S-x*v,P=S*h-E,C=y-x*h,z=x*E-y*S,N=E*f-v*h,F=$*h-y*f,K=y*v-$*E;return{apply:k,inverse:(q,U)=>{const rt=N*q+F*U+K;return[(b*q+A*U+I)/rt,(P*q+C*U+z)/rt]}}}const Wl=(t,e,o,r,n,a)=>{const i=t.crop||{left:0,right:0,top:0,bottom:0},l=1-i.left-i.right||1,p=1-i.top-i.bottom||1,c=Id(t,(o[0]-i.left)/l,(o[1]-i.top)/p,r,n,a,e.mw,e.mh);return[c.px,c.py]};function $i(t,e,o,{point:r="index",side:n="any",W:a=1280,H:i=720}={}){const l=o-t.start,p=hc(t,l),c=F5(e,p,n),s=fc(e,p,c);if(!s)return null;const h=Wl(t,e,bi(s,r),l,a,i),f=Wl(t,e,s[9],l,a,i),m=Wl(t,e,s[0],l,a,i);return{x:h[0],y:h[1],size:Math.hypot(f[0]-m[0],f[1]-m[1]),slot:c}}const q1=1/15;function J6(t,e,{point:o="index",side:r="any",scale:n=!1,offset:a=null,W:i=1280,H:l=720}={}){if(!e?.hands)throw Error("The footage has no hand track yet");const p=Vs(e.hands),c=Math.max(t.start,e.start),s=Math.min(t.start+t.duration,e.start+e.duration);if(!(s-c>=1/30))throw Error("The layer and the footage do not play at the same time");const h=Math.max(1,Math.min(ze.maxFrames,Math.ceil((s-c)/q1))),f=[];for(let k=0;k<=h;k++){const b=c+(s-c)*k/h,A=$i(e,p,b,{point:o,side:r,W:i,H:l});A&&f.push({T:b,...A})}if(!f.length)throw Error("No hand is seen while the layer plays");const m={...t,...Zr(t)},y=f[0],$=k=>ne(k-t.start),x=Array.isArray(a)?Number(a[0])||0:Ut(m,"x",y.T-t.start)-(y.x-i/2)/i,E=Array.isArray(a)?Number(a[1])||0:Ut(m,"y",y.T-t.start)-(y.y-l/2)/l,v=Ut(m,"zoom",y.T-t.start)||1;let S={...m,motionV:2};return delete S.posX,delete S.posY,S={...S,...de(S,"x",f.map(k=>({time:$(k.T),value:ne((k.x-i/2)/i+x)})))},S={...S,...de(S,"y",f.map(k=>({time:$(k.T),value:ne((k.y-l/2)/l+E)})))},n&&(S={...S,...de(S,"zoom",f.map(k=>({time:$(k.T),value:ne(Math.max(.05,v*k.size/(y.size||1)))})))}),{motionV:2,motionKeys:S.motionKeys,posX:void 0,posY:void 0}}function Fm(t,{until:e=1/0}={}){const o=Vs(t.hands),r=t.crop||{left:0,right:0,top:0,bottom:0},n=1-r.left-r.right||1,a=1-r.top-r.bottom||1,i=Math.max(1,Math.ceil(o.n/600)),l=[];for(let p=0;p<ze.slots;p++){const c=[];let s=null,h=null,f=null;for(let y=0;y<o.n;y+=i){const $=ne(h1(t,o.s0+y/o.fps));if($<0||$>t.duration+.001)continue;const x=o.frames[y][p];let E;if(x)E=D5(x.lm,o.mw,o.mh,{edge:x.edge}).map(([v,S])=>[ne(Math.max(-.95,Math.min(1.95,(v-r.left)/n))),ne(Math.max(-.95,Math.min(1.95,(S-r.top)/a)))]),s===null&&(s=$),h=$,f=E;else{const v=f?f.reduce((S,k)=>[S[0]+k[0]/f.length,S[1]+k[1]/f.length],[0,0]):[.5,.5];E=Array.from({length:Xr},()=>[ne(v[0]),ne(v[1])])}c.length&&c.at(-1).t>=$||c.push({t:$,pts:E})}if(s===null)continue;const m=Math.min(h+1/o.fps,e);m<=s||l.push({id:`h${p+1}`,name:p?"Tay trái":"Tay phải",mode:"add",keys:c,feather:.0035,in:ne(s),out:ne(Math.min(t.duration,m))})}return l.length?{v:2,mw:o.mw,mh:o.mh,masks:l}:null}const ad=(t=1280,e=720)=>({v:2,mw:t,mh:e,masks:[{id:"h1",name:"Tay phải",mode:"add",keys:[{t:0,pts:[[0,0],[0,0],[0,0]]}]}]});function Q6({wall:t,layer:e,src:o,clips:r,cam:n=null,W:a=1280,H:i=720,events:l=null,grab:p="auto",side:c="any",fly:s=.7}){if(!Y1(t))throw Error("hudInteract needs a HUD wall layer (hudWall)");const h=Kd(t.motion),f=h.HUD;if(!f)throw Error("The HUD wall has no settings");const m=o.hands?Vs(o.hands):null,y=f.asp||a/i,$=Es(s,...cn.fly,.7),x=Math.max(t.start,o.start,e.start),E=Math.min(t.start+t.duration,o.start+o.duration,e.start+e.duration),v=(U,rt,ot)=>{const G=nd(rd(t,r,ot,a,i,n)),[J,Z]=G.inverse(U,rt);return W6(f,J,Z,y)},S=(U,rt,ot)=>{const G=nd(rd(t,r,ot,a,i,n)),J=Pi(f,U,rt,y),[Z,at]=G.apply(J[0],J[1]);return[Z/a,at/i]};let k;if(Array.isArray(l)&&l.length)k=l.map(U=>{const rt=Number(U.t);if(!Number.isFinite(rt)||!["tap","pinch","release"].includes(U.type))throw Error("hudInteract events: [{t (timeline s), type tap | pinch | release, point? [x, y]}]");let ot,G;if(Array.isArray(U.point)&&U.point.length===2&&U.point.every(Number.isFinite))ot=U.point[0]*a,G=U.point[1]*i;else{const J=m&&$i(o,m,rt,{point:U.type==="tap"?"index":"pinch",side:c,W:a,H:i});if(!J)throw Error(`hudInteract event at ${rt}s: give point [x, y] (no hand seen there)`);ot=J.x,G=J.y}return{type:U.type,T:rt,x:ot,y:G}}).sort((U,rt)=>U.T-rt.T);else{if(!m)throw Error("The footage has no hand track yet");const U=rt=>c==="any"||(c==="right"?rt===0:rt===1);k=R5(m).filter(rt=>U(rt.slot)).map(rt=>{const ot=h1(o,rt.s),G=o.start+ot,[J,Z]=Wl(o,m,[rt.u,rt.v],ot,a,i);return{type:rt.type,T:G,x:J,y:Z,slot:rt.slot}})}k=k.filter(U=>U.T>=x-1e-6&&U.T<=E+1e-6);const b=[],A={taps:0,pinches:0,grabbed:null};let I=null,P=null;const C=U=>U.slot===1?"left":U.slot===0?"right":c,z=U=>{const rt=k[U],ot=k.slice(U+1).find(G=>G.type==="release"&&(G.slot===void 0||G.slot===rt.slot));return Math.min(E-.05,ot?ot.T:E-$)};let N=-1,F=-1/0;p!==!1&&k.forEach((U,rt)=>{if(U.type!=="pinch"||U.T<t.start+.6)return;const[ot,G]=v(U.x,U.y,U.T),J=Nm(f,ot,G,.25),Z=z(rt);if(J<0&&!Number.isInteger(p)||Z-U.T<.3||E-Z<Math.min(.5,$))return;const at=m&&$i(o,m,Z,{point:"pinch",side:C(U),W:a,H:i}),D=at?Math.hypot(at.x-U.x,at.y-U.y)/a:0,H=Math.min(1.5,Z-U.T)+3*D;H>F&&(F=H,N=rt)});for(let U=0;U<k.length;U++){const rt=k[U];if(rt.type==="release")continue;const[ot,G]=v(rt.x,rt.y,rt.T);let J=Nm(f,ot,G,rt.type==="pinch"?.25:0);const Z=ne(rt.T-t.start);if(U===N){Number.isInteger(p)&&(J=Math.max(0,Math.min(f.cards.length-1,p)));const at=z(U),[D,H,ut,gt]=X1(f,J),xt=[[D,H],[ut,H],[D,gt],[ut,gt]].map(([V,d])=>S(V,d,rt.T).map(ne)),u=[],st=Math.max(2,Math.ceil((at+.15-rt.T)*30));for(let V=0;V<=st;V++){const d=rt.T+(at+.15-rt.T)*V/st,w=m&&$i(o,m,d,{point:"pinch",side:C(rt),W:a,H:i});w&&u.push([ne(d-e.start),ne(w.x/a),ne(w.y/i),ne(w.size/a)])}u.length||u.push([ne(rt.T-e.start),ne(rt.x/a),ne(rt.y/i),1]),I={k:J,t0:ne(rt.T-e.start),t1:ne(at-e.start),fly:Vl($),q:xt,path:u},P=od({card:f.cards[J],grab:I,color:t.motion.params?.color??f.color,look:t.motion.params?.look??f.look,assets:t.motion.assets}),b.push({k:J,t:Z,a:ne(ot),b:ne(G)}),A.pinches++,A.grabbed=J;continue}rt.T<t.start+.35||ot<-.05||ot>1.05||G<-.05||G>1.05||(b.push({k:J,t:Z,a:ne(ot),b:ne(G)}),rt.type==="tap"?A.taps++:A.pinches++)}if(I)for(let U=b.length-1;U>=0;U--)b[U].k===I.k&&b[U].t>I.t0+e.start-t.start+1e-6&&b.splice(U,1);const K=[];if(m)for(let U=x;U<=E;U+=1/15){const rt=$i(o,m,U,{point:"index",side:c,W:a,H:i});if(!rt)continue;const[ot,G]=v(rt.x,rt.y,U);if(!(ot<0||ot>1||G<0||G>1)&&(K.push([ne(U-t.start),Vl(ot),Vl(G)]),K.length>=300))break}const _=U1({cfg:f,events:b,grab:I?{k:I.k,t0:ne(I.t0+e.start-t.start)}:null,hover:K,assets:t.motion.assets});_.params={..._.params,...t.motion.params??{}},P||(P=od({card:null,grab:null,color:t.motion.params?.color??f.color,look:t.motion.params?.look??f.look}));const q=I?ne(I.t1+e.start+$*.55-o.start):1/0;return{wall:_,grab:P,cutoutUntil:q,report:A}}function Rm(t){const e=t.point??"index",o=t.hand??"any";if(!uc.includes(e))throw Error(`handAttach point: ${uc.join(" | ")}`);if(!Du.includes(o))throw Error(`hand: ${Du.join(" | ")}`);return{point:e,side:o}}const Sa=Object.freeze({dx:.01,dy:.035,opacity:.3,blur:.65,feather:.025});function tE(t,e,o,{cam:r=null,W:n=1280,H:a=720}={}){const i=Kd(t.motion).HUD,l=i.asp||n/a,p=e.hands?.mw??n,c=e.hands?.mh??a,s=Math.max(t.start,e.start),h=Math.min(t.start+t.duration,e.start+e.duration);let f=1/0,m=1/0,y=-1/0,$=-1/0;for(const E of[s,(s+h)/2,h-.001]){const v=nd(rd(t,o,E,n,a,r));for(const[S,k]of[[-.02,-.04],[1.02,-.04],[-.02,1.04],[1.02,1.04],[.5,-.04],[.5,1.04]]){const b=Pi(i,S,k,l),[A,I]=v.apply(b[0],b[1]),P=fg(e,A,I,E-e.start,n,a,p,c);f=Math.min(f,P.u),y=Math.max(y,P.u),m=Math.min(m,P.v),$=Math.max($,P.v)}}const x=E=>ne(Math.max(-.95,Math.min(1.95,E)));return{id:"wall",name:"Màn hình HUD",mode:"add",feather:Sa.feather,keys:[{t:0,pts:[[x(f),x(m)],[x(y),x(m)],[x(y),x($)],[x(f),x($)]]}]}}function eE(t,{id:e,wallMask:o,mw:r=1280,mh:n=720}){const{mask:a,person:i,...l}=t,p={...l,id:e,label:`${t.label?.replace(/ · tay$/,"")||"Video"} · bóng tay`,volume:0,hud:{...t.hud,role:"shadow"},brightness:0,opacity:Sa.opacity,effects:[{type:"blur",amount:Sa.blur}]};return Array.isArray(l.motionKeys)&&l.motionKeys.some(s=>Number.isFinite(s.x)||Number.isFinite(s.y))?p.motionKeys=l.motionKeys.map(s=>({...s,...Number.isFinite(s.x)?{x:ne(s.x+Sa.dx)}:{},...Number.isFinite(s.y)?{y:ne(s.y+Sa.dy)}:{}})):(p.posX=ne((l.posX||0)+Sa.dx),p.posY=ne((l.posY||0)+Sa.dy)),p.mask=i?{v:2,mw:r,mh:n,masks:[o]}:{v:2,mw:r,mh:n,masks:[{...ad(r,n).masks[0]},{...o,mode:"intersect"}]},i&&(p.person=i),p}const mo=Object.freeze({presets:["down","left","right","push-left","push-right","rush"],defaults:{down:.2,left:.22,right:.22,"push-left":1,"push-right":1,rush:1.2},minAmount:.05,maxAmount:.4,ramp:.4,push:.35,rush:{min:.3,max:1.6},minDuration:1,maxDuration:12}),Dm=mo.presets,Ac=1/30,Vp=.4,gl=(t,e,o)=>Math.max(e,Math.min(o,t)),oE=t=>+t.toFixed(4);function rE(t,e,o,r,n){const a=[];if(r==="rush")a.push({time:t,d:0,ease:"expo-in"},{time:e,d:n,ease:"hold"}),e+Ac*2<o&&a.push({time:ht(e+Ac*2),d:0});else if(r.startsWith("push")){const l=r==="push-left"?-1:1,p=Math.min(mo.push,(e-t)/3);a.push({time:t,d:0,ease:"expo-in"},{time:ht(t+p),d:l,ease:"hold"}),e>=o-1e-6?a.push({time:o,d:l}):a.push({time:ht(e-p),d:-l,ease:"expo-out"},{time:e,d:0})}else{const l=r==="down"||r==="right"?1:-1,p=Math.min(mo.ramp,(e-t)/3);a.push({time:t,d:0,ease:"expo-out"},{time:ht(t+p),d:l*n}),e>=o-1e-6?a.push({time:o,d:l*n}):a.push({time:ht(e-p),d:l*n,ease:"ease-in-out"},{time:e,d:0})}const i=[];for(const l of a)(!i.length||l.time>i.at(-1).time+1e-6)&&i.push(l);return i}function nE(t,{at:e,duration:o,preset:r="down",amount:n}={}){if(t.kind==="audio"||t.kind==="model"||t.title||t.shape||t.motion)throw Error("Make room needs a video or image clip");if(!mo.presets.includes(r))throw Error(`Make room preset must be ${mo.presets.join("/")}`);if(!Number.isFinite(e)||e<0||e>=t.duration-Ac)throw Error("Make room must start inside the clip");const a=r==="rush",i=gl(Number.isFinite(o)?o:3,a?.3:mo.minDuration,mo.maxDuration),l=a?gl(Number.isFinite(n)?n:mo.defaults.rush,mo.rush.min,mo.rush.max):gl(Number.isFinite(n)?n:mo.defaults[r],mo.minAmount,mo.maxAmount),p=ht(e);let c=ht(Math.min(t.duration,p+i));if(t.duration-c<Ac&&(c=t.duration),c-p<(a?.3:mo.minDuration)-1e-6&&c<t.duration)throw Error("Make room is too short for the clip");const s=a?"zoom":r==="down"?"y":"x",h=rE(p,c,t.duration,r,l),f=h[0].time,m=h.at(-1).time,y=Me(t,s).some(P=>P.time>f+.001&&P.time<m-.001),$=[...h];if(y)for(let P=f+Vp;P<m-Vp/2;P+=Vp){const C=ht(P);if(!$.some(z=>Math.abs(z.time-C)<.001)){const z=$.findIndex(K=>K.time>C),N=$[z-1],F=$[z];$.splice(z,0,{time:C,d:N.ease==="hold"?N.d:N.d+(F.d-N.d)*(C-N.time)/(F.time-N.time)})}}const x=Me(t,s).filter(P=>P.time<f-.001||P.time>m+.001),E=$.map(P=>({time:P.time,value:oE(a?Math.min(qi,Ut(t,s,P.time)*(1+P.d)):gl(Ut(t,s,P.time)+P.d,-1,1)),...P.ease?{ease:Jt[P.ease]}:{}})),v={...t,...de(t,s,[...x,...E].sort((P,C)=>P.time-C.time))};hn(v);const{motionV:S,motionKeys:k,posX:b,posY:A,scale:I}=v;return{motionV:S,motionKeys:k,...b!==void 0?{posX:b,posY:A,scale:I}:{}}}const rr=Object.freeze({grow:.5,zoom:3,lead:.1,minCard:1.5,minScene:1.5,sceneIn:.35,centre:{portrait:{prop:"y",off:.5-.27},landscape:{prop:"x",off:.5-.72}}}),tr=t=>+t.toFixed(3),aE=t=>Math.max(-1,Math.min(1,t)),Bm=(t={})=>{const e={};return t.text&&(e.text=String(t.text).slice(0,60)),t.sub&&(e.subText=String(t.sub).slice(0,60)),Array.isArray(t.items)&&t.items.length&&(e.items=t.items.map(o=>String(o).slice(0,48)).slice(0,5)),Number.isFinite(+t.number)&&t.number!==null&&t.number!==""&&(e.numberValue=+t.number),e};function iE({speakerClipId:t,portrait:e=!0,at:o,handoff:r,end:n,card:a,scene:i,rows:l=0,base:p=0}={}){if(!t||!a?.preset||!i?.preset)throw Error("A bridge needs the speaker clip, a card and a scene");if(o=+o,r=Math.max(+r,o+rr.minCard),n=Math.max(+n,r+rr.grow+rr.minScene),!Number.isFinite(o)||o<0||!Number.isFinite(n))throw Error("Bridge times must be timeline seconds");const c=v=>In(l+v),s=e?rr.centre.portrait:rr.centre.landscape,h=rr.zoom,f=tr(Math.max(0,o-rr.lead)),m=tr(r+rr.grow),y=tr(r+rr.grow*.6),$=tr(y+rr.sceneIn+.05),x=Math.min(mo.maxDuration,tr($+mo.ramp+.2-f)),E=v=>`new:${p+v}`;return[{op:"makeRoom",clipId:t,at:f,duration:x,preset:e?"down":"left"},{op:"addMotion",motionPreset:"exp-room-panel",start:f,duration:tr($-f),track:c(0),placement:"top"},{op:"addMotion",motionPreset:a.preset,start:tr(o),duration:tr($-o),track:c(1),placement:"top",...Bm(a)},{op:"setPropertyKeys",clipId:E(2),property:"zoom",propertyKeys:[{time:tr(r-o),value:1,ease:"ease-in"},{time:tr(m-o),value:h}]},{op:"setPropertyKeys",clipId:E(2),property:s.prop,propertyKeys:[{time:tr(r-o),value:0,ease:"ease-in"},{time:tr(m-o),value:tr(aE(s.off*h))}]},{op:"addMotion",motionPreset:i.preset,start:y,duration:tr(n-y),track:c(2),placement:"center",...Bm(i)},{op:"setAnimation",clipId:E(3),property:"enter",preset:"zoom-in",duration:rr.sceneIn,numberValue:.35}]}const Z1={slab:"bridge-slab",iris:"bridge-iris",flash:"bridge-flash",whip:"bridge-whip",ink:"bridge-ink",stripes:"bridge-stripes",shapes:"bridge-shapes",glitch:"bridge-glitch",tunnel:"bridge-tunnel"},_m=Object.freeze(["zoom-through","push","match-zoom",...Object.keys(Z1)]),sE={flash:.8,whip:.8,glitch:.8,slab:1,iris:1,stripes:1,ink:1.2,shapes:1.2,tunnel:1.2},ya=t=>+(+t).toFixed(3),Gm=t=>{const e={};for(const o of["text","subText","items","numberValue","style","color"])t[o]!==void 0&&t[o]!==null&&(e[o]=t[o]);return e},Cc=t=>/^(add|lockup$)/.test(t?.op??"");function lE(t,{portrait:e=!1,rows:o=1,base:r=0}={}){const n=t.preset,a=+t.at,i=Math.max(1,+t.duration||4),l=t.booleanValue!==!1,p=t.fromClipId;if(!_m.includes(n))throw Error(`Bridge kind must be ${_m.join("/")}`);if(!Number.isFinite(a)||a<0)throw Error("Bridge needs at (timeline seconds of the cut)");if(!p)throw Error("Bridge needs fromClipId (the shot it leaves)");if(!t.motionPreset&&!t.clipId)throw Error("Bridge needs the scene (motionPreset) or the clip it joins to (clipId)");const c=x=>In(o+x),s=x=>`new:${r+x}`,h=ya(a+i),f=[],m=(x,E,v)=>t.clipId?t.clipId:(f.push({op:"addMotion",motionPreset:t.motionPreset,start:ya(x),duration:ya(E),track:v,placement:"center",...Gm(t)}),s(f.filter(Cc).length));if(n==="zoom-through"){if(t.clipId)throw Error("zoom-through grows into a new scene: give motionPreset, not clipId");const x=Math.max(rr.minCard,a-rr.grow*.6),E=iE({speakerClipId:p,portrait:e,at:Math.max(0,x-rr.minCard),handoff:x,end:h,rows:o,base:r,card:{preset:"bridge-portal",text:t.text},scene:{preset:t.motionPreset,text:t.text,sub:t.subText,items:t.items,number:t.numberValue}});if(f.push(...E.map(v=>v.op==="addMotion"&&v.motionPreset===t.motionPreset?{...v,...Gm(t)}:v)),l){const v=f.filter(Cc).length;f.push({op:"setAnimation",clipId:s(v),property:"exit",preset:"zoom-out",duration:.4,numberValue:.3})}return f}if(n==="push"){const x=mo.push;f.push({op:"makeRoom",clipId:p,at:ya(Math.max(0,a-x*.5)),duration:ya(Math.min(mo.maxDuration,i+x)),preset:"push-left"});const E=m(a-x*.5,i+x*.5,c(0));return f.push({op:"setAnimation",clipId:E,property:"enter",preset:"slide-left",duration:x,numberValue:1,booleanValue:!1}),l&&f.push({op:"setAnimation",clipId:E,property:"exit",preset:"slide-left",duration:x,numberValue:1,booleanValue:!1}),f}if(n==="match-zoom"){const x=.4666666666666667;f.push({op:"makeRoom",clipId:p,at:Math.max(0,Math.round((a-x)*30)/30),duration:x,preset:"rush"});const E=m(a,i,c(0));return f.push({op:"setAnimation",clipId:E,property:"enter",preset:"zoom-out",duration:.45,numberValue:.45,booleanValue:!1}),l&&f.push({op:"setAnimation",clipId:E,property:"exit",preset:"zoom-in",duration:.35,numberValue:.4,booleanValue:!1}),f}const y=sE[n],$=Z1[n];return m(a,i,c(0)),f.push({op:"addMotion",motionPreset:$,start:ya(Math.max(0,a-y/2)),duration:y,track:c(1),...t.color?{color:t.color}:{}}),l&&f.push({op:"addMotion",motionPreset:$,start:ya(Math.max(0,h-y/2)),duration:y,track:c(1),...t.color?{color:t.color}:{}}),f}function cE(t,{portrait:e=!1}={}){if(!t.some(l=>l?.op==="bridge"))return t;const o=[],r=[];let n=0,a=0;const i=l=>{const p=s=>{const h=typeof s=="string"&&/^new:(\d+)$/.exec(s);if(!h)return s;const f=+h[1];let m=0;for(const y of r)f>y.after&&(m+=y.by);return`new:${f+m}`},c={...l};return c.clipId&&(c.clipId=p(c.clipId)),c.fromClipId&&(c.fromClipId=p(c.fromClipId)),c.sourceClipId&&(c.sourceClipId=p(c.sourceClipId)),Array.isArray(c.clipIds)&&(c.clipIds=c.clipIds.map(p)),c};for(const l of t){const p=i(l);if(p?.op!=="bridge"){o.push(p),Cc(p)&&(n++,a++);continue}const c=lE(p,{portrait:e,base:n}),s=c.filter(Cc).length;o.push(...c),s&&r.push({after:a,by:s}),n+=s}return o}const J1=Object.freeze({"fly-truck":{label:"Bay ngang",at:(t,e)=>[t*e,0,0]},"fly-rise":{label:"Bay lên",at:(t,e)=>[0,-t*e,0]},"fly-zigzag":{label:"Zigzag",at:(t,e)=>[t*e,t%2?-.55*e:0,0]},"fly-dive":{label:"Bay xuyên sâu",at:(t,e)=>[0,0,-t*e*5]}}),_C=Object.keys(J1),Km=8,pE=.25,na=t=>Math.round(t*1e3)/1e3,id=(t,e)=>Math.max(Tr[t].min,Math.min(Tr[t].max,e));function uE(t,e,o){const r=a=>a.map(i=>t.find(l=>l.id===i)).filter(i=>i&&i.kind!=="audio");return(o?.length?o.map(r).filter(a=>a.length):r(e).sort((a,i)=>a.start-i.start).reduce((a,i)=>{const l=a.at(-1);return l&&i.start-l[0].start<pE?l.push(i):a.push([i]),a},[])).map(a=>({clips:a,time:Math.min(...a.map(i=>i.start))})).sort((a,i)=>a.time-i.time)}function dE(t,e,o){if(!o)return{};const r=Me(t,e);return r.length?de(t,e,r.map(n=>({...n,value:na(id(e,n.value+o))}))):Hc(t,e,na(id(e,Ut(t,e,0)+o)),0)}function hE(t,e,o,{style:r="fly-truck",travel:n=1,spacing:a=1.2,swing:i=!0,push:l=!0,groups:p}={}){const c=J1[r];if(!c)throw Error(`Unknown stations style "${r}"`);if(!(n>=.2&&n<=5))throw Error("Flight time must be 0.2–5 s");if(!(a>=.5&&a<=3))throw Error("Station spacing must be 0.5–3");const s=uE(t,e,p);if(s.length<2)throw Error("Cần ít nhất 2 trạm: các layer của mỗi trạm bắt đầu cùng lúc, trạm sau bắt đầu muộn hơn");if(s.length>Km)throw Error(`At most ${Km} stations`);const h=s.length,f=s.map((C,z)=>c.at(z,a));if(f.some(C=>Math.abs(C[0])>Tr.x.max||Math.abs(C[1])>Tr.y.max||C[2]<Sd+5))throw Error("Too many stations for this spacing — lower the spacing");const m={},y=[],$=new Set(s.flatMap(C=>C.clips.map(z=>z.id)));s.forEach((C,z)=>{const N=(Z,at)=>at?Math.round(Z.reduce((D,H)=>D+H,0)/Z.length/at)*at:0,F=C.clips.filter(Z=>!Z.parentId||!$.has(Z.parentId));if(!F.length)return;const[K,_,q]=f[z],U=c.at(1,a)[0]||0,rt=c.at(1,a)[1]||c.at(2,a)[1]||0,ot=c.at(1,a)[2]||0,G=[N(F.map(Z=>Ut(Z,"x",0)),U),N(F.map(Z=>Ut(Z,"y",0)),Math.abs(rt)),N(F.map(Z=>Ut(Z,"depth",0)),Math.abs(ot))];for(const Z of F){let at={...Z,is3D:!0},D={is3D:!0};for(const[H,ut]of[[0,"x"],[1,"y"],[2,"depth"]]){const gt=na([K,_,q][H]-G[H]),xt=dE(at,ut,gt);at={...at,...xt},D={...D,...xt}}m[Z.id]=D}const J=z<h-1?s[z+1].time+n:null;if(J!=null)for(const Z of C.clips)Z.kind!=="video"&&Z.start+Z.duration<J&&(m[Z.id]={...m[Z.id],duration:na(J-Z.start)},y.push(Z.id))});const x=Jt["expo-in-out"],E=Jt.linear,v=s[0].time,S=s.at(-1).time+n;let k={...o??{...Ar},enabled:!0,motionV:2,motionKeys:o?.motionKeys??[]};const b=Gs(k,"roll",v),A=C=>({cx:f[C][0],cy:f[C][1],cz:-5-f[C][2]}),I={cx:[],cy:[],cz:[],roll:[]},P=(C,z,N,F)=>I[C].push({time:na(z),value:na(Math.max(Ln[C].min,Math.min(Ln[C].max,N))),...F?{ease:F}:{}});if(s.forEach((C,z)=>{const N=A(z),F=z?C.time+n:v,K=z<h-1?s[z+1].time:null;for(const _ of["cx","cy","cz"])P(_,F,N[_],l&&_==="cz"?E:x);if(K!=null&&K-F>.3){const _=l?Math.min(.35,(K-F)*.12):0;for(const q of["cx","cy"])P(q,K,N[q],x);P("cz",K,N.cz+_,x)}}),i){const C=(N,F)=>Math.sign(F[0]-N[0]||F[1]-N[1]||1),z=Jt["sine-in-out"];P("roll",v,b),s.forEach((N,F)=>{if(!F)return;const K=C(f[F-1],f[F]);P("roll",N.time,b,z),P("roll",N.time+n/2,b-6*K,z),P("roll",N.time+n,b)})}for(const[C,z]of Object.entries(I)){if(!z.length)continue;const F=[...Bi(k,C).filter(K=>K.time<v-1e-6||K.time>S+1e-6),...z].sort((K,_)=>K.time-_.time).filter((K,_,q)=>!_||Math.abs(K.time-q[_-1].time)>1/120);k=un(k,C,F)}return{patches:m,camera:jr(k),stations:h,extended:y}}function fE(t,e,{strength:o=1}={}){if(!(o>=.25&&o<=3))throw Error("Parallax strength must be 0.25–3");const r=t.filter(c=>e.includes(c.id)&&c.kind!=="audio");if(r.length<2)throw Error("Chọn ít nhất 2 layer để tách lớp parallax");const n=mg(r,()=>0),a=n.length,i=Math.min(3,1.2*o),l=Math.max(Sd+1,-6*o),p={};return n.forEach((c,s)=>{const h=na(l+(i-l)*s/(a-1)),f=Ut(c,"depth",0),m=(5-h)/(5-Math.min(4.5,f));let y={...c,is3D:!0},$={is3D:!0};for(const x of["depth","zoom","x","y"]){const E=k=>na(id(x,x==="depth"?k+h-f:k*m)),v=Me(y,x),S=v.length?de(y,x,v.map(k=>({...k,value:E(k.value)}))):Hc(y,x,E(Ut(y,x,0)),0);y={...y,...S},$={...$,...S}}p[c.id]=$}),p}const Q1=Object.freeze({wall:{label:"Tường ảnh"},arc:{label:"Vòng cung"},fan:{label:"Xoè bài"},scatter:{label:"Tung rải"},stack:{label:"Xếp chồng"},boards:{label:"Bảng nghiêng"}}),GC=Object.keys(Q1),Vm=48,mE=["x","y","depth","zoom","rot","tiltX","tiltY"],Oo=t=>Math.round(t*1e3)/1e3,Fa=t=>t*Math.PI/180,zi=t=>t*180/Math.PI,Wm=(t,e)=>Math.max(Tr[t].min,Math.min(Tr[t].max,e));function gE(t){let e=2166136261;for(const o of String(t))e^=o.charCodeAt(0),e=Math.imul(e,16777619);return()=>{e+=1831565813;let o=e;return o=Math.imul(o^o>>>15,o|1),o^=o+Math.imul(o^o>>>7,o|61),((o^o>>>14)>>>0)/4294967296}}function yE(t,e,{rot:o=0,tiltX:r=0,tiltY:n=0}){const a=Fa(o),i=Fa(r),l=Fa(n),p=t*Math.cos(a)-e*Math.sin(a),c=t*Math.sin(a)+e*Math.cos(a),s=c*Math.cos(i),h=-c*Math.sin(i);return[p*Math.cos(l)-h*Math.sin(l),s,p*Math.sin(l)+h*Math.cos(l)]}function bE(t,e,{W:o=1280,H:r=720,spread:n=1,ids:a=[]}={}){const i=Cr(o,r),l=[],p=([c,s,h],f)=>({x:c/o,y:s/r,depth:-h/i,...f});if(e==="wall"){const c=Math.max(1,Math.min(t,Math.ceil(Math.sqrt(t*1.4)))),s=Math.ceil(t/c),h=.1*n,f=Math.min(.6,1.6/(c*(1+h))),m={rot:-8,tiltX:26,tiltY:-20};for(let y=0;y<t;y++){const $=y%c,x=Math.floor(y/c);l.push(p(yE(($-(c-1)/2)*o*f*(1+h),(x-(s-1)/2)*r*f*(1+h),m),{zoom:f,...m}))}}else if(e==="arc"){const c=Math.min(.75,2.4/t),s=o*c*(1+.012*n),h=4.2*i/Math.max(.5,n),f=s/h;for(let m=0;m<t;m++){const y=(m-(t-1)/2)*f;l.push(p([h*Math.sin(y),0,h*(Math.cos(y)-1)],{zoom:c,rot:0,tiltX:0,tiltY:-zi(y)}))}}else if(e==="fan"){const s=Math.min(14,70/Math.max(1,t-1))*n,h=r*.42*1.15;for(let f=0;f<t;f++){const m=(f-(t-1)/2)*s,y=Fa(m);l.push(p([h*Math.sin(y),r*.12+h*(1-Math.cos(y)),-f*.04*i],{zoom:.42,rot:m,tiltX:0,tiltY:0}))}}else if(e==="scatter")for(let s=0;s<t;s++){const h=gE(a[s]??s),f=Math.min(2,n);l.push({x:(h()-.5)*.9*f,y:(h()-.5)*.7*f,depth:-3.5*h()*f+1.2,zoom:.32,rot:(h()-.5)*50,tiltX:(h()-.5)*70,tiltY:(h()-.5)*80})}else if(e==="stack")for(let c=0;c<t;c++)l.push({x:.05*c*n,y:-.035*c*n,depth:-1.4*c*n,zoom:1,rot:c%2?-2:2,tiltX:0,tiltY:-10});else if(e==="boards")for(let c=0;c<t;c++){const s=c%2?1:-1;l.push({x:1.25*c*n,y:s*.12*n,depth:-2.2*c*n,zoom:1,rot:s*-3,tiltX:s*-6,tiltY:s*28})}else throw Error(`Unknown 3D layout "${e}"`);return l}function ty(t,e,o,{W:r=1280,H:n=720,spread:a=1}={}){if(!Q1[o])throw Error(`Unknown 3D layout "${o}"`);if(!(a>=.5&&a<=2))throw Error("Layout spread must be 0.5–2");const i=new Map(t.map(s=>[s.id,s]));let l=e.map(s=>i.get(s)).filter(s=>s&&s.kind!=="audio");if(l.length<2)throw Error("Chọn ít nhất 2 layer để sắp xếp 3D");if(l.length>Vm)throw Error(`At most ${Vm} layers`);o==="stack"&&(l=mg(l,()=>0).reverse());const p=bE(l.length,o,{W:r,H:n,spread:a,ids:l.map(s=>s.id)}),c={};return l.forEach((s,h)=>{let f={...s,is3D:!0},m={is3D:!0};for(const y of mE){const $=Oo(Wm(y,p[h][y])),x=Me(f,y),E=x.length?de(f,y,x.map(v=>({...v,value:Oo(Wm(y,v.value+$-x[0].value))}))):Hc(f,y,$,0);f={...f,...E},m={...m,...E}}c[s.id]=m}),c}function Xm(t,e,o,r,{margin:n=1}={}){const a=Cr(o,r),{center:i,corners:[l,p,c]}=Pl(t,e,o,r),s=(N,F)=>N.map((K,_)=>K-F[_]),h=N=>Math.hypot(...N),f=N=>{const F=h(N)||1;return N.map(K=>K/F)},m=s(p,l),y=s(c,l),$=h(m);if(!($>1))throw Error("Layer này quá nhỏ để camera nhìn vào");const x=f([m[1]*y[2]-m[2]*y[1],m[2]*y[0]-m[0]*y[2],m[0]*y[1]-m[1]*y[0]]),E=5*a*$/o*n,v=i.map((N,F)=>N-x[F]*E),S=zi(Math.asin(Math.max(-1,Math.min(1,-x[1])))),k=zi(Math.atan2(x[0],x[2])),b=Fa(k),A=Fa(S),I=[Math.cos(b),0,-Math.sin(b)],P=[Math.sin(b)*Math.sin(A),Math.cos(A),Math.cos(b)*Math.sin(A)],C=f(m),z=zi(Math.atan2(C[0]*P[0]+C[1]*P[1]+C[2]*P[2],C[0]*I[0]+C[1]*I[1]+C[2]*I[2]));return{cx:v[0]/o,cy:v[1]/r,cz:v[2]/a,pan:k,tilt:S,roll:z}}const wE=(t,e)=>e==null?t:t+360*Math.round((e-t)/360);function sd(t,e,o,{at:r=0,flight:n=1,hold:a=1.5,margin:i=1,push:l=!0,W:p=1280,H:c=720}={}){if(!(n>=.2&&n<=12))throw Error("Flight time must be 0.2–12 s");if(!(a>=0&&a<=20))throw Error("Rest time must be 0–20 s");if(!(i>=.6&&i<=3))throw Error("Framing margin must be 0.6–3");const s=new Map(t.map(b=>[b.id,b])),h=e.map(b=>s.get(b)).filter(b=>b&&b.kind!=="audio");if(!h.length)throw Error("Chọn layer để camera bay tới");if(h.length>24)throw Error("At most 24 layers in one tour");const f={...o??{...Ar},enabled:!0,motionV:2,motionKeys:o?.motionKeys??[]},m=["cx","cy","cz","pan","tilt","roll"],y=Object.fromEntries(m.map(b=>[b,[]])),$=(b,A,I,P)=>y[b].push({time:Oo(A),value:Oo(Math.max(Ln[b].min,Math.min(Ln[b].max,I))),...P?{ease:P}:{}}),x=Jt["expo-in-out"],E=Jt.linear,v=Object.fromEntries(m.map(b=>[b,Gs(f,b,r)]));for(const b of m)$(b,r,v[b],x);let S=r;h.forEach((b,A)=>{const I=S+n,P=Math.max(0,Math.min(b.duration,I-b.start)),C=Xm({...b,is3D:!0},P,p,c,{margin:i});for(const N of["pan","roll"])C[N]=wE(C[N],v[N]);const z=A===h.length-1;for(const N of m)$(N,I,C[N],N==="cz"&&l&&a>0?E:x);if(a>0){const N=I+a,F=l?Math.min(.04,a*.015):0,K=Xm({...b,is3D:!0},P,p,c,{margin:i*(1-F)});for(const _ of m)$(_,N,_==="pan"||_==="roll"?C[_]:K[_],z?void 0:x);S=N}else S=I;Object.assign(v,C)});let k=f;for(const b of m){const A=Bi(k,b).filter(I=>I.time<r-1e-6||I.time>S+1e-6);k=un(k,b,[...A,...y[b]].sort((I,P)=>I.time-P.time).filter((I,P,C)=>!P||Math.abs(I.time-C[P-1].time)>1/120))}return{camera:jr(k),end:Oo(S)}}const ey=Object.freeze([{id:"photo-wall-tour",label:"Tường ảnh lướt",layout:"wall",camera:"glide",margin:2.6},{id:"curved-panorama",label:"Màn cong panorama",layout:"arc",camera:"sweep"},{id:"card-fan",label:"Xoè bài",layout:"fan",camera:"push",flight:1.6,hold:1.5,margin:1.6},{id:"toss-orbit",label:"Tung rải xoay quanh",layout:"scatter",camera:"orbit"},{id:"deck-dive",label:"Bay xuyên chồng bảng",layout:"stack",camera:"tour",flight:.8,hold:1,margin:1},{id:"boards-fly",label:"Bay qua bảng nghiêng",layout:"boards",camera:"tour",flight:1,hold:1.4,margin:1.08}]);ey.map(t=>t.id);function kE(t,e,o,r,{at:n,W:a=1280,H:i=720}={}){const l=ey.find(y=>y.id===r);if(!l)throw Error(`Unknown 3D scene "${r}"`);const p=ty(t,e,l.layout,{W:a,H:i}),c=new Map(t.map(y=>[y.id,y])),s=e.filter(y=>p[y]),h=t.map(y=>p[y.id]?{...y,...p[y.id]}:y),f=Number.isFinite(n)?n:Math.min(...s.map(y=>c.get(y).start));let m;if(l.camera==="tour")m=sd(h,l.layout==="stack"?[...s].sort((y,$)=>Ut({...c.get($),...p[$]},"depth",0)-Ut({...c.get(y),...p[y]},"depth",0)):s,o,{at:f,flight:l.flight,hold:l.hold,margin:l.margin,W:a,H:i});else if(l.camera==="glide"||l.camera==="sweep"){const y=Cr(a,i),$=s.map(I=>{const P=h.find(C=>C.id===I);return Pl(P,0,a,i).center}),x=Math.min(12,Math.max(4,s.length*.8)),E=f+x,v={...o??{...Ar},enabled:!0,motionV:2,motionKeys:o?.motionKeys??[]},S=Jt["sine-in-out"],k={cx:[],cy:[],cz:[],pan:[],tilt:[],roll:[]},b=(I,P,C,z)=>k[I].push({time:Oo(P),value:Oo(Math.max(Ln[I].min,Math.min(Ln[I].max,C))),...z?{ease:z}:{}});if(l.camera==="glide"){const I=h.find(F=>F.id===s[0]),P=Math.hypot(...Pl(I,0,a,i).corners[1].map((F,K)=>F-Pl(I,0,a,i).corners[0][K])),C=5*y*P/a*l.margin,z=$[0],N=$.at(-1);b("cx",f,z[0]/a,S),b("cx",E,N[0]/a),b("cy",f,z[1]/i,S),b("cy",E,N[1]/i),b("cz",f,(z[2]-C)/y,S),b("cz",E,(N[2]-C)/y);for(const F of["pan","tilt"])b(F,f,0);b("roll",f,-3,S),b("roll",E,2)}else{const P=C=>zi(Math.atan2(C[0],C[2]+7.5*y))*.8;b("cx",f,0),b("cy",f,0),b("cz",f,-7.5),b("tilt",f,0),b("roll",f,0),b("pan",f,P($[0]),S),b("pan",E,P($.at(-1)))}let A=v;for(const[I,P]of Object.entries(k))P.length&&(A=un(A,I,[...Bi(A,I).filter(C=>C.time<f-1e-6||C.time>E+1e-6),...P].sort((C,z)=>C.time-z.time)));m={camera:jr(A),end:Oo(E)}}else if(l.camera==="push")m=sd(h,[s[Math.floor(s.length/2)]],o,{at:f,flight:l.flight,hold:l.hold,margin:l.margin,W:a,H:i});else{const y={...o??{...Ar},enabled:!0,motionV:2,motionKeys:o?.motionKeys??[]},$=Math.max(4,s.length*1.2),x=5,E=f+$,v=Jt["sine-in-out"],S={cx:[],cz:[],pan:[]};for(let b=0;b<=4;b++){const A=Fa(-40+b*20),I=f+$*b/4,P=x-1.2*b/4;S.cx.push({time:Oo(I),value:Oo(Math.sin(A)*P*Cr(a,i)/a),ease:v}),S.cz.push({time:Oo(I),value:Oo(-Math.cos(A)*P),ease:v}),S.pan.push({time:Oo(I),value:Oo(-zi(A)),ease:v})}let k=y;for(const[b,A]of Object.entries(S))k=un(k,b,[...Bi(k,b).filter(I=>I.time<f-1e-6||I.time>E+1e-6),...A].sort((I,P)=>I.time-P.time));m={camera:jr(k),end:Oo(E)}}for(const y of s){const $=c.get(y);$.kind!=="video"&&$.start+$.duration<m.end&&(p[y]={...p[y],duration:Oo(m.end-$.start)})}return{patches:p,camera:m.camera,end:m.end}}const ba=Object.freeze({angle:300,strips:[3,10],samples:16}),xE=Object.freeze(["center","start","end"]),Wp=["posX","posY","scale","scaleX","scaleY","rotation","tiltX","tiltY","spatialDepth","anchorX","anchorY","motionKeys","motionV","parentId","zIndex"],To=t=>Math.round(t*1e4)/1e4;function ME(t,e){const o=t.find(n=>n.id===e);if(!o)return null;if(o.bend)return o;const r=o.parentId?t.find(n=>n.id===o.parentId):null;return r?.bend&&o.bendStrip?r:t.find(n=>n.bend?.source===e)??null}function oy(t,e,o,r){if(t.shape)return t.shape.size?t.shape.size[0]/t.shape.size[1]:t.shape.square?1:16/9;if(t.card)return t.card.width/t.card.height;const n=(r??[]).find(a=>a&&(a.url===t.url||t.nodeId&&a.id===t.nodeId));return n?.width&&n?.height?n.width/n.height:e/o}function $E(t,e,o,r){if(t.shape)return t.shape.size?[t.shape.size[0],t.shape.size[1]]:t.shape.square?[720,720]:[1280,720];if(t.card)return[t.card.width,t.card.height];if(t.motion||t.geo)return e>=o?[Math.round(720*e/o),720]:[720,Math.round(720*o/e)];if(t.title&&!t.url)return[1280,720];const n=(r??[]).find(a=>a&&(a.url===t.url||t.nodeId&&a.id===t.nodeId));return n?.width&&n?.height?[n.width,n.height]:null}function vE(t,e,o,r,n=0){const a=o*Math.PI/180,i=(t+.5)/e-.5;if(Math.abs(a)<1e-6)return{along:i*r,depth:0,turn:0,chord:1};const l=r/a,p=a/e,c=(i-n)*a,s=l*Math.cos(p/2);return{along:n*r+s*Math.sin(c),depth:l-s*Math.cos(c),turn:c*180/Math.PI,chord:Math.abs(2*l*Math.sin(p/2))/(r/e)}}function EE(t,e,o,r,{angle:n=60,angleTo:a,angleKeys:i,axis:l,anchor:p,strips:c,aspect:s,media:h,newId:f,W:m=1280,H:y=720}={}){if(typeof f!="function")throw Error("bendPlan needs newId");const $=Y=>Y!=null&&Number.isFinite(+Y);if(!$(n)||Math.abs(n)>ba.angle||a!=null&&(!$(a)||Math.abs(a)>ba.angle))throw Error("Góc uốn từ −300° đến 300°");const x=ME(t,o),E=new Map(t.map(Y=>[Y.id,Y])),v=x?E.get(x.bend.source):E.get(o);if(!v)throw Error("Không thấy layer để uốn");if(v.kind!=="image"||v.nullLayer||v.solid||v.fit==="cover"||v.geo||v.adjust)throw Error("Uốn cong dùng cho ảnh, shape, chữ, thẻ hoặc Motion Code (không phải video, null, nền màu)");const S=x?t.filter(Y=>Y.parentId===x.id&&Y.bendStrip):[],k=S.map(Y=>Y.id),b={},A=[],I=SE(x?S[0]?.motionKeys:v.motionKeys),P=x?E.get(x.bend.source):E.get(o),C=Array.isArray(i)&&i.length?i.map(Y=>({time:+Y?.time,angle:+Y?.angle})):null;if(C&&(C.length<2||C.length>24||C.some((Y,dt)=>!Number.isFinite(Y.time)||!Number.isFinite(Y.angle)||Math.abs(Y.angle)>ba.angle||Y.time<0||Y.time>(P?.duration??1/0)+1e-6||dt&&Y.time<=C[dt-1].time)))throw Error("Key uốn: 2–24 key theo thứ tự thời gian trong layer, góc từ −300° đến 300°");if(!+n&&!($(a)&&+a)&&!C?.some(Y=>Y.angle)){if(x){k.push(x.id);const Y=Hm(x.motionKeys,I);b[v.id]={disabled:void 0,...Object.fromEntries(Wp.map(dt=>[dt,x[dt]])),motionKeys:Y.length?Y:void 0}}return{add:A,patches:b,remove:k,camera:r??null,end:v.start+v.duration}}const N=l==="y"||!l&&x?.bend.axis==="y"?"y":"x";if(p!=null&&!xE.includes(p))throw Error("Điểm giữ: center, start hoặc end");const F=p??x?.bend.anchor??"center",K=F==="start"?-.5:F==="end"?.5:0,_=Math.max(ba.strips[0],Math.min(ba.strips[1],Math.round(c??x?.bend.strips??8))),q=v.crop??{left:0,right:0,top:0,bottom:0},U=1-q.left-q.right,rt=1-q.top-q.bottom,ot=($(s)&&s>0?+s:oy(v,m,y,h))*U/rt,G=Y=>Y<=m/y?[y*Y,y]:[m,m/Y],[J,Z]=G(ot),at=N==="x"?J:Z,D=Math.min(_,Math.floor((N==="x"?U:rt)/.1+1e-9));if(D<ba.strips[0])throw Error("Layer đã cắt quá hẹp để uốn");const H=Cr(m,y),ut=Math.min(v.motionBlur?.05:.012,.3/D),gt=t.filter(Y=>!k.includes(Y.id)),xt=Y=>{const{track:dt}=Zt(gt,e,Y.start,Y.start+Y.duration),bt={...Y,track:dt};return gt.push(bt),bt},u=x?{...x}:xt({...br({id:f(),track:0,start:v.start,duration:v.duration,label:`Uốn cong · ${String(v.label||"").slice(0,40)}`,is3D:!0}),...Object.fromEntries(Wp.filter(Y=>v[Y]!==void 0).map(Y=>[Y,v[Y]])),...v.motionKeys?{motionKeys:IE(v.motionKeys)}:{},is3D:!0}),st={source:v.id,angle:To(C?C[0].angle:+n),axis:N,strips:D,...K?{anchor:F}:{},...C?{angleKeys:C.map(Y=>({time:To(Y.time),angle:To(Y.angle)}))}:$(a)?{angleTo:To(+a)}:{}};x?b[x.id]={bend:st}:(u.bend=st,A.push(u));const V=$E(v,m,y,h)?.[N==="x"?0:1],d=N==="x"?q.left:q.top,w=N==="x"?U:rt,T=Y=>{if(!V)return Y;const dt=Math.round((d+Y*w)*V/2)*2/V;return Math.max(0,Math.min(1,(dt-d)/w))},j=Y=>Math.round(Y*1e6)/1e6,O=(Y,dt)=>{const bt=j(d+Y*w),tt=j(1-(d+dt*w));if(!V)return{lo:Y,hi:dt,a0:bt,b0:tt};const nt=Math.trunc(V*bt/2)*2,mt=Math.max(2,Math.trunc(V*(1-bt-tt)/2)*2);return{lo:(nt/V-d)/w,hi:((nt+mt)/V-d)/w,a0:bt,b0:tt}},L=Y=>{const{lo:dt,hi:bt,a0:tt,b0:nt}=O(T(Math.max(0,Y/D-(Y?ut:0))),T(Math.min(1,(Y+1)/D+(Y<D-1?ut:0)))),[mt,It]=G(N==="x"?ot*(bt-dt):ot/(bt-dt));return{lo:dt,hi:bt,a0:tt,b0:nt,zoom:N==="x"?Z/It:J/mt}},B=(Y,dt)=>{const bt=vE(Y,D,dt,at,K),{lo:tt,hi:nt,zoom:mt}=L(Y),It=((tt+nt)/2-(Y+.5)/D)*at,Nt=bt.turn*Math.PI/180,$t=bt.along+It*bt.chord*Math.cos(Nt),zt=bt.depth+It*bt.chord*Math.sin(Nt);return N==="x"?{x:To($t/m),depth:To(zt/H),tiltY:To(-bt.turn),zoom:To(mt),sx:To(bt.chord)}:{y:To($t/y),depth:To(zt/H),tiltX:To(bt.turn),zoom:To(mt),sy:To(bt.chord)}},X=Jt["sine-in-out"],Q=C?C.map(Y=>[Y.time,Y.angle]):$(a)&&+a!=+n?[[0,+n],[v.duration,+a]]:null,et=Q?Q.slice(1).flatMap(([Y,dt],bt)=>{const[tt,nt]=Q[bt],mt=Math.max(2,Math.floor(ba.samples*2/Q.length));return Array.from({length:mt+(bt?0:1)},(It,Nt)=>{const $t=(Nt+(bt?1:0))/mt;return[tt+(Y-tt)*$t,nt+(dt-nt)*AE(X,$t)]})}):null,lt=Object.fromEntries(Object.entries(v).filter(([Y])=>!Wp.includes(Y)&&!["id","track","disabled","bendStrip"].includes(Y)));for(let Y=0;Y<D;Y++){const{a0:dt,b0:bt}=L(Y),tt=N==="x"?{left:dt,right:bt,top:q.top,bottom:q.bottom}:{left:q.left,right:q.right,top:dt,bottom:bt},nt=B(Y,C?C[0].angle:+n),mt={posX:nt.x,posY:nt.y,spatialDepth:nt.depth,tiltX:nt.tiltX,tiltY:nt.tiltY,scale:nt.zoom,scaleX:nt.sx,scaleY:nt.sy},It=et?et.map(([zt,Dt])=>{const{zoom:ae,...we}=B(Y,Dt);return{time:To(zt),...Object.fromEntries(Object.entries(we).filter(([,Oe])=>Oe!==void 0))}}):[],Nt=Hm(It,I),$t=xt({...lt,id:f(),label:`${String(v.label||"Layer").slice(0,40)} · ${Y+1}/${D}`,start:v.start,duration:v.duration,parentId:u.id,is3D:!0,bendStrip:!0,crop:tt,...Object.fromEntries(Object.entries(mt).filter(([,zt])=>zt!==void 0)),...Nt.length?{motionV:2,motionKeys:Nt}:{}});A.push($t)}return x||(b[v.id]={disabled:!0}),{add:A,patches:b,remove:k,camera:jr({...r??{...Ar,motionKeys:[]},enabled:!0}),end:v.start+v.duration}}const SE=t=>(t??[]).filter(e=>e.opacity!==void 0).map(e=>({time:e.time,opacity:e.opacity,...e.ease?.opacity?{ease:{opacity:e.ease.opacity}}:{}}));function IE(t){return t.map(e=>{const{opacity:o,ease:r,...n}=e,a=r?Object.fromEntries(Object.entries(r).filter(([i])=>i!=="opacity")):null;return{...n,...a&&Object.keys(a).length?{ease:a}:{}}}).filter(e=>Object.keys(e).some(o=>o!=="time"&&o!=="ease"))}function Hm(t,e){const o=new Map;for(const r of[...t??[],...e??[]]){const n=To(r.time),a=o.get(n);o.set(n,a?{...a,...r,time:n,...a.ease||r.ease?{ease:{...a.ease,...r.ease}}:{}}:{...r,time:n})}return[...o.values()].sort((r,n)=>r.time-n.time)}function AE(t,e){const[o,r,n,a]=t,i=(c,s,h)=>3*c*h*(1-h)**2+3*s*h*h*(1-h)+h**3;let l=0,p=1;for(let c=0;c<30;c++){const s=(l+p)/2;i(o,n,s)<e?l=s:p=s}return i(r,a,(l+p)/2)}const ry=Object.freeze([{id:"orbit-system",label:"Hệ quỹ đạo"},{id:"cube-spin",label:"Khối lập phương xoay"},{id:"camera-orbit",label:"Camera bay vòng quanh"},{id:"bend",label:"Uốn cong"}]),CE=ry.map(t=>t.id),_e=t=>Math.round(t*1e3)/1e3,jE=Jt.linear,Xp=Jt["sine-in-out"];function Ja(t,e,o){const{track:r}=Zt(t,e,o.start,o.start+o.duration),n={...o,track:r};return t.push(n),n}const Hp=t=>({motionV:2,motionKeys:t.map(([e,o,r])=>({time:_e(e),...o,...r?{ease:Object.fromEntries(Object.keys(o).map(n=>[n,r]))}:{}}))});function TE(t,e,o,r,n,{at:a,newId:i,W:l=1280,H:p=720,duration:c,angle:s,angleTo:h,angleKeys:f,axis:m,anchor:y,media:$}={}){if(!ry.some(N=>N.id===n))throw Error(`Unknown 3D null rig "${n}"`);if(typeof i!="function")throw Error("nullRigPlan needs newId");if(n==="bend"){if(o.length!==1)throw Error("Chọn 1 layer để uốn cong");return EE(t,e,o[0],r,{angle:s??60,angleTo:h,angleKeys:f,axis:m,anchor:y,newId:i,W:l,H:p,media:$})}const x=new Map(t.map(N=>[N.id,N])),E=o.map(N=>x.get(N)).filter(N=>N&&N.kind!=="audio"&&!N.nullLayer);if(n!=="cube-spin"&&!E.length)throw Error("Chọn layer để dựng rig null 3D");const v=Number.isFinite(a)?a:E.length?Math.min(...E.map(N=>N.start)):0,S=_e(Math.max(2,Math.min(30,c??6))),k=_e(v+S),b=Cr(l,p),A=[...t],I=[],P={},C=N=>{P[N.id]={...P[N.id]??{},is3D:!0,...N.kind!=="video"&&N.start+N.duration<k?{duration:_e(k-N.start)}:{}}};let z=r;if(n==="orbit-system"){const N=Ja(A,e,{...br({id:i(),track:0,start:v,duration:S,label:"Quỹ đạo",is3D:!0}),posY:.06,tiltX:-70});I.push(N);const F=Ja(A,e,{...br({id:i(),track:0,start:v,duration:S,label:"Vòng quay",is3D:!0}),parentId:N.id,...Hp([[0,{tiltY:0},jE],[S,{tiltY:360}]])});I.push(F);const K=.3,_=E.length;E.forEach((q,U)=>{const rt=2*Math.PI*U/_;P[q.id]={parentId:F.id,is3D:!0,posX:_e(K*Math.cos(rt)),posY:0,spatialDepth:_e(K*Math.sin(rt)*l/b),scale:_e(Math.min(.24,.9/Math.max(3,_))),tiltX:70,rotation:0,tiltY:0},C(q)})}else if(n==="cube-spin"){const N=Ja(A,e,{...br({id:i(),track:0,start:v,duration:S,label:"Khối",is3D:!0}),...Hp([[0,{tiltY:-25,tiltX:18},Xp],[S,{tiltY:335,tiltX:-22}]])});I.push(N);const F=.56*p,K=F/2,_=_e(F/(p*.96)),q=He({v:2,square:!0,items:[{id:"g",name:"Glow",type:"rect",params:{w:960,h:960,round:4},pos:[500,500],rot:0,scale:[1,1],opacity:.35,fill:{type:"none"},stroke:{color:"#d8e6ff",width:14,blur:12,join:"round"}},{id:"r",name:"Glass",type:"rect",params:{w:960,h:960,round:4},pos:[500,500],rot:0,scale:[1,1],opacity:1,fill:{type:"color",color:"#dfe8ff",opacity:.05},stroke:{color:"#f6f9ff",width:3.5,join:"round"}}]}),U=[["Mặt trước",{spatialDepth:_e(K/b)}],["Mặt sau",{spatialDepth:_e(-K/b),tiltY:180}],["Mặt phải",{posX:_e(K/l),tiltY:90}],["Mặt trái",{posX:_e(-K/l),tiltY:-90}],["Mặt trên",{posY:_e(-K/p),tiltX:90}],["Mặt dưới",{posY:_e(K/p),tiltX:-90}]];for(const[ot,G]of U){const J=Ja(A,e,{id:i(),nodeId:"",kind:"image",url:"",label:ot,track:0,start:v,duration:S,volume:0,motionV:2,fit:"contain",shape:structuredClone(q),is3D:!0,parentId:N.id,scale:_,...G});I.push(J)}const rt=He({v:2,square:!0,items:[{id:"g",name:"Glow",type:"rect",params:{w:960,h:960,round:4},pos:[500,500],rot:0,scale:[1,1],opacity:1,fill:{type:"none"},stroke:{color:"#e8f0ff",width:44,blur:24,join:"round",cap:"round"}},{id:"r",name:"Light",type:"rect",params:{w:960,h:960,round:4},pos:[500,500],rot:0,scale:[1,1],opacity:1,fill:{type:"none"},stroke:{color:"#ffffff",width:14,join:"round",cap:"round"}}]});for(const[ot,G,J]of[["Tia cạnh phải",U[2][1],2],["Tia cạnh trái",U[3][1],3]]){const at=[];for(let D=0;D<J;D++)at.push({time:_e(S*D/J),trimStart:0,trimEnd:.14},{time:_e(S*(D+1)/J-(D<J-1?.001:0)),trimStart:1-.14,trimEnd:1});I.push(Ja(A,e,{id:i(),nodeId:"",kind:"image",url:"",label:ot,track:0,start:v,duration:S,volume:0,motionV:2,motionKeys:at,fit:"contain",shape:structuredClone(rt),is3D:!0,parentId:N.id,scale:_,...G}))}E.forEach((ot,G)=>{P[ot.id]={parentId:N.id,is3D:!0,posX:0,posY:0,spatialDepth:_e((G-(E.length-1)/2)*.4),scale:_e(Math.min(.26,.6/Math.max(1,E.length))),tiltX:0,tiltY:0},C(ot)})}else{const N=E[0],F=Math.max(0,Math.min(N.duration,v-N.start)),K=Ja(A,e,{...br({id:i(),track:0,start:v,duration:S,label:"Tâm camera",is3D:!0}),posX:_e(Ut(N,"x",F)),posY:_e(Ut(N,"y",F)),spatialDepth:_e(Ut(N,"depth",F)),tiltX:-10,...Hp([[0,{tiltY:-40},Xp],[S,{tiltY:40}]])});I.push(K);for(const q of E)C(q);z={...r??{...Ar},enabled:!0,motionV:2,motionKeys:r?.motionKeys??[],parentId:K.id};for(const[q,U]of Object.entries({cx:[[0,0]],cy:[[0,0]],pan:[[0,0]],tilt:[[0,0]],roll:[[0,0]],cz:[[0,-5.4],[S,-4.6]]}))z=un(z,q,[...Bi(z,q).filter(rt=>rt.time<v-1e-6||rt.time>k+1e-6),...U.map(([rt,ot],G)=>({time:_e(v+rt),value:ot,...G===0&&U.length>1?{ease:Xp}:{}}))].sort((rt,ot)=>rt.time-ot.time));z=jr(z)}return n!=="camera-orbit"&&(z=jr({...r??{...Ar,motionKeys:[]},enabled:!0})),{add:I,patches:P,camera:z,end:k}}const OE=Object.freeze([{id:"fan-cards",label:"Quạt thẻ 3D"},{id:"coin-beam",label:"Đồng xu trong cột sáng"},{id:"grid-floor",label:"Sàn lưới phối cảnh"},{id:"phone-turn",label:"Điện thoại xoay khoe màn hình"}]),ny=OE.map(t=>t.id),Xe=t=>Math.round(t*1e3)/1e3,Ss=t=>Jt[t];function Wn(t,e,o){const{track:r}=Zt(t,e,o.start,o.start+o.duration),n={...o,track:r};return t.push(n),n}const us=t=>({motionV:2,motionKeys:t.map(([e,o,r])=>({time:Xe(e),...o,...r?{ease:Object.fromEntries(Object.keys(o).map(n=>[n,Ss(r)]))}:{}}))}),yl=(t,e,o,r,n,a={})=>({id:t,nodeId:"",kind:"image",url:"",label:r,track:0,start:e,duration:o,volume:0,motionV:2,fit:"contain",shape:He({v:2,square:!0,items:n}),...a});function bl(t,e,o){const r=(t.motionKeys??[]).map(n=>{const{[e]:a,ease:i,...l}=n;if(i){const{[e]:p,...c}=i;Object.keys(c).length&&(l.ease=c)}return l}).filter(n=>Object.keys(n).some(a=>a!=="time"&&a!=="ease"));for(const[n,a,i]of o){let l=r.find(p=>Math.abs(p.time-n)<.008333333333333333);l||r.push(l={time:Xe(n)}),l[e]=Xe(a),i&&(l.ease={...l.ease,[e]:Ss(i)})}return r.sort((n,a)=>n.time-a.time)}function PE(t,e,o,r,n,{at:a,newId:i,W:l=1280,H:p=720,duration:c,color:s,media:h}={}){if(!ny.includes(n))throw Error(`Unknown 3D null rig "${n}"`);const f=new Map(t.map(I=>[I.id,I])),m=o.map(I=>f.get(I)).filter(I=>I&&I.kind!=="audio"&&!I.nullLayer),y=Number.isFinite(a)?a:m.length?Math.min(...m.map(I=>I.start)):0,$=Xe(Math.max(2,Math.min(30,c??6))),x=Xe(y+$),E=[...t],v=[],S={},k=I=>({is3D:!0,...I.kind!=="video"&&I.start+I.duration<x?{duration:Xe(x-I.start)}:{}});let b=jr({...r??{...Ar,motionKeys:[]},enabled:!0});const A=typeof s=="string"&&/^#[0-9a-fA-F]{6}$/.test(s)?s:"#39e6e0";if(n==="fan-cards"){if(!m.length)throw Error("Chọn 1–6 thẻ để xoè");const I=m.slice(0,6),P=I.length,C=(P-1)/2,z=Wn(E,e,{...br({id:i(),track:0,start:y,duration:$,label:"Quạt thẻ",is3D:!0}),tiltX:-8,...us([[0,{tiltY:-10},"sine-in-out"],[$,{tiltY:10}]])});v.push(z);const N=Xe(Math.min(.42,1.1/Math.max(2.4,P)));I.forEach((F,K)=>{const _=K-C,q=Xe(_*Math.min(.17,.8/Math.max(1,P))),U=Xe(_*9),rt=Xe(Math.abs(_)*.025),ot=y-F.start,G=Math.max(0,ot)+K*.09,J=G+.7;let Z={parentId:z.id,...k(F),posX:q,posY:rt,scale:N,rotation:U,tiltX:0,tiltY:Xe(-_*8),spatialDepth:Xe(K*.12),opacity:1,motionV:2},at=bl(F,"x",[[G,0,"back-out"],[J,q]]);at=bl({motionKeys:at},"y",[[G,.45,"expo-out"],[J,rt]]),at=bl({motionKeys:at},"rot",[[G,0,"back-out"],[J,U]]),at=bl({motionKeys:at},"opacity",[[G,0,"ease-out"],[G+.25,1]]),S[F.id]={...Z,motionKeys:at}})}else if(n==="coin-beam"){const I=Wn(E,e,yl(i(),y,$,"Cột sáng",[{id:"h",name:"Halo",type:"rect",params:{w:520,h:1e3,round:0},pos:[500,500],rot:0,scale:[1,1],opacity:.45,fill:{type:"linear",angle:0,stops:[[`${A}00`,0],[`${A}66`,.5],[`${A}00`,1]]},stroke:null},{id:"b",name:"Beam",type:"rect",params:{w:240,h:1e3,round:0},pos:[500,500],rot:0,scale:[1,1],opacity:1,fill:{type:"linear",angle:0,stops:[[`${A}10`,0],[`${A}cc`,.35],["#e8ffffee",.5],[`${A}cc`,.65],[`${A}10`,1]]},stroke:null}],{...us([[0,{opacity:0},"ease-out"],[.5,{opacity:1}]])}));v.push(I);const P=Wn(E,e,yl(i(),y,$,"Ánh sáng sàn",[{id:"f",name:"Floor glow",type:"ellipse",params:{w:900,h:220},pos:[500,500],rot:0,scale:[1,1],opacity:1,fill:{type:"radial",stops:[[`${A}aa`,0],[`${A}00`,1]]},stroke:null}],{posY:.3,scale:.8}));v.push(P);const C=Wn(E,e,{...br({id:i(),track:0,start:y,duration:$,label:"Đồng xu",is3D:!0}),...us([[0,{tiltY:-720,y:-.05,zoom:.6},"expo-out"],[Math.min(1.6,$*.4),{tiltY:0,y:0,zoom:1},"sine-in-out"],[Math.min(1.6,$*.4)+($-Math.min(1.6,$*.4))/2,{tiltY:16,y:-.015},"sine-in-out"],[$,{tiltY:-8,y:0}]])});v.push(C);const z=.46;if(v.push(Wn(E,e,yl(i(),y,$,"Mặt đồng xu",[{id:"g",name:"Glow",type:"ellipse",params:{w:960,h:960},pos:[500,500],rot:0,scale:[1,1],opacity:.6,fill:{type:"none"},stroke:{color:"#bffcff",width:30,blur:26}},{id:"d",name:"Disc",type:"ellipse",params:{w:940,h:940},pos:[500,500],rot:0,scale:[1,1],opacity:1,fill:{type:"radial",cx:.35,cy:.3,stops:[["#d9fffd",0],[A,.45],["#0b4f55",1]]},stroke:{color:"#e9ffff",width:16}},{id:"r",name:"Rim",type:"ellipse",params:{w:800,h:800},pos:[500,500],rot:0,scale:[1,1],opacity:.5,fill:{type:"none"},stroke:{color:"#0b4f55",width:10}}],{is3D:!0,parentId:C.id,scale:z,spatialDepth:0}))),m[0]){const N=m[0],{track:F}=Zt(E.filter(U=>U.id!==N.id),e,Math.min(N.start,y),Math.max(N.start+N.duration,x)),K=oy(N,l,p,h),_=.6*z*.94*p,q=K>=l/p?_/l:_/(p*Math.max(1,K));S[N.id]={parentId:C.id,...k(N),track:F,posX:0,posY:0,scale:Xe(q),rotation:0,tiltX:0,tiltY:0,spatialDepth:.02}}}else if(n==="grid-floor"){const C=[],z=[];for(let _=0;_<=10;_++){const q=Xe(_*100),U=_%2?[q,1e3]:[q,0],rt=_%2?[q,0]:[q,1e3];C.push(U,rt)}for(let _=0;_<=10;_++){const q=Xe(_*100),U=_%2?[1e3,q]:[0,q],rt=_%2?[0,q]:[1e3,q];z.push(U,rt)}const N=(_,q,U,rt)=>({id:_,name:q,type:"path",params:{pts:U,closed:!1},pos:[0,0],rot:0,scale:[1,1],opacity:rt?.35:.9,fill:{type:"none"},stroke:{color:rt?A:"#cfe9ff",width:rt?10:2.5,...rt?{blur:10}:{},join:"miter"}}),F=Wn(E,e,{...br({id:i(),track:0,start:y,duration:$,label:"Sàn lưới",is3D:!0}),posY:.28,tiltX:-78,...us([[0,{y:.1},"linear"],[$,{y:0}]])});v.push(F),v.push(Wn(E,e,yl(i(),y,$,"Lưới",[N("gv","Glow V",C,!0),N("gh","Glow H",z,!0),N("v","Lines V",C),N("h","Lines H",z)],{is3D:!0,parentId:F.id,scale:2.6,opacity:.8})));const K=m.length;m.forEach((_,q)=>{S[_.id]={...k(_),posX:Xe((q-(K-1)/2)*.28),posY:-.04,spatialDepth:Xe(-.3*(q%2)),scale:Xe(Math.min(.3,.9/Math.max(3,K))),tiltX:0,tiltY:0}})}else{const I=m.find(F=>["image","video"].includes(F.kind)&&F.url);if(!I)throw Error("Chọn một clip ảnh hoặc video để đưa lên màn hình điện thoại");const P=Wn(E,e,{...br({id:i(),track:0,start:y,duration:$,label:"Điện thoại",is3D:!0}),...us([[0,{y:.04,zoom:.85},"expo-out"],[1.4,{y:0,zoom:1},"sine-in-out"],[$/2+.7,{y:-.02},"sine-in-out"],[$,{y:0}]])});v.push(P);const{clip:C,sourcePatch:z}=gg(E,e,I,"phone",{id:i(),color:s,start:y,duration:$,pose:{scale:.62,parentId:P.id,modelRotation:{x:-6,y:180,z:0},motionV:2,motionKeys:[{time:0,ry:180,ease:{ry:Ss("expo-out")}},{time:1.6,ry:-14,ease:{ry:Ss("sine-in-out")}},{time:Xe($),ry:12}]}});C.duration=$,E.push(C),v.push(C),S[I.id]={...z,...I.kind==="image"&&I.start+I.duration<x?{duration:Xe(x-I.start)}:{}};let N={...b,motionV:2,motionKeys:b.motionKeys??[]};N=un(N,"cz",[...Bi(N,"cz").filter(F=>F.time<y-1e-6||F.time>x+1e-6),{time:Xe(y),value:-6,ease:Ss("sine-in-out")},{time:x,value:-4.8}].sort((F,K)=>F.time-K.time)),b=jr(N)}return{add:v,patches:S,camera:b,end:x}}const vi=Object.freeze({points:[2,24],samples:[8,48]}),zE=Object.freeze(["x","y","depth","rot","tiltY"]),Hn=t=>Math.round(t*1e4)/1e4,Pa=(t,e)=>Math.max(Tr[t].min,Math.min(Tr[t].max,e));function ay(t){if(!t||typeof t!="object")throw Error("Invalid motion path");const e=t.points;if(!Array.isArray(e)||e.length<vi.points[0]||e.length>vi.points[1])throw Error(`Motion path needs ${vi.points[0]}–${vi.points[1]} points`);const r={points:e.map(n=>{if(!Array.isArray(n)||n.length<2||n.length>3||!n.every(Number.isFinite))throw Error("A path point is [x, y] or [x, y, depth]");return[Pa("x",n[0]),Pa("y",n[1]),...n.length===3?[Pa("depth",n[2])]:[]]})};for(const n of["start","end"])if(t[n]!==void 0){if(!Number.isFinite(t[n])||t[n]<0)throw Error(`Invalid path ${n}`);r[n]=Hn(t[n])}if(r.start!==void 0&&r.end!==void 0&&r.end<=r.start)throw Error("Path end must be after start");if(t.ease!==void 0){if(typeof t.ease!="string"||!Jt[t.ease])throw Error(`Unknown path ease "${t.ease}"`);r.ease=t.ease}if(t.orient!==void 0){if(typeof t.orient!="boolean")throw Error("Invalid path orient");r.orient=t.orient}if(t.closed!==void 0){if(typeof t.closed!="boolean")throw Error("Invalid path closed");r.closed=t.closed}return r}function LE(t,e){const o=t.length,r=p=>e?t[(p+o)%o]:t[Math.max(0,Math.min(o-1,p))],n=e?o:o-1,a=(p,c)=>{const s=r(p-1),h=r(p),f=r(p+1),m=r(p+2),y=(I,P)=>Math.max(1e-6,Math.sqrt(Math.hypot(...I.map((C,z)=>C-P[z])))),$=y(s,h),x=$+y(h,f),E=x+y(f,m),v=$+(x-$)*c,S=(I,P,C,z)=>I.map((N,F)=>(z-v)/(z-C)*N+(v-C)/(z-C)*P[F]),k=S(s,h,0,$),b=S(h,f,$,x),A=S(f,m,x,E);return S(S(k,b,0,x),S(b,A,$,E),$,x)},i=[{s:0,p:t[0].slice()}];for(let p=0;p<n;p++)for(let c=1;c<=24;c++){const s=a(p,c/24),h=i.at(-1);i.push({s:h.s+Math.hypot(...s.map((f,m)=>f-h.p[m])),p:s})}const l=i.at(-1).s||1;return p=>{const c=Math.max(0,Math.min(1,p))*l;let s=1;for(;s<i.length-1&&i[s].s<c;)s++;const h=i[s-1],f=i[s],m=f.s>h.s?(c-h.s)/(f.s-h.s):0;return h.p.map((y,$)=>y+(f.p[$]-y)*m)}}function iy(t,e,{W:o=1280,H:r=720}={}){const n=ay(e),a=Cr(o,r),i=n.points.some(E=>E.length===3),l=n.points.map(E=>[E[0]*o,E[1]*r,(E[2]??0)*a]),p=LE(l,!!n.closed),c=Math.min(n.start??0,Math.max(0,t.duration-.1)),s=Math.min(t.duration,n.end??t.duration),h=Math.max(.1,s-c),f=Math.max(vi.samples[0],Math.min(vi.samples[1],Math.max(Math.round(h*6),n.points.length*4))),m=Jt[n.ease??"linear"],y=[];for(let E=0;E<=f;E++)y.push(p(oh(m,E/f)));const $=E=>Hn(c+h*E/f),x={x:[],y:[],...i?{depth:[]}:{}};if(y.forEach((E,v)=>{const S=v<f?{ease:"auto"}:{};x.x.push({time:$(v),value:Hn(Pa("x",E[0]/o)),...S}),x.y.push({time:$(v),value:Hn(Pa("y",E[1]/r)),...S}),i&&x.depth.push({time:$(v),value:Hn(Pa("depth",E[2]/a)),...S})}),n.orient){const E=b=>{const A=p(Math.max(0,b-.004)),I=p(Math.min(1,b+.004));return[I[0]-A[0],I[1]-A[1],I[2]-A[2]]},v=b=>{for(let A=1;A<b.length;A++){let I=b[A].value-b[A-1].value;for(;I>180;)b[A].value-=360,I-=360;for(;I<-180;)b[A].value+=360,I+=360}return b},S=[],k=[];for(let b=0;b<=f;b++){const[A,I,P]=E(oh(m,b/f)),C=b<f?{ease:"auto"}:{};if(i){const z=Math.hypot(A,P);k.push({time:$(b),value:Hn(Math.atan2(-P,A||1e-9)*180/Math.PI),...C}),S.push({time:$(b),value:Hn(Math.atan2(I,z||1e-9)*180/Math.PI),...C})}else S.push({time:$(b),value:Hn(Math.atan2(I,A||1e-9)*180/Math.PI),...C})}x.rot=v(S),i&&(x.tiltY=v(k));for(const b of zE)x[b]&&(x[b]=x[b].map(A=>({...A,value:Pa(b,A.value)})))}return x}function NE(t,e,{W:o=1280,H:r=720}={}){let n={...t},a={};const i=t.path?FE(t.path):[];for(const c of i){const s=de(n,c,[]);n={...n,...s},a={...a,...s}}if(!e)return{...a,path:void 0};const l=ay(e),p=iy(n,l,{W:o,H:r});for(const[c,s]of Object.entries(p)){const h=de(n,c,s);n={...n,...h},a={...a,...h}}return{...a,path:l}}function FE(t){const e=t.points?.some(o=>o.length===3);return["x","y",...e?["depth"]:[],...t.orient?e?["rot","tiltY"]:["rot"]:[]]}function KC(t,{W:e=1280,H:o=720}={}){if(!t.path)return!1;try{const r=iy(t,t.path,{W:e,H:o});return Object.entries(r).every(([n,a])=>{const i=Me(t,n);return i.length===a.length&&i.every((l,p)=>Math.abs(l.time-a[p].time)<.001&&Math.abs(l.value-a[p].value)<.001)})}catch{return!1}}const RE=1,sy=100,DE=40,BE=60,Vd=Object.freeze({cut:null,flash:"flash-cut",whip:"whip-pan",zoom:"zoom-punch",glitch:"glitch-hard",dissolve:"dissolve",dip:"dip-black-fast",shake:"shake-cut",spin:"spin-zoom",slide:"push-blur",strobe:"strobe",slam:"slam-in",curl:"page-curl",match:"match-walk"}),ly=Object.freeze({flash:["warm-flash","flash-cut","flash-cut"],whip:["whip-pan","whip-pan","whip-pan-left"],zoom:["zoom-through","zoom-punch","zoom-punch"],glitch:["glitch","glitch-hard","glitch-hard"],dissolve:["dissolve","dissolve","blur-dip"],dip:["dip-black","dip-black-fast","dip-black-fast"],spin:["spin","spin-zoom","spin-zoom"],slide:["push-left","push-blur","push-blur"],strobe:["flash-cut","strobe","strobe"]}),_E=(t,e=3)=>ly[t]?.[e<=2?0:e>=4?2:1]??Vd[t]??null;Object.freeze([...new Set([...Object.values(Vd),...Object.values(ly).flat()].filter(Boolean))]);const GE=Object.freeze(["hook","build","payoff","reaction","outro"]),KE=Object.freeze(["text","framing","motion","color"]),VE=Object.freeze({"extreme-close":1.3,close:1.15,insert:1.2}),Um=["luma","sat","warmth","contrast","shadowTint","highlightTint"],Sn=t=>Math.round(t*1e3)/1e3,jc=(t,e,o)=>Math.max(e,Math.min(o,t)),cy=t=>t&&typeof t=="object"&&Um.every(e=>Number.isFinite(t[e])&&Math.abs(t[e])<=1)?Object.fromEntries(Um.map(e=>[e,Sn(t[e])])):null;function WE(t){const e=cy(t);return e?e.sat<.07?{effect:"mono",amount:.8}:e.shadowTint>.03&&e.highlightTint>.04?{effect:"teal-orange",amount:.6}:e.warmth>.08?{effect:"warm",amount:Sn(jc((e.warmth-.04)*6,.3,.8))}:e.warmth<-.04?{effect:"cool",amount:Sn(jc(-e.warmth*8,.3,.8))}:e.sat<.16&&e.contrast>.22?{effect:"bleach",amount:.6}:e.contrast<.13&&e.luma>.3?{effect:"fade",amount:.5}:e.sat>.38?{effect:"vivid",amount:.5}:e.contrast>.28?{effect:"contrast",amount:.5}:null:null}function XE(t,e){const o=String(e||"").trim().split(/\s+/).filter(Boolean),r=/\p{L}/u.test(t)&&t===t.toLocaleUpperCase();if(!o.length)return{text:t,source:"reference"};const n=/\d/.test(t)?o.findIndex(l=>/\d/.test(l)):-1,a=jc(t.split(/\s+/).filter(Boolean).length+1,2,6),i=o.slice(Math.max(0,n),Math.max(0,n)+a).join(" ").replace(/[,.;:!?…]+$/u,"").slice(0,60);return{text:r?i.toLocaleUpperCase():i,source:"speech"}}function HE(t,e,o,r){const n=(i,l)=>(Array.isArray(i?.scenes)?i.scenes:[]).find(p=>p.start<=l&&p.end>l&&Number.isFinite(p.flowX))?.flowX??0;return n(t,Math.max(0,e-.05))+n(o,r+.05)>.02?1:-1}function UE(t){if(!t||typeof t!="object"||t.v!==RE||!(t.duration>0&&t.duration<=3600)||!Array.isArray(t.shots)||!t.shots.length||t.shots.length>sy)throw Error("Invalid reference recipe");for(const e of t.shots)if(!(e?.len>0&&e.len<=3600)||!Object.hasOwn(Vd,e.transition)||!GE.includes(e.role))throw Error("Invalid reference shot");if(t.color!==void 0&&!cy(t.color))throw Error("Invalid reference colour");return t}function YE(t){return Object.fromEntries(KE.map(e=>[e,!(t&&typeof t=="object"&&t[e]===!1)]))}function qE(t,e,o,r,n){const a={punch:null,move:null,shake:null,text:null},i=VE[t.framing];return r.framing&&i&&o>=.4&&(a.punch={amount:i,style:r.motion&&t.motion==="slow"?"push":"cut"}),r.motion&&o>=.3&&(t.motion==="shake"?a.shake=Sn(jc(.25+.08*t.energy,.3,.65)):t.motion==="fast"?a.move=e%2?"pan-right":"pan-left":t.motion==="slow"&&a.punch?.style!=="push"&&(a.move=t.framing==="wide"?e%2?"pan-left":"pan-right":"push-in")),r.text&&t.text&&(a.text={...XE(t.text,n),placement:t.textPlacement==="bottom"?"lower":t.textPlacement==="top"?"top":"center"}),a}function ZE(t){const e=typeof t=="string"&&/^([A-Za-z0-9_-]{1,100})@(\d+(?:\.\d+)?)-(\d+(?:\.\d+)?)$/.exec(t.trim());if(!e)throw Error(`Pick "${String(t).slice(0,60)}" must be "materialId@start-end"`);const o=Number(e[2]),r=Number(e[3]);if(!(r>o))throw Error(`Pick "${t}": end must be after start`);return{materialId:e[1],start:o,end:r}}function JE({recipe:t,picks:e,beats:o=null,duration:r=null,start:n=0,sourceDuration:a=()=>1/0,copy:i=null,spoken:l=()=>""}){const p=YE(i);if(UE(t),!Array.isArray(e)||!e.length)throw Error("Choose at least one moment of your footage");const c=Math.max(3,Math.min(BE,Number(r)>0?Number(r):t.duration)),s=t.shots.map(k=>({...k}));for(let k=0,b=t.duration;b<c-1e-6&&s.length<sy;k++){const A=t.shots[k%t.shots.length];s.push({...A}),b+=A.len}const h=o?.beats?.length&&(o.confidence??0)>=qc?o:null,f=h?(h.drops||[]).find(k=>k>c*.25&&k<c*.9)??null:null;let m=-1;if(f!=null&&s.length>1){const k=s.findIndex((b,A)=>A>0&&b.role==="payoff");m=k>0?k:s.reduce((b,A,I)=>I>0&&A.energy>s[b].energy?I:b,1)}const y=(k,b,A)=>{const I=k.reduce((z,N)=>z+N.len,0),P=[];let C=b;for(const z of k)C+=z.len*(A-b)/I,P.push(C);return P};let $=m>0?[...y(s.slice(0,m),0,f),...y(s.slice(m),f,c)].slice(0,-1):y(s,0,c).slice(0,-1);if(h){const k=60/(h.bpm||120),b=Math.max(.25,Math.min(k,.6));$=$.map(I=>I===f?I:k5(h,I,k/2));const A=[];for(const I of $)if((I-(A.at(-1)??0)>=b||I===f)&&c-I>=b){if(I===f)for(;A.length&&f-A.at(-1)<b;)A.pop();A.push(I)}$=A}const x=[0,...$,c],E=e.map(k=>({...k,cursor:k.start})),v=[];let S=0;for(let k=0;k<x.length-1;k++){const b=Sn(x[k+1]-x[k]),A=s[Math.min(k,s.length-1)];let I=null;for(let C=0;C<E.length*2&&!I;C++){const z=E[S%E.length];(z.cursor>=z.end-.05||a(z.materialId)-z.cursor<b-.001)&&(z.cursor=z.start),a(z.materialId)-z.cursor>=b-.001?I=z:S++}if(!I)throw Error("The chosen moments are too short for this edit");const P=Sn(I.cursor);v.push({materialId:I.materialId,inPoint:P,duration:b,start:Sn(n+x[k]),transition:k===0?null:_E(A.transition,A.energy),role:A.role,energy:A.energy,...qE(A,k,b,p,A.text&&p.text?l(I.materialId,P,P+b):"")}),I.cursor+=b,S++}return{segments:v,look:p.color?WE(t.color):null,snapped:!!h,drop:f!=null?Sn(f):null,duration:Sn(c)}}const py=Object.freeze([{id:"clear-sky",name:"Trời trong",en:"Clear sky",mixer:{blue:{clean:.6,sat:.1},cyan:{clean:.3}}},{id:"lush-grass",name:"Cỏ xanh tươi",en:"Lush grass",mixer:{green:{shift:.25,sat:.45,clean:.6},yellow:{shift:.18,sat:.2}}},{id:"vivid-red",name:"Hoa đỏ rực",en:"Vivid reds",mixer:{red:{sat:.3,clean:.2,lum:-.05}}},{id:"rosy-skin",name:"Da hồng hào",en:"Rosy skin",mixer:{red:{shift:-.1,clean:.12,lum:.05},yellow:{shift:-.2,sat:-.08,lum:.05}}},{id:"dreamy-sky",name:"Trời tím mộng mơ",en:"Dreamy violet sky",mixer:{blue:{shift:.45,clean:.4,sat:.1},cyan:{shift:.25},green:{sat:-.2}}},{id:"japan-cyan",name:"Cyan kiểu Nhật",en:"Japanese cyan",mixer:{green:{shift:.45,sat:-.15},cyan:{sat:.1,clean:.2},red:{sat:-.15},magenta:{sat:-.35}}},{id:"teal-orange-curves",name:"Tông xanh lơ – cam",en:"Teal & orange curves",curves:{r:[[0,0],[.25,.19],[.75,.82],[1,1]],b:[[0,0],[.25,.3],[.75,.68],[1,1]]}},{id:"remove-yellow",name:"Khử ám vàng",en:"Remove yellow cast",curves:{b:[[0,0],[.5,.57],[1,1]]}},{id:"warm-skin-pop",name:"Da sáng ấm",en:"Warm glowing skin",mixer:{red:{lum:.12},yellow:{lum:.15,sat:.08}},curves:{master:[[0,0],[.5,.53],[1,1]]}}]),uy=new Map(py.map(t=>[t.id,t])),dy=(t,[e,o])=>Math.max(e,Math.min(o,t)),ld=t=>+t.toFixed(3);function QE(t,e){const o=typeof e=="string"?uy.get(e):e;if(!o)throw Error("Unknown colour recipe");const r={...t||{}};if(o.mixer){const n={...r.mixer||{}};for(const[a,i]of Object.entries(o.mixer)){const l={...n[a]||{}};for(const[p,c]of Object.entries(i)){const s=ld(dy((l[p]??0)+c,Uc[p]));s?l[p]=s:delete l[p]}Object.keys(l).length?n[a]=l:delete n[a]}Object.keys(n).length?r.mixer=n:delete r.mixer}return o.curves&&(r.curves={...r.curves||{},...Object.fromEntries(Object.entries(o.curves).map(([n,a])=>[n,a.map(i=>i.slice())]))}),r}function VC(t,e,o,r){const n=typeof t=="string"?uy.get(t):t;if(!n)return[e,o,r];const a={curves:n.curves};return n.curves&&(e=lp(a,"r",e),o=lp(a,"g",o),r=lp(a,"b",r)),n.mixer?bg(n.mixer,e,o,r):[e,o,r]}const hy=20,t8=4;function e8(t,e,o){const{h:r,c:n,l:a}=yg(t,e,o);if(n<.03||a<.05)return null;const i=(r-hy+540)%360-180;return{hue:+r.toFixed(1),delta:+i.toFixed(1),ok:Math.abs(i)<=t8,chroma:+n.toFixed(3),luma:+a.toFixed(3)}}function WC(t,e){const o=e8(...e);if(!o||o.ok)return null;const r=t?.mixer||{},n={red:r.red?.shift??0,yellow:r.yellow?.shift??0},a=h=>{const[f,m,y]=bg({red:{shift:h},yellow:{shift:h}},...e);return(yg(f,m,y).h-hy+540)%360-180};let i=-1,l=1;a(i)>0||a(l)<0;for(let h=0;h<30;h++){const f=(i+l)/2;a(f)>0?l=f:i=f}const p=(i+l)/2,c={...r};for(const h of["red","yellow"]){const f=ld(dy(n[h]+p,Uc.shift)),m={...c[h]||{}};f?m.shift=f:delete m.shift,Object.keys(m).length?c[h]=m:delete c[h]}const s={...t||{}};return Object.keys(c).length?s.mixer=c:delete s.mixer,{grade:s,shift:ld(p),before:o}}const Xn=t=>({...nn,type:"ellipse",...t}),Be=(t,e,o)=>o==="en"?e:t,fy=Object.freeze([{id:"face-light",name:"Rọi sáng mặt",en:"Face light",icon:"☀",needs:"face",build:({face:t,locale:e})=>[t?{name:Be("Sáng mặt","Face",e),window:bs("face"),adjust:{exposure:.3}}:{name:Be("Sáng giữa","Centre",e),window:Xn({cx:.5,cy:.42,w:.34,h:.5,feather:.5}),adjust:{exposure:.3}},{name:Be("Tối quanh","Surround",e),window:Xn({cx:.5,cy:.45,w:.9,h:1,feather:.6}),invert:!0,adjust:{exposure:-.4}}]},{id:"vignette",name:"Vignette điện ảnh",en:"Cinematic vignette",icon:"◎",build:({locale:t})=>[{name:Be("Vignette","Vignette",t),window:Xn({cx:.5,cy:.5,w:1.1,h:1.15,feather:.6}),invert:!0,adjust:{exposure:-.5}}]},{id:"dark-sky",name:"Tối trời",en:"Darker sky",icon:"◒",build:({locale:t})=>[{name:Be("Tối trời","Sky",t),window:{...nn,type:"gradient",cx:.5,cy:.4,w:1,h:1,rot:0,feather:.35},adjust:{exposure:-.4,temperature:-10}}]},{id:"neon-glow",name:"Làm rực đèn neon",en:"Neon glow",icon:"✺",build:({locale:t})=>[{name:Be("Đèn rực","Bright lights",t),qualifier:{hue:0,hueWidth:360,satMin:.25,satMax:1,lumMin:.6,lumMax:1,soft:.3},adjust:{saturation:1.3,exposure:.1}}]},{id:"subject-pop",name:"Tách chủ thể",en:"Subject pop",icon:"◐",needs:"person",build:({person:t,locale:e})=>[t?{name:Be("Nền","Background",e),window:zl(),invert:!0,adjust:{saturation:.7,exposure:-.3}}:{name:Be("Nền","Background",e),window:Xn({cx:.5,cy:.5,w:.5,h:.8,feather:.5}),invert:!0,adjust:{saturation:.7,exposure:-.3}}]},{id:"face-beauty",name:"Làm đẹp mặt",en:"Face beauty",icon:"✨",needs:"face",faceOnly:!0,build:({locale:t})=>[{name:Be("Sáng mặt","Brighter face",t),window:bs("face"),adjust:{exposure:.2}},{name:Be("Mịn da","Smooth skin",t),window:bs("skin"),blur:.1,adjust:{contrast:.97}},{name:Be("Mắt sáng","Bright eyes",t),window:bs("eyes"),adjust:{exposure:.1,contrast:1.15},sharpen:35}]},{id:"depth-far-top",name:"Chiều sâu: xa ở trên",en:"Depth: far at the top",icon:"⛰",group:"depth",build:({locale:t})=>[{name:Be("Xa (trên)","Far (top)",t),window:{...nn,type:"gradient",cx:.5,cy:.45,w:1,h:1,rot:0,feather:.5},adjust:{contrast:.82,saturation:.85,temperature:-14,exposure:.08}},{name:Be("Gần (dưới)","Near (bottom)",t),window:{...nn,type:"gradient",cx:.5,cy:.7,w:1,h:1,rot:0,feather:.5},invert:!0,adjust:{contrast:1.08,saturation:1.06,temperature:8}}]},{id:"depth-far-centre",name:"Chiều sâu: xa ở giữa",en:"Depth: far in the centre",icon:"◉",group:"depth",build:({locale:t})=>[{name:Be("Xa (giữa)","Far (centre)",t),window:Xn({cx:.5,cy:.45,w:.32,h:.45,feather:.6}),adjust:{contrast:.84,saturation:.85,temperature:-12,exposure:.05}},{name:Be("Gần (viền)","Near (edges)",t),window:Xn({cx:.5,cy:.47,w:.95,h:1.05,feather:.6}),invert:!0,adjust:{contrast:1.06,temperature:6,exposure:-.12}}]},{id:"depth-subject",name:"Chiều sâu: người gần, nền xa",en:"Depth: near subject, far background",icon:"◑",group:"depth",needs:"person",build:({person:t,locale:e})=>[{name:Be("Nền (xa)","Background (far)",e),window:t?zl():Xn({cx:.5,cy:.5,w:.5,h:.8,feather:.5}),invert:!0,adjust:{contrast:.85,saturation:.85,temperature:-12,exposure:-.1}},{name:Be("Người (gần)","Subject (near)",e),window:t?zl():Xn({cx:.5,cy:.5,w:.5,h:.8,feather:.5}),adjust:{contrast:1.06,temperature:8}}]},{id:"depth-ai",name:"Chiều sâu AI",en:"AI depth",icon:"✦",group:"depth",needs:"depth",build:({depth:t,locale:e})=>t?[{name:Be("Xa (AI)","Far (AI)",e),window:{...nn,type:"depth",range:[0,.42],feather:.35},adjust:{contrast:.82,saturation:.85,temperature:-14,exposure:.06}},{name:Be("Gần (AI)","Near (AI)",e),window:{...nn,type:"depth",range:[.58,1],feather:.35},adjust:{contrast:1.08,saturation:1.05,temperature:8}}]:[{name:Be("Xa (trên)","Far (top)",e),window:{...nn,type:"gradient",cx:.5,cy:.45,w:1,h:1,rot:0,feather:.5},adjust:{contrast:.82,saturation:.85,temperature:-14,exposure:.07}},{name:Be("Gần (dưới)","Near (bottom)",e),window:{...nn,type:"gradient",cx:.5,cy:.7,w:1,h:1,rot:0,feather:.5},invert:!0,adjust:{contrast:1.08,saturation:1.05,temperature:8}}]},{id:"practical-lights",name:"Đèn ấm trong cảnh",en:"Warm practical lights",icon:"✹",group:"depth",build:({locale:t})=>[{name:Be("Đèn ấm","Warm lamps",t),qualifier:{hue:40,hueWidth:70,satMin:.15,satMax:1,lumMin:.62,lumMax:1,soft:.3},adjust:{temperature:18,saturation:1.2,exposure:.12}}]}]),my=new Map(fy.map(t=>[t.id,t])),gy=t=>my.get(t);function Rs(t,{face:e=!1,person:o=!1,depth:r=!1,locale:n="vi"}={}){const a=my.get(t);if(!a)throw Error("Unknown window preset");return a.faceOnly&&!e?null:a.build({face:e,person:o,depth:r,locale:n})}function o8(t){const e=a=>JSON.stringify([a.window,a.adjust??null,!!a.invert]);let o=0;const r=["vi","en"].map(a=>[Rs("depth-ai",{depth:!1,locale:a}),Rs("depth-ai",{depth:!0,locale:a})]),n=t.map(a=>{for(const[i,l]of r)for(let p=0;p<i.length;p++)if(e(a)===e(i[p]))return o++,{...l[p],...a.on===!1?{on:!1}:{},name:a.name===i[p].name?l[p].name:a.name};return a});return{list:o?n:t,upgraded:o}}function r8(t,e,o){const r=Rs(e,o);if(!r)throw Error("This preset needs a face track — detect faces first");if(t.length+r.length>oc)throw Error(`Up to ${oc} power windows per clip`);return[...t,...r]}const XC=Object.freeze(Object.defineProperty({__proto__:null,WINDOW_PRESETS:fy,presetWindows:Rs,upgradeDepthWindows:o8,windowPreset:gy,withPreset:r8},Symbol.toStringTag,{value:"Module"})),Xl=["exposure","contrast","saturation","brightness","hue"],n8=Yb.map(t=>t[0]),a8=Object.keys(Uc),i8=Object.keys(bu),s8=["exposure","contrast","saturation","hue","temperature","tint"],yo=t=>Math.round(t*1e4)/1e4,ar=(t,e,o)=>Math.max(e,Math.min(o,t)),l8={cx:[-.5,1.5],cy:[-.5,1.5],w:[.02,3],h:[.02,3],rot:[-180,180],feather:[0,1]};function yy(t,e={}){const o={...e};if(!t||typeof t!="object")return o;for(const r of n8){const n=t[r];if(!n||typeof n!="object")continue;const a={};for(const i of a8)if(n[i]!=null){const[l,p]=Uc[i],c=Math.round(ar(Number(n[i])||0,l,p)*1e3)/1e3;c&&(a[i]=c)}Object.keys(a).length?o[r]=a:delete o[r]}return o}function c8(t){if(!t)return null;const e=typeof t=="string"?{preset:t}:typeof t=="object"?t:null;if(!e)return null;if(e.preset!=null&&!Object.hasOwn(bu,e.preset))throw Error(`qualifier: ${i8.join(" | ")} or {hue, hueWidth, satMin, satMax, lumMin, lumMax, soft}`);const o=e.preset!=null?bu[e.preset]:tw,r=(a,i,l,p)=>{const c=e[a]??(p?e[p]:void 0);return c==null||!Number.isFinite(+c)?o[a]:yo(ar(+c,i,l))},n={hue:(r("hue",-360,720)%360+360)%360,hueWidth:r("hueWidth",1,360,"width"),satMin:r("satMin",0,1),satMax:r("satMax",0,1),lumMin:r("lumMin",0,1),lumMax:r("lumMax",0,1),soft:r("soft",0,1)};return n.satMin>n.satMax&&([n.satMin,n.satMax]=[n.satMax,n.satMin]),n.lumMin>n.lumMax&&([n.lumMin,n.lumMax]=[n.lumMax,n.lumMin]),n}function p8(t){if(!t||typeof t!="object")return;const e={};for(const o of["lift","gamma","gain"]){const r=t[o];if(!r||typeof r!="object")continue;let n=ar(Number(r.x)||0,-1,1),a=ar(Number(r.y)||0,-1,1);const i=Math.hypot(n,a);i>1&&(n/=i,a/=i);const l={x:yo(n),y:yo(a),l:yo(ar(Number(r.l)||0,-1,1))};(l.x||l.y||l.l)&&(e[o]=l)}return Object.keys(e).length?e:void 0}function u8(t){if(!t||typeof t!="object")return;const e={};for(const o of["master","r","g","b"]){const r=t[o];if(!Array.isArray(r))continue;const n=[];for(const a of r.map(i=>Array.isArray(i)?{x:i[0],y:i[1]}:i).filter(i=>i&&Number.isFinite(+i.x)&&Number.isFinite(+i.y)).sort((i,l)=>i.x-l.x)){const i=yo(ar(+a.x,0,1)),l=yo(ar(+a.y,0,1));(!n.length||i>n.at(-1)[0]+.001)&&n.push([i,l])}n.length>=2&&n.length<=16&&(e[o]=n)}return Object.keys(e).length?e:void 0}function d8(t,{hasFace:e=!1,hasPerson:o=!1,pending:r=null}={}){const n=(f,m,y,$)=>t[f]==null?$:yo(ar(t[f],m,y));let a;if(t.shape==="whole"||t.shape==="qualifier")a=null;else if(["face","skin","eyes","lips"].includes(t.shape)){if(!e){if(!r)return null;r.add("face")}const f=bs(t.shape==="face"?"face":t.shape);a={...f,cx:n("cx",-.5,.5,0),cy:n("cy",-.5,.5,0),w:n("w",.5,2,1),h:n("h",.5,2,n("w",.5,2,1)),feather:n("feather",0,1,f.feather)}}else if(t.shape==="person"){if(!o){if(!r)return null;r.add("person")}a=zl()}else if(t.shape==="depth"){const f=n("from",0,.99,0),m=n("to",.01,1,.42);a={...nn,type:"depth",range:[Math.min(f,m-.01),Math.max(m,f+.01)],feather:n("feather",0,1,.35)}}else{const f=t.shape==="gradient"?{cx:.5,cy:.4,w:1,h:1,rot:0,feather:.3}:{...nn};a={type:t.shape==="rect"?"rect":t.shape==="gradient"?"gradient":"ellipse",...Object.fromEntries(Object.entries(l8).map(([m,[y,$]])=>[m,n(m,y,$,f[m])]))}}const i={};for(const f of s8)if(t[f]!=null){const{min:m,max:y,base:$}=Qb[f],x=yo(ar(t[f],m,y));x!==$&&(i[f]=f==="hue"||f==="temperature"||f==="tint"?Math.round(x):x)}const l=p8(t.wheels??{lift:t.lift,gamma:t.gamma,gain:t.gain}),p=u8(t.curves),s=t.shape==="qualifier"||t.qualifier!=null&&a&&["ellipse","rect","gradient"].includes(a.type)?c8(t.qualifier??"skin"):null,h={name:String(t.name||"").slice(0,40)||void 0,...s?{qualifier:s}:{},...a?{window:a}:s?{}:{whole:!0},...t.invert&&(a||s)?{invert:!0}:{},...Object.keys(i).length?{adjust:i}:{},...l?{wheels:l}:{},...p?{curves:p}:{},...t.on===!1?{on:!1}:{}};if(t.blur!=null&&t.blur>0&&(h.blur=yo(ar(t.blur,0,1))),t.sharpen!=null&&t.sharpen>0&&(h.sharpen=Math.round(ar(t.sharpen,0,100))),t.cst?h.cst={from:typeof t.cst=="string"?t.cst:t.cst.from}:t.look&&(h.look=typeof t.look=="string"?{preset:t.look}:{preset:t.look.preset,...t.look.mix!=null?{mix:yo(ar(t.look.mix,0,1))}:{}}),t.fx){const f=typeof t.fx=="string"?{type:t.fx}:t.fx;h.fx={type:f.type,...f.amount!=null?{amount:yo(ar(f.amount,0,1))}:{},...f.size!=null?{size:yo(ar(f.size,0,1))}:{}}}if((t.branch==="parallel"||t.branch==="layer")&&(h.branch=t.branch),t.mixer){const f=yy(t.mixer);Object.keys(f).length&&(h.mixer=f)}return h.name||delete h.name,h}function h8(t,e,{locale:o="vi",notes:r=[],queue:n=!1}={}){const a={};for(const l of Xl)if(e[l]!=null){const[p,c]=Fu[l];a[l]=yo(Math.max(p,Math.min(c,e[l])))}let i={...t.grade||{}};if(e.recipe&&(i=QE(i,e.recipe),r.push(`recipe:${e.recipe}`)),e.mixer){const l=yy(e.mixer,i.mixer||{});Object.keys(l).length?i.mixer=l:delete i.mixer,r.push("mixer")}for(const[l,{min:p,max:c}]of Object.entries(rh))e[l]!=null&&(i[l]=Math.round(Math.max(p,Math.min(c,e[l]))));if(e.lut&&(i.lut=qb({id:e.lut.id,name:String(e.lut.name??"LUT").slice(0,80),...e.lut.mix!=null?{mix:Math.max(0,Math.min(1,Number(e.lut.mix)||0))}:{}}),r.push("lut")),e.wheels){const l={...i.wheels||{}};for(const p of Zb){const c=e.wheels[p];if(!c)continue;let s=Math.max(-1,Math.min(1,c.x)),h=Math.max(-1,Math.min(1,c.y));const f=Math.hypot(s,h);f>1&&(s/=f,h/=f),l[p]={x:yo(s),y:yo(h),l:yo(Math.max(-1,Math.min(1,c.l)))}}i.wheels=l}if(e.curves){const l={...i.curves||{}};for(const p of["master","r","g","b"]){const c=e.curves[p];if(!c)continue;const s=[];for(const h of[...c].sort((f,m)=>f.x-m.x)){const f=yo(Math.max(0,Math.min(1,h.x))),m=yo(Math.max(0,Math.min(1,h.y)));(!s.length||f>s.at(-1)[0]+.001)&&s.push([f,m])}s.length>=2&&s.length<=16&&(l[p]=s)}i.curves=l}if(e.windows){const l=n?new Set:null,p={face:!!t.hasFace,person:!!t.hasPerson,depth:!!t.hasDepth,locale:o},c=[];for(const h of e.windows.presets||[]){const f=l?gy(h)?.needs:null,m=f==="face"?!p.face:f==="person"?!p.person:!1,y=Rs(h,m?{...p,[f]:!0}:p);y?(c.push(...y),r.push(`preset:${h}`),m&&l.add(f)):r.push(`skipped:${h}`)}for(const h of e.windows.custom||[]){const f=d8(h,{hasFace:p.face,hasPerson:p.person,pending:l});f?c.push(f):r.push(`skipped:${h.shape}`)}if(l)for(const h of l)r.push(`pending:${h}`);const s=[...e.windows.mode==="replace"?[]:Md(i),...c];if(s.length>oc)throw Error(`Up to ${oc} nodes (power windows) per clip`);i=$d(i,s),c.length&&r.push(`windows:${c.length}`)}for(const l of Object.keys(rh))i[l]||delete i[l];return Jb(i),a.grade=Object.keys(i).length?i:void 0,a}const Mo=Object.freeze({roles:["lead","hero","tail"],sides:["auto","left","right"],styles:["condensed","serif","script"],accents:Object.freeze({red:"#e11d2a",green:"#22c55e"}),maxLines:5,maxChars:40,minDuration:1,maxDuration:12,margin:.04,gap:.03,minColumn:.2,maxColumn:.44,fontSize:96}),f8={condensed:{lead:{font:"Dancing Script",weight:700,scale:.74},hero:{font:"Anton",weight:400,scale:3,tracking:.01,caps:!0},tail:{font:"Oswald",weight:600,scale:.95,tracking:.06,caps:!0}},serif:{lead:{font:"Playfair Display",weight:400,italic:!0,scale:.66},hero:{font:"Playfair Display",weight:900,scale:2.4,caps:!0},tail:{font:"Oswald",weight:500,scale:.9,tracking:.08,caps:!0}},script:{lead:{font:"Dancing Script",weight:700,scale:.9},hero:{font:"Anton",weight:400,scale:3,tracking:.01,caps:!0},tail:{font:"Dancing Script",weight:700,scale:1}}},m8={lead:{duration:.45,easing:"easeOutCubic",from:{opacity:0,y:.35,blur:.15}},hero:{duration:.32,easing:"easeOutBack",from:{opacity:0,scale:2.2,blur:.2}},tail:{duration:.45,easing:"easeOutQuart",from:{opacity:0,x:1.2}}},Kr=t=>Math.round(t*1e3)/1e3,Tc=(t,e,o)=>Math.max(e,Math.min(o,t)),Wr=t=>{throw Error(`lockup: ${t}`)};function by(t,e){if(t==null||t==="")return null;if(t==="accent")return e;if(Object.hasOwn(Mo.accents,t))return Mo.accents[t];if(typeof t=="string"&&Ok.test(t))return t.toLowerCase();Wr(`colour "${String(t).slice(0,20)}" must be #rrggbb, red, green or accent`)}function g8(t,e){(!Array.isArray(t)||!t.length||t.length>Mo.maxLines)&&Wr(`lines needs 1–${Mo.maxLines} entries`);const o=t.map((r,n)=>{const a=typeof r=="string"?{text:r}:r;(!a||typeof a!="object")&&Wr(`lines[${n}] must be {text, role}`);const i=typeof a.text=="string"?a.text.replace(/\s+/g," ").trim():"";return(!i||i.length>Mo.maxChars)&&Wr(`lines[${n}].text needs 1–${Mo.maxChars} characters`),a.role!=null&&!Mo.roles.includes(a.role)&&Wr(`lines[${n}].role must be lead, hero or tail`),{text:i,role:a.role??(t.length===1||n>0?"hero":"lead"),color:by(a.color,e)}});if(o.some(r=>r.role==="hero")||Wr("needs at least one hero line (the big word)"),!o.some(r=>r.color)&&o.length>1){const r=o.map(n=>n.role).lastIndexOf("hero");o[r]={...o[r],color:e}}return o}function y8(t,e,o,r,{W:n,H:a}){const i=a>n*1.1,l=i?ve.halfWidth.portrait:ve.halfWidth.landscape,p=[o,(o+r)/2,Math.max(o,r-.05)].map(c=>xc(t,e,Tc(c,t.start,t.start+t.duration-.001),{W:n,H:a})).filter(Boolean);return p.length?{x0:Math.min(...p.map(c=>c.x))-l,x1:Math.max(...p.map(c=>c.x))+l,top:Math.min(...p.map(c=>c.y))-ve.head,faceY:Math.max(...p.map(c=>c.y)),assumed:p.every(c=>c.assumed),port:i}:null}function b8(t,e="auto",{W:o=1280,H:r=720}={}){const{margin:n,gap:a,minColumn:i,maxColumn:l}=Mo,p=r>o*1.1,c=t??{x0:.5-ve.halfWidth.landscape,x1:.5+ve.halfWidth.landscape,top:.24,faceY:.38},s={left:Math.max(0,c.x0-a-n),right:Math.max(0,1-n-(c.x1+a))},h=x=>!p&&s[x]>=i,f=e==="left"||e==="right"?e:s.left>=s.right?"left":"right",m=f==="left"?"right":"left",y=h(f)?f:h(m)?m:null;if(y){const x=Math.min(l,s[y]),E=y==="left"?n:c.x1+a,v=y==="left"?c.x0-a:1-n,S=y==="left"?Math.min((E+v)/2,v-x/2):Math.max((E+v)/2,E+x/2);return{mode:"side",side:y,cx:Kr(S),width:Kr(x),moved:y!==f&&e!=="auto"}}const $=c.top>(p?.3:.36);return{mode:"band",band:$?"top":"lower",cy:Kr($?Math.max(.12,c.top/2):Math.min(.86,(c.faceY+ve.chin+1)/2)),width:.86,moved:e!=="auto"}}function w8(t,e){let o=Ql(t,Array.isArray(e?.words)&&e.words.length?e.words:null);return!o.length&&Array.isArray(e?.transcript)&&e.transcript.length&&(o=Ql(t,Xc(e.transcript))),o.map(r=>({start:t.start+r.start,end:t.start+r.end,key:wg(r.word)}))}function k8(t,e,o,r){const n=Math.min(10,r-.35),a=(e||[]).filter(s=>s.start>=o-.25&&s.start<o+r),i=t.map(()=>null);let l=0,p=0;if(t.forEach((s,h)=>{const f=wg(s);for(let m=l;m<Math.min(a.length,l+8);m++)if(f&&(a[m].key===f||f.length>2&&a[m].key.startsWith(f))){i[h]=a[m].start-o,l=m+1,p++;break}}),!p)return{times:t.map((s,h)=>Kr(Tc(.15+h*.28,0,n))),matched:0};for(let s=0;s<i.length;s++){if(i[s]!==null)continue;let h=s-1;for(;h>=0&&i[h]===null;)h--;let f=s+1;for(;f<i.length&&i[f]===null;)f++;const m=h>=0?i[h]:null,y=f<i.length?i[f]:null;i[s]=m!==null&&y!==null?m+(y-m)*(s-h)/(f-h):m!==null?m+.25*(s-h):y-.25*(f-s)}let c=0;return{times:i.map(s=>{const h=Kr(Tc(Math.max(c,s),0,n));return c=h,h}),matched:p}}function x8(t,{clips:e=[],materials:o=[],W:r=1280,H:n=720}={}){const a=e.find(z=>z.id===t.clipId);(!a||a.kind!=="video"||a.title||a.motion||a.shape)&&Wr("clipId must be the speaker's video clip");const i=Number.isFinite(t.at)?t.at:Number.isFinite(t.start)?t.start:a.start,l=Number.isFinite(t.duration)?t.duration:3;(l<Mo.minDuration||l>Mo.maxDuration)&&Wr(`duration ${Mo.minDuration}–${Mo.maxDuration} s`),(i<a.start-.05||i>=a.start+a.duration)&&Wr("at must fall inside the speaker clip");const p=t.style==null?"condensed":t.style;Mo.styles.includes(p)||Wr("style must be condensed, serif or script");const c=t.side==null?"auto":t.side;Mo.sides.includes(c)||Wr("side must be auto, left or right");const s=by(t.color,Mo.accents.red)??Mo.accents.red,h=g8(t.lines,s),f=f8[p],m=o.find(z=>z.id===a.nodeId),y=b8(y8(a,m,i,i+l,{W:r,H:n}),c,{W:r,H:n}),$=h.map(z=>f[z.role].caps?z.text.toLocaleUpperCase("vi"):z.text),x=$.flatMap(z=>z.split(" ").filter(Boolean)),{times:E}=k8(x,w8(a,m),i,l);let v=0;const S=$.map((z,N)=>{const F=z.split(" ").filter(Boolean).length,K=h[N].role,_=m8[K],q=E.slice(v,v+F).map(U=>Kr(Math.max(0,K==="hero"?U-.06:U)));return v+=F,K==="tail"?{lines:[N],unit:"line",at:[q[0]],duration:_.duration,easing:_.easing,from:{..._.from,x:y.mode==="side"&&y.side==="right"?_.from.x:-_.from.x}}:{lines:[N],unit:"word",at:q,duration:_.duration,easing:_.easing,from:_.from}}),k=y.mode==="band"?.55:1,b={weight:700,lineHeight:1.25,uppercase:!1,stack:"ink",gap:.12,maxWidth:y.width,lines:h.map(z=>{const N=f[z.role];return{scale:Kr(N.scale*k),font:N.font,weight:N.weight,...N.italic?{italic:!0}:{},...N.tracking!==void 0?{tracking:N.tracking}:{},...z.color?{fill:z.color}:{}}}),layers:[{type:"text",fill:"{color}",shadow:{color:"#000000",blur:.22,x:0,y:.03},opacity:1}]},A=Math.min(1,r*720/1280/n),I=A>.99,P=y.mode==="side"?{posX:Kr(y.cx-.5),posY:0}:I?{posX:0,posY:0}:{posX:0,posY:Kr(Tc(y.cy-.5,-.5+A/2,.5-A/2))},C=y.mode==="band"&&I?y.band:"center";return{addText:{op:"addText",text:$.join(`
|
|
203
|
+
`),start:Kr(i),duration:Kr(l),fontSize:Mo.fontSize,color:"#ffffff",accentColor:s,placement:C,align:"center",fontFamily:f.hero.font,design:b,animation:{version:1,in:S,out:"none"},...P,...t.track!=null?{track:t.track}:{}},placement:y}}const M8=Object.freeze(["wide","medium","close","side","phone"]),Ym=Object.freeze(["speaker","sentence","beat","mixed"]),Ir=Object.freeze({minShot:2.5,maxShot:8,minAngles:2,maxAngles:8,lead:.12,turnGap:.6}),Oc=t=>String(t??"").normalize("NFD").replace(/\p{M}/gu,"").replace(/đ/g,"d").replace(/Đ/g,"D").toLowerCase(),$8=(t,e)=>t.test(e),v8=[["phone",/(?<![a-z])(phone|iphone|android|dien thoai|mobile|selfie|dt)(?![a-z])/],["close",/(?<![a-z])(close[ -]?up|closeup|close|cu|ecu|mcu|can canh|can mat|goc can|tight)(?![a-z])/],["wide",/(?<![a-z])(wide|ws|ews|establishing|master|toan canh|goc rong|canh rong|rong)(?![a-z])/],["side",/(?<![a-z])(side|profile|goc ben|ben canh|goc nghieng|nghieng|goc ngang)(?![a-z])/],["medium",/(?<![a-z])(medium|mid|ms|trung canh|vua|waist)(?![a-z])/]],E8=[["close",/(close[ -]?up|extreme close|can canh|can mat|tight shot)/],["wide",/(wide shot|wide angle|establishing|full shot|long shot|toan canh|canh rong|goc rong)/],["side",/(profile|side view|from the side|goc nghieng|nhin nghieng|goc ben)/],["medium",/(medium shot|mid shot|waist|trung canh|ngang nguc|ngang hong)/]],S8=t=>{const e=t.filter(Number.isFinite).sort((o,r)=>o-r);return e.length?e[Math.floor(e.length/2)]:null};function I8(t,e=[]){if(M8.includes(t?.angle))return{role:t.angle,from:"user"};const o=Oc(t?.label).replace(/\.[a-z0-9]{2,4}$/,"").replace(/[_.]+/g," ");for(const[l,p]of v8)if($8(p,o))return{role:l,from:"name"};const r=Oc([t?.description,...Array.isArray(t?.scenes)?t.scenes.slice(0,20).map(l=>l?.description):[]].filter(Boolean).join(" ")),n=E8.map(([l,p])=>[l,(r.match(new RegExp(p.source,"g"))||[]).length]).filter(([,l])=>l>0).sort((l,p)=>p[1]-l[1]);if(n.length)return{role:n[0][0],from:"analysis"};const a=S8((Array.isArray(t?.scenes)?t.scenes:[]).map(l=>Number(l?.subjectH)));return a!=null?{role:a>=.3?"close":a>=.16?"medium":"wide",from:"size"}:(l=>Number(l?.height)>Number(l?.width)*1.1)(t)&&e.some(l=>l!==t&&Number(l?.width)>Number(l?.height))?{role:"phone",from:"shape"}:{role:null,from:null}}const wy=/\?|(?<![\p{L}])(sao|tai sao|vi sao|the nao|bao nhieu|khong nhi|co khong|phai khong|why|how|what|which|who|when|where)(?![\p{L}])/u,ky=/!|(?<![\p{L}])(quan trong|nhat dinh|tuyet doi|chac chan|never|always|must|important|really|absolutely)(?![\p{L}])/u;function A8(t){const e=(Array.isArray(t)?t:[]).filter(n=>Number.isFinite(n?.start)&&Number.isFinite(n?.end)&&typeof n.word=="string").sort((n,a)=>n.start-a.start),o=[];let r=null;for(let n=0;n<e.length;n++){const a=e[n],i=e[n-1],l=i?a.start-i.end:1/0;(!r||l>=Ir.turnGap||/[.?!…]["”')\]]*$/.test(i?.word??""))&&(r&&o.push(r),r={start:a.start,end:a.end,words:[],gapBefore:l}),r.words.push(a.word.trim()),r.end=Math.max(r.end,a.end)}return r&&o.push(r),o.map(n=>{const a=n.words.join(" "),i=Oc(a);return{start:n.start,end:n.end,text:a,words:n.words.length,gapBefore:n.gapBefore,question:wy.test(i),emphasis:ky.test(i)||n.words.length<=5}})}function C8(t){const e=(Array.isArray(t)?t:[]).filter(o=>Number.isFinite(o?.start)&&Number.isFinite(o?.end)&&typeof o.text=="string").sort((o,r)=>o.start-r.start);return e.map((o,r)=>{const n=Oc(o.text),a=o.text.trim().split(/\s+/).filter(Boolean).length;return{start:o.start,end:o.end,text:o.text,words:a,gapBefore:r?o.start-e[r-1].end:1/0,question:wy.test(n),emphasis:ky.test(n)||a<=5}})}const j8={close:t=>1+(t.question||t.emphasis?3:0)-(t.long?1:0),medium:t=>2+(t.long?1:0),wide:t=>1+(t.long?3:0)+(t.crowd?3:0),side:()=>1.2,phone:()=>.5};function T8({angles:t,span:e,sentences:o=[],beats:r=[],gaps:n=[],mode:a="sentence",minShot:i=Ir.minShot,maxShot:l=Ir.maxShot,wideEvery:p=null,crowd:c=()=>!1}){const[s,h]=e,f=1e-6,m=[],y=A=>A.start-Math.min(Ir.lead,Number.isFinite(A.gapBefore)?A.gapBefore/2:Ir.lead);if(a==="sentence"||a==="mixed")for(const A of o)m.push({t:y(A),strength:Math.min(1,Number.isFinite(A.gapBefore)?A.gapBefore:1)+.5});if(a==="speaker"){const A=o.filter(I=>!(I.gapBefore<Ir.turnGap));for(const I of A.length>=2?A:o)m.push({t:y(I),strength:1.5})}if(a==="beat"||a==="mixed")for(const A of r)m.push({t:A,strength:a==="beat"?1.2:.4});for(const A of t)for(const I of[A.from,A.to])m.push({t:I,strength:.3});const $=m.filter(A=>A.t>s+f&&A.t<h-f).sort((A,I)=>A.t-I.t||I.strength-A.strength),x=Math.min(l,Math.max(i,(i+l)/2-.5)),E=(A,I,P)=>{let C=null;for(const z of n){const N=(z.start+z.end)/2;if(!(N>A&&N<I))continue;const F=Math.min(1,z.end-z.start)-Math.abs(N-P)*.02;(!C||F>C.s+1e-9)&&(C={t:N,s:F})}return C?C.t:null},v=[s];for(let A=s;A<h-f;){const I=h-A;let P;if(I<=l+f)P=h;else if(I<2*i)P=A+I/2;else{const C=A+i,z=Math.min(A+l,h-i),N=$.filter(F=>F.t>=C-f&&F.t<=z+f);N.length?P=N.reduce((F,K)=>{const _=K.strength*1.5-Math.abs(K.t-A-x)/2;return!F||_>F.s+1e-9?{t:K.t,s:_}:F},null).t:P=E(C,z,A+x)??Math.min(A+x,z),P>A+f||(P=Math.min(h,A+l))}v.push(P),A=P}const S=(A,I)=>{const P=o.filter(C=>C.end>A+.05&&C.start<I-.05);return{question:P.some(C=>C.question),emphasis:P.some(C=>C.emphasis)&&P.every(C=>C.words<=12),long:P.some(C=>C.end-C.start>6||C.words>18)||I-A>6&&P.length<=1&&P.some(C=>C.words>10),crowd:!!c((A+I)/2)}},k=[];let b=-1/0;for(let A=0;A+1<v.length;A++){const I=v[A],P=v[A+1],C=S(I,P),z=t.filter(ot=>ot.from<=I+.02&&ot.to>=P-.02),N=z.length?z:t.filter(ot=>ot.to>I&&ot.from<P).sort((ot,G)=>Math.min(G.to,P)-Math.max(G.from,I)-(Math.min(ot.to,P)-Math.max(ot.from,I))).slice(0,1);if(!N.length)continue;const F=k.at(-1),K=k.at(-2);let _=null;N.forEach(ot=>{const G=ot.role??"medium";let J=j8[G](C);G==="wide"&&(A===0||p&&I-b>=p)&&(J+=A===0?2.5:6),F&&F.id===ot.id&&F.end>=I-.02&&(J-=100),K&&K.id===ot.id&&(J-=.8),(!_||J>_.s+1e-9)&&(_={x:ot,s:J,role:G})});const q=C.question?"question":C.emphasis?"emphasis":C.long?"explanation":C.crowd?"group":_.role==="wide"&&A===0?"opening":"rhythm",U=Math.max(I,_.x.from),rt=Math.min(P,_.x.to);if(F&&F.id===_.x.id&&Math.abs(F.end-U)<.02&&rt-F.start<=l+f){F.end=rt;continue}k.push({id:_.x.id,start:U,end:rt,role:_.role,why:q}),_.role==="wide"&&(b=P)}return k}const ao=t=>Number.isFinite(t)?Number(t):null,O8={wide:"toàn",medium:"trung",close:"cận",side:"bên",phone:"điện thoại"};function Qa(t){if(!t||typeof t.syncGroup!="string"||!t.syncGroup)return null;const e=t.syncMain?0:ao(t.syncOffset);return e===null?null:{o:e,d:(ao(t.syncDrift)??0)*1e-6,group:t.syncGroup}}const en=(t,e)=>e*(1+t.d)+t.o,qm=(t,e)=>(e-t.o)/(1+t.d);function P8(t,e,o=[],r={},{newId:n}={}){const a=[...new Set((Array.isArray(e?.materials)?e.materials:Array.isArray(e?.materialIds)?e.materialIds:[]).filter(j=>typeof j=="string"))];if(a.length<Ir.minAngles||a.length>Ir.maxAngles)throw Error(`multicam needs ${Ir.minAngles}–${Ir.maxAngles} video materials (the synced camera angles)`);const i=a.map(j=>{const O=o.find(B=>B.id===j);if(!O)throw Error(`Không thấy material ${j}`);if(O.kind!=="video"||!O.url)throw Error(`${O.label||j}: multicam angles must be videos`);if(!(ao(O.duration)>0))throw Error(`${O.label||j}: unknown duration — open it in Media first`);const L=Qa(O);if(!L)throw Error(`${O.label||j} chưa được đồng bộ — Media → Multicam → Đồng bộ nhiều góc máy trước (or MCP sync_multicam)`);return{m:O,s:L}}),l=i[0].s.group;if(i.some(j=>j.s.group!==l))throw Error("These videos were synced in different groups — sync them together first");const p=e.mode??null;if(p!==null&&!Ym.includes(p))throw Error(`multicam mode must be ${Ym.join(" / ")}`);const c=ao(e.minShot)??Ir.minShot,s=ao(e.maxShot)??Ir.maxShot,h=ao(e.wideEvery);if(c<1||c>20)throw Error("minShot must be 1–20 s");if(s<c+.5||s>60)throw Error("maxShot must be ≥ minShot + 0.5 and ≤ 60 s");if(h!==null&&(h<5||h>300))throw Error("wideEvery must be 5–300 s");const f=o.filter(j=>Qa(j)?.group===l&&(j.kind==="video"||j.kind==="audio")&&ao(j.duration)>0&&j.url),m=typeof e.main=="string"?e.main:null;if(m&&!a.includes(m))throw Error("main must be one of the multicam materials");const y=i.find(j=>j.m.id===m)??i.find(j=>j.m.syncMain)??i[0];let $=null;if(typeof e.audioFrom=="string"){const j=f.find(O=>O.id===e.audioFrom);if(!j)throw Error("audioFrom must be a synced video / audio of the same group");$={m:j,s:Qa(j)}}else{const j=L=>ao(L.syncAudio)??-1/0,O=[...f].sort((L,B)=>j(B)-j(L)||(B.id===y.m.id)-(L.id===y.m.id)||(L.id<B.id?-1:1))[0];$=O&&j(O)>j(y.m)?{m:O,s:Qa(O)}:{m:y.m,s:y.s}}const x=j=>({from:j.s.o,to:en(j.s,ao(j.m.duration))}),E=i.map(j=>({...j,role:I8(j.m,i.map(O=>O.m)).role,...x(j)})),v=x($);let S=null,k=Math.max(v.from,Math.min(...E.map(j=>j.from))),b=Math.min(v.to,Math.max(...E.map(j=>j.to)));if(e.clipId){if(S=t.find(L=>L.id===e.clipId),!S)throw Error("Clip not found");const j=o.find(L=>L.id===S.nodeId),O=Qa(j);if(!O||O.group!==l||!["video","audio"].includes(S.kind))throw Error("clipId must be a clip of one of the synced videos");if(S.speedRamp?.length||S.timeRemap||(S.playbackRate??1)!==1||S.reverse)throw Error("The clip to replace must play at normal speed");k=Math.max(k,en(O,S.inPoint||0)),b=Math.min(b,en(O,(S.inPoint||0)+S.duration))}ao(e.inPoint)!==null&&(k=Math.max(k,ao(e.inPoint))),ao(e.duration)!==null&&(b=Math.min(b,k+Math.max(0,ao(e.duration))));let A=t.filter(j=>j!==S);const I=ht(Math.max(0,ao(e.start)??(S?S.start:A.filter(j=>j.track===0).reduce((j,O)=>Math.max(j,O.start+O.duration),0))));let P="";if(I+(b-k)>Tn&&(b=k+Tn-I,P=` (cut at the ${Tn/60}-minute timeline limit)`),!(b-k>=c))throw Error("The synced videos do not overlap the sound long enough for a multicam edit");const C=[y,$,...i].find(j=>j.m.words?.length)??[y,$,...i].find(j=>j.m.transcript?.length)??null,z=j=>(Array.isArray(j)?j:[]).filter(O=>Number.isFinite(O?.start)&&Number.isFinite(O?.end)).map(O=>({...O,start:en(C.s,O.start),end:en(C.s,O.end)})),N=C?.m.words?.length?z(C.m.words):[],F=N.length?A8(N):C?C8(z(C.m.transcript)):[],K=[];for(let j=1;j<N.length;j++)N[j].start-N[j-1].end>=.12&&K.push({start:N[j-1].end,end:N[j].start});if(!N.length)for(const j of[y,$])for(const O of Array.isArray(j.m.pauses)?j.m.pauses:[])Number.isFinite(O?.start)&&Number.isFinite(O?.end)&&K.push({start:en(j.s,O.start),end:en(j.s,O.end)});const _=[$,...f.map(j=>({m:j,s:Qa(j)}))].find(j=>Array.isArray(j.m.beats?.beats)&&j.m.beats.beats.length&&(j.m.beats.confidence??0)>=.35),q=_?_.m.beats.beats.map(j=>en(_.s,j)):[],U=p??(F.length?"sentence":q.length?"beat":"sentence");if(U==="beat"&&!q.length)throw Error("mode beat needs a song with a beat grid in the group (Media → Nhạc, analysed)");const rt=E.filter(j=>j.role==="wide"||j.m.id===y.m.id),ot=j=>rt.some(O=>(O.m.scenes||[]).some(L=>Number(L?.people)>=2&&en(O.s,L.start)<=j&&en(O.s,L.end)>j)),G=T8({angles:E.map(j=>({id:j.m.id,role:j.role,from:j.from,to:j.to})),span:[k,b],sentences:F,beats:q,gaps:K,mode:U,minShot:c,maxShot:s,wideEvery:h,crowd:ot});if(!G.length)throw Error("No camera angle covers the synced sound");const J=I+(b-k),Z=j=>A.some(O=>O.track===j&&O.start<J-1e-6&&O.start+O.duration>I+1e-6),at=ao(e.track),D=at!==null&&!Z(at)&&!r[at]?.locked?at:!Z(0)&&!r[0]?.locked&&!r[0]?.hidden?0:Zt(A,r,I,J,null).track,H=Ci.find(j=>!r[j]?.locked&&!Z(j));if(H===void 0)throw Error("Không còn hàng audio trống cho âm thanh multicam");if(A.length+G.length+1>Cs)throw Error(`Tối đa ${Cs} clip — chọn đoạn ngắn hơn (inPoint / duration) hoặc maxShot dài hơn`);const ut=[],gt=[],xt=(j,O)=>j<=O+.001?ht(j):Math.floor(O*be+1e-6)/be,u=+Math.max(0,qm($.s,k)).toFixed(4),st=xt(b-k,ao($.m.duration)-u),V={id:n(),nodeId:$.m.id,track:H,start:I,duration:st,inPoint:u,volume:1,url:$.m.url,...$.m.gcsUri?{gcsUri:$.m.gcsUri}:{},kind:"audio",label:`${$.m.label||"Audio"} · multicam audio`,sourceDuration:ao($.m.duration)};ut.push(V.id),gt.push(V);const d={};for(const j of G){const O=E.find(lt=>lt.m.id===j.id),L=ht(I+j.start-k),B=ht(I+j.end-k),X=+Math.max(0,qm(O.s,k+(L-I))).toFixed(4),Q=xt(B-L,ao(O.m.duration)-X);if(Q<1/be)continue;const et={id:n(),nodeId:O.m.id,track:D,start:L,duration:Q,inPoint:X,volume:0,url:O.m.url,...O.m.gcsUri?{gcsUri:O.m.gcsUri}:{},kind:"video",label:`${O.m.label||"Video"} · ${O8[j.role]??j.role}`,sourceDuration:ao(O.m.duration)};ut.push(et.id),gt.push(et),d[j.role]=(d[j.role]||0)+1}const T=`multicam: ${gt.length-1} shots from ${new Set(G.map(j=>j.id)).size} angles (${Object.entries(d).map(([j,O])=>`${j} ${O}`).join(", ")}), cut on ${U}${F.length?"":" (no transcript: pauses / rhythm)"}, audio from ${$.m.label||$.m.id}, ${ht(b-k)}s${P}`;return{clips:[...A,...gt],created:ut,note:T,plan:G}}const Zm=3,Jm=40,wl=[1,6],ds={frames:3,invert:t=>t%5===1||t%5===3,ticks:["pro-shutter-tick-1","pro-shutter-tick-2","pro-shutter-tick-3"],volume:.3},z8={rgb:"invert",luma:"luma-invert"},L8=30,N8=t=>!!t&&dg(t)&&(t.kind==="video"||t.kind==="image")&&!t.motion&&!t.lottie&&!t.geo&&!t.element&&!t.solid&&!t.adjust&&!t.nullLayer&&!t.title&&!t.shape;function F8(t,e={},{clipIds:o,at:r,frames:n,polarity:a=!1,style:i="anchor",newId:l=()=>`mt-${Math.random().toString(36).slice(2,9)}`}={}){const p=i==="strobe",c=[...new Set(Array.isArray(o)?o:[])];if(c.length<Zm||c.length>Jm)throw Error(`A montage needs ${Zm}–${Jm} clips`);const s=c.map(A=>t.find(I=>I.id===A));if(s.some(A=>!A))throw Error("Clip not found");if(s.some(A=>!N8(A)))throw Error("A montage takes filmed clips or photos only (no motion, text, shape or generator layers)");if(s.some(A=>e[A.track]?.locked))throw Error("Track đã khóa");const h=Math.round(Number.isFinite(n)?n:p?ds.frames:2);if(h<wl[0]||h>wl[1])throw Error(`Frames per shot must be ${wl[0]}–${wl[1]}`);const f=p?s.flatMap((A,I)=>ds.invert(I)?[{c:A,copy:!0,inv:"luma"},{c:A,inv:null}]:[{c:A,inv:null}]):s.map((A,I)=>({c:A,inv:a&&I%2?"rgb":null})),m=ht(h/L8),y=s[0].track,$=ht(Number.isFinite(r)?Math.max(0,r):Math.min(...s.map(A=>A.start))),x=$+m*f.length,E=t.find(A=>!c.includes(A.id)&&A.track===y&&A.kind!=="audio"&&A.start<x-1e-6&&A.start+A.duration>$+1e-6);if(E)throw Error(`No room for the montage on that track (${E.label??E.id} is in the way from ${$.toFixed(2)} to ${x.toFixed(2)} s)`);const v=(A,I,P,C)=>{const{transition:z,join:N,visualFadeIn:F,visualFadeOut:K,fadeInColor:_,fadeOutColor:q,enter:U,exit:rt,audioFadeIn:ot,audioFadeOut:G,...J}=A;let Z={...J,id:C,track:y,start:ht($+I*m),duration:m,posX:0,posY:0,volume:0};const at=A.playbackRate||1;A.kind==="video"&&Number.isFinite(A.sourceDuration)&&(A.inPoint||0)+m*at>A.sourceDuration&&(Z.inPoint=Math.max(0,A.sourceDuration-m*at));for(const H of["x","y"])Me(Z,H).length&&(Z={...Z,motionKeys:qr(Z,H,[])});const D=(Z.effects??[]).filter(H=>H.type!=="invert"&&H.type!=="luma-invert");return P&&D.push({type:z8[P],amount:1}),D.length?Z.effects=D:delete Z.effects,Z},S=f.map((A,I)=>v(A.c,I,A.inv,A.copy?l():A.c.id)),k=new Map(S.filter(A=>c.includes(A.id)).map(A=>[A.id,A]));let b=[...t.map(A=>k.get(A.id)??A),...S.filter(A=>!c.includes(A.id))];return p&&S.forEach((A,I)=>{const P=Ba(ds.ticks[I%ds.ticks.length]);if(P)try{b=[...b,zs(b,e,P,A.start,{volume:ds.volume,id:l()})]}catch{}}),b}const R8=Object.freeze(["map","cork","wall","paper"]),Qm=Object.freeze(["year","place","photo","file","news","type","counter","portrait"]),Zo=Object.freeze({maxStations:24,maxSeconds:120,layerSeconds:20,accent:"#d63a2f",text:160,hold:{year:2.4,place:2.2,photo:2.4,file:3.4,news:3.6,type:3.4,counter:3,portrait:4.4},width:{year:560,place:260,photo:250,file:390,news:440,type:760,counter:460,portrait:420},zoom:{year:1.2,place:1,photo:1.26,file:1.14,news:1.08,type:1.18,counter:1.06,portrait:1}}),t0=Object.freeze({year:[["pro-foley-typewriter",.1]],place:[["hit-soft",.15]],photo:[["camera-shutter",.1]],file:[["paper-slide",.05]],news:[["pro-whoosh-paper-fly",0]],stamp:[["pro-hit-stamp",0]],type:[["pro-foley-typewriter",.3]],counter:[["pro-riser-whoosh-riser",.2]],portrait:[["braam-cinematic",1.6]]}),io=t=>Math.round(t*100)/100,cd=t=>Math.round(t*1e3)/1e3,D8=/^#[0-9a-fA-F]{6}$/,jo=(t,e=Zo.text)=>typeof t=="string"?t.replace(/\s+/g," ").trim().slice(0,e):"",Up=t=>typeof t=="number"&&Number.isFinite(t)?t:typeof t=="string"&&t.trim()&&Number.isFinite(+t)?+t:null;function B8(t={},e=0){const o=Qm.includes(t?.kind)?t.kind:null;if(!o)throw Error(`documentary station ${e+1}: kind must be one of ${Qm.join(" | ")}`);const r={kind:o},n=Up(t.at),a=Up(t.hold),i=jo(t.say,120);n!==null&&(r.at=io(Math.max(0,n))),a!==null&&(r.hold=io(Math.min(12,Math.max(1,a)))),i&&(r.say=i);const l=(p,c)=>{const s=jo(t[p],c);if(!s)throw Error(`documentary station ${e+1} (${o}) needs ${p}`);return s};if(o==="year"){r.text=l("text",24);const p=jo(t.sub,60);p&&(r.sub=p)}if(o==="place"){r.label=l("label",48);const p=jo(t.sub,60);p&&(r.sub=p),Array.isArray(t.lonlat)&&t.lonlat.length===2&&t.lonlat.every(Number.isFinite)&&(r.lonlat=t.lonlat.map(cd));const c=jo(t.query,120);c&&(r.query=c)}if(o==="photo"){const p=jo(t.caption,48);p&&(r.caption=p)}if(o==="file"){r.title=jo(t.title,40)||"HỒ SƠ",r.text=l("text");const p=jo(t.sub,60);p&&(r.sub=p)}if(o==="news"){r.headline=l("headline",90),r.paper=jo(t.paper,40)||"NHẬT BÁO";const p=jo(t.date,48),c=jo(t.deck,90),s=jo(t.stamp,22);p&&(r.date=p),c&&(r.deck=c),s&&(r.stamp=s)}if(o==="type"){r.text=l("text",60);const p=jo(t.then,40);p&&(r.then=p)}if(o==="counter"){r.label=l("label",48);const p=Up(t.value);if(p===null||p<0)throw Error(`documentary station ${e+1} (counter) needs value ≥ 0`);r.value=Math.min(9e15,Math.round(p));const c=jo(t.unit,16);c&&(r.unit=c)}if(o==="portrait"){const p=jo(t.title,40),c=jo(t.sub,60);p&&(r.title=p),c&&(r.sub=c)}if(o==="photo"||o==="portrait"){const p=typeof t.asset=="string"?t.asset.trim():"";if(p){if(!/^(?:gs:\/\/[a-z0-9._-]{3,63}\/[A-Za-z0-9._\/%-]{1,240}|local:[A-Za-z0-9._-]{1,100})$/.test(p)||p.includes(".."))throw Error(`documentary station ${e+1}: asset must be a picture of the Media bin`);r.asset=p}else if(o==="photo")throw Error(`documentary station ${e+1} (photo) needs a picture (materialId of an image in the Media bin)`)}return r}function _8(t={}){const e=Array.isArray(t.stations)?t.stations:[];if(!e.length)throw Error("documentary needs stations [{kind, …}]");if(e.length>Zo.maxStations)throw Error(`documentary: at most ${Zo.maxStations} stations`);return{style:R8.includes(t.style)?t.style:"map",accent:D8.test(t.accent??"")?t.accent.toLowerCase():Zo.accent,sfx:t.sfx!==!1,stations:e.map(B8)}}function G8(t,e=()=>null){const o=[];let r=.2;for(const[h,f]of t.stations.entries()){const m={...f},y=m.hold??Zo.hold[m.kind];let $=m.at??(m.say?e(m.say,r-.5):null);$=$==null?r:Math.max($-.35,h?o[h-1].t0+1.1:0),m.t0=io($),m.t1=io($+y),r=m.t1,o.push(m)}for(let h=0;h<o.length-1;h++)o[h].t1=io(Math.max(o[h].t1,Math.min(o[h].t1,o[h+1].t0)));const n=Math.min(Zo.maxSeconds,io(o.at(-1).t1+.6));let a=0;const i=h=>{const f=Math.sin(h*127.1+311.7)*43758.5453;return f-Math.floor(f)};for(const[h,f]of o.entries()){const m=Zo.width[f.kind],y=f.kind==="place"&&t.style==="map";f.x=io(y?a:a+m/2),f.y=io(h?(i(h)-.5)*70:0),f.rot=io((i(h+7)-.5)*(f.kind==="type"||f.kind==="counter"||f.kind==="portrait"||f.kind==="year"?0:5)),a+=y?200:m+170,f.asset&&(f.a=`p${h}`)}const l=[];for(const[h,f]of o.entries()){const m=Zo.zoom[f.kind],y=h?Math.min(1.05,Math.max(.5,(f.t0-o[h-1].t0)*.42)):0,$=f.x,x=f.y+(f.kind==="news"?-20:0),E=h&&t.style==="map"&&o[h-1].kind==="place";E&&l.push([io(f.t0+.9),o[h-1].x,o[h-1].y,Zo.zoom.place]);const v=h?E?f.t0+1.7:f.t0+y*.55:0;l.push([io(v),$,x,m]),f.kind==="file"&&l.push([io(f.t0+1.4),$,x-20,m*1.05],[io(f.t0+2.1),$-10,x-30,m*1.45]),f.kind==="news"&&l.push([io(f.t0+1.6),$,x+30,m*1.2]),l.push([io(Math.max(v+.3,f.t1-(h<o.length-1?Math.min(.9,(o[h+1].t0-f.t0)*.3):0))),$+6,x-4,l.at(-1)[3]*1.04])}for(let h=1;h<l.length;h++)l[h][0]<=l[h-1][0]&&(l[h][0]=io(l[h-1][0]+.05));const p=new Set(["photo","file","news","place"]);for(const[h,f]of o.entries())if(f.kind==="place"&&t.style==="map"){const m=o.findIndex((y,$)=>$>h&&p.has(y.kind)&&y.kind!=="place");m>0&&(f.q=m,f.t2=io(o[m].t0+1.3))}const c=[];if(t.sfx)for(const h of o){for(const[f,m]of t0[h.kind]??[])c.push([f,io(h.t0+m)]);h.kind==="news"&&h.stamp&&c.push([t0.stamp[0][0],io(h.t0+2.05)])}const s=t.style==="map"?o.find(h=>h.kind==="place"):null;return{style:t.style,accent:t.accent,total:n,K:l,S:o,sfx:c,place:s?{lonlat:s.lonlat??null,query:s.query??s.label}:null}}const K8=`
|
|
204
|
+
const ACC=SPEC.accent,INK='#2a2622',PAPER='#e8e2d2',CREAM='#ece6d8',LIGHT=SPEC.style==='paper',WARM=SPEC.style==='wall'||LIGHT,FG=LIGHT?INK:CREAM
|
|
205
|
+
const cl=(x,a=0,b=1)=>x<a?a:x>b?b:x,sm=x=>{x=cl(x);return x*x*(3-2*x)},seg=(t,a,b)=>cl((t-a)/(b-a)),eo=x=>1-Math.pow(1-cl(x),3)
|
|
206
|
+
const back=x=>{x=cl(x);const c=1.9;return 1+(c+1)*Math.pow(x-1,3)+c*Math.pow(x-1,2)}
|
|
207
|
+
const hash=i=>{const s=Math.sin(i*127.1+311.7)*43758.5453;return s-Math.floor(s)}
|
|
208
|
+
const K=SPEC.K
|
|
209
|
+
function cam(t){
|
|
210
|
+
if(t<=K[0][0])return {x:K[0][1],y:K[0][2],z:K[0][3]}
|
|
211
|
+
if(t>=K[K.length-1][0]){const k=K[K.length-1];return {x:k[1],y:k[2],z:k[3]}}
|
|
212
|
+
let i=0;while(i<K.length-2&&t>K[i+1][0])i++
|
|
213
|
+
const a=K[i],b=K[i+1],h=b[0]-a[0],u=cl((t-a[0])/h)
|
|
214
|
+
const tan=(j,k,lg)=>{if(j<=0||j>=K.length-1)return 0;const p=K[j-1],n=K[j+1],f=v=>lg?Math.log(v):v;return (f(n[k])-f(p[k]))/(n[0]-p[0])*0.85}
|
|
215
|
+
const H=(k,lg)=>{const f=v=>lg?Math.log(v):v,p0=f(a[k]),p1=f(b[k]),m0=tan(i,k,lg),m1=tan(i+1,k,lg),u2=u*u,u3=u2*u
|
|
216
|
+
const r=(2*u3-3*u2+1)*p0+(u3-2*u2+u)*h*m0+(-2*u3+3*u2)*p1+(u3-u2)*h*m1;return lg?Math.exp(r):r}
|
|
217
|
+
return {x:H(1),y:H(2),z:H(3,true)}
|
|
218
|
+
}
|
|
219
|
+
const typed=(s,p)=>s.slice(0,Math.floor(s.length*cl(p)))
|
|
220
|
+
const plain=s=>s.replace(/\\*/g,'')
|
|
221
|
+
function shadowCard(ctx,x,y,w,h,col){ctx.save();ctx.shadowColor='rgba(0,0,0,.55)';ctx.shadowBlur=28;ctx.shadowOffsetY=12;ctx.fillStyle=col;ctx.fillRect(x,y,w,h);ctx.restore()}
|
|
222
|
+
function pin(ctx,x,y){ctx.save();ctx.shadowColor='rgba(0,0,0,.6)';ctx.shadowBlur=6;ctx.shadowOffsetY=3;const g=ctx.createRadialGradient(x-2,y-2,1,x,y,7);g.addColorStop(0,'#ff8a7a');g.addColorStop(1,'#a01810');ctx.fillStyle=g;ctx.beginPath();ctx.arc(x,y,6.5,0,7);ctx.fill();ctx.restore()}
|
|
223
|
+
function lines(ctx,x,y,w,n,gap,seed,al){ctx.fillStyle='rgba(42,38,34,'+al+')';for(let i=0;i<n;i++){const L=w*(i===n-1?.45:.78+.22*hash(seed+i));ctx.fillRect(x,y+i*gap,L,2.2)}}
|
|
224
|
+
// wrapped text with *marked* words: draws it, returns the marked words' boxes [[x,y,w,h]] (one per line)
|
|
225
|
+
function wrap(ctx,s,x,y,w,lh,draw){const toks=[];let mark=false;for(const part of s.split('*')){for(const wd of part.split(' '))if(wd)toks.push({wd,mark});mark=!mark}
|
|
226
|
+
const sp=ctx.measureText(' ').width,boxes=[];let cx=x,cy=y,cur=null
|
|
227
|
+
for(const k of toks){const tw=ctx.measureText(k.wd).width;if(cx>x&&cx+tw>x+w){cx=x;cy+=lh;cur=null}
|
|
228
|
+
if(draw!==false)ctx.fillText(k.wd,cx,cy)
|
|
229
|
+
if(k.mark){if(cur&&cur[1]===cy)cur[2]=cx+tw-cur[0];else{cur=[cx,cy,tw,lh];boxes.push(cur)}}else cur=null
|
|
230
|
+
cx+=tw+sp}
|
|
231
|
+
return {boxes,bottom:cy+lh}}
|
|
232
|
+
function circle(ctx,b,p,seed){if(p<=0||!b)return;const cx=b[0]+b[2]/2,cy=b[1]-b[3]*.32,rx=b[2]/2+16,ry=b[3]*.62;ctx.save();ctx.strokeStyle=ACC;ctx.lineWidth=3.2;ctx.lineCap='round';ctx.beginPath();const a0=-2.6,span=Math.PI*2*1.12*p
|
|
233
|
+
for(let k=0;k<=64;k++){const a=a0+span*k/64,j=1+.05*Math.sin(a*3+seed)+.03*Math.sin(a*7+seed*2),g=1+.06*(a-a0)/(Math.PI*2),x=cx+Math.cos(a)*rx*j*g,y=cy+Math.sin(a)*ry*j*g;k?ctx.lineTo(x,y):ctx.moveTo(x,y)}ctx.stroke();ctx.restore()}
|
|
234
|
+
function under(ctx,b,p,dy,wid){if(p<=0||!b)return;ctx.save();ctx.strokeStyle=ACC;ctx.lineWidth=wid||3.4;ctx.lineCap='round';ctx.beginPath();ctx.moveTo(b[0],b[1]+dy);for(let k=1;k<=24;k++){const v=k/24*p;ctx.lineTo(b[0]+b[2]*v,b[1]+dy+Math.sin(v*9)*1.6)}ctx.stroke();ctx.restore()}
|
|
235
|
+
const STAMPS=new Map()
|
|
236
|
+
function stampImg(text,font){const key=text;if(STAMPS.has(key))return STAMPS.get(key);const c=new OffscreenCanvas(540,170),g=c.getContext('2d');g.font=font;const w=Math.min(500,g.measureText(text).width+70)
|
|
237
|
+
g.strokeStyle=ACC;g.fillStyle=ACC;g.lineWidth=9;g.strokeRect(270-w/2,10,w,150);g.lineWidth=3;g.strokeRect(270-w/2+14,24,w-28,122);g.textAlign='center';g.textBaseline='middle';g.fillText(text,270,88)
|
|
238
|
+
g.globalCompositeOperation='destination-out';for(let i=0;i<900;i++){const r=hash(i)*2.6+.4;g.globalAlpha=.35+hash(i+9)*.65;g.beginPath();g.arc(hash(i+3)*540,hash(i+7)*170,r,0,7);g.fill()}
|
|
239
|
+
STAMPS.set(key,c);return c}
|
|
240
|
+
const GREY=new Map()
|
|
241
|
+
function grey(name){if(GREY.has(name))return GREY.get(name);let out=null;try{const bm=M.asset(name);if(bm){const W=84,H=103,c=new OffscreenCanvas(W,H),g=c.getContext('2d'),s=Math.max(W/bm.width,H/bm.height),w=bm.width*s,h=bm.height*s
|
|
242
|
+
g.drawImage(bm,(W-w)/2,(H-h)*.3,w,h);const d=g.getImageData(0,0,W,H).data,L=new Float32Array(W*H);for(let i=0;i<W*H;i++)L[i]=(d[i*4]*.3+d[i*4+1]*.59+d[i*4+2]*.11)/255;out={W,H,L}}}catch(e){out=null}GREY.set(name,out);return out}
|
|
243
|
+
function photo(ctx,name,x,y,w,h){let bm=null;try{bm=name?M.asset(name):null}catch(e){bm=null}
|
|
244
|
+
if(!bm){ctx.fillStyle='#3a3a3a';ctx.fillRect(x,y,w,h);ctx.fillStyle='#565656';ctx.beginPath();ctx.arc(x+w/2,y+h*.38,w*.2,0,7);ctx.fill();ctx.fillRect(x+w*.22,y+h*.62,w*.56,h*.38);return}
|
|
245
|
+
const s=Math.max(w/bm.width,h/bm.height),dw=bm.width*s,dh=bm.height*s;ctx.save();ctx.beginPath();ctx.rect(x,y,w,h);ctx.clip();ctx.filter='grayscale(1) contrast(1.12) brightness(.96)';ctx.drawImage(bm,x+(w-dw)/2,y+(h-dh)*.25,dw,dh);ctx.filter='none'
|
|
246
|
+
const vg=ctx.createLinearGradient(0,y,0,y+h);vg.addColorStop(0,'rgba(60,40,20,.08)');vg.addColorStop(1,'rgba(60,40,20,.22)');ctx.fillStyle=vg;ctx.fillRect(x,y,w,h);ctx.restore()}
|
|
247
|
+
function anchor(s){if(s.kind==='photo')return [s.x,s.y-150];if(s.kind==='file')return [s.x,s.y-235];if(s.kind==='news')return [s.x,s.y-262];if(s.kind==='place')return [s.x,s.y-56];return null}
|
|
248
|
+
function drawStation(ctx,s,T,F,shake){
|
|
249
|
+
const u=T-s.t0,out=s.kind==='year'||s.kind==='type'||s.kind==='counter'?1-sm(seg(T,s.t1-.1,s.t1+.5)):1
|
|
250
|
+
if(out<=0)return
|
|
251
|
+
ctx.save();ctx.globalAlpha*=out;ctx.translate(s.x,s.y);ctx.rotate(s.rot*Math.PI/180)
|
|
252
|
+
if(s.kind==='year'){const a=sm(seg(u,.05,.5));ctx.globalAlpha*=a;ctx.font='200 92px '+F.mont;ctx.textAlign='center';ctx.textBaseline='middle';ctx.fillStyle=CREAM
|
|
253
|
+
const yr=s.text,n=Math.min(yr.length,Math.floor(seg(u,.1,.1+.25*yr.length)*(yr.length+.999)));let o='';for(let i=0;i<yr.length;i++)o+=i<n?yr[i]:(i===n&&/[0-9]/.test(yr[i])?String(Math.floor(hash(Math.floor(T*24)+i)*10)):(i===n?yr[i]:' '))
|
|
254
|
+
if(WARM){ctx.save();ctx.transform(1,0,-.17,1,0,0);const k=1+.25*(1-eo(seg(u,.05,.5)));ctx.scale(k,k);ctx.font='700 150px '+F.oswald;ctx.shadowColor=LIGHT?'rgba(0,0,0,.25)':'rgba(70,22,0,.6)';ctx.shadowBlur=18;ctx.shadowOffsetY=6;ctx.fillStyle=LIGHT?INK:'#fff4e6';ctx.fillText(o,0,0);ctx.restore()}
|
|
255
|
+
else{ctx.fillText(o.split('').join(' '),0,0);const w=ctx.measureText(yr.split('').join(' ')).width/2+20,tl=eo(seg(u,.35,1.2))*170;ctx.fillStyle='rgba(236,230,216,.55)';ctx.fillRect(-w-tl,-1,tl,1.4);ctx.fillRect(w,-1,tl,1.4)}
|
|
256
|
+
if(s.sub){ctx.font='500 13px '+F.mont;ctx.fillStyle=ACC;ctx.fillText(typed(s.sub,seg(u,.8,1.6)),0,WARM?98:64)}}
|
|
257
|
+
if(s.kind==='place'&&SPEC.style!=='map'){const a=seg(u,0,.5);ctx.globalAlpha*=sm(a);ctx.scale(1.1-.1*back(a),1.1-.1*back(a));shadowCard(ctx,-110,-56,220,92,'#efe6c8');ctx.fillStyle=INK;ctx.font='800 22px '+F.mont;ctx.textAlign='center';ctx.fillText(s.label,0,-10);if(s.sub){ctx.font='500 12px '+F.mont;ctx.fillStyle='rgba(42,38,34,.7)';ctx.fillText(s.sub,0,14)}pin(ctx,0,-56)}
|
|
258
|
+
if(s.kind==='photo'){const a=seg(u,0,.55),k=1.18-.18*back(a);ctx.globalAlpha*=sm(a);ctx.rotate((-3+3*eo(a))*Math.PI/180);ctx.scale(k,k);shadowCard(ctx,-118,-150,236,300,'#f1ede4');photo(ctx,s.a,-104,-136,208,255)
|
|
259
|
+
if(s.caption){ctx.fillStyle=INK;ctx.font='700 15px '+F.mont;ctx.textAlign='center';ctx.fillText(s.caption,0,138)}pin(ctx,0,-140)}
|
|
260
|
+
if(s.kind==='file'){const a=seg(u,0,.6);ctx.globalAlpha*=sm(a);ctx.translate(0,30*(1-eo(a)));shadowCard(ctx,-190,-240,380,480,PAPER)
|
|
261
|
+
ctx.fillStyle=INK;ctx.font='800 22px '+F.mont;ctx.fillText(s.title,-160,-196);ctx.fillStyle=ACC;ctx.fillRect(-160,-182,80,3);if(s.sub){ctx.font='500 12px '+F.mont;ctx.fillStyle='rgba(42,38,34,.75)';ctx.fillText(s.sub,-160,-160)}
|
|
262
|
+
lines(ctx,-160,-128,320,5,16,11,.28);ctx.font='600 21px '+F.mont;ctx.fillStyle=INK;const r=wrap(ctx,s.text,-160,-16,320,30);lines(ctx,-160,r.bottom+18,320,6,16,41,.28)
|
|
263
|
+
circle(ctx,r.boxes[0],eo(seg(u,1.5,2.2)),3);if(r.boxes[1])circle(ctx,r.boxes[1],eo(seg(u,2.0,2.6)),5);pin(ctx,0,-235)}
|
|
264
|
+
if(s.kind==='news'){const a=seg(u,0,.6);ctx.globalAlpha*=sm(a);ctx.translate(0,24*(1-eo(a)));shadowCard(ctx,-215,-265,430,530,'#ebe5d6')
|
|
265
|
+
ctx.textAlign='center';ctx.fillStyle=INK;ctx.font='800 28px '+F.bevn;ctx.fillText(s.paper,0,-222);ctx.fillRect(-190,-208,380,2);ctx.font='500 11px '+F.mont;if(s.date)ctx.fillText(s.date,0,-192);ctx.fillRect(-190,-184,380,1)
|
|
266
|
+
ctx.font='400 46px '+F.anton;ctx.textAlign='left';const hw=[];const words=plain(s.headline);let lns=[],cur='';for(const wd of words.split(' ')){const tst=cur?cur+' '+wd:wd;if(ctx.measureText(tst).width>380&&cur){lns.push(cur);cur=wd}else cur=tst}lns.push(cur);lns=lns.slice(0,3)
|
|
267
|
+
let y=-138;const marks=[];let mk=false,rawWords=[];for(const part of s.headline.split('*')){for(const wd of part.split(' '))if(wd)rawWords.push({wd,mk});mk=!mk}let wi=0
|
|
268
|
+
for(const ln of lns){const lw=ctx.measureText(ln).width;let cx=-lw/2;ctx.fillText(ln,cx,y);for(const wd of ln.split(' ')){const tw=ctx.measureText(wd).width,rw=rawWords[wi++];if(rw&&rw.mk){const m=marks[marks.length-1];if(m&&m[1]===y)m[2]=cx+tw-m[0];else marks.push([cx,y,tw,48])}cx+=tw+ctx.measureText(' ').width}y+=52}
|
|
269
|
+
ctx.textAlign='center';if(s.deck){ctx.font='italic 500 14px '+F.mont;ctx.fillStyle='rgba(42,38,34,.8)';ctx.fillText(s.deck,0,y+4)}ctx.textAlign='left'
|
|
270
|
+
lines(ctx,-190,y+30,180,13,15,71,.3);lines(ctx,10,y+30,180,13,15,97,.3);for(const [j,m] of marks.entries())under(ctx,m,eo(seg(u,1.0+j*.3,1.5+j*.3)),12,3.6)
|
|
271
|
+
if(s.stamp){const sa=seg(u,2.0,2.2);if(sa>0){const im=stampImg(s.stamp,'900 64px '+F.anton),k=2.3-1.3*back(sa);ctx.save();ctx.translate(40,150);ctx.rotate(-11*Math.PI/180);ctx.scale(k*.62,k*.62);ctx.globalAlpha*=sm(sa*1.6)*.9;ctx.drawImage(im,-270,-85);ctx.restore()}}pin(ctx,0,-262)}
|
|
272
|
+
if(s.kind==='type'){ctx.textAlign='left';ctx.font='500 46px '+F.oswald;ctx.fillStyle=FG;const l1=plain(s.text),dur=Math.min(1.6,.05*l1.length+.4),t1=typed(l1,seg(u,.3,.3+dur)),full=ctx.measureText(l1).width
|
|
273
|
+
ctx.fillText(t1+(Math.floor(T*3)%2&&t1.length<l1.length?'▍':''),-full/2,s.then?-50:0);const st=eo(seg(u,.5+dur,.85+dur));if(st>0&&s.then){ctx.fillStyle=ACC;ctx.fillRect(-full/2-8,-65,(full+16)*st,5)}
|
|
274
|
+
if(s.then){const b=eo(seg(u,1+dur,1.9+dur));if(b>0){ctx.globalAlpha*=b;ctx.font='200 88px '+F.mont;ctx.letterSpacing=(14*(1-b)+4)+'px';const w=ctx.measureText(s.then).width;ctx.fillStyle=LIGHT?INK:'#f4efe4';ctx.fillText(s.then,-w/2,60);ctx.letterSpacing='0px'}}}
|
|
275
|
+
if(s.kind==='counter'){const a=seg(u,0,.4);ctx.globalAlpha*=sm(a);const p=eo(seg(u,.2,2.4)),n=Math.floor(Math.pow(p,2.2)*s.value);ctx.textAlign='left';ctx.font='600 17px '+F.mont;ctx.fillStyle=ACC;ctx.fillText(s.label,-200,-70)
|
|
276
|
+
ctx.font='500 64px '+F.oswald;ctx.fillText(n.toLocaleString('en-US')+(s.unit?' '+s.unit:''),-200,0);ctx.strokeStyle='rgba(236,230,216,.12)';ctx.lineWidth=1
|
|
277
|
+
for(let i=0;i<5;i++)for(let j=0;j<5;j++){ctx.beginPath();ctx.moveTo(-200,40+i*26);ctx.lineTo(60,40+j*26);ctx.stroke()}ctx.fillStyle='rgba(236,230,216,.45)';for(let i=0;i<5;i++){ctx.beginPath();ctx.arc(-200,40+i*26,3.5,0,7);ctx.arc(60,40+i*26,3.5,0,7);ctx.fill()}}
|
|
278
|
+
if(s.kind==='portrait'){const G=s.a?grey(s.a):null,form=sm(seg(u,.9,2.7)),fw=280,fh=G?fw*G.H/G.W:200,fx=-fw/2,fy=-fh/2-30,N=G?G.W*G.H:0
|
|
279
|
+
if(G){for(let j=0;j<G.H;j+=2)for(let i=0;i<G.W;i+=2){const v=G.L[j*G.W+i],id=j*G.W+i,r1=hash(id),r2=hash(id+5),q=r1*1.4-.2,sx=-460+q*560,sy=60+Math.sin(q*5+T*1.3)*40-q*90+(r2-.5)*36,tx=fx+i/G.W*fw,ty=fy+j/G.H*fh
|
|
280
|
+
const e=sm(cl(form*1.35-r2*.35)),x=sx+(tx-sx)*e,y=sy+(ty-sy)*e,rad=(.6+v*2.1)*(.4+.6*e)+(1-e)*.5,al=(1-e)*.55*cl(u*2)+e*(.15+v*.85);if(al<.03)continue
|
|
281
|
+
ctx.fillStyle=e>.6?'rgba(240,236,226,'+al+')':'rgba(255,'+(120+v*100|0)+',90,'+al+')';ctx.fillRect(x-rad,y-rad,rad*2,rad*2)}}
|
|
282
|
+
else{for(let i=0;i<900;i++){const r1=hash(i),r2=hash(i+5),q=r1*1.4-.2,sx=-460+q*560,sy=60+Math.sin(q*5+T*1.3)*40-q*90+(r2-.5)*36,a=Math.PI*2*r2,rr=60+r1*60,tx=Math.cos(a)*rr,ty=Math.sin(a)*rr*.6-30,e=sm(cl(form*1.3-r2*.3))
|
|
283
|
+
ctx.fillStyle='rgba(255,'+(150+r1*90|0)+',110,'+(.6*cl(u*2))+')';ctx.fillRect(sx+(tx-sx)*e-1,sy+(ty-sy)*e-1,2,2)}}
|
|
284
|
+
const ta=sm(seg(u,2.6,3.2));if(ta>0&&(s.title||s.sub)){ctx.globalAlpha*=ta;ctx.textAlign='center';if(s.title){ctx.font='800 26px '+F.mont;ctx.fillStyle='#f4efe4';ctx.fillText(s.title,0,fy+fh+44)}if(s.sub){ctx.font='500 13px '+F.mont;ctx.fillStyle=ACC;ctx.fillText(s.sub,0,fy+fh+68)}}}
|
|
285
|
+
ctx.restore()
|
|
286
|
+
}
|
|
287
|
+
function cork(ctx,W,H,c,S){ctx.fillStyle='#5a3d22';ctx.fillRect(0,0,W,H);const z=c.z*S,cs=26,x0=c.x-W/2/z,y0=c.y-H/2/z,i0=Math.floor(x0/cs)-1,j0=Math.floor(y0/cs)-1,ni=Math.ceil(W/z/cs)+2,nj=Math.ceil(H/z/cs)+2
|
|
288
|
+
for(let j=j0;j<j0+nj;j++)for(let i=i0;i<i0+ni;i++){const h=hash(i*7919+j*104729),x=(i*cs-c.x)*z+W/2,y=(j*cs-c.y)*z+H/2;ctx.fillStyle=h>.5?'rgba(140,96,52,'+(.18+h*.2)+')':'rgba(40,24,10,'+(.15+h*.2)+')';ctx.fillRect(x+hash(i+j*3)*cs*z*.5,y+hash(j+i*5)*cs*z*.5,(2+h*5)*z,(2+h*4)*z)}
|
|
289
|
+
const g=ctx.createRadialGradient(W/2,H*.45,H*.1,W/2,H/2,W*.65);g.addColorStop(0,'rgba(255,214,150,.16)');g.addColorStop(1,'rgba(0,0,0,.55)');ctx.fillStyle=g;ctx.fillRect(0,0,W,H)}
|
|
290
|
+
// wall: warm plaster (its specks travel with the camera); windowLight: the light of a 2 x 3 pane window falling across the
|
|
291
|
+
// frame (screen space: the light stays while the camera glides), drawn over the stations so it falls across the photos too
|
|
292
|
+
function wall(ctx,W,H,c,S){const g=ctx.createLinearGradient(0,0,W*.4,H);g.addColorStop(0,'#d99150');g.addColorStop(.55,'#b8641f');g.addColorStop(1,'#5a2a0b');ctx.fillStyle=g;ctx.fillRect(0,0,W,H)
|
|
293
|
+
const z=c.z*S,cs=34,x0=c.x-W/2/z,y0=c.y-H/2/z,i0=Math.floor(x0/cs)-1,j0=Math.floor(y0/cs)-1,ni=Math.ceil(W/z/cs)+2,nj=Math.ceil(H/z/cs)+2
|
|
294
|
+
for(let j=j0;j<j0+nj;j++)for(let i=i0;i<i0+ni;i++){const h=hash(i*7919+j*104729);if(h<.5)continue;const x=(i*cs-c.x)*z+W/2,y=(j*cs-c.y)*z+H/2;ctx.fillStyle=h>.8?'rgba(255,222,170,.12)':'rgba(70,30,5,.13)';ctx.fillRect(x+hash(i+j*3)*cs*z,y+hash(j+i*5)*cs*z,(1.4+h*2.4)*z,(1.4+h*2)*z)}}
|
|
295
|
+
function windowLight(ctx,W,H,T){const u=Math.min(W,H),pr=cl(T/Math.max(1,SPEC.total)),ww=u*.95,wh=u*1.25,b=u*.05,ps=[];for(let i=0;i<2;i++)for(let j=0;j<3;j++)ps.push([-ww/2+i*ww/2+b/2,-wh/2+j*wh/3+b/2,ww/2-b,wh/3-b])
|
|
296
|
+
ctx.save();ctx.translate(W*(.12+.68*pr),H*.44);ctx.rotate(-.12);ctx.transform(1,.16,-.5,1,0,0);ctx.filter='blur('+Math.round(u*.012)+'px)'
|
|
297
|
+
ctx.beginPath();ctx.rect(-W*4,-H*4,W*8,H*8);ps.forEach(q=>ctx.rect(q[0],q[1],q[2],q[3]));ctx.fillStyle='rgba(30,13,2,.3)';ctx.fill('evenodd')
|
|
298
|
+
ctx.beginPath();ps.forEach(q=>ctx.rect(q[0],q[1],q[2],q[3]));ctx.fillStyle='rgba(255,199,122,.28)';ctx.fill();ctx.filter='none';ctx.restore()}
|
|
299
|
+
// paper: grid paper that travels with the camera, soft crumple light; torn: red and navy torn paper over the corners, slid in
|
|
300
|
+
function paper(ctx,W,H,c,S){ctx.fillStyle='#e8e8e4';ctx.fillRect(0,0,W,H);const z=c.z*S,step=30*z,ox=W/2-c.x*z,oy=H/2-c.y*z,x0=((ox%step)+step)%step,y0=((oy%step)+step)%step
|
|
301
|
+
ctx.strokeStyle='rgba(80,105,130,.24)';ctx.lineWidth=Math.max(1,z*.8);ctx.beginPath();for(let x=x0;x<W;x+=step){ctx.moveTo(x,0);ctx.lineTo(x,H)}for(let y=y0;y<H;y+=step){ctx.moveTo(0,y);ctx.lineTo(W,y)}ctx.stroke()
|
|
302
|
+
for(let i=0;i<9;i++){const x=hash(i*3+1)*W,y=hash(i*5+2)*H,r=(.2+hash(i+9)*.35)*Math.max(W,H),g=ctx.createRadialGradient(x,y,0,x,y,r);g.addColorStop(0,i%2?'rgba(255,255,255,.2)':'rgba(50,60,75,.1)');g.addColorStop(1,'rgba(0,0,0,0)');ctx.fillStyle=g;ctx.fillRect(0,0,W,H)}}
|
|
303
|
+
function torn(ctx,W,H,T){const u=Math.min(W,H),k=1-eo(seg(T,0,.9))
|
|
304
|
+
const jag=(ax,ay,bx,by,n,a,seed,off)=>{const dx=bx-ax,dy=by-ay,L=Math.hypot(dx,dy)||1,nx=-dy/L,ny=dx/L,o=[];for(let i=0;i<=n;i++){const q=i/n,d=(hash(seed+i)-.5)*2*a+off;o.push([ax+dx*q+nx*d,ay+dy*q+ny*d])}return o}
|
|
305
|
+
const piece=(corner,edge,col,seed,dx,dy)=>{ctx.save();ctx.translate(dx*k,dy*k);for(const [off,fill] of [[u*.014,'#f3f0e8'],[0,col]]){ctx.beginPath();corner.forEach((p,i)=>i?ctx.lineTo(p[0],p[1]):ctx.moveTo(p[0],p[1]));jag(edge[0],edge[1],edge[2],edge[3],34,u*.009,seed,off).forEach(p=>ctx.lineTo(p[0],p[1]));ctx.closePath();ctx.fillStyle=fill;ctx.shadowColor='rgba(0,0,0,.28)';ctx.shadowBlur=u*.02;ctx.fill()}
|
|
306
|
+
ctx.shadowColor='transparent';ctx.clip();for(let i=0;i<60;i++){ctx.fillStyle=i%2?'rgba(255,255,255,.05)':'rgba(0,0,0,.08)';ctx.fillRect(hash(seed+i*3)*W,hash(seed+i*7)*H,u*.05*hash(i),u*.004)}ctx.restore()}
|
|
307
|
+
piece([[0,H*.36],[0,0],[W*.58,0]],[W*.58,0,0,H*.36],'#8b1c22',11,-W*.6,-H*.4)
|
|
308
|
+
piece([[W*.62,H],[0,H],[0,H*.74]],[0,H*.74,W*.62,H],'#1c2a52',37,-W*.6,H*.4)}
|
|
309
|
+
function render(ctx,t,env){
|
|
310
|
+
const W=env.width,H=env.height,S=W/1280,F=env.fonts,T=t+(+env.params.off||0),tot=SPEC.total,fin=sm(seg(T,0,.6))*(1-sm(seg(T,tot-.6,tot)))
|
|
311
|
+
const c=cam(T);let shake=0;for(const s of SPEC.S)if(s.kind==='news'&&s.stamp){const d=T-(s.t0+2.1);if(d>0&&d<.5)shake+=Math.sin(d*90)*6*(1-d/.5)}
|
|
312
|
+
if(SPEC.style==='cork')cork(ctx,W,H,c,S);else if(SPEC.style==='wall')wall(ctx,W,H,c,S);else if(LIGHT)paper(ctx,W,H,c,S);else{ctx.fillStyle='rgba(8,20,22,.42)';ctx.fillRect(0,0,W,H)}
|
|
313
|
+
// the place ping: on the map's centre (style map — the map layer below holds still)
|
|
314
|
+
if(SPEC.style==='map')for(const s of SPEC.S){if(s.kind!=='place')continue;const pE=s.t2||s.t1,pA=sm(seg(T,s.t0,s.t0+.5))*(1-sm(seg(T,pE-.2,pE+.4)));if(pA<=0)continue
|
|
315
|
+
ctx.save();ctx.globalAlpha=pA*fin;const px=W/2,py=H/2
|
|
316
|
+
for(let k=0;k<3;k++){const q=((T*.8+k/3)%1);ctx.strokeStyle='rgba(230,70,55,'+((1-q)*.8)+')';ctx.lineWidth=2*S;ctx.beginPath();ctx.arc(px,py,(6+q*46)*S,0,7);ctx.stroke()}
|
|
317
|
+
const gl=ctx.createRadialGradient(px,py,0,px,py,26*S);gl.addColorStop(0,'rgba(255,90,70,.9)');gl.addColorStop(1,'rgba(255,90,70,0)');ctx.fillStyle=gl;ctx.beginPath();ctx.arc(px,py,26*S,0,7);ctx.fill();ctx.fillStyle='#ff5a46';ctx.beginPath();ctx.arc(px,py,5*S,0,7);ctx.fill()
|
|
318
|
+
ctx.font='600 '+(14*S)+'px '+F.mont;ctx.fillStyle='rgba(235,230,220,.92)';ctx.textBaseline='middle';ctx.fillText(typed(s.label,seg(T,s.t0+.1,s.t0+.8)),px+16*S,py-18*S);if(s.sub){ctx.fillStyle='rgba(235,230,220,.55)';ctx.font='400 '+(11*S)+'px '+F.mont;ctx.fillText(typed(s.sub,seg(T,s.t0+.5,s.t0+1.1)),px+16*S,py-1*S)}ctx.restore()}
|
|
319
|
+
const z=c.z*S,ox=W/2-z*c.x+(Math.sin(T*.7)*3+shake)*S,oy=H/2-z*c.y+(Math.cos(T*.53)*2+shake*.5)*S,vw=W/2/z+40,vh=H/2/z+40
|
|
320
|
+
// red string: cork = from each pinned thing to the next; map = from the place ping (the frame centre) to the next pinned thing
|
|
321
|
+
const str=(A,B,p)=>{if(p<=0)return;const mx=(A[0]+B[0])/2,my=Math.max(A[1],B[1])+40*S;ctx.beginPath();ctx.moveTo(A[0],A[1]);const N=30,m=Math.floor(N*p);for(let k=1;k<=m;k++){const q=k/N;ctx.lineTo((1-q)*(1-q)*A[0]+2*q*(1-q)*mx+q*q*B[0],(1-q)*(1-q)*A[1]+2*q*(1-q)*my+q*q*B[1])}ctx.stroke()}
|
|
322
|
+
ctx.save();ctx.globalAlpha=fin;ctx.strokeStyle='rgba(190,34,26,.92)';ctx.lineWidth=2.6*S
|
|
323
|
+
if(SPEC.style==='cork'){let prev=null;for(const s of SPEC.S){const a=anchor(s);if(!a)continue;if(prev&&T>s.t0+.3)str([ox+prev[0]*z,oy+prev[1]*z],[ox+a[0]*z,oy+a[1]*z],eo(seg(T,s.t0+.3,s.t0+1.1)));prev=a}}
|
|
324
|
+
else for(const s of SPEC.S){if(s.kind!=='place'||!s.q)continue;const q=SPEC.S[s.q],a=anchor(q),al=1-sm(seg(T,s.t2-.2,s.t2+.4));if(!a||al<=0||T<q.t0+.2)continue;ctx.globalAlpha=fin*al;str([W/2,H/2],[ox+a[0]*z,oy+a[1]*z],eo(seg(T,q.t0+.2,q.t0+.9)))}
|
|
325
|
+
ctx.restore()
|
|
326
|
+
ctx.save();ctx.globalAlpha=fin;ctx.setTransform(z,0,0,z,ox,oy)
|
|
327
|
+
for(const s of SPEC.S){if(T<s.t0-.05)continue;if(SPEC.style==='map'&&s.kind==='place')continue;if(Math.abs(s.x-c.x)>vw+DOCW[s.kind]/2||Math.abs(s.y-c.y)>vh+300)continue;drawStation(ctx,s,T,F,shake)}
|
|
328
|
+
ctx.restore()
|
|
329
|
+
if(SPEC.style==='wall')windowLight(ctx,W,H,T);if(LIGHT)torn(ctx,W,H,T)
|
|
330
|
+
ctx.save();const fr=Math.floor(T*24);for(let i=0;i<420;i++){const h1=hash(fr*997+i),h2=hash(fr*991+i*3);ctx.fillStyle=h1>.5?'rgba(255,255,255,.05)':'rgba(0,0,0,.08)';ctx.fillRect(h1*W,h2*H,1.6*S,1.6*S)}
|
|
331
|
+
const vg=ctx.createRadialGradient(W/2,H/2,H*.35,W/2,H/2,W*.75);vg.addColorStop(0,'rgba(0,0,0,0)');vg.addColorStop(1,'rgba(0,0,0,'+(LIGHT?.22:WARM?.45:.62)+')');ctx.fillStyle=vg;ctx.fillRect(0,0,W,H);ctx.fillStyle='rgba(255,240,220,'+(.015+.015*hash(fr))+')';ctx.fillRect(0,0,W,H);ctx.restore()
|
|
332
|
+
}`;function V8(t){const e={style:t.style,accent:t.accent,total:t.total,K:t.K,S:t.S.map(({at:o,say:r,hold:n,asset:a,lonlat:i,query:l,...p})=>p)};return`const SPEC=${JSON.stringify(e)};const DOCW=${JSON.stringify(Zo.width)};
|
|
333
|
+
${K8}`}function W8({ids:t,at:e,plan:o,label:r}){const n=V8(o),a={};for(const p of o.S)p.a&&p.asset&&(a[p.a]=p.asset);const i=Math.ceil(o.total/Zo.layerSeconds-1e-6),l=[];for(let p=0;p<i;p++){const c=p*Zo.layerSeconds,s=Math.min(Zo.layerSeconds,o.total-c);l.push({id:t[p],nodeId:"",kind:"image",url:"",volume:0,start:cd(e+c),duration:cd(s),label:`${r||"Phim tư liệu"}${i>1?` · ${p+1}/${i}`:""}`,motionV:2,posX:0,posY:0,scale:1,motion:Jo({code:n,params:{off:c},assets:a})})}return l}const Yp=(t,e=.45)=>({color:t,blur:e,x:0,y:0}),X8={"neon-cyan":{vi:"Neon xanh BĐS",en:"Neon cyan (real estate)",fontFamily:"Montserrat",fontSize:72,color:"#ffffff",accentColor:"#33e6ff",design:{weight:900,lineHeight:1.28,uppercase:!0,stack:"center",gap:.02,lines:[{scale:1},{scale:.62,weight:800}],layers:[{type:"text",fill:"{accent}",shadow:Yp("{accent}",.6),opacity:.85},{type:"text",fill:"{color}",shadow:Yp("{accent}",.22)}]},animation:{in:[{unit:"char",stagger:.028,order:"random",duration:.38,easing:"easeOutCubic",from:{opacity:0,blur:.6,scale:1.7,y:-.25}}],out:"reverse",outSpeed:1.8}},"gold-combo":{vi:"Combo chữ vàng + viết tay",en:"Gold combo + script",fontFamily:"Anton",fontSize:84,color:"#ffffff",accentColor:"#ffcf4a",design:{weight:400,lineHeight:1.3,uppercase:!1,stack:"center",gap:.02,lines:[{scale:.5,font:"Dancing Script",weight:700},{scale:1.15},{scale:.48,font:"Dancing Script",weight:700}],layers:[{type:"text",fill:{gradient:["#fff3b0","{accent}","#c77d12"],angle:90},stroke:{color:"#2a1600",width:.06},shadow:{color:"#000000",blur:.2,x:0,y:.04}}]},animation:{in:[{lines:[0],unit:"line",duration:.5,easing:"easeInOutCubic",from:{wipeX:0}},{lines:[1],unit:"char",start:.25,stagger:.04,duration:.4,easing:"easeOutBack",from:{opacity:0,scale:1.6,blur:.4}},{lines:[2],unit:"line",start:.6,duration:.5,easing:"easeInOutCubic",from:{wipeX:0}}],out:"reverse",outSpeed:1.8}},"cyan-number":{vi:"Số lớn xanh + chữ viết tay",en:"Big cyan number + script",fontFamily:"Montserrat",fontSize:96,color:"#ffffff",accentColor:"#2fd9ff",design:{weight:900,lineHeight:1.25,uppercase:!1,stack:"center",gap:0,lines:[{scale:1.35},{scale:.46,font:"Dancing Script",weight:700}],layers:[{type:"text",fill:"{accent}",shadow:Yp("{accent}",.7),opacity:.7},{type:"text",fill:{gradient:["#ffffff","#bff6ff","{accent}"],angle:90},stroke:{color:"#04313b",width:.04},shadow:{color:"#000000",blur:.15,x:0,y:.03}}]},animation:{in:[{lines:[0],unit:"line",duration:.55,easing:"easeOutBack",from:{opacity:0,y:-.9,scale:1.5,blur:.3}},{lines:[1],unit:"line",start:.35,duration:.5,easing:"easeInOutCubic",from:{wipeX:0}}],out:"reverse",outSpeed:1.8}},"gold-outline":{vi:"Viền vàng rồi đổ đầy (số liệu)",en:"Gold outline → fill (figures)",fontFamily:"Playfair Display",fontSize:88,color:"#ffffff",accentColor:"#f2c46b",design:{weight:700,lineHeight:1.25,uppercase:!0,stack:"center",gap:.04,lines:[{scale:.5},{scale:1.6}],layers:[{type:"text",fill:"transparent",stroke:{color:"{accent}",width:.035},shadow:{color:"#000000",blur:.25,x:0,y:.03}},{type:"text",fill:{gradient:["#fff1c9","{accent}","#b8862e"],angle:90},motion:{start:.55,duration:.8,easing:"easeInOutCubic",from:{wipeY:0}}}]},animation:{in:[{unit:"line",stagger:.12,duration:.7,easing:"easeOutCubic",from:{opacity:0,blur:.35,spread:.45}}],out:"reverse",outSpeed:1.6}}},pd=Object.freeze(Object.fromEntries(Object.entries(X8).map(([t,e])=>[t,Object.freeze({...e,design:zk(e.design,`estateText.${t}`),animation:Pk(e.animation,`estateText.${t}`)})])));Object.freeze(Object.keys(pd));const H8={top:-.3,center:0,lower:.24},U8=1.7;function Y8(t,{portrait:e=!1}={}){const o=pd[t.preset]??pd["neon-cyan"],r=t.start??t.at,n=["top","center","lower"].includes(t.placement)?t.placement:"center";return{op:"addText",text:t.text,start:r,duration:t.duration,fontFamily:o.fontFamily,fontSize:t.fontSize??o.fontSize,color:t.color??o.color,accentColor:t.accentColor??o.accentColor,placement:n,align:"center",design:e?{...o.design,maxWidth:.52}:o.design,animation:o.animation,posX:t.posX??0,posY:t.posY??H8[n]*(e?.8:1),scale:t.scale??(e?U8:1),...t.track!=null?{track:t.track}:{}}}const aa=t=>Math.round(t*10)/10,g=(t,e)=>`${aa(t)} ${aa(e)}`,bn=.5523,$e=(t,e,o,r)=>`M${g(t+o,e)} C${g(t+o,e+r*bn)} ${g(t+o*bn,e+r)} ${g(t,e+r)} C${g(t-o*bn,e+r)} ${g(t-o,e+r*bn)} ${g(t-o,e)} C${g(t-o,e-r*bn)} ${g(t-o*bn,e-r)} ${g(t,e-r)} C${g(t+o*bn,e-r)} ${g(t+o,e-r*bn)} ${g(t+o,e)} Z`,kt=(t,e,o)=>$e(t,e,o,o);function q8(t,e,o,r,n=0){if(n=Math.max(0,Math.min(n,o/2,r/2)),!n)return`M${g(t,e)} L${g(t+o,e)} L${g(t+o,e+r)} L${g(t,e+r)} Z`;const a=n*(1-bn);return`M${g(t+n,e)} L${g(t+o-n,e)} C${g(t+o-a,e)} ${g(t+o,e+a)} ${g(t+o,e+n)} L${g(t+o,e+r-n)} C${g(t+o,e+r-a)} ${g(t+o-a,e+r)} ${g(t+o-n,e+r)} L${g(t+n,e+r)} C${g(t+a,e+r)} ${g(t,e+r-a)} ${g(t,e+r-n)} L${g(t,e+n)} C${g(t,e+a)} ${g(t+a,e)} ${g(t+n,e)} Z`}const pt=(t,e,o,r,n=0)=>q8(t-o/2,e-r/2,o,r,n),jt=(t,e=!0)=>"M"+t.map(o=>g(o[0],o[1])).join(" L")+(e?" Z":"");function sa(t,e=!0,o=1){const r=t.length,n=i=>e?t[(i+r)%r]:t[Math.max(0,Math.min(r-1,i))];let a=`M${g(...t[0])}`;for(let i=0;i<(e?r:r-1);i++){const l=n(i-1),p=n(i),c=n(i+1),s=n(i+2),h=o/6;a+=` C${g(p[0]+(c[0]-l[0])*h,p[1]+(c[1]-l[1])*h)} ${g(c[0]-(s[0]-p[0])*h,c[1]-(s[1]-p[1])*h)} ${g(...c)}`}return e?a+" Z":a}const Ze=t=>t*Math.PI/180,Pc=(t,e,o,r,n,a,i=10)=>Array.from({length:i+1},(l,p)=>{const c=Ze(n+(a-n)*p/i);return[t+Math.cos(c)*o,e+Math.sin(c)*r]}),Ge=(t,e,o,r,n,a=o)=>sa(Pc(t,e,o,a,r,n),!1),xy=(t,e,o,r,n=-90)=>Array.from({length:o},(a,i)=>{const l=Ze(n+i*360/o);return[t+Math.cos(l)*r,e+Math.sin(l)*r]}),Fe=(t,e,o,r,n,a=-90)=>jt(Array.from({length:o*2},(i,l)=>{const p=Ze(a+l*180/o),c=l%2?n:r;return[t+Math.cos(p)*c,e+Math.sin(p)*c]})),Et=(t,e,o,r)=>`M${g(t,e)} L${g(o,r)}`,wt=(...t)=>t.join(" ");function Uo(t,e,o,r,n){const a=Math.atan2(r-e,o-t)*180/Math.PI,i=n/2;return jt([...Pc(o,r,i,i,a-90,a+90,6),...Pc(t,e,i,i,a+90,a+270,6)])}function wo(t,e,o,r,n=6){const a=[],i=n*6;for(let l=0;l<i;l++){const p=l/i,c=Math.PI*2*p,s=Math.max(0,-Math.sin(c)),h=Math.abs(Math.sin(c*n/2)),f=1+(.18*s+.06)*h;a.push([t+Math.cos(c)*o/2*f,e+Math.sin(c)*r/2*(Math.sin(c)>0?.82:f)])}return sa(a,!0)}function Z8(t,e,o,r=1,n=9,a=.18){const i=[];for(let l=0;l<n;l++){const p=Math.PI*2*l/n,c=Math.sin(r*12.9898+l*78.233)*43758.5453,s=(c-Math.floor(c))*2-1;i.push([t+Math.cos(p)*o*(1+a*s),e+Math.sin(p)*o*(1+a*s)])}return sa(i,!0)}const zc=(t,e,o)=>`M${g(t,e+o*.9)} C${g(t-o*1.3,e+o*.05)} ${g(t-o*1.05,e-o*.95)} ${g(t,e-o*.4)} C${g(t+o*1.05,e-o*.95)} ${g(t+o*1.3,e+o*.05)} ${g(t,e+o*.9)} Z`,On=(t,e,o)=>`M${g(t,e-o)} C${g(t+o*.25,e-o*.45)} ${g(t+o*.75,e-o*.05)} ${g(t+o*.75,e+o*.35)} C${g(t+o*.75,e+o*.8)} ${g(t+o*.4,e+o*1.05)} ${g(t,e+o*1.05)} C${g(t-o*.4,e+o*1.05)} ${g(t-o*.75,e+o*.8)} ${g(t-o*.75,e+o*.35)} C${g(t-o*.75,e-o*.05)} ${g(t-o*.25,e-o*.45)} ${g(t,e-o)} Z`,R=(t,e=1)=>({d:t,fill:null,role:e,_f:!0}),ep=(t,e=1)=>({d:t,fill:null,role:e,_f:!0,eo:!0}),Ct=(t,e=5)=>({d:t,fill:null,role:e,line:!0}),kl=(t,e)=>({d:t,fill:e,role:7}),Wd=Object.freeze(["#f4efe6","#4a90d9","#f2b33d","#e5534b","#ffffff","#2d3142"]),J8=t=>Wd[1+((t-1)%5+5)%5];function Q8(t){return t.map(e=>e.line===!0?{d:e.d,fill:null,role:e.role}:{d:e.d,fill:e.role===7?e.fill:J8(e.role),role:e.role,...e.eo?{eo:!0}:{},...e.line===!1?{line:!1}:{}})}const My=[],Lc={};function to(t,e,o){Lc[t]=[e,o]}function ct(t,e,o,r,n,a,i={}){My.push({id:t,cat:e,vi:o,en:r,words:n,parts:a,human:!!i.human,outline:i.outline??!0,tags:i.tags})}to("people","Người (biểu tượng)","People (pictograms)");const tS=["#f1c7a5","#c68c62","#8d5524"];function Ds({pose:t="stand",body:e="mid"}={}){const o={mid:{h:1,w:1,head:15,limb:13},slim:{h:1.05,w:.82,head:14,limb:10},broad:{h:.98,w:1.28,head:15.5,limb:15},tall:{h:1.15,w:.95,head:15,limb:12},child:{h:.72,w:.9,head:15,limb:10.5},elder:{h:.96,w:1.02,head:14.5,limb:12.5}}[e],r=k=>k*o.h,n=t==="run"?10:t==="elder"?8:0,a=[0,r(18)],i=[n*.6,r(-48)],l=r(-40),p=30*o.w,c=[i[0]+n*.4,i[1]-o.head-6],s={stand:{la:[8,4],ra:[-8,-4],ll:[4,0],rl:[-4,0]},walk:{la:[-28,-10],ra:[30,40],ll:[24,10],rl:[-22,-34]},run:{la:[-55,-110],ra:[55,95],ll:[48,-30],rl:[-40,-80]},sit:{la:[-14,-60],ra:[14,60],ll:[-88,0],rl:[-88,4]},point:{la:[8,4],ra:[-92,-90],ll:[4,0],rl:[-4,0]},wave:{la:[8,4],ra:[-140,-175],ll:[4,0],rl:[-4,0]},cheer:{la:[150,170],ra:[-150,-170],ll:[8,2],rl:[-8,-2]},think:{la:[10,4],ra:[-30,-160],ll:[4,0],rl:[-4,0]},carry:{la:[-60,-95],ra:[60,95],ll:[4,0],rl:[-4,0]},present:{la:[8,4],ra:[-120,-100],ll:[6,0],rl:[-6,0]},elder:{la:[12,6],ra:[-30,-20],ll:[6,2],rl:[-6,-2]}}[t],h=(k,[b,A],I,P,C)=>{const z=Ze(b),N=Ze(A),F=[k[0]+Math.sin(z)*I,k[1]+Math.cos(z)*I],K=[F[0]+Math.sin(N)*P,F[1]+Math.cos(N)*P];return{d:wt(Uo(k[0],k[1],F[0],F[1],C),Uo(F[0],F[1],K[0],K[1],C*.92)),end:K}},f=r(30),m=r(36),y=p/2-o.limb*.35,$=h([i[0]+y,l],s.la,f,f*.95,o.limb),x=h([i[0]-y,l],s.ra,f,f*.95,o.limb),E=h([a[0]+p*.22,a[1]-2],s.ll,m,m,o.limb*1.12),v=h([a[0]-p*.22,a[1]-2],s.rl,m,m,o.limb*1.12),S=sa([[i[0]-p/2,l-6],[i[0]+p/2,l-6],[a[0]+p*.44,a[1]+4],[a[0]-p*.44,a[1]+4]],!0,.35);return{head:kt(c[0],c[1],o.head),torso:S,la:$,ra:x,ll:E,rl:v}}const qn=(t,e=1)=>[R(wt(t.ll.d,t.rl.d,t.la.d,t.torso,t.ra.d,t.head),e)],eS=[["stand","đứng","standing"],["walk","đi bộ","walking"],["run","chạy","running"],["sit","ngồi","sitting"],["point","chỉ tay","pointing"],["wave","vẫy tay","waving"],["cheer","reo hò","cheering"],["think","suy nghĩ","thinking"],["carry","bê đồ","carrying"],["present","thuyết trình","presenting"]],Fn={role:["explain","overlay"],style:["clean","minimal","corporate"]};for(const[t,e,o]of eS){const r=Ds({pose:t}),n=(r.la.end[0]+r.ra.end[0])/2,a=(r.la.end[1]+r.ra.end[1])/2,i=t==="carry"?[R(pt(n,a-14,58,40,4),2)]:t==="sit"?[R(wt(pt(-14,30,72,10,3),pt(-44,56,8,44,2),pt(18,22,8,112,2)),5)]:t==="present"?[R(pt(-130,-40,90,64,4),4),Ct(wt(Et(-160,-20,-102,-20),Et(-160,-4,-110,-4),Et(-160,12,-120,12)),5)]:[];ct(`person-${t}`,"people",`Người ${e}`,`Person ${o}`,["người","person","human","pictogram",e,o],t==="present"||t==="sit"?[...i,...qn(r)]:[...qn(r),...i],{human:!0,tags:Fn})}for(const[t,e,o]of[["slim","dáng gầy","slim"],["broad","dáng đậm","broad"],["tall","dáng cao","tall"],["child","trẻ em","child"],["elder","người lớn tuổi","elder"]]){const r=Ds({pose:t==="elder"?"elder":"stand",body:t}),n=t==="elder"?[R(Uo(-34,-6,-40,72,5),5)]:[];ct(`person-${t}`,"people",`Người ${e}`,`Person ${o}`,["người","person","human","pictogram","body",e,o],[...qn(r,t==="child"?3:1),...n],{human:!0,tags:Fn})}{const t=Ds({pose:"stand"}),e=Ds({pose:"stand",body:"child"}),o=(r,n)=>r.replace(/(-?\d*\.?\d+) (-?\d*\.?\d+)/g,(a,i,l)=>`${aa(+i+n)} ${l}`);ct("people-family","people","Gia đình","Family",["gia đình","family","parent","child","người","people"],[...qn(t).map(r=>({...r,d:o(r.d,-34)})),...qn(e,3).map(r=>({...r,d:o(r.d.replace(/(-?\d*\.?\d+) (-?\d*\.?\d+)/g,(n,a,i)=>`${a} ${aa(+i+16)}`),34)}))],{human:!0,tags:Fn}),ct("people-group","people","Nhóm người","Group of people",["nhóm","group","team","đội","people","người"],[...qn(t,2).map(r=>({...r,d:o(r.d,-52)})),...qn(t,3).map(r=>({...r,d:o(r.d,52)})),...qn(t,1)],{human:!0,tags:Fn})}for(const[t,e,o]of[["stand","đứng","standing"],["walk","đi bộ","walking"],["run","chạy","running"],["wave","vẫy tay","waving"],["present","thuyết trình","presenting"]]){const r=Ds({pose:t});ct(`silhouette-${t}`,"people",`Bóng người ${e}`,`Silhouette ${o}`,["bóng","silhouette","người","person",e,o],[{d:wt(r.ll.d,r.rl.d,r.la.d,r.torso,r.ra.d,r.head),fill:null,role:5,_f:!0,line:!1}],{human:!0,tags:Fn})}function op({skin:t=0,hair:e="short",top:o=1,bottom:r=5,arm:n="down"}){const a=tS[t],i=[];i.push(R(Uo(-14,40,-16,96,17),r),R(Uo(14,40,16,96,17),r)),i.push(R(pt(-17,100,26,10,5),5),R(pt(17,100,26,10,5),5));const l=n==="wave"?wt(Uo(-30,-14,-44,30,13)):Uo(-30,-14,-40,34,13),p=n==="wave"?Uo(30,-14,56,-50,13):Uo(30,-14,40,34,13);return i.push(R(l,o),R(p,o),kl(kt(-41,38,8),a),kl(kt(n==="wave"?58:41,n==="wave"?-56:38,8),a)),i.push(R(sa([[-30,-24],[30,-24],[34,46],[-34,46]],!0,.4),o)),i.push(kl(pt(0,-30,14,12,3),a),kl(kt(0,-58,26),a)),e==="short"?i.push(R(wt(`M${g(-27,-60)} C${g(-28,-92)} ${g(28,-92)} ${g(27,-60)} C${g(18,-74)} ${g(-10,-78)} ${g(-27,-60)} Z`),5)):e==="long"?i.push(R(`M${g(-29,-56)} C${g(-34,-96)} ${g(34,-96)} ${g(29,-56)} L${g(30,-20)} L${g(18,-22)} L${g(20,-56)} C${g(8,-70)} ${g(-14,-72)} ${g(-20,-56)} L${g(-18,-22)} L${g(-30,-20)} Z`,5)):i.push(R(`M${g(-28,-62)} C${g(-28,-92)} ${g(28,-92)} ${g(28,-62)} Z`,3),R(pt(14,-64,34,8,4),3)),i.push({...R(wt(kt(-9,-58,2.6),kt(9,-58,2.6)),5),line:!1},Ct(Ge(0,-50,8,20,160),5)),i}ct("character-a","people","Nhân vật phẳng A","Flat character A",["nhân vật","character","người","person","flat"],op({skin:0,hair:"short",top:1}),{human:!0,tags:Fn});ct("character-b","people","Nhân vật phẳng B","Flat character B",["nhân vật","character","người","person","flat"],op({skin:1,hair:"long",top:3,bottom:2}),{human:!0,tags:Fn});ct("character-c","people","Nhân vật phẳng C (vẫy tay)","Flat character C (waving)",["nhân vật","character","người","person","wave","vẫy"],op({skin:2,hair:"cap",top:2,arm:"wave"}),{human:!0,tags:Fn});ct("character-d","people","Nhân vật phẳng D","Flat character D",["nhân vật","character","người","person","flat"],op({skin:1,hair:"short",top:4,bottom:1,arm:"wave"}),{human:!0,tags:Fn});to("hands","Bàn tay & cử chỉ","Hands & gestures");const rp=(t=0,e=10)=>pt(t,e,56,58,18),Fo=(t,e,o,r=0,n=14)=>Uo(t,e,t+Math.sin(Ze(r))*o,e-Math.cos(Ze(r))*o,n),la={role:["explain","sticker"],style:["playful","clean"]};ct("hand-thumbs-up","hands","Like (giơ ngón cái)","Thumbs up",["like","thích","ngón cái","thumb"],[R(pt(0,14,52,56,14),4),R(Fo(-18,-6,40,-8,18),4),R(wt(pt(18,0,22,12,6),pt(18,14,22,12,6),pt(18,28,22,12,6)),4),R(pt(0,60,58,22,4),1)],{tags:la});ct("hand-point","hands","Tay chỉ","Pointing hand",["chỉ","point","tay","hand"],[R(pt(6,14,50,48,14),4),R(Uo(-10,0,-70,-4,15),4),R(wt(pt(26,0,18,12,6),pt(26,13,18,12,6),pt(26,26,18,12,6)),4),R(pt(14,52,40,20,4),1)],{tags:la});ct("hand-open","hands","Bàn tay mở","Open palm",["bàn tay","palm","stop","dừng","hi"],[R(rp(),4),R(wt(Fo(-20,-10,40,-6),Fo(-6,-14,46,-2),Fo(8,-14,44,2),Fo(21,-10,36,8),Fo(-30,16,30,-60)),4),R(pt(0,52,52,18,4),1)],{tags:la});ct("hand-ok","hands","Tay OK","OK hand",["ok","tốt","được"],[R(rp(4,14),4),R(wt(Fo(-2,-12,44,2),Fo(12,-10,40,8),Fo(24,-4,32,14)),4),R(wt(kt(-22,-10,16)),4),Ct(kt(-22,-10,7),5)],{tags:la});ct("hand-peace","hands","Tay chữ V","Peace sign",["peace","chiến thắng","victory","v"],[R(rp(0,16),4),R(wt(Fo(-10,-8,50,-14),Fo(8,-8,50,12)),4),R(pt(0,54,52,18,4),1)],{tags:la});ct("hand-fist","hands","Nắm tay","Fist",["nắm tay","fist","power","sức mạnh"],[R(pt(0,4,60,54,16),4),Ct(wt(Et(-14,-22,-14,-6),Et(2,-22,2,-6),Et(18,-22,18,-6)),5),R(pt(0,48,52,22,4),1)],{tags:la});ct("hand-wave","hands","Tay vẫy","Waving hand",["vẫy","wave","hello","xin chào"],[R(rp(),4),R(wt(Fo(-20,-10,40,-16),Fo(-6,-14,46,-8),Fo(8,-14,44,-2),Fo(21,-10,36,4),Fo(-30,16,30,-70)),4),Ct(wt(Ge(48,-30,16,-60,40),Ge(48,-30,28,-60,40)),3)],{tags:la});ct("hand-clap","hands","Vỗ tay","Clapping hands",["vỗ tay","clap","applause"],[R(pt(-14,4,40,70,16),4),R(pt(14,0,40,70,16),4),Ct(wt(Et(-48,-40,-38,-30),Et(-30,-56,-26,-42),Et(46,-44,36,-32)),3)],{tags:la});to("faces","Mặt & biểu cảm","Faces & emoji");const oS={role:["sticker","social"],style:["playful"]},Or=(t,e,o,r,n)=>ct(`face-${t}`,"faces",e,o,["mặt","face","emoji","biểu cảm",...r],[R(kt(0,0,60),2),...n],{tags:oS}),Va=(t=-12,e=7)=>R(wt(kt(-20,t,e),kt(20,t,e)),5);Or("smile","Mặt cười","Smile",["vui","happy","cười"],[Va(),Ct(Ge(0,4,28,25,155),5)]);Or("grin","Cười toe","Grin",["toe","grin","haha"],[Va(),R(`M${g(-32,8)} L${g(32,8)} C${g(30,40)} ${g(-30,40)} ${g(-32,8)} Z`,5),R(`M${g(-24,10)} L${g(24,10)} L${g(22,18)} L${g(-22,18)} Z`,4)]);Or("sad","Buồn","Sad",["buồn","sad"],[Va(-8),Ct(Ge(0,38,24,205,335),5)]);Or("wink","Nháy mắt","Wink",["nháy mắt","wink"],[R(kt(-20,-12,7),5),Ct(Ge(20,-10,9,200,340),5),Ct(Ge(0,4,28,25,155),5)]);Or("surprised","Ngạc nhiên","Surprised",["ngạc nhiên","wow","surprised","bất ngờ"],[Va(-14,8),R($e(0,24,12,16),5)]);Or("love","Mắt tim","Heart eyes",["yêu","love","tim"],[R(wt(zc(-21,-12,13),zc(21,-12,13)),3),Ct(Ge(0,4,28,25,155),5)]);Or("cool","Đeo kính","Cool",["ngầu","cool","kính"],[R(wt(pt(-21,-12,34,20,8),pt(21,-12,34,20,8)),5),Ct(Et(-4,-14,4,-14),5),Ct(Ge(0,10,22,30,150),5)]);Or("angry","Giận","Angry",["giận","angry","tức"],[Va(-6),Ct(wt(Et(-34,-30,-10,-20),Et(34,-30,10,-20)),5),Ct(Ge(0,38,20,210,330),5)]);Or("laugh","Cười lớn","Laugh",["cười lớn","laugh","lol"],[Ct(wt(Ge(-20,-10,9,200,340),Ge(20,-10,9,200,340)),5),R(`M${g(-34,4)} L${g(34,4)} C${g(32,46)} ${g(-32,46)} ${g(-34,4)} Z`,5),R($e(0,32,14,8),3)]);Or("think","Suy nghĩ","Thinking",["nghĩ","thinking","hmm"],[Va(-12,6),Ct(Et(-16,24,18,18),5),Ct(wt(Et(-28,-30,-10,-26)),5)]);Or("sleepy","Buồn ngủ","Sleepy",["ngủ","sleepy","zzz"],[Ct(wt(Et(-28,-10,-12,-10),Et(12,-10,28,-10)),5),R($e(0,24,8,10),5),Ct(wt(jt([[40,-60],[56,-60],[40,-44],[56,-44]],!1)),5)]);Or("neutral","Bình thường","Neutral",["bình thường","neutral","meh"],[Va(),Ct(Et(-20,22,20,22),5)]);to("nature","Thiên nhiên","Nature");const eo={role:["overlay","background","explain"],style:["playful","soft","clean"]};ct("tree-round","nature","Cây tán tròn","Round tree",["cây","tree","xanh"],[R(pt(0,50,18,70,4),5),R(wo(0,-20,140,120,5),1)],{tags:eo});ct("tree-pine","nature","Cây thông","Pine tree",["thông","pine","cây","noel"],[R(pt(0,78,16,34,3),5),R(jt([[0,-96],[46,-28],[24,-28],[60,30],[30,30],[70,82],[-70,82],[-30,30],[-60,30],[-24,-28],[-46,-28]]),1)],{tags:eo});ct("tree-palm","nature","Cây dừa","Palm tree",["dừa","palm","biển","cây"],[R(`M${g(-4,96)} C${g(-8,40)} ${g(4,-10)} ${g(14,-50)} L${g(26,-46)} C${g(16,-6)} ${g(8,44)} ${g(12,96)} Z`,5),R(wt(`M${g(18,-52)} C${g(-20,-90)} ${g(-60,-70)} ${g(-80,-40)} C${g(-40,-60)} ${g(-10,-56)} ${g(18,-52)} Z`,`M${g(18,-52)} C${g(50,-96)} ${g(90,-80)} ${g(100,-46)} C${g(70,-64)} ${g(44,-60)} ${g(18,-52)} Z`,`M${g(18,-52)} C${g(30,-100)} ${g(10,-120)} ${g(-14,-118)} C${g(6,-104)} ${g(14,-80)} ${g(18,-52)} Z`,`M${g(18,-52)} C${g(60,-40)} ${g(70,-6)} ${g(64,20)} C${g(52,-6)} ${g(38,-30)} ${g(18,-52)} Z`),1)],{tags:eo});ct("bush","nature","Bụi cây","Bush",["bụi","bush","cỏ"],[R(wo(0,10,170,90,6),1)],{tags:eo});ct("flower","nature","Bông hoa","Flower",["hoa","flower"],[R(Uo(0,10,0,96,8),1),R(`M${g(0,60)} C${g(30,40)} ${g(48,52)} ${g(50,64)} C${g(30,70)} ${g(14,68)} ${g(0,60)} Z`,1),R(wt(...xy(0,-30,6,30).map(([t,e])=>kt(t,e,20))),3),R(kt(0,-30,16),2)],{tags:eo});ct("tulip","nature","Hoa tulip","Tulip",["tulip","hoa","flower"],[R(Uo(0,0,0,96,7),1),R(`M${g(0,64)} C${g(-34,44)} ${g(-40,20)} ${g(-34,4)} C${g(-20,26)} ${g(-10,40)} ${g(0,64)} Z`,1),R(`M${g(-34,-70)} L${g(-17,-46)} L${g(0,-74)} L${g(17,-46)} L${g(34,-70)} C${g(40,-20)} ${g(24,4)} ${g(0,4)} C${g(-24,4)} ${g(-40,-20)} ${g(-34,-70)} Z`,3)],{tags:eo});ct("leaf","nature","Chiếc lá","Leaf",["lá","leaf"],[R(`M${g(-70,60)} C${g(-70,-20)} ${g(-10,-80)} ${g(70,-70)} C${g(70,10)} ${g(10,70)} ${g(-70,60)} Z`,1),Ct(wt(`M${g(-70,60)} C${g(-20,10)} ${g(20,-30)} ${g(60,-60)}`,Et(-24,16,-30,-10),Et(4,-12,2,-40),Et(-24,16,4,22),Et(4,-12,30,-6)),5)],{tags:eo});ct("cactus","nature","Xương rồng","Cactus",["xương rồng","cactus","sa mạc"],[R(pt(0,80,70,30,4),3),R(wt(pt(0,0,36,150,18),`M${g(-18,10)} L${g(-40,10)} C${g(-50,10)} ${g(-54,4)} ${g(-54,-6)} L${g(-54,-40)} C${g(-54,-52)} ${g(-38,-52)} ${g(-38,-40)} L${g(-38,-6)} L${g(-18,-6)} Z`,`M${g(18,20)} L${g(42,20)} C${g(52,20)} ${g(56,14)} ${g(56,4)} L${g(56,-24)} C${g(56,-36)} ${g(40,-36)} ${g(40,-24)} L${g(40,4)} L${g(18,4)} Z`),1)],{tags:eo});ct("mushroom","nature","Cây nấm","Mushroom",["nấm","mushroom"],[R(`M${g(-20,0)} L${g(20,0)} L${g(24,70)} L${g(-24,70)} Z`,4),R(`M${g(-80,10)} C${g(-80,-70)} ${g(80,-70)} ${g(80,10)} Z`,3),R(wt(kt(-36,-20,10),kt(10,-40,12),kt(44,-10,8)),4)],{tags:eo});ct("grass","nature","Đám cỏ","Grass tuft",["cỏ","grass"],[R(jt([[-80,40],[-70,-10],[-56,40],[-44,-40],[-28,40],[-14,-20],[0,40],[12,-50],[28,40],[40,-14],[54,40],[66,-30],[80,40]]),1)],{tags:eo});ct("mountain","nature","Núi","Mountain",["núi","mountain"],[R(jt([[-110,70],[-20,-70],[90,70]]),1),R(jt([[-20,-70],[-44,-32],[-30,-38],[-18,-26],[-4,-40],[8,-30]]),4),R(jt([[20,70],[70,-10],[120,70]]),2)],{tags:eo});ct("hills","nature","Đồi","Hills",["đồi","hills","đồng cỏ"],[R(`M${g(-130,60)} C${g(-90,-30)} ${g(-30,-30)} ${g(10,60)} Z`,1),R(`M${g(-30,60)} C${g(10,-50)} ${g(90,-50)} ${g(130,60)} Z`,2)],{tags:eo});ct("rock","nature","Hòn đá","Rock",["đá","rock","stone"],[R(sa([[-60,40],[-50,-10],[-14,-34],[30,-26],[58,8],[60,40]],!0,.5),5)],{tags:eo});ct("sun","nature","Mặt trời","Sun",["mặt trời","sun","nắng"],[R(Fe(0,0,12,96,70,-90),3),R(kt(0,0,58),2)],{tags:eo});ct("moon","nature","Trăng khuyết","Crescent moon",["trăng","moon","đêm","night"],[R(`M${g(20,-70)} C${g(-40,-70)} ${g(-70,-20)} ${g(-60,20)} C${g(-50,60)} ${g(0,80)} ${g(40,60)} C${g(0,50)} ${g(-24,10)} ${g(-10,-30)} C${g(-2,-52)} ${g(10,-64)} ${g(20,-70)} Z`,2),R(wt(Fe(50,-40,4,10,4,0),Fe(60,20,4,7,3,0)),4)],{tags:eo});ct("cloud","nature","Đám mây","Cloud",["mây","cloud"],[R(wo(0,0,190,100,6),4)],{tags:eo});ct("waves","nature","Sóng biển","Waves",["sóng","biển","sea","waves","nước"],[R(`M${g(-120,0)} C${g(-100,-30)} ${g(-80,-30)} ${g(-60,0)} C${g(-40,-30)} ${g(-20,-30)} ${g(0,0)} C${g(20,-30)} ${g(40,-30)} ${g(60,0)} C${g(80,-30)} ${g(100,-30)} ${g(120,0)} L${g(120,50)} L${g(-120,50)} Z`,1),Ct(wt(`M${g(-110,24)} C${g(-90,10)} ${g(-70,10)} ${g(-50,24)}`,`M${g(10,30)} C${g(30,16)} ${g(50,16)} ${g(70,30)}`),4)],{tags:eo});ct("river","nature","Dòng sông","River",["sông","river","suối"],[R(`M${g(-30,-90)} C${g(30,-60)} ${g(-60,-10)} ${g(-10,30)} C${g(30,60)} ${g(-10,80)} ${g(10,100)} L${g(70,100)} C${g(40,80)} ${g(80,50)} ${g(40,20)} C${g(-10,-20)} ${g(70,-60)} ${g(10,-90)} Z`,1)],{tags:eo});ct("island","nature","Đảo nhỏ","Island",["đảo","island","biển"],[R(`M${g(-110,50)} C${g(-60,20)} ${g(60,20)} ${g(110,50)} Z`,1),R(`M${g(-70,40)} C${g(-50,0)} ${g(50,0)} ${g(70,40)} Z`,3),R(`M${g(0,30)} C${g(-4,0)} ${g(4,-30)} ${g(12,-54)} L${g(20,-50)} C${g(12,-28)} ${g(8,0)} ${g(10,30)} Z`,5),R(wt(`M${g(14,-56)} C${g(-10,-80)} ${g(-40,-70)} ${g(-50,-50)} C${g(-24,-62)} ${g(-4,-60)} ${g(14,-56)} Z`,`M${g(14,-56)} C${g(36,-84)} ${g(64,-74)} ${g(70,-52)} C${g(50,-64)} ${g(32,-62)} ${g(14,-56)} Z`),1)],{tags:eo});ct("rainbow","nature","Cầu vồng","Rainbow",["cầu vồng","rainbow"],[R(`M${g(-100,40)} C${g(-100,-90)} ${g(100,-90)} ${g(100,40)} L${g(80,40)} C${g(80,-66)} ${g(-80,-66)} ${g(-80,40)} Z`,3),R(`M${g(-80,40)} C${g(-80,-66)} ${g(80,-66)} ${g(80,40)} L${g(60,40)} C${g(60,-42)} ${g(-60,-42)} ${g(-60,40)} Z`,2),R(`M${g(-60,40)} C${g(-60,-42)} ${g(60,-42)} ${g(60,40)} L${g(40,40)} C${g(40,-18)} ${g(-40,-18)} ${g(-40,40)} Z`,1),R(wo(-80,46,70,36,4),4),R(wo(80,46,70,36,4),4)],{tags:eo});to("weather","Thời tiết","Weather");const Rn={role:["overlay","explain","sticker"],style:["playful","clean"]};ct("weather-sun-cloud","weather","Nắng có mây","Sun and cloud",["nắng","mây","partly cloudy"],[R(Fe(-26,-24,10,62,46,-90),3),R(kt(-26,-24,38),2),R(wo(20,20,150,80,5),4)],{tags:Rn});ct("weather-rain","weather","Mây mưa","Rain cloud",["mưa","rain"],[R(wo(0,-20,170,90,6),4),R(wt(On(-40,58,12),On(0,72,12),On(40,58,12)),1)],{tags:Rn});ct("weather-storm","weather","Giông bão","Storm",["bão","sấm","storm","thunder"],[R(wo(0,-24,170,90,6),5),R(jt([[6,10],[-20,56],[0,56],[-12,96],[30,40],[10,40],[24,10]]),2)],{tags:Rn});ct("weather-snow","weather","Tuyết rơi","Snow",["tuyết","snow","lạnh"],[R(wo(0,-24,170,90,6),4),Ct(wt(...[[-40,60],[0,74],[40,60]].flatMap(([t,e])=>[Et(t-9,e,t+9,e),Et(t-5,e-8,t+5,e+8),Et(t-5,e+8,t+5,e-8)])),1)],{tags:Rn});ct("snowflake","weather","Bông tuyết","Snowflake",["tuyết","snowflake","noel"],[Ct(wt(...[0,60,120].map(t=>{const e=Math.cos(Ze(t)),o=Math.sin(Ze(t));return Et(-80*e,-80*o,80*e,80*o)}),...[0,60,120,180,240,300].flatMap(t=>{const e=Math.cos(Ze(t)),o=Math.sin(Ze(t)),r=50*e,n=50*o;return[Et(r,n,r+Math.cos(Ze(t+40))*22,n+Math.sin(Ze(t+40))*22),Et(r,n,r+Math.cos(Ze(t-40))*22,n+Math.sin(Ze(t-40))*22)]})),1)],{tags:Rn});ct("wind","weather","Gió","Wind",["gió","wind"],[Ct(wt(`M${g(-90,-30)} L${g(30,-30)} C${g(60,-30)} ${g(60,-70)} ${g(34,-70)}`,`M${g(-70,0)} L${g(60,0)} C${g(96,0)} ${g(96,48)} ${g(64,48)}`,`M${g(-100,30)} L${g(0,30)}`),1)],{tags:Rn});ct("umbrella","weather","Cái ô","Umbrella",["ô","dù","umbrella","mưa"],[R(`M${g(-90,0)} C${g(-90,-80)} ${g(90,-80)} ${g(90,0)} C${g(70,-14)} ${g(50,-14)} ${g(30,0)} C${g(10,-14)} ${g(-10,-14)} ${g(-30,0)} C${g(-50,-14)} ${g(-70,-14)} ${g(-90,0)} Z`,3),Ct(`M${g(0,-4)} L${g(0,70)} C${g(0,90)} ${g(-26,90)} ${g(-26,72)}`,5)],{tags:Rn});ct("thermometer","weather","Nhiệt kế","Thermometer",["nhiệt độ","nóng","thermometer","temperature"],[R(wt(pt(0,-20,30,130,15)),4),R(kt(0,56,26),3),R(pt(0,10,12,80,6),3),Ct(wt(Et(18,-60,28,-60),Et(18,-36,28,-36),Et(18,-12,28,-12)),5)],{tags:Rn});ct("lightning","weather","Tia sét","Lightning bolt",["sét","lightning","điện","energy"],[R(jt([[14,-96],[-46,10],[-6,10],[-22,96],[48,-20],[6,-20]]),2)],{tags:Rn});to("city","Nhà cửa & phố","Buildings & city");const So={role:["background","explain","overlay"],style:["clean","playful"]},Ro=(t,e,o=18,r=22)=>pt(t,e,o,r,2);ct("house","city","Ngôi nhà","House",["nhà","house","home"],[R(pt(0,30,140,100,2),4),R(jt([[-86,-16],[0,-90],[86,-16]]),3),R(pt(40,-70,18,36,1),5),R(pt(-30,50,34,60,3),1),R(wt(Ro(28,20,30,28)),2),Ct(wt(Et(28,6,28,34),Et(13,20,43,20)),5)],{tags:So});ct("house-two-storey","city","Nhà hai tầng","Two-storey house",["nhà","nhà phố","townhouse","house"],[R(pt(0,10,120,160,2),4),R(jt([[-72,-70],[0,-118],[72,-70]]),3),R(wt(Ro(-30,-40,26,30),Ro(30,-40,26,30),Ro(30,30,26,30)),2),R(pt(-30,56,30,68,3),1),R(pt(0,-2,130,8,2),5)],{tags:So});ct("apartment","city","Chung cư","Apartment block",["chung cư","căn hộ","apartment"],[R(pt(0,0,130,200,4),1),R(wt(...[-70,-30,10,50].flatMap(t=>[-38,0,38].map(e=>Ro(e,t,22,24)))),4),R(pt(0,88,34,24,2),5)],{tags:So});ct("skyscraper","city","Toà nhà cao tầng","Skyscraper",["cao ốc","tòa nhà","office tower","skyscraper"],[R(jt([[-40,110],[-40,-80],[0,-110],[40,-80],[40,110]]),2),R(wt(...Array.from({length:8},(t,e)=>pt(0,-60+e*20,56,8,1))),4),R(pt(0,-120,4,30,1),5)],{tags:So});ct("shop","city","Cửa hàng","Shop",["cửa hàng","shop","store","tiệm"],[R(pt(0,26,150,104,2),4),R(wt(...[-60,-20,20,60].map(t=>`M${g(t-20,-26)} L${g(t+20,-26)} L${g(t+20,-6)} C${g(t+20,6)} ${g(t-20,6)} ${g(t-20,-6)} Z`)),3),R(pt(0,-36,160,22,3),1),R(pt(-36,46,40,60,2),2),R(pt(30,36,50,40,2),2)],{tags:So});ct("factory","city","Nhà máy","Factory",["nhà máy","factory","sản xuất","industry"],[R(jt([[-100,80],[-100,-10],[-50,-40],[-50,-10],[0,-40],[0,-10],[50,-40],[50,-10],[100,-10],[100,80]]),4),R(pt(70,-60,22,100,2),5),R(wo(84,-100,50,30,4),4),R(wt(Ro(-70,30),Ro(-30,30),Ro(10,30)),2)],{tags:So});ct("school","city","Trường học","School",["trường","school","học","education"],[R(pt(0,30,170,100,2),4),R(jt([[-50,-20],[0,-70],[50,-20]]),3),R(pt(0,0,100,40,2),4),R(kt(0,-30,12),2),R(wt(Ro(-62,30),Ro(-32,30),Ro(32,30),Ro(62,30)),2),R(pt(0,56,24,48,2),1),Ct(Et(0,-70,0,-100),5),R(jt([[0,-100],[24,-92],[0,-84]]),3)],{tags:So});ct("hospital","city","Bệnh viện","Hospital",["bệnh viện","hospital","y tế","health"],[R(pt(0,20,170,140,4),4),R(wt(pt(0,-20,40,12,2),pt(0,-20,12,40,2)),3),R(wt(Ro(-56,30),Ro(-26,30),Ro(26,30),Ro(56,30)),2),R(pt(0,68,30,44,2),1)],{tags:So});ct("bank","city","Ngân hàng","Bank",["ngân hàng","bank","tài chính","finance"],[R(jt([[-90,-40],[0,-90],[90,-40]]),3),R(pt(0,-34,170,14,2),5),R(wt(...[-60,-20,20,60].map(t=>pt(t,20,16,90,2))),4),R(pt(0,72,180,14,2),5)],{tags:So});ct("pagoda","city","Chùa / tháp","Pagoda",["chùa","tháp","pagoda","temple","đình"],[R(pt(0,70,70,40,2),4),R(`M${g(-70,48)} C${g(-40,40)} ${g(40,40)} ${g(70,48)} L${g(52,30)} L${g(-52,30)} Z`,3),R(pt(0,10,56,40,2),4),R(`M${g(-58,-8)} C${g(-30,-16)} ${g(30,-16)} ${g(58,-8)} L${g(42,-24)} L${g(-42,-24)} Z`,3),R(pt(0,-40,42,32,2),4),R(`M${g(-46,-54)} C${g(-20,-62)} ${g(20,-62)} ${g(46,-54)} L${g(0,-90)} Z`,3)],{tags:So});ct("bridge","city","Cây cầu","Bridge",["cầu","bridge"],[R(`M${g(-130,10)} L${g(130,10)} L${g(130,26)} L${g(-130,26)} Z`,5),Ct(wt(`M${g(-130,10)} C${g(-60,-70)} ${g(60,-70)} ${g(130,10)}`,...[-90,-60,-30,0,30,60,90].map(t=>Et(t,10,t,10-Math.max(0,62-Math.abs(t)*.6)))),1),R(wt(pt(-80,48,20,44,2),pt(80,48,20,44,2)),5)],{tags:So});ct("streetlamp","city","Đèn đường","Street lamp",["đèn đường","street lamp","đèn"],[R(pt(0,10,10,180,4),5),R(`M${g(-24,-80)} L${g(24,-80)} L${g(16,-64)} L${g(-16,-64)} Z`,5),R($e(0,-60,14,8),2),R(pt(0,98,30,10,3),5)],{tags:So});ct("traffic-light","city","Đèn giao thông","Traffic light",["đèn giao thông","traffic light","đèn xanh đỏ"],[R(pt(0,-10,50,130,12),5),R(kt(0,-50,15),3),R(kt(0,-10,15),2),R(kt(0,30,15),1),R(pt(0,90,10,70,3),5)],{tags:So});ct("skyline","city","Đường chân trời thành phố","City skyline",["thành phố","city","skyline","phố"],[R(jt([[-140,60],[-140,-10],[-110,-10],[-110,-40],[-80,-40],[-80,0],[-60,0],[-60,-70],[-30,-70],[-30,-20],[-10,-20],[-10,-50],[20,-50],[20,-90],[40,-90],[40,-30],[70,-30],[70,-60],[100,-60],[100,-10],[140,-10],[140,60]]),5),R(wt(...[[-125,10],[-95,-20],[-45,-50],[-45,-30],[30,-70],[30,-50],[85,-40],[120,10]].map(([t,e])=>pt(t,e,8,10,1))),2)],{tags:So});ct("tent","city","Lều trại","Tent",["lều","cắm trại","tent","camping"],[R(jt([[-90,60],[0,-70],[90,60]]),3),R(jt([[-26,60],[0,0],[26,60]]),5),Ct(wt(Et(0,-70,-10,-90),Et(0,-70,10,-90)),5)],{tags:So});ct("castle","city","Lâu đài","Castle",["lâu đài","castle","cổ tích"],[R(wt(pt(-60,10,40,130,0),pt(60,10,40,130,0),pt(0,30,90,90,0)),4),R(wt(...[-74,-46,46,74].map(t=>pt(t,-62,12,16,0)),...[-30,0,30].map(t=>pt(t,-22,14,14,0))),4),R(wt(jt([[-84,-70],[-60,-110],[-36,-70]]),jt([[36,-70],[60,-110],[84,-70]])),3),R(`M${g(-18,76)} L${g(-18,40)} C${g(-18,20)} ${g(18,20)} ${g(18,40)} L${g(18,76)} Z`,5)],{tags:So});ct("cafe-front","city","Quán cà phê","Café front",["quán","cà phê","cafe","coffee shop"],[R(pt(0,26,160,104,2),4),R(wt(...[-60,-30,0,30,60].map((t,e)=>`M${g(t-15,-34)} L${g(t+15,-34)} L${g(t+15,-14)} L${g(t-15,-14)} Z`)),3),R(pt(0,-40,170,14,2),1),R(pt(-40,40,46,64,2),2),R(pt(34,40,60,44,2),2),R(wt(kt(40,-60,4),Et(30,-66,50,-66)),5)],{tags:So});to("transport","Phương tiện","Transport");const Pr={role:["explain","overlay"],style:["playful","clean"]},cr=(t,e,o=16)=>[R(kt(t,e,o),5),R(kt(t,e,o*.4),4)];ct("car","transport","Ô tô","Car",["ô tô","xe hơi","car"],[R(`M${g(-100,30)} L${g(-100,0)} C${g(-100,-10)} ${g(-90,-14)} ${g(-80,-16)} L${g(-56,-20)} L${g(-30,-50)} C${g(-24,-56)} ${g(-18,-58)} ${g(-10,-58)} L${g(40,-58)} C${g(50,-58)} ${g(56,-54)} ${g(62,-46)} L${g(80,-20)} C${g(94,-18)} ${g(100,-10)} ${g(100,0)} L${g(100,30)} Z`,3),R(wt(`M${g(-44,-22)} L${g(-24,-46)} L${g(4,-46)} L${g(4,-22)} Z`,`M${g(16,-22)} L${g(16,-46)} L${g(44,-46)} L${g(62,-22)} Z`),4),...cr(-54,32,20),...cr(56,32,20)],{tags:Pr});ct("taxi","transport","Taxi","Taxi",["taxi","xe"],[R(`M${g(-100,30)} L${g(-100,-4)} L${g(-60,-20)} L${g(-36,-52)} L${g(40,-52)} L${g(66,-20)} L${g(100,-6)} L${g(100,30)} Z`,2),R(pt(0,-62,40,14,3),5),R(wt(`M${g(-48,-22)} L${g(-30,-44)} L${g(-2,-44)} L${g(-2,-22)} Z`,`M${g(10,-22)} L${g(10,-44)} L${g(36,-44)} L${g(54,-22)} Z`),4),...cr(-54,32,20),...cr(56,32,20)],{tags:Pr});ct("bus","transport","Xe buýt","Bus",["xe buýt","bus"],[R(pt(0,-10,220,100,14),1),R(wt(...[-80,-40,0,40].map(t=>pt(t,-30,30,30,4)),pt(86,-20,26,50,4)),4),R(pt(0,24,220,8,2),4),...cr(-64,46,20),...cr(64,46,20)],{tags:Pr});ct("truck","transport","Xe tải","Truck",["xe tải","truck","giao hàng","delivery"],[R(pt(-30,-14,140,90,6),4),R(`M${g(44,30)} L${g(44,-30)} L${g(84,-30)} L${g(110,4)} L${g(110,30)} Z`,1),R(`M${g(54,-20)} L${g(80,-20)} L${g(98,2)} L${g(54,2)} Z`,4),...cr(-60,38,18),...cr(70,38,18)],{tags:Pr});ct("bicycle","transport","Xe đạp","Bicycle",["xe đạp","bicycle","bike"],[Ct(wt(kt(-56,30,34),kt(56,30,34),jt([[-56,30],[-14,-26],[36,-26],[56,30]],!1),jt([[-14,-26],[0,30],[36,-26]],!1),Et(0,30,-56,30),Et(-20,-40,-4,-40),Et(36,-26,30,-46),Et(22,-48,42,-48)),5)],{tags:Pr});ct("scooter","transport","Xe máy","Motorbike",["xe máy","motorbike","scooter","xe tay ga"],[R(`M${g(-70,20)} C${g(-70,-10)} ${g(-40,-24)} ${g(-10,-20)} L${g(30,-20)} L${g(50,-60)} L${g(64,-60)} L${g(56,20)} Z`,3),R(pt(-30,-30,60,14,6),5),...cr(-56,30,22),...cr(64,30,22),Ct(Et(56,-60,76,-70),5),R(kt(78,-40,6),2)],{tags:Pr});ct("train","transport","Tàu hoả","Train",["tàu hỏa","tàu","train","metro"],[R(pt(0,-10,200,110,24),1),R(pt(0,-36,160,40,8),4),R(pt(0,40,200,14,4),5),R(wt(kt(-60,10,8),kt(60,10,8)),2),...cr(-50,60,14),...cr(50,60,14)],{tags:Pr});ct("airplane","transport","Máy bay","Airplane",["máy bay","plane","du lịch","bay"],[R(`M${g(-110,0)} C${g(-110,-14)} ${g(-96,-16)} ${g(-80,-16)} L${g(90,-16)} C${g(110,-16)} ${g(120,-4)} ${g(120,0)} C${g(120,6)} ${g(110,16)} ${g(90,16)} L${g(-80,16)} C${g(-96,16)} ${g(-110,14)} ${g(-110,0)} Z`,4),R(wt(jt([[-10,-14],[30,-90],[50,-90],[30,-14]]),jt([[-10,14],[30,90],[50,90],[30,14]]),jt([[-100,-12],[-110,-56],[-92,-56],[-70,-14]])),1),R(wt(...[50,70,90].map(t=>kt(t,-2,4))),5)],{tags:Pr});ct("boat","transport","Thuyền buồm","Sailboat",["thuyền","boat","buồm","sail"],[R(`M${g(-90,40)} L${g(90,40)} L${g(66,74)} L${g(-66,74)} Z`,3),R(pt(0,-20,6,124,2),5),R(jt([[6,-80],[6,30],[76,30]]),4),R(jt([[-6,-60],[-6,30],[-60,30]]),2)],{tags:Pr});ct("ship","transport","Tàu thuỷ","Ship",["tàu thủy","ship","cargo"],[R(`M${g(-120,20)} L${g(120,20)} L${g(96,66)} L${g(-100,66)} Z`,3),R(pt(10,-4,120,48,4),4),R(pt(40,-48,30,40,3),3),R(wt(kt(-20,-4,7),kt(10,-4,7),kt(40,-4,7)),2)],{tags:Pr});ct("rocket","transport","Tên lửa","Rocket",["tên lửa","rocket","khởi nghiệp","launch"],[R(`M${g(0,-110)} C${g(40,-70)} ${g(44,-10)} ${g(36,40)} L${g(-36,40)} C${g(-44,-10)} ${g(-40,-70)} ${g(0,-110)} Z`,4),R(wt(`M${g(-36,0)} L${g(-66,50)} L${g(-36,40)} Z`,`M${g(36,0)} L${g(66,50)} L${g(36,40)} Z`),3),R(kt(0,-40,18),1),R(`M${g(-22,44)} L${g(22,44)} C${g(20,70)} ${g(6,96)} ${g(0,110)} C${g(-6,96)} ${g(-20,70)} ${g(-22,44)} Z`,2)],{tags:Pr});ct("delivery-scooter","transport","Xe giao hàng","Delivery scooter",["giao hàng","shipper","delivery","xe máy"],[R(pt(-50,-46,56,50,4),2),R(`M${g(-70,20)} C${g(-70,-6)} ${g(-40,-18)} ${g(-10,-16)} L${g(30,-16)} L${g(50,-56)} L${g(64,-56)} L${g(56,20)} Z`,1),...cr(-56,30,22),...cr(64,30,22),Ct(Et(56,-56,76,-66),5)],{tags:Pr});to("food","Đồ ăn & thức uống","Food & drink");const Io={role:["sticker","explain","overlay"],style:["playful"]};ct("coffee-cup","food","Ly cà phê","Coffee cup",["cà phê","coffee","ly"],[R(`M${g(-50,-30)} L${g(50,-30)} L${g(40,70)} C${g(38,80)} ${g(30,84)} ${g(20,84)} L${g(-20,84)} C${g(-30,84)} ${g(-38,80)} ${g(-40,70)} Z`,4),R(pt(0,-40,112,20,8),3),R(pt(0,20,96,34,0),2),Ct(wt(`M${g(-14,-64)} C${g(-24,-80)} ${g(-4,-90)} ${g(-14,-108)}`,`M${g(14,-64)} C${g(4,-80)} ${g(24,-90)} ${g(14,-108)}`),5)],{tags:Io});ct("pho-bowl","food","Tô phở","Noodle bowl (phở)",["phở","bún","tô","noodle","bowl"],[R(`M${g(-100,-10)} L${g(100,-10)} C${g(96,50)} ${g(50,80)} ${g(0,80)} C${g(-50,80)} ${g(-96,50)} ${g(-100,-10)} Z`,4),R(pt(0,-14,210,14,7),3),Ct(wt(...[-40,-10,20,50].map(t=>`M${g(t,-14)} C${g(t+10,10)} ${g(t-10,30)} ${g(t,50)}`)),2),R(wt(kt(-50,-24,12),kt(40,-26,10)),1),Ct(wt(Et(40,-90,100,-40),Et(58,-96,110,-50)),5)],{tags:Io});ct("banh-mi","food","Bánh mì","Bánh mì",["bánh mì","sandwich","banh mi"],[R(`M${g(-110,10)} C${g(-110,-40)} ${g(110,-40)} ${g(110,10)} C${g(110,40)} ${g(-110,40)} ${g(-110,10)} Z`,2),R(`M${g(-96,4)} C${g(-60,-6)} ${g(60,-6)} ${g(96,4)} L${g(90,12)} C${g(60,4)} ${g(-60,4)} ${g(-90,12)} Z`,1),Ct(wt(Et(-60,-22,-44,-10),Et(-20,-26,-4,-14),Et(20,-26,36,-14),Et(60,-22,76,-10)),5)],{tags:Io});ct("pizza","food","Lát pizza","Pizza slice",["pizza"],[R(jt([[-70,-70],[70,-70],[0,90]]),2),R(pt(0,-74,150,22,10),3),R(wt(kt(-24,-36,12),kt(18,-20,10),kt(-4,22,10)),3)],{tags:Io});ct("burger","food","Bánh burger","Burger",["burger","hamburger","fast food"],[R(`M${g(-90,-10)} C${g(-90,-80)} ${g(90,-80)} ${g(90,-10)} Z`,2),R(`M${g(-96,0)} L${g(96,0)} L${g(80,16)} L${g(60,4)} L${g(40,18)} L${g(20,4)} L${g(0,18)} L${g(-20,4)} L${g(-40,18)} L${g(-60,4)} L${g(-80,16)} Z`,1),R(pt(0,26,190,22,10),5),R(pt(0,54,180,30,14),2)],{tags:Io});ct("apple","food","Quả táo","Apple",["táo","apple","trái cây","fruit"],[R(`M${g(0,-40)} C${g(30,-70)} ${g(80,-50)} ${g(76,0)} C${g(72,50)} ${g(40,86)} ${g(0,70)} C${g(-40,86)} ${g(-72,50)} ${g(-76,0)} C${g(-80,-50)} ${g(-30,-70)} ${g(0,-40)} Z`,3),R(Uo(0,-40,8,-76,7),5),R(`M${g(8,-60)} C${g(30,-90)} ${g(60,-80)} ${g(60,-70)} C${g(40,-60)} ${g(20,-58)} ${g(8,-60)} Z`,1)],{tags:Io});ct("banana","food","Quả chuối","Banana",["chuối","banana","fruit"],[R(`M${g(-90,-50)} C${g(-60,60)} ${g(60,80)} ${g(96,-10)} C${g(60,30)} ${g(-40,20)} ${g(-70,-60)} Z`,2),R(pt(-80,-58,14,20,3),5)],{tags:Io});ct("watermelon","food","Dưa hấu","Watermelon slice",["dưa hấu","watermelon","fruit"],[R(`M${g(-100,-20)} L${g(100,-20)} C${g(100,60)} ${g(-100,60)} ${g(-100,-20)} Z`,1),R(`M${g(-88,-20)} L${g(88,-20)} C${g(88,46)} ${g(-88,46)} ${g(-88,-20)} Z`,3),R(wt(...[[-40,0],[0,14],[40,0],[-20,24],[20,24]].map(([t,e])=>$e(t,e,4,7))),5)],{tags:Io});ct("cake","food","Bánh kem","Cake",["bánh kem","sinh nhật","birthday","cake"],[R(pt(0,40,170,70,6),4),R(`M${g(-85,10)} L${g(85,10)} L${g(85,26)} C${g(70,36)} ${g(56,16)} ${g(42,30)} C${g(28,40)} ${g(14,16)} ${g(0,30)} C${g(-14,40)} ${g(-28,16)} ${g(-42,30)} C${g(-56,40)} ${g(-70,16)} ${g(-85,26)} Z`,3),R(wt(pt(-30,-14,10,40,3),pt(0,-14,10,40,3),pt(30,-14,10,40,3)),1),R(wt(On(-30,-44,9),On(0,-44,9),On(30,-44,9)),2)],{tags:Io});ct("ice-cream","food","Kem ốc quế","Ice cream",["kem","ice cream","mùa hè"],[R(jt([[-40,-10],[40,-10],[0,100]]),2),Ct(wt(Et(-24,10,14,64),Et(24,10,-14,64)),5),R(wo(0,-40,100,80,5),3),R(kt(0,-84,10),3)],{tags:Io});ct("tea-cup","food","Tách trà","Tea cup",["trà","tea","tách"],[R(`M${g(-70,-20)} L${g(70,-20)} C${g(70,40)} ${g(36,64)} ${g(0,64)} C${g(-36,64)} ${g(-70,40)} ${g(-70,-20)} Z`,4),Ct(`M${g(66,-6)} C${g(100,-6)} ${g(100,30)} ${g(58,30)}`,5),R($e(0,70,90,10),1),Ct(`M${g(0,-40)} C${g(-14,-60)} ${g(14,-70)} ${g(0,-90)}`,5)],{tags:Io});ct("rice-bowl","food","Bát cơm","Rice bowl",["cơm","rice","bát"],[R(wo(0,-14,170,60,7),4),R(`M${g(-90,0)} L${g(90,0)} C${g(86,54)} ${g(46,76)} ${g(0,76)} C${g(-46,76)} ${g(-86,54)} ${g(-90,0)} Z`,1),Ct(wt(Et(30,-90,80,-10),Et(46,-96,92,-18)),5)],{tags:Io});ct("cupcake","food","Bánh cupcake","Cupcake",["cupcake","bánh"],[R(jt([[-50,0],[50,0],[36,80],[-36,80]]),1),Ct(wt(Et(-20,4,-14,76),Et(0,4,0,76),Et(20,4,14,76)),5),R(wo(0,-20,120,70,5),4),R(kt(0,-60,12),3)],{tags:Io});ct("egg","food","Trứng ốp la","Fried egg",["trứng","egg","bữa sáng"],[R(Z8(0,0,80,3,10,.16),4),R(kt(10,-6,32),2)],{tags:Io});ct("fish","food","Con cá","Fish",["cá","fish","hải sản","seafood"],[R(`M${g(-80,0)} C${g(-40,-56)} ${g(40,-56)} ${g(70,0)} C${g(40,56)} ${g(-40,56)} ${g(-80,0)} Z`,1),R(jt([[60,0],[110,-40],[100,0],[110,40]]),1),R(kt(-44,-10,7),5),Ct(Ge(-14,0,20,-60,60),5)],{tags:Io});ct("carrot","food","Cà rốt","Carrot",["cà rốt","carrot","rau"],[R(`M${g(-24,-50)} C${g(-20,0)} ${g(-10,60)} ${g(0,100)} C${g(10,60)} ${g(20,0)} ${g(24,-50)} Z`,2),R(wt(jt([[-4,-50],[-30,-100],[0,-60]]),jt([[0,-52],[0,-110],[10,-56]]),jt([[4,-50],[34,-96],[10,-56]])),1),Ct(wt(Et(-16,-14,0,-12),Et(4,20,14,22)),5)],{tags:Io});ct("bubble-tea","food","Trà sữa","Bubble tea",["trà sữa","bubble tea","boba","milk tea"],[R(jt([[-40,-40],[40,-40],[30,90],[-30,90]]),4),R(pt(0,-48,96,18,8),1),R(wt(...[[-16,64],[4,72],[18,58],[-2,50],[-20,40]].map(([t,e])=>kt(t,e,7))),5),R(pt(10,-90,10,90,4),3)],{tags:Io});to("tech","Công nghệ","Tech");const ko={role:["explain","overlay"],style:["tech","clean"]};ct("laptop","tech","Máy tính xách tay","Laptop",["laptop","máy tính","computer"],[R(pt(0,-20,170,110,8),5),R(pt(0,-20,150,90,4),1),R(`M${g(-110,40)} L${g(110,40)} L${g(120,56)} C${g(120,60)} ${g(116,62)} ${g(112,62)} L${g(-112,62)} C${g(-116,62)} ${g(-120,60)} ${g(-120,56)} Z`,4)],{tags:ko});ct("phone","tech","Điện thoại","Phone",["điện thoại","phone","smartphone","mobile"],[R(pt(0,0,90,170,16),5),R(pt(0,-4,76,140,6),1),R(pt(0,-78,24,5,2),4),R(kt(0,78,5),4)],{tags:ko});ct("monitor","tech","Màn hình máy tính","Desktop monitor",["màn hình","monitor","pc","desktop"],[R(pt(0,-20,200,124,8),5),R(pt(0,-24,184,104,4),1),R(jt([[-16,42],[16,42],[26,80],[-26,80]]),5),R(pt(0,82,90,10,4),5)],{tags:ko});ct("tablet","tech","Máy tính bảng","Tablet",["máy tính bảng","tablet","ipad"],[R(pt(0,0,130,170,14),5),R(pt(0,0,114,146,6),1)],{tags:ko});ct("camera","tech","Máy ảnh","Camera",["máy ảnh","camera","chụp ảnh","photo"],[R(pt(0,10,180,110,14),5),R(pt(-40,-50,60,22,6),5),R(kt(0,14,40),4),R(kt(0,14,26),1),R(kt(60,-24,7),2)],{tags:ko});ct("video-camera","tech","Máy quay","Video camera",["máy quay","video","quay phim","camcorder"],[R(pt(-20,0,130,90,12),5),R(jt([[46,-16],[100,-44],[100,44],[46,16]]),5),R(kt(-50,-62,22),4),R(kt(10,-62,22),4),R(kt(40,-24,6),3)],{tags:ko});ct("headphones","tech","Tai nghe","Headphones",["tai nghe","headphones","âm nhạc","music"],[Ct(Ge(0,10,70,180,360),5),R(wt(pt(-70,30,30,64,10),pt(70,30,30,64,10)),1)],{tags:ko});ct("microphone","tech","Micro","Microphone",["micro","mic","podcast","thu âm"],[R(pt(0,-40,52,90,26),5),Ct(wt(`M${g(-44,-20)} C${g(-44,40)} ${g(44,40)} ${g(44,-20)}`,Et(0,30,0,70),Et(-30,70,30,70)),5),Ct(wt(Et(-14,-60,14,-60),Et(-14,-44,14,-44),Et(-14,-28,14,-28)),4)],{tags:ko});ct("gear","tech","Bánh răng","Gear",["bánh răng","gear","cài đặt","settings"],[R(Fe(0,0,10,90,70,0),5),R(kt(0,0,30),4)],{tags:ko});ct("cloud-upload","tech","Đám mây tải lên","Cloud upload",["tải lên","upload","cloud","đám mây"],[R(wo(0,0,190,110,6),4),R(jt([[0,-40],[30,-6],[12,-6],[12,36],[-12,36],[-12,-6],[-30,-6]]),1)],{tags:ko});ct("wifi","tech","Wi-Fi","Wi-Fi",["wifi","mạng","internet","kết nối"],[Ct(wt(Ge(0,40,30,225,315),Ge(0,40,60,225,315),Ge(0,40,90,225,315)),1),R(kt(0,40,10),1)],{tags:ko});ct("battery","tech","Pin","Battery",["pin","battery","năng lượng"],[R(pt(-6,0,150,70,10),5),R(pt(76,0,12,30,3),5),R(pt(-30,0,90,52,4),1)],{tags:ko});ct("lightbulb","tech","Bóng đèn ý tưởng","Light bulb",["ý tưởng","idea","bóng đèn","lightbulb"],[R(`M${g(-26,40)} C${g(-26,10)} ${g(-60,-6)} ${g(-60,-40)} C${g(-60,-80)} ${g(-30,-100)} ${g(0,-100)} C${g(30,-100)} ${g(60,-80)} ${g(60,-40)} C${g(60,-6)} ${g(26,10)} ${g(26,40)} Z`,2),R(wt(pt(0,52,52,12,4),pt(0,68,46,12,4)),5),Ct(wt(Et(-80,-90,-96,-104),Et(80,-90,96,-104),Et(0,-118,0,-136),Et(-92,-40,-112,-40),Et(92,-40,112,-40)),3)],{tags:ko});ct("robot","tech","Rô-bốt","Robot",["robot","ai","trí tuệ nhân tạo","bot"],[R(pt(0,10,130,100,20),4),R(wt(kt(-30,0,14),kt(30,0,14)),1),R(pt(0,38,50,10,4),5),Ct(Et(0,-40,0,-62),5),R(kt(0,-68,9),3),R(wt(pt(-74,10,14,40,5),pt(74,10,14,40,5)),5)],{tags:ko});ct("chip","tech","Vi mạch","Chip",["chip","vi mạch","processor","cpu"],[R(pt(0,0,110,110,10),5),R(pt(0,0,60,60,6),1),Ct(wt(...[-30,0,30].flatMap(t=>[Et(t,-55,t,-80),Et(t,55,t,80),Et(-55,t,-80,t),Et(55,t,80,t)])),5)],{tags:ko});ct("play-button","tech","Nút phát","Play button",["play","phát","video","youtube"],[R(pt(0,0,170,120,30),3),R(jt([[-20,-30],[34,0],[-20,30]]),4)],{tags:ko});ct("cursor","tech","Con trỏ chuột","Mouse cursor",["con trỏ","cursor","click","chuột"],[R(jt([[-30,-60],[40,10],[6,14],[26,56],[10,64],[-10,22],[-30,44]]),4)],{tags:ko});ct("browser","tech","Cửa sổ trình duyệt","Browser window",["trình duyệt","browser","website","web"],[R(pt(0,0,220,150,10),4),R(pt(0,-62,220,26,10),5),R(wt(kt(-92,-62,5),kt(-76,-62,5),kt(-60,-62,5)),3),R(pt(-40,0,100,60,4),1),Ct(wt(Et(30,-20,90,-20),Et(30,0,90,0),Et(30,20,70,20)),5)],{tags:ko});to("office","Văn phòng & kinh doanh","Office & business");const oo={role:["explain","stat","list"],style:["corporate","clean"]};ct("briefcase","office","Cặp tài liệu","Briefcase",["cặp","briefcase","công việc","work"],[R(pt(0,10,180,120,12),2),R(`M${g(-30,-50)} L${g(-30,-66)} C${g(-30,-72)} ${g(-24,-76)} ${g(-18,-76)} L${g(18,-76)} C${g(24,-76)} ${g(30,-72)} ${g(30,-66)} L${g(30,-50)} L${g(18,-50)} L${g(18,-64)} L${g(-18,-64)} L${g(-18,-50)} Z`,5),R(pt(0,4,180,8,2),5),R(pt(0,4,24,22,4),3)],{tags:oo});ct("document","office","Tài liệu","Document",["tài liệu","document","giấy tờ","file"],[R(jt([[-60,-80],[30,-80],[60,-50],[60,80],[-60,80]]),4),R(jt([[30,-80],[30,-50],[60,-50]]),1),Ct(wt(Et(-38,-30,38,-30),Et(-38,-6,38,-6),Et(-38,18,38,18),Et(-38,42,10,42)),5)],{tags:oo});ct("clipboard","office","Bảng kẹp hồ sơ","Clipboard",["clipboard","checklist","danh sách"],[R(pt(0,10,130,170,10),3),R(pt(0,14,110,140,4),4),R(pt(0,-72,56,24,6),5),Ct(wt(...[-30,0,30].flatMap(t=>[jt([[-40,t],[-32,t+8],[-18,t-8]],!1),Et(-4,t,36,t)])),1)],{tags:oo});ct("calendar","office","Lịch","Calendar",["lịch","calendar","ngày","date","sự kiện"],[R(pt(0,10,170,150,12),4),R(pt(0,-48,170,34,12),3),R(wt(pt(-44,-70,10,26,4),pt(44,-70,10,26,4)),5),R(wt(...[[-50,0],[-16,0],[18,0],[52,0],[-50,34],[-16,34],[18,34]].map(([t,e])=>pt(t,e,22,20,3))),1)],{tags:oo});ct("bar-chart","office","Biểu đồ cột","Bar chart",["biểu đồ","chart","số liệu","growth","tăng trưởng"],[R(pt(-54,40,30,70,3),1),R(pt(-14,20,30,110,3),2),R(pt(26,-10,30,170,3),3),R(pt(66,-34,30,218,3),1),Ct(wt(Et(-90,76,100,76),Et(-90,76,-90,-110)),5)],{tags:oo});ct("pie-chart","office","Biểu đồ tròn","Pie chart",["biểu đồ tròn","pie chart","tỉ lệ","percent"],[R(kt(0,0,80),1),R(`M${g(0,0)} L${g(0,-80)} C${g(44,-80)} ${g(80,-44)} ${g(80,0)} Z`,3),R(`M${g(0,0)} L${g(80,0)} C${g(80,34)} ${g(60,62)} ${g(30,74)} Z`,2)],{tags:oo});ct("line-chart","office","Biểu đồ đường","Line chart",["biểu đồ đường","line chart","xu hướng","trend"],[Ct(wt(Et(-100,70,100,70),Et(-100,70,-100,-80)),5),Ct(jt([[-84,40],[-40,10],[0,24],[40,-30],[84,-60]],!1),3),R(wt(...[[-84,40],[-40,10],[0,24],[40,-30],[84,-60]].map(([t,e])=>kt(t,e,8))),1)],{tags:oo});ct("pencil","office","Bút chì","Pencil",["bút chì","pencil","viết","write"],[R(jt([[-90,30],[60,-36],[80,-6],[-70,60]]),2),R(jt([[60,-36],[100,-30],[80,-6]]),4),R(jt([[-90,30],[-104,62],[-70,60]]),5)],{tags:oo});ct("folder","office","Thư mục","Folder",["thư mục","folder","hồ sơ"],[R(`M${g(-90,-60)} L${g(-30,-60)} L${g(-14,-44)} L${g(90,-44)} L${g(90,60)} L${g(-90,60)} Z`,2),R(pt(0,8,180,104,6),2)],{tags:oo});ct("envelope","office","Phong bì / email","Envelope",["thư","email","mail","phong bì"],[R(pt(0,0,180,120,8),4),Ct(jt([[-90,-60],[0,10],[90,-60]],!1),5)],{tags:oo});ct("clock","office","Đồng hồ","Clock",["đồng hồ","clock","thời gian","time"],[R(kt(0,0,86),4),R(kt(0,0,74),1),Ct(wt(Et(0,0,0,-48),Et(0,0,34,18)),5),R(kt(0,0,7),5)],{tags:oo});ct("magnifier","office","Kính lúp","Magnifier",["tìm kiếm","search","kính lúp","magnifier"],[R(Uo(34,34,86,86,22),5),R(kt(-14,-14,62),5),R(kt(-14,-14,46),4)],{tags:oo});ct("target","office","Mục tiêu","Target",["mục tiêu","target","goal","kpi"],[R(kt(0,0,86),3),R(kt(0,0,62),4),R(kt(0,0,38),3),R(kt(0,0,14),4)],{tags:oo});ct("trophy","office","Cúp","Trophy",["cúp","trophy","chiến thắng","winner"],[R(`M${g(-50,-80)} L${g(50,-80)} L${g(46,-20)} C${g(40,10)} ${g(20,24)} ${g(0,24)} C${g(-20,24)} ${g(-40,10)} ${g(-46,-20)} Z`,2),Ct(wt(`M${g(-48,-64)} C${g(-90,-64)} ${g(-90,-14)} ${g(-40,-10)}`,`M${g(48,-64)} C${g(90,-64)} ${g(90,-14)} ${g(40,-10)}`),2),R(pt(0,46,20,44,2),2),R(pt(0,80,90,22,4),5)],{tags:oo});ct("money-bag","office","Túi tiền","Money bag",["tiền","money","doanh thu","revenue"],[R(`M${g(-24,-52)} C${g(-90,-10)} ${g(-90,80)} ${g(0,80)} C${g(90,80)} ${g(90,-10)} ${g(24,-52)} Z`,1),R(jt([[-30,-60],[-40,-90],[0,-76],[40,-90],[30,-60]]),1),R(pt(0,-54,60,10,4),5),Ct(wt(`M${g(18,0)} C${g(8,-12)} ${g(-24,-10)} ${g(-20,8)} C${g(-16,22)} ${g(20,16)} ${g(20,32)} C${g(20,50)} ${g(-12,50)} ${g(-22,38)}`,Et(0,-14,0,56)),4)],{tags:oo});ct("coin","office","Đồng xu","Coin",["xu","coin","tiền"],[R(kt(0,0,70),2),R(kt(0,0,54),2),Ct(wt(`M${g(16,-20)} C${g(8,-30)} ${g(-20,-28)} ${g(-16,-10)} C${g(-12,4)} ${g(18,0)} ${g(18,16)} C${g(18,32)} ${g(-10,32)} ${g(-20,22)}`,Et(0,-36,0,40)),5)],{tags:oo});ct("banknote","office","Tờ tiền","Banknote",["tiền mặt","cash","banknote"],[R(pt(0,0,200,100,8),1),R(pt(0,0,170,74,6),4),R(kt(0,0,26),1),R(wt(kt(-66,0,8),kt(66,0,8)),1)],{tags:oo});ct("piggy-bank","office","Heo đất","Piggy bank",["heo đất","tiết kiệm","savings","piggy bank"],[R($e(0,10,90,64),3),R(wt(pt(-50,70,18,26,4),pt(40,70,18,26,4)),3),R(jt([[-34,-44],[-20,-74],[-6,-50]]),3),R(pt(86,10,22,30,8),3),R(kt(-40,-6,6),5),R(pt(10,-48,40,8,4),5)],{tags:oo});ct("handshake","office","Bắt tay hợp tác","Handshake",["hợp tác","handshake","deal","đối tác"],[R(wt(pt(-80,0,40,40,8),pt(80,0,40,40,8)),5),R(`M${g(-60,-10)} L${g(-10,-30)} L${g(40,-2)} L${g(54,16)} C${g(56,28)} ${g(44,34)} ${g(34,26)} L${g(20,40)} C${g(12,48)} ${g(0,44)} ${g(-6,36)} L${g(-60,20)} Z`,4),Ct(wt(Et(20,0,30,14),Et(6,10,18,26)),5)],{tags:oo});ct("presentation-board","office","Bảng trình chiếu","Presentation board",["thuyết trình","presentation","bảng","slide"],[R(pt(0,-20,200,130,6),4),R(pt(0,-90,210,14,4),5),Ct(wt(Et(0,45,0,90),Et(0,60,-40,96),Et(0,60,40,96)),5),R(wt(pt(-50,-6,26,60,2),pt(-14,-26,26,100,2),pt(22,-16,26,80,2)),1)],{tags:oo});to("home","Nhà & nội thất","Home & interior");const zr={role:["explain","background"],style:["soft","clean"]};ct("sofa","home","Ghế sofa","Sofa",["sofa","ghế","phòng khách","living room"],[R(pt(0,-20,180,70,16),1),R(wt(pt(-96,10,30,70,12),pt(96,10,30,70,12)),1),R(pt(0,24,170,40,10),2),R(wt(pt(-80,62,10,20,3),pt(80,62,10,20,3)),5)],{tags:zr});ct("chair","home","Ghế","Chair",["ghế","chair"],[R(pt(-30,-40,14,120,4),2),R(pt(0,20,80,14,4),2),R(wt(pt(-30,60,10,70,3),pt(30,60,10,70,3)),2)],{tags:zr});ct("table","home","Bàn","Table",["bàn","table"],[R(pt(0,-20,200,18,4),2),R(wt(pt(-80,30,14,90,3),pt(80,30,14,90,3)),2)],{tags:zr});ct("bed","home","Giường","Bed",["giường","bed","ngủ","phòng ngủ"],[R(pt(-90,-10,20,110,4),2),R(pt(10,20,200,40,6),4),R(pt(-50,0,50,24,10),4),R(pt(30,10,130,30,8),1),R(wt(pt(-86,56,10,22,3),pt(104,56,10,22,3)),2)],{tags:zr});ct("lamp","home","Đèn bàn","Table lamp",["đèn","lamp"],[R(jt([[-40,-70],[40,-70],[60,-10],[-60,-10]]),2),R(pt(0,30,10,80,3),5),R(pt(0,72,70,12,5),5)],{tags:zr});ct("plant-pot","home","Chậu cây","Potted plant",["chậu cây","plant","cây cảnh"],[R(jt([[-40,20],[40,20],[30,90],[-30,90]]),3),R(pt(0,20,96,16,4),3),R(wt(`M${g(0,10)} C${g(-60,-10)} ${g(-70,-60)} ${g(-40,-80)} C${g(-30,-40)} ${g(-10,-20)} ${g(0,10)} Z`,`M${g(0,10)} C${g(60,-10)} ${g(70,-60)} ${g(40,-80)} C${g(30,-40)} ${g(10,-20)} ${g(0,10)} Z`,`M${g(0,10)} C${g(-14,-40)} ${g(-8,-90)} ${g(0,-104)} C${g(8,-90)} ${g(14,-40)} ${g(0,10)} Z`),1)],{tags:zr});ct("window","home","Cửa sổ","Window",["cửa sổ","window"],[R(pt(0,0,150,170,4),4),R(wt(pt(-36,-40,62,70,2),pt(36,-40,62,70,2),pt(-36,40,62,70,2),pt(36,40,62,70,2)),1),R(pt(0,92,170,12,3),5)],{tags:zr});ct("door","home","Cửa ra vào","Door",["cửa","door","lối vào"],[R(pt(0,0,110,200,6),2),R(wt(pt(0,-50,80,70,4),pt(0,40,80,70,4)),2),R(kt(38,6,6),3)],{tags:zr});ct("key","home","Chìa khoá","Key",["chìa khóa","key","bảo mật"],[R(kt(-50,0,40),2),R(kt(-50,0,16),4),R(wt(pt(30,0,120,18,4),pt(70,20,14,24,2),pt(46,20,14,18,2)),2)],{tags:zr});ct("lock","home","Ổ khoá","Padlock",["khóa","lock","bảo mật","security"],[Ct(`M${g(-40,-10)} L${g(-40,-40)} C${g(-40,-90)} ${g(40,-90)} ${g(40,-40)} L${g(40,-10)}`,5),R(pt(0,30,120,90,12),2),R(wt(kt(0,20,10),pt(0,38,8,24,3)),5)],{tags:zr});ct("mug","home","Cốc","Mug",["cốc","mug","ly"],[R(pt(0,0,100,120,10),1),Ct(`M${g(50,-30)} C${g(96,-30)} ${g(96,30)} ${g(50,30)}`,1),R(pt(0,-30,70,10,4),4)],{tags:zr});ct("picture-frame","home","Khung tranh","Picture frame",["tranh","khung","picture","frame"],[R(pt(0,0,170,130,4),2),R(pt(0,0,140,100,2),4),R(jt([[-60,40],[-20,-10],[10,20],[30,0],[60,40]]),1),R(kt(36,-26,12),3)],{tags:zr});to("icons","Biểu tượng","Icons");const Ye={role:["sticker","overlay","social"],style:["clean","playful"]};ct("heart","icons","Trái tim","Heart",["tim","heart","yêu","love","like"],[R(zc(0,0,80),3)],{tags:Ye});ct("star","icons","Ngôi sao","Star",["sao","star","đánh giá","rating"],[R(Fe(0,6,5,92,40),2)],{tags:Ye});ct("check","icons","Dấu tích","Check mark",["đúng","check","tick","xong","done"],[R(kt(0,0,80),1),Ct(jt([[-36,0],[-10,28],[40,-30]],!1),4)],{tags:Ye});ct("cross","icons","Dấu X","Cross mark",["sai","cross","x","không"],[R(kt(0,0,80),3),Ct(wt(Et(-30,-30,30,30),Et(30,-30,-30,30)),4)],{tags:Ye});ct("plus","icons","Dấu cộng","Plus",["cộng","plus","thêm","add"],[R(wt(pt(0,0,40,150,10),pt(0,0,150,40,10)),1)],{tags:Ye});ct("location-pin","icons","Ghim vị trí","Location pin",["địa điểm","location","pin","bản đồ","map"],[R(`M${g(0,96)} C${g(-20,60)} ${g(-70,10)} ${g(-70,-30)} C${g(-70,-70)} ${g(-36,-100)} ${g(0,-100)} C${g(36,-100)} ${g(70,-70)} ${g(70,-30)} C${g(70,10)} ${g(20,60)} ${g(0,96)} Z`,3),R(kt(0,-30,26),4)],{tags:Ye});ct("home-icon","icons","Biểu tượng nhà","Home icon",["nhà","home","trang chủ"],[R(wt(jt([[-80,-4],[0,-80],[80,-4],[60,-4],[60,70],[-60,70],[-60,-4]])),1),R(pt(0,40,30,60,4),4)],{tags:Ye});ct("user-icon","icons","Biểu tượng người dùng","User icon",["người dùng","user","tài khoản","account","profile"],[R(kt(0,-36,36),1),R(`M${g(-70,80)} C${g(-70,10)} ${g(70,10)} ${g(70,80)} Z`,1)],{tags:Ye,human:!1});ct("bell","icons","Chuông thông báo","Bell",["chuông","thông báo","notification","bell"],[R(`M${g(-60,40)} C${g(-50,20)} ${g(-50,0)} ${g(-50,-20)} C${g(-50,-60)} ${g(-26,-80)} ${g(0,-80)} C${g(26,-80)} ${g(50,-60)} ${g(50,-20)} C${g(50,0)} ${g(50,20)} ${g(60,40)} Z`,2),R(kt(0,56,14),2),R(kt(0,-86,8),2)],{tags:Ye});ct("flag","icons","Lá cờ","Flag",["cờ","flag","đích","milestone"],[R(pt(-60,0,10,200,3),5),R(`M${g(-56,-96)} C${g(-20,-110)} ${g(10,-80)} ${g(70,-96)} L${g(70,-24)} C${g(10,-8)} ${g(-20,-38)} ${g(-56,-24)} Z`,3)],{tags:Ye});ct("gift","icons","Hộp quà","Gift box",["quà","gift","khuyến mãi","present"],[R(pt(0,30,150,110,6),3),R(pt(0,-34,170,34,6),3),R(wt(pt(0,30,24,110,2),pt(0,-34,24,34,2)),2),Ct(wt(`M${g(0,-52)} C${g(-50,-110)} ${g(-80,-60)} ${g(0,-52)}`,`M${g(0,-52)} C${g(50,-110)} ${g(80,-60)} ${g(0,-52)}`),2)],{tags:Ye});ct("cart","icons","Giỏ hàng","Shopping cart",["giỏ hàng","cart","mua sắm","shopping"],[Ct(jt([[-100,-70],[-70,-70],[-40,40],[70,40]],!1),5),R(jt([[-62,-46],[96,-46],[78,20],[-46,20]]),2),R(wt(kt(-30,66,14),kt(56,66,14)),5)],{tags:Ye});ct("price-tag","icons","Nhãn giá","Price tag",["giá","sale","tag","giảm giá"],[R(jt([[-90,-40],[40,-40],[90,0],[40,40],[-90,40]]),3),R(kt(50,0,10),4)],{tags:Ye});ct("bookmark","icons","Đánh dấu","Bookmark",["bookmark","lưu","save"],[R(jt([[-50,-90],[50,-90],[50,90],[0,50],[-50,90]]),1)],{tags:Ye});ct("fire","icons","Ngọn lửa","Fire",["lửa","hot","fire","trending"],[R(`M${g(0,96)} C${g(-60,96)} ${g(-80,40)} ${g(-60,0)} C${g(-50,-20)} ${g(-40,-30)} ${g(-30,-50)} C${g(-20,-20)} ${g(0,-10)} ${g(0,-10)} C${g(-10,-50)} ${g(10,-90)} ${g(30,-100)} C${g(30,-60)} ${g(80,-20)} ${g(70,30)} C${g(64,70)} ${g(40,96)} ${g(0,96)} Z`,3),R(`M${g(0,90)} C${g(-30,90)} ${g(-40,60)} ${g(-30,40)} C${g(-20,20)} ${g(-4,10)} ${g(0,-4)} C${g(14,20)} ${g(36,40)} ${g(30,64)} C${g(26,80)} ${g(14,90)} ${g(0,90)} Z`,2)],{tags:Ye});ct("water-drop","icons","Giọt nước","Water drop",["giọt nước","water","drop","nước"],[R(On(0,0,90),1),Ct(Ge(-20,20,30,110,170),4)],{tags:Ye});ct("music-note","icons","Nốt nhạc","Music note",["nhạc","music","nốt nhạc"],[R(wt($e(-40,60,26,20),$e(50,40,26,20)),5),R(wt(pt(-16,-10,10,140,2),pt(74,-30,10,140,2)),5),R(jt([[-21,-80],[79,-100],[79,-74],[-21,-54]]),5)],{tags:Ye});ct("speaker","icons","Loa","Speaker",["loa","âm thanh","speaker","sound","volume"],[R(jt([[-70,-30],[-30,-30],[20,-70],[20,70],[-30,30],[-70,30]]),5),Ct(wt(Ge(30,0,30,-50,50),Ge(30,0,56,-50,50)),3)],{tags:Ye});ct("lightning-icon","icons","Tia chớp","Lightning icon",["nhanh","fast","flash","power"],[R(kt(0,0,80),2),R(jt([[10,-56],[-30,8],[-2,8],[-14,56],[30,-10],[2,-10]]),4)],{tags:Ye});ct("shield","icons","Khiên bảo vệ","Shield",["bảo vệ","shield","an toàn","security","bảo hành"],[R(`M${g(0,-90)} C${g(30,-70)} ${g(60,-66)} ${g(80,-66)} C${g(80,10)} ${g(60,70)} ${g(0,96)} C${g(-60,70)} ${g(-80,10)} ${g(-80,-66)} C${g(-60,-66)} ${g(-30,-70)} ${g(0,-90)} Z`,1),Ct(jt([[-30,0],[-6,26],[36,-26]],!1),4)],{tags:Ye});ct("eye","icons","Con mắt","Eye",["mắt","xem","view","eye","lượt xem"],[R(`M${g(-100,0)} C${g(-60,-60)} ${g(60,-60)} ${g(100,0)} C${g(60,60)} ${g(-60,60)} ${g(-100,0)} Z`,4),R(kt(0,0,32),1),R(kt(0,0,14),5)],{tags:Ye});to("arrows","Mũi tên","Arrows");const Lr={role:["explain","overlay"],style:["clean","bold"]};ct("arrow-right","arrows","Mũi tên phải","Arrow right",["mũi tên","arrow","phải"],[R(jt([[-100,-20],[30,-20],[30,-56],[100,0],[30,56],[30,20],[-100,20]]),3)],{tags:Lr});ct("arrow-up","arrows","Mũi tên lên","Arrow up",["mũi tên","arrow","lên","tăng","up"],[R(jt([[-20,100],[-20,-30],[-56,-30],[0,-100],[56,-30],[20,-30],[20,100]]),1)],{tags:Lr});ct("arrow-down","arrows","Mũi tên xuống","Arrow down",["mũi tên","arrow","xuống","giảm","down"],[R(jt([[-20,-100],[-20,30],[-56,30],[0,100],[56,30],[20,30],[20,-100]]),3)],{tags:Lr});ct("arrow-curved","arrows","Mũi tên cong","Curved arrow",["mũi tên cong","curved arrow"],[Ct(`M${g(-90,60)} C${g(-70,-40)} ${g(20,-70)} ${g(80,-30)}`,5),Ct(jt([[46,-52],[84,-28],[56,6]],!1),5)],{tags:Lr});ct("arrow-double","arrows","Mũi tên hai chiều","Double arrow",["hai chiều","double arrow","trao đổi","exchange"],[R(jt([[-100,0],[-50,-44],[-50,-16],[50,-16],[50,-44],[100,0],[50,44],[50,16],[-50,16],[-50,44]]),1)],{tags:Lr});ct("arrow-circle","arrows","Mũi tên vòng","Circular arrow",["vòng lặp","refresh","cycle","lặp lại"],[Ct(Ge(0,0,70,-60,230),5),R(jt([[34,-74],[50,-40],[14,-38]]),5)],{tags:Lr});ct("arrow-zigzag","arrows","Mũi tên gấp khúc","Zigzag arrow",["zigzag","gấp khúc","tăng trưởng"],[Ct(jt([[-100,60],[-40,0],[0,30],[80,-50]],!1),3),R(jt([[50,-60],[96,-66],[90,-20]]),3)],{tags:Lr});ct("arrow-uturn","arrows","Mũi tên quay đầu","U-turn arrow",["quay đầu","u-turn","quay lại","back"],[Ct(`M${g(60,80)} L${g(60,-20)} C${g(60,-80)} ${g(-40,-80)} ${g(-40,-20)} L${g(-40,40)}`,5),R(jt([[-72,20],[-40,70],[-8,20]]),5)],{tags:Lr});ct("chevrons","arrows","Mũi tên kép","Chevrons",["chevron","tiếp theo","next","fast forward"],[R(wt(jt([[-90,-60],[-50,-60],[0,0],[-50,60],[-90,60],[-40,0]]),jt([[0,-60],[40,-60],[90,0],[40,60],[0,60],[50,0]])),3)],{tags:Lr});ct("arrow-swoosh","arrows","Mũi tên vẽ tay","Hand-drawn swoosh arrow",["vẽ tay","swoosh","hand drawn"],[Ct(`M${g(-100,30)} C${g(-60,70)} ${g(-10,60)} ${g(10,20)} C${g(30,-20)} ${g(60,-40)} ${g(96,-40)}`,5),Ct(wt(Et(96,-40,70,-60),Et(96,-40,74,-14)),5)],{tags:Lr});ct("arrow-block-left","arrows","Mũi tên trái","Arrow left",["mũi tên","arrow","trái","left"],[R(jt([[100,-20],[-30,-20],[-30,-56],[-100,0],[-30,56],[-30,20],[100,20]]),2)],{tags:Lr});ct("arrow-dotted","arrows","Đường chấm mũi tên","Dotted path arrow",["đường đi","path","hành trình","journey"],[R(wt(...Array.from({length:7},(t,e)=>{const o=e/7;return kt(-100+o*170,40-Math.sin(o*Math.PI)*70,6)})),5),R(jt([[70,10],[100,40],[60,52]]),5)],{tags:Lr});to("frames","Khung","Frames");const Nr={role:["overlay","title","background"],style:["clean","editorial"]};ct("frame-rounded","frames","Khung bo góc","Rounded frame",["khung","frame","viền"],[ep(wt(pt(0,0,240,160,24),pt(0,0,212,132,14)),1)],{tags:Nr});ct("frame-circle","frames","Khung tròn","Circle frame",["khung tròn","circle frame","avatar"],[ep(wt(kt(0,0,100),kt(0,0,84)),3)],{tags:Nr});ct("banner-ribbon","frames","Băng rôn","Ribbon banner",["băng rôn","ribbon","banner","tiêu đề"],[R(wt(jt([[-130,-10],[-96,-10],[-96,40],[-130,40],[-112,15]]),jt([[130,-10],[96,-10],[96,40],[130,40],[112,15]])),5),R(pt(0,0,200,50,2),3)],{tags:Nr});ct("scroll","frames","Cuộn giấy","Scroll",["cuộn giấy","scroll","thông báo"],[R(pt(0,0,180,120,2),4),R(wt(pt(-96,0,22,140,11),pt(96,0,22,140,11)),2)],{tags:Nr});ct("polaroid","frames","Ảnh polaroid","Polaroid frame",["polaroid","ảnh","photo"],[R(pt(0,0,170,200,4),4),R(pt(0,-18,146,140,2),5)],{tags:Nr});ct("ticket","frames","Vé","Ticket",["vé","ticket","sự kiện","coupon"],[R(`M${g(-110,-50)} L${g(110,-50)} L${g(110,-14)} C${g(96,-14)} ${g(96,14)} ${g(110,14)} L${g(110,50)} L${g(-110,50)} L${g(-110,14)} C${g(-96,14)} ${g(-96,-14)} ${g(-110,-14)} Z`,3),Ct(Et(50,-40,50,40),4)],{tags:Nr});ct("brackets","frames","Ngoặc vuông","Brackets",["ngoặc","brackets","nhấn mạnh"],[Ct(wt(jt([[-60,-80],[-100,-80],[-100,80],[-60,80]],!1),jt([[60,-80],[100,-80],[100,80],[60,80]],!1)),5)],{tags:Nr});ct("filmstrip","frames","Cuộn phim","Film strip",["phim","film","cuộn phim","cinema"],[R(pt(0,0,240,120,4),5),R(wt(...[-80,0,80].map(t=>pt(t,0,64,70,3))),4),R(wt(...Array.from({length:10},(t,e)=>pt(-108+e*24,-50,10,10,2)),...Array.from({length:10},(t,e)=>pt(-108+e*24,50,10,10,2))),4)],{tags:Nr});ct("phone-frame","frames","Khung điện thoại","Phone frame",["khung điện thoại","phone mockup","mockup"],[ep(wt(pt(0,0,120,230,20),pt(0,0,104,200,8)),5),R(pt(0,-104,30,6,3),4)],{tags:Nr});ct("sticky-note","frames","Giấy ghi chú","Sticky note",["ghi chú","note","sticky","post-it"],[R(jt([[-80,-80],[80,-80],[80,40],[40,80],[-80,80]]),2),R(jt([[80,40],[40,40],[40,80]]),5),R(pt(0,-80,60,18,2),4)],{tags:Nr});ct("frame-wavy","frames","Khung lượn sóng","Wavy frame",["khung","wavy","dễ thương"],[R(Fe(0,0,24,100,90,0),1),R(kt(0,0,80),4)],{tags:Nr});ct("frame-stamp","frames","Khung tem","Stamp frame",["tem","stamp","bưu thiếp"],[ep(wt(pt(0,0,170,210,0),...Array.from({length:7},(t,e)=>kt(-72+e*24,-105,8)),...Array.from({length:7},(t,e)=>kt(-72+e*24,105,8)),...Array.from({length:9},(t,e)=>kt(-85,-96+e*24,8)),...Array.from({length:9},(t,e)=>kt(85,-96+e*24,8))),4),R(pt(0,0,140,180,2),1)],{tags:Nr});to("bubbles","Bong bóng thoại","Speech bubbles");const fn={role:["caption","quote","overlay"],style:["playful","clean"]};ct("bubble-round","bubbles","Bóng thoại tròn","Round speech bubble",["lời thoại","speech","nói","bubble"],[R(`M${g(-100,0)} C${g(-100,-60)} ${g(-50,-80)} ${g(0,-80)} C${g(50,-80)} ${g(100,-60)} ${g(100,0)} C${g(100,60)} ${g(50,76)} ${g(0,76)} C${g(-14,76)} ${g(-26,74)} ${g(-38,70)} L${g(-80,96)} L${g(-66,58)} C${g(-90,44)} ${g(-100,24)} ${g(-100,0)} Z`,4)],{tags:fn});ct("bubble-rect","bubbles","Bóng thoại vuông","Box speech bubble",["lời thoại","speech","box","chat"],[R(`M${g(-110,-70)} L${g(110,-70)} L${g(110,50)} L${g(-20,50)} L${g(-60,90)} L${g(-56,50)} L${g(-110,50)} Z`,4)],{tags:fn});ct("bubble-thought","bubbles","Bóng suy nghĩ","Thought bubble",["suy nghĩ","thought","nghĩ"],[R(wo(0,-14,220,140,7),4),R(wt(kt(-70,80,14),kt(-96,104,8)),4)],{tags:fn});ct("bubble-shout","bubbles","Bóng hét","Shout bubble",["hét","shout","wow","bất ngờ","boom"],[R(Fe(0,0,14,110,76,-90),2)],{tags:fn});ct("bubble-chat","bubbles","Tin nhắn chat","Chat message",["chat","tin nhắn","message","nhắn tin"],[R(`M${g(-100,-50)} C${g(-100,-66)} ${g(-90,-76)} ${g(-74,-76)} L${g(74,-76)} C${g(90,-76)} ${g(100,-66)} ${g(100,-50)} L${g(100,30)} C${g(100,46)} ${g(90,56)} ${g(74,56)} L${g(-50,56)} L${g(-90,86)} L${g(-84,52)} C${g(-94,48)} ${g(-100,40)} ${g(-100,30)} Z`,1),R(wt(kt(-40,-10,10),kt(0,-10,10),kt(40,-10,10)),4)],{tags:fn});ct("bubble-double","bubbles","Hai bóng thoại","Conversation",["hội thoại","conversation","trò chuyện"],[R(`M${g(-120,-40)} C${g(-120,-80)} ${g(-10,-80)} ${g(-10,-40)} C${g(-10,-6)} ${g(-60,0)} ${g(-80,-2)} L${g(-110,20)} L${g(-100,-10)} C${g(-114,-18)} ${g(-120,-28)} ${g(-120,-40)} Z`,1),R(`M${g(10,30)} C${g(10,-10)} ${g(120,-10)} ${g(120,30)} C${g(120,62)} ${g(80,70)} ${g(60,68)} L${g(30,90)} L${g(38,60)} C${g(22,54)} ${g(10,44)} ${g(10,30)} Z`,2)],{tags:fn});ct("caption-box","bubbles","Hộp chú thích","Caption box",["chú thích","caption","box"],[R(pt(0,0,240,70,6),4),R(pt(-112,0,16,70,3),3)],{tags:fn});ct("callout-left","bubbles","Chú thích chỉ trái","Callout pointing left",["callout","chú thích","chỉ"],[R(`M${g(-60,-50)} L${g(110,-50)} L${g(110,50)} L${g(-60,50)} L${g(-60,16)} L${g(-110,0)} L${g(-60,-16)} Z`,4)],{tags:fn});ct("bubble-whisper","bubbles","Bóng thì thầm","Whisper bubble",["thì thầm","whisper","nhỏ"],[Ct(wt(...Array.from({length:16},(t,e)=>{const o=e*22.5,r=o+12;return sa(Pc(0,0,100,64,o,r,2),!1)})),5)],{tags:fn});ct("bubble-heart","bubbles","Bóng thoại trái tim","Heart bubble",["yêu","love","trái tim","tim"],[R(zc(0,-10,74),3),R(jt([[-10,50],[-40,96],[14,62]]),3)],{tags:fn});to("badges","Huy hiệu & nhãn","Badges & labels");const mn={role:["proof","cta","sticker"],style:["bold","playful"]};ct("badge-seal","badges","Con dấu răng cưa","Seal badge",["huy hiệu","seal","chất lượng","badge"],[R(Fe(0,0,18,100,86,0),3),R(kt(0,0,70),4),R(kt(0,0,58),3)],{tags:mn});ct("badge-ribbon","badges","Huy chương ruy băng","Ribbon badge",["huy chương","ribbon","giải thưởng","award"],[R(wt(jt([[-40,30],[-70,110],[-36,94],[-20,120],[0,40]]),jt([[40,30],[70,110],[36,94],[20,120],[0,40]])),3),R(kt(0,-10,70),2),R(kt(0,-10,52),4),R(Fe(0,-10,5,34,15),2)],{tags:mn});ct("badge-shield","badges","Huy hiệu khiên","Shield badge",["khiên","shield","an toàn","badge"],[R(`M${g(0,-96)} L${g(84,-66)} C${g(84,20)} ${g(50,70)} ${g(0,100)} C${g(-50,70)} ${g(-84,20)} ${g(-84,-66)} Z`,1),R(`M${g(0,-76)} L${g(64,-52)} C${g(64,14)} ${g(38,52)} ${g(0,78)} C${g(-38,52)} ${g(-64,14)} ${g(-64,-52)} Z`,4),R(Fe(0,-4,5,40,17),2)],{tags:mn});ct("badge-stamp","badges","Tem tròn","Round stamp",["tem","stamp","chứng nhận","approved"],[Ct(wt(kt(0,0,96),kt(0,0,80)),3),R(Fe(0,0,5,36,15),3),Ct(wt(Et(-60,40,60,40),Et(-60,-40,60,-40)),3)],{tags:mn});ct("badge-new","badges","Nhãn MỚI (nổ)","NEW burst",["mới","new","sale","nổ"],[R(Fe(0,0,16,100,74,0),3),R(Fe(0,0,16,80,60,11),2)],{tags:mn});ct("badge-check","badges","Huy hiệu tích xanh","Verified badge",["xác minh","verified","tích xanh","uy tín"],[R(Fe(0,0,12,90,78,0),1),Ct(jt([[-30,0],[-8,24],[34,-24]],!1),4)],{tags:mn});ct("medal","badges","Huy chương","Medal",["huy chương","medal","vàng","winner"],[R(wt(jt([[-50,-100],[-20,-100],[10,-30],[-20,-30]]),jt([[50,-100],[20,-100],[-10,-30],[20,-30]])),1),R(kt(0,30,62),2),R(kt(0,30,46),2),R(Fe(0,30,5,30,13),4)],{tags:mn});ct("label-tag","badges","Nhãn dán","Label",["nhãn","label","tag"],[R(pt(0,0,220,70,35),2),R(kt(-84,0,10),4)],{tags:mn});ct("badge-percent","badges","Nhãn phần trăm","Percent badge",["giảm giá","percent","%","sale","khuyến mãi"],[R(kt(0,0,90),3),Ct(Et(-30,40,30,-40),4),R(wt(kt(-30,-26,14),kt(30,26,14)),4)],{tags:mn});ct("badge-crown","badges","Huy hiệu vương miện","Crown badge",["vương miện","crown","vip","premium"],[R(kt(0,0,90),5),R(jt([[-56,30],[-60,-30],[-30,0],[0,-50],[30,0],[60,-30],[56,30]]),2)],{tags:mn});to("doodles","Hoạ tiết vẽ tay","Doodles & decor");const Ao={role:["overlay","sticker"],style:["playful","soft"]};ct("sparkle","doodles","Lấp lánh","Sparkle",["lấp lánh","sparkle","sáng","shine"],[R(`M${g(0,-90)} C${g(8,-20)} ${g(20,-8)} ${g(90,0)} C${g(20,8)} ${g(8,20)} ${g(0,90)} C${g(-8,20)} ${g(-20,8)} ${g(-90,0)} C${g(-20,-8)} ${g(-8,-20)} ${g(0,-90)} Z`,2),R(`M${g(70,-80)} C${g(73,-64)} ${g(76,-61)} ${g(92,-58)} C${g(76,-55)} ${g(73,-52)} ${g(70,-36)} C${g(67,-52)} ${g(64,-55)} ${g(48,-58)} C${g(64,-61)} ${g(67,-64)} ${g(70,-80)} Z`,2)],{tags:Ao});ct("swirl","doodles","Xoáy","Swirl",["xoáy","swirl","spiral"],[Ct(sa(Array.from({length:30},(t,e)=>{const o=e*.5,r=6+e*3;return[Math.cos(o)*r,Math.sin(o)*r]}),!1),5)],{tags:Ao});ct("underline-scribble","doodles","Gạch chân nguệch ngoạc","Scribble underline",["gạch chân","underline","nhấn mạnh"],[Ct(`M${g(-110,0)} C${g(-60,-10)} ${g(20,-12)} ${g(110,-6)} C${g(40,4)} ${g(-40,10)} ${g(-90,18)}`,3)],{tags:Ao});ct("circle-scribble","doodles","Khoanh tròn vẽ tay","Scribble circle",["khoanh tròn","circle","highlight"],[Ct(`M${g(20,-70)} C${g(-60,-74)} ${g(-110,-30)} ${g(-100,10)} C${g(-90,60)} ${g(-20,74)} ${g(40,66)} C${g(100,56)} ${g(110,0)} ${g(90,-36)} C${g(70,-70)} ${g(10,-80)} ${g(-40,-56)}`,3)],{tags:Ao});ct("stars-cluster","doodles","Chùm sao","Star cluster",["sao","stars","lấp lánh"],[R(wt(Fe(-40,-20,5,40,17),Fe(40,30,5,26,11),Fe(50,-50,5,16,7)),2)],{tags:Ao});ct("confetti","doodles","Hoa giấy","Confetti",["hoa giấy","confetti","chúc mừng","celebrate"],[R(wt(...[[-80,-40,20],[-30,-70,-30],[40,-50,40],[80,-10,-15],[-60,30,60],[10,10,10],[60,50,-50],[-10,60,30]].map(([t,e,o],r)=>{const n=Math.cos(Ze(o)),a=Math.sin(Ze(o)),i=r%2?6:9,l=r%2?18:9;return jt([[t-i*n+l*a,e-i*a-l*n],[t+i*n+l*a,e+i*a-l*n],[t+i*n-l*a,e+i*a+l*n],[t-i*n-l*a,e-i*a+l*n]])})),3),R(wt(kt(-40,0,6),kt(30,-20,5),kt(-20,40,5)),1)],{tags:Ao});ct("dots-pattern","doodles","Chấm bi","Polka dots",["chấm bi","dots","hoạ tiết"],[R(wt(...Array.from({length:25},(t,e)=>kt(-80+e%5*40+Math.floor(e/5)%2*20,-80+Math.floor(e/5)*40,8))),1)],{tags:Ao});ct("zigzag-line","doodles","Đường răng cưa","Zigzag line",["răng cưa","zigzag"],[Ct(jt(Array.from({length:11},(t,e)=>[-100+e*20,e%2?-16:16]),!1),3)],{tags:Ao});ct("heart-doodle","doodles","Tim vẽ tay","Doodle heart",["tim","heart","vẽ tay"],[Ct(`M${g(0,70)} C${g(-90,10)} ${g(-80,-70)} ${g(-30,-66)} C${g(-10,-64)} ${g(0,-50)} ${g(0,-36)} C${g(4,-56)} ${g(20,-70)} ${g(40,-66)} C${g(90,-56)} ${g(86,20)} ${g(0,70)}`,3)],{tags:Ao});ct("crown","doodles","Vương miện","Crown",["vương miện","crown","king","queen"],[R(jt([[-80,50],[-90,-40],[-44,0],[0,-70],[44,0],[90,-40],[80,50]]),2),R(wt(kt(-90,-46,10),kt(0,-76,10),kt(90,-46,10)),2)],{tags:Ao});ct("emphasis-lines","doodles","Vạch nhấn","Emphasis lines",["nhấn mạnh","emphasis","pop","chú ý"],[Ct(wt(Et(-60,-60,-90,-90),Et(0,-70,0,-110),Et(60,-60,90,-90)),3)],{tags:Ao});ct("motion-lines","doodles","Vệt chuyển động","Speed lines",["tốc độ","speed lines","motion","nhanh"],[Ct(wt(Et(-100,-40,40,-40),Et(-70,0,80,0),Et(-100,40,40,40)),5)],{tags:Ao});ct("loop-line","doodles","Đường xoắn vòng","Loop line",["vòng","loop","line"],[Ct(`M${g(-110,30)} C${g(-60,30)} ${g(-40,-50)} ${g(-10,-40)} C${g(30,-30)} ${g(-30,40)} ${g(10,40)} C${g(50,40)} ${g(60,-10)} ${g(110,-10)}`,5)],{tags:Ao});ct("flower-doodle","doodles","Hoa vẽ tay","Doodle flower",["hoa","flower","doodle"],[Ct(wt(...xy(0,0,6,40).map(([t,e])=>kt(t,e,20)),kt(0,0,16)),3)],{tags:Ao});ct("leaf-sprig","doodles","Nhánh lá","Leaf sprig",["nhánh lá","sprig","lá","decor"],[Ct(`M${g(-90,60)} C${g(-30,20)} ${g(30,-20)} ${g(90,-70)}`,1),R(wt(...[[-50,30,-30],[-10,6,-40],[30,-24,-50],[-30,30,40],[10,4,30],[50,-30,20]].map(([t,e,o])=>{const r=Math.cos(Ze(o)),n=Math.sin(Ze(o));return`M${g(t,e)} C${g(t+(r*10-n*14),e+(n*10+r*14))} ${g(t+(r*30-n*10),e+(n*30+r*10))} ${g(t+r*36,e+n*36)} C${g(t+(r*30+n*10),e+(n*30-r*10))} ${g(t+(r*10+n*14),e+(n*10-r*14))} ${g(t,e)} Z`})),1)],{tags:Ao});ct("exclamation","doodles","Dấu chấm than","Exclamation",["chú ý","exclamation","!","warning"],[R(wt(`M${g(-16,-90)} L${g(16,-90)} L${g(10,30)} L${g(-10,30)} Z`,kt(0,66,16)),3)],{tags:Ao});ct("question","doodles","Dấu hỏi","Question mark",["câu hỏi","question","?","faq"],[Ct(`M${g(-40,-50)} C${g(-40,-100)} ${g(40,-100)} ${g(40,-50)} C${g(40,-14)} ${g(0,-14)} ${g(0,20)}`,1),R(kt(0,62,14),1)],{tags:Ao});to("animals","Con vật","Animals");const ca={role:["sticker","explain"],style:["playful","soft"]};ct("cat","animals","Con mèo","Cat",["mèo","cat","thú cưng","pet"],[R($e(0,40,70,56),1),R(kt(0,-40,48),1),R(wt(jt([[-44,-60],[-40,-104],[-12,-82]]),jt([[44,-60],[40,-104],[12,-82]])),1),R(wt($e(-18,-44,6,9),$e(18,-44,6,9)),5),R(jt([[-6,-24],[6,-24],[0,-16]]),3),Ct(`M${g(66,60)} C${g(110,60)} ${g(110,0)} ${g(90,-10)}`,1)],{tags:ca});ct("dog","animals","Con chó","Dog",["chó","dog","thú cưng","pet","cún"],[R($e(0,40,74,54),2),R(kt(0,-34,50),2),R(wt($e(-50,-30,16,34),$e(50,-30,16,34)),5),R(wt(kt(-18,-42,7),kt(18,-42,7)),5),R($e(0,-16,14,10),5),Ct(Ge(0,-8,10,20,160),5)],{tags:ca});ct("bird","animals","Chim","Bird",["chim","bird"],[R($e(0,0,70,50),1),R(kt(46,-34,30),1),R(jt([[74,-36],[100,-28],[74,-22]]),2),R(kt(52,-40,5),5),R(`M${g(-20,-10)} C${g(-60,-60)} ${g(-90,-30)} ${g(-80,0)} C${g(-60,-10)} ${g(-40,-6)} ${g(-20,-10)} Z`,4)],{tags:ca});ct("butterfly","animals","Bướm","Butterfly",["bướm","butterfly"],[R(wt($e(-44,-30,40,48),$e(44,-30,40,48)),3),R(wt($e(-34,36,28,30),$e(34,36,28,30)),2),R(pt(0,0,14,120,7),5),Ct(wt(`M${g(0,-56)} C${g(-6,-80)} ${g(-20,-90)} ${g(-30,-96)}`,`M${g(0,-56)} C${g(6,-80)} ${g(20,-90)} ${g(30,-96)}`),5)],{tags:ca});ct("chicken","animals","Con gà","Chicken",["gà","chicken","rooster"],[R($e(0,20,70,60),4),R(kt(40,-40,32),4),R(wt(kt(36,-76,10),kt(50,-80,9),kt(24,-74,8)),3),R(jt([[68,-42],[90,-36],[68,-30]]),2),R(kt(46,-46,5),5),R(wt(pt(-16,90,6,30,2),pt(16,90,6,30,2)),2)],{tags:ca});ct("fish-tropical","animals","Cá nhiệt đới","Tropical fish",["cá","fish","biển","sea"],[R(`M${g(-70,0)} C${g(-30,-70)} ${g(50,-60)} ${g(70,0)} C${g(50,60)} ${g(-30,70)} ${g(-70,0)} Z`,2),R(jt([[-60,0],[-110,-40],[-100,0],[-110,40]]),3),R(wt(pt(-10,0,14,96,6),pt(24,0,14,80,6)),4),R(kt(46,-10,7),5)],{tags:ca});ct("elephant","animals","Con voi","Elephant",["voi","elephant"],[R($e(-10,20,80,56),5),R(kt(54,-20,40),5),R(`M${g(84,-10)} C${g(110,20)} ${g(100,70)} ${g(80,80)} L${g(70,72)} C${g(84,50)} ${g(84,20)} ${g(64,0)} Z`,5),R($e(30,-24,26,34),4),R(wt(pt(-60,70,24,40,6),pt(30,70,24,40,6)),5),R(kt(62,-28,5),1)],{tags:ca});ct("turtle","animals","Con rùa","Turtle",["rùa","turtle"],[R(wt($e(-50,30,18,12),$e(50,30,18,12),$e(86,0,26,20)),1),R(`M${g(-80,20)} C${g(-80,-60)} ${g(70,-60)} ${g(70,20)} Z`,2),Ct(wt(Et(-50,-24,-36,16),Et(0,-44,0,16),Et(40,-24,30,16)),5),R(kt(96,-6,4),5)],{tags:ca});to("scenery","Cảnh nền","Scenery");const Dn={role:["background"],style:["soft","playful","clean"]};ct("ground-grass","scenery","Dải cỏ","Grass ground",["mặt đất","cỏ","ground","grass"],[R(`M${g(-300,0)} C${g(-200,-20)} ${g(-100,-20)} ${g(0,-6)} C${g(100,8)} ${g(200,-14)} ${g(300,0)} L${g(300,60)} L${g(-300,60)} Z`,1)],{tags:Dn,outline:!1});ct("road","scenery","Con đường","Road",["đường","road","phố","street"],[R(pt(0,0,600,70,0),5),R(wt(...Array.from({length:8},(t,e)=>pt(-262+e*75,0,40,6,2))),4)],{tags:Dn,outline:!1});ct("hills-band","scenery","Dải đồi","Rolling hills",["đồi","hills","landscape"],[R(`M${g(-300,40)} C${g(-220,-60)} ${g(-120,-60)} ${g(-40,30)} C${g(40,-50)} ${g(160,-60)} ${g(300,20)} L${g(300,80)} L${g(-300,80)} Z`,1),R(`M${g(-300,60)} C${g(-180,0)} ${g(-60,10)} ${g(40,56)} C${g(140,10)} ${g(220,10)} ${g(300,50)} L${g(300,80)} L${g(-300,80)} Z`,2)],{tags:Dn,outline:!1});ct("city-band","scenery","Dải thành phố","City band",["thành phố","city","skyline","background"],[R(jt([[-300,60],[-300,0],[-260,0],[-260,-40],[-220,-40],[-220,-10],[-180,-10],[-180,-80],[-140,-80],[-140,-20],[-100,-20],[-100,-60],[-50,-60],[-50,-100],[-20,-100],[-20,-30],[30,-30],[30,-70],[80,-70],[80,-10],[120,-10],[120,-50],[170,-50],[170,-90],[200,-90],[200,-20],[250,-20],[250,-50],[300,-50],[300,60]]),5)],{tags:Dn,outline:!1});ct("sea-band","scenery","Dải biển","Sea band",["biển","sea","ocean","nước"],[R(wt(`M${g(-300,0)}`+Array.from({length:12},(t,e)=>` C${g(-300+e*50+15,-14)} ${g(-300+e*50+35,-14)} ${g(-300+e*50+50,0)}`).join("")+` L${g(300,70)} L${g(-300,70)} Z`),1),Ct(wt(...[-200,-60,80,220].map(t=>`M${g(t,30)} C${g(t+15,22)} ${g(t+35,22)} ${g(t+50,30)}`)),4)],{tags:Dn,outline:!1});ct("sky-clouds","scenery","Trời nhiều mây","Sky with clouds",["bầu trời","sky","mây","clouds"],[R(wt(wo(-180,-10,140,60,5),wo(30,-40,180,70,6),wo(210,10,120,50,4)),4)],{tags:Dn,outline:!1});ct("mountain-range","scenery","Dãy núi","Mountain range",["dãy núi","mountains","range"],[R(jt([[-300,70],[-220,-50],[-150,20],[-60,-90],[30,10],[110,-70],[200,0],[260,-40],[300,0],[300,70]]),2),R(wt(jt([[-60,-90],[-84,-54],[-70,-58],[-56,-48],[-40,-62]]),jt([[110,-70],[94,-44],[108,-48],[122,-40],[130,-50]])),4)],{tags:Dn,outline:!1});ct("rice-field","scenery","Ruộng lúa bậc thang","Rice terraces",["ruộng","lúa","rice field","terraces","quê"],[R(`M${g(-300,-20)} C${g(-150,-50)} ${g(150,-50)} ${g(300,-20)} L${g(300,0)} C${g(150,-30)} ${g(-150,-30)} ${g(-300,0)} Z`,1),R(`M${g(-300,10)} C${g(-150,-18)} ${g(150,-18)} ${g(300,10)} L${g(300,32)} C${g(150,4)} ${g(-150,4)} ${g(-300,32)} Z`,2),R(`M${g(-300,42)} C${g(-150,18)} ${g(150,18)} ${g(300,42)} L${g(300,70)} L${g(-300,70)} Z`,1)],{tags:Dn,outline:!1});ct("night-sky","scenery","Bầu trời đêm","Night sky",["đêm","night","sao","stars"],[R(wt(...[[-240,-40,8],[-160,10,5],[-90,-60,6],[-20,-10,4],[60,-50,7],[140,0,5],[220,-30,6],[260,20,4]].map(([t,e,o])=>Fe(t,e,4,o*2,o*.6,0))),2),R(kt(170,-60,26),4)],{tags:Dn,outline:!1});to("emotes","Biểu cảm hoạt hình","Cartoon emotes");const gn={role:["overlay","sticker"],style:["playful","soft"]};ct("sweat-drops","emotes","Giọt mồ hôi","Sweat drops",["mồ hôi","sweat","lo lắng","nervous","ngại"],[R(wt(On(-20,-30,46),On(34,10,30)),4)],{tags:gn});ct("anger-mark","emotes","Dấu tức giận","Anger mark",["tức giận","anger","giận","bực","💢"],[Ct(wt(...[[-1,-1],[1,-1],[1,1],[-1,1]].map(([t,e])=>`M${g(t*14,e*70)} C${g(t*14,e*30)} ${g(t*30,e*14)} ${g(t*70,e*14)}`)),3)],{tags:gn});ct("zzz","emotes","Ngủ zzz","Sleeping zzz",["ngủ","sleep","zzz","buồn ngủ","mệt"],[Ct(wt(...[[-50,40,36],[10,-6,28],[54,-46,20]].map(([t,e,o])=>`M${g(t-o,e-o)} L${g(t+o,e-o)} L${g(t-o,e+o)} L${g(t+o,e+o)}`)),5)],{tags:gn});ct("idea-bulb","emotes","Ý tưởng","Idea bulb",["ý tưởng","idea","bóng đèn","nghĩ ra","aha"],[R(wt(kt(0,-20,46),`M${g(-22,20)} L${g(22,20)} L${g(18,52)} L${g(-18,52)} Z`),3),R(`M${g(-14,56)} L${g(14,56)} L${g(10,70)} L${g(-10,70)} Z`,2),Ct(wt(Et(-80,-20,-60,-20),Et(60,-20,80,-20),Et(0,-100,0,-80),Et(-58,-78,-44,-64),Et(58,-78,44,-64)),3)],{tags:gn});ct("dizzy","emotes","Choáng váng","Dizzy",["choáng","dizzy","chóng mặt","hoa mắt","bị đánh"],[Ct(`M${g(-70,0)} C${g(-70,-40)} ${g(70,-40)} ${g(70,0)} C${g(70,30)} ${g(-40,34)} ${g(-40,4)} C${g(-40,-14)} ${g(30,-14)} ${g(30,4)}`,1),R(wt(Fe(-60,-50,5,20,9),Fe(64,-36,5,16,7),Fe(0,46,5,14,6)),3)],{tags:gn});ct("shock-lines","emotes","Giật mình","Shock lines",["giật mình","shock","bất ngờ","surprise","hoảng"],[Ct(wt(...Array.from({length:8},(t,e)=>{const o=Ze(e*45),r=Math.cos(o),n=Math.sin(o);return Et(r*44,n*44,r*(e%2?78:96),n*(e%2?78:96))})),3)],{tags:gn});ct("love-hearts","emotes","Tim bay","Floating hearts",["yêu","love","tim","thích","crush"],[R(wt(...[[-30,10,40],[40,-30,28]].map(([t,e,o])=>`M${g(t,e+o*.9)} C${g(t-o*1.4,e)} ${g(t-o,e-o*1.1)} ${g(t,e-o*.4)} C${g(t+o,e-o*1.1)} ${g(t+o*1.4,e)} ${g(t,e+o*.9)} Z`)),3)],{tags:gn});ct("blush-lines","emotes","Ngượng đỏ mặt","Blush lines",["ngượng","blush","đỏ mặt","xấu hổ","shy"],[Ct(wt(...[-60,-10,40].map(t=>Et(t,50,t+30,-50))),3)],{tags:gn});ct("steam-puff","emotes","Xì khói (bực)","Steam puff",["xì khói","steam","bực","tức","huff"],[R(wt(kt(-44,10,26),kt(-14,-6,30),kt(22,4,24),kt(40,-30,18),kt(62,-54,12)),4)],{tags:gn});ct("music-notes-pop","emotes","Nốt nhạc (vui)","Happy notes",["vui","hát","notes","happy","nhạc"],[R(wt(kt(-40,40,16),kt(30,20,14)),1),Ct(wt(Et(-26,40,-26,-50),Et(44,20,44,-60),`M${g(-26,-50)} L${g(44,-60)}`),1)],{tags:gn});const np=My.map(t=>({...t,parts:Q8(t.parts)})),rS=new Map(np.map(t=>[t.id,t])),nS=Object.freeze(Object.entries(Lc).map(([t,[e,o]])=>({id:t,vi:e,en:o,count:np.filter(r=>r.cat===t).length}))),$y=Object.freeze(np.map(({parts:t,...e})=>Object.freeze({...e,tags:Object.freeze({videoType:["explainer","any"],orientation:["any"],cost:"free",energy:"calm",...e.tags||{role:["overlay"],style:["playful"]}})}))),aS=Object.freeze(np.map(t=>t.id)),iS=t=>{let e=1/0,o=1/0,r=-1/0,n=-1/0;for(const a of t){const i=a.d.match(/-?\d*\.?\d+/g).map(Number);for(let l=0;l+1<i.length;l+=2)e=Math.min(e,i[l]),r=Math.max(r,i[l]),o=Math.min(o,i[l+1]),n=Math.max(n,i[l+1])}return[aa(e),aa(o),aa(r),aa(n)]},e0=t=>String(t).toLowerCase().normalize("NFD").replace(/\p{M}/gu,"").replace(/đ/g,"d");function vy(t,{id:e="s1",pos:o=[500,500],scale:r=1,rot:n=0,colors:a=null,en:i=!1,stroke:l=null}={}){const p=rS.get(t);if(!p)throw Error(`Unknown 2D library shape "${String(t).slice(0,48)}" — search_shape_library lists the ids`);const c=Array.isArray(a)?Object.fromEntries(a.map((h,f)=>[f+1,h])):a||{};for(const h of Object.values(c))if(!/^#[0-9a-fA-F]{6}$/.test(h))throw Error("Library colours are #RRGGBB");const s=p.parts.map(h=>h.role!==7&&h.fill!==null&&c[h.role]?{...h,fill:c[h.role],role:7}:h);return{id:e,name:(i?p.en:p.vi).slice(0,40),type:"art",params:{parts:s,box:iS(s),...p.outline?{}:{outline:!1},lib:p.id},pos:[...o],rot:n,scale:[r,r],opacity:1,fill:{type:"color",color:s.find(h=>h.fill)?.fill??"#4a90d9"},stroke:l??{color:c[5]??Wd[5],width:5,cap:"round",join:"round"}}}function sS({query:t="",cat:e=null,human:o=null,limit:r=24}={}){const n=e0(t).split(/[^a-z0-9]+/).filter(i=>i.length>1);return $y.filter(i=>(!e||i.cat===e)&&(o==null||i.human===!!o)).map(i=>{const l=e0([i.id.replace(/-/g," "),i.vi,i.en,...i.words,Lc[i.cat][0],Lc[i.cat][1]].join(" ")),p=n.length?n.reduce((c,s)=>c+(` ${l} `.includes(` ${s} `)?3:l.includes(s)?1:0),0):1;return{e:i,score:p}}).filter(i=>i.score>0).sort((i,l)=>l.score-i.score).slice(0,Math.max(1,Math.min(100,r))).map(i=>i.e)}const HC=Object.freeze(Object.defineProperty({__proto__:null,LIB2D:$y,LIB2D_CATEGORIES:nS,LIB2D_IDS:aS,LIB_PALETTE:Wd,libraryArt:vy,searchLibrary2d:sS},Symbol.toStringTag,{value:"Module"})),o0=(t,e,o,r,n)=>t==="cover"?Math.max(e/r,o/n):Math.min(e/r,o/n);function lS(t,e){if(!(t>0)||!(e>0))return 0;const o=t/e;return 1-Math.min(o,1/o)}const r0=t=>{if(typeof t=="number")return t>0?t:0;const e=/^(\d+(?:\.\d+)?):(\d+(?:\.\d+)?)$/.exec(String(t||""));return e&&+e[2]>0?+e[1]/+e[2]:0},cS=.4,UC=(t,e,o=cS)=>lS(r0(t),r0(e))>o;function pS(t,e,o){const r=-(t.angle||0)*Math.PI/180,n=e-t.cx,a=o-t.cy,i=n*Math.cos(r)-a*Math.sin(r),l=n*Math.sin(r)+a*Math.cos(r);return Math.abs(i)<=t.w/2&&Math.abs(l)<=t.h/2}function YC(t,e,o,{alphaAt:r,threshold:n=8}={}){for(const a of t){const i=r?r(a.id,e,o):null;if(i!=null){if(i>=n)return a.id;continue}if(a.rect&&pS(a.rect,e,o))return a.id}return null}const qC=(t,e=.012)=>Math.abs(t)<e?0:t,ZC=(t,e)=>Math.abs(t)>=Math.abs(e)?{dx:t,dy:0}:{dx:0,dy:e},ti=[.37,0,.63,1],n0=[.33,0,.67,1],Pn=Object.freeze({sway:{vi:"Đung đưa",en:"Sway",amount:4,period:3.2,props:["rot"],anchor:"bottom"},swing:{vi:"Lắc con lắc",en:"Swing",amount:8,period:2.4,props:["rot"],anchor:"top"},breathe:{vi:"Thở",en:"Breathe",amount:.018,period:3.6,props:["sy"],anchor:"bottom"},bob:{vi:"Nhấp nhô",en:"Bob",amount:.012,period:2.2,props:["y"],anchor:null},wave:{vi:"Vẫy tay",en:"Wave",amount:18,period:1.1,props:["rot"],anchor:"top"},nod:{vi:"Gật đầu",en:"Nod",amount:3,period:2.6,props:["rot"],anchor:"bottom"},blink:{vi:"Chớp mắt",en:"Blink",amount:.92,period:3.8,props:["sy"],anchor:"center"},rise:{vi:"Bốc lên (hơi, khói)",en:"Rise (steam, smoke)",amount:.14,period:2.6,props:["y","opacity","zoom"],anchor:"center"},wiggle:{vi:"Rung nhẹ",en:"Wiggle",amount:.004,period:.8,props:["x","y"],anchor:null},drift:{vi:"Trôi qua lại",en:"Drift",amount:.02,period:8,props:["x"],anchor:null},spin:{vi:"Quay tròn",en:"Spin",amount:1,period:6,props:["rot"],anchor:"center"},"push-in":{vi:"Đẩy vào",en:"Push in",amount:.12,period:0,props:["zoom"],anchor:null,move:!0},"pull-out":{vi:"Kéo ra",en:"Pull out",amount:.12,period:0,props:["zoom"],anchor:null,move:!0},"pan-left":{vi:"Lia trái",en:"Pan left",amount:.04,period:0,props:["x"],anchor:null,move:!0},"pan-right":{vi:"Lia phải",en:"Pan right",amount:.04,period:0,props:["x"],anchor:null,move:!0}}),Nc=Object.freeze(Object.keys(Pn).filter(t=>Pn[t].move)),Ey=Object.freeze(Object.keys(Pn)),uS=60,Fc=t=>Math.round(t*1e4)/1e4,dS=t=>Math.round(t*30)/30,Sy=(t,e)=>Math.max(Tr[t].min,Math.min(Tr[t].max,e));function hS(t,e){let o=Math.imul(t^2654435769,2246822507)^Math.imul(e+1,3266489909);return o^=o>>>13,o=Math.imul(o,668265263),o^=o>>>16,(o>>>0)/4294967296}function fS(t,e,{amount:o=1,period:r,a:n=0,b:a=t.duration,phase:i=0}={}){const l=Pn[e];if(!l)throw Error(`animateLayer preset: ${Ey.join(" | ")}`);const p=l.amount*o,c=Math.max(.1,r??l.period),s={},h=x=>Ut(t,x,n),f=Math.max(n+1/30,a),m=(x,E,v,S)=>{const k=s[x]??=[];if(k.length>=uS||E>f+1e-6)return!1;const b=Fc(dS(E));return k.length&&b-k.at(-1).time<1/45||k.push({time:b,value:Fc(Sy(x,v)),...S?{ease:S}:{}}),!0},y=n-i*c,$=(x,E,v=!1)=>{const S=h(x),k=b=>v?S*(1+E*b):S+E*b;m(x,n,S,ti);for(let b=0;;b++){const A=y+c/4+b*c/2;if(!(A<=n+1/30)&&(A>f-c/4||!m(x,A,k(b%2?-1:1),ti)))break}m(x,f,S)};switch(e){case"sway":case"swing":case"wave":$("rot",p);break;case"nod":$("rot",p);break;case"breathe":{const x=h("sy");m("sy",n,x,ti);for(let E=0;;E++){const v=y+c/2+E*c/2;if(!(v<=n+1/30)&&(v>f-c/4||!m("sy",v,x*(1+(E%2?0:p)),ti)))break}m("sy",f,x);break}case"bob":{const x=h("y");m("y",n,x,ti);for(let E=0;;E++){const v=y+c/2+E*c/2;if(!(v<=n+1/30)&&(v>f-c/4||!m("y",v,x-(E%2?0:p),ti)))break}m("y",f,x);break}case"drift":$("x",p);break;case"blink":{const x=h("sy");m("sy",n,x);for(let E=0;;E++){const v=y+c*(E+.6);if(!(v<n+.1)&&(v+.16>f||!m("sy",v,x)||!m("sy",v+.07,x*(1-p))||!m("sy",v+.15,x)))break}m("sy",f,x);break}case"rise":{const x=h("y"),E=h("zoom");for(let v=0;;v++){const S=y+v*c;if(S+c<=n)continue;if(S>=f)break;const k=Math.max(n,S+(S>n?1/30:0)),b=(k-S)/c,A=Math.min(f,S+c);if(!m("y",k,x-p*b)||!m("opacity",k,Math.sin(Math.PI*b)**1.2,[.4,0,.6,1])||!m("zoom",k,E*(.7+.5*b)))break;S+c/2>k+1/30&&S+c/2<A&&m("opacity",S+c/2,1,[.4,0,.6,1]),m("y",A,x-p*(A-S)/c,"hold"),m("opacity",A,Math.sin(Math.PI*(A-S)/c)**1.2,"hold"),m("zoom",A,E*(.7+.5*(A-S)/c),"hold")}break}case"wiggle":{for(const[x,E]of[["x",11],["y",23]]){const v=h(x);m(x,n,v,"auto");for(let S=1;;S++){const k=n+S*c/2;if(k>=f-c/4||!m(x,k,v+p*(hS(S,E+(t.id?.length??0))*2-1),"auto"))break}m(x,f,v)}break}case"spin":{const x=h("rot");m("rot",n,x),m("rot",f,x+360*p*(f-n)/c);break}case"push-in":case"pull-out":{const x=h("zoom"),[E,v]=e==="push-in"?[x,x*(1+p)]:[x*(1+p),x];m("zoom",n,E,n0),m("zoom",f,v);break}case"pan-left":case"pan-right":{const x=h("x");m("x",n,x,n0),m("x",f,x+(e==="pan-left"?-p:p));break}}return s}const mS=t=>{const e=t?.shape;return!e||e.v!==2||t.kind!=="image"||t.fit==="cover"||t.layout!==void 0?null:Array.isArray(e.size)?e.size:e.square?[720,720]:[1280,720]};function Iy(t,e,o){const r=mS(t);if(!r)return null;const n=nw(t,t.start,t.start+t.duration,e,o),a=!n&&(kg(t,"rot")||!!aw(t))&&t.rotFit!=="frame",[i,l]=r,p=Math.ceil(Math.hypot(i,l)/2)*2;return i*(a?o0("contain",e,o,p,p):o0("contain",e,o,i,l))*xg(t,0,e,o).zoom}function qp(t,e){const o=new Set(e);let r=!0;for(;r;){r=!1;for(const n of t)n.parentId&&o.has(n.parentId)&&!o.has(n.id)&&(o.add(n.id),r=!0)}return[...o]}function xl(t,e,o=1280,r=720){nr(t);const n=new Map;for(const a of e){const i=t.find(p=>p.id===a),l=i&&Iy(i,o,r);l&&n.set(a,l)}return n}const a0=(t,e)=>{let o=t;for(const[r,n]of e){const a=Me(o,r);a.length&&(o={...o,...de(o,r,a.map(i=>({...i,value:Math.round(Sy(r,i.value*n)*1e6)/1e6})))})}return o},ei=t=>Math.round(t*1e6)/1e6;function hs(t,e,o=1280,r=720){let n=t.slice();const a=i=>{let l=0,p=n.find(c=>c.id===i);for(;p?.parentId&&l<9;)p=n.find(c=>c.id===p.parentId),l++;return l};for(const i of[...e.keys()].sort((l,p)=>a(l)-a(p))){nr(n);const l=n.findIndex(h=>h.id===i);if(l<0)continue;const p=Iy(n[l],o,r),c=p?e.get(i)/p:1;if(!(Math.abs(c-1)>1e-6))continue;const s=n[l];n[l]=a0({...s,scale:ei((s.scale??1)*c),...s.anchorX!==void 0?{anchorX:ei(s.anchorX/c)}:{},...s.anchorY!==void 0?{anchorY:ei(s.anchorY/c)}:{}},[["zoom",c],["ax",1/c],["ay",1/c]]),n=n.map(h=>h.parentId!==i?h:a0({...h,posX:ei((h.posX??0)/c),posY:ei((h.posY??0)/c),scale:ei((h.scale??1)/c)},[["x",1/c],["y",1/c],["zoom",1/c]]))}return nr(n),n}function Ml(t,e,o={}){if(t.kind==="audio")throw Error("animateLayer needs a visual layer");const r=fS(t,e,o);let n={...t};for(const[a,i]of Object.entries(r))i.length>=2&&(n={...n,...de(n,a,i)});return n}function gS(t,e,o,r=1280,n=720,a=null){let i,l;if(Array.isArray(o))[i,l]=o;else{const[x,E,v,S]=a??[0,0,1,1],k={center:[.5,.5],top:[.5,0],bottom:[.5,1],left:[0,.5],right:[1,.5],"top-left":[0,0],"top-right":[1,0],"bottom-left":[0,1],"bottom-right":[1,1]}[o];if(!k)throw Error("anchor: [x, y] of the frame (0..1) or top | bottom | center | left | right | top-left | top-right | bottom-left | bottom-right");i=x+(v-x)*k[0],l=E+(S-E)*k[1]}if(![i,l].every(x=>Number.isFinite(x)&&x>=-1&&x<=2))throw Error("anchor: x, y are 0..1 of the frame");const p=xg(t,e,r,n),c=.5+p.x,s=.5+p.y,h=-p.rot*Math.PI/180,f=(i-c)*r,m=(l-s)*n,y=(f*Math.cos(h)-m*Math.sin(h))/(p.sx||1),$=(f*Math.sin(h)+m*Math.cos(h))/(p.sy||1);return[Fc(y/(r*p.zoom)),Fc($/(n*p.zoom))]}function wa(t,e,{parentClipId:o,anchor:r,at:n=0,W:a=1280,H:i=720,box:l=null}){let p={...e};if(o!==void 0){if(o!==null){const c=t.find(s=>s.id===o);if(!c||c.kind==="audio")throw Error("rigLayer parentClipId: a visual layer of this timeline");if(ew(t,e.id,c.id))throw Error("rigLayer: that parent would make a loop")}p={...p,...ow(t,p,o,n,a,i)},p.parentId||delete p.parentId,nr(t.map(c=>c.id===e.id?p:c))}if(r!=null){const[c,s]=gS(p,n,r,a,i,l);p={...p,...rw(p,n,c,s,a,i)}}return p}const Rc=t=>t*Math.PI/180,At=(t,e)=>[t[0]+e[0],t[1]+e[1]],Bs=(t,e)=>[t[0]-e[0],t[1]-e[1]],$o=(t,e)=>[t[0]*e,t[1]*e],Xd=t=>Math.hypot(t[0],t[1]),Hd=t=>{const e=Xd(t)||1;return[t[0]/e,t[1]/e]},Ay=t=>[-t[1],t[0]],Xi=(t,e,o)=>t+(e-t)*o,ud=(t,e,o)=>[Xi(t[0],e[0],o),Xi(t[1],e[1],o)],Ei=(t,e,o)=>Math.max(e,Math.min(o,t)),hi=t=>t<.5?2*t*t:1-2*(1-t)**2,fs=t=>1+(1.70158+1)*(t-1)**3+1.70158*(t-1)**2,yS=300,i0={skin:"#f0c4a4",skinB:"#d9a283",hair:"#2a1c18",hairS:"#3d2a24",top:"#c8202f",topS:"#9e1824",inner:"#f6eee8",bottom:"#2a2226",bottomS:"#1c1619",shoe:"#1c1619",accent:"#f6eee8",eye:"#231816",lip:"#c25a5a",mouth:"#6e2230",tongue:"#d86a6a",teeth:"#ffffff",blush:"#f19a8a",prop:"#f6eee8",propS:"#d9cbc2",propLabel:"#c8202f",shadow:"#1e1719"},Aa=Object.freeze({host:{vi:"MC nữ",en:"Female host",hair:"bob",outfit:"blazer",palette:i0},hostman:{vi:"MC nam",en:"Male host",hair:"short",outfit:"shirt",palette:{...i0,top:"#f6eee8",topS:"#d9cbc2",inner:"#f6eee8",accent:"#c8202f",bottom:"#2a3550",bottomS:"#1e2740",hair:"#1c1412"}}}),bS=Object.freeze(Object.keys(Aa)),wS=Object.freeze(["skin","hair","top","inner","bottom","shoe","accent","lip","prop","propLabel"]),s0=Object.freeze(["neutral","smile","grin","surprised","wink","think","sad"]),l0=Object.freeze(["box","bottle","phone","card"]),kS={sway:0,lean:0,tilt:0,turn:0,bounce:0,hR:[42,-128],hL:[-42,-128],shR:"open",shL:"open"},je=t=>({...kS,...t}),Cy=Object.freeze({idle:{vi:"Đứng thở",en:"Idle",dur:2,face:"smile",cyc:t=>je({sway:Math.sin(t*1.6)*2,bounce:Math.sin(t*3.2)*1.2,tilt:Math.sin(t*1.1)*1.5})},talk:{vi:"Nói chuyện",en:"Talk",dur:3,face:"smile",cyc:t=>{const e=Math.sin(t*4.2),o=Math.sin(t*2.6+1);return je({sway:Math.sin(t*1.4)*3,bounce:Math.abs(e)*1.5,tilt:Math.sin(t*1.9)*3,turn:Math.sin(t*.9)*.15,hR:[56+e*10,-142+o*8],hL:[-52-o*8,-138+e*6],shR:"open",shL:"open"})}},wave:{vi:"Vẫy tay",en:"Wave",dur:1.8,face:"smile",keys:[[0,null],[.22,je({hR:[70,-292],shR:"wave",tilt:-3,lean:-2})],[1,je({hR:[70,-292],shR:"wave",tilt:-3,lean:-2})]],wave:!0},point:{vi:"Chỉ tay",en:"Point",dur:1.4,face:"smile",keys:[[0,null],[.3,je({hR:[128,-232],shR:"point",lean:3,turn:.45,tilt:2})],[1,je({hR:[126,-230],shR:"point",lean:3,turn:.45,tilt:2})]],ease:[fs,hi]},"point-up":{vi:"Chỉ lên",en:"Point up",dur:1.4,face:"smile",keys:[[0,null],[.3,je({hR:[66,-318],shR:"point",turn:.2,tilt:-4})],[1,je({hR:[66,-316],shR:"point",turn:.2,tilt:-4})]],ease:[fs,hi]},present:{vi:"Mời xem",en:"Present",dur:1.6,face:"grin",keys:[[0,null],[.35,je({hR:[124,-178],shR:"open",hL:[-36,-150],lean:2,turn:.4,tilt:3})],[1,je({hR:[120,-182],shR:"open",hL:[-36,-150],lean:2,turn:.4,tilt:3})]],ease:[fs,hi]},thumbs:{vi:"Giơ ngón cái",en:"Thumbs up",dur:1.3,face:"grin",keys:[[0,null],[.3,je({hR:[52,-212],shR:"thumb",tilt:-3,bounce:-3})],[1,je({hR:[50,-210],shR:"thumb",tilt:-3})]],ease:[fs,hi]},clap:{vi:"Vỗ tay",en:"Clap",dur:1.6,face:"grin",cyc:t=>{const e=Math.abs(Math.sin(t*7));return je({hR:[4+e*24,-196],hL:[-4-e*24,-194],shR:"open",shL:"open",bounce:-e*2,tilt:Math.sin(t*3.5)*2})}},hold:{vi:"Cầm sản phẩm",en:"Hold a product",dur:2,face:"smile",keys:[[0,null],[.3,je({hR:[24,-170],hL:[-24,-166],shR:"hold",shL:"hold",lean:-2,tilt:3,elDown:1})],[1,je({hR:[24,-174],hL:[-24,-170],shR:"hold",shL:"hold",lean:-2,tilt:3,elDown:1})]],prop:!0},"hold-up":{vi:"Giơ sản phẩm",en:"Show the product",dur:1.6,face:"grin",keys:[[0,null],[.32,je({hR:[70,-276],shR:"hold",hL:[-38,-150],turn:.3,tilt:-2})],[1,je({hR:[70,-280],shR:"hold",hL:[-38,-150],turn:.3,tilt:-2})]],ease:[fs,hi],prop:!0,one:!0},think:{vi:"Suy nghĩ",en:"Think",dur:1.8,face:"think",keys:[[0,null],[.35,je({hR:[14,-240],shR:"fist",hL:[-6,-188],shL:"fist",tilt:7,turn:-.2,elDown:1})],[1,je({hR:[14,-240],shR:"fist",hL:[-6,-188],shL:"fist",tilt:8,turn:-.2,elDown:1})]]},shrug:{vi:"Nhún vai",en:"Shrug",dur:1.2,face:"sad",keys:[[0,null],[.4,je({hR:[78,-170],hL:[-78,-170],shR:"open",shL:"open",bounce:-5,tilt:6})],[.75,je({hR:[78,-170],hL:[-78,-170],shR:"open",shL:"open",bounce:-5,tilt:6})],[1,je({})]]},nod:{vi:"Gật đầu",en:"Nod",dur:1,face:"smile",cyc:t=>je({tilt:0,bounce:Math.max(0,Math.sin(t*9))*-3,nod:Math.max(0,Math.sin(t*9))})}}),c0=Object.freeze(Object.keys(Cy)),xS={a:"A",e:"E",i:"E",y:"E",o:"O",u:"O",w:"O",m:"X",b:"X",p:"X",f:"C",v:"C"};function MS(t){const o=(Array.isArray(t)?t:[]).filter(r=>r&&typeof r.text=="string"&&Number.isFinite(r.start)&&Number.isFinite(r.end)&&r.end>r.start).map(r=>({start:r.start,end:r.end,chars:[...r.text.normalize("NFD").replace(/[̀-ͯ]/g,"").replace(/đ/gi,"d").toLowerCase()].filter(n=>/[a-z ,.!?]/.test(n))}));return r=>{const n=o.find(i=>r>=i.start&&r<i.end);if(!n||!n.chars.length)return null;const a=n.chars[Math.min(n.chars.length-1,Math.floor((r-n.start)/(n.end-n.start)*n.chars.length))];return/[ ,.!?]/.test(a)?"X":xS[a]??"C"}}function hr(t,e,o,r){const n=Hd(Bs(e,t)),a=Ay(n),i=Xd(Bs(e,t)),l=[];for(let p=0;p<=3;p++){const c=p/3*.94;l.push(At(At(t,$o(n,i*c)),$o(a,Xi(o,r,c)/2)))}l.push(At(e,$o(n,r/2)));for(let p=3;p>=0;p--){const c=p/3*.94;l.push(At(At(t,$o(n,i*c)),$o(a,-Xi(o,r,c)/2)))}return l.push(At(t,$o(n,-o/2))),l}const Pe=(t,e,o,r=0,n=10)=>Array.from({length:n},(a,i)=>{const l=i/n*2*Math.PI,p=Math.cos(l)*e,c=Math.sin(l)*o,s=Rc(r);return[t[0]+p*Math.cos(s)-c*Math.sin(s),t[1]+p*Math.sin(s)+c*Math.cos(s)]}),$l=(t,e,o,r,n,a=6)=>Array.from({length:a+1},(i,l)=>{const p=Rc(Xi(r,n,l/a));return[t[0]+Math.cos(p)*e,t[1]+Math.sin(p)*o]});function p0(t,e,o,r,n){const a=Bs(e,t),i=Ei(Xd(a),Math.abs(o-r)+1,o+r-.5),l=Math.atan2(a[1],a[0]),p=Math.acos(Ei((o*o+i*i-r*r)/(2*o*i),-1,1)),c=At(t,$o([Math.cos(l+n*p),Math.sin(l+n*p)],o));return{joint:c,end:At(c,$o(Hd(Bs(e,c)),r))}}function $S(t,e,o,r,n,a,i){const l=[],p=(D,H,ut={})=>l.push({points:D.map(a),fill:H,...ut}),c=(D,H=.6)=>l.push({points:D.map(a),fill:null,closed:!1,lw:H}),s=o.bounce,h=[o.sway,-140+s],f=[Math.sin(Rc(o.lean)),-Math.cos(Rc(o.lean))],m=[-f[1],f[0]],y=(D,H)=>At(At(h,$o(f,D)),$o(m,H));y(78,0);const $=y(98,0),x=At(y(132,0),[o.turn*3,(o.nod??0)*4]),E=y(90,30),v=y(90,-30);p(Pe([o.sway*.5,2],44,6),e.shadow,{line:!1});const S=y(-2,13),k=y(-2,-13),b=[17,-4],A=[-17,-4];t.outfit==="blazer"?(p(hr(S,b,20,13),e.skin),p(hr(k,A,20,13),e.skinB)):(p(hr(S,b,24,18),e.bottom,{lw:1.1}),p(hr(k,A,24,18),e.bottomS,{lw:1.1})),p(Pe([b[0]+4,-2],13,6),e.shoe),p(Pe([A[0]-4,-2],13,6),e.shoe),t.outfit==="blazer"?p([y(4,-26),y(4,26),y(-56,32),y(-60,0),y(-56,-32)],e.bottom,{lw:1.15}):p([y(6,-25),y(6,25),y(-10,26),y(-10,-26)],e.bottom,{lw:1.1}),p([y(4,-25),y(52,-27),y(88,-34),y(96,-12),y(96,12),y(88,34),y(52,27),y(4,25)],e.top,{lw:1.25}),p([y(52,14),y(88,30),y(88,34),y(52,27),y(4,25),y(4,14)],e.topS,{line:!1}),t.outfit==="blazer"?(p([y(96,-10),y(96,10),y(54,0)],e.inner,{line:!1}),c([y(96,-11),y(54,0),y(10,-2)],.7),c([y(96,11),y(54,0)],.7),p(Pe(y(40,-4),2.2,2.2),e.topS,{line:!1}),p(Pe(y(26,-4),2.2,2.2),e.topS,{line:!1})):(c([y(96,-11),y(84,0),y(96,11)],.7),p([y(86,-4),y(86,4),y(50,5),y(42,0),y(50,-5)],e.accent,{lw:.8})),p(hr($,At(x,[0,18]),15,14),e.skinB,{lw:.9}),t.hair==="bob"&&p([At(x,[-33,-8]),At(x,[-30,-30]),At(x,[0,-40]),At(x,[30,-30]),At(x,[33,-8]),At(x,[34,22]),At(x,[22,26]),At(x,[-22,26]),At(x,[-34,22])],e.hair);const I=o.tilt;p(Pe(At(x,[-26,4]),6,8),e.skin,{lw:.8}),p(Pe(At(x,[26,4]),6,8),e.skin,{lw:.8}),p(Pe(x,26,30,I,12),e.skin,{lw:1.2});const P=o.turn*7,C=(D,H)=>At(x,[D+P,H]),z=r.blink,N=(D,H,ut)=>{if(H||ut==="happy"){c(ut==="happy"?$l(C(D,-1),4.5,3.5,200,340):$l(C(D,-2),4.5,2.5,20,160),.7);return}const gt=ut==="wide",xt=gt?4:3.4,u=gt?5.6:4.4;p(Pe(C(D,-2),xt,u),e.eye,{line:!1}),p(Pe(C(D+1.2,-3.6),1.2,1.2,0,6),"#ffffff",{line:!1})},F=r.expr,K=F==="grin"?"happy":F==="surprised"?"wide":null;N(10,z,K),N(-10,z||F==="wink",K);const _=F==="surprised"?-17:F==="sad"?-12:-14;c(F==="think"?[C(5,-15),C(10,-18),C(15,-16)]:[C(5,_+1),C(10,_-(F==="sad"?-1:1)),C(15,_+(F==="sad"?-2:1))],.65),c(F==="think"?[C(-15,-14),C(-10,-14),C(-5,-14)]:[C(-15,_+(F==="sad"?-2:1)),C(-10,_-(F==="sad"?-1:1)),C(-5,_+1)],.65),c([C(1,4),C(2,9),C(-1,10)],.5),p(Pe(C(15,9),4.5,2.6,0,8),e.blush,{line:!1}),p(Pe(C(-15,9),4.5,2.6,0,8),e.blush,{line:!1});const q=C(0,17),U=r.mouth;U==="A"?(p(Pe(q,6,5.5),e.mouth,{lw:.6}),p(Pe(At(q,[0,2.6]),3.6,2),e.tongue,{line:!1})):U==="E"?(p(Pe(q,7,2.8),e.mouth,{lw:.6}),p([At(q,[-5,-1.6]),At(q,[5,-1.6]),At(q,[4,-.4]),At(q,[-4,-.4])],e.teeth,{line:!1})):U==="O"?p(Pe(q,4,4.8),e.mouth,{lw:.6}):U==="C"?p(Pe(q,5,2.2),e.mouth,{lw:.55}):U==="X"?c([At(q,[-5,0]),At(q,[0,.8]),At(q,[5,0])],.6):F==="grin"||F==="surprised"?F==="surprised"?p(Pe(q,4.2,5),e.mouth,{lw:.6}):(p([At(q,[-8,-2]),At(q,[8,-2]),At(q,[5,4]),At(q,[0,6]),At(q,[-5,4])],e.mouth,{lw:.6}),p([At(q,[-7,-1.6]),At(q,[7,-1.6]),At(q,[6,.4]),At(q,[-6,.4])],e.teeth,{line:!1})):F==="sad"?c($l(At(q,[0,3]),6,3,200,340),.65):F==="think"?c([At(q,[-4,0]),At(q,[4,-1])],.6):c($l(At(q,[0,-2]),7,4,20,160),.65),t.hair==="bob"?p([At(x,[-28,-6]),At(x,[-27,-26]),At(x,[-4,-36]),At(x,[22,-31]),At(x,[29,-12]),At(x,[16,-20]),At(x,[2,-15]),At(x,[-12,-20]),At(x,[-20,-8])],e.hair):p([At(x,[-27,-4]),At(x,[-26,-24]),At(x,[-6,-36]),At(x,[18,-34]),At(x,[28,-16]),At(x,[27,-4]),At(x,[20,-18]),At(x,[0,-24]),At(x,[-18,-16])],e.hair);const rt=(D,H,ut,gt,xt,u)=>{const st=p0(D,H,52,48,1),V=p0(D,H,52,48,-1),d=j=>j.joint[0]*ut+j.joint[1]*(o.elDown?4:.9),w=d(st)>=d(V)?st:V,T=xt?e.topS:e.top;p(hr(D,w.joint,19,16),T,{lw:1.15}),p(hr(w.joint,w.end,16,13),T,{lw:1.15}),p(hr(ud(w.joint,w.end,.82),w.end,13,12),t.outfit==="blazer"?e.inner:e.top,{lw:.8}),ot(w.end,Hd(Bs(w.end,w.joint)),gt,u)},ot=(D,H,ut,gt)=>{const xt=Ay(H),u=e.skin;if(ut==="point"){p(hr(D,At(D,$o(H,18)),6,5),u,{lw:.9}),p(Pe(D,8,7),u,{lw:.9});return}if(ut==="thumb"){p(Pe(D,8.5,8),u,{lw:.9}),p(hr(At(D,[0,-4]),At(D,[0,-19]),6,5),u,{lw:.9});return}if(ut==="fist"){p(Pe(D,8.5,8),u,{lw:.9});return}if(ut==="wave"){const st=[0,-1];p(Pe(At(D,[0,-3]),9,10),u,{lw:.9});for(const V of[-6,-2,2,6])p(hr(At(D,[V,-9]),At(D,[V*1.3,-21]),4.2,3.6),u,{lw:.8});p(hr(At(D,[gt?7:-7,0]),At(D,At($o(st,8),[gt?15:-15,-2])),4.6,4),u,{lw:.8});return}p(Pe(At(D,$o(H,3)),9,10,Math.atan2(H[1],H[0])*180/Math.PI),u,{lw:.9});for(const st of[-5,-1.6,1.8,5.2])p(hr(At(At(D,$o(H,9)),$o(xt,st)),At(At(D,$o(H,ut==="hold"?13:19)),$o(xt,st*1.15)),4,3.4),u,{lw:.8})},G=o.shR==="hold",J=D=>{const H=i.kind;H==="bottle"?(p([[-13,28],[13,28],[14,-14],[7,-27],[6,-40],[-6,-40],[-7,-27],[-14,-14]].map(ut=>At(D,ut)),e.prop,{lw:1}),p([[-6,-50],[6,-50],[6,-40],[-6,-40]].map(ut=>At(D,ut)),e.propLabel,{lw:.9}),p([[-14,-4],[14,-4],[14,14],[-14,14]].map(ut=>At(D,ut)),e.propLabel,{line:!1}),p([[-9,-12],[-6,-12],[-6,22],[-9,22]].map(ut=>At(D,ut)),"#ffffff",{line:!1})):H==="phone"?(p([At(D,[-14,-26]),At(D,[14,-26]),At(D,[14,26]),At(D,[-14,26])],e.eye,{lw:1}),p([At(D,[-11,-21]),At(D,[11,-21]),At(D,[11,21]),At(D,[-11,21])],e.propLabel,{line:!1})):H==="card"?(p([At(D,[-26,-15]),At(D,[26,-15]),At(D,[26,15]),At(D,[-26,15])],e.prop,{lw:1}),p([At(D,[-20,-6]),At(D,[4,-6]),At(D,[4,0]),At(D,[-20,0])],e.propLabel,{line:!1})):(p([At(D,[-24,-22]),At(D,[24,-22]),At(D,[24,22]),At(D,[-24,22])],e.prop,{lw:1}),p([At(D,[-24,-22]),At(D,[24,-22]),At(D,[18,-30]),At(D,[-18,-30])],e.propS,{lw:.9}),p([At(D,[-24,-2]),At(D,[24,-2]),At(D,[24,8]),At(D,[-24,8])],e.propLabel,{line:!1}))},Z=At(o.hR,[o.sway,s]),at=At(o.hL,[o.sway,s]);return G&&i&&o.shL==="hold"&&J(At(ud(Z,at,.5),[0,-6])),rt(v,at,-1,o.shL,!0,!0),rt(E,Z,1,o.shR,!1,!1),G&&i&&o.shL!=="hold"&&J(At(Z,[0,-30])),l}const u0=(t,e,o)=>{const r={};for(const n of new Set([...Object.keys(t),...Object.keys(e)])){const a=t[n],i=e[n];r[n]=i==null?a:a==null?i:Array.isArray(i)?ud(a,i,o):typeof i=="number"?Xi(a,i,o):o<.5?a:i}return r},d0=t=>({...t,sway:-t.sway,lean:-t.lean,tilt:-t.tilt,turn:-t.turn,hR:[-t.hL[0],t.hL[1]],hL:[-t.hR[0],t.hR[1]],shR:t.shL,shL:t.shR});function h0({character:t="host",colors:e=null,x:o=.5,ground:r=.95,size:n=.8,fps:a=24,actions:i=[],speech:l=null,W:p=1280,H:c=720}){const s=Aa[t];if(!s)throw Error(`animatePuppet presenter character: ${bS.join(" | ")}`);const h={...s.palette,...e||{}},f=n*c/yS,m=(Array.isArray(i)?i:[]).slice(0,40);if(!m.length)throw Error(`animatePuppet actions: [{move: ${c0.join(" | ")}, duration?, face?, side?, prop?}]`);let y=0;const $=m.map((k,b)=>{const A=Cy[k?.move];if(!A)throw Error(`animatePuppet actions[${b}].move (presenter): ${c0.join(" | ")}`);if(k.face!=null&&!s0.includes(k.face))throw Error(`animatePuppet actions[${b}].face: ${s0.join(" | ")}`);if(k.side!=null&&!["left","right"].includes(k.side))throw Error(`animatePuppet actions[${b}].side: left | right (which side the gesture goes to)`);if(k.prop!=null&&!l0.includes(k.prop))throw Error(`animatePuppet actions[${b}].prop: ${l0.join(" | ")}`);const I=Number.isFinite(k.duration)?Ei(k.duration,.3,20):A.dur,P={g:A,a:k,t0:y,dur:I,face:k.face??A.face,mirror:k.side==="left",prop:A.prop?{kind:k.prop??"box"}:null};return y+=I,P});$.forEach((k,b)=>{k.from=b?$[b-1].at(1,$[b-1].dur):je({}),k.at=(A,I)=>{let P;if(k.g.cyc)P=u0(k.from,k.mirror?d0(k.g.cyc(I)):k.g.cyc(I),Ei(I/.35,0,1));else{const C=k.g.keys.map(([U,rt])=>[U,rt?k.mirror?d0(rt):rt:k.from]);let z=0;for(;z<C.length-2&&A>C[z+1][0];)z++;const[N,F]=C[z],[K,_]=C[z+1],q=(k.g.ease?.[z]??hi)(Ei((A-N)/(K-N),0,1));if(P=u0(F,_,q),k.g.wave&&A>.22){const U=Math.sin(I*13)*14;P=k.mirror?{...P,hL:[P.hL[0]-U,P.hL[1]]}:{...P,hR:[P.hR[0]+U,P.hR[1]]}}}return{...P,bounce:(P.bounce||0)+Math.sin(I*3)*.8}}});const x=MS(l),E=y,v=Math.min(Math.round(E*a),480),S=[];for(let k=0;k<v;k++){const b=k/a,A=$.find(q=>b<q.t0+q.dur-1e-9)??$.at(-1),I=b-A.t0,P=Ei(I/A.dur,0,1),C=A.at(P,I),z=(b+.7)%3.4,N=z<2/a&&A.face!=="wink"&&A.face!=="grin",F={expr:A.face,mouth:x(b),blink:N},K=[o*p,r*c],_=([q,U])=>[Math.round((K[0]+q*f)/p*1e4)/1e4,Math.round((K[1]+U*f)/c*1e4)/1e4];S.push({parts:$S(s,h,C,F,b,_,A.prop)})}return{frames:S,duration:v/a}}const ap=Object.freeze({cutBefore:.08,insert:.32,reaction:.55,minShot:.2,hold:1,lens:{wide:32,insert:50,reaction:50,finisher:28},insertWidth:1.1,insertWidthKick:1.6,insertAxis:.4,reactionSide:1.8,reactionBack:.4,clearance:1.1});function vS(t,e,o,r=ap){const n=[...t].filter(c=>c.time>e+1e-6&&c.time<o-1e-6).sort((c,s)=>c.time-s.time),a=[],i=(c,s,h,f)=>{s-c>1e-6&&a.push({from:c,to:s,kind:h,...f?{beat:f}:{}})},l=c=>{a.length&&(a[a.length-1].to=Math.max(a[a.length-1].to,c))};let p=e;for(let c=0;c<n.length;c++){const s=n[c],h=n[c+1],f=Math.max(p,s.time-r.cutBefore),m=h?h.time-r.cutBefore:o,y=s.result==="head"||s.result==="body";if(f-p>=r.minShot||!a.length?i(p,f,"wide"):l(f),p=Math.max(p,f),s.last&&y){const $=Math.min(p+r.insert,Math.max(p+r.minShot,o-r.hold));i(p,$,"insert",s),i($,o,"finisher",s),p=o;break}if(y){let $=Math.min(p+r.insert,m);m-$<r.minShot&&($=m),i(p,$,"insert",s);const x=Math.min($+r.reaction,m);x-$>=r.minShot&&i($,x,"reaction",s),p=Math.max($,x)}else{const $=Math.min(p+r.insert+r.reaction,m);i(p,$,"reaction",s),p=$}}o-p>1e-6&&(o-p>=r.minShot||!a.length?i(p,o,"wide"):l(o));for(let c=a.length-1;c>0;c--)a[c].to-a[c].from<r.minShot-1e-6&&(a[c-1].to=a[c].to,a.splice(c,1));return a}function JC(t,e=[]){const o=t.map(i=>i.to-i.from).sort((i,l)=>i-l),r=t.length?t[t.length-1].to-t[0].from:0,n=t.filter(i=>i.kind==="insert"&&i.beat).map(i=>+(i.beat.time-i.from).toFixed(3)),a=o.length?o[Math.floor(o.length/2)]:0;return{cuts:Math.max(0,t.length-1),perSecond:r?+((t.length-1)/r).toFixed(2):0,shortest:+(o[0]??0).toFixed(2),median:+a.toFixed(2),longest:+(o[o.length-1]??0).toFixed(2),insertLead:n,beats:e.length}}const Ia=t=>{const e=Math.hypot(t[0],t[1],t[2])||1;return[t[0]/e,t[1]/e,t[2]/e]},Ca=(t,e,o=1)=>[t[0]+e[0]*o,t[1]+e[1]*o,t[2]+e[2]*o],Dc=(t,e)=>[t[0]-e[0],t[1]-e[1],t[2]-e[2]],f0=t=>Math.min(t.atk?.[1]??0,t.def?.[1]??0),m0=t=>Math.atan(18/t);function QC(t,e,o=ap){const r=Ia([e.side[0],0,e.side[2]]),n=Ia([e.axis[0],0,e.axis[2]]),a=[-n[0],0,-n[2]];if(t==="insert"){const f=o.lens.insert,m=(e.foot?o.insertWidthKick:o.insertWidth)/2/Math.tan(m0(f)),y=Ia(Ca(r,n,o.insertAxis??.9)),$=[e.contact[0],e.contact[1],e.contact[2]],x=Ca($,y,m);return x[1]=Math.max(f0(e)+.15,e.contact[1]-.05),{position:x,target:$,lens:f}}if(t==="reaction"){const f=o.lens.reaction,m=[e.defHead[0],e.defHead[1]+.03,e.defHead[2]];let y=a;if(e.defFace){const v=Ia([e.defFace[0],0,e.defFace[2]]),S=v[0]*r[0]+v[2]*r[2],k=[v[0]-r[0]*S,0,v[2]-r[2]*S];Math.hypot(k[0],k[2])>.2&&(y=Ia(k)),y=[y[0]*(1+2.5*Math.max(0,-S)),0,y[2]*(1+2.5*Math.max(0,-S))]}const $=Ia(Ca(r.map(v=>v*o.reactionSide),y,o.reactionBack)),x=Math.hypot(o.reactionSide,o.reactionBack),E=Ca(m,$,x);return E[1]=e.defHead[1]+.15,{position:E,target:m,lens:f}}const i=o.lens.finisher,l=f0(e),p=[(e.atk[0]+e.def[0])/2,l,(e.atk[2]+e.def[2])/2],c=Math.max(2.2,(e.sep+2)/2/Math.tan(m0(i))),s=[p[0],l+.8,p[2]],h=Ca(s,r,c);return h[1]=l+.45,{position:h,target:s,lens:i}}function tj(t,e,o=ap.clearance,r=1.5){const n=Ia(Dc(t.position,t.target)),a=Math.hypot(...Dc(t.position,t.target));let i=0;for(let c=0;c<6;c++){const s=Ca(t.target,n,a+i);let h=1/0;for(const f of e)h=Math.min(h,Math.hypot(f[0]-s[0],f[1]-s[1],f[2]-s[2]));if(h>=o-1e-6||i>=r)return{...t,position:s,backed:+i.toFixed(3),near:+h.toFixed(3)};i=Math.min(r,i+(o-h)+.05)}const l=Ca(t.target,n,a+i);let p=1/0;for(const c of e)p=Math.min(p,Math.hypot(c[0]-l[0],c[1]-l[1],c[2]-l[2]));return{...t,position:l,backed:+i.toFixed(3),near:+p.toFixed(3)}}const ej=Object.freeze([.4,0,.9,-.4,-.8]);function oj(t,e,o,{radius:r=.13,margin:n=.05,skip:a=.06}={}){const i=Dc(e,t),l=Math.hypot(...i),p=[i[0]/l,i[1]/l,i[2]/l];let c=0;for(const s of o){if(Math.hypot(s[0]-e[0],s[1]-e[1],s[2]-e[2])<a)continue;const h=Dc(s,t),f=h[0]*p[0]+h[1]*p[1]+h[2]*p[2];if(f<.1||f>l-n)continue;Math.hypot(h[0]-p[0]*f,h[1]-p[1]*f,h[2]-p[2]*f)<r&&c++}return c}const wn=(t,e,o)=>Math.max(e,Math.min(o,t)),ES=300,Zp=Object.freeze(["jab","cross","combo","front-kick","roundhouse","flying-kick","thrust","smash","staff-spin","sweep","spin-kick","uppercut","slash","beam","energy-slash","whip","bolt"]),Jp=Object.freeze(["block","dodge","hit","knockdown","launched","roll","parry","ko","hurt"]),vl=Object.freeze(["backflip","frontflip","cartwheel","roll","taunt","guard","teleport","approach","dash"]),Bc=Object.freeze({fighters:4,beats:24}),El={whip:560,bolt:900,beam:520,"energy-slash":230,jab:196,cross:196,combo:196,"front-kick":236,roundhouse:226,"flying-kick":360,thrust:300,smash:250,"staff-spin":270,sweep:210,"spin-kick":236,uppercut:176,slash:262},SS={hurt:.014,ko:.02,hit:.011,knockdown:.018,launched:.02,block:.005,clash:.008,dodge:0,roll:0},IS={hurt:.08,ko:.12,hit:.07,knockdown:.1,launched:.12,block:.04,clash:.09,dodge:0,roll:0},AS={hurt:[.05,0],ko:[.09,2.5],hit:[.05,0],knockdown:[.09,2.5],launched:[.1,3],block:[.02,0],clash:[.05,1.2],dodge:[0,0],roll:[0,0]},g0=Object.freeze({jab:["mc-boxing-jab-3","mc-boxing-jab-5","mc-boxing-jab-7"],cross:["mc-boxing-cross-2","mc-boxing-cross-6","mc-boxing-cross-9"],combo:["mc-boxing-combo-6","mc-street-combo-1","mc-boxing-combo-9"],uppercut:["mc-boxing-uppercut-2","mc-boxing-uppercut-5"],roundhouse:["mx-kick-roundhouse-1"],"front-kick":["mx-kick-front-1"],"spin-kick":["mx-gs-spin-kick"],"flying-kick":["mc-jump-kick"],slash:["mx-gs-slash-down","mx-gs-slash-power"],smash:["mx-gs-slash-power"],thrust:["mx-gs-slash-low"],hit:["mx-react-head-1","mx-react-body-1","mx-react-head-big-1"],knockdown:["mc-react-fall-back"],ko:["mc-react-fall-back"],beam:["mc-boxing-cross-6","mc-boxing-cross-9"],"energy-slash":["mc-boxing-hook-4","mc-boxing-hook-9"],whip:["mc-boxing-hook-4","mc-boxing-uppercut-5","mc-boxing-hook-9"],bolt:["mc-boxing-cross-9"],hurt:["mc-react-stagger-back","mx-react-body-1","mc-react-stumble"],walk:["mc-walk","mc-walk-2"],run:["mc-run"],block:["mx-block-1","mx-block-right-1"],roll:["mc-roll-under"],parry:["mx-gs-blocked"],backflip:["mc-backflip"],cartwheel:["mc-cartwheel-2"],frontflip:["mc-front-handspring"],guard:["mc-guard-bounce-1"],"step-in":["mc-step-forward-1","mc-step-forward-2"],"step-out":["mc-step-back-1","mc-step-back-2"]}),CS=new Set(["slash","smash","thrust","parry"]);function jS(t,e){const o=e.length;if(!Array.isArray(t)||!t.length||t.length>Bc.beats)throw Error(`animatePuppet beats: [{by 0–${o-1}, target?, attack ${Zp.join("|")} | move ${vl.join("|")}, react? ${Jp.join("|")}, pause?}] (1–${Bc.beats})`);return t.map((r,n)=>{const a=`animatePuppet beats[${n}]`;if(!r||typeof r!="object")throw Error(`${a} must be an object`);const i=r.by??n%2;if(!(Number.isInteger(i)&&i>=0&&i<o))throw Error(`${a}.by: 0–${o-1} (which fighter of cast acts)`);const l=r.target??(i===0?1:0);if(!(Number.isInteger(l)&&l>=0&&l<o&&l!==i))throw Error(`${a}.target: another fighter of cast (0–${o-1})`);const p=r.pause??.15;if(!(Number.isFinite(p)&&p>=0&&p<=4))throw Error(`${a}.pause: s before the next beat, 0–4`);if(r.stop!=null&&!(Number.isFinite(r.stop)&&r.stop>=.03&&r.stop<=.9))throw Error(`${a}.stop: 0.03–0.9 (fraction of the frame width)`);if(r.move!=null&&r.attack==null){if(!vl.includes(r.move))throw Error(`${a}.move: ${vl.join(" | ")}`);return{by:i,target:l,move:r.move,pause:p,...r.stop!=null?{stop:r.stop}:{}}}if(!Zp.includes(r.attack))throw Error(`${a}.attack: ${Zp.join(" | ")} (or move: ${vl.join(" | ")})`);if(Er[r.attack]?.prop==="staff"&&!Mu(e[i].character??"fighter"))throw Error(`${a}: ${r.attack} needs a fighter with a weapon (${Object.keys(Qn).filter(Mu).join(", ")})`);const c=r.react??"block";if(!Jp.includes(c))throw Error(`${a}.react: ${Jp.join(" | ")}`);return{by:i,target:l,attack:r.attack,react:c,pause:p}})}function TS({cast:t,beats:e,fps:o=12,fx:r=!0,accent:n="#ffd23f",W:a=1280,H:i=720,stick:l=!1,dust:p="#c9bfb2",tempo:c=null,camera:s=null,mocap:h=null,energyColor:f="#ff4fd8",toon:m=null,law:y=!0,maxFrames:$=480}){if(!Array.isArray(t)||t.length<2||t.length>Bc.fighters)throw Error(`animatePuppet cast: 2–${Bc.fighters} fighters for beats [{character, x?, facing?, …}, {…}]`);const x=t.length,E=t.map((tt,nt)=>tt.x??(nt?.64+(nt-1)*.12:.36)),v=tt=>E[tt===0?1:0]>=E[tt]?"right":"left",S=t.map((tt,nt)=>({character:tt.character??(nt?"brawler":"fighter"),x:E[nt],ground:tt.ground??.9,size:(tt.size??.5)*(tt.height??1),facing:tt.facing??v(nt),colors:tt.colors??null,grip:tt.grip??"guard",hair:tt.hair??null,eyes:tt.eyes??null,weight:tt.weight??null}));for(const tt of S)if(!Qn[tt.character])throw Error(`animatePuppet cast character: ${Object.keys(Qn).join(" | ")}`);const k=jS(e,S),b=S.map(tt=>tt.size*i/ES),A=tt=>tt.facing==="left"?-1:1,I=S.map(()=>[]),P=S.map(tt=>tt.x*a),C=S.map(()=>!1),z=S.map(()=>!1),N=[],F=[],K=[],_=tt=>l||Qn[S[tt].character].look==="stick",q={},U=(tt,nt)=>{const mt=h?g0[tt]:null;if(mt&&!(CS.has(tt)&&S[nt].character&&Qn[S[nt].character].prop!=="sword")){const $t=mt.filter(zt=>h[zt]);if($t.length){const zt=q[tt]=(q[tt]??-1)+1,Dt=$t[zt%$t.length];return{...Wh(Dt,h),name:tt}}}const It={ko:"knockdown",hurt:"hit",whip:"energy-slash",bolt:"beam"},Nt=Er[tt]??Er[It[tt]];return Nt?{...Nt,name:Er[tt]?tt:It[tt]}:null},rt=(tt,nt={})=>tt.mocap?{mocap:tt.mocap,...nt}:{move:tt.name,...nt},ot=S.some((tt,nt)=>_(nt)),G=c??(ot?1.35:1),J=tt=>tt.dur/G,Z=(tt,nt,mt)=>A(S[tt])*(mt??nt?.dx??0)*b[tt],at=(tt,nt,mt,It)=>{I[tt].push({...rt(nt,mt),at:Math.round(It*1e4)/1e4}),P[tt]+=Z(tt,nt,mt.dx)};let D=.3;const H=S.map(()=>.3);for(const tt of k){const nt=tt.by,mt=tt.target;if(z[nt])throw Error(`animatePuppet beats: fighter ${nt} was knocked out (ko) — it cannot act again`);for(const ft of[nt,mt])if(C[ft]&&!z[ft]){const yt=U(_(ft)?"kipup":"getup",ft);at(ft,yt,{duration:J(yt)},Math.max(H[ft],D)),H[ft]=Math.max(H[ft],D)+J(yt),C[ft]=!1}if(D=Math.max(D,H[nt],H[mt]-.25),tt.move==="dash"){const ft=tt.stop!=null?tt.stop*a/b[nt]:El.jab*.85,yt=Math.abs(P[mt]-P[nt])/b[nt],Mt=Math.sign(P[mt]-P[nt])*A(S[nt])||1,Pt=Mt*Math.max(0,yt-ft),Lt={...Er.dash,name:"dash"},Ot=J(Lt);at(nt,Lt,{dx:Pt,duration:Ot},D),K.push({kind:"dash",t:D,dur:Ot,by:nt}),H[nt]=D+Ot,D=H[nt]+tt.pause;continue}if(tt.move==="approach"||tt.move==="teleport"){const ft=tt.stop!=null?tt.stop*a/b[nt]:El.jab*.95,yt=Math.abs(P[mt]-P[nt])/b[nt],Mt=Math.sign(P[mt]-P[nt])*A(S[nt])||1,Pt=Mt*Math.max(0,yt-ft);if(tt.move==="approach"){const Lt=Math.abs(Pt)>300,Ot=U(Lt?"run":"walk",nt);if(Ot?.mocap&&Mt>0){const re=Ot.dx||1,ie=wn(Math.round(Math.abs(Pt)/re),1,8),Xt=Wh(Ot.mocap,h,0,ie),te=Xt.dur*(Lt?1:1.05),oe=Math.max(H[nt],D-te*.8-tt.pause);at(nt,{...Xt,name:Ot.name},{dx:Pt,duration:te,repeat:ie},oe),H[nt]=oe+te,D=Math.max(D,H[nt]+tt.pause);continue}const Wt=Lt?Er.run:Er.walk,Ht=wn(Math.abs(Pt)/(Wt.speed*(Lt?1.3:1.15)),.5,3.5),qt=Math.max(H[nt],D-Ht*.8-tt.pause);at(nt,{...Wt,name:Lt?"run":"walk"},{dx:Pt,distance:Pt*b[nt]/a,duration:Ht},qt),H[nt]=qt+Ht,D=Math.max(D,H[nt]+tt.pause);continue}else{const Lt={...Er.teleport,name:"teleport"},Ot=J(Lt);at(nt,Lt,{dx:Pt,duration:Ot},D),K.push({kind:"teleport",t:D,dur:Ot,by:nt}),H[nt]=D+Ot}D=H[nt]+tt.pause;continue}if(tt.move){const ft=U(tt.move,nt),yt=P[nt]+Z(nt,ft),Mt=wn(yt,a*.08,a*.92),Pt=(ft.dx??0)*(yt===P[nt]?1:(Mt-P[nt])/(yt-P[nt]));at(nt,ft,{dx:Pt,duration:J(ft)},D),H[nt]=D+J(ft),(ft.air||ft.mocap&&tt.move!=="guard"||tt.move==="roll")&&F.push({t:D+J(ft)*.97,by:nt}),D=H[nt]+tt.pause;continue}const It=tt.attack==="beam"||tt.attack==="whip"||tt.attack==="bolt",Nt=["ko","knockdown","launched","hurt"].includes(tt.react)?.85:1,$t=Math.abs(P[mt]-P[nt])/b[nt],zt=It?Math.min($t,El[tt.attack]):El[tt.attack]*(_(nt)?.92:1)*Nt;if(Math.abs($t-zt)>18&&tt.attack!=="flying-kick"&&!(It&&$t>200)){const ft=wn($t-zt,-160,220),yt=U(ft>0?"step-in":"step-out",nt)??Er.step,Mt=yt.mocap?wn(yt.dur*.6,.35,.8)/G:wn(.25+Math.abs(ft)/500,.3,.7)/G;at(nt,yt.name?yt:{...Er.step,name:"step"},{dx:ft,duration:Mt},D),D+=Mt}const Dt=U(tt.attack,nt),ae=J(Dt),we=tt.attack==="flying-kick"?wn($t-150,60,260):void 0;at(nt,Dt,{...we!=null?{dx:we}:{},duration:ae},D);const Oe=(Dt.hits??[.5]).map(ft=>D+ft*ae),Ce=Dt.limbs??(Dt.hits??[.5]).map(()=>Dt.mlimb??Dt.limb??(Dt.prop==="staff"?"staff":"fist"));["beam","energy-slash","whip","bolt"].includes(tt.attack)&&K.push({kind:tt.attack,t:D,dur:ae,hit:Oe[0],by:nt,target:mt,limb:Ce[0],react:tt.react});const Yt=U(tt.react,mt)??Er[tt.react],Ft=Oe[0],Bt=Oe.at(-1),_t=Math.max(J(Yt),Bt-Ft+.45/G),pe=Math.max(H[mt],Ft-(Yt.peak??.3)*_t),ee=tt.react==="parry"&&!Mu(S[mt].character)?"block":tt.react,fe=ee===tt.react?Yt:U(ee,mt),Qo=ee==="knockdown"||ee==="launched"||ee==="ko"||ee==="hurt"?.06:.08,kr=P[mt]+Z(mt,fe),Fr=wn(kr,a*Qo,a*(1-Qo)),Co=(fe.dx??0)*(kr===P[mt]?1:(Fr-P[mt])/(kr-P[mt]));at(mt,fe,{duration:ee===tt.react?_t:Math.max(J(fe),_t),dx:Co,...["ko","knockdown","launched"].includes(ee)?{still:!0}:{}},pe),(ee==="knockdown"||ee==="launched"||ee==="ko")&&(C[mt]=!0,F.push({t:pe+_t*.97,by:mt})),ee==="ko"&&(z[mt]=!0),ee==="roll"&&F.push({t:pe+_t*.9,by:mt}),tt.attack==="sweep"&&F.push({t:Oe[0],by:nt,at:"foot"});const qe=ft=>ee==="dodge"||ee==="roll"?"dodge":ee==="block"?"block":ee==="parry"?"clash":ft===Oe.length-1?ee:"hit";Oe.forEach((ft,yt)=>N.push({t:ft,by:nt,target:mt,attack:tt.attack,j:yt,limb:Ce[yt],kind:qe(yt)})),H[nt]=D+ae,H[mt]=pe+_t,D=Math.max(H[nt],H[mt])+tt.pause;const xo=(P[0]+P[1])/2,W=a/2-xo;if(x===2&&Math.abs(W)>a*.1){const ft=.45/G;for(const yt of[0,1])C[yt]||at(yt,{...Er.step,name:"step"},{dx:W*A(S[yt])/b[yt],duration:ft},D);H[0]=H[1]=D+ft,D+=ft}}const ut=Math.max(...H)+.6,gt=ot&&r?N.map(tt=>({t:tt.t,h:IS[tt.kind]??0})).filter(tt=>tt.h>0).sort((tt,nt)=>tt.t-nt.t):[],xt=tt=>tt+gt.filter(nt=>nt.t<tt-1e-9).reduce((nt,mt)=>nt+mt.h,0),u=tt=>{const nt=tt/o;let mt=0;for(const It of gt){const Nt=It.t+mt;if(nt<Nt)return nt-mt;if(nt<Nt+It.h)return It.t;mt+=It.h}return nt-mt},st=Math.min($,Math.round((ut+gt.reduce((tt,nt)=>tt+nt.h,0))*o));for(const tt of N)tt.real=xt(tt.t);const V=tt=>{const nt=tt/o;let mt=0,It=0;for(const Nt of N){const $t=(nt-Nt.real)/.3,zt=r?SS[Nt.kind]??0:0;if($t>=0&&$t<1&&zt){const Dt=(Math.round($t*o*.3)%2?-1:1)*zt*(1-$t);mt+=Dt,It+=Dt*.6}}return[mt,It*a/i]},d=tt=>{if(!h)return null;const nt=t[tt].idle??(S[tt].character==="stick-hero"?"guard":"relaxed");return nt==="none"?null:nt==="relaxed"?"relaxed":g0.guard.find(mt=>h[mt])??null};I.forEach(tt=>{tt.length||tt.push({move:"guard",at:0,duration:.3})});const w=S.map((tt,nt)=>{const mt=d(nt);return Ag({...tt,size:tt.size,fps:o,actions:I[nt],W:a,H:i,shake:V,total:ut,stick:_(nt),clock:{n:st,at:u},mocap:h,toon:m,law:y,maxFrames:$,...mt?{idle:mt}:{}})}),T=zS(w,N,{fps:o}),j=w.map(tt=>({track:tt}));for(const tt of N){const nt=Math.min(w[tt.by].frames.length-1,Math.round(tt.real*o)),mt=w[tt.by].frames[nt],It=mt?Xh(mt.J,tt.limb)??mt.J.haF:null;tt.at=It?ji(w[tt.by],nt,It):null}const O=tt=>tt.frames.map((nt,mt)=>{const It={};for(const Nt of["fist","back","foot","staff","head","chest",...Object.keys(nt.J.sides??{})]){const $t=Xh(nt.J,Nt);$t&&(It[Nt]=ji(tt,mt,$t))}return It});j.forEach((tt,nt)=>{tt.ends=O(w[nt]),tt.frames=w[nt].frames});const L=r?N.filter(tt=>tt.at&&tt.kind!=="dodge").map(tt=>({start:Math.round(tt.real*o)/o,frames:RS(tt,{fps:o,accent:n,W:a,H:i,size:S[tt.by].size})})):[],B=r?F.map(tt=>{const nt=Math.min(j[tt.by].ends.length-1,Math.round(xt(tt.t)*o)),mt=j[tt.by].ends[nt],It=S[tt.by].ground,Nt=w[tt.by].frames[nt],$t=tt.at==="foot"&&mt?.foot?mt.foot[0]:Nt?ji(w[tt.by],nt,[(Nt.J.anF[0]+Nt.J.anB[0])/2,0])[0]:S[tt.by].x;return{start:Math.round(xt(tt.t)*o)/o,frames:DS($t,It,{fps:o,W:a,H:i,size:S[tt.by].size,color:p})}}):[],Q=[...r?K.map(tt=>FS(tt,{actors:j,fps:o,W:a,H:i,realOf:xt,color:f,size:S[tt.by].size})).filter(Boolean):[],...L,...B],et=s??(ot?"follow":"fixed"),lt=Math.max(...S.map(tt=>tt.ground)),Y=et==="follow"||et==="director"?OS(w,N,{fps:o,W:a,H:i,n:st,fx:r,ground:lt}):null,dt=et==="director"?LS(Y,w,N,{fps:o,n:st,ground:lt}):Y;if(dt){for(const tt of w)tt.cam=dt;for(const tt of Q){const nt=Math.round(tt.start*o);tt.frames=tt.frames.map((mt,It)=>NS(mt,dt[Math.min(nt+It,dt.length-1)],a,i))}}j.forEach((tt,nt)=>{tt.frames=Hk(w[nt]).frames});const bt=w.map((tt,nt)=>Uk(tt,T[nt],`fighter ${nt}: `));return{actors:j,fx:Q,impacts:N.map(({real:tt,kind:nt,at:mt})=>({t:Math.round(tt*100)/100,kind:nt,at:mt})),duration:st/o,camera:dt,tracks:w,reports:bt}}function OS(t,e,{fps:o,W:r,H:n,n:a,fx:i,ground:l}){const p=k=>{let b=1/0,A=1/0,I=-1/0,P=-1/0;for(const C of t){const z=Math.min(k,C.frames.length-1),N=C.frames[z];if(!N)continue;const F=N.J,K=26*C.k/C.H,_=[F.head,F.neck,F.pelvis,F.haF,F.haB,F.anF,F.anB,F.knF,F.knB,...F.weapon?[F.weapon.a,F.weapon.b]:[]];for(const q of _){if(!q)continue;const U=ji(C,z,q);b=Math.min(b,U[0]-K*C.H/C.W),I=Math.max(I,U[0]+K*C.H/C.W),A=Math.min(A,U[1]-K),P=Math.max(P,U[1]+K*.4)}}return Number.isFinite(b)?[b,A,I,P]:[.3,.3,.7,.9]},c=k=>{const[b,A,I,P]=p(k),C=I-b+.08,z=P-A+.08,N=wn(Math.min(.74/C,.72/z),1,1.8);return[(b+I)/2,Math.min((A+P)/2,l-.32/N),N]};let[s,h,f]=c(0),m=0,y=0,$=0;const x=[],E=1/o,v=6.5,S=3.2;for(let k=0;k<a;k++){const[b,A,I]=c(k);for(let N=0;N<2;N++){const F=E/2;m+=(v*v*(b-s)-2*v*m)*F,s+=m*F,y+=(v*v*(A-h)-2*v*y)*F,h+=y*F,$+=(S*S*(I-f)-2*S*$)*F,f+=$*F}let P=0,C=0;i&&e.forEach((N,F)=>{const K=(k/o-N.real)/.45;if(K<0||K>=1)return;const[_,q]=AS[N.kind]??[0,0];P+=_*(1-K)**2,C+=(F%2?-1:1)*q*Math.sin(Math.PI*Math.min(1,K*1.6))*(1-K)});const z=Math.min(2,f*(1+P));x.push({cx:Math.round(s*1e4)/1e4,cy:Math.round(h*1e4)/1e4,z:Math.round(z*1e4)/1e4,r:Math.round(C*100)/100})}return x}const PS={jab:"head",cross:"head",combo:["head","chest","head"],uppercut:"head","front-kick":"chest",roundhouse:"head","spin-kick":"head","flying-kick":"head",sweep:"shin",thrust:"chest",smash:"head","staff-spin":"chest",slash:"chest","energy-slash":"chest"};function zS(t,e,{fps:o}){const r=t.map(()=>[]),n=hp.reach.window;for(const a of e){const i=PS[a.attack];if(!i||a.kind==="dodge")continue;const l=t[a.by],p=t[a.target];if(!l||!p)continue;const c=a.kind==="block"||a.kind==="clash"?"guard":Array.isArray(i)?i[a.j%i.length]:i,s=C=>z=>{const N=p.frames[Math.min(z,p.frames.length-1)].J,F=C==="guard"?N.haF:C==="shin"?Hl(N.knF,N.anF,.6):C==="chest"?Hl(N.neck,N.pelvis,.3):C==="belly"?Hl(N.neck,N.pelvis,.7):N.head;return ji(p,Math.min(z,p.frames.length-1),F)},h=Math.min(l.frames.length-1,Math.round(a.real*o)),f=l.frames[h].J,m=Yk(f,a.limb),y=Object.values(qk).find(C=>C[2]===m),$=y?f[y[0]]:m==="weapon"?f.weapon.grip:f.pelvis,x=Zk(f,a.limb)*hp.reach.stretch*.97,E=C=>{const z=fp(l,h,C(h)),N=z[0]-$[0],F=z[1]-$[1];if(Math.hypot(N,F)<=x)return{lunge:0,left:0};const K=Math.abs(F)<x?Math.abs(N)-Math.sqrt(x*x-F*F):Math.abs(N),_=Math.min(hp.reach.glide,Math.max(0,K));return{lunge:Math.sign(N)*_,left:Math.max(0,Math.hypot(Math.abs(N)-_,F)-x)}},v=c==="guard"||c==="shin"?[c]:c==="head"?["head","chest","belly"]:[c,"belly"];let S=v[0],k=1/0;for(const C of v){const z=E(s(C));if(z.left<=1){S=C;break}z.left<k&&(k=z.left,S=C)}const b=s(S),A=E(b).lunge;for(let C=0;C<l.frames.length;C++){const z=l.frames[C],N=z.tt-a.t;if(N<-.3||N>.5)continue;let F=z.J;if(A){const _=N<=0?Hh((N+.25)/.25):1-Hh((N-.1)/.35);if(_>0){const q={};for(const[U,rt]of Object.entries(F)){if(U==="sides"){q.sides=rt;continue}if(U==="weapon"){q.weapon={...rt,a:[rt.a[0]+A*_,rt.a[1]],b:[rt.b[0]+A*_,rt.b[1]],grip:[rt.grip[0]+A*_,rt.grip[1]]};continue}q[U]=[rt[0]+A*_,rt[1]]}F=Jk(q,F,{planted:Qk(F)})}}const K=tx(N,n);K>0&&(F=ex(F,a.limb,fp(l,C,b(C)),K)),z.J=F}const I=ox(l.frames[h].J,a.limb),P=fp(l,h,b(h));r[a.by].push({t:a.real,limb:a.limb,miss:I?Math.hypot(I[0]-P[0],I[1]-P[1])/300:1})}return r}const Hl=(t,e,o)=>[t[0]+(e[0]-t[0])*o,t[1]+(e[1]-t[1])*o];function LS(t,e,o,{fps:r,n,ground:a}){const i=o.map((s,h)=>({time:s.real,im:s,result:s.kind==="dodge"?"miss":s.kind==="block"||s.kind==="clash"?"blocked":"head",last:h===o.length-1&&["ko","knockdown","launched"].includes(s.kind)})),l=vS(i,0,n/r,ap),p=[],c=(s,h,f)=>{const m=e[s],y=Math.min(h,m.frames.length-1),$=m.frames[y].J;return ji(m,y,Hl($.neck,$.pelvis,.35))};for(let s=0;s<n;s++){const h=s/r,f=l.find(v=>h>=v.from-1e-9&&h<v.to)??l.at(-1),m=t[Math.min(s,t.length-1)];if(!f||f.kind==="wide"||!f.beat){p.push(m);continue}const y=f.beat.im,$=Math.round(f.from*r),x=(s-$)/Math.max(1,Math.round((f.to-f.from)*r));let E;if(f.kind==="insert"){const v=y.at??c(y.target,$);E={cx:v[0],cy:Math.min(v[1],a-.2),z:2.3*(1+.04*x),r:m.r}}else if(f.kind==="reaction"){const v=c(y.target,$);E={cx:v[0],cy:Math.min(v[1],a-.27),z:1.75*(1+.03*x),r:0}}else E={...m,z:Math.max(1,m.z*.92),cy:Math.min(m.cy+.03,a-.3),r:0};p.push({cx:Math.round(E.cx*1e4)/1e4,cy:Math.round(E.cy*1e4)/1e4,z:Math.round(E.z*1e4)/1e4,r:Math.round((E.r??0)*100)/100})}return p}function y0(t,e,o,r){const n=e.r*Math.PI/180,a=Math.cos(n),i=Math.sin(n),l=(t[0]-e.cx)*o,p=(t[1]-e.cy)*r;return[Math.round((.5+(l*a-p*i)*e.z/o)*1e4)/1e4,Math.round((.5+(l*i+p*a)*e.z/r)*1e4)/1e4]}function NS(t,e,o,r){return{...t,parts:t.parts.map(n=>n.loops?{...n,loops:n.loops.map(a=>a.map(i=>y0(i,e,o,r)))}:n.points?{...n,points:n.points.map(a=>y0(a,e,o,r))}:n)}}const Li=(t,e,o,r,n=14)=>Array.from({length:n},(a,i)=>{const l=i/n*2*Math.PI;return[t[0]+Math.cos(l)*e*r/o,t[1]+Math.sin(l)*e]});function on(t,e,o,r,n,a=1){const i=[],l=p=>Math.max(.02,Math.round(Math.min(1,p)*100)/100);for(const[p,c]of[[3.2,.08],[2.2,.14],[1.5,.24]])i.push({points:Li(t,e*p,r,n),fill:o,line:!1,opacity:l(c*a)});return i.push({points:Li(t,e,r,n),fill:o,line:!1,...a<1?{opacity:l(a)}:{}},{points:Li(t,e*.55,r,n,10),fill:"#ffffff",line:!1,...a<1?{opacity:l(a)}:{}}),i}function b0(t,e,o,r,n,a){const i=e[0]-t[0],l=(e[1]-t[1])*a/n,p=Math.hypot(i,l)||1,c=-l/p,s=i/p,h=(f,m,y)=>{const $=o*f;return{points:[[t[0]+c*$*a/n,t[1]+s*$],[e[0]+c*$*a/n,e[1]+s*$],[e[0]-c*$*a/n,e[1]-s*$],[t[0]-c*$*a/n,t[1]-s*$]],fill:m,line:!1,smooth:!1,...y<1?{opacity:y}:{}}};return[h(3.4,r,.1),h(2.2,r,.18),h(1.3,r,.4),h(.8,r,1),h(.32,"#ffffff",1)]}function FS(t,{actors:e,fps:o,W:r,H:n,realOf:a,color:i,size:l}){const p=(f,m,y)=>{const $=e[f].ends,x=$[Math.max(0,Math.min($.length-1,m))];return x?.[y]??x?.fist??null},c=l*.06,s=[],h=(f,m=Math.round(o*.55))=>{const y=[];for(let $=0;$<=m;$++){const x=f+$,E=$/m,v=p(t.target,x,"chest")||p(t.target,x,"head");if(!v){y.push({parts:[{points:[[0,0],[0,0],[0,0]],fill:i,line:!1,opacity:.02}]});continue}const S=[];E<.25&&S.push(...on(v,c*(2.6-E*4),"#ffffff",r,n,1-E*3)),S.push(...on(v,c*(1.2+E*1.4),i,r,n,(1-E)*.9));const k=c*(1.2+E*5),b=k-c*.5*(1-E);S.push({points:[...Li(v,k,r,n,24),...Li(v,b,r,n,24).reverse()],fill:i,line:!1,eo:!0,opacity:Math.max(.02,Math.round((1-E)*.8*100)/100)});for(let A=0;A<7;A++){const I=A*2.4+.6,P=c*(1.5+E*6)*(.7+.3*Math.sin(A*3.7)),C=[v[0]+Math.cos(I)*P*n/r,v[1]+Math.sin(I)*P];S.push({points:Li(C,c*.18*(1-E*.6),r,n,6),fill:"#1a1a1a",line:!1,...E>.6?{opacity:Math.max(.02,Math.round((1-E)*2.5*100)/100)}:{}})}y.push({parts:S})}return y};if(t.kind==="beam"){const f=Math.round(a(t.t+t.dur*.12)*o),m=Math.round(a(t.hit)*o),y=m+Math.round(o*.45);for(let x=f;x<=y;x++){const E=p(t.by,x,t.limb)||p(t.by,x,"back"),v=p(t.target,x,"head")||p(t.target,x,"chest"),S=[];if(E){if(x<m){const k=(x-f)/Math.max(1,m-f);S.push(...on(E,c*(.4+k*1.1),i,r,n,.6+k))}else{const k=(x-m)/Math.max(1,y-m),b=1-Math.max(0,k-.6)/.4,A=1+.25*Math.sin(x*2.3);v&&S.push(...b0(E,v,c*.55*A*b,i,r,n)),S.push(...on(E,c*1.2*b,i,r,n,b)),v&&S.push(...on(v,c*(1.4+k*.8)*b,i,r,n,b))}s.push({parts:S})}}const $=h(m);for(let x=0;x<$.length;x++){const E=m-f+x;s[E]?s[E]={parts:[...s[E].parts,...$[x].parts]}:s.push($[x])}return s.length?{start:Math.round(f)/o,frames:s}:null}if(t.kind==="energy-slash"){const f=Math.round(a(t.hit-.22)*o),m=Math.round(a(t.hit+.06)*o),y=m+Math.round(o*.3),$=[];for(let x=f;x<=m;x++){const E=p(t.by,x,t.limb);E&&$.push(E)}if($.length<3)return null;for(let x=f;x<=y;x++){const E=Math.min($.length,x-f+1),v=$.slice(0,E),S=x>m?1-(x-m)/(y-m+1):1,k=[];if(v.length>=2)for(const[b,A,I]of[[2.4,.18,i],[1.4,.4,i],[.7,1,i],[.28,1,"#ffffff"]]){const P=[],C=[],z=v.length-1;v.forEach((N,F)=>{const K=v[Math.max(0,F-1)],_=v[Math.min(z,F+1)],q=_[0]-K[0],U=(_[1]-K[1])*n/r,rt=Math.hypot(q,U)||1,ot=c*b*Math.sin(Math.PI*Math.min(1,(F+.5)/(z+.5)));P.push([N[0]-U/rt*ot*n/r,N[1]+q/rt*ot]),C.push([N[0]+U/rt*ot*n/r,N[1]-q/rt*ot])}),k.push({points:[...P,...C.reverse()],fill:I,line:!1,opacity:Math.max(.02,Math.round(A*S*100)/100)})}s.push({parts:k.length?k:[{points:[[0,0],[0,0],[0,0]],fill:i,line:!1,opacity:.02}]})}return{start:f/o,frames:s}}if(t.kind==="whip"){const f=Math.round(a(t.hit-.2)*o),m=Math.round(a(t.hit)*o),y=m+Math.round(o*.3);for(let x=f;x<=y;x++){const E=p(t.by,x,"chest"),v=p(t.target,x,"chest"),S=[];if(E&&v){const k=x<=m?(x-f)/Math.max(1,m-f):1-(x-m)/Math.max(1,y-m);for(let b=0;b<3;b++){const A=[-.9,.5,1.3][b],I=Math.hypot((v[0]-E[0])*r/n,v[1]-E[1]),P=[(E[0]+v[0])/2,(E[1]+v[1])/2-A*I*.22],C=16,z=[];for(let N=0;N<=C*k;N++){const F=N/C,K=1-F;z.push([K*K*E[0]+2*K*F*P[0]+F*F*v[0],K*K*E[1]+2*K*F*P[1]+F*F*v[1]+Math.sin(F*9+x*.7+b)*c*.15])}if(!(z.length<3)){for(const[N,F,K]of[[2,.16,i],[1.1,.45,i],[.5,1,i]]){const _=[],q=[],U=z.length-1;z.forEach((rt,ot)=>{const G=z[Math.max(0,ot-1)],J=z[Math.min(U,ot+1)],Z=J[0]-G[0],at=(J[1]-G[1])*n/r,D=Math.hypot(Z,at)||1,H=c*N*(.35+.65*ot/U);_.push([rt[0]-at/D*H*n/r,rt[1]+Z/D*H]),q.push([rt[0]+at/D*H*n/r,rt[1]-Z/D*H])}),S.push({points:[..._,...q.reverse()],fill:K,line:!1,...F<1?{opacity:F}:{}})}S.push(...on(z.at(-1),c*.55,i,r,n,1.2))}}}s.push({parts:S.length?S:[{points:[[0,0],[0,0],[0,0]],fill:i,line:!1,opacity:.02}]})}const $=h(m);for(let x=0;x<$.length;x++){const E=m-f+x;s[E]?s[E]={parts:[...s[E].parts,...$[x].parts]}:s.push($[x])}return{start:f/o,frames:s}}if(t.kind==="bolt"){const f=Math.round(a(t.hit-.32)*o),m=Math.round(a(t.hit)*o);for(let y=f;y<m;y++){const $=p(t.by,f,t.limb)||p(t.by,f,"chest"),x=p(t.target,m,"chest"),E=[];if($&&x){const v=(y-f)/Math.max(1,m-f),S=[$[0]+(x[0]-$[0])*v,$[1]+(x[1]-$[1])*v],k=Math.max(0,v-.45);for(const b of[0,Math.PI]){const A=[];for(let P=0;P<=14;P++){const C=k+(v-k)*P/14,z=[$[0]+(x[0]-$[0])*C,$[1]+(x[1]-$[1])*C],N=Math.sin(C*22+b+y*.4)*c*.5*(P/14);A.push([z[0],z[1]+N])}for(const[P,C,z]of[[1,.3,i],[.4,1,i],[.15,1,"#ffffff"]]){const N=[],F=[],K=A.length-1;A.forEach((_,q)=>{const U=A[Math.max(0,q-1)],rt=A[Math.min(K,q+1)],ot=rt[0]-U[0],G=(rt[1]-U[1])*n/r,J=Math.hypot(ot,G)||1,Z=c*P*(.2+.8*q/K);N.push([_[0]-G/J*Z*n/r,_[1]+ot/J*Z]),F.push([_[0]+G/J*Z*n/r,_[1]-ot/J*Z])}),E.push({points:[...N,...F.reverse()],fill:z,line:!1,...C<1?{opacity:C}:{}})}}E.push(...on(S,c*.9,i,r,n,1.3))}s.push({parts:E.length?E:[{points:[[0,0],[0,0],[0,0]],fill:i,line:!1,opacity:.02}]})}return{start:f/o,frames:[...s,...h(m)]}}if(t.kind==="dash"){const f=Math.round(a(t.t)*o),m=Math.round(a(t.t+t.dur)*o),y=m+Math.round(o*.35),$=p(t.by,f,"chest");for(let x=f;x<=y;x++){const E=p(t.by,Math.min(x,m),"chest"),v=[];if($&&E){const S=x>m?1-(x-m)/(y-m+1):1,k=[$[0]+(E[0]-$[0])*Math.max(0,(x-m)/(y-m+1)),$[1]];v.push(...b0(k,E,c*1.5*S,i,r,n).map((b,A)=>A===4?{...b,fill:"#f3dcff"}:b)),v.push(...on(E,c*1.6*S,i,r,n,S))}s.push({parts:v.length?v:[{points:[[0,0],[0,0],[0,0]],fill:i,line:!1,opacity:.02}]})}return{start:f/o,frames:s}}if(t.kind==="teleport"){const f=Math.round(a(t.t)*o),m=Math.round(a(t.t+t.dur*.5)*o),y=m+Math.round(o*.3),$=p(t.by,f,"chest"),x=p(t.by,Math.min(y,m+2),"chest");for(let E=f;E<=y;E++){const v=[],S=(E-f)/Math.max(1,m-f),k=(E-m)/Math.max(1,y-m);$&&E<=m+3&&v.push(...on($,c*(1+S*2.2)*(E>m?.5:1),i,r,n,1-Math.max(0,S-.7))),x&&E>=m-1&&v.push(...on(x,c*(2.6-k*1.8),i,r,n,1-k*.8)),s.push({parts:v.length?v:[{points:[[0,0],[0,0],[0,0]],fill:i,line:!1,opacity:.02}]})}return{start:f/o,frames:s}}return null}function RS(t,{fps:e,accent:o,W:r,H:n,size:a}){const i=Math.max(3,Math.round(e*.25)),[l,p]=t.at,c=a*.16*(t.kind==="knockdown"||t.kind==="launched"?1.4:t.kind==="clash"?1.2:t.kind==="block"?.7:1),s=t.kind==="block",h=t.kind==="clash",f=s||h?"#e8f6ff":"#fffbe8",m=s?"#8fd3ff":h?"#ffffff":o,y=(x,E)=>[l+Math.cos(E)*x*n/r,p+Math.sin(E)*x],$=[];for(let x=0;x<i;x++){const E=x/(i-1),v=c*(.55+E*.9),S=[],k=s?8:12;if(x<i-1){const b=[];for(let A=0;A<k*2;A++){const I=A/(k*2)*2*Math.PI+(A%4===1?.08:0);b.push(y(A%2?v*.38:v*(A%3===0?1.1:.85),I))}S.push({points:b,fill:m,line:!1}),S.push({points:Array.from({length:10},(A,I)=>y(v*.28,I/10*2*Math.PI)),fill:f,line:!1})}for(let b=0;b<8;b++){const A=b/8*2*Math.PI+.2;S.push({points:[y(v*(.9+E*.5),A),y(v*(1.3+E*.9),A)],fill:null,closed:!1,lw:Math.max(.3,1.4-E)})}$.push({parts:S})}return $}function DS(t,e,{fps:o,W:r,H:n,size:a,color:i}){const l=Math.max(3,Math.round(o*.4)),p=a*.05,c=[];for(let s=0;s<l;s++){const h=s/(l-1),f=[];for(const[m,y]of[[-1,1],[-.45,1.25],[.45,1.25],[1,1]]){const $=p*y*(1-h*.65),x=t+m*p*(1.4+h*2.6)*n/r,E=e-$*.7-h*p*.5;f.push({points:Array.from({length:10},(v,S)=>{const k=S/10*2*Math.PI;return[x+Math.cos(k)*$*n/r,E+Math.sin(k)*$*.75]}),fill:i,line:!1})}c.push({parts:f})}return c}const Sl=t=>Math.round(t*10)/10,Qp=(t,e,o,r,n,a,i=0)=>{const l=[];for(let p=0;p<=n*3;p++){const c=p/(n*3),s=t+(e-t)*c,h=o-r*(.55+.45*Math.sin(c*n*2*Math.PI+i)*Math.cos(c*n*.7*Math.PI+i*2));l.push([s,h])}return[...l,[e,a],[t,a]]},tu=(t,e,o,r=9,n=1)=>Array.from({length:r},(a,i)=>{const l=i/r*2*Math.PI,p=1+.18*Math.sin(i*2.7+n);return[t[0]+Math.cos(l)*e*p,t[1]+Math.sin(l)*o*p*(Math.sin(l)>0?.55:1)]}),fr=(t,e,o,r)=>[[t,e],[o,e],[o,r],[t,r]],jy=Object.freeze({canyon:{vi:"Hẻm núi đỏ (trời xanh)",en:"Red canyon (blue sky)",sky:["#1f86e0","#9ad6ff"],layers:t=>[{p:.18,parts:[...[-.7,-.15,.35,.85,1.35].map((e,o)=>({pts:tu([e,.36+o%2*.06],.26,.11,10,o),fill:o%2?"#d8b4dc":"#c69fd3"})),{pts:Qp(-1.2,2.2,t-.2,.22,7,t+.1,.4),fill:"#b48ac8"}]},{p:.5,parts:[{pts:Qp(-1.3,2.3,t-.06,.12,5,t+.12,1.3),fill:"#8f2f2c"},{pts:Qp(-1.3,2.3,t-.03,.05,9,t+.12,2.1),fill:"#a8413a"}]},{p:1,parts:[{pts:fr(-1.6,t,2.6,t+.9),fill:"#4e3423",smooth:!1},{pts:fr(-1.6,t-.004,2.6,t+.022),fill:"#d9c6a8",smooth:!1},{pts:tu([.5,t+.05],.28,.03,14,3),fill:"#3f2a1c"}]}]},dojo:{vi:"Võ đường gỗ",en:"Wooden dojo",sky:["#e9dcc0","#d8c8a6"],layers:t=>[{p:.45,parts:[...[-1.1,-.6,-.1,.4,.9,1.4,1.9].map(e=>({pts:fr(e-.035,-.4,e+.035,t),fill:"#6b4423",smooth:!1})),{pts:fr(-1.5,.08,2.5,.12),fill:"#5a381c",smooth:!1},...[-.85,-.35,.15,.65,1.15,1.65].map(e=>({pts:fr(e-.17,.2,e+.17,t-.08),fill:"#f3ead6",smooth:!1}))]},{p:1,parts:[{pts:fr(-1.6,t,2.6,t+.9),fill:"#a8743f",smooth:!1},...[0,1,2,3].map(e=>({pts:fr(-1.6,t+.03+e*.05,2.6,t+.034+e*.05),fill:"#8c5d30",smooth:!1})),{pts:fr(-1.6,t-.004,2.6,t+.012),fill:"#c9965c",smooth:!1}]}]},night:{vi:"Sân thượng đêm",en:"Night rooftop",sky:["#070b1f","#2a3466"],layers:t=>[{p:.08,parts:[{pts:tu([.78,.2],.05,.09,14,0),fill:"#f3efd2"}]},{p:.25,parts:[...Array.from({length:14},(e,o)=>{const r=-1.1+o*.24,n=.18+.14*(o*7%5)/4;return{pts:fr(r,t-.08-n,r+.2,t),fill:"#141a36",smooth:!1}})]},{p:.55,parts:[...Array.from({length:9},(e,o)=>{const r=-1.2+o*.42,n=.12+.1*(o*3%4)/3;return{pts:fr(r,t-.02-n,r+.3,t),fill:"#1d2547",smooth:!1}}),...Array.from({length:18},(e,o)=>{const r=-1.12+o*.21,n=t-.1-.05*(o%3);return{pts:fr(r,n,r+.025,n+.03),fill:"#e8c66a",smooth:!1}})]},{p:1,parts:[{pts:fr(-1.6,t,2.6,t+.9),fill:"#10142a",smooth:!1},{pts:fr(-1.6,t-.006,2.6,t+.01),fill:"#3a4470",smooth:!1}]}]}}),dd=Object.freeze(Object.keys(jy));function BS(t,{size:e,camera:o,fps:r,duration:n,ground:a=.9,finish:i,en:l=!1}){const p=jy[t];if(!p)throw Error(`animatePuppet scene: ${dd.join(" | ")}`);const c=Vr(e),s=c.pt([.5,.5]),h=c.k,f=p.layers(a).map((b,A)=>{const I=b.parts.map(P=>{const C=P.pts.map(z=>{const N=c.pt(z);return[N[0]-s[0],N[1]-s[1]]});return{d:P.smooth===!1?"M"+C.map(z=>`${Math.round(z[0])} ${Math.round(z[1])}`).join(" L")+" Z":_i(C,!0),fill:P.fill,line:!1,role:7}});return{p:b.p,it:{id:`d${A+1}`,name:`${l?"Depth":"Lớp"} ${A+1}`,type:"art",params:{parts:I,box:ir(I.map(P=>P.d).join(" ")),outline:!1},pos:[s[0],s[1]],rot:0,scale:[1,1],opacity:1,fill:{type:"color",color:I[0].fill},stroke:null,role:7}}}),[m,y]=e,$={id:"sky",name:l?"Sky":"Bầu trời",type:"rect",params:{w:Sl(m/h*1.6),h:Sl(y/h*1.6),round:0},pos:[s[0],s[1]],rot:0,scale:[1,1],opacity:1,fill:{type:"linear",stops:[[p.sky[0],0],[p.sky[1],1]],angle:90},stroke:null},x=(b,A)=>{const I=1+(A.z-1)*b,P=A.r*Math.PI/180,C=Math.cos(P),z=Math.sin(P),N=c.pt([.5+(A.cx-.5)*b,.5+(A.cy-.5)*b]),F=s[0]-N[0],K=s[1]-N[1];return{x:Sl(s[0]+(F*C-K*z)*I),y:Sl(s[1]+(F*z+K*C)*I),z:Math.round(I*1e4)/1e4,r:Math.round(A.r*100)/100}},E=`${l?"Scene":"Cảnh nền"} · ${l?p.en:p.vi}`;if(!o?.length){const b=f.map(({p:A,it:I})=>({...I,...(()=>{const P=x(A,{cx:.5,cy:.5,z:1,r:0});return{pos:[P.x,P.y]}})()}));return[{shape:i({v:2,size:e,items:[$,...b]},null,{colors:"keep"}),label:E,start:0,duration:n}]}const v=[],S=o.length,k=Math.max(1,Math.round(6*r));for(let b=0;b<S;b+=k){const A=Math.min(S,b+k),I=b/r,P=(A-b)/r,C=Math.min(60,A-b-1)||1,z=[...new Set(Array.from({length:C+1},(F,K)=>Math.min(A-1,b+Math.round(K*(A-1-b)/C))))],N=f.map(({p:F,it:K})=>{const _=z.map(U=>({t:Math.round((U-b)/r*1e4)/1e4,q:x(F,o[U])})),q=U=>_.map(({t:rt,q:ot},G)=>({time:rt,value:U(ot),...G<_.length-1?{ease:"auto"}:{}}));return{...K,pos:[_[0].q.x,_[0].q.y],scale:[_[0].q.z,_[0].q.z],rot:_[0].q.r,keys:{"pos.0":q(U=>U.x),"pos.1":q(U=>U.y),"scale.0":q(U=>U.z),"scale.1":q(U=>U.z),rot:q(U=>U.r)}}});v.push({shape:i({v:2,size:e,items:[$,...N]},null,{colors:"keep"}),label:E,start:I,duration:P})}return v}const Il=/^#[0-9a-fA-F]{6}$/,ms=Number.isFinite,_S=t=>[1,3,5].map(e=>parseInt(t.slice(e,e+2),16)),GS=t=>"#"+t.map(e=>Math.round(Math.max(0,Math.min(255,e))).toString(16).padStart(2,"0")).join(""),Sr=(t,e)=>GS(_S(t).map(o=>e>=0?o+(255-o)*e:o*(1+e))),w0=Object.freeze(["box","stairs","cylinder","plane","panel"]),_c=Object.freeze({iso:[Math.cos(Math.PI/6),.5],dimetric:[2/Math.sqrt(5),1/Math.sqrt(5)]}),Is=Object.freeze({solids:24,steps:24,size:[.002,2]}),As=t=>Math.round(t),KS=(t,e=!0)=>"M"+t.map(o=>`${As(o[0])} ${As(o[1])}`).join(" L")+(e?" Z":"");function VS(t){const e=[...t].sort((a,i)=>a[0]-i[0]||a[1]-i[1]),o=(a,i,l)=>(i[0]-a[0])*(l[1]-a[1])-(i[1]-a[1])*(l[0]-a[0]),r=[],n=[];for(const a of e){for(;r.length>=2&&o(r.at(-2),r.at(-1),a)<=0;)r.pop();r.push(a)}for(const a of e.reverse()){for(;n.length>=2&&o(n.at(-2),n.at(-1),a)<=0;)n.pop();n.push(a)}return r.slice(0,-1).concat(n.slice(0,-1))}function WS(t,e){const o=`drawShape solids[${e}]`;if(!t||typeof t!="object"||Array.isArray(t))throw Error(`${o} must be an object`);const r=t.kind??"box";if(!w0.includes(r))throw Error(`${o}.kind: ${w0.join(" | ")}`);if(!Array.isArray(t.at)||t.at.length!==2||!t.at.every(p=>ms(p)&&p>=-.5&&p<=1.5))throw Error(`${o}.at: [x, y] of its base centre on the ground, 0..1 of the frame`);const[n,a]=Is.size;if(!Array.isArray(t.size)||t.size.length!==3||!t.size.every((p,c)=>ms(p)&&p<=a&&(p>=n||c===2&&r==="plane"&&p>=0||c===1&&r==="panel"&&p>=0)))throw Error(`${o}.size: [w, d, h] as fractions of the frame width (${n}–${a}; a plane's h and a panel's d may be 0)`);if(t.z!=null&&!(ms(t.z)&&t.z>=0&&t.z<=2))throw Error(`${o}.z: how high it stands above the ground (on a desk, a shelf), 0–2 of the frame width`);const i=t.color??"#d8c8bd";if(!Il.test(i))throw Error(`${o}.color: #RRGGBB (its faces are shaded from it)`);if(t.colors!=null&&(typeof t.colors!="object"||Object.entries(t.colors).some(([p,c])=>!["top","left","right"].includes(p)||!Il.test(c))))throw Error(`${o}.colors: {top?, left?, right?: #RRGGBB}`);if(t.steps!=null&&!(Number.isInteger(t.steps)&&t.steps>=2&&t.steps<=Is.steps))throw Error(`${o}.steps: 2–${Is.steps}`);for(const[p,c]of[["rise",["left","right"]],["face",["left","right"]]])if(t[p]!=null&&!c.includes(t[p]))throw Error(`${o}.${p}: ${c.join(" | ")}`);if(t.inset!=null&&!(ms(t.inset)&&t.inset>=0&&t.inset<=.45))throw Error(`${o}.inset: the panel's frame width, 0–0.45 of its size`);if(t.inner!=null&&!Il.test(t.inner))throw Error(`${o}.inner: #RRGGBB (the panel's inside: screen, mirror, window)`);const l=t.shadow;if(l!=null&&typeof l!="boolean"&&(typeof l!="object"||Array.isArray(l)||Object.keys(l).some(p=>!["length","side","color"].includes(p))||l.length!=null&&!(ms(l.length)&&l.length>=0&&l.length<=4)||l.side!=null&&!["left","right"].includes(l.side)||l.color!=null&&!Il.test(l.color)))throw Error(`${o}.shadow: true | false | {length? 0–4 (× its height), side? left|right, color? #RRGGBB}`);return{kind:r,at:[...t.at],z:t.z??0,size:[...t.size],color:i,colors:t.colors??null,steps:t.steps??8,rise:t.rise??"left",face:t.face??"left",inset:t.inset??.08,inner:t.inner??null,shadow:l??!0,name:t.name!=null?String(t.name).slice(0,40):null}}function XS(t,e,{view:o="iso",light:r="left",shadowColor:n="#1e1719"}={}){const[a,i]=_c[o]??_c.iso,l=e.pt(t.at),p=ot=>e.len(ot),[c,s,h]=t.size.map(p),f=p(t.z||0),m=([ot,G,J])=>[l[0]+(ot-G)*a,l[1]+(ot+G)*i-J-f],y=t.colors?.left??t.color,$={top:t.colors?.top??Sr(t.color,.18),lit:y,dark:t.colors?.right??Sr(t.color,-.28)},x=r==="left"?$.lit:$.dark,E=r==="left"?$.dark:$.lit,v=[],S=(ot,G)=>v.push({d:KS(ot),fill:G,line:!1,role:7}),k=t.shadow,b=k===!1?0:typeof k=="object"?k.length??1:1,I=(typeof k=="object"&&k.side?k.side:r==="left"?"right":"left")==="right"?[1,-.35]:[-.35,1],P=t.kind==="plane"?0:(t.kind==="panel",h);if(b>0&&P>0){let ot;if(t.kind==="cylinder"){ot=[];for(let Z=0;Z<16;Z++){const at=Z/16*2*Math.PI;ot.push([Math.cos(at)*c/2,Math.sin(at)*c/2])}}else t.kind==="panel"?ot=t.face==="left"?[[-c/2,0],[c/2,0]]:[[0,-c/2],[0,c/2]]:ot=[[-c/2,-s/2],[c/2,-s/2],[c/2,s/2],[-c/2,s/2]];const G=[I[0]*P*b,I[1]*P*b],J=VS([...ot,...ot.map(Z=>[Z[0]+G[0],Z[1]+G[1]])]);S(J.map(([Z,at])=>m([Z,at,0])),typeof k=="object"&&k.color?k.color:n)}const C=(ot,G,J,Z,at,D,H=$)=>{const ut=[[ot,J,D],[G,J,D],[G,Z,D],[ot,Z,D]].map(m),gt=[[ot,Z,at],[G,Z,at],[G,Z,D],[ot,Z,D]].map(m),xt=[[G,J,at],[G,Z,at],[G,Z,D],[G,J,D]].map(m);D-at>0&&(S(gt,H===$?x:H.left),S(xt,H===$?E:H.right)),S(ut,H.top)};if(t.kind==="box")C(-c/2,c/2,-s/2,s/2,0,h);else if(t.kind==="plane")S([[-c/2,-s/2,h],[c/2,-s/2,h],[c/2,s/2,h],[-c/2,s/2,h]].map(m),$.top);else if(t.kind==="stairs"){const ot=t.steps;for(let G=ot-1;G>=0;G--){const J=h*(G+1)/ot;t.rise==="left"?C(c/2-c*(G+1)/ot,c/2-c*G/ot,-s/2,s/2,0,J):C(-c/2,c/2,s/2-s*(G+1)/ot,s/2-s*G/ot,0,J)}}else if(t.kind==="cylinder"){const G=D=>Array.from({length:24},(H,ut)=>{const gt=ut/24*2*Math.PI;return m([Math.cos(gt)*c/2,Math.sin(gt)*c/2,D])}),J=G(0),Z=G(h),at=(D,H)=>{const ut=[];for(let gt=D;gt<=H;gt++)ut.push(J[gt%24]);for(let gt=H;gt>=D;gt--)ut.push(Z[gt%24]);return ut};h>0&&(S(at(0,24/4),E),S(at(24/4,24/2),x)),S(Z,$.top)}else if(t.kind==="panel"){const ot=(J,Z)=>t.face==="left"?m([J,s/2,Z]):m([s/2,J,Z]),G=(J,Z,at,D)=>[ot(J,at),ot(Z,at),ot(Z,D),ot(J,D)];if(s>0?C(...t.face==="left"?[-c/2,c/2,-s/2,s/2]:[-s/2,s/2,-c/2,c/2],0,h):S(G(-c/2,c/2,0,h),t.face==="left"?x:E),t.inner){const J=Math.min(c,h)*t.inset;S(G(-c/2+J,c/2-J,J,h-J),t.inner)}}const z=v.flatMap(ot=>ot.d.match(/-?\d+(\.\d+)?/g).map(Number)),N=z.filter((ot,G)=>G%2===0),F=z.filter((ot,G)=>G%2===1),K=As((Math.min(...N)+Math.max(...N))/2),_=As((Math.min(...F)+Math.max(...F))/2),q=v.map(ot=>{let G=0;return{...ot,d:ot.d.replace(/-?\d+(\.\d+)?/g,J=>String(As(Number(J)-(G++%2?_:K))))}}),U=N.map(ot=>ot-K),rt=F.map(ot=>ot-_);return{parts:q,pos:[K,_],box:[Math.min(...U),Math.min(...rt),Math.max(...U),Math.max(...rt)]}}const ka=/^#[0-9a-fA-F]{6}$/,oi=Number.isFinite,k0=Object.freeze(["corridor","box","panel","wall-panel"]),Zn=Object.freeze({solids:24,depth:[0,60],repeat:24,fly:[0,40]}),gs=-.55;function Ty(t,e){const o=`drawShape solids[${e}]`;if(!t||typeof t!="object"||Array.isArray(t))throw Error(`${o} must be an object`);const r=t.kind??"box";if(!k0.includes(r))throw Error(`${o}.kind (perspective): ${k0.join(" | ")}`);const n=t.color??"#efe6df";if(!ka.test(n))throw Error(`${o}.color: #RRGGBB`);const a=(l,p,c)=>{if(l==null)return null;if(typeof l!="object"||Array.isArray(l)||Object.entries(l).some(([s,h])=>!p.includes(s)||!ka.test(h)))throw Error(`${o}.${c}: {${p.join(", ")}: #RRGGBB}`);return l};if(((l,p)=>{if(l!=null&&!(oi(l)&&l>=Zn.depth[0]&&l<=Zn.depth[1]))throw Error(`${o}.${p}: 0–${Zn.depth[1]} (0 = the picture plane, 1 = twice as far)`)})(t.depth,"depth"),r==="corridor"){const l=(h,f,m)=>{if(h==null)return null;if(typeof h!="object"||Array.isArray(h))throw Error(`${o}.${m} must be an object`);for(const y of Object.keys(h))if(!f.includes(y))throw Error(`${o}.${m}: ${f.join(", ")}`);return h},p=l(t.carpet,["color","width"],"carpet"),c=l(t.doors,["count","color","inner","height","width"],"doors"),s=l(t.lines,["count","color"],"lines");if(p&&(!ka.test(p.color??"")||p.width!=null&&!(oi(p.width)&&p.width>0&&p.width<=1)))throw Error(`${o}.carpet: {color #RRGGBB, width? 0–1 of the floor}`);if(c&&(!(Number.isInteger(c.count)&&c.count>=1&&c.count<=8)||c.color!=null&&!ka.test(c.color)||c.inner!=null&&!ka.test(c.inner)))throw Error(`${o}.doors: {count 1–8 per wall, color?, inner?, height? 0–1, width? depth units}`);if(s&&(!(Number.isInteger(s.count)&&s.count>=1&&s.count<=16)||s.color!=null&&!ka.test(s.color)))throw Error(`${o}.lines: {count 1–16, color?} (floor lines across)`);return{kind:r,color:n,colors:a(t.colors,["floor","ceiling","left","right","back"],"colors"),depth:t.depth??6,carpet:p,doors:c,lines:s}}if(!Array.isArray(t.at)||t.at.length!==2||!t.at.every(l=>oi(l)&&l>=-1&&l<=2))throw Error(`${o}.at: [x, y] of its front bottom centre on the picture plane (0..1 of the frame)`);if(!Array.isArray(t.size)||t.size.length!==3||!t.size.every((l,p)=>oi(l)&&l>=0&&l<=(p===1?60:3)))throw Error(`${o}.size: [w, d, h] — w, h fractions of the frame width, d in depth units`);if(t.repeat!=null&&(typeof t.repeat!="object"||!(Number.isInteger(t.repeat.count)&&t.repeat.count>=2&&t.repeat.count<=Zn.repeat)||!(oi(t.repeat.step)&&t.repeat.step>0&&t.repeat.step<=20)||t.repeat.dx!=null&&!oi(t.repeat.dx)))throw Error(`${o}.repeat: {count 2–${Zn.repeat}, step (depth units), dx? (frame width per copy)}`);if(t.inner!=null&&!ka.test(t.inner))throw Error(`${o}.inner: #RRGGBB`);if(r==="wall-panel"&&!["left","right"].includes(t.side))throw Error(`${o}.side: left | right (the wall it hangs on)`);return{kind:r,color:n,colors:a(t.colors,["front","top","side","bottom"],"colors"),at:[...t.at],size:[...t.size],depth:t.depth??0,repeat:t.repeat??null,inner:t.inner??null,inset:t.inset??.1,side:t.side??null,name:t.name!=null?String(t.name).slice(0,40):null}}function HS(t,{vanish:e=[.5,.45],cam:o=0,W:r=1280,H:n=720}={}){const a=[e[0]*r,e[1]*n],i=[],l=(h,f,m)=>{const y=1/(1+Math.max(gs,m-o));return[(a[0]+(h-a[0])*y)/r,(a[1]+(f-a[1])*y)/n]},p=(h,f)=>i.push({pts:h.map(m=>[Math.round(m[0]*1e4)/1e4,Math.round(m[1]*1e4)/1e4]),fill:f}),c=h=>Math.max(h,o+gs);if(t.kind==="corridor"){const h=t.colors||{},f=t.depth,m=c(0),y=f,$=h.floor??Sr(t.color,-.12),x=h.ceiling??Sr(t.color,.1),E=h.left??t.color,v=h.right??Sr(t.color,-.06),S=h.back??Sr(t.color,-.2);if(y<=o+gs)return i;if(p([l(0,0,m),l(r,0,m),l(r,0,y),l(0,0,y)],x),p([l(0,n,m),l(r,n,m),l(r,n,y),l(0,n,y)],$),p([l(0,0,m),l(0,0,y),l(0,n,y),l(0,n,m)],E),p([l(r,0,m),l(r,0,y),l(r,n,y),l(r,n,m)],v),p([l(0,0,y),l(r,0,y),l(r,n,y),l(0,n,y)],S),t.lines){const k=t.lines.count;for(let b=1;b<=k;b++){const A=f*b/(k+1);if(A<=m)continue;const I=.006*r;p([l(0,n,A),l(r,n,A),l(r,n,A+I/r*f*.4),l(0,n,A+I/r*f*.4)],t.lines.color??Sr($,-.1))}}if(t.carpet){const k=(t.carpet.width??.3)*r/2;p([l(r/2-k,n,m),l(r/2+k,n,m),l(r/2+k,n,y),l(r/2-k,n,y)],t.carpet.color)}if(t.doors){const k=t.doors.count,b=(t.doors.height??.62)*n,A=t.doors.width??Math.min(.55,f/(k*2.2)),I=t.doors.color??Sr(E,-.25),P=t.doors.inner??Sr(E,-.45);for(let C=k-1;C>=0;C--){const z=f*(C+.35)/k,N=z+A;if(N<=o+gs)continue;const F=c(z);for(const K of[0,r]){p([l(K,n-b,F),l(K,n-b,N),l(K,n,N),l(K,n,F)],I);const _=A*.14;N-_>F+_&&p([l(K,n-b*.9,F+_),l(K,n-b*.9,N-_),l(K,n,N-_),l(K,n,F+_)],P)}}}return i}const s=t.repeat?Array.from({length:t.repeat.count},(h,f)=>f):[0];for(const h of s.reverse()){const f=t.depth+(t.repeat?t.repeat.step*h:0),m=(t.repeat?.dx??0)*r*h,[y,$]=[t.at[0]*r+m,t.at[1]*n],x=t.size[0]*r,E=t.size[1],v=t.size[2]*r,S=y-x/2,k=y+x/2,b=$,A=$-v,I=f+E;if(I<=o+gs)continue;const P=c(f),C=t.colors||{},z=C.front??t.color,N=C.top??Sr(t.color,.16),F=C.side??Sr(t.color,-.22),K=C.bottom??Sr(t.color,-.35);if(t.kind==="wall-panel"){if(p([l(y,A,P),l(y,A,I),l(y,b,I),l(y,b,P)],z),t.inner){const _=(I-P)*t.inset,q=v*t.inset;p([l(y,A+q,P+_),l(y,A+q,I-_),l(y,b-q,I-_),l(y,b-q,P+_)],t.inner)}continue}if(E>0&&(A>a[1]&&p([l(S,A,P),l(k,A,P),l(k,A,I),l(S,A,I)],N),b<a[1]&&p([l(S,b,P),l(k,b,P),l(k,b,I),l(S,b,I)],K),S>a[0]&&p([l(S,A,P),l(S,A,I),l(S,b,I),l(S,b,P)],F),k<a[0]&&p([l(k,A,P),l(k,A,I),l(k,b,I),l(k,b,P)],F)),p([l(S,A,P),l(k,A,P),l(k,b,P),l(S,b,P)],z),t.kind==="panel"&&t.inner){const _=Math.min(x,v)*t.inset;p([l(S+_,A+_,P),l(k-_,A+_,P),l(k-_,b-_,P),l(S+_,b-_,P)],t.inner)}}return i}function Oy(t,e){return t.map((r,n)=>({s:r,i:n})).sort((r,n)=>(n.s.kind==="corridor")-(r.s.kind==="corridor")||n.s.depth+(n.s.repeat?n.s.repeat.step*(n.s.repeat.count-1):0)-(r.s.depth+(r.s.repeat?r.s.repeat.step*(r.s.repeat.count-1):0))||r.i-n.i).map(({s:r})=>({s:r,parts:HS(r,e)}))}const eu=Object.freeze({size:[6,16],size0:10,palette:[2,16],sampleFrames:16,parts:64,points:900,partPoints:200,backdropPoints:4e3}),US=Object.freeze(["plate","none","keep"]),YS=/^#[0-9a-f]{6}$/i;function qS(t={}){if(t.colors!=null)throw Error("rotoscope look flat: give palette (2–16 #RRGGBB) or paletteSize (6–16), not colors");if(t.effects!=null)throw Error("rotoscope look flat: effects are for the stick-figure looks (flashes, smoke… are traced as regions here)");let e=null;if(t.palette!=null){if(!Array.isArray(t.palette)||t.palette.length<2||t.palette.length>16||t.palette.some(r=>!YS.test(String(r))))throw Error("rotoscope palette: 2–16 colours [#RRGGBB…] — every region is filled with the nearest one");e=[...new Set(t.palette.map(r=>String(r).toLowerCase()))]}const o=t.paletteSize??eu.size0;if(!(Number.isInteger(o)&&o>=eu.size[0]&&o<=eu.size[1]))throw Error("rotoscope paletteSize: 6–16 colours picked from the video for the whole clip");if(t.boil!=null&&typeof t.boil!="boolean")throw Error("rotoscope boil: true (every outline redrawn afresh, a hand-drawn wobble) | false (steady, default)");return{palette:e,size:o,boil:t.boil===!0}}const ou=Object.freeze({seconds:30,fps:[8,12,24,30],width:640,plateFrames:48,parts:64,points:100}),x0=Object.freeze(["flash","glow","smoke","shadow","blood","cloth","eyes"]),ru=Object.freeze(["dark","mid","cloth","blood"]),hd=Object.freeze({keep:{vi:"Giữ màu gốc",en:"Keep the colours",colors:{dark:"#1b1b1b",mid:"#5c5c5c",cloth:"#f4f4f4",blood:"#8a1020"},eyes:!1},ninja:{vi:"Ninja đỏ – ninja đen",en:"Red ninja vs black ninjas",colors:{dark:"#141414",mid:"#c3172a",cloth:"#8e1020",blood:"#7a0d16"},eyes:!0},hero:{vi:"Anh hùng xanh – bóng đen",en:"Blue hero vs shadows",colors:{dark:"#16161c",mid:"#1f5fd6",cloth:"#f2c230",blood:"#7a0d16"},eyes:!0},gold:{vi:"Võ sĩ vàng – bóng đen",en:"Gold fighter vs shadows",colors:{dark:"#121212",mid:"#d99a1e",cloth:"#b8201c",blood:"#7a0d16"},eyes:!0},ink:{vi:"Mực tàu",en:"Ink silhouettes",colors:{dark:"#101010",mid:"#2b2b2b",cloth:"#9a1b1b",blood:"#5a0a10"},eyes:!1},flat:{vi:"Màu phẳng (vector)",en:"Flat colours (vector)",colors:{dark:"#2d5f8a",mid:"#f2a65a",cloth:"#e8e1d0",blood:"#c0392b"},eyes:!1,flat:!0}}),ZS=/^#[0-9a-f]{6}$/i;function JS(t={}){const e=hd[t.look??"ninja"];if(!e)throw Error(`rotoscope look: ${Object.keys(hd).join(" | ")}`);if(e.flat)return{flat:qS(t)};for(const n of["palette","paletteSize","boil"])if(t[n]!=null)throw Error(`rotoscope ${n}: only with look flat`);const o={...e.colors};if(t.colors!=null){if(typeof t.colors!="object"||Array.isArray(t.colors))throw Error(`rotoscope colors: {${ru.join(" | ")}: '#RRGGBB'}`);for(const[n,a]of Object.entries(t.colors)){if(!ru.includes(n)||!ZS.test(String(a)))throw Error(`rotoscope colors: {${ru.join(" | ")}: '#RRGGBB'}`);o[n]=String(a).toLowerCase()}}const r={flash:!0,glow:!0,smoke:!0,shadow:!0,blood:!0,cloth:!0,eyes:e.eyes};if(t.effects!=null){if(typeof t.effects!="object"||Array.isArray(t.effects)||Object.entries(t.effects).some(([n,a])=>!x0.includes(n)||typeof a!="boolean"))throw Error(`rotoscope effects: {${x0.join(" | ")}: true | false}`);Object.assign(r,t.effects)}return{colors:o,effects:r}}function QS(t,e,o=480){const r=Number.isFinite,n=t.fps??24;if(!ou.fps.includes(n))throw Error(`rotoscope fps: ${ou.fps.join(" | ")} drawings per second (24 = smooth, 12 = on twos)`);const a=t.from??0,i=Math.min(ou.seconds,Math.floor(o/n*100)/100);if(!(r(a)&&a>=0&&a<e))throw Error(`rotoscope from: s into the video clip, 0–${Math.round(e*100)/100}`);const l=t.duration??Math.round(Math.min(i,e-a)*1e4)/1e4;if(!(r(l)&&l>=.25&&l<=i+1e-6&&a+l<=e+1e-6))throw Error(`rotoscope duration: 0.25–${i} s at ${n} fps, inside the video clip`);return{fps:n,from:a,duration:l,n:Math.max(1,Math.round(l*n))}}function tI(t={}){const e=!!hd[t.look??"ninja"]?.flat,o=t.background??"plate";if(!(e?US:["plate","none"]).includes(o))throw Error(e?"rotoscope background: plate (the backdrop traced once on its own layer, default) | none (the characters alone, see-through) | keep (the whole picture redrawn every frame — a moving camera)":"rotoscope background: plate (the video's own backdrop as flat colours, default) | none (see-through)");return o}const ri=Object.freeze({events:24,size:[.02,.6]}),eI=/^#[0-9a-f]{6}$/i,ni=Number.isFinite,ke=t=>Math.round(t*1e3)/1e3,Ni=Object.freeze({hits:{size:.12,color:"#ffffff",about:"impact burst that pops and fades (0.2 s)"},dust:{size:.1,about:"dust puffs spreading from the ground (0.6 s)"},slash:{size:.3,color:"#ffffff",angle:!0,about:"a sword / kick arc that sweeps and fades (0.25 s); angle = its direction in degrees"},speed:{size:.5,color:"#ffffff",angle:!0,span:!0,about:"speed lines streaking across, for span s (0.4); angle = the motion direction"},sparks:{size:.1,color:"#ffd34d",about:"sparks flying out from a clash (0.35 s)"},ring:{size:.25,color:"#ffffff",about:"a shockwave ring growing from the point (0.35 s)"},aura:{size:.4,color:"#7fd3ff",span:!0,about:"a flickering glow round the figure nearest the point, for span s (1)"},flash:{size:1,color:"#ffffff",about:"the whole frame flashes (0.1 s), x / y ignored"}}),nu=["shadow","trail",...Object.keys(Ni)];function Py(t,e="drawFrames"){if(t==null||t===!1)return null;const o=Object.fromEntries(Object.keys(Ni).map(n=>[n,[]]));if(t===!0)return{shadow:!0,trail:!0,...o};if(typeof t!="object"||Array.isArray(t))throw Error(`${e} fx: true | {${nu.join("?, ")}?}`);for(const n of Object.keys(t))if(!nu.includes(n))throw Error(`${e} fx: ${nu.join("?, ")}? (unknown "${String(n).slice(0,20)}")`);const r=n=>{const a=Ni[n],i=t[n];if(i==null)return[];if(!Array.isArray(i)||i.length>ri.events)throw Error(`${e} fx.${n}: up to ${ri.events} [{at (s), x, y (0..1 of the frame), size?}]`);return i.map((l,p)=>{const c=l?.at,s=l?.x??.5,h=l?.y??.5,f=l?.size??a.size;if(!(ni(c)&&c>=0&&ni(s)&&s>=-.2&&s<=1.2&&ni(h)&&h>=-.2&&h<=1.2))throw Error(`${e} fx.${n}[${p}]: {at (s from the start), x, y (0..1 of the frame)}`);if(!(ni(f)&&f>=ri.size[0]&&f<=(n==="flash"?1:ri.size[1])))throw Error(`${e} fx.${n}[${p}].size: ${ri.size[0]}–${n==="flash"?1:ri.size[1]} of the frame height`);if(a.color&&l.color!=null&&!eI.test(l.color))throw Error(`${e} fx.${n}[${p}].color: #RRGGBB`);if(a.angle&&l.angle!=null&&!ni(l.angle))throw Error(`${e} fx.${n}[${p}].angle: degrees`);if(a.span&&l.span!=null&&!(ni(l.span)&&l.span>=.05&&l.span<=10))throw Error(`${e} fx.${n}[${p}].span: 0.05–10 s`);return{at:c,x:s,y:h,size:f,...a.color?{color:l.color??a.color}:{},...a.angle?{angle:l.angle??0}:{},...a.span?{span:l.span??(n==="aura"?1:.4)}:{}}})};return{shadow:t.shadow!==!1,trail:t.trail!==!1,...Object.fromEntries(Object.keys(Ni).map(n=>[n,r(n)]))}}const oI=t=>t.fill&&(t.opacity??1)>.9&&Array.isArray(t.points);function M0(t){let e=1e9,o=1e9,r=-1e9,n=-1e9;for(const a of t)for(const[i,l]of a.points)i<e&&(e=i),i>r&&(r=i),l<o&&(o=l),l>n&&(n=l);return r<e?null:{x0:e,y0:o,x1:r,y1:n,cx:(e+r)/2,cy:(o+n)/2,w:r-e,h:n-o}}function rI(t){const e=t.filter(oI).map(r=>({p:r,b:M0([r])})).filter(r=>r.b),o=[];for(const r of e){const n=o.filter(i=>r.b.x0<=i.b.x1+.01&&r.b.x1>=i.b.x0-.01&&r.b.y0<=i.b.y1+.01&&r.b.y1>=i.b.y0-.01),a={parts:[r.p,...n.flatMap(i=>i.parts)]};a.b=M0(a.parts);for(const i of n)o.splice(o.indexOf(i),1);o.push(a)}return o.filter(r=>r.b.h>.04)}const ai=(t,e,o,r,n=16)=>Array.from({length:n},(a,i)=>{const l=i/n*Math.PI*2;return[ke(t+Math.cos(l)*o),ke(e+Math.sin(l)*r)]});function $0(t,e,o,r,n){const a=[];for(let i=0;i<r*2;i++){const l=i/(r*2)*Math.PI*2+n,p=i%2?.38:1+(Math.sin(n*7+i*3.1)+1)/2*.35;a.push([ke(t+Math.cos(l)*o*p),ke(e+Math.sin(l)*o*p*1.05)])}return a}function nI(t,e,o,{aspect:r=16/9,maxParts:n=64}={}){if(!o)return t;let a=0;const i=t.map(p=>{const c=a;return a+=(p.hold??1)/e,c}),l=t.map(p=>rI(p.parts));return t.map((p,c)=>{const s=[],h=[],f=i[c];if(o.shadow)for(const S of l[c]){const k=Math.max(.03,S.b.w*.55);s.push({points:ai(S.b.cx,S.b.y1+.006,k/2,Math.max(.006,k*r*.07)),fill:"#000000",opacity:.22,line:!1,smooth:!0})}if(o.trail&&c>0)for(const S of l[c]){const k=l[c-1].reduce((b,A)=>{const I=Math.hypot(A.b.cx-S.b.cx,(A.b.cy-S.b.cy)/r);return I<b.d?{d:I,q:A}:b},{d:1e9,q:null});if(k.q&&k.d>Math.max(.02,S.b.h*.12)&&k.d<S.b.h*1.5)for(const b of k.q.parts)s.push({points:b.points,fill:b.fill,opacity:.22,line:!1,smooth:b.smooth!==!1})}for(const[S,k]of o.hits.entries()){const b=(f-k.at)/.2;if(b<0||b>=1)continue;const A=k.size*(.6+.6*Math.sin(Math.min(1,b*1.6)*Math.PI/2)),I=A/r;h.push({points:$0(k.x,k.y,1,9,S*1.7).map(([P,C])=>[ke(k.x+(P-k.x)*I*1.25),ke(k.y+(C-k.y)*A*1.25)]),fill:k.color,opacity:Math.max(.02,ke(.45*(1-b))),line:!1,smooth:!1}),h.push({points:$0(k.x,k.y,1,7,S*2.3).map(([P,C])=>[ke(k.x+(P-k.x)*I*.8),ke(k.y+(C-k.y)*A*.8)]),fill:"#ffffff",opacity:ke(Math.max(.05,1-b)),line:!1,smooth:!1})}for(const[S,k]of o.dust.entries()){const b=(f-k.at)/.6;if(!(b<0||b>=1))for(let A=0;A<3;A++){const I=(A-1)*k.size*.9*(.4+b)/r,P=k.size*(.35+b*.6)*(A===1?1.1:.8);h.push({points:ai(k.x+I,k.y-P*.45,P/r,P*.55,14),fill:"#d9d2cc",opacity:Math.max(.02,ke(.55*(1-b))),line:!1,smooth:!0})}}const m=S=>Math.max(.02,ke(S)),y=S=>S*Math.PI/180;for(const S of o.slash){const k=(f-S.at)/.25;if(k<0||k>=1)continue;const b=y(S.angle)-1.3,A=2.6*Math.min(1,k*2.2),I=S.size/2,P=[],C=[];for(let z=0;z<=14;z++){const N=b+A*z/14,F=Math.sin(Math.PI*z/14)*I*.22;P.push([ke(S.x+Math.cos(N)*I/r),ke(S.y+Math.sin(N)*I)]),C.push([ke(S.x+Math.cos(N)*(I-F)/r),ke(S.y+Math.sin(N)*(I-F))])}h.push({points:[...P,...C.reverse()],fill:S.color,opacity:m(.9*(1-k)),line:!1,smooth:!0})}for(const[S,k]of o.speed.entries()){if(f<k.at||f>=k.at+k.span)continue;const b=y(k.angle),A=Math.cos(b),I=Math.sin(b),P=-I,C=A;for(let z=0;z<7;z++){const N=Math.sin((S+1)*12.9898+z*78.233+Math.floor(f*24)*3.1)*43758.5453,F=N-Math.floor(N),K=(F-.5)*k.size,_=k.size*(.5+F*.6),q=.0025+F*.003,U=k.x+P*K/r,rt=k.y+C*K,ot=U-A*_/r,G=rt-I*_,J=U+A*_*.2/r,Z=rt+I*_*.2;h.push({points:[[ke(ot),ke(G)],[ke(J+P*q/r),ke(Z+C*q)],[ke(J-P*q/r),ke(Z-C*q)]],fill:k.color,opacity:m(.55),line:!1,smooth:!1})}}for(const[S,k]of o.sparks.entries()){const b=(f-k.at)/.35;if(!(b<0||b>=1))for(let A=0;A<8;A++){const I=A/8*Math.PI*2+S*.7,P=k.size*(.2+b*.9),C=k.size*.18*(1-b*.5),z=k.x+Math.cos(I)*P/r,N=k.y+Math.sin(I)*P+b*b*k.size*.4;h.push({points:[[ke(z),ke(N)],[ke(z+Math.cos(I)*C/r+.002),ke(N+Math.sin(I)*C)],[ke(z+Math.cos(I)*C/r-.002),ke(N+Math.sin(I)*C+.003)]],fill:k.color,opacity:m(1-b),line:!1,smooth:!1})}}for(const S of o.ring){const k=(f-S.at)/.35;if(k<0||k>=1)continue;const b=S.size/2*(.2+k*.8),A=b*(.18*(1-k)+.04);h.push({points:[...ai(S.x,S.y,b/r,b*.55,20),...ai(S.x,S.y,(b-A)/r,(b-A)*.55,20).reverse()],fill:S.color,opacity:m(.7*(1-k)),line:!1,smooth:!0})}for(const[S,k]of o.aura.entries()){if(f<k.at||f>=k.at+k.span)continue;const b=l[c].reduce((C,z)=>{const N=Math.hypot(z.b.cx-k.x,z.b.cy-k.y);return N<C.d?{d:N,q:z}:C},{d:1e9,q:null}).q??{b:{cx:k.x,cy:k.y,w:k.size*.35/r,h:k.size*.8}},A=.85+.15*Math.sin(f*40+S),I=(b.b.w/2+k.size*.15/r)*A,P=(b.b.h/2+k.size*.12)*A;s.push({points:ai(b.b.cx,b.b.cy,I,P,18),fill:k.color,opacity:.35,line:!1,smooth:!0},{points:ai(b.b.cx,b.b.cy,I*.75,P*.85,18),fill:k.color,opacity:.3,line:!1,smooth:!0})}for(const S of o.flash){const k=(f-S.at)/.1;k<0||k>=1||h.push({points:[[0,0],[1,0],[1,1],[0,1]],fill:S.color,opacity:m(.85*(1-k)),line:!1,smooth:!1})}if(!s.length&&!h.length)return p;const $=Math.max(0,n-p.parts.length),x=[...h,...s].slice(0,$),E=s.filter(S=>x.includes(S)),v=h.filter(S=>x.includes(S));return{...p,parts:[...E,...p.parts,...v]}})}const aI={hits:.2,dust:.6,slash:.25,speed:0,sparks:.35,ring:.35,aura:0,flash:.1},iI={points:[[.5,.5],[.501,.5],[.5,.501]],fill:"#000000",opacity:.02,line:!1};function rj(t,e,o={},{fps:r=30,label:n}={}){const a=Ni[t];if(!a)throw Error(`fxLayerOp kind: ${Object.keys(Ni).join(" | ")}`);const i=a.span?o.span??(t==="aura"?1:.4):0,l=Math.ceil((aI[t]+i+.05)*r),p={at:.01,x:o.x??.5,y:o.y??.5,...o.size!=null?{size:o.size}:{},...a.color&&o.color?{color:o.color}:{},...a.angle&&o.angle!=null?{angle:o.angle}:{},...a.span?{span:i}:{}};return{op:"drawFrames",start:e,fps:r,frames:Array.from({length:l},()=>({parts:[iI]})),fx:{shadow:!1,trail:!1,[t]:[p]},width:0,brush:"none",...n?{label:n}:{}}}function sI(t){const e=String(t).match(/[MLCSQZ]|-?\d*\.?\d+(?:e[-+]?\d+)?/gi)??[],o=[];let r=0,n="M",a=[0,0],i=[0,0],l=null,p=!1;const c=()=>Number(e[r++]),s=(h,f,m,y)=>{for(let $=1;$<=8;$++){const x=$/8,E=1-x;o.push([E*E*E*h[0]+3*E*E*x*f[0]+3*E*x*x*m[0]+x*x*x*y[0],E*E*E*h[1]+3*E*E*x*f[1]+3*E*x*x*m[1]+x*x*x*y[1]])}};for(;r<e.length;){if(/^[MLCSQZ]$/i.test(e[r])&&(n=e[r++].toUpperCase()),n==="Z"){p=!0,a=i,l=null;continue}if(n==="M")a=[c(),c()],i=a,o.push(a),n="L",l=null;else if(n==="L")a=[c(),c()],o.push(a),l=null;else if(n==="C"){const h=[c(),c()],f=[c(),c()],m=[c(),c()];s(a,h,f,m),l=f,a=m}else if(n==="S"){const h=l?[2*a[0]-l[0],2*a[1]-l[1]]:a,f=[c(),c()],m=[c(),c()];s(a,h,f,m),l=f,a=m}else if(n==="Q"){const h=[c(),c()],f=[c(),c()];s(a,[a[0]+2/3*(h[0]-a[0]),a[1]+2/3*(h[1]-a[1])],[f[0]+2/3*(h[0]-f[0]),f[1]+2/3*(h[1]-f[1])],f),l=null,a=f}else r++;if(!Number.isFinite(a[0]))break}return{pts:o.filter(h=>h.every(Number.isFinite)),closed:p}}function v0(t,e,o=!1){const r=o?[...t,t[0]]:t;if(r.length<2)return Array.from({length:e},()=>[...r[0]??[0,0]]);const n=[0];for(let p=1;p<r.length;p++)n.push(n[p-1]+Math.hypot(r[p][0]-r[p-1][0],r[p][1]-r[p-1][1]));const a=n.at(-1)||1,i=[];let l=1;for(let p=0;p<e;p++){const c=o?a*p/e:a*p/(e-1);for(;l<r.length-1&&n[l]<c;)l++;const s=r[l-1],h=r[l],f=(c-n[l-1])/(n[l]-n[l-1]||1);i.push([s[0]+(h[0]-s[0])*f,s[1]+(h[1]-s[1])*f])}return i}function lI(t,e){const o=e.length;let r=0,n=1,a=1/0;for(const i of[1,-1])for(let l=0;l<o;l++){let p=0;for(let c=0;c<o;c+=Math.max(1,o>>3)){const s=e[((l+i*c)%o+o)%o];p+=Math.hypot(s[0]-t[c][0],s[1]-t[c][1])}p<a&&(a=p,r=l,n=i)}return Array.from({length:o},(i,l)=>e[((r+n*l)%o+o)%o])}const E0=Object.freeze(["draw","erase","undoLine","duplicate","insert","delete","hold","clear","transform","clone","unlink","fill","warp","mark","inbetween"]),S0=Object.freeze(["key","breakdown","inbetween"]),I0=Object.freeze(["even","slow-out","slow-in","slow-in-out"]),A0=Object.freeze(["ramp","ramp-down","bump","hold"]),xn=Object.freeze({strokes:32,points:400,hold:48,fps:[4,60]}),au=/^#[0-9a-f]{6}$/i,Si=Number.isFinite,Ve=t=>Math.round(Math.round(t*120)/120*1e4)/1e4,cI=t=>Array.isArray(t?.size)?t.size:t?.square?[720,720]:[1280,720];function zy(t){const e=Array.isArray(t?.items)?t.items:[];return e.map((o,r)=>({index:r,id:o.id,t0:o.span?.[0],t1:o.span?.[1]})).filter(o=>Array.isArray(e[o.index].span)).sort((o,r)=>o.t0-r.t0)}const nj=t=>zy(t).length>0,Al=t=>{let e=t.length+1;for(;t.some(o=>o.id===`s${e}`);)e++;return`s${e}`},xa=(t,e,o)=>t.map(r=>r.span&&r.span[0]>=e-1e-6?{...r,span:[Ve(r.span[0]+o),Ve(r.span[1]+o)]}:r);function Gc(t,e){if(!Array.isArray(t)||t.length<1||t.length>xn.points)throw Error(`${e}.points: 1–${xn.points} [x, y] pairs`);return t.map((o,r)=>{if(!Array.isArray(o)||o.length!==2||!o.every(Si))throw Error(`${e}.points[${r}]: [x, y]`);return[o[0],o[1]]})}function pI(t,e){let o=t;if(o.length===1&&(o=[o[0],[o[0][0]+.6,o[0][1]]]),o.length>120){const r=(o.length-1)/119;o=Array.from({length:120},(n,a)=>o[Math.round(a*r)])}for(let r=0;r<1;r++)o=o.map((n,a)=>a===0||a===o.length-1?n:[(o[a-1][0]+2*n[0]+o[a+1][0])/4,(o[a-1][1]+2*n[1]+o[a+1][1])/4]);return _i(o,e&&o.length>2)}function uI(t,e,o=null){let r=t.length===1?[t[0],[t[0][0]+.6,t[0][1]]]:t,n=o&&o.length===t.length?o:null;if(r.length>80){const p=(r.length-1)/79,c=Array.from({length:80},(s,h)=>Math.round(h*p));r=c.map(s=>r[s]),n&&(n=c.map(s=>n[s]))}const a=r.length,i=[],l=[];for(let p=0;p<a;p++){const c=r[Math.max(0,p-1)],s=r[Math.min(a-1,p+1)],h=s[0]-c[0],f=s[1]-c[1],m=Math.hypot(h,f)||1,y=a>1?p/(a-1):.5,$=Math.max(.25,Math.min(1,Math.min(y,1-y)*5)),x=e/2*(n?Math.max(.12,Math.min(1.3,.2+n[p]*1.1))*Math.max(.5,$):$);i.push([r[p][0]-f/m*x,r[p][1]+h/m*x]),l.push([r[p][0]+f/m*x,r[p][1]-h/m*x])}return _i([...i,...l.reverse()],!0)}const dI=t=>"M"+t.map(([e,o])=>`${Math.round(e)} ${Math.round(o)}`).join(" L")+" Z",fd=t=>{const e=String(t).match(/-?\d*\.?\d+(?:e[-+]?\d+)?/gi)?.map(Number)??[],o=[];for(let r=0;r+1<e.length;r+=2)o.push([e[r],e[r+1]]);return o};function C0(t,e,o,{units:r,toShape:n,where:a,k:i}){if(!t||t.type!=="art"||!Array.isArray(t.params.parts))throw Error(`${a}: frame ${i+1} is not a drawing`);const l=rc(Jn(t)),p=_=>{const q=n(_);return Ms(l,q[0],q[1])};if(e.tag!=null&&!Ad.test(e.tag))throw Error(`${a} tag: a part name (armR, head…)`);const c=e.tag!=null?null:Gc(e.lasso,`${a} lasso`).map(p);if(c&&c.length<3)throw Error(`${a} lasso: at least 3 points round the lines to move`);const s=e.dx??0,h=e.dy??0,f=e.rotate??0,m=e.scale??1;if(![s,h,f,m].every(Si)||m<=0||m>10)throw Error(`${a}: dx, dy (frame fractions), rotate (degrees), scale (0–10)`);const y=([_,q])=>{let U=!1;for(let rt=0,ot=c.length-1;rt<c.length;ot=rt++){const[G,J]=c[rt],[Z,at]=c[ot];J>q!=at>q&&_<(Z-G)*(q-J)/(at-J)+G&&(U=!U)}return U},$=_=>e.tag!=null?_.tag===e.tag:(()=>{const q=fd(_.d);return q.length>0&&q.filter(y).length>=q.length*.6})(),x=t.params.parts.filter($);if(!x.length)return{item:t,moved:0};const[E,v]=e.pivot!=null?p(Gc([e.pivot],`${a} pivot`)[0]):c?[c.reduce((_,q)=>_+q[0],0)/c.length,c.reduce((_,q)=>_+q[1],0)/c.length]:fd(x[0].d)[0],S=p([0,0]),k=p([s,h]),b=(k[0]-S[0])*o,A=(k[1]-S[1])*o,I=f*o*Math.PI/180,P=Math.pow(m,o),C=Math.cos(I)*P,z=Math.sin(I)*P,N=(_,q)=>[Math.round(E+(_-E)*C-(q-v)*z+b),Math.round(v+(_-E)*z+(q-v)*C+A)];let F=0;const K=t.params.parts.map(_=>{if(!$(_))return _;F++;let q=0,U=0;const rt=_.d.replace(/-?\d*\.?\d+(?:e[-+]?\d+)?/gi,ot=>{const G=Number(ot);if(q++%2===0)return U=G,"\0";const[J,Z]=N(U,G);return`${J} ${Z}`}).replace(/\u0000[\s,]*/g,"");return{..._,d:rt}});return{item:{...t,params:{...t.params,parts:K,box:ir(K.map(_=>_.d).join(" "))}},moved:F}}function Ly(t,e,{units:o="frame",ink:r="#1d1a17",width:n=4}={}){const a="editFrames";if(!t||!Array.isArray(t.items))throw Error(`${a}: not a shape layer`);if(!E0.includes(e?.action))throw Error(`${a} action: ${E0.join(" | ")}`);const i=e.fps??24;if(!(Si(i)&&i>=xn.fps[0]&&i<=xn.fps[1]))throw Error(`${a} fps: ${xn.fps.join("–")}`);const l=e.hold??1;if(!(Number.isInteger(l)&&l>=1&&l<=xn.hold))throw Error(`${a} hold: 1–${xn.hold} frames`);const p=Ve(l/i);let c=t.items.map(k=>({...k}));const s=zy({items:c});let h=-1,f=null;if(e.frame==null&&e.action==="warp"&&e.from!=null&&(e={...e,frame:e.from}),e.frame!=null){if(!(Number.isInteger(e.frame)&&e.frame>=1&&e.frame<=s.length+1))throw Error(`${a} frame: 1–${s.length+1} (the drawings in time order; ${s.length+1} = a new one after the last)`);h=e.frame-1,f=h<s.length?s[h].t0:s.length?s.at(-1).t1:0}else{if(e.action==="fill")throw Error(`${a} fill: frame (1-based) — the drawing to fill`);if(!(Si(e.at)&&e.at>=0&&e.at<=600))throw Error(`${a}: frame (1-based) or at (seconds into the layer)`);f=e.at,h=s.findIndex(k=>f>=k.t0-1e-6&&f<k.t1-1e-6)}const m=h>=0&&h<s.length?s[h]:null,y=m?c.findIndex(k=>k.id===m.id):-1,$=cI(t),x=Vr($),E=k=>o==="shape"?k:x.pt(k);let v="";if(e.action==="fill"){if(!Array.isArray(e.region))throw Error(`${a} fill: {frame, at [x, y], color} — the region the lines close round "at" is found by the Clipoox server (MCP edit_timeline); in the editor use the Fill tool`);if(!au.test(e.color??""))throw Error(`${a} fill color: #RRGGBB`);const k=Ly(t,{...e,action:"draw",lines:[{points:e.region,fill:e.color,under:!0,...e.tag?{tag:e.tag}:{}}]},{units:e.regionUnits??o,ink:r,width:n});return{...k,note:k.note.replace(/line\(s\)/,"colour fill")}}switch(e.action){case"draw":{const k=Array.isArray(e.lines)?e.lines:null;if(!k||!k.length||k.length>xn.strokes)throw Error(`${a} draw lines: 1–${xn.strokes} [{points, width?, fill?}]`);let b=y>=0?c[y]:null;if(b&&b.type!=="art")throw Error(`${a}: frame ${h+1} is a ${b.type} item, not a drawing — draw on a drawFrames / frame-editor layer`);if(b?.params?.rig)throw Error(`${a}: frame ${h+1} is a character played from its skeleton — it cannot take lines`);const A=k.map((N,F)=>({...N,pts:Gc(N?.points,`${a} lines[${F}]`).map(E)}));if(!b){if(c.length>=Xo.items)throw Error(`${a}: this layer already holds ${Xo.items} drawings — continue on a new frame layer`);const N=s.find(rt=>rt.t0>f+1e-6),F=Ve(f),K=Ve(Math.min(f+p,N?N.t0:f+p)),_=A.flatMap(rt=>rt.pts),q=Math.round((Math.min(..._.map(rt=>rt[0]))+Math.max(..._.map(rt=>rt[0])))/2),U=Math.round((Math.min(..._.map(rt=>rt[1]))+Math.max(..._.map(rt=>rt[1])))/2);b={id:Al(c),name:`Frame ${s.filter(rt=>rt.t0<F).length+1}`,type:"art",params:{parts:[],box:[0,0,1,1]},pos:[q,U],rot:0,scale:[1,1],opacity:1,fill:{type:"color",color:r},stroke:{color:r,width:n,cap:"round",join:"round"},role:7,span:[F,K>F?K:Ve(F+p)]},c.push(b)}const I=rc(Jn(b)),P=b.stroke?.width||n,C=[...b.params.parts??[]];for(const[N,F]of A.entries()){const K=F.pts.map(at=>Ms(I,at[0],at[1])),_=F.fill??null;if(_!==null&&!au.test(_))throw Error(`${a} lines[${N}].fill: #RRGGBB or omitted (an ink line)`);const q=F.width==null?null:o==="shape"?F.width:x.len(F.width);if(q!=null&&!(Si(q)&&q>0))throw Error(`${a} lines[${N}].width: a fraction of the frame width (e.g. 0.004)`);const U=q==null?1:Math.max(.1,Math.min(5,Math.round(q/P*100)/100)),rt=F.color??null;if(rt!==null&&!au.test(rt))throw Error(`${a} lines[${N}].color: #RRGGBB`);const ot=F.tag??null;if(ot!==null&&!Ad.test(ot))throw Error(`${a} lines[${N}].tag: a part name — a letter then letters / digits / dashes, ≤ 24 (armR, head)`);const G=ot?{tag:ot}:{},J=F.pressures==null?null:Array.isArray(F.pressures)&&F.pressures.length===F.points.length&&F.pressures.every(at=>Si(at)&&at>=0&&at<=1)?F.pressures:(()=>{throw Error(`${a} lines[${N}].pressures: one 0..1 value per point (the pen's pressure)`)})();if(_&&F.under===!0){const at=C.findIndex(D=>!(D.eo===!0&&D.line===!1));C.splice(at<0?C.length:at,0,{d:dI(K),fill:_,line:!1,eo:!0,role:7,...G});continue}const Z=Math.hypot(I[0],I[1])||1;if(!_&&(J||rt&&rt.toLowerCase()!==String(b.stroke?.color??r).toLowerCase())){C.push({d:uI(K,(q??P)*Z,J),fill:rt??b.stroke?.color??r,line:!1,role:7,...G});continue}C.push({d:pI(K,!!_||F.closed===!0),fill:_,..._&&F.line===!1?{line:!1}:{},...U!==1?{lw:U}:{},role:7,...G})}if(C.length>Gi.parts)throw Error(`${a}: frame ${h+1} would hold ${C.length} lines (max ${Gi.parts}) — fewer, longer lines`);const z=ir(C.map(N=>N.d).join(" "));c=c.map(N=>N.id===b.id?{...b,params:{...b.params,parts:C,box:z}}:N),v=`${k.length} line(s) on frame ${(m?h:s.filter(N=>N.t0<f).length)+1}`;break}case"erase":case"undoLine":{if(y<0)throw Error(`${a}: no drawing on that frame to ${e.action==="erase"?"erase":"undo"}`);const k=c[y];if(k.type!=="art"||!Array.isArray(k.params.parts))throw Error(`${a}: frame ${h+1} is not a drawing`);let b=k.params.parts;if(e.action==="undoLine")b=b.slice(0,-1);else{const I=Array.isArray(e.lines)?e.lines:[];if(!I.length)throw Error(`${a} erase lines: the eraser's path [{points}]`);const P=rc(Jn(k)),C=I.flatMap((N,F)=>Gc(N?.points,`${a} lines[${F}]`).map(E).map(K=>Ms(P,K[0],K[1]))),z=e.radius==null?12:o==="shape"?e.radius:x.len(e.radius);b=b.filter(N=>!fd(N.d).some(F=>C.some(K=>Math.hypot(F[0]-K[0],F[1]-K[1])<=z)))}const A=k.params.parts.length-b.length;c=b.length?c.map((I,P)=>P===y?{...I,params:{...I.params,parts:b,box:ir(b.map(C=>C.d).join(" "))}}:I):c.filter((I,P)=>P!==y),v=`${A} line(s) taken out of frame ${h+1}${b.length?"":" (now blank)"}`;break}case"duplicate":{if(y<0)throw Error(`${a}: no drawing on that frame to duplicate`);if(c.length>=Xo.items)throw Error(`${a}: this layer already holds ${Xo.items} drawings — continue on a new frame layer`);const k=c[y],b=Ve(k.span[1]-k.span[0]);c=xa(c,k.span[1],b),c.push({...structuredClone(k),id:Al(c),name:`${k.name} copy`.slice(0,40),span:[k.span[1],Ve(k.span[1]+b)]}),v=`frame ${h+1} duplicated`;break}case"insert":{c=xa(c,m?m.t0:f,p),v=`blank frame put in at ${Ve(m?m.t0:f)}s`;break}case"delete":{if(!m){const b=s.find(P=>P.t0>f+1e-6);if(!b)throw Error(`${a}: nothing to take out there`);const A=s.filter(P=>P.t1<=f+1e-6).reduce((P,C)=>Math.max(P,C.t1),0),I=Math.min(p,Ve(b.t0-A));c=xa(c,b.t0,-I),v="blank frame taken out";break}const k=Ve(m.t1-m.t0);c=xa(c.filter((b,A)=>A!==y),m.t1,-k),v=`frame ${h+1} taken out`;break}case"hold":{if(y<0)throw Error(`${a}: no drawing on that frame to hold`);const k=c[y],b=Ve(k.span[1]-k.span[0]),A=Ve(p-b);c=xa(c,k.span[1],A).map((I,P)=>P===y?{...I,span:[k.span[0],Ve(k.span[0]+p)]}:I),v=`frame ${h+1} lasts ${l} frame(s)`;break}case"clear":{if(y<0)throw Error(`${a}: that frame is already blank`);c=c.filter((k,b)=>b!==y),v=`frame ${h+1} cleared (blank)`;break}case"transform":{if(y<0)throw Error(`${a}: no drawing on that frame to transform`);const k=C0(c[y],e,1,{units:o,toShape:E,where:a,k:h});if(!k.moved)throw Error(`${a}: the ${e.tag?`part "${e.tag}"`:"lasso"} holds no line of frame ${h+1}`);c=c.map((b,A)=>A===y?k.item:b),v=`${k.moved} line(s) of frame ${h+1} transformed`;break}case"warp":{const k=(e.from??e.frame)-1,b=(e.to??e.from??e.frame)-1;if(!(Number.isInteger(k)&&Number.isInteger(b)&&k>=0&&b>=k&&b<s.length))throw Error(`${a} warp: from / to = frame numbers 1–${s.length} (from ≤ to)`);const A=e.ease??"ramp";if(!A0.includes(A))throw Error(`${a} warp ease: ${A0.join(" | ")}`);let I=0,P=0;for(let C=k;C<=b;C++){const z=b===k?1:(C-k)/(b-k),N=A==="hold"?1:A==="ramp"?z:A==="ramp-down"?1-z:Math.sin(Math.PI*z);if(N<=1e-4)continue;const F=c.findIndex(_=>_.id===s[C].id),K=C0(c[F],e,N,{units:o,toShape:E,where:a,k:C});K.moved&&(c=c.map((_,q)=>q===F?K.item:_),I+=K.moved,P++)}if(!P)throw Error(`${a}: the ${e.tag?`part "${e.tag}"`:"lasso"} holds no line in frames ${k+1}–${b+1}`);v=`warp over frames ${k+1}–${b+1} (${A}): ${I} line(s) in ${P} frame(s)`;break}case"mark":{if(y<0)throw Error(`${a}: no drawing on that frame to mark`);const k=e.mark??null;if(k!==null&&!S0.includes(k))throw Error(`${a} mark: ${S0.join(" | ")} | null (no mark)`);c=c.map((b,A)=>{if(A!==y)return b;const{mark:I,...P}=b;return k?{...P,mark:k}:P}),v=`frame ${h+1} ${k?`marked ${k}`:"unmarked"}`;break}case"inbetween":{if(y<0)throw Error(`${a}: no drawing on that frame to in-between from`);const k=e.to!=null?e.to-1:h+1;if(!(Number.isInteger(k)&&k>h&&k<s.length))throw Error(`${a} inbetween: to = a later drawing (frame ${h+2}–${s.length}); default the next one`);const b=e.count??1;if(!(Number.isInteger(b)&&b>=1&&b<=12))throw Error(`${a} inbetween count: 1–12 drawings between the two keys`);const A=e.ease??"even";if(!I0.includes(A))throw Error(`${a} inbetween ease: ${I0.join(" | ")}`);if(c.length+b>Xo.items)throw Error(`${a}: ${b} more drawings would pass ${Xo.items} on this layer — fewer, or continue on a new frame layer`);const I=c[y],P=c.find(G=>G.id===s[k].id);if(I.type!=="art"||P.type!=="art"||!I.params.parts||!P.params.parts)throw Error(`${a} inbetween: both frames must be drawings`);const C=e.hold!=null?p:Ve(I.span[1]-I.span[0]),z=Jn(I),N=Jn(P),F=G=>G.fill===null?"line":"fill",K=[],_=new Set,q=(G,J)=>G.map((Z,at)=>({q:Z,i:at})).filter(({q:Z})=>!Z.tag&&F(Z)===J);for(const[G,J]of I.params.parts.entries()){let Z=-1;if(J.tag)Z=P.params.parts.findIndex((at,D)=>at.tag===J.tag&&!_.has(D));else{const at=q(I.params.parts,F(J)),D=q(P.params.parts,F(J)).filter(({i:ut})=>!_.has(ut)),H=at.findIndex(ut=>ut.i===G);Z=D[Math.min(H,D.length-1)]?.i??-1,H>=D.length&&(Z=-1)}Z>=0?(_.add(Z),K.push([J,P.params.parts[Z]])):K.push([J,null])}const U=P.params.parts.filter((G,J)=>!_.has(J)),rt=(G,J)=>{const Z=sI(G.d);return{pts:Z.pts.map(at=>Ms(J,at[0],at[1])),closed:Z.closed||!!G.fill}},ot=G=>A==="even"?G:A==="slow-out"?G*G:A==="slow-in"?1-(1-G)*(1-G):G*G*(3-2*G);c=xa(c,I.span[1],Ve(b*C));for(let G=1;G<=b;G++){const J=ot(G/(b+1)),Z=[Math.round(I.pos[0]+(P.pos[0]-I.pos[0])*J),Math.round(I.pos[1]+(P.pos[1]-I.pos[1])*J)],at=[];for(const[H,ut]of K){if(!ut){J<.5&&at.push({...H,d:H.d.replace(/-?\d*\.?\d+(?:e[-+]?\d+)?/gi,(()=>{let j=0;return O=>{const L=Number(O)+(j++%2?I.pos[1]-Z[1]:I.pos[0]-Z[0]);return String(Math.round(L))}})())});continue}const gt=rt(H,z),xt=rt(ut,N),u=gt.closed?48:40,st=v0(gt.pts,u,gt.closed),V=v0(xt.pts,u,gt.closed),d=gt.closed?lI(st,V):V,w=gt.closed?st.map((j,O)=>[j[0]+(d[O][0]-j[0])*J-Z[0],j[1]+(d[O][1]-j[1])*J-Z[1]]):(()=>{const j=[[st[0][0]+(d[0][0]-st[0][0])*J,st[0][1]+(d[0][1]-st[0][1])*J]];for(let O=1;O<st.length;O++){const L=[st[O][0]-st[O-1][0],st[O][1]-st[O-1][1]],B=[d[O][0]-d[O-1][0],d[O][1]-d[O-1][1]],X=Math.atan2(L[1],L[0]),Q=Math.atan2(B[1],B[0]),et=(Q-X+3*Math.PI)%(2*Math.PI)-Math.PI,lt=X+et*J,Y=Math.hypot(...L)+(Math.hypot(...B)-Math.hypot(...L))*J;j.push([j[O-1][0]+Math.cos(lt)*Y,j[O-1][1]+Math.sin(lt)*Y])}return j.map(O=>[O[0]-Z[0],O[1]-Z[1]])})(),T=H.lw!=null||ut.lw!=null?Math.round(((H.lw??1)+((ut.lw??1)-(H.lw??1))*J)*100)/100:null;at.push({...H,d:gt.closed?_i(w,!0):_i(w,!1),fill:J<.5?H.fill:ut.fill,...T!=null&&T!==1?{lw:T}:{}})}for(const H of U)J>=.5&&at.push({...H,d:H.d.replace(/-?\d*\.?\d+(?:e[-+]?\d+)?/gi,(()=>{let ut=0;return gt=>{const xt=Number(gt)+(ut++%2?P.pos[1]-Z[1]:P.pos[0]-Z[0]);return String(Math.round(xt))}})())});if(!at.length)continue;const D=Ve(I.span[1]+(G-1)*C);c.push({...structuredClone(I),id:Al(c),name:`${I.name} · ${G}/${b+1}`.slice(0,40),params:{...I.params,parts:at,box:ir(at.map(H=>H.d).join(" "))},pos:Z,mark:"inbetween",span:[D,Ve(D+C)],...I.group?{group:void 0}:{}})}c=c.map(G=>G.id===I.id||G.id===P.id?{...G,mark:G.mark??"key"}:G).map(G=>{if(G.group===void 0&&"group"in G){const{group:J,...Z}=G;return Z}return G}),v=`${b} in-between(s) drawn between frames ${h+1} and ${k+1} (${A})`;break}case"clone":{if(y<0)throw Error(`${a}: no drawing on that frame to clone`);if(c.length>=Xo.items)throw Error(`${a}: this layer already holds ${Xo.items} drawings — continue on a new frame layer`);const k=c[y],b=Ve(k.span[1]-k.span[0]),A=k.group??`ln${k.id}`.slice(0,16);c=xa(c,k.span[1],b).map((I,P)=>P===y?{...I,group:A}:I),c.push({...structuredClone(k),id:Al(c),group:A,name:`${k.name} ↻`.slice(0,40),span:[k.span[1],Ve(k.span[1]+b)]}),v=`frame ${h+1} cloned (live)`;break}case"unlink":{if(y<0||!c[y].group)throw Error(`${a}: frame ${h+1} is not a live copy`);const{group:k,...b}=c[y];c=c.map((A,I)=>I===y?b:A),v=`frame ${h+1} is its own drawing again`;break}}if(["draw","erase","undoLine","transform"].includes(e.action)){const k=m?c.find(b=>b.id===m.id):c.at(-1);if(k?.group)c=c.map(b=>b.group===k.group&&b.id!==k.id?{...b,params:structuredClone(k.params),pos:k.pos,stroke:k.stroke}:b);else if(m&&!k&&t.items.find(b=>b.id===m.id)?.group){const b=t.items.find(A=>A.id===m.id).group;c=c.filter(A=>A.group!==b)}}if(c.some(k=>k.span&&k.span[0]<0))throw Error(`${a}: a frame would start before the layer`);const S=c.reduce((k,b)=>Math.max(k,b.span?.[1]??0),0);return{shape:{...t,items:c},end:Ve(S),note:v}}const iu=Object.freeze(["ink","sweep","speed","tear","swirl"]),aj=Object.freeze({ink:["Mực loang","Ink spread"],sweep:["Nét cọ quét","Brush sweep"],speed:["Tia tốc độ","Speed lines"],tear:["Giấy xé","Torn paper"],swirl:["Vệt xoáy","Skill swirl"]}),hI=Object.freeze({ink:{color:"#121014",color2:"#3a2f3a"},sweep:{color:"#c8202f",color2:"#1d1a1f"},speed:{color:"#ffffff",color2:"#16181d"},tear:{color:"#efe6d2",color2:"#b9ab8f"},swirl:{color:"#4d5660",color2:"#c5ccd3"}}),su=Object.freeze({duration:[.4,2.5],fps:[12,24]}),j0=/^#[0-9a-f]{6}$/i,lu=Number.isFinite,Kc=t=>Math.round(t*1e4)/1e4,Ra=(t,e)=>[Kc(Math.max(-1,Math.min(2,t))),Kc(Math.max(-1,Math.min(2,e)))],dn=t=>t<=0?0:t>=1?1:t<.5?4*t*t*t:1-Math.pow(-2*t+2,3)/2;function Ji(t){let e=t*2654435761>>>0||1;return()=>(e^=e<<13,e>>>=0,e^=e>>>17,e^=e<<5,e>>>=0,e/4294967296)}function fi(t,e,o,r,n,a,i=40){const l=Ji(n),p=[l()*6.3,l()*6.3,l()*6.3],c=[];for(let s=0;s<i;s++){const h=s/i*2*Math.PI,f=o*(1+r*(.5*Math.sin(3*h+p[0])+.28*Math.sin(5*h+p[1])+.16*Math.sin(11*h+p[2])+.1*Math.sin(19*h+p[0]*2)+(l()-.5)*.35));c.push(Ra(t+Math.cos(h)*f/a,e+Math.sin(h)*f))}return c}const Hi=[[-.05,-.05],[1.05,-.05],[1.05,1.05],[-.05,1.05]],Ny=t=>({points:Hi,fill:t,line:!1,smooth:!1});function fI(t,{c1:e,c2:o,o:r,A:n,seed:a}){const i=[],l=t<.5,p=dn(l?t*2:(t-.5)*2),c=1.2*Math.max(...[[0,0],[1,0],[0,1],[1,1]].map(([s,h])=>Math.hypot((s-r[0])*n,h-r[1])));if(l){const s=Math.max(.02,c*p);i.push({points:fi(r[0],r[1],s*1.12+.02,.22,a+1,n),fill:o,opacity:.45,line:!1}),i.push({points:fi(r[0],r[1],s,.22,a,n,56),fill:e,line:!1});const h=Ji(a+7);for(let f=0;f<10;f++){const m=h()*6.3,y=s*(.25+h()*.5),$=.012+h()*.03,x=s*.92,E=[r[0]+Math.cos(m)*(x+y)/n,r[1]+Math.sin(m)*(x+y)],v=[r[0]+Math.cos(m-$/Math.max(.05,x))*x/n,r[1]+Math.sin(m-$/Math.max(.05,x))*x],S=[r[0]+Math.cos(m+$/Math.max(.05,x))*x/n,r[1]+Math.sin(m+$/Math.max(.05,x))*x];i.push({points:[Ra(...v),Ra(...E),Ra(...S)],fill:e,line:!1,smooth:!1})}for(let f=0;f<14;f++){const m=h()*6.3,y=s*(1.1+h()*.7),$=(.006+h()*.035)*(.5+p);i.push({points:fi(r[0]+Math.cos(m)*y/n,r[1]+Math.sin(m)*y,$,.3,a+20+f,n,12),fill:e,line:!1})}p>.92&&i.push(Ny(e))}else{const s=Math.max(.01,c*p);i.push({loops:[Hi,fi(r[0],r[1],s*.94,.16,a+3,n)],fill:o,opacity:.5,line:!1,eo:!0}),i.push({loops:[Hi,fi(r[0],r[1],s,.18,a+2,n)],fill:e,line:!1,eo:!0})}return i}function mI(t,{c1:e,c2:o,angle:r,seed:n}){const a=r*Math.PI/180,i=Math.cos(a),l=Math.sin(a),p=t<.5,c=dn(p?t*2:(t-.5)*2),s=1.6,h=-.8+s*c,f=([x,E])=>Ra(.5+x*i-E*l,.5+x*l+E*i),m=Ji(n),y=[],$=(x,E)=>{const v=[];for(let S=0;S<=24;S++){const k=-.9+1.8*S/24;v.push([x+E*(Math.sin(S*1.7+n)*.012+(m()-.5)*.02),k])}return v};if(p){const x=$(h,1);y.push({points:[[-1,-.9],...x,[-1,.9]].map(f),fill:e,line:!1,smooth:!1});for(let E=0;E<16;E++){const v=-.9+1.8*(E+.5)/16+(m()-.5)*.04,S=.03+m()*.12*(1-Math.abs(c-.5)),k=.006+m()*.01;y.push({points:[[h-.02,v-k],[h+S,v],[h-.02,v+k]].map(f),fill:E%3?e:o,line:!1,smooth:!1})}c>.05&&c<.95&&y.push({points:[[h-.35,-.9],[h-.05,-.9],[h-.05,.9],[h-.35,.9]].map(f),fill:o,opacity:.18,line:!1,smooth:!1})}else{const x=$(h,-1);y.push({points:[...x,[1,.9],[1,-.9]].map(f),fill:e,line:!1,smooth:!1});for(let E=0;E<12;E++){const v=-.9+1.8*(E+.5)/12+(m()-.5)*.05,S=.04+m()*.1,k=.005+m()*.009;y.push({points:[[h+.02,v-k],[h-S,v],[h+.02,v+k]].map(f),fill:e,line:!1,smooth:!1})}}return y}function gI(t,{c1:e,c2:o,o:r,A:n,seed:a}){const i=t<.5,l=dn(i?t*2:(t-.5)*2),p=Ji(a),c=[],s=26,h=i?1.4*(1-l):1.4*l,f=i?l:1-l;f>.05&&c.push({points:Hi,fill:o,opacity:Math.max(.02,Math.min(1,f*1.1)),line:!1,smooth:!1});for(let m=0;m<s;m++){const y=(m+p()*.6)/s*2*Math.PI,$=.025+p()*.04,x=h*(.7+p()*.5),E=2,v=(S,k)=>Ra(r[0]+Math.cos(y+k)*S/n,r[1]+Math.sin(y+k)*S);c.push({points:[v(E,-$),v(Math.max(.001,x),0),v(E,$)],fill:m%4===0?o:e,opacity:i?Math.min(1,.4+l):Math.max(.05,1-l),line:!1,smooth:!1})}return Math.abs(t-.5)<.06&&c.push({points:Hi,fill:e,line:!1,smooth:!1}),c.slice(0,64)}function yI(t,{c1:e,c2:o,seed:r}){const n=[],a=t<.5,i=dn(a?t*2:(t-.5)*2),l=(p,c,s)=>{const h=Ji(c),f=[];for(let m=0;m<=30;m++)f.push([p+s*((h()-.5)*.03+(m%2?.012:0)),-.05+1.1*m/30]);return f};if(a){const p=1.08-1.13*i,c=(1-i)*.03,s=l(p,r,1).map(([h,f])=>[h+c*(f-.5),f]);n.push({points:[...s.map(([h,f])=>[h-.015,f+.01]),[1.1,1.06],[1.1,-.06]],fill:"#000000",opacity:.22,line:!1,smooth:!1}),n.push({points:[...s,[1.1,1.05],[1.1,-.05]],fill:e,line:!1,smooth:!1}),n.push({points:[...s,...s.slice().reverse().map(([h,f])=>[h+.012,f])],fill:o,opacity:.8,line:!1,smooth:!1})}else{const p=.62*i,c=l(.5,r+5,1),s=[[-.1,-.05],...c.map(([f,m])=>[f-p-0+(m-.5)*i*.06,m]),[-.1,1.05]],h=[...c.map(([f,m])=>[f+p+(m-.5)*-i*.06,m]),[1.1,1.05],[1.1,-.05]];for(const f of[s,h])n.push({points:f,fill:e,line:!1,smooth:!1});n.push({points:[...c.map(([f,m])=>[f-p+(m-.5)*i*.06,m]),...c.slice().reverse().map(([f,m])=>[f-p-.012+(m-.5)*i*.06,m])],fill:"#ffffff",opacity:.85,line:!1,smooth:!1}),n.push({points:[...c.map(([f,m])=>[f+p-(m-.5)*i*.06,m]),...c.slice().reverse().map(([f,m])=>[f+p+.012-(m-.5)*i*.06,m])],fill:"#ffffff",opacity:.85,line:!1,smooth:!1})}return n}function T0(t,e,o,r,n,a,i,l,p){const s=[],h=[],f=Math.cos(n),m=Math.sin(n);for(let y=0;y<=18;y++){const $=y/18,x=a+i*$,E=l*Math.pow(Math.sin(Math.PI*Math.min(1,$*1.15)),.7);for(const[v,S]of[[s,1],[h,1-E]]){const k=Math.cos(x)*o*S,b=Math.sin(x)*r*S;v.push(Ra(t+(k*f-b*m)/p,e+k*m+b*f))}}return[...s,...h.reverse()]}function bI(t,{c1:e,c2:o,o:r,A:n,seed:a}){const i=t<.5,l=dn(i?t*2:(t-.5)*2),p=[],c=Ji(a),s=(i?l:1+l)*Math.PI*2.4,h=.35+(i?l:1-l)*.6,f=i?.25+l*.75:1-l*.8;for(let m=0;m<4;m++){const y=h*(.55+m*.17),$=s+m*1.3+c()*.2,x=Math.PI*(1.1+.25*m);p.push({points:T0(r[0],r[1],y*1.06,y*.62,.25,$-.1,x*1.03,Math.min(.95,f*1.1),n),fill:e,opacity:.28,line:!1}),p.push({points:T0(r[0],r[1],y,y*.58,.25,$,x,Math.min(.95,f),n),fill:m%2?o:e,line:!1})}if(i&&l>.85&&p.push(Ny(e)),!i){const m=Math.max(.01,l*1.4);p.unshift({loops:[Hi,fi(r[0],r[1],m,.12,a+9,n)],fill:e,line:!1,eo:!0})}return p}const wI={ink:fI,sweep:mI,speed:gI,tear:yI,swirl:bI};function kI(t,{aspect:e=16/9}={}){const o="drawnTransition";if(!t||typeof t!="object")throw Error(`${o}: {kind ${iu.join("|")}, duration?, …}`);const r=t.kind??"ink";if(!iu.includes(r))throw Error(`${o} kind: ${iu.join(" | ")}`);const n=t.duration??1;if(!(lu(n)&&n>=su.duration[0]&&n<=su.duration[1]))throw Error(`${o} duration: ${su.duration.join("–")} s (the frame is covered at the middle, on the cut)`);const a=t.fps??24;if(![12,24].includes(a))throw Error(`${o} fps: 24 (every frame) | 12 (on twos, the anime look)`);const i=hI[r],l=t.color??i.color,p=t.color2??i.color2;if(!j0.test(l)||!j0.test(p))throw Error(`${o} color / color2: #RRGGBB`);const c=t.from??[.5,.5];if(!Array.isArray(c)||c.length!==2||!c.every(m=>lu(m)&&m>=0&&m<=1))throw Error(`${o} from: [x, y] in 0..1 (where it starts: the ink drop, the swirl's centre, where the speed lines meet)`);const s=t.angle??-12;if(!(lu(s)&&s>=-80&&s<=80))throw Error(`${o} angle: −80..80 degrees (the sweep's tilt)`);const h=Math.max(6,Math.round(n*a)),f=e;return Array.from({length:h},(m,y)=>{const $=h>1?y/(h-1):.5,x=1e3+Math.floor(y/(a===24?2:1))*37,v=wI[r]($,{c1:l,c2:p,o:c,A:f,seed:x,angle:s}).slice(0,64).map(S=>{if(S.opacity==null)return S;const k=Math.round(S.opacity*100)/100;if(k>=.99){const{opacity:b,...A}=S;return A}return{...S,opacity:Math.max(.02,k)}});return{parts:v.length?v:[{points:[[.5,.5],[.501,.5],[.5,.501]],fill:l,opacity:.02,line:!1}]}})}const xI=(t,e)=>({start:Math.max(0,Kc(t-e/2)),cut:Kc(t)}),O0=Object.freeze([...Mg,...Cd,"still","morph","boil","step"]),Ie=Object.freeze({paths:Xo.items,points:Xo.points,d:4e3,items:Xo.items}),bo=/^#[0-9a-fA-F]{6}$/,Vt=t=>Number.isFinite(t),vo=(t,e,o)=>Math.max(e,Math.min(o,t)),Te=t=>Math.round(t*10)/10;function Fy(t){let e={};if(typeof t?.prompt=="string"&&t.prompt.trim().startsWith("{"))try{e=JSON.parse(t.prompt)}catch{throw Error(`${t.op} options (prompt) must be JSON`)}const o={...e};for(const[r,n]of Object.entries(t||{}))n!=null&&r!=="prompt"&&(o[r]=n);return o}const Mn=t=>Array.isArray(t?.size)?t.size:t?.square?[720,720]:[1280,720],Yr=(t,e,o)=>{if(!Array.isArray(t)||t.length!==2||!t.every(r=>Vt(r)&&r>=-1&&r<=2))throw Error(`${o}: point ${e} must be [x, y] with x, y in 0..1 of the frame`);return t},sn=/-?\d*\.?\d+(?:e[-+]?\d+)?/gi;function Ry(t,e){if(typeof t!="string"||t.length>Ie.d||!/^\s*M[MLCQZ0-9eE.,\s+-]*$/.test(t))throw Error(`drawShape d: absolute SVG path data (M L C Q Z only), at most ${Ie.d} characters, coordinates 0..1 of the frame`);const o=[...t.matchAll(sn)].map(a=>Number(a[0]));if(o.length%2||!o.length)throw Error("drawShape d: coordinates come in x y pairs");const r=[];for(let a=0;a<o.length;a+=2){const i=e.pt(Yr([o[a],o[a+1]],a/2,"drawShape d"));r.push(Math.round(i[0]),Math.round(i[1]))}let n=0;return t.replace(sn,()=>String(r[n++]))}function MI(t){const[e,o,r,n]=ir(t),a=Te((e+r)/2),i=Te((o+n)/2);let l=0;const p=t.replace(sn,c=>String(Math.round(Number(c)-(l++%2?i:a))));return{d:p,pos:[a,i],box:ir(p)}}function Dy(t,e,o,r,n){if(!t||typeof t!="object"||Array.isArray(t))throw Error(`drawShape paths[${r}] must be an object`);const a=t.color??"#2d3142",i=t.fill??null,l=t.brush??"marker";if(!bo.test(a))throw Error(`drawShape paths[${r}].color must be #RRGGBB`);const p=i&&typeof i=="object"&&!Array.isArray(i);if(p&&!(Array.isArray(i.stops)&&i.stops.length>=2&&i.stops.length<=8&&i.stops.every(E=>Array.isArray(E)&&E.length===2&&bo.test(E[0])&&Vt(E[1])&&E[1]>=0&&E[1]<=1)&&(i.angle==null||Vt(i.angle)&&Math.abs(i.angle)<=360)&&(i.type==null||["linear","radial"].includes(i.type))))throw Error(`drawShape paths[${r}].fill gradient: {stops [[#RRGGBB, 0..1] ×2–8], angle? degrees, type? linear|radial}`);if(i!==null&&!p&&!bo.test(i))throw Error(`drawShape paths[${r}].fill must be #RRGGBB, a gradient {stops, angle?} or null`);if(t.opacity!=null&&!(Vt(t.opacity)&&t.opacity>=0&&t.opacity<=1))throw Error(`drawShape paths[${r}].opacity is 0–1`);if(l!=="none"&&!Ts.includes(l))throw Error(`drawShape brush must be none | ${Ts.join(" | ")}`);if(t.texture!=null&&(!hw(t.texture)||!i))throw Error(`drawShape paths[${r}].texture: {type hatch|crosshatch|halftone|grain|stipple|wash|paper|riso|grid, scale?, angle?, amount?, color?} on a filled path`);const c=t.width==null?.006:Number(t.width);if(!Vt(c)||c<0||c>.06)throw Error(`drawShape paths[${r}].width is a fraction of the frame width, 0–0.06`);for(const E of["taper","press"])if(t[E]!=null&&!(Vt(t[E])&&t[E]>=0&&t[E]<=1))throw Error(`drawShape ${E} must be 0–1`);if(t.boil!=null&&!(Number.isInteger(t.boil)&&t.boil>=0&&t.boil<=24))throw Error("drawShape paths[].boil = re-draws per second 0–24");const s=Da(e);let h,f;if(t.d!=null){const E=MI(Ry(t.d,o));if(!fw(E.d))throw Error(`drawShape paths[${r}].d is not valid path data`);h={d:E.d,box:E.box,...t.closed!=null?{closed:!!t.closed}:{}},f=E.pos}else{const E=Array.isArray(t.points)?t.points:null;if(!E||E.length<2||E.length>Ie.points)throw Error(`drawShape paths[${r}]: points [[x,y]…] (2–${Ie.points}, 0..1 of the frame) or d`);const v=E.map((P,C)=>o.pt(Yr(P,C,`drawShape paths[${r}]`))),S=v.map(P=>P[0]),k=v.map(P=>P[1]),b=Te((Math.min(...S)+Math.max(...S))/2),A=Te((Math.min(...k)+Math.max(...k))/2),I=t.closed??!!i;h={pts:vg(v.map(P=>[P[0]-b,P[1]-A]),{smooth:t.smooth!==!1,closed:I}),closed:I},f=[b,A]}const m=l==="none"?void 0:{style:l,...t.taper!=null?{taper:t.taper}:{},...t.press!=null?{press:t.press}:{},...t.boil?{boil:t.boil}:{},seed:r+1},y=o.len(c),$=()=>p?{type:i.type??"linear",stops:i.stops.map(E=>[E[0],E[1]]),...i.angle!=null?{angle:i.angle}:{},...t.texture?{texture:t.texture}:{}}:{type:"color",color:i,...t.texture?{texture:t.texture}:{}},x={id:s,name:String(t.name??(n?`Stroke ${e.length+1}`:`Nét ${e.length+1}`)).slice(0,40),type:"path",params:h,pos:f,rot:0,scale:[1,1],opacity:t.opacity??1,fill:i?$():{type:"none"},stroke:y>0?{color:a,width:vo(Te(y),.5,240),cap:t.cap??"round",join:"round",...m?{hand:m}:{}}:null,...Number.isInteger(t.role)&&t.role>=0&&t.role<=7?{role:t.role}:{},...Array.isArray(t.span)?{span:t.span}:{}};if(!x.stroke&&x.fill.type==="none")throw Error(`drawShape paths[${r}] needs a width > 0 or a fill`);return x}function $I(t,e,o,r){if(t.solids==null)return[];if(!Array.isArray(t.solids)||t.solids.length>Is.solids)throw Error(`drawShape solids: [{kind, at, size, …}] (≤ ${Is.solids})`);if(t.view!=null&&!_c[t.view]&&t.view!=="perspective")throw Error(`drawShape view: ${[...Object.keys(_c),"perspective"].join(" | ")}`);if(t.view==="perspective"){const[l,p]=[o.k*1e3+2*o.ox,o.k*1e3+2*o.oy].map(Math.round),c=By(t),s=t.solids.map((m,y)=>Ty(m,y)),h=[],f={corridor:["Corridor","Hành lang"],box:["Box","Khối"],panel:["Panel","Tấm"],"wall-panel":["Wall panel","Tấm tường"]};for(const{s:m,parts:y}of Oy(s,{vanish:c,W:l,H:p})){if(!y.length)continue;const $=y.map(I=>({d:"M"+I.pts.map(P=>o.pt(P).map(Math.round).join(" ")).join(" L")+" Z",fill:I.fill,line:!1,role:7})),x=$.flatMap(I=>I.d.match(/-?\d+/g).map(Number)),E=x.filter((I,P)=>P%2===0),v=x.filter((I,P)=>P%2===1),S=Math.round((Math.min(...E)+Math.max(...E))/2),k=Math.round((Math.min(...v)+Math.max(...v))/2),b=$.map(I=>{let P=0;return{...I,d:I.d.replace(/-?\d+/g,C=>String(Number(C)-(P++%2?k:S)))}}),A=Da([...e,...h]);h.push({id:A,name:m.name??`${f[m.kind][r?0:1]} ${e.length+h.length+1}`,type:"art",params:{parts:b,box:[Math.min(...E)-S,Math.min(...v)-k,Math.max(...E)-S,Math.max(...v)-k],outline:!1},pos:[S,k],rot:0,scale:[1,1],opacity:1,fill:{type:"color",color:m.color},stroke:null,role:7})}return h}if(t.light!=null&&!["left","right"].includes(t.light))throw Error("drawShape light: left | right (the lit side)");if(t.shadowColor!=null&&!bo.test(t.shadowColor))throw Error("drawShape shadowColor: #RRGGBB");const n=t.solids.map((l,p)=>({s:WS(l,p),i:p}));t.order!=="given"&&n.sort((l,p)=>(p.s.kind==="plane"&&!p.s.z)-(l.s.kind==="plane"&&!l.s.z)||l.s.at[1]-p.s.at[1]||l.s.z-p.s.z||l.i-p.i);const a=[],i={box:["Box","Khối"],stairs:["Stairs","Cầu thang"],cylinder:["Cylinder","Trụ"],plane:["Plane","Mặt phẳng"],panel:["Panel","Tấm"]};for(const{s:l}of n){const p=XS(l,o,{view:t.view??"iso",light:t.light??"left",shadowColor:t.shadowColor??"#1e1719"}),c=Da([...e,...a]);a.push({id:c,name:l.name??`${i[l.kind][r?0:1]} ${e.length+a.length+1}`,type:"art",params:{parts:p.parts,box:p.box,outline:!1},pos:p.pos,rot:0,scale:[1,1],opacity:1,fill:{type:"color",color:l.color},stroke:null,role:7})}return a}const cu=Object.freeze(["band","brush","iris","slats","grid"]);function vI(t,{target:e,B:o,size:r,en:n,finish:a}){const i=t.wipe;if(!i||typeof i!="object"||Array.isArray(i))throw Error(`drawShape wipe: {style ${cu.join("|")}, duration?, color?, color2?, count?, at?}`);const l=i.style??"band";if(!cu.includes(l))throw Error(`drawShape wipe.style: ${cu.join(" | ")}`);const p=i.duration??t.duration??.9;if(!(Vt(p)&&p>=.2&&p<=4))throw Error("drawShape wipe.duration: 0.2–4 s (the frame is covered at the middle)");const c=i.color??"#c8202f",s=i.color2??c;if(!bo.test(c)||!bo.test(s))throw Error("drawShape wipe.color / color2: #RRGGBB");const h=i.at??[.5,.5];if(!Array.isArray(h)||h.length!==2||!h.every(k=>Vt(k)&&k>=-.5&&k<=1.5))throw Error("drawShape wipe.at: [x, y] (the iris centre, 0..1)");const f=i.count??(l==="slats"?7:l==="grid"||l==="brush"?6:4);if(!(Number.isInteger(f)&&f>=2&&f<=12))throw Error("drawShape wipe.count: 2–12");const m=p/2,y=[...e.items],$=[],x=[],E=(k,b)=>{const A=Dy({brush:"none",width:0,smooth:!1,...k},y,o,y.length,n);y.push(A),$.push(A.id),x.push(b)},v=Jt["expo-in-out"];if(l==="band"){const k=Math.tan((i.angle??20)*Math.PI/180)*.7,b=.5+k+.05;E({points:[[.5-b+k,-.2],[.5+b+k,-.2],[.5+b-k,1.2],[.5-b-k,1.2]],fill:c},{move:[{t:0,dx:-(2*b+k),ease:"ease-in-out"},{t:p,dx:2*b+k}]})}else if(l==="brush"){const k=1/f;for(let b=0;b<f;b++){const A=k*(b+.5),I=b%2?.012:-.012;E({points:[[-.15,A+I],[.3,A-I],[.7,A+I],[1.15,A-I]],color:b%2?s:c,width:.06,brush:"marker",smooth:!0},{trim:[b*m/f*.55,m*.55+b*m/f*.45,m+b*m/f*.45,p]});const P=y.length-1;y[P]={...y[P],stroke:{...y[P].stroke,width:Math.min(240,Math.round(o.len(k*1.25*.5625)))}}}}else if(l==="iris"){const b=h[0],A=h[1],I=Array.from({length:24},(P,C)=>{const z=C/24*2*Math.PI;return[b+Math.cos(z)*1.25*.5625,A+Math.sin(z)*1.25]});E({points:I,fill:c,smooth:!0},{scale:[{t:0,v:0,ease:"expo-in"},{t:m,v:1,ease:"expo-out"},{t:p,v:0}]})}else if(l==="slats")for(let k=0;k<f;k++){const b=k/f,A=(k+1)/f+.002;E({points:[[b,-.05],[A,-.05],[A,1.05],[b,1.05]],fill:k%2?s:c},{scale:[{t:0,sx:0,sy:1,ease:"expo-out"},{t:m*.6+k*m*.4/f,sx:1,sy:1},{t:m+k*m*.4/f,sx:1,sy:1,ease:"expo-in"},{t:Math.min(p,m+m*.6+k*m*.4/f),sx:0,sy:1}]})}else{const k=f,b=Math.max(2,Math.round(f*9/16));for(let A=0;A<b;A++)for(let I=0;I<k;I++){const P=I/k,C=A/b,z=(I+1)/k+.003,N=(A+1)/b+.003,F=(I+A)/(k+b-2);if(y.length-e.items.length>=Ie.items)break;E({points:[[P,C],[z,C],[z,N],[P,N]],fill:(I+A)%2?s:c},{scale:[{t:0,v:0,ease:"back-out"},{t:m*.5+F*m*.5,v:1},{t:m+F*m*.45,v:1,ease:"expo-in"},{t:Math.min(p,m+m*.5+F*m*.45),v:0}]})}}if(y.length>Ie.items)throw Error(`drawShape wipe: too many pieces (max ${Ie.items})`);let S={...e,items:y};return $.forEach((k,b)=>{const A=x[b];if(A.trim){const[I,P,C,z]=A.trim.map(N=>Math.round(N*1e4)/1e4);S={...S,items:S.items.map(N=>N.id!==k?N:{...N,ops:[{op:"trim",start:0,end:1,offset:0}],keys:{"ops.0.end":[{time:I,value:0,ease:v},{time:P,value:1}],"ops.0.start":[{time:C,value:0,ease:v},{time:z,value:1}]}})}}else S={...S,items:Gy(S,[k],A,{stagger:0,add:!1,dur:p,B2:o})}}),{patches:[],layer:{shape:a(S,$,{colors:"keep"}),label:String(t.label??(n?"Transition":"Chuyển cảnh")).slice(0,60),duration:p},note:`drawShape wipe ${l}: covers at ${Math.round((EI(t.start)+m)*100)/100}s (cut there), ${p}s`}}const EI=t=>Number.isFinite(t)?t:0,By=t=>{const e=t.vanish??[.5,.45];if(!Array.isArray(e)||e.length!==2||!e.every(o=>Vt(o)&&o>=-.5&&o<=1.5))throw Error("drawShape vanish: [x, y] of the vanishing point (0..1 of the frame)");return e};function SI(t,{size:e,en:o,finish:r,W:n,H:a}){if(t.view!=="perspective")throw Error("drawShape fly: needs view:'perspective' and solids (a corridor, boxes …)");if(!Array.isArray(t.solids)||!t.solids.length||t.solids.length>Zn.solids)throw Error(`drawShape solids: 1–${Zn.solids} perspective solids`);if(t.paths!=null)throw Error("drawShape fly: draw paths in their own drawShape (over the flying set)");const i=t.fly;if(!i||typeof i!="object")throw Error("drawShape fly: {to (depth units the camera travels), duration s, ease?, fps?, from?}");const[l,p]=Zn.fly;for(const S of["to","from"])if(i[S]!=null&&!(Vt(i[S])&&i[S]>=l&&i[S]<=p))throw Error(`drawShape fly.${S}: ${l}–${p} depth units`);if(!(Vt(i.duration)&&i.duration>=.2&&i.duration<=20))throw Error("drawShape fly.duration: 0.2–20 s");const c=i.fps??24;if(!(Number.isInteger(c)&&c>=8&&c<=24))throw Error("drawShape fly.fps: 8–24");const s=_y(i.ease??"easy-ease","drawShape fly"),h=By(t),f=t.solids.map((S,k)=>Ty(S,k)),m=i.from??0,y=i.to??2,$=Math.max(2,Math.min(fo.frames,Math.round(i.duration*c))),x=[],E=Array.isArray(s)?s:null;for(let S=0;S<$;S++){const k=S/($-1),b=E?II(E,k):k,A=Oy(f,{vanish:h,cam:m+(y-m)*b,W:n,H:a}).flatMap(I=>I.parts).filter(I=>I.pts.length>=3).map(I=>({points:I.pts,fill:I.fill,smooth:!1,line:!1}));if(A.length>fo.parts)throw Error(`drawShape fly: ${A.length} shapes in a frame (max ${fo.parts}) — fewer doors / lines / copies`);x.push({parts:A.length?A:[{points:[[0,0],[0,0],[0,0]],fill:"#000000",smooth:!1}]})}const v=mi({start:t.start,fps:c,frames:x,width:0,brush:"none",label:t.label??(o?"Fly-through":"Máy quay bay vào")},{size:e,en:o,finish:r});return{...v,note:`drawShape fly: camera ${m}→${y} in ${i.duration}s — ${v.note}`}}function II([t,e,o,r],n){const a=(p,c,s)=>3*p*(1-s)**2*s+3*c*(1-s)*s*s+s**3;let i=0,l=1;for(let p=0;p<30;p++){const c=(i+l)/2;a(t,o,c)<n?i=c:l=c}return a(e,r,(i+l)/2)}const P0=Object.freeze(["move","rot","scale","opacity","color","morph"]),_y=(t,e)=>{if(t==null)return;const o=typeof t=="string"?Jt[t]:t;if(o==null)throw Error(`${e}.ease: ${Object.keys(Jt).join(" | ")} or [x1,y1,x2,y2]`);return wu(o)};function AI(t,e,o){const r=o?[...t,t[0]]:t,n=[];let a=0;for(let s=1;s<r.length;s++){const h=Math.hypot(r[s][0]-r[s-1][0],r[s][1]-r[s-1][1]);n.push(h),a+=h}if(!(a>0))return Array.from({length:e},()=>[...t[0]]);const i=[],l=a/(o?e:e-1);let p=0,c=0;for(let s=0;s<e;s++){const h=Math.min(a,s*l);for(;p<n.length-1&&c+n[p]<h;)c+=n[p],p++;const f=n[p]?(h-c)/n[p]:0;i.push([r[p][0]+(r[p+1][0]-r[p][0])*f,r[p][1]+(r[p+1][1]-r[p][1])*f])}return i}function Gy(t,e,o,{stagger:r,add:n,dur:a,B2:i}){if(!o||typeof o!="object"||Array.isArray(o)||!Object.keys(o).length||Object.keys(o).some(y=>!P0.includes(y)))throw Error(`animateShape keys: {${P0.join(" | ")}: [{t (clip s), …, ease?}]}`);const[l,p]=Mn(t),c=i.k,s=y=>(y*l-i.ox)/c,h=y=>(y*p-i.oy)/c,f=y=>Math.round(y*100)/100;let m=0;return t.items.map(y=>{if(!e.includes(y.id))return y;const $=r*m++,x={...y.keys||{}},E=(v,S)=>{const k=n?(x[v]||[]).filter(b=>!S.some(A=>Math.abs(A.time-b.time)<.008333333333333333)):[];if(x[v]=[...k,...S].sort((b,A)=>b.time-A.time),x[v].length>Xo.keys)throw Error(`animateShape keys: at most ${Xo.keys} keys per property`)};for(const[v,S]of Object.entries(o)){const k=`animateShape keys.${v}`;if(!Array.isArray(S)||!S.length||S.length>Xo.keys)throw Error(`${k}: 1–${Xo.keys} keys [{t, …}]`);let b=-1;const A=S.map((P,C)=>{if(!P||typeof P!="object"||!Vt(P.t)||P.t<0||P.t>600)throw Error(`${k}[${C}].t: clip-local seconds (0 = the layer's start)`);const z=Math.round(Math.min(P.t+$,Math.max(0,a))*1e4)/1e4;if(z<=b)throw Error(`${k}: times must increase`);return b=z,{q:P,time:z,ease:_y(P.ease,`${k}[${C}]`)}}),I=P=>A.map(({q:C,time:z,ease:N},F)=>({time:z,value:P(C,F),...N!==void 0?{ease:N}:{}}));if(v==="move"){const P=I((z,N)=>{if(z.x!=null){if(!Vt(z.x))throw Error(`${k}[${N}].x`);return f(s(z.x))}if(z.dx!=null&&!Vt(z.dx))throw Error(`${k}[${N}].dx`);return f(y.pos[0]+(z.dx??0)*l/c)}),C=I((z,N)=>{if(z.y!=null){if(!Vt(z.y))throw Error(`${k}[${N}].y`);return f(h(z.y))}if(z.dy!=null&&!Vt(z.dy))throw Error(`${k}[${N}].dy`);return f(y.pos[1]+(z.dy??0)*p/c)});E("pos.0",P),E("pos.1",C)}else if(v==="rot")E("rot",I((P,C)=>{if(!Vt(P.v))throw Error(`${k}[${C}].v: degrees added to its rest rotation`);return f((y.rot||0)+P.v)}));else if(v==="scale"){const P=C=>(z,N)=>{const F=z[C]??z.v;if(!(Vt(F)&&Math.abs(F)<=10))throw Error(`${k}[${N}]: v (× its size) or sx / sy, -10..10`);return f((y.scale?.[C==="sx"?0:1]??1)*F)};E("scale.0",I(P("sx"))),E("scale.1",I(P("sy")))}else if(v==="opacity")E("opacity",I((P,C)=>{if(!(Vt(P.v)&&P.v>=0&&P.v<=1))throw Error(`${k}[${C}].v: 0–1`);return P.v}));else if(v==="color"){const P=y.fill?.type==="color"&&y.type!=="art"?"fill.color":y.stroke?"stroke.color":null;if(!P)throw Error(`${k}: item ${y.id} has no plain fill or line colour to key`);E(P,I((C,z)=>{if(!bo.test(C.v??""))throw Error(`${k}[${z}].v: #RRGGBB`);return C.v}))}else if(v==="morph"){if(y.type!=="path"||!y.params?.pts)throw Error(`${k}: item ${y.id} is not a point path (draw it with points)`);const P=A.map(({q:N},F)=>{if(!Array.isArray(N.points)||N.points.length<2||N.points.length>Ie.points)throw Error(`${k}[${F}].points: [[x,y]…] (0..1 of the frame)`);return N.points.map((K,_)=>(Yr(K,_,`${k}[${F}]`),[s(K[0])-y.pos[0],h(K[1])-y.pos[1]]))}),C=Math.min(Ie.points,Math.max(...P.map(N=>N.length),y.params.closed?12:4)),z=P.map(N=>vg(AI(N,C,!!y.params.closed).map(F=>[f(F[0]),f(F[1])]),{smooth:!0,closed:!!y.params.closed}));E("params.pts",I((N,F)=>z[F]))}}return{...y,keys:x}})}const ii=t=>{if(!t||!jd(t.shape))throw Error("Needs a Shape layer (clipId of a shape v2 layer)");return t.shape},pu=(t,e,o)=>{if(e==null)return t.items.map(r=>r.id);if(!Array.isArray(e)||!e.length)throw Error(`${o}: itemIds is a list of item ids (get_timeline lists a layer's items)`);for(const r of e)if(!t.items.some(n=>n.id===r))throw Error(`${o}: no item ${String(r).slice(0,20)} in this layer`);return e};function Ud(t,e){const o=Fy(t),r=!!e.en,n=pw(e.W||1280,e.H||720);if(o.style!=null&&!cp(o.style))throw Error(`Unknown 2D style "${String(o.style).slice(0,40)}". Styles: ${nh.join(", ")}`);const a=o.clipId?e.find(o.clipId):null;if(o.clipId&&!a)throw Error("Clip not found");const i=a&&o.op!=="traceMotion"&&o.op!=="rotoscope"?ii(a):{v:2,size:n,items:[]},l=Vr(Mn(i)),p=(c,s,{colors:h=null}={})=>{const f=o.style??c.style2d,m=f?lh(c,f,{itemIds:a?s:null,timing:!a||o.style!=null,colors:h??(o.colors==="keep"?"keep":null)}):c;return He(m)};switch(o.op){case"drawShape":{if(o.fly!=null)return SI(o,{size:n,en:r,finish:p,W:e.W||1280,H:e.H||720});if(o.wipe!=null)return vI(o,{target:i,B:l,size:n,en:r,finish:p});if(o.text!=null)throw Error("drawShape text: written by the Clipoox server (MCP edit_timeline / the AI Editor) — here, send the letters as paths");const c=Array.isArray(o.paths)?o.paths:o.d!=null||o.points!=null?[o]:o.solids!=null?[]:null;if(!c)throw Error("drawShape needs paths [{points | d, …}] or solids [{kind, at, size, …}]");if(c.length>Ie.paths)throw Error(`drawShape: at most ${Ie.paths} paths per op`);const s=[...i.items],h=[];for(const m of $I(o,s,l,r))s.push(m),h.push(m.id);if(c.forEach((m,y)=>{const $=Dy(m,s,l,y,r);s.push($),h.push($.id)}),!h.length)throw Error("drawShape needs paths [{points | d, …}] or solids [{kind, at, size, …}]");if(o.write!=null){const m=o.write;if(typeof m!="object"||Array.isArray(m))throw Error("drawShape write: {at? (clip s), duration? s per path, stagger? s, fill? true}");for(const[v,S,k]of[["at",0,600],["duration",.05,10],["stagger",0,5]])if(m[v]!=null&&!(Vt(m[v])&&m[v]>=S&&m[v]<=k))throw Error(`drawShape write.${v}: ${S}–${k} s`);const y=m.at??0,$=m.duration??.5,x=m.stagger??$*.6;let E=0;for(let v=0;v<s.length;v++){const S=s[v];if(!h.includes(S.id)||S.type!=="path")continue;const k=y+x*E++;let b=S.stroke?sh(S,"draw-on",{at:k,duration:$}):S;m.fill!==!1&&b.fill?.type==="color"&&(b={...b,keys:{...b.keys||{},"fill.opacity":[{time:Math.round(k*1e4)/1e4,value:0},{time:Math.round((k+$*.65)*1e4)/1e4,value:0,ease:Jt["ease-out"]},{time:Math.round((k+$)*1e4)/1e4,value:1}]}}),s[v]=b}}if(s.length>Ie.items)throw Error(`A Shape layer holds up to ${Ie.items} items — draw into a new layer (leave clipId out)`);const f=p({...i,items:s},h);return a?{patches:[{id:a.id,shape:f}],note:`drawShape: ${h.length} item(s) → ${a.label}`}:{patches:[],layer:{shape:f,label:String(o.label??(r?"Drawing":"Hình vẽ")).slice(0,60)},note:`drawShape: ${h.length} item(s), new layer`}}case"addLibraryShape":{const c=Array.isArray(o.items)&&o.items.length&&typeof o.items[0]=="object"?o.items:o.libraryId||o.id?[o]:null;if(!c)throw Error("addLibraryShape needs items [{id (from search_shape_library), x, y, size?}]");if(c.length>Ie.items)throw Error(`addLibraryShape: at most ${Ie.items} items per op`);const s=[...i.items],h=[],[f,m]=Mn(i),y=Math.min(f,m)/1e3;if(c.forEach((x,E)=>{const v=x.libraryId??x.id,S=x.x??.5,k=x.y??.5;Yr([S,k],E,"addLibraryShape");const b=x.size??.25;if(!(Vt(b)&&b>=.02&&b<=1.5))throw Error("addLibraryShape size = height as a fraction of the frame, 0.02–1.5");const A=x.rotation??0;if(!(Vt(A)&&Math.abs(A)<=360))throw Error("addLibraryShape rotation is degrees");const I=vy(v,{id:Da(s),pos:l.pt([S,k]),colors:x.colors??null,en:r}),P=Math.max(1,I.params.box[3]-I.params.box[1]),C=vo(Te(b*m/y/P*100)/100,.02,10),z={...I,rot:Te(A),scale:[x.flip?-C:C,C],...x.name?{name:String(x.name).slice(0,40)}:{},...Array.isArray(x.span)?{span:x.span}:{}};s.push(z),h.push(z.id)}),s.length>Ie.items)throw Error(`A Shape layer holds up to ${Ie.items} items — add into a new layer (leave clipId out)`);const $=p({...i,items:s},h);return a?{patches:[{id:a.id,shape:$}],note:`addLibraryShape: ${h.length} → ${a.label}`}:{patches:[],layer:{shape:$,label:String(o.label??(r?"2D scene":"Cảnh 2D")).slice(0,60)},note:`addLibraryShape: ${h.length}, new layer`}}case"applyStyle2d":{if(!o.style)throw Error(`applyStyle2d needs style: ${nh.join(", ")}`);const s=(Array.isArray(o.clipIds)&&o.clipIds.length?o.clipIds:o.clipId?[o.clipId]:e.clips.filter(m=>jd(m.shape)&&!Ky(m)).map(m=>m.id)).map(m=>{const y=e.find(m);if(!y)throw Error(`Clip ${String(m).slice(0,30)} not found`);return ii(y),y}).filter(m=>!e.isLocked?.(m));if(!s.length)throw Error("applyStyle2d: no Shape layer to style");if(o.colors!=null&&o.colors!=="keep"&&o.colors!=="style")throw Error("applyStyle2d colors: keep (the drawing keeps its own colours) | style (the style palette, default)");const h=s.map(m=>({id:m.id,shape:He(lh(m.shape,o.style,{itemIds:o.itemIds&&o.clipId?pu(m.shape,o.itemIds,"applyStyle2d"):null,timing:o.timing!==!1,colors:o.colors==="keep"?"keep":null}))}));let f=null;if(o.paper!==!1&&o.paper!=null){const m=Math.min(...s.map($=>$.start)),y=Math.max(...s.map($=>$.start+$.duration));f={shape:He(cw(o.style,n)),label:`${r?"Paper":"Giấy"} · ${r?cp(o.style).en:cp(o.style).vi}`.slice(0,60),start:m,duration:y-m}}return{patches:h,paper:f,note:`applyStyle2d ${o.style}: ${h.length} layer(s)${f?" + paper":""}`}}case"animateShape":{let c=ii(a);const s=pu(c,o.itemIds,"animateShape"),h=S=>Math.max(0,Math.min(a.duration,(S??a.start)-a.start)),f=o.preset;if(f==="boil"){const S=typeof o.boil=="number"?{amount:o.boil,fps:8}:o.boil??{amount:2,fps:8};if(!sw(S))throw Error("animateShape boil = {amount 0–24 (frame units ×1000), fps 1–24}");const k={...c,boil:S};return S.amount||delete k.boil,{patches:[{id:a.id,shape:He(k)}],note:`boil ${S.amount}@${S.fps}fps: ${a.label}`}}if(f==="step"){const S=o.step??2;if(![1,2,3].includes(S))throw Error("animateShape step = 1 | 2 | 3 (animate on ones / twos / threes)");const k={...c,step:S};return S===1&&delete k.step,{patches:[{id:a.id,shape:He(k)}],note:`on ${S}s: ${a.label}`}}const m=h(o.at),y=Vt(o.duration)?o.duration:1,$=Vt(o.stagger)?vo(o.stagger,0,5):0;if(o.keys!=null){const S=Gy(c,s,o.keys,{stagger:$,add:o.add===!0,dur:a.duration,B2:Vr(Mn(c))});return{patches:[{id:a.id,shape:He({...c,items:S})}],note:`keys ${Object.keys(o.keys).join(", ")}: ${s.length} item(s) of ${a.label}`}}if(f==null&&o.pivot==null&&o.parent==null)throw Error(`animateShape preset: ${O0.join(" | ")}`);const x=Cd.includes(f)||f==="still"||f==null;if(x||o.pivot!=null||o.parent!=null){if(o.parent!=null&&!(typeof o.parent=="string"&&c.items.some(z=>z.id===o.parent)))throw Error("animateShape parent: an item id of this layer (the item the others follow)");if(o.parent!=null&&s.includes(o.parent))throw Error("animateShape parent: an item cannot follow itself");const S=Vr(Mn(c)),k=$g[f],b=Vt(o.amount)?vo(o.amount,0,8):1,A=Vt(o.period)?vo(o.period,.1,60):null,I=s.length;let P=0;const C=c.items.map(z=>{if(!s.includes(z.id))return z;let N={...z};o.parent!=null&&(N.parent=o.parent);const F=o.pivot??(k&&!z.pivot?k.pivot:null);if(F!=null&&(N=gd(N,md(N,F,S))),f==="still"){const{motion:K,..._}=N;return _}if(k&&x){const K=A??k.period,_=I>1?$?P*$/K%1:f==="rise"?P/I:0:0,q={type:f,...b!==1?{amount:Math.round(k.amount*b*1e4)/1e4}:{},...A?{period:A}:{},..._?{phase:Math.round(_*1e3)/1e3}:{},...o.at!=null&&m>0?{delay:Math.round(m*1e3)/1e3}:{}},U=[...(N.motion||[]).filter(rt=>rt.type!==f),q];if(U.length>ih.perItem)throw Error(`An item takes up to ${ih.perItem} looping motions (preset still clears them)`);N.motion=U}return P++,N});if(x)return{patches:[{id:a.id,shape:He({...c,items:C})}],note:`${f??"rig"}: ${s.length} item(s) of ${a.label}`};c={...c,items:C}}if(f==="morph"){if(s.length!==1)throw Error("animateShape morph takes one itemId");const S=c.items.find(I=>I.id===s[0]),k=Vr(Mn(c));let b;if(o.toItemId){const I=c.items.find(P=>P.id===o.toItemId);if(!I?.params?.pts)throw Error("morph toItemId must be a point path");b=I.params.pts.map(P=>[P[0]+I.pos[0]-S.pos[0],P[1]+I.pos[1]-S.pos[1]])}else{if(!Array.isArray(o.to)||o.to.length<2||o.to.length>Ie.points)throw Error("morph needs to [[x,y]…] (0..1 of the frame) or toItemId");b=o.to.map((I,P)=>{Yr(I,P,"morph");const C=k.pt(I);return[C[0]-S.pos[0],C[1]-S.pos[1]]})}const A=c.items.map(I=>I.id===S.id?lw(I,b,{at:m,duration:y}):I);return{patches:[{id:a.id,shape:He({...c,items:A})}],note:`morph ${S.name}`}}if(!Mg.includes(f))throw Error(`animateShape preset: ${O0.join(" | ")}`);let E=0;const v=c.items.map(S=>s.indexOf(S.id)<0?S:sh(S,f,{at:Math.min(a.duration-1/30,m+$*E++),duration:y,amount:Vt(o.amount)?o.amount:1,count:Vt(o.count)?o.count:1}));return{patches:[{id:a.id,shape:He({...c,items:v})}],note:`${f}: ${s.length} item(s) of ${a.label}`}}case"editFrames":{if(!a)throw Error("editFrames needs clipId: a frame layer (drawFrames, Vẽ Animation, or one drawn in the frame editor)");const c=ii(a),s=o.ink??"#1d1a17";if(!bo.test(s))throw Error("editFrames ink: #RRGGBB");const h=o.width??.004;if(!(Vt(h)&&h>0&&h<=.03))throw Error("editFrames width: ink line width, a fraction of the frame width (e.g. 0.004)");const f=Ly(c,{...o,at:o.at},{ink:s,width:vo(Te(Vr(Mn(c)).len(h)),.5,240)});return{patches:[{id:a.id,shape:He(f.shape),...f.end>a.duration+1e-6?{duration:Math.ceil(f.end*30)/30}:{}}],note:`editFrames ${o.action}: ${f.note}`}}case"drawnTransition":{if(!Vt(o.at)||o.at<0)throw Error("drawnTransition at: the cut, timeline seconds");const c=kI(o,{aspect:n[0]/n[1]}),s=o.duration??1,{start:h}=xI(o.at,s),f=mi({op:"drawFrames",fps:o.fps??24,frames:c,width:0,brush:"none",outline:!1,label:o.label??(r?"Transition":"Chuyển cảnh")},{size:n,en:r,finish:p});return{...f,layers:f.layers.map(m=>({...m,start:m.start+h})),startAbs:!0,...o.motion!==!1?{shakeAt:o.at}:{},note:`drawnTransition ${o.kind??"ink"}: ${c.length} drawings, covers the frame at ${o.at}s (cut there)${o.motion!==!1?", the shots shake at the cut":""}`}}case"traceImage":return zI(o,{into:a,target:i,size:n,ctx:e,en:r,finish:p});case"drawFrames":return mi(o,{size:n,en:r,finish:p});case"animatePuppet":{const c=o.look==="stick"||o.character?.startsWith?.("stick")||Array.isArray(o.cast)&&o.cast.some(F=>String(F?.character??"").startsWith("stick")),s=o.fps??(c?30:Aa[o.character]?24:12);if(o.look!=null&&!["ink","clean","stick"].includes(o.look))throw Error("animatePuppet look: ink (hand-drawn outline) | clean (no outline around the shapes, fine detail lines only) | stick (stick figures: thick round limbs, a round head, motion trails)");const h=o.look==="clean",f=h?o.width??.0022:o.width??.0028,m=e.W||1280,y=e.H||720,$=F=>h?F.map(K=>({...K,parts:K.parts.map(_=>_.fill?{..._,line:!1}:_)})):F,x=(F,K)=>{const _=!!Aa[F.character],q=_?wS:$u,U=F.colors??null;if(U!=null&&(typeof U!="object"||Array.isArray(U)||Object.entries(U).some(([rt,ot])=>!q.includes(rt)||!bo.test(ot))))throw Error(`${K} colors: {${q.join(" | ")}: '#RRGGBB'}`);for(const[rt,ot,G]of[["x",-.5,1.5],["ground",.2,1.2],["size",.04,1.2]])if(F[rt]!=null&&!(Vt(F[rt])&&F[rt]>=ot&&F[rt]<=G))throw Error(`${K} ${rt}: ${ot}–${G} (fractions of the frame)`);if(F.facing!=null&&!["left","right"].includes(F.facing))throw Error(`${K} facing: left | right`);if(F.hair!=null&&!ac.includes(F.hair))throw Error(`${K} hair: ${ac.join(" | ")} (stick figures)`);if(F.eyes!=null&&!ic.includes(F.eyes))throw Error(`${K} eyes: ${ic.join(" | ")} (stick figures)`);if(F.grip!=null&&!qh.includes(F.grip))throw Error(`${K} grip: ${qh.join(" | ")} (how the weapon is held when resting, walking, waiting)`);if(F.height!=null&&!(Vt(F.height)&&F.height>=.6&&F.height<=1.4))throw Error(`${K} height: 0.6–1.4 (× size)`);if(F.weight!=null&&!(Vt(F.weight)&&F.weight>=.6&&F.weight<=2))throw Error(`${K} weight: 0.6–2 (how thick a stick figure is drawn)`);return{pres:_,colors:U}},E=[];let v=null,S=null;if(o.store!=null&&!["rig","frames"].includes(o.store))throw Error("animatePuppet store: rig (the skeletons, drawn as it plays: small, long, editable with editPose) | frames (every drawing baked in)");if(o.toon!=null&&!(Vt(o.toon)&&o.toon>=0&&o.toon<=1))throw Error("animatePuppet toon: 0–1 (anticipation, overshoot and pose-to-pose snap; stick figures 0.6, costumed 0.4)");const k=o.store!=="frames",b=k?Math.min(iw.frames,1800):480,A=[];if(o.scene!=null&&!dd.includes(o.scene))throw Error(`animatePuppet scene: ${dd.join(" | ")} (a painted backdrop in depth layers that moves with the camera)`);const I=String(o.label??(r?"Puppet":"Nhân vật")).slice(0,40);if(o.cast!=null){if(!Array.isArray(o.cast)||o.cast.length<1||o.cast.length>4)throw Error("animatePuppet cast: 1–4 characters [{character, x, facing?, actions?, …}] (beats: 2–4 fighters)");if(o.cast.forEach((F,K)=>{if(!F||typeof F!="object")throw Error(`animatePuppet cast[${K}] must be an object`);x(F,`animatePuppet cast[${K}]`)}),o.beats!=null){if(o.cast.some(K=>Aa[K.character]))throw Error("animatePuppet beats: fighters are side-view puppets (fighter | monk | villager | brawler)");if(o.accent!=null&&!bo.test(o.accent))throw Error("animatePuppet accent: #RRGGBB (the impact sparks)");if(o.energy!=null&&!bo.test(o.energy))throw Error("animatePuppet energy: #RRGGBB (the glow of beams, energy slashes, teleports)");if(o.dust!=null&&!bo.test(o.dust))throw Error("animatePuppet dust: #RRGGBB (the dust puffs on the ground)");if(o.tempo!=null&&!(Vt(o.tempo)&&o.tempo>=.5&&o.tempo<=2.5))throw Error("animatePuppet tempo: 0.5–2.5 (× speed of the whole fight; stick figures default 1.35)");if(o.motion!=null&&!["mocap","drawn"].includes(o.motion))throw Error("animatePuppet motion: mocap (real motion capture for stick fighters, the default) | drawn (the drawn moves)");if(o.camera!=null&&!["follow","fixed","director"].includes(o.camera))throw Error("animatePuppet camera: follow (frames the pair, glides after them, punches in on a hit; stick fights default) | director (cuts like a filmed fight: a close-up on each blow, a reaction shot, wide between exchanges) | fixed");const F=TS({cast:o.cast,beats:o.beats,fps:s,fx:o.fx!==!1,accent:o.accent??"#ffd23f",W:m,H:y,stick:o.look==="stick",dust:o.dust??"#c9bfb2",tempo:o.tempo??null,camera:o.camera??null,mocap:o.motion==="drawn"?null:o.mocapClips??null,energyColor:o.energy??"#ff4fd8",toon:o.toon??null,maxFrames:b});S={camera:F.camera,duration:F.duration,ground:Math.max(...o.cast.map(K=>K.ground??.9))},F.actors.forEach((K,_)=>E.push({frames:K.frames,track:F.tracks[_],start:0,label:`${I} ${_+1}`})),A.push(...F.reports),F.fx.forEach((K,_)=>E.push({frames:K.frames,start:K.start,label:`${r?"Impact":"Va chạm"} ${_+1}`,ink:o.accent??"#ffd23f",width:.0022})),v=`fight: ${o.beats.length} beat(s), impacts at ${F.impacts.map(K=>K.t+"s").join(" ").slice(0,160)} (add impact sfx / cameraShake there)`}else o.cast.forEach((F,K)=>{const _=Aa[F.character]?h0({...F,fps:s,W:m,H:y}):Yh({...F,character:F.character??"fighter",fps:s,W:m,H:y,stick:o.look==="stick",mocap:o.mocapClips??null,toon:o.toon??null,maxFrames:b});E.push({frames:_.frames,..._.track?{track:_.track}:{},start:0,label:`${I} ${K+1}`}),_.report&&A.push(_.report)})}else if(x(o,"animatePuppet"),Aa[o.character]){if(o.speech!=null&&(!Array.isArray(o.speech)||o.speech.length>200||o.speech.some(K=>!K||typeof K.text!="string"||!Vt(K.start)||!Vt(K.end)||K.end<=K.start)))throw Error("animatePuppet speech: [{text, start, end}] (s from the op start; a line, or each word from get_transcript)");const F=h0({character:o.character,colors:o.colors??null,x:o.x??.5,ground:o.ground??.96,size:o.size??.8,fps:s,actions:o.actions,speech:o.speech??null,W:m,H:y});E.push({frames:F.frames,start:0,label:I})}else{const F=Yh({character:o.character??"fighter",colors:o.colors??null,x:o.x??.4,ground:o.ground??.9,size:o.size??.55,facing:o.facing??"right",fps:s,actions:o.actions,W:m,H:y,stick:o.look==="stick",grip:o.grip??null,mocap:o.mocapClips??null,hair:o.hair??null,eyes:o.eyes??null,weight:o.weight??null,height:o.height??null,toon:o.toon??null,maxFrames:b});E.push({frames:F.frames,track:F.track,start:0,label:I}),A.push(F.report)}const P=[];let C=[];if(o.scene){const F=S?.duration??Math.max(...E.map(K=>K.start+K.frames.length/s));for(const K of BS(o.scene,{size:n,camera:S?.camera??null,fps:s,duration:F,ground:S?.ground??o.ground??.9,finish:p,en:r}))P.push(K)}for(const F of E){if(k&&F.track){const _=L0(F.track,{label:F.label,size:n,clean:h,width:f,ink:o.ink,brush:o.brush,finish:p});P.push({..._,start:_.start+F.start}),C.push(_.note);continue}const K=mi({start:o.start,fps:s,frames:F.ink?F.frames:$(F.frames),width:F.width??f,ink:F.ink??o.ink,brush:F.ink?"none":o.brush,label:F.label},{size:n,en:r,finish:p});for(const _ of K.layers)P.push({..._,start:_.start+F.start});C.push(K.note)}const z=o.cast?`${o.cast.length} character(s)`:o.character??"fighter",N=A.length?` — ${ax(A)}`:"";return{patches:[],layers:P,frameLayers:!0,note:`animatePuppet ${z}${v?` — ${v}`:`: ${(o.actions||[]).map(F=>F.move??F.mocap).join(" → ").slice(0,120)}`} — ${C[0]}${E.length>1?` (+${E.length-1} more sequence(s))`:""}${N}`}}case"editPose":{if(!a)throw Error("editPose needs clipId: a character layer made by animatePuppet (store rig)");const c=ii(a),s=c.items.findIndex(A=>A.type==="art"&&A.params?.rig);if(s<0)throw Error("editPose: this layer has no skeletons — make the character with animatePuppet (store: rig, the default) to edit its poses");const h=c.items[s],f=rx(h.params.rig),m=f.frames.length/f.fps;if(!Uh[o.joint])throw Error(`editPose joint: ${Object.keys(Uh).join(" | ")}`);if(!(Vt(o.at)&&o.at>=0&&o.at<=m))throw Error(`editPose at: s from the layer's start, 0–${Math.round(m*100)/100}`);const y=o.dx??0,$=o.dy??0,x=o.span??.3;if(!Vt(y)||!Vt($)||Math.abs(y)>.5||Math.abs($)>.5)throw Error("editPose dx, dy: how far the joint moves, fractions of the frame (−0.5..0.5; dy < 0 = up)");if(!(Vt(x)&&x>=.04&&x<=3))throw Error("editPose span: s the change eases in and out over around `at`, 0.04–3");if(!y&&!$)throw Error("editPose: give dx and / or dy");const E=y*f.W/(f.fs*f.k),v=$*f.H/f.k;let S=0;f.frames.forEach((A,I)=>{const P=I/f.fps,C=Math.abs(P-o.at)/x;if(C>=1)return;const z=1-C*C*C*(C*(6*C-15)+10);A.J=nx(A.J,o.joint,[E*z,v*z]),S++});const k=Cg(f),b=c.items.map((A,I)=>I===s?{...A,params:{...A.params,rig:k}}:A);return{patches:[{id:a.id,shape:He({...c,items:b})}],note:`editPose ${o.joint} at ${o.at}s: ${S} drawing(s) changed`}}case"traceMotion":{if(!a||a.kind!=="video")throw Error("traceMotion needs clipId: a video clip on the timeline (the person whose motion the character copies)");const c=o.character??"stickman";if(!Qn[c])throw Error(`traceMotion character: a side-view character (${Object.keys(Qn).join(" | ")})`);OI(o,"traceMotion");const s=o.from??0,h=a.duration,f=o.duration??Math.min(60,h-s),m=o.fps??30,y=o.person??1;if(!(Vt(s)&&s>=0&&s<h))throw Error(`traceMotion from: s into the video clip, 0–${Math.round(h*100)/100}`);if(!(Vt(f)&&f>=.5&&f<=60&&s+f<=h+1e-6))throw Error("traceMotion duration: 0.5–60 s, inside the video clip");if(!(Number.isInteger(m)&&m>=12&&m<=30))throw Error("traceMotion fps: 12–30 (30 = every frame)");if(!(y===1||y===2))throw Error("traceMotion person: 1 | 2 (counted from the left when there are two people)");if(o.mode!=null&&!["trace","place"].includes(o.mode))throw Error("traceMotion mode: trace (drawn right over the person, default) | place (moved to x, ground, size)");const $=o.mode==="place"?{x:o.x??.5,ground:o.ground??.9,size:o.size??.5}:null,x={...o.hair!=null?{hair:o.hair}:{},...o.eyes!=null?{eyes:o.eyes}:{},...o.weight!=null?{weight:o.weight}:{},...o.colors?{colors:o.colors}:{},...o.look==="stick"&&Qn[c].look!=="stick"?{stick:!0}:{}},E=e.W||1280,v=e.H||720,S=Ag({character:c,...x,x:$?.x??.5,ground:$?.ground??.9,size:$?.size??.5,fps:m,W:E,H:v,actions:[{move:"idle",duration:.2}],toon:0,law:!1});S.frames=S.frames.slice(0,1);const k=L0(S,{label:String(o.label??(r?"Character from video":"Người theo video")).slice(0,40),size:n,clean:o.look==="clean",width:o.width??.0028,ink:o.ink,brush:o.brush,finish:p});k.shape.items[0].opacity=.45,k.shape.items[0].span=[0,Math.round(f*1e4)/1e4];const b=a.start+s-(Vt(o.start)?o.start:0);return{patches:[],frameLayers:!0,layers:[{...k,start:b,duration:f,clientJob:{kind:"pose-track",op:"traceMotion",params:{source:a.id,from:s,duration:f,fps:m,person:y,character:c,style:x,place:$,W:E,H:v}}}],note:`traceMotion: a ${c} layer following the person in "${String(a.label??"video").slice(0,40)}" (${Math.round(f*100)/100}s) — the open Clipoox editor follows the person and fills it in (get_pending_jobs)`}}case"rotoscope":{if(!a||a.kind!=="video")throw Error("rotoscope needs clipId: a 2D video clip on the timeline (its figures are drawn frame by frame)");const c=!!JS(o).flat,s=tI(o),{fps:h,from:f,duration:m,n:y}=QS(o,a.duration,fo.frames),$=o.ink??"#1a0508";if(!bo.test($))throw Error("rotoscope ink: #RRGGBB");if(Py(o.fx,"rotoscope"),typeof o.job!="string"||!jI.test(o.job))throw Error("rotoscope is paid (Vẽ Animation, 0.2 credit a second): start it from the Shape tab, or through MCP edit_timeline (dry_run for the price, then max_credits)");const x=String(o.label??(r?"Animation":"Vẽ Animation")).slice(0,40),E=a.start+f-(Vt(o.start)?o.start:0),v=e.W||1280,S=e.H||720,k=[];if(c&&s==="plate"){const b=mi({op:"rotoscope",fps:h,width:0,brush:"none",label:x,frames:[{parts:[z0],hold:1}]},{size:n,en:r,finish:p}).layers[0];b.shape.items[0].span=[0,Math.round(y/h*1e4)/1e4],k.push({...b,label:`${x} · ${r?"backdrop":"nền"}`.slice(0,60),start:E,duration:y/h,clientJob:{kind:"rotoscope",op:"rotoscope",params:{job:o.job,backdrop:!0,first:0,count:y,fps:h,ink:$,W:v,H:S,label:`${x} · ${r?"backdrop":"nền"}`.slice(0,40)}}})}for(const b of c&&s==="keep"?[0,1]:[null])for(let A=0,I=0;A<y;A+=Ie.items,I++){const P=Math.min(Ie.items,y-A),C=mi({op:"rotoscope",fps:h,width:0,brush:"none",label:x,frames:[{parts:[z0],hold:P}]},{size:n,en:r,finish:p}).layers[0],z=`${y>Ie.items?`${x} ${I+1}`:x}${b===1?` · ${r?"front":"trước"}`:""}`;k.push({...C,label:z,start:E+A/h,duration:P/h,clientJob:{kind:"rotoscope",op:"rotoscope",params:{job:o.job,first:A,count:P,fps:h,ink:$,fx:b===1?null:o.fx??null,W:v,H:S,label:z.slice(0,40),...b!=null?{half:b}:{}}}})}return{patches:[],frameLayers:!0,layers:k,rotoscope:{job:o.job,clipId:a.id,fps:h,from:f,duration:m,n:y},note:`rotoscope: ${y} drawing(s) of "${String(a.label??"video").slice(0,40)}" at ${h} fps on ${k.length} layer(s)${c&&s==="plate"?" (the first: the backdrop)":""} — drawn by the Vẽ Animation job`}}case"arrangeShape":{const c=ii(a),s=pu(c,o.itemIds,"arrangeShape"),h=o.action;let f=[...c.items];if(h==="group"){const m=String(o.group??`g${Date.now().toString(36).slice(-5)}`).replace(/[^a-z0-9-]/gi,"").slice(0,16)||"g1";f=f.map(y=>s.includes(y.id)?{...y,group:m}:y)}else if(h==="ungroup")f=f.map(m=>{if(!s.includes(m.id))return m;const{group:y,...$}=m;return $});else if(h==="front"||h==="back"){const m=f.filter($=>s.includes($.id)),y=f.filter($=>!s.includes($.id));f=h==="front"?[...y,...m]:[...m,...y]}else if(h==="forward"||h==="backward")for(const m of h==="forward"?[...s].reverse():s){const y=f.findIndex(x=>x.id===m),$=h==="forward"?y+1:y-1;$>=0&&$<f.length&&([f[y],f[$]]=[f[$],f[y]])}else if(ah.includes(h))f=f.map(m=>{if(!s.includes(m.id))return m;const y=(m.ops||[]).filter($=>$.op!=="merge");if(y.length>=8)throw Error("An item takes up to 8 operators");return{...m,ops:[...y,{...ys("merge"),mode:h}]}});else if(h==="move"){const m=o.dx??0,y=o.dy??0;if(!Vt(m)||!Vt(y)||Math.abs(m)>1||Math.abs(y)>1)throw Error("arrangeShape move: dx, dy are fractions of the frame (−1..1)");const[$,x]=Mn(c),E=Math.min($,x)/1e3;f=f.map(v=>s.includes(v.id)?{...v,pos:[Te(v.pos[0]+m*$/E),Te(v.pos[1]+y*x/E)]}:v)}else if(h==="hide"||h==="show")f=f.map(m=>{if(!s.includes(m.id))return m;if(h==="hide")return{...m,hidden:!0};const{hidden:y,...$}=m;return $});else throw Error(`arrangeShape action: group | ungroup | front | back | forward | backward | move | hide | show | ${ah.join(" | ")}`);return{patches:[{id:a.id,shape:He({...c,items:f})}],note:`arrange ${h}: ${s.length} item(s)`}}}throw Error(`Unknown 2D op ${o.op}`)}function md(t,e,o){if(typeof e=="string"){const n=uw(e,dw(t));if(!n)throw Error(`pivot: ${ch.join(" | ")} or [x, y] of the frame`);return n}if(!Array.isArray(e)||e.length!==2)throw Error(`pivot: ${ch.join(" | ")} or [x, y] of the frame`);Yr(e,0,"pivot");const r=Ms(rc(Jn({...t})),...o.pt(e));return[Te(r[0]),Te(r[1])]}function gd(t,e){const o=Jn(t),r=Jn({...t,pivot:e}),n=o[4]-r[4],a=o[5]-r[5],i={...t,pivot:e,pos:[Te(t.pos[0]+n),Te(t.pos[1]+a)]};return t.keys&&(t.keys["pos.0"]||t.keys["pos.1"])&&(i.keys={...t.keys},t.keys["pos.0"]&&(i.keys["pos.0"]=t.keys["pos.0"].map(l=>({...l,value:Te(l.value+n)}))),t.keys["pos.1"]&&(i.keys["pos.1"]=t.keys["pos.1"].map(l=>({...l,value:Te(l.value+a)})))),i}const z0={points:[[0,0],[1,0],[1,1],[0,1]],fill:"#000000",opacity:.06,line:!1,smooth:!1},CI={points:[[.5,.5],[.501,.5],[.5,.501]],fill:"#000000",opacity:.02,line:!1,smooth:!1},jI=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;function ij(t,e,{en:o=!1}={}){const r=e||{},n=Array.isArray(t)?{frames:t}:t||{},a=r.fps??24;if(r.backdrop){if(!Array.isArray(n.backdrop)||!n.backdrop.length)throw Error("rotoscope: the job has no backdrop for this layer");const c=Ud({op:"drawFrames",fps:a,ink:r.ink??"#1a0508",width:.0028,brush:"none",label:r.label,frames:[{parts:n.backdrop}]},{clips:[],find:()=>null,W:r.W||1280,H:r.H||720,en:o}).layers[0].shape;return c.items[0].span=[0,Math.round((r.count??1)/a*1e4)/1e4],{shape:c}}const i=(Array.isArray(n.frames)?n.frames:[]).slice(r.first??0,(r.first??0)+(r.count??24));if(!i.length)throw Error("rotoscope: the job has no drawings for this layer");const l=r.half==null?i:i.map(p=>{const c=Number.isInteger(p?.split)?p.split:p?.parts?.length??0;return{parts:r.half===1?(p?.parts??[]).slice(c):(p?.parts??[]).slice(0,c)}});return{shape:TI(l,r,{en:o})}}function TI(t,e,{en:o}){return Ud({op:"drawFrames",fps:e.fps??24,ink:e.ink??"#1a0508",width:.0028,brush:"none",label:e.label,...e.fx?{fx:e.fx}:{},frames:t.map(n=>({parts:Array.isArray(n?.parts)&&n.parts.length?n.parts:[CI]}))},{clips:[],find:()=>null,W:e.W||1280,H:e.H||720,en:o}).layers[0].shape}function OI(t,e){if(t.hair!=null&&!ac.includes(t.hair))throw Error(`${e} hair: ${ac.join(" | ")} (stick figures)`);if(t.eyes!=null&&!ic.includes(t.eyes))throw Error(`${e} eyes: ${ic.join(" | ")} (stick figures)`);if(t.weight!=null&&!(Vt(t.weight)&&t.weight>=.6&&t.weight<=2))throw Error(`${e} weight: 0.6–2 (how thick a stick figure is drawn)`);if(t.colors!=null&&(typeof t.colors!="object"||Array.isArray(t.colors)||Object.entries(t.colors).some(([o,r])=>!$u.includes(o)||!bo.test(r))))throw Error(`${e} colors: {${$u.join(" | ")}: '#RRGGBB'}`);for(const[o,r,n]of[["x",-.5,1.5],["ground",.2,1.2],["size",.04,1.2]])if(t[o]!=null&&!(Vt(t[o])&&t[o]>=r&&t[o]<=n))throw Error(`${e} ${o}: ${r}–${n} (fractions of the frame)`)}function L0(t,{label:e,size:o,clean:r,width:n,ink:a="#2a1d14",brush:i="ink",finish:l}){const p=Cg(t),c=p.n/p.fps,s=Vr(o),h=s.pt([.5,.5]),f=s.pt([0,0]),m=s.pt([1,1]),y=t.ch.look==="stick",$=s.len(n);if(!bo.test(a))throw Error("animatePuppet ink: #RRGGBB");const x=!y&&$>0?{color:a,width:vo(Te($),.5,240),cap:"round",join:"round",...i&&i!=="none"&&Ts.includes(i)?{hand:{style:i,taper:.7,press:.6,seed:7}}:{}}:null,E={id:"s1",name:String(e).slice(0,40),type:"art",params:{rig:p,box:[Te(f[0]-h[0]),Te(f[1]-h[1]),Te(m[0]-h[0]),Te(m[1]-h[1])],...r?{outline:!1}:{}},pos:h,rot:0,scale:[1,1],opacity:1,fill:{type:"color",color:t.C.stick??t.C.top??"#222222"},stroke:x,role:7,span:[0,Math.round(c*1e4)/1e4]};return{shape:l({v:2,size:o,items:[E]},null,{colors:"keep"}),label:String(e).slice(0,60),start:0,duration:c,note:`rig layer: ${p.n} drawing(s) at ${p.fps} fps = ${Math.round(c*100)/100}s from ${Math.round(p.data.length/1e3)}k chars of skeletons`}}const fo=Object.freeze({frames:480,parts:64,points:256,chars:3e6,fps:[4,30],cycles:8});function mi(t,{size:e,en:o,finish:r}){const n=t.fps??12;if(!(Number.isInteger(n)&&n>=fo.fps[0]&&n<=fo.fps[1]))throw Error("drawFrames fps: 4–30 drawings per second (30 = every timeline frame, smoothest; 12 = on twos, 8 = on threes)");const a=Array.isArray(t.frames)?t.frames:null;if(!a||!a.length||a.length>fo.frames)throw Error(`drawFrames frames: 1–${fo.frames} drawings [{parts:[{points | d, fill?, line?}], hold?}]`);const i=t.cycles??1;if(!(Number.isInteger(i)&&i>=1&&i<=fo.cycles))throw Error(`drawFrames cycles: 1–${fo.cycles} (the whole drawing sequence repeated)`);const l=t.ink??"#2a1d14";if(!bo.test(l))throw Error("drawFrames ink: #RRGGBB");const p=t.width??.0035;if(!(Vt(p)&&p>=0&&p<=.03))throw Error("drawFrames width: ink line width, a fraction of the frame width (0–0.03; 0 = no ink lines)");const c=t.brush??"ink";if(c!=="none"&&!Ts.includes(c))throw Error(`drawFrames brush: none | ${Ts.join(" | ")}`);const s=Vr(e),h=b=>Math.round(b),f=Py(t.fx,t.op==="rotoscope"?"rotoscope":"drawFrames"),m=f?nI(a.map((b,A)=>{if(!Array.isArray(b?.parts))throw Error(`drawFrames frames[${A}].parts: 1–${fo.parts} shapes`);return b}),n,f,{aspect:e[0]/e[1],maxParts:fo.parts}):a;let y=0;const $=m.map((b,A)=>{const I=Array.isArray(b?.parts)?b.parts:null;if(!I||!I.length||I.length>fo.parts)throw Error(`drawFrames frames[${A}].parts: 1–${fo.parts} shapes`);const P=b.hold??1;if(!(Number.isInteger(P)&&P>=1&&P<=48))throw Error(`drawFrames frames[${A}].hold: how many frames it stays, 1–48`);const C=I.map((_,q)=>{if(!_||typeof _!="object")throw Error(`drawFrames frames[${A}].parts[${q}] must be an object`);const U=_.fill??null;if(U!==null&&!bo.test(U))throw Error(`drawFrames frames[${A}].parts[${q}].fill: #RRGGBB or null (an ink line)`);let rt;if(Array.isArray(_.loops)){if(!_.loops.length||_.loops.length>24||_.loops.some(ot=>!Array.isArray(ot)||ot.length<3||ot.length>1500))throw Error(`drawFrames frames[${A}].parts[${q}].loops: 1–24 closed outlines of 3–1500 points`);rt=_.loops.map((ot,G)=>"M"+ot.map((J,Z)=>{const at=s.pt(Yr(J,Z,`drawFrames frames[${A}].parts[${q}].loops[${G}]`));return`${h(at[0])} ${h(at[1])}`}).join(" L")+" Z").join(" ")}else if(_.d!=null)rt=Ry(_.d,s);else{const ot=Array.isArray(_.points)?_.points:null;if(!ot||ot.length<2||ot.length>fo.points)throw Error(`drawFrames frames[${A}].parts[${q}]: points [[x,y]…] (2–${fo.points}) or d`);const G=ot.map((Z,at)=>s.pt(Yr(Z,at,`drawFrames frames[${A}].parts[${q}]`))),J=_.closed??!!U;rt=_.smooth===!1?"M"+G.map(Z=>`${h(Z[0])} ${h(Z[1])}`).join(" L")+(J?" Z":""):_i(G,J&&G.length>2)}if(!U&&_.line===!1)throw Error(`drawFrames frames[${A}].parts[${q}] needs a fill or a line`);if(_.lw!=null&&!(Vt(_.lw)&&_.lw>=.1&&_.lw<=5))throw Error(`drawFrames frames[${A}].parts[${q}].lw: line weight 0.1–5 (× width)`);if(_.opacity!=null&&!(Vt(_.opacity)&&_.opacity>=.02&&_.opacity<=1))throw Error(`drawFrames frames[${A}].parts[${q}].opacity: 0.02–1`);if(_.tag!=null&&!Ad.test(_.tag))throw Error(`drawFrames frames[${A}].parts[${q}].tag: a name — a letter then letters / digits / dashes, ≤ 24 (armR, head, leg-left)`);return{d:rt,fill:U,..._.tag!=null?{tag:_.tag}:{},...U&&_.line===!1?{line:!1}:{},..._.lw!=null&&_.lw!==1?{lw:Math.round(_.lw*100)/100}:{},..._.eo===!0&&U?{eo:!0}:{},..._.opacity!=null&&_.opacity<1?{o:Math.round(_.opacity*100)/100}:{},role:7}}),z=C.reduce((_,q)=>{const U=ir(q.d);return[Math.min(_[0],U[0]),Math.min(_[1],U[1]),Math.max(_[2],U[2]),Math.max(_[3],U[3])]},[1/0,1/0,-1/0,-1/0]),N=Math.round((z[0]+z[2])/2),F=Math.round((z[1]+z[3])/2),K=C.map(_=>{let q=0;return{..._,d:_.d.replace(sn,U=>String(Math.round(Number(U)-(q++%2?F:N))))}});for(const _ of K){if(_.d.length>Gi.d)throw Error(`drawFrames frames[${A}]: a shape is too long (max ${Gi.d} characters)`);y+=_.d.length}return{parts:K,pos:[N,F],hold:P}});if(y*i>fo.chars)throw Error(`drawFrames: ${y*i} characters of drawing (max ${fo.chars}) — fewer frames, cycles or points`);const x=s.len(p),E=x>0?{color:l,width:vo(Te(x),.5,240),cap:"round",join:"round",...c!=="none"?{hand:{style:c,taper:.7,press:.6,seed:7}}:{}}:null,v=[];let S=0;for(let b=0;b<i;b++)for(const A of $)v.push({...A,t0:S,t1:S+A.hold/n}),S+=A.hold/n;const k=[];for(let b=0;b<v.length;b+=Ie.items){const A=v.slice(b,b+Ie.items),I=A[0].t0,P=A.at(-1).t1,C=A.map((z,N)=>({id:`s${N+1}`,name:`${o?"Frame":"Khung"} ${b+N+1}`,type:"art",params:{parts:z.parts,box:ir(z.parts.map(F=>F.d).join(" ")),outline:t.outline!==!1},pos:z.pos,rot:0,scale:[1,1],opacity:1,fill:{type:"color",color:z.parts.find(F=>F.fill)?.fill??l},stroke:E,role:7,span:[Math.round((z.t0-I)*1e4)/1e4,Math.round((z.t1-I)*1e4)/1e4]}));k.push({shape:r({v:2,size:e,items:C},null,{colors:"keep"}),label:`${String(t.label??(o?"Frames":"Khung vẽ")).slice(0,48)}${v.length>Ie.items?` ${k.length+1}`:""}`,start:I,duration:P-I})}return{patches:[],layers:k,frameLayers:!0,note:`drawFrames: ${a.length} drawing(s)${i>1?` × ${i}`:""} at ${n} fps = ${Math.round(S*100)/100}s on ${k.length} layer(s), ${Math.round(y/1e3)}k chars`}}const PI=13;function zI(t,{into:e,target:o,size:r,ctx:n,en:a,finish:i}){const l=t.traced;if(!l||typeof l!="object")throw Error("traceImage needs materialId (an image in the Media bin); the picture is traced when the plan is applied");const p=l.width,c=l.height,s=l.unit;if(!(Number.isInteger(p)&&Number.isInteger(c)&&p>=8&&c>=8&&p<=2048&&c<=2048&&(s===.5||s===1)&&Array.isArray(l.groups)&&l.groups.length&&l.groups.length<=PI))throw Error("traceImage: bad traced data");const h=t.fit??"cover";if(!["cover","contain"].includes(h))throw Error("traceImage fit: cover | contain");const f=Array.isArray(t.regions)?t.regions:[],[m,y]=Mn(o),$=Vr([m,y]),x=n.W||1280,E=n.H||720;let v;if(t.background==="remove"&&(t.x!=null||t.y!=null||t.size!=null)){const K=t.x??.5,_=t.y??.5,q=t.size??.6;if(Yr([K,_],0,"traceImage"),!(Vt(q)&&q>=.02&&q<=1.5))throw Error("traceImage size = height of the subject as a fraction of the frame, 0.02–1.5");const U=l.groups.reduce((J,Z)=>Z.parts.reduce((at,D)=>{const H=ir(D.d);return[Math.min(at[0],H[0]),Math.min(at[1],H[1]),Math.max(at[2],H[2]),Math.max(at[3],H[3])]},J),[1/0,1/0,-1/0,-1/0]).map(J=>J*s),rt=Math.max(1,U[3]-U[1]),ot=q/rt,G=ot*E/x;v={x0:K-(U[0]+U[2])/2*G,y0:_-(U[1]+U[3])/2*ot,sx:G,sy:ot}}else{const K=p/c,_=x/E,q=h==="cover",U=q?K>_:K<_,rt=U?q?K/_:1:q?1:K/_,ot=U?q?1:_/K:q?_/K:1;v={x0:(1-rt)/2,y0:(1-ot)/2,sx:rt/p,sy:ot/c}}const k=(K,_)=>$.pt([v.x0+K*s*v.sx,v.y0+_*s*v.sy]),b=!e&&t.layers!==!1&&l.groups.length>1,A=[...o.items],I=[],P=[];if(!b&&A.length+l.groups.length>Ie.items)throw Error(`A Shape layer holds up to ${Ie.items} items — trace into a new layer (leave clipId out)`);const C=([K,_])=>[(K*$.k+$.ox)/m,(_*$.k+$.oy)/y];let z=0;for(const K of l.groups){if(!K||!Array.isArray(K.parts)||!K.parts.length||K.parts.length>Gi.parts)throw Error("traceImage: bad traced group");const _=K.parts.map(at=>{if(!at||typeof at.d!="string"||!/^\s*M[MLCQZ0-9eE.,\s+-]*$/.test(at.d)||!bo.test(at.fill??""))throw Error("traceImage: bad traced part");const D=[...at.d.matchAll(sn)].map(gt=>Number(gt[0]));if(D.length%2)throw Error("traceImage: bad traced part");const H=[];for(let gt=0;gt<D.length;gt+=2){const xt=k(D[gt],D[gt+1]);H.push(Math.round(xt[0]),Math.round(xt[1]))}let ut=0;return{d:at.d.replace(sn,()=>String(H[ut++])),fill:at.fill}}),q=_.reduce((at,D)=>{const H=ir(D.d);return[Math.min(at[0],H[0]),Math.min(at[1],H[1]),Math.max(at[2],H[2]),Math.max(at[3],H[3])]},[1/0,1/0,-1/0,-1/0]),U=Math.round((q[0]+q[2])/2),rt=Math.round((q[1]+q[3])/2),ot=_.map(at=>{let D=0;return{d:at.d.replace(sn,H=>String(Math.round(Number(H)-(D++%2?rt:U)))),fill:at.fill,role:7,eo:!0}});z+=ot.reduce((at,D)=>at+D.d.length,0);const G=Da(A),J=Number.isInteger(K.region)&&K.region>=0?f[K.region]:null;let Z={id:G,name:String(K.name||(a?"Traced":"Hình vẽ lại")).slice(0,40),type:"art",params:{parts:ot,box:ir(ot.map(at=>at.d).join(" ")),outline:!1},pos:[U,rt],rot:0,scale:[1,1],opacity:1,fill:{type:"color",color:ot[0].fill},stroke:null,role:7};if(b){const at=Z.name,D=[...C([q[0],q[1]]),...C([q[2],q[3]])];let H=null,ut=null,gt=null;if(J){if(J.motion!=null){if(!Pn[J.motion])throw Error(`traceImage regions[].motion (layers): ${Ey.join(" | ")}`);ut={preset:J.motion,...Vt(J.amount)?{amount:vo(J.amount,0,8)}:{},...Vt(J.period)?{period:vo(J.period,.1,60)}:{},...Vt(J.phase)?{phase:vo(J.phase,0,1)}:{}}}const tt=J.pivot??(ut?Pn[ut.preset].anchor:null);if(Array.isArray(tt)?(Yr(tt,0,"traceImage regions[].pivot"),H=[v.x0+tt[0]*p*v.sx,v.y0+tt[1]*c*v.sy]):tt!=null&&(H=tt),J.parent!=null){const nt=f.findIndex(mt=>mt&&mt.name===J.parent);if(nt<0)throw Error(`traceImage regions[].parent "${String(J.parent).slice(0,40)}": the name of another region`);gt=nt}}if(K.region===-1){P.push({shape:{v:2,size:[m,y],items:[{...Z,id:"s1"}]},label:String(at).slice(0,60),region:null,anchor:H,box:D,parent:gt,motion:ut});continue}const xt=D[0]-3/x,u=D[1]-3/E,st=D[2]+3/x,V=D[3]+3/E,d=(st-xt)*x,w=(V-u)*E,T=Math.min(Math.max(1.5,64/Math.max(1,Math.min(d,w))),2560/Math.max(d,w)),j=vo(Math.round(d*T),64,2560),O=vo(Math.round(w*T),64,2560),L=Vr([j,O]),B=Math.min(x/j,E/O),X=(tt,nt)=>L.pt([(v.x0+tt*s*v.sx-xt)/(st-xt),(v.y0+nt*s*v.sy-u)/(V-u)]),Q=K.parts.map(tt=>{const nt=[...tt.d.matchAll(sn)].map(Nt=>Number(Nt[0])),mt=[];for(let Nt=0;Nt<nt.length;Nt+=2){const $t=X(nt[Nt],nt[Nt+1]);mt.push(Math.round($t[0]),Math.round($t[1]))}let It=0;return{d:tt.d.replace(sn,()=>String(mt[It++])),fill:tt.fill}}),et=Q.reduce((tt,nt)=>{const mt=ir(nt.d);return[Math.min(tt[0],mt[0]),Math.min(tt[1],mt[1]),Math.max(tt[2],mt[2]),Math.max(tt[3],mt[3])]},[1/0,1/0,-1/0,-1/0]),lt=Math.round((et[0]+et[2])/2),Y=Math.round((et[1]+et[3])/2),dt=Q.map(tt=>{let nt=0;return{d:tt.d.replace(sn,mt=>String(Math.round(Number(mt)-(nt++%2?Y:lt)))),fill:tt.fill,role:7,eo:!0}}),bt={...Z,id:"s1",pos:[lt,Y],params:{parts:dt,box:ir(dt.map(tt=>tt.d).join(" ")),outline:!1}};P.push({shape:{v:2,size:[j,O],items:[bt]},label:String(at).slice(0,60),region:Number.isInteger(K.region)?K.region:null,anchor:H,box:D,parent:gt,motion:ut,place:{posX:Math.round(((xt+st)/2-.5)*1e4)/1e4,posY:Math.round(((u+V)/2-.5)*1e4)/1e4,scale:Math.round(d/(j*B)*1e5)/1e5}});continue}if(J&&(J.pivot!=null&&(Z=gd(Z,Array.isArray(J.pivot)?(()=>{Yr(J.pivot,0,"traceImage regions[].pivot");const at=k(J.pivot[0]*p/s,J.pivot[1]*c/s);return[Te(at[0]-U),Te(at[1]-rt)]})():md(Z,J.pivot,$))),J.motion!=null)){const at=$g[J.motion];if(!at)throw Error(`traceImage regions[].motion: ${Cd.join(" | ")}`);J.pivot==null&&(Z=gd(Z,md(Z,at.pivot,$)));const D=Vt(J.amount)?vo(J.amount,0,8):1;Z.motion=[{type:J.motion,...D!==1?{amount:Math.round(at.amount*D*1e4)/1e4}:{},...Vt(J.period)?{period:vo(J.period,.1,60)}:{},...Vt(J.phase)?{phase:vo(J.phase,0,1)}:{}}]}A.push(Z),I.push(G)}if(z>Gi.layer)throw Error("traceImage: the drawing is too big for one layer — fewer colours or less detail");if(b){const K=new Map(P.map((q,U)=>[q.region,U]));for(const q of P)q.parent=q.parent==null?null:K.get(q.parent)??null,q.shape=i(q.shape,null,{colors:"keep"}),delete q.region;let _=null;if(t.camera!=null){const q=typeof t.camera=="string"?{preset:t.camera}:t.camera;if(!q||!Nc.includes(q.preset))throw Error(`traceImage camera: ${Nc.join(" | ")} (or {preset, amount})`);_={preset:q.preset,...Vt(q.amount)?{amount:vo(q.amount,0,8)}:{}}}return{patches:[],layers:P,camera:_,note:`traceImage: ${P.length} layers (${P.map(q=>q.label).join(", ").slice(0,140)}), ${l.palette?.length??"?"} colours, ${Math.round(z/1e3)}k chars`}}const N=i({...o,items:A},I,{colors:"keep"}),F=`traceImage: ${l.groups.length} part(s) (${l.groups.map(K=>K.name).join(", ").slice(0,120)}), ${l.palette?.length??"?"} colours, ${Math.round(z/1e3)}k chars`;return e?{patches:[{id:e.id,shape:N}],note:F}:{patches:[],layer:{shape:N,label:String(t.label??(a?"Traced drawing":"Vẽ lại từ ảnh")).slice(0,60)},note:F}}const Ky=t=>jd(t?.shape)&&t.shape.items.length===1&&t.shape.items[0].name==="Paper"&&t.zIndex===-1,yd=Object.freeze([{id:"cyber-neon",vi:"Cyber neon",en:"Cyber neon",bg:["#05060f","#1a0b2e",160],panel:"#0b1020cc",rim:"#3ef0d0",accent:"#ff3fa4",label:"#c6ff3d",text:"#e8fbff",font:"Archivo",move:"Archivo",italic:!1,round:.07,glow:1.4,floor:"#39e6e0",sig:["brackets"],layout:"stack"},{id:"lime-glass",vi:"Kính chanh",en:"Lime glass",bg:["#0b0d0b","#1c2219",150],panel:"#121612cc",rim:"#c6f432",accent:"#c6f432",label:"#c6f432",text:"#f4ffe0",font:"Inter",move:"Inter",italic:!1,round:.08,glow:1.1,floor:"#c6f432",sig:["frost","index"],layout:"stack"},{id:"minimal-white",vi:"Trắng tối giản",en:"Minimal white",bg:["#fafafa","#e4dbff",90],panel:"#ffffffee",rim:"#111111",accent:"#8c6cff",label:"#111111",text:"#111111",font:"Inter",move:"Playfair Display",italic:!0,round:.06,glow:0,floor:null,sig:["index","strip"],layout:"split"},{id:"terminal",vi:"Terminal",en:"Terminal",bg:["#020402","#06140a",180],panel:"#031006dd",rim:"#2bff6a",accent:"#2bff6a",label:"#2bff6a",text:"#b8ffcc",font:"Courier New",move:"Courier New",italic:!1,round:.02,glow:.8,floor:"#2bff6a",sig:["log","scan"],layout:"split"},{id:"blueprint",vi:"Bản vẽ kỹ thuật",en:"Blueprint",bg:["#0b2a5b","#103a7a",135],panel:"#0b2a5bcc",rim:"#ffffff",accent:"#9fd3ff",label:"#ffffff",text:"#e6f3ff",font:"Archivo",move:"Archivo",italic:!1,round:0,glow:0,floor:"#9fd3ff",sig:["dims"],layout:"focus"},{id:"retro-vhs",vi:"Retro VHS",en:"Retro VHS",bg:["#1b0b1f","#3a1030",160],panel:"#1b0b1fcc",rim:"#ff8a3d",accent:"#ff3d7f",label:"#ffd23f",text:"#fff1d6",font:"Bungee",move:"Bungee",italic:!1,round:.03,glow:1,floor:"#ff3d7f",sig:["osd","scan"],layout:"stack"},{id:"dark-luxury",vi:"Sang trọng tối",en:"Dark luxury",bg:["#060504","#1a1510",170],panel:"#0d0b08dd",rim:"#d4a24c",accent:"#e8c27a",label:"#d4a24c",text:"#f6ead2",font:"Inter",move:"Playfair Display",italic:!0,round:.05,glow:.6,floor:null,sig:["headline","index"],layout:"focus"},{id:"sport-red",vi:"Thể thao đỏ",en:"Sport red",bg:["#080808","#2a0606",160],panel:"#120606dd",rim:"#ff2b2b",accent:"#ff2b2b",label:"#ffffff",text:"#ffffff",font:"Oswald",move:"Anton",italic:!1,round:.02,glow:1.2,floor:"#ff2b2b",sig:["gauge","strip"],layout:"stack"},{id:"apple-clean",vi:"Sạch kiểu Apple",en:"Clean studio",bg:["#f5f5f7","#dfe3ea",180],panel:"#ffffffee",rim:"#ffffff",accent:"#0071e3",label:"#1d1d1f",text:"#1d1d1f",font:"Inter",move:"Inter",italic:!1,round:.09,glow:0,floor:null,sig:["frost","strip"],layout:"split"},{id:"synthwave",vi:"Synthwave",en:"Synthwave",bg:["#12002b","#ff3fa4",180],panel:"#1a0436cc",rim:"#ff6ad5",accent:"#00f0ff",label:"#ffe66d",text:"#ffe9ff",font:"Bungee",move:"Bungee",italic:!1,round:.05,glow:1.5,floor:"#ff6ad5",sig:["sun"],layout:"stack"},{id:"ice-glass",vi:"Kính băng",en:"Ice glass",bg:["#0a1a26","#1d4157",150],panel:"#0f2635bb",rim:"#bff6ff",accent:"#7fe7ff",label:"#e6fbff",text:"#e6fbff",font:"Lexend",move:"Lexend",italic:!1,round:.09,glow:1,floor:"#7fe7ff",sig:["frost","rings"],layout:"focus"},{id:"editorial",vi:"Tạp chí",en:"Editorial",bg:["#f3eee3","#e2d8c3",180],panel:"#fbf8f1ee",rim:"#1a1a1a",accent:"#c0392b",label:"#1a1a1a",text:"#1a1a1a",font:"Noto Serif",move:"Playfair Display",italic:!0,round:0,glow:0,floor:null,sig:["headline","index","arrows"],layout:"split"},{id:"sunset-gold",vi:"Hoàng hôn",en:"Sunset gold",bg:["#2b0f05","#a33d0b",160],panel:"#2b0f05cc",rim:"#ffb347",accent:"#ffd56a",label:"#ffe2a8",text:"#fff3e0",font:"Archivo",move:"Archivo",italic:!1,round:.06,glow:1,floor:"#ffb347",sig:["strip","headline"],layout:"focus"},{id:"mono-grid",vi:"Lưới đơn sắc",en:"Mono grid",bg:["#e9e9e6","#d6d6d2",180],panel:"#f6f6f3ee",rim:"#2a2a2a",accent:"#2a2a2a",label:"#2a2a2a",text:"#2a2a2a",font:"Archivo",move:"Archivo",italic:!1,round:.04,glow:0,floor:"#8a8a86",sig:["arrows","dims"],layout:"split"},{id:"hologram",vi:"Hologram xanh",en:"Hologram",bg:["#020814","#06224a",170],panel:"#04142ccc",rim:"#5ee7ff",accent:"#5ee7ff",label:"#9ff3ff",text:"#dffaff",font:"Lexend",move:"Lexend",italic:!1,round:.05,glow:1.6,floor:"#5ee7ff",sig:["rings","brackets"],layout:"stack"}]),N0=yd.map(t=>t.id),bd=Object.freeze(["stack","split","focus"]),za=Object.freeze({shots:12,seconds:60,labels:40}),LI={en:{final:"FINAL EDIT",raw:"RAW FOOTAGE",graph:"SPEED GRAPH",start:"START FRAME",end:"END FRAME",cut:"CUT",ramp:"SPEED RAMP"},vi:{final:"BẢN DỰNG",raw:"FOOTAGE GỐC",graph:"ĐƯỜNG TỐC ĐỘ",start:"KHUNG ĐẦU",end:"KHUNG CUỐI",cut:"CẮT",ramp:"TĂNG GIẢM TỐC"}},NI={portrait:{stack:{final:{x:-.17,y:-.24,h:.4},raw:{x:.25,y:-.33,h:.2},graph:{x:.25,y:-.07,w:.42},start:{x:-.24,y:.28,h:.27},end:{x:.24,y:.28,h:.27},move:{x:0,y:.28},floor:!0,horizon:.53},split:{final:{x:-.22,y:-.15,h:.4},raw:{x:.22,y:-.15,h:.4},graph:{x:0,y:.33,w:.8},move:{x:0,y:.1}},focus:{final:{x:0,y:-.06,h:.66},raw:{x:.3,y:-.34,h:.2},graph:{x:-.24,y:.39,w:.44},start:{x:.15,y:.39,h:.15},end:{x:.36,y:.39,h:.15},move:{x:.255,y:.29},stillLabels:!1}},landscape:{stack:{final:{x:-.3,y:-.17,h:.48},raw:{x:-.06,y:-.22,h:.38},graph:{x:.27,y:-.24,w:.34},start:{x:-.12,y:.28,h:.36},end:{x:.12,y:.28,h:.36},move:{x:0,y:.07},floor:!0,horizon:.5},split:{final:{x:-.2,y:-.06,h:.72},raw:{x:.2,y:-.06,h:.72},graph:{x:0,y:.39,w:.5},move:{x:0,y:.34}},focus:{final:{x:-.2,y:-.02,h:.78},raw:{x:.17,y:-.22,h:.36},graph:{x:.38,y:-.22,w:.2},start:{x:.17,y:.27,h:.36},end:{x:.38,y:.27,h:.36},move:{x:.275,y:.04},stillLabels:!1}}},Gt=t=>Math.round(t*1e3)/1e3,go=t=>Math.round(t*1e4)/1e4,wd=t=>Jt[t],FI=/^#[0-9a-fA-F]{6}$/,uu=t=>t&&["video","image"].includes(t.kind)&&(t.url||t.gcsUri||t.nodeId)&&!t.title&&!t.shape&&!t.motion&&!t.card&&!t.geo&&!t.lottie&&!t.nullLayer&&!t.solid&&!t.model&&!t.adjust;function RI(t,e,o){const{track:r}=Zt(t,e,o.start,o.start+o.duration),n={...o,track:r};return t.push(n),n}function DI(t,e){const o=yd.find(r=>r.id===t)??yd[0];return FI.test(e??"")?{...o,accent:e.toLowerCase(),rim:o.glow?e.toLowerCase():o.rim}:o}function Vc(t,e){return zn(t)?Math.abs(mw(t,e)):Hr(t)?gw(t,e):t.playbackRate||1}function BI(t,e,o){const r=t[e],n=t[e-1],a=n&&Math.abs(n.start+n.duration-r.start)<.05?n.transition:null,i=a?.ramp?.preset||a?.name||r.seam?.style||r.join?.style||n?.join?.style||(Hr(r)||zn(r)?o.ramp:null);return String(i||o.cut).replace(/\s*\([^)]*\)\s*/g," ").replace(/[-_]+/g," ").trim().toUpperCase().slice(0,za.labels)}function _I(t,e,o,r){const n=e.find(i=>i.id===t.nodeId),a=n?.width>1&&n?.height>1?n.width/n.height:t.kind==="video"?o/r:1;return Math.min(1,o/a/r)}function GI(t,e,o){const r=e.find(a=>a.id===t.nodeId);if(!(Number.isInteger(r?.width)&&r.width>1&&Number.isInteger(r?.height)&&r.height>1))return;const n=Ma(r.width,r.height,t.crop);return gr({mw:r.width,mh:r.height},[Yn({kind:"rect",cx:.5,cy:.5,w:1,h:1,rot:0,round:o},n.w,n.h)])}function KI(t,{x:e,y:o,s:r}){const n={...t,...Zr(t)},a=(n.motionKeys??[]).map(i=>({...i,...Number.isFinite(i.x)?{x:go(e+r*i.x)}:{},...Number.isFinite(i.y)?{y:go(o+r*i.y)}:{},...Number.isFinite(i.zoom)?{zoom:go(r*i.zoom)}:{}}));return{motionV:2,posX:go(e+r*(n.posX??0)),posY:go(o+r*(n.posY??0)),scale:go(r*(n.scale??1)),motionKeys:a}}const Cl=(t,e=0)=>{const o=Gt(Math.min(t,e)),r=Gt(Math.min(t,e+.35));return r>o?[{time:o,opacity:0,ease:{opacity:wd("ease-out")}},{time:r,opacity:1}]:[]};function VI(t,e){const o=t.map(r=>({...r}));for(const r of e){const n=o.find(a=>Math.abs(a.time-r.time)<.008333333333333333);n?Object.assign(n,{...r,ease:{...n.ease,...r.ease}}):o.push({...r})}return o.sort((r,n)=>r.time-n.time)}function vr(t,e,o,r,n,{x:a,y:i,size:l=30,color:p,font:c,italic:s=!1,weight:h=700,anim:f="word-blur",track:m=0,glow:y=!0,k:$=1}){const x=p??n.label,E=Nl({text:r,fontSize:Math.max(24,Math.min(96,l)),color:x,placement:"center",fontFamily:c??n.font,align:"center",animation:f,design:{lines:[{scale:1,fill:x,font:c??n.font,italic:s,weight:h,tracking:.06}],layers:[{type:"text",fill:"{color}",...y&&n.glow?{shadow:{color:x,blur:.35,x:0,y:0}}:{}}]}});return{id:t,nodeId:"",kind:"image",url:"",label:r.slice(0,40),title:E,volume:0,track:m,start:e,duration:o,motionV:2,posX:go(a),posY:go(i),scale:Gt($),motionKeys:[]}}function WI(t,e){const o=t.duration,r=40,n=Array.from({length:r+1},(f,m)=>Vc(t,o*m/r)),a=Math.max(2,...n)*1.12,i=f=>Gt(90+820*f),l=f=>Gt(740-430*Math.min(1,f/a)),p=n.map((f,m)=>[i(m/r),l(f)]),c=Math.min(24,Math.max(2,Math.round(o*4))),s=Array.from({length:c+1},(f,m)=>({t:Gt(o*m/c),p:[i(m/c),l(Vc(t,o*m/c))]})),h=l(1);return He({v:2,square:!0,items:[{id:"p",name:"Panel",type:"rect",params:{w:960,h:600,round:e.round*600},pos:[500,500],rot:0,scale:[1,1],opacity:1,fill:{type:"color",color:e.panel.slice(0,7),opacity:parseInt(e.panel.slice(7,9)||"ff",16)/255},stroke:{color:e.rim,width:4,...e.glow?{blur:6}:{}}},{id:"g1",name:"Base",type:"path",params:{pts:[[90,740],[910,740]],closed:!1},pos:[0,0],rot:0,scale:[1,1],opacity:.5,fill:{type:"none"},stroke:{color:e.text,width:3}},{id:"g2",name:"1x",type:"path",params:{pts:[[90,h],[910,h]],closed:!1},pos:[0,0],rot:0,scale:[1,1],opacity:.45,fill:{type:"none"},stroke:{color:e.text,width:2,dash:[14,12]}},{id:"cg",name:"Curve glow",type:"path",params:{pts:p,closed:!1},pos:[0,0],rot:0,scale:[1,1],opacity:e.glow?.45:0,fill:{type:"none"},stroke:{color:e.accent,width:16,blur:12,cap:"round",join:"round"},ops:[{op:"trim",start:0,end:1,offset:0}],keys:{"ops.0.end":[{time:0,value:0},{time:Gt(o),value:1}]}},{id:"c",name:"Curve",type:"path",params:{pts:p,closed:!1},pos:[0,0],rot:0,scale:[1,1],opacity:1,fill:{type:"none"},stroke:{color:e.accent,width:6,cap:"round",join:"round"},ops:[{op:"trim",start:0,end:1,offset:0}],keys:{"ops.0.end":[{time:0,value:0},{time:Gt(o),value:1}]}},{id:"d",name:"Dot",type:"ellipse",params:{w:30,h:30},pos:s[0].p,rot:0,scale:[1,1],opacity:1,fill:{type:"color",color:e.label},stroke:{color:e.accent,width:6,...e.glow?{blur:8}:{}},keys:{"pos.0":s.map(f=>({time:f.t,value:f.p[0]})),"pos.1":s.map(f=>({time:f.t,value:f.p[1]}))}}]})}function XI(t,e,o,r){const n=Math.min(1777.7777777777778,1e3*e),a=$=>Gt(500+($-.5)*n),i=[],l=($,x,E)=>({color:t.floor,width:x,...E?{blur:E}:{},opacity:$});if(o==null){const x=[],E=[];for(let S=0;S<=8;S++){const k=a(S/8);x.push(...S%2?[[k,1e3],[k,0]]:[[k,0],[k,1e3]])}const v=Math.round(8/e);for(let S=0;S<=v;S++){const k=Gt(1e3*S/v);E.push(...S%2?[[a(1),k],[a(0),k]]:[[a(0),k],[a(1),k]])}return i.push({id:"v",name:"Grid V",type:"path",params:{pts:x,closed:!1},pos:[0,0],rot:0,scale:[1,1],opacity:.14,fill:{type:"none"},stroke:l(1,2)},{id:"h",name:"Grid H",type:"path",params:{pts:E,closed:!1},pos:[0,0],rot:0,scale:[1,1],opacity:.14,fill:{type:"none"},stroke:l(1,2)}),He({v:2,items:i})}const p=Gt(1e3*o),c=[500,Gt(p-120)],s=14,h=[];for(let $=0;$<=s;$++){const x=a(-.7+2.4*$/s),E=(p-1e3)/(c[1]-1e3),v=Gt(x+(c[0]-x)*E);h.push(...$%2?[[v,p],[x,1e3]]:[[x,1e3],[v,p]])}i.push({id:"vg",name:"Floor glow",type:"path",params:{pts:h,closed:!1},pos:[0,0],rot:0,scale:[1,1],opacity:.35,fill:{type:"none"},stroke:l(1,9,9)},{id:"v",name:"Floor lines",type:"path",params:{pts:h,closed:!1},pos:[0,0],rot:0,scale:[1,1],opacity:.8,fill:{type:"none"},stroke:{color:"#e6f6ff",width:2}});for(let $=1;$<=8;$++){const x=1+$*.55,E=Gt(p+(1e3-p)*(1/x-1/(1+8*.55))/(1-1/(1+8*.55)));i.push({id:`h${$}`,name:`Row ${$}`,type:"path",params:{pts:[[a(-.2),E],[a(1.2),E]],closed:!1},pos:[0,0],rot:0,scale:[1,1],opacity:Gt(.25+.6*(1-$/8)),fill:{type:"none"},stroke:l(1,$<3?4:2.5,$<3?4:0)})}i.push({id:"hz",name:"Horizon",type:"path",params:{pts:[[a(-.2),p],[a(1.2),p]],closed:!1},pos:[0,0],rot:0,scale:[1,1],opacity:.9,fill:{type:"none"},stroke:l(1,5,10)});const f=1.6,m=[];for(let $=0;$<=r+1e-6&&m.length<60;$+=f)m.push({time:Gt($),value:p},{time:Gt(Math.min(r,$+f-1/30)),value:1e3});const y=m.filter(($,x,E)=>!x||$.time>E[x-1].time);return i.push({id:"scan",name:"Scan",type:"rect",params:{w:Gt(n*1.4),h:8,round:4},pos:[500,p],rot:0,scale:[1,1],opacity:.8,fill:{type:"color",color:t.floor},stroke:{color:t.floor,width:6,blur:14},...y.length>1?{keys:{"pos.1":y}}:{}}),He({v:2,items:i})}const F0={en:{head:"BEHIND THE EDIT",play:"▶ PLAY",shot:"SHOT",speed:"SPEED",move:"MOVE"},vi:{head:"HẬU TRƯỜNG",play:"▶ PHÁT",shot:"CẢNH",speed:"TỐC ĐỘ",move:"CHUYỂN"}},HI=["I","II","III","IV","V","VI","VII","VIII","IX","X","XI","XII"];function UI(t){const e=Math.min(1777.7777777777778,1e3*t);return{X:o=>Gt(500+(o-.5)*e),Y:o=>Gt(o*1e3),w:e}}const Vo=(t,e,o,r={})=>({id:t,name:t,type:"path",params:{pts:e,closed:!1},pos:[0,0],rot:0,scale:[1,1],opacity:1,fill:{type:"none"},stroke:o,...r}),gi=(t,e,o,r,n,a,i=null,l={})=>({id:t,name:t,type:"rect",params:{w:Gt(r),h:Gt(n),round:l.round??0},pos:[Gt(e),Gt(o)],rot:0,scale:[1,1],opacity:l.opacity??1,fill:a,stroke:i,...l.keys?{keys:l.keys}:{}});function YI(t,e){const o=t.duration,r=Math.min(24,Math.max(2,Math.round(o*4))),n=8,a=c=>Gt(-120+240*Math.min(1,Math.log(Math.max(.1,c)/.1)/Math.log(n/.1))),i=[];for(let c=0;c<=40;c++){const s=(-210+240*c/40)*Math.PI/180;i.push([Gt(500+Math.cos(s)*380),Gt(560+Math.sin(s)*380)])}const l=[];[.1,.5,1,2,4,8].forEach((c,s)=>{const h=(a(c)-90)*Math.PI/180,f=[[Gt(500+Math.cos(h)*330),Gt(560+Math.sin(h)*330)],[Gt(500+Math.cos(h)*380),Gt(560+Math.sin(h)*380)]];l.push(...s%2?f.reverse():f)});const p=Array.from({length:r+1},(c,s)=>({time:Gt(o*s/r),value:a(Vc(t,o*s/r))}));return He({v:2,square:!0,items:[gi("p",500,500,960,760,{type:"color",color:e.panel.slice(0,7),opacity:parseInt(e.panel.slice(7,9)||"ff",16)/255},{color:e.rim,width:4},{round:e.round*760}),Vo("a",i,{color:e.text,width:10,cap:"round",opacity:.35}),Vo("t",l,{color:e.text,width:8}),{id:"n",name:"Needle",type:"path",params:{pts:[[500,560],[500,230]],closed:!1},pos:[0,0],rot:p[0].value,scale:[1,1],opacity:1,fill:{type:"none"},stroke:{color:e.accent,width:14,cap:"round",...e.glow?{blur:8}:{}},pivot:[500,560],keys:{rot:p}},{id:"h",name:"Hub",type:"ellipse",params:{w:60,h:60},pos:[500,560],rot:0,scale:[1,1],opacity:1,fill:{type:"color",color:e.accent},stroke:null}]})}function qI(t,e,o,r={}){const{newId:n,W:a=1280,H:i=720,materials:l=[]}=r,p=new Map(t.map(st=>[st.id,st])),c=(o??[]).map(st=>p.get(st)).filter(Boolean);let s;if(c.length>1)s=c.filter(uu);else{const st=c[0]??t.filter(uu).sort((V,d)=>V.track-d.track||V.start-d.start)[0];if(!st)throw Error("breakdownShowcase needs the edit: a video / picture clip (clipId) or the shots (clipIds)");s=t.filter(V=>V.track===st.track&&uu(V))}if(s=s.sort((st,V)=>st.start-V.start).slice(0,za.shots),!s.length)throw Error("breakdownShowcase: no video / picture shots in that edit");const h=s[0].start,f=Math.max(...s.map(st=>st.start+st.duration)),m=Gt(f-h);if(m>za.seconds+1e-6)throw Error(`breakdownShowcase: the edit is ${m}s — at most ${za.seconds}s (pick fewer shots)`);const y=Math.max(0,...t.map(st=>st.start+st.duration)),$=Gt(Number.isFinite(r.at)&&r.at>=0?r.at:y),x=Gt($+m),E=$-h,v=DI(r.style,r.color),S=LI[r.lang==="vi"?"vi":"en"],k=bd.includes(r.layout)?r.layout:v.layout??"stack",b=NI[i>a*1.05?"portrait":"landscape"][k],A=Array.isArray(r.labels)?r.labels.map(st=>typeof st=="string"?st.trim().slice(0,za.labels).toUpperCase():""):[],I=[...t],P=[],C=st=>{const V=RI(I,e,st);return P.push(V),V},z=new Set(v.sig??[]),N=r.lang==="vi"?"vi":"en",F=F0[N],K=UI(a/i),_=(st,V,d=$,w=m,T={})=>C({id:n(),nodeId:"",kind:"image",url:"",label:st,track:0,start:d,duration:w,volume:0,motionV:2,fit:"cover",shape:He({v:2,items:V}),...T}),q=_I(s[0],l,a,i),U=i>a*1.05,rt=U?2.2:1.15,ot=st=>go(st.h/q),G=st=>go(st.y-st.h/2-.03);if(C({...Td({id:n(),track:0,start:$,duration:m,label:"Breakdown · nền",fill:{type:"linear",from:v.bg[0],to:v.bg[1],angle:v.bg[2]},aspect:a/i})}),v.floor){const st=XI(v,a/i,b.floor?b.horizon??.5:null,m);C({id:n(),nodeId:"",kind:"image",url:"",label:b.floor?"Breakdown · sàn":"Breakdown · lưới",track:0,start:$,duration:m,volume:0,motionV:2,fit:"cover",shape:st})}const J=l.find(st=>st.id===s[0].nodeId),Z=J?.width>1&&J?.height>1?J.width/J.height:s[0].kind==="video"?a/i:1,at=st=>{const V=st.h,d=ot(st)*Math.min(1,Z*i/a);return{x0:.5+st.x-d/2,x1:.5+st.x+d/2,y0:.5+st.y-V/2,y1:.5+st.y+V/2}},{X:D,Y:H}=K;if(z.has("sun")){const st=(b.horizon??.5)-.02,V=.2,d=[{id:"sun",name:"Sun",type:"ellipse",params:{w:Gt(V*2*1e3),h:Gt(V*2*1e3)},pos:[D(.5),H(st)],rot:0,scale:[1,1],opacity:.9,fill:{type:"linear",angle:90,stops:[["#ffd85a",0],[v.accent,1]]},stroke:null}];for(let w=0;w<6;w++)d.push(gi(`b${w}`,D(.5),H(st+V*(.1+w*.15)),V*2.2*1e3,4+w*3,{type:"color",color:v.bg[1]}));_("Breakdown · mặt trời",d)}if(z.has("frost")){const st=[],d=(w,T)=>st.push(gi(w,D((T.x0+T.x1)/2),H((T.y0+T.y1)/2),D(T.x1)-D(T.x0)+40,H(T.y1)-H(T.y0)+40,{type:"color",color:"#ffffff",opacity:.1},{color:"#ffffff",width:2,opacity:.35},{round:40}));if(b.final&&d("f",at(b.final)),b.raw&&d("r",at(b.raw)),b.start&&b.end){const w=at(b.start),T=at(b.end);d("s",{x0:Math.min(w.x0,T.x0),x1:Math.max(w.x1,T.x1),y0:Math.min(w.y0,T.y0),y1:Math.max(w.y1,T.y1)})}st.length&&_("Breakdown · kính mờ",st)}const ut=st=>{const V=GI(st,l,v.round);return V?{mask:V}:{}},gt={color:v.rim,width:.012,glow:v.glow||0,amount:.9},xt={...vn,opacity:v.glow?.55:.25,blur:24,distance:v.glow?12:8};if(b.final){const st=b.final,V=ot(st),d=Zt(I,e,$,x).track;s.forEach((w,T)=>{const{id:j,parentId:O,...L}=w,B=KI(w,{x:st.x,y:st.y,s:V}),X={...L,...B,id:n(),track:d,start:Gt(w.start+E),...ut(w),edge:gt,shadow:xt,motionKeys:T===0?VI(B.motionKeys,Cl(w.duration,0)):B.motionKeys};I.push(X),P.push(X)}),z.has("headline")?C(vr(n(),$,m,F.head,v,{x:st.x,y:go(G(st)-.004),size:30,color:v.accent,font:v.move,italic:v.italic,weight:800,k:rt})):C(vr(n(),$,m,S.final,v,{x:st.x,y:G(st),size:26,k:rt}))}if(b.raw){const st=b.raw,V=ot(st),d=Zt(I,e,$,x).track;s.forEach((w,T)=>{const j=l.find(Q=>Q.id===w.nodeId),O=w.kind==="video"?w.sourceDuration??j?.duration??null:null,L=w.inPoint||0,B=w.kind==="video"&&Number.isFinite(O)&&L+w.duration>O?Math.max(.1,(O-L)/w.duration):1,X={id:n(),nodeId:w.nodeId,kind:w.kind,url:w.url,...w.gcsUri?{gcsUri:w.gcsUri}:{},label:w.label,track:d,start:Gt(w.start+E),duration:w.duration,inPoint:L,...O!=null?{sourceDuration:O}:{},volume:0,...B!==1?{playbackRate:Gt(B)}:{},...w.crop?{crop:w.crop}:{},motionV:2,posX:st.x,posY:st.y,scale:V,motionKeys:T===0?Cl(w.duration,.08):[],...ut(w),edge:gt,shadow:xt};I.push(X),P.push(X)}),C(vr(n(),$,m,S.raw,v,{x:st.x,y:G(st),size:24,k:rt}))}if(b.graph){const st=b.graph,V=go(z.has("gauge")?Math.min(st.w/.96,.3/(.76*a/i)):st.w/.96),d=Zt(I,e,$,x).track;s.forEach((T,j)=>{const O={id:n(),nodeId:"",kind:"image",url:"",label:`Speed graph · ${j+1}`,track:d,start:Gt(T.start+E),duration:T.duration,volume:0,motionV:2,fit:"contain",posX:st.x,posY:st.y,scale:V,motionKeys:j===0?Cl(T.duration,.16):[],shape:z.has("gauge")?YI(T,v):WI(T,v)};I.push(O),P.push(O)});const w=V*(z.has("gauge")?.76:.6)*a/i;C(vr(n(),$,m,z.has("gauge")?F0[N].speed:S.graph,v,{x:st.x,y:go(st.y-w/2-.028),size:24,k:rt}))}if(b.start&&b.end){const st=Zt(I,e,$,x).track,V=(d,w,T)=>{const j=ot(w),O=d.kind==="video"?Gt(Math.max(0,lg(d,Math.min(d.duration,Math.max(0,T))))):null;return{id:n(),nodeId:d.nodeId,kind:d.kind,url:d.url,...d.gcsUri?{gcsUri:d.gcsUri}:{},label:d.label,start:Gt(d.start+E),duration:d.duration,inPoint:d.inPoint||0,...d.sourceDuration!=null?{sourceDuration:d.sourceDuration}:{},volume:0,...d.crop?{crop:d.crop}:{},...O!=null?{timeRemap:{keys:[{t:0,source:O},{t:Gt(d.duration),source:O}],blend:"none"}}:{},motionV:2,posX:w.x,posY:w.y,scale:j,motionKeys:[{time:0,opacity:.25,zoom:go(j*.92),ease:{opacity:wd("ease-out"),zoom:wd("back-out")}},{time:Gt(Math.min(d.duration,.2)),opacity:1,zoom:j}],...ut(d),edge:gt,shadow:xt}};s.forEach((d,w)=>{const T=V(d,b.start,0),j=V(d,b.end,d.duration-1/30);T.track=st,I.push(T),P.push(T),j.track=Zt(I,e,j.start,j.start+j.duration).track,I.push(j),P.push(j)}),b.stillLabels!==!1&&C(vr(n(),$,m,S.start,v,{x:b.start.x,y:G(b.start),size:22,k:rt})),b.stillLabels!==!1&&C(vr(n(),$,m,S.end,v,{x:b.end.x,y:G(b.end),size:22,k:rt}))}if(b.move&&s.forEach((st,V)=>{const d=A[V]||BI(s,V,S);if(z.has("log")){const T=Array.from({length:25},(B,X)=>Vc(st,st.duration*X/24)),j=Math.min(...T),O=Math.max(...T),L=`> ${F.shot} ${String(V+1).padStart(2,"0")}/${String(s.length).padStart(2,"0")} ${st.duration.toFixed(1)}s
|
|
334
|
+
> ${F.speed} ${j.toFixed(1)}× → ${O.toFixed(1)}×
|
|
335
|
+
> ${F.move}: ${d}`;C(vr(n(),Gt(st.start+E),st.duration,L,v,{x:b.move.x,y:b.move.y,size:20,color:v.accent,font:"Courier New",weight:700,anim:"type-on",k:rt}))}else C(vr(n(),Gt(st.start+E),st.duration,d,v,{x:b.move.x,y:b.move.y,size:32,color:v.accent,font:v.move,italic:v.italic,weight:800,k:rt}))}),z.has("scan")){const st=(V,d)=>{const w=[];for(let T=0;T<128;T++){const j=Gt(d+T*7.8);w.push(...T%2?[[D(1),j],[D(0),j]]:[[D(0),j],[D(1),j]])}return Vo(V,w,{color:"#000000",width:2,opacity:.35})};_("Breakdown · scanline",[st("s1",2),st("s2",2+128*7.8)])}const u=b.final?at(b.final):null;if(z.has("brackets")&&u){const d={color:v.accent,width:6,join:"miter",...v.glow?{blur:6}:{}},w=u.x0-.018,T=u.x1+.018,j=u.y0-.018,O=u.y1+.018;_("Breakdown · ngoặc góc",[Vo("tl",[[D(w),H(j+.05)],[D(w),H(j)],[D(w+.05*i/a),H(j)]],d),Vo("tr",[[D(T-.05*i/a),H(j)],[D(T),H(j)],[D(T),H(j+.05)]],d),Vo("bl",[[D(w),H(O-.05)],[D(w),H(O)],[D(w+.05*i/a),H(O)]],d),Vo("br",[[D(T-.05*i/a),H(O)],[D(T),H(O)],[D(T),H(O-.05)]],d)])}if(z.has("rings")&&u){const st=(u.x0+u.x1)/2,V=(u.y0+u.y1)/2,d=Math.max(u.y1-u.y0,(u.x1-u.x0)*a/i)*.62*1e3,w=(T,j,O,L,B)=>({id:T,name:T,type:"ellipse",params:{w:Gt(j*2),h:Gt(j*2)},pos:[D(st),H(V)],rot:0,scale:[1,1],opacity:.7,fill:{type:"none"},stroke:{color:v.accent,width:B,dash:O,...v.glow?{blur:6}:{}},keys:{rot:[{time:0,value:0},{time:Gt(m),value:Gt(L*m*24)}]}});_("Breakdown · vòng HUD",[w("r1",d,[40,26],1,4),w("r2",d*1.07,[8,18],-1,3)])}if(z.has("index")&&u&&s.forEach((st,V)=>{const d=v.id==="dark-luxury"?HI[V]:String(V+1).padStart(2,"0");C(vr(n(),Gt(st.start+E),st.duration,d,v,{x:go(u.x0-.5+.07),y:go(u.y0-.5+.06),size:48,color:v.accent,font:v.move,italic:v.italic,weight:800,k:rt,glow:!1}))}),z.has("dims")&&u){const st={color:v.text,width:3},V=.012,d=u.y1+.03,w=u.x0-.035*i/a;_("Breakdown · kích thước",[Vo("h",[[D(u.x0),H(d)],[D(u.x1),H(d)]],st),Vo("ha",[[D(u.x0+V),H(d-V)],[D(u.x0),H(d)],[D(u.x0+V),H(d+V)]],st),Vo("hb",[[D(u.x1-V),H(d-V)],[D(u.x1),H(d)],[D(u.x1-V),H(d+V)]],st),Vo("v",[[D(w),H(u.y0)],[D(w),H(u.y1)]],st),Vo("va",[[D(w-V),H(u.y0+V)],[D(w),H(u.y0)],[D(w+V),H(u.y0+V)]],st),Vo("vb",[[D(w-V),H(u.y1-V)],[D(w),H(u.y1)],[D(w+V),H(u.y1-V)]],st)]);const T=J?.width>1?`${J.width} × ${J.height}`:"";s.forEach((j,O)=>{const L=C(vr(n(),Gt(j.start+E),j.duration,`${T?T+" · ":""}${j.duration.toFixed(1)} s`,v,{x:go((w+u.x0)/2-.5-.012*i/a),y:go((u.y0+u.y1)/2-.5),size:16,color:v.text,weight:500,k:rt,glow:!1}));L.rotation=-90})}if(z.has("arrows")&&u&&b.raw){const st=at(b.raw),V=[st.x0<u.x0?st.x1+.01:st.x0-.01,(st.y0+st.y1)/2],d=[u.x0<st.x0?u.x1+.01:u.x0-.01,(u.y0+u.y1)/2+.03],w=[(V[0]+d[0])/2,Math.min(V[1],d[1])-.08],T=[];for(let lt=0;lt<=16;lt++){const Y=lt/16,dt=(1-Y)*(1-Y)*V[0]+2*Y*(1-Y)*w[0]+Y*Y*d[0],bt=(1-Y)*(1-Y)*V[1]+2*Y*(1-Y)*w[1]+Y*Y*d[1];T.push([D(dt),H(bt)])}const j=T[16][0]-T[15][0],O=T[16][1]-T[15][1],L=Math.hypot(j,O)||1,B=j/L,X=O/L,Q=26,et=T[16];_("Breakdown · mũi tên",[Vo("c",T,{color:v.accent,width:6,cap:"round",dash:[18,12]}),Vo("hd",[[Gt(et[0]-B*Q-X*Q*.6),Gt(et[1]-X*Q+B*Q*.6)],et,[Gt(et[0]-B*Q+X*Q*.6),Gt(et[1]-X*Q-B*Q*.6)]],{color:v.accent,width:6,cap:"round"})],$,m,{motionKeys:Cl(m,.3)})}if(z.has("strip")){const st=U?.965:.955,V=.06,d=.94,w=[gi("bg",D(.5),H(st),D(d)-D(V),18,{type:"color",color:v.text,opacity:.15})];s.forEach((T,j)=>{const O=V+(d-V)*(T.start-h)/m,L=V+(d-V)*(T.start+T.duration-h)/m;w.push(gi(`s${j}`,D((O+L)/2),H(st),D(L)-D(O)-4,14,{type:"color",color:j%2?v.accent:v.rim,opacity:.85}))}),w.push(gi("ph",D(V),H(st),5,44,{type:"color",color:"#ff3b3b"},null,{keys:{"pos.0":[{time:0,value:D(V)},{time:Gt(m),value:D(d)}]}})),_("Breakdown · timeline",w)}return z.has("osd")&&(C(vr(n(),$,m,F.play,v,{x:-.33,y:.465,size:22,color:"#ffffff",font:"Courier New",weight:700,k:rt,glow:!1})),_("Breakdown · REC",[{id:"rec",name:"Rec",type:"ellipse",params:{w:22,h:22},pos:[D(.06),H(.035)],rot:0,scale:[1,1],opacity:1,fill:{type:"color",color:"#ff2b2b"},stroke:null,keys:{opacity:Array.from({length:Math.min(60,Math.floor(m/.5)+1)},(st,V)=>({time:Gt(V*.5),value:V%2?0:1}))}}]),s.forEach((st,V)=>{const d=st.start-h,w=Math.floor(d/60),T=(d%60).toFixed(1).padStart(4,"0");C(vr(n(),Gt(st.start+E),st.duration,`${F.shot} ${String(V+1).padStart(2,"0")} 00:${String(w).padStart(2,"0")}:${T}`,v,{x:.22,y:.465,size:20,color:"#ffffff",font:"Courier New",weight:700,k:rt,glow:!1}))})),{add:P,shots:s.map(st=>st.id),start:$,end:x,style:v.id,layout:k}}const ZI=String.raw`
|
|
336
|
+
const L=S.look
|
|
337
|
+
const FONTS={mont:'"Clipoox Montserrat", system-ui, sans-serif',anton:'"Clipoox Anton", Impact, sans-serif',oswald:'"Clipoox Oswald", "Arial Narrow", sans-serif',play:'"Clipoox Playfair Display", Georgia, serif',bevn:'"Clipoox Be Vietnam Pro", system-ui, sans-serif',bungee:'"Clipoox Bungee", Impact, sans-serif',mono:'"SF Mono", Menlo, "Courier New", monospace'}
|
|
338
|
+
function FF(env,k){const f=env.fonts||{};return (k!=='mono'&&f[k])||FONTS[k]||FONTS.mont}
|
|
339
|
+
const KEYS=[['q','w','e','r','t','y','u','i','o','p'],['a','s','d','f','g','h','j','k','l'],['z','x','c','v','b','n','m']]
|
|
340
|
+
const LIGHT=['widget','paper','comic'].includes(L.frame)
|
|
341
|
+
function rr(g,x,y,w,h,r){r=Math.max(0,Math.min(r,w/2,h/2));g.beginPath();g.moveTo(x+r,y);g.arcTo(x+w,y,x+w,y+h,r);g.arcTo(x+w,y+h,x,y+h,r);g.arcTo(x,y+h,x,y,r);g.arcTo(x,y,x+w,y,r);g.closePath()}
|
|
342
|
+
function poly(g,pts){g.beginPath();pts.forEach((p,i)=>i?g.lineTo(p[0],p[1]):g.moveTo(p[0],p[1]));g.closePath()}
|
|
343
|
+
function glowStroke(g,w,c,blur){g.lineWidth=w;g.strokeStyle=c||L.line;if(blur){g.shadowColor=c||L.line;g.shadowBlur=blur}g.stroke();g.shadowBlur=0}
|
|
344
|
+
// the panel's body in its design: x, y, w, h in the element canvas; role = chip | box | card | key
|
|
345
|
+
function box(g,x,y,w,h,role,a,t){
|
|
346
|
+
g.save();g.globalAlpha=a;const s=Math.min(w,h),lw=Math.max(1.5,s*.018)
|
|
347
|
+
const F=L.frame
|
|
348
|
+
if(F==='glass'){rr(g,x,y,w,h,role==='chip'?h/2:s*.12);g.fillStyle=L.fill;g.fill();const gr=g.createLinearGradient(x,y,x,y+h);gr.addColorStop(0,'rgba(255,255,255,0.16)');gr.addColorStop(.5,'rgba(255,255,255,0.02)');g.fillStyle=gr;g.fill();glowStroke(g,lw,L.line,L.glow)}
|
|
349
|
+
else if(F==='cut'){const c=s*.16;poly(g,[[x+c,y],[x+w,y],[x+w,y+h-c],[x+w-c,y+h],[x,y+h],[x,y+c]]);g.fillStyle=L.fill;g.fill();glowStroke(g,lw,L.line,L.glow)
|
|
350
|
+
const b=s*.12,o=lw*3;g.lineWidth=lw*1.6;g.strokeStyle=L.line;g.shadowColor=L.line;g.shadowBlur=L.glow*.6;[[x-o,y+b,x-o,y-o,x+b,y-o],[x+w+o-b,y+h+o,x+w+o,y+h+o,x+w+o,y+h+o-b]].forEach(p=>{g.beginPath();g.moveTo(p[0],p[1]);g.lineTo(p[2],p[3]);g.lineTo(p[4],p[5]);g.stroke()})
|
|
351
|
+
g.shadowBlur=0;g.globalAlpha=a*.5;for(let i=0;i<6;i++){g.fillStyle=L.line;g.fillRect(x+w*.62+i*w*.05,y+lw*2.5,w*.025,lw*1.4)}}
|
|
352
|
+
else if(F==='terminal'){rr(g,x,y,w,h,s*.05);g.fillStyle=L.fill;g.fill();g.lineWidth=lw*.8;g.strokeStyle=M.rgba(L.line,.5);g.stroke()
|
|
353
|
+
if(role!=='key'&&role!=='chip'){const bh=Math.max(10,h*.13);g.save();rr(g,x,y,w,h,s*.05);g.clip();g.fillStyle='rgba(255,255,255,0.08)';g.fillRect(x,y,w,bh);g.restore();['#ff5f57','#febc2e','#28c840'].forEach((c,i)=>{g.beginPath();g.arc(x+bh*.6+i*bh*.65,y+bh/2,bh*.2,0,7);g.fillStyle=c;g.fill()})}}
|
|
354
|
+
else if(F==='widget'){g.shadowColor='rgba(0,0,0,0.35)';g.shadowBlur=s*.18;g.shadowOffsetY=s*.05;rr(g,x,y,w,h,role==='key'?s*.18:role==='chip'?h/2:s*.2);g.fillStyle=L.fill;g.fill();g.shadowColor='transparent'}
|
|
355
|
+
else if(F==='wire'){g.setLineDash([]);rr(g,x,y,w,h,s*.04);glowStroke(g,lw*.8,L.line,L.glow*.6);g.save();rr(g,x,y,w,h,s*.04);g.clip();g.globalAlpha=a*.12;g.fillStyle=L.line;for(let yy=y;yy<y+h;yy+=4)g.fillRect(x,yy,w,1);g.restore()
|
|
356
|
+
g.fillStyle=L.line;[[x,y],[x+w,y],[x,y+h],[x+w,y+h]].forEach(p=>{g.fillRect(p[0]-lw*1.5,p[1]-lw*1.5,lw*3,lw*3)})}
|
|
357
|
+
else if(F==='neon'){rr(g,x,y,w,h,role==='chip'?h/2:s*.16);g.lineWidth=lw*3.2;g.strokeStyle=L.line;g.shadowColor=L.line;g.shadowBlur=L.glow*1.4;g.globalAlpha=a*.55;g.stroke();g.globalAlpha=a;g.shadowBlur=L.glow*.4;g.lineWidth=lw*1.1;g.strokeStyle='#ffffff';g.stroke();g.shadowBlur=0}
|
|
358
|
+
else if(F==='paper'){g.shadowColor='rgba(0,0,0,0.4)';g.shadowBlur=s*.08;g.shadowOffsetY=s*.03;g.fillStyle=L.fill;g.fillRect(x,y,w,h);g.shadowColor='transparent'
|
|
359
|
+
if(role!=='key'){g.fillStyle='rgba(255,236,170,0.75)';g.save();g.translate(x+w*.12,y);g.rotate(-.35);g.fillRect(-s*.12,-s*.035,s*.24,s*.07);g.restore();g.save();g.translate(x+w*.88,y);g.rotate(.35);g.fillRect(-s*.12,-s*.035,s*.24,s*.07);g.restore()}}
|
|
360
|
+
else if(F==='notch'){const c=s*.14;poly(g,[[x,y],[x+w-c,y],[x+w,y+c],[x+w,y+h],[x+c,y+h],[x,y+h-c]]);g.fillStyle=L.fill;g.fill();glowStroke(g,lw,L.line,L.glow*.5)
|
|
361
|
+
if(role!=='key'&&role!=='chip'){g.save();poly(g,[[x,y],[x+w-c,y],[x+w,y+c],[x+w,y+h],[x+c,y+h],[x,y+h-c]]);g.clip();g.globalAlpha=a*.5;g.fillStyle=L.line;for(let i=-4;i<24;i++){g.beginPath();g.moveTo(x+i*s*.06,y+h);g.lineTo(x+i*s*.06+s*.03,y+h);g.lineTo(x+i*s*.06+s*.03+h*.06,y+h-h*.06);g.lineTo(x+i*s*.06+h*.06,y+h-h*.06);g.fill()}g.restore()}}
|
|
362
|
+
else if(F==='pixel'){const p=Math.max(3,Math.round(s*.03));g.fillStyle=L.fill;g.fillRect(x+p,y,w-2*p,h);g.fillRect(x,y+p,w,h-2*p);g.fillStyle=L.line;g.fillRect(x+p,y,w-2*p,p);g.fillRect(x+p,y+h-p,w-2*p,p);g.fillRect(x,y+p,p,h-2*p);g.fillRect(x+w-p,y+p,p,h-2*p)
|
|
363
|
+
g.fillStyle='rgba(0,0,0,0.35)';g.fillRect(x+p,y+h,w-p,p);g.fillRect(x+w,y+p,p,h-p)}
|
|
364
|
+
else if(F==='comic'){if(role!=='key'){g.fillStyle='#111';g.fillRect(x+s*.04,y+s*.04,w,h)}g.fillStyle=L.fill;g.fillRect(x,y,w,h);g.lineWidth=Math.max(3,s*.035);g.strokeStyle='#111';g.strokeRect(x,y,w,h)
|
|
365
|
+
if(role==='box'||role==='chip'){g.save();g.beginPath();g.rect(x,y,w,h);g.clip();g.fillStyle=M.rgba(L.accent,.35);for(let yy=y;yy<y+h*.4;yy+=s*.05)for(let xx=x+w*.6;xx<x+w;xx+=s*.05){const r=s*.012*(1-(yy-y)/(h*.4));if(r>0){g.beginPath();g.arc(xx,yy,r,0,7);g.fill()}}g.restore()}
|
|
366
|
+
if(role==='chip'){g.fillStyle=L.fill;g.beginPath();g.moveTo(x+w*.2,y+h);g.lineTo(x+w*.15,y+h+h*.4);g.lineTo(x+w*.32,y+h);g.closePath();g.fill();g.lineWidth=Math.max(3,s*.035);g.strokeStyle='#111';g.beginPath();g.moveTo(x+w*.2,y+h);g.lineTo(x+w*.15,y+h+h*.4);g.lineTo(x+w*.32,y+h);g.stroke()}}
|
|
367
|
+
else if(F==='underline'){g.fillStyle=L.line;g.shadowColor=L.line;g.shadowBlur=L.glow;g.fillRect(x,y+h-lw,w*(role==='key'?1:M.ease.outCubic(M.clamp(t*2,0,1))),lw);g.shadowBlur=0;if(role!=='key'){g.fillRect(x,y+h*.2,lw*1.5,h*.6)}}
|
|
368
|
+
else if(F==='bubble'){const r=role==='key'?s*.2:Math.min(h*.45,s*.3);rr(g,x,y,w,h,r);g.fillStyle=role==='key'?'rgba(255,255,255,0.9)':L.fill;g.fill();if(role==='box'||role==='chip'){g.beginPath();g.moveTo(x+w-r*.4,y+h-r*.6);g.quadraticCurveTo(x+w+r*.35,y+h+r*.1,x+w+r*.45,y+h);g.quadraticCurveTo(x+w-r*.1,y+h+r*.05,x+w-r*1.1,y+h-r*.05);g.fill()}}
|
|
369
|
+
else if(F==='radial'){if(role==='chip'){rr(g,x,y,w,h,h/2);g.fillStyle=L.fill;g.fill();glowStroke(g,lw,L.line,L.glow)}else{rr(g,x,y,w,h,s*.08);g.fillStyle=L.fill;g.fill();glowStroke(g,lw*.7,M.rgba(L.line,.6),0)}}
|
|
370
|
+
else if(F==='film'){g.fillStyle=L.fill;g.fillRect(x,y,w,h);if(role!=='key'){const hs=Math.max(6,h*.07),gp=hs*1.8;g.fillStyle='rgba(255,255,255,0.85)';for(let xx=x+gp*.5;xx<x+w-hs;xx+=gp){rr(g,xx,y+hs*.5,hs,hs*.8,hs*.2);g.fill();rr(g,xx,y+h-hs*1.3,hs,hs*.8,hs*.2);g.fill()}}else{g.lineWidth=lw*.6;g.strokeStyle=M.rgba(L.line,.4);g.strokeRect(x,y,w,h)}}
|
|
371
|
+
else if(F==='luxe'){g.fillStyle=L.fill;g.fillRect(x,y,w,h);g.lineWidth=Math.max(1,lw*.5);g.strokeStyle=L.line;g.strokeRect(x,y,w,h);if(role!=='key'){const i=s*.04;g.strokeRect(x+i,y+i,w-2*i,h-2*i);g.fillStyle=L.line;g.save();g.translate(x+w/2,y);g.rotate(Math.PI/4);g.fillRect(-s*.025,-s*.025,s*.05,s*.05);g.restore()}}
|
|
372
|
+
g.restore()
|
|
373
|
+
}
|
|
374
|
+
// text inside a panel: dark on the light designs, mono / caps per design
|
|
375
|
+
function inkOf(){return L.text}
|
|
376
|
+
function fontOf(env,wt,px){const caps=['cut','notch','film','pixel'].includes(L.frame);return [(L.frame==='luxe'||L.frame==='paper')&&wt<700?'italic ':'',wt,' ',Math.round(px),'px ',FF(env,L.font)].join('')}
|
|
377
|
+
function txt(s){return ['cut','notch','film','pixel'].includes(L.frame)?String(s).toUpperCase():String(s)}
|
|
378
|
+
function wrap(g,text,maxW){const words=String(text).split(' '),lines=[];let cur='';for(const w of words){const n=cur?cur+' '+w:w;if(g.measureText(n).width>maxW&&cur){lines.push(cur);cur=w}else cur=n}if(cur||!lines.length)lines.push(cur);return lines}
|
|
379
|
+
function typedAt(t){let n=0;for(let i=0;i<TT.length;i++)if(TT[i]<=t)n=i+1;return n}
|
|
380
|
+
function draw(g,t,DW,DH,env){
|
|
381
|
+
const pad=DH*.08
|
|
382
|
+
if(S.kind==='chip'){box(g,4,4,DW-8,DH-8-(L.frame==='comic'?DH*.25:0),'chip',1,t);g.fillStyle=inkOf();g.font=fontOf(env,600,DH*.36);g.textBaseline='middle';g.textAlign='center';g.fillText(txt(S.text),DW/2,(DH-(L.frame==='comic'?DH*.25:0))/2,DW-DH*.6);return}
|
|
383
|
+
if(S.kind==='prompt'){
|
|
384
|
+
const ch=DH*.18,n=typedAt(t)
|
|
385
|
+
// the model line: a chip over the box, or the window title (terminal), or the slate (film)
|
|
386
|
+
if(L.frame==='terminal'){box(g,2,0,DW-4,DH-2,'box',1,t);g.fillStyle=M.rgba(L.text,.6);g.font=fontOf(env,500,DH*.05);g.textBaseline='middle';g.textAlign='center';g.fillText(S.label+' '+S.model,DW/2,DH*.065)}
|
|
387
|
+
else if(L.frame==='bubble'){g.fillStyle=M.rgba('#ffffff',.85);g.font=fontOf(env,600,ch*.4);g.textAlign='left';g.textBaseline='middle';g.fillText(S.label+' '+S.model,DW*.05,ch*.45)}
|
|
388
|
+
else{box(g,DW*.04,0,DW*.6,ch,'chip',1,t);g.textBaseline='middle';g.textAlign='left';g.font=fontOf(env,500,ch*.4);g.fillStyle=inkOf();const lab=txt(S.label)+' ',lw=g.measureText(lab).width;g.fillText(lab,DW*.08,ch/2);g.fillStyle=L.accent;g.font=fontOf(env,700,ch*.4);g.fillText(txt(S.model),DW*.08+lw,ch/2,DW*.52-lw)}
|
|
389
|
+
const by=L.frame==='terminal'?DH*.15:ch+DH*.05,bh=DH-by-4,bx=L.frame==='radial'?DH*.42:0
|
|
390
|
+
if(L.frame!=='terminal')box(g,2,by,DW-4-(L.frame==='bubble'?DH*.08:0),bh,'box',1,t)
|
|
391
|
+
if(L.frame==='radial'){const cx=bh*.42+8,cy=by+bh/2,r=bh*.3,p=TT.length?n/TT.length:0;g.lineWidth=bh*.07;g.strokeStyle=M.rgba(L.line,.2);g.beginPath();g.arc(cx,cy,r,0,7);g.stroke();g.strokeStyle=L.accent;g.shadowColor=L.accent;g.shadowBlur=L.glow;g.beginPath();g.arc(cx,cy,r,-Math.PI/2,-Math.PI/2+p*Math.PI*2);g.stroke();g.shadowBlur=0;g.fillStyle=L.text;g.font=fontOf(env,700,r*.55);g.textAlign='center';g.textBaseline='middle';g.fillText(Math.round(p*100)+'%',cx,cy)}
|
|
392
|
+
// chat: three bouncing dots until the first letter
|
|
393
|
+
if(L.frame==='bubble'&&TT.length&&t<TT[0]){for(let i=0;i<3;i++){const yy=by+bh/2-Math.max(0,Math.sin((t*8-i*.8)))*bh*.08;g.beginPath();g.arc(DW*.12+i*bh*.16,yy,bh*.05,0,7);g.fillStyle='rgba(255,255,255,0.9)';g.fill()}return}
|
|
394
|
+
const shown=S.text.slice(0,n),fs=Math.round(bh*(L.frame==='terminal'?.13:.15)),x0=pad*1.2+bx;g.font=fontOf(env,L.frame==='terminal'?500:500,fs);g.fillStyle=inkOf();g.textBaseline='top';g.textAlign='left'
|
|
395
|
+
const lead=L.frame==='terminal'?'> ':'',maxW=DW-pad*2.4-bx-(L.frame==='bubble'?DH*.08:0)
|
|
396
|
+
const lines=wrap(g,lead+txt(shown),maxW).slice(-4)
|
|
397
|
+
lines.forEach((l,i)=>{if(L.frame==='luxe'){const tr=Math.max(0,1-M.clamp((t-.1)/.8,0,1));g.fillText(l.split('').join(tr>0.05?' ':''),x0,by+pad+i*fs*1.3)}else g.fillText(l,x0,by+pad+i*fs*1.3)})
|
|
398
|
+
const typing=n>0&&n<S.text.length,blink=typing||Math.floor(t*2)%2===0,last=lines[lines.length-1]||'',cx=x0+g.measureText(last).width+3,cy=by+pad+(lines.length-1)*fs*1.3
|
|
399
|
+
if(blink&&TT.length&&t>=TT[0]-.6){g.fillStyle=L.accent;if(L.frame==='terminal'||L.frame==='pixel')g.fillRect(cx,cy,fs*.55,fs);else g.fillRect(cx,cy,Math.max(2,fs*.08),fs*1.05)}
|
|
400
|
+
return}
|
|
401
|
+
if(S.kind==='grid')return drawGrid(g,t,DW,DH,env)
|
|
402
|
+
if(S.kind==='cta'){
|
|
403
|
+
const C=S.cta;g.textAlign='center';g.textBaseline='middle';g.fillStyle=L.frame==='comic'||L.frame==='paper'?'#ffffff':L.text;g.font=fontOf(env,500,DH*.075);g.fillText(txt(C.lead),DW/2,DH*.1)
|
|
404
|
+
const pop=L.frame==='luxe'?M.ease.outCubic(M.clamp((t-.15)/.7,0,1)):M.ease.outBack(M.clamp((t-.15)/.45,0,1))
|
|
405
|
+
g.save();g.translate(DW/2,DH*.28);g.scale(pop,pop)
|
|
406
|
+
if(L.frame==='comic'){g.fillStyle='#ffd23f';g.beginPath();for(let i=0;i<24;i++){const r=i%2?DH*.13:DH*.24,a=i/24*Math.PI*2;g.lineTo(Math.cos(a)*r*2.2,Math.sin(a)*r)}g.closePath();g.fill();g.lineWidth=5;g.strokeStyle='#111';g.stroke()}
|
|
407
|
+
const big=L.frame==='luxe'||L.frame==='paper'?'italic 800 '+Math.round(DH*.17)+'px '+FF(env,'play'):L.frame==='terminal'?'700 '+Math.round(DH*.14)+'px '+FF(env,'mono'):L.frame==='pixel'||L.frame==='neon'||L.frame==='comic'?'400 '+Math.round(DH*.16)+'px '+FF(env,'bungee'):'italic 400 '+Math.round(DH*.2)+'px '+FF(env,'anton')
|
|
408
|
+
g.font=big;g.fillStyle=L.frame==='comic'?'#111':L.accent;if(L.glow){g.shadowColor=L.accent;g.shadowBlur=L.glow}g.fillText((L.frame==='terminal'?'$ ':'')+'“'+C.word+'”',0,0,DW*.96);g.restore()
|
|
409
|
+
const n=C.chips.length,cw=DW*.32,chh=DH*.16,gap=DW*.04,x0=DW/2-(n*cw+(n-1)*gap)/2
|
|
410
|
+
C.chips.forEach((tx,k)=>{const e=M.ease.outCubic(M.clamp((t-.45-k*.15)/.35,0,1));if(e<=0)return;const x=x0+k*(cw+gap),y=DH*.47+(1-e)*DH*.04;box(g,x,y,cw,chh,'card',e,t)
|
|
411
|
+
const parts=String(tx).split('|');g.save();g.globalAlpha=e;g.textAlign='center';parts.forEach((p,i)=>{g.fillStyle=i?inkOf():L.accent;g.font=i?fontOf(env,600,chh*.17):fontOf(env,800,chh*.25);g.fillText(txt(p.trim()),x+cw/2,y+chh*(parts.length>1?(.36+.34*i):.5),cw*.9)});g.restore()})
|
|
412
|
+
if(C.doc){const e=M.ease.outCubic(M.clamp((t-.45-n*.15)/.35,0,1));if(e>0){const w=DW*.2,h=DH*.2,x=DW/2-w/2,y=DH*.7;box(g,x,y,w,h,'card',e,t);g.save();g.globalAlpha=e;g.strokeStyle=inkOf();g.lineWidth=2.5;const ix=x+w/2-w*.12,iy=y+h*.14,iw=w*.24,ih=h*.42;rr(g,ix,iy,iw,ih,3);g.stroke();for(let i=0;i<3;i++){g.beginPath();g.moveTo(ix+iw*.2,iy+ih*(.35+i*.2));g.lineTo(ix+iw*.8,iy+ih*(.35+i*.2));g.stroke()}
|
|
413
|
+
g.fillStyle=inkOf();g.font=fontOf(env,600,h*.13);g.textAlign='center';g.fillText(txt(C.doc),x+w/2,y+h*.8,w*.92);g.restore()}}
|
|
414
|
+
return}
|
|
415
|
+
if(S.kind==='keyboard')return drawKeys(g,t,DW,DH,env)
|
|
416
|
+
}
|
|
417
|
+
function litMap(t){const lit={},n=typedAt(t);for(let i=0;i<TT.length;i++){const d=t-TT[i];if(d>=-.02&&d<.2){let ch=S.text[i].toLowerCase().normalize('NFD').replace(/[̀-ͯ]/g,'').replace('đ','d');if(ch===' ')ch='space';lit[ch]=Math.max(lit[ch]||0,1-d/.2)}}
|
|
418
|
+
if(n>=S.text.length&&TT.length&&t-TT[TT.length-1]>.25&&t-TT[TT.length-1]<.6)lit.enter=1;return lit}
|
|
419
|
+
function drawKeys(g,t,DW,DH,env){
|
|
420
|
+
const lit=litMap(t),K=L.keys
|
|
421
|
+
if(K==='radial'){const cx=DW/2,cy=DH*1.05,R=DH*.92,all=KEYS.flat();all.forEach((k,i)=>{const a=Math.PI*(1.08+.84*i/(all.length-1)),x=cx+Math.cos(a)*R,y=cy+Math.sin(a)*R*.95,v=lit[k]||0,r=DH*.075*(1+.35*v)
|
|
422
|
+
g.beginPath();g.arc(x,y,r,0,7);g.fillStyle=v?M.rgba(L.accent,.5+.5*v):'rgba(255,255,255,0.08)';g.fill();g.lineWidth=2;g.strokeStyle=v?L.accent:M.rgba(L.line,.6);if(v){g.shadowColor=L.accent;g.shadowBlur=L.glow*1.5}g.stroke();g.shadowBlur=0;g.fillStyle=v?'#fff':L.text;g.font=fontOf(env,700,r*.9);g.textAlign='center';g.textBaseline='middle';g.fillText(k.toUpperCase(),x,y)})
|
|
423
|
+
const sv=lit.space||0;g.beginPath();g.arc(cx,cy,R*.55,Math.PI*1.15,Math.PI*1.85);g.lineWidth=DH*.08;g.strokeStyle=sv?L.accent:M.rgba(L.line,.25);g.lineCap='round';g.stroke();g.lineCap='butt';return}
|
|
424
|
+
const kw=DW/10.6,kh=DH/4.6,g1=kw*.12
|
|
425
|
+
const key=(x,y,w,h,label,v)=>{
|
|
426
|
+
g.save()
|
|
427
|
+
if(K==='flat'){rr(g,x,y,w,h,h*.18);g.fillStyle=v?M.rgba(L.accent,.35+.5*v):'rgba(255,255,255,0.10)';g.fill();g.lineWidth=v?2.5:1.3;g.strokeStyle=v?L.accent:M.rgba(L.line,.7);if(v){g.shadowColor=L.accent;g.shadowBlur=L.glow*1.4*v}g.stroke()}
|
|
428
|
+
else if(K==='outline'){rr(g,x,y,w,h,K==='outline'&&L.frame==='cut'?0:h*.25);if(v){g.fillStyle=M.rgba(L.accent,.6*v);g.fill()}g.lineWidth=2;g.strokeStyle=L.line;g.shadowColor=L.line;g.shadowBlur=v?L.glow*1.6:L.glow*.3;g.globalAlpha=.5+.5*v;g.stroke()}
|
|
429
|
+
else if(K==='mono'){g.font=fontOf(env,500,h*.42);g.fillStyle=v?L.accent:M.rgba(L.text,.55);g.textAlign='center';g.textBaseline='middle';if(label)g.fillText('['+label+']',x+w/2,y+h/2);if(v){g.fillStyle=M.rgba(L.accent,.25*v);g.fillRect(x,y,w,h)}g.restore();return}
|
|
430
|
+
else if(K==='ios'){g.shadowColor='rgba(0,0,0,0.35)';g.shadowBlur=3;g.shadowOffsetY=2;rr(g,x,y,w,h,h*.16);g.fillStyle='rgba(255,255,255,0.92)';g.fill();g.shadowColor='transparent'
|
|
431
|
+
if(v&&label){rr(g,x-w*.15,y-h*1.25,w*1.3,h*1.2,h*.2);g.fillStyle='#ffffff';g.fill();g.fillStyle='#111';g.font='500 '+Math.round(h*.75)+'px '+FF(env,'bevn');g.textAlign='center';g.textBaseline='middle';g.fillText(label.toLowerCase(),x+w/2,y-h*.65)}}
|
|
432
|
+
else if(K==='dots'){const n=4;for(let i=0;i<n;i++)for(let j=0;j<3;j++){g.beginPath();g.arc(x+w*(i+.5)/n,y+h*(j+.5)/3,Math.min(w,h)*.05*(1+2*v),0,7);g.fillStyle=v?L.accent:M.rgba(L.line,.35);g.fill()}}
|
|
433
|
+
else if(K==='round'){const r=Math.min(w,h)*.48;g.beginPath();g.arc(x+w/2,y+h/2,r,0,7);g.fillStyle=L.frame==='comic'?'#fff':'#2b2b2b';g.fill();g.lineWidth=Math.max(2,r*.16);g.strokeStyle=v?L.accent:L.frame==='comic'?'#111':'#c9b48a';g.stroke();if(v){g.beginPath();g.arc(x+w/2,y+h/2+r*.12,r*.92,0,7);g.fillStyle=M.rgba(L.accent,.35);g.fill()}}
|
|
434
|
+
else if(K==='pixel'){g.fillStyle=v?L.accent:'rgba(255,255,255,0.12)';g.fillRect(x,y+(v?3:0),w,h-3);if(!v){g.fillStyle='rgba(0,0,0,0.45)';g.fillRect(x,y+h-3,w,3)}}
|
|
435
|
+
else if(K==='minimal'){if(v){g.fillStyle=L.accent;g.shadowColor=L.accent;g.shadowBlur=L.glow*2;g.fillRect(x+w*.2,y+h-3,w*.6,2)}}
|
|
436
|
+
if(label){g.shadowBlur=0;const ink=K==='ios'?'#111':K==='round'&&L.frame!=='comic'?'#f6f1e4':K==='round'?'#111':v?'#ffffff':L.text;g.fillStyle=ink;g.globalAlpha=K==='minimal'?.55+.45*v:1;g.font=fontOf(env,K==='minimal'?400:700,h*(K==='minimal'?.5+.15*v:.36));g.textAlign='center';g.textBaseline='middle';g.fillText(label,x+w/2,y+h/2)}
|
|
437
|
+
g.restore()}
|
|
438
|
+
KEYS.forEach((row,ri)=>{const off=ri*kw*.5+(DW-10*kw-g1*9)/2;row.forEach((k,ci)=>key(off+ci*(kw+g1)+g1/2,ri*(kh+g1)+g1,kw-g1,kh-g1*.4,K==='mono'?k:k.toUpperCase(),lit[k]||0))})
|
|
439
|
+
key(DW*.27,3*(kh+g1)+g1,DW*.46,kh-g1*.4,K==='mono'?'space':'',lit.space||0);key(DW*.76,3*(kh+g1)+g1,DW*.2,kh-g1*.4,K==='mono'?'enter':'⏎',lit.enter||0)
|
|
440
|
+
}
|
|
441
|
+
function drawGrid(g,t,DW,DH,env){
|
|
442
|
+
const n=S.items.length,G=L.grid,picked=S.pick>=0&&t>=S.pickAt,pk=M.ease.outCubic(M.clamp((t-S.pickAt)/.4,0,1))
|
|
443
|
+
const card=(k,cx,cy,cw,chh,rot,e,z)=>{if(e<=0)return;const me=picked&&S.pick===k,dim=picked&&!me?.35:1,s=(G==='ring'?z:1)*(me?1+.14*pk:1)
|
|
444
|
+
g.save();g.translate(cx,cy);g.rotate(rot*(me?1-pk:1));g.scale(s,s);g.globalAlpha=Math.min(1,e)*dim
|
|
445
|
+
const it=S.items[k],img=it.img&&M.asset?M.asset(it.img):null,pol=G==='polaroid',bw=pol?cw*.06:0,x=-cw/2,y=-chh/2
|
|
446
|
+
box(g,x,y,cw,chh+(pol?cw*.18:0),'card',1,t)
|
|
447
|
+
const ix=x+bw,iy=y+bw,iw=cw-bw*2,ih=chh-bw*2;g.save();g.beginPath();g.rect(ix,iy,iw,ih);g.clip()
|
|
448
|
+
if(img&&img.width){const sc=Math.max(iw/img.width,ih/img.height);g.drawImage(img,ix+iw/2-img.width*sc/2,iy+ih/2-img.height*sc/2,img.width*sc,img.height*sc)}
|
|
449
|
+
else{const base=L.frame==='bubble'?'#ffffff':L.accent,gr=g.createLinearGradient(ix,iy,ix+iw,iy+ih);gr.addColorStop(0,M.rgba(base,LIGHT?.18:.12));gr.addColorStop(1,M.rgba(base,LIGHT?.45:.38));g.fillStyle=gr;g.fillRect(ix,iy,iw,ih);g.fillStyle=LIGHT?'#222':L.text;g.font=fontOf(env,700,Math.min(iw,ih)*.22);g.textAlign='center';g.textBaseline='middle';g.fillText(txt(it.title||''),0,iy+ih/2,iw*.9)}
|
|
450
|
+
g.restore()
|
|
451
|
+
if(pol){g.fillStyle='#333';g.font=fontOf(env,500,cw*.09);g.textAlign='center';g.fillText('#'+(k+1),0,chh/2+cw*.09)}
|
|
452
|
+
if(me){rr(g,x-3,y-3,cw+6,chh+6+(pol?cw*.18:0),cw*.05);g.lineWidth=4;g.strokeStyle=L.accent;g.shadowColor=L.accent;g.shadowBlur=(L.glow||8)*1.6;g.stroke()}
|
|
453
|
+
g.restore()}
|
|
454
|
+
const appear=k=>M.ease.outBack(M.clamp((t-.08-k*.09)/.4,0,1))
|
|
455
|
+
if(G==='grid'){const c=S.cols,r=Math.ceil(n/c),gap=DW*.035,cw=(DW-gap*(c+1))/c,chh=(DH-gap*(r+1))/r
|
|
456
|
+
for(let k=0;k<n;k++){const i=Math.floor(k/c),j=k%c,e=appear(k),x=gap+j*(cw+gap)+cw/2,y=gap+i*(chh+gap)+chh/2;card(k,x+(DW/2-x)*(1-e),y+(DH/2-y)*(1-e),cw*(.6+.4*e),chh*(.6+.4*e),0,e,1)}}
|
|
457
|
+
else if(G==='fan'){const cw=DW*.3,chh=cw*1.3;for(let k=0;k<n;k++){const e=appear(k),u=n>1?k/(n-1)-.5:0,ang=u*1.1*e,x=DW/2+Math.sin(ang)*DH*.9,y=DH*.95-Math.cos(ang)*DH*.6;card(k,x,y,cw,chh,ang,e,1)}}
|
|
458
|
+
else if(G==='list'){const rh=DH/(n+.5);for(let k=0;k<n;k++){const e=M.clamp((t-.1-k*.12)/.15,0,1);if(e<=0)continue;const y=rh*(k+.5),me=picked&&S.pick===k
|
|
459
|
+
g.save();g.globalAlpha=picked&&!me?.4:1;if(me){g.fillStyle=M.rgba(L.accent,.25);g.fillRect(0,y,DW,rh*.9)}g.fillStyle=L.accent;g.font=fontOf(env,500,rh*.4);g.textAlign='left';g.textBaseline='middle';g.fillText((me?'> ':' ')+'img_0'+(k+1)+'.png',DW*.03,y+rh*.45)
|
|
460
|
+
g.fillStyle=M.rgba(L.text,.6);g.textAlign='right';g.fillText((1.2+k*.37).toFixed(1)+' MB ✓',DW*.97,y+rh*.45);const tw=rh*.75;g.save();g.translate(DW*.55,y+rh*.45);card(k,0,0,tw*1.3,tw,0,1,1);g.restore();g.restore()}}
|
|
461
|
+
else if(G==='stack'){const cw=DW*.42,chh=cw*.72;for(let k=0;k<n;k++){const e=M.ease.outCubic(M.clamp((t-.1-k*.14)/.35,0,1)),col=k%2,row=Math.floor(k/2),x=DW*(col?.71:.29),y=DH*.16+row*chh*1.12+(1-e)*DH*.08;card(k,x,y,cw,chh,0,e,1)}}
|
|
462
|
+
else if(G==='polaroid'){const cw=DW*.3,chh=cw;for(let k=0;k<n;k++){const e=M.ease.outBack(M.clamp((t-.1-k*.12)/.35,0,1)),i=Math.floor(k/3),j=k%3,rot=((k*37)%7-3)*.06,x=DW*(.2+.3*j)+((k*13)%5-2)*6,y=DH*(.3+.42*i)-(1-e)*DH*.4;card(k,x,y,cw,chh,rot,e,1)}}
|
|
463
|
+
else if(G==='strip'){const cw=DW*.3,chh=cw*.7,hs=chh*.12,slide=(1-M.ease.outCubic(M.clamp((t-.05)/.7,0,1)))*DW*.8,pickShift=picked?(DW/2-(cw*.55+S.pick*cw*1.05))*pk:0
|
|
464
|
+
g.fillStyle='rgba(10,10,10,0.88)';g.fillRect(0,DH/2-chh*.75,DW,chh*1.5);g.fillStyle='rgba(255,255,255,0.8)';for(let x=6;x<DW;x+=hs*2){g.fillRect(x,DH/2-chh*.7,hs,hs*.8);g.fillRect(x,DH/2+chh*.7-hs*.8,hs,hs*.8)}
|
|
465
|
+
for(let k=0;k<n;k++)card(k,cw*.55+k*cw*1.05+slide+pickShift,DH/2,cw,chh,0,1,1)}
|
|
466
|
+
else if(G==='ring'){const rot=t*.5+(picked?pk*0:0),items=[];for(let k=0;k<n;k++){const a=k/n*Math.PI*2+rot-(picked?((S.pick/n*Math.PI*2+rot)%(Math.PI*2))*pk:0),z=(Math.cos(a)+1.6)/2.6;items.push({k,x:DW/2+Math.sin(a)*DW*.36,y:DH*.5,z})}
|
|
467
|
+
items.sort((a,b)=>a.z-b.z).forEach(o=>card(o.k,o.x,o.y,DW*.26,DW*.32,0,appear(o.k),o.z))}
|
|
468
|
+
}
|
|
469
|
+
// the element's 4 corners on screen (TL TR BL BR, px): a w (of the frame width) × its-aspect rectangle at (x, y), turned
|
|
470
|
+
// tiltX (top away) / tiltY (right side away) degrees, in perspective; stuck on a surface it fills the layer
|
|
471
|
+
function quad(W,H,DW,DH){
|
|
472
|
+
if(S.fill)return [[W*.04,H*.04],[W*.96,H*.04],[W*.04,H*.96],[W*.96,H*.96]]
|
|
473
|
+
const w=S.w*W,h=w*DH/DW,ax=S.tiltX*Math.PI/180,ay=S.tiltY*Math.PI/180,D=W*1.6,cx=(.5+S.x)*W,cy=(.5+S.y)*H
|
|
474
|
+
return [[-w/2,-h/2],[w/2,-h/2],[-w/2,h/2],[w/2,h/2]].map(([x,y])=>{const X=x*Math.cos(ay),Y=y*Math.cos(ax),Z=x*Math.sin(ay)-y*Math.sin(ax),s=D/(D+Z);return [cx+X*s,cy+Y*s]})
|
|
475
|
+
}
|
|
476
|
+
function warp(ctx,img,iw,ih,q,sx0,sy0,sx1,sy1){sx0=sx0||0;sy0=sy0||0;sx1=sx1==null?1:sx1;sy1=sy1==null?1:sy1;const N=6;for(let i=0;i<N;i++)for(let j=0;j<N;j++){const u0=sx0+(sx1-sx0)*j/N,u1=sx0+(sx1-sx0)*(j+1)/N,v0=sy0+(sy1-sy0)*i/N,v1=sy0+(sy1-sy0)*(i+1)/N
|
|
477
|
+
const P=(u,v)=>[q[0][0]*(1-u)*(1-v)+q[1][0]*u*(1-v)+q[2][0]*(1-u)*v+q[3][0]*u*v,q[0][1]*(1-u)*(1-v)+q[1][1]*u*(1-v)+q[2][1]*(1-u)*v+q[3][1]*u*v]
|
|
478
|
+
const a=P(u0,v0),b=P(u1,v0),c=P(u0,v1),d=P(u1,v1);for(const [s0,s1,s2,d0,d1,d2] of [[[u0,v0],[u1,v0],[u0,v1],a,b,c],[[u1,v0],[u1,v1],[u0,v1],b,d,c]]){
|
|
479
|
+
ctx.save();ctx.beginPath();const mx=(d0[0]+d1[0]+d2[0])/3,my=(d0[1]+d1[1]+d2[1])/3,gr=p=>{const dx=p[0]-mx,dy=p[1]-my,l=Math.hypot(dx,dy)||1;return [p[0]+dx/l*.7,p[1]+dy/l*.7]}
|
|
480
|
+
const e0=gr(d0),e1=gr(d1),e2=gr(d2);ctx.moveTo(e0[0],e0[1]);ctx.lineTo(e1[0],e1[1]);ctx.lineTo(e2[0],e2[1]);ctx.closePath();ctx.clip()
|
|
481
|
+
const S0=[s0[0]*iw,s0[1]*ih],S1=[s1[0]*iw,s1[1]*ih],S2=[s2[0]*iw,s2[1]*ih],den=S0[0]*(S1[1]-S2[1])+S1[0]*(S2[1]-S0[1])+S2[0]*(S0[1]-S1[1])
|
|
482
|
+
if(Math.abs(den)>1e-9){const A=(d0[0]*(S1[1]-S2[1])+d1[0]*(S2[1]-S0[1])+d2[0]*(S0[1]-S1[1]))/den,B=(d0[1]*(S1[1]-S2[1])+d1[1]*(S2[1]-S0[1])+d2[1]*(S0[1]-S1[1]))/den
|
|
483
|
+
const C=(d0[0]*(S2[0]-S1[0])+d1[0]*(S0[0]-S2[0])+d2[0]*(S1[0]-S0[0]))/den,Dd=(d0[1]*(S2[0]-S1[0])+d1[1]*(S0[0]-S2[0])+d2[1]*(S1[0]-S0[0]))/den
|
|
484
|
+
const E=(d0[0]*(S1[0]*S2[1]-S2[0]*S1[1])+d1[0]*(S2[0]*S0[1]-S0[0]*S2[1])+d2[0]*(S0[0]*S1[1]-S1[0]*S0[1]))/den,F=(d0[1]*(S1[0]*S2[1]-S2[0]*S1[1])+d1[1]*(S2[0]*S0[1]-S0[0]*S2[1])+d2[1]*(S0[0]*S1[1]-S1[0]*S0[1]))/den
|
|
485
|
+
ctx.transform(A,B,C,Dd,E,F);ctx.drawImage(img,0,0)}
|
|
486
|
+
ctx.restore()}}}
|
|
487
|
+
function size(){const k=S.kind
|
|
488
|
+
if(k==='keyboard')return L.keys==='radial'?[1100,560]:[1100,520]
|
|
489
|
+
if(k==='chip')return [Math.round(260+S.text.length*15),L.frame==='comic'?130:100]
|
|
490
|
+
if(k==='cta')return [900,760]
|
|
491
|
+
if(k==='grid')return L.grid==='stack'?[900,Math.round(900*.42*.72*1.12*Math.ceil(S.items.length/2)+900*.2)]:L.grid==='grid'?[900,Math.round(900*Math.ceil(S.items.length/S.cols)/S.cols*1.25)]:L.grid==='list'?[900,Math.round(110*(S.items.length+.5))]:L.grid==='strip'?[1000,420]:L.grid==='ring'?[1000,560]:[900,760]
|
|
492
|
+
return [1000,560]}
|
|
493
|
+
function render(ctx,t,env){
|
|
494
|
+
const W=env.width,H=env.height,dur=env.duration,E=L.enter
|
|
495
|
+
const len=E==='step'?.5:E==='drop'?.6:E==='spring'?.7:E==='track'?.9:E==='scan'?.55:E==='strip'?.55:.35
|
|
496
|
+
const on=M.clamp((t-.02)/len,0,1),off=M.clamp((dur-t)/.3,0,1);if(on<=0||off<=0)return
|
|
497
|
+
const [DW,DH]=size(),cv=typeof OffscreenCanvas!=='undefined'?new OffscreenCanvas(DW,DH):null;if(!cv)return
|
|
498
|
+
draw(cv.getContext('2d'),t,DW,DH,env)
|
|
499
|
+
let q=quad(W,H,DW,DH),a=off,sx=1,sy=1,dx=0,dy=0,rot=L.frame==='paper'?-.035:0,clipY=1,iris=1,slices=0
|
|
500
|
+
const eo=M.ease.outCubic(on)
|
|
501
|
+
if(E==='flicker'){a*=eo*(t<.3?(.55+.45*Math.abs(Math.sin(t*90))):1);sx=sy=.86+.14*M.ease.outBack(on)}
|
|
502
|
+
else if(E==='unfold'){sy=on<.4?.02:.02+.98*M.ease.outCubic((on-.4)/.6);sx=M.ease.outCubic(Math.min(1,on/.4));a*=Math.min(1,on*3)}
|
|
503
|
+
else if(E==='slide'){dy=(1-eo)*H*.08;a*=eo}
|
|
504
|
+
else if(E==='spring'){sx=sy=M.ease.outElastic?M.ease.outElastic(on)*.999+.001:eo;a*=Math.min(1,on*4)}
|
|
505
|
+
else if(E==='glitch'){a*=Math.min(1,on*3);slices=on<1?1-on:0}
|
|
506
|
+
else if(E==='buzz'){const f=t<.9?[1,0,1,1,0,0,1,.3,1,0,1,1,1][Math.floor(t*14)%13]:1;a*=f}
|
|
507
|
+
else if(E==='drop'){dy=-(1-M.ease.outBounce(on))*H*.25;rot+=(1-on)*.15;a*=Math.min(1,on*4)}
|
|
508
|
+
else if(E==='scan'){clipY=eo}
|
|
509
|
+
else if(E==='step'){const s=Math.ceil(on*4)/4;sx=sy=s;a*=on>0?1:0}
|
|
510
|
+
else if(E==='burst'){sx=sy=M.ease.outBack(on)*1.0;a*=Math.min(1,on*3)}
|
|
511
|
+
else if(E==='fade'){a*=eo;dy=(1-eo)*H*.015}
|
|
512
|
+
else if(E==='iris'){iris=eo}
|
|
513
|
+
else if(E==='strip'){dx=-(1-eo)*W*.6;a*=Math.min(1,on*2)}
|
|
514
|
+
else if(E==='track'){a*=eo}
|
|
515
|
+
const mx=(q[0][0]+q[3][0])/2,my=(q[0][1]+q[3][1])/2,cs=Math.cos(rot),sn=Math.sin(rot)
|
|
516
|
+
q=q.map(p=>{const x=(p[0]-mx)*sx,y=(p[1]-my)*sy;return [mx+x*cs-y*sn+dx,my+x*sn+y*cs+dy]})
|
|
517
|
+
ctx.save();ctx.globalAlpha=Math.max(0,a)
|
|
518
|
+
if(E==='burst'&&on<1){ctx.save();ctx.globalAlpha=(1-on)*.8;ctx.strokeStyle=L.accent;ctx.lineWidth=4;for(let i=0;i<16;i++){const an=i/16*Math.PI*2,r0=Math.hypot(q[1][0]-q[0][0],q[2][1]-q[0][1])*.35*(1+on),r1=r0*1.5;ctx.beginPath();ctx.moveTo(mx+Math.cos(an)*r0,my+Math.sin(an)*r0);ctx.lineTo(mx+Math.cos(an)*r1,my+Math.sin(an)*r1);ctx.stroke()}ctx.restore()}
|
|
519
|
+
if(E==='iris'&&iris<1){ctx.beginPath();ctx.arc(mx,my,Math.hypot(W,H)*.5*iris,0,7);ctx.clip()}
|
|
520
|
+
if(slices>0){const n=7;for(let i=0;i<n;i++){const off=(Math.sin(i*91.7+Math.floor(t*30)*3.1)*.5)*W*.08*slices,q2=q.map(p=>[p[0]+off,p[1]]);warp(ctx,cv,DW,DH,q2,0,i/n,1,(i+1)/n)}}
|
|
521
|
+
else warp(ctx,cv,DW,DH,q,0,0,1,clipY)
|
|
522
|
+
if(E==='scan'&&on<1){const y=q[0][1]+(q[2][1]-q[0][1])*clipY;ctx.globalCompositeOperation='lighter';ctx.strokeStyle=L.line;ctx.lineWidth=3;ctx.shadowColor=L.line;ctx.shadowBlur=14;ctx.beginPath();ctx.moveTo(q[0][0],y);ctx.lineTo(q[1][0],y);ctx.stroke()}
|
|
523
|
+
ctx.restore()
|
|
524
|
+
}`,Go=(t,e,o,r,n,a,i,l,p)=>({id:t,vi:e,en:o,frame:r,enter:n,keys:a,grid:i,font:l,...p}),kd=Object.freeze([Go("glass","Kính hologram","Glass hologram","glass","flicker","flat","grid","mont",{line:"#c6f432",fill:"rgba(28,32,24,0.55)",text:"#f2ffe0",accent:"#c6f432",glow:18}),Go("scifi","Sci-fi góc vát","Sci-fi bevel","cut","unfold","outline","fan","oswald",{line:"#5ee7ff",fill:"rgba(4,22,36,0.62)",text:"#dffaff",accent:"#5ee7ff",glow:20}),Go("terminal","Terminal","Terminal","terminal","slide","mono","list","mono",{line:"#2bff6a",fill:"rgba(4,10,6,0.86)",text:"#b9ffcf",accent:"#2bff6a",glow:10}),Go("widget","Widget iOS","iOS widget","widget","spring","ios","stack","bevn",{line:"#ffffff",fill:"rgba(250,250,252,0.86)",text:"#111318",accent:"#0a84ff",glow:0}),Go("wireframe","Khung dây","Wireframe","wire","glitch","dots","grid","mono",{line:"#7fb8ff",fill:"rgba(0,0,0,0)",text:"#cfe4ff",accent:"#7fb8ff",glow:12}),Go("neon","Ống neon","Neon tube","neon","buzz","outline","fan","bungee",{line:"#ff4fd8",fill:"rgba(0,0,0,0)",text:"#ffe6fa",accent:"#ff4fd8",glow:26}),Go("paper","Giấy & polaroid","Paper & polaroid","paper","drop","round","polaroid","play",{line:"#2b2b2b",fill:"#f6f1e4",text:"#1e1e1e",accent:"#d9472b",glow:0}),Go("military","Quân sự","Military HUD","notch","scan","flat","grid","oswald",{line:"#ffb020",fill:"rgba(20,14,2,0.6)",text:"#ffe2a8",accent:"#ffb020",glow:12}),Go("pixel","Pixel 8-bit","8-bit pixel","pixel","step","pixel","grid","bungee",{line:"#ffd23f",fill:"rgba(30,14,60,0.85)",text:"#ffffff",accent:"#ffd23f",glow:0}),Go("comic","Truyện tranh","Comic","comic","burst","round","polaroid","bungee",{line:"#111111",fill:"#ffffff",text:"#111111",accent:"#ff2e4d",glow:0}),Go("minimal","Tối giản","Minimal","underline","fade","minimal","strip","bevn",{line:"#ffffff",fill:"rgba(0,0,0,0)",text:"#ffffff",accent:"#ffffff",glow:4}),Go("chat","Bong bóng chat","Chat bubbles","bubble","slide","ios","stack","bevn",{line:"#2f80ff",fill:"#2f80ff",text:"#ffffff",accent:"#2f80ff",glow:0}),Go("radial","Vòng tròn","Radial","radial","iris","radial","ring","mont",{line:"#9b7bff",fill:"rgba(14,8,34,0.6)",text:"#efe9ff",accent:"#b49bff",glow:18}),Go("film","Cuộn phim","Film strip","film","strip","flat","strip","oswald",{line:"#f2f2f2",fill:"rgba(12,12,12,0.88)",text:"#f5f5f5",accent:"#ffcc33",glow:0}),Go("luxury","Sang trọng","Luxury","luxe","track","minimal","fan","play",{line:"#e8c27a",fill:"rgba(8,6,2,0.55)",text:"#fff4dd",accent:"#e8c27a",glow:8})]),R0=kd.map(t=>t.id),D0=Object.freeze(["chip","prompt","grid","cta","keyboard"]),or=Object.freeze({maxSeconds:30,text:160,chip:48,items:9,chips:3,cps:[4,40],tilt:75,width:[.1,1]}),Vy=/^#[0-9a-fA-F]{6}$/,Ul=t=>Math.round(t*1e3)/1e3,Fi=t=>Math.round(t*1e4)/1e4,rn=(t,e,o,r)=>Number.isFinite(t)?Math.min(o,Math.max(e,t)):r,yn=(t,e)=>typeof t=="string"?t.replace(/[\u0000-\u001f]/g," ").trim().slice(0,e):"";function Wy(t,e){const o=kd.find(r=>r.id===t)??kd[0];return Vy.test(e??"")?{...o,accent:e.toLowerCase(),...o.glow?{line:e.toLowerCase()}:{}}:o}function Xy(t,e=.4,o=14){const r=[],n=1/rn(o,...or.cps,14);let a=e;for(let i=0;i<t.length;i++){r.push(Ul(a));const l=t[i],p=(Math.sin((i+1)*12.9898)*43758.5453%1+1)%1;a+=n*(.7+.6*p)*(l===" "?1.4:/[,.!?]/.test(l)?2.2:1)}return r}const B0=(t,e)=>`const ${t}=${JSON.stringify(e)};`;function JI(t,e=[],o){return Jo({code:[B0("S",t),B0("TT",e),ZI].join(`
|
|
525
|
+
`),params:{color:t.look.accent},preset:`hud-${t.kind}`,...o&&Object.keys(o).length?{assets:o}:{}})}function QI(t,e,{materials:o=[],locale:r="vi",fill:n=!1}={}){if(!D0.includes(t))throw Error(`hudPanel kind: ${D0.join(" | ")}`);if(e.look!=null&&!R0.includes(e.look))throw Error(`HUD look: ${R0.join(" | ")}`);if(e.color!=null&&!Vy.test(e.color))throw Error("HUD color must be #RRGGBB");const a=Wy(e.look,e.color),i=r==="en",l={chip:[0,-.32,.6,8,-10],prompt:[0,-.12,.78,10,-8],grid:[0,-.12,.8,6,6],cta:[0,-.18,.86,0,0],keyboard:[0,.32,.9,52,0]}[t],p={kind:t,look:a,fill:!!n,x:Fi(rn(Number(e.posX),-.5,.5,l[0])),y:Fi(rn(Number(e.posY),-.5,.5,l[1])),w:Fi(rn(Number(e.width),...or.width,l[2])),tiltX:Ul(rn(Number(e.tiltX),-or.tilt,or.tilt,l[3])),tiltY:Ul(rn(Number(e.tiltY),-or.tilt,or.tilt,l[4]))};let c=[],s={},h;if(t==="chip"&&(p.text=yn(e.text,or.chip)||(i?"Random photos → AI Edit":"Ảnh bất kỳ → AI Edit"),h=`HUD · ${p.text}`),t==="prompt"||t==="keyboard"){if(p.text=yn(e.text,or.text),!p.text)throw Error(`hudPanel ${t} needs text (the prompt that types in)`);c=Xy(p.text,rn(Number(e.typeAt),0,or.maxSeconds,.5),Number(e.cps)),t==="prompt"&&(p.label=yn(e.label,30)||(i?"Image model:":"Model ảnh:"),p.model=yn(e.model,30)||"Clipoox AI"),h=t==="prompt"?"HUD · prompt":"HUD · bàn phím"}if(t==="grid"){const f=Array.isArray(e.items)?e.items.slice(0,or.items):null,m=f?f.length:Math.round(rn(Number(e.count),2,or.items,6));if(m<2)throw Error("hudPanel grid needs 2–9 items");p.items=[];for(let y=0;y<m;y++){const $=f?.[y],x=typeof $=="string"?$:$?.materialId,E={title:yn(typeof $=="object"?$?.title:"",30)||`${y+1}`};if(x!=null){const v=o.find(k=>k.id===x);if(!v||v.kind!=="image"||typeof v.gcsUri!="string")throw Error(`hudPanel grid item ${y+1}: "${String(x).slice(0,40)}" is not a picture in the Media bin`);const S=`grid${y}.img`;s[S]=v.gcsUri,E.img=S}p.items.push(E)}p.cols=Math.round(rn(Number(e.cols),1,3,m<=4?2:3)),p.pick=Number.isInteger(e.pick)&&e.pick>=0&&e.pick<m?e.pick:-1,p.pickAt=Ul(rn(Number(e.pickAt),0,or.maxSeconds,1.6)),h=`HUD · ${m} ảnh`}if(t==="cta"){const f=Array.isArray(e.chips)?e.chips.slice(0,or.chips).map(m=>yn(m,48)).filter(Boolean):[];p.cta={lead:yn(e.lead,30)||(i?"comment":"bình luận"),word:yn(e.keyword,20).toUpperCase()||"CLIPOOX",chips:f,doc:e.doc===!1?"":yn(e.doc,20)||(i?"FULL GUIDE":"HƯỚNG DẪN")},h=`HUD · comment ${p.cta.word}`}return{S:p,TT:c,assets:s,label:h}}function tA(t){const e=t.look,o=t.kind;if(o==="keyboard")return(e.keys==="radial"?560:520)/1100;if(o==="chip")return(e.frame==="comic"?130:100)/(260+t.text.length*15);if(o==="cta")return 760/900;if(o==="grid"){const r=t.items.length;return e.grid==="stack"?(900*.42*.72*1.12*Math.ceil(r/2)+180)/900:e.grid==="grid"?Math.ceil(r/t.cols)/t.cols*1.25:e.grid==="list"?110*(r+.5)/900:e.grid==="strip"?.42:e.grid==="ring"?.56:760/900}return .56}function eA(t,e,o,r){if(!e||t.fill)return"";const n=e.y-.15,a=e.y+.13,i=r>o*1.1?.3:.17,l=f=>f*tA(t)*(o/r)*Math.cos(t.tiltX*Math.PI/180),p=(f,m)=>[.5+f-l(m)/2,.5+f+l(m)/2],c=f=>[.5+t.x-f/2,.5+t.x+f/2];if(!((f,m)=>{const[y,$]=p(f,m),[x,E]=c(m);return $>n&&y<a&&E>e.x-i&&x<e.x+i})(t.y,t.w))return"";const h=t.y;for(let f=t.w;f>=.3;f=Fi(f*.9)){const m=l(f),y=n-.012-m/2-.5,$=a+.012+m/2-.5,x=v=>.5+v-m/2>=.02&&.5+v+m/2<=.98,E=[y,$].filter(x).sort((v,S)=>Math.abs(v-h)-Math.abs(S-h))[0];if(E!=null)return t.y=Fi(E),t.w=f,`moved ${E<h?"up":"down"} off the face${f<.999*t.w,""}`}return t.w=.3,t.y=Fi(.48-l(.3)/2),"shrunk to the bottom edge, off the face"}const co=1/30,le=(t,e,o)=>Math.max(e,Math.min(o,t)),he=t=>+t.toFixed(4),Se=(t,e)=>Number.isFinite(t)?t:e,oA=/^#[0-9a-f]{6}$/i,Ws=t=>!!t&&(t.kind==="video"||t.kind==="image")&&!t.title&&!t.shape&&!t.motion&&!t.solid,Hy=["roto","planar","personPending","clientJobs","hands","sceneTrack","objectTracks","captions","captionWords","captionStyle","transition","join","shocks","impacts","trail","pendingPin","pin","bubble","layout"],se=Object.freeze({step:Object.freeze({steps:[2,6],frames:[1,8],amount:[1.1,3],defaults:Object.freeze({steps:3,frames:3,amount:1.6})}),matte:Object.freeze({frames:[1,6],default:2}),drain:Object.freeze({duration:[.2,10],default:1.2}),iris:Object.freeze({radius:[.08,.5],push:[1,1.5],defaults:Object.freeze({radius:.42,push:1.08})}),card:Object.freeze({width:[.12,.96],aspect:[.4,2.4],round:[0,.5],zIndex:58,defaults:Object.freeze({width:.42,round:.08,rim:"#ffffff"})}),board:Object.freeze({max:8,gap:.03,step:.09,area:Object.freeze({x:.06,y:.1,w:.88,h:.8})}),camera:Object.freeze({moves:12,zoom:[1,4],ramp:[.1,3],defaultRamp:.45}),wipe:Object.freeze({dirs:Object.freeze(["auto","right","left","down","up"]),feather:[0,.1],defaultFeather:.012,finish:.12})});function rA(t,{at:e,steps:o=se.step.defaults.steps,frames:r=se.step.defaults.frames,amount:n=se.step.defaults.amount,point:a=null,back:i=!0}={}){if(!Ws(t))throw Error("stepPunch needs a video or image clip");const l=se.step,p=Math.round(le(Se(o,l.defaults.steps),...l.steps)),c=Math.round(le(Se(r,l.defaults.frames),...l.frames)),s=le(Se(n,l.defaults.amount),...l.amount);if(!Number.isFinite(e)||e<0||e>=t.duration-co)throw Error("stepPunch must start inside the clip");const h=ht(e),f=p*c*co;let m=ht(h+f),y=!i;if(m>=t.duration-co/2&&(m=t.duration,y=!0),h+c*co>t.duration+1e-6)throw Error("stepPunch is too long for the clip");const $=Jt.hold,x=Array.isArray(a)?le(Number(a[0])-.5,-.5,.5):0,E=Array.isArray(a)?le(Number(a[1])-.5,-.5,.5):0,v={...t,...Zr(t)},S=[];h>=co&&S.push({time:ht(h-co),f:0});for(let P=1;P<=p;P++){const C=ht(h+(P-1)*c*co);C<t.duration-1e-6&&S.push({time:C,f:P/p})}y||S.push({time:m,f:0});const k=S[0].time,b=y?t.duration:m,A=(P,C)=>{const z=Ut(v,"zoom",C.time)||1,N=Math.min(qi,z*(1+(s-1)*C.f));if(P==="zoom")return he(N);const F=Math.max(0,(N-1)/2),K=-(N-z)*(P==="x"?x:E);return he(le(Ut(v,P,C.time)+le(K,-F,F),-1,1))};let I={...v};for(const P of x||E?["zoom","x","y"]:["zoom"]){const C=Me(v,P).filter(N=>N.time<k-.001||N.time>b+.001),z=S.map(N=>({time:N.time,value:A(P,N),ease:$}));I={...I,...de(I,P,[...C,...z].sort((N,F)=>N.time-F.time))}}return hn(I),{motionV:I.motionV,motionKeys:I.motionKeys,...I.posX!==void 0?{posX:I.posX,posY:I.posY,scale:I.scale}:{}}}function nA(t,{frames:e=se.matte.default,side:o="in",aspect:r=16/9}={},n){if(!t||t.kind!=="video"&&t.kind!=="image")throw Error("matteFlash needs a video or image clip");if(!t.person)throw Error("matteFlash needs the AI cut-out of the subject on the clip (segmentPerson / cutOutObject first)");if(o!=="in"&&o!=="out")throw Error("matteFlash side: in | out");const a=Math.round(le(Se(e,se.matte.default),...se.matte.frames)),i=ht(a*co);if(t.duration<i+co)throw Error("matteFlash: the clip is shorter than the flash");const l=o==="in"?t.start:ht(t.start+t.duration-i);let p=Nn(t,n());for(const h of Hy)delete p[h];if(delete p.enter,delete p.exit,o==="in"){const[h]=Ne(p,ht(t.start+i),n());p={...h,id:p.id}}else{const[,h]=Ne(p,l,n());p={...h??p,id:p.id}}const c={...p,label:`${t.label||"Clip"} · bóng`,volume:0,effects:[{type:"fade",amount:1},{type:"threshold",amount:.02}],opacity:1};delete c.saturation;for(const h of["colorBypass","blend","grade","edge","shadow","glow"])delete c[h];return[Td({id:n(),track:t.track,start:l,duration:i,label:"Nền đen",fill:{type:"color",color:"#000000"},aspect:r}),c]}function aA(t,{at:e,duration:o=se.drain.default}={},r){if(!Ws(t))throw Error("endingDrain needs a video or image clip");const n=ht(le(Se(e,t.start),t.start,t.start+t.duration-2*co)),a=t.start+t.duration,i=ht(le(Se(o,se.drain.default),se.drain.duration[0],Math.min(se.drain.duration[1],a-n)));if(i<2*co)throw Error("endingDrain: not enough of the clip left after `at`");let l={...t,id:r(),volume:0};for(const c of Hy)delete l[c];if(delete l.enter,delete l.exit,n>t.start+1e-6){const[,c]=Ne(l,n,r());c&&(l={...c,id:l.id})}l={...l,label:`${t.label||"Clip"} · rút màu`,saturation:0};const p=[{time:0,value:0,ease:Jt["ease-in-out"]},{time:he(Math.min(i,l.duration)),value:1}];return{...l,...de(l,"opacity",p)}}function iA(t,e,{at:o,radius:r=se.iris.defaults.radius,push:n=se.iris.defaults.push,cx:a=.5,cy:i=.5,feather:l=.006,W:p=1280,H:c=720,material:s=null,newId:h}={}){const f=t.find(N=>N.id===e);if(!Ws(f))throw Error("irisHold needs a video or image clip");const m=se.iris,y=Math.round(s?.width)||p,$=Math.round(s?.height)||c,x=le(Se(r,m.defaults.radius),...m.radius)*Math.min(y,$)/y,E=x*y/$,v=le(Se(n,m.defaults.push),...m.push),S=le(Se(a,.5),x,1-x),k=le(Se(i,.5),Math.min(E,.5),Math.max(1-E,.5));let b=t,A=f;const I=ht(le(Se(o,f.start),f.start,f.start+f.duration-3*co));if(I>f.start+1e-6){const[N,F]=Ne(f,I,h?.()??`${f.id}-iris`);F&&(b=b.flatMap(K=>K.id===f.id?[N,F]:[K]),A=F)}const P={...A,...Zr(A)},C=Ut(P,"zoom",0)||1;let z={...P,mask:{v:1,mw:y,mh:$,keys:[{t:0,pts:D1(S,k,x,y,$,32)}],smooth:!0,feather:le(Se(l,.006),0,.1)}};for(const N of["person","roto","planar","bubble"])delete z[N];return v>1.0005&&(z={...z,...de(z,"zoom",[{time:0,value:he(C),ease:Jt["ease-out"]},{time:he(A.duration),value:he(Math.min(qi,C*v))}])}),hn(z),{clips:b.map(N=>N.id===A.id?z:N),irisId:A.id}}function sA({W:t,H:e,width:o,cx:r=.5,cy:n=.5,aspect:a}){const i=se.card,l=.02*Math.min(t,e);let p=t*le(Se(o,i.defaults.width),...i.width),c=p/le(a,...i.aspect);return c>e-2*l&&(c=e-2*l,p=c*le(a,...i.aspect)),{x:le(t*Se(r,.5)-p/2,l,Math.max(l,t-l-p)),y:le(e*Se(n,.5)-c/2,l,Math.max(l,e-l-c)),w:p,h:c}}function lA(t,{W:e,H:o,mw:r,mh:n,rect:a,round:i=se.card.defaults.round}){const l=a.w/a.h;let p=r,c=p/l;c>n&&(c=n,p=c*l);const s=t.fit==="cover"?Math.max(e/r,o/n):Math.min(e/r,o/n),h=a.w/(p*s),f=le(2*le(Se(i,se.card.defaults.round),...se.card.round)*a.w/Math.min(a.w,a.h),0,1),m=Yn({kind:"rect",cx:.5,cy:.5,w:he(p/r),h:he(c/n),rot:0,round:he(f)},r,n);return{mask:gr({mw:r,mh:n},[m]),posX:he((a.x+a.w/2-e/2)/e),posY:he((a.y+a.h/2-o/2)/o),scale:he(h)}}function Uy(t,{W:e=1280,H:o=720,material:r=null,width:n,cx:a,cy:i,aspect:l,round:p,rim:c=se.card.defaults.rim,glow:s=.25,zIndex:h=se.card.zIndex,enter:f=!0}={}){if(!Ws(t))throw Error("mediaCard needs a video or image clip");if(c!==!1&&!oA.test(String(c)))throw Error("mediaCard rim must be #RRGGBB or false");const m=Math.round(r?.width)||e,y=Math.round(r?.height)||o,$=sA({W:e,H:o,width:n,cx:a,cy:i,aspect:Se(l,m/y)}),x=lA(t,{W:e,H:o,mw:m,mh:y,rect:$,round:p}),E={...t,motionV:2,motionKeys:[],posX:x.posX,posY:x.posY,scale:x.scale,mask:x.mask,zIndex:h,shadow:{...vn,opacity:.5,blur:22,distance:8},...c===!1?{}:{edge:{color:String(c).toLowerCase(),width:.004,glow:le(Se(s,.25),0,2)}},...f?{enter:{type:"pop",duration:.3},exit:{type:"fade",duration:.2}}:{}};c===!1&&delete E.edge;for(const S of["glow","person","roto","planar","scaleX","scaleY","anchorX","anchorY","tiltX","tiltY","rotation","crop","pin","layout","bubble"])delete E[S];hn(E);const v={};for(const S of["motionV","motionKeys","posX","posY","scale","mask","zIndex","shadow","edge","enter","exit"])v[S]=E[S];for(const S of["glow","person","roto","planar","scaleX","scaleY","anchorX","anchorY","tiltX","tiltY","rotation","crop","pin","layout","bubble"])v[S]=void 0;return{patch:v,rect:{x:he($.x/e),y:he($.y/o),w:he($.w/e),h:he($.h/o)}}}function cA(t,{W:e=1280,H:o=720,area:r=se.board.area,gap:n=se.board.gap,cols:a}={}){if(!Number.isInteger(t)||t<1||t>se.board.max)throw Error(`mediaBoard takes 1–${se.board.max} clips`);const i=o>e,l=le(Math.round(Se(a,i?Math.min(2,t):Math.min(t,t<=3?t:Math.ceil(t/2)))),1,t),p=Math.ceil(t/l),c=n*Math.min(e,o),s=r.w*e,h=r.h*o,f=(s-c*(l-1))/l,m=(h-c*(p-1))/p;return Array.from({length:t},(y,$)=>{const x=Math.floor($/l),E=x===p-1?t-x*l:l,v=$-x*l,S=r.x*e+(s-(E*f+(E-1)*c))/2;return{cx:he((S+v*(f+c)+f/2)/e),cy:he((r.y*o+x*(m+c)+m/2)/o),width:he(f/e),aspect:he(f/m)}})}function pA(t,{W:e=1280,H:o=720,materials:r=[],area:n,gap:a,cols:i,step:l=se.board.step,rim:p,round:c}={}){const s=cA(t.length,{W:e,H:o,area:n,gap:a,cols:i}),h=new Map,f=[];return t.forEach((m,y)=>{const $=r.find(z=>z.id===m.nodeId)??null,x=Math.round($?.width)||e,E=Math.round($?.height)||o,v=s[y],S=x/E,k=S>=v.aspect?v.width:v.width*S/v.aspect,{patch:b,rect:A}=Uy(m,{W:e,H:o,material:$,width:k,cx:v.cx,cy:v.cy,aspect:S,rim:p,round:c,enter:!1,zIndex:se.card.zIndex-y%8}),I=he(Math.min(Math.max(0,m.duration-.4),y*le(Se(l,se.board.step),0,1))),P=Jt["expo-out"];let C={...m,...b};for(const z of Object.keys(b))b[z]===void 0&&delete C[z];C={...C,...de(C,"y",[{time:I,value:he(b.posY+.05),ease:P},{time:he(I+.32),value:b.posY}])},C={...C,...de(C,"opacity",[...I>co/2?[{time:0,value:0,ease:Jt.hold}]:[],{time:I,value:0,ease:P},{time:he(I+.24),value:1}])},hn(C),h.set(m.id,{...b,motionV:C.motionV,motionKeys:C.motionKeys,posX:C.posX,posY:C.posY,scale:C.scale}),f.push({id:m.id,...A})}),{patches:h,rects:f}}function uA(t,{moves:e}={}){if(!Ws(t))throw Error("screenCamera needs a video or image clip");const o=se.camera;if(!Array.isArray(e)||!e.length||e.length>o.moves)throw Error(`screenCamera moves: 1–${o.moves} of {at, point [u,v], zoom}`);const r={...t,...Zr(t)},n=Se(r.scale,1),a=Se(r.posX,0),i=Se(r.posY,0),l=e.map(y=>{const $=Number(y?.at),x=le(Se(Number(y?.zoom),1.6),...o.zoom),E=le(Se(Number(y?.ramp),o.defaultRamp),...o.ramp);if(!Number.isFinite($)||$<0||$>t.duration)throw Error("screenCamera: every move needs `at` inside the clip (seconds from its start)");const v=Array.isArray(y?.point)&&y.point.length===2&&y.point.every(Number.isFinite)?[le(y.point[0],0,1),le(y.point[1],0,1)]:[.5,.5],S=he(Math.min(qi,n*x)),k=Math.max(0,(x-1)/2);return{at:ht($),ramp:E,z:S,x:he(a+le(-(v[0]-.5)*x,-k,k)),y:he(i+le(-(v[1]-.5)*x,-k,k))}}).sort((y,$)=>y.at-$.at);for(let y=1;y<l.length;y++)if(l[y].at-l[y-1].at<2*co)throw Error("screenCamera: moves must be at least 2 frames apart");const p=Jt["easy-ease"],c=Jt.hold,s=y=>{const $=y==="zoom"?n:y==="x"?a:i,x=[];let E=$;return l.forEach((v,S)=>{const k=ht(Math.max(S?l[S-1].at:0,v.at-v.ramp)),b=y==="zoom"?v.z:v[y];v.at-k>=co&&x.push({time:k,value:he(E),ease:p}),x.push({time:v.at,value:b,ease:c}),E=b}),x.filter((v,S,k)=>!S||v.time>k[S-1].time+1e-6)},h=Math.max(0,l[0].at-l[0].ramp),f=l.at(-1).at;let m={...r};for(const y of["zoom","x","y"]){const $=Me(r,y).filter(x=>x.time<h-.001||x.time>f+.001);m={...m,...de(m,y,[...$,...s(y)].sort((x,E)=>x.time-E.time))}}return hn(m),{motionV:m.motionV,motionKeys:m.motionKeys,posX:m.posX,posY:m.posY,scale:m.scale}}const dA=(t=1280,e=720)=>({v:1,mw:t,mh:e,keys:[{t:0,pts:[[-1,-1],[-1,-.999],[-.999,-.999],[-.999,-1]]}],smooth:!1,feather:0});function hA(t,e,{point:o="palm",side:r="any",dir:n="auto",feather:a=se.wipe.defaultFeather,finish:i=se.wipe.finish,W:l=1280,H:p=720,mw:c,mh:s}={}){if(!e?.hands)throw Error("The footage has no hand track yet");if(!se.wipe.dirs.includes(n))throw Error(`handWipe dir: ${se.wipe.dirs.join(" | ")}`);const h=Vs(e.hands),f=Math.max(t.start,e.start),m=Math.min(t.start+t.duration,e.start+e.duration);if(!(m-f>=4*co))throw Error("The layer and the footage do not play at the same time");const y=Math.max(2,Math.min(ze.maxFrames-10,Math.ceil((m-f)/q1))),$=[];for(let D=0;D<=y;D++){const H=f+(m-f)*D/y,ut=$i(e,h,H,{point:o,side:r,W:l,H:p});ut&&$.push({T:H,x:ut.x/l,y:ut.y/p})}if($.length<2)throw Error("No hand is seen while the layer plays");let x=n;if(x==="auto"){const D=$.map(u=>u.x),H=$.map(u=>u.y),ut=Math.max(...D)-Math.min(...D),gt=Math.max(...H)-Math.min(...H),xt=ut>=gt?$.at(-1).x-$[0].x:$.at(-1).y-$[0].y;x=ut>=gt?xt>=0?"right":"left":xt>=0?"down":"up"}const E=x==="right"||x==="left",v=x==="right"||x==="down",S=D=>E?D.x:D.y;let k=v?-1/0:1/0;const b=$.map(D=>(k=v?Math.max(k,S(D)):Math.min(k,S(D)),{T:D.T,e:k}));let A=b.findIndex(D=>Math.abs(D.e-b[0].e)>.004);if(A<0)throw Error("The hand does not move across the picture while the layer plays");A=Math.max(0,A-1);let I=b.length-1;for(;I>A+1&&Math.abs(b[I].e-b[I-1].e)<1e-4;)I--;const P=v?-.02:1.02,C=b.slice(A,I+1),z=C[0],N=C.at(-1),F=.3,K=D=>D*D*(3-2*D),_=D=>P+(D.e-P)*K(le((D.T-z.T)/F,0,1)),q=Math.round(c)||l,U=Math.round(s)||p,rt=D=>he(D-t.start),ot=(D,H,ut)=>{const gt=fg(t,D*l,H*p,ut-t.start,l,p,q,U);return[gt.u,gt.v]},G=(D,H)=>{const ut=P,gt=le(D,-.02,1.02);return(E?[[ut,-.02],[gt,-.02],[gt,1.02],[ut,1.02]]:[[-.02,ut],[1.02,ut],[1.02,gt],[-.02,gt]]).map(([u,st])=>ot(u,st,H).map(V=>he(le(V,-1,2))))},J=[],Z=(D,H)=>{(!J.length||D>J.at(-1).t+1e-4)&&J.push({t:D,pts:H})};z.T-t.start>co/2&&Z(0,G(P,t.start));for(const D of C)Z(rt(D.T),G(_(D),D.T));const at=Math.min(t.start+t.duration,N.T+le(Se(i,se.wipe.finish),co,2));return at-N.T>=co/2?Z(rt(at),G(v?1.02:-.02,at)):J[J.length-1]={t:J.at(-1).t,pts:G(v?1.02:-.02,N.T)},{patch:{mask:{v:1,mw:q,mh:U,keys:J,smooth:!1,feather:le(Se(a,se.wipe.defaultFeather),...se.wipe.feather)}},dir:x,from:he(z.T),to:he(at)}}const _0=["track","planar"],Ui=t=>+Number(t).toFixed(5),fA=t=>{const e=t.map(r=>r[0]),o=t.map(r=>r[1]);return{x0:Math.min(...e),x1:Math.max(...e),y0:Math.min(...o),y1:Math.max(...o)}};function mA(t,e){if(e!==void 0){if(!Array.isArray(e)||e.length!==4||!e.every(s=>Array.isArray(s)&&s.length===2&&s.every(h=>Number.isFinite(h)&&h>=0&&h<=1)))throw Error("region: 4 corners [[u,v]…] inside 0..1");return e.map(s=>s.map(Ui))}const o=fA(t),r=(o.x1-o.x0)*.1+.01,n=(o.y1-o.y0)*.1+.01,a=s=>Math.max(0,Math.min(1,s)),i=a(o.x0-r),l=a(o.x1+r),p=a(o.y0-n),c=a(o.y1+n);return[[i,p],[l,p],[l,c],[i,c]].map(s=>s.map(Ui))}function gA(t,e){for(const n of[t.mask,t.person,t.colorPerson,t.planar,t.roto])if(n&&Number.isInteger(n.mw)&&Number.isInteger(n.mh)&&n.mw>=2&&n.mh>=2)return{mw:n.mw,mh:n.mh};const o=Number(e?.width),r=Number(e?.height);return Number.isInteger(o)&&Number.isInteger(r)&&o>=2&&r>=2?{mw:o,mh:r}:null}function yA(t,e,{size:o}={}){const r=Object.fromEntries(Object.entries(e||{}).filter(([,s])=>s!==null));if(!t||!["video","image"].includes(t.kind))throw Error("needs a video or image clip");if(yw(t.mask))throw Error("this clip's masks are stored large (frame-by-frame roto) — edit them in the Clipoox editor");const n=r.masks===void 0?[]:r.masks;if(!Array.isArray(n)||n.length>Hs)throw Error(`masks: up to ${Hs}`);const a=r.remove===void 0?[]:r.remove;if(!Array.isArray(a)||a.some(s=>typeof s!="string"))throw Error("remove: mask ids");if(!n.length&&!a.length&&r.replace!==!0)throw Error("give masks, remove or replace");const i=t.mask?{mw:t.mask.mw,mh:t.mask.mh}:o;if(!i)throw Error("the video's size is unknown — run analyze_footage on it (or segmentPerson) first");let l=r.replace===!0?[]:Ka(t.mask).filter(s=>!a.includes(s.id));const p=[];for(const[s,h]of n.entries()){if(!h||typeof h!="object")throw Error(`masks[${s}]: an object`);const f=Object.fromEntries(Object.entries(h).filter(([,v])=>v!==null)),m=f.mode??"add";if(!ph.includes(m))throw Error(`masks[${s}].mode: ${ph.join("|")}`);if(!Array.isArray(f.keys)||!f.keys.length||f.keys.length>ku)throw Error(`masks[${s}].keys: 1–${ku} keys {t, pts}`);const y=[...f.keys].map(v=>({t:Ui(Number(v?.t)),pts:Array.isArray(v?.pts)?v.pts.map(S=>Array.isArray(S)?S.map(Ui):S):v?.pts})).sort((v,S)=>v.t-S.t);for(const v of y)if(!Array.isArray(v.pts)||v.pts.length<3||v.pts.length>yu)throw Error(`masks[${s}]: every key has 3–${yu} points [u,v] (0..1 of the source frame)`);const $=typeof f.id=="string"?l.find(v=>v.id===f.id):null,x=$?$.id:typeof f.id=="string"&&/^[a-zA-Z0-9_-]{1,24}$/.test(f.id)?f.id:bw(l),E={id:x,name:String(f.name??$?.name??`Mask ${x.replace(/^m(?=\d)/,"")}`).slice(0,40).trim()||"Mask",mode:m,keys:y,...f.feather!==void 0?{feather:Number(f.feather)}:$?.feather!==void 0?{feather:$.feather}:{},...f.invert!==void 0?{invert:f.invert}:{},...f.smooth!==void 0?{smooth:f.smooth}:{}};if(f.follow!==void 0&&f.follow!==null){if(!_0.includes(f.follow))throw Error(`masks[${s}].follow: ${_0.join(" | ")}`);if(t.kind!=="video")throw Error("follow needs a video clip");const v=f.follow==="track"?"translate":f.planarMode??"perspective";if(!uh.includes(v))throw Error(`masks[${s}].planarMode: ${uh.join("|")}`);p.push({id:x,at:y[0].t,region:mA(y[0].pts,f.region),mode:v})}l=$?l.map(v=>v.id===x?E:v):[...l,E]}if(l.length>Hs)throw Error(`at most ${Hs} masks per clip`);const c=l.length?gr(i,l):void 0;return c&&ww(c,t.duration),{mask:c,follow:p}}function sj(t,e,o,r,{maxKeys:n=ku,maxPoints:a=6e4}={}){if(!e.length)return t.keys;const i={frames:e},l=t.keys.find($=>Math.abs($.t-o)<.001)??t.keys[0],p=dh(i,o),c=l.pts.length,s=Math.max(2,Math.min(n,Math.floor(a/c))),h=e[0][0],f=e.at(-1)[0],m=Math.max(2,Math.min(s,e.length));return[...new Set([...Array.from({length:m},($,x)=>+(h+(f-h)*x/(m-1)).toFixed(4)),+o.toFixed(4)])].sort(($,x)=>$-x).map($=>{const x=dh(i,$),E=Math.abs($-o)<1e-4?null:kw(r,p,x);return{t:$,pts:l.pts.map(v=>{if(!E)return v;const[S,k]=xw(E,v[0],v[1]);return[Ui(S),Ui(k),...v.slice(2)]})}})}const bA=3,Qi=(t,e)=>!!t?.[e.track]?.locked;function lj(t,e,o,r,{tracks:n={},makeId:a=()=>crypto.randomUUID()}={}){const i=t.find($=>$.id===e);if(!i)throw Error("Không tìm thấy clip");if(Qi(n,i))throw Error("Track đã khóa");const l=Ne(i,o,a());if(l.length<2)throw Error("Đặt playhead trong clip");const[p,c]=l,s=r==="left"?p:c,h=r==="left"?c:p,f=s.duration,m=i.start+i.duration;return{clips:t.flatMap($=>$.id===i.id?[r==="left"?{...h,start:i.start}:h]:[$.track===i.track&&$.start>=m-1/60?{...$,start:ht(Math.max(0,$.start-f))}:$]),kept:h.id}}function cj(t,e,{tracks:o={},makeId:r}={}){const n=t.filter(i=>e.includes(i.id));if(!n.length)return{clips:t,pasted:[]};const a=Math.max(...n.map(i=>i.start+i.duration));return Jy(t,n,ht(a),{insert:!0,tracks:o,...r?{makeId:r}:{}})}function pj(t,e,o,{tracks:r={},seconds:n=bA,makeId:a=()=>crypto.randomUUID()}={}){const i=t.find(E=>E.id===e);if(!i)throw Error("Không tìm thấy clip");if(i.kind!=="video")throw Error("Dừng hình cần clip video");if(i.reverse)throw Error("Tắt phát ngược trước khi dừng hình");if(i.freeze)throw Error("Clip này đã là khung dừng hình");if(Qi(r,i))throw Error("Track đã khóa");const l=ht(Math.max(i.start,Math.min(i.start+i.duration,o))),p=i.playbackRate||1,c=Ne(i,l,a()),s=c[0],h=c[1],f=ht(Math.min(i.duration-1/30,l-i.start)),m=zn(i)?Mw(i,f):Hr(i)?(i.inPoint||0)+Di(i,f):(i.inPoint||0)+f*p,y={...i,id:a(),start:l,duration:ht(n),inPoint:+m.toFixed(4),playbackRate:1,volume:0,freeze:!0,label:`${i.label} · freeze`};for(const E of["speedRamp","timeRemap","transition","motionKeys","enter","exit","captions","captionWords","captionStyle","audioFadeIn","audioFadeOut","visualFadeIn","visualFadeOut","roto","duck"])delete y[E];const $=ht(n),x=t.flatMap(E=>E.id===i.id?h?[s,{...h,start:ht(h.start+$)}]:[s]:[E.track===i.track&&E.start>=l-1/60?{...E,start:ht(E.start+$)}:E]);return c.length===1&&l<=i.start+1/60&&x.splice(x.findIndex(E=>E.id===i.id),1,{...i,start:ht(i.start+$)}),{clips:[...x,y],hold:y.id}}function Yy(t,e,{tracks:o={},makeId:r=()=>crypto.randomUUID()}={}){const n=t.find(p=>p.id===e);if(!n)throw Error("Không tìm thấy clip");if(n.kind!=="video")throw Error("Chỉ tách được âm thanh của clip video");if(n.freeze)throw Error("Khung dừng hình không có âm thanh");if((n.volume??1)<=0)throw Error("Clip này đã tắt tiếng");if(Qi(o,n))throw Error("Track đã khóa");if(Hr(n))throw Error("Clip có speed ramp không có âm thanh — đặt tốc độ cố định trước khi tách âm thanh");const a=n.start+n.duration,i=Ci.find(p=>!o[p]?.locked&&!t.some(c=>c.track===p&&c.start<a-1/60&&c.start+c.duration>n.start+1/60));if(i===void 0)throw Error("Không còn track âm thanh trống ở đoạn này");const l={id:r(),nodeId:n.nodeId,track:i,start:n.start,duration:n.duration,kind:"audio",url:n.url,label:`${n.label} · audio`,inPoint:n.inPoint||0,...n.sourceDuration!==void 0?{sourceDuration:n.sourceDuration}:{},...n.gcsUri?{gcsUri:n.gcsUri}:{},...n.playbackRate&&n.playbackRate!==1?{playbackRate:n.playbackRate}:{},volume:n.volume??1,...zn(n)?{timeRemap:n.timeRemap}:{},...Object.fromEntries(["audioFadeIn","audioFadeOut","duck"].filter(p=>n[p]!==void 0).map(p=>[p,n[p]]))};return{clips:[...t.map(p=>p.id===n.id?{...p,volume:0}:p),l],audio:l.id}}function uj(t,e,{tracks:o={}}={}){const r=t.find(n=>n.id===e);if(!r)throw Error("Không tìm thấy clip");if(r.kind!=="video"||(r.volume??1)<=0)throw Error("Clip này không có âm thanh");if(Qi(o,r))throw Error("Track đã khóa");return{clips:t.map(n=>{if(n.id!==e)return n;const a={...n,volume:0};for(const i of["audioFadeIn","audioFadeOut","duck","volumeKeys"])delete a[i];return a})}}function dj(t,e,o,{tracks:r={},makeId:n=()=>crypto.randomUUID()}={}){const a=t.find(c=>c.id===e);if(!a)throw Error("Không tìm thấy clip");if(!(o>a.start+1/60&&o<a.start+a.duration-1/60))throw Error("Đặt playhead trong clip để cắt");const i=Yy(t,e,{tracks:r,makeId:n}),l=i.clips.find(c=>c.id===i.audio),p=Ne(l,o,n());return{clips:i.clips.flatMap(c=>c.id===l.id?p:[c]),audio:p.map(c=>c.id)}}function hj(t,e,{tracks:o={}}={}){const r=t.filter(i=>e.includes(i.id)&&!Qi(o,i)),n=r.some(i=>!i.disabled),a=new Set(r.map(i=>i.id));return t.map(i=>{if(!a.has(i.id))return i;const l={...i};return n?l.disabled=!0:delete l.disabled,l})}const xd=3,Ri=1/30,wA=new Set(["id","start","duration","inPoint","label","captions","captionWords"]),kA=(t,e)=>{const o=new Set([...Object.keys(t),...Object.keys(e)].filter(r=>!wA.has(r)));for(const r of o)if(JSON.stringify(t[r])!==JSON.stringify(e[r]))return!1;return!0};function _s(t,e,{gap:o=0}={}){if(!t||!e||t.id===e.id||t.track!==e.track||t.kind!==e.kind||!["video","audio"].includes(t.kind)||t.reverse||e.reverse||t.freeze||e.freeze||t.speedRamp||e.speedRamp||t.nodeId!==e.nodeId||t.url!==e.url)return!1;const r=t.playbackRate||1;if((e.playbackRate||1)!==r)return!1;const n=e.start-(t.start+t.duration);return n<-Ri/2||n>o+Ri/2?!1:Math.abs((e.inPoint||0)-((t.inPoint||0)+(t.duration+Math.max(0,n))*r))<=Ri/2*r+1e-6}function qy(t,e){if(!_s(t,e,{gap:xd*Ri})||t.transition||!kA(t,e))return null;const o=ht(e.start-t.start),r=ht(o+e.duration),n=i=>i.map(l=>({...l,start:+(l.start+o).toFixed(3),end:+(l.end+o).toFixed(3)})),a={...t,duration:r};return(t.captions||e.captions)&&(a.captions=[...t.captions||[],...n(e.captions||[])]),(t.captionWords||e.captionWords)&&(a.captionWords=[...t.captionWords||[],...n(e.captionWords||[])]),a}function fj(t,e,{tracks:o={}}={}){const r=t.find(s=>s.id===e);if(!r)throw Error("Không tìm thấy clip");if(Qi(o,r))throw Error("Track đã khóa");const n=t.filter(s=>s.track===r.track&&s.id!==r.id),a=n.filter(s=>_s(r,s,{gap:xd*Ri})).sort((s,h)=>s.start-h.start)[0],i=n.filter(s=>_s(s,r,{gap:xd*Ri})).sort((s,h)=>h.start-s.start)[0],[l,p]=a?[r,a]:i?[i,r]:[];if(!l)throw Error("Không có đoạn liền mạch để nối (cần 2 đoạn của cùng một video, nguồn chạy tiếp nhau)");const c=qy(l,p);if(!c)throw Error("Hai đoạn khác nhau về hiệu ứng, keyframe hoặc chuyển cảnh nên không gộp được");return{clips:t.filter(s=>s.id!==p.id).map(s=>s.id===l.id?c:s),kept:l.id}}function mj(t,e){const o=t.find(c=>c.id===e);if(!o)return{clips:t,joined:!1};const r=t.filter(c=>c.track===o.track&&c.id!==o.id),n=r.find(c=>_s(o,c)),a=r.find(c=>_s(c,o)),[i,l]=n?[o,n]:a?[a,o]:[],p=i&&qy(i,l);return p?{clips:t.filter(c=>c.id!==l.id).map(c=>c.id===i.id?p:c),joined:!0,kept:i.id}:{clips:t,joined:!1}}function gj(t,e,o,{playhead:r,pps:n,px:a=8}={}){const l=[0,...r===void 0?[]:[r],...t.filter(p=>p.id!==e.id&&p.track===e.track).flatMap(p=>[p.start,p.start+p.duration])].sort((p,c)=>Math.abs(p-o)-Math.abs(c-o))[0];return l!==void 0&&Math.abs(l-o)*n<a?ht(l):null}function yj(t,e,{tracks:o={},makeId:r=()=>crypto.randomUUID()}={}){const n=t.filter(l=>e.includes(l.id)&&l.kind!=="audio");if(!n.length)throw Error("Chọn clip hình để nhân bản");let a=t;const i=[];for(const l of n){const p=h=>!o[h]?.locked&&!o[h]?.hidden&&!a.some(f=>f.track===h&&f.start<l.start+l.duration-1e-6&&f.start+f.duration>l.start+1e-6);let c=ci(l.track)+1;for(;c<40&&!p(In(c));)c++;if(c>=40)throw Error("Không còn track trống phía trên");const s={...l,id:r(),track:In(c),volume:0};delete s.transition,a=[...a,s],i.push(s.id)}return{clips:a,pasted:i}}function G0(t,e,o){return Array.isArray(t)?t.slice(0,Sg.models).map(r=>{const n=p=>Number.isFinite(Number(p))?Number(p):void 0,a=Array.isArray(r?.lonlat)&&r.lonlat.length===2?r.lonlat.map(Number):Number.isFinite(Number(r?.lat))&&Number.isFinite(Number(r?.lng))?[Number(r.lng),Number(r.lat)]:void 0;if(r?.project!==void 0){const p=z4(String(r.project));if(!p)throw Error(`Map model: no project "${String(r.project).slice(0,60)}" in the map project library (list_map_projects)`);return{...L4(p,{show:n(r.show)??0,rise:r.rise!==!1,at:a?.every(Number.isFinite)?a:void 0,height:n(r.height),rotation:n(r.rotation)}),...r.reveal?{reveal:r.reveal}:{},...r.color?{color:r.color}:{}}}const i=e.find(p=>p.id===r?.materialId);if(!i||i.kind!=="model"||typeof i.gcsUri!="string")throw Error(`Map model: "${String(r?.materialId??"").slice(0,40)}" is not a GLB in the Media bin`);const l=Array.isArray(r.lonlat)&&r.lonlat.length===2?r.lonlat.map(Number):Number.isFinite(Number(r.lat))&&Number.isFinite(Number(r.lng))?[Number(r.lng),Number(r.lat)]:o.at(-1)?.center;if(!Array.isArray(l)||!l.every(Number.isFinite))throw Error("Map model needs lonlat (or lat + lng)");return{gcsUri:i.gcsUri,label:String(r.label||i.label||"GLB").slice(0,60),at:l,height:Number.isFinite(Number(r.height))?Number(r.height):40,rotation:Number(r.rotation)||0,show:Number.isFinite(Number(r.show))?Number(r.show):0,rise:r.rise!==!1,...r.reveal?{reveal:r.reveal}:{},...r.color?{color:r.color}:{}}}):null}function K0(t,e,o){return Array.isArray(t)?t.slice(0,Sg.images).map(r=>{const n=e.find(p=>p.id===r?.materialId);if(!n||n.kind!=="image"||typeof n.gcsUri!="string")throw Error(`Map picture: "${String(r?.materialId??"").slice(0,40)}" is not an image in the Media bin`);const a=Array.isArray(r.lonlat)&&r.lonlat.length===2?r.lonlat.map(Number):Number.isFinite(Number(r.lat))&&Number.isFinite(Number(r.lng))?[Number(r.lng),Number(r.lat)]:o.at(-1)?.center;if(!Array.isArray(a)||!a.every(Number.isFinite))throw Error("Map picture needs lonlat (or lat + lng)");const i=Number(n.width)>0&&Number(n.height)>0?Number(n.height)/Number(n.width):Number(r.aspect)||1,l=(p,c)=>Number.isFinite(Number(p))?Number(p):c;return{gcsUri:n.gcsUri,label:String(r.label||n.label||"").slice(0,60),at:a,width:l(r.width,120),aspect:i,tilt:l(r.tilt,90),rotation:l(r.rotation,0),face:r.face==="fixed"?"fixed":"camera",show:l(r.show,0),...r.reveal?{reveal:r.reveal}:{}}}):null}const xA=["fit","posX","posY","scale","scaleX","scaleY","anchorX","anchorY","rotation","tiltX","tiltY","flipX","flipY","crop","opacity","blend","brightness","contrast","exposure","saturation","hue","grade"],V0=new Set(py.map(t=>t.id)),no=t=>Math.round(t*1e4)/1e4;function MA(t){const e=a=>Number.isFinite(a)?a:void 0,o=(Array.isArray(t.hits)?t.hits:e(t.at)!=null?[t.at]:[]).filter(Number.isFinite).slice(0,xu.max),r={...e(t.start)!=null?{start:t.start}:{},...e(t.duration)!=null?{duration:t.duration}:{}},n=typeof t.color=="string"?{color:t.color}:{};return[{op:"personElectric",clipId:t.clipId,...n,...r},...o.map(a=>({op:"addImpact",clipId:t.clipId,at:a,...Array.isArray(t.hitPoint)?{point:t.hitPoint}:{}})),{op:"speedBolt",clipId:t.clipId,...Array.isArray(t.point)?{point:t.point}:{},...n,...r.start!=null?{at:r.start}:{},...r.duration!=null?{duration:r.duration}:{}}]}function Qt(t){let e={};if(typeof t?.prompt=="string"&&t.prompt.trim().startsWith("{"))try{e=JSON.parse(t.prompt)}catch{throw Error("Map options (prompt) must be JSON")}const o={...e};for(const[r,n]of Object.entries(t||{}))n!=null&&r!=="prompt"&&(o[r]=n);return o.kind==null&&typeof t?.preset=="string"&&(o.kind=t.preset),o.labels==null&&Array.isArray(t?.items)&&(o.labels=t.items),o}const W0=t=>{try{return Ai(t,{})}catch{return null}},Yl=500,ql=500,Kt=Cs;function $A(t){if(t==null)return null;if(!Array.isArray(t)||!t.length||t.length>4||t.some(e=>!Array.isArray(e)||e.length!==2||e.some(o=>typeof o!="number"||!Number.isFinite(o)||o<0||o>1)))throw Error("points: 1–4 [u, v] (0..1 of the video picture)");return t.map(([e,o])=>[+e.toFixed(4),+o.toFixed(4)])}function X0(t,e){const o=Math.max(t.start,Math.min(t.start+t.duration-.016666666666666666,e));return+((t.inPoint||0)+(o-t.start)*(t.playbackRate||1)).toFixed(3)}const We=Tn,jl=2,Tl=Pg,vA=3;function H0(t){if(t.space===void 0||t.space===null||t.space==="")return{};if(typeof t.space!="string"||!/^[\w:.-]{1,100}$/.test(t.space))throw Error("space must be the id of a 3D null");return{space:t.space}}const Zy=["addBroll","addText","estateText","lockup","addCard","addShape","addSolid","addAdjustmentLayer","addFlash","addElement","addMotion","addMap","generateElement","generateBroll"],it=t=>Number.isFinite(t)?Number(t):null,vt=t=>it(t)??void 0,U0=t=>t.sourceDuration??We;function Y0(t,e,o,r=[]){const n=r.find(l=>l.id===e?.nodeId),a=r.find(l=>l.id===o?.nodeId),i=e?(e.inPoint||0)+Di(e,e.duration||0):0;return HE(n,i,a,o?.inPoint||0)>0?J2(t):t}function du(t,e,o){const r=t.findIndex(i=>i.id===e);if(r<0||o===null)return r;const n=t[r];if(!n.nodeId||o>=n.start-1e-6&&o<n.start+n.duration-1e-6)return r;const a=t.findIndex(i=>i.nodeId===n.nodeId&&i.track===n.track&&i.kind===n.kind&&(!i.mask||i.speakerLayout)&&o>=i.start-1e-6&&o<i.start+i.duration-1e-6);return a>=0?a:r}const ks=t=>Array.isArray(t?.words)&&t.words.length?t.words.length:Number.isInteger(t?.wordCount)&&t.wordCount>0?t.wordCount:0;function EA(t,e,o){const r=Array.isArray(t)?t:[],n=typeof o=="string"?o.trim():"",a=n&&r.find(c=>c.id===n);if(a)return a;if(n){const c=r.find(m=>m.id.split(":").slice(1).join(":")===n||m.label===n);if(c)return c;const s=(e||[]).find(m=>m.id===n),h=s&&r.find(m=>m.id===s.nodeId);if(h)return h;const f=n.length>=40?r.filter(m=>m.id.startsWith(n)):[];if(f.length===1)return f[0]}const i=r.filter(c=>ks(c)>0),l=i.filter(c=>c.role==="aroll"),p=l.length?l:i;return p.length===1?p[0]:void 0}function q0(t){const e=t.shape,[o,r]=Array.isArray(e.size)?e.size:e.square?[720,720]:[1280,720],n=Math.min(o,r)/1e3,a=(o-1e3*n)/2,i=(r-1e3*n)/2;let l=1/0,p=1/0,c=-1/0,s=-1/0;for(const h of e.items){const f=h.type==="art"?h.params.box:null,m=Math.abs(h.scale[0]),y=Math.abs(h.scale[1]);f&&(l=Math.min(l,h.pos[0]+f[0]*m),p=Math.min(p,h.pos[1]+f[1]*y),c=Math.max(c,h.pos[0]+f[2]*m),s=Math.max(s,h.pos[1]+f[3]*y))}return Number.isFinite(l)?[(l*n+a)/o,(p*n+i)/r,(c*n+a)/o,(s*n+i)/r]:null}const Z0=t=>Array.isArray(t?.masks)?t.masks.map(e=>e.id):t?["m1"]:[];function SA(t,e,o){if(typeof t.prompt=="string"&&t.prompt.trim().startsWith("{"))try{const f=JSON.parse(t.prompt);t={...f,...t,presetId:t.presetId??f.presetId,params:t.params??f.params}}catch{throw Error("addVfxPreset: prompt must be JSON {presetId, params}")}const r=t.preset&&typeof t.preset=="object"&&t.preset.id?t.preset:L5(String(t.presetId??""));if(!r)throw Error(`addVfxPreset: unknown presetId "${String(t.presetId??"").slice(0,64)}" — search_vfx_presets`);const n=O5(r,t.params&&typeof t.params=="object"?t.params:{}),a=Math.max(0,it(t.start)??it(t.at)??0);let i=A5(r.id),l=null,p=!1;if(typeof t.materialId=="string"){const f=(o??[]).find(m=>m.id===t.materialId);if(!f||f.kind!=="video"||typeof f.url!="string")throw Error(`addVfxPreset: ${t.materialId} is not a video of the Media bin (the move's render: clipoox render --vfx … then add_media)`);i=f.url,l=typeof f.gcsUri=="string"?f.gcsUri:null,p=!0}const s=[{op:"addVfxPreset",_footage:{id:`preset:${r.id}`,url:i,...l?{gcsUri:l}:{},name:r.name,duration:r.duration,width:r.width,height:r.height,bg:"alpha",anchorU:r.emit[0],anchorV:r.emit[1]},_preset:{id:r.id,params:n,rendered:p},start:a,track:t.track,point:t.point,scale:t.scale}],h=a+r.impact;if(t.sfx!==!1)for(const f of r.sfx)s.push({op:"addSfx",sfxId:f.id,at:Math.round((a+f.at)*1e3)/1e3,volume:.8});if(t.shake!==!1&&r.shake){const f=(e??[]).filter(m=>m.kind==="video"&&!m.vfxFootage&&!m.vfx&&m.start<=h&&m.start+m.duration>h).sort((m,y)=>(m.track??0)-(y.track??0))[0];f&&s.push({op:"cameraShake",clipId:f.id,at:Math.round((a+r.shake.at)*1e3)/1e3,duration:r.shake.duration,numberValue:r.shake.intensity})}return s}function IA(t,e,o){const r=Math.max(0,it(t.start)??0),n=(Array.isArray(t.stations)?t.stations:[]).map((s,h)=>{if(!s||typeof s!="object"||typeof s.materialId!="string"||s.asset)return s;const f=(o??[]).find(y=>y.id===s.materialId),m=(typeof f?.gcsUri=="string"&&f.gcsUri.startsWith("gs://")?f.gcsUri:null)??/^upload:(gs:\/\/\S+)$/.exec(s.materialId)?.[1]??null;if(f&&f.kind&&f.kind!=="image")throw Error(`documentary station ${h+1}: ${s.materialId} is not a picture`);if(!m)throw Error(`documentary station ${h+1}: ${s.materialId} is not an uploaded picture of the Media bin (upload it or pick it from My Assets)`);return{...s,asset:m}}),a=_8({...t,stations:n}),i=a.stations.some(s=>s.say)?c1(e,o,r,r+Zo.maxSeconds+30,typeof t.voiceClipId=="string"?t.voiceClipId:null):[],l=G8(a,(s,h)=>{if(!i.length)return null;const f=Nu(s,i,r+h);return f?f.at-r:null}),p=[],c=a.style==="map"?a.stations.find(s=>s.kind==="place"&&Array.isArray(s.lonlat)):null;c&&t.map!==!1&&p.push({op:"addMap",start:r,duration:l.total,label:c.label,geo:Eg({places:[{label:"",center:c.lonlat,zoom:Math.min(14,Math.max(2,it(t.mapZoom)??6))}],duration:l.total,style:"dark",route:!1,pins:!1})}),p.push({op:"documentary",_plan:l,start:r,label:typeof t.label=="string"?t.label.slice(0,60):""});for(const[s,h]of l.sfx)h<l.total&&p.push({op:"addSfx",sfxId:s,at:Math.round((r+h)*1e3)/1e3,volume:.6});return p}function yi(t,e,o=[],r={},n=null,a={}){const i=a.seamFrame??a,l=i.W>0&&i.H>0?{W:i.W,H:i.H}:{};let p=n?structuredClone(n):null;const c=a.motion?Nd(a.motion):{in:.5,out:.5,settle:"none"};e=Sv(e,{clips:t,materials:o,brand:a.brand??null,portrait:a.H>a.W*1.1,en:a.locale==="en",simulate:D=>yi(t,D,o,r,n,a).clips}),e=jv(e,{materials:o,portrait:a.H>a.W*1.1}),e=f6(e,{clips:t,materials:o,brand:a.brand??null,W:a.W||1280,H:a.H||720,en:a.locale==="en"?!0:null,maxOps:Math.min(ql,a?.maxOps??Yl),simulate:D=>yi(t,D,o,r,n,a).clips}),e=R6(e,{clips:t,materials:o,W:a.W||1280,H:a.H||720,maxOps:Math.min(ql,a?.maxOps??Yl),simulate:D=>yi(t,D,o,r,n,a).clips}),e=C6(e,{W:a.W||1280,H:a.H||720}),e=cE(Ex(e,{brand:a.brand??null,portrait:a.H>a.W*1.1}),{portrait:a.H>a.W*1.1});let s=t.map(D=>({...D}));r=structuredClone(r);const h=[],f=[],m=[],y=[],$=[],x=[],E=[],v=[],S=[],k=[],b=D=>s.find(H=>H.id===D),A=(D,H,ut=null)=>{let gt=v.find(T=>T.clipId===D.id&&!T.object);gt||(gt={clipId:D.id,behind:[]},v.push(gt)),H&&!gt.behind.includes(H)&>.behind.push(H);const xt=Fh(D.personPending),u=xt?.behind??[],st=xt?.job,V=xt?.ready,d=xt?.then??[],w=ut?[...d,ut].slice(-ok):d;D.personPending={behind:[...new Set([...u,...gt.behind])].slice(0,Rh),...st?{job:st}:{},...st&&V?{ready:V}:{},...w.length?{then:w}:{},...xt?.objects?{objects:xt.objects,person:!0}:{}}},I=(D,H=null)=>ut=>!r[ut]?.locked&&!s.some(gt=>gt.id!==H&>.track===ut&>.start<D.start+D.duration&>.start+gt.duration>D.start),P=(D,H,ut)=>{const gt={...Fh(D.personPending)??{behind:[]}},xt=(gt.objects??[]).map(V=>({...V,behind:[...V.behind]}));D.personPending&&!D.personPending.object&&!D.personPending.objects&&(gt.person=!0);let u=xt.find(V=>V.id===H.id);if(u)H.pts&&H.pts!==u.pts&&(u.pts=H.pts,u.at=H.at);else{if(xt.length>=Dh)throw Error(`"${D.label||D.id}" already waits for ${Dh} object cut-outs`);u={id:H.id,name:H.name,pts:H.pts,at:H.at,behind:[],...H.layer?{layer:H.layer}:{}},xt.push(u)}if(ut&&!u.behind.includes(ut)){if(u.behind.length>=Rh)throw Error("Too many layers behind one object");u.behind.push(ut)}D.personPending={...gt,objects:xt};let st=v.find(V=>V.clipId===D.id&&V.object?.id===H.id);st||(st={clipId:D.id,behind:[],object:{id:u.id,name:u.name,pts:u.pts,at:u.at,...u.layer?{layer:u.layer}:{}}},v.push(st)),st.behind=[...u.behind]},C=(D,H,ut)=>{const gt=a.objectMattes?.get?.(`${D.id}|${H.id}`);if(!gt)return null;const xt={id:H.id,name:H.name,...H.pts?{pts:H.pts,at:H.at}:{}},u=j=>j.id===D.id?rk(j,H.id):j,st=H.layer?b(H.layer):null;if(st&&pp(st)){const j=Q2(st,gt,xt);return s=s.map(O=>O.id===st.id?j:u(O)),Zs(s),j}const V=qs(ut??D,D,{index:ci,at:In,isFree:I(D)});if(V===null)throw Error(`No free track above ${D.label||D.id} for "${H.name}"`);let d=`${D.id}-${H.id}`,w=2;for(;b(d);)d=`${D.id}-${H.id}-${w++}`;const T=tk(s,D,gt,{id:d,track:V,label:ek(D,H.name,s),target:ut,obj:xt});return s=T.clips.map(u),Zs(s),T.layer},z=(D,H,ut)=>{const gt=qs(H,ut,{index:ci,at:In,isFree:I(D,D.id)});if(gt===null)throw Error(`No free track above ${H.label||H.id} for "${up(D).name}"`);s=s.map(xt=>xt.id!==D.id?xt:{...xt,track:gt,...(H.zIndex??0)>(xt.zIndex??0)?{zIndex:H.zIndex}:{}})};let N=null,F=null,K,_=null;const q=()=>_??(Array.isArray(a?.markers)?a.markers:[]),U=[],rt=new Map,ot=(D,H)=>({posX:Math.max(-1,Math.min(1,it(D.posX)??0)),posY:Math.max(-1,Math.min(1,it(D.posY)??0)),scale:Math.max(.25,Math.min(4,it(D.scale)??H))});Array.isArray(e)&&e.some(D=>D?.op==="speedster")&&(e=e.flatMap(D=>D?.op==="speedster"?MA(Qt(D)):[D])),Array.isArray(e)&&e.some(D=>D?.op==="beautyFace")&&(e=e.flatMap(D=>{if(D?.op!=="beautyFace")return[D];const H=Qt(D),ut=Array.isArray(H.clipIds)?H.clipIds:H.clipId!=null?[H.clipId]:[],gt=H.booleanValue===!1?[]:f$(h$(H),a.locale);return[{op:"beautyStrip",clipIds:ut,_off:H.booleanValue===!1},...gt.length?[{op:"colorGrade",clipIds:ut,windows:{mode:"add",custom:gt}}]:[]]})),Array.isArray(e)&&e.some(D=>D?.op==="energyAura")&&(e=e.flatMap(D=>{if(D?.op!=="energyAura")return[D];const H=Qt(D);if(H._auraId||Array.isArray(H.path)||H.behind===!1)return[H];const ut=Rt();return[{...H,_auraId:ut},{op:"placeBehindPerson",clipId:ut,sourceClipId:H.clipId}]})),Array.isArray(e)&&e.some(D=>D?.op==="addVfxPreset"&&!D._footage)&&(e=e.flatMap(D=>{if(D?.op!=="addVfxPreset"||D._footage)return[D];try{return SA(Qt(D),t,o)}catch(H){return[{op:"addVfxPreset",_footage:null,_error:H?.message||String(H)}]}})),Array.isArray(e)&&e.some(D=>D?.op==="documentary"&&!D._plan)&&(e=e.flatMap(D=>{if(D?.op!=="documentary"||D._plan)return[D];try{return IA(Qt(D),t,o)}catch(H){return[{op:"documentary",_plan:null,_error:H?.message||String(H)}]}})),Array.isArray(e)&&e.some(D=>D?.op==="animePower")&&(e=e.flatMap(D=>D?.op==="animePower"?x$(Qt(D)):[D]));const G=(Array.isArray(e)?e:[]).slice(0,Math.min(ql,a?.maxOps??Yl)),J=D=>vs.includes(D?.op),Z=D=>D?.op==="speakerBubble"||D?.op==="speakerWindow",at=[...G.filter(D=>!Z(D)&&!J(D)),...G.filter(Z),...G.filter(J)];for(const[D,H]of at.entries()){const ut=U.length,gt=typeof H?.clipId=="string"&&/^new:(\d+)$/.exec(H.clipId),xt=V=>{const d=typeof V=="string"&&/^new:(\d+)$/.exec(V);return d?U[Number(d[1])-1]??V:V};let u=gt||Array.isArray(H?.clipIds)?{...H,clipId:gt?U[Number(gt[1])-1]??H.clipId:H.clipId,...Array.isArray(H.clipIds)?{clipIds:H.clipIds.map(xt)}:{}}:H;typeof u?.parentClipId=="string"&&/^new:\d+$/.test(u.parentClipId)&&(u={...u,parentClipId:xt(u.parentClipId)});let st=null;try{if(u?.op==="lockup"&&(st=x8(u,{clips:s,materials:o,W:a.W||1280,H:a.H||720}),u=st.addText),u?.op==="estateText"){if(typeof u.text!="string"||!u.text.trim())throw Error("estateText needs its text");u=Y8(u,{portrait:(a.H||720)>(a.W||1280)*1.1})}if(u?.op==="syncMapToVoice"){const d=b(u.clipId);if(!d?.geo)throw Error("syncMapToVoice needs an animated map clip (addMap)");const w=Qt(u),T=d.start,j=d.start+d.duration,O=Array.isArray(w.times)?w.times:null,L=O?[]:c1(s,o,T,j,typeof w.voiceClipId=="string"?w.voiceClipId:null);if(!O&&!L.length){if(s.some(X=>X.start<j&&X.start+X.duration>T&&ks(o.find(Q=>Q.id===X.nodeId))>0)){h.push(`map ${d.id}: timed to the voice when applied`);continue}throw Error("Transcribe the voice-over first: the map is timed to the words it says")}const B=u5(hh(d.geo),d.geo.icons??[],{words:L,times:O,start:d.start,duration:d.duration,lead:Number(w.lead)});h.push(`map ${d.id} timed to the voice: ${d5(B.report)}`),u={op:"updateMap",clipId:d.id,places:B.places,placesResolved:!0,icons:B.icons}}if(u?.op==="addMotionCode"){if(typeof u.code!="string"||!/\brender\b/.test(u.code))throw Error("Motion code must define function render(ctx, t, env)");const{kind:d,...w}=u;u={...w,op:"addMotion",...d==="three"?{motionKind:"three"}:{}}}if(u?.clipId&&r[b(u.clipId)?.track]?.locked||u?.track!==void 0&&r[u.track]?.locked&&!Zy.includes(u.op)&&!(u.op==="setTrackProperty"&&u.property==="locked"&&u.booleanValue===!1))throw Error("Track đã khóa");const V=u?.clipId?b(u.clipId)?.label||u.clipId:"";if(vs.includes(u?.op)){if(at.indexOf(H)!==at.length-1)throw Error("Control action must follow all edits");if(["undo","redo","analyzeFootage"].includes(u.op)&&e.length!==1)throw Error("History/analysis actions must be requested alone");if(u.op==="seek"&&(!Number.isFinite(u.at)||u.at<0||u.at>Math.max(0,...s.map(d=>d.start+d.duration))))throw Error("Seek outside timeline");if(["play","exportVideo"].includes(u.op)&&!s.length)throw Error("No clips to export");if(m.length)throw Error("Only one playback/export action per request");if(["exportVideo","setExportFormat"].includes(u.op)){if(u.resolution!=null&&!["720p","1080p"].includes(u.resolution)||u.aspectRatio!=null&&!["16:9","9:16","1:1","4:5"].includes(u.aspectRatio)||u.fps!=null&&![24,25,30,60].includes(u.fps)||u.loudness!=null&&![-14,-16,0].includes(u.loudness))throw Error("Invalid export format");if(N&&u.aspectRatio!=null&&u.aspectRatio!==N)throw Error("Export aspect ratio must match the reframe")}m.push({op:u.op,at:u.at,...["exportVideo","setExportFormat"].includes(u.op)?{...Object.fromEntries(["resolution","aspectRatio","fps","loudness"].filter(d=>u[d]!=null).map(d=>[d,u[d]])),...N&&u.aspectRatio==null?{aspectRatio:N}:{}}:{}});continue}if(u?.op!=="matchReference"&&typeof u?.materialId=="string"&&o.find(d=>d.id===u.materialId)?.role==="reference")throw Error("Video mẫu chỉ để phân tích nhịp — không đưa vào timeline");switch(u?.op){case"setExportRange":{const d=w=>w==null?null:typeof w=="number"&&Number.isFinite(w)?w:NaN;try{K=Bk(d(u.in),d(u.out))}catch{throw Error("setExportRange needs in / out in timeline seconds, 0 ≤ in < out ≤ 600 (both omitted = the whole film)")}h.push(K?`export range ${K.in}s–${K.out>=We?"the end":`${K.out}s`}`:"export range: whole film");break}case"addMarker":{if(u.color!=null&&!gc.includes(u.color))throw Error(`addMarker color must be one of ${gc.join(", ")}`);let d;if(u.onBeats!=null){if(!Uf.includes(u.onBeats))throw Error(`addMarker onBeats must be ${Uf.join(" | ")}`);if(d=n$(s,o,{density:u.onBeats}).filter(j=>u.onBeats==="beats"||j.kind!=="beat").map(j=>j.t),!d.length)throw Error("No beats found: add the song with add_media (its beats are found automatically) first")}else d=Array.isArray(u.times)?u.times:[u.at];if(d.length>200)throw Error("addMarker: at most 200 times per op");let w=q(),T=0;for(const j of d){const O=e$(w,{t:it(j)??NaN,label:u.label,color:u.color??void 0,id:`mk${Rt().replace(/[^A-Za-z0-9]/g,"").slice(0,12)}`});w=O.markers,O.added&&T++}_=w,h.push(`markers: +${T}${d.length>T?` (${d.length-T} already there)`:""}`);break}case"updateMarker":{_=o$(q(),u.markerId,{...u.at!==void 0?{t:it(u.at)??NaN}:{},...u.label!==void 0?{label:u.label??""}:{},...u.color!==void 0?{color:u.color}:{}}),h.push(`marker ${u.markerId} updated`);break}case"removeMarker":{if(u.all===!0){h.push(`markers: −${q().length}`),_=[];break}_=r$(q(),u.markerId),h.push(`marker ${u.markerId} removed`);break}case"cutAtMarkers":{const d=Array.isArray(u.markerIds)?q().filter(O=>u.markerIds.includes(O.id)):q();if(!d.length)throw Error("No markers: add some first (addMarker, or the M key in the editor)");const w=Array.isArray(u.clipIds)?u.clipIds:null,T=s.filter(O=>!r[O.track]?.locked&&(w?w.includes(O.id):u.track!=null?O.track===u.track:(u.includeAudio===!0||O.kind!=="audio")&&O.kind!=="text"));if(w&&T.length!==w.length)throw Error("cutAtMarkers: a clip is missing or on a locked track");let j=0;for(const O of T){let L=O;for(const B of a$(O,d.map(X=>X.t))){if(s.length>=Kt)throw Error(`Tối đa ${Kt} clip`);const X=Ne(L,B,Rt());X.length!==1&&(s=s.flatMap(Q=>Q.id===L.id?X:[Q]),L=X[1],j++)}}h.push(`cut at markers: ${j} cut${j===1?"":"s"}`);break}case"setCamera":{p={...p??{...Ar,motionKeys:[]},enabled:u.booleanValue!==!1};const d=Object.hasOwn(u,"parentClipId")?u.parentClipId:u.clipId;if(d!==void 0)if(d===null||d==="")delete p.parentId;else{const w=b(d);if(!w||w.kind==="audio")throw Error(`Camera parent ${d} not found`);p.parentId=w.id}jr(p),h.push(`camera ${p.enabled?"on":"off"}${p.parentId?` · follows ${b(p.parentId)?.label??p.parentId}`:""}`);break}case"setPath":{const d=b(u.clipId);if(!d||d.kind==="audio")throw Error(`Không tìm thấy layer ${u.clipId}`);const w=u.points==null||Array.isArray(u.points)&&!u.points.length,T=NE(d,w?null:{points:u.points,...it(u.start)!=null?{start:it(u.start)}:{},...it(u.end)!=null?{end:it(u.end)}:{},...typeof u.ease=="string"&&u.ease!=="linear"?{ease:u.ease}:{},...u.booleanValue===!0?{orient:!0}:{},...u.closed===!0?{closed:!0}:{}},{W:a.W||1280,H:a.H||720});Object.assign(d,T),T.path===void 0&&delete d.path,h.push(w?`path off ${V}`:`path ${V}: ${u.points.length} points${u.booleanValue===!0?" · auto-orient":""}`);break}case"linkProperty":{const d=b(u.clipId);if(!d||d.kind==="audio")throw Error(`Không tìm thấy layer ${u.clipId}`);if(!Qs.includes(u.property))throw Error(`property must be one of ${Qs.join("/")}`);const w=(d.links??[]).filter(L=>L.prop!==u.property),T=xt(u.fromClipId),j=T?{prop:u.property,from:T,...u.fromProperty?{fromProp:u.fromProperty}:{},...it(u.factor)!=null?{factor:it(u.factor)}:{},...it(u.offset)!=null?{offset:it(u.offset)}:{},...it(u.delay)!=null?{delay:it(u.delay)}:{},...u.booleanValue===!0?{add:!0}:{}}:null,O=Vk(s,d,j?[...w,j]:w);Object.assign(d,O),O.links===void 0&&delete d.links,h.push(j?`link ${V}.${u.property} ← ${b(T)?.label??T}.${j.fromProp??u.property}`:`unlink ${V}.${u.property}`);break}case"setExpression":{const d=b(u.clipId);if(!d||d.kind==="audio")throw Error(`Không tìm thấy layer ${u.clipId}`);if(!Object.hasOwn(Tr,u.property))throw Error(`property must be one of ${Object.keys(Tr).join("/")}`);const w=u.expression!==void 0?u.expression:u.text,T=typeof u.enabled=="boolean"?u.enabled:typeof u.booleanValue=="boolean"?u.booleanValue:void 0;if(w!=null){if(typeof w!="string")throw Error("expression must be text");H2(w)}if(w==null&&T===void 0&&u.expression!==null&&u.text!==null)throw Error("expression (text) or enabled is required");const j=U2(d,u.property,w===void 0?void 0:w,T);Object.assign(d,j),j.expr===void 0&&delete d.expr;let O=null;d.expr?.[u.property]&&!d.expr[u.property].off&&(Y2(s),O=q2(d,u.property,0)),h.push(w===null?`expression off ${V}.${u.property}`:`expression ${V}.${u.property}${d.expr?.[u.property]?.off?" (disabled)":""}: ${d.expr?.[u.property]?.src.slice(0,80)}${O?` — warning: ${O}`:""}`);break}case"followChain":{const d=b(u.clipId);if(!d)throw Error(`Không tìm thấy layer ${u.clipId}`);const w=Array.isArray(u.properties)&&u.properties.length?u.properties:["x","y","rot"];if(w.some(j=>!Qs.includes(j)))throw Error(`properties must be from ${Qs.join("/")}`);const T=Kk(s,d.id,(u.clipIds||[]).filter(j=>j!==d.id),w,it(u.numberValue)??.08);for(const[j,O]of Object.entries(T))Object.assign(b(j),O);h.push(`followChain ${Object.keys(T).length} layer(s) after ${V} on ${w.join("/")}`);break}case"addNull":{const d=ht(Math.max(0,it(u.start)??0)),w=ht(Math.max(1/30,it(u.duration)??5)),{track:T}=Zt(s,r,d,d+w),j=typeof u.text=="string"&&u.text.trim()?u.text.trim().slice(0,80):X2(s),O={...br({id:Rt(),track:T,start:d,duration:w,label:j,is3D:u.booleanValue===!0}),...Number.isFinite(u.posX)?{posX:u.posX}:{},...Number.isFinite(u.posY)?{posY:u.posY}:{},...u.booleanValue===!0&&Number.isFinite(u.numberValue)?{spatialDepth:u.numberValue}:{}};s.push(O),U.push(O.id);const L=(Array.isArray(u.clipIds)?u.clipIds:[]).filter(B=>B!==O.id);if(L.length){const B=a.W||1280,X=a.H||720;for(const et of L){const lt=b(et);if(!lt||lt.kind==="audio")throw Error(`addNull clipIds: ${et} is not a visual layer`);if(r[lt.track]?.locked)throw Error("That layer is locked")}nr(s);const Q=xl(s,qp(s,L),B,X);for(const et of L){const lt=b(et),Y=s.indexOf(lt);s[Y]=wa(s,lt,{parentClipId:O.id,at:Math.max(0,Math.min(lt.duration,d-lt.start)),W:B,H:X})}s=hs(s,Q,B,X)}h.push(`addNull ${O.is3D?"3D ":""}"${j}" (${O.id})${L.length?` with ${L.length} layer(s) linked`:""}`);break}case"setCameraKeys":{if(!Nh.includes(u.property))throw Error(`Camera property must be ${Nh.join("/")}`);if(!Array.isArray(u.propertyKeys)||u.propertyKeys.length>30)throw Error("Provide 0–30 camera keys");const{min:d,max:w}=Ln[u.property],T={...p??{...Ar,motionKeys:[]},enabled:!0},j=u.propertyKeys.map(O=>{if(!Number.isFinite(O?.time)||O.time<0||O.time>We)throw Error("Camera key time must be timeline seconds");if(!Number.isFinite(O.value)||O.value<d||O.value>w)throw Error(`${u.property} must be ${d}..${w}`);const L=O.ease&&O.ease!=="linear"?Jt[O.ease]:void 0;if(O.ease&&O.ease!=="linear"&&!L)throw Error(`Unknown easing "${O.ease}"`);return{time:ht(O.time),value:O.value,...L?{ease:L}:{}}}).sort((O,L)=>O.time-L.time);p=j.length?un(T,u.property,j):{...un(T,u.property,[]),[u.property]:Gs(T,u.property,0)},jr(p),h.push(`camera ${u.property}: ${j.length} key`);break}case"cameraMove":{const d=u.ease&&u.ease!=="linear"?Jt[u.ease]:void 0;p=W2(p,u.preset,it(u.at)??0,it(u.duration)??2,{amount:it(u.numberValue)??1,ease:d}),h.push(`camera ${u.preset} ${it(u.at)??0}s → ${(it(u.at)??0)+(it(u.duration)??2)}s`);break}case"cutPauses":{const d=b(u.clipId),w=d&&o.find(j=>j.id===d.nodeId);if(!d)throw Error("Clip not found");const T=B4(s,u.clipId,w,{minGap:u.numberValue??.6,padding:.12,fillers:u.booleanValue===!0,maxClips:Kt,isBed:j=>j.kind==="audio"&&j.nodeId!==d.nodeId&&!o.find(O=>O.id===j.nodeId)?.transcript?.length},r,Rt);if(!T.removed)throw Error(T.skipped?`No pause could be removed (${T.skipped} blocked by other clips or the clip limit)`:"No pause long enough to remove");s=T.clips,h.push(`cut pauses: ${V} −${T.removed} (${T.saved}s)${T.skipped?`, ${T.skipped} skipped`:""}`);break}case"removeRetakes":{if(u.keep!=null&&!r1.includes(u.keep))throw Error("keep must be best, last or first");const d=a.locale==="en",w=p5(s,o,{clipIds:Array.isArray(u.clipIds)&&u.clipIds.length?u.clipIds:null,window:it(u.window)??void 0,minSimilarity:it(u.minSimilarity)??void 0,keep:u.keep??"best",tracks:r,maxClips:Kt,makeId:Rt,en:d,isBed:T=>T.kind==="audio"&&!o.find(j=>j.id===T.nodeId)?.transcript?.length&&!o.find(j=>j.id===T.nodeId)?.words?.length});if(!w.found.groups.length){h.push(d?"retakes: no repeated line found":"retakes: không thấy câu nói lại");break}if(!w.removed&&w.groups.some(T=>T.cut.length))throw Error(`No retake could be cut: ${[...new Set(w.groups.flatMap(T=>T.blocked.map(j=>j.reason)))].join(", ")||"nothing to cut"}`);s=w.clips,h.push(...w.lines,d?`retakes: −${w.removed} cut (${+w.saved.toFixed(2)}s)`:`retakes: −${w.removed} đoạn (${+w.saved.toFixed(2)}s)`);break}case"scriptEdit":{const d=b(u.clipId);if(!d)throw Error("Clip not found");const w=o.find(Y=>Y.id===d.nodeId),T=Array.isArray(w?.words)?w.words:[];if(!T.length){if(ks(w)>0){h.push(`script edit ${V}: planned on the clip's words when applied`);break}throw Error("Transcribe the clip first: the script edit finds each line in its words")}const j=Array.isArray(u.scriptLines)&&u.scriptLines.length?u.scriptLines.slice(0,ia.maxLines).map(Y=>typeof Y=="string"?Qf(Y)[0]??{text:Y}:{text:String(Y?.text??""),...it(Y?.duration)>0?{duration:it(Y.duration)}:{}}).filter(Y=>Y.text.trim()):Qf(u.script??u.prompt??"");if(!j.length)throw Error("The script is empty");const O=u.referenceId??null,L=O?o.find(Y=>Y.id===O):null;if(O&&!L)throw Error("Reference video not found");if(L&&!(Array.isArray(L.words)&&L.words.length)&&!ks(L))throw Error("Transcribe the reference video first: its pace comes from its words");const B=d.inPoint||0,X=B+d.duration*(d.playbackRate||1),Q=N$(j,T.filter(Y=>Y.start>=B-.05&&Y.end<=X+.05),{pace:L?.words?.length?L$(L.words):null,cutPauses:u.cutPauses!==!1,speed:typeof u.speed=="boolean"?u.speed:u.booleanValue!==!1,maxPause:it(u.maxPause)??it(u.numberValue)??void 0,skip:Array.isArray(u.skipLines)?u.skipLines.filter(Number.isInteger):[],silences:o1(w)??[]}),et=a.locale==="en";if(h.push(...D$(Q,et)),u.dryRun===!0){h.push(et?`script edit (preview): ${Q.found} / ${Q.lines.length} lines found → ${Q.length.toFixed(1)}s`:`dựng theo kịch bản (xem trước): thấy ${Q.found} / ${Q.lines.length} câu → ${Q.length.toFixed(1)}s`);break}const lt=R$(s,d.id,Q,{tracks:r,maxClips:Kt,makeId:Rt,isBed:Y=>Y.kind==="audio"&&!o.find(dt=>dt.id===Y.nodeId)?.transcript?.length&&!o.find(dt=>dt.id===Y.nodeId)?.words?.length});s=lt.clips,h.push(et?`script edit: ${Q.found} / ${Q.lines.length} lines, ${lt.pieces} pieces → ${lt.length.toFixed(1)}s (${lt.delta>=0?"+":""}${lt.delta.toFixed(1)}s)`:`dựng theo kịch bản: ${Q.found} / ${Q.lines.length} câu, ${lt.pieces} đoạn → ${lt.length.toFixed(1)}s (${lt.delta>=0?"+":""}${lt.delta.toFixed(1)}s)`);break}case"audioTool":{if(!Lh.includes(u.tool))throw Error(`audioTool: tool must be one of ${Lh.join(", ")}`);if(!Array.isArray(u.processed)||!u.processed.length)throw Error("audioTool runs through Clipoox MCP edit_timeline only (the server processes the sound first)");for(const d of u.processed){let w=rt.get(d.clipId)??d.clipId,T=b(w);if(!T)throw Error(`Không thấy clip ${d.clipId}`);if(T.kind==="video"){const L=Yy(s,T.id,{tracks:r,makeId:Rt});s=L.clips,rt.set(d.clipId,L.audio),w=L.audio,T=b(w)}if(T?.kind!=="audio")throw Error("audioTool: only video and audio clips have sound");const j=[...T.audioTools??[],u.tool];V2(j);const O=it(d.duration);if(!d.dry&&(typeof d.url!="string"||!O||O<=0))throw Error("audioTool: the processed sound is missing");s=s.map(L=>L.id!==w?L:d.dry?{...L,audioTools:j}:{...L,url:d.url,...typeof d.gcsUri=="string"?{gcsUri:d.gcsUri}:{},inPoint:0,sourceDuration:+O.toFixed(3),audioTools:j}),h.push(`${u.tool} ${T.label||w}${rt.get(d.clipId)===w&&d.clipId!==w?" (sound detached from the video)":""}`)}break}case"muffleAudio":{s=K2(s,u.clipId,u.booleanValue===!1?{remove:!0}:{at:it(u.at),duration:it(u.duration)}),h.push(u.booleanValue===!1?`unmuffle ${V}`:`muffle ${V} ${it(u.at)}–${(it(u.at)+it(u.duration)).toFixed(2)} s`);break}case"duckAudio":{const d=u.clipId?[u.clipId]:s.filter(T=>T.kind==="audio"&&!T.sfx&&(u.track===void 0||T.track===u.track)&&!o.find(j=>j.id===T.nodeId)?.transcript?.length).map(T=>T.id);if(u.booleanValue===!1){let T=0;if(s=s.map(j=>{if(!d.includes(j.id)||!j.duck)return j;T++;const{duck:O,...L}=j;return L}),!T)throw Error("Nothing is ducked");h.push(`unduck ${T} clip`);break}const w=G4(s,d,o,u.numberValue??.25,r);if(!w.ducked)throw Error("The music does not overlap any speech");s=w.clips,h.push(`duck ${w.ducked} clip → ${u.numberValue??.25} under speech`);break}case"punchIn":{const d=it(u.at);if(d===null)throw Error("punchIn needs at (timeline seconds)");const w=du(s,u.clipId,d);if(w<0)throw Error("Clip not found");const T=s[w];if(u.punchStyle!=null&&!Wo.styles.includes(u.punchStyle))throw Error(`Punch-in style must be ${Wo.styles.join(" or ")}`);s[w]={...T,...gm(T,{at:ht(d-T.start),duration:it(u.duration)??void 0,amount:it(u.numberValue)??void 0,style:u.punchStyle??void 0,anchor:wc(T,o.find(j=>j.id===T.nodeId))})},h.push(`punch-in ${V} @ ${ht(d)}s`);break}case"makeRoom":{const d=it(u.at);if(d===null)throw Error("makeRoom needs at (timeline seconds)");const w=du(s,u.clipId,d);if(w<0)throw Error("Clip not found");const T=s[w];if(!Dm.includes(u.preset))throw Error(`Make room preset must be ${Dm.join("/")}`);s[w]={...T,...nE(T,{at:ht(d-T.start),duration:it(u.duration)??void 0,preset:u.preset,amount:it(u.numberValue)??void 0})},h.push(`make room ${u.preset} ${V} @ ${ht(d)}s`);break}case"speakerBubble":{const d=it(u.at),w=b(u.clipId);if(!w)throw Error("Clip not found");const T=d!==null&&!(d>=w.start&&d<w.start+w.duration)?s.find(B=>B.nodeId===w.nodeId&&B.track===w.track&&!B.mask&&d>=B.start&&d<B.start+B.duration)??w:w;if(s.length+2>Kt)throw Error(`Tối đa ${Kt} clip`);const j=it(u.at);if(j===null)throw Error("speakerBubble needs at (timeline seconds)");const O=u.corner??"bottom-left";if(!lo.corners.includes(O))throw Error(`Bubble corner must be ${lo.corners.join("/")}`);for(const B of["posX","posY"])if(u[B]!=null&&!(Number.isFinite(u[B])&&u[B]>=0&&u[B]<=1))throw Error(`speakerBubble ${B} must be 0..1 (the bubble centre)`);if(u.color!=null&&!/^#[0-9a-fA-F]{6}$/.test(String(u.color)))throw Error("speakerBubble color must be #RRGGBB");s=Tv(s,T.id,{at:j,duration:it(u.duration)??void 0,corner:O,size:it(u.numberValue)??void 0,posX:it(u.posX),posY:it(u.posY),color:u.color!=null?String(u.color).toLowerCase():null,W:a?.W||1280,H:a?.H||720,material:o.find(B=>B.id===T.nodeId)??null,newId:Rt}).clips,h.push(`speaker bubble ${V} @ ${ht(j)}s`);break}case"stepPunch":{u=Qt(u);const d=it(u.at);if(d===null)throw Error("stepPunch needs at (timeline seconds)");const w=du(s,u.clipId,d);if(w<0)throw Error("Clip not found");const T=s[w];s[w]={...T,...rA(T,{at:ht(d-T.start),steps:vt(u.steps),frames:vt(u.frames),amount:vt(u.amount)??vt(u.numberValue),point:Array.isArray(u.point)?u.point:null,back:u.back!==!1})},h.push(`stepPunch ${V} @ ${ht(d)}s`);break}case"matteFlash":{u=Qt(u);let d=b(u.clipId);if(!d||d.kind!=="video"&&d.kind!=="image")throw Error("matteFlash needs a video or image clip");if(!d.person){const j=d,O=s.find(L=>L.id!==j.id&&L.kind===j.kind&&L.person&&L.url===j.url);O&&(d={...j,person:O.person})}if(!d.person){if(d.kind!=="video"||a.noPendingMatte||!t.some(L=>L.id===d.id))throw Error(`"${d.label||d.id}" has no AI cut-out yet — segmentPerson / cutOutObject on it first`);const{clipId:j,...O}=u;A(d,null,{...O,clipId:d.id}),h.push(`matteFlash ${d.label||d.id}: waits for the AI person matte (made in the editor), then runs`);break}const w=()=>{let j=Rt();for(;b(j);)j=Rt();return j},T=nA(d,{frames:vt(u.frames)??vt(u.numberValue),side:u.side==="out"?"out":"in",aspect:a.W&&a.H?a.W/a.H:void 0},w);if(s.length+T.length>Kt)throw Error(`Tối đa ${Kt} clip`);for(const j of T){const{track:O}=Zt(s,r,j.start,j.start+j.duration);s.push({...j,track:O}),U.push(j.id)}h.push(`matteFlash ${d.label||d.id}: ${Math.round(T[0].duration*30)} frame(s) of white silhouette on black at ${T[0].start}s`);break}case"endingLook":{u=Qt(u);const d=u.style??u.preset??"drain";if(!["drain","iris","drain-iris"].includes(d))throw Error("endingLook style: drain | iris | drain-iris");const w=b(u.clipId);if(!w)throw Error("Clip not found");const T=it(u.at),j=()=>{let L=Rt();for(;b(L);)L=Rt();return L};if(s.length+2>Kt)throw Error(`Tối đa ${Kt} clip`);let O=w;if(d!=="drain"){const L=s.length,B=iA(s,w.id,{at:T??void 0,radius:vt(u.radius),push:vt(u.push),cx:Array.isArray(u.point)?Number(u.point[0]):vt(u.posX),cy:Array.isArray(u.point)?Number(u.point[1]):vt(u.posY),W:a.W||1280,H:a.H||720,material:o.find(X=>X.id===w.nodeId)??null,newId:j});s=B.clips,O=s.find(X=>X.id===B.irisId),s.length>L&&U.push(B.irisId)}if(d!=="iris"){const L=aA(O,{at:d==="drain"?T??void 0:it(u.drainAt)??void 0,duration:vt(u.duration)},j);if(d==="drain-iris"&&L.mask?.keys?.length===1){const X=L.mask.keys[0].pts,Q=X.reduce((lt,Y)=>lt+Y[0],0)/X.length,et=X.reduce((lt,Y)=>lt+Y[1],0)/X.length;L.mask={...L.mask,keys:[{t:0,pts:X.map(([lt,Y])=>[no(Q+(lt-Q)*1.04),no(et+(Y-et)*1.04)])}]}}const{track:B}=Zt(s,r,L.start,L.start+L.duration);s.push({...L,track:B}),U.push(L.id)}h.push(`endingLook ${d}: ${V}`);break}case"mediaCard":{u=Qt(u);const d=b(u.clipId);if(!d)throw Error("Clip not found");for(const j of["posX","posY"])if(u[j]!=null&&!(Number.isFinite(u[j])&&u[j]>=0&&u[j]<=1))throw Error(`mediaCard ${j} must be 0..1 (the card centre)`);const{patch:w,rect:T}=Uy(d,{W:a.W||1280,H:a.H||720,material:o.find(j=>j.id===d.nodeId)??null,width:vt(u.width)??vt(u.numberValue),cx:vt(u.posX),cy:vt(u.posY),aspect:vt(u.aspect),round:vt(u.round),rim:u.rim===!1?!1:u.color??void 0});for(const[j,O]of Object.entries(w))O===void 0?delete d[j]:d[j]=O;h.push(`mediaCard ${V}: card at x ${T.x}, y ${T.y}, w ${T.w}, h ${T.h} (fractions of the frame)`);break}case"mediaBoard":{u=Qt(u);const d=Array.isArray(u.clipIds)?u.clipIds:[],w=d.map(B=>b(B));if(!w.length||w.some(B=>!B)||new Set(d).size!==d.length)throw Error(`mediaBoard needs clipIds: 1–${se.board.max} different clips`);const T=Math.max(...w.map(B=>B.start));if(!(Math.min(...w.map(B=>B.start+B.duration))-T>=.5))throw Error("mediaBoard: the clips must play at the same time (each on its own row)");const O=u.area&&["x","y","w","h"].every(B=>Number.isFinite(u.area[B])&&u.area[B]>=0&&u.area[B]<=1)&&u.area.w>.1&&u.area.h>.1?{x:u.area.x,y:u.area.y,w:Math.min(u.area.w,1-u.area.x),h:Math.min(u.area.h,1-u.area.y)}:void 0,L=pA(w,{W:a.W||1280,H:a.H||720,materials:o,area:O,cols:vt(u.cols),step:vt(u.step),round:vt(u.round),rim:u.rim===!1?!1:u.color??void 0});for(const B of w)for(const[X,Q]of Object.entries(L.patches.get(B.id)))Q===void 0?delete B[X]:B[X]=Q;h.push(`mediaBoard: ${w.length} card(s) — ${L.rects.map(B=>`${B.id} at x ${B.x}, y ${B.y}, w ${B.w}, h ${B.h}`).join("; ")}`);break}case"screenCamera":{u=Qt(u);const d=b(u.clipId);if(!d)throw Error("Clip not found");const w=(Array.isArray(u.moves)?u.moves:[]).map(T=>({...T,at:Number(T?.at)-d.start}));Object.assign(d,uA(d,{moves:w})),h.push(`screenCamera ${V}: ${w.length} move(s)`);break}case"outlineObject":{u=Qt(u);const d=b(u.clipId);if(!d||!d.person&&!d.mask)throw Error("outlineObject needs a cut-out layer (cutOutObject / segmentPerson, or a masked layer)");if(u.booleanValue===!1){delete d.edge,h.push(`outlineObject ${V}: removed`);break}const w=(T,j,O,L)=>Math.max(j,Math.min(O,Number.isFinite(T)?T:L));d.edge=mu({color:String(u.color??"#a3ff00").toLowerCase(),width:w(vt(u.width),.002,.08,.006),glow:w(vt(u.glow),0,2,1),...u.run===!0?{cover:.35,sweep:180,comet:!0}:{}}),h.push(`outlineObject ${V}: outline ${d.edge.color}`);break}case"handWipe":{u=Qt(u);const d=b(u.clipId);if(!d||d.kind!=="video"&&d.kind!=="image"||d.motion||d.title)throw Error("handWipe needs clipId = the picture / video to reveal");const w=b(u.sourceClipId);if(!w||w.kind!=="video")throw Error("handWipe needs sourceClipId = the footage with the hand");if(w.id===d.id)throw Error("handWipe: the layer and the footage must be two clips");if(d.mask||d.person)throw Error("handWipe: the layer already has a mask / cut-out");const T=Rm({...u,point:u.point??"palm"}),j=u.dir??"auto",O=vt(u.feather);if(!se.wipe.dirs.includes(j))throw Error(`handWipe dir: ${se.wipe.dirs.join(" | ")}`);const L=Math.max(d.start,w.start),B=Math.min(d.start+d.duration,w.start+w.duration);if(!(B-L>=4/30))throw Error("The layer and the footage do not play at the same time");if(s.length+1>Kt)throw Error(`Tối đa ${Kt} clip`);const X=a.W||1280,Q=a.H||720,et=o.find(It=>It.id===d.nodeId),lt=Math.round(et?.width)||X,Y=Math.round(et?.height)||Q;let dt=Rt();for(;b(dt);)dt=Rt();let bt={...w,id:dt};if(L>bt.start+1e-6){const[,It]=Ne(bt,L,`${dt}-a`);It&&(bt={...It,id:dt})}if(B<bt.start+bt.duration-1e-6){const[It]=Ne(bt,B,`${dt}-b`);bt={...It,id:dt}}const tt=bt,nt={...bt,label:`${w.label||"Video"} · tay`,volume:0,mask:ad(w.hands?.mw,w.hands?.mh)};for(const It of["roto","planar","personPending","clientJobs","hands","sceneTrack","objectTracks","captions","captionWords","captionStyle","transition","enter","exit","shocks","impacts","trail","pendingPin","pin","person"])delete nt[It];nt.track=Zt(s,r,nt.start,nt.start+nt.duration).track,s.push(nt),U.push(dt);const mt={source:w.id,mode:"wipe",cutout:dt,point:T.point,side:T.side,dir:j,...O!=null?{feather:O}:{},from:no(L-w.start),duration:no(B-L)};if(Ap(w,L-w.start,B-L)){const It=hA(d,w,{point:T.point,side:T.side,dir:j,feather:O??void 0,W:X,H:Q,mw:lt,mh:Y});d.mask=It.patch.mask;const Nt=Fm(tt);Nt&&(nt.mask=Nt),Object.assign(d,Re(d,{kind:"hand-track",op:"handWipe",params:mt})),h.push(`handWipe ${V}: revealed by the hand moving ${It.dir} (${It.from}–${It.to}s), hand in front`);break}d.mask=dA(lt,Y),Object.assign(d,Re(d,{kind:"hand-track",op:"handWipe",params:mt})),h.push(`handWipe ${V}: the hands are tracked in the editor, then the layer is revealed along the swipe`);break}case"beautyStrip":{const d=Array.isArray(u.clipIds)?u.clipIds:[];if(!d.length||d.length>40)throw Error("beautyFace needs clipId or clipIds (1–40)");let w=0;for(const T of d){const j=b(xt(T));if(!j)throw Error(`Clip not found: ${String(T).slice(0,60)}`);if(j.kind!=="video"&&j.kind!=="image"||j.title||j.shape||j.motion||j.card)throw Error(`beautyFace: ${j.label||j.id} is not footage (a video / image clip)`);const O=Md(j.grade),L=O.filter(B=>!d$(B));if(w+=O.length-L.length,L.length!==O.length){const B=$d(j.grade||{},L);Object.keys(B).length?j.grade=B:delete j.grade}}h.push(u._off?`beautyFace: removed ${w} beauty node(s)`:`beautyFace: ${d.length} clip(s)${w?` (replaced ${w} earlier beauty node(s))`:""}`);break}case"trackFace3D":{const d=b(u.clipId);if(!d||d.kind!=="video")throw Error("trackFace3D needs clipId = a video clip");if(rs(d)&&u.booleanValue!==!0){h.push(`trackFace3D ${d.label||d.id}: already tracked in 3D (${d.face.n} samples)`);break}Object.assign(d,Re(d,{kind:"face-3d",op:"trackFace3D"})),h.push(`trackFace3D ${d.label||d.id}: the face is tracked in 3D in the open editor`);break}case"pinToFace":{u=Qt(u);const d=b(u.clipId),w=b(u.sourceClipId);if(!d||!G2(d))throw Error("pinToFace needs clipId = an image / video / text / Motion layer");if(!w||w.kind!=="video"||w.id===d.id)throw Error("pinToFace needs sourceClipId = the footage with the face (a video clip)");const T=Math.max(d.start,w.start);if(Math.min(d.start+d.duration,w.start+w.duration)-T<1/30)throw Error("The layer and the footage do not play at the same time");const O=o.find(B=>B.id===d.nodeId),L=d.motion||d.title||!O?.width?(a.W||1280)/(a.H||720):O.width/O.height;delete d.pendingPin,d.pin={clip:w.id,face:df(u.place??"front",L,u)},rs(w)||Object.assign(w,Re(w,{kind:"face-3d",op:"pinToFace"})),h.push(`pinToFace ${d.label||d.id} → ${w.label||w.id} (${u.place??"front"}${rs(w)?"":", face tracked in 3D in the open editor"})`);break}case"faceHologram":{u=Qt(u);const d=b(u.sourceClipId??u.clipId);if(!d||d.kind!=="video")throw Error("faceHologram needs sourceClipId = the footage with the face");const w=Xg[u.set??"call"];if(!w)throw Error(`faceHologram set must be one of ${D3.join(", ")}`);if(u.place!=null&&!Su.includes(u.place))throw Error(`faceHologram place must be one of ${Su.join(", ")}`);const T=u.at==null?d.start:Number(u.at);if(!Number.isFinite(T)||T<d.start-1e-6||T>=d.start+d.duration)throw Error("faceHologram at must be a timeline time inside the footage");const j=Math.min(Qe.maxDuration,d.start+d.duration-T,u.duration==null?1/0:Number(u.duration));if(!(j>=1/be))throw Error("faceHologram duration is too short");if(s.length+w.layers.length>Kt)throw Error(`Tối đa ${Kt} clip`);const O=(a.W||1280)/(a.H||720),L=ht(T),B=ht(j),X=[];for(const Q of w.layers){const et=Ai(Q.preset,{text:u.text,subText:u.subText??u.subtitle,numberValue:u.numberValue,color:u.color}),lt=Jo({code:et.code,params:et.params,preset:et.preset,kind:et.kind});let Y=Rt();for(;b(Y);)Y=Rt();const{track:dt}=Zt(s,r,L,L+B);s.push({id:Y,nodeId:"",kind:"image",url:"",label:`Hologram · ${et.name}`,volume:0,motion:lt,blend:"add",start:L,duration:B,track:dt,motionKeys:[],pin:{clip:d.id,face:df(u.place??Q.place,O,u)}}),U.push(Y),X.push(Y)}rs(d)||Object.assign(d,Re(d,{kind:"face-3d",op:"faceHologram"})),h.push(`faceHologram ${u.set??"call"} on ${d.label||d.id}: ${X.length} layer(s) ${X.join(", ")}${rs(d)?"":" — the face is tracked in 3D in the open editor"}`);break}case"fixFace":{u=Qt(u);const d=b(u.clipId);if(!d?.face)throw Error("fixFace needs clipId = a video with a face track (trackFace3D)");if(u.booleanValue===!1){delete d.face.fix,d.face={...d.face},h.push(`fixFace ${d.label||d.id}: corrections removed`);break}const w=u.at==null?d.start:Number(u.at);if(!Number.isFinite(w)||w<d.start-1e-6||w>d.start+d.duration+1e-6)throw Error("fixFace at must be a timeline time inside the clip");const T=_2(d,w-d.start,{dx:vt(u.dx),dy:vt(u.dy),ds:vt(u.scale),droll:vt(u.roll),dyaw:vt(u.yaw),dpitch:vt(u.pitch)});d.face={...d.face,fix:T.fix},h.push(`fixFace ${d.label||d.id} at ${no(w)}s: ${T.text}`);break}case"speakerWindow":{const d=it(u.at);if(d===null)throw Error("speakerWindow needs at (timeline seconds)");const w=b(u.clipId);if(!w)throw Error("Clip not found");const T=d>=w.start&&d<w.start+w.duration?w:s.find(O=>O.nodeId===w.nodeId&&O.track===w.track&&!O.mask&&d>=O.start&&d<O.start+O.duration)??w;if(s.length+2>Kt)throw Error(`Tối đa ${Kt} clip`);for(const O of["posX","posY"])if(u[O]!=null&&!(Number.isFinite(u[O])&&u[O]>=0&&u[O]<=1))throw Error(`speakerWindow ${O} must be 0..1 (the window centre)`);if(u.aspect!=null&&!(Number.isFinite(u.aspect)&&u.aspect>=.4&&u.aspect<=2))throw Error("speakerWindow aspect must be .4–2 (width / height)");s=Pv(s,T.id,{at:d,duration:it(u.duration)??void 0,width:it(u.numberValue)??void 0,cx:it(u.posX)??void 0,cy:it(u.posY)??void 0,aspect:it(u.aspect)??void 0,color:u.color??void 0,W:a?.W||1280,H:a?.H||720,material:o.find(O=>O.id===T.nodeId)??null,newId:Rt}).clips,h.push(`speaker window ${V} @ ${ht(d)}s`);break}case"speakerLayout":{if(u.error)throw Error(u.error);const d=_d(u,"speakerLayout"),w=b(d.clipId);if(!w)throw Error("Clip not found");const T=v6(s,w.id,{beats:d.beats,morph:d.morph,W:a?.W||1280,H:a?.H||720,material:o.find(j=>j.id===w.nodeId)??null});s=T.clips,h.push(`speaker layout ${V}: ${d.beats.length} beat${d.beats.length>1?"s":""} on ${T.pieces} piece${T.pieces>1?"s":""}`);break}case"courseStyle":{const d=b(u.clipId);if(!d||!["image","video"].includes(d.kind)||d.motion||d.title||d.shape||d.card)throw Error("Course style needs a photo / video clip");const w=o.find(O=>O.id===d.nodeId),T=Number.isInteger(w?.width)&&w.width>1?w.width:1e3,j=Number.isInteger(w?.height)&&w.height>1?w.height:1e3;if(u.crop!=null){const{left:O=0,right:L=0,top:B=0,bottom:X=0}=u.crop;if(![O,L,B,X].every(Q=>Number.isFinite(Q)&&Q>=0&&Q<=.9)||O+L>.9||B+X>.9)throw Error("Invalid crop");d.crop={left:O,right:L,top:B,bottom:X}}if(u.rotation!=null){const O=it(u.rotation);if(O===null||Math.abs(O)>xs)throw Error(`rotation must be -${xs}..${xs}`);d.rotation=O}if(u.mask!=null){if(!["circle","rounded","none"].includes(u.mask))throw Error("Course style mask must be circle / rounded / none");if(u.mask==="none")delete d.mask;else{const O=Ma(T,j,d.crop),L=Math.min(O.w,O.h),B=u.mask==="circle"?{kind:"circle",cx:.5,cy:.5,w:+(L/O.w).toFixed(5),h:+(L/O.h).toFixed(5),rot:0}:{kind:"rect",cx:.5,cy:.5,w:1,h:1,rot:0,round:.12};d.mask=gr({mw:T,mh:j},[Yn(B,O.w,O.h)])}}if(u.color!=null){if(!/^#[0-9a-f]{6}$/i.test(u.color))throw Error("Course style color must be #RRGGBB");d.edge={color:u.color.toLowerCase(),width:Math.max(.002,Math.min(.08,it(u.numberValue)??.008)),glow:.7}}if(u.shadow===!0&&(d.shadow={...vn,opacity:.55,blur:18,distance:8}),u.fit!=null){if(!["contain","cover"].includes(u.fit))throw Error("Course style fit must be contain / cover");u.fit==="cover"?d.fit="cover":delete d.fit}h.push(`course style ${V}`);break}case"luxuryCard":{const d=b(u.clipId);if(!d||!["image","video"].includes(d.kind)||d.motion||d.title||d.shape||d.card||d.geo)throw Error("luxuryCard needs a photo / video clip");const w=o.find(X=>X.id===d.nodeId),T=Number.isInteger(w?.width)&&w.width>1?w.width:1e3,j=Number.isInteger(w?.height)&&w.height>1?w.height:1e3;if(u.color!=null&&!/^#[0-9a-f]{6}$/i.test(u.color))throw Error("luxuryCard color must be #RRGGBB");const O=Math.max(0,Math.min(.3,it(u.numberValue)??.04)),L=Ma(T,j,d.crop),B=(u.color??"#ffd56a").toLowerCase();if(d.mask=gr({mw:T,mh:j},[Yn({kind:"rect",cx:.5,cy:.5,w:1,h:1,rot:0,round:O},L.w,L.h)]),u.booleanValue===!0)d.edge={color:B,width:.01,glow:1.2,cover:.45,sweep:120,comet:!0};else{const X=[];for(let Q=0;Q<=d.duration+1e-6&&X.length<30;Q+=.6)X.push({time:+Q.toFixed(3),value:X.length%2?1:.45,ease:Jt["ease-in-out"]});d.edge={color:B,width:.01,glow:1.2,...X.length>1?{keys:X}:{}}}d.shadow={...vn,opacity:.5,blur:22,distance:10},h.push(`gold card ${d.label||d.id}${u.booleanValue===!0?" (running light)":""}`);break}case"floatCard":{const d=[...new Set([...Array.isArray(u.clipIds)?u.clipIds:[],...u.clipId?[u.clipId]:[]])];if(!d.length||d.length>6)throw Error("floatCard needs 1–6 picture / video clips (clipId or clipIds)");if(u.color!=null&&!/^#[0-9a-f]{6}$/i.test(u.color))throw Error("floatCard color must be #RRGGBB");const w=(u.color??"#ffffff").toLowerCase(),T=Math.max(0,Math.min(20,it(u.numberValue)??6)),j=u.booleanValue!==!1,O=d.length;d.forEach((L,B)=>{const X=b(L);if(!X||!["image","video"].includes(X.kind)||X.motion||X.title||X.shape||X.card||X.geo)throw Error(`floatCard needs photo / video clips (${L})`);if(r[X.track]?.locked)throw Error("Track đã khóa");const Q=o.find($t=>$t.id===X.nodeId),et=Number.isInteger(Q?.width)&&Q.width>1?Q.width:1e3,lt=Number.isInteger(Q?.height)&&Q.height>1?Q.height:1e3;X.mask=gr({mw:et,mh:lt},[Yn({kind:"rect",cx:.5,cy:.5,w:1,h:1,rot:0,round:.06},Ma(et,lt,X.crop).w,Ma(et,lt,X.crop).h)]),X.edge={color:w,width:.009,glow:1.3,amount:.9},X.shadow={...vn,opacity:.6,blur:26,distance:16};const Y=O>1?+((B-(O-1)/2)*Math.min(.3,.9/O)).toFixed(4):Ut(X,"x",0),dt=O>1?B%2?.035:-.035:Ut(X,"y",0),bt=O>1?+Math.min(.62,1.5/O).toFixed(3):Math.abs(Ut(X,"zoom",0)-1)<1e-6?.62:Ut(X,"zoom",0),tt=(B%2?-1:1)*T,nt=X.duration,mt=$t=>+Math.min(nt,$t).toFixed(3),It="ease-in-out",Nt=($t,zt)=>{Object.assign(X,li(X,$t,zt.filter((Dt,ae,we)=>!ae||Dt.time-we[ae-1].time>=1/30)))};if(Nt("zoom",[{time:0,value:+(bt*.82).toFixed(4),ease:"back-out"},{time:mt(.38),value:bt}]),Nt("opacity",[{time:0,value:0},{time:mt(.22),value:1}]),Nt("x",[{time:0,value:Y}]),j&&nt>1){const $t=[],zt=[];for(let Dt=0,ae=0;Dt<=nt+1e-6&&$t.length<30;Dt+=1.4,ae++)$t.push({time:mt(Dt),value:+(dt+(ae%2?.012:-.012)).toFixed(4),ease:It}),zt.push({time:mt(Dt),value:+(tt+(ae%2?-1:1)*Math.max(.6,T*.3)).toFixed(3),ease:It});Nt("y",$t),Nt("rot",zt)}else Nt("y",[{time:0,value:dt}]),Nt("rot",[{time:0,value:tt}])}),h.push(`floatCard: ${O} floating card${O>1?"s":""} (tilt ${T}°${j?", drifting":""})`);break}case"breakdownShowcase":{if(u.color!=null&&!/^#[0-9a-f]{6}$/i.test(u.color))throw Error("breakdownShowcase color must be #RRGGBB");if(u.style!=null&&!N0.includes(u.style))throw Error(`breakdownShowcase style: ${N0.join(" | ")}`);if(u.layout!=null&&u.layout!=="auto"&&!bd.includes(u.layout))throw Error(`breakdownShowcase layout: auto | ${bd.join(" | ")}`);if(u.labels!=null&&(!Array.isArray(u.labels)||u.labels.length>za.shots||u.labels.some(T=>typeof T!="string")))throw Error(`breakdownShowcase labels: up to ${za.shots} strings`);const d=[...new Set([...Array.isArray(u.clipIds)?u.clipIds:[],...u.clipId?[u.clipId]:[]])];for(const T of d)if(!b(T))throw Error(`Không thấy clip ${T}`);const w=qI(s,r,d,{style:u.style,color:u.color,layout:u.layout,lang:u.lang??(a.locale==="vi"?"vi":void 0),labels:u.labels,at:it(u.at)??void 0,newId:Rt,W:a.W||1280,H:a.H||720,materials:o});if(s.length+w.add.length>Kt)throw Error(`Tối đa ${Kt} clip`);s.push(...w.add),h.push(`breakdownShowcase: ${w.shots.length} shot${w.shots.length>1?"s":""}, ${w.style} · ${w.layout}, ${w.start}–${w.end}s (${w.add.length} layers)`);break}case"portfolioWall":{const d=[...new Set(Array.isArray(u.clipIds)?u.clipIds:[])];if(d.length<2||d.length>16)throw Error("portfolioWall needs 2–16 picture / video clips (clipIds)");const w=u.style??"grid";if(!["grid","arc","mosaic"].includes(w))throw Error("portfolioWall style must be grid, arc or mosaic");const T=u.shape??(w==="mosaic"?"landscape":"portrait");if(!["portrait","landscape","square"].includes(T))throw Error("portfolioWall shape must be portrait, landscape or square");if(u.color!=null&&!/^#[0-9a-f]{6}$/i.test(u.color))throw Error("portfolioWall color must be #RRGGBB");const j=it(u.numberValue);if(j!==null&&!(Number.isInteger(j)&&j>=1&&j<=4))throw Error("portfolioWall rows (numberValue) must be 1–4");let O=null;if(u.sourceClipId!=null&&(O=b(u.sourceClipId),!O||O.kind!=="video"))throw Error("portfolioWall sourceClipId must be the speaker video");const L=a.W>0?a.W:1280,B=a.H>0?a.H:720,X=d.length,Q=T==="portrait"?9/16:T==="square"?1:16/9,et=(u.color??"#ffffff").toLowerCase(),lt=u.booleanValue!==!1,Y=j??(w==="mosaic"?Math.max(2,Math.round(Math.sqrt(X*Q*B/L))):X<=5?1:X<=10?2:3),dt=Math.ceil(X/Y),bt=L*(w==="mosaic"?1.04:w==="arc"?1.02:.95),tt=B*(w==="mosaic"?1.06:w==="arc"?.88:.9),nt=bt/dt,mt=tt/Y,It=w==="mosaic"?.94:w==="arc"?.86:.9,Nt=Math.min(nt*It,mt*It*Q);if(d.forEach(($t,zt)=>{const Dt=b($t);if(!Dt||!["image","video"].includes(Dt.kind)||Dt.motion||Dt.title||Dt.shape||Dt.card||Dt.geo||Dt.vfx)throw Error(`portfolioWall needs photo / video clips (${$t})`);if(O&&Dt.id===O.id)throw Error("portfolioWall cannot use the speaker video as a card");if(r[Dt.track]?.locked)throw Error("Track đã khóa");const ae=o.find(Pt=>Pt.id===Dt.nodeId),we=Number.isInteger(ae?.width)&&ae.width>1?ae.width:1280,Oe=Number.isInteger(ae?.height)&&ae.height>1?ae.height:720,Ce=Ma(we,Oe,Dt.crop),Yt=Ce.w/Ce.h,Ft=Q<Yt?Q/Yt:1,Bt=Q<Yt?1:Yt/Q;Dt.mask=gr({mw:we,mh:Oe},[Yn({kind:"rect",cx:.5,cy:.5,w:Ft,h:Bt,rot:0,round:.08},Ce.w,Ce.h)]),Dt.edge={color:et,width:.006,glow:.8,amount:.85},Dt.shadow={...vn,opacity:.45,blur:18,distance:8},Dt.fit==="cover"&&delete Dt.fit,w==="mosaic"&&(Dt.exposure=-.75,Dt.saturation=.9);const _t=Math.floor(zt/dt),pe=_t===Y-1?X-_t*dt:dt,ee=zt-_t*dt+(dt-pe)/2,fe=Math.min(L/Ce.w,B/Ce.h)*Ce.w,Qo=+(Nt/(fe*Ft)).toFixed(4),kr=+(((ee+.5)/dt-.5)*bt/L).toFixed(4),Fr=+(((_t+.5)/Y-.5)*tt/B).toFixed(4),Co=Dt.duration,qe=Pt=>+Math.min(Co,Math.max(0,Pt)).toFixed(3),xo=qe(zt*(w==="mosaic"?.035:.07)),W=qe(xo+(w==="mosaic"?.4:.55)),ft=w==="mosaic"?1.07:1.03,yt=(Pt,Lt)=>{Object.assign(Dt,li(Dt,Pt,Lt.filter((Ot,Wt,Ht)=>!Wt||Ot.time-Ht[Wt-1].time>=1/30)))};if(w==="arc"){const Pt=L*1.25,Lt=Cr(L,B),Ot=(ee-(dt-1)/2)*nt/Pt,Wt=Math.abs(Ot)>1e-6?Math.sign(Ot):zt%2?1:-1,Ht=Ot+Wt*.95,qt=Ot+.06,re=oe=>({x:+(Pt*Math.sin(oe)/L).toFixed(4),depth:+(Pt*(1-Math.cos(oe))/Lt).toFixed(4),tiltY:+(-oe*180/Math.PI).toFixed(3)}),ie=re(Ht),Xt=re(Ot),te=re(qt);Dt.is3D=!0;for(const oe of["x","depth","tiltY"])yt(oe,[{time:0,value:ie[oe]},{time:xo,value:ie[oe],ease:"ease-out"},{time:W,value:Xt[oe],ease:"ease-in-out"},{time:qe(Co),value:te[oe]}]);yt("y",[{time:0,value:Fr}]),yt("zoom",[{time:0,value:Qo}]),yt("rot",[{time:0,value:0}]),yt("opacity",[{time:0,value:0},{time:xo,value:0},{time:qe(xo+.25),value:1},...lt&&Co>W+.5?[{time:qe(Co-.35),value:1},{time:qe(Co),value:0}]:[]]);return}const Mt=w==="mosaic"?.035:0;yt("x",[{time:0,value:kr},{time:W,value:kr,ease:"ease-in-out"},{time:qe(Co),value:+(kr*ft-Mt).toFixed(4)}]),yt("y",w==="grid"?[{time:0,value:+(Fr+.75).toFixed(4)},{time:xo,value:+(Fr+.75).toFixed(4),ease:"ease-out"},{time:W,value:Fr,ease:"ease-in-out"},{time:qe(Co),value:+(Fr*ft).toFixed(4)}]:[{time:0,value:Fr},{time:qe(Co),value:+(Fr*ft).toFixed(4)}]),yt("zoom",[{time:0,value:+(Qo*(w==="grid"?.8:1.25)).toFixed(4)},{time:xo,value:+(Qo*(w==="grid"?.8:1.25)).toFixed(4),ease:"back-out"},{time:W,value:Qo,ease:"ease-in-out"},{time:qe(Co),value:+(Qo*ft).toFixed(4)}]),yt("rot",w==="grid"?[{time:0,value:zt%2?7:-7},{time:xo,value:zt%2?7:-7,ease:"ease-out"},{time:W,value:0}]:[{time:0,value:0}]),yt("opacity",[{time:0,value:0},{time:xo,value:0},{time:qe(xo+.18),value:1},...lt&&Co>W+.5?[{time:qe(Co-.35),value:1},{time:qe(Co),value:0}]:[]])}),w==="arc"&&!p?.enabled&&(p={...p??Ar,enabled:!0,motionV:2,motionKeys:p?.motionKeys??[]}),O){const $t=d.reduce((zt,Dt)=>_n(b(Dt),b(zt))>0?Dt:zt);at.splice(D+1,0,{op:"placeBehindPerson",clipId:$t,sourceClipId:O.id})}h.push(`portfolioWall: ${X} cards, ${w} ${Y}×${dt}${w==="arc"?" (3D, timeline camera on)":""}${O?", behind the speaker":""}`);break}case"avatarBadge":{const d=b(u.clipId);if(!d||!["image","video"].includes(d.kind)||d.motion||d.title||d.shape||d.card||d.geo)throw Error("avatarBadge needs a photo / video clip");if(r[d.track]?.locked)throw Error("Track đã khóa");if(u.color!=null&&!/^#[0-9a-f]{6}$/i.test(u.color))throw Error("avatarBadge color must be #RRGGBB");const w=o.find(dt=>dt.id===d.nodeId),T=Number.isInteger(w?.width)&&w.width>1?w.width:1e3,j=Number.isInteger(w?.height)&&w.height>1?w.height:1e3,O=Ma(T,j,d.crop),L=Math.min(O.w,O.h),B=(u.color??"#ffd56a").toLowerCase();d.mask=gr({mw:T,mh:j},[Yn({kind:"circle",cx:.5,cy:.5,w:+(L/O.w).toFixed(5),h:+(L/O.h).toFixed(5),rot:0},O.w,O.h)]),d.edge=u.booleanValue===!1?{color:B,width:.03,glow:1.6}:{color:B,width:.03,glow:1.6,cover:.7,sweep:200,comet:!0},d.shadow={...vn,opacity:.5,blur:20,distance:8};const X=Math.max(.1,Math.min(1,it(u.numberValue)??.32)),Q=Math.max(-.5,Math.min(.5,it(u.posX)??0)),et=Math.max(-.5,Math.min(.5,it(u.posY)??0)),lt=d.duration,Y=(dt,bt)=>{Object.assign(d,li(d,dt,bt.filter(tt=>tt.time<=lt+1e-6)))};Y("x",[{time:0,value:Q}]),Y("y",[{time:0,value:et}]),Y("zoom",lt>.5?[{time:0,value:+(X*.3).toFixed(4),ease:"back-out"},{time:+Math.min(lt,.42).toFixed(3),value:X}]:[{time:0,value:X}]),h.push(`avatarBadge ${V}: round badge${u.booleanValue===!1?"":" with a running ring light"}`);break}case"beatRamp":{const d=[...new Set([...Array.isArray(u.clipIds)?u.clipIds:[],...u.clipId?[u.clipId]:[]])];if(!d.length||d.length>60)throw Error("beatRamp needs 1–60 video clips (clipIds)");const w=d.map(Y=>{const dt=b(Y);if(!dt)throw Error(`Clip not found: ${Y}`);if(dt.kind!=="video")throw Error(`beatRamp: ${dt.label||Y} is not a video clip`);if(r[dt.track]?.locked)throw Error("Track đã khóa");return dt}).sort((Y,dt)=>Y.start-dt.start||Y.track-dt.track),T=it(u.every)??it(u.numberValue)??1;if(!Af.includes(T))throw Error(`beatRamp every must be one of ${Af.join(", ")} beats`);const j=u.preset??"peak-burst",O=$5(s,o);if(O.length<2)throw Error("beatRamp needs the beats of a song on the timeline: add the song (add_media) and analyze_music it first (free)");const L=E5(O,w.length,w[0].start,T);if(!L.length)throw Error("No beats left after the first shot — move the shots over the song");const B=w[0].track,X=new Set(w.map(Y=>Y.id)),Q=L.at(-1).start+L.at(-1).duration,et=s.find(Y=>Y.track===B&&!X.has(Y.id)&&Y.start<Q-1e-6&&Y.start+Y.duration>L[0].start+1e-6);if(et)throw Error(`beatRamp would cover "${et.label||et.id}" on the same row (${L[0].start}–${+Q.toFixed(2)} s) — move it or pick the shots on a free row`);const lt=it(u.peak)??void 0;L.forEach((Y,dt)=>{const bt=w[dt],tt={...bt,start:Y.start,track:B},nt=mf(tt,j,Y.duration,{peak:lt}),mt=s.findIndex(It=>It.id===bt.id);s[mt]=nt}),h.push(`beatRamp ${j}: ${L.length} shot(s) on every ${T} beat(s) from ${L[0].start}s${L.length<w.length?` (${w.length-L.length} left out: the beats ran out)`:""}`);break}case"setAnchor":{const d=[...new Set([...Array.isArray(u.clipIds)?u.clipIds:[],...u.clipId?[u.clipId]:[]])];if(!d.length)throw Error("setAnchor needs clipId or clipIds");if(!Cf.includes(u.preset))throw Error(`setAnchor preset must be one of ${Cf.join(", ")}`);const w=a.W||1280,T=a.H||720,j={tl:"top-left",t:"top",tr:"top-right",l:"left",c:"center",r:"right",bl:"bottom-left",b:"bottom",br:"bottom-right"}[u.preset];for(const O of d){const L=b(O);if(!L||L.kind==="audio")throw Error("Clip not found");if(r[L.track]?.locked)throw Error("That layer is locked");const B=Math.max(0,Math.min(L.duration,(it(u.at)??L.start)-L.start)),X=o.find($t=>$t.id===L.nodeId),Q=X?.width>0&&X?.height>0?X.width/X.height:w/T,et=w/T,lt=L.fit==="cover"?1:Math.min(1,Q/et),Y=L.fit==="cover"?1:Math.min(1,et/Q),dt=Ut(L,"zoom",B),bt=.5+Ut(L,"x",B),tt=.5+Ut(L,"y",B),nt=lt*dt/2,mt=Y*dt/2,It=L.shape?.v===2?q0(L):[bt-nt,tt-mt,bt+nt,tt+mt];nr(s);const Nt=s.indexOf(L);s[Nt]=wa(s,L,{anchor:j,at:B,W:w,H:T,box:It})}h.push(`setAnchor ${u.preset} (${u1[u.preset].join(", ")}): ${d.length} layer(s)`);break}case"zoomMove":{const d=[...new Set([...Array.isArray(u.clipIds)?u.clipIds:[],...u.clipId?[u.clipId]:[]])];if(!d.length)throw Error("zoomMove needs clipId or clipIds");if(!pc.includes(u.preset))throw Error(`zoomMove preset must be one of ${pc.join(", ")}`);for(const w of d){const T=b(w);if(!T||T.kind==="audio")throw Error("Clip not found");if(r[T.track]?.locked)throw Error("That layer is locked");const j=u.preset.endsWith("start"),O=Ut(T,"zoom",j?T.duration:0),L=I5(u.preset,T.duration,O,it(u.numberValue)??void 0,it(u.duration)??void 0),B=L[0].time,X=L.at(-1).time,Q=Me(T,"zoom").filter(Y=>Y.time<B-1e-6||Y.time>X+1e-6).map(Y=>({time:Y.time,value:Y.value})),et=li(T,"zoom",[...Q,...L].sort((Y,dt)=>Y.time-dt.time)),lt=s.indexOf(T);s[lt]=et}h.push(`zoomMove ${u.preset}: ${d.length} clip(s)`);break}case"stabilize":{const d=b(u.clipId);if(!d)throw Error("Clip not found");if(u.booleanValue===!1){if(!d.stabilized)throw Error("That clip is not stabilized");const{url:L,gcsUri:B,inPoint:X,sourceDuration:Q}=d.stabilized,et=s.indexOf(d),lt={...d,url:L,inPoint:X,sourceDuration:Q};delete lt.stabilized,B?lt.gcsUri=B:delete lt.gcsUri,s[et]=lt,h.push(`stabilize off: ${V}`);break}const w=Array.isArray(u.processed)?u.processed.find(L=>L.clipId===d.id):null;if(!w)throw Error("stabilize runs through Clipoox (the server stabilises the clip first): the editor's Speed Kit or MCP edit_timeline");if(w.dry){h.push(`stabilize ${V} (dry run)`);break}const T=it(w.duration);if(typeof w.url!="string"||!T||T<=0)throw Error("stabilize: the stabilised video is missing");const j=d.stabilized??{url:d.url,...d.gcsUri?{gcsUri:d.gcsUri}:{},inPoint:d.inPoint??0,sourceDuration:d.sourceDuration},O=s.indexOf(d);s[O]={...d,url:w.url,...typeof w.gcsUri=="string"?{gcsUri:w.gcsUri}:{},inPoint:0,sourceDuration:+T.toFixed(3),stabilized:{...j,amount:w.amount}},h.push(`stabilize ${V} (${Math.round((w.amount??.5)*100)}%)`);break}case"logoLight":{const d=b(u.clipId);if(!d||!["image","video"].includes(d.kind)||d.motion||d.title||d.shape||d.card||d.geo)throw Error("logoLight needs the logo picture clip");const w=Math.max(0,Math.min(d.duration-.2,it(u.at)??0)),T=Math.max(.4,Math.min(4,it(u.duration)??1.2,d.duration-w)),j=(L,B,X)=>[{time:+w.toFixed(3),value:0,ease:Jt["ease-out"]},{time:+(w+T*L).toFixed(3),value:B,ease:Jt["ease-in-out"]},{time:+(w+T).toFixed(3),value:X}],O=[...(d.effects||[]).filter(L=>L.type!=="glow"&&L.type!=="exposure"),{type:"glow",amount:.35,keys:j(.45,.9,.35)},{type:"exposure",amount:0,keys:j(.4,.55,0)}];if(O.length>kn)throw Error(`At most ${kn} effects per clip`);d.effects=O,d.enter={type:"zoom-out",duration:+Math.min(T,.9).toFixed(3),amount:.12,fade:!0},h.push(`logo light ${d.label||d.id} @ ${w}s`);break}case"addSfx":{if(s.length>=Kt)throw Error(`Tối đa ${Kt} clip`);const d=Ba(u.sfxId)??P3(u);if(!d)throw Error(`Unknown sound effect "${u.sfxId}"`);const w=it(u.at);if(w===null||w<0||w+d.duration>We)throw Error("addSfx needs at (timeline seconds) inside the timeline");const T=it(u.volume);if(T!==null&&(T<0||T>1))throw Error("SFX volume must be 0..1");const j=(d.music?L3:zs)(s,r,d,w,{volume:T??void 0,track:it(u.track),id:Rt()});d.gcsUri&&(j.gcsUri=d.gcsUri),s.push(j),h.push(`sfx ${d.name} → ${j.start}s`);break}case"reframe":{if(!["16:9","9:16","1:1","4:5"].includes(u.aspectRatio))throw Error("Reframe needs aspectRatio");const d=V4(s,o,u.aspectRatio,{clipId:u.clipId},r);if(!d.reframed)throw Error(d.skipped.join("; ")||"Nothing to reframe");s=d.clips,N=u.aspectRatio,h.push(`reframe ${u.aspectRatio}: ${d.reframed} clip${d.skipped.length?` (skipped: ${d.skipped.join("; ")})`:""}`);break}case"rippleDelete":s=gf(s,u.clipId,null,r),h.push(`ripple delete: ${V}`);break;case"setTransition":{if(u.nearestCut===!0&&u.transitionId&&Number.isFinite(u.at)){const d=b(u.clipId);if(!d)throw Error("Clip not found");const T=s.filter(j=>j.nodeId===d.nodeId&&j.track===d.track&&j.kind===d.kind&&!j.mask&&s.some(O=>O.id!==j.id&&O.track===j.track&&O.kind!=="audio"&&Math.abs(O.start-(j.start+j.duration))<1/60)).sort((j,O)=>Math.abs(j.start+j.duration-u.at)-Math.abs(O.start+O.duration-u.at))[0];if(!T||Math.abs(T.start+T.duration-u.at)>1.5)throw Error("No cut near that time");u={...u,clipId:T.id}}try{if(u.transitionId){if(!u.spec||u.spec.id!==u.transitionId)throw Error(`Unknown transition "${u.transitionId}"`);const d=b(u.clipId),w=d&&s.find(T=>T.id!==d.id&&T.track===d.track&&T.kind!=="audio"&&Math.abs(T.start-(d.start+d.duration))<1/60);s=yh(s,u.clipId,u.spec.id==="match-walk"?Y0(u.spec,d,w,o):u.spec,it(u.duration)??void 0),h.push(`transition ${u.spec.name}: ${V}`);break}b(u.clipId)?.transition&&(s=Oh(s,u.clipId)),b(u.clipId)?.join&&(s=s.map(d=>{if(d.id!==u.clipId)return d;const{join:w,...T}=d;return T})),s=Y3(s,u.clipId,u.preset,u.duration??0,r),h.push(`transition: ${V}`);break}catch(d){const w=AA(s,u,c,r);if(!w)throw d;s=w.clips,h.push(`transition → ${w.note}: ${V}`);break}}case"addSubtitles":{const d=b(u.clipId),w=d&&o.find(O=>O.id===d.nodeId);if(!d||!w?.transcript?.length)throw Error("Analyze speech first");const T=Jl(d,zh(w.transcript)),j=Ph(T,d.duration);d.captionWords?.length&&(d.captionWords=Ys(B2(d.captions,j,d.captionWords,d.duration),d.duration)),d.captions=j,h.push(`subtitles: ${V}`);break}case"addSocialCaptions":{const d=b(u.clipId),w=d&&o.find(L=>L.id===d.nodeId);if(!d||!["video","audio"].includes(d.kind))throw Error("Social captions need a video or audio clip");const T=u.captionStyle??"social";if(!["social","karaoke","classic","lesson"].includes(T))throw Error("Invalid caption preset");if(u.captionPosition!=null&&!["top","center","bottom"].includes(u.captionPosition))throw Error("Invalid caption position");if(u.emphasis!=null&&typeof u.emphasis!="boolean")throw Error("Invalid emphasis flag");if(u.perGroup!=null&&![1,2,3].includes(u.perGroup))throw Error("Words per group must be 1–3");if(u.look!=null&&!Yg(u.look))throw Error(`Unknown caption look; use one of ${Ug.map(L=>L.id).join(", ")}`);if(!d.captions?.length){if(!w?.transcript?.length)throw Error("Analyze speech first");d.captions=Ph(Jl(d,zh(w.transcript)),d.duration)}const j={...u.cueWords!=null?{cueWords:u.cueWords}:{},...u.lineWords!=null?{lineWords:u.lineWords}:{}};if(T==="classic"){d.captionStyle=si({...u.look?yf({style:"classic"},u.look):{style:"classic"},...j}),h.push(`captions classic: ${V}`);break}if(d.captionWords=Ys((w?.words?.length?vd(d,Ys(w.words,1/0,gh)):Xc(d.captions)).slice(0,R2),d.duration),!d.captionWords.length)throw Error("No words to caption");if(d.captionStyle=si({...D2,...T==="lesson"?Lv:{style:T},...u.captionPosition?{position:u.captionPosition}:{},...u.emphasis!=null?{emphasis:u.emphasis}:{},...u.perGroup!=null?{perGroup:u.perGroup}:{},...typeof u.color=="string"&&/^#[0-9a-fA-F]{6}$/.test(u.color)?{emphasisColor:u.color,emphasisColor2:u.color}:{}}),u.look&&(d.captionStyle=yf(d.captionStyle,u.look)),Object.keys(j).length&&(d.captionStyle=si({...d.captionStyle,...j})),u.highlight!=null){if(!Zg(u.highlight))throw Error(`Unknown highlight look; use one of ${qg.map(X=>X.id).join(", ")}`);const L=t4(u.highlight,d.captionStyle),B={...d.captionStyle,...L};for(const X of Object.keys(B))B[X]===void 0&&delete B[X];d.captionStyle=si(B)}const O={...u.emphasisScale!=null?{emphasisScale:u.emphasisScale}:{},...u.anim!=null?{anim:u.anim}:{},...u.rowWords!=null?{rowWords:u.rowWords}:{},...u.lineGap!=null?{lineGap:u.lineGap}:{},...u.rowShift!=null?{rowShift:u.rowShift}:{}};Object.keys(O).length&&(d.captionStyle=si({...d.captionStyle,...O})),h.push(`${T} captions: ${V}`);break}case"editCaptions":{h.push(...g5(s,u));break}case"rippleTrim":{const d=b(u.clipId);if(!d)throw Error("Clip not found");const w=yi([d],[{...u,op:"trim"}],o,r);if(w.errors.length)throw Error(w.errors.join("; "));s=gf(s,d.id,w.clips[0],r),h.push(`ripple trim: ${V}`);break}case"speedRampTransition":{const d=(et,lt)=>et&<&&et.id!==lt.id&&et.track===lt.track&&et.kind!=="audio"&<.kind!=="audio"&&Math.abs(lt.start-(et.start+et.duration))<.016666666666666666;let w=u.clipId!=null?b(u.clipId):null,T=w?s.find(et=>d(et,w)):null;if(w&&!T){const et=s.find(lt=>d(w,lt));et&&(T=w,w=et)}if(!w&&Number.isFinite(u.at)){const lt=s.flatMap(Y=>s.filter(dt=>d(Y,dt)&&(Y.kind==="video"||Y.kind==="image")&&(dt.kind==="video"||dt.kind==="image")).map(dt=>[Y,dt])).sort((Y,dt)=>Math.abs(Y[1].start-u.at)-Math.abs(dt[1].start-u.at)||Y[0].track-dt[0].track)[0];lt&&Math.abs(lt[1].start-u.at)<=.25&&([T,w]=lt)}if(!T||!w)throw Error(u.clipId!=null?"speedRampTransition: no cut there — clipId is the clip right AFTER a cut (touching the one before it on its row)":"speedRampTransition needs clipId (the clip after the cut) or at (a cut within 0.25 s)");if(r[T.track]?.locked)throw Error("Track đã khóa");if(u.remove===!0||u.preset==="none"||u.booleanValue===!1){if(!T.transition?.ramp)throw Error("No speed ramp transition on that cut");s=Oh(s,T.id),h.push(`speed ramp off: ${T.label||T.id} → ${w.label||w.id}`);break}const j=u.rampFx&&typeof u.rampFx=="object"?u.rampFx:{},O=et=>u[et]!==void 0&&u[et]!==null&&!(et==="align"&&!["center","end","start"].includes(u[et]))?u[et]:j[et]??void 0,L=Object.fromEntries(["preset","duration","align","peak","zoomCenter","curve",...z2].map(et=>[et,et==="curve"&&u.curve===null?null:O(et)]).filter(([,et])=>et!==void 0)),B=L2(T,w,L,T.transition?.ramp?T.transition:null);s=s.map(et=>et.id===T.id?{...et,transition:B,join:void 0,visualFadeOut:void 0,fadeOutColor:void 0}:et.id===w.id?{...et,visualFadeIn:void 0,fadeInColor:void 0}:et),N2(s.find(et=>et.id===T.id),s);const X=F2(s).plans.get(T.id),Q=[["A",X?.peakA],["B",X?.peakB]].filter(([,et])=>et!=null&&et<B.ramp.peak-.01);h.push(`speed ramp ${B.name} ${B.duration}s peak ${B.ramp.peak}×${B.align?` align ${B.align}`:""}: ${T.label||T.id} → ${w.label||w.id}${Q.length?` (not enough spare footage: peak ${Q.map(([et,lt])=>`${et} ${lt}×`).join(", ")})`:""}`);break}case"speedRamp":{const d=b(u.clipId);if(!d)throw Error("Clip not found");const w=Array.isArray(u.keys)&&u.keys.length?u.keys:null;if(!w&&u.preset==null)throw Error("speedRamp needs a preset or keys");const T=!w&&it(u.at)!==null?it(u.at)-d.start:void 0;if(T!==void 0&&!(T>0&&T<d.duration))throw Error("speedRamp at must be a timeline time inside the clip");const j=it(u.peak)??void 0,L=(u.fit===!0||u.booleanValue===!0)&&!w&&u.preset!=null&&u.preset!=="normal"?mf(d,u.preset,d.duration,{peak:j}):X3(d,{preset:u.preset??void 0,keys:w,hitAt:T,peak:j});s=s.map(B=>B.id===d.id?L:B),h.push(`speed ramp ${w?"keys":u.preset}${T!==void 0?" (hit placed)":""}: ${V}`);break}case"setTimeRemap":{const d=b(u.clipId);if(!d)throw Error("Clip not found");let w;if(u.booleanValue===!1)w=dp(d,{off:!0});else{const T=Array.isArray(u.keys)&&u.keys.length?u.keys:void 0,j=it(u.duration);w=dp(d,{preset:u.preset??void 0,keys:T,blend:u.blend??void 0,duration:j??void 0});const O=it(u.freezeAt);if(O!==null){const L=P2(w,O,it(u.hold)??1);w=dp(w,{keys:L.keys,duration:L.duration})}}s=s.map(T=>T.id===d.id?w:T),h.push(`time remap ${u.booleanValue===!1?"off":u.preset??(u.keys?"keys":u.freezeAt!=null?"freeze":u.blend?`blend ${u.blend}`:"on")}: ${V}`);break}case"setClipProperty":case"setSpeed":case"setCrop":case"setKeyframes":{const d=b(u.clipId);if(!d)throw Error("Clip not found");const w=b5(d,u);s=s.map(T=>T.id===d.id?w:T),h.push(`${u.op}: ${V}`);break}case"colorGrade":{const d=Array.isArray(u.clipIds)?u.clipIds:u.clipId!=null?[u.clipId]:[];if(!d.length||d.length>40)throw Error("needs clipId or clipIds (1–40)");const w=lt=>Array.isArray(lt)?lt.map(Y=>Array.isArray(Y)?{x:Y[0],y:Y[1]}:Y):lt,T=lt=>lt&&typeof lt=="object"?{x:it(lt.x)??0,y:it(lt.y)??0,l:it(lt.l)??0}:null,j=u.nodes??u.windows,O=Array.isArray(j)?{mode:"add",custom:j}:j,L={...Object.fromEntries([...Xl,"temperature","tint","shadows","highlights","sharpness"].map(lt=>[lt,it(u[lt])])),recipe:typeof u.recipe=="string"?u.recipe:null,wheels:u.wheels&&typeof u.wheels=="object"?Object.fromEntries(["lift","gamma","gain","offset"].map(lt=>[lt,T(u.wheels[lt])])):null,curves:u.curves&&typeof u.curves=="object"?Object.fromEntries(["master","r","g","b"].map(lt=>[lt,u.curves[lt]?w(u.curves[lt]):null])):null,mixer:u.mixer&&typeof u.mixer=="object"?u.mixer:null,lut:u.lut&&typeof u.lut=="object"&&!Array.isArray(u.lut)?u.lut:null,windows:O&&typeof O=="object"?{mode:O.mode==="replace"?"replace":"add",presets:Array.isArray(O.presets)?O.presets.slice(0,4):[],custom:Array.isArray(O.custom)?O.custom.slice(0,16):[]}:null};if(L.recipe&&!V0.has(L.recipe))throw Error(`recipe: ${[...V0].join(" | ")}`);const B=[],X=new Set,Q=new Set;let et=null;if(u.copyFrom!=null&&(et=b(xt(u.copyFrom)),!et))throw Error(`copyFrom clip not found: ${String(u.copyFrom).slice(0,60)}`);for(const lt of d){const Y=b(xt(lt));if(!Y)throw Error(`Clip not found: ${String(lt).slice(0,60)}`);const dt=Th(Y);if(!dt&&!(Y.kind==="video"||Y.kind==="image")||Y.title||Y.shape||Y.motion||Y.card)throw Error(`${Y.label||Y.id} is not footage (a video / image clip or an adjustment layer)`);if(dt&&L.windows)throw Error("an adjustment layer takes no power windows — put the windows on the clip");let bt=u.reset||et?Object.fromEntries(Object.entries(Y).filter(([zt])=>zt!=="grade"&&!Xl.includes(zt))):Y;if(et&&et.id!==Y.id){if(dt!==Th(et))throw Error("copyFrom: copy between two footage clips or two adjustment layers");if(bt={...bt,...Object.fromEntries(Xl.filter(zt=>et[zt]!=null).map(zt=>[zt,et[zt]])),...et.grade?{grade:JSON.parse(JSON.stringify(et.grade))}:{}},dt&&bt.grade?.secondaries)throw Error("an adjustment layer takes no power windows")}const tt=[],nt=h8({...bt,hasFace:!!Y.face,hasPerson:!!Y.colorPerson,hasDepth:!!Y.depthMap},L,{notes:tt,queue:Y.kind==="video"&&!dt});for(const zt of tt)zt.startsWith("skipped:")&&X.add(zt.slice(8));const mt=tt.filter(zt=>zt.startsWith("pending:")).map(zt=>zt.slice(8)),It=s.findIndex(zt=>zt.id===Y.id),Nt={...bt,...nt};nt.grade||delete Nt.grade,(L.windows?.presets?.includes("depth-ai")||L.windows?.custom?.some(zt=>zt?.shape==="depth"))&&!Y.depthMap&&(Y.kind==="video"||Y.kind==="image")&&Object.assign(Nt,Re(Nt,{kind:"depth-map",op:"colorGrade",params:{upgrade:"depth-ai"}}));let $t=Nt;for(const zt of mt)$t=Re($t,{kind:zt==="face"?"color-face":"color-person",op:"colorGrade"}),Q.add(zt);s[It]=$t,B.push(Y.label||Y.id)}h.push(`colorGrade: ${B.join(", ").slice(0,160)}${X.size?` — skipped (needs the clip's face track / person matte, made in the open editor): ${[...X].join(", ")}`:""}${Q.size?` — pending: the ${[...Q].map(lt=>lt==="face"?"face track":"person matte").join(" and ")} is made when the timeline is open in the editor (free); those nodes start working then (get_pending_jobs)`:""}`);break}case"setTrackProperty":{if(!Number.isInteger(u.track))throw Error("Missing track ID");const d=["gain","pan"].includes(u.property)?u.numberValue:u.booleanValue,w={...r,[u.track]:{...r[u.track],[u.property]:d}};O2(w),r=w,h.push(`track ${u.track}: ${u.property}`);break}case"updateText":{const d=b(u.clipId);if(!d?.title)throw Error("Clip is not an editable title");if(typeof u.templateId=="string"&&u.design==null)throw Error(`Unknown text template "${u.templateId.slice(0,64)}"`);const w=u.design!=null?{design:u.design,animation:u.animation??void 0,templateId:u.templateId,styleId:"classic"}:{},T=Nl({...d.title,...w,...Object.fromEntries(["text","fontSize","color","placement","fontFamily","align","accentColor"].filter(B=>u[B]!=null).map(B=>[B,u[B]]))}),j=it(u.posX),O=it(u.posY),L=j!==null||O!==null?{...Zr(d),...j!==null?{posX:Math.max(-1,Math.min(1,j))}:{},...O!==null?{posY:Math.max(-1,Math.min(1,O))}:{}}:{};L.motionV===2&&L.posX===void 0&&d.posX===void 0&&(L.posX=0),L.motionV===2&&L.posY===void 0&&d.posY===void 0&&(L.posY=0),Object.assign(d,{title:T,url:"",gcsUri:void 0,label:T.text.slice(0,40),...L}),h.push(`text: ${V}${O!==null&&Math.abs(d.posY)>.45?" (posY past ±0.45: the text may leave the frame)":""}`);break}case"addTextAnimator":case"removeTextAnimator":{const d=Qt(u),w=b(d.clipId);if(!w?.title)throw Error(`${u.op} needs a text layer (clipId)`);const T=[...w.title.animators||[]],j=it(d.index)??it(d.numberValue),O=()=>{if(j===null||!Number.isInteger(j)||j<0||j>=T.length)throw Error(T.length?`index: 0–${T.length-1}`:"the text has no animators");return j};if(u.op==="removeTextAnimator")d.all===!0?T.length=0:T.splice(O(),1);else{const B=typeof d.preset=="string"&&d.preset?Lk(d.preset,w.duration):[Nk({...typeof d.name=="string"?{name:d.name}:{},properties:d.properties,selectors:d.selectors})];if(j!==null?T.splice(O(),1,...B):T.push(...B),T.length>Gh)throw Error(`at most ${Gh} animators on a text layer`)}const L=Nl({...w.title,animators:T});Object.assign(w,{title:L,url:"",gcsUri:void 0}),h.push(`text animators (${T.length}): ${V}`);break}case"duplicateClip":{const d=b(u.clipId);if(!d)throw Error("Clip not found");const w=Jy(s,[d],u.at,{tracks:r,insert:u.booleanValue===!0});if(!Number.isFinite(u.at)||u.at<0||w.error)throw Error(w.error||"Invalid paste time");s=w.clips,h.push(`duplicate: ${V}`);break}case"move":{const d=b(u.clipId);if(!d)throw Error(`Không thấy clip ${u.clipId}`);const w=it(u.start);w!==null&&(d.start=ht(Math.max(0,Math.min(We-d.duration,w))));const T=it(u.track);if(T!==null){if(!jh(d.kind,T))throw Error("Track không hợp lệ cho loại clip này");d.track=T}h.push(`move ${V} → ${d.start}s${u.track!==void 0?` (track ${Ci.includes(d.track)?"A"+(Ci.indexOf(d.track)+1):"V"+(ci(d.track)+1)})`:""}`);break}case"trim":{const d=b(u.clipId);if(!d)throw Error(`Không thấy clip ${u.clipId}`);Object.assign(d,C2(d));const w={...d};if(zn(d)){const et=it(u.inPoint),lt=it(u.duration);if(et!==null){const Y=ht(Math.max(0,Math.min(d.duration-1/be,et)));Object.assign(d,j2(d,Y)),d.start=ht(d.start+Y),d.duration=ht(d.duration-Y)}lt!==null&&(d.duration=ht(Math.max(1/be,Math.min(We-d.start,lt)))),Object.assign(d,Ol(w,et!==null?ht(Math.max(0,Math.min(w.duration-1/be,et))):0,d.duration)),h.push(`trim ${V} → ${d.duration}s (time remap)`);break}if(Hr(d)&&!d.reverse){const et=d.kind!=="image"?o.find(nt=>nt.id===d.nodeId)?.words:null,lt=nt=>{const mt=vp(et,nt);return Math.abs(mt-nt)<=Ti.reach?mt:nt};let Y=it(u.inPoint),dt=0;if(Y!==null&&et?.length&&(Y=lt(Y)),Y!==null){const nt=Math.max(0,Math.min(U0(d)-1/be,Y));dt=ja(d,nt-(d.inPoint||0)),Object.assign(d,T2(d,dt)),d.inPoint=nt,Hr(d)||delete d.speedRamp}let bt=it(u.duration);bt!==null&&et?.length&&(bt=ja(d,lt((d.inPoint||0)+Di(d,bt))-(d.inPoint||0)));const tt=ja(d,U0(d)-(d.inPoint||0));d.duration=ht(Math.max(1/be,Math.min(tt,bt??d.duration))),d.start+d.duration>We&&(d.duration=ht(We-d.start)),Object.assign(d,Ol(w,dt,d.duration)),h.push(`trim ${V} → ${d.duration}s (in ${+(d.inPoint||0).toFixed(3)}s)`);break}const T=d.playbackRate||1,j=d.sourceDuration??d.motion?.duration??We,O=d.kind!=="image"&&!d.reverse?o.find(et=>et.id===d.nodeId)?.words:null,L=et=>{const lt=vp(O,et);return Math.abs(lt-et)<=Ti.reach?lt:et};let B=it(u.inPoint);B!==null&&O?.length&&(B=L(B)),B!==null&&(d.inPoint=ht(Math.max(0,Math.min(j-1/be,B))));let X=it(u.duration);X!==null&&O?.length&&(X=(L((d.inPoint||0)+X*T)-(d.inPoint||0))/T),X!==null?d.duration=ht(Math.max(1/be,Math.min((j-(d.inPoint||0))/T,X))):d.duration=ht(Math.max(1/be,Math.min((j-(d.inPoint||0))/T,d.duration))),d.start+d.duration>We&&(d.duration=ht(We-d.start));const Q=w.reverse?w.duration-d.duration-((d.inPoint||0)-(w.inPoint||0))/T:((d.inPoint||0)-(w.inPoint||0))/T;Object.assign(d,Ol(w,Q,d.duration)),h.push(`trim ${V} → ${d.duration}s (in ${d.inPoint||0}s)`);break}case"split":{const d=b(u.clipId);if(!d)throw Error(`Không thấy clip ${u.clipId}`);if(s.length>=Kt)throw Error(`Tối đa ${Kt} clip`);let w=it(u.at);if(w===null)throw Error("Thiếu thời điểm cắt");const T=d.kind!=="image"&&!d.reverse?o.find(O=>O.id===d.nodeId)?.words:null;if(T?.length){const O=(d.inPoint||0)+Di(d,w-d.start),L=vp(T,O),B=d.start+ja(d,L-(d.inPoint||0));Math.abs(L-O)<=Ti.reach&&B>d.start+1/be&&B<d.start+d.duration-1/be&&(w=B)}const j=Ne(d,w,Rt());if(j.length===1)throw Error("Điểm cắt phải nằm trong clip");s=s.flatMap(O=>O.id===d.id?j:[O]),h.push(`split ${V} tại ${ht(w)}s`);break}case"delete":{if(!b(u.clipId))throw Error(`Không thấy clip ${u.clipId}`);s=s.filter(d=>d.id!==u.clipId),h.push(`delete ${V}`);break}case"setVolume":{const d=b(u.clipId);if(!d)throw Error(`Không thấy clip ${u.clipId}`);const w=it(u.volume);if(w===null)throw Error("Thiếu volume");d.volume=Math.max(0,Math.min(1,w)),h.push(`volume ${V} → ${Math.round(d.volume*100)}%`);break}case"addClip":{if(s.length>=Kt)throw Error(`Tối đa ${Kt} clip`);const d=o.find(B=>B.id===u.materialId);if(!d||!d.url)throw Error(`Không thấy material ${u.materialId}`);if(d.kind==="lottie"){const B=S2(d.lottie),X=it(u.start)??0,Q=ht(Math.max(1/be,it(u.duration)??Math.min(120,I2(B))));if(X<0||X+Q>We)throw Error("Vượt giới hạn 20 phút");const{track:et}=Zt(s,r,ht(X),ht(X)+Q,it(u.track)),lt=Rt();U.push(lt),s.push({id:lt,nodeId:d.id,track:et,start:ht(X),duration:Q,inPoint:0,volume:0,url:d.url,...d.gcsUri?{gcsUri:d.gcsUri}:{},kind:"image",label:d.label||"Lottie",lottie:{w:B.w,h:B.h,fr:B.fr,ip:B.ip,op:B.op,loop:!0},motionKeys:[]}),h.push(`add Lottie ${d.label||""} → ${ht(X)}s`);break}const w=it(u.track)??(d.kind==="audio"?A2:0);if(!jh(d.kind,w))throw Error("Track không hợp lệ cho loại material này");const T=d.kind==="image"?null:it(d.duration);let j=it(u.duration)??(d.kind==="image"?vA:T);if(j===null)throw Error("Material chưa có thời lượng — hãy nêu duration cụ thể");T!==null&&(j=Math.min(j,T)),j=ht(Math.max(1/be,j));const O=it(u.start)??s.filter(B=>B.track===w).reduce((B,X)=>Math.max(B,X.start+X.duration),0);if(O<0||O+j>We)throw Error("Vượt giới hạn 20 phút");if(r[w]?.locked)throw Error("Track đã khóa");const L=Rt();U.push(L),s.push({id:L,nodeId:d.id,track:w,start:ht(O),duration:j,inPoint:0,volume:1,url:d.url,...d.gcsUri?{gcsUri:d.gcsUri}:{},kind:d.kind,label:d.label||d.kind,...T!==null?{sourceDuration:T}:{}}),h.push(`add ${d.label||d.kind} → ${ht(O)}s`);break}case"addVfxPreset":{if(u._error)throw Error(u._error);const d=u._footage;if(!d)throw Error("addVfxPreset needs presetId (search_vfx_presets)");if(s.length>=Kt)throw Error(`Tối đa ${Kt} clip`);const w=ht(Math.max(0,it(u.start)??0)),T=ht(Number(d.duration));if(w+T>We)throw Error("Vượt giới hạn 20 phút");const j=Array.isArray(u.point)&&u.point.length===2&&u.point.every(B=>Number.isFinite(B))?u.point.map(B=>Math.max(0,Math.min(1,B))):null,{track:O}=Zt(s,r,w,w+T,it(u.track)),L=Rt();U.push(L),s.push({...Mf({id:L,track:O,start:w,duration:T,footage:d,frame:{W:l.W||1280,H:l.H||720},at:j,scale:it(u.scale)??1}),vfxPreset:{...u._preset}}),h.push(`addVfxPreset: ${String(d.name).slice(0,40)}${u._preset?.rendered?"":" (preview — render it with Cycles: clipoox render --vfx)"} → ${w}s`);break}case"addVfxFootage":{const d=u.footage;if(!d||typeof d!="object"||typeof d.url!="string"||!(Number(d.duration)>0))throw Error("addVfxFootage needs a footage clip from the library (footageId — search_vfx_footage)");if(s.length>=Kt)throw Error(`Tối đa ${Kt} clip`);const w=ht(Math.max(0,it(u.start)??0)),T=ht(Math.max(1/be,Math.min(it(u.duration)??Number(d.duration),Number(d.duration))));if(w+T>We)throw Error("Vượt giới hạn 20 phút");const j=Array.isArray(u.point)&&u.point.length===2&&u.point.every(B=>Number.isFinite(B))?u.point.map(B=>Math.max(0,Math.min(1,B))):null,{track:O}=Zt(s,r,w,w+T,it(u.track)),L=Rt();U.push(L),s.push(Mf({id:L,track:O,start:w,duration:T,footage:d,frame:{W:l.W||1280,H:l.H||720},at:j,scale:it(u.scale)??1,sound:u.booleanValue===!0})),h.push(`addVfxFootage: ${String(d.name||"VFX").slice(0,40)} → ${w}s`);break}case"vfxFootageFollow":{const d=b(u.clipId);if(!d||!d.vfxFootage)throw Error("vfxFootageFollow needs clipId = a Footage VFX layer (addVfxFootage)");if(u.booleanValue===!1){const O=Math.max(0,Math.min(d.duration,it(u.time)??0));for(const[L,B]of Object.entries(MM(d,O)))B===void 0?delete d[L]:d[L]=B;h.push(`vfxFootageFollow ${V}: stopped`);break}const w=u.sourceClipId?b(u.sourceClipId):s.filter(O=>O.kind==="video"&&!O.vfxFootage&&!O.vfx&&O.id!==d.id&&O.start<d.start+d.duration&&O.start+O.duration>d.start&&(O.hands||O.face||O.roto||O.planar||O.objectTracks?.length)).sort((O,L)=>O.track-L.track)[0];if(!w)throw Error("vfxFootageFollow needs sourceClipId = the filmed clip with a hand / face / object / Roto / planar track");const T=typeof u.point=="string"?u.point:typeof u.handPoint=="string"?u.handPoint:"palm",j=xM(d,w,{source:u.source,hand:u.hand==="left"?"left":"right",point:T,...u.object!=null?{object:u.object}:{},scale:u.scale===!0||u.followScale===!0,offset:Array.isArray(u.offset)&&u.offset.length>=2?u.offset:null,W:a.W||1280,H:a.H||720});for(const[O,L]of Object.entries(j.patch))L===void 0?delete d[O]:d[O]=L;h.push(`vfxFootageFollow ${V}: follows the ${u.source}${u.source==="hand"?` (${u.hand==="left"?"left":"right"} ${T})`:""} of ${w.label||w.id} — ${j.keys} keys ${j.from}–${j.to}s`);break}case"addVfxLayer":{let d=b(u.clipId);if(!d||d.kind!=="video"||d.vfx)throw Error("VFX needs the filmed video clip");if(d.person){const X=d,Q=s.find(et=>et.id!==X.id&&et.kind==="video"&&!et.person&&!et.vfx&&et.url===X.url&&et.start===X.start&&et.duration===X.duration);Q&&(d=Q)}if(!Ch.includes(u.layer))throw Error(`VFX layer must be ${Ch.join(" / ")}`);const w=o.find(X=>X.id===u.materialId);if(!w||!w.url||w.kind!=="video")throw Error(`Không thấy video ${u.materialId}`);const T=it(w.duration),j=ht(Math.max(1/be,Math.min(d.duration,T??d.duration))),O=M2(s,d.id,u.layer);if(O){$2(O,w,{duration:j,blend:u.blend}),U.push(O.id),h.push(`addVfxLayer: ${u.layer} pass of ${V} replaced`);break}if(s.length>=Kt)throw Error(`Tối đa ${Kt} clip`);const L=v2(s,r,d,u.layer,d.start,d.start+j),B=Rt();U.push(B),s.push(E2({id:B,material:w,src:d,layer:u.layer,track:L,start:d.start,duration:j,blend:u.blend})),h.push(`addVfxLayer: ${u.layer} pass over ${V}`),u.layer==="behind"&&at.splice(D+1,0,{op:"placeBehindPerson",clipId:B,sourceClipId:d.id});break}case"finishVfx":{const d=k2(s,b(u.clipId));if(!d||d.kind!=="video"||d.vfx)throw Error("VFX needs the filmed video clip");const w=x2(s,d,{strength:it(u.numberValue)??1,off:u.booleanValue===!1,newId:Rt,tracks:r,maxClips:Kt});s=w.clips,U.push(...w.added),h.push(`finishVfx ${V}: ${w.notes.join(", ")}`);break}case"set3DLayer":case"setLayerOrder":case"setPropertyKeys":case"setEase":case"setAnimation":case"setReveal":case"setShapeStyle":{const d=s.findIndex(j=>j.id===u.clipId);if(d<0)throw Error("Clip not found");const w=s[d],T=[];s[d]=u.op==="set3DLayer"?m2(w,u.booleanValue!==!1,u.numberValue):u.op==="setLayerOrder"?g2(w,u.numberValue):u.op==="setPropertyKeys"?li(w,u.property,Array.isArray(u.propertyKeys)?y2(w,u.propertyKeys,T):u.propertyKeys):u.op==="setEase"?b2(w,u.property,u.ease,u.times):u.op==="setReveal"?Sh(w,u.preset,{start:it(u.at),duration:it(u.duration),ease:u.ease}):u.op==="setShapeStyle"?w2(w,{color:u.color,fill:u.fill,strokeWidth:it(u.numberValue)}):nc(w,u.property,u.preset,{duration:u.duration??(u.property==="exit"?c.out:c.in),amount:u.numberValue,fade:u.booleanValue,ease:u.ease??(a.motion?c.ease:void 0)}),h.push(`${u.op}${u.property?` ${u.property}`:""}: ${V}${T.length?` (${T.join("; ")})`:""}`);break}case"addPins":{const d=EA(o,s,u.materialId);if(!d)throw Error("Pins need the A-roll material");const w=Array.isArray(d.words)?d.words.length:ks(d)||1/0,T=(Array.isArray(u.pins)?u.pins:[]).slice(0,60).map((L,B)=>({id:`ai${Date.now().toString(36)}${B}`,mediaId:d.id,from:L?.fromWord,to:L?.toWord,kind:L?.kind,...L?.note?{note:String(L.note).slice(0,300)}:{},status:"idea"}));if(!T.length||T.some(L=>!Number.isInteger(L.from)||L.to>=w))throw Error("Pin words out of range");const j=F??a?.pins??[],O=j.filter(L=>!T.some(B=>B.mediaId===L.mediaId&&B.from<=L.to&&B.to>=L.from));F=HM([...O,...T]),h.push(`pins: +${T.length}`);break}case"setTrackMatte":{const d=b(u.clipId);if(!d||d.kind==="audio")throw Error("Clip not found");if(!u.sourceClipId){delete d.matte,h.push(`setTrackMatte off: ${V}`);break}const w=b(u.sourceClipId);if(!w)throw Error("Matte source not found");const T=Number.isFinite(u.numberValue)?_k(u.numberValue):d.matte?.feather,j=Gk.includes(u.matteMode)?u.matteMode:"alpha";d.matte={source:w.id,mode:j,...T?{feather:T}:{},...j==="depth"?{depth:d.matte?.depth??.5}:{}},Vh(s),h.push(`setTrackMatte: ${V}`);break}case"modelMove":{const d=s.findIndex(T=>T.id===u.clipId);if(d<0)throw Error("Clip not found");const w=s[d];if(!["model","image","video"].includes(w.kind))throw Error("3D moves need a 3D model, image or video");if(!_f.includes(u.preset))throw Error(`Unknown 3D move (${_f.join(", ")})`);s[d]=RM(w.kind==="model"||w.is3D?w:{...w,is3D:!0},u.preset,{at:it(u.at)??0,duration:it(u.duration),amount:it(u.numberValue)??1}),h.push(`modelMove ${u.preset}: ${V}`);break}case"setModelAnimation":{const d=b(u.clipId);if(!d||d.kind!=="model")throw Error("GLB animations need a 3D model clip");const w=typeof u.text=="string"?u.text.trim():"";if(!w||w==="none"){delete d.modelAnim,h.push(`model animation off: ${V}`);break}const T={clip:w,...it(u.numberValue)!==null?{speed:it(u.numberValue)}:{},...typeof u.booleanValue=="boolean"?{loop:u.booleanValue}:{},...it(u.at)!==null?{offset:Math.max(0,it(u.at))}:{}};f2(T),d.modelAnim=T,h.push(`model animation ${w}: ${V}`);break}case"modelBuild":{u=Qt(u);const d=b(u.clipId);if(!d||d.kind!=="model")throw Error("modelBuild needs a 3D model clip (a GLB layer)");if(u.booleanValue===!1||u.style==="none"){delete d.modelBuild,h.push(`model build off: ${V}`);break}const w=Math.max(0,Math.min(d.duration,(it(u.at)??d.start)-d.start));d.modelBuild=h2({style:u.style,order:u.order,at:w,duration:it(u.duration)??void 0,stagger:it(u.stagger)??void 0,dust:u.dust,dustColor:u.dustColor??u.color,seed:Number.isInteger(u.seed)?u.seed:void 0}),h.push(`model build ${d.modelBuild.style} (${d.modelBuild.order}) at ${(d.start+w).toFixed(2)} s for ${d.modelBuild.duration} s: ${V}`);break}case"modelLook":{u=Qt(u);const d=b(u.clipId);if(!d||d.kind!=="model")throw Error("modelLook needs a 3D model clip (a GLB layer)");const w=d2(d.modelLook,u);if(!w){delete d.modelLook,h.push(`model look off: ${V}`);break}d.modelLook=w,h.push(`model look ${w.preset??"custom"}${w.shadow!==void 0?` shadow ${w.shadow}`:""}: ${V}`);break}case"modelLaunch":{u=Qt(u);const d=b(u.clipId);if(!d||d.kind!=="model")throw Error("modelLaunch needs a 3D model clip (a GLB layer)");const w=p2(d,u);if(!w){delete d.modelLaunch,h.push(`model launch off: ${V}`);break}d.modelLaunch=w,h.push(`model launch ${w.land} at ${(d.start+w.at).toFixed(2)} s, lands at ${(d.start+u2(w)).toFixed(2)} s on [${w.to.map(T=>T.toFixed(2)).join(", ")}] (height ${w.height}): ${V}`);break}case"modelPlace":{u=Qt(u);const d=b(u.clipId);if(!d||d.kind!=="model")throw Error("modelPlace needs a 3D model clip (a GLB layer)");const w={x:it(u.x)??void 0,y:it(u.y)??void 0,lift:it(u.lift)??void 0,scale:it(u.scale)??void 0,yaw:it(u.yaw)??void 0,tilt:it(u.tilt)??void 0,roll:it(u.roll)??void 0};if(!Object.values(w).some(O=>O!==void 0))throw Error("modelPlace: give x, y, lift, scale, yaw, tilt or roll");const T=Math.max(0,Math.min(d.duration,(it(u.at)??d.start)-d.start)),j=_M(d,w,T,u.key===!0);Object.assign(d,j),h.push(`model placed${u.key===!0||j.motionKeys?` (key at ${(d.start+T).toFixed(2)} s)`:""}: ${V}`);break}case"trackCamera3D":{u=Qt(u);const d=b(u.clipId),w=jk(u,d);Object.assign(d,Re(d,{kind:"camera-track",op:"trackCamera3D",params:w})),h.push(`trackCamera3D ${V}: the camera is solved in the open editor${w.lens?` (lens ${w.lens} mm)`:""}`);break}case"placeOnTrack":{u=Qt(u);const d=b(u.clipId),w=Ck(u,d,b(u.sourceClipId));Object.assign(d,Re(d,{kind:"camera-place",op:"placeOnTrack",params:w})),d.kind==="model"&&!d.modelLook&&(d.modelLook={preset:"overcast"}),h.push(`placeOnTrack ${V}: placed on the 3D camera track of ${b(u.sourceClipId).label||u.sourceClipId} in the open editor${d.kind==="model"?" (modelLook overcast: shadow on the ground)":""}`);break}case"trackObject3D":{u=Qt(u);const d=b(u.clipId),w=hM(u,d);Object.assign(d,Re(d,{kind:"object-track",op:"trackObject3D",params:w})),h.push(`trackObject3D ${V}: the object is tracked in 3D in the open editor`);break}case"placeOnObject":{u=Qt(u);const d=b(u.clipId),w=fM(u,d,b(u.sourceClipId));Object.assign(d,Re(d,{kind:"object-place",op:"placeOnObject",params:w})),h.push(`placeOnObject ${V}: glued to the tracked object of ${b(u.sourceClipId).label||u.sourceClipId} in the open editor`);break}case"segmentPerson":{const d=b(u.clipId);if(!d||d.kind!=="video")throw Error("segmentPerson needs a video clip");if(u.quality!==void 0&&u.quality!=="free"&&u.quality!=="hq")throw Error("segmentPerson quality: free | hq");if(u.quality==="hq"){if(typeof u.job!="string"||!/^[A-Za-z0-9-]{8,64}$/.test(u.job))throw Error("segmentPerson quality hq is paid: ask for the price first (dry_run), then confirm it (max_credits) — or use Roto → HQ cut-out");if(d.person?.hq&&!d.personPending){h.push(`segmentPerson: ${V} already has an HQ person matte`);break}A(d,null),d.personPending={behind:d.personPending.behind,job:u.job},h.push(`segmentPerson: ${V} (HQ person matte, made on the server)`);break}if(d.person&&d.person.src!=="object"){h.push(`segmentPerson: ${V} already has an AI person matte`);break}if(a.noPendingMatte)throw Error(`"${V}" has no AI person matte yet — open Roto → Tách người bằng AI on it`);A(d,null),h.push(`segmentPerson: ${V} (AI person matte computed in the editor)`);break}case"samCutout":{const d=b(u.clipId);if(!d||d.kind!=="video")throw Error("samCutout needs a video clip");if(typeof u.job!="string"||!/^[A-Za-z0-9-]{8,64}$/.test(u.job))throw Error("samCutout is paid: ask for the price first (dry_run), then confirm it (max_credits) — or use Roto → Tách AI Pro");const w=c2(u.prompts);if(d.samPending&&d.samPending.job!==u.job)throw Error(`"${V}" is already being cut out by AI Pro — wait for it (get_pending_jobs)`);d.samPending={job:u.job,prompts:w.map(T=>({id:T.id,name:Ih(T.name)}))},h.push(`samCutout: ${V} (${w.length} AI Pro cut-out${w.length>1?"s":""}, made on the server)`);break}case"placeBehindPerson":{const d=b(u.clipId);if(!d||d.kind==="audio")throw Error("Clip not found");let w=b(u.sourceClipId);if(!w||w.kind!=="video")throw Error("Person video not found");if(w.id===d.id)throw Error("A layer cannot go behind its own person");if(!w.person){const tt=w,nt=s.find(mt=>mt.id!==tt.id&&mt.kind==="video"&&mt.person&&mt.person.src!=="object"&&mt.url===tt.url);nt&&(w={...tt,person:nt.person})}if(_n(d,w)<0){h.push(`placeBehindPerson: ${V} already behind`);break}if(!w.person){if(a.noPendingMatte||!t.some(tt=>tt.id===w.id))throw Error(`"${w.label||w.id}" has no AI person matte yet — open Roto → Tách người bằng AI on it first`);A(w,d.id),U.push(`${w.id}-person-pending`),h.push(`placeBehindPerson: ${V} (waits for the AI person matte of ${w.label||w.id})`);break}const j=qs(d,w,{index:ci,at:In,isFree:tt=>!r[tt]?.locked&&!s.some(nt=>nt.track===tt&&nt.start<w.start+w.duration&&nt.start+nt.duration>w.start)});if(j===null)throw Error("No free track above the person");let O=`${w.id}-person`,L=2;for(;b(O);)O=`${w.id}-person-${L++}`;const B=Eh(s,w,{id:O,track:j,label:`${w.label||"Video"} · ${w.person.src==="object"?"vật thể":"người"}`,target:d}),X=!w.motionKeys?.length&&!w.speedRamp&&!w.timeRemap&&!w.reverse&&!(w.playbackRate&&w.playbackRate!==1);let Q=Math.max(w.start,d.start),et=Math.min(w.start+w.duration,d.start+d.duration);const lt=B.clips.find(tt=>tt.id===O),Y=w.start+w.duration,dt=Q,bt=et;for(const tt of B.clips)tt.id!==O&&tt.id!==w.id&&tt.kind!=="audio"&&!tt.person&&tt.start<bt&&tt.start+tt.duration>dt&&_n(tt,lt)<0&&_n(tt,w)>0&&(Q=Math.min(Q,Math.max(w.start,tt.start)),et=Math.max(et,Math.min(Y,tt.start+tt.duration)));if(X&&et-Q>1/30&&(Q>w.start+1e-6||et<w.start+w.duration-1e-6)){const tt=B.clips.find(nt=>nt.id===O);tt.inPoint=+((w.inPoint||0)+(Q-w.start)).toFixed(4),tt.start=+Q.toFixed(4),tt.duration=+(et-Q).toFixed(4)}Zs(B.clips),s=B.clips,U.push(O),h.push(`placeBehindPerson: ${V}`);break}case"placeBehindObject":case"cutOutObject":{const d=u.op==="placeBehindObject",w=d?b(u.clipId):null,T=u.op;if(d&&(!w||w.kind==="audio"))throw Error("Clip not found");let j=b(d?u.sourceClipId:u.clipId);if(!j||j.kind!=="video")throw Error("Object video not found");if(w&&j.id===w.id)throw Error("A layer cannot go behind its own video");const O=$A(u.points),L=Ih(u.objectName??u.name);let B=typeof u.objectId=="string"?u.objectId.trim().slice(0,120):"";if(d&&j.person?.src==="object"&&!j.person.obj&&!L&&!B){if(_n(w,j)<0){h.push(`placeBehindObject: ${V} already behind`);break}at.splice(D+1,0,{op:"placeBehindPerson",clipId:w.id,sourceClipId:j.id}),h.push(`placeBehindObject: ${V}`);break}pp(j)&&!B&&!L&&(B=up(j).id);const X=O?X0(j,it(u.at)??(w??j).start):void 0,Q=n2(s,j,{id:B||void 0,name:L||void 0,...O&&!L&&!B?{pts:O,at:X}:{}});if(B&&!Q)throw Error(`No object "${B}" on ${j.label||j.id}`);let et;if(Q?.layer){const Y=Q.layer,dt=up(Y);if(d){if(_n(w,Y)<0){h.push(`placeBehindObject: ${V} already behind "${dt.name}"`);break}z(Y,w,j),h.push(`placeBehindObject: ${V} behind "${dt.name}"`);break}if(!O||Ah(O,a2(Y).obj?.pts)){U.push(Y.id),h.push(`cutOutObject: "${dt.name}" is already its own layer`);break}et={...dt,pts:O,at:X,layer:Y.id}}else if(Q?.pending)et=Q.pending,j=Q.clip,!d&&O&&!Ah(O,et.pts)&&(et={...et,pts:O,at:X});else{if(!O){if(!d)throw Error("cutOutObject needs points [[u,v]…] (1–4 on the object)");if(!L)throw Error("placeBehindObject needs points [[u,v]…] (1–4 on the object) or objectName");if(a.noObjectLookup)throw Error(`Give the points of "${L}" ([[u,v]…] on the video picture): finding an object by name runs in the AI Editor only`);k.push({op:D,clipId:j.id,name:L,at:X0(j,it(u.at)??w.start)}),h.push(`placeBehindObject: ${V} (finds "${L}" after Accept)`);break}if(pp(j)){const Y=s.find(dt=>dt.id!==j.id&&dt.kind==="video"&&dt.url===j.url&&!dt.person&&!dt.mask);Y&&(j=Y)}et={id:l2(s,j),name:L||i2(s2(s,j)+1),pts:O,at:X}}const lt=C(j,et,w);if(lt){et.layer||U.push(lt.id),d&&_n(w,lt)>=0&&z(lt,w,j),h.push(d?`placeBehindObject: ${V} behind "${et.name}"`:et.layer?`cutOutObject: "${et.name}" re-picked`:`cutOutObject: "${et.name}" of ${j.label||j.id}`);break}if(a.noPendingMatte||!t.some(Y=>Y.id===j.id))throw Error(`"${j.label||j.id}" has no AI matte for the object "${et.name}" yet — open Roto → Tách vật thể bằng AI on it`);P(j,et,w?.id??null),U.push(`${j.id}-${et.id}-pending`),h.push(d?`placeBehindObject: ${V} (waits for the AI matte of "${et.name}" in ${j.label||j.id})`:`${T}: "${et.name}" of ${j.label||j.id} (AI object matte computed in the editor)`);break}case"placeBehindDepth":{const d=b(u.clipId);if(!d||d.kind==="audio")throw Error("Clip not found");let w=b(u.sourceClipId);if(!w||w.kind==="audio")throw Error("Depth map or footage not found");if(u.materialId){const O=o.find(Q=>Q.id===u.materialId);if(!O||!O.url||!["video","image"].includes(O.kind))throw Error(`Không thấy bản đồ độ sâu ${u.materialId}`);const L=w,B=d.matte?.source&&b(d.matte.source),X=B&&B.nodeId===O.id&&B.start===L.start?B:null;if(X)w=X;else{if(s.length>=Kt)throw Error(`Tối đa ${Kt} clip`);const Q=Zt(s,r,L.start,L.start+L.duration,null).track,et=Rt();U.push(et);const lt=["inPoint","playbackRate","speedRamp","posX","posY","scale","scaleX","scaleY","rotation","flipX","flipY","crop","motionKeys","reverse","fit"];w={id:et,nodeId:O.id,track:Q,start:L.start,duration:L.duration,url:O.url,...O.gcsUri?{gcsUri:O.gcsUri}:{},kind:O.kind,label:`${L.label||"Video"} · độ sâu`,volume:0,...Object.fromEntries(lt.filter(Y=>L[Y]!==void 0).map(Y=>[Y,structuredClone(L[Y])])),...it(O.duration)!=null?{sourceDuration:it(O.duration)}:{}},s.push(w)}}if(w.id===d.id)throw Error("A layer cannot be its own depth map");const T=Math.max(0,Math.min(1,it(u.numberValue)??d.matte?.depth??.5)),j=d.matte?.source===w.id?d.matte.feather:void 0;d.matte={source:w.id,mode:"depth",depth:+T.toFixed(3),...j?{feather:j}:{}},Vh(s),h.push(`placeBehindDepth: ${V} at depth ${Math.round(T*100)}%`);break}case"collageStyle":{const d=b(u.clipId);if(!d||d.kind==="audio"||d.kind==="model")throw Error("Collage style needs a visual clip");if(u.back&&(d.zIndex=-100),u.sticker!=null)if(u.sticker==="none")delete d.sticker;else{const w=Iv[u.sticker];if(!w)throw Error("Unknown sticker edge");d.sticker=structuredClone(w)}if(u.torn!=null){const w=u.torn==="all"?Ic:[u.torn];if(!w.every(L=>Ic.includes(L)))throw Error("Unknown torn side");const T=o.find(L=>L.id===d.nodeId),j=Number.isInteger(T?.width)&&T.width>1?T.width:1600,O=Number.isInteger(T?.height)&&T.height>1?T.height:1e3;d.mask=G6(d.mask,{mw:j,mh:O,crop:d.crop,sides:w,seed:Number.isInteger(u.seed)?u.seed:1})}if(u.watercolor){const w=Sh(d,"watercolor",{start:0,duration:Math.min(1.2,d.duration/2)});Object.assign(d,w)}if(u.cutout!=null){if(!["person","object"].includes(u.cutout)||d.kind!=="image"||!d.url)throw Error("Background removal needs a photo and person / object");E.push({clipId:d.id,mode:u.cutout})}h.push(`collage ${V}`);break}case"rotoMask":{const d=b(u.clipId);if(!d)throw Error("rotoMask needs clipId (a video / image clip)");const{mask:w,follow:T}=yA(d,u,{size:gA(d,o.find(B=>B.id===d.nodeId))});w?d.mask=w:delete d.mask;const j=new Set(Z0(w)),L=[...((d.clientJobs??[]).find(B=>B?.kind==="mask-track"&&(B.state==="pending"||B.state==="running"))?.params?.masks??[]).filter(B=>j.has(B.id)&&!T.some(X=>X.id===B.id)),...T];L.length?Object.assign(d,Re(d,{kind:"mask-track",op:"rotoMask",params:{masks:L}})):d.clientJobs?.some(B=>B?.kind==="mask-track"&&B.state==="pending")&&(d.clientJobs=d.clientJobs.filter(B=>!(B?.kind==="mask-track"&&B.state==="pending"))),h.push(`rotoMask ${V}: ${Z0(w).length} mask(s)${T.length?`, ${T.length} to track in the editor`:""}`);break}case"runAnalyzer":{const d=b(u.clipId);if(!d)throw Error("Clip not found");if(d.kind!=="video")throw Error("runAnalyzer needs a video clip");const w=u.plugin;if(!w||typeof w!="object"||typeof w.id!="string"||!/^[a-z0-9.-]{3,40}$/.test(w.id)||w.item!==void 0&&(typeof w.item!="string"||!/^[a-z0-9-]{1,40}$/.test(w.item))||typeof w.v!="string"||w.v.length>20)throw Error("runAnalyzer: plugin {id, item?, v} of an installed analyzer");const T=u.values&&typeof u.values=="object"&&!Array.isArray(u.values)?u.values:{};if(JSON.stringify(T).length>4096)throw Error("runAnalyzer: values too large");Object.assign(d,Re(d,{kind:"plugin-analyze",op:"runAnalyzer",params:{plugin:{id:w.id,...w.item?{item:w.item}:{},v:w.v},values:T}})),h.push(`runAnalyzer ${w.id}${w.item?`/${w.item}`:""}: ${V} (in the open editor)`);break}case"bakeMap":{const d=b(u.clipId);if(!d)throw Error("Clip not found");if(!d.geo)throw Error("bakeMap needs an animated map layer (addMap)");Object.assign(d,Re(d,{kind:"map-bake",op:"bakeMap"})),h.push(`bakeMap: ${V} → video (in the open editor)`);break}case"portalDive":{const d=b(u.clipId);if(!d)throw Error("Clip not found");const w=d.pendingPin&&!d.pin;if(!w&&!d.pin)throw Error("portalDive needs a pinned layer: pinToSurface (mode plane) or a corner pin first");if(d.pin?.scene||w&&d.pendingPin.mode!=="plane")throw Error("portalDive works on a flat pin (pinToSurface mode plane, corner / face / map pin)");if((w?d.pendingPin:d.pin).dive){const X=K3(s,d.id);s.splice(0,s.length,...X)}const j=b(u.clipId),O=w?j.pendingPin:j.pin;if(u.booleanValue===!1){h.push(`portalDive off: ${V}`);break}const L=r2(j,b(O.clip??O.source),{at:it(u.at)??null,dur:it(u.duration)??1.2}),B=G3(L);if(w?j.pendingPin={...j.pendingPin,dive:B}:j.pin={...j.pin,dive:B},!w&&a.W&&a.H){const X=Hg(s,j.id,a.W,a.H);s.splice(0,s.length,...X)}h.push(`portalDive: the camera pushes into ${V} from ${L.at.toFixed(2)}s, the screen fills the frame at ${(L.at+L.dur).toFixed(2)}s`);break}case"pinToSurface":{const d=b(u.clipId),w=b(u.sourceClipId),T=Us(d,w,u);delete d.pin,Object.assign(d,T),S.push({clipId:d.id,...T.pendingPin});let j="";if(w.person&&u.booleanValue!==!1&&_n(d,w)>=0){const L=qs(d,w,{index:ci,at:In,isFree:B=>!r[B]?.locked&&!s.some(X=>X.track===B&&X.start<w.start+w.duration&&X.start+X.duration>w.start)});if(L!==null){let B=`${w.id}-person`,X=2;for(;b(B);)B=`${w.id}-person-${X++}`;const Q=Eh(s,w,{id:B,track:L,label:`${w.label||"Video"} · người`,target:d});Zs(Q.clips),s=Q.clips,U.push(B),j=", person in front"}}h.push(`pinToSurface ${V} → ${w.label||w.id} (${T.pendingPin.mode}${j})`);break}case"addFlash":{const d=Array.isArray(u.times)&&u.times.length?u.times.map(it):[it(u.at)];if(!d.length||d.length>Yf||d.some(L=>L===null||L<0||L>We))throw Error(`addFlash: at (timeline s) or times [≤${Yf} instants]`);const w=u.flashStyle??u.style??"white";if(!Object.hasOwn(Oi,w))throw Error(`addFlash style: ${Object.keys(Oi).join("|")}`);const T=l$(w,it(u.strength)??it(u.numberValue)??1),j=ht(s$(w)),O=Oi[w][a.locale==="en"?"en":"vi"];for(const L of d){if(s.length>=Kt)throw Error(`Tối đa ${Kt} clip`);const B=ht(L),{track:X}=Zt(s,r,B,B+j,it(u.track)),Q=Rt();U.push(Q),s.push({...bh({id:Q,track:X,start:B,duration:j,label:`${a.locale==="en"?"Flash":"Chớp"} · ${O}`}),motionKeys:[],effects:T.map(et=>({...et,keys:et.keys.map(lt=>({...lt}))}))})}h.push(`flash ${w} ×${d.length} (${d.map(L=>ht(L)).join(", ")}s)`);break}case"setEffect":{const d=b(u.clipId);if(!d||d.kind==="audio"||d.kind==="model")throw Error("Effects need a 2D visual clip");if(!Object.hasOwn(tc,u.property))throw Error("Unknown effect");const w=it(u.numberValue);if(w===null||w<0||w>1)throw Error("Effect amount must be 0..1");let T=null;if(u.property==="glow-pro"){const B=u.glow??(typeof u.prompt=="string"&&u.prompt.trim().startsWith("{")?(()=>{try{return JSON.parse(u.prompt)}catch{throw Error("Glow Pro settings (prompt) must be JSON")}})():void 0),X=(d.effects||[]).find(Q=>Q.type==="glow-pro")?.params;B!==void 0?T=o2({...X||{},...B}):X&&(T=X)}const j={type:u.property,amount:w,...T?{params:T}:{}},O=(d.effects||[]).filter(B=>B.type!==u.property),L=(d.effects||[]).findIndex(B=>B.type===u.property);if(w>0&&(L>=0?O.splice(L,0,j):O.push(j)),O.length>kn)throw Error(`At most ${kn} effects per clip`);O.length?d.effects=O:delete d.effects,h.push(`effect ${u.property} ${w?Math.round(w*100)+"%":"off"}: ${V}`);break}case"personEcho":case"clonePerson":{u=Qt(u);let d=b(u.clipId);if(!d||d.kind!=="video")throw Error(`${u.op} needs the filmed video clip of the person`);if(!d.person){const L=d,B=s.find(X=>X.id!==L.id&&X.kind==="video"&&X.person&&X.person.src!=="object"&&X.url===L.url);B&&(d={...L,person:B.person})}if(!d.person){if(a.noPendingMatte||!t.some(X=>X.id===d.id))throw Error(`"${d.label||d.id}" has no AI person matte yet — open Roto → Tách người bằng AI on it first`);const{clipId:L,...B}=u;A(d,null,{...B,clipId:d.id}),h.push(`${u.op} ${d.label||d.id}: waits for the AI person matte (made in the editor), then runs`);break}const w=[],T=()=>{let L=Rt();for(;b(L);)L=Rt();return w.push(L),L},j=u.op==="personEcho"?{layers:$M(d,{copies:vt(u.copies)??vt(u.numberValue),gap:vt(u.gap),fade:vt(u.fade),opacity:vt(u.opacity),spread:vt(u.spread),look:typeof u.look=="string"&&u.look?u.look:null,start:vt(u.start),duration:vt(u.duration)},T),poofs:[]}:EM(d,{count:vt(u.count)??vt(u.numberValue),layout:u.layout,spread:vt(u.spread),depth:vt(u.depth),delay:vt(u.delay),mirror:u.mirror!==!1,feet:Array.isArray(u.feet)?u.feet:void 0,horizon:vt(u.horizon),start:vt(u.start),duration:vt(u.duration),smoke:u.smoke!==!1},T);if(s.length+j.layers.length+j.poofs.length>Kt)throw Error(`Tối đa ${Kt} clip`);for(const L of[...j.layers,...j.poofs]){const{track:B}=Zt(s,r,L.start,L.start+L.duration);s.push({...L,track:B}),U.push(L.id)}s.some(L=>L.id!==d.id&&L.kind==="video"&&L.url===d.url&&!L.person&&!L.mask&&L.start===d.start&&L.duration===d.duration&&(L.inPoint||0)===(d.inPoint||0))||(s=s.map(L=>{if(L.id!==d.id)return L;const B={...L};return delete B.person,delete B.mask,B})),h.push(u.op==="personEcho"?`personEcho ${d.label||d.id}: ${j.layers.length-1} copies + the person on top`:`clonePerson ${d.label||d.id}: ${j.layers.length-1} clones${j.poofs.length?` (${j.poofs.length} smoke poofs)`:""} + the person in front`);break}case"addShock":{u=Qt(u);const d=b(u.clipId);if(!d||d.kind==="audio")throw Error("addShock needs a visual clip");if(u.booleanValue===!1){delete d.shocks,h.push(`addShock ${V}: rings removed`);break}const w=vt(u.at)??d.start,T=Array.isArray(u.point)?u.point:[vt(u.u)??.5,vt(u.v)??.8];if(w<d.start-1e-6||w>d.start+d.duration+1e-6)throw Error("addShock at must be a timeline time inside the clip");if((d.shocks?.length??0)>=vh.max)throw Error(`A clip holds up to ${vh.max} shockwaves`);const j=t2({t:w-d.start,u:vt(T[0])??.5,v:vt(T[1])??.8,radius:vt(u.radius),strength:vt(u.strength),duration:vt(u.duration),squash:vt(u.squash),light:vt(u.light)});if(d.shocks=e2([...d.shocks??[],j].sort((O,L)=>O.t-L.t),d.duration),u.cracks===!0){let O=Rt();for(;b(O);)O=Rt();const L=a.W||1280,B=a.H||720,X=d.scale??1,Q=.5+(d.posX??0)+(j.u-.5)*X,et=.5+(d.posY??0)+(j.v-.5)*X,lt=zM({id:O,at:w,duration:Math.min(Math.max(1.2,j.duration*1.8),d.start+d.duration-w+.5),u:Q,v:et,size:j.radius*.65*X,squash:j.squash,seed:Math.round(w*1e3)%9973+1,W:L,H:B}),{track:Y}=Zt(s,r,lt.start,lt.start+lt.duration);s.push({...lt,track:Y}),U.push(O)}h.push(`addShock ${V}: ring at ${(+w).toFixed(2)} s${u.cracks===!0?" + ground cracks":""}`);break}case"smoothSlowMo":{const d=b(u.clipId);if(!d||d.kind!=="video")throw Error("smoothSlowMo needs a video clip");if(u.booleanValue===!1){delete d.smoothSlow,h.push(`smoothSlowMo ${V}: off`);break}d.smoothSlow=!0,h.push(`smoothSlowMo ${V}: on${E1(d)?"":" (slow it below 1× with setSpeed / speedRamp to see it)"}`);break}case"objectTrail":{u=Qt(u);const d=b(u.clipId);if(!d||d.kind!=="video")throw Error("objectTrail needs a video clip");const w=Array.isArray(u.path)&&u.path.length>=2&&u.path.every(Q=>Array.isArray(Q)&&(Q.length===3||Q.length===4)&&Q.every(Number.isFinite)&&Q[1]>=-.2&&Q[1]<=1.2&&Q[2]>=-.2&&Q[2]<=1.2)?[...u.path].sort((Q,et)=>Q[0]-et[0]):null;if(u.path!==void 0&&u.path!==null&&!w)throw Error("objectTrail path: ≥ 2 [timeline s, u, v, r?] points (u, v 0..1 of the frame; r = wheel radius, a share of the frame height)");const T=w?[Math.min(1,Math.max(0,w[0][1])),Math.min(1,Math.max(0,w[0][2]))]:Array.isArray(u.point)?u.point:null;if(!T||!T.every(Q=>Number.isFinite(Q)&&Q>=0&&Q<=1))throw Error("objectTrail point [u, v] (0..1 of the picture)");const j=vt(u.at)??(w?w[0][0]:d.start),O=Math.min(vt(u.duration)??(w?w.at(-1)[0]-j+(vt(u.length)??.45):d.start+d.duration-j),d.start+d.duration-j);if(!(O>=.2)||j<d.start-1e-6)throw Error("objectTrail must lie inside the footage");let L=Rt();for(;b(L);)L=Rt();const B=Ik({id:L,at:j,duration:O,color:u.color,width:vt(u.width),length:vt(u.length),source:d.id,point:T,style:u.style==="energy"||u.style==="ribbon"||u.style==="wheel"?u.style:void 0,aspect:vt(u.ringAspect),rot:vt(u.ringRot),wind:Array.isArray(u.wind)?u.wind:void 0,stretch:vt(u.stretch),taper:vt(u.taper),vanish:Array.isArray(u.vanish)?u.vanish:void 0,flow:vt(u.flow),ring:vt(u.ring),spread:vt(u.spread)}),{track:X}=Zt(s,r,B.start,B.start+B.duration);if(w){const Q=a.W||1280,et=a.H||720,lt=(nt,mt,It,Nt,$t)=>.5*(2*mt+(It-nt)*$t+(2*nt-5*mt+4*It-Nt)*$t*$t+(3*mt-nt-3*It+Nt)*$t*$t*$t),Y=nt=>w[Math.max(0,Math.min(w.length-1,nt))],dt=[];for(let nt=Math.max(B.start,w[0][0]);nt<=Math.min(B.start+B.duration,w.at(-1)[0])+1e-6;nt+=1/30){let mt=0;for(;mt<w.length-2&&w[mt+1][0]<nt;)mt++;const It=Math.min(1,Math.max(0,(nt-Y(mt)[0])/(Y(mt+1)[0]-Y(mt)[0]||1)));dt.push([+(nt-B.start).toFixed(4),lt(Y(mt-1)[1],Y(mt)[1],Y(mt+1)[1],Y(mt+2)[1],It)*Q,lt(Y(mt-1)[2],Y(mt)[2],Y(mt+1)[2],Y(mt+2)[2],It)*et,...w.every(Nt=>Nt.length===4)?[(Y(mt)[3]+(Y(mt+1)[3]-Y(mt)[3])*It)*et]:[]])}const{pendingPin:bt,...tt}=B;if(s.push({...tt,track:X,...Ak({...tt,track:X},dt,Q,et),pendingPin:void 0}),U.push(L),u.split===!0&&u.style==="wheel"){const nt=s.at(-1);nt.motion={...nt.motion,params:{...nt.motion.params,part:"back"}},nt.label="Bánh xe năng lượng · sau";let mt=Rt();for(;b(mt);)mt=Rt();const It=Zt(s,r,nt.start,nt.start+nt.duration).track;s.push({...nt,id:mt,track:Math.max(It,nt.track+2),label:"Bánh xe năng lượng · lốp",motion:{...nt.motion,params:{...nt.motion.params,part:"front"}}}),U.push(mt)}h.push(`objectTrail on ${d.label||d.id}: drawn along the given path (${w.length} points)`);break}s.push({...B,track:X}),U.push(L),S.push({clipId:L,...B.pendingPin}),h.push(`objectTrail on ${d.label||d.id}: tracked in the editor, then drawn`);break}case"addImpact":{u=Qt(u);const d=b(u.clipId);if(!d||d.kind==="audio"||d.kind==="model")throw Error("addImpact needs a visual clip");if(u.booleanValue===!1){delete d.impacts,h.push(`addImpact ${V}: hits removed`);break}const w=vt(u.at)??d.start,T=Array.isArray(u.point)?u.point:[vt(u.u)??.5,vt(u.v)??.5];if(w<d.start-1e-6||w>d.start+d.duration+1e-6)throw Error("addImpact at must be a timeline time inside the clip");if((d.impacts?.length??0)>=xu.max)throw Error(`A clip holds up to ${xu.max} impact hits`);const j=Jw({t:w-d.start,u:vt(T[0])??.5,v:vt(T[1])??.5,strength:vt(u.strength),duration:vt(u.duration),blur:vt(u.blur),rgb:vt(u.rgb),flash:vt(u.flash)});d.impacts=Qw([...d.impacts??[],j].sort((nt,mt)=>nt.t-mt.t),d.duration);const O=kg(d,"rot")||Math.abs(d.rotation??0)>1e-6,L=a.W||1280,B=a.H||720,X=O?Id(d,j.u,j.v,w-d.start,L,B,L,B):null,Q=d.scale??1,et=X?X.px/L:.5+(d.posX??0)+(j.u-.5)*Q,lt=X?X.py/B:.5+(d.posY??0)+(j.v-.5)*Q,Y=[];let dt=()=>{let nt=Rt();for(;b(nt)||Y.some(mt=>mt.id===nt);)nt=Rt();return nt};u.debris!==!1&&Y.push(IM({id:dt(),at:w,u:et,v:lt,size:.6+.6*(vt(u.strength)??.8),seed:Math.round(w*1e3)%9973+1})),u.pillars===!0&&Y.push(k$({id:dt(),at:w,u:et,v:lt,size:.7+.5*(vt(u.strength)??.8),color:/^#[0-9a-fA-F]{6}$/.test(u.color??"")?u.color:void 0}));const bt=d.person&&d.person.src!=="object"?d.person:s.find(nt=>nt.id!==d.id&&nt.kind==="video"&&nt.person&&nt.person.src!=="object"&&nt.url===d.url)?.person;let tt=null;if(u.keepPerson!==!1&&bt&&d.kind==="video"){const nt=Math.min(d.start+d.duration,w+j.duration+.05);tt=Nn({...d,person:bt},dt(),{start:no(w),duration:no(nt-w),inPoint:no((d.inPoint||0)+(w-d.start)*(d.playbackRate||1)),label:`${d.label||"Video"} · người nét`}),delete tt.impacts,delete tt.motionKeys,X&&Object.assign(tt,P1(d,w,nt-w)),Y.push(tt)}if(u.shake!==!1){const nt=Math.max(.15,Math.min(1,.35+.5*(vt(u.strength)??.8))),mt=w-d.start,It=Math.min(d.duration,mt+.35),Nt=Math.round(w*1e3)+d.id.length;Object.assign(d,ts(d,{amount:nt,freq:14,from:mt,to:It,seed:Nt,props:["x","y"]})),tt&&Object.assign(tt,ts(tt,{amount:nt,freq:14,from:0,to:It-mt,seed:Nt,props:["x","y"]}))}if(s.length+Y.length>Kt)throw Error(`Tối đa ${Kt} clip`);if(X){const nt=Math.round(Ut(d,"rot",w-d.start)*100)/100;for(const mt of Y)mt.motion&&(mt.rotation=nt)}for(const nt of Y){const{track:mt}=Zt(s,r,nt.start,nt.start+nt.duration);s.push({...nt,track:mt}),U.push(nt.id)}h.push(`addImpact ${V}: hit at ${(+w).toFixed(2)} s${u.debris!==!1?" + debris":""}${u.pillars===!0?" + a pillar of light":""}${tt?" + the person sharp on top":""}`);break}case"speedBolt":{u=Qt(u);const d=b(u.clipId);if(!d||d.kind!=="video")throw Error("speedBolt needs a video clip");const w=Array.isArray(u.point)?u.point:null;if(w&&!w.every(Q=>Number.isFinite(Q)&&Q>=0&&Q<=1))throw Error("speedBolt point [u, v] (0..1 of the picture)");const T=vt(u.at)??d.start,j=Math.min(vt(u.duration)??d.start+d.duration-T,d.start+d.duration-T);if(!(j>=.2)||T<d.start-1e-6)throw Error("speedBolt must lie inside the footage");if(!w&&d.personPending&&!(d.person&&d.person.src!=="object")&&!a.noPendingMatte&&t.some(Q=>Q.id===d.id)&&!s.some(Q=>Q.id!==d.id&&Q.kind==="video"&&Q.person&&Q.person.src!=="object"&&Q.url===d.url)){const{clipId:Q,...et}=u;A(d,null,{...et,clipId:d.id}),h.push(`speedBolt ${d.label||d.id}: waits for the AI person matte (made in the editor), then runs`);break}const O=!w&&!(d.person||d.personPending)?s.find(Q=>Q.id!==d.id&&Q.kind==="video"&&Q.person&&Q.person.src!=="object"&&Q.url===d.url)??d:d;let L=Rt();for(;b(L);)L=Rt();const B=Sk({id:L,at:T,duration:j,color:u.color,width:vt(u.width),length:vt(u.length),jag:vt(u.jag),source:O.id,point:w??void 0}),{track:X}=Zt(s,r,B.start,B.start+B.duration);s.push({...B,track:X}),U.push(L),S.push({clipId:L,...B.pendingPin}),h.push(`speedBolt on ${d.label||d.id}: tracked in the editor, then drawn`);break}case"personElectric":{u=Qt(u);let d=b(u.clipId);if(!d||d.kind!=="video")throw Error("personElectric needs the filmed video of the person");if(!d.person){const et=d,lt=s.find(Y=>Y.id!==et.id&&Y.kind==="video"&&Y.person&&Y.person.src!=="object"&&Y.url===et.url);lt&&(d={...et,person:lt.person})}if(!d.person){if(a.noPendingMatte||!t.some(Y=>Y.id===d.id))throw Error(`"${d.label||d.id}" has no AI person matte yet — open Roto → Tách người bằng AI on it first`);const{clipId:et,...lt}=u;A(d,null,{...lt,clipId:d.id}),h.push(`personElectric ${d.label||d.id}: waits for the AI person matte (made in the editor), then runs`);break}const w=Math.max(d.start,vt(u.start)??d.start),T=Math.min(d.start+d.duration,vt(u.duration)!=null?w+vt(u.duration):d.start+d.duration);if(!(T-w>.1))throw Error("personElectric must lie inside the person clip");let j=Rt();for(;b(j);)j=Rt();const O=/^#[0-9a-fA-F]{6}$/.test(u.color??"")?u.color:"#ffc23d",L=Math.max(.1,Math.min(1,vt(u.crackle)??.75)),B=Nn(d,j,{start:no(w),duration:no(T-w),inPoint:no((d.inPoint||0)+(w-d.start)*(d.playbackRate||1)),label:`${d.label||"Video"} · điện`,edge:mu({color:O,width:.009,glow:1.6,crackle:L,amount:1})});delete B.impacts;const{track:X}=Zt(s,r,B.start,B.start+B.duration);s.push({...B,track:X}),U.push(j),s.some(et=>et.id!==d.id&&et.kind==="video"&&et.url===d.url&&!et.person&&!et.mask&&et.start===d.start&&et.duration===d.duration&&(et.inPoint||0)===(d.inPoint||0))||(s=s.map(et=>{if(et.id!==d.id)return et;const lt={...et};return delete lt.person,delete lt.mask,lt})),h.push(`personElectric ${d.label||d.id}: electricity on the person`);break}case"worldFlip":{u=Qt(u);const d=b(u.clipId);if(!d||d.kind==="audio"||d.kind==="model")throw Error("worldFlip needs a 2D visual clip");const w=vt(u.at)??d.start,T=w-d.start,j=vt(u.duration)??.6;if(T<-1e-6||T>d.duration)throw Error("worldFlip at must be a timeline time inside the clip");Object.assign(d,y$(d,{from:Math.max(0,T),to:T+j,turn:vt(u.turn)??vt(u.numberValue)??180,back:u.back===!0,W:a.W||1280,H:a.H||720})),h.push(`worldFlip ${V}: turns ${vt(u.turn)??vt(u.numberValue)??180}° at ${(+w).toFixed(2)} s`);break}case"lightBurst":{u=Qt(u);const d=b(u.clipId);if(!d||d.kind==="audio"||d.kind==="model")throw Error("lightBurst needs a 2D visual clip");const w=(Array.isArray(u.hits)?u.hits:[vt(u.at)??d.start]).filter(Number.isFinite).slice(0,Jc.maxHits),T=M$(d,w);if(!T.length)throw Error("lightBurst hits must be timeline times inside the clip");const j=[...d.effects||[]].filter(O=>O.type!=="light-burst");if(j.length>=kn)throw Error(`At most ${kn} effects per clip`);d.effects=Zw([...j,{type:"light-burst",amount:0,keys:T}]),h.push(`lightBurst ${V}: ${w.length} burst(s) of light`);break}case"breathMist":{u=Qt(u);const d=b(u.clipId),w=vt(u.at)??d?.start??0,T=Array.isArray(u.point)?u.point:[vt(u.u)??.5,vt(u.v)??.35];if(d&&(w<d.start-1e-6||w>d.start+d.duration+1e-6))throw Error("breathMist at must be a timeline time inside the clip");let j=Rt();for(;b(j);)j=Rt();const O=w$({id:j,at:w,u:vt(T[0])??.5,v:vt(T[1])??.35,angle:vt(u.angle)??200,length:vt(u.length)??1,size:vt(u.size)??1,duration:vt(u.duration)??1.6,color:/^#[0-9a-fA-F]{6}$/.test(u.color??"")?u.color:void 0}),{track:L}=Zt(s,r,O.start,O.start+O.duration);s.push({...O,track:L}),U.push(j),h.push(`breathMist at ${(+w).toFixed(2)} s`);break}case"documentary":{if(u._error)throw Error(u._error);const d=u._plan;if(!d||!Array.isArray(d.S)||!Array.isArray(d.K))throw Error("documentary needs stations");const w=Math.max(0,it(u.start)??0),T=Math.ceil(d.total/Zo.layerSeconds-1e-6),j=[];for(let B=0;B<T;B++){let X=Rt();for(;b(X)||j.includes(X);)X=Rt();j.push(X)}const O=W8({ids:j,at:w,plan:d,label:u.label||void 0}),{track:L}=Zt(s,r,w,w+d.total);for(const B of O)s.push({...B,track:L}),U.push(B.id);h.push(`documentary: ${d.S.length} station(s) in one camera move, ${d.total.toFixed(1)} s (${d.style})`);break}case"energyAura":{u=Qt(u);const d=b(u.clipId);if(!d||d.kind!=="video")throw Error("energyAura needs a video clip (the footage of the person / thing)");const w=Array.isArray(u.path)&&u.path.length>=2&&u.path.every(et=>Array.isArray(et)&&et.length===4&&et.every(Number.isFinite))?[...u.path].sort((et,lt)=>et[0]-lt[0]):null;if(u.path!==void 0&&u.path!==null&&!w)throw Error("energyAura path: ≥ 2 [timeline s, u, v, r] points (u, v 0..1 of the frame, r = radius as a share of the frame height)");const T=Math.max(d.start,vt(u.start)??(w?w[0][0]:d.start)),j=Math.min(d.start+d.duration,T+(vt(u.duration)??(w?w.at(-1)[0]-T:d.start+d.duration-T)));if(!(j-T>=.2))throw Error("energyAura must lie inside the footage");const O={look:u.look,color:u.color,hot:u.hot,size:vt(u.size),intensity:vt(u.intensity),wind:Array.isArray(u.wind)?u.wind:void 0,speed:vt(u.speed),stretch:vt(u.stretch),taper:vt(u.taper)};let L=typeof u._auraId=="string"&&!b(u._auraId)?u._auraId:Rt();for(;!u._auraId&&b(L);)L=Rt();const B=w?w.map(et=>[+(et[0]-T).toFixed(4),et[1],et[2],et[3]]):[];let X=OM({id:L,at:T,duration:j-T,settings:O,body:B,kind:w?"thing":"person"});w||(X=Re(X,{kind:"aura-pose",op:"energyAura",params:{source:d.id,from:+(T-d.start).toFixed(4),duration:+(j-T).toFixed(4),person:Number.isInteger(u.person)?u.person:1}}));const{track:Q}=Zt(s,r,X.start,X.start+X.duration);s.push({...X,track:Q}),U.push(L),h.push(`energyAura ${Ld(O).look} on ${d.label||d.id}${w?" (along the given path)":": the body tracked in the editor"}`);break}case"personAura":{u=Qt(u);let d=b(u.clipId);if(!d||d.kind!=="video")throw Error("personAura needs the filmed video of the person");if(!d.person){const O=d,L=s.find(B=>B.id!==O.id&&B.kind==="video"&&B.person&&B.person.src!=="object"&&B.url===O.url);L&&(d={...O,person:L.person})}if(!d.person){if(a.noPendingMatte||!t.some(B=>B.id===d.id))throw Error(`"${d.label||d.id}" has no AI person matte yet — open Roto → Tách người bằng AI on it first`);const{clipId:O,...L}=u;A(d,null,{...L,clipId:d.id}),h.push(`personAura ${d.label||d.id}: waits for the AI person matte (made in the editor), then runs`);break}const T=b$(d,()=>{let O=Rt();for(;b(O)||s.some(L=>L.id===O);)O=Rt();return O},{start:vt(u.start),duration:vt(u.duration),color:/^#[0-9a-fA-F]{6}$/.test(u.color??"")?u.color:void 0,silhouette:u.silhouette===!0});if(s.length+T.length>Kt)throw Error(`Tối đa ${Kt} clip`);for(const O of T){const{track:L}=Zt(s,r,O.start,O.start+O.duration);s.push({...O,track:L}),U.push(O.id)}s.some(O=>O.id!==d.id&&O.kind==="video"&&O.url===d.url&&!O.person&&!O.mask&&O.start===d.start&&O.duration===d.duration&&(O.inPoint||0)===(d.inPoint||0))||(s=s.map(O=>{if(O.id!==d.id)return O;const L={...O};return delete L.person,delete L.mask,L})),h.push(`personAura ${d.label||d.id}: aura${u.silhouette===!0?" + coloured figure":""}`);break}case"hudWall":{u=Qt(u);const d=u.sourceClipId!=null?b(u.sourceClipId):null;if(u.sourceClipId!=null&&(!d||d.kind!=="video"))throw Error("hudWall sourceClipId must be the footage (a video clip)");const w=vt(u.start)??d?.start??0,T=Math.min(cn.maxSeconds,vt(u.duration)??(d?d.start+d.duration-w:6)),{cards:j,assets:O}=X6(u,o,a.locale),L=u.region!=null&&typeof u.region=="object"?u.region:null,B=a.W||1280,X=a.H||720,Q=H6({cards:j,cols:vt(u.cols),rows:vt(u.rows),curve:vt(u.curve),color:u.color,look:u.look,toolbar:u.toolbar,...L&&Number(L.w)>0&&Number(L.h)>0&&(u.mode??"plane")==="plane"?{W:B*L.w,H:X*L.h,fill:!0}:{W:B,H:X}});let et=Rt();for(;b(et);)et=Rt();const lt=Z6({id:et,at:w,duration:T,cfg:Q,assets:O});if(u.region!=null){if(!d)throw Error("hudWall region needs sourceClipId (the footage to stick the wall to)");Object.assign(lt,Us(lt,d,{region:u.region,mode:u.mode??"plane",at:u.at}))}const{track:Y}=Zt(s,r,lt.start,lt.start+lt.duration);s.push({...lt,track:Y}),U.push(et),lt.pendingPin&&S.push({clipId:et,...lt.pendingPin}),h.push(`hudWall: ${j.length} card(s), ${Q.cols}×${Q.rows}${lt.pendingPin?`, stuck to ${d.label||d.id} (${lt.pendingPin.mode}, tracked in the editor)`:""}`);break}case"hudPanel":{u=Qt(u);const d=u.sourceClipId!=null?b(u.sourceClipId):null;if(u.sourceClipId!=null&&(!d||d.kind!=="video"))throw Error("hudPanel sourceClipId must be the footage (a video clip)");if(u.region!=null&&!d)throw Error("hudPanel region needs sourceClipId (the footage to stick the panel to)");const w=ht((vt(u.start)??d?.start??0)+Math.max(0,vt(u.delay)??0)),T=Math.min(or.maxSeconds,vt(u.duration)??(u.kind==="prompt"||u.kind==="keyboard"?Math.max(4,Xy(String(u.text??""),vt(u.typeAt)??.5,vt(u.cps)??14).at(-1)+1.6||4):4));if(!(T>=.5))throw Error("hudPanel: duration ≥ 0.5 s");const j=u.kind==="prompt"&&u.keyboard===!0?["prompt","keyboard"]:[u.kind],O=[],L=[];for(const B of j){const X=QI(B,B==="keyboard"&&u.kind==="prompt"?{...u,posX:void 0,posY:u.keyboardY,width:void 0,tiltX:void 0,tiltY:void 0}:u,{materials:o,locale:a.locale,fill:u.region!=null&&B!=="keyboard"});if(u.region==null){const Y=a.W||1280,dt=a.H||720,bt=d??s.filter(mt=>mt.kind==="video"&&!mt.motion&&mt.start<=w+1e-6&&mt.start+mt.duration>w&&!r[mt.track]?.hidden).sort((mt,It)=>mt.track-It.track)[0],tt=bt?xc(bt,o.find(mt=>mt.id===bt.nodeId),w+T/2,{W:Y,H:dt})??{...dt>Y*1.1?ve.face.portrait:ve.face.landscape,assumed:!0}:null,nt=eA(X.S,tt,Y,dt);nt&&L.push(`${B} ${nt}`)}let Q=Rt();for(;b(Q);)Q=Rt();const et={id:Q,nodeId:"",kind:"image",url:"",volume:0,start:w,duration:ht(T),label:X.label,motionV:2,posX:0,posY:0,scale:1,motion:JI(X.S,X.TT,X.assets)};u.region!=null&&B!=="keyboard"&&Object.assign(et,Us(et,d,{region:u.region,mode:u.mode??"plane",at:u.at}));const{track:lt}=Zt(s,r,et.start,et.start+et.duration);s.push({...et,track:lt}),U.push(Q),O.push(B),et.pendingPin&&S.push({clipId:Q,...et.pendingPin})}h.push(`hudPanel: ${O.join(" + ")} (${Wy(u.look,u.color).id}) ${w.toFixed(2)}–${(w+T).toFixed(2)}s${L.length?` — ${L.join(", ")}`:""}${u.region!=null?`, stuck to ${d.label||d.id} (tracked in the editor)`:""}`);break}case"hudInteract":{u=Qt(u);const d=b(xt(u.wallClipId??u.clipId));if(!Y1(d))throw Error("hudInteract needs wallClipId = a HUD wall layer (hudWall)");const w=b(u.sourceClipId);if(!w||w.kind!=="video")throw Error("hudInteract needs sourceClipId = the footage with the hands");const T=Math.max(d.start,w.start),j=Math.min(d.start+d.duration,w.start+w.duration);if(!(j-T>=.3))throw Error("The HUD wall and the footage do not play at the same time");const O=Du.includes(u.hand)?u.hand:"any",L=u.grab===!1?!1:Number.isInteger(u.grab)?u.grab:"auto",B=vt(u.fly),X=Array.isArray(u.events)?u.events.slice(0,64).map(Yt=>({t:it(Yt?.t),type:Yt?.type,...Array.isArray(Yt?.point)?{point:Yt.point.map(Number)}:{}})):null,Q=u.matteClipId!=null?b(u.matteClipId):null;if(u.matteClipId!=null&&!Q?.person)throw Error("hudInteract matteClipId must be a clip with an AI person / object cut-out of the hands");s=s.filter(Yt=>Yt.hud?.wall!==d.id);const et=()=>{let Yt=Rt();for(;b(Yt);)Yt=Rt();return Yt},{HUD:lt}=Kd(d.motion),Y=d.motion.params?.color??lt.color,dt=d.motion.params?.look??lt.look,bt=a.W||1280,tt=a.H||720,nt=w.hands?.mw??bt,mt=w.hands?.mh??tt,It=tE(d,w,s,{cam:p,W:bt,H:tt}),Nt=et();let $t=null;if(u.shadow===!0){const Yt={...w,id:Nt,volume:0,hud:{wall:d.id,role:"hands"},label:`${w.label||"Video"} · tay`};for(const Ft of["roto","planar","personPending","clientJobs","hands","sceneTrack","objectTracks","captions","captionWords","captionStyle","transition","shocks","impacts","trail","pendingPin","pin","person","mask"])delete Yt[Ft];$t=eE(Yt,{id:Nt,wallMask:It,mw:nt,mh:mt}),$t.track=Zt(s,r,$t.start,$t.start+$t.duration).track,s.push($t),U.push(Nt)}const zt=et(),Dt={id:zt,nodeId:"",kind:"image",url:"",volume:0,start:no(T),duration:no(j-T),label:"HUD · thẻ kéo ra",motionV:2,posX:0,posY:0,scale:1,motion:od({color:Y,look:dt}),hud:{wall:d.id,role:"grab"}};Dt.track=Zt(s,r,Dt.start,Dt.start+Dt.duration).track,s.push(Dt),U.push(zt);const ae=et(),we={...w,id:ae,label:`${w.label||"Video"} · tay`,volume:0,hud:{wall:d.id,role:"hands",src:w.id},mask:ad(w.hands?.mw,w.hands?.mh)};for(const Yt of["roto","planar","personPending","clientJobs","hands","sceneTrack","objectTracks","captions","captionWords","captionStyle","transition","shocks","impacts","trail","pendingPin","pin"])delete we[Yt];const Oe=Q?.person??(w.person&&w.person.src!=="object"?w.person:s.find(Yt=>Yt.id!==w.id&&Yt.kind==="video"&&Yt.url===w.url&&Yt.person&&Yt.person.src!=="object")?.person);Oe?we.person=Oe:delete we.person,we.track=Zt(s,r,w.start,w.start+w.duration).track,s.push(we),U.push(ae);const Ce={source:w.id,mode:"hud",wall:d.id,cutout:ae,...$t?{shadow:Nt}:{},side:O,grab:L,...Q?{matte:Q.id}:{},...B!=null?{fly:B}:{},...X?{events:X}:{},from:no(T-w.start),duration:no(j-T)};if(Ap(w,T-w.start,j-T)||X?.every(Yt=>Array.isArray(Yt.point))){const Yt=Q6({wall:d,layer:Dt,src:w,clips:s,cam:p,W:a.W||1280,H:a.H||720,events:X,grab:L,side:O,fly:B});if(d.motion=Yt.wall,Dt.motion=Yt.grab,w.hands){const Ft=Fm(w,{until:Yt.cutoutUntil});Ft&&(we.mask=Ft,$t&&($t.mask={...Ft,masks:[...Ft.masks,{...It,mode:"intersect"}]}))}h.push(`hudInteract ${d.label||d.id}: ${Yt.report.taps} tap(s), ${Yt.report.pinches} pinch(es)${Yt.report.grabbed!=null?`, card ${Yt.report.grabbed+1} pulled out`:""}, hands in front${w.hands?" (the open editor then cuts them out pixel by pixel)":""}`),w.hands&&Object.assign(Dt,Re(Dt,{kind:"hand-track",op:"hudInteract",params:Ce}));break}Object.assign(Dt,Re(Dt,{kind:"hand-track",op:"hudInteract",params:Ce})),h.push(`hudInteract ${d.label||d.id}: the hands are tracked in the editor, then the HUD reacts`);break}case"handAttach":{u=Qt(u);const d=b(u.clipId);if(!d||d.kind==="audio"||d.kind==="model")throw Error("handAttach needs a visual layer (clipId)");const w=b(u.sourceClipId);if(!w||w.kind!=="video")throw Error("handAttach needs sourceClipId = the footage with the hands");if(w.id===d.id)throw Error("A layer cannot follow its own hands");if(d.pin||d.pendingPin||d.parentId)throw Error("handAttach: unpin / unparent the layer first");const{point:T,side:j}=Rm(u),O=u.scale===!0,L=Array.isArray(u.offset)&&u.offset.length===2&&u.offset.every(Number.isFinite)?u.offset:null,B=Math.max(d.start,w.start),X=Math.min(d.start+d.duration,w.start+w.duration);if(!(X-B>=1/30))throw Error("The layer and the footage do not play at the same time");if(Ap(w,B-w.start,X-B)){for(const[Q,et]of Object.entries(J6(d,w,{point:T,side:j,scale:O,offset:L,W:a.W||1280,H:a.H||720})))et===void 0?delete d[Q]:d[Q]=et;h.push(`handAttach ${V}: follows the ${j==="any"?"":j+" "}hand's ${T}`);break}Object.assign(d,Re(d,{kind:"hand-track",op:"handAttach",params:{source:w.id,mode:"attach",point:T,side:j,scale:O,...L?{offset:L}:{},from:no(B-w.start),duration:no(X-B)}})),h.push(`handAttach ${V}: the hands are tracked in the editor, then it follows the ${T}`);break}case"fixMatte":{u=Qt(u);const d=b(u.clipId);if(!d?.person)throw Error("fixMatte needs a clip with an AI cut-out (a person / object cut-out, or the hands of a HUD)");const w=d.clientJobs?.find(X=>X?.kind==="matte-fix"&&X.state==="pending"),T=w?.params?.strokes??[];if(u.clear===!0){Object.assign(d,Re(d,{kind:"matte-fix",op:"fixMatte",params:{clear:!0,strokes:[]}})),h.push(`fixMatte ${V}: back to the AI cut-out (in the editor)`);break}if(u.roto===!0){Object.assign(d,Re(d,{kind:"matte-fix",op:"fixMatte",params:{...w?.params??{},roto:!0}})),h.push(`fixMatte ${V}: traced into Roto splines (in the editor)`);break}const j=it(u.at),O=u.mode??"add";if(j===null||j<d.start-1e-6||j>d.start+d.duration+1e-6)throw Error("fixMatte at must be a timeline time inside the clip");if(!["add","erase"].includes(O))throw Error("fixMatte mode: add | erase");const L=Array.isArray(u.points)?u.points:null;if(!L||!L.length||L.length>120||!L.every(X=>Array.isArray(X)&&X.length===2&&X.every(Q=>Number.isFinite(Q)&&Q>=-.2&&Q<=1.2)))throw Error("fixMatte points: [[x, y] …] 0..1 of the frame (≤ 120)");const B={local:no(j-d.start),mode:O,points:L.map(X=>X.map(no)),size:Math.max(.002,Math.min(.3,it(u.size)??.015)),spread:Math.round(Math.max(0,Math.min(60,it(u.spread)??8)))};Object.assign(d,Re(d,{kind:"matte-fix",op:"fixMatte",params:{...w?.params?.clear?{clear:!0}:{},...w?.params?.roto?{roto:!0}:{},strokes:[...T,B].slice(-50)}})),h.push(`fixMatte ${V}: ${O} stroke at ${(+j).toFixed(2)}s, followed ±${B.spread} frames (in the editor)`);break}case"cameraShake":{const d=b(u.clipId);if(!d||d.kind==="audio"||d.kind==="model")throw Error("Camera shake needs a 2D visual clip");const w=it(u.at)??0,T=it(u.duration)??Math.min(1.5,d.duration-w),j=Math.max(.1,Math.min(1,it(u.numberValue)??.5)),O=Math.round(w*1e3)+d.id.length;if(u.preset!=null&&!Ru.includes(u.preset))throw Error(`cameraShake preset (axis) must be one of ${Ru.join(", ")}`);const L=u.preset!=null?S5(u.preset,j,{amountX:it(u.amountX)??void 0,amountY:it(u.amountY)??void 0,amountRot:it(u.amountRot)??void 0,freq:it(u.freq)??void 0}):null;Object.assign(d,ts(d,L?{props:L.props,amp:L.amp,freq:L.freq,from:w,to:w+T,seed:O}:{amount:j,freq:12,from:w,to:w+T,seed:O})),h.push(`camera shake${u.preset?` ${u.preset}`:""} ${V}: ${w}s +${T}s`);break}case"writeMotion":{const d=typeof u.prompt=="string"?u.prompt.trim():"";if(d.length<6||d.length>6e3)throw Error("Motion brief must be 6–6000 characters");if(y.length>=jl)throw Error(`At most ${jl} Claude motion jobs per request`);if(u.clipId){const L=b(u.clipId);if(!L?.motion)throw Error("writeMotion clipId must be a Motion Code layer");y.push({clipId:L.id,prompt:d}),h.push(`Claude motion (sửa) ${V}`);break}const w=u.fromClipId?b(u.fromClipId):null;if(u.fromClipId&&!w?.motion)throw Error("writeMotion fromClipId must be a Motion Code layer");const T=it(u.start)??(w?w.start+w.duration:null),j=it(u.duration)??6;if(T===null||T<0||j<1||j>Tl+1e-6||T+j>We)throw Error(`Motion layer timing: start ≥ 0, 1–${Tl}s`);const O=y.filter(L=>!L.clipId&&L.join==null).reduce((L,B)=>L+(B.duration||0),0);if(O+j>Tl+1e-6)throw Error(`Claude motion: at most ${Tl}s of new layers per request (this plan asks for ${ht(O+j)}s) — split it into several requests`);y.push({prompt:d,start:ht(T),duration:ht(j),...w?{fromClipId:w.id}:{},...u.preset==="motion3d"?{kind:"three"}:{}}),h.push(`Claude motion (${w?`nối tiếp ${w.label}`:"mới"}) → ${ht(T)}s / ${ht(j)}s`);break}case"setMotionCode":{const d=b(u.clipId);if(!d?.motion)throw Error("setMotionCode clipId must be a Motion Code layer");if(typeof u.code!="string"||!/\brender\b/.test(u.code))throw Error("Motion code must define function render(ctx, t, env)");const w=u.motionKind==="three"?"three":u.motionKind==="2d"?void 0:d.motion.kind,T=Jo({code:u.code,params:u.params??{},...d.motion.prompt?{prompt:d.motion.prompt}:{},...w?{kind:w}:{},...d.motion.assets?{assets:d.motion.assets}:{}});d.motion=d.motion.duration?{...T,duration:d.motion.duration}:T,u.space===null||u.space===""?delete d.space:u.space!==void 0&&Object.assign(d,H0(u)),h.push(`motion code ${V}`);break}case"setMotion":{const d=b(u.clipId);if(!d||d.kind==="audio")throw Error("Motion requires a visual clip");const w=Ll(u.preset,d.duration);d.motionKeys=fu(d,w),delete d.posX,delete d.posY,delete d.scale,d.motionV=2,h.push(`motion ${V}: ${u.preset}`);break}case"generateBroll":{if(s.length>=Kt)throw Error(`Tối đa ${Kt} clip`);if(s.filter(O=>O.gen?.status==="pending"&&!t.some(L=>L.id===O.id)).length>=Js)throw Error(`At most ${Js} generated B-roll per request`);const d=u.layout??"cutaway";if(!ng.includes(d))throw Error("Unsupported B-roll layout");const w=Rt(),{clip:T,trackNote:j}=M4({clips:s,tracks:r,materials:o,generator:u.generator,prompt:u.prompt,start:it(u.start),duration:it(u.duration),layout:d,preset:u.preset,track:it(u.track),trackFallback:!0,newId:()=>w,refs:u.refs??void 0});U.push(w),s.push(T),h.push(`generateBroll → ${T.start}s / ${T.duration}s${j?` (${j})`:""}`);break}case"redrawVideo":{if(s.length>=Kt)throw Error(`Tối đa ${Kt} clip`);const d=b(u.clipId);if(!d||d.kind!=="video"||d.gen||d.title||d.shape||d.motion)throw Error("needs a video clip");if(!pi(d.gcsUri))throw Error("this video has no stored copy — add it to the project first (upload / Media)");if(d.duration<Qr.minSeconds-1e-6)throw Error(`the clip must be at least ${Qr.minSeconds}s`);if(u.style!==void 0&&!$h.includes(u.style))throw Error(`style: one of ${$h.join(", ")}`);if(u.mode!==void 0&&!Xw.includes(u.mode))throw Error("mode: keyframes or fast");if(u.resolution!==void 0&&!Hw.includes(u.resolution))throw Error("resolution: 720p or 1080p");if(u.keyframes!==void 0&&(!Number.isInteger(u.keyframes)||u.keyframes<Qr.minKeyframes||u.keyframes>Qr.maxKeyframes))throw Error(`keyframes: ${Qr.minKeyframes}–${Qr.maxKeyframes}`);const w=typeof u.character=="string"?u.character.trim():"";if(w.length>Qr.maxCharacterText)throw Error(`character: at most ${Qr.maxCharacterText} characters`);const T=Array.isArray(u.characterIds)?u.characterIds:[],j=[...new Set([...T.map(Y=>{const dt=o.find(bt=>bt.id===Y)||s.find(bt=>bt.id===Y&&bt.kind==="image");if(!dt||dt.kind!=="image"||!pi(dt.gcsUri))throw Error(`character picture ${String(Y).slice(0,40)} is not a stored image`);return dt.gcsUri}),...Array.isArray(u.refs)?u.refs:[]])];if(j.length>Qr.maxCharacterRefs||!j.every(pi))throw Error(`at most ${Qr.maxCharacterRefs} stored character pictures`);if(!w&&!j.length)throw Error("needs a character (description and / or picture)");const O=Uw(d.duration),L=Yw(u.style),B=ht(Math.min(d.duration,O)),{moved:X,...Q}=Cu(s,r,d.start,d.start+B,it(u.track),{fallback:!0}),et=Rt(),lt=`${a.locale==="en"?"Redraw":"Vẽ lại"} · ${a.locale==="en"?L.en:L.vi}`;s.push({nodeId:"",kind:"video",url:"",label:lt,inPoint:0,sourceDuration:O,volume:0,fit:"cover",...Q,id:et,start:d.start,duration:B,gen:{status:"pending",generator:qw,prompt:w,duration:O,finish:{colorMatch:!1},...j.length?{refs:j}:{},redraw:{src:d.gcsUri,inPoint:ht(d.inPoint??0),seconds:O,style:L.id,mode:u.mode??"keyframes",...u.keyframes!==void 0?{keyframes:u.keyframes}:{},resolution:u.resolution??"720p"}}}),U.push(et),h.push(`redrawVideo ${lt} → ${d.start}s / ${B}s (${u.mode??"keyframes"})${X?` (track ${Q.track})`:""}`);break}case"regionEdit":{const d=b(u.clipId);if(!d||d.kind!=="video"||d.gen||d.title||d.shape||d.motion||d.freeze)throw Error("regionEdit needs a video clip");if(!pi(d.gcsUri))throw Error("this video has no stored copy — add it to the project first (upload / Media)");if((d.playbackRate??1)!==1||Hr(d)||zn(d)||d.reverse)throw Error("regionEdit needs the clip at normal speed (not reversed, sped up or ramped)");if(u.aspectRatio!=null&&!kh.includes(u.aspectRatio))throw Error(`aspectRatio: one of ${kh.join(", ")}`);const w=Array.isArray(u.regions)?u.regions.map(L=>L&&typeof L=="object"?{...L,start:Number.isFinite(L.start)?ht(L.start):L.start,end:Number.isFinite(L.end)?ht(L.end):L.end}:L):u.regions;if(Bw(w,d.duration),s.length+w.length>Kt)throw Error(`Tối đa ${Kt} clip`);const T=Object.fromEntries(xA.filter(L=>d[L]!==void 0).map(L=>[L,structuredClone(d[L])])),j=a.locale==="en",O=new Set;for(const[L,B]of[...w].sort((X,Q)=>X.start-Q.start).entries()){const X=typeof B.prompt=="string"?B.prompt.trim():"",Q=B.action??(X?"custom":null),et=B.model??_w;if(!Q)throw Error(`region ${L+1}: action (scene, camera, character, relight, dof) or prompt (custom)`);if(Q==="custom"&&!X)throw Error(`region ${L+1}: custom needs prompt (what to change)`);let lt=null;if(B.imageMaterialId!=null){const Dt=o.find(ae=>ae.id===B.imageMaterialId)||s.find(ae=>ae.id===B.imageMaterialId&&ae.kind==="image");if(!Dt||Dt.kind!=="image"||!pi(Dt.gcsUri))throw Error(`region ${L+1}: imageMaterialId ${String(B.imageMaterialId).slice(0,40)} is not a stored image in Media`);lt=Dt.gcsUri}if(xh(Q).image==="required"&&!lt)throw Error(`region ${L+1}: ${Q} needs imageMaterialId (one front view of the new character from Media)`);let Y;try{Y=Gw({inPoint:d.inPoint??0,length:d.duration,start:B.start,end:B.end,model:et})}catch(Dt){throw Error(`region ${L+1}: ${Dt.message}`)}const dt=B.exact===!0&&X?X.slice(0,Mh.maxPrompt):Kw(Q,X,{hasImage:!!lt}),bt=ht(d.start+B.start),tt=ht(B.end-B.start),nt=Math.max(.05,Math.min(Mh.fade,tt/4)),{moved:mt,...It}=Cu(s,r,bt,bt+tt,it(u.track),{fallback:!0}),Nt=Rt(),$t=xh(Q),zt=Vw[et];s.push({nodeId:"",kind:"video",url:"",label:`${j?$t.en:$t.vi} · ${zt.label}`,...T,inPoint:Y.offset,sourceDuration:Y.seconds,volume:0,...It,id:Nt,start:bt,duration:tt,enter:{type:"fade",duration:nt},exit:{type:"fade",duration:nt},gen:{status:"pending",generator:Ww,prompt:dt,duration:Y.seconds,finish:{colorMatch:!1},...lt?{refs:[lt]}:{},region:{src:d.gcsUri,action:Q,model:et,winStart:Y.winStart,seconds:Y.seconds,offset:Y.offset,...u.aspectRatio!=null?{aspect:u.aspectRatio}:{}}}}),U.push(Nt),O.add(It.track)}h.push(`regionEdit ${V} → ${w.length} region(s) on track ${[...O].join(", ")}`);break}case"addBroll":case"addText":case"addShape":case"addSolid":case"addAdjustmentLayer":case"addElement":case"addMotion":case"addMap":case"addCard":case"generateElement":{if(s.length>=Kt)throw Error(`Tối đa ${Kt} clip`);const d=it(u.start),w=it(u.duration);if(d===null||w===null||d<0||w<1/be||d+w>We)throw Error("Invalid creative clip timing");const T=ht(d),j=ht(w),O=it(u.track),{track:L,moved:B}=Zt(s,r,T,T+j,O);let X;if(u.op==="addAdjustmentLayer"){const{id:bt,track:tt,start:nt,duration:mt,...It}=bh({id:"x",track:0,start:0,duration:1,label:Ow(s)}),Nt=it(u.numberValue);X={...It,...Nt!==null&&Nt>=0&&Nt<1?{opacity:Nt}:{}}}else if(u.op==="addSolid"){const bt=["linear","radial"].includes(u.preset)?u.preset:"color",tt=u.color??"#d93a3a",{id:nt,track:mt,start:It,duration:Nt,...$t}=Td({id:"x",track:0,start:0,duration:1,aspect:a.W&&a.H?a.W/a.H:void 0,label:Pw(s),fill:bt==="color"?{type:bt,color:tt}:{type:bt,from:tt,to:u.fill??"#0d0f12",angle:it(u.angle)??90}}),zt=it(u.numberValue);X={...$t,...zt!==null&&zt>=0&&zt<1?{opacity:zt}:{}}}else if(u.op==="addBroll"){const bt=o.find(nt=>nt.id===u.materialId);if(!bt?.url||!["image","video"].includes(bt.kind))throw Error("B-roll requires an existing image or video material");const tt=it(u.inPoint)??0;if(tt<0||bt.kind==="image"&&tt!==0||bt.kind==="video"&&(!Number.isFinite(bt.duration)||tt+j>bt.duration+1e-6))throw Error("B-roll range exceeds known source duration");X={nodeId:bt.id,kind:bt.kind,url:bt.url,label:bt.label||"B-roll",inPoint:tt,sourceDuration:bt.kind==="video"?bt.duration:void 0,volume:0,fit:"cover"}}else if(u.op==="generateElement"){const bt=u.generator??vk;if(!Ek[bt])throw Error("Unsupported element generator");const nt=typeof u.prompt=="string"?u.prompt.trim():"";if(nt.length<6||nt.length>1200)throw Error("Element prompt must be 6–1200 characters");if(s.filter(mt=>mt.gen?.status==="pending"&&!t.some(It=>It.id===mt.id)).length>=Js)throw Error(`At most ${Js} generated items per request`);X={nodeId:"",kind:"image",url:"",label:`AI element · ${nt.slice(0,40)}`,volume:0,gen:{status:"pending",generator:bt,prompt:nt,duration:j},...ot(u,.45)},u.anim!=null&&(X.element={},X.pendingAnim=u.anim)}else if(u.op==="addElement"){if(u.elementId!=null){const bt=tg(u.elementId);if(!bt)throw Error("Unknown element");const tt={id:bt.id,...u.primary?{primary:u.primary}:{},...u.secondary?{secondary:u.secondary}:{}};X={nodeId:"",kind:"image",url:"",label:`Element · ${bt.name}`,volume:0,shape:zw(bt.id,tt),element:tt,...ot(u,.25)}}else{const bt=o.find(tt=>tt.id===u.materialId);if(!bt?.url||bt.kind!=="image")throw Error("Element requires a library id or an image material");X={nodeId:bt.id,kind:"image",url:bt.url,...bt.gcsUri?{gcsUri:bt.gcsUri}:{},label:bt.label||"Element",volume:0,element:{},...ot(u,.25)}}X.pendingAnim=u.anim??{}}else if(u.op==="addMotion"){if(j>Qe.maxDuration+1e-6)throw Error(`Motion Code layers: at most ${Qe.maxDuration}s`);const bt=!u.code&&u.motionPreset?Ai(u.motionPreset,u):null,tt=Jo(bt?{code:bt.code,params:{...bt.params,...u.params??{}},preset:bt.preset,kind:bt.kind}:{code:u.code,params:u.params??{},preset:u.motionPreset??void 0,prompt:u.prompt??void 0,kind:u.motionKind??void 0,assets:u.motionAssets??void 0});X={nodeId:"",kind:"image",url:"",label:typeof u.label=="string"&&u.label.trim()?u.label.trim().slice(0,60):bt?`Motion · ${String(u.text||bt.name).slice(0,40)}`:"Motion code",volume:0,motion:tt,...H0(u)}}else if(u.op==="addMap"){const bt=G0(u.models,o,u.geo?.stops??[]),tt=K0(u.images,o,u.geo?.stops??[]),nt=mh({...u.geo,...bt?{models:bt}:{},...tt?{images:tt}:{},...u.buildings!==void 0&&u.buildings!==null?{buildings:u.buildings}:{}},j),mt=typeof u.label=="string"&&u.label.trim()?u.label.trim().slice(0,60):[...nt.stops.map(It=>It.label),...nt.areas.map(It=>It.name),...nt.pins.map(It=>It.label)].find(Boolean)||"";X={nodeId:"",kind:"image",url:"",label:`Bản đồ${mt?` · ${mt.slice(0,40)}`:""}`,volume:0,geo:nt}}else if(u.op==="addCard"){const bt=Lw({html:u.html,width:it(u.width)??wh.width,height:it(u.height)??wh.height,...u.fill?{bg:u.fill}:{}}),tt=720/Math.min(a.W||1280,a.H||720),nt=(a.W||1280)*tt,mt=(a.H||720)*tt;X={nodeId:"",kind:"image",url:"",label:`Card · ${Rw(bt.html).slice(0,40)||"HTML"}`,volume:0,card:bt,posX:Math.max(-1,Math.min(1,it(u.posX)??0)),posY:Math.max(-1,Math.min(1,it(u.posY)??Fw(bt,u.placement,nt,mt))),scale:Math.max(.05,Math.min(4,it(u.scale)??Nw(bt,nt,mt))),enter:{type:"fade",duration:Math.min(.4,j/4)},exit:{type:"fade",duration:Math.min(.3,j/4)}}}else if(u.op==="addShape"){const bt=u.shape&&Object.hasOwn(Fd,u.shape),tt=bt?p$(u.shape,{color:u.color??"#c6f432",accent:u.fill??"#2bd4c9",duration:j}):Dw({preset:u.shape??void 0,d:u.path??void 0,stroke:u.color??"#c6f432",fill:u.fill??null,strokeWidth:it(u.numberValue)??18});X={nodeId:"",kind:"image",url:"",label:`Shape · ${u.shape??"custom"}`,volume:0,shape:tt,...ot(u,bt?1:.6)}}else{const bt=Nl(u);X={nodeId:"",kind:"image",url:"",label:bt.text.slice(0,40),title:bt,volume:0,...it(u.posX)!==null||it(u.posY)!==null?ot(u,1):{},...u.decor===!0?{decor:!0}:{}}}const Q=u.op==="addSolid"||u.op==="addAdjustmentLayer"||u.op==="addMap"?[]:Ll(u.preset??"none",j),et=Rt();U.push(et);const{pendingAnim:lt,...Y}=X,dt={...Y,id:et,start:T,duration:j,track:L,motionKeys:Q,...X.posX!==void 0?{motionV:2}:{}};s.push(lt?s4(dt,lt):st?nc(dt,"exit","fade",{duration:Math.min(.3,j/4)}):dt),h.push(`${st?"lockup":u.op} → ${T}s / ${j}s${st?` (${st.placement.mode==="side"?st.placement.side:st.placement.band})`:""}${B?` (track ${O} → ${L}: ${B})`:""}`);break}case"drawShape":case"addLibraryShape":case"applyStyle2d":case"animateShape":case"arrangeShape":case"traceImage":case"drawFrames":case"animatePuppet":case"editPose":case"traceMotion":case"rotoscope":case"editFrames":case"drawnTransition":{const d=Ud(u,{clips:s,find:b,W:a.W||1280,H:a.H||720,en:a.locale==="en",isLocked:T=>!!r[T.track]?.locked});for(const T of d.patches){const j=s.findIndex(O=>O.id===T.id);s[j]={...s[j],shape:T.shape,...T.duration?{duration:T.duration}:{}}}const w=(T,j,O,L,B={})=>{if(s.length>=Kt)throw Error(`Tối đa ${Kt} clip`);if(O===null||L===null||O<0||L<1/be||O+L>We)throw Error("Invalid creative clip timing");const X=ht(O),Q=ht(L),{track:et}=Zt(s,r,X,X+Q,B.zIndex===-1?null:it(u.track)),lt=Rt();return U.push(lt),s.push({id:lt,nodeId:"",kind:"image",url:"",label:j,volume:0,shape:T,posX:0,posY:0,scale:1,motionV:2,start:X,duration:Q,track:et,motionKeys:[],...B}),lt};if(d.layer&&w(d.layer.shape,d.layer.label,it(u.start),d.layer.duration??it(u.duration)),d.frameLayers){const T=d.startAbs?0:it(u.start)??0;for(const j of d.layers){const O=w(j.shape,j.label,T+j.start,j.duration,u.track!=null?{}:{});if(j.clientJob){const L=s.findIndex(B=>B.id===O);s[L]=Re(s[L],j.clientJob)}}if(d.shakeAt!=null){const j=d.shakeAt,O=L=>!U.includes(L.id)&&!L.disabled&&(L.kind==="video"||L.kind==="image")&&!L.shape&&!L.title&&!r[L.track]?.locked;for(const[L,B]of s.entries()){if(!O(B))continue;const X=Math.abs(B.start+B.duration-j)<.05,Q=Math.abs(B.start-j)<.05;if(!X&&!Q)continue;const et=X?Math.max(0,B.duration-.25):0,lt=X?B.duration:Math.min(B.duration,.4);if(lt-et>=.2)try{s[L]={...B,...ts(B,{amount:X?.3:.45,freq:16,from:et,to:lt,seed:Math.round(j*1e3)+L})}}catch{}}}}else if(d.layers){const T=a.W||1280,j=a.H||720,O=d.layers.map(X=>w(X.shape,X.label,it(u.start),it(u.duration),X.place??{})),L=X=>s.findIndex(Q=>Q.id===O[X]);d.layers.forEach((X,Q)=>{X.anchor!=null&&(nr(s),s[L(Q)]=wa(s,s[L(Q)],{anchor:X.anchor,box:X.box,W:T,H:j}))});const B=xl(s,O,T,j);if(d.layers.forEach((X,Q)=>{X.parent!=null&&X.parent!==Q&&(nr(s),s[L(Q)]=wa(s,s[L(Q)],{parentClipId:O[X.parent],W:T,H:j}))}),d.camera){const X=ht(it(u.start)??0),Q=ht(it(u.duration)??1),{track:et}=Zt(s,r,X,X+Q,null),lt=Rt();s.push(br({id:lt,track:et,start:X,duration:Q,label:"Camera 2D"})),U.push(lt);const Y=s.length-1;s[Y]=Ml(s[Y],d.camera.preset,{W:T,H:j,amount:d.camera.amount??1}),O.forEach((dt,bt)=>{d.layers[bt].parent==null&&(nr(s),s[L(bt)]=wa(s,s[L(bt)],{parentClipId:lt,W:T,H:j}))})}nr(s),d.layers.forEach((X,Q)=>{if(X.motion){const{preset:et,...lt}=X.motion;s[L(Q)]=Ml(s[L(Q)],et,{...lt,W:T,H:j})}}),s=hs(s,B,T,j)}if(d.paper){const T=s.find(j=>Ky(j)&&j.start<=d.paper.start+1e-6&&j.start+j.duration>=d.paper.start+d.paper.duration-1e-6&&!r[j.track]?.locked);T?Object.assign(T,{shape:d.paper.shape,label:d.paper.label}):w(d.paper.shape,d.paper.label,d.paper.start,d.paper.duration,{zIndex:-1})}h.push(d.note);break}case"animateLayer":case"rigLayer":{const d=Fy(u),w=a.W||1280,T=a.H||720;if(u.op==="rigLayer"){const Q=b(d.clipId);if(!Q||Q.kind==="audio")throw Error("Clip not found");if(r[Q.track]?.locked)throw Error("That layer is locked");const et=Object.hasOwn(u,"parentClipId")?u.parentClipId:d.parentClipId,lt=et===void 0?void 0:et===null||et===""?null:et;if(lt===void 0&&d.anchor==null)throw Error("rigLayer needs parentClipId (null = unlink) and / or anchor");nr(s);const Y=Math.max(0,Math.min(Q.duration,(it(d.at)??Q.start)-Q.start)),dt=Q.shape?.v===2?q0(Q):null,bt=xl(s,qp(s,[Q.id]),w,T),tt=s.indexOf(Q);s[tt]=wa(s,Q,{parentClipId:lt,anchor:d.anchor,at:Y,W:w,H:T,box:dt}),s=hs(s,bt,w,T),h.push(`rigLayer: ${Q.label}${lt!==void 0?` → ${lt?b(lt)?.label:"no parent"}`:""}`);break}const j=Array.isArray(d.clipIds)&&d.clipIds.length?d.clipIds:d.clipId?[d.clipId]:null;if(!j)throw Error("animateLayer needs clipId (or clipIds)");if(!Pn[d.preset])throw Error(`animateLayer preset: ${Object.keys(Pn).join(" | ")}`);const O=it(d.stagger)??0,L=it(d.period),B=it(d.amount);if(B!==null&&!(B>=0&&B<=8))throw Error("animateLayer amount: × the preset's default, 0–8");if(L!==null&&!(L>=.1&&L<=60))throw Error("animateLayer period: 0.1–60 s per cycle");nr(s);const X=xl(s,qp(s,j.map(Q=>b(Q)?.id).filter(Boolean)),w,T);if(d.camera===!0){if(!Nc.includes(d.preset))throw Error(`animateLayer camera: true takes a camera preset (${Nc.join(" | ")})`);const Q=j.map(mt=>{const It=b(mt);if(!It||It.kind==="audio")throw Error("Clip not found");if(r[It.track]?.locked)throw Error("That layer is locked");return It}),et=Math.min(...Q.map(mt=>mt.start)),lt=Math.max(...Q.map(mt=>mt.start+mt.duration)),{track:Y}=Zt(s,r,ht(et),ht(lt),null),dt=Rt();s.push(br({id:dt,track:Y,start:ht(et),duration:ht(lt-et),label:"Camera 2D"})),U.push(dt);const bt=s.length-1,tt=Math.max(0,(it(d.at)??et)-et),nt=it(d.duration);s[bt]=Ml(s[bt],d.preset,{W:w,H:T,amount:B??1,a:tt,b:nt!==null?Math.min(lt-et,tt+nt):lt-et});for(const mt of Q)if(!mt.parentId){nr(s);const It=s.findIndex(Nt=>Nt.id===mt.id);s[It]=wa(s,s[It],{parentClipId:dt,W:w,H:T})}nr(s),s=hs(s,X,w,T),h.push(`animateLayer ${d.preset}: Camera 2D over ${Q.length} layer(s)`);break}j.forEach((Q,et)=>{const lt=b(Q);if(!lt||lt.kind==="audio")throw Error("Clip not found");if(r[lt.track]?.locked)throw Error("That layer is locked");const Y=Math.max(0,Math.min(lt.duration-1/be,(it(d.at)??lt.start)-lt.start)),dt=it(d.duration),bt=L??Pn[d.preset].period,tt=s.indexOf(lt);s[tt]=Ml(lt,d.preset,{W:w,H:T,amount:B??1,...L!==null?{period:L}:{},a:Y,b:dt!==null?Math.min(lt.duration,Y+dt):lt.duration,phase:O?et*O/bt%1:0})}),s=hs(s,X,w,T),h.push(`animateLayer ${d.preset}: ${j.length} layer(s)`);break}case"setEasing":case"loopKeys":case"addBounce":{const d=b(u.clipId);if(!d||d.kind==="audio")throw Error("Clip not found");const w=u.property?[u.property]:void 0,T=KM(a.motion),j=(Q,et)=>Q==null?et:Math.max(0,Math.min(1,it(Q)??et)),O=Math.max(.05,Math.min(1,it(u.numberValue)??.5)),L=u.op==="setEasing"&&Array.isArray(u.times)&&u.times.length?u.times:null,B=u.easeIn!=null||u.easeOut!=null,X=L?gk(d,{in:u.easeIn!=null||!B?j(u.easeIn,T.in):null,out:u.easeOut!=null||!B?j(u.easeOut,T.out):null},L,w):u.op==="setEasing"?yk(d,{in:j(u.easeIn,T.in),out:j(u.easeOut,T.out)},w?Me(d,w[0]).map(Q=>({prop:w[0],time:Q.time})):void 0):u.op==="loopKeys"?bk(d,["cycle","pingpong","offset"].includes(u.loopMode)?u.loopMode:"cycle",{props:w}):wk(d,(u.settle??c.settle)==="bounce"?"bounce":"elastic",{amount:O,...w?{props:w}:{}});if(!w&&!L&&u.op==="setEasing")for(const Q of["enter","exit"])d[Q]&&(X[Q]={...d[Q],ease:wu([j(u.easeOut,T.out),0,1-j(u.easeIn,T.in),1])});if(!w&&u.op==="addBounce"&&!Object.keys(X).length&&d.enter&&(X.enter={...d.enter,ease:wu([.34,1+O*1.2,.64,1])}),!Object.keys(X).length)throw Error(L?"No key at those times (clip-local seconds)":u.op==="addBounce"?"Needs a property with at least 2 keys and room after the last key, or an enter animation":u.op==="setEasing"?"Layer has no keys or enter / exit animation":"Layer has no keys");Object.assign(d,X),h.push(`${u.op}: ${V}`);break}case"matchReference":{const d=o.find(Ft=>Ft.id===u.materialId);if(!d||d.role!=="reference")throw Error("materialId phải là một Video mẫu (Media → vai trò Video mẫu)");if(!d.refRecipe)throw Error("Video mẫu chưa được phân tích — phân tích trước rồi dựng");const w=(Array.isArray(u.picks)?u.picks:Array.isArray(u.items)?u.items:[]).slice(0,DE).map(ZE);for(const Ft of w){const Bt=o.find(_t=>_t.id===Ft.materialId);if(!Bt)throw Error(`Không thấy material ${Ft.materialId}`);if(Bt.role==="reference"||Bt.id===d.id)throw Error("Không dùng cảnh của video mẫu — chọn khoảnh khắc từ footage của bạn");if(!["video","image"].includes(Bt.kind))throw Error(`${Bt.label||Bt.id}: chỉ dùng video / ảnh`)}const T=ht(Math.max(0,it(u.start)??0));let j=u.fromClipId?b(xt(u.fromClipId)):null,O=null;if(u.fromClipId&&(!j||j.kind!=="audio"))throw Error("fromClipId phải là clip nhạc (audio)");if(j)O=o.find(Ft=>Ft.id===j.nodeId)??null;else{const Ft=o.filter(Bt=>Bt.kind==="audio"&&Bt.role==="music");O=Ft.length===1?Ft[0]:null}let L=null;try{L=O?.beats?x5(O.beats):null}catch{L=null}const B=Ft=>{const Bt=o.find(_t=>_t.id===Ft);return Bt?.kind==="image"?1/0:it(Bt?.duration)??1/0},X=j?j.start-(j.inPoint||0)-T:0,Q=Ft=>!j||Ft>=(j.inPoint||0)&&Ft<(j.inPoint||0)+j.duration,et=L?{...L,beats:L.beats.filter(Q).map(Ft=>Ft+X).filter(Ft=>Ft>=0),drops:L.drops.filter(Q).map(Ft=>Ft+X).filter(Ft=>Ft>=0)}:null,lt=(Ft,Bt,_t)=>{const pe=o.find(fe=>fe.id===Ft),ee=fe=>Number.isFinite(fe?.start)&&Number.isFinite(fe?.end)&&fe.end>Bt&&fe.start<_t;return Array.isArray(pe?.words)&&pe.words.length?pe.words.filter(ee).map(fe=>fe.word).join(" "):(Array.isArray(pe?.transcript)?pe.transcript:[]).filter(ee).map(fe=>fe.text).join(" ")},Y=JE({recipe:d.refRecipe,picks:w,beats:et,duration:it(u.duration),start:T,sourceDuration:B,copy:u.copy,spoken:lt}),dt=T+Y.duration;if(s.length+Y.segments.length+1>Kt)throw Error(`Tối đa ${Kt} clip`);if(dt>We)throw Error("Vượt giới hạn 20 phút");const tt=!(Ft=>s.some(Bt=>Bt.kind!=="audio"&&Bt.track===Ft&&Bt.start<dt-1e-6&&Bt.start+Bt.duration>T+1e-6))(0)&&!r[0]?.locked?0:Zt(s,r,T,dt,null).track,nt=Math.max(0,Math.min(2,it(u.volume)??(O?0:1))),mt=[];for(const Ft of Y.segments){const Bt=o.find(ee=>ee.id===Ft.materialId),_t=Rt();U.push(_t),mt.push(_t);const pe=Bt.kind==="image"?null:it(Bt.duration);s.push({id:_t,nodeId:Bt.id,track:tt,start:ht(Ft.start),duration:ht(Ft.duration),inPoint:Bt.kind==="image"?0:Ft.inPoint,volume:Bt.kind==="image"?0:nt,url:Bt.url,...Bt.gcsUri?{gcsUri:Bt.gcsUri}:{},kind:Bt.kind,label:`${Bt.label||Bt.kind} · ${Ft.role}`,...pe!==null?{sourceDuration:pe}:{}})}if(O&&!j){const Ft=Ci.find(_t=>!r[_t]?.locked&&!s.some(pe=>pe.track===_t&&pe.start<dt-1e-6&&pe.start+pe.duration>T+1e-6));if(Ft===void 0)throw Error("Không còn hàng audio trống cho nhạc");const Bt=Rt();U.push(Bt),s.push({id:Bt,nodeId:O.id,track:Ft,start:T,duration:ht(Math.min(Y.duration,it(O.duration)??Y.duration)),inPoint:0,volume:1,url:O.url,...O.gcsUri?{gcsUri:O.gcsUri}:{},kind:"audio",label:O.label||"Music",...it(O.duration)!=null?{sourceDuration:it(O.duration)}:{}})}const It={punch:0,move:0,shake:0,look:0,text:0},Nt=[];Y.segments.forEach((Ft,Bt)=>{const _t=b(mt[Bt]),pe=o.find(fe=>fe.id===Ft.materialId),ee=(fe,Qo)=>{try{Qo(),It[fe]++}catch{Nt.push(fe)}};Ft.move&&ee("move",()=>{_t.motionKeys=fu(_t,Ll(Ft.move,_t.duration)),delete _t.posX,delete _t.posY,delete _t.scale,_t.motionV=2}),Ft.punch&&ee("punch",()=>Object.assign(_t,gm(_t,{at:0,duration:Math.min(Wo.maxDuration,_t.duration),amount:Ft.punch.amount,style:Ft.punch.style,anchor:wc(_t,pe)}))),Ft.shake&&ee("shake",()=>Object.assign(_t,ts(_t,{amount:Ft.shake,freq:12,from:0,to:_t.duration,seed:Bt+1}))),Y.look&&ee("look",()=>{const fe=[...(_t.effects||[]).filter(Qo=>Qo.type!==Y.look.effect),{type:Y.look.effect,amount:Y.look.amount}];if(fe.length>kn)throw Error("effects");_t.effects=fe})});const $t=u.specs&&typeof u.specs=="object"?u.specs:{},zt=[];Y.segments.forEach((Ft,Bt)=>{if(!Bt||!Ft.transition)return;let _t=$t[Ft.transition];if(!_t){zt.push(Ft.transition);return}const pe=b(mt[Bt-1]),ee=b(mt[Bt]);try{_t.id==="match-walk"&&(_t=Y0(_t,pe,ee,o)),s=yh(s,mt[Bt-1],_t,Math.min(_t.duration,.45*Math.min(pe.duration,ee.duration)))}catch{zt.push(Ft.transition)}});const{W:Dt=1280,H:ae=720}=a,we=ae>Dt*1.1,Oe=we?ve.bands.portrait:ve.bands.landscape,Ce=[];if(Y.segments.forEach((Ft,Bt)=>{if(!Ft.text)return;const _t=b(mt[Bt]),pe=xc(_t,o.find(fe=>fe.id===Ft.materialId),_t.start+_t.duration/2,{W:Dt,H:ae});let ee=Ft.text.placement;pe&&!(pe.assumed&&ee!=="center")&&Mm(Oe[ee],pe,we)&&(ee=["top","lower","center"].find(fe=>!Mm(Oe[fe],pe,we))??ee),Ce.push({op:"addText",text:Ft.text.text,start:_t.start,duration:Math.max(.5,_t.duration),placement:ee,fontFamily:"Anton",fontSize:we?72:64,color:"#ffffff",styleId:"classic",preset:Ft.energy>=4?"pop-in":"none"})}),Ce.length){const Ft=new Set(s.map(_t=>_t.id)),Bt=yi(s,Ce,o,r,p,{...a,maxOps:Ce.length});s=Bt.clips,It.text=Ce.length-Bt.errors.length;for(let _t=0;_t<Bt.errors.length;_t++)Nt.push("text");for(const _t of s)Ft.has(_t.id)||U.push(_t.id)}const Yt=Object.entries(It).filter(([,Ft])=>Ft).map(([Ft,Bt])=>`${Bt} ${Ft}`).join(", ");h.push(`matchReference: ${Y.segments.length} cảnh, ${Y.duration}s${Y.snapped?", cắt theo beat":""}${Y.drop!=null?`, payoff @${Y.drop}s`:""}${Yt?`; style: ${Yt}${Y.look?` (${Y.look.effect})`:""}`:""}${zt.length?` (${zt.length} chuyển cảnh thành cắt thẳng)`:""}${Nt.length?` (${Nt.length} style bỏ qua)`:""}`);break}case"multicam":{const d=P8(s,u,o,r,{newId:Rt});s=d.clips,U.push(...d.created),h.push(d.note);break}case"kineticEdit":{const d=u.fromClipId?b(xt(u.fromClipId)):null,w=d&&o.find($t=>$t.id===d.nodeId);let T=[];if(d&&(T=Ql(d,w?.words?.length?Ys(w.words,1/0,gh):null).map(zt=>({word:zt.word,start:d.start+zt.start,end:d.start+zt.end}))),!T.length&&typeof(u.text??u.prompt)=="string"&&(T=Hx(u.text??u.prompt,it(u.start)??d?.start??0)),!T.length)throw Error(d?"Clip này chưa có lời thoại — tạo phụ đề trước":"Kinetic Edit needs fromClipId (a clip with speech) or text");const j=it(u.start),O=j!=null&&it(u.duration)!=null?j+it(u.duration):null;j!=null&&(T=T.filter($t=>$t.start>=j-1e-6&&(O==null||$t.start<O)));const L=a.H>a.W*1.1,B=a.brand?.colors??[],X=u.color&&/^#[0-9a-f]{6}$/i.test(u.color)?u.color:B[0]??"#e8141c",Q=T.map($t=>$t.word).join(" "),et=typeof u.preset=="string"&&u.preset.startsWith("poox-")?u.preset.slice(5):"auto",lt=[...new Set([...jg(Q).industries,...Ng(Q),...a.brand?.industry&&a.brand.industry!=="general"?[a.brand.industry]:[]])];let Y=La[et]?et:Qx(Q,{industries:lt,tone:a.brand?.tone??null,seed:T.length});et==="auto"&&La[Y].kind==="scenes"&&!W0(La[Y].caption)&&(Y="punch");const dt=b3(T,{palette:{accent:X,dark:"#0b0b0d",light:"#f4f4f1"},io:Math.max(.08,Math.min(.4,it(u.numberValue)??.16)),portrait:L,orb:!1,seed:1,industry:a.brand?.industry??null,genre:Y,known:$t=>!!W0($t)});if(s.length+dt.beats.length+dt.els.length+dt.carriers.length+dt.orbs.length+dt.texture.length+dt.sfx.length>Kt)throw Error(`Kinetic Edit: ${dt.beats.length} nhịp vượt giới hạn ${Kt} clip — chọn đoạn ngắn hơn (start / duration)`);const bt=dt.beats[0].start,tt=Math.max(...dt.beats.map($t=>$t.start+$t.duration)),nt=[];let mt=s;for(let $t=0;$t<(dt.orbs.length?6:5);$t++){const{track:zt}=Zt(mt,r,bt,tt,null);nt.push(zt),mt=[...mt,{id:`probe${$t}`,kind:"image",track:zt,start:bt,duration:tt-bt}]}const It=($t,zt,Dt,ae,we,Oe)=>{const Ce=Ai($t,{}),Yt=Rt();U.push(Yt),s.push({id:Yt,nodeId:"",kind:"image",url:"",label:we,volume:0,track:Oe,start:Dt,duration:ae,motionKeys:[],motion:Jo({code:Tw+$t,params:{...Ce.params,...zt},preset:$t})})};dt.beats.forEach(($t,zt)=>It($t.preset??"kin-beat",$t.params,$t.start,$t.duration,`Kinetic · ${String($t.params.text).split(" ").slice($t.params.n-$t.params.k,$t.params.n).join(" ").slice(0,40)}`,nt[zt%2])),dt.els.forEach($t=>It($t.preset,$t.params,$t.start,$t.duration,`Kinetic · ${$t.library?$t.preset:$t.params.el}`,nt[2])),dt.carriers.forEach($t=>It($t.preset,$t.params,$t.start,$t.duration,`Kinetic · ${$t.preset!=="kin-carry"?$t.preset:$t.params.mode==="line"?"line":"match cut"}`,nt[3])),dt.texture.forEach($t=>It("kin-texture",$t.params,$t.start,$t.duration,"Kinetic · grain",nt[4])),dt.orbs.forEach($t=>It("kin-orb",$t.params,$t.start,$t.duration,"Kinetic · orb",nt[5]));let Nt=0;for(const $t of dt.sfx){const zt=Ba($t.id);if(zt)try{s.push(zs(s,r,zt,$t.at,{id:Rt()})),Nt++}catch{}}h.push(`Poox 1.1 (${dt.genre}): ${dt.lines} lines, ${dt.beats.length} beats, ${Nt} whooshes (${bt.toFixed(1)}–${tt.toFixed(1)} s)`);break}case"parallax":{const d=(u.clipIds||[]).filter(T=>b(T));if(d.some(T=>r[b(T).track]?.locked))throw Error("Track đã khóa");const w=fE(s,d,{strength:it(u.numberValue)??1});for(const[T,j]of Object.entries(w))Object.assign(b(T),j);h.push(`parallax ${Object.keys(w).length} layers`);break}case"stations":{const d=(u.clipIds||[]).filter(T=>b(T));if(d.some(T=>r[b(T).track]?.locked))throw Error("Track đã khóa");const w=hE(s,d,p,{style:u.preset??"fly-truck",travel:it(u.duration)??1,spacing:it(u.numberValue)??1.2,swing:u.booleanValue!==!1});for(const[T,j]of Object.entries(w.patches))Object.assign(b(T),j);p=w.camera,h.push(`stations ${u.preset??"fly-truck"}: camera flies through ${w.stations} stations`);break}case"arrange3D":{const d=(u.clipIds||[]).filter(T=>b(T));if(d.some(T=>r[b(T).track]?.locked))throw Error("Track đã khóa");const w=ty(s,d,u.preset??"wall",{W:a.W||1280,H:a.H||720,spread:it(u.numberValue)??1});for(const[T,j]of Object.entries(w))Object.assign(b(T),j);h.push(`arrange3D ${u.preset??"wall"}: ${Object.keys(w).length} layers`);break}case"cameraTour":{const d=(u.clipIds||[]).filter(j=>b(j)),w=it(u.at)??Math.min(...d.map(j=>b(j).start)),T=sd(s,d,p,{at:Number.isFinite(w)?w:0,flight:it(u.duration)??1,hold:it(u.numberValue)??1.5,W:a.W||1280,H:a.H||720});p=T.camera,h.push(`cameraTour: ${d.length} layer(s) ${(Number.isFinite(w)?w:0).toFixed(1)}–${T.end.toFixed(1)} s`);break}case"addDevice":{const d=b(u.clipId);if(!d)throw Error(`Không tìm thấy clip ${u.clipId}`);if(r[d.track]?.locked)throw Error("Track đã khóa");const w=typeof u.color=="string"&&/^#[0-9a-fA-F]{6}$/.test(u.color)?u.color:void 0,T=gg(s,r,d,u.preset??"phone",{id:Rt(),color:w,pose:{scale:.8,modelRotation:{x:-6,y:-18,z:0}}});s.push(T.clip),U.push(T.clip.id),Object.assign(d,T.sourcePatch),h.push(`addDevice ${T.clip.device.type}: ${d.label||d.id} on screen (${T.clip.id})`);break}case"scene3D":{const d=(u.clipIds||[]).filter(T=>b(T));if(d.some(T=>r[b(T).track]?.locked))throw Error("Track đã khóa");if(CE.includes(u.preset)){const T=TE(s,r,d,p,u.preset,{at:it(u.at)??void 0,newId:Rt,W:a.W||1280,H:a.H||720,duration:it(u.duration)??void 0,angle:it(u.numberValue)??void 0,angleTo:it(u.angleTo)??void 0,angleKeys:Array.isArray(u.angleKeys)?u.angleKeys:void 0,axis:u.axis==="y"?"y":u.axis==="x"?"x":void 0,anchor:["center","start","end"].includes(u.anchor)?u.anchor:void 0,media:o});for(const j of T.remove??[]){const O=s.findIndex(L=>L.id===j);O>=0&&s.splice(O,1)}for(const[j,O]of Object.entries(T.patches))Object.assign(b(j),O);for(const j of T.add)s.push(j),U.push(j.id);p=T.camera,h.push(`scene3D ${u.preset}: ${T.add.length} rig layer(s), to ${T.end.toFixed(1)} s`);break}if(ny.includes(u.preset)){const T=typeof u.color=="string"&&/^#[0-9a-fA-F]{6}$/.test(u.color)?u.color:void 0,j=PE(s,r,d,p,u.preset,{at:it(u.at)??void 0,newId:Rt,W:a.W||1280,H:a.H||720,duration:it(u.duration)??void 0,color:T,media:o});for(const[O,L]of Object.entries(j.patches))Object.assign(b(O),L);for(const O of j.add)s.push(O),U.push(O.id);p=j.camera,h.push(`scene3D ${u.preset}: ${j.add.length} rig layer(s), to ${j.end.toFixed(1)} s`);break}if(Cw.includes(u.preset)){const T=typeof u.color=="string"&&/^#[0-9a-fA-F]{6}$/.test(u.color)?u.color:void 0,j=jw(s,r,d,p,u.preset,{at:it(u.at)??void 0,newId:Rt,color:T});for(const[O,L]of Object.entries(j.patches))Object.assign(b(O),L);for(const O of j.add)s.push(O),U.push(O.id);p=j.camera,h.push(`scene3D ${u.preset}: ${j.add.length} device(s), camera to ${j.end.toFixed(1)} s`);break}const w=kE(s,d,p,u.preset??"photo-wall-tour",{at:it(u.at)??void 0,W:a.W||1280,H:a.H||720});for(const[T,j]of Object.entries(w.patches))Object.assign(b(T),j);p=w.camera,h.push(`scene3D ${u.preset??"photo-wall-tour"}: ${Object.keys(w.patches).length} layers, camera to ${w.end.toFixed(1)} s`);break}case"anchorMontage":{s=F8(s,r,{clipIds:u.clipIds,at:it(u.at)??void 0,frames:it(u.numberValue)??void 0,polarity:u.booleanValue===!0,style:u.preset==="strobe"?"strobe":"anchor",newId:Rt}),h.push(`montage of ${u.clipIds.length} shots`);break}case"stagger":{const d=(u.clipIds||[]).filter(O=>b(O));if(d.length<2)throw Error("stagger needs at least 2 clipIds");if(d.some(O=>r[b(O).track]?.locked))throw Error("Track đã khóa");const w=Math.max(0,Math.min(10,it(u.numberValue)??.1)),T=["forward","reverse","center","random"].includes(u.order)?u.order:"forward",j=mk(s,d,w,T,7);for(const O of j){const L=b(O.id);L&&L.start!==O.start&&(L.start=O.start)}h.push(`stagger ${d.length} layers by ${w}s (${T})`);break}case"alignLayers":{if(!dk.includes(u.gridPoint))throw Error("Unknown grid point");const d=u.clipIds?.length?u.clipIds:u.clipId?[u.clipId]:[],w=a.W??1280,T=a.H??720;if(!d.length)throw Error("alignLayers needs clipIds");for(const j of d){const O=b(j);if(!O||O.kind==="audio")throw Error("Clip not found");if(r[O.track]?.locked)throw Error("Track đã khóa");const L=Math.max(0,Math.min(O.duration,u.at!=null?it(u.at)-O.start:0));Object.assign(O,hk(O,a.rectOf?.(O)??fk(O,L,w,T),u.gridPoint,ht(L),w,T))}h.push(`align ${d.length} layer(s) → ${u.gridPoint}`);break}case"physicsDrop":{const d=u.clipIds?.length?u.clipIds:u.clipId?[u.clipId]:[];if(!d.length)throw Error("physicsDrop needs clipIds");for(const O of d){const L=b(O);if(!L)throw Error("Clip not found");if(r[L.track]?.locked)throw Error("Track đã khóa")}const w=it(u.at)??Math.min(...d.map(O=>b(O).start)),T=it(u.numberValue),j=uk(s,d,{at:w,W:a.W??1280,H:a.H??720,rectOf:a.rectOf,mode:u.mode==="above"?"above":"here",bounciness:T!=null?Math.max(0,Math.min(.95,T)):"normal",duration:it(u.duration)??3,walls:u.booleanValue===!0});s=s.map(O=>d.includes(O.id)?j.clips.find(L=>L.id===O.id)??O:O),h.push(`physics drop: ${d.length} layer(s) from ${ht(w)}s`);break}case"applyPalette":{const d=u.clipIds?.length?u.clipIds:u.clipId?[u.clipId]:[];if(!d.length)throw Error("applyPalette needs clipIds");for(const w of d){const T=b(w);if(!T)throw Error("Clip not found");if(r[T.track]?.locked)throw Error("Track đã khóa");Object.assign(T,pk(T,u.colors))}h.push(`palette (${(u.colors||[]).length} colours) → ${d.length} layer(s)`);break}case"makeSeamless":{if(u.booleanValue===!1){h.push("seamless: off");break}const d=it(u.numberValue),w=Rd(s,r,p,{overlap:d!==null&&d>0&&d<=.6?d:void 0,accent:typeof u.color=="string"&&/^#[0-9a-fA-F]{6}$/.test(u.color)?u.color:void 0,newId:Rt,...l});s=w.clips,p=w.camera,h.push(`seamless: ${w.notes.join("; ")}`);break}case"setJoin":{const d=dv(s,r,p,{join:it(u.numberValue),style:u.preset,duration:it(u.duration),ease:u.ease,newId:Rt,...l});if(s=d.clips,p=d.camera,h.push(`join ${it(u.numberValue)}: ${d.style}${typeof u.text=="string"&&u.text.trim()?` — ${u.text.trim().slice(0,200)}`:""}${d.notes.length>1?` (${d.notes.slice(1).join("; ")})`:""}`),u.booleanValue===!0&&typeof u.prompt=="string"&&u.prompt.trim().length>=6){if(y.length>=jl)throw Error(`At most ${jl} Claude motion jobs per request`);y.push({join:it(u.numberValue),prompt:u.prompt.trim().slice(0,1200)})}break}case"joinCut":{s=Aw(s,u.clipId,u.preset,{duration:it(u.duration)??void 0,color:typeof u.color=="string"&&/^#[0-9a-fA-F]{6}$/.test(u.color)?u.color:void 0}),h.push(u.preset==="none"?`join removed: ${V}`:`join ${u.preset}: ${V}`);break}case"silhouetteReveal":{const d=Iw(s,r,u.clipId,{duration:it(u.duration)??void 0,newId:Rt});s=d.clips,E.push({clipId:d.copyId,mode:u.preset==="object"?"object":"person"}),h.push(`silhouette reveal: ${V}`);break}case"setJoinMotion":{const d=fv(s,r,p,{join:it(u.numberValue),code:u.code,params:u.params??{},prompt:u.prompt??"",duration:it(u.duration),newId:Rt,...l});s=d.clips,p=d.camera,h.push(`join ${it(u.numberValue)}: Claude Motion layer`);break}case"separateText":{const d=Ju(s,{tracks:r});s=d.clips,h.push(`text guard: ${d.notes.length?d.notes.join("; "):"no overlapping text"}`);break}case"precompose":{const d=Qt(u),w=Array.isArray(d.clipIds)?d.clipIds:typeof d.clipId=="string"?[d.clipId]:[];if(!w.length)throw Error("precompose needs clipIds (the layers to put in the comp)");for(const O of w)if(!b(O))throw Error(`Không tìm thấy clip ${O}`);let T=Rt();for(;b(T);)T=Rt();const j=Rk(s,w,{id:T,label:typeof d.label=="string"&&d.label.trim()?d.label.trim().slice(0,80):Dk(s),tracks:r,W:a.W||1280,H:a.H||720});s=j.clips,U.push(j.id),h.push(`precompose ${w.length} layer(s) → comp ${b(j.id).label} (${j.id}) on track ${j.track}`);break}case"uncompose":{const d=b(u.clipId);if(!Kh(d))throw Error("uncompose needs a comp layer (clipId)");const w=Fk(s,d.id,{tracks:r,W:a.W||1280,H:a.H||720,newId:Rt});s=w.clips,h.push(`uncompose ${d.label}: ${w.ids.length} layer(s) back${w.nullId?` (its transform on null ${w.nullId})`:""}${w.dropped.length?`; dropped with the comp: ${w.dropped.join(", ")}`:""}`);break}case"compact":{const d=(it(u.track)!==null?[it(u.track)]:[...new Set(s.map(w=>w.track))]).filter(w=>!r[w]?.locked);for(const w of d){let T=0;for(const j of s.filter(O=>O.track===w).sort((O,L)=>O.start-L.start))j.start=ht(T),T=ht(T+j.duration)}h.push(`compact ${it(u.track)!==null?"track "+u.track:"tất cả track"}`);break}case"courseEdit":throw Error(u.error||"courseEdit could not be built");case"framedEdit":throw Error(u.error||"framedEdit could not be built");case"updateMap":{const d=b(u.clipId);if(!d?.geo)throw Error("updateMap needs an animated map clip (addMap)");if(Array.isArray(u.places)&&!u.placesResolved)throw Error("updateMap places must be resolved first");const w=d.geo,T=w.plan??{},j=Array.isArray(u.places)?u.places:hh(w),O=(lt,Y)=>lt??Y,L=Eg({places:j,duration:d.duration,style:O(u.mapStyle,w.style),route:O(u.route,T.route??!!w.route),routeLook:O(u.routeLook,T.routeLook??w.route?.look??"saber"),color:O(u.color,T.color??w.route?.color??"#ff3b30"),pins:O(u.pins,T.pins??w.pins.length>0),drawnRoute:u.routePoints!==void 0?u.routePoints:T.drawnRoute,drawnAreas:u.areas!==void 0?u.areas:T.drawnAreas,icons:Array.isArray(u.icons)?u.icons:w.icons??null}),B=u.models!==void 0?G0(u.models,o,j)??[]:w.models,X=u.images!==void 0?K0(u.images,o,j)??[]:w.images??[],Q=u.buildings===void 0||u.buildings===null?w.buildings:u.buildings,et=s.indexOf(d);s[et]={...d,geo:mh({...L,models:B,images:X,...w.hd?{hd:w.hd}:{},...Q?{buildings:Q}:{}},d.duration)},h.push(`map ${d.id}: ${L.stops.length} stop(s)${s[et].geo.buildings?", 3D buildings":""}${L.route?`, ${L.route.look} route`:""}${L.areas.length?`, ${L.areas.length} area(s)`:""}${B.length?`, ${B.length} model(s)`:""}${X.length?`, ${X.length} picture(s)`:""}${L.icons?.length?`, ${L.icons.length} icon(s)`:""}`);break}case"annotateMap":case"flyTo":case"setMapBounds":{const d=Qt(u),w=b(d.clipId);if(!w)throw Error("Map clip not found");if(w.geo)throw Error("That clip is an animated map (addMap): its pins, routes and areas are part of the map itself — change them with addMap / the Map panel, not annotateMap / flyTo / setMapBounds");const T=o.find(B=>B.id===w.nodeId);if(!w.mapSize&&Number.isInteger(T?.width)&&Number.isInteger(T?.height)&&T.width>1&&T.height>1&&(w.mapSize=[T.width,T.height]),Array.isArray(d.size)&&d.size.length===2&&d.size.every(B=>Number.isInteger(B)&&B>1&&B<=2e4)&&!w.mapSize&&(w.mapSize=[d.size[0],d.size[1]]),d.bounds!=null&&(w.mapBounds=xk(d.bounds)),u.op==="setMapBounds"){if(d.bounds==null)throw Error("setMapBounds needs bounds [west, south, east, north]");h.push(`map bounds ${JSON.stringify(w.mapBounds)}`);break}const j=a.W||1280,O=a.H||720;if(u.op==="flyTo"){const B=Mk(w,d,{W:j,H:O,cam:p});B.camera?p=B.camera:Object.assign(w,B.patch),h.push(B.applied);break}const L=$k(d,{base:w,W:j,H:O,cam:p,materials:o});if(s.length+L.layers.length>Kt)throw Error(`Tối đa ${Kt} clip`);for(const B of L.layers){const{track:X}=Zt(s,r,B.start,B.start+B.duration),Q=Rt();if(U.push(Q),d.kind==="icon"&&w.kind==="video"){const[et,lt]=B.mapAnno.follow,Y=.07,dt={x:Math.max(0,Math.min(1-2*Y,et-Y)),y:Math.max(0,Math.min(1-2*Y,lt-Y)),w:2*Y,h:2*Y},bt={...B,id:Q,track:X},tt=Us(bt,w,{region:dt,mode:d.follow==="point"?"point":"scene",at:B.start});s.push({...bt,...tt}),S.push({clipId:Q,...tt.pendingPin})}else s.push({...B,id:Q,track:X})}h.push(`${L.applied} (${L.layers.length} layer${L.layers.length>1?"s":""}${d.kind==="icon"&&w.kind==="video"?", tracked on the footage once the editor opens":""})`);break}case"reglueMap":{s=_h(s,p,a.W||1280,a.H||720),h.push("map items re-glued to the camera");break}case"meshWarp":case"puppet":case"liquify":case"displace":case"clearDistort":{const d=Qt(u),w=b(d.clipId);if(!w)throw Error(`Không tìm thấy layer ${d.clipId}`);if(!$w(w))throw Error("Distort needs a video / picture / text / shape layer");const T={...w.distort||{}};if(u.op==="meshWarp"){const O=Math.round(it(d.rows)??3),L=Math.round(it(d.cols)??3),B=O*L,X=(Array.isArray(d.keys)?d.keys:[]).map(Q=>{const et=Q?.offsets??Q?.d;if(et!=null&&(!Array.isArray(et)||et.length!==B))throw Error(`meshWarp offsets: ${B} [dx, dy] pairs (rows × cols, row by row)`);return{t:it(Q?.t)??0,d:et==null?new Array(B*2).fill(0):et.flatMap(lt=>Array.isArray(lt)?[Number(lt[0]),Number(lt[1])]:[Number(lt),NaN])}});T.mesh={rows:O,cols:L,keys:X.sort((Q,et)=>Q.t-et.t)},h.push(`mesh warp ${V}: ${O}×${L}, ${X.length} key${X.length===1?"":"s"}`)}else if(u.op==="puppet"){if(!Array.isArray(d.pins))throw Error("puppet needs pins [{u, v, dx?, dy?, keys?}]");T.puppet={pins:d.pins.map(O=>({u:O?.u,v:O?.v,...O?.dx!=null?{dx:O.dx}:{},...O?.dy!=null?{dy:O.dy}:{},...Array.isArray(O?.keys)?{keys:[...O.keys].map(L=>({t:L?.t,dx:L?.dx??0,dy:L?.dy??0})).sort((L,B)=>L.t-B.t)}:{}})),...it(d.stiff)!=null?{stiff:it(d.stiff)}:{}},h.push(`puppet ${V}: ${d.pins.length} pin${d.pins.length===1?"":"s"}`)}else if(u.op==="liquify"){if(!Array.isArray(d.strokes)||!d.strokes.length||d.strokes.length>200)throw Error("liquify needs strokes [{tool, points [[u,v]…], size?, pressure?}] (1–200)");for(const O of d.strokes)if(!fh.includes(O?.tool)||!Array.isArray(O.points)||!O.points.length||O.points.length>500||O.points.some(L=>!Array.isArray(L)||!L.every(B=>Number.isFinite(B)&&B>=-.5&&B<=1.5)))throw Error(`liquify strokes: tool ${fh.join(" | ")}, points [[u,v]…] (0..1 of the picture)`);T.liquify=vw(d.reset?null:T.liquify,d.strokes,{aspect:it(d.aspect)??1}),h.push(`liquify ${V}: ${d.strokes.length} stroke${d.strokes.length===1?"":"s"}`)}else if(u.op==="displace")if(d.mapClipId==null)delete T.displace,h.push(`displacement map off ${V}`);else{const O=b(d.mapClipId);if(!O||O.id===w.id||O.kind!=="video"&&O.kind!=="image")throw Error("displace needs mapClipId: another video / picture layer");T.displace={map:O.id,x:it(d.x)??0,y:it(d.y)??0,...d.channel==="rg"?{channel:"rg"}:{},...Array.isArray(d.keys)?{keys:[...d.keys].map(L=>({t:L?.t,x:L?.x??0,y:L?.y??0})).sort((L,B)=>L.t-B.t)}:{}},h.push(`displacement map ${V} ← ${O.label||O.id} (${T.displace.x}, ${T.displace.y} px)`)}else{const O=d.tool??d.preset;if(O!=null&&!["mesh","puppet","liquify","displace"].includes(O))throw Error("clearDistort tool: mesh | puppet | liquify | displace (omitted = all)");if(O==null)for(const L of Object.keys(T))delete T[L];else delete T[O];h.push(`distort off ${V}${O?` (${O})`:""}`)}const j=Ew(Sw(T));j?w.distort=j:delete w.distort,hn(w);break}default:throw Error(`Op không hỗ trợ: ${u?.op}`)}for(const d of[u?.clipId,...Array.isArray(u?.clipIds)?u.clipIds:[]]){const w=typeof d=="string"?b(d):null;if(Kh(w)){const T=Z2(w);if(T.length)throw Error(`not supported on a comp layer (${T.join(", ")}) — apply it to the layers inside the comp`)}}for(let d=ut;d<U.length;d++)x.push(D)}catch(V){U.length=ut,$.push(D),f.push(`${u?.op||"?"}: ${V.message}`)}}if(s=Wk(s),s.some(D=>D.mapAnno?.follow)&&(JSON.stringify(p)!==JSON.stringify(n)||at.some(D=>D?.op==="flyTo"||D?.op==="move"||D?.op==="setPropertyKeys"))&&(s=_h(s,p,a.W||1280,a.H||720)),U.length){const D=new Set(U.filter(ut=>!s.find(gt=>gt.id===ut)?.mapAnno)),H=Ju(s,{tracks:r,movable:D});H.notes.length&&(s=H.clips,h.push(`text guard: ${H.notes.join("; ")}`))}return N&&!m.length&&m.push({op:"setExportFormat",aspectRatio:N}),{clips:s,tracks:r,actions:m,motionJobs:y,applied:h,errors:f,failed:$,createdBy:x,camera:p,...F?{pins:F}:{},..._?{markers:_}:{},...K!==void 0?{exportRange:K}:{},...E.length?{cutouts:E}:{},...v.length?{mattes:v}:{},...k.length?{lookups:k}:{},...S.length?{surfacePins:S}:{}}}function AA(t,e,o={in:.5,out:.5},r={}){const n=t.find($=>$.id===e?.clipId);if(!n||n.kind==="audio"||n.kind==="model"||e.preset==="none")return null;const a=n.start+n.duration,i=$=>$.id!==n.id&&$.kind!=="audio"&&$.kind!=="model"&&!r[$.track]?.locked&&Math.abs($.start-a)<=.1,l=t.find($=>i($)&&$.track===n.track)??t.filter(i).sort(($,x)=>Math.abs($.start-a)-Math.abs(x.start-a)||x.track-$.track)[0]??null,p=`${e.transitionId??""} ${e.spec?.name??""} ${e.preset??""} ${(e.spec?.tags??[]).join(" ")}`.toLowerCase(),c=/slide|push|wipe|whip|trượt|đẩy/.test(p)?"slide":/zoom|phóng/.test(p)?"zoom":"fade",s=it(e.duration)??it(e.spec?.duration)??((o.in??.5)+(o.out??.5))/2,h=Math.max(.1,Math.min(1,s/2)),f=c==="slide"?"slide-left":c==="zoom"?"zoom-in":"fade",m=c==="slide"?"slide-left":c==="zoom"?"zoom-out":"fade";return{clips:t.map($=>$.id===n.id?nc($,"exit",f,{duration:h}):l&&$.id===l.id?nc($,"enter",m,{duration:h}):$),note:`${f} out${l?` / ${m} in on ${l.label||l.id}`:""} (no footage cut to transition)`}}const CA=new Set(["addClip","placeBehindPerson","cutOutObject","annotateMap",...Zy]);function bj(t,e,o=[],r={},n=null,a={}){const i=Math.min(ql,a?.maxOps??Yl);let l=(Array.isArray(e)?e:[]).slice(0,i).map((c,s)=>({op:c,index:s}));const p=[];for(let c=0;c<=i+1;c++){const s=yi(t,l.map(k=>k.op),o,r,n,a);if(!s.errors.length){if(p.length&&l.some(k=>vs.includes(k.op?.op))){for(const k of l.filter(b=>vs.includes(b.op?.op)))p.push({index:k.index,op:k.op?.op,error:"skipped: part of the plan could not be applied"});l=l.filter(k=>!vs.includes(k.op?.op));continue}return p.sort((k,b)=>k.index-b.index),{ops:l.map(k=>k.op),skipped:p,result:s}}const h=new Set(s.failed),f=new Map(s.failed.map((k,b)=>[k,s.errors[b]])),m=new Set(s.createdBy),y=l.map((k,b)=>b).filter(k=>m.has(k)||h.has(k)&&CA.has(l[k].op?.op)),$=k=>[k?.clipId,...Array.isArray(k?.clipIds)?k.clipIds:[]].filter(b=>typeof b=="string"&&/^new:\d+$/.test(b)),x=k=>y[Number(k.slice(4))-1];let E,v,S;for(let k=new Set;;){E=new Set([...h].filter(I=>!k.has(I))),S=new Set;for(let I=!0;I;)I=!1,l.forEach((P,C)=>{!E.has(C)&&$(P.op).some(z=>x(z)!==void 0&&E.has(x(z)))&&(E.add(C),S.add(C),I=!0)});const b=y.filter(I=>!E.has(I));v=I=>{if(typeof I!="string"||!/^new:\d+$/.test(I))return I;const P=x(I);return P===void 0?I:`new:${b.indexOf(P)+1}`};const A=[...E].filter(I=>h.has(I)&&!S.has(I)&&!k.has(I)&&$(l[I].op).some(P=>v(P)!==P));if(!A.length)break;A.forEach(I=>k.add(I))}for(const k of[...E].sort((b,A)=>b-A))p.push({index:l[k].index,op:l[k].op?.op??"?",error:S.has(k)?`${l[k].op?.op??"?"}: targets a layer that could not be created`:f.get(k)});if(l=l.flatMap((k,b)=>E.has(b)?[]:[{index:k.index,op:k.op&&(typeof k.op.clipId=="string"||Array.isArray(k.op.clipIds))?{...k.op,...typeof k.op.clipId=="string"?{clipId:v(k.op.clipId)}:{},...Array.isArray(k.op.clipIds)?{clipIds:k.op.clipIds.map(v)}:{}}:k.op}]),!l.length)break}return p.sort((c,s)=>c.index-s.index),{ops:[],skipped:p,result:null}}function Jy(t,e,o,{insert:r=!1,makeId:n=Rt,tracks:a={}}={}){if(!Array.isArray(e)||!e.length)return{clips:t,pasted:[]};if(t.length+e.length>Kt)return{clips:t,pasted:[],error:`Tối đa ${Kt} clip`};if(e.some(s=>a[s.track]?.locked))return{clips:t,pasted:[],error:"Track đã khóa"};const i=Math.min(...e.map(s=>s.start)),l=Math.max(0,Number(o)||0),p=e.map(s=>({...s,id:n(),start:ht(l+(s.start-i))}));let c=t.map(s=>({...s}));if(r){const s={};for(const h of p)s[h.track]=Math.max(s[h.track]||0,ht(h.start+h.duration-l));for(const h of c)s[h.track]&&h.start>=l-1/(2*be)&&(h.start=ht(h.start+s[h.track]))}return c=[...c,...p],c.some(s=>s.start+s.duration>We)?{clips:t,pasted:[],error:"Vượt giới hạn 20 phút"}:{clips:c,pasted:p.map(s=>s.id)}}let jA=0;function Rt(){try{return crypto.randomUUID()}catch{return`op-${Date.now()}-${jA++}`}}export{Ir as $,A5 as A,gx as B,Ug as C,Zo as D,rC as E,YM as F,AC as G,qg as H,jC as I,IC as J,VM as K,q3 as L,Sx as M,JM as N,o$ as O,La as P,r$ as Q,OC as R,Eu as S,Og as T,zv as U,v4 as V,lo as W,N8 as X,Zm as Y,Jm as Z,F8 as _,px as a,s$ as a$,I8 as a0,M8 as a1,Ym as a2,h1 as a3,RC as a4,DC as a5,BC as a6,K3 as a7,G3 as a8,mC as a9,MC as aA,$C as aB,_M as aC,Ey as aD,Pn as aE,ou as aF,hd as aG,Ni as aH,rj as aI,PC as aJ,Fd as aK,p$ as aL,Nd as aM,KM as aN,vC as aO,EC as aP,zm as aQ,FC as aR,NC as aS,G6 as aT,zy as aU,hI as aV,iu as aW,aj as aX,kI as aY,i$ as aZ,Oi as a_,Lo as aa,iM as ab,hC as ac,gC as ad,fC as ae,dM as af,lC as ag,zd as ah,x1 as ai,cC as aj,pC as ak,aM as al,dC as am,uC as an,rs as ao,Su as ap,df as aq,D3 as ar,Xg as as,hc as at,wC as au,UA as av,ZC as aw,qC as ax,YC as ay,xC as az,BA as b,Af as b$,l$ as b0,T1 as b1,ME as b2,ey as b3,ry as b4,OE as b5,GC as b6,Q1 as b7,TE as b8,kE as b9,KA as bA,Pg as bB,CC as bC,YA as bD,bj as bE,qA as bF,_A as bG,GA as bH,l4 as bI,s5 as bJ,r5 as bK,o1 as bL,L$ as bM,Qf as bN,N$ as bO,R$ as bP,B4 as bQ,G4 as bR,Wo as bS,F1 as bT,Vg as bU,XA as bV,zC as bW,WA as bX,zs as bY,z3 as bZ,v5 as b_,PE as ba,ty as bb,sd as bc,KC as bd,NE as be,uE as bf,_C as bg,J1 as bh,fE as bi,hE as bj,Xx as bk,Ta as bl,VA as bm,e8 as bn,WC as bo,fy as bp,Rs as bq,py as br,QE as bs,VC as bt,w4 as bu,ZA as bv,hv as bw,T5 as bx,_f as by,RM as bz,s4 as c,mc as c$,Ru as c0,eC as c1,Cf as c2,oC as c3,tC as c4,SC as c5,ql as c6,F3 as c7,Ba as c8,C3 as c9,dj as cA,hj as cB,ij as cC,sj as cD,va as cE,kC as cF,jM as cG,J6 as cH,hA as cI,Fm as cJ,Q6 as cK,Ap as cL,ze as cM,Vs as cN,fc as cO,sC as cP,aC as cQ,D5 as cR,iC as cS,vS as cT,QC as cU,ej as cV,tj as cW,ap as cX,oj as cY,JC as cZ,bC as c_,HA as ca,$5 as cb,Uf as cc,n$ as cd,TC as ce,V4 as cf,LC as cg,U3 as ch,c1 as ci,gf as cj,UC as ck,nj as cl,Au as cm,cj as cn,yj as co,Yy as cp,e$ as cq,Jy as cr,Ly as cs,gj as ct,mj as cu,lj as cv,fj as cw,bA as cx,pj as cy,uj as cz,u5 as d,yM as d0,XC as d1,HC as d2,a4 as e,x4 as f,P4 as g,t4 as h,z4 as i,QA as j,L4 as k,J3 as l,JA as m,E1 as n,yi as o,hx as p,Y1 as q,Qm as r,X3 as s,o0 as t,xf as u,yC as v,yf as w,z5 as x,O5 as y,nC as z};
|